Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4262437imm; Mon, 8 Oct 2018 18:34:26 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Es9mQUnuG48vOBfeZXyzCVIVydJiVm3WQGESot7/jtHR1lDcVAoPqC/bd1duYOYKzYelE X-Received: by 2002:a62:c502:: with SMTP id j2-v6mr28484157pfg.194.1539048866205; Mon, 08 Oct 2018 18:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539048866; cv=none; d=google.com; s=arc-20160816; b=SVSKEtOsN3Jq3x78vr7VuKymWbsCThYhNntjwA64SORC+gQmWkURBU3bGJiu20LDOm xMym1LlvMoDzqCL6rMQ+pCWw3zM75KtGuIJQjtaDyeJWat5tSFKrIV5c2KgVgUJEVjgV gtmFicQsHef31P7uuJByRdtpVQNin0LTUHvqzdE6X1XnnxMk/rcrojUznp/2ApcRosY4 4ER3xopCxa4CmAehjje9T+18Wz5GJPf2H8ZvuuGbXAasZ6kkn4ylmQlD2ttfRBLviKO7 e3wIJGeWogTNI1TJ1SXtIk7Qbt7lSUHgNLVoRfENO7J0cq3vQzWaWk71v7sTfmYkhoMQ r4lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=DEmAFEukNjBuJ2mkXEf/xrv4vdpDOGkWYaADMVgzl8o=; b=R7Jt97DcJZz/1GcW94PDFGcjS/ueKDsYtGt5rTluF5iIopCuKwwWNy61pgBQws+TPU Da6fC0kJG+PQoqgzhtBuGHuLwBdgEQj+nw1Fq63hiaKjjfLBvMoCtSeRulIuZNtw9ts1 Idyb/doVX5Fy12nmzcRh8c4EKsOVj0oRaDBWnXD8xOTh2Be84tI/RZTs4qR/F82z5juG noD5t73K14cvPwmWiPyP8OB2y4rH0MmgOlreRoYcv2Y/cUsZ6PKQp2bH3XhKDKbrYn9W DRij/dKI6LuN/Jl5Sd5Z5F9IYVAxTC6476Xe2DDNV3f+spo4ZCYCS1rMelihcz17xRqU u73w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=kchSpnXZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z11-v6si19094029pgf.66.2018.10.08.18.34.11; Mon, 08 Oct 2018 18:34:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=kchSpnXZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726510AbeJIIsS (ORCPT + 99 others); Tue, 9 Oct 2018 04:48:18 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:45345 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbeJIIsR (ORCPT ); Tue, 9 Oct 2018 04:48:17 -0400 Received: by mail-pl1-f195.google.com with SMTP id y15-v6so10834076plr.12 for ; Mon, 08 Oct 2018 18:33:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DEmAFEukNjBuJ2mkXEf/xrv4vdpDOGkWYaADMVgzl8o=; b=kchSpnXZP3Wuzx/fKM6kMuQqfdullDuzAgNA8URCbPncOYLNZlBJQ6WY2Rjfq0KODj njJmdhnaH2VwhPQ+gD/ZMiOo8i83+uaOHUTSrs/zprp9mM4sYw+kEtSuDlv8lvmUmyzb y+EU4a2d6342gcsKGFr51EbnsFnwnNb07YIqs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DEmAFEukNjBuJ2mkXEf/xrv4vdpDOGkWYaADMVgzl8o=; b=XkBz9IepGxWSYCLf7AdfK4zIkPwcTamisz3PSmTZLyug36fbMZ/59qxgCPKQcjnda0 N5q+sUhauiZ63pAIFuZohBDMADJbgg05u6mSrsM2+FuMPAxaic0YWieOKGsAUC636xmH /i843LJpFekLx2OBknF4tdVJS4MOXqZ7yAq/6X2l39bMkr+U4w11ntRet90NdYnJ6plc Sewa2Kd0dJVxFzTjvNHFUh6dfv6O18trN3kNP5oPW2GI4q/slq3LqS7P6KNgVF5DgPZO IAGLayJbMBCbVtH2wUwBPRZPITkaRAvP049KCcwzC0KLHKlYtDMMCi2mQMCPnd+M0rSH UvdQ== X-Gm-Message-State: ABuFfohLIxcZWmIIvP5ZGwJ2bqapCYr+iL99veABQBGZXbQJJrEe7+Ev shmhF5SUgW4vx60fxOEoIf4xrJvc1MM= X-Received: by 2002:a17:902:a989:: with SMTP id bh9-v6mr25644758plb.245.1539048828983; Mon, 08 Oct 2018 18:33:48 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id h5-v6sm24153803pfo.135.2018.10.08.18.33.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 18:33:47 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , tytso@mit.edu, Jonathan Corbet , Josh Triplett , Lai Jiangshan , linux-doc@vger.kernel.org, Mathieu Desnoyers , "Paul E. McKenney" , Steven Rostedt Subject: [PATCH] docs: rcu: Make reader aware of rcu_dereference_protected Date: Mon, 8 Oct 2018 18:33:41 -0700 Message-Id: <20181009013341.60111-1-joel@joelfernandes.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org whatisRCU says rcu_dereference cannot be used outside of rcu read lock protected sections. Its better to mention rcu_dereference_protected when it says that, so that the new reader is aware of this API and is not led to believing that all RCU dereferences in all situations have to be protected by a rcu_read_lock() and rcu_read_unlock(). Cc: tytso@mit.edu Suggested-by: tytso@mit.edu Signed-off-by: Joel Fernandes (Google) --- Documentation/RCU/whatisRCU.txt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt index 7c33445fd0e5..da820fc9b307 100644 --- a/Documentation/RCU/whatisRCU.txt +++ b/Documentation/RCU/whatisRCU.txt @@ -266,7 +266,7 @@ rcu_dereference() unnecessary overhead on Alpha CPUs. Note that the value returned by rcu_dereference() is valid - only within the enclosing RCU read-side critical section. + only within the enclosing RCU read-side critical section [1]. For example, the following is -not- legal: rcu_read_lock(); @@ -292,6 +292,24 @@ rcu_dereference() typically used indirectly, via the _rcu list-manipulation primitives, such as list_for_each_entry_rcu(). + [1] The variant rcu_dereference_protected() can be used outside + of an RCU read-side critical section as long as the usage is + protected by update-side locks. These update-side locks are + obviously acquired by the update-side code, but may also be used + to protect other code sequences outside of the reader and the + updater. If such sequences need to make an rcu_dereference() call, + they can instead simply call rcu_dereference_protected() without + needing extra calls to rcu_read_lock() and rcu_read_unlock(). + Another advantage of using rcu_dereference_protected() is it does + not prevent compiler optimizations unlike rcu_dereference() which + could result in optimized and the result is assured to be + functionaly correct due to the update-side locks. + rcu_dereference_protected() takes a lockdep expression to + indicate what is providing the protection. If the indicated + protection is not provided, a lockdep splat is emitted. + See RCU/Design/Requirements.html and the API's code comments + for more details and example usage. + The following diagram shows how each API communicates among the reader, updater, and reclaimer. -- 2.19.0.605.g01d371f741-goog