From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.126 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796355334; b=ni354V59vY/5rH29d2Lr2RZoMrItvSAcOHd1/cIgYcP+wSf4R6eqYkOLiz7mNU57KhKY 7KqyBEmlq1PKJmRzMl7jTMTnMcXEsYfVy1VtOXzWhujDIUxHoVlkfQN64tW8EqcUHHz6R TCoBO0sie3W5wgTPPIXW9IpbFAK5oVi+s3mTYOk5hU/ItPo5QHt45nUhi59NsY7L7IkjH Gjttc/Ew6y8/Sh7lr9a8x5+m3synf2T2OWjSIm8J0ywz6EiT0Mv2cOJr5+0FtPqMwlVMO WsfL6bsarsbYdqcU/m3rNzklD6Z0+qhaIPtciFu4dYf+o7DB5RjNSgPP6dIJjYOd72g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796355334; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=MF1ZJxuPPg8L6L6+IFzCx8EqLaejgNow6QHbqHN3Ymo=; b=UCI+Wr8fsvRBHJKpWLGRPaiU02P2e/eMq7/DjgeC5m5Z+xbnNwU+dz46LlgxrDi5UJHA xiiRTZyY6jOHRJb98Ya10YtPlJt/tFUlKKj2u6Q1xY6XpHMx8yWkOa5HJtIXnwIMIaFcv FzPTbuIXK9ZZbmLx9IlIxUWFPbbyg/wgTHxonogled1cRJ/xttgRiAPbr+QtdImhR0HW5 Dqp+BdvC6TpD8fru8XZc2VtP1tJD02NnemfcidxBA3bhZG+S6fNw1OU1i9pDQNxSUi1m6 XYpSEw2gf3nEt0XUz2oaFESTxI2B8ExfmZcSzCCEd9vOSakeZgnGyCPyl257XmOz+tQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=pLVhISuQ; arc=none smtp.remote-ip=91.218.175.126 Received: from mta0.migadu.com (out-126.mta0.migadu.com [91.218.175.126]) (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 4CA01606A322 for ; Fri, 4 Dec 2026 03:35:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4CA01606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=pLVhISuQ X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=HcbLsosqpGgdGxY2NPxf0p/ngXUOO9mGIS0veFcwImY=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796355331; v=1; x=1796960131; b=pLVhISuQjhq7I7PjCH6fUXPImZbqonY8l+Vz4J7VtF+K+DAsmLLbYkAREyWeAIUlmgqsK0sC DO5xtKDnTTURaLKGQCQBh01vZ36qPYpcRUdUsYooOXAHeJ/nsBdbNGaZKLcmNRnRVD+flHVmOYR 1w31YnsZEe30/0RDQRcdzjJ0= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 9d2e481c69df70e0; Fri, 04 Dec 2026 03:35:29 +0000 X-Mizu-Trace-ID: 9d2e481c69df70e0 X-Migadu-Flow: FLOW_OUT Message-ID: Date: Fri, 4 Dec 2026 11:35:23 +0800 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] cgroup/cpuset: Update the parent when a partition switch adds CPUs To: Hang Zhengyang , Waiman Long , Tejun Heo Cc: Johannes Weiner , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Shuah Khan , cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20261203195843.187930-1-hang.zhengyang1010@gmail.com> <20261203195843.187930-2-hang.zhengyang1010@gmail.com> From: Ridong Chen In-Reply-To: <20261203195843.187930-2-hang.zhengyang1010@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/4/2026 3:58 AM, Hang Zhengyang wrote: > When a valid partition is switched between "root" and "isolated", > update_prstate() updates isolated_cpus with the CPUs the partition has > and then calls update_cpumasks_hier(). That recomputes the exclusive > CPUs of the partition with compute_excpus(), which leaves out the > exclusive CPUs of its siblings. If the partition has no > cpuset.cpus.exclusive and a sibling has released exclusive CPUs since > the partition was created, the partition gets them, but they are not > taken from the parent, or from the top cpuset for a remote partition. > update_cpumasks_hier() does that for child partitions, but not for the > cpuset it starts from. > > Example on an 8-CPU system: > > cd /sys/fs/cgroup > echo +cpuset > cgroup.subtree_control > mkdir A1 B1 > echo 3-4 > A1/cpuset.cpus.exclusive > echo 2-5 > B1/cpuset.cpus > echo root > B1/cpuset.cpus.partition # B1: 2,5, root: 0-1,3-4,6-7 > echo > A1/cpuset.cpus.exclusive # B1 is still 2,5 > echo isolated > B1/cpuset.cpus.partition > > B1 now has CPUs 2-5, the root cpuset still has 0-1,3-4,6-7, and > cpuset.cpus.isolated shows only 2,5. Switching from isolated to root > instead makes two load balancing partitions overlap: > > WARNING: kernel/cgroup/cpuset.c:919 at rebuild_sched_domains_locked+0x4f8/0x890 > > The same happens when the sibling was a partition root that became a > member or was removed. A remote partition also triggers a warning in > remote_partition_disable() when it becomes a member later. > > Take the new CPUs after the new state is set, as update_cpumasks_hier() > does for child partitions: with update_parent_effective_cpumask() for a > local partition and with remote_cpus_update() for a remote one. If the > parent can't give them up, for example because it has tasks and no > other CPUs, the partition becomes invalid. > > With this patch, B1 gets CPUs 2-5 in both directions, the root cpuset > keeps 0-1,6-7, and cpuset.cpus.isolated shows 2-5 when B1 is isolated. > > Fixes: 2a3602030d80 ("cgroup/cpuset: Don't invalidate sibling partitions on cpuset.cpus conflict") > Cc: stable@vger.kernel.org # v7.0+ > Signed-off-by: Hang Zhengyang > --- > kernel/cgroup/cpuset.c | 41 +++++++++++++++++++++++++++++++---------- > 1 file changed, 31 insertions(+), 10 deletions(-) > > diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c > index aa82080dd1fa..bc5b0fa5199b 100644 > --- a/kernel/cgroup/cpuset.c > +++ b/kernel/cgroup/cpuset.c > @@ -1909,11 +1909,11 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus, > * update_prstate(). An error code may be returned and the caller will check > * for error. > * > - * The partcmd_update command is used by update_cpumasks_hier() with newmask > - * NULL and update_cpumask() with newmask set. The partcmd_invalidate is used > - * by update_cpumask() with NULL newmask. In both cases, the callers won't > - * check for error and so partition_root_state and prs_err will be updated > - * directly. > + * The partcmd_update command is used by update_cpumasks_hier() and > + * update_prstate() with newmask NULL and update_cpumask() with newmask set. > + * The partcmd_invalidate is used by update_cpumask() with NULL newmask. In > + * both cases, the callers won't check for error and so partition_root_state > + * and prs_err will be updated directly. > */ > static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, > struct cpumask *newmask, > @@ -2081,6 +2081,7 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, > * This can be called from: > * 1) update_cpumasks_hier() > * 2) cpuset_hotplug_update_tasks() > + * 3) update_prstate() > * > * Check to see if it can be transitioned from valid to > * invalid partition or vice versa. > @@ -2213,9 +2214,8 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, > } > > /* > - * For partcmd_update without newmask, it is being called from > - * cpuset_handle_hotplug(). Update the load balance flag and > - * scheduling domain accordingly. > + * For partcmd_update without newmask, update the load balance flag > + * and scheduling domain accordingly. > */ > if ((cmd == partcmd_update) && !newmask) > update_partition_sd_lb(cs, old_prs); > @@ -3008,8 +3008,9 @@ static int update_prstate(struct cpuset *cs, int new_prs) > ? PRS_ROOT : parent->partition_root_state; > > /* > - * A change in load balance state only, no change in cpumasks. > - * Need to update isolated_cpus. > + * A change in load balance state. Need to update isolated_cpus. > + * The cpumasks change only if a sibling has released exclusive > + * CPUs, see below. > */ > if (prstate_housekeeping_conflict(new_prs, parent_prs, > cs->effective_xcpus, NULL)) > @@ -3077,6 +3078,26 @@ static int update_prstate(struct cpuset *cs, int new_prs) > isolated_cpus_update(new_prs, tmpmask.new_cpus); > spin_unlock_irq(&callback_lock); > > + /* > + * A sibling may have released exclusive CPUs since cs became a > + * partition. update_cpumasks_hier() recomputes the effective CPUs of > + * cs and would include them, so take them from the parent, or from > + * the top cpuset for a remote partition, first. This has to come > + * after the new partition state is set so that the new CPUs are > + * accounted with it. If the CPUs can't be given, cs becomes invalid. > + */ > + if (isolcpus_updated) { > + if (is_remote_partition(cs)) { > + compute_excpus(cs, tmpmask.new_cpus); > + if (!cpumask_equal(cs->effective_xcpus, tmpmask.new_cpus)) > + remote_cpus_update(cs, NULL, tmpmask.new_cpus, > + &tmpmask); > + } else { > + update_parent_effective_cpumask(cs, partcmd_update, > + NULL, &tmpmask); > + } > + } > + > /* Force update if partition is disabled & update effective_xcpus */ > update_cpumasks_hier(cs, &tmpmask, disable_partition); > The fix looks correct to me, but it also makes the code more complex. update_prstate() now needs separate local and remote handling for the switch, and update_parent_effective_cpumask() gets one more caller with special cases to document. This would be much simpler to fix on top of my rework series [1]. There the switch is done in partition_switch(), and the fix is just calling local_partition_update(), or remote_cpus_update() for a remote partition, at its beginning. Those helpers already take the new CPUs from the parent and invalidate the partition on failure. [1] https://lore.kernel.org/cgroups/20261101114206.2434398-1-ridong.chen@linux.dev/ -- Best regards Ridong