On 5/6/26 2:36 PM, Sayali Patil wrote:
A kernel panic is observed when handling machine check exceptions from
real mode.

   BUG: Unable to handle kernel data access on read at 0xc00000006be21300
   Oops: Kernel access of bad area, sig: 11 [#1]
   NIP [c000000000029e40] arch_irq_work_raise+0x10/0x70
   LR [c00000000003ffc8] machine_check_queue_event+0xa8/0x150
   Call Trace:
   [c0000000179d3c70] [c00000000003ff64] machine_check_queue_event+0x44/0x150
   [c0000000179d3d30] [c0000000000084e0] machine_check_early_common+0x1f0/0x2c0

The crash occurs because arch_irq_work_raise() calls preempt_disable()
from machine check exception (MCE) handlers running in real mode. In
this context, accessing the preempt_count can fault, leading to the panic.

The preempt_disable()/preempt_enable() pair in arch_irq_work_raise()
was originally added by commit 0fe1ac48bef0 ("powerpc/perf_event: Fix
oops due to perf_event_do_pending call") to avoid races while raising
irq work from exception context.

Later, commit 471ba0e686cb ("irq_work: Do not raise an IPI when
queueing work on the local CPU") added preemption protection in
irq_work_queue() path, while commit 20b876918c06 ("irq_work: Use per
cpu atomics instead of regular atomics") added equivalent
protection in irq_work_queue_on() before reaching arch_irq_work_raise():

   irq_work_queue() / irq_work_queue_on()
     -> preempt_disable()
       -> __irq_work_queue_local()
         -> irq_work_raise()
           -> arch_irq_work_raise()

As a result, callers other than mce_irq_work_raise() already execute
with preemption disabled, making the additional
preempt_disable()/preempt_enable() pair in arch_irq_work_raise()
redundant.

Remove it to avoid accessing preempt_count from real mode context.

I assume interrupt is disabled here. So it should be functionally safe
to remove it.


Fixes: cc15ff327569 ("powerpc/mce: Avoid using irq_work_queue() in realmode")
Suggested-by: Mahesh Salgaonkar <[email protected]>
Signed-off-by: Sayali Patil <[email protected]>
---
  arch/powerpc/kernel/time.c | 2 --
  1 file changed, 2 deletions(-)

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 4bbeb8644d3d..a99eb43f6ce9 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -471,10 +471,8 @@ void arch_irq_work_raise(void)

Could you please add a comment for the function that it expects to
be called with preemption_disabled?

         * which could get tangled up if we're messing with the same state
         * here.
         */
-       preempt_disable();
        set_irq_work_pending_flag();
        set_dec(1);
-       preempt_enable();
  }
static void set_dec_or_work(u64 val)

Acked-by: Shrikanth Hegde <[email protected]>

Reply via email to