From 2eb706e6db6a2729d1e87e48cc8acc7f7aae5568 Mon Sep 17 00:00:00 2001 From: Xunlei Pang Date: Mon, 23 Nov 2020 11:46:29 +0800 Subject: [PATCH 2419/2944] alinux: pidns: Support rich container switch on/off to #31381921 Introduce "/proc/sys/kernel/rich_container_enable" to control rich container at runtime. Default off. Reviewed-by: Alex Shi Reviewed-by: Michael Wang Signed-off-by: Xunlei Pang --- include/linux/pid_namespace.h | 4 ++++ kernel/pid_namespace.c | 4 ++++ kernel/sysctl.c | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h index 9a956a4..e558345 100644 --- a/include/linux/pid_namespace.h +++ b/include/linux/pid_namespace.h @@ -101,8 +101,12 @@ static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) void pid_idr_init(void); #ifdef CONFIG_RICH_CONTAINER +extern int sysctl_rich_container_enable; static inline bool in_rich_container(struct task_struct *tsk) { + if (sysctl_rich_container_enable == 0) + return false; + return (task_active_pid_ns(tsk) != &init_pid_ns) && child_cpuacct(tsk); } #else diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 95271f1..435eb0a 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -23,6 +23,10 @@ #include #include +#ifdef CONFIG_RICH_CONTAINER +int sysctl_rich_container_enable; +#endif + static DEFINE_MUTEX(pid_caches_mutex); static struct kmem_cache *pid_ns_cachep; /* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */ diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 30e6c35..608d481 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1293,6 +1293,17 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write, .extra2 = &one, }, #endif +#ifdef CONFIG_RICH_CONTAINER + { + .procname = "rich_container_enable", + .data = &sysctl_rich_container_enable, + .maxlen = sizeof(int), + .mode = 0600, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + }, +#endif { } }; -- 1.8.3.1