Re: [PATCH v2] sched_ext: Reject NMI calls to lock-taking kfuncs

From: Tejun Heo

Date: Wed Sep 02 2026 - 17:58:28 EST


Hello,

On Wed, Sep 02, 2026 at 09:48:28PM +0800, liwanwu wrote:
> Three "any"-category kfuncs read scx_locked_rq() on their success path
> and treat a non-NULL return as "the rq lock is already held by me",
> which a false positive under NMI turns into either a data race or a
> wrong result:

Let's add the in_nmi() test to scx_locked_rq() so that it returns NULL from
NMI. That sends all three down their unlocked paths.

> pick_idle_cpu_from_online_nodes() (kernel/sched/ext/idle.c:151), which
> writes the per-CPU nodemask per_cpu_unvisited (idle.c:146) under only
> preempt_disable(). preempt_disable() does not mask NMIs, so an NMI that
> lands on a CPU whose interrupted context is mid-way through that loop
> clobbers the scratch nodemask the interrupted context is still
> iterating.

That probably needs to be irqsave'd. preempt_disable() doesn't mask IRQs
either and the idle kfuncs can be called from IRQ-enabled contexts. As for
NMI, if someone is calling pick_idle from NMI, they're asking for it. As
long as the machine doesn't crash, it doesn't matter.

Thanks.

--
tejun