Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1117878ybi; Fri, 12 Jul 2019 10:02:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwirsUxb2vMFwOMn9vaXE5bOCqERu4SrxAziubobqLMPnM5A0F2vocO1UUkPvsCOaOPhI8H X-Received: by 2002:a63:1847:: with SMTP id 7mr12296338pgy.204.1562950928847; Fri, 12 Jul 2019 10:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562950928; cv=none; d=google.com; s=arc-20160816; b=QwSS+ZHrLTB9ze819HDvDCkRrs5f6koEJI7Iq80xQYDme0pLvT3437JieOStI/8PaP TBC7HdaX/EdSnK1iPnFwUtrC9C0bZgzdk5UaS54iwwEXnEssXCAvwGkLckHyiS5cUucn gnIX5j5A/pmkZNJxrrX0P5j3BMJwPcamoNxL3zmiF4Kdb6U6SursF98QiAChuYAbnoYk SVp5KooRGAWQh/QoXV6MX4mQWMxBILN/vOX3WOQiEOdjYpbFR4/murk2WqEvmCJCfrV5 /PsyzbeKV8PNLdE4f/bV94IFYpPPOJ4gmxXtkgYItRekYLFkWjaVXRxBDZ7E9ceYnBE7 LlGw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/5hJQY7vBLoyimOM3U70MNxFgsc86oXhHYtdVzU5ujQ=; b=nigRrmDy3oK5dKTlsFUHD3SA3pCKTP5a8aPAew2e9X2a2XacWB4oyLh0iaS6Bim/92 jqsHXXXt5kA1AbewV9/2NSsIj+vDFSpPHhoHYHq9xCG3DF786AZB0madSdkgwc9VNpf5 JIIsXXPBanqZafnLdW9aeeEr5DWdFo8JSvw4M2iEOjaY1Op0/ryRao8tpohvNgAvkA4h 8o4XAkhfyjHNW1i6Ls+I3h8siAzRwkapxOIgi7gI5RreZot+Ytu0mof4rMXw3teFo30L OznLvq/bFpScNQERAwHdUpd506y7O6FJV2H2a+8J6HYV5xEiHQAMhjHF0UG77AMqAFMh xx4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=UAjbMqka; 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 l64si8567894pjb.93.2019.07.12.10.01.52; Fri, 12 Jul 2019 10:02:08 -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=UAjbMqka; 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 S1727645AbfGLRBP (ORCPT + 99 others); Fri, 12 Jul 2019 13:01:15 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:44089 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727654AbfGLRBN (ORCPT ); Fri, 12 Jul 2019 13:01:13 -0400 Received: by mail-pg1-f194.google.com with SMTP id i18so4783624pgl.11 for ; Fri, 12 Jul 2019 10:01:12 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=/5hJQY7vBLoyimOM3U70MNxFgsc86oXhHYtdVzU5ujQ=; b=UAjbMqka7p1GCxFlNusyg29g1RCPFz9WIMtWvkN7qrcNF+ATnO9YKmLvPnuqPRJWG8 01CXWPFPyGYm3lOSoebpREdMbvmnc55dMqjKROvd/t5QxrZ6o7iZwPGUGOYk4Ll55hdr IVAnsP7Rq6Ff+RAPzreODHBCQNzqAghR4nuBM= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=/5hJQY7vBLoyimOM3U70MNxFgsc86oXhHYtdVzU5ujQ=; b=G7iack0dedj0nsPTM2lMHWx6niCtANxyxgpnESvDyMfvHNDBFlprhnCn2027ORE0uW WlUGwupEoWyTbUtZKGjkJDAgl0tAVk/Sp7id2LsbAdtJV3tpctrJCue1+0h41ADEPj/U Lmf1U392UUk8shmr7fv2u3X51EjmT/hrWiRKjSrTUb/GW6kL1vRXdSQPUTdO2VI/G3y0 mB6m8wit80sGcZtigyty6TGQeBQNTJpviJJSx1c6LvkC33iZTkvwR6IIA1oyGq6vT7yD IXLT/h7rlxdJqEVhHfbGWWKiV+1ocS3pROByyXqfiIr3zK4AYsENBJlN5UN43omeQcmH bw/A== X-Gm-Message-State: APjAAAVRqfn9WaUkZyTPwRAHZYxJ//X5lxhbWLkXaGbL5+6DtKLrlOVJ wlnTsT745adoUkDdzFvLkObHJRvL X-Received: by 2002:a63:dc56:: with SMTP id f22mr12036675pgj.305.1562950871565; Fri, 12 Jul 2019 10:01:11 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id a15sm7127385pgw.3.2019.07.12.10.01.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 12 Jul 2019 10:01:10 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , Alexey Kuznetsov , Bjorn Helgaas , Borislav Petkov , c0d1n61at3@gmail.com, "David S. Miller" , edumazet@google.com, Greg Kroah-Hartman , Hideaki YOSHIFUJI , "H. Peter Anvin" , Ingo Molnar , Jonathan Corbet , Josh Triplett , keescook@chromium.org, kernel-hardening@lists.openwall.com, kernel-team@android.com, Lai Jiangshan , Len Brown , linux-acpi@vger.kernel.org, linux-doc@vger.kernel.org, linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, Mathieu Desnoyers , neilb@suse.com, netdev@vger.kernel.org, Oleg Nesterov , "Paul E. McKenney" , Pavel Machek , peterz@infradead.org, "Rafael J. Wysocki" , Rasmus Villemoes , rcu@vger.kernel.org, Steven Rostedt , Tejun Heo , Thomas Gleixner , will@kernel.org, x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH v2 9/9] doc: Update documentation about list_for_each_entry_rcu Date: Fri, 12 Jul 2019 13:00:24 -0400 Message-Id: <20190712170024.111093-10-joel@joelfernandes.org> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog In-Reply-To: <20190712170024.111093-1-joel@joelfernandes.org> References: <20190712170024.111093-1-joel@joelfernandes.org> 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 This patch updates the documentation with information about usage of lockdep with list_for_each_entry_rcu(). Signed-off-by: Joel Fernandes (Google) --- Documentation/RCU/lockdep.txt | 15 +++++++++++---- Documentation/RCU/whatisRCU.txt | 9 ++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Documentation/RCU/lockdep.txt b/Documentation/RCU/lockdep.txt index da51d3068850..3d967df3a801 100644 --- a/Documentation/RCU/lockdep.txt +++ b/Documentation/RCU/lockdep.txt @@ -96,7 +96,14 @@ other flavors of rcu_dereference(). On the other hand, it is illegal to use rcu_dereference_protected() if either the RCU-protected pointer or the RCU-protected data that it points to can change concurrently. -There are currently only "universal" versions of the rcu_assign_pointer() -and RCU list-/tree-traversal primitives, which do not (yet) check for -being in an RCU read-side critical section. In the future, separate -versions of these primitives might be created. +Similar to rcu_dereference_protected, The RCU list and hlist traversal +primitives also check for whether there are called from within a reader +section. However, an optional lockdep expression can be passed to them as +the last argument in case they are called under other non-RCU protection. + +For example, the workqueue for_each_pwq() macro is implemented as follows. +It is safe to call for_each_pwq() outside a reader section but under protection +of wq->mutex: +#define for_each_pwq(pwq, wq) + list_for_each_entry_rcu((pwq), &(wq)->pwqs, pwqs_node, + lock_is_held(&(wq->mutex).dep_map)) diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt index 981651a8b65d..a08c03735963 100644 --- a/Documentation/RCU/whatisRCU.txt +++ b/Documentation/RCU/whatisRCU.txt @@ -290,7 +290,7 @@ rcu_dereference() at any time, including immediately after the rcu_dereference(). And, again like rcu_assign_pointer(), rcu_dereference() is typically used indirectly, via the _rcu list-manipulation - primitives, such as list_for_each_entry_rcu(). + primitives, such as list_for_each_entry_rcu() [2]. [1] The variant rcu_dereference_protected() can be used outside of an RCU read-side critical section as long as the usage is @@ -305,6 +305,13 @@ rcu_dereference() a lockdep splat is emitted. See RCU/Design/Requirements/Requirements.html and the API's code comments for more details and example usage. + [2] In case the list_for_each_entry_rcu() primitive is intended + to be used outside of an RCU reader section such as when + protected by a lock, then an additional lockdep expression can be + passed as the last argument to it so that RCU lockdep checking code + knows that the dereference of the list pointers are safe. If the + indicated protection is not provided, a lockdep splat is emitted. + The following diagram shows how each API communicates among the reader, updater, and reclaimer. -- 2.22.0.510.g264f2c817a-goog