The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andrea Arcangeli <andrea@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@osdl.org>, Linus Torvalds <torvalds@osdl.org>
Subject: one more kthread_should_stop smp race
Date: Mon, 5 Apr 2004 01:57:40 +0200	[thread overview]
Message-ID: <20040404235740.GA21069@dualathlon.random> (raw)

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;

                 reply	other threads:[~2004-04-04 23:57 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=20040404235740.GA21069@dualathlon.random \
    --to=andrea@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox