Re: Confused about hlist_unhashed_lockless()
From: Paul E. McKenney
Date: Fri Jan 31 2020 - 15:52:07 EST
On Fri, Jan 31, 2020 at 08:47:23PM +0100, Thomas Gleixner wrote:
> Eric Dumazet <edumazet@xxxxxxxxxx> writes:
> > On Fri, Jan 31, 2020 at 9:21 AM Will Deacon <will@xxxxxxxxxx> wrote:
> >> Without serialisation, timer_pending() as currently implemented does
> >> not reliably tell you whether the timer is in the hlist. Is that not a
> >> problem?
> >
> > No it is not a problem.
>
> Even if we would take the base lock then this is just a snapshot, which
> can be wrong at the moment the lock is dropped. So why bother?
The risk of leaving it as-is or of using data_race() is that if it is
checked multiple times, the compiler might use the old value. Yes,
we could say that things like barrier() should be used in those cases,
but READ_ONCE() has the advantage of making it so that no one has to
worry about those cases.
Thanx, Paul