Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4315354imb; Wed, 6 Mar 2019 10:18:10 -0800 (PST) X-Google-Smtp-Source: APXvYqzHok1y3qB7zCqaQfphF8weB760BKiO4fJ3YRDHipeOShERDQiwaopwG/D7VynhIpx7sbcF X-Received: by 2002:aa7:9259:: with SMTP id 25mr8412896pfp.221.1551896290109; Wed, 06 Mar 2019 10:18:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551896290; cv=none; d=google.com; s=arc-20160816; b=a2YX0xPNOXafe6vPG6CtQ8IeFqZBp2TQIUNdR9LXbDXu1A/M3nixywbODOu/lYDQOt 1RHVltGC9D3OKU0Ldcfw3r/hyigbAN4uzKBtcAvdLX1DgmiYetcbwr9mtXgB0E/MK2jg qcqJ4UyKwzXFL53Rz5ydVDOj5rVQ4ocUWQHX/yCjVVyzjXIJSV0hqoZ4kjVyS0uC8SvT Reej6saZ9KpRuGegpuueJHc3yiYjdn7sCROia0IiZvC/1/aqHXBpTSGsxZ6Xx5A3frIU sZ6TVNMhlkj4plC64w/cEbwO/ZxusWQTixvRLzh3tMjVUF3n6GKad1fayKpXc0VvKiPr zb6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=BMNquzZ7LCKcc4KxDMrDMb83ZG4KwGAqon0uKkeZEyI=; b=nns7C3UOTaSyrrVMTa/fTGPchLvDxvl5GKoNetG+8193UjJ1Ibt56meTVALef3mAg/ SWWNCh5z1pvgP7850sbl9PnEyfAcm8v3RIbX7LEX6vFS+PWQDBHkY8+QyyGDFmczKxKF Mhqa5dVPt0ZLLiv+hF29medceupJ1h+BprYsER3t9uyvQ0TBYUcj9mlhWZEXT+hypZik q10IE1tvBey79el5IpbfrXNtRdYXLWLGSHbZ507KDETAMnqZNGCyKQcoXmSMWQgjvQ3o rx8p3t05vhbvsCOF7YhHnI7nzJANHssJVmLRvYUCaZdZzIhYAYpLDShgXUAZt9R05ALv mkfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ACYxicgu; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 11si2093531pfh.90.2019.03.06.10.17.54; Wed, 06 Mar 2019 10:18:10 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ACYxicgu; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729477AbfCFPqO (ORCPT + 99 others); Wed, 6 Mar 2019 10:46:14 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40951 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726786AbfCFPqO (ORCPT ); Wed, 6 Mar 2019 10:46:14 -0500 Received: by mail-pg1-f194.google.com with SMTP id u9so8712824pgo.7; Wed, 06 Mar 2019 07:46:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=BMNquzZ7LCKcc4KxDMrDMb83ZG4KwGAqon0uKkeZEyI=; b=ACYxicgue5JCZwd/qlIJuStp6zl0+75jIs1RQY3bVI/AKVkAzxFBeLt/5iEQHz8kra xc+6ykp5+UlXczY57jndzxSHNf+x3DiP4/dKZzypUbG30ujCA/dFvVzDpqoqV0J7LVqC cruEsZIDS8eApIfvKZt3H2wdKlp2rBYI51cWrpgZS5ues60exR5EZjSkGOms4zJWiQ93 /cZJ9tX+tTpTMrLTbOLf11RX6BIsAwqohzBfcavpZ94EjxDBvmBS83N9n8YIwg1Sb8Oz I+6mrfGIC8xcvZiONVcyXzGSQ9U6nmMAh0llTPnfRL4OwVtKwyF3UF0KmeFAXW0KywMm d5DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=BMNquzZ7LCKcc4KxDMrDMb83ZG4KwGAqon0uKkeZEyI=; b=Nxh0H5sLcN6ElFL/CPbdJWMmapAlzwhhCRuwTriEoN/jIpu8zxM4IUg/e0jtQ2vG+C fQ4njJ5/9GSU3vudcK8xgflJuKlZdz2rsy1Tvc79AbdkizHvUdXipUBp7BtA3Z3mVgps ek4o9ZvdS2ewVeI5q5QdVJzD5HlRdPW97rq/otgpFQy43/qA6LjJAFWlbsrNSPpLH/au MEEXknqiH/3MO/SVBs6UJMqjM8s42pgTY7VuIcC2qlt46RpQeUzdflP3Iqtk2qARjpzS NTWNxdnb+5qC/+ufIhqB/3Ux5DvymfgI3d86/nRMctQuP3NaFXsANPK/4vCPsO6yQi0H XJlA== X-Gm-Message-State: APjAAAUcjIysCHyttItkT2bCWg4sLZcTBIPPYCL6GMfKFAy8HG6Y6Jh+ SGURd/sA4sdws5W2HCwoD+E= X-Received: by 2002:a17:902:7798:: with SMTP id o24mr7682531pll.212.1551887172957; Wed, 06 Mar 2019 07:46:12 -0800 (PST) Received: from [192.168.11.4] (KD106167171201.ppp-bb.dion.ne.jp. [106.167.171.201]) by smtp.gmail.com with ESMTPSA id p2sm5740358pfi.95.2019.03.06.07.46.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 07:46:12 -0800 (PST) Subject: Re: [RFC PATCH] tools/memory-model: Remove (dep ; rfi) from ppo To: Peter Zijlstra , "Paul E. McKenney" Cc: Borislav Petkov , Andrea Parri , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Alan Stern , Will Deacon , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , Daniel Lustig References: <20190222130014.GY32494@hirez.programming.kicks-ass.net> <20190225175517.GK4072@linux.ibm.com> <20190226093009.GS32477@hirez.programming.kicks-ass.net> <20190226104551.GF32534@hirez.programming.kicks-ass.net> <20190226112133.GG32534@hirez.programming.kicks-ass.net> <20190226112521.GH32534@hirez.programming.kicks-ass.net> <20190226113008.GI32534@hirez.programming.kicks-ass.net> <20190226113813.GA14753@zn.tnic> <20190226134906.GG32494@hirez.programming.kicks-ass.net> <20190226142845.GK4072@linux.ibm.com> <20190226150450.GW32477@hirez.programming.kicks-ass.net> From: Akira Yokosawa Message-ID: Date: Thu, 7 Mar 2019 00:46:05 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: <20190226150450.GW32477@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 26 Feb 2019 16:04:50 +0100, Peter Zijlstra wrote: > On Tue, Feb 26, 2019 at 06:28:45AM -0800, Paul E. McKenney wrote: > >> Yes, this all is a bit on the insane side from a kernel viewpoint. >> But the paper you found does not impose this; it has instead been there >> for about 20 years, back before C and C++ admitted to the existence >> of concurrency. But of course compilers are getting more aggressive, >> and yes, some of the problems show up in single-threaded code. > > But that paper is from last year!! It has Peter Sewell on, I'm sure he's > heard of concurrency. > >> The usual response is "then cast the pointers to intptr_t!" but of >> course that breaks type checking. > > I tried laundering the pointer through intptr_t, but I can't seem to > unbreak it. > > > root@ivb-ep:~/tmp# gcc-8 -O2 -fno-strict-aliasing -o ptr ptr.c ; ./ptr > p=0x55aacdc80034 q=0x55aacdc80034 > x=1 y=2 *p=11 *q=2 > root@ivb-ep:~/tmp# cat ptr.c > #include > #include > #include > int y = 2, x = 1; > int main (int argc, char **argv) { > intptr_t P = (intptr_t)&x; > intptr_t Q = (intptr_t)&y; > P += sizeof(int); > int *q = &y; > printf("p=%p q=%p\n", (int*)P, (int*)Q); > if (P == Q) { > int *p = (int *)P; > *p = 11; > printf("x=%d y=%d *p=%d *q=%d\n", x, y, *p, *q); > } > } > So, I'm looking at the macro RELOC_HIDE() defined in include/linux/compiler-gcc.h. It says: -------- /* * This macro obfuscates arithmetic on a variable address so that gcc * shouldn't recognize the original var, and make assumptions about it. * * This is needed because the C standard makes it undefined to do * pointer arithmetic on "objects" outside their boundaries and the * gcc optimizers assume this is the case. In particular they * assume such arithmetic does not wrap. * [...] */ #define RELOC_HIDE(ptr, off) \ ({ \ unsigned long __ptr; \ __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \ (typeof(ptr)) (__ptr + (off)); \ }) -------- Looks like this macro has existed ever since the origin of Linus' git repo. And the optimization "bug" discussed in this thread can be suppressed by this macro. For example, $ gcc -O2 -o reloc_hide reloc_hide.c; ./reloc_hide x=1 y=11 *p=11 *q=11 $ cat reloc_hide.c #include #include #define RELOC_HIDE(ptr, off) \ ({ \ uintptr_t __ptr; \ __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \ (typeof(ptr)) (__ptr + (off)); \ }) int y = 2, x = 1; int main (int argc, char **argv) { int *p = RELOC_HIDE(&x, sizeof(*p)); int *q = RELOC_HIDE(&y, 0); if (p == q) { *p = 11; printf("x=%d y=%d *p=%d *q=%d\n", x, y, *p, *q); } } Note that "uintptr_t" is used in this version of RELOC_HIDE() for user-land code. Am I the only one who was not aware of this gcc-specific macro? Thanks, Akira