Commit 73cb4a2d8d7e ("parisc: Use irq_enter_rcu() to fix warning at kernel/context_tracking.c:367") switched do_cpu_irq_mask() from irq_enter() to irq_enter_rcu() to silence a lockdep_assert_irqs_disabled() in ct_irq_enter(). The irq_*_rcu() variants assume that the caller has already told RCU about the interrupt, which nothing on parisc does. An interrupt taken from the idle loop, where RCU is not watching, then runs its handlers with RCU still not watching: RCU not watching for tracepoint WARNING: include/trace/events/lock.h:68 at lock_release+0x428/0x708, CPU#3: swapper/3/0 ... Backtrace: ktime_get_update_offsets_now+0xf4/0x408 hrtimer_run_queues+0xd0/0x2e4 update_process_times+0xb0/0x2ac tick_periodic+0xac/0x284 tick_handle_periodic+0x80/0x150 timer_interrupt+0xc0/0xd8 __handle_irq_event_percpu+0x10c/0x95c handle_irq_event_percpu+0x34/0xc8 handle_percpu_irq+0x10c/0x154 generic_handle_irq+0x64/0xb0 call_on_stack+0x18/0x24 execute_on_irq_stack+0xd4/0x100 do_cpu_irq_mask+0x408/0x5c8 intr_return+0x0/0xc hardirqs last enabled at (112229): do_idle+0x158/0x584 That assertion fired only because lockdep did not know that interrupts are disabled on entry to do_cpu_irq_mask(). Commit a739c9192173 ("parisc: irq: Trace hardirq state in do_cpu_irq_mask()") fixed that by calling trace_hardirqs_off() first, so go back to irq_enter() and irq_exit(). Fixes: 73cb4a2d8d7e ("parisc: Use irq_enter_rcu() to fix warning at kernel/context_tracking.c:367") Cc: stable@vger.kernel.org # v6.9+ Signed-off-by: Matt Turner --- arch/parisc/kernel/irq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/parisc/kernel/irq.c b/arch/parisc/kernel/irq.c index d9f6cb04e4bc..3b4562e67db1 100644 --- a/arch/parisc/kernel/irq.c +++ b/arch/parisc/kernel/irq.c @@ -498,7 +498,7 @@ asmlinkage void do_cpu_irq_mask(struct pt_regs *regs) old_regs = set_irq_regs(regs); trace_hardirqs_off(); - irq_enter_rcu(); + irq_enter(); eirr_val = mfctl(23) & cpu_eiem & per_cpu(local_ack_eiem, cpu); if (!eirr_val) @@ -533,7 +533,7 @@ asmlinkage void do_cpu_irq_mask(struct pt_regs *regs) #endif /* CONFIG_IRQSTACKS */ out: - irq_exit_rcu(); + irq_exit(); set_irq_regs(old_regs); if (!irqs_disabled_flags(regs->gr[0])) trace_hardirqs_on(); -- 2.56.1 When the unwinder reaches handle_interruption() or intr_return, it reads the interrupted context's sp and pc from the pt_regs just below the frame. That only holds for an interruption from kernel space. For one from user space, get_stack_use_cr30 saves the registers in task->thread.regs and starts the kernel stack PT_SZ_ALGN bytes above the base of the stack, so the unwinder reads whatever stale data is at the base of the stack. dump_stack() from such a trap then unwinds through a bogus frame into stale frames left on the stack, and repeats them: Backtrace: ... handle_interruption+0x674/0x106c __cmpxchg_u64+0x118/0x170 unwind_once+0x30/0x74 do_show_stack+0x10c/0x170 show_stack+0x68/0x80 dump_stack_lvl+0x1a8/0x260 dump_stack+0x34/0x48 check_preemption_disabled+0x18c/0x194 __this_cpu_preempt_check+0x38/0x4c handle_interruption+0x674/0x106c __cmpxchg_u64+0x118/0x170 ... On a C8000 with lockdep enabled, this left one CPU unwinding forever and the other CPUs soft-locked in smp_call_function_many_cond(). End the unwind when the pt_regs would sit at the base of the stack. Fixes: 05dc16d6a175 ("[PARISC] unwinder improvements") Fixes: c8921d72e390 ("parisc: Fix and improve kernel stack unwinding") Cc: stable@vger.kernel.org Signed-off-by: Matt Turner --- arch/parisc/kernel/unwind.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/parisc/kernel/unwind.c b/arch/parisc/kernel/unwind.c index fab9ae22191a..5f129c5d6e07 100644 --- a/arch/parisc/kernel/unwind.c +++ b/arch/parisc/kernel/unwind.c @@ -211,6 +211,19 @@ static bool pc_is_kernel_fn(unsigned long pc, void *fn) return (unsigned long)dereference_kernel_function_descriptor(fn) == pc; } +/* + * An interruption from user space saves its registers in the task struct + * and starts the kernel stack PT_SZ_ALGN bytes above the base of the + * stack, leaving stale data where a pt_regs would be. End the unwind there. + */ +static bool unwind_stop_at_user_regs(struct unwind_frame_info *info, struct pt_regs *regs) +{ + if ((unsigned long)regs != (unsigned long)task_stack_page(info->t)) + return false; + info->prev_sp = info->prev_ip = 0; + return true; +} + static int unwind_special(struct unwind_frame_info *info, unsigned long pc, int frame_size) { /* @@ -231,6 +244,8 @@ static int unwind_special(struct unwind_frame_info *info, unsigned long pc, int if (pc_is_kernel_fn(pc, handle_interruption)) { struct pt_regs *regs = (struct pt_regs *)(info->sp - frame_size - PT_SZ_ALGN); dbg("Unwinding through handle_interruption()\n"); + if (unwind_stop_at_user_regs(info, regs)) + return 1; info->prev_sp = regs->gr[30]; info->prev_ip = regs->iaoq[0]; return 1; @@ -247,6 +262,8 @@ static int unwind_special(struct unwind_frame_info *info, unsigned long pc, int dbg("Found intr_return()\n"); regs = (struct pt_regs *)(info->sp - PT_SZ_ALGN); + if (unwind_stop_at_user_regs(info, regs)) + return 1; info->prev_sp = regs->gr[30]; info->prev_ip = regs->iaoq[0]; info->rp = regs->gr[2]; -- 2.56.1 handle_interruption() enables interrupts when the trapping context had them enabled, so the FP assist trap (code 14) and the unaligned access handler can run preemptible. Both bump a per-CPU counter with __inc_irq_stat(), which is only safe with preemption disabled. A task can migrate in the middle of the read-modify-write and lose an update to another CPU's count, and with CONFIG_DEBUG_PREEMPT it warns: BUG: using __this_cpu_add() in preemptible [00000000] code: systemd-timesyn/1338 caller is __this_cpu_preempt_check+0x38/0x4c ... Backtrace: show_stack+0x68/0x80 dump_stack_lvl+0x1a8/0x260 dump_stack+0x34/0x48 check_preemption_disabled+0x18c/0x194 __this_cpu_preempt_check+0x38/0x4c handle_interruption+0x674/0x106c (The rest of the trace is garbage from the unwinder bug fixed by "parisc: unwind: Stop at interruptions from user space".) Use inc_irq_stat() instead. Fixes: d0c3be806a3f ("parisc: show number of FPE and unaligned access handler calls in /proc/interrupts") Cc: stable@vger.kernel.org Signed-off-by: Matt Turner --- arch/parisc/kernel/traps.c | 2 +- arch/parisc/kernel/unaligned.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c index 4c7c5df80bd0..b3528696e572 100644 --- a/arch/parisc/kernel/traps.c +++ b/arch/parisc/kernel/traps.c @@ -633,7 +633,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs) case 14: /* Assist Exception Trap, i.e. floating point exception. */ die_if_kernel("Floating point exception", regs, 0); /* quiet */ - __inc_irq_stat(irq_fpassist_count); + inc_irq_stat(irq_fpassist_count); perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, 0); handle_fpe(regs); return; diff --git a/arch/parisc/kernel/unaligned.c b/arch/parisc/kernel/unaligned.c index fb64d9ce0b17..454daf1f22d4 100644 --- a/arch/parisc/kernel/unaligned.c +++ b/arch/parisc/kernel/unaligned.c @@ -378,7 +378,7 @@ void handle_unaligned(struct pt_regs *regs) int modify = 0; int ret = ERR_NOTHANDLED; - __inc_irq_stat(irq_unaligned_count); + inc_irq_stat(irq_unaligned_count); perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, regs->ior); /* log a message with pacing */ -- 2.56.1 ipi_interrupt() briefly enables interrupts between IPI operations to "let in any pending interrupts". That dates from commit 7085689ed135 ("[PARISC] Allow nested interrupts"), before commit e58aa3d2d0cc ("genirq: Run irq handlers with interrupts disabled") made every handler run with interrupts disabled. Enabling interrupts in hardirq context lets other interrupts nest on the IRQ stack, and lockdep rejects it: DEBUG_LOCKS_WARN_ON(lockdep_hardirq_context()) WARNING: kernel/locking/lockdep.c:4448 at lockdep_hardirqs_on_prepare+0x378/0x490, CPU#0: systemd-sysctl/993 ... Backtrace: trace_hardirqs_on+0x108/0x2dc ipi_interrupt+0x268/0x448 __handle_irq_event_percpu+0x10c/0x95c handle_irq_event_percpu+0x34/0xc8 handle_percpu_irq+0x10c/0x154 generic_handle_irq+0x64/0xb0 execute_on_irq_stack+0x88/0x100 do_cpu_irq_mask+0x408/0x5c8 intr_return+0x0/0xc Handle all pending IPIs with interrupts disabled. Fixes: 7085689ed135 ("[PARISC] Allow nested interrupts") Cc: stable@vger.kernel.org Signed-off-by: Matt Turner --- arch/parisc/kernel/smp.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/arch/parisc/kernel/smp.c b/arch/parisc/kernel/smp.c index 36be17e32948..a7c67032389b 100644 --- a/arch/parisc/kernel/smp.c +++ b/arch/parisc/kernel/smp.c @@ -181,12 +181,6 @@ ipi_interrupt(int irq, void *dev_id) this_cpu, which); return IRQ_NONE; } /* Switch */ - - /* before doing more, let in any pending interrupts */ - if (ops) { - local_irq_enable(); - local_irq_disable(); - } } /* while (ops) */ } return IRQ_HANDLED; -- 2.56.1 The firmware may need up to 8 seconds to move a CPU into the rendezvous state, and no other PDC calls may be made meanwhile. So __cpu_die() takes pdc_lock and arch_cpuhp_cleanup_dead_cpu() releases it after waiting with schedule_timeout(). pdc_lock is a spinlock, so this sleeps in atomic context, and when the task migrates while asleep the lock is released on a different CPU than the one whose preempt count it raised: BUG: scheduling while atomic: cr16-hp.sh/1660/0x00000002 ... Preemption disabled at: pdc_cpu_rendezvous_lock+0x38/0x4c ... Backtrace: ... schedule_timeout+0xd8/0x240 arch_cpuhp_cleanup_dead_cpu+0xc0/0xf4 takedown_cpu+0x2a4/0x3f0 cpuhp_invoke_callback+0x208/0x3d8 __cpuhp_invoke_callback_range+0xbc/0x19c _cpu_down.constprop.0+0x368/0x5dc cpu_device_down+0x90/0xe8 cpu_subsys_offline+0x30/0x44 device_offline+0x1a8/0x334 online_store+0xb4/0x274 ... DEBUG_LOCKS_WARN_ON(pc - uval > pc) WARNING: kernel/sched/core.c:6092 at preempt_count_sub+0xd0/0x15c, CPU#0: cr16-hp.sh/1660 ... Backtrace: _raw_spin_unlock+0x94/0xec pdc_cpu_rendezvous_unlock+0x38/0x4c arch_cpuhp_cleanup_dead_cpu+0xe0/0xf4 takedown_cpu+0x2a4/0x3f0 ... The second warning turns lockdep off. On a C8000 that ran CPU hotplug in a loop, the machine later hung in smp_call_function_many_cond(). Busy-wait with mdelay() instead. It keeps one CPU busy for the 8 seconds (2 on 32-bit) given to the firmware, but any other CPU wanting PDC already has to spin on pdc_lock for that long. Fixes: 88b3aac6228b ("parisc: Implement __cpu_die() and __cpu_disable() for CPU hotplugging") Cc: stable@vger.kernel.org # v5.18+ Signed-off-by: Matt Turner --- arch/parisc/kernel/smp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/parisc/kernel/smp.c b/arch/parisc/kernel/smp.c index a7c67032389b..2fbe4b96e96a 100644 --- a/arch/parisc/kernel/smp.c +++ b/arch/parisc/kernel/smp.c @@ -493,9 +493,8 @@ void arch_cpuhp_cleanup_dead_cpu(unsigned int cpu) { pr_info("CPU%u: is shutting down\n", cpu); - /* set task's state to interruptible sleep */ - set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout((IS_ENABLED(CONFIG_64BIT) ? 8:2) * HZ); + /* pdc_lock is held, so wait for the rendezvous without sleeping */ + mdelay((IS_ENABLED(CONFIG_64BIT) ? 8 : 2) * MSEC_PER_SEC); pdc_cpu_rendezvous_unlock(); } -- 2.56.1