On 5/7/24 02:57, Xuewen Yan wrote:
These changes essentially reverts commit 851a723e45d1c("sched: Always
clear user_cpus_ptr in do_set_cpus_allowed()") except the additional
caller in the cpuset code.
How about the following less invasive change?
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 7019a40457a6..646837eab70c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2796,21 +2796,24 @@ __do_set_cpus_allowed(struct task_struct *p,
struct affinity_context *ctx)
}
/*
- * Used for kthread_bind() and select_fallback_rq(), in both cases the user
- * affinity (if any) should be destroyed too.
+ * Used for kthread_bind() and select_fallback_rq(). Destroy user affinity
+ * if no intersection with the new mask.
*/
void do_set_cpus_allowed(struct task_struct *p, const struct cpumask
*new_mask)
{
struct affinity_context ac = {
.new_mask = new_mask,
.user_mask = NULL,
- .flags = SCA_USER, /* clear the user requested mask */
+ .flags = 0,
};
union cpumask_rcuhead {
cpumask_t cpumask;
struct rcu_head rcu;
};
+ if (current->user_cpus_ptr &&
!cpumask_intersects(current->user_cpus_ptr, new_mask))
Thanks for your suggestion, and I try it and as for me, it works well,
but I change the "current" to p.
I think “current” is inappropriate because what is changed here is the
mask of p.
It is possible that “p” and “current” are not equal.
I would send the next patch later and add your Suggested-by. Thanks
again for your advice!
You are right. It should be "p" instead of "current".
Thanks,
Longman