[lkml]   [2009]   [Sep]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[patch 56/71] kthreads: fix kthread_create() vs kthread_stop() race
2.6.30-stable review patch.  If anyone has any objections, please let us know.

From: Oleg Nesterov <>

The bug should be "accidently" fixed by recent changes in 2.6.31,
all kernels <= 2.6.30 need the fix. The problem was never noticed before,
it was found because it causes mysterious failures with GFS mount/umount.

Credits to Robert Peterson. He blaimed kthread.c from the very beginning.
But, despite my promise, I forgot to inspect the old implementation until
he did a lot of testing and reminded me. This led to huge delay in fixing
this bug.

kthread_stop() does put_task_struct(k) before it clears kthread_stop_info.k.
This means another kthread_create() can re-use this task_struct, but the
new kthread can still see kthread_should_stop() == T and exit even without
calling threadfn().

Reported-by: Robert Peterson <>
Tested-by: Robert Peterson <>
Signed-off-by: Oleg Nesterov <>
Acked-by: Rusty Russell <>
Signed-off-by: Greg Kroah-Hartman <>

kernel/kthread.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -216,12 +216,12 @@ int kthread_stop(struct task_struct *k)
/* Now set kthread_should_stop() to true, and wake it up. */
kthread_stop_info.k = k;
- put_task_struct(k);

/* Once it dies, reset stop ptr, gather result and we're done. */
kthread_stop_info.k = NULL;
ret = kthread_stop_info.err;
+ put_task_struct(k);


 \ /
  Last update: 2009-09-05 02:39    [W:0.214 / U:44.152 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site