Re: [PATCH] sched/core: Avoid atomic cpuset_lock() in __sched_setscheduler()
From: Juri Lelli
Date: Thu Nov 26 2026 - 06:12:18 EST
Hello,
On 25/11/26 22:27, Elkin Cruz wrote:
> When Magic SysRq-N invokes normalize_rt_tasks(), it holds
> read_lock(&tasklist_lock) in atomic context and calls
> __sched_setscheduler(p, &attr, false, false) with pi == false to reset
> real-time and deadline tasks to SCHED_NORMAL.
>
> For a SCHED_DEADLINE task, dl_policy(p->policy) is true, so
> __sched_setscheduler() calls cpuset_lock() (mutex_lock(&cpuset_mutex))
> while in atomic context under tasklist_lock and then skips
> cpuset_unlock() on exit because unlocking is gated on if (pi), leaving
> cpuset_mutex permanently locked.
>
> Guard cpuset_lock() with pi (matching the non-atomic caller contract,
> where switched_from_dl() releases deadline utilization under rq/dl_bw
> spinlocks) and call cpuset_unlock() on exit whenever cpuset_locked is
> set.
>
> Fixes: 111cd11bbc54 ("sched/cpuset: Bring back cpuset_mutex")
> Signed-off-by: Elkin Cruz <elkin@xxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
> ---
>
> I am trying out new Clang static analysis checks for kernel bug
> classes, and they flagged this code as possibly buggy. The findings
> were triaged/fixed and commit descriptions were drafted with help of AI,
> then checked against linux-next (not runtime-tested on hardware).
Thanks for this, but I believe Mathieu's patch takes care of it already?
https://lore.kernel.org/lkml/9194486f15bb0cb36b51e4525f471d1150c0d58b.1795115075.git.mathieu.desnoyers@xxxxxxxxxxxx/
Best,
Juri