Skip to contentSkip to conversation

cgroups: move cpuset specific checks from generic code to cpuset_can_attach

PATCH In review Marcelo Tosatti 4 participants 7 messages Nov 25, 2015 – Dec 2, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroups: move cpuset specific checks from generic code to cpuset_can_attach

Move PF_NO_SETAFFINITY check to cpuset cgroups, where it belongs. This makes it possible to attach PF_NO_SETAFFINITY to Intel CAT cgroups.

kernel/cgroup.c +0 -10
index f89d929..0603652 100644
@@ -2466,16 +2466,6 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
 	if (threadgroup)
 		tsk = tsk->group_leader;
 
-	/*
-	 * Workqueue threads may acquire PF_NO_SETAFFINITY and become
-	 * trapped in a cpuset, or RT worker may be born in a cgroup
-	 * with no rt_runtime allocated.  Just say no.
-	 */
-	if (tsk == kthreadd_task || (tsk->flags & PF_NO_SETAFFINITY)) {
-		ret = -EINVAL;
-		goto out_unlock_rcu;
-	}
-
 	get_task_struct(tsk);
 	rcu_read_unlock();
 
kernel/cpuset.c +12 -0
index f0acff0..9fff4d6 100644
@@ -53,6 +53,7 @@
 #include <linux/time.h>
 #include <linux/backing-dev.h>
 #include <linux/sort.h>
+#include <linux/kthread.h>
 
 #include <asm/uaccess.h>
 #include <linux/atomic.h>
