All of lore.kernel.org
 help / color / mirror / Atom feed
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: Make kfree_scale_thread() exit through torture_kthread_stopping()
Date: Wed,  2 Dec 2026 17:20:47 +0800	[thread overview]
Message-ID: <20261202092047.18137-1-qiang.zhang@linux.dev> (raw)

The kzalloc_objs() failed returning -ENOMEM lets the kthread exit on its
own, so it's task_struct is auto-reaped while kfree_reader_tasks[] still
holds a stale, unrefcounted pointer to it. the cleanup path then calls
kthread_stop() on that pointer, dereferencing freed memory.

This commit route the failure through torture_kthread_stopping() instead,
so the kthread only exits in response to kthread_stop().

Signed-off-by: Zqiang <qiang.zhang@linux.dev>
---
 kernel/rcu/rcuscale.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c
index 687249d686a5..681f08e644cc 100644
--- a/kernel/rcu/rcuscale.c
+++ b/kernel/rcu/rcuscale.c
@@ -801,6 +801,7 @@ static int
 kfree_scale_thread(void *arg)
 {
 	int i, loop = 0;
+	int firsterr = 0;
 	long me = (long)arg;
 	struct kfree_obj *alloc_ptr;
 	u64 start_time, end_time;
@@ -831,8 +832,11 @@ kfree_scale_thread(void *arg)
 
 		for (i = 0; i < kfree_alloc_num; i++) {
 			alloc_ptr = kzalloc_objs(struct kfree_obj, kfree_mult);
-			if (!alloc_ptr)
-				return -ENOMEM;
+			if (!alloc_ptr) {
+				SCALEOUT_ERRSTRING("out of memory");
+				firsterr = -ENOMEM;
+				goto out;
+			}
 
 			if (kfree_by_call_rcu) {
 				call_rcu(&(alloc_ptr->rh), kfree_call_rcu);
@@ -874,8 +878,9 @@ kfree_scale_thread(void *arg)
 		}
 	}
 
+out:
 	torture_kthread_stopping("kfree_scale_thread");
-	return 0;
+	return firsterr;
 }
 
 static void
-- 
2.17.1


                 reply	other threads:[~2026-12-02  9:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261202092047.18137-1-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.