All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Matt Fleming" <matt@readmodwrite.com>
Cc: tj@kernel.org, sched-ext@lists.linux.dev, mkoutny@suse.com,
	hannes@cmpxchg.org
Subject: Re: [PATCH] sched_ext: Fix deadlock with PSI trigger creation
Date: Fri, 10 Jul 2026 10:17:31 +0000	[thread overview]
Message-ID: <20260710101732.93C481F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260710100441.2653477-1-matt@readmodwrite.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The patch fixes an ABBA deadlock between `cgroup_mutex` and `scx_fork_rwsem` in `scx_root_enable_workfn()`, but leaves the exact same lock inversion unpatched in `scx_root_disable()`, `scx_sub_disable()`, and `scx_sub_enable_workfn()`.
--

--- Patch [1]: [PATCH] sched_ext: Fix deadlock with PSI trigger creation ---
commit aacffeaa1e10b05888e4970e698ee8d1863dbbbd
Author: Matt Fleming <mfleming@cloudflare.com>

sched_ext: Fix deadlock with PSI trigger creation

This commit fixes an ABBA deadlock between cgroup_mutex and scx_fork_rwsem
in scx_root_enable_workfn(). It prevents deadlocks that can occur when
concurrent writes to cgroup PSI trigger files attempt to create kthreads.

> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 691d53fe0f648..ba89eafe79643 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
> @@ -7193,7 +7193,10 @@ static void scx_root_enable_workfn(struct kthread_work *work)
>  	/*
>  	 * Lock out forks, cgroup on/offlining and moves before opening the
>  	 * floodgate so that they don't wander into the operations prematurely.
> +	 * cgroup_mutex must nest outside scx_fork_rwsem because cgroup file
> +	 * operations may create kthreads while holding cgroup_mutex.
>  	 */
> +	scx_cgroup_lock();
>  	percpu_down_write(&scx_fork_rwsem);

[Severity: High]
This is a pre-existing issue, but does this same lock inversion still exist
in other scheduler functions?

For example, scx_sub_disable() takes scx_fork_rwsem before scx_cgroup_lock():

kernel/sched/ext/ext.c:scx_sub_disable() {
    ...
    percpu_down_write(&scx_fork_rwsem);
    scx_cgroup_lock();
    ...
}

scx_root_disable() also takes the locks in the old order:

kernel/sched/ext/ext.c:scx_root_disable() {
    ...
    percpu_down_write(&scx_fork_rwsem);
    ...
    scx_cgroup_lock();
    ...
}

And scx_sub_enable_workfn() appears to do the same:

kernel/sched/ext/ext.c:scx_sub_enable_workfn() {
    ...
    percpu_down_write(&scx_fork_rwsem);
    scx_cgroup_lock();
    ...
}

Could a concurrent PSI trigger write still cause a deadlock if it races
with these other paths?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260710100441.2653477-1-matt@readmodwrite.com?part=1

  reply	other threads:[~2026-07-10 10:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10 10:04 [PATCH] sched_ext: Fix deadlock with PSI trigger creation Matt Fleming
2026-07-10 10:17 ` sashiko-bot [this message]
2026-07-10 17:46 ` Andrea Righi
2026-07-10 18:24   ` Andrea Righi
2026-07-10 23:49 ` [PATCH cgroup/for-7.2-fixes] cgroup: Create the psimon kthread outside of cgroup_mutex Tejun Heo
2026-07-11  0:04   ` sashiko-bot
2026-07-11  5:54   ` Matt Fleming
2026-07-12 17:49   ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260710101732.93C481F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=matt@readmodwrite.com \
    --cc=mkoutny@suse.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sched-ext@lists.linux.dev \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.