[RFT] sched_ext: Skip stack trace capture in NMI context

From: Joel Fernandes

Date: Mon Dec 22 2025 - 19:50:52 EST


stack_trace_save() is not guaranteed to be NMI-safe on all
architectures.

The hardlockup detector calls into sched_ext via the following call
chain when an NMI occurs:

watchdog_overflow_callback()
watchdog_hardlockup_check()
scx_hardlockup()
stack_trace_save()

Skip stack trace capture when in_nmi() returns true to prevent
potential deadlocks.

Fixes: 582f700e1bdc ("sched_ext: Hook up hardlockup detector")
Signed-off-by: Joel Fernandes <joelagnelf@xxxxxxxxxx>
---
kernel/sched/ext.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 05f5a49e9649..a96255ca3a08 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -4678,7 +4678,8 @@ static bool scx_vexit(struct scx_sched *sch,

ei->exit_code = exit_code;
#ifdef CONFIG_STACKTRACE
- if (kind >= SCX_EXIT_ERROR)
+ /* Skip stack trace capture in NMI context as its unsafe. */
+ if (kind >= SCX_EXIT_ERROR && !in_nmi())
ei->bt_len = stack_trace_save(ei->bt, SCX_EXIT_BT_LEN, 1);
#endif
vscnprintf(ei->msg, SCX_EXIT_MSG_LEN, fmt, args);
--
2.34.1