public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Uladzislau Rezki <urezki@gmail.com>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Boqun Feng <boqun.feng@gmail.com>,
	Uladzislau Rezki <urezki@gmail.com>, RCU <rcu@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	Cheung Wall <zzqq0103.hey@gmail.com>,
	Neeraj upadhyay <Neeraj.Upadhyay@amd.com>,
	Joel Fernandes <joel@joelfernandes.org>,
	Oleksiy Avramchenko <oleksiy.avramchenko@sony.com>
Subject: Re: [PATCH v4 3/3] rcu: Use _full() API to debug synchronize_rcu()
Date: Mon, 3 Mar 2025 17:03:42 +0100	[thread overview]
Message-ID: <Z8XS3hJFR3qMNniG@pc636> (raw)
In-Reply-To: <e62483fc-489e-40bd-b77d-b4728a53df3e@paulmck-laptop>

On Sun, Mar 02, 2025 at 12:36:51PM -0800, Paul E. McKenney wrote:
> On Sun, Mar 02, 2025 at 10:46:29AM -0800, Boqun Feng wrote:
> > On Sun, Mar 02, 2025 at 09:39:44AM -0800, Paul E. McKenney wrote:
> > > On Sun, Mar 02, 2025 at 11:19:44AM +0100, Uladzislau Rezki wrote:
> > > > On Fri, Feb 28, 2025 at 05:08:49PM -0800, Paul E. McKenney wrote:
> > > > > On Fri, Feb 28, 2025 at 11:59:55AM -0800, Paul E. McKenney wrote:
> > > > > > On Fri, Feb 28, 2025 at 08:12:51PM +0100, Uladzislau Rezki wrote:
> > > > > > > Hello, Paul!
> > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > Except that I got this from overnight testing of rcu/dev on the shared
> > > > > > > > > > > > RCU tree:
> > > > > > > > > > > > 
> > > > > > > > > > > > WARNING: CPU: 5 PID: 14 at kernel/rcu/tree.c:1636 rcu_sr_normal_complete+0x5c/0x80
> > > > > > > > > > > > 
> > > > > > > > > > > > I see this only on TREE05.  Which should not be too surprising, given
> > > > > > > > > > > > that this is the scenario that tests it.  It happened within five minutes
> > > > > > > > > > > > on all 14 of the TREE05 runs.
> > > > > > > > > > > > 
> > > > > > > > > > > Hm.. This is not fun. I tested this on my system and i did not manage to
> > > > > > > > > > > trigger this whereas you do. Something is wrong.
> > > > > > > > > > 
> > > > > > > > > > If you have a debug patch, I would be happy to give it a go.
> > > > > > > > > > 
> > > > > > > > > I can trigger it. But.
> > > > > > > > > 
> > > > > > > > > Some background. I tested those patches during many hours on the stable
> > > > > > > > > kernel which is 6.13. On that kernel i was not able to trigger it. Running
> > > > > > > > > the rcutorture on the our shared "dev" tree, which i did now, triggers this
> > > > > > > > > right away.
> > > > > > > > 
> > > > > > > > Bisection?  (Hey, you knew that was coming!)
> > > > > > > > 
> > > > > > > Looks like this: rcu: Fix get_state_synchronize_rcu_full() GP-start detection
> > > > > > > 
> > > > > > > After revert in the dev, rcutorture passes TREE05, 16 instances.
> > > > > > 
> > > > > > Huh.  We sure don't get to revert that one...
> > > > > > 
> > > > > > Do we have a problem with the ordering in rcu_gp_init() between the calls
> > > > > > to rcu_seq_start() and portions of rcu_sr_normal_gp_init()?  For example,
> > > > > > do we need to capture the relevant portion of the list before the call
> > > > > > to rcu_seq_start(), and do the grace-period-start work afterwards?
> > > > > 
> > > > > I tried moving the call to rcu_sr_normal_gp_init() before the call to
> > > > > rcu_seq_start() and got no failures in a one-hour run of 200*TREE05.
> > > > > Which does not necessarily mean that this is the correct fix, but I
> > > > > figured that it might at least provide food for thought.
> > > > > 
> > > > > 							Thanx, Paul
> > > > > 
> > > > > ------------------------------------------------------------------------
> > > > > 
> > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > > > > index 48384fa2eaeb8..d3efeff7740e7 100644
> > > > > --- a/kernel/rcu/tree.c
> > > > > +++ b/kernel/rcu/tree.c
> > > > > @@ -1819,10 +1819,10 @@ static noinline_for_stack bool rcu_gp_init(void)
> > > > >  
> > > > >  	/* Advance to a new grace period and initialize state. */
> > > > >  	record_gp_stall_check_time();
> > > > > +	start_new_poll = rcu_sr_normal_gp_init();
> > > > >  	/* Record GP times before starting GP, hence rcu_seq_start(). */
> > > > >  	rcu_seq_start(&rcu_state.gp_seq);
> > > > >  	ASSERT_EXCLUSIVE_WRITER(rcu_state.gp_seq);
> > > > > -	start_new_poll = rcu_sr_normal_gp_init();
> > > > >  	trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq, TPS("start"));
> > > > >  	rcu_poll_gp_seq_start(&rcu_state.gp_seq_polled_snap);
> > > > >  	raw_spin_unlock_irq_rcu_node(rnp);
> > > > >
> > > > Running this 24 hours already. TREE05 * 16 scenario. I do not see any
> > > > warnings yet. There is a race, indeed. The gp_seq is moved forward,
> > > > wheres clients can still come until rcu_sr_normal_gp_init() places a
> > > > dummy-wait-head for this GP.
> > > > 
> > > > Thank you for testing Paul and looking to this :)
> > > 
> > > Very good!  This is a bug in this commit of mine:
> > > 
> > > 012f47f0f806 ("rcu: Fix get_state_synchronize_rcu_full() GP-start detection")
> > > 
> > > Boqun, could you please fold this into that commit with something like
> > > this added to the commit log just before the paragraph starting with
> > > "Although this fixes 91a967fd6934"?
> > > 
> > > 	However, simply changing get_state_synchronize_rcu_full() function
> > > 	to use rcu_state.gp_seq instead of the root rcu_node structure's
> > > 	->gp_seq field results in a theoretical bug in kernels booted
> > > 	with rcutree.rcu_normal_wake_from_gp=1 due to the following
> > > 	sequence of events:
> > > 
> > > 	o	The rcu_gp_init() function invokes rcu_seq_start()
> > > 		to officially start a new grace period.
> > > 
> > > 	o	A new RCU reader begins, referencing X from some
> > > 		RCU-protected list.  The new grace period is not
> > > 		obligated to wait for this reader.
> > > 
> > > 	o	An updater removes X, then calls synchronize_rcu(),
> > > 		which queues a wait element.
> > > 
> > > 	o	The grace period ends, awakening the updater, which
> > > 		frees X while the reader is still referencing it.
> > > 
> > > 	The reason that this is theoretical is that although the
> > > 	grace period has officially started, none of the CPUs are
> > > 	officially aware of this, and thus will have to assume that
> > > 	the RCU reader pre-dated the start of the grace period.
> > > 
> > > 	Except for kernels built with CONFIG_PROVE_RCU=y, which use the
> > > 	polled grace-period APIs, which can and do complain bitterly when
> > > 	this sequence of events occurs.  Not only that, there might be
> > > 	some future RCU grace-period mechanism that pulls this sequence
> > > 	of events from theory into practice.  This commit therefore
> > > 	also pulls the call to rcu_sr_normal_gp_init() to precede that
> > > 	to rcu_seq_start().
> > > 
> > > I will let you guys decide whether the call to rcu_sr_normal_gp_init()
> > > needs a comment, and, if so, what that comment should say.  ;-)
> > > 
> > 
> > Please see the updated patch below (next and rcu/dev branches are
> > updated too).
> 
> Works for me!
> 
> >               For the comment, I think we can add something like
> > 
> > 	/* 
> > 	 * A new wait segment must be started before gp_seq advanced, so
> > 	 * that previous gp waiters won't observe the new gp_seq.
> > 	 */
> > 
> > but I will let Ulad to decide ;-)
> 
> Over to you, Uladzislau!  ;-)
> 
Works for me! Sorry for late answer. I got a fever, therefore i reply not
in time.

