Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

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.

Fixes: 6d492ecc6489 ("powerpc/THP: Add code to handle HPTE faults for hugepages")
Cc: stable@vger.kernel.org # v3.11+
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Reviewed-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Aneesh Kumar K.V and committed by
Michael Ellerman
36b35d5d 655471f5

+2 -1
+2 -1
arch/powerpc/mm/hugepage-hash64.c
··· 85 85 BUG_ON(index >= 4096); 86 86 87 87 vpn = hpt_vpn(ea, vsid, ssize); 88 - hash = hpt_hash(vpn, shift, ssize); 89 88 hpte_slot_array = get_hpte_slot_array(pmdp); 90 89 if (psize == MMU_PAGE_4K) { 91 90 /* ··· 100 101 valid = hpte_valid(hpte_slot_array, index); 101 102 if (valid) { 102 103 /* update the hpte bits */ 104 + hash = hpt_hash(vpn, shift, ssize); 103 105 hidx = hpte_hash_index(hpte_slot_array, index); 104 106 if (hidx & _PTEIDX_SECONDARY) 105 107 hash = ~hash; ··· 126 126 if (!valid) { 127 127 unsigned long hpte_group; 128 128 129 + hash = hpt_hash(vpn, shift, ssize); 129 130 /* insert new entry */ 130 131 pa = pmd_pfn(__pmd(old_pmd)) << PAGE_SHIFT; 131 132 new_pmd |= _PAGE_HASHPTE;