[PATCH next v1 2/2] nmi_backtrace: use the printk cpu lock for show_regs()
From: John Ogness
Date: Mon May 31 2021 - 13:29:54 EST
dump_stack() uses the printk cpu lock to synchronize the stacktrace,
but this can also be used for dumping the banner and regs.
Since the cpu lock allows recursive locking, it is not an issue to
call dump_stack() with the printk cpu lock held.
Signed-off-by: John Ogness <john.ogness@xxxxxxxxxxxxx>
---
lib/nmi_backtrace.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/nmi_backtrace.c b/lib/nmi_backtrace.c
index 8abe1870dba4..9ed02c2d77be 100644
--- a/lib/nmi_backtrace.c
+++ b/lib/nmi_backtrace.c
@@ -92,17 +92,21 @@ module_param(backtrace_idle, bool, 0644);
bool nmi_cpu_backtrace(struct pt_regs *regs)
{
int cpu = smp_processor_id();
+ unsigned int cpu_store;
+ unsigned long flags;
if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
if (!READ_ONCE(backtrace_idle) && regs && cpu_in_idle(instruction_pointer(regs))) {
pr_warn("NMI backtrace for cpu %d skipped: idling at %pS\n",
cpu, (void *)instruction_pointer(regs));
} else {
+ printk_cpu_lock(&cpu_store, &flags);
pr_warn("NMI backtrace for cpu %d\n", cpu);
if (regs)
show_regs(regs);
else
dump_stack();
+ printk_cpu_unlock(cpu_store, flags);
}
cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask));
return true;
--
2.20.1