[PATCH] rcuscale: Handle cur_ops->init() failures for srcu testing
From: Zqiang
Date: Fri Nov 20 2026 - 05:05:11 EST
The init_srcu_struct() and init_srcu_struct_atomic() can fail, but rcuscale
ignored their return values, proceeding to run the test on an uninitialized
srcu_struct and to invoke cleanup_srcu_struct() on it during unwind. this
will cause kernel panic.
This commit make the rcu_scale_ops->init() return bool, check the return
values, reset srcu_ctlp to NULL on failure so that the cleanup path skips
cleanup_srcu_struct(), and return -ENOMEM when cur_ops->init() fails.
Signed-off-by: Zqiang <qiang.zhang@xxxxxxxxx>
---
kernel/rcu/rcuscale.c | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c
index 5659eaebc5c0..e5722322a69c 100644
--- a/kernel/rcu/rcuscale.c
+++ b/kernel/rcu/rcuscale.c
@@ -147,7 +147,7 @@ static unsigned long b_rcu_gp_test_finished;
struct rcu_scale_ops {
int ptype;
- void (*init)(void);
+ bool (*init)(void);
void (*cleanup)(void);
int (*readlock)(void);
void (*readunlock)(int idx);
@@ -185,8 +185,9 @@ static unsigned long __maybe_unused rcu_no_completed(void)
return 0;
}
-static void rcu_sync_scale_init(void)
+static bool rcu_sync_scale_init(void)
{
+ return true;
}
static struct rcu_scale_ops rcu_ops = {
@@ -269,15 +270,21 @@ static struct rcu_scale_ops srcu_ops = {
static struct srcu_struct srcud;
-static void srcu_sync_scale_init(void)
+static bool srcu_sync_scale_init(void)
{
srcu_ctlp = &srcud;
- init_srcu_struct(srcu_ctlp);
+ if (init_srcu_struct(srcu_ctlp)) {
+ srcu_ctlp = NULL;
+ return false;
+ }
+
+ return true;
}
static void srcu_sync_scale_cleanup(void)
{
- cleanup_srcu_struct(srcu_ctlp);
+ if (srcu_ctlp)
+ cleanup_srcu_struct(srcu_ctlp);
}
static struct rcu_scale_ops srcud_ops = {
@@ -314,10 +321,15 @@ static void srcu_scale_atomic_synchronize(void)
synchronize_srcu_atomic(srcu_ctlp);
}
-static void srcu_atomic_scale_init(void)
+static bool srcu_atomic_scale_init(void)
{
srcu_ctlp = &srcua;
- init_srcu_struct_atomic(srcu_ctlp);
+ if (init_srcu_struct_atomic(srcu_ctlp)) {
+ srcu_ctlp = NULL;
+ return false;
+ }
+
+ return true;
}
static struct rcu_scale_ops srcua_ops = {
@@ -1162,7 +1174,10 @@ rcu_scale_init(void)
goto unwind;
}
if (cur_ops->init)
- cur_ops->init();
+ if (!cur_ops->init()) {
+ firsterr = -ENOMEM;
+ goto unwind;
+ }
if (cur_ops->rso_gp_kthread) {
kthread_tp = cur_ops->rso_gp_kthread();
--
2.17.1