@@ -1445,6 +1446,17 @@ static int cpuset_can_attach(struct cgroup_subsys_state *css,
 		goto out_unlock;
 
 	cgroup_taskset_for_each(task, tset) {
+		/*
+		 * Workqueue threads may acquire PF_NO_SETAFFINITY and become
+		 * trapped in a cpuset, or RT worker may be born in a cgroup
+		 * with no rt_runtime allocated.  Just say no.
+		 */
+		if (task == kthreadd_task ||
+		    (task->flags & PF_NO_SETAFFINITY)) {
+			ret = -EINVAL;
+			goto out_unlock;
+		}
+
 		ret = task_can_attach(task, cs->cpus_allowed);
 		if (ret)
 			goto out_unlock;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Marcelo Tosatti

Move PF_NO_SETAFFINITY check to cpuset cgroups, where it belongs. This makes it possible to attach PF_NO_SETAFFINITY to Intel CAT cgroups.

Looks that's the right place. I tried intel_rdt subsystem at least it doesn't have this restriction anymore (all the tasks can be moved out of the default group), hence:

Chao

#3 lore raw

PATCH 1/1 cgroups: move cpuset specific checks from generic code to cpuset_can_attach (v2)

Move PF_NO_SETAFFINITY and kthreadd_task checks to cpuset cgroups, where they belong. This makes it possible to attach PF_NO_SETAFFINITY tasks to Intel CAT cgroup.

v2: "PF_NO_SETAFFINITY check" -> "PF_NO_SETAFFINITY and kthreadd_task checks"

kernel/cgroup.c +0 -10
index f89d929..0603652 100644
@@ -2466,16 +2466,6 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
 	if (threadgroup)
 		tsk = tsk->group_leader;
 
-	/*
-	 * Workqueue threads may acquire PF_NO_SETAFFINITY and become
-	 * trapped in a cpuset, or RT worker may be born in a cgroup
-	 * with no rt_runtime allocated.  Just say no.
-	 */
-	if (tsk == kthreadd_task || (tsk->flags & PF_NO_SETAFFINITY)) {
-		ret = -EINVAL;
-		goto out_unlock_rcu;
-	}
-
 	get_task_struct(tsk);
 	rcu_read_unlock();
 
kernel/cpuset.c +12 -0
index f0acff0..9fff4d6 100644
@@ -53,6 +53,7 @@
 #include <linux/time.h>
 #include <linux/backing-dev.h>
 #include <linux/sort.h>
+#include <linux/kthread.h>
 
 #include <asm/uaccess.h>
 #include <linux/atomic.h>
@@ -1445,6 +1446,17 @@ static int cpuset_can_attach(struct cgroup_subsys_state *css,
 		goto out_unlock;
 
 	cgroup_taskset_for_each(task, tset) {
+		/*
+		 * Workqueue threads may acquire PF_NO_SETAFFINITY and become
+		 * trapped in a cpuset, or RT worker may be born in a cgroup
+		 * with no rt_runtime allocated.  Just say no.
+		 */
+		if (task == kthreadd_task ||
+		    (task->flags & PF_NO_SETAFFINITY)) {
+			ret = -EINVAL;
+			goto out_unlock;
+		}
+
 		ret = task_can_attach(task, cs->cpus_allowed);
 		if (ret)
 			goto out_unlock;
#4 lore raw

Re: [PATCH] cgroups: move cpuset specific checks from generic code to cpuset_can_attach (v2)

Quoted 52 lines · Marcelo Tosatti

Move PF_NO_SETAFFINITY and kthreadd_task checks to cpuset cgroups, where they belong. This makes it possible to attach PF_NO_SETAFFINITY tasks to Intel CAT cgroup.

v2: "PF_NO_SETAFFINITY check" -> "PF_NO_SETAFFINITY and kthreadd_task checks"

kernel/cgroup.c +0 -10
index f89d929..0603652 100644
@@ -2466,16 +2466,6 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
 	if (threadgroup)
 		tsk = tsk->group_leader;
 
-	/*
-	 * Workqueue threads may acquire PF_NO_SETAFFINITY and become
-	 * trapped in a cpuset, or RT worker may be born in a cgroup
-	 * with no rt_runtime allocated.  Just say no.
-	 */
-	if (tsk == kthreadd_task || (tsk->flags & PF_NO_SETAFFINITY)) {
-		ret = -EINVAL;
-		goto out_unlock_rcu;
-	}
-
 	get_task_struct(tsk);
 	rcu_read_unlock();
 
kernel/cpuset.c +5 -0
index f0acff0..9fff4d6 100644
@@ -53,6 +53,7 @@
 #include <linux/time.h>
 #include <linux/backing-dev.h>
 #include <linux/sort.h>
+#include <linux/kthread.h>
 
 #include <asm/uaccess.h>
 #include <linux/atomic.h>
@@ -1445,6 +1446,17 @@ static int cpuset_can_attach(struct cgroup_subsys_state *css,
 		goto out_unlock;
 
 	cgroup_taskset_for_each(task, tset) {
+		/*
+		 * Workqueue threads may acquire PF_NO_SETAFFINITY and become
+		 * trapped in a cpuset, or RT worker may be born in a cgroup
+		 * with no rt_runtime allocated.  Just say no.

kernel/cpuset.c static int cpuset_can_attach(struct cgroup_subsys_state *css, · line 1462

Quoted 10 lines
kernel/cpuset.c +7 -0
+		 */
+		if (task == kthreadd_task ||
+		    (task->flags & PF_NO_SETAFFINITY)) {
+			ret = -EINVAL;
+			goto out_unlock;
+		}
+
 		ret = task_can_attach(task, cs->cpus_allowed);
 		if (ret)
 			goto out_unlock;

Note the rt_runtime reference in the comment, that wasn't about cpuset. The kthreadd wants to remain immune to all fiddlings methinks.

-Mike

#5 lore raw

Re: [PATCH] cgroups: move cpuset specific checks from generic code to cpuset_can_attach (v2)

In reply to Marcelo Tosatti
Quoted 11 lines · Marcelo Tosatti

Move PF_NO_SETAFFINITY and kthreadd_task checks to cpuset cgroups, where they belong. This makes it possible to attach PF_NO_SETAFFINITY tasks to Intel CAT cgroup.

v2: "PF_NO_SETAFFINITY check" -> "PF_NO_SETAFFINITY and kthreadd_task checks"

This wasn't just for cpuset. It's for all controllers.

Thanks.

Signature · 1 line
tejun
#6 lore raw

Re: [PATCH] cgroups: move cpuset specific checks from generic code to cpuset_can_attach (v2)

Quoted 6 lines · Tejun Heo
Quoted 5 lines · Marcelo Tosatti

Move PF_NO_SETAFFINITY and kthreadd_task checks to cpuset cgroups, where they belong. This makes it possible to attach PF_NO_SETAFFINITY tasks to Intel CAT cgroup.

Quoted 8 lines
Quoted 6 lines

v2: "PF_NO_SETAFFINITY check" -> "PF_NO_SETAFFINITY and kthreadd_task checks"

This wasn't just for cpuset. It's for all controllers.

Hm, indeed. Workers landing in a throttled cfs rq wouldn't be as painful as an rt worker being born in an rq with no rt_runtime, but could sting. Workers stuffed into the freezer would sting mightily.

-Mike