Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752823AbcKBMMF (ORCPT ); Wed, 2 Nov 2016 08:12:05 -0400 Received: from ud10.udmedia.de ([194.117.254.50]:41680 "EHLO mail.ud10.udmedia.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751284AbcKBMME (ORCPT ); Wed, 2 Nov 2016 08:12:04 -0400 Date: Wed, 2 Nov 2016 13:11:58 +0100 From: Markus Trippelsdorf To: Peter Zijlstra Cc: Richard Biener , "Luis R. Rodriguez" , Vegard Nossum , Jiri Slaby , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Linus Torvalds , stable@vger.kernel.org, Ming Lei , Steven Rostedt , "H. Peter Anvin" , Josh Poimboeuf , Cesar Eduardo Barros , Michael Matz , David Miller , Guenter Roeck , Fengguang Wu , Borislav Petkov , Boris Ostrovsky , Juergen Gross , Kees Cook , ArnaldoCarva@x4 Subject: Re: [PATCH 01/12] extarray: define helpers for arrays defined in linker scripts Message-ID: <20161102121158.GA11638@x4> References: <186f8242-3f8d-31cd-a8e8-9743bbc1c1fd@suse.cz> <20161017090930.GT3142@twins.programming.kicks-ass.net> <55e00c01-2da8-8d06-1d05-9ebf775736ec@oracle.com> <20161017114517.GQ3117@twins.programming.kicks-ass.net> <55b3cbe0-f8fc-6505-411d-5f050d3414cc@oracle.com> <20161018211803.GV8651@wotan.suse.de> <20161019091347.GE3102@twins.programming.kicks-ass.net> <20161019102555.GJ3102@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161019102555.GJ3102@twins.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1807 Lines: 55 On 2016.10.19 at 12:25 +0200, Peter Zijlstra wrote: > On Wed, Oct 19, 2016 at 11:33:41AM +0200, Richard Biener wrote: > > On Wed, 19 Oct 2016, Peter Zijlstra wrote: > > > > This is also an entirely different class of optimizations than the whole > > > pointer arithmetic is only valid inside an object thing. > > > > Yes, it is not related to that. I've opened > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78035 to track an > > inconsistency in that new optimization. > > > > > The kernel very much relies on unbounded pointer arithmetic, including > > > overflow. Sure, C language says its UB, but we know our memory layout, > > > and it would be very helpful if we could define it. > > > > It's well-defined and correctly handled if you do the arithmetic > > in uintptr_t. No need for knobs. > > So why not extend that to the pointers themselves and be done with it? > > In any case, so you're saying our: > > #define RELOC_HIDE(ptr, off) \ > ({ \ > unsigned long __ptr; \ > __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \ > (typeof(ptr)) (__ptr + (off)); \ > }) > > could be written like: > > #define RELOC_HIDE(ptr, off) \ > ({ \ > uintptr_t __ptr = (ptr); \ > (typeof(ptr)) (__ptr + (off)); \ > }) > > Without laundering it through inline asm? > > Is there any advantage to doing so? > > But this still means we need to be aware of this and use these macros to > launder our pointers. > > Which gets us back to the issue that started this whole thread. We have > code that now gets miscompiled, silently. > > That is a bad situation. So we need to either avoid the miscompilation, > or make it verbose. FYI this issue was fixed on gcc trunk by: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=76bc343a2f1aa540e3f5c60e542586bb1ca0e032 -- Markus