[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <6967a07f-d48c-4fdf-8adc-414d5127b576@redhat.com>
Date: Mon, 20 Oct 2025 16:21:36 -0400
From: Waiman Long <llong@...hat.com>
To: David Hildenbrand <david@...hat.com>, Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>, Juri Lelli <juri.lelli@...hat.com>,
Vincent Guittot <vincent.guittot@...aro.org>,
Dietmar Eggemann <dietmar.eggemann@....com>,
Steven Rostedt <rostedt@...dmis.org>, Ben Segall <bsegall@...gle.com>,
Mel Gorman <mgorman@...e.de>, Valentin Schneider <vschneid@...hat.com>,
Jonathan Corbet <corbet@....net>
Cc: linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-doc@...r.kernel.org, Andrew Morton <akpm@...ux-foundation.org>,
Catalin Marinas <catalin.marinas@....com>, Nico Pache <npache@...hat.com>,
Phil Auld <pauld@...hat.com>, John Coleman <jocolema@...hat.com>
Subject: Re: [PATCH 1/2] sched/core: Enable full cpumask to clear user cpumask
in sched_setaffinity()
On 10/20/25 4:13 PM, David Hildenbrand wrote:
> On 23.09.25 19:54, Waiman Long wrote:
>> Since commit 8f9ea86fdf99 ("sched: Always preserve the user requested
>> cpumask"), user provided CPU affinity via sched_setaffinity(2) is
>> perserved even if the task is being moved to a different cpuset.
>> However, that affinity is also being inherited by any subsequently
>> created child processes which may not want or be aware of that affinity.
>
> So I assume setting the affinity to the full bitmap would then allow
> any child to essentially reset to the default, correct?
Yes, that is the point.
>
>>
>> One way to solve this problem is to provide a way to back off from
>> that user provided CPU affinity. This patch implements such a scheme
>> by using a full cpumask (a cpumask with all bits set) to signal the
>> clearing of the user cpumask to follow the default as allowed by
>> the current cpuset. In fact, with a full cpumask in user_cpus_ptr,
>> the task behavior should be the same as with a NULL user_cpus_ptr.
>> This patch just formalizes it without causing any incompatibility and
>> discard an otherwise useless cpumask.
>>
>> Signed-off-by: Waiman Long <longman@...hat.com>
>> ---
>> kernel/sched/syscalls.c | 20 ++++++++++++++------
>> 1 file changed, 14 insertions(+), 6 deletions(-)
>>
>> diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
>> index 77ae87f36e84..d68c7a4ee525 100644
>> --- a/kernel/sched/syscalls.c
>> +++ b/kernel/sched/syscalls.c
>> @@ -1229,14 +1229,22 @@ long sched_setaffinity(pid_t pid, const
>> struct cpumask *in_mask)
>> return retval;
>> /*
>> - * With non-SMP configs, user_cpus_ptr/user_mask isn't used and
>> - * alloc_user_cpus_ptr() returns NULL.
>> + * If a full cpumask is passed in, clear user_cpus_ptr and reset
>> the
>> + * current cpu affinity to the default for the current cpuset.
>> */
>> - user_mask = alloc_user_cpus_ptr(NUMA_NO_NODE);
>> - if (user_mask) {
>> - cpumask_copy(user_mask, in_mask);
>> + if (cpumask_full(in_mask)) {
>> + user_mask = NULL;
>> } else {
>> - return -ENOMEM;
>> + /*
>> + * With non-SMP configs, user_cpus_ptr/user_mask isn't used and
>> + * alloc_user_cpus_ptr() returns NULL.
>> + */
>> + user_mask = alloc_user_cpus_ptr(NUMA_NO_NODE);
>> + if (user_mask) {
>> + cpumask_copy(user_mask, in_mask);
>> + } else {
>> + return -ENOMEM;
>> + }
>> }
>> ac = (struct affinity_context){
>
> Not an expert on this code.
>
> I'm only wondering if there is somehow, some way we could be breaking
> user space by doing that.
>
I don't think so. Setting user_cpus_ptr to a full cpumask will make the
task strictly follow the cpumask restriction imposed by the current
cpuset as if user_cpus_ptr isn't set.
Cheers,
Longman
Powered by blists - more mailing lists