Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933205AbdIXVAf (ORCPT ); Sun, 24 Sep 2017 17:00:35 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60438 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932999AbdIXUlD (ORCPT ); Sun, 24 Sep 2017 16:41:03 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lance Roy , "Paul E. McKenney" Subject: [PATCH 4.13 006/109] srcu: Provide ordering for CPU not involved in grace period Date: Sun, 24 Sep 2017 22:32:27 +0200 Message-Id: <20170924203353.359258813@linuxfoundation.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170924203353.104695385@linuxfoundation.org> References: <20170924203353.104695385@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2488 Lines: 60 4.13-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paul E. McKenney commit 35732cf9dd38b1efb0f2f22c91c61b51337d1ac3 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- kernel/rcu/srcutree.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -896,6 +896,15 @@ static void __synchronize_srcu(struct sr __call_srcu(sp, &rcu.head, wakeme_after_rcu, do_norm); wait_for_completion(&rcu.completion); destroy_rcu_head_on_stack(&rcu.head); + + /* + * 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(); } /**