Re: [PATCH v3] sched/core: Skip user_cpus_ptr masking if no online CPU left

From: Waiman Long
Date: Mon Jul 21 2025 - 11:28:34 EST


On 7/21/25 11:13 AM, Michal Koutný wrote:
On Fri, Jul 18, 2025 at 12:48:56PM -0400, Waiman Long <longman@xxxxxxxxxx> wrote:
Chen Ridong reported that cpuset could report a kernel warning for a task
due to set_cpus_allowed_ptr() returning failure in the corner case that:

1) the task used sched_setaffinity(2) to set its CPU affinity mask to
be the same as the cpuset.cpus of its cpuset,
2) all the CPUs assigned to that cpuset were taken offline, and
3) cpuset v1 is in use and the task had to be migrated to the top cpuset.
Does this make sense for cpuset v2 (or no cpuset at all for that matter)?
I'm asking whether this mask modification could only be extracted into
cpuset-v1.c (like cgroup_tranfer_tasks() or a new function)

This corner case as specified in Chen Ridong's patch only happens with a cpuset v1 environment, but it is still the case that the default cpu affinity of the root cgroup (with or without CONFIG_CGROUPS) will include offline CPUs, if present. So it still make senses to skip the sched_setaffinity() setting if there is no online CPU left, though it will be much harder to have such a condition without using cpuset v1.

Cheers,
Longman