From nobody Fri Dec 19 04:06:48 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) Reviewed-by: Andrew Cooper --- 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 */ From nobody Fri Dec 19 04:06:48 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 9EEB4C001DF for ; Wed, 2 Aug 2023 11:04:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233985AbjHBLEU (ORCPT ); Wed, 2 Aug 2023 07:04:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232240AbjHBLES (ORCPT ); Wed, 2 Aug 2023 07:04:18 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1CAD1FC3 for ; Wed, 2 Aug 2023 04:04:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=apvcoInpYri3GsLvQN0fxRBQnpJkdbgo5+Z9wGvq+yo=; b=XEcRpPw5c69fzYWh1h/qfPIB+K 8dBdsEFZr8Y/HzyE158xsbYYZ+OO4A1CRwh7L8WE2J59E2svQNy6f7U4Ze319MLlwCE2PkU+VjdtT RUgQ+93ftb8xEIouyffxoqfLJ5KkxH8opEY+RlimBq0xjpp5/VogA3ZKhiScFH9+v7uEtCMbK5ibz auTRVjsdudL4fnvMEYokZwNMUvCEeyuk0fKZn/yb/xHueCegsaJ4qdXgGBtFCcwNrVR0EYe4J6uUZ qXrT0aM2VkL0TM5SnpdEw6c9JdYy8GVJnU7KZCXyNMO3/yOAfzL1l42g/Dvm16d7RJ+wXVP54rLFS ObeSoyjg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qR9eE-00FtVq-1a; Wed, 02 Aug 2023 11:04:11 +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 2659A3001DD; Wed, 2 Aug 2023 13:04:10 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id F3D4121000C9E; Wed, 2 Aug 2023 13:04:09 +0200 (CEST) Message-ID: <20230802110323.086971726@infradead.org> User-Agent: quilt/0.66 Date: Wed, 02 Aug 2023 12:55:47 +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 2/2] x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*() 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" Commit cb855971d717 ("x86/putuser: Provide room for padding") changed __put_user_nocheck_*() into proper functions but failed to note that SYM_FUNC_START() already provides ENDBR, rendering the explicit ENDBR superfluous. Fixes: cb855971d717 ("x86/putuser: Provide room for padding") Reported-by: David Kaplan Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Andrew Cooper --- arch/x86/lib/putuser.S | 4 ---- 1 file changed, 4 deletions(-) --- a/arch/x86/lib/putuser.S +++ b/arch/x86/lib/putuser.S @@ -56,7 +56,6 @@ SYM_FUNC_END(__put_user_1) EXPORT_SYMBOL(__put_user_1) =20 SYM_FUNC_START(__put_user_nocheck_1) - ENDBR ASM_STAC 2: movb %al,(%_ASM_CX) xor %ecx,%ecx @@ -76,7 +75,6 @@ SYM_FUNC_END(__put_user_2) EXPORT_SYMBOL(__put_user_2) =20 SYM_FUNC_START(__put_user_nocheck_2) - ENDBR ASM_STAC 4: movw %ax,(%_ASM_CX) xor %ecx,%ecx @@ -96,7 +94,6 @@ SYM_FUNC_END(__put_user_4) EXPORT_SYMBOL(__put_user_4) =20 SYM_FUNC_START(__put_user_nocheck_4) - ENDBR ASM_STAC 6: movl %eax,(%_ASM_CX) xor %ecx,%ecx @@ -119,7 +116,6 @@ SYM_FUNC_END(__put_user_8) EXPORT_SYMBOL(__put_user_8) =20 SYM_FUNC_START(__put_user_nocheck_8) - ENDBR ASM_STAC 9: mov %_ASM_AX,(%_ASM_CX) #ifdef CONFIG_X86_32