public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Subbaraman Narayanamurthy <subbaram@codeaurora.org>,
	daniel@numascale.com, yuyang.du@intel.com,
	linux-kernel@vger.kernel.org,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH]: kthread: Fix memory ordering in __kthread_parkme
Date: Fri, 7 Nov 2014 22:27:39 +0100	[thread overview]
Message-ID: <20141107212739.GV10501@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <20141107184103.GA16043@redhat.com>

On Fri, Nov 07, 2014 at 07:41:03PM +0100, Oleg Nesterov wrote:
> On 11/07, Peter Zijlstra wrote:
> >
> >  static void __kthread_parkme(struct kthread *self)
> >  {
> > -	__set_current_state(TASK_PARKED);
> > +	set_current_state(TASK_PARKED);
> >  	while (test_bit(KTHREAD_SHOULD_PARK, &self->flags)) {
> >  		if (!test_and_set_bit(KTHREAD_IS_PARKED, &self->flags))
> >  			complete(&self->parked);
> >  		schedule();
> > -		__set_current_state(TASK_PARKED);
> > +		set_current_state(TASK_PARKED);
> >  	}
> 
> Perhaps it makses sense to do set_current_state(PARKED) once at the start
> of "for (;;)" loop, but this is cosmetic.

Yeah, we should probably clean that up, it looks a bit odd. But I didn't
want to do too many changes.

> What if kthread_unpark() is called right after test_bit(KTHREAD_SHOULD_PARK)
> and KTHREAD_IS_PARKED is not set? It seems that __kthread_unpark() should
> call wake_up_state() unconditionally ?

set_current_state(TASK_PARKED)
while (test_bit(KTHREAD_SHOULD_PARK, ..)) {
						clear_bit(KTHREAD_SHOULD_PARK, ..);
						if (test_and_clear_bit(KTHREAD_IS_PARKED, ..) {
							...
							wake_up_state(, TASK_PARKED);
						}
	if (!test_and_set_bit(KTHREAD_IS_PARKED, ..))
		complete(..);
	schedule();


Then yes we'll miss the wakeup, but we also miss the __kthread_bind().

Now I don't think this'll actually happen because kthread_park() waits
for the completion under the hotplug and smpboot_threads_lock lock, and
we do the unpark under the hotplug lock as well, so its fully serialized

But yes, we should probably clean this up as well.

      reply	other threads:[~2014-11-07 21:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-06 15:01 hotplug thread issues Peter Zijlstra
2014-11-07  9:39 ` Thomas Gleixner
2014-11-07 10:28   ` [PATCH]: kthread: Fix memory ordering in __kthread_parkme Peter Zijlstra
2014-11-07 18:41     ` Oleg Nesterov
2014-11-07 21:27       ` Peter Zijlstra [this message]

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=20141107212739.GV10501@worktop.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=daniel@numascale.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=subbaram@codeaurora.org \
    --cc=tglx@linutronix.de \
    --cc=yuyang.du@intel.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