Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[platform/kernel/linux-starfive.git] / kernel / time / hrtimer.c
index 9e20873..8de90ea 100644 (file)
@@ -966,7 +966,8 @@ static int enqueue_hrtimer(struct hrtimer *timer,
 
        base->cpu_base->active_bases |= 1 << base->index;
 
-       timer->state = HRTIMER_STATE_ENQUEUED;
+       /* Pairs with the lockless read in hrtimer_is_queued() */
+       WRITE_ONCE(timer->state, HRTIMER_STATE_ENQUEUED);
 
        return timerqueue_add(&base->active, &timer->node);
 }
@@ -988,7 +989,8 @@ static void __remove_hrtimer(struct hrtimer *timer,
        struct hrtimer_cpu_base *cpu_base = base->cpu_base;
        u8 state = timer->state;
 
-       timer->state = newstate;
+       /* Pairs with the lockless read in hrtimer_is_queued() */
+       WRITE_ONCE(timer->state, newstate);
        if (!(state & HRTIMER_STATE_ENQUEUED))
                return;
 
@@ -1013,8 +1015,9 @@ static void __remove_hrtimer(struct hrtimer *timer,
 static inline int
 remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base, bool restart)
 {
-       if (hrtimer_is_queued(timer)) {
-               u8 state = timer->state;
+       u8 state = timer->state;
+
+       if (state & HRTIMER_STATE_ENQUEUED) {
                int reprogram;
 
                /*