All of lore.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will@kernel.org>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: David Laight <David.Laight@ACULAB.COM>,
	'Eric Dumazet' <edumazet@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	the arch/x86 maintainers <x86@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Marco Elver <elver@google.com>
Subject: Re: Confused about hlist_unhashed_lockless()
Date: Mon, 3 Feb 2020 18:27:37 +0000	[thread overview]
Message-ID: <20200203182737.GB12136@willie-the-truck> (raw)
In-Reply-To: <20200203172947.GM2935@paulmck-ThinkPad-P72>

Hi Paul,

On Mon, Feb 03, 2020 at 09:29:47AM -0800, Paul E. McKenney wrote:
> On Mon, Feb 03, 2020 at 04:02:28PM +0000, Will Deacon wrote:
> > On Mon, Feb 03, 2020 at 07:58:39AM -0800, Paul E. McKenney wrote:
> > > On Mon, Feb 03, 2020 at 03:45:54PM +0000, David Laight wrote:
> > > > From: Eric Dumazet
> > > > > Sent: 31 January 2020 18:53
> > > > > 
> > > > > On Fri, Jan 31, 2020 at 10:48 AM Eric Dumazet <edumazet@google.com> wrote:
> > > > > >
> > > > > 
> > > > > > This is nice, now with have data_race()
> > > > > >
> > > > > > Remember these patches were sent 2 months ago, at a time we were
> > > > > > trying to sort out things.
> > > > > >
> > > > > > data_race() was merged a few days ago.
> > > > > 
> > > > > Well, actually data_race() is not there yet anyway.
> > > > 
> > > > Shouldn't it be NO_DATA_RACE() ??
> > > 
> > > No, because you use data_race() when there really are data races, but you
> > > want KCSAN to ignore them.  For example, diagnostic code that doesn't
> > > participate in the actual concurrency design and that doesn't run all
> > > that often might use data_race().  For another example, if a developer
> > > knew that data races existed, but that the compiler could not reasonably
> > > do anything untoward with those data races, that developer might well
> > > choose to use data_race() instead of READ_ONCE().  Especially if the
> > > access in question was on a fastpath where helpful compiler optimizations
> > > would be prohibited by use of READ_ONCE().
> > 
> > Yes, and in this particular case I think we can remove some WRITE_ONCE()s
> > from the non-RCU hlist code too (similarly for hlist_nulls).
> 
> Quite possibly, but we should take them case by case.  READ_ONCE()
> really does protect against some optimizations, while data_race() does
> not at all.

Agreed, and I plan to send patches for review so we can discuss them in
more detail then.

> But yes, in some cases you want to -avoid- using READ_ONCE() and
> WRITE_ONCE() so that KCSAN can do its job.  For example, given a per-CPU
> variable that is only supposed to be accessed from the corresponding CPU
> except for reads by diagnostic code, you should have the main algorithm
> use plain C-language reads and writes, and have the diagnostic code
> use data_race().  This allows KCSAN to correctly flag bugs that access
> this per-CPU variable off-CPU while leaving the diagnostic code alone.

Yes, and in a similar vein I think the WRITE_ONCE() additions to the hlist
code may hide unintentional racy access to the hlist where I would argue
that the correct behaviour is either to acknowledge the data race (like the
timer code) or to use the RCU variant. The problem with what's currently in
mainline is that it reads a bit like the non-RCU hlist is directly usable as
a lock-free list implementation, which really isn't the case.

> Seem reasonable?

It does to me, but we should probably try to apply this a bit more
consistently in patch review. Adding {READ,WRITE}_ONCE() until the
sanitiser shuts up is easy, but picking that apart later on is a real
challenge.

Will

  reply	other threads:[~2020-02-03 18:27 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-31 16:43 Confused about hlist_unhashed_lockless() Will Deacon
2020-01-31 16:48 ` Eric Dumazet
2020-01-31 16:57   ` Will Deacon
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 [this message]
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=20200203182737.GB12136@willie-the-truck \
    --to=will@kernel.org \
    --cc=David.Laight@ACULAB.COM \
    --cc=edumazet@google.com \
    --cc=elver@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.