[PATCH] rcuscale: Invoke cur_ops->cleanup() in kfree_scale_cleanup()
From: Zqiang
Date: Fri Nov 20 2026 - 05:05:20 EST
When the kfree_rcu test is selected, rcu_scale_cleanup() delegates to
kfree_scale_cleanup() and returns, so cur_ops->cleanup() is never invoked,
for the srcud and srcua flavors, this fails to release the srcu_struct
which allocated by cur_ops->init().
This commit therefore call cur_ops->cleanup() before kfree_scale_cleanup()
ends, and also guard the cur_ops is not NULL.
Signed-off-by: Zqiang <qiang.zhang@xxxxxxxxx>
---
insmod rcuscale.ko scale_type=srcua kfree_rcu_test=1 gp_exp=1
unreferenced object (percpu) 0x607d981476c0 (size 576):
comm "insmod", pid 1151, jiffies 4294997383
hex dump (first 32 bytes on cpu 11):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace (crc ad6c346):
kmemleak_alloc_percpu+0x89/0xa0
pcpu_alloc_noprof+0x69c/0xd30
init_srcu_struct_fields+0xb45/0x1070
__init_srcu_struct_common+0x4d/0x60
__init_srcu_struct_atomic+0x45/0x70
0xffffffffc060380e
0xffffffffc06071d8
do_one_initcall+0xd9/0x620
do_init_module+0x2b6/0x830
load_module+0x7b5b/0x81d0
init_module_from_file+0x15f/0x180
idempotent_init_module+0x3b1/0x800
__x64_sys_finit_module+0x11a/0x170
x64_sys_call+0x3e0/0x1fb0
do_syscall_64+0xd2/0x750
entry_SYSCALL_64_after_hwframe+0x76/0x7e
kernel/rcu/rcuscale.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c
index 5659eaebc5c0..a5644db54119 100644
--- a/kernel/rcu/rcuscale.c
+++ b/kernel/rcu/rcuscale.c
@@ -901,6 +901,8 @@ kfree_scale_cleanup(void)
kfree_reader_tasks = NULL;
}
+ if (cur_ops && cur_ops->cleanup != NULL)
+ cur_ops->cleanup();
torture_cleanup_end();
}
@@ -1036,7 +1038,7 @@ rcu_scale_cleanup(void)
SCALEOUT_ERRSTRING("No expedited async GPs, so went with async!");
// If built-in, just report all of the GP kthread's CPU time.
- if (IS_BUILTIN(CONFIG_RCU_SCALE_TEST) && !kthread_tp && cur_ops->rso_gp_kthread)
+ if (IS_BUILTIN(CONFIG_RCU_SCALE_TEST) && cur_ops && !kthread_tp && cur_ops->rso_gp_kthread)
kthread_tp = cur_ops->rso_gp_kthread();
if (kthread_tp) {
u32 ns;
--
2.17.1