From: Will Deacon <will@kernel.org>
To: Eric Dumazet <edumazet@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
"Paul E. McKenney" <paulmck@kernel.org>,
the arch/x86 maintainers <x86@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: Confused about hlist_unhashed_lockless()
Date: Fri, 31 Jan 2020 16:57:18 +0000 [thread overview]
Message-ID: <20200131165718.GA5517@willie-the-truck> (raw)
In-Reply-To: <CANn89i+CnezK81gZSLOy0w7MaZy0uT=xyxoKSTyZU3aMpzifOA@mail.gmail.com>
On Fri, Jan 31, 2020 at 08:48:05AM -0800, Eric Dumazet wrote:
> On Fri, Jan 31, 2020 at 8:43 AM Will Deacon <will@kernel.org> wrote:
> > I just ran into c54a2744497d ("list: Add hlist_unhashed_lockless()")
> > but I'm a bit confused about what it's trying to achieve. It also seems
> > to have been merged without any callers (even in -next) -- was that
> > intentional?
> >
> > My main source of confusion is the lack of memory barriers. For example,
> > if you look at the following pair of functions:
> >
> >
> > static inline int hlist_unhashed_lockless(const struct hlist_node *h)
> > {
> > return !READ_ONCE(h->pprev);
> > }
> >
> > static inline void hlist_add_before(struct hlist_node *n,
> > struct hlist_node *next)
> > {
> > WRITE_ONCE(n->pprev, next->pprev);
> > WRITE_ONCE(n->next, next);
> > WRITE_ONCE(next->pprev, &n->next);
> > WRITE_ONCE(*(n->pprev), n);
> > }
> >
> >
> > Then running these two concurrently on the same node means that
> > hlist_unhashed_lockless() doesn't really tell you anything about whether
> > or not the node is reachable in the list (i.e. there is another node
> > with a next pointer pointing to it). In other words, I think all of
> > these outcomes are permitted:
> >
> > hlist_unhashed_lockless(n) n reachable in list
> > 0 0 (No reordering)
> > 0 1 (No reordering)
> > 1 0 (No reordering)
> > 1 1 (Reorder first and last WRITE_ONCEs)
> >
> > So I must be missing some details about the use-case here. Please could
> > you enlighten me? The RCU implementation permits only the first three
> > outcomes afaict, why not use that and leave non-RCU hlist as it was?
> >
>
> I guess the following has been lost :
Thanks, although...
> Author: Eric Dumazet <edumazet@google.com>
> Date: Thu Nov 7 11:23:14 2019 -0800
>
> timer: use hlist_unhashed_lockless() in timer_pending()
>
> timer_pending() is mostly used in lockless contexts.
... my point above still stands: the value returned by
hlist_unhashed_lockless() doesn't tell you anything about whether or
not the timer is reachable in the hlist or not. The comment above
timer_pending() also states that:
| Callers must ensure serialization wrt. other operations done to
| this timer, e.g. interrupt contexts, or other CPUs on SMP.
If that is intended to preclude list operations, shouldn't we use an
RCU hlist instead of throwing {READ,WRITE}_ONCE() at the problem to
shut the sanitiser up without actually fixing anything? :(
Will
next prev parent reply other threads:[~2020-01-31 16:57 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-31 16:43 Will Deacon
2020-01-31 16:48 ` Eric Dumazet
2020-01-31 16:57 ` Will Deacon [this message]
2020-01-31 17:06 ` Eric Dumazet
2020-01-31 17:20 ` Will Deacon
2020-01-31 17:33 ` Eric Dumazet
2020-01-31 18:32 ` Will Deacon
2020-01-31 19:47 ` Thomas Gleixner
2020-01-31 20:52 ` Paul E. McKenney
2020-01-31 18:43 ` Peter Zijlstra
2020-01-31 18:48 ` Eric Dumazet
2020-01-31 18:52 ` Eric Dumazet
2020-01-31 20:53 ` Paul E. McKenney
2020-01-31 21:04 ` Eric Dumazet
2020-01-31 21:19 ` Paul E. McKenney
2020-02-03 15:45 ` David Laight
2020-02-03 15:54 ` Marco Elver
2020-02-03 16:05 ` David Laight
2020-02-03 17:25 ` Paul E. McKenney
2020-02-03 15:58 ` Paul E. McKenney
2020-02-03 16:02 ` Will Deacon
2020-02-03 17:29 ` Paul E. McKenney
2020-02-03 18:27 ` Will Deacon
2020-02-03 21:16 ` Paul E. McKenney
2020-01-31 19:20 ` Marco Elver
2020-01-31 18:52 ` Paul E. McKenney
2020-01-31 18:55 ` Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200131165718.GA5517@willie-the-truck \
--to=will@kernel.org \
--cc=edumazet@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®