Skip to content

Commit f15c21a

Browse files
ryotakakura98palmer-dabbelt
authored andcommitted
RISC-V: Enable IPI CPU Backtrace
Add arch_trigger_cpumask_backtrace() which is a generic infrastructure for sampling other CPUs' backtrace using IPI. The feature is used when lockups are detected or in case of oops/panic if parameters are set accordingly. Below is the case of oops with the oops_all_cpu_backtrace enabled. $ sysctl kernel.oops_all_cpu_backtrace=1 triggering oops shows: [ 212.214237] NMI backtrace for cpu 1 [ 212.214390] CPU: 1 PID: 610 Comm: in:imklog Tainted: G OE 6.10.0-rc6 #1 [ 212.214570] Hardware name: riscv-virtio,qemu (DT) [ 212.214690] epc : fallback_scalar_usercopy+0x8/0xdc [ 212.214809] ra : _copy_to_user+0x20/0x40 [ 212.214913] epc : ffffffff80c3a930 ra : ffffffff8059ba7e sp : ff20000000eabb50 [ 212.215061] gp : ffffffff82066f90 tp : ff6000008e958000 t0 : 3463303866660000 [ 212.215210] t1 : 000000000000005b t2 : 3463303866666666 s0 : ff20000000eabb60 [ 212.215358] s1 : 0000000000000386 a0 : 00007ff6e81df926 a1 : ff600000824df800 [ 212.215505] a2 : 000000000000003f a3 : 7fffffffffffffc0 a4 : 0000000000000000 [ 212.215651] a5 : 000000000000003f a6 : 0000000000000000 a7 : 0000000000000000 [ 212.215857] s2 : ff600000824df800 s3 : ffffffff82066cc0 s4 : 0000000000001c1a [ 212.216074] s5 : ffffffff8206a5a8 s6 : 00007ff6e81df926 s7 : ffffffff8206a5a0 [ 212.216278] s8 : ff600000824df800 s9 : ffffffff81e25de0 s10: 000000000000003f [ 212.216471] s11: ffffffff8206a59d t3 : ff600000824df812 t4 : ff600000824df812 [ 212.216651] t5 : ff600000824df818 t6 : 0000000000040000 [ 212.216796] status: 0000000000040120 badaddr: 0000000000000000 cause: 8000000000000001 [ 212.217035] [<ffffffff80c3a930>] fallback_scalar_usercopy+0x8/0xdc [ 212.217207] [<ffffffff80095f56>] syslog_print+0x1f4/0x2b2 [ 212.217362] [<ffffffff80096e5c>] do_syslog.part.0+0x94/0x2d8 [ 212.217502] [<ffffffff800979e8>] do_syslog+0x66/0x88 [ 212.217636] [<ffffffff803a5dda>] kmsg_read+0x44/0x5c [ 212.217764] [<ffffffff80392dbe>] proc_reg_read+0x7a/0xa8 [ 212.217952] [<ffffffff802ff726>] vfs_read+0xb0/0x24e [ 212.218090] [<ffffffff803001ba>] ksys_read+0x64/0xe4 [ 212.218264] [<ffffffff8030025a>] __riscv_sys_read+0x20/0x2c [ 212.218453] [<ffffffff80c4af9a>] do_trap_ecall_u+0x60/0x1d4 [ 212.218664] [<ffffffff80c56998>] ret_from_exception+0x0/0x64 Signed-off-by: Ryo Takakura <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 7c08a26 commit f15c21a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

arch/riscv/include/asm/irq.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
#include <asm-generic/irq.h>
1414

15+
#ifdef CONFIG_SMP
16+
void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu);
17+
#define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace
18+
#endif
19+
1520
void riscv_set_intc_hwnode_fn(struct fwnode_handle *(*fn)(void));
1621

1722
struct fwnode_handle *riscv_get_intc_hwnode(void);

arch/riscv/kernel/smp.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/delay.h>
2222
#include <linux/irq.h>
2323
#include <linux/irq_work.h>
24+
#include <linux/nmi.h>
2425

2526
#include <asm/tlbflush.h>
2627
#include <asm/cacheflush.h>
@@ -33,6 +34,7 @@ enum ipi_message_type {
3334
IPI_CPU_CRASH_STOP,
3435
IPI_IRQ_WORK,
3536
IPI_TIMER,
37+
IPI_CPU_BACKTRACE,
3638
IPI_MAX
3739
};
3840

@@ -136,6 +138,9 @@ static irqreturn_t handle_IPI(int irq, void *data)
136138
tick_receive_broadcast();
137139
break;
138140
#endif
141+
case IPI_CPU_BACKTRACE:
142+
nmi_cpu_backtrace(get_irq_regs());
143+
break;
139144
default:
140145
pr_warn("CPU%d: unhandled IPI%d\n", smp_processor_id(), ipi);
141146
break;
@@ -203,6 +208,7 @@ static const char * const ipi_names[] = {
203208
[IPI_CPU_CRASH_STOP] = "CPU stop (for crash dump) interrupts",
204209
[IPI_IRQ_WORK] = "IRQ work interrupts",
205210
[IPI_TIMER] = "Timer broadcast interrupts",
211+
[IPI_CPU_BACKTRACE] = "CPU backtrace interrupts",
206212
};
207213

208214
void show_ipi_stats(struct seq_file *p, int prec)
@@ -323,3 +329,13 @@ void arch_smp_send_reschedule(int cpu)
323329
send_ipi_single(cpu, IPI_RESCHEDULE);
324330
}
325331
EXPORT_SYMBOL_GPL(arch_smp_send_reschedule);
332+
333+
static void riscv_backtrace_ipi(cpumask_t *mask)
334+
{
335+
send_ipi_mask(mask, IPI_CPU_BACKTRACE);
336+
}
337+
338+
void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu)
339+
{
340+
nmi_trigger_cpumask_backtrace(mask, exclude_cpu, riscv_backtrace_ipi);
341+
}

0 commit comments

Comments
 (0)