Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4352190ybi; Mon, 15 Jul 2019 07:40:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9Mzf58oiGioEH6ti8dvOqEFp7wyuw/sFKZ5yZh0B8+3KXFKZFYCwAm829kx4HN6r1HFLy X-Received: by 2002:a63:31cc:: with SMTP id x195mr16840095pgx.147.1563201659267; Mon, 15 Jul 2019 07:40:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563201659; cv=none; d=google.com; s=arc-20160816; b=mkHpUqZbCSObJdoGxEi8eMtRM65WcQYkT4J5f3hgCorFbExnU719O+NYbt/4FgBLRr OCFv84SMCGkrUP8+FjEcmiHcMfEHES0ZUwT3TAjxkNASeTRNyrVi/Fme30YVC301XKQT NGqi2Mpbel75j6FJy/NC8V2EpVBHwTDN9oE+TbbwufL0ogxc6PUjsuvxZIqhbGzx0n4T eGTqFPa4Du7IALjkWuSqEPVjal/q4jP+OwtxZY88X+jXl9LX37QXE0mKJg0yeKoLh0uI /3TrQQUdDaTjabgaWUeceh45huzRvaOmJYjp8jqWe9uLSeneifqKymmPnLE0OGQ0gHZV XkGw== 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=3/Yc3rMkHMZtDKtPxvXMbpuJtYxFK974gkQSASG7nfg=; b=SyZPI+8NRqrns8WYaclxQhiql7+8XP6NZCeyB7/yG9DgSG0QATZYJO3JKyWaoAvYiP AquGrV0i6KMct4OY9GB5BI4W7be2a1GTTfZq6gTUSy+Bez8CY2Qv7OHKdxGohV3A2cj4 EaQbaVZcg/KsMLhNRW121x0E32/QdFJfle/PBk965tfwna5xz4C4mNQKXjNmNPHJLCVl bWJnzdOQsnHpMT6wYeiEZwkszxFFMqgmtNM/pCHWPLuDyWxgdEVM2izLYz5N2SeEJPdP nPHDFXpxn40wQIUh2pb2gI10Ctd947gi/wuHoHQYzDMuJ6qghRH7eoWTqbb8zpyKFV+/ d5Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Irsk1l+c; 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 f8si17300139pgi.191.2019.07.15.07.40.39; Mon, 15 Jul 2019 07:40:59 -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=Irsk1l+c; 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 S2392137AbfGOOh6 (ORCPT + 99 others); Mon, 15 Jul 2019 10:37:58 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:39295 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391363AbfGOOhw (ORCPT ); Mon, 15 Jul 2019 10:37:52 -0400 Received: by mail-pl1-f193.google.com with SMTP id b7so8397982pls.6 for ; Mon, 15 Jul 2019 07:37:51 -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=3/Yc3rMkHMZtDKtPxvXMbpuJtYxFK974gkQSASG7nfg=; b=Irsk1l+cCvhHrnLDCclN8wIYVEkPEbD9MdUbMAfJ0kSrDpX7chroJyo2YF46UzcBkM XJuVwKS6BKM9ZHR0du6EvejWG8y2q+OPRVvdrOulKML9bNBty7xmC4DwYF/BBFtQPuLu EwiuS9bOEcElBlknIAsc95qH+foz6NeembQns= 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=3/Yc3rMkHMZtDKtPxvXMbpuJtYxFK974gkQSASG7nfg=; b=DIDozj5iMUqFBSVyiEcAlsgEJFMZjBmRqjHlo5adETw0Yjyu3xJ8kN5s69i/Du86Sy dCsTHwSo/TsFgbecotqjuWS10jX0DHtT+5SbUZFDPIxDfU+lnIArQuNGj5OTeNkArT4n pUQaWyaaC+lqOeC2Pcs0R/5SaQoZLKhXJ+Z2hd/lz0LNyqpJ4mfkVC8mqo6X7JXjX4gf 3UVfVsVfFg07y3U7FdGNuXF861ibCsZruKel0YS4saIRK4OMsmf8+HlejVPrdS0+v8jk fsAAMYrv7G55XDkSEBeXO/g3yOQbDzogjUZtRpD/T+TGJC065+m6Rvt47vLBCZoEjbo1 gs1g== X-Gm-Message-State: APjAAAX2BKZo8Zd924YmrhL2jPUkxUoeq0aI9PEj2JLCbSn1ooLDtM0N uGKpJhztuuBcq08C6VVHiS9ARAAd X-Received: by 2002:a17:902:27e6:: with SMTP id i35mr28686773plg.190.1563201470637; Mon, 15 Jul 2019 07:37:50 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id s66sm18381852pfs.8.2019.07.15.07.37.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 15 Jul 2019 07:37:49 -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 9/9] doc: Update documentation about list_for_each_entry_rcu (v1) Date: Mon, 15 Jul 2019 10:37:05 -0400 Message-Id: <20190715143705.117908-10-joel@joelfernandes.org> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog In-Reply-To: <20190715143705.117908-1-joel@joelfernandes.org> References: <20190715143705.117908-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 7e1a8721637a..00fe77ede1e2 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