Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1203893imu; Fri, 21 Dec 2018 14:43:34 -0800 (PST) X-Google-Smtp-Source: ALg8bN5UyQPRaIV30iREFjT+SVNfoR7JXhgmLC0CwHvAwcdYTfuOrxfptGWekCH0yEDFoWBJl8/b X-Received: by 2002:a17:902:4225:: with SMTP id g34mr4449747pld.152.1545432214185; Fri, 21 Dec 2018 14:43:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545432214; cv=none; d=google.com; s=arc-20160816; b=D8zcKA1MW77uTPuN/j7cbbclYQePJOngYwSpHSYxNxtsfijz6iuvtmEvdF6LZho1zZ QTqc2Jw4fxsod+/jCLimjasX71Iek2/UK4GPhhXZCx2PDSWOAdUI57Gkna9rXstasq5P 4X+bMMcKCZfyqtOnRsIFAQE3r15ec0/WREW/mZ74ca15/aUyDvCKuB5bDEWJlle1PF7W meqDmy/c/0d32MgjegjBxTxqPBvCgW9fR3Y4OYbNiG4PNSvxXwKQv5M2r4WuAqIxmWIz FkRgH+1P0MI+XcfC/48M+HAx1Pz276rBdplveF7Bx7ejB5h2D57YfD4GNaEalRH1UAKx KE8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date; bh=U1BXKagA416r4rYgPQqwRw6Tr19ZD1muuOzaM2CCI64=; b=HnXEWnbPjGvF03iA5DFSBySx1SsKO2uvjuNZT+hqBKnF/GLB+Hx0ozl1YgLnVr3ycU h5nLdsH3mraZa+/BtXE15PBnNnv6pe8iPBdEppHf+fu5R7esUuxyYDNe3d2kg71AbOhn 93EcJngPFxU3qEvlp1yZ5broMR9GEBl0W3ImlVCd9TNnomWjr31Sk4SQccc9zIrypez2 Ea/m1xHXlpWabo+jF2zfwIzeQ82hzbCv8yNb2NiStpmS3uxaaCpSwtHndGav5B6S8Gl5 YjWb2zAPwL77QXi29Sg9S1WUZXl12Ch15N2MTKudJ/9h4uEl226q1cb/guNcVhl0emJT bnKQ== 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 y123si4653595pfy.18.2018.12.21.14.43.18; Fri, 21 Dec 2018 14:43:34 -0800 (PST) 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 S2403814AbeLUOXY (ORCPT + 99 others); Fri, 21 Dec 2018 09:23:24 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:46996 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1733305AbeLUOXY (ORCPT ); Fri, 21 Dec 2018 09:23:24 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wBLEJ3Hr089271 for ; Fri, 21 Dec 2018 09:23:22 -0500 Received: from e14.ny.us.ibm.com (e14.ny.us.ibm.com [129.33.205.204]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ph1h51bbq-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Dec 2018 09:23:22 -0500 Received: from localhost by e14.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 21 Dec 2018 14:23:21 -0000 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e14.ny.us.ibm.com (146.89.104.201) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 21 Dec 2018 14:23:17 -0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wBLENGsk14418124 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 21 Dec 2018 14:23:17 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D875BB2068; Fri, 21 Dec 2018 14:23:16 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B5D48B2064; Fri, 21 Dec 2018 14:23:16 +0000 (GMT) Received: from paulmck-ThinkPad-W541 (unknown [9.85.153.1]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 21 Dec 2018 14:23:16 +0000 (GMT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 6DD9116C20FC; Fri, 21 Dec 2018 06:23:23 -0800 (PST) Date: Fri, 21 Dec 2018 06:23:23 -0800 From: "Paul E. McKenney" To: Peter Zijlstra Cc: Andi Kleen , Arnd Bergmann , Nicolas Pitre , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Will Deacon , Ingo Molnar , Thomas Gleixner Subject: Re: [PATCH 0/7] ARM: hacks for link-time optimization Reply-To: paulmck@linux.ibm.com References: <20180220215954.4092811-1-arnd@arndb.de> <20181217225020.GA16520@hirez.programming.kicks-ass.net> <20181218000800.GB25620@tassilo.jf.intel.com> <20181218091824.GI2218@hirez.programming.kicks-ass.net> <20181218100014.GA16284@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181218100014.GA16284@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 18122114-0052-0000-0000-0000036B5E2A X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010261; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000272; SDB=6.01134977; UDB=6.00590153; IPR=6.00915149; MB=3.00024785; MTD=3.00000008; XFM=3.00000015; UTC=2018-12-21 14:23:20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18122114-0053-0000-0000-00005F2FE03E Message-Id: <20181221142323.GO4170@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-21_07:,, 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=1015 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-1812210113 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 18, 2018 at 11:00:14AM +0100, Peter Zijlstra wrote: > On Tue, Dec 18, 2018 at 10:18:24AM +0100, Peter Zijlstra wrote: > > In particular turning an address-dependency into a control-dependency, > > which is something allowed by the C language, since it doesn't recognise > > these concepts as such. > > > > The 'optimization' is allowed currently, but LTO will make it much more > > likely since it will have a much wider view of things. Esp. when combined > > with PGO. > > > > Specifically; if you have something like: > > > > int idx; > > struct object objs[2]; > > > > the statement: > > > > val = objs[idx & 1].ponies; > > > > which you 'need' to be translated like: > > > > struct object *obj = objs; > > obj += (idx & 1); > > val = obj->ponies; > > > > Such that the load of obj->ponies depends on the load of idx. However > > our dear compiler is allowed to make it: > > > > if (idx & 1) > > obj = &objs[1]; > > else > > obj = &objs[0]; > > > > val = obj->ponies; > > > > Because C doesn't recognise this as being different. However this is > > utterly broken, because in this translation we can speculate the load > > of obj->ponies such that it no longer depends on the load of idx, which > > breaks RCU. Hence the following in Documentation/RCU/rcu_dereference.txt: You are only permitted to use rcu_dereference on pointer values. The compiler simply knows too much about integral values to trust it to carry dependencies through integer operations. I got rid of the carrying of dependencies via non-pointers in 2014. You are telling me that they have crept back? Sigh!!! :-/ Thanx, Paul > > Note that further 'optimization' is possible and the compiler could even > > make it: > > > > if (idx & 1) > > val = objs[1].ponies; > > else > > val = objs[0].ponies; > > A variant that is actually broken on x86 too (due to issuing the loads > in the 'wrong' order): > > val = objs[0].ponies; > if (idx & 1) > val = objs[1].ponies; > > Which is a translation that makes sense if we either marked > unlikely(idx & 1) or if PGO found the same. > > > Now, granted, this is a fairly artificial example, but it does > > illustrate the exact problem. > > > > The more the compiler can see of the complete program, the more likely > > it can make inferrences like this, esp. when coupled with PGO. > > > > Now, we're (usually) very careful to wrap things in READ_ONCE() and > > rcu_dereference() and the like, which makes it harder on the compiler > > (because 'volatile' is special), but nothing really stops it from doing > > this. > > > > Paul has been trying to beat clue into the language people, but given > > he's been at it for 10 years now, and there's no resolution, I figure we > > ought to get compiler implementations to give us a knob. >