Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4539424ybi; Mon, 3 Jun 2019 12:44:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKb7+w1t/nVPSBAuvJsvQt2QuQRhTc2kFmhhUnhk66xFeo0buPxdv9tM8jGERjAJQEL7nI X-Received: by 2002:a17:902:e48d:: with SMTP id cj13mr32498540plb.156.1559591078853; Mon, 03 Jun 2019 12:44:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559591078; cv=none; d=google.com; s=arc-20160816; b=eW8xgoPZwiIpbKhEGXybknj+E0QjDa6ly4UTulKm1QJPzjQYKjc4pKSTQ7NsW3RUcD e96y1rdkDEd6x+2y1IdIFHpS2ygHNiguOcC4j9R2rUqQHtrbnNWllwh4/a7801Z1NnkO Ig7FUwiIkZGt/U13WgTIPItc+WZ1QKhWHDkr1HGT0FIOqFUUO8lfxpUQZ/wjci70wIE4 kL28kYP3T9Mn5vordBYkTXJSbaaD1epekoe+M0S3DkOC9CQFMOR8cYa/O4FxJwGVGvpb OG0ZoUg1qqlBjJFcU+sJBJkjfacC7dpoxaaIbhfG5cc+6dZZgFVQF8nTuKYr/+WFnvvY dKcA== 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=a+lhr9Q+24Qfza3c4uXpEdm8TyEjYoUavdn6rBgETA0=; b=qbzYXdgfdJjc9pds67sj0lp7mCB3Z6f8iaVtROUG7X8+QralXzHIgIBDmsld6VwXkM PelbjBP2BLRfI+H1nF5ZAiXVTaMevTnwkcWcQh+FqtjmZokoPyjbKzI71/Xg1icRCdJR lrmH7dUVPvJrFZYgrn3l0kfvN1fJ2e3pgfu/AphdfwLIrECmjHRU9DonfuNS0/dRx7dQ CoTcH4t+PkIgpTbf2M2phDvY+Wye/FEQPAezRd14nHrLLd+NlyJBRFxje3DH5JwVVwOW U0n9FMwA8yXd28JWKtQbEX4d+R0y0/bKV+oLFSquzcvcVGP+hXoO3qw+wltuG3Vvbo33 gNTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=v57zkduk; 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 cj11si13830248plb.373.2019.06.03.12.44.22; Mon, 03 Jun 2019 12:44:38 -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=v57zkduk; 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 S1726660AbfFCTmP (ORCPT + 99 others); Mon, 3 Jun 2019 15:42:15 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:34721 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726223AbfFCTmO (ORCPT ); Mon, 3 Jun 2019 15:42:14 -0400 Received: by mail-pf1-f193.google.com with SMTP id c85so2403677pfc.1 for ; Mon, 03 Jun 2019 12:42:14 -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=a+lhr9Q+24Qfza3c4uXpEdm8TyEjYoUavdn6rBgETA0=; b=v57zkdukOzYOvhfiKNqk2b/GOjkFP1SHWP5I5eo7SiatQZoyLWIBR+84HSu7EA2L8f /Txa/lSthx5I4+d0+ItNuTqwsJewXfi+56sABsg3JwRHrqq33I7sTzcN+0Twcbb6KpI7 +Pr2kvxYQLWF4bCfr03Db/6neBgFbrX8K2sXo= 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=a+lhr9Q+24Qfza3c4uXpEdm8TyEjYoUavdn6rBgETA0=; b=McVEfGnPY2OLRxpnKpeoLKlpyn93Znfx2Pwj0xzNGh4a9ESGUD8Qm7TVmmV4AZcuBL h7JO9vTAjGSZecOaKinxyYRp4Q0GR3JeR+FTzKnQC9h42BqDu5xqRZ48/HQiZf1QjA68 xnHc1G8q5X2zf3uDhfOprKF/y1W92B6KjmqCnM5EM7Hbt6ceC67eF/FGhs0eNxd56XSP jY2sRw3UAN3r/neYSkrfTCPMvZH1VjlR3zoXSVl+vvdziYUels4FQw/nvFLWh9z9JO0u 9WjMMosbJw340SiPS9GgW6uESWRfpHE5ozgwC3bavk2TA1tcIPm1801Upm0EdiuOyEGN 8F6g== X-Gm-Message-State: APjAAAVMa/RFwFG2pgGY/XsfcZhfcmH1ekCPvCRHPgiGouQOc4D5LXrM apiL9LHm/dXIP846+4YNp3VMbQ== X-Received: by 2002:a63:e10d:: with SMTP id z13mr9626011pgh.116.1559590933600; Mon, 03 Jun 2019 12:42:13 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id o2sm13442018pgm.51.2019.06.03.12.42.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jun 2019 12:42:12 -0700 (PDT) Date: Mon, 3 Jun 2019 15:42:11 -0400 From: Joel Fernandes To: Peter Zijlstra 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 , "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: <20190603194211.GA228607@google.com> References: <20190601222738.6856-1-joel@joelfernandes.org> <20190601222738.6856-2-joel@joelfernandes.org> <20190603080128.GA3436@hirez.programming.kicks-ass.net> <20190603141847.GA94186@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190603141847.GA94186@google.com> 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 Mon, Jun 03, 2019 at 10:18:47AM -0400, Joel Fernandes wrote: > On Mon, Jun 03, 2019 at 10:01:28AM +0200, Peter Zijlstra wrote: > > On Sat, Jun 01, 2019 at 06:27:33PM -0400, Joel Fernandes (Google) wrote: > > > +#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)) > > > > > > /** > > > @@ -621,7 +648,12 @@ static inline void hlist_add_behind_rcu(struct hlist_node *n, > > > * the _rcu list-mutation primitives such as hlist_add_head_rcu() > > > * as long as the traversal is guarded by rcu_read_lock(). > > > */ > > > +#define hlist_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 = hlist_entry_safe (rcu_dereference_raw(hlist_first_rcu(head)),\ > > > typeof(*(pos)), member); \ > > > pos; \ > > > > > > This breaks code like: > > > > if (...) > > list_for_each_entry_rcu(...); > > > > as they are no longer a single statement. You'll have to frob it into > > the initializer part of the for statement. > > Thanks a lot for that. I fixed it as below (diff is on top of the patch): > > If not for that '##' , I could have abstracted the whole if/else > expression into its own macro and called it from list_for_each_entry_rcu() to > keep it more clean. Actually was able to roll the if/else into its own macro as well, thus keeping it clean. thanks! ---8<----------------------- diff --git a/include/linux/rculist.h b/include/linux/rculist.h index b641fdd9f1a2..cc9c382b080c 100644 --- a/include/linux/rculist.h +++ b/include/linux/rculist.h @@ -43,7 +43,11 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list) /* * Check during list traversal that we are within an RCU reader */ -#define __list_check_rcu() \ + +#define SIXTH_ARG(a1, a2, a3, a4, a5, a6, ...) a6 +#define COUNT_VARGS(...) SIXTH_ARG(dummy, ## __VA_ARGS__, 4, 3, 2, 1, 0) + +#define __list_check_rcu_nocond() \ RCU_LOCKDEP_WARN(!rcu_read_lock_any_held(), \ "RCU-list traversed in non-reader section!") @@ -59,6 +63,16 @@ static inline void __list_check_rcu_cond(int dummy, ...) RCU_LOCKDEP_WARN(!cond && !rcu_read_lock_any_held(), "RCU-list traversed in non-reader section!"); } + +#define __list_check_rcu(cond...) \ + ({ \ + if (COUNT_VARGS(cond) != 0) { \ + __list_check_rcu_cond(0, ## cond); \ + } else { \ + __list_check_rcu_nocond(); \ + } \ + }) + /* * Insert a new entry between two known consecutive entries. * @@ -357,9 +371,6 @@ 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. @@ -371,12 +382,8 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, * as long as the traversal is guarded by rcu_read_lock(). */ #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); \ + for (__list_check_rcu(cond), \ + pos = list_entry_rcu((head)->next, typeof(*pos), member); \ &pos->member != (head); \ pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) @@ -649,12 +656,8 @@ static inline void hlist_add_behind_rcu(struct hlist_node *n, * as long as the traversal is guarded by rcu_read_lock(). */ #define hlist_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 = hlist_entry_safe (rcu_dereference_raw(hlist_first_rcu(head)),\ + for (__list_check_rcu(cond), \ + pos = hlist_entry_safe (rcu_dereference_raw(hlist_first_rcu(head)),\ typeof(*(pos)), member); \ pos; \ pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(\ -- 2.22.0.rc1.311.g5d7573a151-goog