add basic task isolation prctl interface
Subsystems (3)
PATCH v9 1/10 add basic task isolation prctl interface
The logic to disable vmstat worker thread, when entering nohz full, does not cover all scenarios. For example, it is possible for the following to happen:
References: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Add basic prctl task isolation interface, which allows informing the kernel that application is executing latency sensitive code (where interruptions are undesired).
Interface is described by task_isolation.rst (added by next patch).
---
v6:
- Move oneshot mode enablement to configuration time (Frederic Weisbecker).
- Allow more extensions to CFG_SET of ISOL_F_QUIESCE (Frederic Weisbecker).
- prctl_task_isolation_activate_get should copy active_mask
to address in arg2.
v5:
- No changes
v4:
- Switch to structures for parameters when possible
(which are more extensible).
- Switch to CFG_{S,G}ET naming and drop
"internal configuration" prctls (Frederic Weisbecker).
v3:
- Split in smaller patches (Nitesh Lal).
- Misc cleanups (Nitesh Lal).
- Clarify nohz_full is not a dependency (Nicolas Saenz).
- Incorrect values for prctl definitions (kernel robot).
- Save configured state, so applications
can activate externally configured
task isolation parameters.
- Remove "system default" notion (chisol should make it obsolete).
v2:
- Finer-grained control of quiescing (Frederic Weisbecker / Nicolas Saenz).
- Avoid potential regressions by allowing applications
to use ISOL_F_QUIESCE_DEFMASK (whose default value
is configurable in /sys/). (Nitesh Lal / Nicolas Saenz).
include/linux/sched.h | 5 include/linux/task_isolation.h | 91 ++++++++++ include/uapi/linux/prctl.h | 43 +++++ init/init_task.c | 3 kernel/Makefile | 2 kernel/fork.c | 22 ++ kernel/sys.c | 16 + kernel/task_isolation.c | 350 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 530 insertions(+), 2 deletions(-)
include/uapi/linux/prctl.h +47 -0
@@ -275,4 +275,51 @@ struct prctl_mm_map {#define PR_SET_VMA 0x53564d41# define PR_SET_VMA_ANON_NAME 0 +#define PR_ISOL_FEAT_GET 63 +#define PR_ISOL_CFG_GET 64 +#define PR_ISOL_CFG_SET 65 + +/* arg2 to CFG_GET/CFG_SET */ +# define I_CFG_FEAT 1 +# define I_CFG_INHERIT 2 + +#define PR_ISOL_ACTIVATE_GET 66 +#define PR_ISOL_ACTIVATE_SET 67 + + +/* Supported features */ +# define ISOL_F_QUIESCE (1UL << 0) + +# define ISOL_F_QUIESCE_MULTIPLE (1UL << 0) +# define ISOL_F_QUIESCE_VMSTATS (1UL << 0) + +struct task_isol_quiesce_extensions { +__u64 flags; +__u64 supported_quiesce_bits; +__u64 pad[6 ]; +}; + +/* +* This structure provides control over +* inheritance of task isolation across +* clone and fork. +*/ +struct task_isol_inherit_control { +__u8 inherit_mask; +__u8 flags; +__u8 pad[6 ]; +}; + +# define ISOL_INHERIT_CONF (1UL << 0) +# define ISOL_INHERIT_ACTIVE (1UL << 1) + +struct task_isol_quiesce_control { +__u64 flags; +__u64 quiesce_mask; +__u64 quiesce_oneshot_mask; +__u64 pad[5 ]; +}; + +# define QUIESCE_CONTROL (1UL << 0) +#endif /* _LINUX_PRCTL_H */
kernel/Makefile +2 -0
@@ -132,6 +132,8 @@ obj-$(CONFIG_WATCH_QUEUE) += watch_queue obj-$(CONFIG_RESOURCE_KUNIT_TEST) += resource_kunit.o obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o +obj-$(CONFIG_TASK_ISOLATION) += task_isolation.o + CFLAGS_stackleak.o += $(DISABLE_STACKLEAK_PLUGIN) obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak.o KASAN_SANITIZE_stackleak.o := n
kernel/sys.c +16 -0
@@ -58,6 +58,7 @@#include <linux/sched/coredump.h> #include <linux/sched/task.h> #include <linux/sched/cputime.h> +#include <linux/task_isolation.h> #include <linux/rcupdate.h> #include <linux/uidgid.h> #include <linux/cred.h>
@@ -2593,6 +2594,21 @@ SYSCALL_DEFINE5(prctl, int, option, unsicase PR_SET_VMA : error =prctl_set_vma (arg2, arg3, arg4, arg5);break ; +case PR_ISOL_FEAT_GET : + error =prctl_task_isol_feat_get (arg2, arg3, arg4, arg5); +break ; +case PR_ISOL_CFG_GET : + error =prctl_task_isol_cfg_get (arg2, arg3, arg4, arg5); +break ; +case PR_ISOL_CFG_SET : + error =prctl_task_isol_cfg_set (arg2, arg3, arg4, arg5); +break ; +case PR_ISOL_ACTIVATE_GET : + error =prctl_task_isol_activate_get (arg2, arg3, arg4, arg5); +break ; +case PR_ISOL_ACTIVATE_SET : + error =prctl_task_isol_activate_set (arg2, arg3, arg4, arg5); +break ;default : error = -EINVAL ;break ;
include/linux/sched.h +5 -0
@@ -67,6 +67,7 @@ struct sighand_struct;struct signal_struct ;struct task_delay_info ;struct task_group ; +struct task_isol_info ;/* * Task state bitmask. NOTE! These bits are also
@@ -1492,6 +1493,10 @@ struct task_struct {struct callback_head l1d_flush_kill;#endif +#ifdef CONFIG_TASK_ISOLATION +struct task_isol_info *task_isol_info; +#endif +/* * New fields for task_struct should be added above here, so that * they are included in the randomized portion of task_struct.
init/init_task.c +3 -0
@@ -209,6 +209,9 @@ struct task_struct init_task#ifdef CONFIG_SECCOMP_FILTER .seccomp = { .filter_count = ATOMIC_INIT(0) },#endif +#ifdef CONFIG_TASK_ISOLATION + .task_isol_info = NULL, +#endif };EXPORT_SYMBOL (init_task);
kernel/fork.c +20 -2
@@ -97,6 +97,7 @@#include <linux/scs.h> #include <linux/io_uring.h> #include <linux/bpf.h> +#include <linux/task_isolation.h> #include <asm/pgalloc.h> #include <linux/uaccess.h>
@@ -748,6 +749,7 @@ void __put_task_struct(struct task_strucWARN_ON (refcount_read (&tsk->usage));WARN_ON (tsk == current); +task_isol_free (tsk);io_uring_free (tsk);cgroup_free (tsk);task_numa_free (tsk, true);
@@ -1557,6 +1559,15 @@ out:return error; } +static int copy_task_isol (struct task_struct *tsk) +{ +#ifdef CONFIG_TASK_ISOLATION +if (current->task_isol_info) +return __copy_task_isol (tsk); +#endif +return 0 ; +} +static int copy_sighand (unsigned long clone_flags,struct task_struct *tsk) {struct sighand_struct *sig;
@@ -2129,7 +2140,9 @@ static __latent_entropy struct task_struRCU_INIT_POINTER (p->bpf_storage,NULL ); p->bpf_ctx =NULL ;#endif - +#ifdef CONFIG_TASK_ISOLATION + p->task_isol_info =NULL ; +#endif /* Perform scheduler related setup. Assign this task to a CPU. */ retval =sched_fork (clone_flags, p);if (retval)
@@ -2173,6 +2186,9 @@ static __latent_entropy struct task_stru retval =copy_thread (clone_flags, args->stack, args->stack_size, p, args->tls);if (retval) goto bad_fork_cleanup_io; + retval =copy_task_isol (p); +if (retval) + goto bad_fork_cleanup_thread;stackleak_task_init (p);
@@ -2181,7 +2197,7 @@ static __latent_entropy struct task_stru args->set_tid_size);if (IS_ERR (pid)) { retval =PTR_ERR (pid); - goto bad_fork_cleanup_thread; + goto bad_fork_cleanup_task_isol; } }
@@ -2400,6 +2416,8 @@ bad_fork_put_pidfd: bad_fork_free_pid:if (pid != &init_struct_pid)free_pid (pid); +bad_fork_cleanup_task_isol: +task_isol_free (p); bad_fork_cleanup_thread:exit_thread (p); bad_fork_cleanup_io:
include/linux/task_isolation.h new file +91 -0
91 lines not on this page · raw message
kernel/task_isolation.c new file +351 -0
351 lines not on this page · raw message
init/Kconfig +16 -0
@@ -675,6 +675,22 @@ config CPU_ISOLATION Say Y if unsure. +config TASK_ISOLATION + bool "Task isolation prctl()" + depends on GENERIC_ENTRY + default n + help + Certain types of applications benefit from running uninterrupted by + background OS activities. Realtime systems and high-bandwidth networking + applications with user-space drivers can fall into the category. + + To create an OS noise free environment for the application, this option + enables the task isolation prctl interface, which allows userspace to + inform the kernel the start and end of the latency sensitive application + section (with configurable system behaviour for that section). + + Say N if unsure. + source "kernel/rcu/Kconfig" config BUILD_BIN2C