From 1ba1301b72f47fce2f30d1a7b82fbac39b35790d Mon Sep 17 00:00:00 2001 From: Wang Jingjin Date: Wed, 28 Sep 2022 19:26:48 +0800 Subject: [PATCH] Revert "sched: Worker Group Contrl Monitor" linux inclusion category: feature issue: #I5TOQE CVE: NA Signed-off-by: Wang Jingjin ------------------------------------ This reverts commit d21dc3efeae4fd8800feb1385a1a5ecb7dc2c910 and commit 99f73066c449ff170a6cdac8c012504688c6705f. Signed-off-by: Wang Jingjin --- fs/exec.c | 2 - include/linux/sched.h | 10 -- include/linux/wgcm.h | 63 ---------- include/trace/events/sched.h | 18 --- include/uapi/linux/prctl.h | 3 - include/uapi/linux/wgcm.h | 53 -------- init/Kconfig | 7 -- kernel/exit.c | 3 - kernel/sched/Makefile | 1 - kernel/sched/core.c | 7 -- kernel/sched/wgcm.c | 238 ----------------------------------- kernel/sys.c | 6 - 12 files changed, 411 deletions(-) delete mode 100644 include/linux/wgcm.h delete mode 100644 include/uapi/linux/wgcm.h delete mode 100644 kernel/sched/wgcm.c diff --git a/fs/exec.c b/fs/exec.c index c4d216a1afb9..18afcc44b786 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -64,7 +64,6 @@ #include #include #include -#include #include #include @@ -1835,7 +1834,6 @@ static int bprm_execve(struct linux_binprm *bprm, current->fs->in_exec = 0; current->in_execve = 0; rseq_execve(current); - wgcm_clear_child(current); acct_update_integrals(current); task_numa_free(current, false); return retval; diff --git a/include/linux/sched.h b/include/linux/sched.h index a67583bfada7..d519887139e8 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1317,11 +1317,6 @@ struct task_struct { unsigned long rseq_event_mask; #endif -#ifdef CONFIG_WGCM - struct wgcm_task *wgcm_task; - struct wgcm_task *wgcm_server_task; -#endif - struct tlbflush_unmap_batch tlb_ubc; union { @@ -1702,11 +1697,6 @@ extern struct pid *cad_pid; #define PF_KTHREAD 0x00200000 /* I am a kernel thread */ #define PF_RANDOMIZE 0x00400000 /* Randomize virtual address space */ #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */ - -#ifdef CONFIG_WGCM -#define PF_WGCM_WORKER 0x01000000 /* WGCM worker*/ -#endif - #define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_mask */ #define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */ #define PF_MEMALLOC_NOCMA 0x10000000 /* All allocation request will have _GFP_MOVABLE cleared */ diff --git a/include/linux/wgcm.h b/include/linux/wgcm.h deleted file mode 100644 index 584a588bd03f..000000000000 --- a/include/linux/wgcm.h +++ /dev/null @@ -1,63 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * WGCM: Workergroup Control Monitor - * - * Copyright (c) 2022-2023 Huawei Technologies Co., Ltd. - */ - -#ifndef _LINUX_WGCM_H -#define _LINUX_WGCM_H - -#include - -#ifdef CONFIG_WGCM -#include -#include - -/* - * struct wgcm_task: controls the state of WGCM tasks. - */ -struct wgcm_task { - unsigned int server_tid; - - /* count the number of workers which is bound with server */ - atomic_t workers_sum; - - /* count the number of block workers */ - atomic_t blk_workers_sum; -}; - -/* - * use sys_prctl() (see kernel/sys.c) : - * wgcm_ctl(): register/unregister WGCM tasks. - */ -extern int wgcm_ctl(unsigned long flags, unsigned long server_tid); - -extern void wgcm_do_exit(struct task_struct *tsk); -extern void wgcm_clear_child(struct task_struct *p); -extern void wgcm_activate_task(struct task_struct *p); -extern void wgcm_deactivate_task(struct task_struct *p, int flags); -#else -static inline int wgcm_ctl(unsigned long flags, unsigned long server_tid) -{ - return -EOPNOTSUPP; -} - -static inline void wgcm_do_exit(struct task_struct *tsk) -{ -} - -static inline void wgcm_clear_child(struct task_struct *p) -{ -} - -static inline void wgcm_activate_task(struct task_struct *p) -{ -} - -static inline void wgcm_deactivate_task(struct task_struct *p, int flags) -{ -} -#endif /* CONFIG_WGCM */ - -#endif /* _LINUX_WGCM_H */ diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index 11b133fa9296..dd5fff2bb1b2 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -764,24 +764,6 @@ TRACE_EVENT(sched_isolate, ); #endif -#ifdef CONFIG_WGCM -TRACE_EVENT(tracing_mark_wgcm, - TP_PROTO(int pid, const char *name, bool trace_begin), - TP_ARGS(pid, name, trace_begin), - TP_STRUCT__entry( - __field(int, pid) - __string(trace_name, name) - __field(bool, trace_begin) - ), - TP_fast_assign( - __entry->pid = pid; - __assign_str(trace_name, name); - __entry->trace_begin = trace_begin; - ), - TP_printk("%s|%d|%s", __entry->trace_begin ? "B" : "E", - __entry->pid, __get_str(trace_name)) -); -#endif /* * Following tracepoints are not exported in tracefs and provide hooking * mechanisms only for testing and debugging purposes. diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index 771ed5e04166..c190e220ff67 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -247,9 +247,6 @@ struct prctl_mm_map { #define PR_SET_IO_FLUSHER 57 #define PR_GET_IO_FLUSHER 58 -/* Control WGCM tasks */ -#define PR_WGCM_CTL 59 - #define PR_SET_VMA 0x53564d41 # define PR_SET_VMA_ANON_NAME 0 diff --git a/include/uapi/linux/wgcm.h b/include/uapi/linux/wgcm.h deleted file mode 100644 index f04b90beaf62..000000000000 --- a/include/uapi/linux/wgcm.h +++ /dev/null @@ -1,53 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ -/* - * WGCM: Workergroup Control Monitor - * - * Copyright (c) 2022-2023 Huawei Technologies Co., Ltd. - */ - -#ifndef _UAPI_LINUX_WGCM_H -#define _UAPI_LINUX_WGCM_H - -#include - -#define UMCG_TASK_ALIGN 64 -/** - * struct wgcm_task: controls the state of WGCM tasks. - * - * The struct is aligned at 64 bytes to ensure that it fits into - * a single cache line. - */ -struct wgcm_task_data { - /** - * @server_tid: server's tid. - */ - __u32 server_tid; - - /** - * @workers_sum: count the number of workers which is bound with server - */ - int workers_sum; - - /** - * @blk_workers_sum: count the number of block workers - */ - int blk_workers_sum; - - __u32 __zero[1]; - -} __attribute__((packed, aligned(UMCG_TASK_ALIGN))); - -/** - * enum wgcm_ctl_flag - flags to pass to wgcm_ctl() - * @WGCM_CTL_REGISTER: register the current task as a WGCM task - * @WGCM_CTL_UNREGISTER: unregister the current task as a WGCM task - * @WGCM_CTL_WORKER: register the current task as a WGCM worker - */ -enum wgcm_ctl_flag { - WGCM_CTL_REGISTER = 0x0001, - WGCM_CTL_UNREGISTER = 0x0002, - WGCM_CTL_GET = 0x0004, - WGCM_CTL_WORKER = 0x0100, -}; - -#endif /* _UAPI_LINUX_WGCM_H */ diff --git a/init/Kconfig b/init/Kconfig index 7acf079f9609..3bbdf947391e 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1706,13 +1706,6 @@ config KALLSYMS symbolic stack backtraces. This increases the size of the kernel somewhat, as all symbols have to be loaded into the kernel image. -config WGCM - bool "Enable Workgroup Control Monitor API" - default n - help - Enable Workgroup Control Monitor API, userspace can get the number of - blocked threads. - config KALLSYMS_ALL bool "Include all symbols in kallsyms" depends on DEBUG_KERNEL && KALLSYMS diff --git a/kernel/exit.c b/kernel/exit.c index f1c08236b40d..795e16ecc422 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -64,7 +64,6 @@ #include #include #include -#include #include #include @@ -851,8 +850,6 @@ void __noreturn do_exit(long code) if (tsk->task_frag.page) put_page(tsk->task_frag.page); - wgcm_do_exit(tsk); - validate_creds_for_do_exit(tsk); check_stack_usage(); diff --git a/kernel/sched/Makefile b/kernel/sched/Makefile index 8290730d57c9..1b4834073ae7 100644 --- a/kernel/sched/Makefile +++ b/kernel/sched/Makefile @@ -40,4 +40,3 @@ obj-$(CONFIG_CPU_ISOLATION) += isolation.o obj-$(CONFIG_PSI) += psi.o obj-$(CONFIG_SCHED_RUNNING_AVG) += sched_avg.o obj-$(CONFIG_SCHED_CORE_CTRL) += core_ctl.o -obj-$(CONFIG_WGCM) += wgcm.o diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e2f00be4bb61..f4c71e0cf094 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include @@ -1650,15 +1649,11 @@ void activate_task(struct rq *rq, struct task_struct *p, int flags) { enqueue_task(rq, p, flags); - wgcm_activate_task(p); - p->on_rq = TASK_ON_RQ_QUEUED; } void deactivate_task(struct rq *rq, struct task_struct *p, int flags) { - wgcm_deactivate_task(p, flags); - p->on_rq = (flags & DEQUEUE_SLEEP) ? 0 : TASK_ON_RQ_MIGRATING; dequeue_task(rq, p, flags); @@ -3265,8 +3260,6 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p) #ifdef CONFIG_SCHED_RTG p->rtg_depth = 0; #endif - - wgcm_clear_child(p); } DEFINE_STATIC_KEY_FALSE(sched_numa_balancing); diff --git a/kernel/sched/wgcm.c b/kernel/sched/wgcm.c deleted file mode 100644 index c09ba22e75cf..000000000000 --- a/kernel/sched/wgcm.c +++ /dev/null @@ -1,238 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * WGCM: Workergroup Control Monitor - * - * Copyright (c) 2022-2023 Huawei Technologies Co., Ltd. - */ - -#include -#include -#include - -#include "sched.h" - -void wgcm_clear_child(struct task_struct *p) -{ - if (p->wgcm_task) { - WRITE_ONCE(p->wgcm_task, NULL); - p->flags &= ~PF_WGCM_WORKER; - } - p->wgcm_server_task = NULL; -} - - -static void wgcm_clear_task(struct task_struct *tsk) -{ - /* - * This is either called for the current task, or for a newly forked - * task that is not yet running, so we don't need strict atomicity - * below. - */ - if (tsk->wgcm_task) { - kfree(tsk->wgcm_task); - tsk->flags &= ~PF_WGCM_WORKER; - } - - tsk->wgcm_server_task = NULL; -} - -void wgcm_upd_blk_workers_sum(struct task_struct *p, bool active) -{ - struct wgcm_task *server = p->wgcm_server_task; - - if (!server) { - pr_err("[WGCM]The WGCM worker is not bound to it's server.\n"); - return; - } - - if (active) - atomic_dec(&server->blk_workers_sum); - else - atomic_inc(&server->blk_workers_sum); -} - -static void wgcm_upd_workers_sum(struct wgcm_task *server, bool regist) -{ - if (regist) - atomic_inc(&server->workers_sum); - else - atomic_dec(&server->workers_sum); -} - -void wgcm_activate_task(struct task_struct *p) -{ - if (!(p->flags & PF_WGCM_WORKER) || p->on_rq) - return; - - trace_tracing_mark_wgcm(current->tgid, "active_task", true); - wgcm_upd_blk_workers_sum(p, true); - trace_tracing_mark_wgcm(current->tgid, "", false); -} - -void wgcm_deactivate_task(struct task_struct *p, int flags) -{ - unsigned int old_state = p->on_rq; - unsigned int new_state = (flags & DEQUEUE_SLEEP) ? 0 : TASK_ON_RQ_MIGRATING; - - if (!(p->flags & PF_WGCM_WORKER) || !old_state || new_state) - return; - - trace_tracing_mark_wgcm(current->tgid, "deactive_task", true); - wgcm_upd_blk_workers_sum(p, false); - trace_tracing_mark_wgcm(current->tgid, "", false); -} - -void wgcm_do_exit(struct task_struct *tsk) -{ - struct wgcm_task *server = tsk->wgcm_server_task; - struct wgcm_task *self = tsk->wgcm_task; - - if (!server) - return; - - if (tsk->flags & PF_WGCM_WORKER) - wgcm_upd_workers_sum(server, false); - - kfree(self); -} - -int wgcm_get_taskinfo(struct wgcm_task_data __user *self) -{ - struct task_struct *tsk = current; - - if (tsk->flags & PF_WGCM_WORKER || !tsk->wgcm_task) - return -EINVAL; - - self->workers_sum = atomic_read(&tsk->wgcm_task->workers_sum); - self->blk_workers_sum = atomic_read(&tsk->wgcm_task->blk_workers_sum); - - return 0; -} - -static int wgcm_register(unsigned long flags, unsigned int __user *server_tid) -{ - unsigned int tid; - struct task_struct *server; - struct wgcm_task *wt; - struct task_struct *tsk = current; - - if (copy_from_user(&tid, server_tid, sizeof(tid))) { - return -EFAULT; - } - - if (tsk->wgcm_task || tid == 0) { - pr_err("[WGCM][PID:%d]server_tid = %u.\n", current->pid, tid); - return -EINVAL; - } - - wt = kzalloc(sizeof(*wt), GFP_KERNEL); - if (!wt) { - pr_err("[WGCM_REG] alloc wgcm task fail!\n"); - return -ENOMEM; - } - - wt->server_tid = tid; - - rcu_read_lock(); - server = find_task_by_vpid(tid); - if (!server) - pr_err("[WGCM][PID:%d]find server(%d) fail.\n", tsk->pid, tid); - if (server && server->mm == current->mm) { - if (flags == WGCM_CTL_WORKER) { - if (!server->wgcm_task || (server->flags & PF_WGCM_WORKER)) - server = NULL; - } else { - if (server != current) - server = NULL; - } - } else { - server = NULL; - } - rcu_read_unlock(); - - if (!server) { - kfree(wt); - return -ESRCH; - } - - if (flags == WGCM_CTL_WORKER) { - WRITE_ONCE(tsk->wgcm_task, wt); - WRITE_ONCE(tsk->wgcm_server_task, server->wgcm_task); - wgcm_upd_workers_sum(tsk->wgcm_server_task, true); - current->flags |= PF_WGCM_WORKER; /* hook schedule() */ - } else { - WRITE_ONCE(tsk->wgcm_task, wt); - } - - return 0; -} - -static int wgcm_unregister(void) -{ - if (current->wgcm_server_task) - wgcm_upd_workers_sum(current->wgcm_server_task, false); - - wgcm_clear_task(current); - return 0; -} - -#define WGCM_CTL_CMD 0xff - -/** - * wgcm_ctl: (un)register the current task as a WGCM task. - * @flags: ORed values from enum umcg_ctl_flag; see below; - * @server_tid: server's(monitor's) thread id. - * - * @flags & WGCM_CTL_REGISTER: register a WGCM task: - * - * @flags & WGCM_CTL_UNREGISTER: unregister a WGCM task. - * - * WGCM workers: - * - @flags & WGCM_CTL_WORKER - * - * WGCM server: - * - !(@flags & WGCM_CTL_WORKER) - * - * All tasks: - * - server_tid must be valid(e.g. not zero). - * - * If the conditions above are met, wgcm_ctl() immediately returns - * if the registered task is a server. If the registered task is a - * worker, it's server's workers_sum will be added. Conversely, if - * the unregisted task is a worker, it's server's workers_sum will - * be decreased. - * - * Return: - * 0 - success - * -EFAULT - failed to read @self - * -EINVAL - some other error occurred - * -ESRCH - no such server_tid - */ -int wgcm_ctl(unsigned long flags, unsigned long addr) -{ - int cmd = flags & WGCM_CTL_CMD; - - flags &= ~WGCM_CTL_CMD; - - if (!addr) - return -EINVAL; - - if (flags & ~WGCM_CTL_WORKER) - return -EINVAL; - - switch (cmd) { - case WGCM_CTL_REGISTER: - return wgcm_register(flags, (unsigned int __user *)addr); - - case WGCM_CTL_UNREGISTER: - return wgcm_unregister(); - - case WGCM_CTL_GET: - return wgcm_get_taskinfo((struct wgcm_task_data __user *)addr); - - default: - break; - } - - return -EINVAL; -} diff --git a/kernel/sys.c b/kernel/sys.c index b0c1896a8359..c63de71889bf 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -62,7 +62,6 @@ #include #include #include -#include #include @@ -2589,11 +2588,6 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, error = (current->flags & PR_IO_FLUSHER) == PR_IO_FLUSHER; break; - case PR_WGCM_CTL: - if (arg4 || arg5) - return -EINVAL; - - return wgcm_ctl(arg2, arg3); case PR_SET_VMA: error = prctl_set_vma(arg2, arg3, arg4, arg5); break; -- Gitee