[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251127125305.89961-5-cuiyunhui@bytedance.com>
Date: Thu, 27 Nov 2025 20:53:01 +0800
From: Yunhui Cui <cuiyunhui@...edance.com>
To: conor@...nel.org,
paul.walmsley@...ive.com,
palmer@...belt.com,
aou@...s.berkeley.edu,
alex@...ti.fr,
cuiyunhui@...edance.com,
luxu.kernel@...edance.com,
linux-kernel@...r.kernel.org,
linux-riscv@...ts.infradead.org,
jassisinghbrar@...il.com,
conor.dooley@...rochip.com,
valentina.fernandezalanis@...rochip.com,
catalin.marinas@....com,
will@...nel.org,
maz@...nel.org,
timothy.hayes@....com,
lpieralisi@...nel.org,
arnd@...db.de,
kees@...nel.org,
tglx@...utronix.de,
viresh.kumar@...aro.org,
boqun.feng@...il.com,
linux-arm-kernel@...ts.infradead.org,
cleger@...osinc.com,
atishp@...osinc.com,
ajones@...tanamicro.com
Subject: [PATCH v3 4/8] riscv: smp: use NMI for crash stop
Use NMI instead of IPI for crash stop if RISC-V SSE NMI is supported.
Signed-off-by: Yunhui Cui <cuiyunhui@...edance.com>
---
arch/riscv/kernel/smp.c | 11 ++++++++++-
drivers/firmware/riscv/riscv_sse_nmi.c | 12 ++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c
index 669325e68a21a..1b8cf986abbd0 100644
--- a/arch/riscv/kernel/smp.c
+++ b/arch/riscv/kernel/smp.c
@@ -16,6 +16,7 @@
#include <linux/kgdb.h>
#include <linux/percpu.h>
#include <linux/profile.h>
+#include <linux/riscv_sse_nmi.h>
#include <linux/smp.h>
#include <linux/sched.h>
#include <linux/seq_file.h>
@@ -300,7 +301,15 @@ void crash_smp_send_stop(void)
atomic_set(&waiting_for_crash_ipi, num_other_online_cpus());
pr_crit("SMP: stopping secondary CPUs\n");
- send_ipi_mask(&mask, IPI_CPU_CRASH_STOP);
+
+ /*
+ * Not a high frequency operation and is in final state, directly use
+ * NMI instead of IPI to ensure reliability.
+ */
+ if (!nmi_support())
+ send_ipi_mask(&mask, IPI_CPU_CRASH_STOP);
+ else
+ send_nmi_mask(&mask, LOCAL_NMI_CRASH);
/* Wait up to one second for other CPUs to stop */
timeout = USEC_PER_SEC;
diff --git a/drivers/firmware/riscv/riscv_sse_nmi.c b/drivers/firmware/riscv/riscv_sse_nmi.c
index 752ee88b230da..add028efd25a0 100644
--- a/drivers/firmware/riscv/riscv_sse_nmi.c
+++ b/drivers/firmware/riscv/riscv_sse_nmi.c
@@ -10,6 +10,9 @@
#include <asm/sbi.h>
#include <asm/smp.h>
+#define NMI_HANDLE(mask, func, ...) \
+ do { if (type & (mask)) func(__VA_ARGS__); } while (0)
+
static bool nmi_available;
static struct sse_event *local_nmi_evt;
static DEFINE_PER_CPU(atomic_t, local_nmi) = ATOMIC_INIT(LOCAL_NMI_NONE);
@@ -49,6 +52,15 @@ void send_nmi_mask(cpumask_t *mask, enum local_nmi_type type)
static int local_nmi_handler(u32 evt, void *arg, struct pt_regs *regs)
{
+ enum local_nmi_type type;
+ unsigned int cpu = smp_processor_id();
+
+ type = atomic_read(this_cpu_ptr(&local_nmi));
+
+ NMI_HANDLE(LOCAL_NMI_CRASH, cpu_crash_stop, cpu, regs);
+
+ atomic_andnot(type, this_cpu_ptr(&local_nmi));
+
return 0;
}
--
2.39.5
Powered by blists - more mailing lists