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 1350CC28CC6 for ; Mon, 3 Jun 2019 19:42:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6B0E26703 for ; Mon, 3 Jun 2019 19:42:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="v57zkduk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726697AbfFCTmP (ORCPT ); Mon, 3 Jun 2019 15:42:15 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:34721 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726223AbfFCTmO (ORCPT ); Mon, 3 Jun 2019 15:42:14 -0400 Received: by mail-pf1-f193.google.com with SMTP id c85so2403677pfc.1 for ; Mon, 03 Jun 2019 12:42:14 -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=a+lhr9Q+24Qfza3c4uXpEdm8TyEjYoUavdn6rBgETA0=; b=v57zkdukOzYOvhfiKNqk2b/GOjkFP1SHWP5I5eo7SiatQZoyLWIBR+84HSu7EA2L8f /Txa/lSthx5I4+d0+ItNuTqwsJewXfi+56sABsg3JwRHrqq33I7sTzcN+0Twcbb6KpI7 +Pr2kvxYQLWF4bCfr03Db/6neBgFbrX8K2sXo= 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=a+lhr9Q+24Qfza3c4uXpEdm8TyEjYoUavdn6rBgETA0=; b=McVEfGnPY2OLRxpnKpeoLKlpyn93Znfx2Pwj0xzNGh4a9ESGUD8Qm7TVmmV4AZcuBL h7JO9vTAjGSZecOaKinxyYRp4Q0GR3JeR+FTzKnQC9h42BqDu5xqRZ48/HQiZf1QjA68 xnHc1G8q5X2zf3uDhfOprKF/y1W92B6KjmqCnM5EM7Hbt6ceC67eF/FGhs0eNxd56XSP jY2sRw3UAN3r/neYSkrfTCPMvZH1VjlR3zoXSVl+vvdziYUels4FQw/nvFLWh9z9JO0u 9WjMMosbJw340SiPS9GgW6uESWRfpHE5ozgwC3bavk2TA1tcIPm1801Upm0EdiuOyEGN 8F6g== X-Gm-Message-State: APjAAAVMa/RFwFG2pgGY/XsfcZhfcmH1ekCPvCRHPgiGouQOc4D5LXrM apiL9LHm/dXIP846+4YNp3VMbQ== X-Google-Smtp-Source: APXvYqxWMwntCJiOP/Rg6qilGaE0r4tvP3xYpgRSB5zm6o29WMIRTYv7JT5/hpFHq7FY7Jh/PBhQ6A== X-Received: by 2002:a63:e10d:: with SMTP id z13mr9626011pgh.116.1559590933600; Mon, 03 Jun 2019 12:42:13 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id o2sm13442018pgm.51.2019.06.03.12.42.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jun 2019 12:42:12 -0700 (PDT) Date: Mon, 3 Jun 2019 15:42:11 -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: <20190603194211.GA228607@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190603141847.GA94186@google.com> 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:18:47AM -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. Actually was able to roll the if/else into its own macro as well, thus keeping it clean. thanks! ---8<----------------------- diff --git a/include/linux/rculist.h b/include/linux/rculist.h index b641fdd9f1a2..cc9c382b080c 100644 --- a/include/linux/rculist.h +++ b/include/linux/rculist.h @@ -43,7 +43,11 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list) /* * Check during list traversal that we are within an RCU reader */ -#define __list_check_rcu() \ + +#define SIXTH_ARG(a1, a2, a3, a4, a5, a6, ...) a6 +#define COUNT_VARGS(...) SIXTH_ARG(dummy, ## __VA_ARGS__, 4, 3, 2, 1, 0) + +#define __list_check_rcu_nocond() \ RCU_LOCKDEP_WARN(!rcu_read_lock_any_held(), \ "RCU-list traversed in non-reader section!") @@ -59,6 +63,16 @@ static inline void __list_check_rcu_cond(int dummy, ...) RCU_LOCKDEP_WARN(!cond && !rcu_read_lock_any_held(), "RCU-list traversed in non-reader section!"); } + +#define __list_check_rcu(cond...) \ + ({ \ + if (COUNT_VARGS(cond) != 0) { \ + __list_check_rcu_cond(0, ## cond); \ + } else { \ + __list_check_rcu_nocond(); \ + } \ + }) + /* * Insert a new entry between two known consecutive entries. * @@ -357,9 +371,6 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, member) : NULL; \ }) -#define SIXTH_ARG(a1, a2, a3, a4, a5, a6, ...) a6 -#define COUNT_VARGS(...) SIXTH_ARG(dummy, ## __VA_ARGS__, 4, 3, 2, 1, 0) - /** * list_for_each_entry_rcu - iterate over rcu list of given type * @pos: the type * to use as a loop cursor. @@ -371,12 +382,8 @@ 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 (__list_check_rcu(cond), \ + pos = list_entry_rcu((head)->next, typeof(*pos), member); \ &pos->member != (head); \ pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) @@ -649,12 +656,8 @@ 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 (__list_check_rcu(cond), \ + 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