From nobody Tue Dec 16 13:07:24 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA545C001DF for ; Wed, 2 Aug 2023 11:04:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234027AbjHBLEZ (ORCPT ); Wed, 2 Aug 2023 07:04:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234005AbjHBLEW (ORCPT ); Wed, 2 Aug 2023 07:04:22 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9831E1FC2 for ; Wed, 2 Aug 2023 04:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=OJDFzby0ZnN0v9KkGBrIpBxHQA0M/SWomoqJPt4Ln9Y=; b=kzTXafX28IJou13ECVF9CGzks4 9p3lDuem3HsbpaPsV6FxeKtg4Mg7vi8wa/2r3mDzHa5P6voZ4HQqDtWTDl8oa85++z2HpVto9WPoP L1rRgkFBrrBjTzPNHa9+vtZyZhSDliH4BesAb0Uf74WBDNtbTGxC/GGZnZ3+K3NY5Ul97NU7ckqV8 yMjAGmW4kNV3sdlmYOBDxQ70LWwfzWF5UEOh4Bbl+3kZyCEl79QgqcgvLwLL5TeVoXaCt+fFHaDGb /JANK/uTbwqL5qy/ceTeVJPnXMQNHatYUQzAej5EI/Ok2VkYPJJhfwKQweAJHlXL4MH3nPtWJN3Ou pSSZvOIA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qR9eE-00EaIn-Fy; Wed, 02 Aug 2023 11:04:10 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 283E6300301; Wed, 2 Aug 2023 13:04:10 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id F1F1021000C90; Wed, 2 Aug 2023 13:04:09 +0200 (CEST) Message-ID: <20230802110323.016197440@infradead.org> User-Agent: quilt/0.66 Date: Wed, 02 Aug 2023 12:55:46 +0200 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, jpoimboe@kernel.org, andrew.cooper3@citrix.com, David.Kaplan@amd.com Subject: [PATCH 1/2] x86/ibt: Suppress spurious ENDBR References: <20230802105545.594381530@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It was reported that under certain circumstances GCC emits ENDBR instructions for _THIS_IP_ usage. Specifically, when it appears at the start of a basic block -- but not elsewhere. Since _THIS_IP_ is never used for control flow, these ENDBR instructions are completely superfluous. Override the _THIS_IP_ definition for x86_64 to avoid this. Less ENDBR instructions is better. Fixes: 156ff4a544ae ("x86/ibt: Base IBT bits") Reported-by: David Kaplan Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/linkage.h | 8 ++++++++ include/linux/instruction_pointer.h | 5 +++++ 2 files changed, 13 insertions(+) --- a/arch/x86/include/asm/linkage.h +++ b/arch/x86/include/asm/linkage.h @@ -8,6 +8,14 @@ #undef notrace #define notrace __attribute__((no_instrument_function)) =20 +#ifdef CONFIG_64BIT +/* + * The generic version tends to create spurious ENDBR instructions under + * certain conditions. + */ +#define _THIS_IP_ ({ unsigned long __here; asm ("lea 0(%%rip), %0" : "=3Dr= " (__here)); __here; }) +#endif + #ifdef CONFIG_X86_32 #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) #endif /* CONFIG_X86_32 */ --- a/include/linux/instruction_pointer.h +++ b/include/linux/instruction_pointer.h @@ -2,7 +2,12 @@ #ifndef _LINUX_INSTRUCTION_POINTER_H #define _LINUX_INSTRUCTION_POINTER_H =20 +#include + #define _RET_IP_ (unsigned long)__builtin_return_address(0) + +#ifndef _THIS_IP_ #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) +#endif =20 #endif /* _LINUX_INSTRUCTION_POINTER_H */