From: Boqun Feng <boqun.feng@gmail.com>
To: Frederic Weisbecker <frederic@kernel.org>
Cc: "Paul E. McKenney" <paulmck@kernel.org>,
rcu@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@fb.com, mingo@kernel.org, jiangshanlai@gmail.com,
akpm@linux-foundation.org, mathieu.desnoyers@efficios.com,
josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org,
rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com,
fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH rcu 04/18] rcu: Weaken ->dynticks accesses and updates
Date: Fri, 30 Jul 2021 13:56:41 +0800 [thread overview]
Message-ID: <YQOUmZmAZQIhjEWC@boqun-archlinux> (raw)
In-Reply-To: <20210729105331.GA301667@lothringen>
On Thu, Jul 29, 2021 at 12:53:31PM +0200, Frederic Weisbecker wrote:
> On Thu, Jul 29, 2021 at 03:58:04PM +0800, Boqun Feng wrote:
> > > The following litmus test, also adapted from the one supplied off-list
> > > by Frederic Weisbecker, models the RCU grace-period kthread detecting
> > > a non-idle CPU that is concurrently transitioning to idle:
> > >
> > > C dynticks-into-idle
> > >
> > > {
> > > DYNTICKS=1; (* Initially non-idle. *)
> > > }
> > >
> > > P0(int *X, int *DYNTICKS)
> > > {
> > > int dynticks;
> > >
> > > // Non-idle.
> > > WRITE_ONCE(*X, 1);
> > > dynticks = READ_ONCE(*DYNTICKS);
> > > smp_store_release(DYNTICKS, dynticks + 1);
> > > smp_mb();
> >
> > this smp_mb() is not needed, as we rely on the release-acquire pair to
> > provide the ordering.
> >
> > This means that if we use different implementations (one w/ smp_mb(),
> > another w/o) rcu_dynticks_inc() for idle-to-nonidle and nonidle-to-idle,
> > we could save a smp_mb(). Thoughts?
>
> That's exactly what I wanted to propose but everybody was sober. Namely order
> only the RCU read side critical sections before/after idle together:
>
> READ side critical section
> //enter idle
> //exit idle
> smp_mb()
> READ side critical section
>
> instead of ordering the RCU read side critical section before idle - with the RCU
> idle extended quiescent state - with the RCU read side critical section after idle:
>
> READ side critical section
> //enter idle
> smp_mb();
> //exit idle
> smp_mb()
> READ side critical section
>
> So the side effect now is that if the write side waits for the reader to
> report a quiescent state and scans its dynticks state and see it's not yet in
> RCU idle mode, then later on when the read side enters in RCU idle mode we
> expect it to see the write side updates.
> But after the barrier removal the reader will only see the write side update
> once we exit RCU idle mode.
>
> So the following may happen:
>
> P0(int *X, int *Y, int *DYNTICKS)
> {
> int y;
>
> WRITE_ONCE(*X, 1);
> smp_store_release(DYNTICKS, 1); // rcu_eqs_enter
> //smp_mb() not there anymore
> y = READ_ONCE(*Y);
> smp_store_release(DYNTICKS, 2); // rcu_eqs_exit()
> smp_mb();
> }
>
> P1(int *X, int *Y, int *DYNTICKS)
> {
> int x;
> int dynticks;
>
> WRITE_ONCE(*Y, 1);
> smp_mb();
> dynticks = smp_load_acquire(DYNTICKS);
> x = READ_ONCE(*X);
> }
>
> exists (1:x=0 /\ 0:y=0)
>
Thanks for the detailed explanation ;-)
> Theoretically it shouldn't matter because the RCU idle mode isn't
> supposed to perform RCU reads. But theoretically again once a CPU
Right, in LOCKDEP=y kernel, rcu_read_lock_held() requires
rcu_is_watching(), so rcu_dereference() is not allowed in idle mode,
unless using RCU_NONIDLE() or rcu_irq_enter_irqson() to temporarily exit
the idle mode.
> has reported a quiescent state, any further read is expected to see
> the latest updates from the write side.
Yes, but in your above case, doesn't P0 already reach to a quiescent
state even before WRITE_ONCE()? IOW, that case is similar to the
following:
P0(int *X, int *Y)
{
// in QS
WRITE_ONCE(*X, 1);
y = READ_ONCE(*Y);
}
P1(int *X, int *Y)
{
WRITE_ONCE(*Y, 1);
synchronize_rcu();
x = READ_ONCE(*X);
}
exists (1:x=0 /\ 0:y=0)
And RCU doesn't guarantee the READ_ONCE() on P0 sees the WRITE_ONCE() on
P1.
>
> So I don't know what to think. In practice I believe it's not a big deal
> because RCU idle mode code is usually a fragile path that just handles
> cpuidle code to put the CPU in/out low power mode. But what about dragons...
My current thought is that if the cpuidle code requires some ordering
with synchronize_rcu(), RCU_NONIDLE() should be used, and ordering can
be guaranteed in this case (RCU_NONIDLE() has a rcu_eqs_exit() in it).
Otherwise, it's a bug.
So looks like we can drop that smp_mb() in rcu_eqs_enter()? At least, we
can say something in the doc to prevent people from relying on the
ordering between normal reads in RCU idle mode and synchronize_rcu().
Thoughts?
Regards,
Boqun
next prev parent reply other threads:[~2021-07-30 5:57 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-21 20:20 [PATCH rcu 0/18] Miscellaneous fixes for v5.15 Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 01/18] rcu: Fix to include first blocked task in stall warning Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 02/18] rcu: Fix stall-warning deadlock due to non-release of rcu_node ->lock Paul E. McKenney
2021-08-03 14:24 ` Qais Yousef
2021-08-03 15:52 ` Paul E. McKenney
2021-08-03 16:12 ` Qais Yousef
2021-08-03 16:28 ` Paul E. McKenney
2021-08-03 16:33 ` Qais Yousef
2021-08-04 13:50 ` Qais Yousef
2021-08-04 22:33 ` Paul E. McKenney
2021-08-06 9:56 ` Qais Yousef
2021-08-06 9:57 ` Qais Yousef
2021-08-06 11:43 ` Paul E. McKenney
2021-08-06 12:33 ` Qais Yousef
2021-07-21 20:21 ` [PATCH rcu 03/18] rcu: Remove special bit at the bottom of the ->dynticks counter Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 04/18] rcu: Weaken ->dynticks accesses and updates Paul E. McKenney
2021-07-21 20:41 ` Linus Torvalds
2021-07-21 21:25 ` Paul E. McKenney
2021-07-28 17:37 ` [PATCH v2 " Paul E. McKenney
2021-07-28 17:58 ` Linus Torvalds
2021-07-28 18:12 ` Mathieu Desnoyers
2021-07-28 18:32 ` Linus Torvalds
2021-07-28 18:39 ` Mathieu Desnoyers
2021-07-28 18:46 ` Paul E. McKenney
2021-07-28 18:46 ` Paul E. McKenney
2021-07-28 18:57 ` Linus Torvalds
2021-07-28 18:23 ` Mathieu Desnoyers
2021-07-28 18:58 ` Paul E. McKenney
2021-07-28 19:45 ` Paul E. McKenney
2021-07-28 20:03 ` Mathieu Desnoyers
2021-07-28 20:28 ` Paul E. McKenney
2021-07-29 14:41 ` Mathieu Desnoyers
2021-07-29 15:57 ` Paul E. McKenney
2021-07-29 17:41 ` Mathieu Desnoyers
2021-07-29 18:05 ` Paul E. McKenney
2021-07-29 18:42 ` Mathieu Desnoyers
2021-07-28 20:37 ` Josh Triplett
2021-07-28 20:47 ` Paul E. McKenney
2021-07-28 22:23 ` Frederic Weisbecker
2021-07-29 1:07 ` Paul E. McKenney
2021-07-29 7:58 ` [PATCH " Boqun Feng
2021-07-29 10:53 ` Frederic Weisbecker
2021-07-30 5:56 ` Boqun Feng [this message]
2021-07-30 17:18 ` Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 05/18] rcu: Mark accesses to ->rcu_read_lock_nesting Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 06/18] rculist: Unify documentation about missing list_empty_rcu() Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 07/18] rcu/tree: Handle VM stoppage in stall detection Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 08/18] rcu: Do not disable GP stall detection in rcu_cpu_stall_reset() Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 09/18] rcu: Start timing stall repetitions after warning complete Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 10/18] srcutiny: Mark read-side data races Paul E. McKenney
2021-07-29 8:23 ` Boqun Feng
2021-07-29 13:36 ` Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 11/18] rcu: Mark lockless ->qsmask read in rcu_check_boost_fail() Paul E. McKenney
2021-07-29 8:54 ` Boqun Feng
2021-07-29 14:03 ` Paul E. McKenney
2021-07-30 2:28 ` Boqun Feng
2021-07-30 3:26 ` Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 12/18] rcu: Make rcu_gp_init() and rcu_gp_fqs_loop noinline to conserve stack Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 13/18] rcu: Remove trailing spaces and tabs Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 14/18] rcu: Mark accesses in tree_stall.h Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 15/18] rcu: Remove useless "ret" update in rcu_gp_fqs_loop() Paul E. McKenney
2021-08-03 16:48 ` Joe Perches
2021-08-03 17:10 ` Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 16/18] rcu: Use per_cpu_ptr to get the pointer of per_cpu variable Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 17/18] rcu: Explain why rcu_all_qs() is a stub in preemptible TREE RCU Paul E. McKenney
2021-07-21 20:21 ` [PATCH rcu 18/18] rcu: Print human-readable message for schedule() in RCU reader Paul E. McKenney
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=YQOUmZmAZQIhjEWC@boqun-archlinux \
--to=boqun.feng@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=edumazet@google.com \
--cc=frederic@kernel.org \
--cc=fweisbec@gmail.com \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).