Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6015074ybi; Tue, 4 Jun 2019 16:59:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTZRtyYI5txoM/MMUEh0eDQ7pgXU9wtlXqISkxBuhfp91+rTOQMRiIe0CGr/lceaUJ7e9i X-Received: by 2002:a63:f410:: with SMTP id g16mr466504pgi.428.1559692742347; Tue, 04 Jun 2019 16:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559692742; cv=none; d=google.com; s=arc-20160816; b=B8eHBjohIn2k0irDCEMyXXzVhjuz15nNfgYHYbeE8sUGS+XBPBWrC1LKEqMzx8FMZ8 xhmZrjPzlxNLnPCeO5E28NYzG2llEZemDDr3T+y6D+w5tsdSrpTZUko/BKM/7DQ8RqH8 5Kf/fKV6upnhlr3kmqgsvcoXMH0XsatJC5wpT+RkTr1jb4TjLJ1cd3IdWVvB5yPAoIXO RVTCYuFK1A0bBMRZcah2zI5Iw2ES5QVf/EG3Pq02xhbv9gU+iP2Xr0tLvoWp8tHQ2Qws Y28BN2HZMfK2PG4hlU+aqQgj+bU4L6QAPVFKM01lrpnXiMHGkclnasluxkjzyoPeUObP 49jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=1RoeYwTbHJ5uZrqzOkCL/eOap3xEJq8UUohxtmtls+0=; b=05KUcyagEApT1zcBI3PWuDKsmKgTMaMWKszeKVIZW/r3Fwr4BC8+9m16OwYK6fhVo4 Ye65r2FdiPBdoNRcUmCvd1RMXwNauNCPW1czNlR0LQpLpSYLDxwRf89+jLfmBUuNM80w NnAR5aih4+sht3PNjPSLvEe9Y8/BSW7GIrM/HAMixnWAT5hMk6TeUl95YOsC7+Tc0DQz lvNbyOkWVQkOl5+pjgWAGI1wOLpJQMgF5CC/LjNCALYkAYQaOyQQ8OuOA0k2QcAGhzSG ncsoS7eYCanubepdAasM46Qbpt/tU8iW0woUTLQN+eDLU/VnHTRewUOkSTr/E6AQZsLv 4Qvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b="Zj/4RsKS"; 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 m2si23489182pjk.63.2019.06.04.16.58.44; Tue, 04 Jun 2019 16:59:02 -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="Zj/4RsKS"; 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 S1726725AbfFDX5j (ORCPT + 99 others); Tue, 4 Jun 2019 19:57:39 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:46292 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726605AbfFDX5i (ORCPT ); Tue, 4 Jun 2019 19:57:38 -0400 Received: by mail-pf1-f196.google.com with SMTP id y11so13658309pfm.13 for ; Tue, 04 Jun 2019 16:57:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=1RoeYwTbHJ5uZrqzOkCL/eOap3xEJq8UUohxtmtls+0=; b=Zj/4RsKSPEX80sxrowiW9yJRYHKyPgNTX80646pPhD24cF78L+/cbq0AbaGX9N2dlW NbcaJdsi+uqQaXkEEuBCyBbDTXEvFRlnvVcH9GuGiMzwzkWU5HOPuyPDk8tLI4VkyyJv /DfRIx8bv02qOCZ6ndDiCIPf3hcKSC8m4VzgQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=1RoeYwTbHJ5uZrqzOkCL/eOap3xEJq8UUohxtmtls+0=; b=pWwuFi3k2lVH+uqysRUOC8r35O/nTpSJb1hx9yw70RTErHjlmvD4bffGkM6MQ0h9j/ hOhMqF4enbbMm/9oJpEP0h4jJK1mW97TWlZH5OZuD+WY6fgH+BSUeN/yveZ9S5UcX4he RYznrhZfDNHjNtEZXQ+Wraue+mQI+k8kjoJQdF1MvItLzF7FNMGq3z9v7/WRAMhpUjHI LBQMK+LiGEFpk0RZLUeOFE9K9YDjRYyZzGGHy51PEpYcdqIGwgCKMsfTJvXtKBJ96igt TEp382YneaCa5x4bYmI4a9VpcTE3k2P4dpq2ekfnLFFpl6jW22yPK6gBKqwTg4lhOgjj oR6Q== X-Gm-Message-State: APjAAAXHWiLWibbqfy/n7a8nltpVhz/xRZtJMLLRZsX9jK8veObba+VN FegL7N43unvVmFa5ClsApI18cg== X-Received: by 2002:a17:90a:a790:: with SMTP id f16mr40544193pjq.27.1559692657614; Tue, 04 Jun 2019 16:57:37 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id q13sm34687078pjc.1.2019.06.04.16.57.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jun 2019 16:57:36 -0700 (PDT) Date: Tue, 4 Jun 2019 19:57:35 -0400 From: Joel Fernandes To: Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, Alexey Kuznetsov , Bjorn Helgaas , Borislav Petkov , "David S. Miller" , edumazet@google.com, Greg Kroah-Hartman , Hideaki YOSHIFUJI , "H. Peter Anvin" , Ingo Molnar , Josh Triplett , keescook@chromium.org, kernel-hardening@lists.openwall.com, Lai Jiangshan , Len Brown , linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, Mathieu Desnoyers , neilb@suse.com, netdev@vger.kernel.org, oleg@redhat.com, "Paul E. McKenney" , Pavel Machek , peterz@infradead.org, "Rafael J. Wysocki" , rcu@vger.kernel.org, Steven Rostedt , Tejun Heo , Thomas Gleixner , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Subject: Re: [RFC 1/6] rcu: Add support for consolidated-RCU reader checking Message-ID: <20190604235735.GA254287@google.com> References: <20190601222738.6856-1-joel@joelfernandes.org> <20190601222738.6856-2-joel@joelfernandes.org> <0ff9e0e3-b9fb-8953-1f76-807102f785ee@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0ff9e0e3-b9fb-8953-1f76-807102f785ee@rasmusvillemoes.dk> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 04, 2019 at 04:01:00PM +0200, Rasmus Villemoes wrote: > On 02/06/2019 00.27, Joel Fernandes (Google) wrote: > > This patch adds support for checking RCU reader sections in list > > traversal macros. Optionally, if the list macro is called under SRCU or > > other lock/mutex protection, then appropriate lockdep expressions can be > > passed to make the checks pass. > > > > Existing list_for_each_entry_rcu() invocations don't need to pass the > > optional fourth argument (cond) unless they are under some non-RCU > > protection and needs to make lockdep check pass. > > > > Signed-off-by: Joel Fernandes (Google) > > --- > > include/linux/rculist.h | 40 ++++++++++++++++++++++++++++++++++++---- > > include/linux/rcupdate.h | 7 +++++++ > > kernel/rcu/update.c | 26 ++++++++++++++++++++++++++ > > 3 files changed, 69 insertions(+), 4 deletions(-) > > > > diff --git a/include/linux/rculist.h b/include/linux/rculist.h > > index e91ec9ddcd30..b641fdd9f1a2 100644 > > --- a/include/linux/rculist.h > > +++ b/include/linux/rculist.h > > @@ -40,6 +40,25 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list) > > */ > > #define list_next_rcu(list) (*((struct list_head __rcu **)(&(list)->next))) > > > > +/* > > + * Check during list traversal that we are within an RCU reader > > + */ > > +#define __list_check_rcu() \ > > + RCU_LOCKDEP_WARN(!rcu_read_lock_any_held(), \ > > + "RCU-list traversed in non-reader section!") > > + > > +static inline void __list_check_rcu_cond(int dummy, ...) > > +{ > > + va_list ap; > > + int cond; > > + > > + va_start(ap, dummy); > > + cond = va_arg(ap, int); > > + va_end(ap); > > + > > + RCU_LOCKDEP_WARN(!cond && !rcu_read_lock_any_held(), > > + "RCU-list traversed in non-reader section!"); > > +} > > /* > > * Insert a new entry between two known consecutive entries. > > * > > @@ -338,6 +357,9 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, > > member) : NULL; \ > > }) > > > > +#define SIXTH_ARG(a1, a2, a3, a4, a5, a6, ...) a6 > > +#define COUNT_VARGS(...) SIXTH_ARG(dummy, ## __VA_ARGS__, 4, 3, 2, 1, 0) > > +> /** > > * list_for_each_entry_rcu - iterate over rcu list of given type > > * @pos: the type * to use as a loop cursor. > > @@ -348,9 +370,14 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, > > * the _rcu list-mutation primitives such as list_add_rcu() > > * as long as the traversal is guarded by rcu_read_lock(). > > */ > > -#define list_for_each_entry_rcu(pos, head, member) \ > > - for (pos = list_entry_rcu((head)->next, typeof(*pos), member); \ > > - &pos->member != (head); \ > > +#define list_for_each_entry_rcu(pos, head, member, cond...) \ > > + if (COUNT_VARGS(cond) != 0) { \ > > + __list_check_rcu_cond(0, ## cond); \ > > + } else { \ > > + __list_check_rcu(); \ > > + } \ > > + for (pos = list_entry_rcu((head)->next, typeof(*pos), member); \ > > + &pos->member != (head); \ > > pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) > > Wouldn't something as simple as > > #define __list_check_rcu(dummy, cond, ...) \ > RCU_LOCKDEP_WARN(!cond && !rcu_read_lock_any_held(), \ > "RCU-list traversed in non-reader section!"); > > for ( ({ __list_check_rcu(junk, ##cond, 0); }), pos = ... ) > > work just as well (i.e., no need for two list_check_rcu and > list_check_rcu_cond variants)? If there's an optional cond, we use that, > if not, we pick the trailing 0, so !cond disappears and it reduces to > your __list_check_rcu(). Moreover, this ensures the RCU_LOCKDEP_WARN > expansion actually picks up the __LINE__ and __FILE__ where the for loop > is used, and not the __FILE__ and __LINE__ of the static inline function > from the header file. It also makes it a bit more type safe/type generic > (if the cond expression happened to have type long or u64 something > rather odd could happen with the inline vararg function). This is much better. I will do it this way. Thank you! - Joel