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

From: Andrea Righi

Date: Tue Dec 23 2025 - 01:39:48 EST


On Mon, Dec 22, 2025 at 07:50:37PM -0500, Joel Fernandes wrote:
> 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. */

nit: s/its/it's/

> + if (kind >= SCX_EXIT_ERROR && !in_nmi())
> ei->bt_len = stack_trace_save(ei->bt, SCX_EXIT_BT_LEN, 1);

If stack_trace_save() isn't NMI-safe on certain architectures, shouldn't we
fix this inside stack_trace_save()?

There are probably other places where we call stack_trace_save() without
checking in_nmi(). Making stack_trace_save() handle the NMI case would
solve all of them.

> #endif
> vscnprintf(ei->msg, SCX_EXIT_MSG_LEN, fmt, args);
> --
> 2.34.1
>

Thanks,
-Andrea