From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFC4CC282CE for ; Tue, 4 Jun 2019 10:54:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A3B3624A1D for ; Tue, 4 Jun 2019 10:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727346AbfFDKyL (ORCPT ); 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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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(\