From nobody Wed Feb 11 08:11:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51531C761A6 for ; Tue, 4 Apr 2023 17:07:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233215AbjDDRHH (ORCPT ); Tue, 4 Apr 2023 13:07:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233879AbjDDRHD (ORCPT ); Tue, 4 Apr 2023 13:07:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2977E12D for ; Tue, 4 Apr 2023 10:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680627981; 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=k8j2HkuWn0j0Z7PhnLLGKz76k+59+HcmFbNhPcenFyw=; b=f1dxsfC3FWlFy3tKVjyILA69Aw+t08YMLykOxKfVMdrowLCNXwIgKT3wuUlm3JPmdpkZa7 BK9hZL9ZfjYZ5VbEq9VyM8cfqWE7FK2QKYku714JyhdNtWS5vzKA+iDyaZA7jDy5sKIwbb rSGKCTjyPb/nq7mc7M//jFzrFgL9+oI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-Xrcny9mLNxWYG8y8aIzIeQ-1; Tue, 04 Apr 2023 13:06:17 -0400 X-MC-Unique: Xrcny9mLNxWYG8y8aIzIeQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 16BAF185A790; Tue, 4 Apr 2023 17:06:17 +0000 (UTC) Received: from llong.com (unknown [10.22.32.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9ABDFFD6E; Tue, 4 Apr 2023 17:06:16 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner , Christian Brauner Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Juri Lelli , Dietmar Eggemann , =?UTF-8?q?Michal=20Koutn=C3=BD?= , gscrivan@redhat.com, Waiman Long Subject: [PATCH v2 1/4] cgroup/cpuset: Wake up cpuset_attach_wq tasks in cpuset_cancel_attach() Date: Tue, 4 Apr 2023 13:05:43 -0400 Message-Id: <20230404170546.2585050-2-longman@redhat.com> In-Reply-To: <20230404170546.2585050-1-longman@redhat.com> References: <20230404170546.2585050-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" After a successful cpuset_can_attach() call which increments the attach_in_progress flag, either cpuset_cancel_attach() or cpuset_attach() will be called later. In cpuset_attach(), tasks in cpuset_attach_wq, if present, will be woken up at the end. That is not the case in cpuset_cancel_attach(). So missed wakeup is possible if the attach operation is somehow cancelled. Fix that by doing the wakeup in cpuset_cancel_attach() as well. Fixes: e44193d39e8d ("cpuset: let hotplug propagation work wait for task at= taching") Signed-off-by: Waiman Long Reviewed-by: Michal Koutn=C3=BD --- kernel/cgroup/cpuset.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index bc4dcfd7bee5..066689a7dcc3 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2507,11 +2507,15 @@ static int cpuset_can_attach(struct cgroup_taskset = *tset) static void cpuset_cancel_attach(struct cgroup_taskset *tset) { struct cgroup_subsys_state *css; + struct cpuset *cs; =20 cgroup_taskset_first(tset, &css); + cs =3D css_cs(css); =20 percpu_down_write(&cpuset_rwsem); - css_cs(css)->attach_in_progress--; + cs->attach_in_progress--; + if (!cs->attach_in_progress) + wake_up(&cpuset_attach_wq); percpu_up_write(&cpuset_rwsem); } =20 --=20 2.31.1 From nobody Wed Feb 11 08:11:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3B52C6FD1D for ; Tue, 4 Apr 2023 17:07:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231972AbjDDRH6 (ORCPT ); Tue, 4 Apr 2023 13:07:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235560AbjDDRHv (ORCPT ); Tue, 4 Apr 2023 13:07:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78A4E4496 for ; Tue, 4 Apr 2023 10:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680627986; 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=/4wgT1fYjYVeznO6I+FNrA2iUCmOb49EFy/x6QZ8ObU=; b=V6F6O4A8ODTLyKxsJJpJPjRlWA77Mj1pfexCkjuUkmX9lCdmddflxIMO2Kpu5pwJSDt0NK Pn9Ss+MnRcdcO8NFu85//xz6WIhKGQHMk0bOYAXe8wEiVZ0AQ5cXhQVS+6o7clZER8GwrR BaQSMy9VhM9qfH74jKFlOv5CdLfJe/M= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-56-Q4coWh77MBmmO0wbvhdCRw-1; Tue, 04 Apr 2023 13:06:20 -0400 X-MC-Unique: Q4coWh77MBmmO0wbvhdCRw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8F6F3857FB3; Tue, 4 Apr 2023 17:06:17 +0000 (UTC) Received: from llong.com (unknown [10.22.32.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 231FBFD6E; Tue, 4 Apr 2023 17:06:17 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner , Christian Brauner Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Juri Lelli , Dietmar Eggemann , =?UTF-8?q?Michal=20Koutn=C3=BD?= , gscrivan@redhat.com, Waiman Long Subject: [PATCH v2 2/4] cgroup/cpuset: Make cpuset_fork() handle CLONE_INTO_CGROUP properly Date: Tue, 4 Apr 2023 13:05:44 -0400 Message-Id: <20230404170546.2585050-3-longman@redhat.com> In-Reply-To: <20230404170546.2585050-1-longman@redhat.com> References: <20230404170546.2585050-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" By default, the clone(2) syscall spawn a child process into the same cgroup as its parent. With the use of the CLONE_INTO_CGROUP flag introduced by commit ef2c41cf38a7 ("clone3: allow spawning processes into cgroups"), the child will be spawned into a different cgroup which is somewhat similar to writing the child's tid into "cgroup.threads". The current cpuset_fork() method does not properly handle the CLONE_INTO_CGROUP case where the cpuset of the child may be different from that of its parent. Update the cpuset_fork() method to treat the CLONE_INTO_CGROUP case similar to cpuset_attach(). Since the newly cloned task has not been running yet, its actual memory usage isn't known. So it is not necessary to make change to mm in cpuset_fork(). Fixes: ef2c41cf38a7 ("clone3: allow spawning processes into cgroups") Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 56 +++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 066689a7dcc3..dc82f753373e 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2520,16 +2520,33 @@ static void cpuset_cancel_attach(struct cgroup_task= set *tset) } =20 /* - * Protected by cpuset_rwsem. cpus_attach is used only by cpuset_attach() + * Protected by cpuset_rwsem. cpus_attach is used only by cpuset_attach_ta= sk() * but we can't allocate it dynamically there. Define it global and * allocate from cpuset_init(). */ static cpumask_var_t cpus_attach; +static nodemask_t cpuset_attach_nodemask_to; + +static void cpuset_attach_task(struct cpuset *cs, struct task_struct *task) +{ + percpu_rwsem_assert_held(&cpuset_rwsem); + + if (cs !=3D &top_cpuset) + guarantee_online_cpus(task, cpus_attach); + else + cpumask_copy(cpus_attach, task_cpu_possible_mask(task)); + /* + * can_attach beforehand should guarantee that this doesn't + * fail. TODO: have a better way to handle failure here + */ + WARN_ON_ONCE(set_cpus_allowed_ptr(task, cpus_attach)); + + cpuset_change_task_nodemask(task, &cpuset_attach_nodemask_to); + cpuset_update_task_spread_flags(cs, task); +} =20 static void cpuset_attach(struct cgroup_taskset *tset) { - /* static buf protected by cpuset_rwsem */ - static nodemask_t cpuset_attach_nodemask_to; struct task_struct *task; struct task_struct *leader; struct cgroup_subsys_state *css; @@ -2560,20 +2577,8 @@ static void cpuset_attach(struct cgroup_taskset *tse= t) =20 guarantee_online_mems(cs, &cpuset_attach_nodemask_to); =20 - cgroup_taskset_for_each(task, css, tset) { - if (cs !=3D &top_cpuset) - guarantee_online_cpus(task, cpus_attach); - else - cpumask_copy(cpus_attach, task_cpu_possible_mask(task)); - /* - * can_attach beforehand should guarantee that this doesn't - * fail. TODO: have a better way to handle failure here - */ - WARN_ON_ONCE(set_cpus_allowed_ptr(task, cpus_attach)); - - cpuset_change_task_nodemask(task, &cpuset_attach_nodemask_to); - cpuset_update_task_spread_flags(cs, task); - } + cgroup_taskset_for_each(task, css, tset) + cpuset_attach_task(cs, task); =20 /* * Change mm for all threadgroup leaders. This is expensive and may @@ -3271,11 +3276,22 @@ static void cpuset_bind(struct cgroup_subsys_state = *root_css) */ static void cpuset_fork(struct task_struct *task) { - if (task_css_is_root(task, cpuset_cgrp_id)) + struct cpuset *cs =3D task_cs(task); + + if (cs =3D=3D task_cs(current)) { + if (cs =3D=3D &top_cpuset) + return; + + set_cpus_allowed_ptr(task, current->cpus_ptr); + task->mems_allowed =3D current->mems_allowed; return; + } =20 - set_cpus_allowed_ptr(task, current->cpus_ptr); - task->mems_allowed =3D current->mems_allowed; + /* CLONE_INTO_CGROUP */ + percpu_down_write(&cpuset_rwsem); + guarantee_online_mems(cs, &cpuset_attach_nodemask_to); + cpuset_attach_task(cs, task); + percpu_up_write(&cpuset_rwsem); } =20 struct cgroup_subsys cpuset_cgrp_subsys =3D { --=20 2.31.1 From nobody Wed Feb 11 08:11:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E3E5C761A6 for ; Tue, 4 Apr 2023 17:07:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233879AbjDDRHN (ORCPT ); Tue, 4 Apr 2023 13:07:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235456AbjDDRHI (ORCPT ); Tue, 4 Apr 2023 13:07:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC8F81BC9 for ; Tue, 4 Apr 2023 10:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680627984; 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=+e6sqRHNS3qAQLVSnMsuMIX+XPuRaTp7/RZUmzbwZM0=; b=GL6uhdaR08hVo4JMChmDa5kQviRlhl711rGtgvKsD554M8yOm6lvM4pZSPfYQivhTz2PxI vTceDANCY95fsSVbMs0EPV7vVWBRYyuRHw8FQI14MDk5wyhTqLHAdkJgD23lLMorEXp2+8 feQSeYb5Q/xDUdE1lw77BdAZ6ZnAlko= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-313-wffusJxgNTO3I_GzG5OjSg-1; Tue, 04 Apr 2023 13:06:18 -0400 X-MC-Unique: wffusJxgNTO3I_GzG5OjSg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 16AFF85A5B1; Tue, 4 Apr 2023 17:06:18 +0000 (UTC) Received: from llong.com (unknown [10.22.32.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BC93FD6E; Tue, 4 Apr 2023 17:06:17 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner , Christian Brauner Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Juri Lelli , Dietmar Eggemann , =?UTF-8?q?Michal=20Koutn=C3=BD?= , gscrivan@redhat.com, Waiman Long Subject: [PATCH v2 3/4] cgroup/cpuset: Add cpuset_can_fork() and cpuset_cancel_fork() methods Date: Tue, 4 Apr 2023 13:05:45 -0400 Message-Id: <20230404170546.2585050-4-longman@redhat.com> In-Reply-To: <20230404170546.2585050-1-longman@redhat.com> References: <20230404170546.2585050-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In the case of CLONE_INTO_CGROUP, not all cpusets are ready to accept new tasks. It is too late to check that in cpuset_fork(). So we need to add the cpuset_can_fork() and cpuset_cancel_fork() methods to pre-check it before we can allow attachment to a different cpuset. We also need to set the attach_in_progress flag to alert other code that a new task is going to be added to the cpuset. Fixes: ef2c41cf38a7 ("clone3: allow spawning processes into cgroups") Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 87 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 11 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index dc82f753373e..db1fca5cba06 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2458,6 +2458,20 @@ static int fmeter_getrate(struct fmeter *fmp) =20 static struct cpuset *cpuset_attach_old_cs; =20 +/* + * Check to see if a cpuset can accept a new task + * For v1, cpus_allowed and mems_allowed can't be empty. + * For v2, effective_cpus can't be empty. + * Note that in v1, effective_cpus =3D cpus_allowed. + */ +static int cpuset_can_attach_check(struct cpuset *cs) +{ + if (cpumask_empty(cs->effective_cpus) || + (!is_in_v2_mode() && nodes_empty(cs->mems_allowed))) + return -ENOSPC; + return 0; +} + /* Called by cgroups to determine if a cpuset is usable; cpuset_rwsem held= */ static int cpuset_can_attach(struct cgroup_taskset *tset) { @@ -2472,16 +2486,9 @@ static int cpuset_can_attach(struct cgroup_taskset *= tset) =20 percpu_down_write(&cpuset_rwsem); =20 - /* allow moving tasks into an empty cpuset if on default hierarchy */ - ret =3D -ENOSPC; - if (!is_in_v2_mode() && - (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed))) - goto out_unlock; - - /* - * Task cannot be moved to a cpuset with empty effective cpus. - */ - if (cpumask_empty(cs->effective_cpus)) + /* Check to see if task is allowed in the cpuset */ + ret =3D cpuset_can_attach_check(cs); + if (ret) goto out_unlock; =20 cgroup_taskset_for_each(task, css, tset) { @@ -2498,7 +2505,6 @@ static int cpuset_can_attach(struct cgroup_taskset *t= set) * changes which zero cpus/mems_allowed. */ cs->attach_in_progress++; - ret =3D 0; out_unlock: percpu_up_write(&cpuset_rwsem); return ret; @@ -3269,6 +3275,58 @@ static void cpuset_bind(struct cgroup_subsys_state *= root_css) percpu_up_write(&cpuset_rwsem); } =20 +/* + * In case the child is cloned into a cpuset different from its parent, + * additional checks are done to see if the move is allowed. + */ +static int cpuset_can_fork(struct task_struct *task, struct css_set *cset) +{ + struct cpuset *cs =3D css_cs(cset->subsys[cpuset_cgrp_id]); + int ret; + + if (cs =3D=3D task_cs(current)) + return 0; + + lockdep_assert_held(&cgroup_mutex); + percpu_down_write(&cpuset_rwsem); + + /* Check to see if task is allowed in the cpuset */ + ret =3D cpuset_can_attach_check(cs); + if (ret) + goto out_unlock; + + ret =3D task_can_attach(task, cs->effective_cpus); + if (ret) + goto out_unlock; + + ret =3D security_task_setscheduler(task); + if (ret) + goto out_unlock; + + /* + * Mark attach is in progress. This makes validate_change() fail + * changes which zero cpus/mems_allowed. + */ + cs->attach_in_progress++; +out_unlock: + percpu_up_write(&cpuset_rwsem); + return ret; +} + +static void cpuset_cancel_fork(struct task_struct *task, struct css_set *c= set) +{ + struct cpuset *cs =3D css_cs(cset->subsys[cpuset_cgrp_id]); + + if (cs =3D=3D task_cs(current)) + return; + + percpu_down_write(&cpuset_rwsem); + cs->attach_in_progress--; + if (!cs->attach_in_progress) + wake_up(&cpuset_attach_wq); + percpu_up_write(&cpuset_rwsem); +} + /* * Make sure the new task conform to the current state of its parent, * which could have been changed by cpuset just after it inherits the @@ -3291,6 +3349,11 @@ static void cpuset_fork(struct task_struct *task) percpu_down_write(&cpuset_rwsem); guarantee_online_mems(cs, &cpuset_attach_nodemask_to); cpuset_attach_task(cs, task); + + cs->attach_in_progress--; + if (!cs->attach_in_progress) + wake_up(&cpuset_attach_wq); + percpu_up_write(&cpuset_rwsem); } =20 @@ -3304,6 +3367,8 @@ struct cgroup_subsys cpuset_cgrp_subsys =3D { .attach =3D cpuset_attach, .post_attach =3D cpuset_post_attach, .bind =3D cpuset_bind, + .can_fork =3D cpuset_can_fork, + .cancel_fork =3D cpuset_cancel_fork, .fork =3D cpuset_fork, .legacy_cftypes =3D legacy_files, .dfl_cftypes =3D dfl_files, --=20 2.31.1 From nobody Wed Feb 11 08:11:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78438C6FD1D for ; Tue, 4 Apr 2023 17:07:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235643AbjDDRHz (ORCPT ); Tue, 4 Apr 2023 13:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235305AbjDDRHu (ORCPT ); Tue, 4 Apr 2023 13:07:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0F2044BB for ; Tue, 4 Apr 2023 10:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680627990; 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=kw9bOB+w9RaCMC/2ecbxmrC9gMAMXWH6G3Pa3TXU2lQ=; b=R6vihc0qA8EJY1CEKmTG67PyWH9XY5ytO2kFekQ2/XQxdDQCcAiX3sAOGtLk2msbg9PQ00 7gTrr040rNCvELVQ4jNDi9wBBh/1h3W7RDFYT7CEV0nOewJ7gyK+a+ANdQ0WQuJZxwrp95 pd8odFJf74Atl/u+6TasSaog4lvtDTU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-122-5HyO8yuwOo-sQk7DTiQ7Nw-1; Tue, 04 Apr 2023 13:06:26 -0400 X-MC-Unique: 5HyO8yuwOo-sQk7DTiQ7Nw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 95CBF1C06ED5; Tue, 4 Apr 2023 17:06:18 +0000 (UTC) Received: from llong.com (unknown [10.22.32.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 231BCFD6E; Tue, 4 Apr 2023 17:06:18 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner , Christian Brauner Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Juri Lelli , Dietmar Eggemann , =?UTF-8?q?Michal=20Koutn=C3=BD?= , gscrivan@redhat.com, Waiman Long Subject: [PATCH v2 4/4] cgroup/cpuset: Make cpuset_attach_task() skip subpartitions CPUs for top_cpuset Date: Tue, 4 Apr 2023 13:05:46 -0400 Message-Id: <20230404170546.2585050-5-longman@redhat.com> In-Reply-To: <20230404170546.2585050-1-longman@redhat.com> References: <20230404170546.2585050-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is found that attaching a task to the top_cpuset does not currently ignore CPUs allocated to subpartitions in cpuset_attach_task(). So the code is changed to fix that. Signed-off-by: Waiman Long Reviewed-by: Michal Koutn=C3=BD --- kernel/cgroup/cpuset.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index db1fca5cba06..056ec7dbfa3c 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2540,7 +2540,8 @@ static void cpuset_attach_task(struct cpuset *cs, str= uct task_struct *task) if (cs !=3D &top_cpuset) guarantee_online_cpus(task, cpus_attach); else - cpumask_copy(cpus_attach, task_cpu_possible_mask(task)); + cpumask_andnot(cpus_attach, task_cpu_possible_mask(task), + cs->subparts_cpus); /* * can_attach beforehand should guarantee that this doesn't * fail. TODO: have a better way to handle failure here --=20 2.31.1