]> Git Repo - linux.git/commitdiff
sched: fix warning in sched_setaffinity
authorJosh Don <[email protected]>
Mon, 11 Nov 2024 18:27:38 +0000 (10:27 -0800)
committerPeter Zijlstra <[email protected]>
Mon, 2 Dec 2024 11:01:27 +0000 (12:01 +0100)
Commit 8f9ea86fdf99b added some logic to sched_setaffinity that included
a WARN when a per-task affinity assignment races with a cpuset update.

Specifically, we can have a race where a cpuset update results in the
task affinity no longer being a subset of the cpuset. That's fine; we
have a fallback to instead use the cpuset mask. However, we have a WARN
set up that will trigger if the cpuset mask has no overlap at all with
the requested task affinity. This shouldn't be a warning condition; its
trivial to create this condition.

Reproduced the warning by the following setup:

- $PID inside a cpuset cgroup
- another thread repeatedly switching the cpuset cpus from 1-2 to just 1
- another thread repeatedly setting the $PID affinity (via taskset) to 2

Fixes: 8f9ea86fdf99b ("sched: Always preserve the user requested cpumask")
Signed-off-by: Josh Don <[email protected]>
Acked-and-tested-by: Vincent Guittot <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Acked-by: Waiman Long <[email protected]>
Tested-by: Madadi Vineeth Reddy <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
kernel/sched/syscalls.c

index 0d71fcbaf1e37f612dccc832845a1b1819747ee3..ff0e5ab4e37cb171b03281b743105c21f2e10800 100644 (file)
@@ -1200,7 +1200,7 @@ int __sched_setaffinity(struct task_struct *p, struct affinity_context *ctx)
                        bool empty = !cpumask_and(new_mask, new_mask,
                                                  ctx->user_mask);
 
-                       if (WARN_ON_ONCE(empty))
+                       if (empty)
                                cpumask_copy(new_mask, cpus_allowed);
                }
                __set_cpus_allowed_ptr(p, ctx);
This page took 0.057364 seconds and 4 git commands to generate.