Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1793664ybm; Thu, 23 May 2019 06:54:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxsw3UAoNKBePQiUStt3NY9qWuNn5lxN/bfUhClFbjjZZGioEWnoWCYGTH2gNJHeiXwlbJX X-Received: by 2002:a63:e24c:: with SMTP id y12mr74089184pgj.276.1558619677713; Thu, 23 May 2019 06:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558619677; cv=none; d=google.com; s=arc-20160816; b=aPqg79qbrYcpUUuAixVjC2JLgNhbMLxYmn7Hayuu1MkzMzP3F1U+S6/fKA8dKX7eYr ThNt3YTnH2kixV/25v/ip46IRdVfm0mBWdMDk//dS2Ch4W/hdjQ72GD321d8XGQeeuzL +k6aTpxSYUW4+oeudmXSncZp5jugDwUXanagnYdHnxNbtSM44zMU2US6EC3kvdCZ9J+e BOgeHVFS4KWdJmYEiXEXnx41Q1nEUs1s59C5vGEL7e2vg969l4Q+GsUQZJ8cEyWHYR4i ZHuRuBakXtOHUQ0vKDavTy5KHjKPVNk6mvRifxltrJ3G5WM6nq3RNnCeGQAqg+vBa/I+ GRdQ== 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-transfer-encoding:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date; bh=Y+ENua599c+ww/uctZAgkoHi+EwAbGGJINXQNDPYdIM=; b=hhHhJcRSrsPPHT/ZaUY325d5bY4k59Ano95CZ8H45xJfGpi71yfCivps84yVIDAENc VmozMMkugfe/wV3M6Y548l2SCjTQduXKvW6m4CkNMCvheWDSG/I7GxP+IY+U9MfwDQsJ pmpkyWDJEma4DTJ+8QZH85ZV49upMh4mzH1uFZE7Uz1+fqVITFM3b5qSeyYZNiJgJhlw 6RseNbIUBA98FR5jMoXqrqG7rp3JXRGXmNd+Msu5JHlhAvZtLpw9IyoLY2PxfphH7ZQE G5edE5HDFpfdnfV3uIdh3Hta6Ovum/gC9IGpdVeMS7q0GqFqvWy6294e5BKSP/gBqry9 u+DA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si31288960plo.300.2019.05.23.06.54.22; Thu, 23 May 2019 06:54:37 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730791AbfEWNwR (ORCPT + 99 others); Thu, 23 May 2019 09:52:17 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:47892 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730323AbfEWNwR (ORCPT ); Thu, 23 May 2019 09:52:17 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4NDn21n121341; Thu, 23 May 2019 09:51:30 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 2snunr3s69-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2019 09:51:30 -0400 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.27/8.16.0.27) with SMTP id x4NDn55p121840; Thu, 23 May 2019 09:51:29 -0400 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 2snunr3s5d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2019 09:51:29 -0400 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id x4N7mSO7021521; Thu, 23 May 2019 07:56:08 GMT Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by ppma01dal.us.ibm.com with ESMTP id 2sn84n1kgf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 May 2019 07:56:08 +0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x4NDoCSq23003300 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 May 2019 13:50:12 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8E0B0B208A; Thu, 23 May 2019 13:50:12 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A045B208B; Thu, 23 May 2019 13:50:12 +0000 (GMT) Received: from paulmck-ThinkPad-W541 (unknown [9.70.82.216]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 23 May 2019 13:50:12 +0000 (GMT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 985A416C0FB0; Thu, 23 May 2019 06:50:13 -0700 (PDT) Date: Thu, 23 May 2019 06:50:13 -0700 From: "Paul E. McKenney" To: Andrea Parri Cc: linux-kernel@vger.kernel.org, Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , rcu@vger.kernel.org, Peter Zijlstra , Will Deacon , Mark Rutland Subject: Re: [RFC PATCH] rcu: Make 'rcu_assign_pointer(p, v)' of type 'typeof(p)' Message-ID: <20190523135013.GL28207@linux.ibm.com> Reply-To: paulmck@linux.ibm.com References: <1558618340-17254-1-git-send-email-andrea.parri@amarulasolutions.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1558618340-17254-1-git-send-email-andrea.parri@amarulasolutions.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-23_12:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905230096 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 23, 2019 at 03:32:20PM +0200, Andrea Parri wrote: > The expression > > rcu_assign_pointer(p, typeof(p) v) > > is reported to be of type 'typeof(p)' in the documentation (c.f., e.g., > Documentation/RCU/whatisRCU.txt) but this is not the case: for example, > the following snippet > > int **y; > int *x; > int *r0; > > ... > > r0 = rcu_assign_pointer(*y, x); > > can currently result in the compiler warning > > warning: assignment to ‘int *’ from ‘uintptr_t’ {aka ‘long unsigned int’} makes pointer from integer without a cast [-Wint-conversion] > > Cast the uintptr_t value to a typeof(p) value. > > Signed-off-by: Andrea Parri > Cc: "Paul E. McKenney" > Cc: Josh Triplett > Cc: Steven Rostedt > Cc: Mathieu Desnoyers > Cc: Lai Jiangshan > Cc: Joel Fernandes > Cc: rcu@vger.kernel.org > Cc: Peter Zijlstra > Cc: Will Deacon > Cc: Mark Rutland > --- > NOTE: > > TBH, I'm not sure this is 'the right patch' (hence the RFC...): in > fact, I'm currently missing the motivations for allowing assignments > such as the "r0 = ..." assignment above in generic code. (BTW, it's > not currently possible to use such assignments in litmus tests...) Given that a quick (and perhaps error-prone) search of the uses of rcu_assign_pointer() in v5.1 didn't find a single use of the return value, let's please instead change the documentation and implementation to eliminate the return value. > The usual concern is, of course, that if something is allowed (read > 'compile!' ;/) then people will soon or later use it and they'll do > it in all sorts of 'creative' ways, such as 'to extend dependencies > across rcu_assign_pointer() calls' as in > > x = READ_ONCE(*z); > r0 = rcu_assign_pointer(*y, x); > WRITE_ONCE(*w, r0); > > Notice that using a 'do { ... } while (0)', say, would prevent such > tricks/rvalues. (The same approach is used by smp_store_release().) As you in fact suggest here. ;-) Thanx, Paul > For a related discussion, please see: > > https://lkml.kernel.org/r/20190523083013.GA4616@andrea > > Thoughts? > > Andrea > --- > include/linux/rcupdate.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h > index 915460ec08722..b94ba5de78fba 100644 > --- a/include/linux/rcupdate.h > +++ b/include/linux/rcupdate.h > @@ -375,7 +375,7 @@ static inline void rcu_preempt_sleep_check(void) { } > WRITE_ONCE((p), (typeof(p))(_r_a_p__v)); \ > else \ > smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \ > - _r_a_p__v; \ > + ((typeof(p))_r_a_p__v); \ > }) > > /** > -- > 2.7.4 >