mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: vatsa@in.ibm.com
Cc: rusty@rustcorp.com.au, mingo@elte.hu, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Fix deadlock in __create_workqueue
Date: Mon, 3 May 2004 13:08:29 -0700	[thread overview]
Message-ID: <20040503130829.5c43c6fe.akpm@osdl.org> (raw)
In-Reply-To: <20040503122412.GB7143@in.ibm.com>

Srivatsa Vaddagiri <vatsa@in.ibm.com> wrote:
>
> On Fri, Apr 30, 2004 at 07:19:01PM -0700, Andrew Morton wrote:
> > Yes, the logic in worker_thread() is a bit dorky, but I
> > don't believe that there is a race in there.
> 
> worker_thread examines kthread_should_stop() while its state
> is TASK_RUNNING, after which it sets its state to TASK_INTERRUPTIBLE.
> If kthread_stop were to come after kthread_should_stop and before
> worker_thread has set its state to TASK_INTERRUPTIBLE (which is possible
> because of a CPU going dead), wouldn't kthread_stop block forever? 
> Note that in case of CPU going dead, it is possible that a worker
> thread bound to the dead cpu continues executing on a different cpu 
> before it is killed in CPU_DEAD processing.

yup, sorry, I misread the code.  Like this?


--- 25/kernel/workqueue.c~worker_thread-race-fix	Mon May  3 13:02:25 2004
+++ 25-akpm/kernel/workqueue.c	Mon May  3 13:07:34 2004
@@ -201,19 +201,20 @@ static int worker_thread(void *__cwq)
 	siginitset(&sa.sa.sa_mask, sigmask(SIGCHLD));
 	do_sigaction(SIGCHLD, &sa, (struct k_sigaction *)0);
 
+	set_current_state(TASK_INTERRUPTIBLE);
 	while (!kthread_should_stop()) {
-		set_task_state(current, TASK_INTERRUPTIBLE);
-
 		add_wait_queue(&cwq->more_work, &wait);
 		if (list_empty(&cwq->worklist))
 			schedule();
 		else
-			set_task_state(current, TASK_RUNNING);
+			__set_current_state(TASK_RUNNING);
 		remove_wait_queue(&cwq->more_work, &wait);
 
 		if (!list_empty(&cwq->worklist))
 			run_workqueue(cwq);
+		set_current_state(TASK_INTERRUPTIBLE);
 	}
+	__set_current_state(TASK_RUNNING);
 	return 0;
 }
 

_


  reply	other threads:[~2004-05-03 20:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-30 11:37 Srivatsa Vaddagiri
2004-05-01  2:19 ` Andrew Morton
2004-05-03 12:24   ` Srivatsa Vaddagiri
2004-05-03 20:08     ` Andrew Morton [this message]
2004-05-04  6:51       ` Srivatsa Vaddagiri
2004-05-01  2:27 ` Andrew Morton
2004-05-03 12:23   ` Srivatsa Vaddagiri
2004-05-03 19:25     ` Andrew Morton
2004-05-04  6:50       ` Srivatsa Vaddagiri
2004-05-04  7:35         ` Andrew Morton
2004-05-05  8:37     ` Rusty Russell

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=20040503130829.5c43c6fe.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rusty@rustcorp.com.au \
    --cc=vatsa@in.ibm.com \
    /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

all inboxes | Powered by JetHome®