public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andrew Morton <akpm@osdl.org>,
	linux-kernel@vger.kernel.org
Subject: Re: PATCH? hrtimer_wakeup: fix a theoretical race wrt rt_mutex_slowlock()
Date: Mon, 6 Nov 2006 15:09:38 +0300	[thread overview]
Message-ID: <20061106120938.GA85@oleg> (raw)
In-Reply-To: <Pine.LNX.4.64.0611051906040.25218@g5.osdl.org>

On 11/05, Linus Torvalds wrote:
> 
> On Sun, 5 Nov 2006, Steven Rostedt wrote:
> > 
> > This whole situation is very theoretical, but I think this actually can
> > happen *theoretically*.
> > 
> > OK, the spin_lock doesn't do any serialization, but the unlock does. But
> > the problem can happen before the unlock. Because of the loop.
> > 
> > CPU 1                                    CPU 2
> > 
> >     task_rq_lock()
> > 
> >     p->state = TASK_RUNNING;
> > 
> > 
> >                                       (from bottom of for loop)
> >                                       set_current_state(TASK_INTERRUPTIBLE);
> > 
> >                                     for (;;) {  (looping)
> > 
> >                                       if (timeout && !timeout->task)
> > 
> > 
> >    (now CPU implements)
> >    t->task = NULL
> > 
> >    task_rq_unlock();
> > 
> >                                    schedule() (with state == TASK_INTERRUPTIBLE)
> 
> Yeah, that seems a real bug. You _always_ need to actually do the thing 
> that you wait for _before_ you want it up. That's what all the scheduling 
> primitives depend on - you can't wake people up first, and then set the 
> condition variable.
> 
> So if a rt_mutex depeds on something that is set inside the rq-lock, it 
> needs to get the task rw-lock in order to check it.

No, rt_mutex is fine (I think).

My changelog was very unclean and confusing, I'll try again. What we are
doing is:

	rt_mutex_slowlock:

		task->state = TASK_INTERRUPTIBLE;

		mb();

		if (CONDITION)
			return -ETIMEDOUT;

		schedule();

This is common and correct.

	hrtimer_wakeup:

		CONDITION = 1;			// [1]

		spin_lock(rq->lock);

		task->state = TASK_RUNNING;	// [2]

This needs 'wmb()' between [1] and [2] unless spin_lock() garantees memory
ordering. Of course, rt_mutex can take rq->lock to solve this, but I don't
think it would be right.

Oleg.


  reply	other threads:[~2006-11-06 11:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-05 19:34 PATCH? hrtimer_wakeup: fix a theoretical race wrt rt_mutex_slowlock() Oleg Nesterov
2006-11-05 22:29 ` Linus Torvalds
2006-11-05 22:53   ` Steven Rostedt
2006-11-05 23:08     ` Oleg Nesterov
2006-11-06  3:08     ` Linus Torvalds
2006-11-06 12:09       ` Oleg Nesterov [this message]
2006-11-06 12:26         ` Steven Rostedt
2006-11-05 22:53   ` Oleg Nesterov
2006-11-06  8:57   ` Benjamin Herrenschmidt
2006-11-06 12:35     ` Steven Rostedt
2006-11-06 20:53       ` Benjamin Herrenschmidt
2006-11-06 21:17         ` Steven Rostedt
2006-11-06 21:41           ` Benjamin Herrenschmidt
2006-11-06 12:31 ` Steven Rostedt
2006-11-06 14:15   ` Oleg Nesterov
2006-11-06 14:11     ` Steven Rostedt
2006-11-06 15:05       ` Steven Rostedt

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=20061106120938.GA85@oleg \
    --to=oleg@tv-sign.ru \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --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