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 424F9262A6 for ; Thu, 21 May 2026 07:09:21 +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=1779347364; cv=none; b=eU8dzNWFOcjxwDXrw5FDlcCDVCkJBtmIcX4BemcRC1T9hxqNQl2wXS2BF/YZHCmVdZKu2o0U1syf8NP1O9g3LxFoyPMf/xBHB64f5+CFWPYGGVhaI/Cu10PafupXAhYgtxSmTpMVjICgPcA2VohXHflSwFjWi0BAWJTK1lMxZfk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779347364; c=relaxed/simple; bh=b7BuyRNx8PjyuSOg2ZRtFdmPn1Lvmmn3uQv6tg+abaI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O0EEFw+0hjYMD9Jq56E9iLySRyGBkzmpb471iPmA76uGLGzbKC+5My8VC4IGoRrcUjMQRmxVICczd6Tr8tFtFiHoGQiB2VJDf0Lt2nDfF+AbDOi8lf1R1aoT411ynp9YigBQnK89qFwrwIRGSglTYDv/4Lox00cV/zFRjzCmdN0= 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=fkA0m0tZ; 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="fkA0m0tZ" 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=f9McKS4nlLCCtiv76TmzKtcTunkszlPk8DG3sGZZo0o=; b=fkA0m0tZtfq4pGfXSW4XNhYvys VSSsgvClXlblgNUYTII1LlHVFLQ7z86OkHWC4hY6RPZBm2UTEsBXa+OKwzrP8i41ZuIL31bmDTSGg 2LLdx+IiW1SJWE/KEJYwhYmnTan1F/PGbShPqbqtZR6UF6xP8vlZ0X2blaUi0cJq5GNhDqffRTWLr imesl4j1ct5kJr6BLUspIkZ+rS7U2Fc0A5LtR3U1uHFvNyTjiMyJE6r7+ovHzUQqfbS3ezIzDGCQL oHwQqeIfBv9NZclwmMeRlNY2NhpxGr5CHZyut/+gjIrln/cqOAXf9QEl289j4CiVxh4p1ob4QZMyO UwHgHXVw==; Received: from 2001-1c00-8d85-4b00-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:4b00:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wPxVj-00000008Dtj-2yci; Thu, 21 May 2026 07:09:15 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 98DEB300446; Thu, 21 May 2026 09:08:01 +0200 (CEST) Date: Thu, 21 May 2026 09:08:01 +0200 From: Peter Zijlstra To: Marco Elver Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86: Implement _THIS_IP_ using inline asm for 32-bit Message-ID: <20260521070801.GE3126523@noisy.programming.kicks-ass.net> References: <20260521000011.3926424-1-elver@google.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: <20260521000011.3926424-1-elver@google.com> 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.