public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix unsafe operation in high resolution timer
@ 2010-12-23 13:29 Hillf Danton
  2010-12-24  7:17 ` Yong Zhang
  0 siblings, 1 reply; 8+ messages in thread
From: Hillf Danton @ 2010-12-23 13:29 UTC (permalink / raw)
  To: linux-kernel

After calling the callback function of hrtimer, the timer could become
unreliable in corner cases where the timer will no longer be queued
and the mm segment, in which the timer is embedded, could be reclaimed
in the callback.

The unreliability is fixed by checking the result of callback before
operating the timer again.

Signed-off-by: Hillf Danton <dhillf@gmail.com>
---

--- a/kernel/hrtimer.c	2010-11-01 19:54:12.000000000 +0800
+++ b/kernel/hrtimer.c	2010-12-23 21:17:02.000000000 +0800
@@ -1225,6 +1225,7 @@ static void __run_hrtimer(struct hrtimer
 	raw_spin_unlock(&cpu_base->lock);
 	trace_hrtimer_expire_entry(timer, now);
 	restart = fn(timer);
+	if (restart != HRTIMER_NORESTART)
 	trace_hrtimer_expire_exit(timer);
 	raw_spin_lock(&cpu_base->lock);

@@ -1236,11 +1237,8 @@ static void __run_hrtimer(struct hrtimer
 	if (restart != HRTIMER_NORESTART) {
 		BUG_ON(timer->state != HRTIMER_STATE_CALLBACK);
 		enqueue_hrtimer(timer, base);
+		timer->state &= ~HRTIMER_STATE_CALLBACK;
 	}
-
-	WARN_ON_ONCE(!(timer->state & HRTIMER_STATE_CALLBACK));
-
-	timer->state &= ~HRTIMER_STATE_CALLBACK;
 }

 #ifdef CONFIG_HIGH_RES_TIMERS

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

end of thread, other threads:[~2010-12-29 15:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-23 13:29 [PATCH] fix unsafe operation in high resolution timer Hillf Danton
2010-12-24  7:17 ` Yong Zhang
2010-12-24 14:28   ` Hillf Danton
2010-12-25  2:12     ` Yong Zhang
2010-12-25 14:19       ` Hillf Danton
2010-12-26 13:12         ` Yong Zhang
2010-12-27 13:12           ` Hillf Danton
2010-12-29 15:43           ` Hillf Danton

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