Re: [PATCH v13 06/11] riscv: enable NMI-safe lockdep irqflags tracking

From: Clement Leger

Date: Thu Nov 19 2026 - 08:46:53 EST




On 11/19/26 13:08, Zhanpeng Zhang wrote:
An SSE handler runs with interrupts masked, but can interrupt code whose
lockdep hardirq state is enabled. Bare nmi_enter()/nmi_exit() do not
update that state. Consequently, lockdep_assert_irqs_disabled() in the
perf overflow path can report a warning despite interrupts being masked.

Select TRACE_IRQFLAGS_NMI_SUPPORT so lockdep can update its hardirq state
inside an NMI. Pair this with irqentry_nmi_enter()/irqentry_nmi_exit() in
the SSE wrapper: these helpers save the previous tracked state, mark
interrupts disabled on entry and restore the tracked state on exit.
Selecting the configuration option alone does not perform those updates.
This follows the entry helpers used by the other RISC-V NMI-like traps.

Signed-off-by: Zhanpeng Zhang <zhangzhanpeng.jasper@xxxxxxxxxxxxx>
---
arch/riscv/Kconfig | 1 +
arch/riscv/kernel/sbi_sse.c | 7 ++++---
2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index d2db8f40c616..5501c02a07eb 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -225,6 +225,7 @@ config RISCV
select SYSCTL_EXCEPTION_TRACE
select THREAD_INFO_IN_TASK
select TRACE_IRQFLAGS_SUPPORT
+ select TRACE_IRQFLAGS_NMI_SUPPORT
select UACCESS_MEMCPY if !MMU
select VDSO_DATASTORE if MMU
select VDSO_GETRANDOM if MMU && 64BIT
diff --git a/arch/riscv/kernel/sbi_sse.c b/arch/riscv/kernel/sbi_sse.c
index 032fcc07abcf..59e47a39589d 100644
--- a/arch/riscv/kernel/sbi_sse.c
+++ b/arch/riscv/kernel/sbi_sse.c
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2025 Rivos Inc.
*/
-#include <linux/nmi.h>
+#include <linux/entry-common.h>
#include <linux/sched.h>
#include <linux/scs.h>
#include <linux/bitfield.h>
@@ -36,9 +36,10 @@ void noinstr do_sse(struct sse_event_arch_data *arch_evt,
{
struct riscv_sse_interrupted_context context = { regs, hstatus };
struct riscv_sse_interrupted_context *previous;
+ irqentry_state_t state;
struct sbiret sret;
- nmi_enter();
+ state = irqentry_nmi_enter(regs);
instrumentation_begin();
/* Retrieve missing GPRs from SBI */
@@ -84,7 +85,7 @@ void noinstr do_sse(struct sse_event_arch_data *arch_evt,
out:
instrumentation_end();
- nmi_exit();
+ irqentry_nmi_exit(regs, state);
}
static void *alloc_to_stack_pointer(void *alloc)

Hi Zhanpeng,

Not sure if it was already suggested but I would fold that in the commit adding SSE itself.

Thanks,

Clément