From: Chen Ridong <chenridong@huaweicloud.com>
To: "Waiman Long" <longman@redhat.com>,
"Chen Ridong" <chenridong@huawei.com>,
"Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] cgroup/cpuset: Skip security check for hotplug induced v1 task migration
Date: Mon, 30 Mar 2026 09:48:46 +0800 [thread overview]
Message-ID: <c80c6838-e33e-4e5c-82ac-9bfa4d012dcb@huaweicloud.com> (raw)
In-Reply-To: <20260329173958.2634925-3-longman@redhat.com>
On 2026/3/30 1:39, Waiman Long wrote:
> When a CPU hot removal causes a v1 cpuset to lose all its CPUs, the
> cpuset hotplug handler will schedule a work function to migrate tasks
> in that cpuset with no CPU to its ancestor to enable those tasks to
> continue running.
>
> If a strict security policy is in place, however, the task migration
> may fail when security_task_setscheduler() call in cpuset_can_attach()
> returns a -EACCESS error. That will mean that those tasks will have
> no CPU to run on. The system administrators will have to explicitly
> intervene to either add CPUs to that cpuset or move the tasks elsewhere
> if they are aware of it.
>
> This problem was found by a reported test failure in the LTP's
> cpuset_hotplug_test.sh. Fix this problem by treating this special case
> as an exception to skip the setsched security check as it is initated
> internally within the kernel itself instead of from user input. Do that
> by setting a new one-off CS_TASKS_OUT flag in the affected cpuset by the
> hotplug handler to allow cpuset_can_attach() to skip the security check.
>
> With that patch applied, the cpuset_hotplug_test.sh test can be run
> successfully without failure.
>
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
> kernel/cgroup/cpuset-internal.h | 1 +
> kernel/cgroup/cpuset-v1.c | 3 +++
> kernel/cgroup/cpuset.c | 14 ++++++++++++++
> 3 files changed, 18 insertions(+)
>
> diff --git a/kernel/cgroup/cpuset-internal.h b/kernel/cgroup/cpuset-internal.h
> index fd7d19842ded..75e2c20249ad 100644
> --- a/kernel/cgroup/cpuset-internal.h
> +++ b/kernel/cgroup/cpuset-internal.h
> @@ -46,6 +46,7 @@ typedef enum {
> CS_SCHED_LOAD_BALANCE,
> CS_SPREAD_PAGE,
> CS_SPREAD_SLAB,
> + CS_TASKS_OUT,
> } cpuset_flagbits_t;
>
> /* The various types of files and directories in a cpuset file system */
> diff --git a/kernel/cgroup/cpuset-v1.c b/kernel/cgroup/cpuset-v1.c
> index 7308e9b02495..0c818edd0a1d 100644
> --- a/kernel/cgroup/cpuset-v1.c
> +++ b/kernel/cgroup/cpuset-v1.c
> @@ -322,6 +322,9 @@ void cpuset1_hotplug_update_tasks(struct cpuset *cs,
> return;
> }
>
> + /* Enable task removal without security check */
> + set_bit(CS_TASKS_OUT, &cs->flags);
> +
> s->cs = cs;
> INIT_WORK(&s->work, cpuset_migrate_tasks_workfn);
> schedule_work(&s->work);
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 58c5b7b72cca..24d3ceef7991 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -3011,6 +3011,20 @@ static int cpuset_can_attach(struct cgroup_taskset *tset)
> setsched_check = !cpuset_v2() ||
> !cpumask_equal(cs->effective_cpus, oldcs->effective_cpus) ||
> !nodes_equal(cs->effective_mems, oldcs->effective_mems);
> + /*
> + * Also check if task migration away from the old cpuset is allowed
> + * without security check. This bit should only be set by the hotplug
> + * handler when task migration from a child v1 cpuset to its ancestor
> + * is needed because there is no CPU left for the tasks to run on after
> + * a hot CPU removal. Clear the bit if set as it is one-off. Also
> + * doube-check the CPU emptiness of oldcs to be sure before clearing
> + * setsched_check.
> + */
> + if (test_bit(CS_TASKS_OUT, &oldcs->flags)) {
> + if (cpumask_empty(oldcs->effective_cpus))
> + setsched_check = false;
> + clear_bit(CS_TASKS_OUT, &oldcs->flags);
> + }
>
If there are many tasks in the cpuset that has no CPUs, they will be migrated
one by one. I'm afraid that only the first task will succeed, and the rest will
fail because the flag is cleared after processing the first one.
--
Best regards,
Ridong
next prev parent reply other threads:[~2026-03-30 1:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-29 17:39 [PATCH v2 0/3] cgroup/cpuset: Fix v1 task migration failure from empty cpuset Waiman Long
2026-03-29 17:39 ` [PATCH v2 1/3] cgroup/cpuset: Simplify setsched decision check in task iteration loop of cpuset_can_attach() Waiman Long
2026-03-29 17:39 ` [PATCH v2 2/3] cgroup/cpuset: Skip security check for hotplug induced v1 task migration Waiman Long
2026-03-30 1:48 ` Chen Ridong [this message]
2026-03-30 16:15 ` Waiman Long
2026-03-30 18:21 ` Tejun Heo
2026-03-31 3:15 ` Waiman Long
2026-03-29 17:39 ` [PATCH v2 3/3] cgroup/cpuset: Improve check for v1 task migration out of empty cpuset Waiman Long
2026-03-30 18:25 ` Tejun Heo
2026-03-31 1:05 ` Waiman Long
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c80c6838-e33e-4e5c-82ac-9bfa4d012dcb@huaweicloud.com \
--to=chenridong@huaweicloud.com \
--cc=cgroups@vger.kernel.org \
--cc=chenridong@huawei.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mkoutny@suse.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox