Skip to contentSkip to conversation

sched: Core scheduling interfaces

PATCH In review Peter Zijlstra 6 participants 36 messages Apr 1, 2021 – Apr 21, 2021

Subsystems (7)
VFS Kselftest perf events MM core +3 more subsystems
lore
Share & tools
lore

Peter Zijlstra

author maintainer
#0 lore raw

cover sched: Core scheduling interfaces

Hi,

This is a rewrite of the core sched interface bits, and mostly replaces patches 2-5 from this set here:

https://lkml.kernel.org/r/[email protected]

The task interface is extended to include PR_SCHED_CORE_GET, because the selftest. Otherwise the task interface is much the same, except completely new code.

The cgroup interface now uses a 'core_sched' file, which still takes 0,1. It is however changed such that you can have nested tags. The for any given task, the first parent with a cookie is the effective one. The rationale is that this way you can delegate subtrees and still allow them some control over grouping.

The cgroup thing also '(ab)uses' cgroup_mutex for serialization because it needs to ensure continuity between ss->can_attach() and ss->attach() for the memory allocation. If the prctl() were allowed to interleave it might steal the memory.

Using cgroup_mutex feels icky, but is not without precedent, kernel/bpf/cgroup.c does the same thing afaict.

TJ, can you please have a look at this?

The last patch implements the prctl() / cgroup interaction, up until that point each task carries the cookie set last between either interface, which is not desirable. It really isn't the nicest thing ever, but it does keep the scheduling core from having to consider multiple cookies.

Also, I still hate the kernel/sched/core_sched.c filename, but short of using gibberish names to make tab-completion easier I simply cannot come up with a remotely sane alternative :/

The code seems to not insta crash, and I can run the prctl() selftest while in a cgroup and have it pass, not leak any references etc.. But it's otherwise lightly tested code. Please read carefully etc..

Also of note; I didn't seem to need the css_offline and css_exit handlers the other set added.

FWIW, I have a 4 day weekend ahead :-)

author maintainer
#1 lore raw

PATCH 1/9 sched: Allow sched_core_put() from atomic context

Stuff the meat of sched_core_put() into a work such that we can use sched_core_put() from atomic context.

---
 kernel/sched/core.c |   33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)
kernel/sched/core.c +27 -6
@@ -223,7 +223,7 @@ static struct task_struct *sched_core_ne
  */
 
 static DEFINE_MUTEX(sched_core_mutex);
-static int sched_core_count;
+static atomic_t sched_core_count;
 static struct cpumask sched_core_mask;
 
 static void __sched_core_flip(bool enabled)
@@ -286,18 +286,39 @@ static void __sched_core_disable(void)
 
 void sched_core_get(void)
 {
+	if (atomic_inc_not_zero(&sched_core_count))
+		return;
+
 	mutex_lock(&sched_core_mutex);
-	if (!sched_core_count++)
+	if (!atomic_read(&sched_core_count))
 		__sched_core_enable();
+
+	smp_mb__before_atomic();
+	atomic_inc(&sched_core_count);
 	mutex_unlock(&sched_core_mutex);
 }
 
-void sched_core_put(void)
+static void __sched_core_put(struct work_struct *work)
 {
-	mutex_lock(&sched_core_mutex);
-	if (!--sched_core_count)
+	if (atomic_dec_and_mutex_lock(&sched_core_count, &sched_core_mutex)) {
 		__sched_core_disable();
-	mutex_unlock(&sched_core_mutex);
+		mutex_unlock(&sched_core_mutex);
+	}
+}
+
+void sched_core_put(void)
+{
+	static DECLARE_WORK(_work, __sched_core_put);
+
+	/*
+	 * "There can only be one"
+	 *
+	 * Either this is the last one, or we don't actually need to do any
+	 * 'work'. If it is the last *again*, we rely on
+	 * WORK_STRUCT_PENDING_BIT.
+	 */
+	if (!atomic_add_unless(&sched_core_count, -1, 1))
+		schedule_work(&_work);
 }
 
 #else /* !CONFIG_SCHED_CORE */
author maintainer
#2 lore raw

PATCH 2/9 sched: Implement core-sched assertions

In reply to Peter Zijlstra
---
 kernel/sched/core.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
kernel/sched/core.c +10 -4
@@ -268,18 +268,24 @@ static void __sched_core_flip(bool enabl
 	cpus_read_unlock();
 }
 
-static void __sched_core_enable(void)
+static void sched_core_assert_empty(void)
 {
-	// XXX verify there are no cookie tasks (yet)
+	int cpu;
+
+	for_each_possible_cpu(cpu)
+		WARN_ON_ONCE(!RB_EMPTY_ROOT(&cpu_rq(cpu)->core_tree));
+}
 
+static void __sched_core_enable(void)
+{
 	static_branch_enable(&__sched_core_enabled);
 	__sched_core_flip(true);
+	sched_core_assert_empty();
 }
 
 static void __sched_core_disable(void)
 {
-	// XXX verify there are no cookie tasks (left)
-
+	sched_core_assert_empty();
 	__sched_core_flip(false);
 	static_branch_disable(&__sched_core_enabled);
 }
author maintainer
#3 lore raw

PATCH 3/9 sched: Trivial core scheduling cookie management

In reply to Peter Zijlstra

In order to not have to use pid_struct, create a new, smaller, structure to manage task cookies for core scheduling.

---
 include/linux/sched.h     |    6 ++
 kernel/fork.c             |    1 
 kernel/sched/Makefile     |    1 
 kernel/sched/core.c       |    7 +--
 kernel/sched/core_sched.c |  106 ++++++++++++++++++++++++++++++++++++++++++++++
 kernel/sched/sched.h      |   16 ++++++
 6 files changed, 134 insertions(+), 3 deletions(-)
include/linux/sched.h +6 -0
@@ -2169,4 +2169,10 @@ int sched_trace_rq_nr_running(struct rq
 
 const struct cpumask *sched_trace_rd_span(struct root_domain *rd);
 
+#ifdef CONFIG_SCHED_CORE
+extern void sched_core_free(struct task_struct *tsk);
+#else
+static inline void sched_core_free(struct task_struct *tsk) { }
+#endif
+
 #endif
kernel/fork.c +1 -0
@@ -737,6 +737,7 @@ void __put_task_struct(struct task_struc
 	exit_creds(tsk);
 	delayacct_tsk_free(tsk);
 	put_signal_struct(tsk->signal);
+	sched_core_free(tsk);
 
 	if (!profile_handoff_task(tsk))
 		free_task(tsk);
kernel/sched/Makefile +1 -0
@@ -36,3 +36,4 @@ obj-$(CONFIG_CPU_FREQ_GOV_SCHEDUTIL) +=
 obj-$(CONFIG_MEMBARRIER) += membarrier.o
 obj-$(CONFIG_CPU_ISOLATION) += isolation.o
 obj-$(CONFIG_PSI) += psi.o
+obj-$(CONFIG_SCHED_CORE) += core_sched.o
kernel/sched/core.c +4 -3
@@ -157,7 +157,7 @@ static inline int rb_sched_core_cmp(cons
 	return 0;
 }
 
-static void sched_core_enqueue(struct rq *rq, struct task_struct *p)
+void sched_core_enqueue(struct rq *rq, struct task_struct *p)
 {
 	rq->core->core_task_seq++;
 
@@ -167,14 +167,15 @@ static void sched_core_enqueue(struct rq
 	rb_add(&p->core_node, &rq->core_tree, rb_sched_core_less);
 }
 
-static void sched_core_dequeue(struct rq *rq, struct task_struct *p)
+void sched_core_dequeue(struct rq *rq, struct task_struct *p)
 {
 	rq->core->core_task_seq++;
 
-	if (!p->core_cookie)
+	if (!sched_core_enqueued(p))
 		return;
 
 	rb_erase(&p->core_node, &rq->core_tree);
+	RB_CLEAR_NODE(&p->core_node);
 }
 
 /*
kernel/sched/core_sched.c new file +106 -0

106 lines not on this page · raw message

kernel/sched/sched.h +16 -0
@@ -1222,6 +1222,22 @@ static inline bool sched_group_cookie_ma
 
 extern void queue_core_balance(struct rq *rq);
 
+static inline bool sched_core_enqueued(struct task_struct *p)
+{
+	return !RB_EMPTY_NODE(&p->core_node);
+}
+
+extern void sched_core_enqueue(struct rq *rq, struct task_struct *p);
+extern void sched_core_dequeue(struct rq *rq, struct task_struct *p);
+
+extern void sched_core_get(void);
+extern void sched_core_put(void);
+
+extern unsigned long sched_core_alloc_cookie(void);
+extern void sched_core_put_cookie(unsigned long cookie);
+extern unsigned long sched_core_get_cookie(unsigned long cookie);
+extern unsigned long sched_core_update_cookie(struct task_struct *p, unsigned long cookie);
+
 #else /* !CONFIG_SCHED_CORE */
 
 static inline bool sched_core_enabled(struct rq *rq)
#4 lore raw

Re: [PATCH 3/9] sched: Trivial core scheduling cookie management

Quoted 6 lines

+/*
+ * sched_core_update_cookie - Common helper to update a task's core cookie. This
+ * updates the selected cookie field.
+ * @p: The task whose cookie should be updated.
+ * @cookie: The new cookie.
+ * @cookie_type: The cookie field to which the cookie corresponds.

No cookie_type in this patch (or cookie fields). Also might want to call out that the caller is responsible for put'ing the return value.

author maintainer
#5 lore raw

Re: [PATCH 3/9] sched: Trivial core scheduling cookie management

Quoted 9 lines · Josh Don
Quoted 6 lines

+/*
+ * sched_core_update_cookie - Common helper to update a task's core cookie. This
+ * updates the selected cookie field.
+ * @p: The task whose cookie should be updated.
+ * @cookie: The new cookie.
+ * @cookie_type: The cookie field to which the cookie corresponds.

No cookie_type in this patch (or cookie fields). Also might want to call out that the caller is responsible for put'ing the return value.

Lol, I don't think I've even seen the comment. Yes that needs more than a rewording.

author maintainer
#6 lore raw

PATCH 4/9 sched: Default core-sched policy

In reply to Peter Zijlstra

Implement default core scheduling policy.

- fork() / clone(): inherit cookie from parent
- exec(): if cookie then new cookie

Did that exec() thing want to change cookie on suid instead, just like perf_event_exit_task() ?

Note that sched_core_fork() is called from under tasklist_lock, and not from sched_fork() earlier. This avoids a few races later.

---
 fs/exec.c                  |    4 +++-
 include/linux/sched.h      |    4 ++++
 include/linux/sched/task.h |    4 ++--
 kernel/fork.c              |    3 +++
 kernel/sched/core.c        |   11 +++++++++--
 kernel/sched/core_sched.c  |   21 +++++++++++++++++++++
 6 files changed, 42 insertions(+), 5 deletions(-)
fs/exec.c +3 -1
@@ -1807,7 +1807,9 @@ static int bprm_execve(struct linux_binp
 	if (IS_ERR(file))
 		goto out_unmark;
 
-	sched_exec();
+	retval = sched_exec();
+	if (retval)
+		goto out;
 
 	bprm->file = file;
 	/*
include/linux/sched.h +4 -0
@@ -2171,8 +2171,12 @@ const struct cpumask *sched_trace_rd_spa
 
 #ifdef CONFIG_SCHED_CORE
 extern void sched_core_free(struct task_struct *tsk);
+extern int sched_core_exec(void);
+extern void sched_core_fork(struct task_struct *p);
 #else
 static inline void sched_core_free(struct task_struct *tsk) { }
+static inline int sched_core_exec(void) { return 0; }
+static inline void sched_core_fork(struct task_struct *p) { }
 #endif
 
 #endif
include/linux/sched/task.h +2 -2
@@ -94,9 +94,9 @@ extern void free_task(struct task_struct
 
 /* sched_exec is called by processes performing an exec */
 #ifdef CONFIG_SMP
-extern void sched_exec(void);
+extern int sched_exec(void);
 #else
-#define sched_exec()   {}
+static inline int sched_exec(void) { return 0; }
 #endif
 
 static inline struct task_struct *get_task_struct(struct task_struct *t)
kernel/fork.c +3 -0
@@ -2242,6 +2242,8 @@ static __latent_entropy struct task_stru
 
 	klp_copy_process(p);
 
+	sched_core_fork(p);
+
 	spin_lock(&current->sighand->siglock);
 
 	/*
@@ -2329,6 +2331,7 @@ static __latent_entropy struct task_stru
 	return p;
 
 bad_fork_cancel_cgroup:
+	sched_core_free(p);
 	spin_unlock(&current->sighand->siglock);
 	write_unlock_irq(&tasklist_lock);
 	cgroup_cancel_fork(p, args);
kernel/sched/core.c +9 -2
@@ -4762,11 +4762,17 @@ unsigned long nr_iowait(void)
  * sched_exec - execve() is a valuable balancing opportunity, because at
  * this point the task has the smallest effective memory and cache footprint.
  */
-void sched_exec(void)
+int sched_exec(void)
 {
 	struct task_struct *p = current;
 	unsigned long flags;
 	int dest_cpu;
+	int ret;
+
+	/* this may change what tasks current can share a core with */
+	ret = sched_core_exec();
+	if (ret)
+		return ret;
 
 	raw_spin_lock_irqsave(&p->pi_lock, flags);
 	dest_cpu = p->sched_class->select_task_rq(p, task_cpu(p), WF_EXEC);
@@ -4778,10 +4784,11 @@ void sched_exec(void)
 
 		raw_spin_unlock_irqrestore(&p->pi_lock, flags);
 		stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg);
-		return;
+		return 0;
 	}
 unlock:
 	raw_spin_unlock_irqrestore(&p->pi_lock, flags);
+	return 0;
 }
 
 #endif
kernel/sched/core_sched.c +21 -0
@@ -100,7 +100,28 @@ static unsigned long sched_core_clone_co
 	return cookie;
 }
 
+void sched_core_fork(struct task_struct *p)
+{
+	RB_CLEAR_NODE(&p->core_node);
+	p->core_cookie = sched_core_clone_cookie(current);
+}
+
 void sched_core_free(struct task_struct *p)
 {
 	sched_core_put_cookie(p->core_cookie);
 }
+
+int sched_core_exec(void)
+{
+	/* absent a policy mech, if task had a cookie, give it a new one */
+	if (current->core_cookie) {
+		unsigned long cookie = sched_core_alloc_cookie();
+		if (!cookie)
+			return -ENOMEM;
+		cookie = sched_core_update_cookie(current, cookie);
+		sched_core_put_cookie(cookie);
+	}
+
+	return 0;
+}
+
author maintainer
#7 lore raw

Re: [PATCH 4/9] sched: Default core-sched policy

Quoted 7 lines · Peter Zijlstra

Implement default core scheduling policy.

- fork() / clone(): inherit cookie from parent
- exec(): if cookie then new cookie

Did that exec() thing want to change cookie on suid instead, just like perf_event_exit_task() ?

Talk to me about that exec() thing; I still think it's weird. Did we just want to drop cookie on suid instead?

#8 lore raw

Re: [PATCH 4/9] sched: Default core-sched policy

Quoted 12 lines · Peter Zijlstra
Quoted 7 lines · Peter Zijlstra

Implement default core scheduling policy.

- fork() / clone(): inherit cookie from parent
- exec(): if cookie then new cookie

Did that exec() thing want to change cookie on suid instead, just like perf_event_exit_task() ?

Talk to me about that exec() thing; I still think it's weird. Did we just want to drop cookie on suid instead?

The choices for fork and exec were for security. A forked process or thread gets a copy because the code is "trusted", but execed code is not by default (that was the policy choice) and so it gets a new cookie. Dropping the cookie on suid was not considered (an oversight on my part), but seems like a good idea, but I think, also orthogonal.

The biggest issue with a new cookie on exec is that makes it difficult to construct a large process tree of all the same cookies like the cgroup interface does. If we remove the cgroup interface, we either need to remove the "new cookie on exec" (inherit cookie from parent from fork) or provide a global/per-task policy for controlling that. Probably easiest to just drop it.

-chrish

author maintainer
#9 lore raw

PATCH 5/9 sched: prctl() core-scheduling interface

In reply to Peter Zijlstra

From: Chris Hyser <[email protected]>

This patch provides support for setting, clearing and copying core scheduling 'task cookies' between threads (PID), processes (TGID), and process groups (PGID).

The value of core scheduling isn't that tasks don't share a core, 'nosmt' can do that. The value lies in exploiting all the sharing opportunities that exist to recover possible lost performance and that requires a degree of flexibility in the API.

Quoted 1 line

From a security perspective (and there are others), the thread,

process and process group distinction is an existent hierarchal categorization of tasks that reflects many of the security concerns about 'data sharing'. For example, protecting against cache-snooping by a thread that can just read the memory directly isn't all that useful.

With this in mind, subcommands to CLEAR/CREATE/SHARE (TO/FROM) provide a mechanism to create, clear and share cookies. CLEAR/CREATE/SHARE_TO specify a target pid with enum pidtype used to specify the scope of the targeted tasks. For example, PIDTYPE_TGID will share the cookie with the process and all of it's threads as typically desired in a security scenario.

API:

prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, tgtpid, pidtype, &cookie) prctl(PR_SCHED_CORE, PR_SCHED_CORE_CLEAR, tgtpid, pidtype, NULL) prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, tgtpid, pidtype, NULL) prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_TO, tgtpid, pidtype, NULL) prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_FROM, srcpid, pidtype, NULL)

where 'tgtpid/srcpid == 0' implies the current process and pidtype is kernel enum pid_type {PIDTYPE_PID, PIDTYPE_TGID, PIDTYPE_PGID, ...}. PIDTYPE_SID, sharing a cookie with an entire session, was considered less useful given the choice to create a new cookie on task exec().

For return values, EINVAL, ENOMEM are what they say. ESRCH means the tgtpid/srcpid was not found. EPERM indicates lack of PTRACE permission access to tgtpid/srcpid. EACCES indicates that a task in the target pidtype group was not updated due to permission.

Current hard-coded policies are:

- a user can clear the cookie of any process they can set a cookie for. Lack of a cookie *might* be a security issue if cookies are being used for that.

---
 include/linux/sched.h            |    2 
 include/uapi/linux/prctl.h       |    9 +++
 kernel/sched/core_sched.c        |  117 +++++++++++++++++++++++++++++++++++++++
 kernel/sys.c                     |    5 +
 tools/include/uapi/linux/prctl.h |    9 +++
 5 files changed, 142 insertions(+)
include/linux/sched.h +2 -0
@@ -2173,6 +2173,8 @@ const struct cpumask *sched_trace_rd_spa
 extern void sched_core_free(struct task_struct *tsk);
 extern int sched_core_exec(void);
 extern void sched_core_fork(struct task_struct *p);
+extern int sched_core_share_pid(unsigned int cmd, pid_t pid, enum pid_type type,
+				unsigned long uaddr);
 #else
 static inline void sched_core_free(struct task_struct *tsk) { }
 static inline int sched_core_exec(void) { return 0; }
include/uapi/linux/prctl.h +9 -0
@@ -255,4 +255,13 @@ struct prctl_mm_map {
 # define SYSCALL_DISPATCH_FILTER_ALLOW	0
 # define SYSCALL_DISPATCH_FILTER_BLOCK	1
 
+/* Request the scheduler to share a core */
+#define PR_SCHED_CORE			60
+# define PR_SCHED_CORE_GET		0
+# define PR_SCHED_CORE_CLEAR		1 /* clear core_sched cookie of pid */
+# define PR_SCHED_CORE_CREATE		2 /* create unique core_sched cookie */
+# define PR_SCHED_CORE_SHARE_TO		3 /* push core_sched cookie to pid */
+# define PR_SCHED_CORE_SHARE_FROM	4 /* pull core_sched cookie to pid */
+# define PR_SCHED_CORE_MAX		5
+
 #endif /* _LINUX_PRCTL_H */
kernel/sched/core_sched.c +117 -0

125 lines not on this page · raw message

kernel/sys.c +5 -0
@@ -2534,6 +2534,11 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
 		error = set_syscall_user_dispatch(arg2, arg3, arg4,
 						  (char __user *) arg5);
 		break;
+#ifdef CONFIG_SCHED_CORE
+	case PR_SCHED_CORE:
+		error = sched_core_share_pid(arg2, arg3, arg4, arg5);
+		break;
+#endif
 	default:
 		error = -EINVAL;
 		break;
tools/include/uapi/linux/prctl.h +9 -0
@@ -255,4 +255,13 @@ struct prctl_mm_map {
 # define SYSCALL_DISPATCH_FILTER_ALLOW	0
 # define SYSCALL_DISPATCH_FILTER_BLOCK	1
 
+/* Request the scheduler to share a core */
+#define PR_SCHED_CORE			60
+# define PR_SCHED_CORE_GET		0
+# define PR_SCHED_CORE_CLEAR		1 /* clear core_sched cookie of pid */
+# define PR_SCHED_CORE_CREATE		2 /* create unique core_sched cookie */
+# define PR_SCHED_CORE_SHARE_TO		3 /* push core_sched cookie to pid */
+# define PR_SCHED_CORE_SHARE_FROM	4 /* pull core_sched cookie to pid */
+# define PR_SCHED_CORE_MAX		5
+
 #endif /* _LINUX_PRCTL_H */
author maintainer
#10 lore raw

Re: [PATCH 5/9] sched: prctl() core-scheduling interface

Quoted 5 lines · Peter Zijlstra

Current hard-coded policies are:

- a user can clear the cookie of any process they can set a cookie for. Lack of a cookie *might* be a security issue if cookies are being used for that.

ChromeOS people, what are you doing about this? syscall/prctl filtering?

#11 lore raw

Re: [PATCH 5/9] sched: prctl() core-scheduling interface

Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · Peter Zijlstra

Current hard-coded policies are:

- a user can clear the cookie of any process they can set a cookie for. Lack of a cookie *might* be a security issue if cookies are being used for that.

ChromeOS people, what are you doing about this? syscall/prctl filtering?

Yes, in ChromeOS, we allow the prctl(2) syscall only before entering the seccomp sandbox. Once we enter the sandbox, we do not allow the prctl(2).

This has the nice design that the security is enforced on entering the sandbox, and prior to entering the sandbox, no permissions need be given.

Let me know if that makes sense and if you had any other questions. thanks,

-Joel

author maintainer
#12 lore raw

PATCH 6/9 kselftest: Add test for core sched prctl interface

In reply to Peter Zijlstra

From: Chris Hyser <[email protected]>

Provides a selftest and examples of using the interface.

---
 tools/testing/selftests/sched/.gitignore      |    1 
 tools/testing/selftests/sched/Makefile        |   14 +
 tools/testing/selftests/sched/config          |    1 
 tools/testing/selftests/sched/cs_prctl_test.c |  356 ++++++++++++++++++++++++++
 4 files changed, 372 insertions(+)
 create mode 100644 tools/testing/selftests/sched/.gitignore
 create mode 100644 tools/testing/selftests/sched/Makefile
 create mode 100644 tools/testing/selftests/sched/config
 create mode 100644 tools/testing/selftests/sched/cs_prctl_test.c
tools/testing/selftests/sched/.gitignore new file +1 -0
@@ -0,0 +1 @@
+cs_prctl_test
tools/testing/selftests/sched/Makefile new file +14 -0
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
+CLANG_FLAGS += -no-integrated-as
+endif
+
+CFLAGS += -O2 -Wall -g -I./ -I../../../../usr/include/  -Wl,-rpath=./ \
+	  $(CLANG_FLAGS)
+LDLIBS += -lpthread
+
+TEST_GEN_FILES := cs_prctl_test
+TEST_PROGS := cs_prctl_test
+
+include ../lib.mk
tools/testing/selftests/sched/config new file +1 -0
@@ -0,0 +1 @@
+CONFIG_SCHED_DEBUG=y
tools/testing/selftests/sched/cs_prctl_test.c new file +356 -0

356 lines not on this page · raw message

author maintainer
#13 lore raw

PATCH 7/9 sched: Cgroup core-scheduling interface

In reply to Peter Zijlstra

Implement a basic cgroup core-scheduling interface.

A new cpu.core_sched file is added which takes the values 0,1. When set, the cgroup and all it's descendants will be granted the same cookie and thus allowed to share a core with each-other, but not with system tasks or tasks of other subtrees that might have another cookie.

The file is hierarchical, and a subtree can again set it to 1, in which case that subtree will get a different cookie and will no longer share with the parent tree.

For each task, the nearest core_sched parent 'wins'.

Interaction with the prctl() interface is non-existent and left for a future patch.

Noteably; this patch somewhat abuses cgroup_mutex. By holding cgroup_mutex over the write() operation, which sets the cookie, the cookie is stable in any cgroup callback (that is called with cgroup_mutex held). A future patch relies on ss->can_attach() and ss->attach() being 'atomic', which is hard to do without cgroup_mutex.

---
 kernel/sched/core.c  |  150 +++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/sched/sched.h |    7 ++
 2 files changed, 157 insertions(+)
kernel/sched/core.c +150 -0
@@ -5688,10 +5688,53 @@ static inline void sched_core_cpu_starti
 		}
 	}
 }
+
+void sched_core_cgroup_online(struct task_group *parent, struct task_group *tg)
+{
+	lockdep_assert_held(&cgroup_mutex);
+
+	if (parent->core_parent) {
+		WARN_ON_ONCE(parent->core_cookie);
+		WARN_ON_ONCE(!parent->core_parent->core_cookie);
+		tg->core_parent = parent->core_parent;
+
+	} else if (parent->core_cookie) {
+		WARN_ON_ONCE(parent->core_parent);
+		tg->core_parent = parent;
+	}
+}
+
+void sched_core_cgroup_free(struct task_group *tg)
+{
+	sched_core_put_cookie(tg->core_cookie);
+}
+
+unsigned long sched_core_cgroup_cookie(struct task_group *tg)
+{
+	unsigned long cookie = 0;
+
+	lockdep_assert_held(&cgroup_mutex);
+
+	if (tg->core_cookie)
+		cookie = tg->core_cookie;
+	else if (tg->core_parent)
+		cookie = tg->core_parent->core_cookie;
+
+	return sched_core_get_cookie(cookie);
+}
+
 #else /* !CONFIG_SCHED_CORE */
 
 static inline void sched_core_cpu_starting(unsigned int cpu) {}
 
+static inline void sched_core_cgroup_free(struct task_group *tg) { }
+static inline void sched_core_cgroup_online(struct task_group *parent, struct task_group tg) { }
+
+static inline unsigned long sched_core_cgroup_cookie(struct task_group *tg)
+{
+	return 0;
+}
+
 static struct task_struct *
 pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
 {
@@ -9310,6 +9353,7 @@ static void sched_free_group(struct task
 	free_fair_sched_group(tg);
 	free_rt_sched_group(tg);
 	autogroup_free(tg);
+	sched_core_cgroup_free(tg);
 	kmem_cache_free(task_group_cache, tg);
 }
 
@@ -9353,6 +9397,8 @@ void sched_online_group(struct task_grou
 	spin_unlock_irqrestore(&task_group_lock, flags);
 
 	online_fair_sched_group(tg);
+
+	sched_core_cgroup_online(parent, tg);
 }
 
 /* rcu callback to free various structures associated with a task group */
@@ -9414,6 +9460,7 @@ void sched_move_task(struct task_struct
 {
 	int queued, running, queue_flags =
 		DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK;
+	unsigned long cookie;
 	struct rq_flags rf;
 	struct rq *rq;
 
@@ -9443,6 +9490,10 @@ void sched_move_task(struct task_struct
 	}
 
 	task_rq_unlock(rq, tsk, &rf);
+
+	cookie = sched_core_cgroup_cookie(tsk->sched_task_group);
+	cookie = sched_core_update_cookie(tsk, cookie);
+	sched_core_put_cookie(cookie);
 }
 
 static inline struct task_group *css_tg(struct cgroup_subsys_state *css)
@@ -10050,6 +10101,89 @@ static u64 cpu_rt_period_read_uint(struc
 }
 #endif /* CONFIG_RT_GROUP_SCHED */
 
+#ifdef CONFIG_SCHED_CORE
+u64 cpu_sched_core_read_u64(struct cgroup_subsys_state *css, struct cftype *cft)
+{
+	return !!css_tg(css)->core_cookie;
+}
+
+int cpu_sched_core_write_u64(struct cgroup_subsys_state *css, struct cftype *cft, u64 val)
+{
+	unsigned long cookie = 0, old_cookie = 0;
+	struct task_group *tg = css_tg(css);
+	struct cgroup_subsys_state *cssi;
+	struct task_group *parent = NULL;
+	int ret = 0;
+
+	if (val > 1)
+		return -ERANGE;
+
+	if (!static_branch_likely(&sched_smt_present))
+		return -ENODEV;
+
+	mutex_lock(&cgroup_mutex);
+	if (!!val == !!tg->core_cookie)
+		goto unlock;
+
+	old_cookie = tg->core_cookie;
+	if (val) {
+		cookie = sched_core_alloc_cookie();
+		if (!cookie) {
+			ret = -ENOMEM;
+			goto unlock;
+		}
+		WARN_ON_ONCE(old_cookie);
+
+	} else if (tg->parent) {
+		if (tg->parent->core_parent)
+			parent = tg->parent->core_parent;
+		else if (tg->parent->core_cookie)
+			parent = tg->parent;
+	}
+
+	WARN_ON_ONCE(cookie && parent);
+
+	tg->core_cookie = sched_core_get_cookie(cookie);
+	tg->core_parent = parent;
+
+	if (cookie)
+		parent = tg;
+	else if (parent)
+		cookie = sched_core_get_cookie(parent->core_cookie);
+
+	css_for_each_descendant_pre(cssi, css) {
+		struct task_group *tgi = css_tg(cssi);
+		struct css_task_iter it;
+		struct task_struct *p;
+
+		if (tgi != tg) {
+			if (tgi->core_cookie || (tgi->core_parent && tgi->core_parent != tg))
+				continue;
+
+			tgi->core_parent = parent;
+			tgi->core_cookie = 0;
+		}
+
+		css_task_iter_start(cssi, 0, &it);
+		while ((p = css_task_iter_next(&it))) {
+			unsigned long p_cookie;
+
+			cookie = sched_core_get_cookie(cookie);
+			p_cookie = sched_core_update_cookie(p, cookie);
+			sched_core_put_cookie(p_cookie);
+		}
+		css_task_iter_end(&it);
+	}
+
+unlock:
+	mutex_unlock(&cgroup_mutex);
+
+	sched_core_put_cookie(cookie);
+	sched_core_put_cookie(old_cookie);
+	return ret;
+}
+#endif
+
 static struct cftype cpu_legacy_files[] = {
 #ifdef CONFIG_FAIR_GROUP_SCHED
 	{
@@ -10100,6 +10234,14 @@ static struct cftype cpu_legacy_files[]
 		.write = cpu_uclamp_max_write,
 	},
 #endif
+#ifdef CONFIG_SCHED_CORE
+	{
+		.name = "core_sched",
+		.flags = CFTYPE_NOT_ON_ROOT,
+		.read_u64 = cpu_sched_core_read_u64,
+		.write_u64 = cpu_sched_core_write_u64,
+	},
+#endif
 	{ }	/* Terminate */
 };
 
@@ -10281,6 +10423,14 @@ static struct cftype cpu_files[] = {
 		.write = cpu_uclamp_max_write,
 	},
 #endif
+#ifdef CONFIG_SCHED_CORE
+	{
+		.name = "core_sched",
+		.flags = CFTYPE_NOT_ON_ROOT,
+		.read_u64 = cpu_sched_core_read_u64,
+		.write_u64 = cpu_sched_core_write_u64,
+	},
+#endif
 	{ }	/* terminate */
 };
 
kernel/sched/sched.h +7 -0
@@ -431,6 +431,10 @@ struct task_group {
 	struct uclamp_se	uclamp[UCLAMP_CNT];
 #endif
 
+#ifdef CONFIG_SCHED_CORE
+	struct task_group	*core_parent;
+	unsigned long		core_cookie;
+#endif
 };
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
@@ -1130,6 +1134,9 @@ static inline bool is_migration_disabled
 
 struct sched_group;
 #ifdef CONFIG_SCHED_CORE
+
+extern struct mutex cgroup_mutex; // XXX
+
 DECLARE_STATIC_KEY_FALSE(__sched_core_enabled);
 static inline struct cpumask *sched_group_span(struct sched_group *sg);
 
#14 lore raw

Re: [PATCH 7/9] sched: Cgroup core-scheduling interface

Thanks, allowing for multiple group cookies in a hierarchy is a nice improvement.

kernel/sched/core.c static u64 cpu_rt_period_read_uint(struc · line 10164

Quoted 6 lines
kernel/sched/core.c +6 -0
+               if (tgi != tg) {
+                       if (tgi->core_cookie || (tgi->core_parent && tgi->core_parent != tg))
+                               continue;
+
+                       tgi->core_parent = parent;
+                       tgi->core_cookie = 0;

core_cookie must already be 0, given the check above.

author maintainer
#15 lore raw

PATCH 8/9 rbtree: Remove const from the rb_find_add() comparator

In reply to Peter Zijlstra

This allows the rb_find_add() comparator to modify existing entries.

---
 include/linux/rbtree.h       |    2 +-
 kernel/events/uprobes.c      |    2 +-
 tools/include/linux/rbtree.h |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
include/linux/rbtree.h +1 -1
@@ -248,7 +248,7 @@ rb_add(struct rb_node *node, struct rb_r
  */
 static __always_inline struct rb_node *
 rb_find_add(struct rb_node *node, struct rb_root *tree,
-	    int (*cmp)(struct rb_node *, const struct rb_node *))
+	    int (*cmp)(struct rb_node *, struct rb_node *))
 {
 	struct rb_node **link = &tree->rb_node;
 	struct rb_node *parent = NULL;
kernel/events/uprobes.c +1 -1
@@ -646,7 +646,7 @@ static inline int __uprobe_cmp_key(const
 	return uprobe_cmp(a->inode, a->offset, __node_2_uprobe(b));
 }
 
-static inline int __uprobe_cmp(struct rb_node *a, const struct rb_node *b)
+static inline int __uprobe_cmp(struct rb_node *a, struct rb_node *b)
 {
 	struct uprobe *u = __node_2_uprobe(a);
 	return uprobe_cmp(u->inode, u->offset, __node_2_uprobe(b));
tools/include/linux/rbtree.h +1 -1
@@ -232,7 +232,7 @@ rb_add(struct rb_node *node, struct rb_r
  */
 static __always_inline struct rb_node *
 rb_find_add(struct rb_node *node, struct rb_root *tree,
-	    int (*cmp)(struct rb_node *, const struct rb_node *))
+	    int (*cmp)(struct rb_node *, struct rb_node *))
 {
 	struct rb_node **link = &tree->rb_node;
 	struct rb_node *parent = NULL;
author maintainer
#16 lore raw

PATCH 9/9 sched: prctl() and cgroup interaction

In reply to Peter Zijlstra

All the nasty bits that manage prctl() and cgroup core-sched interaction.

In order to manage this; a 'fat' cookie is introduced, this is basically a nested cookie that links to two other cookies. Any unique combination of task and cgroup cookies will get _one_ fat cookie.

Uniqueness of fat cookies is ensured by use of a global tree.

Due to the locking rules for cookies, the need for fat cookies is not apparent up-front, nor can they be allocated in-situ, therefore pre-allocate them agressively and mostly free them instantly when not used.

---
 include/linux/sched.h     |    1 
 kernel/sched/core.c       |   25 +++
 kernel/sched/core_sched.c |  329 ++++++++++++++++++++++++++++++++++++++++++----
 kernel/sched/sched.h      |   11 +
 4 files changed, 337 insertions(+), 29 deletions(-)
include/linux/sched.h +1 -0
@@ -704,6 +704,7 @@ struct task_struct {
 #ifdef CONFIG_SCHED_CORE
 	struct rb_node			core_node;
 	unsigned long			core_cookie;
+	void				*core_spare_fat;
 	unsigned int			core_occupation;
 #endif
 
kernel/sched/core.c +22 -3
@@ -9487,7 +9487,7 @@ void sched_move_task(struct task_struct
 	task_rq_unlock(rq, tsk, &rf);
 
 	cookie = sched_core_cgroup_cookie(tsk->sched_task_group);
-	cookie = sched_core_update_cookie(tsk, cookie);
+	cookie = sched_core_update_cookie(tsk, cookie | GROUP_COOKIE);
 	sched_core_put_cookie(cookie);
 }
 
@@ -9592,6 +9592,10 @@ static int cpu_cgroup_can_attach(struct
 
 		if (ret)
 			break;
+
+		ret = sched_core_prealloc_fat(task);
+		if (ret)
+			break;
 	}
 	return ret;
 }
@@ -10122,13 +10126,28 @@ int cpu_sched_core_write_u64(struct cgro
 
 	old_cookie = tg->core_cookie;
 	if (val) {
-		cookie = sched_core_alloc_cookie();
+		cookie = sched_core_alloc_cookie(GROUP_COOKIE);
 		if (!cookie) {
 			ret = -ENOMEM;
 			goto unlock;
 		}
 		WARN_ON_ONCE(old_cookie);
 
+		css_for_each_descendant_pre(cssi, css) {
+			struct css_task_iter it;
+			struct task_struct *p;
+
+			css_task_iter_start(cssi, 0, &it);
+			while ((p = css_task_iter_next(&it))) {
+				ret = sched_core_prealloc_fat(p);
+				if (ret) {
+					css_task_iter_end(&it);
+					goto unlock;
+				}
+			}
+			css_task_iter_end(&it);
+		}
+
 	} else if (tg->parent) {
 		if (tg->parent->core_parent)
 			parent = tg->parent->core_parent;
@@ -10164,7 +10183,7 @@ int cpu_sched_core_write_u64(struct cgro
 			unsigned long p_cookie;
 
 			cookie = sched_core_get_cookie(cookie);
-			p_cookie = sched_core_update_cookie(p, cookie);
+			p_cookie = sched_core_update_cookie(p, cookie | GROUP_COOKIE);
 			sched_core_put_cookie(p_cookie);
 		}
 		css_task_iter_end(&it);
kernel/sched/core_sched.c +304 -25

466 lines not on this page · raw message

kernel/sched/sched.h +10 -1
@@ -1240,10 +1240,14 @@ extern void sched_core_dequeue(struct rq
 extern void sched_core_get(void);
 extern void sched_core_put(void);
 
-extern unsigned long sched_core_alloc_cookie(void);
+#define TASK_COOKIE	0x01
+#define GROUP_COOKIE	0x02
+
+extern unsigned long sched_core_alloc_cookie(unsigned int type);
 extern void sched_core_put_cookie(unsigned long cookie);
 extern unsigned long sched_core_get_cookie(unsigned long cookie);
 extern unsigned long sched_core_update_cookie(struct task_struct *p, unsigned long cookie);
+extern int sched_core_prealloc_fat(struct task_struct *p);
 
 #else /* !CONFIG_SCHED_CORE */
 
@@ -1257,6 +1261,11 @@ static inline bool sched_core_disabled(v
 	return true;
 }
 
+static inline int sched_core_prealloc_fat(struct task_struct *p)
+{
+	return 0;
+}
+
 static inline raw_spinlock_t *rq_lockp(struct rq *rq)
 {
 	return &rq->__lock;
#17 lore raw

Re: [PATCH 9/9] sched: prctl() and cgroup interaction

Hi Peter,

I walked through the reference counting, and it seems good to me (though it did take a few passes to fully digest the invariants for the fat cookie stuff).

Quoted 12 lines
kernel/sched/core_sched.c +4 -2
+unsigned long sched_core_alloc_cookie(unsigned int type)
 {
        struct sched_core_cookie *ck = kmalloc(sizeof(*ck), GFP_KERNEL);
        if (!ck)
                return 0;
-       refcount_set(&ck->refcnt, 1);
+       WARN_ON_ONCE(type > GROUP_COOKIE);
+       sched_core_init_cookie(ck, type);
        sched_core_get();
 
-       return (unsigned long)ck;
+       return (unsigned long)ck | type;
Quoted 1 line

}

This feels like it needs to be stronger than a WARN_ON_ONCE; could create a corrupted address that we later try to kfree().

Also, for my own edification, why will the bottom two bits here always be 0?

kernel/sched/core_sched.c line 25

Quoted 10 lines
kernel/sched/core_sched.c +9 -1
-unsigned long sched_core_alloc_cookie(void)
+static inline void *cookie_ptr(unsigned long cookie)
+{
+       return (void *)(cookie & ~3UL);
+}
+
+static inline int cookie_type(unsigned long cookie)
+{
+       return cookie & 3;
+}

s/3/FAT_COOKIE

Quoted 1 line

+#define FAT_COOKIE 0x03

Move to sched.h to group with TASK/GROUP_COOKIE?

kernel/sched/core_sched.c line 106

Quoted 4 lines
kernel/sched/core_sched.c +4 -0
+static unsigned long __sched_core_fat_cookie(struct task_struct *p,
+                                            void **spare_fat,
+                                            unsigned long cookie)
+{

This function looks good to me, but could use some more comments about the pre/post-condition assumptions. Ie. cookie already has a get() associated with it, caller is expected to kfree the spare_fat.

kernel/sched/core_sched.c line 169

Quoted 7 lines
kernel/sched/core_sched.c +7 -0
+       raw_spin_lock_irqsave(&fat_lock, flags);
+       n = rb_find_add(&fat->node, &fat_root, fat_cmp);
+       raw_spin_unlock_irqrestore(&fat_lock, flags);
+
+       if (n) {
+               sched_core_put_fat(fat);
+               fat = node_2_fat(n);

This put() doesn't seem strictly necessary; caller will be unconditionally freeing the spare_fat. Keep anyway for completeness, but add a comment?

author maintainer
#18 lore raw

Re: [PATCH 9/9] sched: prctl() and cgroup interaction

Quoted 16 lines · Josh Don

Hi Peter,

I walked through the reference counting, and it seems good to me (though it did take a few passes to fully digest the invariants for the fat cookie stuff).

Quoted 10 lines
kernel/sched/core_sched.c +3 -1
+unsigned long sched_core_alloc_cookie(unsigned int type)
 {
        struct sched_core_cookie *ck = kmalloc(sizeof(*ck), GFP_KERNEL);
        if (!ck)
                return 0;
-       refcount_set(&ck->refcnt, 1);
+       WARN_ON_ONCE(type > GROUP_COOKIE);
+       sched_core_init_cookie(ck, type);
        sched_core_get();
Quoted 6 lines
Quoted 3 lines
kernel/sched/core_sched.c +1 -1
-       return (unsigned long)ck;
+       return (unsigned long)ck | type;

}

This feels like it needs to be stronger than a WARN_ON_ONCE; could create a corrupted address that we later try to kfree().

The fattie is also released with kfree(), not a real problem that.

Quoted 1 line

Also, for my own edification, why will the bottom two bits here always be 0?

#define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long)

Quoted 4 lines
Quoted 4 lines
kernel/sched/core_sched.c +3 -1
-unsigned long sched_core_alloc_cookie(void)
+static inline void *cookie_ptr(unsigned long cookie)
+{
+       return (void *)(cookie & ~3UL);
Quoted 8 lines

kernel/sched/core_sched.c line 25

Quoted 6 lines
kernel/sched/core_sched.c +6 -0
+}
+
+static inline int cookie_type(unsigned long cookie)
+{
+       return cookie & 3;
+}

s/3/FAT_COOKIE

COOKIE_MASK if anything..

Quoted 3 lines
Quoted 1 line

+#define FAT_COOKIE 0x03

Move to sched.h to group with TASK/GROUP_COOKIE?

Didn't want to expose FAT outside the ifdef

Quoted 8 lines

kernel/sched/core_sched.c line 106

Quoted 4 lines
kernel/sched/core_sched.c +4 -0
+static unsigned long __sched_core_fat_cookie(struct task_struct *p,
+                                            void **spare_fat,
+                                            unsigned long cookie)
+{

This function looks good to me, but could use some more comments about the pre/post-condition assumptions. Ie. cookie already has a get() associated with it, caller is expected to kfree the spare_fat.

Fair enough. I'll go write up something. I had to fix a refcount issue here, which should've been clue a comment it required.

There's actually a bug with the rb tree magic too, I'll go fix.

Quoted 11 lines

kernel/sched/core_sched.c line 169

Quoted 7 lines
kernel/sched/core_sched.c +7 -0
+       raw_spin_lock_irqsave(&fat_lock, flags);
+       n = rb_find_add(&fat->node, &fat_root, fat_cmp);
+       raw_spin_unlock_irqrestore(&fat_lock, flags);
+
+       if (n) {
+               sched_core_put_fat(fat);
+               fat = node_2_fat(n);

This put() doesn't seem strictly necessary; caller will be unconditionally freeing the spare_fat. Keep anyway for completeness, but add a comment?

It needs to put the references we got on constructing the new fat.

#19 lore raw
In reply to Peter Zijlstra

cc'ing Michal and Christian who've been spending some time on cgroup interface issues recently and Li Zefan for cpuset.

Quoted 4 lines · Peter Zijlstra

The cgroup interface now uses a 'core_sched' file, which still takes 0,1. It is however changed such that you can have nested tags. The for any given task, the first parent with a cookie is the effective one. The rationale is that this way you can delegate subtrees and still allow them some control over grouping.

I find it difficult to like the proposed interface from the name (the term "core" is really confusing given how the word tends to be used internally) to the semantics (it isn't like anything else) and even the functionality (we're gonna have fixed processors at some point, right?).

Here are some preliminary thoughts:

* Are both prctl and cgroup based interfaces really necessary? I could be being naive but given that we're (hopefully) working around hardware deficiencies which will go away in time, I think there's a strong case for minimizing at least the interface to the bare minimum.

Given how cgroups are set up (membership operations happening only for seeding, especially with the new clone interface), it isn't too difficult to synchronize process tree and cgroup hierarchy where it matters - ie. given the right per-process level interface, restricting configuration for a cgroup sub-hierarchy may not need any cgroup involvement at all. This also nicely gets rid of the interaction between prctl and cgroup bits.

* If we *have* to have cgroup interface, I wonder whether this would fit a lot better as a part of cpuset. If you squint just right, this can be viewed as some dynamic form of cpuset. Implementation-wise, it probably won't integrate with the rest but I think the feature will be less jarring as a part of cpuset, which already is a bit of kitchensink anyway.

Quoted 9 lines

The cgroup thing also '(ab)uses' cgroup_mutex for serialization because it needs to ensure continuity between ss->can_attach() and ss->attach() for the memory allocation. If the prctl() were allowed to interleave it might steal the memory.

Using cgroup_mutex feels icky, but is not without precedent, kernel/bpf/cgroup.c does the same thing afaict.

TJ, can you please have a look at this?

Yeah, using cgroup_mutex for stabilizing cgroup hierarchy for consecutive operations is fine. It might be worthwhile to break that out into a proper interface but that's the least of concerns here.

Can someone point me to a realistic and concrete usage scenario for this feature?

Thanks.

Signature · 1 line
tejun
#20 lore raw

Hi TJ, Peter,

Quoted 15 lines · Tejun Heo

cc'ing Michal and Christian who've been spending some time on cgroup interface issues recently and Li Zefan for cpuset.

Quoted 4 lines · Peter Zijlstra

The cgroup interface now uses a 'core_sched' file, which still takes 0,1. It is however changed such that you can have nested tags. The for any given task, the first parent with a cookie is the effective one. The rationale is that this way you can delegate subtrees and still allow them some control over grouping.

I find it difficult to like the proposed interface from the name (the term "core" is really confusing given how the word tends to be used internally) to the semantics (it isn't like anything else) and even the functionality (we're gonna have fixed processors at some point, right?).

Quoted 6 lines

Here are some preliminary thoughts:

* Are both prctl and cgroup based interfaces really necessary? I could be being naive but given that we're (hopefully) working around hardware deficiencies which will go away in time, I think there's a strong case for minimizing at least the interface to the bare minimum.

I don't think these issues are going away as there are constantly new exploits related to SMT that are coming out. Further, core scheduling is not only for SMT - there are other usecases as well (such as VM performance by preventing vCPU threads from core-sharing).

Quoted 12 lines

Given how cgroups are set up (membership operations happening only for seeding, especially with the new clone interface), it isn't too difficult to synchronize process tree and cgroup hierarchy where it matters - ie. given the right per-process level interface, restricting configuration for a cgroup sub-hierarchy may not need any cgroup involvement at all. This also nicely gets rid of the interaction between prctl and cgroup bits.
* If we *have* to have cgroup interface, I wonder whether this would fit a lot better as a part of cpuset. If you squint just right, this can be viewed as some dynamic form of cpuset. Implementation-wise, it probably won't integrate with the rest but I think the feature will be less jarring as a part of cpuset, which already is a bit of kitchensink anyway.

I think both interfaces are important for different reasons. Could you take a look at the initial thread I started few months ago? I tried to elaborate about usecases in detail:
http://lore.kernel.org/r/[email protected]

Also, in ChromeOS we can't use CGroups for this purpose. The CGroup hierarchy does not fit well with the threads we are tagging. Also, we use CGroup v1, and since CGroups cannot overlap, this is impossible let alone cumbersome. And, the CGroup interface having core scheduling is still useful for people using containers and wanting to core-schedule each container separately ( +Hao Luo can elaborate more on that, but I did describe it in the link above).

Quoted 8 lines
Quoted 8 lines

The cgroup thing also '(ab)uses' cgroup_mutex for serialization because it needs to ensure continuity between ss->can_attach() and ss->attach() for the memory allocation. If the prctl() were allowed to interleave it might steal the memory.

Using cgroup_mutex feels icky, but is not without precedent, kernel/bpf/cgroup.c does the same thing afaict.

Quoted 8 lines
Quoted 1 line

TJ, can you please have a look at this?

Yeah, using cgroup_mutex for stabilizing cgroup hierarchy for consecutive operations is fine. It might be worthwhile to break that out into a proper interface but that's the least of concerns here.

Can someone point me to a realistic and concrete usage scenario for this feature?

Yeah, its at http://lore.kernel.org/r/[email protected]
as mentioned above, let me know if you need any more details about usecase.

About the file name, how about kernel/sched/smt.c ? That definitely provides more information than 'core_sched.c'.

Thanks,
- Joel

#21 lore raw

Hello,

Quoted 3 lines · Joel Fernandes

Yeah, its at http://lore.kernel.org/r/[email protected]
as mentioned above, let me know if you need any more details about usecase.

Except for the unspecified reason in usecase 4, I don't see why cgroup is in the picture at all. This doesn't really have much to do with hierarchical resource distribution. Besides, yes, you can use cgroup for logical structuring and identificaiton purposes but in those cases the interactions and interface should be with the original subsystem while using cgroup IDs or paths as parameters - see tracing and bpf for examples.

Thanks.

Signature · 1 line
tejun
#22 lore raw
Quoted 7 lines · Tejun Heo

Hello,

Quoted 3 lines · Joel Fernandes

Yeah, its at http://lore.kernel.org/r/[email protected]
as mentioned above, let me know if you need any more details about usecase.

Quoted 6 lines

Except for the unspecified reason in usecase 4, I don't see why cgroup is in the picture at all. This doesn't really have much to do with hierarchical resource distribution. Besides, yes, you can use cgroup for logical structuring and identificaiton purposes but in those cases the interactions and interface should be with the original subsystem while using cgroup IDs or paths as parameters - see tracing and bpf for examples.

Personally for ChromeOS, we need only the per-task interface. Considering that the second argument of this prctl is a command, I don't see why we cannot add a new command PR_SCHED_CORE_CGROUP_SHARE to do what Tejun is saying (in the future).

In order to not block ChromeOS and other "per-task interface" usecases, I suggest we keep the CGroup interface for a later time (whether that's through prctl or the CGroups FS way which Tejun dislikes) and move forward with per-task interface only initially.

Peter, any thoughts on this?

thanks,

- Joel

author maintainer
#23 lore raw
Quoted 20 lines · Joel Fernandes
Quoted 7 lines · Tejun Heo

Hello,

Quoted 3 lines · Joel Fernandes

Yeah, its at http://lore.kernel.org/r/[email protected]
as mentioned above, let me know if you need any more details about usecase.

Quoted 6 lines

Except for the unspecified reason in usecase 4, I don't see why cgroup is in the picture at all. This doesn't really have much to do with hierarchical resource distribution. Besides, yes, you can use cgroup for logical structuring and identificaiton purposes but in those cases the interactions and interface should be with the original subsystem while using cgroup IDs or paths as parameters - see tracing and bpf for examples.

Personally for ChromeOS, we need only the per-task interface. Considering that the second argument of this prctl is a command, I don't see why we cannot add a new command PR_SCHED_CORE_CGROUP_SHARE to do what Tejun is saying (in the future).

Quoted 4 lines

In order to not block ChromeOS and other "per-task interface" usecases, I suggest we keep the CGroup interface for a later time (whether that's through prctl or the CGroups FS way which Tejun dislikes) and move forward with per-task interface only initially.

Josh, you being on the other Google team, the one that actually uses the cgroup interface AFAIU, can you fight the good fight with TJ on this?

Quoted 1 line

Peter, any thoughts on this?

Adding CGROUP_SHARE is not sufficient to close the hole against CLEAR. So we either then have to 'tweak' the meaning of CLEAR or replace it entirely, neither seem attractive.

I'd love to make some progress on all this.

author maintainer
#24 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 1 line · Joel Fernandes

Peter, any thoughts on this?

Adding CGROUP_SHARE is not sufficient to close the hole against CLEAR. So we either then have to 'tweak' the meaning of CLEAR or replace it entirely, neither seem attractive.

I'd love to make some progress on all this.

Can I comment out CLEAR so we can sort that out later? I suppose people can still do temp cookies simply by using a temp task.

#25 lore raw
Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · Peter Zijlstra
Quoted 1 line · Joel Fernandes

Peter, any thoughts on this?

Quoted 8 lines
Quoted 6 lines

Adding CGROUP_SHARE is not sufficient to close the hole against CLEAR. So we either then have to 'tweak' the meaning of CLEAR or replace it entirely, neither seem attractive.

I'd love to make some progress on all this.

Can I comment out CLEAR so we can sort that out later? I suppose people

I merely added CLEAR for completeness. Ultimately, I think having to kill a process because a cookie got set by mistake is bad, but it can absolutely be sorted out later.

-chrish

author maintainer
#26 lore raw
In reply to Tejun Heo
Quoted 9 lines · Tejun Heo

cc'ing Michal and Christian who've been spending some time on cgroup interface issues recently and Li Zefan for cpuset.

Quoted 4 lines · Peter Zijlstra

The cgroup interface now uses a 'core_sched' file, which still takes 0,1. It is however changed such that you can have nested tags. The for any given task, the first parent with a cookie is the effective one. The rationale is that this way you can delegate subtrees and still allow them some control over grouping.

Quoted 4 lines

I find it difficult to like the proposed interface from the name (the term "core" is really confusing given how the word tends to be used internally) to the semantics (it isn't like anything else) and even the functionality (we're gonna have fixed processors at some point, right?).

Core is the topological name for the thing that hosts the SMT threads. Can't really help that.

Quoted 6 lines

Here are some preliminary thoughts:

* Are both prctl and cgroup based interfaces really necessary? I could be being naive but given that we're (hopefully) working around hardware deficiencies which will go away in time, I think there's a strong case for minimizing at least the interface to the bare minimum.

I'm not one for cgroups much, so I'll let others argue that case, except that per systemd and all the other new fangled shit, people seem to use cgroups a lot to group tasks. So it makes sense to also expose this through cgroups in some form.

That said; I've had requests from lots of non security folks about this feature to help mitigate the SMT interference.

Consider for example Real-Time. If you have an active SMT sibling, the CPU performance is much less than it would be when the SMT sibling is idle. Therefore, for the benefit of determinism, it would be very nice if RT tasks could force-idle their SMT siblings, and voila, this interface allows exactly that.

The same is true for other workloads that care about interference.

Quoted 6 lines

Given how cgroups are set up (membership operations happening only for seeding, especially with the new clone interface), it isn't too difficult to synchronize process tree and cgroup hierarchy where it matters - ie. given the right per-process level interface, restricting configuration for a cgroup sub-hierarchy may not need any cgroup involvement at all. This also nicely gets rid of the interaction between prctl and cgroup bits.

I've no idea what you mean :/ The way I use cgroups (when I have to, for testing) is to echo the pid into /cgroup/foo/tasks. No clone or anything involved.

None of my test machines come up with cgroupfs mounted, and any and all cgroup setup is under my control.

Quoted 5 lines

* If we *have* to have cgroup interface, I wonder whether this would fit a lot better as a part of cpuset. If you squint just right, this can be viewed as some dynamic form of cpuset. Implementation-wise, it probably won't integrate with the rest but I think the feature will be less jarring as a part of cpuset, which already is a bit of kitchensink anyway.

Not sure I agree, we do not change the affinity of things, we only control who's allowed to run concurrently on SMT siblings. There could be a cpuset partition split between the siblings and it would still work fine.

#27 lore raw

Hello,

Quoted 7 lines · Peter Zijlstra
Quoted 4 lines

I find it difficult to like the proposed interface from the name (the term "core" is really confusing given how the word tends to be used internally) to the semantics (it isn't like anything else) and even the functionality (we're gonna have fixed processors at some point, right?).

Core is the topological name for the thing that hosts the SMT threads. Can't really help that.

I find the name pretty unfortunate given how overloaded the term is generally and also in kernel but oh well...

Quoted 11 lines
Quoted 6 lines

Here are some preliminary thoughts:

* Are both prctl and cgroup based interfaces really necessary? I could be being naive but given that we're (hopefully) working around hardware deficiencies which will go away in time, I think there's a strong case for minimizing at least the interface to the bare minimum.

I'm not one for cgroups much, so I'll let others argue that case, except that per systemd and all the other new fangled shit, people seem to use cgroups a lot to group tasks. So it makes sense to also expose this through cgroups in some form.

All the new fangled things follow a certain usage pattern which makes aligning parts of process tree with cgroup layout trivial, so when restrictions can be applied along the process tree like this and there isn't a particular need for dynamic hierarchical control, there isn't much need for direct cgroup interface.

Quoted 10 lines

That said; I've had requests from lots of non security folks about this feature to help mitigate the SMT interference.

Consider for example Real-Time. If you have an active SMT sibling, the CPU performance is much less than it would be when the SMT sibling is idle. Therefore, for the benefit of determinism, it would be very nice if RT tasks could force-idle their SMT siblings, and voila, this interface allows exactly that.

The same is true for other workloads that care about interference.

I see.

Quoted 10 lines
Quoted 6 lines

Given how cgroups are set up (membership operations happening only for seeding, especially with the new clone interface), it isn't too difficult to synchronize process tree and cgroup hierarchy where it matters - ie. given the right per-process level interface, restricting configuration for a cgroup sub-hierarchy may not need any cgroup involvement at all. This also nicely gets rid of the interaction between prctl and cgroup bits.

I've no idea what you mean :/ The way I use cgroups (when I have to, for testing) is to echo the pid into /cgroup/foo/tasks. No clone or anything involved.

The usage pattern is creating a new cgroup, seeding it with a process (either writing to tasks or using CLONE_INTO_CGROUP) and let it continue only on that sub-hierarchy, so cgroup hierarchy usually partially overlays process trees.

Quoted 9 lines

None of my test machines come up with cgroupfs mounted, and any and all cgroup setup is under my control.

Quoted 5 lines

* If we *have* to have cgroup interface, I wonder whether this would fit a lot better as a part of cpuset. If you squint just right, this can be viewed as some dynamic form of cpuset. Implementation-wise, it probably won't integrate with the rest but I think the feature will be less jarring as a part of cpuset, which already is a bit of kitchensink anyway.

Quoted 4 lines

Not sure I agree, we do not change the affinity of things, we only control who's allowed to run concurrently on SMT siblings. There could be a cpuset partition split between the siblings and it would still work fine.

I see. Yeah, if we really need it, I'm not sure it fits in cgroup interface proper. As I wrote elsewhere, these things are usually implemented on the originating subsystem interface with cgroup ID as a parameter.

Thanks.

Signature · 1 line
tejun
author maintainer
#28 lore raw
Quoted 3 lines · Tejun Heo

I see. Yeah, if we really need it, I'm not sure it fits in cgroup interface proper. As I wrote elsewhere, these things are usually implemented on the originating subsystem interface with cgroup ID as a parameter.

This would be something like:

  prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_FROM, cgroup-fd, PIDTYPE_CGROUP, NULL);

right? Where we assign to self the cookie from the cgroup.

The problem I see with this is that a task can trivially undo/circumvent this by calling PR_SCHED_CORE_CLEAR on itself, at which point it can share with system tasks again.

Also, it doesn't really transfer well to the group/tasks thing. When a task joins a cgroup, it doesn't automagically gain the cgroup properties. Whoever does the transition will then also have to prctl() this, which nobody will do.

#29 lore raw
In reply to Tejun Heo

Hello.

IIUC, the premise is that the tasks that have different cookies imply they would never share a core.

Quoted 4 lines · Peter Zijlstra

The cgroup interface now uses a 'core_sched' file, which still takes 0,1. It is however changed such that you can have nested tags. The for any given task, the first parent with a cookie is the effective one. The rationale is that this way you can delegate subtrees and still allow them some control over grouping.

Given the existence of prctl and clone APIs, I don't see the reason to have a separate cgroup-bound interface too (as argued by Tejun). The potential speciality is the possibility to re-tag whole groups of processes at runtime (but the listed use cases [1] don't require that and it's not such a good idea given its asynchronicity).

Also, I would find useful some more explanation how the hierarchical behavior is supposed to work. In my understanding the task is either allowed to request its own isolation or not. The cgroups could be used to restrict this privilege, however, that doesn't seem to be the case here.

My two cents,
Michal

[1] https://lore.kernel.org/lkml/[email protected]/

author maintainer
#30 lore raw
Quoted 4 lines · Michal Koutný

Hello.

IIUC, the premise is that the tasks that have different cookies imply they would never share a core.

Correct.

Quoted 8 lines · Peter Zijlstra
Quoted 4 lines

The cgroup interface now uses a 'core_sched' file, which still takes 0,1. It is however changed such that you can have nested tags. The for any given task, the first parent with a cookie is the effective one. The rationale is that this way you can delegate subtrees and still allow them some control over grouping.

Given the existence of prctl and clone APIs, I don't see the reason to have a separate cgroup-bound interface too (as argued by Tejun).

IMO as long as cgroups have that tasks file, you get to support people using it. That means that tasks joining your cgroup need to 'inherit' cgroup properties.

That's not something covered by either prctl or clone.

Quoted 3 lines

The potential speciality is the possibility to re-tag whole groups of processes at runtime (but the listed use cases [1] don't require that and it's not such a good idea given its asynchronicity).

That seems to be the implication of having that tasks file. Tasks can join a cgroup, so you get to deal with that.

You can't just say, don't do that then.

Quoted 5 lines

Also, I would find useful some more explanation how the hierarchical behavior is supposed to work. In my understanding the task is either allowed to request its own isolation or not. The cgroups could be used to restrict this privilege, however, that doesn't seem to be the case here.

Given something like:

	R
       / \
      A   B
         / \
	C   D

B group can set core_sched=1 and then all its (and its decendants) tasks get to have the same (group) cookie and cannot share with others.

If however B is a delegate and has a subgroup D that is security sensitive and must not share core resources with the rest of B, then it can also set D.core_sched=1, such that D (and its decendants) will have another (group) cookie.

On top of this, say C has a Real-Time tasks, that wants to limit SMT interference, then it can set a (task/prctl) cookie on itself, such that it will not share the core with the rest of the tasks of B.

In that scenario the D subtree is a restriction (doesn't share) with the B subtree.

And all of B is a restriction on all its tasks, including the Real-Time task that set a task cookie, in that none of them can share with tasks outside of B (including system tasks which are in R), irrespective of what they do with their task cookie.

#31 lore raw
Quoted 3 lines · Peter Zijlstra

IMO as long as cgroups have that tasks file, you get to support people using it. That means that tasks joining your cgroup need to 'inherit' cgroup properties.

The tasks file is consequence of binding this to cgroups, I'm one step back. Why to make "core isolation" a cgroup property?

(I understand this could help "visualize" what the common domains are if cgroups were the only API but with prctl the structure can be arbitrarily modified anyway.)

Quoted 7 lines

Given something like:

        R
       / \
      A   B
         / \
        C   D

Thanks for the example.

Quoted 2 lines

B group can set core_sched=1 and then all its (and its decendants) tasks get to have the same (group) cookie and cannot share with others.

The same could be achieved with the first task of group B allocating its new cookie which would be inherited in its descednants.

Quoted 4 lines

If however B is a delegate and has a subgroup D that is security sensitive and must not share core resources with the rest of B, then it can also set D.core_sched=1, such that D (and its decendants) will have another (group) cookie.

If there is such a sensitive descendant task, it could allocate a new cookie (same way as the first one in B did).

Quoted 3 lines

On top of this, say C has a Real-Time tasks, that wants to limit SMT interference, then it can set a (task/prctl) cookie on itself, such that it will not share the core with the rest of the tasks of B.

(IIUC, in this particular example it'd be redundant if B had no inner tasks since D isolated itself already.)
Yes, so this is again the same pattern as the tasks above have done.

Quoted 2 lines

In that scenario the D subtree is a restriction (doesn't share) with the B subtree.

This implies D's isolation from everything else too, not just B's members, no?

Quoted 4 lines

And all of B is a restriction on all its tasks, including the Real-Time task that set a task cookie, in that none of them can share with tasks outside of B (including system tasks which are in R), irrespective of what they do with their task cookie.

IIUC, the equivalent restriction could be achieved with the PTRACE-like check in the prctl API too (with respectively divided uids).

I'm curious whether the cgroup API actually simplifies things that are possible with the clone/prctl API or allows anything that wouldn't be otherwise possible.

Regards,
Michal

author maintainer
#32 lore raw
Quoted 6 lines · Michal Koutný
Quoted 3 lines · Peter Zijlstra

IMO as long as cgroups have that tasks file, you get to support people using it. That means that tasks joining your cgroup need to 'inherit' cgroup properties.

The tasks file is consequence of binding this to cgroups, I'm one step back. Why to make "core isolation" a cgroup property?

Yeah, dunno, people asked for it. I'm just proposing an implementation that, when given the need, seems to make sense and is internally consistent.

Quoted 12 lines

(I understand this could help "visualize" what the common domains are if cgroups were the only API but with prctl the structure can be arbitrarily modified anyway.)

Quoted 7 lines

Given something like:

        R
       / \
      A   B
         / \
        C   D
Quoted 6 lines

Thanks for the example.

Quoted 2 lines

B group can set core_sched=1 and then all its (and its decendants) tasks get to have the same (group) cookie and cannot share with others.

The same could be achieved with the first task of group B allocating its new cookie which would be inherited in its descednants.

Except then the task can CLEAR its own cookie and escape the constraint.

Quoted 4 lines
Quoted 2 lines

In that scenario the D subtree is a restriction (doesn't share) with the B subtree.

This implies D's isolation from everything else too, not just B's members, no?

Correct. Look at it as a contraint on co-scheduling, you can never, whatever you do, share an SMT sibling with someone outside your subtree.

Quoted 6 lines
Quoted 4 lines

And all of B is a restriction on all its tasks, including the Real-Time task that set a task cookie, in that none of them can share with tasks outside of B (including system tasks which are in R), irrespective of what they do with their task cookie.

IIUC, the equivalent restriction could be achieved with the PTRACE-like check in the prctl API too (with respectively divided uids).

I'm not sure I understand; if tasks in A and B are of the same user, then ptrace will not help anything. And per the above, you always have ptrace on yourself so you can escape your constraint per the above.

Quoted 3 lines

I'm curious whether the cgroup API actually simplifies things that are possible with the clone/prctl API or allows anything that wouldn't be otherwise possible.

With the cgroup API it is impossible for a task to escape the cgroup constraint. It can never share a core with anything not in the subtree.

This is not possible with just the task interface.

If this is actually needed I've no clue, IMO all of cgroups is not needed :-) Clearly other people feel differently about that.

Much of this would go away if CLEAR were not possible I suppose. But IIRC the idea was to let a task isolate itself temporarily, while doing some sensitive thing (eg. encrypt an email) but otherwise not be constrained. But I'm not sure I can remember all the various things people wanted this crud for :/

#33 lore raw
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Michal Koutný

I'm curious whether the cgroup API actually simplifies things that are possible with the clone/prctl API or allows anything that wouldn't be otherwise possible.

Quoted 7 lines

With the cgroup API it is impossible for a task to escape the cgroup constraint. It can never share a core with anything not in the subtree.

This is not possible with just the task interface.

If this is actually needed I've no clue, IMO all of cgroups is not needed :-) Clearly other people feel differently about that.

The cgroup interface seems very nice from a management perspective; moving arbitrary tasks around in the cgroup hierarchy will handle the necessary cookie adjustments to ensure that nothing shares with an unexpected task. It also makes auditing the core scheduling groups very straightforward; anything in a cookie'd cgroup's tasks file will be guaranteed isolated from the rest of the system, period.

Further, if a system management thread wants two arbitrary tasks A and B to share a cookie, this seems more painful with the PRCTL interface. The management thread would need to something like
- PR_SCHED_CORE_CREATE
- PR_SCHED_CORE_SHARE_TO A
- PR_SCHED_CORE_SHARE_TO B
- PR_SCHED_CORE_CLEAR

#34 lore raw
In reply to Peter Zijlstra

Hello,

Sorry about late reply.

Quoted 5 lines · Peter Zijlstra
Quoted 2 lines

Given the existence of prctl and clone APIs, I don't see the reason to have a separate cgroup-bound interface too (as argued by Tejun).

IMO as long as cgroups have that tasks file, you get to support people using it. That means that tasks joining your cgroup need to 'inherit'

This argument doesn't really make sense to me. We don't just add things to make interfaces orthogonal. It can be a consideration but not the only or even one of the most important ones. There are many cases we say to not shoot oneself in the foot and also many interfaces which are fading away or in the process of being deprecated.

I'm not planning to deprecate the dynamic migration interfaces given the history and usefulness in testing but the usage model of cgroup2 is clearly defined and documented in this regard - whether the initial population of the cgroup happens through CLONE_INTO_CGROUP or migration, for resource tracking and control purposes, cgroup2 does not support dynamic migration with the exception of migrations within threaded domains.

Anything is a possibility but given how this requirement is intertwined with achieveing comprehensive resource control, a core goal of cgroup2, and widely adopted by all the new fangled things as you put it, changing this wouldn't be easy. Not just because some people including me are against it but because there are inherent technical challenges and overheads to supporting dynamic charge migration for stateful controllers and the cost-benefit balance doesn't come out in favor.

So, the current "policy" is something like this:

* cgroupfs interface is for cgroup core features of organizing cgroups and processes and configuring resource configurations which preferably follow one of the control models defined in the doc.

* The hierarchical organization is semi-static in the sense that once a cgroup is populated tasks shouldn't be moved in or out of the cgroup with the exception of threaded domains.

* Non-resource control usages can hook into cgroup for identification / tagging purposes but should use the originating interface for interactions.

This has been consistently applied over the years now. There of course can be exceptions but I haven't seen anything outstanding in this round of discussion so am pretty skeptical. The actual use cases don't seem to need it and the only argument for it is it'd be nice to have it and involves violating the usage model.

My suggestion is going ahead with the per-process interface with cgroup extension on mind in case actual use cases arise. Also, when planning cgroup integration, putting dynamic migration front and center likely isn't a good idea.

Thanks.

Signature · 1 line
tejun
#35 lore raw
Quoted 3 lines · Peter Zijlstra

Josh, you being on the other Google team, the one that actually uses the cgroup interface AFAIU, can you fight the good fight with TJ on this?

A bit of extra context is in
https://lore.kernel.org/lkml/CABk29NtTScu2HO7V9Di+Fh2gv8zu5xiC5iNRwPFCLhpD+DKP0A@mail.gmail.com.

On the management/auditing side, the cgroup interface gives a clear indication of which tasks share a cookie. It is a bit less attractive to add a prctl interface for enumerating this.

Also on the management side, I illustrated in the above message how a thread would potentially group together other threads. One limitation of the current prctl interface is that the share_{to, from} always operates on the current thread. Granted we can work around this as described, and also potentially extend the prctl interface to operate on two tasks.

So I agree that the cgroup interface here isn't strictly necessary, though it seems convenient. I will double-check with internal teams that would be using the interface to see if there are any other considerations I'm missing.

Quoted 5 lines · Tejun Heo

My suggestion is going ahead with the per-process interface with cgroup extension on mind in case actual use cases arise. Also, when planning cgroup integration, putting dynamic migration front and center likely isn't a good idea.

tasks would not be frequently moved around; I'd expect security configuration to remain mostly static. Or maybe I'm misunderstanding your emphasis here?

If you feel the above is not strong enough (ie. there should be a use case not feasible with prctl), I'd support that we move forward with the prctl stuff for now, since the cgroup interface is independant.

Thanks,
Josh