Skip to contentSkip to conversation

powerpc/mm/mce: Keep irq disabled during lockless page table walk

RFC PATCH Applied Aneesh Kumar K.V 2 participants 2 messages Sep 18, 2019 – Sep 20, 2019 PowerPC

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 powerpc/mm/mce: Keep irq disabled during lockless page table walk

__find_linux_mm_pte return a page table entry pointer walking the page table without holding locks. To make it safe against a THP split and collapse, we disable interrupts around the lockless page table walk. We need to keep the interrupts disabled as long as we use the page table entry pointer.

Cc Balbir Singh <[email protected]>
Cc Reza Arbab <[email protected]>
Cc Santosh Sivaraj <[email protected]>
Fixes ba41e1e1ccb9 ("powerpc/mce: Hookup derror (load/store) UE errors")
---
 arch/powerpc/kernel/mce_power.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
arch/powerpc/kernel/mce_power.c +11 -7
index 356e7b99f661..585c37dc1b18 100644
@@ -28,6 +28,7 @@
 unsigned long addr_to_pfn(struct pt_regs *regs, unsigned long addr)
 {
 	pte_t *ptep;
+	unsigned long pfn;
 	unsigned int shift;
 	unsigned long flags;
 	struct mm_struct *mm;
@@ -39,18 +40,21 @@ unsigned long addr_to_pfn(struct pt_regs *regs, unsigned long addr)
 
 	local_irq_save(flags);
 	ptep = __find_linux_pte(mm->pgd, addr, NULL, &shift);
-	local_irq_restore(flags);
 
-	if (!ptep || pte_special(*ptep))
-		return ULONG_MAX;
+	if (!ptep || pte_special(*ptep)) {
+		pfn = ULONG_MAX;
+		goto err_out;
+	}
 
 	if (shift > PAGE_SHIFT) {
 		unsigned long rpnmask = (1ul << shift) - PAGE_SIZE;
 
-		return pte_pfn(__pte(pte_val(*ptep) | (addr & rpnmask)));
-	}
-
-	return pte_pfn(*ptep);
+		pfn = pte_pfn(__pte(pte_val(*ptep) | (addr & rpnmask)));
+	} else
+		pfn = pte_pfn(*ptep);
+err_out:
+	local_irq_restore(flags);
+	return pfn;
 }
 
 /* flush SLBs and reload */
Signature · 1 line
2.21.0
#1 lore raw
Quoted 11 lines · Aneesh Kumar K.V

__find_linux_mm_pte return a page table entry pointer walking the page table without holding locks. To make it safe against a THP split and collapse, we disable interrupts around the lockless page table walk. We need to keep the interrupts disabled as long as we use the page table entry pointer.

Cc Balbir Singh <[email protected]>
Cc Reza Arbab <[email protected]>
Cc Santosh Sivaraj <[email protected]>
Fixes ba41e1e1ccb9 ("powerpc/mce: Hookup derror (load/store) UE errors")

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/d9101bfa6adc831bda8836c4d774820553c14942

cheers