Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp626020pxj; Thu, 10 Jun 2021 08:51:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxd4rzkvYL57Q0DeApJrWKftFkKjml8sA739Iz3VQ/9oU58kBOAigZ16wIWiRBulkfVbcs3 X-Received: by 2002:a05:6402:543:: with SMTP id i3mr88278edx.173.1623340316094; Thu, 10 Jun 2021 08:51:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623340316; cv=none; d=google.com; s=arc-20160816; b=WE59pHiMB6xHA8gh992zRQdkFfVuLDKuLCY+dbKQQQ4VaZC8TlIUp08ud9queYk9O3 szdNv/gngfGByv9KopV1AuaJkr+PMnYWZlOlkCegz/xYeNtNC7quHpNfB6ce6KyvDfFs /+A5JTZspgAkwHPFQMunC6lMNOSFKT51cn80TVTwj++Rs2Yl7MuCJBXurKstiBz1qrVG 2HCQpgT/tDlamEfT8B4cjmTiYVjw1sEdrbVf+NkDdtfyzcNSFL3NSfx3O7B7E/RIAkGa d0y8iuuoRrgx57q52G83j3UaropLSjVnyWIZ8jKqL3N4UFwnYRu3BfMowruukwDTrrR2 bftw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=VJnzDF4WM1UBhIhfuxMe5C8ynggWleh/QPBdo/7H4fg=; b=K0YNNmf4CxVQT09tcgCJrl8K9qyxCY2ySK4uS37QSG1tbuNVEASelEPG2idhUSUD7A vAd17YOD+hVWGN6Z9x6RaO4GoSJN6vphd6VsKwE8gnzaZkFgY19nZzwQSV/wBcWyNa3/ nzX0eP2HojayI1TJk2Dx1nDPdAJbfpwELnAfIwz3krzB1ELNeQmx9dGNjb3jL0rhMERF eKmKfQKUCtbicXY2wgSVYkJMCJ0Z8ZSU0Da+g8VL+LyMmmaP9CO9C+xL0RPL7H3wfYjo qIbcoGeyP7vDL2iOpIjTgR0BQo92JY5qkI/rGOeCoWX0aBZZEiIUK523JafdgIt8gKV3 MMzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DJmfsIgK; 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 eb8si2970933edb.249.2021.06.10.08.51.32; Thu, 10 Jun 2021 08:51:56 -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=DJmfsIgK; 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 S231542AbhFJPwe (ORCPT + 99 others); Thu, 10 Jun 2021 11:52:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:41446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230298AbhFJPwd (ORCPT ); Thu, 10 Jun 2021 11:52:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2AFEE61376; Thu, 10 Jun 2021 15:50:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623340236; bh=DgGdJqIKAoxqN2PVGkeutE+hR+bSiyT05Kgawa3NJ3s=; h=From:To:Cc:Subject:Date:From; b=DJmfsIgK2+/zvxTMjgyEcAPdy1I9VG1rfkQGi1jgXY0oUSPFkveYvwOqYW9BpJY0c b4ZK4nzCYIt7iI+aNERT6228mI7tI1XNZ1DyE1fdnB1G1HBPc6RVqOxppEENlNlMyd v5IrgxLYfzKCElf1fT0tnSvBwXeecaGAYg71+rQ9MgeEUaFULNJheA2IwbXFBYJA+c ULzSigdku/mAVF0ve6brfD154PrZk+dXbUMOGVpAjJmykQVm1A36nXEy6KwveoMXY7 mYbZTnf/onOeSLUI1BQjA8nF1eQfagKgnVgd6NfmujmDIBqgW9tjpq/rOAicCbm4QG YTMTMJLVqsx8A== From: Frederic Weisbecker To: "Paul E . McKenney" Cc: LKML , Frederic Weisbecker , Neeraj Upadhyay , Boqun Feng , Uladzislau Rezki , Joel Fernandes Subject: [PATCH] rcu/doc: Add a quick quiz to explain further why we need smp_mb__after_unlock_lock() Date: Thu, 10 Jun 2021 17:50:29 +0200 Message-Id: <20210610155029.130812-1-frederic@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- .../Tree-RCU-Memory-Ordering.rst | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) 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..f21432115627 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,39 @@ on PowerPC. The ``smp_mb__after_unlock_lock()`` invocations prevent this ``WARN_ON()`` from triggering. ++-----------------------------------------------------------------------+ +| **Quick Quiz**: | ++-----------------------------------------------------------------------+ +| But the whole chain of rnp locking is enough for the readers to see | +| all the pre-grace-period accesses from the updater and for the updater| +| to see all the accesses from the readers performed before the end of | +| the grace period. So why do we need to enforce full ordering at all | +| through smp_mb__after_unlock_lock()? | ++-----------------------------------------------------------------------+ +| **Answer**: | ++-----------------------------------------------------------------------+ +| Because we still need to take care of the lockless counterparts of | +| RCU. The first key example here is grace period polling. Using | +| poll_state_synchronize_rcu() or cond_synchronize_rcu(), an updater | +| can rely solely on lockess full ordering to benefit from the usual | +| TREE RCU ordering guarantees. | +| | +| The second example lays behind the fact that a grace period still | +| claims to imply full memory ordering. Therefore in the following | +| scenario: | +| | +| CPU 0 CPU 1 | +| ---- ---- | +| WRITE_ONCE(X, 1) WRITE_ONCE(Y, 1) | +| synchronize_rcu() smp_mb() | +| r0 = READ_ONCE(Y) r1 = READ_ONCE(X) | +| | +| It must be impossible to have r0 == 0 && r1 == 0 after both CPUs | +| have completed their sequences, even if CPU 1 is in an RCU extended | +| quiescent state (idle mode) and thus won't report a quiescent state | +| throughout the common rnp locking chain. | ++-----------------------------------------------------------------------+ + 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 -- 2.25.1