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=-5.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_MUTT 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 2FABEC28CC6 for ; Mon, 3 Jun 2019 14:18:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EFDDC2796C for ; Mon, 3 Jun 2019 14:18:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="ILFGoBB8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728987AbfFCOSv (ORCPT ); Mon, 3 Jun 2019 10:18:51 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44450 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726968AbfFCOSu (ORCPT ); Mon, 3 Jun 2019 10:18:50 -0400 Received: by mail-pf1-f195.google.com with SMTP id t16so1886152pfe.11 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=bLHrpyICIa+Q4KimuA59kHD6ptogP12xTv+QSnNT1qLYTmW9SFiwZlBZUL6df//BmI H8hhoPxPkS1tpo1r2zohMwOzJ4eyEKg7gCazycMpwRQrcj8gMnjlGWa1Wf8SAjaH5XkS WRP+VB2hQd4LQHjTUXJZ7OWnYiMTnzoaXej4mMo1+yRmZab/LjLVOm4zq/R3y9bcL3XP enL0A9Av9fvBxkbDkqRTZz2N9infufuKxOjdkiIbWqUGf3c0RrvIjpQNiEEBiWD6XBrf ijDTNDid5pVhF0LWWkZowDRockpF/2ygnG6NngJcCsr3s9+98WrZ/pej4o54T1iHWhQn gHkA== X-Gm-Message-State: APjAAAWYwjIIMIzOdNTEgBmF9iCiDfE2rvxkjx7uyZaacG7ReZ2tQpUn XIIj96ZfW9YkVv/LWsmIIn7+MQ== X-Google-Smtp-Source: APXvYqyKAjR/D78/kGgs8thHzTfUR/LOLb5cBxjo6X/LlWYPb4MJB9cnaSwLt+1e5dELPHpdsRQU0Q== 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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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