Skip to content

Commit fd3f1e0

Browse files
npigginmpe
authored andcommitted
powerpc/traps: factor common code from program check and emulation assist
Move the program check handling into a function called by both, rather than have the emulation assist handler call the program check handler. This allows each of these handlers to be implemented with "interrupt wrappers" in a later change. Signed-off-by: Nicholas Piggin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 25b7e6b commit fd3f1e0

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

arch/powerpc/kernel/traps.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,9 +1462,8 @@ static int emulate_math(struct pt_regs *regs)
14621462
static inline int emulate_math(struct pt_regs *regs) { return -1; }
14631463
#endif
14641464

1465-
void program_check_exception(struct pt_regs *regs)
1465+
static void do_program_check(struct pt_regs *regs)
14661466
{
1467-
enum ctx_state prev_state = exception_enter();
14681467
unsigned int reason = get_reason(regs);
14691468

14701469
/* We can now get here via a FP Unavailable exception if the core
@@ -1473,22 +1472,22 @@ void program_check_exception(struct pt_regs *regs)
14731472
if (reason & REASON_FP) {
14741473
/* IEEE FP exception */
14751474
parse_fpe(regs);
1476-
goto bail;
1475+
return;
14771476
}
14781477
if (reason & REASON_TRAP) {
14791478
unsigned long bugaddr;
14801479
/* Debugger is first in line to stop recursive faults in
14811480
* rcu_lock, notify_die, or atomic_notifier_call_chain */
14821481
if (debugger_bpt(regs))
1483-
goto bail;
1482+
return;
14841483

14851484
if (kprobe_handler(regs))
1486-
goto bail;
1485+
return;
14871486

14881487
/* trap exception */
14891488
if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
14901489
== NOTIFY_STOP)
1491-
goto bail;
1490+
return;
14921491

14931492
bugaddr = regs->nip;
14941493
/*
@@ -1500,10 +1499,10 @@ void program_check_exception(struct pt_regs *regs)
15001499
if (!(regs->msr & MSR_PR) && /* not user-mode */
15011500
report_bug(bugaddr, regs) == BUG_TRAP_TYPE_WARN) {
15021501
regs->nip += 4;
1503-
goto bail;
1502+
return;
15041503
}
15051504
_exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
1506-
goto bail;
1505+
return;
15071506
}
15081507
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
15091508
if (reason & REASON_TM) {
@@ -1524,7 +1523,7 @@ void program_check_exception(struct pt_regs *regs)
15241523
*/
15251524
if (user_mode(regs)) {
15261525
_exception(SIGILL, regs, ILL_ILLOPN, regs->nip);
1527-
goto bail;
1526+
return;
15281527
} else {
15291528
printk(KERN_EMERG "Unexpected TM Bad Thing exception "
15301529
"at %lx (msr 0x%lx) tm_scratch=%llx\n",
@@ -1557,18 +1556,18 @@ void program_check_exception(struct pt_regs *regs)
15571556
* pattern to occurrences etc. -dgibson 31/Mar/2003
15581557
*/
15591558
if (!emulate_math(regs))
1560-
goto bail;
1559+
return;
15611560

15621561
/* Try to emulate it if we should. */
15631562
if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) {
15641563
switch (emulate_instruction(regs)) {
15651564
case 0:
15661565
regs->nip += 4;
15671566
emulate_single_step(regs);
1568-
goto bail;
1567+
return;
15691568
case -EFAULT:
15701569
_exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
1571-
goto bail;
1570+
return;
15721571
}
15731572
}
15741573

@@ -1578,7 +1577,14 @@ void program_check_exception(struct pt_regs *regs)
15781577
else
15791578
_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
15801579

1581-
bail:
1580+
}
1581+
1582+
void program_check_exception(struct pt_regs *regs)
1583+
{
1584+
enum ctx_state prev_state = exception_enter();
1585+
1586+
do_program_check(regs);
1587+
15821588
exception_exit(prev_state);
15831589
}
15841590
NOKPROBE_SYMBOL(program_check_exception);
@@ -1589,8 +1595,12 @@ NOKPROBE_SYMBOL(program_check_exception);
15891595
*/
15901596
void emulation_assist_interrupt(struct pt_regs *regs)
15911597
{
1598+
enum ctx_state prev_state = exception_enter();
1599+
15921600
regs->msr |= REASON_ILLEGAL;
1593-
program_check_exception(regs);
1601+
do_program_check(regs);
1602+
1603+
exception_exit(prev_state);
15941604
}
15951605
NOKPROBE_SYMBOL(emulation_assist_interrupt);
15961606

0 commit comments

Comments
 (0)