From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17FA7384CEC for ; Thu, 21 May 2026 10:20:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779358834; cv=none; b=t9ml9+syzS2CW7gX3JsROs/TKZGpmiuBWGiYmMDa9iRir6usRY3m0nfM6wd1BrqdVjYy2UN5aLiNVjVHxhOUZA941zVvZ0X0BgdlkfBm1SGKRHl7f/sQtYZFKFKHYWHpFFGSdqiz5s6hpzykfryr5+2TrNwlYiXJXzMggt4xkY4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779358834; c=relaxed/simple; bh=hHLvCtHxrHLXtPxfV7caH/xSD9e3yqQEvCWgDm6tiVo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UtN574E3p3MqS7iWQAtwxAF2QFQclev4tD6iPoe1bOfrEU/f/AEGqXaiw+uvaeHzjDEo51rFcQGdzV/l2sfOlkGP3S4QIDIjQK05aLzI6N8rAQFGVgSU6daO9YG9ubntDU/AWomSzOFLLroJb+z0jS+k2sZjG+xffTmMp8n81eE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=NnKcWEat; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="NnKcWEat" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=NbAa+nf0+6biOCfuhCKiuw2+Xk3RQSSEAlNiJlRbD40=; b=NnKcWEatDM/Qb8rFZ+EEE1wpOa Yj7lheOe14CoxnVKzZKvJWJxDLZJFugBZuEIFdCGDgZjlLU9VkuROJM12b1yMRKUfYakpuweKQ/3C ztn4S14/IpBbnwSSZoAmsrfWZyr8uvRUuPNgMZ10DtJcTEKes9Lkte3vQQBhyFTeisobl8CVEORbo 8C3FVfiewO83oGkbpeHGRTIsafvJvcEwkPjmiPz7USv75kRaEhCKG9opxQz3WBNDrFCbODQQemDqG ueFO7BmPPgtsDZQ+WyQH1OPAwsMO3ydl8m+96PzR+Y9YqABZIkCf1GRJabW6c7jPfYhbY3sXDBx5G iOc087Sg==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wQ0Vt-00000008O1R-4Bte; Thu, 21 May 2026 10:20:26 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id C112B300446; Thu, 21 May 2026 12:20:23 +0200 (CEST) Date: Thu, 21 May 2026 12:20:23 +0200 From: Peter Zijlstra To: "H. Peter Anvin" Cc: Marco Elver , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86: Implement _THIS_IP_ using inline asm for 32-bit Message-ID: <20260521102023.GH3126523@noisy.programming.kicks-ass.net> References: <20260521000011.3926424-1-elver@google.com> <20260521070801.GE3126523@noisy.programming.kicks-ass.net> <7B8752AA-2A82-4ABD-BF90-B1A5DCF3F363@zytor.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7B8752AA-2A82-4ABD-BF90-B1A5DCF3F363@zytor.com> On Thu, May 21, 2026 at 02:55:22AM -0700, H. Peter Anvin wrote: > On May 21, 2026 12:08:01 AM PDT, Peter Zijlstra wrote: > >On Thu, May 21, 2026 at 02:00:09AM +0200, Marco Elver wrote: > >> Both GCC [1] and Clang [2] consider the generic version of _THIS_IP_ to > >> be broken: > >> > >> #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) > >> > >> In particular, the address of a label is only expected to be used with a > >> computed goto. > >> > >> While the generic version more or less works today, it is known to be > >> brittle and may break with current and future optimizations. For > >> example, Clang -O2 always returns 1 when this function is inlined: > >> > >> static inline unsigned long get_ip(void) > >> { return ({ __label__ __here; __here: (unsigned long)&&__here; }); } > >> > > > >Oh gawd :/ > > > >> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120071 [1] > >> Link: https://github.com/llvm/llvm-project/issues/138272 [2] > >> Signed-off-by: Marco Elver > >> --- > >> arch/x86/include/asm/linkage.h | 3 ++- > >> 1 file changed, 2 insertions(+), 1 deletion(-) > >> > >> diff --git a/arch/x86/include/asm/linkage.h b/arch/x86/include/asm/linkage.h > >> index a7294656ad90..bce3c6f4b94f 100644 > >> --- a/arch/x86/include/asm/linkage.h > >> +++ b/arch/x86/include/asm/linkage.h > >> @@ -13,11 +13,12 @@ > >> * The generic version tends to create spurious ENDBR instructions under > >> * certain conditions. > >> */ > >> -#define _THIS_IP_ ({ unsigned long __here; asm ("lea 0(%%rip), %0" : "=r" (__here)); __here; }) > >> +#define _THIS_IP_ ({ unsigned long __here; asm volatile("lea 0(%%rip), %0" : "=r" (__here)); __here; }) > >> #endif > >> > >> #ifdef CONFIG_X86_32 > >> #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) > >> +#define _THIS_IP_ ({ unsigned long __ip; asm volatile("call 1f\n1: pop %0" : "=r" (__ip)); __ip; }) > > > >This will mess up the RSB and cause bad performance ripple effects for a > >bit each use. Now, I don't think anybody still cares about performance > >on 32bit (I certainly don't), so perhaps this is fine. But urgh. > > Most microarchitectures do *not* have a problem with call/pop, as they > know that call with a zero offset is not going to return. The main > exception was the Pentium 4. Oh, that's good to know. Still the "1: mov $1b, %reg" thing is shorter, and generates the exact same code the compilers used to (and GCC still does). Isn't that a better option?