* [PATCH] rcuscale: Make kfree_scale_thread() exit through torture_kthread_stopping()
@ 2026-12-02 9:20 Zqiang
0 siblings, 0 replies; only message in thread
From: Zqiang @ 2026-12-02 9:20 UTC (permalink / raw)
To: paulmck, frederic, neeraj.upadhyay, joelagnelf, urezki, boqun
Cc: qiang.zhang, rcu, linux-kernel
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-02 9:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 9:20 [PATCH] rcuscale: Make kfree_scale_thread() exit through torture_kthread_stopping() Zqiang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox