Skip to content

Commit 5567b1e

Browse files
npigginmpe
authored andcommitted
powerpc/64s: fix hash page fault interrupt handler
The early bad fault or key fault test in do_hash_fault() ends up calling into ___do_page_fault without having gone through an interrupt handler wrapper (except the initial _RAW one). This can end up calling local irq functions while the interrupt has not been reconciled, which will likely cause crashes and it trips up on a later patch that adds more assertions. pkey_exec_prot from selftests causes this path to be executed. There is no real reason to run the in_nmi() test should be performed before the key fault check. In fact if a perf interrupt in the hash fault code did a stack walk that was made to take a key fault somehow then running ___do_page_fault could possibly cause another hash fault causing problems. Move the in_nmi() test first, and then do everything else inside the regular interrupt handler function. Fixes: 3a96570 ("powerpc: convert interrupt handlers to use wrappers") Reported-by: Sachin Sant <[email protected]> Signed-off-by: Nicholas Piggin <[email protected]> Tested-by: Sachin Sant <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fc49998 commit 5567b1e

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

arch/powerpc/mm/book3s64/hash_utils.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,8 +1522,8 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap,
15221522
}
15231523
EXPORT_SYMBOL_GPL(hash_page);
15241524

1525-
DECLARE_INTERRUPT_HANDLER_RET(__do_hash_fault);
1526-
DEFINE_INTERRUPT_HANDLER_RET(__do_hash_fault)
1525+
DECLARE_INTERRUPT_HANDLER(__do_hash_fault);
1526+
DEFINE_INTERRUPT_HANDLER(__do_hash_fault)
15271527
{
15281528
unsigned long ea = regs->dar;
15291529
unsigned long dsisr = regs->dsisr;
@@ -1533,6 +1533,11 @@ DEFINE_INTERRUPT_HANDLER_RET(__do_hash_fault)
15331533
unsigned int region_id;
15341534
long err;
15351535

1536+
if (unlikely(dsisr & (DSISR_BAD_FAULT_64S | DSISR_KEYFAULT))) {
1537+
hash__do_page_fault(regs);
1538+
return;
1539+
}
1540+
15361541
region_id = get_region_id(ea);
15371542
if ((region_id == VMALLOC_REGION_ID) || (region_id == IO_REGION_ID))
15381543
mm = &init_mm;
@@ -1571,9 +1576,10 @@ DEFINE_INTERRUPT_HANDLER_RET(__do_hash_fault)
15711576
bad_page_fault(regs, SIGBUS);
15721577
}
15731578
err = 0;
1574-
}
15751579

1576-
return err;
1580+
} else if (err) {
1581+
hash__do_page_fault(regs);
1582+
}
15771583
}
15781584

15791585
/*
@@ -1582,13 +1588,6 @@ DEFINE_INTERRUPT_HANDLER_RET(__do_hash_fault)
15821588
*/
15831589
DEFINE_INTERRUPT_HANDLER_RAW(do_hash_fault)
15841590
{
1585-
unsigned long dsisr = regs->dsisr;
1586-
1587-
if (unlikely(dsisr & (DSISR_BAD_FAULT_64S | DSISR_KEYFAULT))) {
1588-
hash__do_page_fault(regs);
1589-
return 0;
1590-
}
1591-
15921591
/*
15931592
* If we are in an "NMI" (e.g., an interrupt when soft-disabled), then
15941593
* don't call hash_page, just fail the fault. This is required to
@@ -1607,8 +1606,7 @@ DEFINE_INTERRUPT_HANDLER_RAW(do_hash_fault)
16071606
return 0;
16081607
}
16091608

1610-
if (__do_hash_fault(regs))
1611-
hash__do_page_fault(regs);
1609+
__do_hash_fault(regs);
16121610

16131611
return 0;
16141612
}

0 commit comments

Comments
 (0)