powerpc: Skip emulating & leave interrupts off for kernel program checks
authorMichael Ellerman <michael@ellerman.id.au>
Thu, 15 Aug 2013 05:22:19 +0000 (15:22 +1000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Tue, 27 Aug 2013 04:45:09 +0000 (14:45 +1000)
In the program check handler we handle some causes with interrupts off
and others with interrupts on.

We need to enable interrupts to handle the emulation cases, because they
access userspace memory and might sleep.

For faults in the kernel we don't want to do any emulation, and
emulate_instruction() enforces that. do_mathemu() doesn't but probably
should.

The other disadvantage of enabling interrupts for kernel faults is that
we may take another interrupt, and recurse. As seen below:

  --- Exception: e40 at c000000000004ee0 performance_monitor_relon_pSeries_1
  [link register   ] c00000000000f858 .arch_local_irq_restore+0x38/0x90
  [c000000fb185dc100000000000000000 (unreliable)
  [c000000fb185dc80c0000000007d8558 .program_check_exception+0x298/0x2d0
  [c000000fb185dd00c000000000002f40 emulation_assist_common+0x140/0x180
  --- Exception: e40 at c000000000004ee0 performance_monitor_relon_pSeries_1
  [link register   ] c00000000000f858 .arch_local_irq_restore+0x38/0x90
  [c000000fb185dff000000000008b9190 (unreliable)
  [c000000fb185e060c0000000007d8558 .program_check_exception+0x298/0x2d0

So avoid both problems by checking if the fault was in the kernel and
skipping the enable of interrupts and the emulation. Go straight to
delivering the SIGILL, which for kernel faults calls die() and so on,
dropping us in the debugger etc.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/kernel/traps.c

index bdf2dd14159882c4cd299d7286314bf8df902d5d..77a7581dcb1c7d0fa01732478c13cbeab7405a93 100644 (file)
@@ -1151,6 +1151,16 @@ void __kprobes program_check_exception(struct pt_regs *regs)
        }
 #endif
 
+       /*
+        * If we took the program check in the kernel skip down to sending a
+        * SIGILL. The subsequent cases all relate to emulating instructions
+        * which we should only do for userspace. We also do not want to enable
+        * interrupts for kernel faults because that might lead to further
+        * faults, and loose the context of the original exception.
+        */
+       if (!user_mode(regs))
+               goto sigill;
+
        /* We restore the interrupt state now */
        if (!arch_irq_disabled_regs(regs))
                local_irq_enable();
@@ -1179,6 +1189,7 @@ void __kprobes program_check_exception(struct pt_regs *regs)
                }
        }
 
+sigill:
        if (reason & REASON_PRIVILEGED)
                _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
        else