public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-team@meta.com, rostedt@goodmis.org
Subject: Re: [PATCH RFC v2 rcu] Fix get_state_synchronize_rcu_full() GP-start detection
Date: Fri, 24 Jan 2025 23:25:01 +0100	[thread overview]
Message-ID: <Z5QTPWMUzqEE-h6A@pavilion.home> (raw)
In-Reply-To: <c58693df-24dc-4c2a-b04a-d96637235e09@paulmck-laptop>

Le Fri, Jan 24, 2025 at 11:40:54AM -0800, Paul E. McKenney a écrit :
> > > > I'm wondering, what prevents us from removing rcu_state.gp_seq and rely only on
> > > > the root node for the global state ?
> > > 
> > > One scenario comes to mind immediately.  There may be others.
> > > 
> > > Suppose we were running with default configuration on a system with
> > > "only" eight CPUs.  Then there is only the one rcu_node structure,
> > > which is both root and leaf.  Without rcu_state.gp_seq, there
> > > would be no way to communicate the beginning of the grace period to
> > > get_state_synchronize_rcu_full() without also allowing quiescent states
> > > to be reported.  There would thus be no time in which to check for newly
> > > onlined/offlined CPUs.
> > 
> > Heh, that makes sense! Though perhaps that qsmaskinit[next] handling part
> > could be done before rcu_seq_start()?
> 
> If we do that, aren't we vulnerable to a CPU coming online just after
> we handled qsmaskinit{,next} and just before we do rcu_seq_start()?

But then that CPU is guaranteed to see the pre-GP accesses because
rcutree_report_cpu_starting() holds the rnp lock.

Hmm but it won't see the starting gp_seq and it might therefore be one GP
too early while accelerating its own callbacks (mis-attributing them the
current GP in progress instead of a subsequent one) even though other CPUs
may have reported their own QS already.

Because I only now realize this necessary order while starting a grace period:

1) rcu_seq_start(rcu_state.gp_seq)
2) go through ->qsmaskinit[next] _while holding leaf rnp locks_
3) go through the whole tree breadth first to reflect rcu_state.gp_seq to
   rnp->gp_seq. CPUs may start reporting QS concurrently once the first leaf
   node is reached

And the step 2) with its fully ordered locking on leaves which release the write
to rcu_state.gp_seq is what makes sure that if any CPU from step 3) has already
reported a QS, it is guaranteed that any call to rcu_seq_snap() under any other
leaf rnp locking will return the sequence of the subsequent GP number and not the
current one in progress.

This is what makes RCU an entertaining companion. You (think you) understand
it in the evening and then you forget it all over again in the next morning.
(And in lunch time you stare at things...).

Thanks.

  reply	other threads:[~2025-01-24 22:25 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-13  0:59 [PATCH RFC rcu] Fix get_state_synchronize_rcu_full() GP-start detection Paul E. McKenney
2024-12-13 19:49 ` [PATCH RFC v2 " Paul E. McKenney
2025-01-24 14:49   ` Frederic Weisbecker
2025-01-24 15:58     ` Paul E. McKenney
2025-01-24 16:42       ` Frederic Weisbecker
2025-01-24 19:40         ` Paul E. McKenney
2025-01-24 22:25           ` Frederic Weisbecker [this message]
2025-01-24 22:50             ` Paul E. McKenney
2025-01-24 23:03   ` Frederic Weisbecker
2025-01-25  0:01     ` Paul E. McKenney
2025-01-25 14:56       ` Frederic Weisbecker
2025-01-25 18:39         ` Paul E. McKenney
2025-01-27  1:13           ` Joel Fernandes
2025-01-27  1:22             ` Joel Fernandes
2025-01-27  2:03               ` Paul E. McKenney
2025-01-27  2:55                 ` Joel Fernandes
2025-01-27  2:58                   ` Joel Fernandes
2025-01-27 16:49                     ` Paul E. McKenney
2025-01-27 18:45                       ` Joel Fernandes
2025-02-11  0:28                         ` Joel Fernandes
2025-02-11  1:22                           ` Joel Fernandes
2025-02-12 10:14                             ` Paul E. McKenney
2025-02-12 10:42                               ` Paul E. McKenney
2025-01-24  1:49 ` [PATCH RFC " Joel Fernandes
2025-01-24 14:56   ` Frederic Weisbecker
2025-01-24 20:21     ` Joel Fernandes

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=Z5QTPWMUzqEE-h6A@pavilion.home \
    --to=frederic@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.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