[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ff2aecbc-cd5d-4a9c-92b1-792555300301@paulmck-laptop>
Date: Wed, 18 Dec 2024 07:43:41 -0800
From: "Paul E. McKenney" <paulmck@...nel.org>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Daniel Xu <dxu@...uu.xyz>, mingo@...hat.com, will@...nel.org,
longman@...hat.com, boqun.feng@...il.com,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] seqlock: Use WRITE_ONCE() when updating sequence
On Wed, Dec 18, 2024 at 11:30:00AM +0100, Peter Zijlstra wrote:
> On Tue, Dec 17, 2024 at 03:17:36PM -0800, Daniel Xu wrote:
> > `sequence` is a concurrently accessed shared variable on the reader
> > side. Therefore, it needs to be wrapped in WRITE_ONCE() in order to
> > prevent unwanted compiler optimizations like store tearing.
> >
> > Signed-off-by: Daniel Xu <dxu@...uu.xyz>
> > ---
> > include/linux/seqlock.h | 14 +++++++-------
> > 1 file changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
> > index 5298765d6ca4..f4c6f2507742 100644
> > --- a/include/linux/seqlock.h
> > +++ b/include/linux/seqlock.h
> > @@ -45,7 +45,7 @@ static inline void __seqcount_init(seqcount_t *s, const char *name,
> > * Make sure we are not reinitializing a held lock:
> > */
> > lockdep_init_map(&s->dep_map, name, key, 0);
> > - s->sequence = 0;
> > + WRITE_ONCE(s->sequence, 0);
> > }
> >
> > #ifdef CONFIG_DEBUG_LOCK_ALLOC
> > @@ -405,7 +405,7 @@ do { \
> > static inline void do_raw_write_seqcount_begin(seqcount_t *s)
> > {
> > kcsan_nestable_atomic_begin();
> > - s->sequence++;
> > + WRITE_ONCE(s->sequence, READ_ONCE(s->sequence) + 1);
> > smp_wmb();
> > }
>
> This results in significantly worse code-gen, it will change an inc to
> memory with a load,inc,store.
Isn't that code-generation bug in the process of being fixed? And,
either way, given the likely cache miss, should we really care?
Thanx, Paul
Powered by blists - more mailing lists