Skip to contentSkip to conversation

powerpc/mm: Recompute hash value after a failed update

PATCH Applied Aneesh Kumar K.V 3 participants 8 messages Sep 15, 2015 – Sep 17, 2015 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/mm: Recompute hash value after a failed update

If we had secondary hash flag set, we ended up modifying hash value in the updatepp code path. Hence with a failed updatepp we will be using a wrong hash value for the following hash insert. Fix this by recomputing hash before insert.

---
 arch/powerpc/mm/hugepage-hash64.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/mm/hugepage-hash64.c +2 -1
index 43dafb9d6a46..4d87122cf6a7 100644
@@ -85,7 +85,6 @@ int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid,
 	BUG_ON(index >= 4096);
 
 	vpn = hpt_vpn(ea, vsid, ssize);
-	hash = hpt_hash(vpn, shift, ssize);
 	hpte_slot_array = get_hpte_slot_array(pmdp);
 	if (psize == MMU_PAGE_4K) {
 		/*
@@ -101,6 +100,7 @@ int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid,
 	valid = hpte_valid(hpte_slot_array, index);
 	if (valid) {
 		/* update the hpte bits */
+		hash = hpt_hash(vpn, shift, ssize);
 		hidx =  hpte_hash_index(hpte_slot_array, index);
 		if (hidx & _PTEIDX_SECONDARY)
 			hash = ~hash;
@@ -126,6 +126,7 @@ int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid,
 	if (!valid) {
 		unsigned long hpte_group;
 
+		hash = hpt_hash(vpn, shift, ssize);
 		/* insert new entry */
 		pa = pmd_pfn(__pmd(old_pmd)) << PAGE_SHIFT;
 		new_pmd |= _PAGE_HASHPTE;
Signature · 1 line
2.5.0
#1 lore raw
Quoted 4 lines · Aneesh Kumar K.V

If we had secondary hash flag set, we ended up modifying hash value in the updatepp code path. Hence with a failed updatepp we will be using a wrong hash value for the following hash insert. Fix this by recomputing hash before insert.

Without this patch we can end up with using wrong slot number in linux pte. That can result in us missing an hash pte update or invalidate which can cause memory corruption or even machine check ?

-aneesh

#2 lore raw
Quoted 10 lines · Aneesh Kumar K.V
Quoted 4 lines · Aneesh Kumar K.V

If we had secondary hash flag set, we ended up modifying hash value in the updatepp code path. Hence with a failed updatepp we will be using a wrong hash value for the following hash insert. Fix this by recomputing hash before insert.

Without this patch we can end up with using wrong slot number in linux pte. That can result in us missing an hash pte update or invalidate which can cause memory corruption or even machine check ?

Thanks. When did this break? Always? If so this should go to stable?

cheers

#3 lore raw
Quoted 8 lines · Michael Ellerman
Quoted 7 lines · Aneesh Kumar K.V
Quoted 4 lines · Aneesh Kumar K.V

If we had secondary hash flag set, we ended up modifying hash value in the updatepp code path. Hence with a failed updatepp we will be using a wrong hash value for the following hash insert. Fix this by recomputing hash before insert.

Quoted 6 lines
Quoted 3 lines

Without this patch we can end up with using wrong slot number in linux pte. That can result in us missing an hash pte update or invalidate which can cause memory corruption or even machine check ?

Thanks. When did this break? Always? If so this should go to stable?

IIUC we have this issue with initial support for THP (6d492ecc6489113968ec269be1cf88942d4a5d29) " powerpc/THP: Add code to handle HPTE faults for hugepages". So yes
this should got to stable.

-aneesh

#4 lore raw
Quoted 14 lines · Aneesh Kumar K.V
Quoted 12 lines · Michael Ellerman
Quoted 10 lines · Aneesh Kumar K.V
Quoted 4 lines · Aneesh Kumar K.V

If we had secondary hash flag set, we ended up modifying hash value in the updatepp code path. Hence with a failed updatepp we will be using a wrong hash value for the following hash insert. Fix this by recomputing hash before insert.

Without this patch we can end up with using wrong slot number in linux pte. That can result in us missing an hash pte update or invalidate which can cause memory corruption or even machine check ?

Quoted 6 lines
Quoted 2 lines

Thanks. When did this break? Always? If so this should go to stable?

IIUC we have this issue with initial support for THP (6d492ecc6489113968ec269be1cf88942d4a5d29) " powerpc/THP: Add code to handle HPTE faults for hugepages". So yes
this should got to stable.

Thanks. And that went into 3.11.

You haven't actually seen any crashes that are definitely linked to this though am I right? You just found it by code inspection?

cheers

#5 lore raw
Quoted 18 lines · Michael Ellerman
Quoted 17 lines · Aneesh Kumar K.V
Quoted 14 lines · Michael Ellerman
Quoted 10 lines · Aneesh Kumar K.V
Quoted 4 lines · Aneesh Kumar K.V

If we had secondary hash flag set, we ended up modifying hash value in the updatepp code path. Hence with a failed updatepp we will be using a wrong hash value for the following hash insert. Fix this by recomputing hash before insert.

Without this patch we can end up with using wrong slot number in linux pte. That can result in us missing an hash pte update or invalidate which can cause memory corruption or even machine check ?

Thanks. When did this break? Always? If so this should go to stable?

Quoted 9 lines
Quoted 3 lines

IIUC we have this issue with initial support for THP (6d492ecc6489113968ec269be1cf88942d4a5d29) " powerpc/THP: Add code to handle HPTE faults for hugepages". So yes
this should got to stable.

Thanks. And that went into 3.11.

You haven't actually seen any crashes that are definitely linked to this though am I right? You just found it by code inspection?

I am still not sure, why we haven't seen crashes. One of the possibility is that we removed that slot because we ran out of free space soon enough and everything went back normal.

Yes I found this by code inspection.

-aneesh

reviewer Applied
#7 lore raw
In reply to Aneesh Kumar K.V
Quoted 7 lines · Aneesh Kumar K.V

If we had secondary hash flag set, we ended up modifying hash value in the updatepp code path. Hence with a failed updatepp we will be using a wrong hash value for the following hash insert. Fix this by recomputing hash before insert.

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/36b35d5d807b7e57aff7d08e

cheers