Linux cgroups development
 help / color / mirror / Atom feed
From: Guopeng Zhang <guopeng.zhang@linux.dev>
To: "Ridong Chen" <ridong.chen@linux.dev>,
	"Waiman Long" <longman@redhat.com>, "Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ridong Chen <chenridong@xiaomi.com>
Subject: Re: [PATCH v6 07/12] cpuset: introduce validate_local_partition()
Date: Sat, 5 Dec 2026 15:51:03 +0800	[thread overview]
Message-ID: <d37d8936-ca87-4876-990b-9222d4b0562f@linux.dev> (raw)
In-Reply-To: <20261129024431.2485721-8-ridong.chen@linux.dev>



在 2026/11/29 10:44, Ridong Chen 写道:
> From: Ridong Chen <chenridong@xiaomi.com>
> 
> Add validate_local_partition() to check the requirements of a local
> partition in one place, so that local partition enablement and update
> can share it:
> 
> 1. The parent must be a valid partition root, otherwise PERR_INVPARENT
>    or PERR_NOTPART is returned.
> 2. If both cpuset.cpus and cpuset.cpus.exclusive are empty, return
>    PERR_CPUSEMPTY rather than reporting an invalid cpu list.
> 3. A root partition is not allowed under an isolated parent.
> 4. Optionally, the user exclusive CPUs must not overlap with any
>    sibling. A valid partition has passed this check already, so it is
>    only needed when an invalid partition is to become valid again.
> 5. validate_partition() for the common checks, including the
>    housekeeping conflict and tasks_nocpu_error() checks.
> 
> It is marked __maybe_unused until local_partition_enable() starts to
> use it in the next patch.
> 
> Signed-off-by: Ridong Chen <chenridong@xiaomi.com>
> ---
>  kernel/cgroup/cpuset.c | 61 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
> 
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 39d5b56f14b0..a3b3a3fe63ff 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1989,6 +1989,67 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus,
>  	partition_disable(cs, -prs, cs->prs_err, tmp);
>  }
>  
> +static bool is_user_xcpus_exclusive(struct cpuset *cs)
> +{
> +	struct cpuset *parent = parent_cs(cs);
> +	struct cgroup_subsys_state *css;
> +	struct cpuset *child;
> +	bool exclusive = true;
> +
> +	rcu_read_lock();
> +	cpuset_for_each_child(child, css, parent) {
> +		if (child == cs)
> +			continue;
> +		if (!cpusets_are_exclusive(cs, child)) {
> +			exclusive = false;
> +			break;
> +		}
> +	}
> +	rcu_read_unlock();
> +	return exclusive;
> +}
> +
> +/**
> + * validate_local_partition - Validate for local partition
> + * @cs: Target cpuset to validate
> + * @new_prs: New partition root state to validate
> + * @excpus: New effective exclusive CPUs mask to validate
> + * @excl_check: Flag to enable exclusive CPUs ownership validation
> + * @tmp: Temporary masks
> + *
> + * Return: PERR_NONE if validation passes, appropriate error code otherwise
> + *
> + * Important: The caller must ensure that @cs's cpu mask is updated before
> + * invoking this function when exclusive CPU validation is required.
> + */
> +static enum prs_errcode __maybe_unused
> +validate_local_partition(struct cpuset *cs, int new_prs,
> +			 struct cpumask *excpus, bool excl_check,
> +			 struct tmpmasks *tmp)
> +{
> +	struct cpuset *parent = parent_cs(cs);
> +
> +	/* The parent must be a partition root */
> +	if (!is_partition_valid(parent)) {
> +		return is_partition_invalid(parent)
> +			? PERR_INVPARENT : PERR_NOTPART;
> +	}
> +
> +	/* Report the empty user cpumasks instead of an invalid cpu list */
> +	if (cpumask_empty(excpus) && xcpus_empty(cs))
> +		return PERR_CPUSEMPTY;
> +
> +	/* A root partition is not allowed under an isolated parent */
> +	if (new_prs == PRS_ROOT && parent->partition_root_state == PRS_ISOLATED)
> +		return PERR_ISOPARENT;
> +
> +	if (excl_check && !is_user_xcpus_exclusive(cs))
> +		return PERR_NOTEXCL;
> +
> +	return validate_partition(cs, parent, new_prs, excpus,
> +				  tmp ? tmp->delmask : NULL);

Hi Ridong,

I noticed that in this series, the last argument of
validate_local_partition() is NULL in the enable path and tmp in the
update path. When tmp is non-NULL, the function only uses tmp->delmask.

Would it make sense to take a struct cpumask *delmask directly instead
of struct tmpmasks *tmp? The enable path could still pass NULL, while
the update path could pass tmp->delmask directly.

Would this make the interface clearer about which CPU mask is actually
needed?

Thanks,
Guopeng

> +}
> +
>  /**
>   * update_parent_effective_cpumask - update effective_cpus mask of parent cpuset
>   * @cs:      The cpuset that requests change in partition root state


  reply	other threads:[~2026-12-05  7:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  2:44 [PATCH v6 00/12] cpuset: rework local partition logic Ridong Chen
2026-11-29  2:44 ` [PATCH v6 01/12] cpuset: introduce partition_enable() Ridong Chen
2026-12-05  4:20   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 02/12] cpuset: introduce partition_disable() Ridong Chen
2026-12-05  4:20   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 03/12] cpuset: introduce partition_update() Ridong Chen
2026-12-05  4:20   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 04/12] cpuset: use partition_enable() for remote partition enablement Ridong Chen
2026-12-05  4:21   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 05/12] cpuset: use partition_disable() for remote partition disablement Ridong Chen
2026-12-01  3:16   ` Waiman Long
2026-12-01 12:16     ` Ridong Chen
2026-11-29  2:44 ` [PATCH v6 06/12] cpuset: use partition_update() for remote partition update Ridong Chen
2026-12-05  4:50   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 07/12] cpuset: introduce validate_local_partition() Ridong Chen
2026-12-05  7:51   ` Guopeng Zhang [this message]
2026-11-29  2:44 ` [PATCH v6 08/12] cpuset: introduce local_partition_enable() Ridong Chen
2026-12-05  7:52   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 09/12] cpuset: use partition_disable() for local partition disablement Ridong Chen
2026-12-05  7:53   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 10/12] cpuset: use partition_disable() to invalidate local partition Ridong Chen
2026-11-29  2:44 ` [PATCH v6 11/12] cpuset: introduce local_partition_update() Ridong Chen
2026-11-29  2:44 ` [PATCH v6 12/12] cpuset: remove update_parent_effective_cpumask Ridong Chen
2026-12-04  3:49 ` [PATCH v6 00/12] cpuset: rework local partition logic Ridong Chen

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=d37d8936-ca87-4876-990b-9222d4b0562f@linux.dev \
    --to=guopeng.zhang@linux.dev \
    --cc=cgroups@vger.kernel.org \
    --cc=chenridong@xiaomi.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mkoutny@suse.com \
    --cc=ridong.chen@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox