Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5709242ybi; Tue, 4 Jun 2019 10:49:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxlaNa2TbJAi8YiH5/7iY1u3XaUtTn0U7+jvVSWf5JOr+B2apz1btjy43Xa4BAuH9tPr2Uq X-Received: by 2002:a17:90a:ad83:: with SMTP id s3mr11976493pjq.43.1559670567066; Tue, 04 Jun 2019 10:49:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559670567; cv=none; d=google.com; s=arc-20160816; b=s1ITmFY3H89wCMT14j9jZVFPU/MJqlCyFehAEiWrPCH/7y6iFm2HAbhVyNkqt28gpV APJe62cR41XdCE4Iandnt76CaCht8kGdtOcF3XSKPg9U6nNLnlQvIVY0wQAAzGiULZQ5 pZGsqA0WuQQ9PKCkjMfg2Hi7RFObwAObw4EHSjrWsBn6As1KsMOJ4lE34Sw5CRfvGam9 3GbJXl8aDbFsF4GqNpq9NPLG4CvfpT1RP7DTnk3uZpaQQAJJfQjM0wLgI7AXP6JQr/tg GZKYCN5JUgkZn0YLMktqFN5cQs9m1JtNgW+Jm3sJOkmqyQ3QiGpUhX50oeQQLM86Yvoz Ayeg== 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=WO/pU2tXKcWaOz/Mz8XljUSgZVyxjPQIhAnHQSTWhKk=; b=a3V2iQfHyvAxKKZ0ofsjnuvm+o81ZEwlQtAGuFxCrgCfUQNjhRa6PUEmEnpdozKUTE DymISZTYZ3YX6tf9daf86pc+e96cKkwn55QZ8IHoeDVETvU4+6Ml1oyQri3JlpFMWPTg aZU6thJfs108J7ivxq10SVT6sWuhQslTAgF06b8bu/rVXA2g70VNf2f5PcAUaKMlpwSC LDlD6NgGv6LYn4WMn9jcjYNcXZ/nG+f3A+mDZKS5paf5reD4SU5Agx2Suw3J/PJ4m2A4 1L4YqjHrcSsGDUJHe5frAZxIOlzB9yzIKVT7ONrr/RY9iPOD/8/OJ7Bdz8GyPxIqs1DL bsaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=xswXLDjN; 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 q1si22834981pll.25.2019.06.04.10.49.10; Tue, 04 Jun 2019 10:49:27 -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=xswXLDjN; 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 S1726488AbfFDRsG (ORCPT + 99 others); Tue, 4 Jun 2019 13:48:06 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34251 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725929AbfFDRsG (ORCPT ); Tue, 4 Jun 2019 13:48:06 -0400 Received: by mail-pf1-f194.google.com with SMTP id c85so4339366pfc.1 for ; Tue, 04 Jun 2019 10:48:05 -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=WO/pU2tXKcWaOz/Mz8XljUSgZVyxjPQIhAnHQSTWhKk=; b=xswXLDjNe6Jf8a386sadmYdZwL+QReS4MtQ+UfRYLrhTIRzkvqzQ03azY36uhAFiZ6 VUlZKPeFui2lSXPN/A1Ld5L6ikHcGCXM0hfmX2/Daawvc4dvYRdpTQNj2TB11YyjMros 4yJDUHelpg3r8bdjufBbLRnEpioOFwufDjlJU= 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=WO/pU2tXKcWaOz/Mz8XljUSgZVyxjPQIhAnHQSTWhKk=; b=NyRh/87a3rtcB1Ec52Ne0Yw7EO/apFJ/FrxG2irIJmgN213BcHbz/97KGYagZp1TKj DDM/qSyeLYf4a7vrkPSaBeRFwDpt/9+1I+Cm7icGpQt4apnDwAnjPgTjUPiwbY27yrK6 DWjKmLC/Gf1kLGreLaxTxrFBzdulW/AQrelT1BBk68fIw17cPAMNqD5oeIVJjy3Te7+N aYUTnKK6mbj0oMvf3luvz++48jQnDf16kFF8DJHhNaEnDw0gr5TCxC0UA6rZ2h3ekOYN bipK5MmUMuGQSeevwtyS4f3HEbeZvSkoYf51AACL/YKAVRSiQEi8Z65wC86r2qZ91e4c guEA== X-Gm-Message-State: APjAAAVVj7zShG4BNALxvuB/chiOVzn+Lw20mE5jGjNsvF9AnQ+mLwsL k7lG/1r0WUJ0yx8oRkqtxhpjzA== X-Received: by 2002:a62:5487:: with SMTP id i129mr38037550pfb.68.1559670484899; Tue, 04 Jun 2019 10:48:04 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id v4sm24304610pff.45.2019.06.04.10.48.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jun 2019 10:48:03 -0700 (PDT) Date: Tue, 4 Jun 2019 13:48:02 -0400 From: Joel Fernandes To: Steven Rostedt Cc: Peter Zijlstra , 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, 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: <20190604174802.GB228607@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> <20190604065358.73347ced@oasis.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190604065358.73347ced@oasis.local.home> 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 06:53:58AM -0400, Steven Rostedt wrote: > On Mon, 3 Jun 2019 10:18:47 -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. > > > > ---8<----------------------- > > > > diff --git a/include/linux/rculist.h b/include/linux/rculist.h > > index b641fdd9f1a2..cc742d294bb0 100644 > > --- a/include/linux/rculist.h > > +++ b/include/linux/rculist.h > > @@ -371,12 +372,15 @@ 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 ( \ > > + ({ \ > > + if (COUNT_VARGS(cond) != 0) { \ > > + __list_check_rcu_cond(0, ## cond); \ > > + } else { \ > > + __list_check_rcu_nocond(); \ > > + } \ > > + }), \ > > For easier to read I would do something like this: > > #define check_rcu_list(cond) \ > ({ \ > if (COUNT_VARGS(cond) != 0) \ > __list_check_rcu_cond(0, ## cond); \ > else \ > __list_check_rcu_nocond(); \ > }) > > #define list_for_each_entry_rcu(pos, head, member, cond...) \ > for (check_rcu_list(cond), \ Yes, already doing it this way as I replied to Peter here: https://lore.kernel.org/patchwork/patch/1082846/#1278489 Thanks! - Joel