--
Uladzislau Rezki

  reply	other threads:[~2025-03-03 16:03 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-27 13:16 [PATCH v4 1/3] rcutorture: Allow a negative value for nfakewriters Uladzislau Rezki (Sony)
2025-02-27 13:16 ` [PATCH v4 2/3] rcu: Update TREE05.boot to test normal synchronize_rcu() Uladzislau Rezki (Sony)
2025-02-27 13:16 ` [PATCH v4 3/3] rcu: Use _full() API to debug synchronize_rcu() Uladzislau Rezki (Sony)
2025-02-27 17:12   ` Boqun Feng
2025-02-27 17:26     ` Paul E. McKenney
2025-02-27 17:30       ` Boqun Feng
2025-02-27 17:44       ` Uladzislau Rezki
2025-02-28 15:41         ` Paul E. McKenney
2025-02-28 16:36           ` Uladzislau Rezki
2025-02-28 17:08             ` Uladzislau Rezki
2025-02-28 18:25               ` Paul E. McKenney
2025-02-28 18:30                 ` Uladzislau Rezki
2025-02-28 18:21             ` Paul E. McKenney
2025-02-28 18:24               ` Uladzislau Rezki
2025-02-28 18:38                 ` Paul E. McKenney
2025-02-28 19:12                   ` Uladzislau Rezki
2025-02-28 19:59                     ` Paul E. McKenney
2025-03-01  1:08                       ` Paul E. McKenney
2025-03-02 10:19                         ` Uladzislau Rezki
2025-03-02 17:39                           ` Paul E. McKenney
2025-03-02 18:46                             ` Boqun Feng
2025-03-02 20:36                               ` Paul E. McKenney
2025-03-03 16:03                                 ` Uladzislau Rezki [this message]
2025-03-03  0:15                         ` Joel Fernandes
2025-03-03  0:17                           ` Joel Fernandes
2025-03-03 17:00                             ` Joel Fernandes
2025-03-03 17:07                               ` Boqun Feng
2025-03-03 17:30                                 ` Joel Fernandes
2025-03-03 17:59                                   ` Joel Fernandes
2025-03-03 18:55                                   ` Paul E. McKenney
2025-03-03 20:02                                     ` Joel Fernandes
2025-03-04  3:23                           ` Boqun Feng
2025-03-04 10:52                             ` Uladzislau Rezki
2025-03-04 10:56                               ` Uladzislau Rezki
2025-03-05  2:54                                 ` Boqun Feng
2025-03-05 15:37                                   ` Joel Fernandes
2025-03-05 15:24                             ` Joel Fernandes
2025-02-27 17:43     ` Uladzislau Rezki
2025-03-10  1:55   ` Joel Fernandes
2025-03-11 12:38     ` Uladzislau Rezki

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=Z8XS3hJFR3qMNniG@pc636 \
    --to=urezki@gmail.com \
    --cc=Neeraj.Upadhyay@amd.com \
    --cc=boqun.feng@gmail.com \
    --cc=frederic@kernel.org \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleksiy.avramchenko@sony.com \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=zzqq0103.hey@gmail.com \
    /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