lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250828125631.1978176-8-chenridong@huaweicloud.com>
Date: Thu, 28 Aug 2025 12:56:27 +0000
From: Chen Ridong <chenridong@...weicloud.com>
To: longman@...hat.com,
	tj@...nel.org,
	hannes@...xchg.org,
	mkoutny@...e.com
Cc: cgroups@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	lujialin4@...wei.com,
	chenridong@...wei.com
Subject: [PATCH -next RFC 07/11] cpuset: refactor out invalidate_cs_partition

From: Chen Ridong <chenridong@...wei.com>

Refactor the invalidate_cs_partition function to handle cpuset partition
invalidation when modifying cpuset.cpus. This refactoring also makes the
function reusable for handling cpuset.cpus.exclusive updates in subsequent
patches.

Signed-off-by: Chen Ridong <chenridong@...wei.com>
---
 kernel/cgroup/cpuset.c | 49 +++++++++++++++++++++++++++++++-----------
 1 file changed, 36 insertions(+), 13 deletions(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 5cfc53fe717c..71190f142700 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -2376,6 +2376,40 @@ static int parse_cpulist(const char *buf, struct cpumask *out_mask)
 	return 0;
 }
 
+/**
+ * invalidate_cs_partition - Validate and mark the validity of a cpuset partition configuration
+ * @cs: The cpuset to validate
+ * This function checks multiple constraints for a cpuset partition configuration.
+ * If any check fails, it sets the appropriate error code in the cpuset and returns true.
+ * Mainly used to ensure correctness and consistency of partition configurations.
+ * Return: true if the configuration is invalid, false if valid.
+ */
+static bool invalidate_cs_partition(struct cpuset *cs)
+{
+	struct cpuset *parent = parent_cs(cs);
+
+	if (cs_is_member(cs))
+		return false;
+
+	if (cpumask_empty(cs->effective_xcpus)) {
+		cs->prs_err = PERR_INVCPUS;
+		return true;
+	}
+
+	if (prstate_housekeeping_conflict(cs->partition_root_state,
+					  cs->effective_xcpus)) {
+		cs->prs_err = PERR_HKEEPING;
+		return true;
+	}
+
+	if (tasks_nocpu_error(parent, cs, cs->effective_xcpus)) {
+		cs->prs_err = PERR_NOCPUS;
+		return true;
+	}
+
+	return false;
+}
+
 /**
  * update_cpumask - update the cpus_allowed mask of a cpuset and all tasks in it
  * @cs: the cpuset to consider
@@ -2405,19 +2439,8 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
 
 	compute_trialcs_excpus(trialcs, cs);
 
-	if (old_prs) {
-		if (is_partition_valid(cs) &&
-		    cpumask_empty(trialcs->effective_xcpus)) {
-			invalidate = true;
-			cs->prs_err = PERR_INVCPUS;
-		} else if (prstate_housekeeping_conflict(old_prs, trialcs->effective_xcpus)) {
-			invalidate = true;
-			cs->prs_err = PERR_HKEEPING;
-		} else if (tasks_nocpu_error(parent, cs, trialcs->effective_xcpus)) {
-			invalidate = true;
-			cs->prs_err = PERR_NOCPUS;
-		}
-	}
+	invalidate = invalidate_cs_partition(trialcs);
+	cs->prs_err = trialcs->prs_err;
 
 	/*
 	 * Check all the descendants in update_cpumasks_hier() if
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