From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792964734; b=n+fq7+zmgJIj7nClR90OPypJy8nQ8fGlbJbVtkjGII90/+lqFmRKImZDs3wBA3ePUpbA PpJOs8NAMOXwcuKriA+uKyjjiY5+XBhJ2C5I4JWWHJ0NyMZY/fAIzePdLEbx+91Z7f9U8 yOtH9ZRpYxDxVDwGJe8jjGSX/3Akt5MGSv10dXmSclt42DTkwJwvb32nIEKnWCY46qui8 K0ZiClesDG8uWvh8Wzp4yNHp0a3ifdVnJ6qv39oSYG9Qy5oRA3xlCxe4cf8EWceuE9Obh kV6rXXjGAsxuA/rHwm+X+D/FF34zbb5afpr6v1aI+NzcCg0dOfO26UpJKxwMnHmuzCw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792964734; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=hq2/PF+JuIi0SJGOsKa9UMorySX00/w1KvSGJkRcpbE=; b=Ni1bkiXoe3JXqdsgN25a2aCMUMg85PbsBvKFDauTLC7oeTNWHU6wgoXFuDo1MbC7f1C9 88TCH5BA95vM5IoUlMfs2Psvtu66NKDj72hPXWeHTZdm63miO5o+kKv22NWM7AW2oVp1x AxEYJxqJCytrM53pORRnr6JqQDJSgFSdnGm2lYFT9dA+wTrHSD+1Gbl9nr3/GD1KJTHe5 IeOt40Yly9F4dlfPryso7BB8OwUT5K5bK8J7nna4IpBli4twTewfxRvkR8j/0zaANHE4s n8K4lAOTD3KtpyUHIvqXFtQazyk47qqaJKaNuZcfARhQRIgP1tudJ4+nq4Dp/unuQXg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XbhXYr2a; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FD66606A324 for ; Sun, 25 Oct 2026 21:45:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5FD66606A324 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XbhXYr2a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792964733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hq2/PF+JuIi0SJGOsKa9UMorySX00/w1KvSGJkRcpbE=; b=XbhXYr2axYR3zcBDFP1pIVj18BSsPqL0F6GRazkpsQcZ4bgI2/U8kT5KzlNWBEMpWtxNGD 8jArO7UU2gUFLgvMRBCT/vuzxDuFLVCRR/2uxirYgR8f6vb7uaUQ80/eNHHjUNizaQLRnQ uzL414bZBhtzEKDgy2RdrUvtZGOyeus= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-475-8q0vAT8hN1Skg5WDdLb6jw-1; Sun, 25 Oct 2026 17:45:28 -0400 X-MC-Unique: 8q0vAT8hN1Skg5WDdLb6jw-1 X-Mimecast-MFC-AGG-ID: 8q0vAT8hN1Skg5WDdLb6jw_1792964726 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A840C1800615; Sun, 25 Oct 2026 21:45:26 +0000 (UTC) Received: from llong-thinkpadp16vgen1.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 048551956087; Sun, 25 Oct 2026 21:45:24 +0000 (UTC) From: Waiman Long To: Ridong Chen , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Shuah Khan Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Guopeng Zhang , Waiman Long Subject: [PATCH-next v3 08/11] cgroup/cpuset: Release invalid isolated CPUs in compute_partition_effective_cpumask() Date: Sun, 25 Oct 2026 17:44:46 -0400 Message-ID: <20261025214449.310715-9-longman@redhat.com> In-Reply-To: <20261025214449.310715-1-longman@redhat.com> References: <20261025214449.310715-1-longman@redhat.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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 It is found by sashiko that when a child isolated partition with parent root partition is invalidated in compute_partition_effective_cpumask(), the switching of the isolated exclusive CPUs from child to parent will not be reflected in isolated_cpus leading to CPU leakage. Fix that by calling isolated_cpus_update() when that happens. Also simplify compute_partition_effective_cpumask() by doing child partition invalidation only for the special case of no more effective_cpus left in a populated parent. The other case doesn't actually warrant invalidation at this stage and subsequent iteration in update_cpumasks_hier() and update_parent_effective_cpumask() for that child should handle that. Also drop the make_partition_invalid() helper by inlining it into compute_partition_effective_cpumask() as it is the only caller. A new test case is add to test_cpuset_prs.sh to verify this. Fixes: 11e5f407b64a ("cgroup/cpuset: Keep track of CPUs in isolated partitions") Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 46 +++++++------------ .../selftests/cgroup/test_cpuset_prs.sh | 4 ++ 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 53fa3970946e..6d224e614e74 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -254,15 +254,6 @@ static inline bool cs_is_member(const struct cpuset *cs) return cs->partition_root_state == PRS_MEMBER; } -/* - * Callers should hold callback_lock to modify partition_root_state. - */ -static inline void make_partition_invalid(struct cpuset *cs) -{ - if (cs->partition_root_state > 0) - cs->partition_root_state = -cs->partition_root_state; -} - /* * Send notification event of whenever partition_root_state changes. */ @@ -2153,8 +2144,6 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, * or update_cpumasks_hier() where parent and children are modified * successively, we don't need to call update_parent_effective_cpumask() * and the child's effective_cpus will be updated in later iterations. - * - * Note that rcu_read_lock() is assumed to be held. */ static void compute_partition_effective_cpumask(struct cpuset *cs, struct cpumask *new_ecpus) @@ -2166,15 +2155,16 @@ static void compute_partition_effective_cpumask(struct cpuset *cs, WARN_ON_ONCE(!is_partition_valid(cs)); /* - * Check child partition roots to see if they should be - * invalidated when - * 1) child effective_xcpus not a subset of new - * excluisve_cpus - * 2) All the effective_cpus will be used up and cp - * has tasks + * Check child partition roots to see if they should be invalidated + * when all the effective_cpus will be used up and cs is populated. + * It is better to sacrifice a child partition root than invalidating + * the whole subtree. + * + * Return early if the effective_cpus is already empty. */ compute_excpus(cs, new_ecpus); - cpumask_and(new_ecpus, new_ecpus, cpu_active_mask); + if (!cpumask_and(new_ecpus, new_ecpus, cpu_active_mask)) + return; rcu_read_lock(); cpuset_for_each_child(child, css, cs) { @@ -2186,22 +2176,20 @@ static void compute_partition_effective_cpumask(struct cpuset *cs, * partition root. */ WARN_ON_ONCE(is_remote_partition(child)); - WRITE_ONCE(child->prs_err, 0); - if (!cpumask_subset(child->effective_xcpus, - cs->effective_xcpus)) - WRITE_ONCE(child->prs_err, PERR_INVCPUS); - else if (populated && - cpumask_subset(new_ecpus, child->effective_xcpus)) - WRITE_ONCE(child->prs_err, PERR_NOCPUS); - - if (child->prs_err) { + if (populated && cpumask_subset(new_ecpus, child->effective_xcpus)) { int old_prs = child->partition_root_state; + int parent_prs = cs->partition_root_state; /* - * Invalidate child partition + * Invalidate child partition and update isolated_cpus + * if necessary. */ spin_lock_irq(&callback_lock); - make_partition_invalid(child); + WRITE_ONCE(child->prs_err, PERR_NOCPUS); + if ((old_prs == PRS_ISOLATED) && (parent_prs == PRS_ROOT)) + isolated_cpus_update(PRS_ISOLATED, PRS_ROOT, + child->effective_xcpus); + child->partition_root_state = -old_prs; spin_unlock_irq(&callback_lock); notify_partition_change(child, old_prs); continue; diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh index f0d98da3cfd8..d7d0bef0a17a 100755 --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh @@ -518,6 +518,10 @@ TEST_MATRIX=( " CX0-4:P2 CX2-4:P2 CX3-4:P2 . . X2 . . 0 A1:0-1,3-4|A2:2|A3:2 \ A1:P2|A2:P2|A3:P-2 0-4" + # When an isolated partition child with root partition parent is invalidated, + # its effective xcpus will be removed from isolated_cpus. + " C1-4:P1 C3-4:P2 . . T:C3-4 . . . 0 A1:3-4|A2:3-4 A1:P1|A2:P-2 ." + # # old-A1 old-A2 old-A3 old-B1 new-A1 new-A2 new-A3 new-B1 fail ECPUs Pstate ISOLCPUS # ------ ------ ------ ------ ------ ------ ------ ------ ---- ----- ------ -------- -- 2.56.0