[PATCH v5 07/12] cpuset: introduce validate_local_partition()
From: Ridong Chen
Date: Sat Nov 14 2026 - 03:32:42 EST
From: Ridong Chen <chenridong@xxxxxxxxxx>
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@xxxxxxxxxx>
---
kernel/cgroup/cpuset.c | 61 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 7a3e797aee52..78ca3c39c029 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1983,6 +1983,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);
+}
+
/**
* update_parent_effective_cpumask - update effective_cpus mask of parent cpuset
* @cs: The cpuset that requests change in partition root state
--
2.34.1