The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* one more kthread_should_stop smp race
@ 2004-04-04 23:57 Andrea Arcangeli
  0 siblings, 0 replies; only message in thread
From: Andrea Arcangeli @ 2004-04-04 23:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Linus Torvalds

reviewing the patchsets between 2.6.5-rc3 and 2.6.5 I noticed another
race like in do_softirq:

---------------
PatchSet 17177
Date: 2004/03/30 19:49:13
Author: vatsa
Branch: HEAD
Tag: (none)
Log:
[PATCH] Fix obvious stupid race in do_stop

We don't set the task state to TASK_INTERRUPTIBLE _before_ checking for
kthread_should_stop in do_stop.

BKrev: 4069c129adimxhudm2NaqM222iNj9A

Members:
        ChangeSet:1.17177->1.17178
        kernel/stop_machine.c:1.3->1.4

Index: linux-2.5/kernel/stop_machine.c
diff -u linux-2.5/kernel/stop_machine.c:1.3
linux-2.5/kernel/stop_machine.c:1.4
--- linux-2.5/kernel/stop_machine.c:1.3 Wed Mar 10 02:03:28 2004
+++ linux-2.5/kernel/stop_machine.c     Tue Mar 30 20:49:13 2004
@@ -149,10 +149,12 @@
        complete(&smdata->done);

        /* Wait for kthread_stop */
+       __set_current_state(TASK_INTERRUPTIBLE);
        while (!kthread_should_stop()) {
-               __set_current_state(TASK_INTERRUPTIBLE);
                schedule();
+               __set_current_state(TASK_INTERRUPTIBLE);
        }
+       __set_current_state(TASK_RUNNING);
        return ret;
 }
---------------

the TASK_INTERRUPTIBLE may become visible to other cpus after the
current cpu read kthread_should_stop.

Fix:

--- x/kernel/stop_machine.c.~1~	2004-04-04 08:09:33.000000000 +0200
+++ x/kernel/stop_machine.c	2004-04-05 01:54:00.719800824 +0200
@@ -149,10 +149,10 @@ static int do_stop(void *_smdata)
 	complete(&smdata->done);
 
 	/* Wait for kthread_stop */
-	__set_current_state(TASK_INTERRUPTIBLE);
+	set_current_state(TASK_INTERRUPTIBLE);
 	while (!kthread_should_stop()) {
 		schedule();
-		__set_current_state(TASK_INTERRUPTIBLE);
+		set_current_state(TASK_INTERRUPTIBLE);
 	}
 	__set_current_state(TASK_RUNNING);
 	return ret;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-04-04 23:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-04 23:57 one more kthread_should_stop smp race Andrea Arcangeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox