Skip to content

Commit 851a723

Browse files
Waiman-LongPeter Zijlstra
authored andcommitted
sched: Always clear user_cpus_ptr in do_set_cpus_allowed()
The do_set_cpus_allowed() function is used by either kthread_bind() or select_fallback_rq(). In both cases the user affinity (if any) should be destroyed too. Suggested-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Waiman Long <longman@redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20220922180041.1768141-6-longman@redhat.com
1 parent da01903 commit 851a723

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

kernel/sched/core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2593,14 +2593,20 @@ __do_set_cpus_allowed(struct task_struct *p, struct affinity_context *ctx)
25932593
set_next_task(rq, p);
25942594
}
25952595

2596+
/*
2597+
* Used for kthread_bind() and select_fallback_rq(), in both cases the user
2598+
* affinity (if any) should be destroyed too.
2599+
*/
25962600
void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
25972601
{
25982602
struct affinity_context ac = {
25992603
.new_mask = new_mask,
2600-
.flags = 0,
2604+
.user_mask = NULL,
2605+
.flags = SCA_USER, /* clear the user requested mask */
26012606
};
26022607

26032608
__do_set_cpus_allowed(p, &ac);
2609+
kfree(ac.user_mask);
26042610
}
26052611

26062612
int dup_user_cpus_ptr(struct task_struct *dst, struct task_struct *src,

0 commit comments

Comments
 (0)