Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4392404ybi; Mon, 3 Jun 2019 10:05:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDTGDAUIiLVtU0nO8WGNAfH99RuoDkrOX7Pj4g37lQo7jDXfzCR89L6e3yde8ownzb9zQ2 X-Received: by 2002:aa7:8394:: with SMTP id u20mr22542125pfm.252.1559581551176; Mon, 03 Jun 2019 10:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559581551; cv=none; d=google.com; s=arc-20160816; b=h7t1+h3vhh3Tn1kMDkS/rIXM4T5JOWSuhujxNQrxGKgVvZNALSR2tYTnvt7jFa8r33 rfJ+KUW1Y51iC6O58eAHjChSdFJdUG8r8m9Aq/M3hbU+1BXmCYDNmgmkfjxwQesISDFx zG2QRNlNVBJoBDRU8jsrUmc6GzxiVvfEqJU7uDTZFGbqH4J/T0OdinzN8qL/vXqFzqNZ GY0B6gcQ85/GJZBJnjl3h6J4BWcM8zE73PT15yargwKFi+w2OIkjo0ZiAB5t0O9xYyRE cdL0xUD3cK1Ch0xdS+6vmR6h0Pvd+feDdMpePAVuOUka2fPyrBtUGtSMhCCC9ky4joaX 1Xrg== 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=wino6sk3VdZE6+hAQNM1PvtsWBqO77h9pHog6R+saB4=; b=XT1ZvbFicIYUswZTGa3x/F0fELQUafs30agh79/RUuYyUappbljst26AaDSSRDItoW P/rW2nCKSBP8W2XHspGI+OoNKDBlDhbZNX4E3bnsWgObDfEJx3JE1rSLYoLC/wr9Phjg bTlV/ZxFJpJfEr5sIvRPqM1DbQqa0yvB9bJ+oIz76CMUIeeOMwWlJ9Q8hHCxni+ivY+P tk1pvdly4UihvnAE244zuAepW6pcYXx06C7U1Mw98h7asJYUDRTYTeyoLhNPmt6Bk89i QeVoM6JUdFpEnyWaMdkVT4dCdeZsMNgreb3XNoy0iR4KDsSW5h9k8TZqwP3u1xNh/iSV wF2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=ILFGoBB8; 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 t8si19025258pgn.112.2019.06.03.10.05.31; Mon, 03 Jun 2019 10:05:51 -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=ILFGoBB8; 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 S1728999AbfFCOSy (ORCPT + 99 others); Mon, 3 Jun 2019 10:18:54 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37392 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728122AbfFCOSu (ORCPT ); Mon, 3 Jun 2019 10:18:50 -0400 Received: by mail-pf1-f194.google.com with SMTP id a23so10721481pff.4 for ; Mon, 03 Jun 2019 07:18:50 -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=wino6sk3VdZE6+hAQNM1PvtsWBqO77h9pHog6R+saB4=; b=ILFGoBB8mLMqVVtS8/R/M5XmKpli9djqbjha1UCLJ1dh/6QP3UUReHWHDiD4kff4T7 9/EuFMLCU7KEekS2AIMDnGtUJRZ7MQJimC/aYCot7tPs1eoHEET2YsyCOXT26R5TB610 BnMntKUbojtA1j1WCh9KSm7cLhDJ39hgwOFSU= 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=wino6sk3VdZE6+hAQNM1PvtsWBqO77h9pHog6R+saB4=; b=TEGzNd2FOejfQSOcpX+Wnopno09LVCeDhddBKcXHREKGH4HFkvqze/SRGvwsANK3nf I2rlWSel67bd75t1fDChy9h9FYo+LKrTrU88OEvnXtzDjXTUXhjZ4UoMhwxv6BqLfWwN x6AO3vVel5YD6zV5Cvc0MhlHxTM+ZLEx4rOZ1GvZWVaZBLAp5dMpP6Z0sLdJbbNqRQS2 QTwPbxshIAreFUU5aLLFAxDiGw4SA8uO1NuJLYubJaOuumIKHNeoRJRN9/gN0mzVemZ/ pfjcf5QmbQx23+e/97U60tCXGr51R+zfsdblEUjhqcTNBit/7wB7wVTZVhiVgPI7yN4A Nvjg== X-Gm-Message-State: APjAAAVOnRoIMA/i5nhGzGto/7PSqbXjNHc+LBt0sqRI0SQvgrN7HUpm +XacaWNqOEpaZPozURWxv0CKWw== X-Received: by 2002:a63:6157:: with SMTP id v84mr14697278pgb.36.1559571529472; Mon, 03 Jun 2019 07:18:49 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id d2sm13148346pfh.115.2019.06.03.07.18.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jun 2019 07:18:48 -0700 (PDT) Date: Mon, 3 Jun 2019 10:18:47 -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: <20190603141847.GA94186@google.com> References: <20190601222738.6856-1-joel@joelfernandes.org> <20190601222738.6856-2-joel@joelfernandes.org> <20190603080128.GA3436@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190603080128.GA3436@hirez.programming.kicks-ass.net> 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: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(); \ + } \ + }), \ + 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(\ -- 2.22.0.rc1.311.g5d7573a151-goog