Skip to contentSkip to conversation

sched/core: Fix a missed update of user_cpus_ptr

PATCH Applied Waiman Long 4 participants 5 messages Feb 3, 2023 – Feb 15, 2023 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/core: Fix a missed update of user_cpus_ptr

Since commit 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask"), a successful call to sched_setaffinity() should always save the user requested cpu affinity mask in a task's user_cpus_ptr. However, when the given cpu mask is the same as the current one, user_cpus_ptr is not updated. Fix this by saving the user mask in this case too.

Fixes 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask")
---
 kernel/sched/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/sched/core.c +4 -1
index 30d9752e2ca5..91255f791df3 100644
@@ -2951,8 +2951,11 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p,
 	}
 
 	if (!(ctx->flags & SCA_MIGRATE_ENABLE)) {
-		if (cpumask_equal(&p->cpus_mask, ctx->new_mask))
+		if (cpumask_equal(&p->cpus_mask, ctx->new_mask)) {
+			if (ctx->flags & SCA_USER)
+				swap(p->user_cpus_ptr, ctx->user_mask);
 			goto out;
+		}
 
 		if (WARN_ON_ONCE(p == current &&
 				 is_migration_disabled(p) &&
Signature · 1 line
2.31.1
#1 lore raw
Quoted 19 lines · Waiman Long

Since commit 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask"), a successful call to sched_setaffinity() should always save the user requested cpu affinity mask in a task's user_cpus_ptr. However, when the given cpu mask is the same as the current one, user_cpus_ptr is not updated. Fix this by saving the user mask in this case too.

Fixes 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask")
---
 kernel/sched/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/sched/core.c +0 -0
index 30d9752e2ca5..91255f791df3 100644
@@ -2951,8 +2951,11 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p,
 	}
 

kernel/sched/core.c static int __set_cpus_allowed_ptr_locked(struct task_struct *p, · line 2961

Quoted 10 lines
kernel/sched/core.c +4 -1
 	if (!(ctx->flags & SCA_MIGRATE_ENABLE)) {
-		if (cpumask_equal(&p->cpus_mask, ctx->new_mask))
+		if (cpumask_equal(&p->cpus_mask, ctx->new_mask)) {
+			if (ctx->flags & SCA_USER)
+				swap(p->user_cpus_ptr, ctx->user_mask);
 			goto out;
+		}
 
 		if (WARN_ON_ONCE(p == current &&
 				 is_migration_disabled(p) &&

and this is for a separate bug and should go through the scheduler tree.

Thanks.

Signature · 1 line
tejun
#2 lore raw
Quoted 28 lines · Tejun Heo
Quoted 27 lines · Waiman Long

Since commit 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask"), a successful call to sched_setaffinity() should always save the user requested cpu affinity mask in a task's user_cpus_ptr. However, when the given cpu mask is the same as the current one, user_cpus_ptr is not updated. Fix this by saving the user mask in this case too.

Fixes 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask")
---
  kernel/sched/core.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
kernel/sched/core.c +4 -1
index 30d9752e2ca5..91255f791df3 100644
@@ -2951,8 +2951,11 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p,
  	}
 
  	if (!(ctx->flags & SCA_MIGRATE_ENABLE)) {
-		if (cpumask_equal(&p->cpus_mask, ctx->new_mask))
+		if (cpumask_equal(&p->cpus_mask, ctx->new_mask)) {
+			if (ctx->flags & SCA_USER)
+				swap(p->user_cpus_ptr, ctx->user_mask);
  			goto out;
+		}
 
Quoted 3 lines

kernel/sched/core.c static int __set_cpus_allowed_ptr_locked(struct task_struct *p, · line 2961

Quoted 2 lines
kernel/sched/core.c +0 -0
  		if (WARN_ON_ONCE(p == current &&
  				 is_migration_disabled(p) &&

and this is for a separate bug and should go through the scheduler tree.

Yes, this is for Peter to pick up.

Cheers,
Longman

maintainer
#3 lore raw
In reply to Waiman Long
Quoted 19 lines · Waiman Long

Since commit 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask"), a successful call to sched_setaffinity() should always save the user requested cpu affinity mask in a task's user_cpus_ptr. However, when the given cpu mask is the same as the current one, user_cpus_ptr is not updated. Fix this by saving the user mask in this case too.

Fixes 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask")
---
 kernel/sched/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/sched/core.c +0 -0
index 30d9752e2ca5..91255f791df3 100644
@@ -2951,8 +2951,11 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p,
 	}
 

kernel/sched/core.c static int __set_cpus_allowed_ptr_locked(struct task_struct *p, · line 2961

Quoted 10 lines
kernel/sched/core.c +4 -1
 	if (!(ctx->flags & SCA_MIGRATE_ENABLE)) {
-		if (cpumask_equal(&p->cpus_mask, ctx->new_mask))
+		if (cpumask_equal(&p->cpus_mask, ctx->new_mask)) {
+			if (ctx->flags & SCA_USER)
+				swap(p->user_cpus_ptr, ctx->user_mask);
 			goto out;
+		}
 
 		if (WARN_ON_ONCE(p == current &&
 				 is_migration_disabled(p) &&

Indeed. Thanks!

merge bot Applied
#4 lore raw
In reply to Waiman Long
The following commit has been merged into the sched/urgent branch of tip:

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     df14b7f9efcda35e59bb6f50351aac25c50f6e24
Gitweb:        https://git.kernel.org/tip/df14b7f9efcda35e59bb6f50351aac25c50f6e24
Author:        Waiman Long <[email protected]>
AuthorDate:    Fri, 03 Feb 2023 13:18:49 -05:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 13 Feb 2023 16:36:14 +01:00

sched/core: Fix a missed update of user_cpus_ptr

Since commit 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask"), a successful call to sched_setaffinity() should always save the user requested cpu affinity mask in a task's user_cpus_ptr. However, when the given cpu mask is the same as the current one, user_cpus_ptr is not updated. Fix this by saving the user mask in this case too.

Fixes 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask")
---
 kernel/sched/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/sched/core.c +4 -1
index e838feb..2a4918a 100644
@@ -2951,8 +2951,11 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p,
 	}
 
 	if (!(ctx->flags & SCA_MIGRATE_ENABLE)) {
-		if (cpumask_equal(&p->cpus_mask, ctx->new_mask))
+		if (cpumask_equal(&p->cpus_mask, ctx->new_mask)) {
+			if (ctx->flags & SCA_USER)
+				swap(p->user_cpus_ptr, ctx->user_mask);
 			goto out;
+		}
 
 		if (WARN_ON_ONCE(p == current &&
 				 is_migration_disabled(p) &&