Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1288576rwr; Fri, 5 May 2023 11:44:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Pj6SOq6l/0N1aiBd4lO60y71lEwM+TFYWClfGuDtWYmzgMjiAYTCsrsqe13L9DZvDqD1I X-Received: by 2002:a05:6a00:13a8:b0:63d:6744:8cae with SMTP id t40-20020a056a0013a800b0063d67448caemr3435339pfg.2.1683312293702; Fri, 05 May 2023 11:44:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683312293; cv=none; d=google.com; s=arc-20160816; b=FkNVe12o2kP1SEAkVEJ+JxuVg5RK40/okw100jLWiaAjlxWovZ+vAHpzOEhm6whW0e 3U8m+0NreWLFEnZl3HSp4oQ4c4GtjYyFVL7wORop6Dlem8t3KKPDhqWFZFlOj4oyEvHn LkdxkBkALJcczqvaNjEVnBI3edyV6XgvmE2u4PDHjyaCo2+phbEV2rzqUpjkWtPRFfrz HEEUV7VftKWQwmaOjGkDGE6lJWWT+mQnOAwdBea2gQUxuEDXIS6wvqwf697bjzD3yd5h sppqOjCX9C2+X2Qqivc0uyRXxwBJgyhB64Y/dax0ztkKJ5Uk9gft56Vra2yMtZa/n5cE 1Pkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=h3Cd1EP3d2qId+aiBzvN1/NByXqjI5ORWM8CTy9L3EE=; b=AWsryw+zJhRU7ESIyGqET7g0MHeU37FvU1YzsQ7WuZKsRm+qrBCN3O6IsNedG1p+EL nlQB1nubb5kgvYyWu2rV+OcuaO3uI0BEE0ivCE+2YUMBRWGHT3tYIcbaGg2g4vM2WhG8 P51RV91fsmimmiDaZL/LkJddh0RXJnRJdn8P7est/q1HiiZAyMM6HSn03mi5DgLoRePN sDbSPRTfGXhovSOdeGTjzCUetgm/7lJDg3YxJB9Odx5bxK+cJSAkTpgVqjdgtSWMVeSY Ra6Yi/Ix9Pah8kSqn+ISRzOjMPpCGKBPv6xep33t0cTE4xbd4V5cjtVpIx34zgrhkaws 6PIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LqIZ7b2v; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d18-20020a637352000000b0052c7c84229esi2694875pgn.702.2023.05.05.11.44.36; Fri, 05 May 2023 11:44:53 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LqIZ7b2v; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233074AbjEESjb (ORCPT + 99 others); Fri, 5 May 2023 14:39:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231580AbjEESj2 (ORCPT ); Fri, 5 May 2023 14:39:28 -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 821FE1AEC7 for ; Fri, 5 May 2023 11:39:26 -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 08024612BE for ; Fri, 5 May 2023 18:39:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 683F2C433EF; Fri, 5 May 2023 18:39:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683311965; bh=Dh7G9B1wiGWf3GmFb0fdhL0vZbXH9ywECZDZ4w6wpbs=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=LqIZ7b2vIi5pchCnETaZENGZ7lGaUGNszx+jCFOHb8r+wO9WDv2IyMEiCjEUMWPjZ FZAKeZleKNUVCUpQ7vHs/pNohVXRZMmRydnOR/wVuLEI4asjLV6lacMf1G1exr9Wfd Pqzcm93QW7qBEwVla0HssOq8823uaL8kY0cHT6Lze3Uj3z4p/Wi2I5pSbv3+Jg7FYa l9My0LT/7wguyI7K19FbzZXtNx6ykPnCS3KVgDM0NjwFLx0+KCFVdYp1s1rWvMZM9Y 6SwfpPzLjcm0/l0ze+b0HbVVprNuNh2NiW0VqHWXVq8ROJn/Q/bHgHkdrULIoiAwb6 FwXRka7G8ijww== Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id BF48F15405AC; Fri, 5 May 2023 11:39:24 -0700 (PDT) Date: Fri, 5 May 2023 11:39:24 -0700 From: "Paul E. McKenney" To: Mathieu Desnoyers Cc: Steven Rostedt , 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: <41c82bac-014f-49a8-8223-683db77e8671@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20230503203236.1587590-1-mathieu.desnoyers@efficios.com> <20230503180640.630f3006@gandalf.local.home> <5b102a66-f88c-4a77-887e-1b41f8064454@paulmck-laptop> <34b873b0-93e5-d492-9c30-9d6b5c022ace@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <34b873b0-93e5-d492-9c30-9d6b5c022ace@efficios.com> X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Fri, May 05, 2023 at 09:15:12AM -0400, Mathieu Desnoyers wrote: > On 2023-05-04 20:28, Paul E. McKenney wrote: > > On Wed, May 03, 2023 at 06:06:40PM -0400, Steven Rostedt wrote: > > > 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) > > > > Thank you all! I applied Steve's suggested change with attribution > > as shown below. Please let me know if I messed anything up. > > Hi Paul, > > I've done a new version of that patch which fixes other issues in rcupdate.h > in the next round. Can you hold merging this until I remove the "RFC PATCH" > tag please ? My goal is to gather feedback first to make sure everyone is OK > with the overall changes across headers, so everything can become > consistent. Hello, Mathieu, Very well, I have removed it. Thanx, Paul > Thanks, > > Mathieu > > > > > Thanx, Paul > > > > ------------------------------------------------------------------------ > > > > commit d3d734216c88fb7c13205dc62178ff5011da415b > > Author: Mathieu Desnoyers > > Date: Wed May 3 16:32:36 2023 -0400 > > > > rcu: Add missing parentheses around rcu_dereference() "p" parameter > > 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 */ > > } > > [ paulmck: Apply Steve Rostedt additional () feedback. ] > > 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 > > Reviewed-by: Boqun Feng > > Reviewed-by: Steven Rostedt (Google) > > Reviewed-by: Joel Fernandes (Google) > > Signed-off-by: Paul E. McKenney > > > > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h > > index ddd42efc6224..cb938a89a923 100644 > > --- a/include/linux/rcupdate.h > > +++ b/include/linux/rcupdate.h > > @@ -405,16 +405,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))) > > #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 > > @@ -427,29 +427,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)) > > -- > Mathieu Desnoyers > EfficiOS Inc. > https://www.efficios.com >