Re: [PATCHv4 2/4] powerpc/watchdog: Disable preemption in arch_touch_nmi_watchdog()
From: Mukesh Kumar Chaurasiya
Date: Thu Nov 26 2026 - 00:19:09 EST
On Wed, Nov 25, 2026 at 04:56:04PM +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 to fix this.
>
> Fixes: 2104180a5369 ("powerpc/64s: implement arch-specific hardlockup watchdog")
> Cc: stable@xxxxxxxxxxxxxxx
> Reviewed-by: Shrikanth Hegde <sshegde@xxxxxxxxxxxxx>
> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx>
> ---
> arch/powerpc/kernel/watchdog.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c
> index 44f178e07531..1a8514b2d853 100644
> --- a/arch/powerpc/kernel/watchdog.c
> +++ b/arch/powerpc/kernel/watchdog.c
> @@ -459,9 +459,13 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
> 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
>
LGTM
Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@xxxxxxxxx>