[PATCH OLK-5.10 0/2] CPU inspect bugfix

Yu Liao (2): cpuinspect: make inspector unregister reliable cpuinspect: fix [stop/start]_inspect_threads return type drivers/cpuinspect/cpuinspect.c | 22 ++++++++++++++++------ drivers/cpuinspect/cpuinspect.h | 5 +++-- drivers/cpuinspect/inspector.c | 5 +---- 3 files changed, 20 insertions(+), 12 deletions(-) -- 2.33.0

hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAO4PE CVE: NA ---------------------------------------- Calling cpuinspect_unregister_inspector() while the inspector is running will lead a issue as follow: [ 733.650856] Unable to handle kernel paging request at virtual address ffff80000922b0e4 [ 733.651118] Call trace: [ 733.651136] run_inspector+0xe4/0x220 [cpu_inspect] [ 733.651148] kthread+0x108/0x150 [ 733.651154] ret_from_fork+0x10/0x18 Return -EBUSY do not prevent the inspector form being removed. Fix this by providing a synchronized stop function to ensure inspect threads are really finished. Fixes: 069486b6d964 ("cpuinspect: add CPU-inspect infrastructure") Signed-off-by: Yu Liao <liaoyu15@huawei.com> --- drivers/cpuinspect/cpuinspect.c | 14 ++++++++++++++ drivers/cpuinspect/cpuinspect.h | 1 + drivers/cpuinspect/inspector.c | 5 +---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/cpuinspect/cpuinspect.c b/drivers/cpuinspect/cpuinspect.c index 65a935f6264d..65ce790fe28d 100644 --- a/drivers/cpuinspect/cpuinspect.c +++ b/drivers/cpuinspect/cpuinspect.c @@ -149,6 +149,20 @@ int stop_inspect_threads(void) return 0; } +/** + * stop_inspect_threads_sync - Stop all the inspect threads and wait for + * current inspect tasks to finish. + * + * This function must be called with the cpuinspect lock held. + */ +void stop_inspect_threads_sync(void) +{ + stop_inspect_threads(); + + while (atomic_read(&active_threads_num)) + cpu_relax(); +} + /** * cpuinspect_init - core initializer */ diff --git a/drivers/cpuinspect/cpuinspect.h b/drivers/cpuinspect/cpuinspect.h index 9a336d396a16..508309d34b39 100644 --- a/drivers/cpuinspect/cpuinspect.h +++ b/drivers/cpuinspect/cpuinspect.h @@ -16,6 +16,7 @@ void cpuinspect_result_notify(void); /* inspect control */ int start_inspect_threads(void); int stop_inspect_threads(void); +void stop_inspect_threads_sync(void); int cpuinspect_is_running(void); /* switch inspector */ diff --git a/drivers/cpuinspect/inspector.c b/drivers/cpuinspect/inspector.c index e56e35ec6325..10e905c4eb5c 100644 --- a/drivers/cpuinspect/inspector.c +++ b/drivers/cpuinspect/inspector.c @@ -106,10 +106,7 @@ int cpuinspect_unregister_inspector(struct cpu_inspector *insp) mutex_lock(&cpuinspect_lock); if (curr_cpu_inspector == insp) { - if (ci_core.inspect_on) { - mutex_unlock(&cpuinspect_lock); - return -EBUSY; - } + stop_inspect_threads_sync(); curr_cpu_inspector = NULL; } -- 2.33.0

hulk inclusion category: cleanup bugzilla: https://gitee.com/openeuler/kernel/issues/IAO4S0 CVE: NA ---------------------------------------- [stop/start]_inspect_threads do not return non-zero values. Therefore, change them return type to void. No functional change intended. Signed-off-by: Yu Liao <liaoyu15@huawei.com> --- drivers/cpuinspect/cpuinspect.c | 10 +++------- drivers/cpuinspect/cpuinspect.h | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/cpuinspect/cpuinspect.c b/drivers/cpuinspect/cpuinspect.c index 65ce790fe28d..d8d87dadf0d8 100644 --- a/drivers/cpuinspect/cpuinspect.c +++ b/drivers/cpuinspect/cpuinspect.c @@ -99,7 +99,7 @@ static int run_inspector(void *data) return 0; } -int start_inspect_threads(void) +void start_inspect_threads(void) { unsigned int cpu = 0; @@ -129,24 +129,20 @@ int start_inspect_threads(void) ci_core.inspect_on = 0; cpuinspect_result_notify(); } - - return 0; } -int stop_inspect_threads(void) +void stop_inspect_threads(void) { unsigned int cpu = 0; /* All inspection threads has been stopped */ if (atomic_read(&active_threads_num) == 0) - return 0; + return; for_each_cpu(cpu, &ci_core.inspect_cpumask) { if (cpuinspect_threads[cpu]) kthread_stop(cpuinspect_threads[cpu]); } - - return 0; } /** diff --git a/drivers/cpuinspect/cpuinspect.h b/drivers/cpuinspect/cpuinspect.h index 508309d34b39..c0610bef93c2 100644 --- a/drivers/cpuinspect/cpuinspect.h +++ b/drivers/cpuinspect/cpuinspect.h @@ -14,8 +14,8 @@ void cpuinspect_remove_interface(struct device *dev); void cpuinspect_result_notify(void); /* inspect control */ -int start_inspect_threads(void); -int stop_inspect_threads(void); +void start_inspect_threads(void); +void stop_inspect_threads(void); void stop_inspect_threads_sync(void); int cpuinspect_is_running(void); -- 2.33.0

反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/11327 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/V... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/11327 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/V...
participants (2)
-
patchwork bot
-
Yu Liao