hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IDB5TR ----------------------------------------- When concurrently reading and writing to sched_class, the allocation and deallocation of cfs_rq in perxcu lacked lock protection. This could lead to the cfs_rq being freed twice during concurrent operations, resulting in a null pointer issue. Therefore, a mutex lock has been added when setting up sched_class to ensure that memory is not released repeatedly, and to allocate and deallocate the memory for xsched_group more reasonably. Fixes: 43bbefc53356 ("xsched: Add XCU control group implementation and its backend in xsched CFS") Signed-off-by: Liu Kai <liukai284@huawei.com> Signed-off-by: Zicheng Qu <quzicheng@huawei.com> --- kernel/xsched/cgroup.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/xsched/cgroup.c b/kernel/xsched/cgroup.c index 450439aac9ef..bab7d1049f7e 100644 --- a/kernel/xsched/cgroup.c +++ b/kernel/xsched/cgroup.c @@ -31,6 +31,7 @@ struct xsched_group *root_xcg = &root_xsched_group; static struct kmem_cache *xsched_group_cache __read_mostly; static struct kmem_cache *xcg_attach_entry_cache __read_mostly; static LIST_HEAD(xcg_attach_list); +static DEFINE_MUTEX(xcg_mutex); static const char xcu_sched_name[XSCHED_TYPE_NUM][4] = { [XSCHED_TYPE_RT] = "rt", @@ -537,7 +538,9 @@ static ssize_t xcu_sched_class_write(struct kernfs_open_file *of, char *buf, if (!xsched_group_is_root(xg->parent)) return -EINVAL; + mutex_lock(&xcg_mutex); ret = xcu_cg_set_sched_class(xg, type); + mutex_unlock(&xcg_mutex); return (ret) ? ret : nbytes; } -- 2.34.1