[PATCH 3/3] hrtimer: fix the __hrtimer_start_range_ns() race with hrtimer_active()

From: Oleg Nesterov
Date: Mon Jun 08 2015 - 11:13:09 EST


Change __hrtimer_start_range_ns() to preserve ENQUEUED.
---
kernel/time/hrtimer.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 5fceb3d..1761f96 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -902,8 +902,8 @@ out:
/*
* remove hrtimer, called with base lock held
*/
-static inline int
-remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base)
+static inline int remove_hrtimer(struct hrtimer *timer,
+ struct hrtimer_clock_base *base, bool clear_enqueued)
{
if (hrtimer_is_queued(timer)) {
int reprogram;
@@ -923,7 +923,7 @@ remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base)
* This preserves the CALLBACK flag, otherwise we could move
* the timer base in switch_hrtimer_base.
*/
- __remove_hrtimer(timer, base, true, reprogram);
+ __remove_hrtimer(timer, base, clear_enqueued, reprogram);
return 1;
}
return 0;
@@ -940,7 +940,7 @@ int __hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
base = lock_hrtimer_base(timer, &flags);

/* Remove an active timer from the queue: */
- ret = remove_hrtimer(timer, base);
+ ret = remove_hrtimer(timer, base, false);

if (mode & HRTIMER_MODE_REL) {
tim = ktime_add_safe(tim, base->get_time());
@@ -1061,7 +1061,7 @@ int hrtimer_try_to_cancel(struct hrtimer *timer)
base = lock_hrtimer_base(timer, &flags);

if (!hrtimer_callback_running(timer))
- ret = remove_hrtimer(timer, base);
+ ret = remove_hrtimer(timer, base, true);

unlock_hrtimer_base(timer, &flags);

--
1.5.5.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/