Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp675866pxj; Thu, 10 Jun 2021 09:59:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe8xVTQnkIf0PjpOOkz0jOolq7xG3Nqt9A+dRNNs5XMumruCVed0eb3DEkS65ynInvPCZj X-Received: by 2002:aa7:d3ca:: with SMTP id o10mr406090edr.197.1623344361621; Thu, 10 Jun 2021 09:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623344361; cv=none; d=google.com; s=arc-20160816; b=R4vNXytzWUYCojz2BbpLAkQKDYIofiqYu0pj8BgnS45hFdHW7arq6YuMEj6zAxf7DU 3heyImY7HgYiS31jkHzXqm6e0VmZm31xgjfAMPt/OMXXHd+EZ5xXac09Oka4Sx6ygvvX 0bv4gd4ijv07Oe3q5sZzjmd9dO0sVlryPkcGrm92/vzLj+Q4jphb0fyhT7DcWyEnNOY4 7QLuwmLK65or7IsoY9EtMwX181P5VwsEmeLbXuJDaY21T3+xRHlilml/qOpNrpBvt4ju sLrLTNd+2fkGKYueCf21FiINe/E+TnUGGzCPmBTtEEdyAvwiRiixJNNcUhevBkoMUZwZ JH7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Tnh4uHbWyFtyzHeEdFH973/UyKDSvlC0a3Hi9XWq6y0=; b=BALbVLSSMQbJrpnCKLrK6napfue18wdDB8qiilZZ4/kBNS9ZVxjHyO0jJ5UnmDE7Qf I4rIYU6VxRMcf8+5FYF3EpRxDlqL76CwAJSn2LCkMiMS0bEnZyYzOXPlOVNsC6UnAoCP e0XYN7e+f60YcOobyC2pYLNu/5bRezUgGfiEEgRV9csBeeIV0VadDiPEiFoNxBKwbDxh d3a4BU/ofgBZORcMHErUel1jWVnEObjVxU3aCmDaEfTNaAPW4vSpYX3ophC6jDOn+pls HOGh4RRZzuGSqpwNm/DqVJeSty4mkwFhHV12VRK1tRrKghi/UPSK/AeJ4PLb9Rj8N+R/ UnsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qZNA0q+Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b3si2520199edh.532.2021.06.10.09.58.58; Thu, 10 Jun 2021 09:59:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qZNA0q+Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231308AbhFJQ7K (ORCPT + 99 others); Thu, 10 Jun 2021 12:59:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:34840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230184AbhFJQ7H (ORCPT ); Thu, 10 Jun 2021 12:59:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BC589613C9; Thu, 10 Jun 2021 16:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623344230; bh=hPzF3JJ08+uolh2AjL4CPlo6jg8ZUJv7Mm0OOsHZoh8=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=qZNA0q+QjG+nlHY+dv5xa/+qi8G/JLGtlPLZxqtcMDJFfrFOZ590SWecrRLrEJeyg 5ulONcsKR7kpRj2fvYlDPBWSciZGhOVSlPt5qfuwfs5SA0KOAeXm+3jVuwrMF9B4Pj VPHAdMyRc6xu8lekdIZvhq5Yr5PgGMhXLA+pDyDcZW16uc9IOrx+jH5BDsd2O7yWHm ghelUS3u3NfS8kswGuicH8As4jdxVzVRCEU33ZXLqWOn9mKGL8gnOgVcrKIjC+t0IH g/I0ZJOEQWIdikiO/ElekHWP1Af9JAjUjkOG0L393111vOu8NXHEU39ZGU3mCuugX6 +kSdf1chH1sEw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 8AE935C0611; Thu, 10 Jun 2021 09:57:10 -0700 (PDT) Date: Thu, 10 Jun 2021 09:57:10 -0700 From: "Paul E. McKenney" To: Frederic Weisbecker Cc: LKML , Neeraj Upadhyay , Boqun Feng , Uladzislau Rezki , Joel Fernandes Subject: Re: [PATCH] rcu/doc: Add a quick quiz to explain further why we need smp_mb__after_unlock_lock() Message-ID: <20210610165710.GT4397@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20210610155029.130812-1-frederic@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210610155029.130812-1-frederic@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 10, 2021 at 05:50:29PM +0200, Frederic Weisbecker wrote: > Add some missing critical pieces of explanation to understand the need > for full memory barriers throughout the whole grace period state machine, > thanks to Paul's explanations. > > Signed-off-by: Frederic Weisbecker > Cc: Neeraj Upadhyay > Cc: Joel Fernandes > Cc: Uladzislau Rezki > Cc: Boqun Feng Nice!!! And not bad wording either, though I still could not resist the urge to wordsmith further. Plus I combined your two examples, in order to provide a trivial example use of the polling interfaces, if nothing else. Please let me know if I messed anything up. Thanx, Paul ------------------------------------------------------------------------ commit f21b8fbdf9a59553da825265e92cedb639b4ba3c Author: Frederic Weisbecker Date: Thu Jun 10 17:50:29 2021 +0200 rcu/doc: Add a quick quiz to explain further why we need smp_mb__after_unlock_lock() Add some missing critical pieces of explanation to understand the need for full memory barriers throughout the whole grace period state machine, thanks to Paul's explanations. Signed-off-by: Frederic Weisbecker Cc: Neeraj Upadhyay Cc: Joel Fernandes Cc: Uladzislau Rezki Cc: Boqun Feng Signed-off-by: Paul E. McKenney diff --git a/Documentation/RCU/Design/Memory-Ordering/Tree-RCU-Memory-Ordering.rst b/Documentation/RCU/Design/Memory-Ordering/Tree-RCU-Memory-Ordering.rst index 11cdab037bff..3cd5cb4d86e5 100644 --- a/Documentation/RCU/Design/Memory-Ordering/Tree-RCU-Memory-Ordering.rst +++ b/Documentation/RCU/Design/Memory-Ordering/Tree-RCU-Memory-Ordering.rst @@ -112,6 +112,35 @@ on PowerPC. The ``smp_mb__after_unlock_lock()`` invocations prevent this ``WARN_ON()`` from triggering. ++-----------------------------------------------------------------------+ +| **Quick Quiz**: | ++-----------------------------------------------------------------------+ +| But the whole chain of rcu_node-structure locking guarantees that | +| readers see all pre-grace-period accesses from the updater and | +| also guarantees that the updater to see all post-grace-period | +| accesses from the readers. So why do we need all of those calls | +| to smp_mb__after_unlock_lock()? | ++-----------------------------------------------------------------------+ +| **Answer**: | ++-----------------------------------------------------------------------+ +| Because we must provide ordering for RCU's polling grace-period | +| primitives, for example, get_state_synchronize_rcu() and | +| poll_state_synchronize_rcu(). For example: | +| | +| CPU 0 CPU 1 | +| ---- ---- | +| WRITE_ONCE(X, 1) WRITE_ONCE(Y, 1) | +| g = get_state_synchronize_rcu() smp_mb() | +| while (!poll_state_synchronize_rcu(g)) r1 = READ_ONCE(X) | +| continue; | +| r0 = READ_ONCE(Y) | +| | +| RCU guarantees that that the outcome r0 == 0 && r1 == 0 will not | +| happen, even if CPU 1 is in an RCU extended quiescent state (idle | +| or offline) and thus won't interact directly with the RCU core | +| processing at all. | ++-----------------------------------------------------------------------+ + This approach must be extended to include idle CPUs, which need RCU's grace-period memory ordering guarantee to extend to any RCU read-side critical sections preceding and following the current