Re: [tip: timers/core] hrtimer: Annotate lockless access to timer->state

From: Eric Dumazet
Date: Wed Nov 06 2019 - 17:03:14 EST


On Wed, Nov 6, 2019 at 1:06 PM tip-bot2 for Eric Dumazet
<tip-bot2@xxxxxxxxxxxxx> wrote:
>
> The following commit has been merged into the timers/core branch of tip:
>
> Commit-ID: de4db39b9f0e682e59caa828a277632510901560
> Gitweb: https://git.kernel.org/tip/de4db39b9f0e682e59caa828a277632510901560
> Author: Eric Dumazet <edumazet@xxxxxxxxxx>
> AuthorDate: Wed, 06 Nov 2019 09:48:04 -08:00
> Committer: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> CommitterDate: Wed, 06 Nov 2019 21:59:56 +01:00
>
> hrtimer: Annotate lockless access to timer->state

...

> -/*
> - * Helper function to check, whether the timer is on one of the queues
> +/**
> + * hrtimer_is_queued = check, whether the timer is on one of the queues
> + * @timer: Timer to check
> + *
> + * Returns: True if the timer is queued, false otherwise
> + *
> + * The function can be used lockless, but it gives only a current snapshot.
> */
> -static inline int hrtimer_is_queued(struct hrtimer *timer)
> +static inline bool hrtimer_is_queued(struct hrtimer *timer)
> {
> - return timer->state & HRTIMER_STATE_ENQUEUED;
> + /* The READ_ONCE pairs with the update functions of timer->state */
> + return !!READ_ONCE(timer->state) & HRTIMER_STATE_ENQUEUED;

You probably meant :

return !!(READ_ONCE(timer->state) & HRTIMER_STATE_ENQUEUED);

Sorry for not spotting this earlier.