Skip to contentSkip to conversation

Hugepage hash flushing bugfix

PPC64 David Gibson 2 participants 2 messages Feb 25, 2005

lore
Share & tools
lore
#0 lore raw

Andrew, Linus, please apply:

Fix a potentially bad (although very rarely triggered) bug in the ppc64 hugepage code. hpte_update() did not correctly calculate the address for hugepages, so pte_clear() (which we use for hugepage ptes as well as normal ones) would not correctly flush the hash page table entry. Under the right circumstances this could potentially lead to duplicate hash entries, which is very bad.

davem's upcoming patch to pass the virtual address directly to set_pte() and its ilk will obsolete this, but this is bad enough it should probably be fixed in the meantime.

arch/ppc64/mm/tlb.c +6 -2
Index: working-2.6/arch/ppc64/mm/tlb.c
===================================================================
@@ -85,8 +85,12 @@
 
 	ptepage = virt_to_page(ptep);
 	mm = (struct mm_struct *) ptepage->mapping;
-	addr = ptepage->index +
-		(((unsigned long)ptep & ~PAGE_MASK) * PTRS_PER_PTE);
+	addr = ptepage->index;
+	if (pte_huge(pte))
+		addr +=  ((unsigned long)ptep & ~PAGE_MASK)
+			/ sizeof(*ptep) * HPAGE_SIZE;
+	else
+		addr += ((unsigned long)ptep & ~PAGE_MASK) * PTRS_PER_PTE;
 
 	if (REGION_ID(addr) == USER_REGION_ID)
 		context = mm->context.id;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist.  NOT _the_ _other_ _way_
				| _around_!
http://www.ozlabs.org/people/dgibson
#1 lore raw
Quoted 11 lines · David Gibson

Andrew, Linus, please apply:
Fix a potentially bad (although very rarely triggered) bug in the ppc64 hugepage code. hpte_update() did not correctly calculate the address for hugepages, so pte_clear() (which we use for hugepage ptes as well as normal ones) would not correctly flush the hash page table entry. Under the right circumstances this could potentially lead to duplicate hash entries, which is very bad.
davem's upcoming patch to pass the virtual address directly to set_pte() and its ilk will obsolete this, but this is bad enough it should probably be fixed in the meantime.

Very clear explanation. I second the motion for a rapid merge.