public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* PATCH? hrtimer_wakeup: fix a theoretical race wrt rt_mutex_slowlock()
@ 2006-11-05 19:34 Oleg Nesterov
  2006-11-05 22:29 ` Linus Torvalds
  2006-11-06 12:31 ` Steven Rostedt
  0 siblings, 2 replies; 17+ messages in thread
From: Oleg Nesterov @ 2006-11-05 19:34 UTC (permalink / raw)
  To: Thomas Gleixner, Steven Rostedt
  Cc: Andrew Morton, Linus Torvalds, linux-kernel

When task->array != NULL, try_to_wake_up() just goes to "out_running" and sets
task->state = TASK_RUNNING.

In that case hrtimer_wakeup() does:

	timeout->task = NULL;		<----- [1]

	spin_lock(runqueues->lock);

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

from Documentation/memory-barriers.txt

	Memory operations that occur before a LOCK operation may appear to
	happen after it completes.

This means that [2] may be completed before [1], and

CPU_0							CPU_1
rt_mutex_slowlock:

for (;;) {
	...
		if (timeout && !timeout->task)
			return -ETIMEDOUT;
	...

	schedule();
							hrtimer_wakeup() sets
	...						task->state = TASK_RUNNING,
							but "timeout->task = NULL"
							is not completed
	set_current_state(TASK_INTERRUPTIBLE);
}

we can miss a timeout.

Of course, this all is scholasticism, this can't happen in practice, but
may be this patch makes sense as a documentation update.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- STATS/kernel/hrtimer.c~1_hrtw	2006-10-22 18:24:03.000000000 +0400
+++ STATS/kernel/hrtimer.c	2006-11-05 22:32:36.000000000 +0300
@@ -662,9 +662,12 @@ static int hrtimer_wakeup(struct hrtimer
 		container_of(timer, struct hrtimer_sleeper, timer);
 	struct task_struct *task = t->task;
 
-	t->task = NULL;
-	if (task)
+	if (task) {
+		t->task = NULL;
+		/* must be visible before task->state = TASK_RUNNING */
+		smp_wmb();
 		wake_up_process(task);
+	}
 
 	return HRTIMER_NORESTART;
 }


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2006-11-06 21:41 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox