Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1433698rwr; Wed, 3 May 2023 15:24:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ISh+F2b7XIzqwvAC8kqYHz1NNaLjGCwk+D5+/XZAR4r9nlI78jEfYWpixAajRrmJRCUlg X-Received: by 2002:a05:6a21:9703:b0:f6:d4d:2d with SMTP id ub3-20020a056a21970300b000f60d4d002dmr95135pzb.31.1683152642543; Wed, 03 May 2023 15:24:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683152642; cv=none; d=google.com; s=arc-20160816; b=hl1UPs0o13PZfgywyN/L/tozK7Mm9etotC0p6Tfjj/cLGCYv3kZvIdHfbDA8VzXk/2 mvrTAiJJIez35nR8seTRy6ummtcg9fwaK7g/DBJpfwVWNhdUW5a1EBkqKkvOdaSusD/d Z8OAUXEKa61pmYq/eGiKL/Y/o04WMhd6w03zs7LqiyIk930dZVy0hWKIB0AV48Im5vdo Hm833mLmC2xCBMYM34rJkiBT7+GwOhjHMXcHW6rT14Grgea4EB3//UhZ7sSBV9t2yse6 Wz3Y//If/WZtLdDDOK6PuLnieY7znavHzRQILiW8gHtmaP4X8I8/NTR4GPPP/kC74krE NrWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=XPUbU2qhoZ5D1BTOltfIyM5hEUq+aXXDzmFYMzUAvWQ=; b=FUtqsDBqOVkZ5NxxVsPKfZIGnM0B4E7DIS4kxUigIW9hnwGHEPLAqP3/J6yqjGexCc twCgQzLQBXKcnyb3/O71PASjcUHKSrVC0uA/2R0j1LKahvUmBzrTApIBTxLTX9VlnPM5 vjPvQ69/94tzy9cJDztXl8ZWyT6JyYxj60a97xt3oSSYZH8//0kySeiJm8VjF0d0APeD 4ZXiS8O54mh3luxtu8ilHAAeEBm34T5yUQifAidSCs40OOkjpU97RUOA0HgHnPs5HQvm AcnxOvLNSbMgxiA1VNQNQCoPYZSTZO3txwYSR526Yl2VKMRx41SO/Vb2MsZGqFtidhPQ 7mew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a1-20020a624d01000000b0063f1582c50bsi32058910pfb.338.2023.05.03.15.23.48; Wed, 03 May 2023 15:24:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229619AbjECWGr (ORCPT + 99 others); Wed, 3 May 2023 18:06:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbjECWGq (ORCPT ); Wed, 3 May 2023 18:06:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6F237DB0 for ; Wed, 3 May 2023 15:06:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 485C26303D for ; Wed, 3 May 2023 22:06:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A57D2C433D2; Wed, 3 May 2023 22:06:42 +0000 (UTC) Date: Wed, 3 May 2023 18:06:40 -0400 From: Steven Rostedt To: Mathieu Desnoyers Cc: "Paul E. McKenney" , linux-kernel@vger.kernel.org, Joel Fernandes , Josh Triplett , Boqun Feng , Lai Jiangshan , Zqiang Subject: Re: [RFC PATCH] rcu: rcupdate.h: Add missing parentheses around macro pointer dereference Message-ID: <20230503180640.630f3006@gandalf.local.home> In-Reply-To: <20230503203236.1587590-1-mathieu.desnoyers@efficios.com> References: <20230503203236.1587590-1-mathieu.desnoyers@efficios.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 3 May 2023 16:32:36 -0400 Mathieu Desnoyers wrote: > linux/rcupdate.h macros use the *p parameter without parentheses, e.g.: > > typeof(*p) > > rather than > > typeof(*(p)) > > The following test-case shows how it can generate confusion due to C > operator precedence being reversed compared to the expectations: > > #define m(p) \ > do { \ > __typeof__(*p) v = 0; \ > } while (0) > > void fct(unsigned long long *p1) > { > m(p1 + 1); /* works */ > m(1 + p1); /* broken */ > } > > Signed-off-by: Mathieu Desnoyers > Cc: "Paul E. McKenney" > Cc: Joel Fernandes > Cc: Josh Triplett > Cc: Boqun Feng > Cc: Steven Rostedt > Cc: Lai Jiangshan > Cc: Zqiang > --- > include/linux/rcupdate.h | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h > index dcd2cf1e8326..1565012fa47f 100644 > --- a/include/linux/rcupdate.h > +++ b/include/linux/rcupdate.h > @@ -430,16 +430,16 @@ static inline void rcu_preempt_sleep_check(void) { } > > #ifdef __CHECKER__ > #define rcu_check_sparse(p, space) \ > - ((void)(((typeof(*p) space *)p) == p)) > + ((void)(((typeof(*(p)) space *)p) == p)) Hmm, should we have that be: ((void)(((typeof(*(p)) space *)(p)) == (p))) In case of the 1 + p1, which would end up as: ((void)(((typeof(*(1 + p1)) __rcu *)1 + p1 == 1 + p1; I don't know how that __rcu get's passed around via the + statement there, so it may be fine. May not even make sense to have that. But I like to error on more parenthesis. ;-) The rest looks fine. Reviewed-by: Steven Rostedt (Google) -- Steve > #else /* #ifdef __CHECKER__ */ > #define rcu_check_sparse(p, space) > #endif /* #else #ifdef __CHECKER__ */ > > #define __unrcu_pointer(p, local) \ > ({ \ > - typeof(*p) *local = (typeof(*p) *__force)(p); \ > + typeof(*(p)) *local = (typeof(*(p)) *__force)(p); \ > rcu_check_sparse(p, __rcu); \ > - ((typeof(*p) __force __kernel *)(local)); \ > + ((typeof(*(p)) __force __kernel *)(local)); \ > }) > /** > * unrcu_pointer - mark a pointer as not being RCU protected > @@ -452,29 +452,29 @@ static inline void rcu_preempt_sleep_check(void) { } > > #define __rcu_access_pointer(p, local, space) \ > ({ \ > - typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \ > + typeof(*(p)) *local = (typeof(*(p)) *__force)READ_ONCE(p); \ > rcu_check_sparse(p, space); \ > - ((typeof(*p) __force __kernel *)(local)); \ > + ((typeof(*(p)) __force __kernel *)(local)); \ > }) > #define __rcu_dereference_check(p, local, c, space) \ > ({ \ > /* Dependency order vs. p above. */ \ > - typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \ > + typeof(*(p)) *local = (typeof(*(p)) *__force)READ_ONCE(p); \ > RCU_LOCKDEP_WARN(!(c), "suspicious rcu_dereference_check() usage"); \ > rcu_check_sparse(p, space); \ > - ((typeof(*p) __force __kernel *)(local)); \ > + ((typeof(*(p)) __force __kernel *)(local)); \ > }) > #define __rcu_dereference_protected(p, local, c, space) \ > ({ \ > RCU_LOCKDEP_WARN(!(c), "suspicious rcu_dereference_protected() usage"); \ > rcu_check_sparse(p, space); \ > - ((typeof(*p) __force __kernel *)(p)); \ > + ((typeof(*(p)) __force __kernel *)(p)); \ > }) > #define __rcu_dereference_raw(p, local) \ > ({ \ > /* Dependency order vs. p above. */ \ > typeof(p) local = READ_ONCE(p); \ > - ((typeof(*p) __force __kernel *)(local)); \ > + ((typeof(*(p)) __force __kernel *)(local)); \ > }) > #define rcu_dereference_raw(p) __rcu_dereference_raw(p, __UNIQUE_ID(rcu)) >