archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <>
	"Paul E. McKenney" <>
Subject: [PATCH tip/core/rcu 4/4] srcu: Provide ordering for CPU not involved in grace period
Date: Mon, 24 Jul 2017 15:15:31 -0700	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

Tree RCU guarantees that every online CPU has a memory barrier between
any given grace period and any of that CPU's RCU read-side sections that
must be ordered against that grace period.  Since RCU doesn't always
know where read-side critical sections are, the actual implementation
guarantees order against prior and subsequent non-idle non-offline code,
whether in an RCU read-side critical section or not.  As a result, there
does not need to be a memory barrier at the end of synchronize_rcu()
and friends because the ordering internal to the grace period has
ordered every CPU's post-grace-period execution against each CPU's
pre-grace-period execution, again for all non-idle online CPUs.

In contrast, SRCU can have non-idle online CPUs that are completely
uninvolved in a given SRCU grace period, for example, a CPU that
never runs any SRCU read-side critical sections and took no part in
the grace-period processing.  It is in theory possible for a given
synchronize_srcu()'s wakeup to be delivered to a CPU that was completely
uninvolved in the prior SRCU grace period, which could mean that the
code following that synchronize_srcu() would end up being unordered with
respect to both the grace period and any pre-existing SRCU read-side
critical sections.

This commit therefore adds an smp_mb() to the end of __synchronize_srcu(),
which prevents this scenario from occurring.

Reported-by: Lance Roy <>
Signed-off-by: Paul E. McKenney <>
Acked-by: Lance Roy <>
 kernel/rcu/srcutree.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 94bd6ed43ea3..c1c0ee3cce3b 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -897,6 +897,15 @@ static void __synchronize_srcu(struct srcu_struct *sp, bool do_norm)
 	__call_srcu(sp, &rcu.head, wakeme_after_rcu, do_norm);
+	/*
+	 * Make sure that later code is ordered after the SRCU grace
+	 * period.  This pairs with the raw_spin_lock_irq_rcu_node()
+	 * in srcu_invoke_callbacks().  Unlike Tree RCU, this is needed
+	 * because the current CPU might have been totally uninvolved with
+	 * (and thus unordered against) that grace period.
+	 */
+	smp_mb();

      parent reply	other threads:[~2017-07-24 22:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-24 22:15 [PATCH tip/core/rcu 0/4] SRCU updates Paul E. McKenney
2017-07-24 22:15 ` [PATCH tip/core/rcu 1/4] srcu: Move rcu_scheduler_starting() from Tiny RCU to Tiny SRCU Paul E. McKenney
2017-07-24 22:15 ` [PATCH tip/core/rcu 2/4] rcutorture: Remove obsolete SRCU-C.boot Paul E. McKenney
2017-07-24 22:15 ` [PATCH tip/core/rcu 3/4] srcu: Make process_srcu() be static Paul E. McKenney
2017-07-24 22:15 ` Paul E. McKenney [this message]

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
    --subject='Re: [PATCH tip/core/rcu 4/4] srcu: Provide ordering for CPU not involved in grace period' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).