From cf8819cb2e1d5e7a4cc818f5865cd4c0f82ecd83 Mon Sep 17 00:00:00 2001 From: Wang Jingjin Date: Mon, 25 Jul 2022 21:13:31 +0800 Subject: [PATCH] sched:Fix some build errors which are produced in ci linux inclusion category:bugfix issue: #I5ISA9 CVE: NA ------------------------------- Fix build errors which are produced in ci. Signed-off-by: Wang Jingjin --- fs/exec.c | 1 + include/linux/sched.h | 29 ------------------ include/linux/wgcm.h | 63 +++++++++++++++++++++++++++++++++++++++ include/uapi/linux/wgcm.h | 29 +++++++----------- kernel/exit.c | 1 + kernel/sched/core.c | 1 + kernel/sched/wgcm.c | 27 ++++++++--------- kernel/sys.c | 1 + 8 files changed, 90 insertions(+), 62 deletions(-) create mode 100644 include/linux/wgcm.h diff --git a/fs/exec.c b/fs/exec.c index 131bfbb88698..56f62c231bbd 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include diff --git a/include/linux/sched.h b/include/linux/sched.h index e9be57f0ccf4..ffd86ffb2cab 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2217,35 +2217,6 @@ static inline void rseq_syscall(struct pt_regs *regs) #endif -#ifdef CONFIG_WGCM -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 - const struct sched_avg *sched_trace_cfs_rq_avg(struct cfs_rq *cfs_rq); char *sched_trace_cfs_rq_path(struct cfs_rq *cfs_rq, char *str, int len); int sched_trace_cfs_rq_cpu(struct cfs_rq *cfs_rq); diff --git a/include/linux/wgcm.h b/include/linux/wgcm.h new file mode 100644 index 000000000000..584a588bd03f --- /dev/null +++ b/include/linux/wgcm.h @@ -0,0 +1,63 @@ +// 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/uapi/linux/wgcm.h b/include/uapi/linux/wgcm.h index 3d8bc4e09f66..f04b90beaf62 100644 --- a/include/uapi/linux/wgcm.h +++ b/include/uapi/linux/wgcm.h @@ -1,46 +1,37 @@ /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ -#ifndef _UAPI_LINUX_WGCM_H -#define _UAPI_LINUX_WGCM_H - -#include - /* - * WGCM: Workegroup Control Monitor. - * - * use sys_prctl() (see kernel/sys.c) : - * wgcm_ctl(): register/unregister WGCM tasks. + * WGCM: Workergroup Control Monitor * + * Copyright (c) 2022-2023 Huawei Technologies Co., Ltd. */ -#define UMCG_TASK_ALIGN 64 +#ifndef _UAPI_LINUX_WGCM_H +#define _UAPI_LINUX_WGCM_H -#define UMCG_TID_MASK 0x3fffffffU +#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 { +struct wgcm_task_data { /** * @server_tid: server's tid. */ - __u32 server_tid; /* r w */ + __u32 server_tid; /** * @workers_sum: count the number of workers which is bound with server - - * Read-only for the userspace */ - atomic_t workers_sum; /* r */ + int workers_sum; /** * @blk_workers_sum: count the number of block workers - * - * Read-only for the userspace */ - atomic_t blk_workers_sum; /* r */ + int blk_workers_sum; __u32 __zero[1]; diff --git a/kernel/exit.c b/kernel/exit.c index e870f93113a5..f1c08236b40d 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 5a31a425cec9..436e84c129c7 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/kernel/sched/wgcm.c b/kernel/sched/wgcm.c index 09690cbcf597..c09ba22e75cf 100644 --- a/kernel/sched/wgcm.c +++ b/kernel/sched/wgcm.c @@ -1,6 +1,9 @@ -// SPDX-License-Identifier: GPL-2.0-only - -/* WGCM: Workergroup Control Monitor */ +// SPDX-License-Identifier: GPL-2.0 +/* + * WGCM: Workergroup Control Monitor + * + * Copyright (c) 2022-2023 Huawei Technologies Co., Ltd. + */ #include #include @@ -38,7 +41,7 @@ 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"); + pr_err("[WGCM]The WGCM worker is not bound to it's server.\n"); return; } @@ -93,19 +96,15 @@ void wgcm_do_exit(struct task_struct *tsk) kfree(self); } -int wgcm_get_taskinfo(struct wgcm_task __user *self) +int wgcm_get_taskinfo(struct wgcm_task_data __user *self) { struct task_struct *tsk = current; - int ret; if (tsk->flags & PF_WGCM_WORKER || !tsk->wgcm_task) return -EINVAL; - ret = copy_to_user(self, tsk->wgcm_task, sizeof(*self)); - if (ret) { - pr_err("[WGCM] wgcm_task copy to user fail, ret = %d.", ret); - return ret; - } + self->workers_sum = atomic_read(&tsk->wgcm_task->workers_sum); + self->blk_workers_sum = atomic_read(&tsk->wgcm_task->blk_workers_sum); return 0; } @@ -122,7 +121,7 @@ static int wgcm_register(unsigned long flags, unsigned int __user *server_tid) } if (tsk->wgcm_task || tid == 0) { - pr_err("[WGCM][PID:%d]server_tid = %ld", current->pid, tid); + pr_err("[WGCM][PID:%d]server_tid = %u.\n", current->pid, tid); return -EINVAL; } @@ -137,7 +136,7 @@ static int wgcm_register(unsigned long flags, unsigned int __user *server_tid) rcu_read_lock(); server = find_task_by_vpid(tid); if (!server) - pr_err("[WGCM][PID:%d]find server(%d) fail", tsk->pid, tid); + 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)) @@ -229,7 +228,7 @@ int wgcm_ctl(unsigned long flags, unsigned long addr) return wgcm_unregister(); case WGCM_CTL_GET: - return wgcm_get_taskinfo((struct wgcm_task __user *)addr); + return wgcm_get_taskinfo((struct wgcm_task_data __user *)addr); default: break; diff --git a/kernel/sys.c b/kernel/sys.c index c91318f58034..b0c1896a8359 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -62,6 +62,7 @@ #include #include #include +#include #include -- Gitee