one more kthread_should_stop smp race
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.4Index: 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
kernel/stop_machine.c Tue Mar 30 20:49:13 2004 renamed from kernel/stop_machine.c:1.3 Wed Mar 10 02:03:28 2004 +3 -2
@@ -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:
kernel/stop_machine.c renamed from kernel/stop_machine.c.~1~ +2 -2
@@ -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;