Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5253982ybi; Tue, 4 Jun 2019 03:55:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqyvJ0DmF6tVvwt07Tqa32lc5Q9BJLTJhkJxg6ri0bz/wZ03bgUircaJvMuIm9uQvtDJ0m3S X-Received: by 2002:a17:902:8a87:: with SMTP id p7mr19232757plo.124.1559645738979; Tue, 04 Jun 2019 03:55:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559645738; cv=none; d=google.com; s=arc-20160816; b=0nLZ81qnubJDAbI4z6DVroau2IrsWc2okLOdENK1Zv8pNrwtTddz10SjTNDQ045C8X ikKlXAUmTkOEC9BMFAfVv5cj4MXh1ACkhHTWUv87HlZB9xAALDS4r02p8cQAYZ0/wyHw MIIZgsewQJ9SObY3MDXGshkOCQE5vZSuZ1QwDWtfkXPJij2X8ibSBMl9dPqmlxjAWLQP 19LAxrLJo9gDIrqN1iWbQ6hpC7uM/Pt8ZsFEWUdMrCXroznMbVLNV6gkxttFl9BYF5JW m3/V04aI7XrDI3b29IQQeB3PZ9A2FTPJBk0FGDWmKF0IN2krCOMF3QG2HsmUs3IaOXTU uXNg== 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:subject:cc:to:from:date; bh=Lmzc6ilcwF6NKihMfXhb12JFmT4CBQQ0D3NLuRWcfGA=; b=LAdtUkimCXhQIOWq2V/a+dJBn941XWR1F6sMw72MVIjzWDV6AtJPmCyEltpNIkXSSC Di8ZXKIlrMJFOGn7R2wpomPoW/S4lDU9/Z7qXLNR0GJDEL9h8MnFkwf1pYVoNwVb/pO9 Cj2nBMNr3sE5NyED5p6mKR5a1dWtQWhLAmlmNuGse5Expcd6kjI/7CDwWTBp80i1i0r6 +FCtSF04kbFzsEb7SicATNBCmrxUly1a0srQcKLIlbNksgtY5hKjPl1fig+5vCCfUIzR ++/CUE+tc5Wuga1Wvp5FbLIoEDNpoUAVsmfcv6fiNGK4k6GF+NPQVLyhHAzeBMEQIHpg ajyg== ARC-Authentication-Results: i=1; mx.google.com; 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 v20si22604252pjn.106.2019.06.04.03.55.21; Tue, 04 Jun 2019 03:55: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; 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 S1727423AbfFDKyL (ORCPT + 99 others); Tue, 4 Jun 2019 06:54:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:51490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727088AbfFDKyL (ORCPT ); Tue, 4 Jun 2019 06:54:11 -0400 Received: from oasis.local.home (unknown [146.247.46.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5A53624986; Tue, 4 Jun 2019 10:54:03 +0000 (UTC) Date: Tue, 4 Jun 2019 06:53:58 -0400 From: Steven Rostedt To: Joel Fernandes 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: <20190604065358.73347ced@oasis.local.home> In-Reply-To: <20190603141847.GA94186@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> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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), \ -- Steve > + pos = list_entry_rcu((head)->next, typeof(*pos), member); \ > &pos->member != (head); \ > pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) > > @@ -649,12 +653,15 @@ 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 ( \ > + ({ \ > + if (COUNT_VARGS(cond) != 0) { \ > + __list_check_rcu_cond(0, ## cond); \ > + } else { \ > + __list_check_rcu_nocond(); \ > + } \ > + }), \ > + 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(\