From nobody Fri Dec 19 14:31:17 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 095051A08BC for ; Mon, 7 Apr 2025 21:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060930; cv=none; b=YODA9STjUh/L1YqTIGpSGGJR/ujmZRKoZ9/XJtwH1hNdP1XfbfiS7+Q+1MamSgeR2G22ov6S9ZmvD7qBk3hSI6KJhXNarF+5Rz5xo/kbbq33kTI/JpzRY/WZLxhRXAAVTiSH+nQNpCJ43UpBwjTd1ni9//7KJ4T0sQpvdaO9vek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060930; c=relaxed/simple; bh=YH2klgv1+YNmSwKYe294v1zMFm+mJ3i/FYBHzY7qVpY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mSPW0NfiSOuVYWWGxz8bxOkFBfKJzJZ619G3bhAOO7qw1tABHp9ZvHG+4+S6eDSxRcA73QsXexPGIyi2qIpgQuLz7neSF/tQdQdyzfIpyC1SzU34GXqGQmAU6FSXLNF9zN5y3Ji5216Xzc5qZc0Lb+lFotpTh5NSETy7/nr20dI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NPkWt9uM; arc=none smtp.client-ip=170.10.133.124 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) header.d=redhat.com header.i=@redhat.com header.b="NPkWt9uM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744060928; 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=GvQBB32oIWPf4vbhux4hr6gO5yAT1ux/syBLJoggcGc=; b=NPkWt9uMVbiM8MqCAwVTPbBuWlPtPKQISp7jmYqX9JT9lsWFyquAENOrPonuM/lKIUcL0I KhKpiyOSoox5N9rGOF/JMXa9EwcFgNfdOaf0rNETNJMl1HhtvPhVSmyt15/eeSz8Chm7OP FSFgOMZJAnNKnVEPRh8lJTAJSJNOHmw= Received: from mx-prod-mc-08.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-606-cE3b0L5DOp61xUvvCScDnA-1; Mon, 07 Apr 2025 17:22:06 -0400 X-MC-Unique: cE3b0L5DOp61xUvvCScDnA-1 X-Mimecast-MFC-AGG-ID: cE3b0L5DOp61xUvvCScDnA_1744060925 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 03B78180899B; Mon, 7 Apr 2025 21:22:05 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.90.98]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B23C8180B487; Mon, 7 Apr 2025 21:22:03 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Waiman Long Subject: [PATCH 1/3] cgroup/cpuset: Always use cpu_active_mask Date: Mon, 7 Apr 2025 17:21:03 -0400 Message-ID: <20250407212127.1534285-2-longman@redhat.com> In-Reply-To: <20250407212127.1534285-1-longman@redhat.com> References: <20250407212127.1534285-1-longman@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The current cpuset code uses both cpu_active_mask and cpu_online_mask and it can be confusing which one should be used if we need to update the code. The top_cpuset is always synchronized to cpu_active_mask and we should avoid using cpu_online_mask as much as possible. An active CPU is always an online CPU, but not vice versa. cpu_active_mask and cpu_online_mask can differ during hotplug operations. A CPU is marked active at the last stage of CPU bringup (CPUHP_AP_ACTIVE). It is also the stage where cpuset hotplug code will be called to update the sched domains so that the scheduler can move a normal task to a newly active CPU or remove tasks away from a newly inactivated CPU. The online bit is set much earlier in the CPU bringup process and cleared much later in CPU teardown. If cpu_online_mask is used while a hotunplug operation is happening in parallel, we may leave an offline CPU in cpu_allowed or have a higher chance of leaving an offline CPU in some other masks. Avoid this problem by always using cpu_active_mask in the cpuset code and leave a comment as to why the use of cpu_online_mask is discouraged. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 306b60430091..583f20942802 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -192,6 +192,20 @@ static inline void notify_partition_change(struct cpus= et *cs, int old_prs) WRITE_ONCE(cs->prs_err, PERR_NONE); } =20 +/* + * The top_cpuset is always synchronized to cpu_active_mask and we should = avoid + * using cpu_online_mask as much as possible. An active CPU is always an o= nline + * CPU, but not vice versa. cpu_active_mask and cpu_online_mask can differ + * during hotplug operations. A CPU is marked active at the last stage of = CPU + * bringup (CPUHP_AP_ACTIVE). It is also the stage where cpuset hotplug co= de + * will be called to update the sched domains so that the scheduler can mo= ve + * a normal task to a newly active CPU or remove tasks away from a newly + * inactivated CPU. The online bit is set much earlier in the CPU bringup + * process and cleared much later in CPU teardown. + * + * If cpu_online_mask is used while a hotunplug operation is happening in + * parallel, we may leave an offline CPU in cpu_allowed or some other mask= s. + */ static struct cpuset top_cpuset =3D { .flags =3D BIT(CS_ONLINE) | BIT(CS_CPU_EXCLUSIVE) | BIT(CS_MEM_EXCLUSIVE) | BIT(CS_SCHED_LOAD_BALANCE), @@ -355,18 +369,18 @@ static inline bool partition_is_populated(struct cpus= et *cs, * appropriate cpus. * * One way or another, we guarantee to return some non-empty subset - * of cpu_online_mask. + * of cpu_active_mask. * * Call with callback_lock or cpuset_mutex held. */ -static void guarantee_online_cpus(struct task_struct *tsk, +static void guarantee_active_cpus(struct task_struct *tsk, struct cpumask *pmask) { const struct cpumask *possible_mask =3D task_cpu_possible_mask(tsk); struct cpuset *cs; =20 - if (WARN_ON(!cpumask_and(pmask, possible_mask, cpu_online_mask))) - cpumask_copy(pmask, cpu_online_mask); + if (WARN_ON(!cpumask_and(pmask, possible_mask, cpu_active_mask))) + cpumask_copy(pmask, cpu_active_mask); =20 rcu_read_lock(); cs =3D task_cs(tsk); @@ -2263,7 +2277,7 @@ static int update_cpumask(struct cpuset *cs, struct c= puset *trialcs, bool force =3D false; int old_prs =3D cs->partition_root_state; =20 - /* top_cpuset.cpus_allowed tracks cpu_online_mask; it's read-only */ + /* top_cpuset.cpus_allowed tracks cpu_active_mask; it's read-only */ if (cs =3D=3D &top_cpuset) return -EACCES; =20 @@ -3082,7 +3096,7 @@ static void cpuset_attach_task(struct cpuset *cs, str= uct task_struct *task) lockdep_assert_held(&cpuset_mutex); =20 if (cs !=3D &top_cpuset) - guarantee_online_cpus(task, cpus_attach); + guarantee_active_cpus(task, cpus_attach); else cpumask_andnot(cpus_attach, task_cpu_possible_mask(task), subpartitions_cpus); @@ -4026,7 +4040,7 @@ void __init cpuset_init_smp(void) * * Description: Returns the cpumask_var_t cpus_allowed of the cpuset * attached to the specified @tsk. Guaranteed to return some non-empty - * subset of cpu_online_mask, even if this means going outside the + * subset of cpu_active_mask, even if this means going outside the * tasks cpuset, except when the task is in the top cpuset. **/ =20 @@ -4040,7 +4054,7 @@ void cpuset_cpus_allowed(struct task_struct *tsk, str= uct cpumask *pmask) =20 cs =3D task_cs(tsk); if (cs !=3D &top_cpuset) - guarantee_online_cpus(tsk, pmask); + guarantee_active_cpus(tsk, pmask); /* * Tasks in the top cpuset won't get update to their cpumasks * when a hotplug online/offline event happens. So we include all @@ -4054,7 +4068,7 @@ void cpuset_cpus_allowed(struct task_struct *tsk, str= uct cpumask *pmask) * allowable online cpu left, we fall back to all possible cpus. */ cpumask_andnot(pmask, possible_mask, subpartitions_cpus); - if (!cpumask_intersects(pmask, cpu_online_mask)) + if (!cpumask_intersects(pmask, cpu_active_mask)) cpumask_copy(pmask, possible_mask); } =20 --=20 2.48.1 From nobody Fri Dec 19 14:31:17 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3932821B192 for ; Mon, 7 Apr 2025 21:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060931; cv=none; b=aoYnuKv3uzQ3YHUR4eR04ZUPXgtAPIC34U0WluHi25DmEE/hsyA7T/CdkPodgQ5qzMeqGjI34xB13sLaxg+c0SNKVCQHa43rDsgjxeeSgtc187k61jT31rURjxMg1DzTkR4sbKtRGvliG7UHULOF9RnV2tczHzrFHz4aLhkroe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060931; c=relaxed/simple; bh=EfF4dAbUv6xiHbKdAZn9zu83Y5I8dMHD1u4TY/zaCGM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EgYMAvp5uPvTrbgQK5IKimlAcgGvOLRnRctqp8POlVknAit2LOq/4R1X4hCNroL+Ktx3tb3+8qnGDnvIL/5yK5/+CzbdCxv1/W77M5R/VwwI1kWMXBxO7NdJ9i4mseuBX2ZlTBTjJmmhKhyGWfZdQ+HsQnIX+WOCfsZLq8HMbUI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EQ3hUieP; arc=none smtp.client-ip=170.10.129.124 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) header.d=redhat.com header.i=@redhat.com header.b="EQ3hUieP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744060929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YHK0+caqHkWkmDYmUREBSe8ATHgicW3LTgCek9DEivA=; b=EQ3hUiePWcLV2UqkdB2GAoRrYVzYAahrOw6KmIzzCGXcNju2ofOL1Nw82r4swoQQQWgP1c lSBbhd0xmxFtgJwEE4h/ANpaMs+IQttoZq+2ld/bC/JlbSQkep/DzlnGOkGoXqjYED0czW P8Hq7ZlXdlMCiuO9yVvL3IuJfK4ATOQ= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-R2lktt8sP8uNOuFnpPEyLg-1; Mon, 07 Apr 2025 17:22:08 -0400 X-MC-Unique: R2lktt8sP8uNOuFnpPEyLg-1 X-Mimecast-MFC-AGG-ID: R2lktt8sP8uNOuFnpPEyLg_1744060927 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B685819560BB; Mon, 7 Apr 2025 21:22:06 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.90.98]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4B040180A803; Mon, 7 Apr 2025 21:22:05 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Waiman Long Subject: [PATCH 2/3] cgroup/cpuset: Fix obsolete comment in cpuset_css_offline() Date: Mon, 7 Apr 2025 17:21:04 -0400 Message-ID: <20250407212127.1534285-3-longman@redhat.com> In-Reply-To: <20250407212127.1534285-1-longman@redhat.com> References: <20250407212127.1534285-1-longman@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Move the partition disablement comment from cpuset_css_offline() to cpuset_css_killed() and reword it to remove the remnant of sched.partition. Suggested-by: Michal Koutn=C3=BD Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 583f20942802..1497a2a4b2a3 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -3538,11 +3538,7 @@ static int cpuset_css_online(struct cgroup_subsys_st= ate *css) * will call rebuild_sched_domains_locked(). That is not needed * in the default hierarchy where only changes in partition * will cause repartitioning. - * - * If the cpuset has the 'sched.partition' flag enabled, simulate - * turning 'sched.partition" off. */ - static void cpuset_css_offline(struct cgroup_subsys_state *css) { struct cpuset *cs =3D css_cs(css); @@ -3560,6 +3556,11 @@ static void cpuset_css_offline(struct cgroup_subsys_= state *css) cpus_read_unlock(); } =20 +/* + * If a dying cpuset has the 'cpus.partition' enabled, turn it off by + * changing it back to member to free its exclusive CPUs back to the pool = to + * be used by other online cpusets. + */ static void cpuset_css_killed(struct cgroup_subsys_state *css) { struct cpuset *cs =3D css_cs(css); --=20 2.48.1 From nobody Fri Dec 19 14:31:17 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2380226173 for ; Mon, 7 Apr 2025 21:22:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060935; cv=none; b=a9MgRzw9q2pSCZFisqMLW8I7bmqMPsQpZSxWiPRe8yzSyBDi9UzbxrsIpdTrcI0oxaGnBvTET4ZLhC+zMF1Fe99buWhXyvzS350Zkze7CvX2n556bRAM5LfgllsqGo6sP5WpbuIfXBOSGNDQVZKxWGCJBjWCXnu7xn949H/kJjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060935; c=relaxed/simple; bh=lgWxqBtLH9pJAIx5zVJb3BGHn1TkxNAuETrUPhk326w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ieeiyO41Q1g2DwjKVgrYJasNJ8OT5cqSQZdSINnYdxdOjgTjDSTKsflnjYYnc9V4931CNeEkrrDs1WyrftKIO43o1oSI/pQs76VVf0+x0nI/BeKUchcJYLyTTP/6md0wKid/VUzUsRGQHqGQuWplodVYRugAlG3qrdjwHdYkyNg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=jOOIysrs; arc=none smtp.client-ip=170.10.133.124 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) header.d=redhat.com header.i=@redhat.com header.b="jOOIysrs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744060932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NR/Ky/GsJ2q9CL9cmUdAHPUCzxFT+B+70sC+38xj5+8=; b=jOOIysrsEQLu8UbJTLUwTOmUV2KKoYU9pvYQ4EscTtnB/tZ5vj0+41YW2uBnfIEdVcntzd ykLhQkFGx/+g92FuEgz/hQYvOmPfiCJLTsQ7wdor3Ztu6Y4zPDcBZdtId6ow5789Gf6bgM KUl59m/OYfbuZgZnQCXXOLRoWo6ifhg= Received: from mx-prod-mc-08.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-650-2kV8-peZO2uTnlO-MfBbcQ-1; Mon, 07 Apr 2025 17:22:09 -0400 X-MC-Unique: 2kV8-peZO2uTnlO-MfBbcQ-1 X-Mimecast-MFC-AGG-ID: 2kV8-peZO2uTnlO-MfBbcQ_1744060928 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 72CA9180AF4D; Mon, 7 Apr 2025 21:22:08 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.90.98]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 083C8180B488; Mon, 7 Apr 2025 21:22:06 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Waiman Long Subject: [PATCH 3/3] cgroup/cpuset: Add warnings to catch inconsistency in exclusive CPUs Date: Mon, 7 Apr 2025 17:21:05 -0400 Message-ID: <20250407212127.1534285-4-longman@redhat.com> In-Reply-To: <20250407212127.1534285-1-longman@redhat.com> References: <20250407212127.1534285-1-longman@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Add WARN_ON_ONCE() statements whenever new exclusive CPUs are being added to a partition root to catch inconsistency in the way exclusive CPUs are being handled in the cpuset code. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 43 ++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 1497a2a4b2a3..d0143b3dce47 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1453,13 +1453,15 @@ static int remote_partition_enable(struct cpuset *c= s, int new_prs, * The requested exclusive_cpus must not be allocated to other * partitions and it can't use up all the root's effective_cpus. * - * Note that if there is any local partition root above it or - * remote partition root underneath it, its exclusive_cpus must - * have overlapped with subpartitions_cpus. + * The effective_xcpus mask can contain offline CPUs, but there must + * be at least one or more online CPUs present before it can be enabled. + * + * Note that creating a remote partition with any local partition root + * above it or remote partition root underneath it is not allowed. */ compute_effective_exclusive_cpumask(cs, tmp->new_cpus, NULL); - if (cpumask_empty(tmp->new_cpus) || - cpumask_intersects(tmp->new_cpus, subpartitions_cpus) || + WARN_ON_ONCE(cpumask_intersects(tmp->new_cpus, subpartitions_cpus)); + if (!cpumask_intersects(tmp->new_cpus, cpu_active_mask) || cpumask_subset(top_cpuset.effective_cpus, tmp->new_cpus)) return PERR_INVCPUS; =20 @@ -1555,6 +1557,7 @@ static void remote_cpus_update(struct cpuset *cs, str= uct cpumask *xcpus, * left in the top cpuset. */ if (adding) { + WARN_ON_ONCE(cpumask_intersects(tmp->addmask, subpartitions_cpus)); if (!capable(CAP_SYS_ADMIN)) cs->prs_err =3D PERR_ACCESS; else if (cpumask_intersects(tmp->addmask, subpartitions_cpus) || @@ -1664,7 +1667,7 @@ static int update_parent_effective_cpumask(struct cpu= set *cs, int cmd, bool nocpu; =20 lockdep_assert_held(&cpuset_mutex); - WARN_ON_ONCE(is_remote_partition(cs)); + WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */ =20 /* * new_prs will only be changed for the partcmd_update and @@ -1710,7 +1713,7 @@ static int update_parent_effective_cpumask(struct cpu= set *cs, int cmd, * exclusive_cpus not set. Sibling conflict should only happen * if exclusive_cpus isn't set. */ - xcpus =3D tmp->new_cpus; + xcpus =3D tmp->delmask; if (compute_effective_exclusive_cpumask(cs, xcpus, NULL)) WARN_ON_ONCE(!cpumask_empty(cs->exclusive_cpus)); =20 @@ -1731,9 +1734,20 @@ static int update_parent_effective_cpumask(struct cp= uset *cs, int cmd, if (nocpu) return PERR_NOCPUS; =20 - deleting =3D cpumask_and(tmp->delmask, xcpus, parent->effective_xcpus); - if (deleting) - subparts_delta++; + /* + * This function will only be called when all the preliminary + * checks have passed. At this point, the following condition + * should hold. + * + * (cs->effective_xcpus & cpu_active_mask) =E2=8A=86 parent->effective_c= pus + * + * Warn if it is not the case. + */ + cpumask_and(tmp->new_cpus, xcpus, cpu_active_mask); + WARN_ON_ONCE(!cpumask_subset(tmp->new_cpus, parent->effective_cpus)); + + deleting =3D true; + subparts_delta++; new_prs =3D (cmd =3D=3D partcmd_enable) ? PRS_ROOT : PRS_ISOLATED; } else if (cmd =3D=3D partcmd_disable) { /* @@ -1787,6 +1801,15 @@ static int update_parent_effective_cpumask(struct cp= uset *cs, int cmd, deleting =3D cpumask_and(tmp->delmask, tmp->delmask, parent->effective_xcpus); } + /* + * The new CPUs to be removed from parent's effective CPUs + * must be present. + */ + if (deleting) { + cpumask_and(tmp->new_cpus, tmp->delmask, cpu_active_mask); + WARN_ON_ONCE(!cpumask_subset(tmp->new_cpus, parent->effective_cpus)); + } + /* * Make partition invalid if parent's effective_cpus could * become empty and there are tasks in the parent. --=20 2.48.1