From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.230.113 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796208325; b=J2aLSzPUwi53F7lMbU6OyXOj1QhPc8GGPkky6D+WLwtK24ZcXve1049qQXIr1XYugr4+ syRTsGWcBcOD/hAlLgntaFa3L/zh8sXDFW8+jUVUpFDJCXdSHsW08d1kjLX6AYvHimWZt wCtHyPTPV9v5ZdvwzHm4ehZuavlSv2Dp575pnoyNaw7rb/5U39VywluC4l3KJ9rN3V7UR VBJLjQlejE3ONlp8No48PtzUmDE898ehRY8EECKiFLZsuKnYSiV/FrrGi38QHGCASwm9D pv7mxkXms+HmXwtKG8v7onCWHy3Q1QJlCrI1FzgqNZHrvvTLx6dbX4TRbV+LRxcKhJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796208325; h=DMARC-Filter:DKIM-Signature:Content-Transfer-Encoding:In-Reply-To: X-Lms-Return-Path:Subject:Date:Message-Id:Mime-Version:X-Mailer:To:Cc: X-Original-From:From:References:Content-Type; bh=DWOJGaxC5tFqC2M2LKym/MfLY/YDhSId0B1QKjGjIXk=; b=Eh+WVjCeRyux+oBkB4FXmM/i4zlhmjPWPSX69gjQxShJxB5wGh0jEG1fNM/mF4hG31r4 veqzlD8d/RtXf5ho4NPZirrUDiIHGF86qeKalqy4kSJX9NqKLhB0wCN5Z2CYBGOLEb4oI CgDmFleNIqqtpUvDNi6fTgXuUYsy5dLHoUXoVqTt6SkteF5g8jmBD1Q+DK2neePqb+Q+m 7HZB+YKbFSfZP3HdAemwdmsWLUrBuaI0654B+3jAyFhdXAzbESYhepPq8JQFV3Z/mIWeL tw2VulFS+wpDhxy1CPWtG1bEKzQwNPRVt8O0FGf8iNesGbKTPWQulfMI+kfNA9cocAg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=k1HAoDQ9; arc=none smtp.remote-ip=209.127.230.113 Received: from va-1-113.ptr.blmpb.com (va-1-113.ptr.blmpb.com [209.127.230.113]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA14F606A33A for ; Wed, 2 Dec 2026 10:45:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AA14F606A33A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=k1HAoDQ9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1796208313; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=DWOJGaxC5tFqC2M2LKym/MfLY/YDhSId0B1QKjGjIXk=; b=k1HAoDQ9Wcs/c2BgnAM2XxWJ4woisBFe+P0/mJJ4Ne7T1zyjRktSzv9CDyq5UWwpX/awMh XfDK6XH6FR1aiEpFis7gnNDwVDYYju4FPwIhCZzFHfJ9lAoPFruYMImJRGkOnhRdncCbpv 8NC/tqlcGaECc5ZfHpqRx8EtM7ptBQeF6eJpD5AlirxR9lzL+mhIUXmTYCXqCm8nKk7p3b rM1pc7L+oYeWptA9EkXR3+Sx1rDI3hARbr0qGAum2JDEac57n4Mg9ypES49roT1ZI/ox1e YN3Cwb0WAsv3i9ikdFIxZkGTW2RRcx0S2YueJG2Pa6y5ApCN1z3J0fpBNkY+jw== Content-Transfer-Encoding: 7bit In-Reply-To: X-Lms-Return-Path: Subject: [PATCH 2/2] cgroup/cpuset: Separate v1 and v2 sibling exclusivity checks Date: Wed, 2 Dec 2026 18:44:21 +0800 Message-Id: <11f097daefc2fbc3ca364066d4c344fc75391d69.1796202058.git.zhouchuyi@bytedance.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.20.1 To: , , , , Cc: , "Chuyi Zhou" X-Original-From: Chuyi Zhou From: "Chuyi Zhou" References: Content-Type: text/plain; charset=UTF-8 validate_change() selects the CPU exclusivity rules for each sibling and checks memory exclusivity on both hierarchies. On v1, exclusivity depends on flags and the allowed CPU and memory masks. On v2, the proposed exclusive CPU mask must be disjoint from each sibling's exclusive CPU mask. If the proposed mask changes, it must also leave at least one allowed CPU for each sibling with a nonempty allowed CPU mask. Select the hierarchy once before walking the siblings. Move the v1 CPU and memory checks into cpuset-v1.c and keep the v2 CPU checks together in cpuset.c. Use cpuset_v2() so v1 mounts with the cpuset_v2_mode option retain their v1 exclusivity rules. Suggested-by: Ridong Chen Link: https://lore.kernel.org/r/825c0c94-8565-4c4c-82c7-9c0f5872e6a9@linux.dev Signed-off-by: Chuyi Zhou --- kernel/cgroup/cpuset-internal.h | 6 +-- kernel/cgroup/cpuset-v1.c | 36 +++++++++----- kernel/cgroup/cpuset.c | 88 +++++++++++++-------------------- 3 files changed, 62 insertions(+), 68 deletions(-) diff --git a/kernel/cgroup/cpuset-internal.h b/kernel/cgroup/cpuset-internal.h index b1c8f8fc2edf..84a67bfeae5b 100644 --- a/kernel/cgroup/cpuset-internal.h +++ b/kernel/cgroup/cpuset-internal.h @@ -322,7 +322,7 @@ void cpuset1_hotplug_update_tasks(struct cpuset *cs, struct cpumask *new_cpus, nodemask_t *new_mems, bool cpus_updated, bool mems_updated); int cpuset1_validate_change(struct cpuset *cur, struct cpuset *trial); -bool cpuset1_cpus_excl_conflict(struct cpuset *cs1, struct cpuset *cs2); +bool cpuset1_siblings_excl_conflict(struct cpuset *cur, struct cpuset *trial); void cpuset1_init(struct cpuset *cs); void cpuset1_online_css(struct cgroup_subsys_state *css); int cpuset1_generate_sched_domains(cpumask_var_t **domains, @@ -337,8 +337,8 @@ static inline void cpuset1_hotplug_update_tasks(struct cpuset *cs, bool cpus_updated, bool mems_updated) {} static inline int cpuset1_validate_change(struct cpuset *cur, struct cpuset *trial) { return 0; } -static inline bool cpuset1_cpus_excl_conflict(struct cpuset *cs1, - struct cpuset *cs2) { return false; } +static inline bool cpuset1_siblings_excl_conflict(struct cpuset *cur, + struct cpuset *trial) { return false; } static inline void cpuset1_init(struct cpuset *cs) {} static inline void cpuset1_online_css(struct cgroup_subsys_state *css) {} static inline int cpuset1_generate_sched_domains(cpumask_var_t **domains, diff --git a/kernel/cgroup/cpuset-v1.c b/kernel/cgroup/cpuset-v1.c index e64bbf181faf..babea80f3927 100644 --- a/kernel/cgroup/cpuset-v1.c +++ b/kernel/cgroup/cpuset-v1.c @@ -382,21 +382,35 @@ int cpuset1_validate_change(struct cpuset *cur, struct cpuset *trial) return ret; } -/* - * cpuset1_cpus_excl_conflict() - Check if two cpusets have exclusive CPU conflicts - * to legacy (v1) - * @cs1: first cpuset to check - * @cs2: second cpuset to check +/** + * cpuset1_siblings_excl_conflict - Check v1 sibling CPU and memory exclusivity + * @cur: Cpuset being updated, which must have a parent + * @trial: Copy of @cur with the proposed changes * - * Returns: true if CPU exclusivity conflict exists, false otherwise + * If either cpuset is CPU-exclusive, their allowed CPU masks must be + * disjoint. If either is memory-exclusive, their allowed memory nodes + * must be disjoint. * - * If either cpuset is CPU exclusive, their allowed CPUs cannot intersect. + * Context: Caller holds cpuset_mutex and rcu_read_lock(). + * Return: %true if @trial conflicts with an online sibling, %false otherwise. */ -bool cpuset1_cpus_excl_conflict(struct cpuset *cs1, struct cpuset *cs2) +bool cpuset1_siblings_excl_conflict(struct cpuset *cur, struct cpuset *trial) { - if (is_cpu_exclusive(cs1) || is_cpu_exclusive(cs2)) - return cpumask_intersects(cs1->cpus_allowed, - cs2->cpus_allowed); + struct cgroup_subsys_state *css; + struct cpuset *sibling; + + cpuset_for_each_child(sibling, css, parent_cs(cur)) { + if (sibling == cur) + continue; + + if ((is_cpu_exclusive(trial) || is_cpu_exclusive(sibling)) && + cpumask_intersects(trial->cpus_allowed, sibling->cpus_allowed)) + return true; + + if ((is_mem_exclusive(trial) || is_mem_exclusive(sibling)) && + nodes_intersects(trial->mems_allowed, sibling->mems_allowed)) + return true; + } return false; } diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index d2337f817568..d9fc70f956cf 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -706,39 +706,47 @@ static inline bool cpusets_are_exclusive(struct cpuset *cs1, struct cpuset *cs2) } /** - * cpus_excl_conflict - Check if two cpusets have exclusive CPU conflicts - * @trial: the trial cpuset to be checked - * @sibling: a sibling cpuset to be checked against - * @xcpus_changed: set if exclusive_cpus has been set + * siblings_excl_conflict - Check a cpuset change for sibling conflicts + * @cur: Cpuset being updated, which must have a parent + * @trial: Copy of @cur with the proposed changes * - * Returns: true if CPU exclusivity conflict exists, false otherwise + * On v2, siblings' explicit exclusive CPU masks must be disjoint. A change + * to the exclusive mask must also leave at least one allowed CPU for each + * sibling with a nonempty allowed CPU mask. * - * Conflict detection rules: - * o cgroup v1 - * See cpuset1_cpus_excl_conflict() - * o cgroup v2 - * - The exclusive_cpus values cannot overlap. - * - New exclusive_cpus cannot be a superset of a sibling's cpus_allowed. + * Context: Caller holds cpuset_mutex and rcu_read_lock(). + * Return: %true if @trial conflicts with an online sibling, %false otherwise. */ -static inline bool cpus_excl_conflict(struct cpuset *trial, struct cpuset *sibling, - bool xcpus_changed) +static bool siblings_excl_conflict(struct cpuset *cur, struct cpuset *trial) { + struct cgroup_subsys_state *css; + struct cpuset *sibling; + bool xcpus_changed; + if (!cpuset_v2()) - return cpuset1_cpus_excl_conflict(trial, sibling); + return cpuset1_siblings_excl_conflict(cur, trial); - /* The cpus_allowed of a sibling cpuset cannot be a subset of the new exclusive_cpus */ - if (xcpus_changed && !cpumask_empty(sibling->cpus_allowed) && - cpumask_subset(sibling->cpus_allowed, trial->exclusive_cpus)) - return true; + /* + * On v2 an empty exclusive CPU mask cannot conflict with + * a sibling's CPU masks. Only the top cpuset is memory-exclusive. + */ + if (cpumask_empty(trial->exclusive_cpus)) + return false; - /* Exclusive_cpus cannot intersect */ - return cpumask_intersects(trial->exclusive_cpus, sibling->exclusive_cpus); -} + xcpus_changed = !cpumask_equal(cur->exclusive_cpus, trial->exclusive_cpus); + cpuset_for_each_child(sibling, css, parent_cs(cur)) { + if (sibling == cur) + continue; + + /* New exclusive CPUs must leave siblings with allowed CPUs. */ + if (xcpus_changed && !cpumask_empty(sibling->cpus_allowed) && + cpumask_subset(sibling->cpus_allowed, trial->exclusive_cpus)) + return true; + + if (cpumask_intersects(trial->exclusive_cpus, sibling->exclusive_cpus)) + return true; + } -static inline bool mems_excl_conflict(struct cpuset *cs1, struct cpuset *cs2) -{ - if ((is_mem_exclusive(cs1) || is_mem_exclusive(cs2))) - return nodes_intersects(cs1->mems_allowed, cs2->mems_allowed); return false; } @@ -764,9 +772,6 @@ static inline bool mems_excl_conflict(struct cpuset *cs1, struct cpuset *cs2) int validate_change(struct cpuset *cur, struct cpuset *trial) { - struct cgroup_subsys_state *css; - struct cpuset *c, *par; - bool xcpus_changed; int ret = 0; rcu_read_lock(); @@ -780,8 +785,6 @@ int validate_change(struct cpuset *cur, struct cpuset *trial) if (cur == &top_cpuset) goto out; - par = parent_cs(cur); - /* * We can't shrink if we won't have enough room for SCHED_DEADLINE * tasks. This check is not done when scheduling is disabled as the @@ -805,30 +808,7 @@ int validate_change(struct cpuset *cur, struct cpuset *trial) !cpuset_cpumask_can_shrink(cur->effective_cpus, user_xcpus(trial))) goto out; - /* - * On v2 an empty exclusive CPU mask cannot conflict with - * a sibling's CPU masks. Only the top cpuset is memory-exclusive. - */ - if (cpuset_v2() && cpumask_empty(trial->exclusive_cpus)) - goto valid; - - /* - * If either I or some sibling (!= me) is exclusive, we can't - * overlap. exclusive_cpus cannot overlap with each other if set. - */ - ret = -EINVAL; - xcpus_changed = !cpumask_equal(cur->exclusive_cpus, trial->exclusive_cpus); - cpuset_for_each_child(c, css, par) { - if (c == cur) - continue; - if (cpus_excl_conflict(trial, c, xcpus_changed)) - goto out; - if (mems_excl_conflict(trial, c)) - goto out; - } - -valid: - ret = 0; + ret = siblings_excl_conflict(cur, trial) ? -EINVAL : 0; out: rcu_read_unlock(); return ret; -- 2.20.1