From: Ridong Chen <ridong.chen@linux.dev>
To: "Waiman Long" <longman@redhat.com>, "Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Shuah Khan" <shuah@kernel.org>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Guopeng Zhang <guopeng.zhang@linux.dev>
Subject: Re: [PATCH-next v4 6/6] cgroup/cpuset: Fix lockdep_is_cpuset_held()
Date: Mon, 16 Nov 2026 15:24:59 +0800 [thread overview]
Message-ID: <f5f1ecf6-d33a-4245-a522-34b986a3d7c2@linux.dev> (raw)
In-Reply-To: <20261116012330.2271010-7-longman@redhat.com>
On 11/16/2026 9:23 AM, Waiman Long wrote:
> Commit a84097e625f2 ("cgroup/cpuset: Call housekeeping_update()
> without holding cpus_read_lock") changes lockdep_is_cpuset_held()
> to return true if either cpuset_mutex or cpuset_top_mutex is held.
> lockdep_is_cpuset_held() is used by housekeeping_dereference_check()
> as one of the conditions that rcu_read_lock() is not needed to
> access HK_TYPE_DOMAIN cpumask that can be changed at run time.
> In reality, it should return true only if cpuset_top_mutex is held as
> housekeeping_update() is called with only cpuset_top_mutex held.
>
> If only cpuset_mutex is held, it is possible that there can be a parallel
> housekeeping_update() call leading to a potential use-after-free situation
> when HK_TYPE_DOMAIN housekeeping cpumask is being accessed. It also
> means that rcu_read_lock will be required if only cpuset_mutex is being
> held like when calling from hotplug, scheduler or cgroup.
>
> Fixes: a84097e625f2 ("cgroup/cpuset: Call housekeeping_update() without holding cpus_read_lock")
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
> kernel/cgroup/cpuset-v1.c | 16 ++++++++++------
> kernel/cgroup/cpuset.c | 9 +++++++--
> 2 files changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset-v1.c b/kernel/cgroup/cpuset-v1.c
> index 7c7f2887dfaf..6bf6da639fec 100644
> --- a/kernel/cgroup/cpuset-v1.c
> +++ b/kernel/cgroup/cpuset-v1.c
> @@ -686,6 +686,7 @@ int cpuset1_generate_sched_domains(cpumask_var_t **domains,
> int csn; /* how many cpuset ptrs in csa so far */
> int i, j; /* indices for partition finding loops */
> cpumask_var_t *doms; /* resulting partition; i.e. sched domains */
> + cpumask_var_t hk_cpus; /* HK_TYPE_DOMAIN housekeeping CPUs */
> struct sched_domain_attr *dattr; /* attributes for custom domains */
> int ndoms = 0; /* number of sched domains in result */
> int nslot; /* next empty doms[] struct cpumask slot */
> @@ -698,6 +699,11 @@ int cpuset1_generate_sched_domains(cpumask_var_t **domains,
> dattr = NULL;
> csa = NULL;
>
> + alloc_cpumask_var(&hk_cpus, GFP_KERNEL);
> + scoped_guard(rcu) {
> + cpumask_copy(hk_cpus, housekeeping_cpumask(HK_TYPE_DOMAIN));
> + }
> +
The return value of alloc_cpumask_var() isn't checked. With
CONFIG_CPUMASK_OFFSTACK=y, hk_cpus is NULL on failure. Maybe goto done
like the other allocation failures here?
Also, rebuild_sched_domains() can be called from outside cpuset, e.g.
arch_topology and the energy model, with only cpus_read_lock and
cpuset_mutex held. partition_sched_domains_locked() reads
HK_TYPE_DOMAIN in asym_cpu_capacity_scan() and in its fallback path.
Will these trigger a lockdep warning after this change? If so, do they
need an RCU read lock as well?
> /* Special case for the 99% of systems with one, full, sched domain */
> if (is_sched_load_balance(&top_cpuset)) {
> ndoms = 1;
> @@ -710,9 +716,7 @@ int cpuset1_generate_sched_domains(cpumask_var_t **domains,
> *dattr = SD_ATTR_INIT;
> update_domain_attr_tree(dattr, &top_cpuset);
> }
> - cpumask_and(doms[0], top_cpuset.effective_cpus,
> - housekeeping_cpumask(HK_TYPE_DOMAIN));
> -
> + cpumask_and(doms[0], top_cpuset.effective_cpus, hk_cpus);
> goto done;
> }
>
> @@ -736,8 +740,7 @@ int cpuset1_generate_sched_domains(cpumask_var_t **domains,
> */
> if (!cpumask_empty(cp->cpus_allowed) &&
> !(is_sched_load_balance(cp) &&
> - cpumask_intersects(cp->cpus_allowed,
> - housekeeping_cpumask(HK_TYPE_DOMAIN))))
> + cpumask_intersects(cp->cpus_allowed, hk_cpus)))
> continue;
>
> if (is_sched_load_balance(cp) &&
> @@ -794,7 +797,7 @@ int cpuset1_generate_sched_domains(cpumask_var_t **domains,
> *(dattr + nslot) = SD_ATTR_INIT;
> }
> cpumask_or(dp, dp, csa[j]->effective_cpus);
> - cpumask_and(dp, dp, housekeeping_cpumask(HK_TYPE_DOMAIN));
> + cpumask_and(dp, dp, hk_cpus);
> if (dattr)
> update_domain_attr_tree(dattr + nslot, csa[j]);
> }
> @@ -806,6 +809,7 @@ int cpuset1_generate_sched_domains(cpumask_var_t **domains,
>
> done:
> kfree(csa);
> + free_cpumask_var(hk_cpus);
>
> /*
> * Fallback to the default domain if kmalloc() failed.
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 64cbcbdbf6da..d18439e13bce 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -343,10 +343,13 @@ void cpuset_full_unlock(void)
> }
>
> #ifdef CONFIG_LOCKDEP
> +/*
> + * Holding cpuset_top_mutex will guarantee that a parallel
> + * housekeeping_update() call modifying housekeeping cpumasks is not possible.
> + */
> bool lockdep_is_cpuset_held(void)
> {
> - return lockdep_is_held(&cpuset_mutex) ||
> - lockdep_is_held(&cpuset_top_mutex);
> + return lockdep_is_held(&cpuset_top_mutex);
> }
> #endif
>
> @@ -1416,8 +1419,10 @@ static bool prstate_housekeeping_conflict(int new_prs, int parent_prs,
> }
> }
>
> + rcu_read_lock();
> cpumask_and(full_hk_cpus, housekeeping_cpumask(HK_TYPE_KERNEL_NOISE),
> housekeeping_cpumask(HK_TYPE_DOMAIN));
> + rcu_read_unlock();
> cpumask_andnot(full_hk_cpus, full_hk_cpus, isolated_cpus);
> cpumask_and(full_hk_cpus, full_hk_cpus, cpu_active_mask);
> res = !cpumask_weight_andnot(full_hk_cpus, new_cpus);
--
Best regards
Ridong
prev parent reply other threads:[~2026-11-16 7:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 1:23 [PATCH-next v4 0/6] cgroup/cpuset: More fix patches Waiman Long
2026-11-16 1:23 ` [PATCH-next v4 1/6] cgroup/cpuset: Fix incorrect partition invalidation logic in cpuset_hotplug_update_tasks() Waiman Long
2026-11-16 10:19 ` Guopeng Zhang
2026-11-16 1:23 ` [PATCH-next v4 2/6] cgroup/cpuset: excpus parameter of remote_cpus_update() must have at least 1 active CPU Waiman Long
2026-11-16 3:07 ` Ridong Chen
2026-11-16 3:34 ` Waiman Long
2026-11-16 7:37 ` Ridong Chen
2026-11-16 1:23 ` [PATCH-next v4 3/6] cgroup/cpuset: Check remote partition underneath before making an invalid partition valid Waiman Long
2026-11-16 3:47 ` Ridong Chen
2026-11-16 4:21 ` Waiman Long
2026-11-16 1:23 ` [PATCH-next v4 4/6] cgroup/cpuset: Revert "remove global remote_children list" Waiman Long
2026-11-16 1:23 ` [PATCH-next v4 5/6] cgroup/cpuset: Handle remote partitions before local partitions in cpuset_handle_hotplug() Waiman Long
2026-11-16 7:08 ` Ridong Chen
2026-11-16 8:56 ` kernel test robot
2026-11-16 10:33 ` Guopeng Zhang
2026-11-16 1:23 ` [PATCH-next v4 6/6] cgroup/cpuset: Fix lockdep_is_cpuset_held() Waiman Long
2026-11-16 7:24 ` Ridong Chen [this message]
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=f5f1ecf6-d33a-4245-a522-34b986a3d7c2@linux.dev \
--to=ridong.chen@linux.dev \
--cc=cgroups@vger.kernel.org \
--cc=guopeng.zhang@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mkoutny@suse.com \
--cc=shuah@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®