From: Zqiang <qiang.zhang@linux.dev>
To: paulmck@kernel.org, frederic@kernel.org,
neeraj.upadhyay@kernel.org, joelagnelf@nvidia.com,
urezki@gmail.com, boqun@kernel.org
Cc: qiang.zhang@linux.dev, rcu@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] rcuscale: Handle cur_ops->init() failures for srcu testing
Date: Fri, 20 Nov 2026 18:04:51 +0800 [thread overview]
Message-ID: <20261120100453.5826-2-qiang.zhang@linux.dev> (raw)
In-Reply-To: <20261120100453.5826-1-qiang.zhang@linux.dev>
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@linux.dev>
---
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
next prev parent reply other threads:[~2026-11-20 10:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 10:04 [PATCH] refscale: Fix possible oops in the typesafe_cleanup() Zqiang
2026-11-20 10:04 ` Zqiang [this message]
2026-11-20 10:04 ` [PATCH] rcuscale: Disable gp_exp when cur_ops->exp_completed is not implemented Zqiang
2026-11-20 10:04 ` [PATCH] rcuscale: Invoke cur_ops->cleanup() in kfree_scale_cleanup() Zqiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120100453.5826-2-qiang.zhang@linux.dev \
--to=qiang.zhang@linux.dev \
--cc=boqun@kernel.org \
--cc=frederic@kernel.org \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=neeraj.upadhyay@kernel.org \
--cc=paulmck@kernel.org \
--cc=rcu@vger.kernel.org \
--cc=urezki@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®