* [PATCHv3 1/4] powerpc/64: Leave lockdep hardirq context around replayed interrupts [not found] <cover.1795441238.git.ritesh.list@gmail.com> @ 2026-11-23 13:51 ` Ritesh Harjani (IBM) 2026-11-25 5:19 ` Mukesh Kumar Chaurasiya 2026-11-23 13:51 ` [PATCHv3 2/4] powerpc/watchdog: Disable preemption in arch_touch_nmi_watchdog() Ritesh Harjani (IBM) ` (2 subsequent siblings) 3 siblings, 1 reply; 12+ messages in thread From: Ritesh Harjani (IBM) @ 2026-11-23 13:51 UTC (permalink / raw) To: linuxppc-dev Cc: Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy, Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, Mukesh Kumar Chaurasiya, Ritesh Harjani (IBM), stable With PROVE_LOCKING, boot warns once and lockdep turns itself off: DEBUG_LOCKS_WARN_ON(lockdep_hardirq_context()) WARNING: kernel/locking/lockdep.c:4448 at lockdep_hardirqs_on_prepare+0x22c/0x2d4, CPU#0: swapper/0/0 CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 7.4.0-rc2-00027-g074831f06e18-dirty #123 PREEMPT NIP: c0000000002b2f2c LR: c0000000002b2f28 CTR: c000000002426f90 REGS: c000000004f075c0 TRAP: 0700 Not tainted (7.4.0-rc2-00027-g074831f06e18-dirty) MSR: 8000000002021033 <SF,VEC,ME,IR,DR,RI,LE> CR: 48022221 XER: 20040000 NIP [c0000000002b2f2c] lockdep_hardirqs_on_prepare+0x22c/0x2d4 LR [c0000000002b2f28] lockdep_hardirqs_on_prepare+0x228/0x2d4 Call Trace: lockdep_hardirqs_on_prepare+0x228/0x2d4 (unreliable) trace_hardirqs_on+0x98/0x11c irqentry_exit+0x64c/0x1064 timer_interrupt+0x274/0x6bc __replay_soft_interrupts+0x158/0x380 arch_local_irq_restore+0x1cc/0x244 console_flush_one_record+0x438/0x654 console_unlock+0xb8/0x1e0 vprintk_emit+0x300/0x56c vprintk+0x20/0x34 _printk+0x40/0x54 lockdep_init+0xdc/0x104 The warning is triggered because trace_hardirqs_on() gets called while lockdep's hardirq_context still says we are handling an interrupt. To fix that, we need to ensure lockdep's hardirq_context and hardirqs_enabled state stays consistent with powerpc's soft-masked interrupt replay code and the generic entry/exit code. With the current change, this is how the new state machine looks like: hardirq_context hardirqs_enabled arch_local_irq_restore() trace_hardirqs_off() 0 1 -> 0 irq_enter() 0 -> 1 0 (softirqs held off) __replay_soft_interrupts() lockdep_hardirq_exit() 1 -> 0 0 patch: the loop is not a handler timer_interrupt(®s) irq_enter_rcu() 0 -> 1 0 handler starts irq_exit_rcu() 1 -> 0 0 handler done irqentry_exit() trace_hardirqs_on() 0 0 -> 1 legal: context is 0 next_interrupt() trace_hardirqs_off() 0 1 -> 0 still replaying: back to off ... same for each pending interrupt lockdep_hardirq_enter() 0 -> 1 0 patch: restore for the caller irq_exit() 1 -> 0 0 softirqs may run now trace_hardirqs_on() 0 0 -> 1 IRQs really enabled Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature") Cc: stable@vger.kernel.org Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> --- arch/powerpc/kernel/irq_64.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/kernel/irq_64.c b/arch/powerpc/kernel/irq_64.c index d5c48d1b0a31..e2f1e5b7a3a7 100644 --- a/arch/powerpc/kernel/irq_64.c +++ b/arch/powerpc/kernel/irq_64.c @@ -76,13 +76,11 @@ static inline void next_interrupt(struct pt_regs *regs) } /* - * We are responding to the next interrupt, so interrupt-off - * latencies should be reset here. + * We are responding to the next interrupt. The irqentry_exit() of the + * replayed handler has traced hardirqs on, which also reset the + * interrupt-off latencies. Trace them off again. */ - lockdep_hardirq_exit(); - trace_hardirqs_on(); trace_hardirqs_off(); - lockdep_hardirq_enter(); } static inline bool irq_happened_test_and_clear(u8 irq) @@ -116,6 +114,15 @@ static __no_kcsan void __replay_soft_interrupts(void) */ local_paca->irq_happened |= PACA_IRQ_REPLAYING; + /* + * The irq_enter() of our callers is there to hold off softirqs. Each + * replayed handler enters and leaves the hardirq context itself and + * returns through irqentry_exit(), which again traces hardirqs on. + * Since lockdep only allows that outside of hardirq context, so leave + * it for the duration of the replay. + */ + lockdep_hardirq_exit(); + ppc_save_regs(®s); regs.softe = IRQS_ENABLED; regs.msr |= MSR_EE; @@ -168,6 +175,8 @@ static __no_kcsan void __replay_soft_interrupts(void) next_interrupt(®s); } + lockdep_hardirq_enter(); + local_paca->irq_happened &= ~PACA_IRQ_REPLAYING; } -- 2.39.5 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCHv3 1/4] powerpc/64: Leave lockdep hardirq context around replayed interrupts 2026-11-23 13:51 ` [PATCHv3 1/4] powerpc/64: Leave lockdep hardirq context around replayed interrupts Ritesh Harjani (IBM) @ 2026-11-25 5:19 ` Mukesh Kumar Chaurasiya 0 siblings, 0 replies; 12+ messages in thread From: Mukesh Kumar Chaurasiya @ 2026-11-25 5:19 UTC (permalink / raw) To: Ritesh Harjani (IBM) Cc: linuxppc-dev, Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy, Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, stable On Mon, Nov 23, 2026 at 07:21:50PM +0530, Ritesh Harjani (IBM) wrote: > With PROVE_LOCKING, boot warns once and lockdep turns itself off: > DEBUG_LOCKS_WARN_ON(lockdep_hardirq_context()) > WARNING: kernel/locking/lockdep.c:4448 at lockdep_hardirqs_on_prepare+0x22c/0x2d4, CPU#0: swapper/0/0 > CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 7.4.0-rc2-00027-g074831f06e18-dirty #123 PREEMPT > NIP: c0000000002b2f2c LR: c0000000002b2f28 CTR: c000000002426f90 > REGS: c000000004f075c0 TRAP: 0700 Not tainted (7.4.0-rc2-00027-g074831f06e18-dirty) > MSR: 8000000002021033 <SF,VEC,ME,IR,DR,RI,LE> CR: 48022221 XER: 20040000 > NIP [c0000000002b2f2c] lockdep_hardirqs_on_prepare+0x22c/0x2d4 > LR [c0000000002b2f28] lockdep_hardirqs_on_prepare+0x228/0x2d4 > Call Trace: > lockdep_hardirqs_on_prepare+0x228/0x2d4 (unreliable) > trace_hardirqs_on+0x98/0x11c > irqentry_exit+0x64c/0x1064 > timer_interrupt+0x274/0x6bc > __replay_soft_interrupts+0x158/0x380 > arch_local_irq_restore+0x1cc/0x244 > console_flush_one_record+0x438/0x654 > console_unlock+0xb8/0x1e0 > vprintk_emit+0x300/0x56c > vprintk+0x20/0x34 > _printk+0x40/0x54 > lockdep_init+0xdc/0x104 > > The warning is triggered because trace_hardirqs_on() gets called while > lockdep's hardirq_context still says we are handling an interrupt. To > fix that, we need to ensure lockdep's hardirq_context and > hardirqs_enabled state stays consistent with powerpc's soft-masked > interrupt replay code and the generic entry/exit code. > > With the current change, this is how the new state machine looks like: > hardirq_context hardirqs_enabled > arch_local_irq_restore() > trace_hardirqs_off() 0 1 -> 0 > irq_enter() 0 -> 1 0 (softirqs held off) > __replay_soft_interrupts() > lockdep_hardirq_exit() 1 -> 0 0 patch: the loop is not a handler Yeah this makes sense to have it here. > timer_interrupt(®s) > irq_enter_rcu() 0 -> 1 0 handler starts > irq_exit_rcu() 1 -> 0 0 handler done > irqentry_exit() > trace_hardirqs_on() 0 0 -> 1 legal: context is 0 > next_interrupt() > trace_hardirqs_off() 0 1 -> 0 still replaying: back to off > ... same for each pending interrupt > lockdep_hardirq_enter() 0 -> 1 0 patch: restore for the caller > irq_exit() 1 -> 0 0 softirqs may run now > trace_hardirqs_on() 0 0 -> 1 IRQs really enabled > > Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature") > Cc: stable@vger.kernel.org > Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> > --- > arch/powerpc/kernel/irq_64.c | 19 ++++++++++++++----- > 1 file changed, 14 insertions(+), 5 deletions(-) > > diff --git a/arch/powerpc/kernel/irq_64.c b/arch/powerpc/kernel/irq_64.c > index d5c48d1b0a31..e2f1e5b7a3a7 100644 > --- a/arch/powerpc/kernel/irq_64.c > +++ b/arch/powerpc/kernel/irq_64.c > @@ -76,13 +76,11 @@ static inline void next_interrupt(struct pt_regs *regs) > } > > /* > - * We are responding to the next interrupt, so interrupt-off > - * latencies should be reset here. > + * We are responding to the next interrupt. The irqentry_exit() of the > + * replayed handler has traced hardirqs on, which also reset the > + * interrupt-off latencies. Trace them off again. > */ > - lockdep_hardirq_exit(); > - trace_hardirqs_on(); > trace_hardirqs_off(); > - lockdep_hardirq_enter(); > } > > static inline bool irq_happened_test_and_clear(u8 irq) > @@ -116,6 +114,15 @@ static __no_kcsan void __replay_soft_interrupts(void) > */ > local_paca->irq_happened |= PACA_IRQ_REPLAYING; > > + /* > + * The irq_enter() of our callers is there to hold off softirqs. Each > + * replayed handler enters and leaves the hardirq context itself and > + * returns through irqentry_exit(), which again traces hardirqs on. > + * Since lockdep only allows that outside of hardirq context, so leave > + * it for the duration of the replay. > + */ > + lockdep_hardirq_exit(); > + > ppc_save_regs(®s); > regs.softe = IRQS_ENABLED; > regs.msr |= MSR_EE; > @@ -168,6 +175,8 @@ static __no_kcsan void __replay_soft_interrupts(void) > next_interrupt(®s); > } > > + lockdep_hardirq_enter(); > + > local_paca->irq_happened &= ~PACA_IRQ_REPLAYING; > } > > -- > 2.39.5 > LGTM Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com> ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCHv3 2/4] powerpc/watchdog: Disable preemption in arch_touch_nmi_watchdog() [not found] <cover.1795441238.git.ritesh.list@gmail.com> 2026-11-23 13:51 ` [PATCHv3 1/4] powerpc/64: Leave lockdep hardirq context around replayed interrupts Ritesh Harjani (IBM) @ 2026-11-23 13:51 ` Ritesh Harjani (IBM) 2026-11-25 5:50 ` Mukesh Kumar Chaurasiya 2026-11-23 13:51 ` [PATCHv3 3/4] powerpc/kvm-hv-pmu: Don't allocate gsm/gsb GFP_KERNEL allocations under spinlock Ritesh Harjani (IBM) 2026-11-23 13:51 ` [PATCHv3 4/4] powerpc/kvm-hv-pmu: Free hostwide stats buffers if perf_pmu_register() fails Ritesh Harjani (IBM) 3 siblings, 1 reply; 12+ messages in thread From: Ritesh Harjani (IBM) @ 2026-11-23 13:51 UTC (permalink / raw) To: linuxppc-dev Cc: Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy, Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, Mukesh Kumar Chaurasiya, Ritesh Harjani (IBM), stable touch_nmi_watchdog() can be called from preemptible context, e.g. sysrq-w via /proc/sysrq-trigger. The powerpc implementation uses smp_processor_id(), so with DEBUG_PREEMPT we get: root@buildroot:/# echo w > /proc/sysrq-trigger sysrq: Show Blocked State BUG: using smp_processor_id() in preemptible [00000000] code: bash/238 caller is arch_touch_nmi_watchdog+0x3c/0xd4 CPU: 0 UID: 0 PID: 238 Comm: bash Not tainted 7.4.0-rc2-00029-g7664547149ae-dirty #126 PREEMPT Call Trace: dump_stack_lvl+0x138/0x150 (unreliable) check_preemption_disabled+0x120/0x158 arch_touch_nmi_watchdog+0x3c/0xd4 show_state_filter+0xf0/0x338 sysrq_handle_showstate_blocked+0x24/0x38 __handle_sysrq+0x134/0x3a8 write_sysrq_trigger+0x178/0x22c proc_reg_write+0xf4/0x150 vfs_write+0xfc/0x71c ksys_write+0x8c/0x150 system_call_exception+0x310/0x590 system_call_vectored_common+0x15c/0x2ec ---- interrupt: 3000 at 0x7ffd01755b98 Unlike the generic version, which only sets a flag, we update the CPU's timebase stamp and its SMP watchdog pending bit, so a migration in between touches the state of a CPU we are no longer on. Disable preemption across the update. While at it, let's also mark the function as notrace (since we might be within a tracer when this function gets called). Fixes: 2104180a5369 ("powerpc/64s: implement arch-specific hardlockup watchdog") Cc: stable@vger.kernel.org Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> --- arch/powerpc/kernel/watchdog.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c index 44f178e07531..32d4e716cb0a 100644 --- a/arch/powerpc/kernel/watchdog.c +++ b/arch/powerpc/kernel/watchdog.c @@ -456,12 +456,16 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) return HRTIMER_RESTART; } -void arch_touch_nmi_watchdog(void) +notrace void arch_touch_nmi_watchdog(void) { unsigned long ticks = tb_ticks_per_usec * wd_timer_period_ms * 1000; - int cpu = smp_processor_id(); + int cpu; u64 tb; + /* Callers may be preemptible. Stay on this CPU for the update. */ + guard(preempt_notrace)(); + cpu = raw_smp_processor_id(); + if (!cpumask_test_cpu(cpu, &watchdog_cpumask)) return; -- 2.39.5 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCHv3 2/4] powerpc/watchdog: Disable preemption in arch_touch_nmi_watchdog() 2026-11-23 13:51 ` [PATCHv3 2/4] powerpc/watchdog: Disable preemption in arch_touch_nmi_watchdog() Ritesh Harjani (IBM) @ 2026-11-25 5:50 ` Mukesh Kumar Chaurasiya 2026-11-25 9:58 ` Ritesh Harjani 0 siblings, 1 reply; 12+ messages in thread From: Mukesh Kumar Chaurasiya @ 2026-11-25 5:50 UTC (permalink / raw) To: Ritesh Harjani (IBM) Cc: linuxppc-dev, Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy, Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, stable On Mon, Nov 23, 2026 at 07:21:51PM +0530, Ritesh Harjani (IBM) wrote: > touch_nmi_watchdog() can be called from preemptible context, e.g. > sysrq-w via /proc/sysrq-trigger. The powerpc implementation uses > smp_processor_id(), so with DEBUG_PREEMPT we get: > > root@buildroot:/# echo w > /proc/sysrq-trigger > sysrq: Show Blocked State > BUG: using smp_processor_id() in preemptible [00000000] code: bash/238 > caller is arch_touch_nmi_watchdog+0x3c/0xd4 > CPU: 0 UID: 0 PID: 238 Comm: bash Not tainted 7.4.0-rc2-00029-g7664547149ae-dirty #126 PREEMPT > Call Trace: > dump_stack_lvl+0x138/0x150 (unreliable) > check_preemption_disabled+0x120/0x158 > arch_touch_nmi_watchdog+0x3c/0xd4 > show_state_filter+0xf0/0x338 > sysrq_handle_showstate_blocked+0x24/0x38 > __handle_sysrq+0x134/0x3a8 > write_sysrq_trigger+0x178/0x22c > proc_reg_write+0xf4/0x150 > vfs_write+0xfc/0x71c > ksys_write+0x8c/0x150 > system_call_exception+0x310/0x590 > system_call_vectored_common+0x15c/0x2ec > ---- interrupt: 3000 at 0x7ffd01755b98 > > Unlike the generic version, which only sets a flag, we update the CPU's > timebase stamp and its SMP watchdog pending bit, so a migration in > between touches the state of a CPU we are no longer on. > > Disable preemption across the update. While at it, let's also mark the > function as notrace (since we might be within a tracer when this > function gets called). Do we need to also mark wd_smp_clear_cpu_pending as notrace? Regards, Mukesh > Fixes: 2104180a5369 ("powerpc/64s: implement arch-specific hardlockup watchdog") > Cc: stable@vger.kernel.org > Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com> > Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> > --- > arch/powerpc/kernel/watchdog.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c > index 44f178e07531..32d4e716cb0a 100644 > --- a/arch/powerpc/kernel/watchdog.c > +++ b/arch/powerpc/kernel/watchdog.c > @@ -456,12 +456,16 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) > return HRTIMER_RESTART; > } > > -void arch_touch_nmi_watchdog(void) > +notrace void arch_touch_nmi_watchdog(void) > { > unsigned long ticks = tb_ticks_per_usec * wd_timer_period_ms * 1000; > - int cpu = smp_processor_id(); > + int cpu; > u64 tb; > > + /* Callers may be preemptible. Stay on this CPU for the update. */ > + guard(preempt_notrace)(); > + cpu = raw_smp_processor_id(); > + > if (!cpumask_test_cpu(cpu, &watchdog_cpumask)) > return; > > -- > 2.39.5 > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCHv3 2/4] powerpc/watchdog: Disable preemption in arch_touch_nmi_watchdog() 2026-11-25 5:50 ` Mukesh Kumar Chaurasiya @ 2026-11-25 9:58 ` Ritesh Harjani 2026-11-26 10:13 ` Christophe Leroy (CS GROUP) 0 siblings, 1 reply; 12+ messages in thread From: Ritesh Harjani @ 2026-11-25 9:58 UTC (permalink / raw) To: Mukesh Kumar Chaurasiya Cc: linuxppc-dev, Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy, Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, stable Mukesh Kumar Chaurasiya <mkchauras@gmail.com> writes: > On Mon, Nov 23, 2026 at 07:21:51PM +0530, Ritesh Harjani (IBM) wrote: >> touch_nmi_watchdog() can be called from preemptible context, e.g. >> sysrq-w via /proc/sysrq-trigger. The powerpc implementation uses >> smp_processor_id(), so with DEBUG_PREEMPT we get: >> >> root@buildroot:/# echo w > /proc/sysrq-trigger >> sysrq: Show Blocked State >> BUG: using smp_processor_id() in preemptible [00000000] code: bash/238 >> caller is arch_touch_nmi_watchdog+0x3c/0xd4 >> CPU: 0 UID: 0 PID: 238 Comm: bash Not tainted 7.4.0-rc2-00029-g7664547149ae-dirty #126 PREEMPT >> Call Trace: >> dump_stack_lvl+0x138/0x150 (unreliable) >> check_preemption_disabled+0x120/0x158 >> arch_touch_nmi_watchdog+0x3c/0xd4 >> show_state_filter+0xf0/0x338 >> sysrq_handle_showstate_blocked+0x24/0x38 >> __handle_sysrq+0x134/0x3a8 >> write_sysrq_trigger+0x178/0x22c >> proc_reg_write+0xf4/0x150 >> vfs_write+0xfc/0x71c >> ksys_write+0x8c/0x150 >> system_call_exception+0x310/0x590 >> system_call_vectored_common+0x15c/0x2ec >> ---- interrupt: 3000 at 0x7ffd01755b98 >> >> Unlike the generic version, which only sets a flag, we update the CPU's >> timebase stamp and its SMP watchdog pending bit, so a migration in >> between touches the state of a CPU we are no longer on. >> >> Disable preemption across the update. While at it, let's also mark the >> function as notrace (since we might be within a tracer when this >> function gets called). > Do we need to also mark wd_smp_clear_cpu_pending as notrace? > aah yes, I didn't see that there is another function which is not inlined. Thanks for spotting that. The reason I added "notrace" was mainly to have consistency with kernel/watchdog.c which is due to this commit: cb9d7fd51d9f ("watchdog: Mark watchdog touch functions as notrace") However, after looking more closely now, I don't think we need notrace here at all. To simply put, on powerpc, we don't use stop_machine() from within arch_ftrace_update_code() like how arch/arm does and besides, I think it is even safe for one cpu to be executing the instruction on powerpc, while another cpu modifying that atomically. For e.g. see this - commit ee456bb346e75a9b6d941224b108250e6ee5f79f Author: Steven Rostedt <srostedt@redhat.com> Date: Thu Apr 26 08:31:17 2012 +0000 powerpc/ftrace: Have PPC skip updating with stop_machine() PowerPC does not have the synchronization issues that x86 has with modifying code on one CPU while another CPU is executing it. The other CPU will either see the old or new code without any issues, unlike x86 which may issue a GPF. Instead of calling the heavy stop_machine, just update the code. And as I see it, this problem only exists on ARM with THUMB2 instruction, as can be seen from their implementation of arch_ftrace_update_code(), which uses stop_machine(). So, let me drop the "notrace" as it is not really needed here and re-spin a v4 with it being dropped. -ritesh >> Fixes: 2104180a5369 ("powerpc/64s: implement arch-specific hardlockup watchdog") >> Cc: stable@vger.kernel.org >> Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com> >> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> >> --- >> arch/powerpc/kernel/watchdog.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c >> index 44f178e07531..32d4e716cb0a 100644 >> --- a/arch/powerpc/kernel/watchdog.c >> +++ b/arch/powerpc/kernel/watchdog.c >> @@ -456,12 +456,16 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) >> return HRTIMER_RESTART; >> } >> >> -void arch_touch_nmi_watchdog(void) >> +notrace void arch_touch_nmi_watchdog(void) >> { >> unsigned long ticks = tb_ticks_per_usec * wd_timer_period_ms * 1000; >> - int cpu = smp_processor_id(); >> + int cpu; >> u64 tb; >> >> + /* Callers may be preemptible. Stay on this CPU for the update. */ >> + guard(preempt_notrace)(); >> + cpu = raw_smp_processor_id(); >> + >> if (!cpumask_test_cpu(cpu, &watchdog_cpumask)) >> return; >> >> -- >> 2.39.5 >> ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCHv3 2/4] powerpc/watchdog: Disable preemption in arch_touch_nmi_watchdog() 2026-11-25 9:58 ` Ritesh Harjani @ 2026-11-26 10:13 ` Christophe Leroy (CS GROUP) 2026-11-26 12:36 ` Ritesh Harjani 0 siblings, 1 reply; 12+ messages in thread From: Christophe Leroy (CS GROUP) @ 2026-11-26 10:13 UTC (permalink / raw) To: Ritesh Harjani (IBM), Mukesh Kumar Chaurasiya Cc: linuxppc-dev, Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, stable Le 25/11/2026 à 10:58, Ritesh Harjani a écrit : > Mukesh Kumar Chaurasiya <mkchauras@gmail.com> writes: > >> On Mon, Nov 23, 2026 at 07:21:51PM +0530, Ritesh Harjani (IBM) wrote: >>> touch_nmi_watchdog() can be called from preemptible context, e.g. >>> sysrq-w via /proc/sysrq-trigger. The powerpc implementation uses >>> smp_processor_id(), so with DEBUG_PREEMPT we get: >>> >>> root@buildroot:/# echo w > /proc/sysrq-trigger >>> sysrq: Show Blocked State >>> BUG: using smp_processor_id() in preemptible [00000000] code: bash/238 >>> caller is arch_touch_nmi_watchdog+0x3c/0xd4 >>> CPU: 0 UID: 0 PID: 238 Comm: bash Not tainted 7.4.0-rc2-00029-g7664547149ae-dirty #126 PREEMPT >>> Call Trace: >>> dump_stack_lvl+0x138/0x150 (unreliable) >>> check_preemption_disabled+0x120/0x158 >>> arch_touch_nmi_watchdog+0x3c/0xd4 >>> show_state_filter+0xf0/0x338 >>> sysrq_handle_showstate_blocked+0x24/0x38 >>> __handle_sysrq+0x134/0x3a8 >>> write_sysrq_trigger+0x178/0x22c >>> proc_reg_write+0xf4/0x150 >>> vfs_write+0xfc/0x71c >>> ksys_write+0x8c/0x150 >>> system_call_exception+0x310/0x590 >>> system_call_vectored_common+0x15c/0x2ec >>> ---- interrupt: 3000 at 0x7ffd01755b98 >>> >>> Unlike the generic version, which only sets a flag, we update the CPU's >>> timebase stamp and its SMP watchdog pending bit, so a migration in >>> between touches the state of a CPU we are no longer on. >>> >>> Disable preemption across the update. While at it, let's also mark the >>> function as notrace (since we might be within a tracer when this >>> function gets called). >> Do we need to also mark wd_smp_clear_cpu_pending as notrace? >> > > aah yes, I didn't see that there is another function which is not > inlined. Thanks for spotting that. The reason I added "notrace" was > mainly to have consistency with kernel/watchdog.c which is due to this > commit: > > cb9d7fd51d9f ("watchdog: Mark watchdog touch functions as notrace") > > > However, after looking more closely now, I don't think we need notrace > here at all. To simply put, on powerpc, we don't use stop_machine() from > within arch_ftrace_update_code() like how arch/arm does and besides, I > think it is even safe for one cpu to be executing the instruction on > powerpc, while another cpu modifying that atomically. But haven't we identified in another discussion that it might be needed to use stop_machine() ? See https://lore.kernel.org/all/qzh06fxn.ritesh.list@gmail.com/ Christophe > > For e.g. see this - > > commit ee456bb346e75a9b6d941224b108250e6ee5f79f > Author: Steven Rostedt <srostedt@redhat.com> > Date: Thu Apr 26 08:31:17 2012 +0000 > > powerpc/ftrace: Have PPC skip updating with stop_machine() > > PowerPC does not have the synchronization issues that x86 has with > modifying code on one CPU while another CPU is executing it. > The other CPU will either see the old or new code without any > issues, unlike x86 which may issue a GPF. > > Instead of calling the heavy stop_machine, just update the code. > > > And as I see it, this problem only exists on ARM with THUMB2 > instruction, as can be seen from their implementation of > arch_ftrace_update_code(), which uses stop_machine(). > > > So, let me drop the "notrace" as it is not really needed here and > re-spin a v4 with it being dropped. > > -ritesh > >>> Fixes: 2104180a5369 ("powerpc/64s: implement arch-specific hardlockup watchdog") >>> Cc: stable@vger.kernel.org >>> Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com> >>> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> >>> --- >>> arch/powerpc/kernel/watchdog.c | 8 ++++++-- >>> 1 file changed, 6 insertions(+), 2 deletions(-) >>> >>> diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c >>> index 44f178e07531..32d4e716cb0a 100644 >>> --- a/arch/powerpc/kernel/watchdog.c >>> +++ b/arch/powerpc/kernel/watchdog.c >>> @@ -456,12 +456,16 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) >>> return HRTIMER_RESTART; >>> } >>> >>> -void arch_touch_nmi_watchdog(void) >>> +notrace void arch_touch_nmi_watchdog(void) >>> { >>> unsigned long ticks = tb_ticks_per_usec * wd_timer_period_ms * 1000; >>> - int cpu = smp_processor_id(); >>> + int cpu; >>> u64 tb; >>> >>> + /* Callers may be preemptible. Stay on this CPU for the update. */ >>> + guard(preempt_notrace)(); >>> + cpu = raw_smp_processor_id(); >>> + >>> if (!cpumask_test_cpu(cpu, &watchdog_cpumask)) >>> return; >>> >>> -- >>> 2.39.5 >>> ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCHv3 2/4] powerpc/watchdog: Disable preemption in arch_touch_nmi_watchdog() 2026-11-26 10:13 ` Christophe Leroy (CS GROUP) @ 2026-11-26 12:36 ` Ritesh Harjani 0 siblings, 0 replies; 12+ messages in thread From: Ritesh Harjani @ 2026-11-26 12:36 UTC (permalink / raw) To: Christophe Leroy (CS GROUP), Mukesh Kumar Chaurasiya Cc: linuxppc-dev, Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, stable "Christophe Leroy (CS GROUP)" <chleroy@kernel.org> writes: > Le 25/11/2026 à 10:58, Ritesh Harjani a écrit : >> Mukesh Kumar Chaurasiya <mkchauras@gmail.com> writes: >> >>> On Mon, Nov 23, 2026 at 07:21:51PM +0530, Ritesh Harjani (IBM) wrote: >>>> touch_nmi_watchdog() can be called from preemptible context, e.g. >>>> sysrq-w via /proc/sysrq-trigger. The powerpc implementation uses >>>> smp_processor_id(), so with DEBUG_PREEMPT we get: >>>> >>>> root@buildroot:/# echo w > /proc/sysrq-trigger >>>> sysrq: Show Blocked State >>>> BUG: using smp_processor_id() in preemptible [00000000] code: bash/238 >>>> caller is arch_touch_nmi_watchdog+0x3c/0xd4 >>>> CPU: 0 UID: 0 PID: 238 Comm: bash Not tainted 7.4.0-rc2-00029-g7664547149ae-dirty #126 PREEMPT >>>> Call Trace: >>>> dump_stack_lvl+0x138/0x150 (unreliable) >>>> check_preemption_disabled+0x120/0x158 >>>> arch_touch_nmi_watchdog+0x3c/0xd4 >>>> show_state_filter+0xf0/0x338 >>>> sysrq_handle_showstate_blocked+0x24/0x38 >>>> __handle_sysrq+0x134/0x3a8 >>>> write_sysrq_trigger+0x178/0x22c >>>> proc_reg_write+0xf4/0x150 >>>> vfs_write+0xfc/0x71c >>>> ksys_write+0x8c/0x150 >>>> system_call_exception+0x310/0x590 >>>> system_call_vectored_common+0x15c/0x2ec >>>> ---- interrupt: 3000 at 0x7ffd01755b98 >>>> >>>> Unlike the generic version, which only sets a flag, we update the CPU's >>>> timebase stamp and its SMP watchdog pending bit, so a migration in >>>> between touches the state of a CPU we are no longer on. >>>> >>>> Disable preemption across the update. While at it, let's also mark the >>>> function as notrace (since we might be within a tracer when this >>>> function gets called). >>> Do we need to also mark wd_smp_clear_cpu_pending as notrace? >>> >> >> aah yes, I didn't see that there is another function which is not >> inlined. Thanks for spotting that. The reason I added "notrace" was >> mainly to have consistency with kernel/watchdog.c which is due to this >> commit: >> >> cb9d7fd51d9f ("watchdog: Mark watchdog touch functions as notrace") >> >> >> However, after looking more closely now, I don't think we need notrace >> here at all. To simply put, on powerpc, we don't use stop_machine() from >> within arch_ftrace_update_code() like how arch/arm does and besides, I >> think it is even safe for one cpu to be executing the instruction on >> powerpc, while another cpu modifying that atomically. > > But haven't we identified in another discussion that it might be needed > to use stop_machine() ? See > https://lore.kernel.org/all/qzh06fxn.ritesh.list@gmail.com/ > Yes, that is why I also quoted second reason too on why we don't need it on powerpc. But here is the detailed explaination of what I understood - while looking at the history of changes on why "notrace" was added to some arch (like arm or to the generic definition) in the first place. On ARM, ftrace call sites were patched under stop_machine() and the code used to rely on other CPUs not executing any call site meanwhile. (Note that this itself is not needed on PowerPC see commit ee456bb346e7). However, with a THUMB-2 instruction set on ARM, a 4byte instruction is only 2 byte aligned, so while patching the instruction it can result into a 2 x 16bit stores. Now after commit ce4f06dcbb5d ("stop_machine: Touch_nmi_watchdog() after MULTI_STOP_PREPARE"), stopped cpus started calling the watchdog touch functions (which were not marked notrace yet) from multi_cpu_stop(), so a stopped cpu could therefore execute the ftrace call site of those functions between the two stores. This resulted into kernel crashes as seen on ARM while enabling/disabling ftrace on ARM kernels built with THUMB-2 instruction set. Therefore commit cb9d7fd51d9f ("watchdog: Mark watchdog touch functions as notrace") was needed on ARM to fix these crashes. So I still think we don't need a "notrace" on arch_touch_nmi_watchdog() on powerpc, even if tomorrow, we extend the use of stop_machine() for patching usecase, as we discussed on that other thread. Btw, we already use stop_machine() on powerpc for several usecases today like... # git grep "stop_machine" arch/powerpc/ arch/powerpc/lib/feature-fixups.c:#include <linux/stop_machine.h> arch/powerpc/lib/feature-fixups.c: * then stop_machine runs which will ensure all CPUs are out of the arch/powerpc/lib/feature-fixups.c: stop_machine(__do_stf_barrier_fixups, &types, NULL); arch/powerpc/lib/feature-fixups.c: * Note we are protected by stop_machine() from other CPUs executing the code in a arch/powerpc/lib/feature-fixups.c: stop_machine(__do_entry_flush_fixups, &types, NULL); arch/powerpc/lib/feature-fixups.c: * stop_machine gets all CPUs out of the interrupt exit handler same arch/powerpc/lib/feature-fixups.c: * without stop_machine, so this could be achieved with a broadcast arch/powerpc/lib/feature-fixups.c: stop_machine(__do_rfi_flush_fixups, &types, NULL); arch/powerpc/mm/book3s64/hash_pgtable.c:#include <linux/stop_machine.h> arch/powerpc/mm/book3s64/hash_pgtable.c: stop_machine_cpuslocked(change_memory_range_fn, &chmem_parms, arch/powerpc/mm/numa.c:#include <linux/stop_machine.h> arch/powerpc/platforms/powernv/subcore.c:#include <linux/stop_machine.h> arch/powerpc/platforms/powernv/subcore.c: stop_machine_cpuslocked(cpu_update_split_mode, &new_mode, arch/powerpc/platforms/pseries/lpar.c:#include <linux/stop_machine.h> arch/powerpc/platforms/pseries/lpar.c: rc = stop_machine_cpuslocked(pseries_lpar_resize_hpt_commit, arch/powerpc/platforms/pseries/mobility.c:#include <linux/stop_machine.h> arch/powerpc/platforms/pseries/mobility.c: ret = stop_machine(do_join, &info, cpu_online_mask); > Christophe > Thanks for the review! -ritesh >> >> For e.g. see this - >> >> commit ee456bb346e75a9b6d941224b108250e6ee5f79f >> Author: Steven Rostedt <srostedt@redhat.com> >> Date: Thu Apr 26 08:31:17 2012 +0000 >> >> powerpc/ftrace: Have PPC skip updating with stop_machine() >> >> PowerPC does not have the synchronization issues that x86 has with >> modifying code on one CPU while another CPU is executing it. >> The other CPU will either see the old or new code without any >> issues, unlike x86 which may issue a GPF. >> >> Instead of calling the heavy stop_machine, just update the code. >> >> >> And as I see it, this problem only exists on ARM with THUMB2 >> instruction, as can be seen from their implementation of >> arch_ftrace_update_code(), which uses stop_machine(). >> >> >> So, let me drop the "notrace" as it is not really needed here and >> re-spin a v4 with it being dropped. >> >> -ritesh >> >>>> Fixes: 2104180a5369 ("powerpc/64s: implement arch-specific hardlockup watchdog") >>>> Cc: stable@vger.kernel.org >>>> Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com> >>>> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> >>>> --- >>>> arch/powerpc/kernel/watchdog.c | 8 ++++++-- >>>> 1 file changed, 6 insertions(+), 2 deletions(-) >>>> >>>> diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c >>>> index 44f178e07531..32d4e716cb0a 100644 >>>> --- a/arch/powerpc/kernel/watchdog.c >>>> +++ b/arch/powerpc/kernel/watchdog.c >>>> @@ -456,12 +456,16 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) >>>> return HRTIMER_RESTART; >>>> } >>>> >>>> -void arch_touch_nmi_watchdog(void) >>>> +notrace void arch_touch_nmi_watchdog(void) >>>> { >>>> unsigned long ticks = tb_ticks_per_usec * wd_timer_period_ms * 1000; >>>> - int cpu = smp_processor_id(); >>>> + int cpu; >>>> u64 tb; >>>> >>>> + /* Callers may be preemptible. Stay on this CPU for the update. */ >>>> + guard(preempt_notrace)(); >>>> + cpu = raw_smp_processor_id(); >>>> + >>>> if (!cpumask_test_cpu(cpu, &watchdog_cpumask)) >>>> return; >>>> >>>> -- >>>> 2.39.5 >>>> ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCHv3 3/4] powerpc/kvm-hv-pmu: Don't allocate gsm/gsb GFP_KERNEL allocations under spinlock [not found] <cover.1795441238.git.ritesh.list@gmail.com> 2026-11-23 13:51 ` [PATCHv3 1/4] powerpc/64: Leave lockdep hardirq context around replayed interrupts Ritesh Harjani (IBM) 2026-11-23 13:51 ` [PATCHv3 2/4] powerpc/watchdog: Disable preemption in arch_touch_nmi_watchdog() Ritesh Harjani (IBM) @ 2026-11-23 13:51 ` Ritesh Harjani (IBM) 2026-11-25 5:53 ` Mukesh Kumar Chaurasiya 2026-11-23 13:51 ` [PATCHv3 4/4] powerpc/kvm-hv-pmu: Free hostwide stats buffers if perf_pmu_register() fails Ritesh Harjani (IBM) 3 siblings, 1 reply; 12+ messages in thread From: Ritesh Harjani (IBM) @ 2026-11-23 13:51 UTC (permalink / raw) To: linuxppc-dev Cc: Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy, Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, Mukesh Kumar Chaurasiya, Ritesh Harjani (IBM), stable kvmppc_init_hostwide() takes lock_l0_stats with spin_lock_irqsave() and then allocates the guest state message and buffer with GFP_KERNEL. On a nested API v2 host with DEBUG_ATOMIC_SLEEP this warns at boot: BUG: sleeping function called from invalid context at include/linux/sched/mm.h:322 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 1, name: swapper/0 preempt_count: 1, expected: 0 RCU nest depth: 0, expected: 0 locks held by swapper/0/1: 1, on CPU#0: #0: c000000004ad95b8 (lock_l0_stats){....}-{3:3}, at: kvmppc_register_pmu+0x50/0x270 CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.4.0-rc2-00028-ge5a8bf3a3ee9-dirty #124 PREEMPT Call Trace: dump_stack_lvl+0xe8/0x150 (unreliable) __might_resched+0x190/0x30c __kmalloc_cache_noprof+0x4dc/0x760 kvmppc_gsm_new+0x68/0xcc kvmppc_register_pmu+0xd4/0x270 do_one_initcall+0xac/0x48c kernel_init_freeable+0x3cc/0x7f0 kernel_init+0x3c/0x274 ret_from_kernel_user_thread+0x14/0x1c The lock is not needed for the allocation of gsm and gsb buffers. Allocate and fill the message and buffer without the lock and only take it to publish the two global pointers. Fixes: f0c9c49c5067 ("powerpc/kvm-hv-pmu: Implement GSB message-ops for hostwide counters") Cc: stable@vger.kernel.org Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> --- arch/powerpc/perf/kvm-hv-pmu.c | 65 ++++++++++++++++------------------ 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/arch/powerpc/perf/kvm-hv-pmu.c b/arch/powerpc/perf/kvm-hv-pmu.c index aa72b96b5a8c..a58634f656e9 100644 --- a/arch/powerpc/perf/kvm-hv-pmu.c +++ b/arch/powerpc/perf/kvm-hv-pmu.c @@ -314,53 +314,48 @@ static struct kvmppc_gs_msg_ops gsb_ops_l0_stats = { static int kvmppc_init_hostwide(void) { - int rc = 0; + struct kvmppc_gs_msg *gsm; + struct kvmppc_gs_buff *gsb; unsigned long flags; + int rc; - spin_lock_irqsave(&lock_l0_stats, flags); - - /* already registered ? */ - if (gsm_l0_stats) { - rc = 0; - goto out; - } - - /* setup the Guest state message/buffer to talk to L0 */ - gsm_l0_stats = kvmppc_gsm_new(&gsb_ops_l0_stats, &l0_stats, - GSM_SEND, GFP_KERNEL); - if (!gsm_l0_stats) { - rc = -ENOMEM; - goto out; - } + /* allocate the Guest state message/buffer to talk to L0 */ + gsm = kvmppc_gsm_new(&gsb_ops_l0_stats, &l0_stats, GSM_SEND, + GFP_KERNEL); + if (!gsm) + return -ENOMEM; /* Populate the Idents */ - kvmppc_gsm_include(gsm_l0_stats, KVMPPC_GSID_L0_GUEST_HEAP); - kvmppc_gsm_include(gsm_l0_stats, KVMPPC_GSID_L0_GUEST_HEAP_MAX); - kvmppc_gsm_include(gsm_l0_stats, KVMPPC_GSID_L0_GUEST_PGTABLE_SIZE); - kvmppc_gsm_include(gsm_l0_stats, KVMPPC_GSID_L0_GUEST_PGTABLE_SIZE_MAX); - kvmppc_gsm_include(gsm_l0_stats, KVMPPC_GSID_L0_GUEST_PGTABLE_RECLAIM); + kvmppc_gsm_include(gsm, KVMPPC_GSID_L0_GUEST_HEAP); + kvmppc_gsm_include(gsm, KVMPPC_GSID_L0_GUEST_HEAP_MAX); + kvmppc_gsm_include(gsm, KVMPPC_GSID_L0_GUEST_PGTABLE_SIZE); + kvmppc_gsm_include(gsm, KVMPPC_GSID_L0_GUEST_PGTABLE_SIZE_MAX); + kvmppc_gsm_include(gsm, KVMPPC_GSID_L0_GUEST_PGTABLE_RECLAIM); /* allocate GSB. Guest/Vcpu Id is ignored */ - gsb_l0_stats = kvmppc_gsb_new(kvmppc_gsm_size(gsm_l0_stats), 0, 0, - GFP_KERNEL); - if (!gsb_l0_stats) { + gsb = kvmppc_gsb_new(kvmppc_gsm_size(gsm), 0, 0, GFP_KERNEL); + if (!gsb) { rc = -ENOMEM; - goto out; + goto free_gsm; } /* ask the ops to fill in the info */ - rc = kvmppc_gsm_fill_info(gsm_l0_stats, gsb_l0_stats); + rc = kvmppc_gsm_fill_info(gsm, gsb); + if (rc) + goto free_gsb; -out: - if (rc) { - if (gsm_l0_stats) - kvmppc_gsm_free(gsm_l0_stats); - if (gsb_l0_stats) - kvmppc_gsb_free(gsb_l0_stats); - gsm_l0_stats = NULL; - gsb_l0_stats = NULL; - } + /* setup the Guest state message/buffer to talk to L0 */ + spin_lock_irqsave(&lock_l0_stats, flags); + gsm_l0_stats = gsm; + gsb_l0_stats = gsb; spin_unlock_irqrestore(&lock_l0_stats, flags); + + return 0; + +free_gsb: + kvmppc_gsb_free(gsb); +free_gsm: + kvmppc_gsm_free(gsm); return rc; } -- 2.39.5 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCHv3 3/4] powerpc/kvm-hv-pmu: Don't allocate gsm/gsb GFP_KERNEL allocations under spinlock 2026-11-23 13:51 ` [PATCHv3 3/4] powerpc/kvm-hv-pmu: Don't allocate gsm/gsb GFP_KERNEL allocations under spinlock Ritesh Harjani (IBM) @ 2026-11-25 5:53 ` Mukesh Kumar Chaurasiya 0 siblings, 0 replies; 12+ messages in thread From: Mukesh Kumar Chaurasiya @ 2026-11-25 5:53 UTC (permalink / raw) To: Ritesh Harjani (IBM) Cc: linuxppc-dev, Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy, Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, stable On Mon, Nov 23, 2026 at 07:21:52PM +0530, Ritesh Harjani (IBM) wrote: > kvmppc_init_hostwide() takes lock_l0_stats with spin_lock_irqsave() and > then allocates the guest state message and buffer with GFP_KERNEL. On > a nested API v2 host with DEBUG_ATOMIC_SLEEP this warns at boot: > > BUG: sleeping function called from invalid context at include/linux/sched/mm.h:322 > in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 1, name: swapper/0 > preempt_count: 1, expected: 0 > RCU nest depth: 0, expected: 0 > locks held by swapper/0/1: 1, on CPU#0: > #0: c000000004ad95b8 (lock_l0_stats){....}-{3:3}, at: kvmppc_register_pmu+0x50/0x270 > CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.4.0-rc2-00028-ge5a8bf3a3ee9-dirty #124 PREEMPT > Call Trace: > dump_stack_lvl+0xe8/0x150 (unreliable) > __might_resched+0x190/0x30c > __kmalloc_cache_noprof+0x4dc/0x760 > kvmppc_gsm_new+0x68/0xcc > kvmppc_register_pmu+0xd4/0x270 > do_one_initcall+0xac/0x48c > kernel_init_freeable+0x3cc/0x7f0 > kernel_init+0x3c/0x274 > ret_from_kernel_user_thread+0x14/0x1c > > The lock is not needed for the allocation of gsm and gsb buffers. > Allocate and fill the message and buffer without the lock and only take > it to publish the two global pointers. > > Fixes: f0c9c49c5067 ("powerpc/kvm-hv-pmu: Implement GSB message-ops for hostwide counters") > Cc: stable@vger.kernel.org > Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> > --- > arch/powerpc/perf/kvm-hv-pmu.c | 65 ++++++++++++++++------------------ > 1 file changed, 30 insertions(+), 35 deletions(-) > > diff --git a/arch/powerpc/perf/kvm-hv-pmu.c b/arch/powerpc/perf/kvm-hv-pmu.c > index aa72b96b5a8c..a58634f656e9 100644 > --- a/arch/powerpc/perf/kvm-hv-pmu.c > +++ b/arch/powerpc/perf/kvm-hv-pmu.c > @@ -314,53 +314,48 @@ static struct kvmppc_gs_msg_ops gsb_ops_l0_stats = { > > static int kvmppc_init_hostwide(void) > { > - int rc = 0; > + struct kvmppc_gs_msg *gsm; > + struct kvmppc_gs_buff *gsb; > unsigned long flags; > + int rc; > > - spin_lock_irqsave(&lock_l0_stats, flags); > - > - /* already registered ? */ > - if (gsm_l0_stats) { > - rc = 0; > - goto out; > - } > - > - /* setup the Guest state message/buffer to talk to L0 */ > - gsm_l0_stats = kvmppc_gsm_new(&gsb_ops_l0_stats, &l0_stats, > - GSM_SEND, GFP_KERNEL); > - if (!gsm_l0_stats) { > - rc = -ENOMEM; > - goto out; > - } > + /* allocate the Guest state message/buffer to talk to L0 */ > + gsm = kvmppc_gsm_new(&gsb_ops_l0_stats, &l0_stats, GSM_SEND, > + GFP_KERNEL); > + if (!gsm) > + return -ENOMEM; > > /* Populate the Idents */ > - kvmppc_gsm_include(gsm_l0_stats, KVMPPC_GSID_L0_GUEST_HEAP); > - kvmppc_gsm_include(gsm_l0_stats, KVMPPC_GSID_L0_GUEST_HEAP_MAX); > - kvmppc_gsm_include(gsm_l0_stats, KVMPPC_GSID_L0_GUEST_PGTABLE_SIZE); > - kvmppc_gsm_include(gsm_l0_stats, KVMPPC_GSID_L0_GUEST_PGTABLE_SIZE_MAX); > - kvmppc_gsm_include(gsm_l0_stats, KVMPPC_GSID_L0_GUEST_PGTABLE_RECLAIM); > + kvmppc_gsm_include(gsm, KVMPPC_GSID_L0_GUEST_HEAP); > + kvmppc_gsm_include(gsm, KVMPPC_GSID_L0_GUEST_HEAP_MAX); > + kvmppc_gsm_include(gsm, KVMPPC_GSID_L0_GUEST_PGTABLE_SIZE); > + kvmppc_gsm_include(gsm, KVMPPC_GSID_L0_GUEST_PGTABLE_SIZE_MAX); > + kvmppc_gsm_include(gsm, KVMPPC_GSID_L0_GUEST_PGTABLE_RECLAIM); > > /* allocate GSB. Guest/Vcpu Id is ignored */ > - gsb_l0_stats = kvmppc_gsb_new(kvmppc_gsm_size(gsm_l0_stats), 0, 0, > - GFP_KERNEL); > - if (!gsb_l0_stats) { > + gsb = kvmppc_gsb_new(kvmppc_gsm_size(gsm), 0, 0, GFP_KERNEL); > + if (!gsb) { > rc = -ENOMEM; > - goto out; > + goto free_gsm; > } > > /* ask the ops to fill in the info */ > - rc = kvmppc_gsm_fill_info(gsm_l0_stats, gsb_l0_stats); > + rc = kvmppc_gsm_fill_info(gsm, gsb); > + if (rc) > + goto free_gsb; > > -out: > - if (rc) { > - if (gsm_l0_stats) > - kvmppc_gsm_free(gsm_l0_stats); > - if (gsb_l0_stats) > - kvmppc_gsb_free(gsb_l0_stats); > - gsm_l0_stats = NULL; > - gsb_l0_stats = NULL; > - } > + /* setup the Guest state message/buffer to talk to L0 */ > + spin_lock_irqsave(&lock_l0_stats, flags); > + gsm_l0_stats = gsm; > + gsb_l0_stats = gsb; > spin_unlock_irqrestore(&lock_l0_stats, flags); > + > + return 0; > + > +free_gsb: > + kvmppc_gsb_free(gsb); > +free_gsm: > + kvmppc_gsm_free(gsm); > return rc; > } > > -- > 2.39.5 > LGTM Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com> ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCHv3 4/4] powerpc/kvm-hv-pmu: Free hostwide stats buffers if perf_pmu_register() fails [not found] <cover.1795441238.git.ritesh.list@gmail.com> ` (2 preceding siblings ...) 2026-11-23 13:51 ` [PATCHv3 3/4] powerpc/kvm-hv-pmu: Don't allocate gsm/gsb GFP_KERNEL allocations under spinlock Ritesh Harjani (IBM) @ 2026-11-23 13:51 ` Ritesh Harjani (IBM) 2026-11-25 5:58 ` Mukesh Kumar Chaurasiya 3 siblings, 1 reply; 12+ messages in thread From: Ritesh Harjani (IBM) @ 2026-11-23 13:51 UTC (permalink / raw) To: linuxppc-dev Cc: Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy, Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, Mukesh Kumar Chaurasiya, Ritesh Harjani (IBM), stable kvmppc_register_pmu() calls kvmppc_init_hostwide(), which allocates gsm_l0_stats and gsb_l0_stats. It then registers the pmu. If perf_pmu_register() fails we return without freeing them. Call kvmppc_cleanup_hostwide() on that error path. Fixes: f0c9c49c5067 ("powerpc/kvm-hv-pmu: Implement GSB message-ops for hostwide counters") Cc: stable@vger.kernel.org Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> --- arch/powerpc/perf/kvm-hv-pmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/perf/kvm-hv-pmu.c b/arch/powerpc/perf/kvm-hv-pmu.c index a58634f656e9..ec05b4855736 100644 --- a/arch/powerpc/perf/kvm-hv-pmu.c +++ b/arch/powerpc/perf/kvm-hv-pmu.c @@ -402,8 +402,10 @@ static int __init kvmppc_register_pmu(void) /* Register the pmu */ rc = perf_pmu_register(&kvmppc_pmu, kvmppc_pmu.name, -1); - if (rc) + if (rc) { + kvmppc_cleanup_hostwide(); goto out; + } pr_info("Registered kvm-hv pmu"); } -- 2.39.5 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCHv3 4/4] powerpc/kvm-hv-pmu: Free hostwide stats buffers if perf_pmu_register() fails 2026-11-23 13:51 ` [PATCHv3 4/4] powerpc/kvm-hv-pmu: Free hostwide stats buffers if perf_pmu_register() fails Ritesh Harjani (IBM) @ 2026-11-25 5:58 ` Mukesh Kumar Chaurasiya 2026-11-25 9:48 ` Ritesh Harjani 0 siblings, 1 reply; 12+ messages in thread From: Mukesh Kumar Chaurasiya @ 2026-11-25 5:58 UTC (permalink / raw) To: Ritesh Harjani (IBM) Cc: linuxppc-dev, Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy, Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, stable On Mon, Nov 23, 2026 at 07:21:53PM +0530, Ritesh Harjani (IBM) wrote: > kvmppc_register_pmu() calls kvmppc_init_hostwide(), which allocates > gsm_l0_stats and gsb_l0_stats. It then registers the pmu. If > perf_pmu_register() fails we return without freeing them. > > Call kvmppc_cleanup_hostwide() on that error path. > > Fixes: f0c9c49c5067 ("powerpc/kvm-hv-pmu: Implement GSB message-ops for hostwide counters") > Cc: stable@vger.kernel.org > Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> > --- > arch/powerpc/perf/kvm-hv-pmu.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/arch/powerpc/perf/kvm-hv-pmu.c b/arch/powerpc/perf/kvm-hv-pmu.c > index a58634f656e9..ec05b4855736 100644 > --- a/arch/powerpc/perf/kvm-hv-pmu.c > +++ b/arch/powerpc/perf/kvm-hv-pmu.c > @@ -402,8 +402,10 @@ static int __init kvmppc_register_pmu(void) > > /* Register the pmu */ > rc = perf_pmu_register(&kvmppc_pmu, kvmppc_pmu.name, -1); > - if (rc) > + if (rc) { > + kvmppc_cleanup_hostwide(); Just a question. Inside this function, should we also take lock just to set the pointers NULL rather than putting the whole logic(free also) inside the lock like we did in previous patch? Apart from this, all looks good. Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com> > goto out; > + } > > pr_info("Registered kvm-hv pmu"); > } > -- > 2.39.5 > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCHv3 4/4] powerpc/kvm-hv-pmu: Free hostwide stats buffers if perf_pmu_register() fails 2026-11-25 5:58 ` Mukesh Kumar Chaurasiya @ 2026-11-25 9:48 ` Ritesh Harjani 0 siblings, 0 replies; 12+ messages in thread From: Ritesh Harjani @ 2026-11-25 9:48 UTC (permalink / raw) To: Mukesh Kumar Chaurasiya Cc: linuxppc-dev, Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy, Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, stable Mukesh Kumar Chaurasiya <mkchauras@gmail.com> writes: > On Mon, Nov 23, 2026 at 07:21:53PM +0530, Ritesh Harjani (IBM) wrote: >> kvmppc_register_pmu() calls kvmppc_init_hostwide(), which allocates >> gsm_l0_stats and gsb_l0_stats. It then registers the pmu. If >> perf_pmu_register() fails we return without freeing them. >> >> Call kvmppc_cleanup_hostwide() on that error path. >> >> Fixes: f0c9c49c5067 ("powerpc/kvm-hv-pmu: Implement GSB message-ops for hostwide counters") >> Cc: stable@vger.kernel.org >> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> >> --- >> arch/powerpc/perf/kvm-hv-pmu.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/arch/powerpc/perf/kvm-hv-pmu.c b/arch/powerpc/perf/kvm-hv-pmu.c >> index a58634f656e9..ec05b4855736 100644 >> --- a/arch/powerpc/perf/kvm-hv-pmu.c >> +++ b/arch/powerpc/perf/kvm-hv-pmu.c >> @@ -402,8 +402,10 @@ static int __init kvmppc_register_pmu(void) >> >> /* Register the pmu */ >> rc = perf_pmu_register(&kvmppc_pmu, kvmppc_pmu.name, -1); >> - if (rc) >> + if (rc) { >> + kvmppc_cleanup_hostwide(); > Just a question. > Inside this function, should we also take lock just to set the pointers > NULL rather than putting the whole logic(free also) inside the lock like > we did in previous patch? > In the previous patch, we brought GFP_KERNEL (sleepable) allocation outside of atomic context. However, in here, there is no harm in keeping the lock to assign the null values to pointers. But I guess what you are suggesting is - Do we need to keep the lock around in the cleanup? Looks like no, we don't, since if the perf pmu register failed then we won't get a perf pmu update event for this - which is the only other user of this lock which can race. However, this patch is mostly an error handling fix (reported as a bug by Sashiko). One can pickup the cleanup of that path as a separate patch. There is also a powerpc wide clang's context analysis work that is going on, so as part of that - we could maybe optimize away taking of the lock in kvmppc_cleanup_hostwide() as well. As for this patch series, I think let's go with this, as most of the patches in the series are with Fixes tag to be backported. > Apart from this, all looks good. > > Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com> Thanks for the review! ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-11-26 13:20 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <cover.1795441238.git.ritesh.list@gmail.com>
2026-11-23 13:51 ` [PATCHv3 1/4] powerpc/64: Leave lockdep hardirq context around replayed interrupts Ritesh Harjani (IBM)
2026-11-25 5:19 ` Mukesh Kumar Chaurasiya
2026-11-23 13:51 ` [PATCHv3 2/4] powerpc/watchdog: Disable preemption in arch_touch_nmi_watchdog() Ritesh Harjani (IBM)
2026-11-25 5:50 ` Mukesh Kumar Chaurasiya
2026-11-25 9:58 ` Ritesh Harjani
2026-11-26 10:13 ` Christophe Leroy (CS GROUP)
2026-11-26 12:36 ` Ritesh Harjani
2026-11-23 13:51 ` [PATCHv3 3/4] powerpc/kvm-hv-pmu: Don't allocate gsm/gsb GFP_KERNEL allocations under spinlock Ritesh Harjani (IBM)
2026-11-25 5:53 ` Mukesh Kumar Chaurasiya
2026-11-23 13:51 ` [PATCHv3 4/4] powerpc/kvm-hv-pmu: Free hostwide stats buffers if perf_pmu_register() fails Ritesh Harjani (IBM)
2026-11-25 5:58 ` Mukesh Kumar Chaurasiya
2026-11-25 9:48 ` Ritesh Harjani
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox