Skip to content

Commit 5cc0591

Browse files
committed
powerpc/64s: Wire up arch_trigger_cpumask_backtrace()
This allows eg. the RCU stall detector, or the soft/hardlockup detectors to trigger a backtrace on all CPUs. We implement this by sending a "safe" NMI, which will actually only send an IPI. Unfortunately the generic code prints "NMI", so that's a little confusing but we can probably live with it. If one of the CPUs doesn't respond to the IPI, we then print some info from it's paca and do a backtrace based on its saved_r1. Example output: INFO: rcu_sched detected stalls on CPUs/tasks: 2-...0: (0 ticks this GP) idle=1be/1/4611686018427387904 softirq=1055/1055 fqs=25735 (detected by 4, t=58847 jiffies, g=58, c=57, q=1258) Sending NMI from CPU 4 to CPUs 2: CPU 2 didn't respond to backtrace IPI, inspecting paca. irq_soft_mask: 0x01 in_mce: 0 in_nmi: 0 current: 3623 (bash) Back trace of paca->saved_r1 (0xc0000000e1c83ba0) (possibly stale): Call Trace: [c0000000e1c83ba0] [0000000000000014] 0x14 (unreliable) [c0000000e1c83bc0] [c000000000765798] lkdtm_do_action+0x48/0x80 [c0000000e1c83bf0] [c000000000765a40] direct_entry+0x110/0x1b0 [c0000000e1c83c90] [c00000000058e650] full_proxy_write+0x90/0xe0 [c0000000e1c83ce0] [c0000000003aae3c] __vfs_write+0x6c/0x1f0 [c0000000e1c83d80] [c0000000003ab214] vfs_write+0xd4/0x240 [c0000000e1c83dd0] [c0000000003ab5cc] ksys_write+0x6c/0x110 [c0000000e1c83e30] [c00000000000b860] system_call+0x58/0x6c Signed-off-by: Michael Ellerman <[email protected]> Reviewed-by: Nicholas Piggin <[email protected]>
1 parent 6ba5571 commit 5cc0591

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

arch/powerpc/include/asm/nmi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ extern void arch_touch_nmi_watchdog(void);
88
static inline void arch_touch_nmi_watchdog(void) {}
99
#endif
1010

11+
#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_STACKTRACE)
12+
extern void arch_trigger_cpumask_backtrace(const cpumask_t *mask,
13+
bool exclude_self);
14+
#define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace
15+
#endif
16+
1117
#endif /* _ASM_NMI_H */

arch/powerpc/kernel/stacktrace.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/export.h>
1414
#include <linux/kallsyms.h>
1515
#include <linux/module.h>
16+
#include <linux/nmi.h>
1617
#include <linux/sched.h>
1718
#include <linux/sched/debug.h>
1819
#include <linux/sched/task_stack.h>
@@ -22,6 +23,8 @@
2223
#include <linux/ftrace.h>
2324
#include <asm/kprobes.h>
2425

26+
#include <asm/paca.h>
27+
2528
/*
2629
* Save stack-backtrace addresses into a stack_trace buffer.
2730
*/
@@ -194,3 +197,51 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
194197
}
195198
EXPORT_SYMBOL_GPL(save_stack_trace_tsk_reliable);
196199
#endif /* CONFIG_HAVE_RELIABLE_STACKTRACE */
200+
201+
#ifdef CONFIG_PPC_BOOK3S_64
202+
static void handle_backtrace_ipi(struct pt_regs *regs)
203+
{
204+
nmi_cpu_backtrace(regs);
205+
}
206+
207+
static void raise_backtrace_ipi(cpumask_t *mask)
208+
{
209+
unsigned int cpu;
210+
211+
for_each_cpu(cpu, mask) {
212+
if (cpu == smp_processor_id())
213+
handle_backtrace_ipi(NULL);
214+
else
215+
smp_send_safe_nmi_ipi(cpu, handle_backtrace_ipi, 5 * USEC_PER_SEC);
216+
}
217+
218+
for_each_cpu(cpu, mask) {
219+
struct paca_struct *p = paca_ptrs[cpu];
220+
221+
cpumask_clear_cpu(cpu, mask);
222+
223+
pr_warn("CPU %d didn't respond to backtrace IPI, inspecting paca.\n", cpu);
224+
if (!virt_addr_valid(p)) {
225+
pr_warn("paca pointer appears corrupt? (%px)\n", p);
226+
continue;
227+
}
228+
229+
pr_warn("irq_soft_mask: 0x%02x in_mce: %d in_nmi: %d",
230+
p->irq_soft_mask, p->in_mce, p->in_nmi);
231+
232+
if (virt_addr_valid(p->__current))
233+
pr_cont(" current: %d (%s)\n", p->__current->pid,
234+
p->__current->comm);
235+
else
236+
pr_cont(" current pointer corrupt? (%px)\n", p->__current);
237+
238+
pr_warn("Back trace of paca->saved_r1 (0x%016llx) (possibly stale):\n", p->saved_r1);
239+
show_stack(p->__current, (unsigned long *)p->saved_r1);
240+
}
241+
}
242+
243+
void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self)
244+
{
245+
nmi_trigger_cpumask_backtrace(mask, exclude_self, raise_backtrace_ipi);
246+
}
247+
#endif /* CONFIG_PPC64 */

0 commit comments

Comments
 (0)