All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger@xenproject.org>
To: Jan Beulich <jbeulich@suse.com>
Cc: Alejandro Vallejo <alejandro.garciavallejo@amd.com>,
	xen-devel@lists.xenproject.org,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Anthony PERARD <anthony.perard@vates.tech>,
	Michal Orzel <michal.orzel@amd.com>,
	Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: [PATCH v2 1/3] xen/rcu: introduce the concept of RCU epoch
Date: Wed, 30 Sep 2026 10:09:49 +0200	[thread overview]
Message-ID: <arzDzQMP5rGz1-QJ@macbook.local> (raw)
In-Reply-To: <3e600ac0-3096-4cfb-967b-c6d87d8c04e6@suse.com>

On Wed, Sep 30, 2026 at 07:58:55AM +0200, Jan Beulich wrote:
> On 30.09.2026 00:14, Alejandro Vallejo wrote:
> > On Tue Sep 29, 2026 at 4:52 PM CEST, Jan Beulich wrote:
> >> On 29.09.2026 16:20, Roger Pau Monné wrote:
> >>> On Mon, Sep 28, 2026 at 10:24:04AM +0200, Alejandro Vallejo wrote:
> >>>> On Fri Sep 25, 2026 at 6:30 PM CEST, Roger Pau Monne wrote:
> >>>>>  static inline void rcu_quiesce_disable(void)
> >>>>>  {
> >>>>> +    unsigned int cpu = smp_processor_id();
> >>>>> +
> >>>>>      preempt_disable();
> >>>>> -    this_cpu(rcu_lock_cnt)++;
> >>>>> -    barrier();
> >>>>> +    if ( !ACCESS_ONCE(per_cpu(rcu_lock_cnt, cpu))++ )
> >>>>> +        ACCESS_ONCE(per_cpu(rcu_lock_epoch, cpu)) = ACCESS_ONCE(rcu_epoch);
> >>>>
> >>>> I'm not terribly convinced about using ACCESS_ONCE() for atomic
> >>>> accesses. In particular...
> >>>>
> >>>>> +    smp_mb();
> >>>>>  }
> >>>>>  
> >>>>>  static inline void rcu_quiesce_enable(void)
> >>>>>  {
> >>>>> -    barrier();
> >>>>> -    this_cpu(rcu_lock_cnt)--;
> >>>>> +
> >>>>> +    smp_mb();
> >>>>> +    ACCESS_ONCE(this_cpu(rcu_lock_cnt))--;
> >>>>
> >>>> ... this variable is to be read by remote CPUs and autodecrement seems
> >>>> like the wrong tool for an atomic decrement.
> >>>
> >>> I can use {read,write}_atomic() instead, but there's been a tendency
> >>> to phase out the usage of those functions.  On x86 this should be a
> >>> plain `addl` or `subl` instruction (the non-locked version of
> >>> atomic_{inc,dec}()).
> > 
> > I don't think the compiler can merge volatile reads and writes. It can
> > shatter them (thus my fear), but they are meant to be distinct because
> > each might have different side effects. Jan already mentioned this in
> > other words.
> > 
> > You don't need an atomic decrement though, just an atomic write. Note
> > IRQs restore it on exit and other CPUs don't write to it.
> > 
> >   unsigned int *lock_cnt = &this_cpu(rcu_lock_cnt);
> >   write_atomic(lock_cnt, *lock_cnt - 1);
> > 
> > and this yields a plain mov, through a static inline stub (plus the
> > mov from the read access + dec)
> > 
> > The problem with ACCESS_ONCE() is that the write isn't guaranteed to be
> > atomic.
> 
> It may not be properly written down anywhere, but at least the compilers
> we use are known to not tear aligned accesses up to a machine word in
> width.

Then I possibly don't need the ACCESS_ONCE() at all, as I was using it
to guarantee unshattered accesses.  However this should be written
somewhere, maybe in docs/process/coding-best-practices.pandoc?

Thanks, Roger.


  reply	other threads:[~2026-09-30  8:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 16:30 [PATCH v2 0/3] xen/rcu: rework the RCU logic Roger Pau Monne
2026-09-25 16:30 ` [PATCH v2 1/3] xen/rcu: introduce the concept of RCU epoch Roger Pau Monne
2026-09-28  8:24   ` Alejandro Vallejo
2026-09-29 14:20     ` Roger Pau Monné
2026-09-29 14:52       ` Jan Beulich
2026-09-29 22:14         ` Alejandro Vallejo
2026-09-30  5:58           ` Jan Beulich
2026-09-30  8:09             ` Roger Pau Monné [this message]
2026-09-30  8:34               ` Jan Beulich
2026-09-30 10:07                 ` Roger Pau Monné
2026-09-30 10:31                   ` Jan Beulich
2026-09-30 11:56                   ` Alejandro Vallejo
2026-09-30  8:32           ` Roger Pau Monné
2026-09-30 11:59             ` Alejandro Vallejo
2026-09-25 16:30 ` [PATCH v2 2/3] xen/rcu: simplify RCU implementation Roger Pau Monne
2026-09-28  8:31   ` Alejandro Vallejo
2026-09-28  9:05   ` Alejandro Vallejo
2026-09-29 13:53     ` Roger Pau Monné
2026-09-25 16:30 ` [PATCH v2 3/3] xen/rcu: remove rcu_quiesce_{disable,enable}() Roger Pau Monne

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=arzDzQMP5rGz1-QJ@macbook.local \
    --to=roger@xenproject.org \
    --cc=alejandro.garciavallejo@amd.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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.