From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) (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 AEE66371895 for ; Fri, 19 Jun 2026 10:24:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781864669; cv=none; b=RqIkmKQGVBbSMQ/cn9AYQPq/7hajF4XZW8JB6kATqHZclvuEYaDzyC1O2RgHfvlM3n7joIcf7T19s406nt55FNCKdJ4Dvjrmk7Ue2M4vn27CxnfZEsFKStFHbi04iReCuZkEvaqMTSHM/ltyXio3sHqgP1LRWJXKH1fO/5YW2bk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781864669; c=relaxed/simple; bh=2r4PTO+3zNY6/cFa8bICMUPrFY/d8JgqOHRl7aikyJw=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=RaNWSBUYA22uQfgGychJ7pNMSLjoc6T8xKVcEVFXzPXqnwdc81YaIO2mkAuj+t5QJyRUGPsq9OfWPYqR0i4kR2X7Ebet4yI5+3Tay27/9HA0dOZrK3Uv+kmO2VmVH3x8fPClexTBAhPshmzK5ZdH4nS0ZWzki3aLRLyJMhoPIeE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com; spf=pass smtp.mailfrom=zytor.com; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b=j2OIFp5y; arc=none smtp.client-ip=198.137.202.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zytor.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="j2OIFp5y" Received: from ehlo.thunderbird.net (c-76-133-66-138.hsd1.ca.comcast.net [76.133.66.138]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 65JANv78858353 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Fri, 19 Jun 2026 03:23:57 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 65JANv78858353 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2026052701; t=1781864638; bh=5RXLBhdsAbhQzrf//QkrA5CRgENg4+I70t3Ng3Kj8eg=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=j2OIFp5y8i9775CwWqY8LkCH/V+vInnyoKp5azEZOOqlDSiYNk8efACtRtd+gNGC9 Vf4Z/gGy7XGAxFortjMeR4cWRV9Yat8dWElvhKGrXrlaGEeCylwTMb6ZKEPWSLvUHf Si9aucLNVa/NXsQ4e6zMrzOaRoidREbCClQYbPtjXc1NaF7SqJ08TgF52wMklgo/p8 WJPM+3xm3yTGxQI6VhPLhxA3MmyoEBNkllx+U8e8c7RBqmIpbpMA8d+pDmM86KeoA3 YysxkPD+X79J5LDg9+3FrIVDnUUgQ5GryEA39cQ+Jb/cgwOMc7klzKz/+B3xxTROwM nzlzu9UivB2PQ== Date: Fri, 19 Jun 2026 03:23:52 -0700 From: "H. Peter Anvin" To: Peter Zijlstra , Linus Torvalds CC: tglx@kernel.org, mingo@redhat.com, bp@alien8.de, Nathan Chancellor , Calvin Owens , Dave Hansen , x86-ML , LKML Subject: =?US-ASCII?Q?Re=3A_8aeb879baf12_-_significant_syst?= =?US-ASCII?Q?em_call_latency_regression=2C_bisected?= User-Agent: K-9 Mail for Android In-Reply-To: <20260619081427.GD49529@noisy.programming.kicks-ass.net> References: <20260613085919.GF42921@noisy.programming.kicks-ass.net> <203E61B7-290F-4F87-860F-B352D0072703@zytor.com> <20260616082814.GQ48970@noisy.programming.kicks-ass.net> <20260617123718.GM49951@noisy.programming.kicks-ass.net> <20260619081427.GD49529@noisy.programming.kicks-ass.net> Message-ID: <6B52EE70-FB51-4053-B888-DD3EC6D66C54@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=utf-8 Content-Transfer-Encoding: quoted-printable On June 19, 2026 1:14:27 AM PDT, Peter Zijlstra wr= ote: >On Wed, Jun 17, 2026 at 02:37:18PM +0200, Peter Zijlstra wrote: >> - makes -fno-jump-tables unconditional >> - removes array_index_nospec() from the syscall dispatch > >FWIW, this also allows making all SYSCALLs __noendbr, very much >including the 'legacy' sys_call_table :-) > >Compile tested with IA32_EMULATION=3Dn and reliably yields: > >vmlinux=2Eo: warning: objtool: sys_call_table+0x0: data relocation to !EN= DBR: __x64_sys_read+0x0 >=2E=2E=2E >vmlinux=2Eo: warning: objtool: sys_call_table+0xeb0: data relocation to != ENDBR: __x64_sys_listns+0x0 > >(which is just one little objtool patch away from being fixed) > >and boots fine (in kvm)=2E > >--- >diff --git a/arch/x86/Makefile b/arch/x86/Makefile >index 598f178102ee=2E=2Eb154a2a20eb2 100644 >--- a/arch/x86/Makefile >+++ b/arch/x86/Makefile >@@ -90,17 +90,8 @@ CC_FLAGS_FPU +=3D -mhard-float > endif >=20 > ifeq ($(CONFIG_X86_KERNEL_IBT),y) >-# >-# Kernel IBT has S_CET=2ENOTRACK_EN=3D0, as such the compilers must not = generate >-# NOTRACK prefixes=2E Current generation compilers unconditionally emplo= y NOTRACK >-# for jump-tables, as such, disable jump-tables for now=2E >-# >-# (jump-tables are implicitly disabled by RETPOLINE) >-# >-# https://gcc=2Egnu=2Eorg/bugzilla/show_bug=2Ecgi?id=3D104816 >-# >-KBUILD_CFLAGS +=3D $(call cc-option,-fcf-protection=3Dbranch -fno-jump-t= ables) >-KBUILD_RUSTFLAGS +=3D -Zcf-protection=3Dbranch $(if $(call rustc-min-ver= sion,109300),-Cjump-tables=3Dn,-Zno-jump-tables) >+KBUILD_CFLAGS +=3D $(call cc-option,-fcf-protection=3Dbranch) >+KBUILD_RUSTFLAGS +=3D -Zcf-protection=3Dbranch > else > KBUILD_CFLAGS +=3D $(call cc-option,-fcf-protection=3Dnone) > endif >@@ -173,6 +164,13 @@ endif > KBUILD_RUSTFLAGS +=3D -Ccode-model=3Dkernel >=20 > percpu_seg :=3D gs >+ >+ # Due to retpolines and cf-protection=3Dbranch's implicit NOTRACK usage >+ # for jump-tables, blanked disable jump-tables for all x86_64 builds to >+ # get a consistent behaviour across configurations=2E This allows >+ # removing some array_index_nospec() usage=2E >+ KBUILD_CFLAGS +=3D -fno-jump-tables >+ KBUILD_RISTFLAGS +=3D $(if $(call rustc-min-version,109300),-Cjump-tabl= es=3Dn,-Zno-jump-tables) > endif >=20 > ifeq ($(CONFIG_STACKPROTECTOR),y) >@@ -209,15 +207,6 @@ KBUILD_CFLAGS +=3D -fno-asynchronous-unwind-tables > ifdef CONFIG_MITIGATION_RETPOLINE > KBUILD_CFLAGS +=3D $(RETPOLINE_CFLAGS) > KBUILD_RUSTFLAGS +=3D $(RETPOLINE_RUSTFLAGS) >- # Additionally, avoid generating expensive indirect jumps which >- # are subject to retpolines for small number of switch cases=2E >- # LLVM turns off jump table generation by default when under >- # retpoline builds, however, gcc does not for x86=2E This has >- # only been fixed starting from gcc stable version 8=2E4=2E0 and >- # onwards, but not for older ones=2E See gcc bug #86952=2E >- ifndef CONFIG_CC_IS_CLANG >- KBUILD_CFLAGS +=3D -fno-jump-tables >- endif > endif >=20 > ifdef CONFIG_MITIGATION_SLS >diff --git a/arch/x86/entry/syscall_64=2Ec b/arch/x86/entry/syscall_64=2E= c >index 71f032504e73=2E=2E7e87947e12be 100644 >--- a/arch/x86/entry/syscall_64=2Ec >+++ b/arch/x86/entry/syscall_64=2Ec >@@ -8,9 +8,10 @@ > #include > #include > #include >+#include >=20 >-#define __SYSCALL(nr, sym) extern long __x64_##sym(const struct pt_regs = *); >-#define __SYSCALL_NORETURN(nr, sym) extern long __noreturn __x64_##sym(c= onst struct pt_regs *); >+#define __SYSCALL(nr, sym) extern __noendbr long __x64_##sym(const struc= t pt_regs *); >+#define __SYSCALL_NORETURN(nr, sym) extern __noendbr long __noreturn __x= 64_##sym(const struct pt_regs *); > #include > #ifdef CONFIG_X86_X32_ABI > #include >@@ -25,30 +26,47 @@ > * kernel/trace/trace_syscalls=2Ec still wants to know the system > * call address=2E > */ >-#define __SYSCALL(nr, sym) __x64_##sym, >+#define __SYSCALL(nr, sym) (void *)&__x64_##sym, > const sys_call_ptr_t sys_call_table[] =3D { > #include > }; > #undef __SYSCALL >=20 > #define __SYSCALL(nr, sym) case nr: return __x64_##sym(regs); >-long x64_sys_call(const struct pt_regs *regs, unsigned int nr) >+static noinstr long x64_sys_call(const struct pt_regs *regs, unsigned in= t nr) > { >+ /* >+ * Because -fno-jump-tables, this compiles into a binary branch tree >+ * rather than a jump-table=2E As such @nr is not used as an array >+ * index=2E Additionally, this is an out-of-line function on purpose, >+ * such that all the actual syscall function calls are tail-calls, >+ * returning to our caller for the common bits=2E >+ */ >+ instrumentation_begin(); > switch (nr) { > #include > default: return __x64_sys_ni_syscall(regs); > } >+ instrumentation_end(); > } >=20 > #ifdef CONFIG_X86_X32_ABI >-long x32_sys_call(const struct pt_regs *regs, unsigned int nr) >+static noinstr long x32_sys_call(const struct pt_regs *regs, unsigned in= t nr) > { >+ instrumentation_begin(); > switch (nr) { > #include > default: return __x64_sys_ni_syscall(regs); > } >+ instrumentation_end(); >+} >+#else >+static __always_inline long x32_sys_call(const struct pt_regs *regs, uns= igned int nr) >+{ >+ return __x64_sys_ni_syscall(regs); > } > #endif >+#undef __SYSCALL >=20 > static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr) > { >@@ -59,7 +77,6 @@ static __always_inline bool do_syscall_x64(struct pt_re= gs *regs, int nr) > unsigned int unr =3D nr; >=20 > if (likely(unr < NR_syscalls)) { >- unr =3D array_index_nospec(unr, NR_syscalls); > regs->ax =3D x64_sys_call(regs, unr); > return true; > } >@@ -76,7 +93,6 @@ static __always_inline bool do_syscall_x32(struct pt_re= gs *regs, int nr) > unsigned int xnr =3D nr - __X32_SYSCALL_BIT; >=20 > if (IS_ENABLED(CONFIG_X86_X32_ABI) && likely(xnr < X32_NR_syscalls)) { >- xnr =3D array_index_nospec(xnr, X32_NR_syscalls); > regs->ax =3D x32_sys_call(regs, xnr); > return true; > } >@@ -84,7 +100,7 @@ static __always_inline bool do_syscall_x32(struct pt_r= egs *regs, int nr) > } >=20 > /* Returns true to return using SYSRET, or false to use IRET */ >-__visible noinstr bool do_syscall_64(struct pt_regs *regs, int nr) >+__visible noinstr bool do_syscall_64(struct pt_regs *regs, int nr) > { > nr =3D syscall_enter_from_user_mode(regs, nr); >=20 >diff --git a/arch/x86/include/asm/syscall_wrapper=2Eh b/arch/x86/include/= asm/syscall_wrapper=2Eh >index 7e88705e907f=2E=2E1639fbc02680 100644 >--- a/arch/x86/include/asm/syscall_wrapper=2Eh >+++ b/arch/x86/include/asm/syscall_wrapper=2Eh >@@ -7,9 +7,10 @@ > #define _ASM_X86_SYSCALL_WRAPPER_H >=20 > #include >+#include >=20 >-extern long __x64_sys_ni_syscall(const struct pt_regs *regs); >-extern long __ia32_sys_ni_syscall(const struct pt_regs *regs); >+extern __noendbr long __x64_sys_ni_syscall(const struct pt_regs *regs); >+extern __noendbr long __ia32_sys_ni_syscall(const struct pt_regs *regs); >=20 > /* > * Instead of the generic __SYSCALL_DEFINEx() definition, the x86 versio= n takes >@@ -83,15 +84,15 @@ extern long __ia32_sys_ni_syscall(const struct pt_reg= s *regs); > __MAP(x, __SC_TYPE, __VA_ARGS__)) \ >=20 > #define __SYS_STUB0(abi, name) \ >- long __##abi##_##name(const struct pt_regs *regs); \ >+ long __noendbr __##abi##_##name(const struct pt_regs *regs); \ > ALLOW_ERROR_INJECTION(__##abi##_##name, ERRNO); \ >- long __##abi##_##name(const struct pt_regs *regs) \ >+ long __noendbr __##abi##_##name(const struct pt_regs *regs) \ > __alias(__do_##name); >=20 > #define __SYS_STUBx(abi, name, =2E=2E=2E) \ >- long __##abi##_##name(const struct pt_regs *regs); \ >+ long __noendbr __##abi##_##name(const struct pt_regs *regs); \ > ALLOW_ERROR_INJECTION(__##abi##_##name, ERRNO); \ >- long __##abi##_##name(const struct pt_regs *regs) \ >+ long __noendbr __##abi##_##name(const struct pt_regs *regs) \ > { \ > return __se_##name(__VA_ARGS__); \ > } >@@ -257,8 +258,8 @@ extern long __ia32_sys_ni_syscall(const struct pt_reg= s *regs); > * For VSYSCALLS, we need to declare these three syscalls with the new > * pt_regs-based calling convention for in-kernel use=2E > */ >-long __x64_sys_getcpu(const struct pt_regs *regs); >-long __x64_sys_gettimeofday(const struct pt_regs *regs); >-long __x64_sys_time(const struct pt_regs *regs); >+long __noendbr __x64_sys_getcpu(const struct pt_regs *regs); >+long __noendbr __x64_sys_gettimeofday(const struct pt_regs *regs); >+long __noendbr __x64_sys_time(const struct pt_regs *regs); >=20 > #endif /* _ASM_X86_SYSCALL_WRAPPER_H */ *Very* nice indeed=2E=20 I was definitely hoping this would be the next step=2E