From nobody Sat Jul 25 23:06:00 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 66D573A6B85; Sun, 12 Jul 2026 12:44:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783860244; cv=none; b=LT/8ZxRwdPtme1fnDuBiq6RXcHfPM2jOGd+qDGz22Ohlv9XL/N33gXL6Azv5Qck2M6acL3FbY9+D5R1QJnAncWkCNDGoSTn7rEXOyuSStI5JZ3U+/l1TPJ+dKxDKm9T60qRCJlh9cmB1AlHxmxz0l9uBI47HEc7gehkwyZwm0d8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783860244; c=relaxed/simple; bh=5bwzvZx2bVG5I33PZ+Fok4VZLaYXjKaVF3w54oV5euk=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=MOclSUHlksmzVbCA0gFT8oKXXigrCL7Jh5NK89me/t1qDCDjgOAlwUXHQL0i2QSSb0e5AERk+eEdZuBMO/MVVLST2BCgHDrBwNIcPG/gfIQUOwmyqf42OnYAQagKNY3RM/FmwzG2z9AlQbux9L++j5Jo6GwAsSdL365zMthUQB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=DHR6lo6Z; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=s+VTH11E; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="DHR6lo6Z"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="s+VTH11E" Date: Sun, 12 Jul 2026 12:43:53 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1783860235; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WW8S3IUw6R9A1S9uGJ8/Zy+pDzlbvLikelgfDfYQQpg=; b=DHR6lo6Z6nO42fCvn2j6qVNNn8paxs7m2ddSpKHdyiuCfDJIOiHyUtNFhtZEYNZ3tNCx7R tmCtJM0b9/4rXLrePX7hRlaLqLeG1ClOtC2WUOrRThtQTwjaMMFl1dqkiHnSDZH9H2/2Pt xFM4XNmi3kOZaO+RmsAJQoIkAbm8i3nVkF1pcESG/BDq4awZ8LOt7xJA8vpl3re+tcTl6Y 2MqPQKmBF60slyMmxb/qOT/ybLTBLc6GvuispjSQWoQsLAEblsiTjSmA6OyLUYrixnXVYb ArNRepIzFy0VaQYYEuCcRhJ+bPriCTGCkEtR/zpTb7ee2Syu+O87xByLIAwcZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1783860235; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WW8S3IUw6R9A1S9uGJ8/Zy+pDzlbvLikelgfDfYQQpg=; b=s+VTH11EBC/NjPXOBiEcGOWdDC1Q4OW0iHyrXYfNGCz8baWAEhihileU44AHxOxKY1x708 HB7uNh64BpeHKeCw== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: core/entry] x86/entry: Simplify the syscall number logic Cc: Thomas Gleixner , "Mukesh Kumar Chaurasiya (IBM)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260707190254.545214398@kernel.org> References: <20260707190254.545214398@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178386023329.1844600.15133447576857554133.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the core/entry branch of tip: Commit-ID: fb419d53f2619e29bf4f96613d9a614e1c263736 Gitweb: https://git.kernel.org/tip/fb419d53f2619e29bf4f96613d9a614e1= c263736 Author: Thomas Gleixner AuthorDate: Tue, 07 Jul 2026 21:07:05 +02:00 Committer: Thomas Gleixner CommitterDate: Sun, 12 Jul 2026 12:38:02 +02:00 x86/entry: Simplify the syscall number logic Converting from int to long, back to int and then to unsigned int is confusing at best. None of this voodoo is required. Negative syscall numbers including -1 don't need any of this treatment and the low level ASM code already does the sign extension to 64-bit on a 64-bit kernel. The only point where signedness matters is the comparison against the maximum syscall number, but that can be simplified by just using a unsigned argument for the various syscall invocation functions. Signed-off-by: Thomas Gleixner Tested-by: Mukesh Kumar Chaurasiya (IBM) Link: https://patch.msgid.link/20260707190254.545214398@kernel.org --- arch/x86/entry/syscall_32.c | 26 ++++++++++--------------- arch/x86/entry/syscall_64.c | 34 ++++++++++++--------------------- arch/x86/include/asm/syscall.h | 2 +- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/arch/x86/entry/syscall_32.c b/arch/x86/entry/syscall_32.c index 68e2f13..92369d8 100644 --- a/arch/x86/entry/syscall_32.c +++ b/arch/x86/entry/syscall_32.c @@ -41,6 +41,8 @@ const sys_call_ptr_t sys_call_table[] =3D { #endif =20 #define __SYSCALL(nr, sym) case nr: return __ia32_##sym(regs); + +/* The unsigned int @nr argument is intentional as it creates denser code = in a 64-bit build */ static noinline long ia32_sys_call(const struct pt_regs *regs, unsigned in= t nr) { switch (nr) { @@ -49,7 +51,7 @@ static noinline long ia32_sys_call(const struct pt_regs *= regs, unsigned int nr) } } =20 -static __always_inline int syscall_32_enter(struct pt_regs *regs) +static __always_inline long syscall_32_enter(struct pt_regs *regs) { if (IS_ENABLED(CONFIG_IA32_EMULATION)) current_thread_info()->status |=3D TS_COMPAT; @@ -70,17 +72,11 @@ early_param("ia32_emulation", ia32_emulation_override_c= mdline); /* * Invoke a 32-bit syscall. Called with IRQs on in CT_STATE_KERNEL. */ -static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs, in= t nr) +static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs, un= signed long nr) { - /* - * Convert negative numbers to very high and thus out of range - * numbers for comparisons. - */ - unsigned int unr =3D nr; - - if (likely(unr < IA32_NR_syscalls)) { - unr =3D array_index_nospec(unr, IA32_NR_syscalls); - regs->ax =3D ia32_sys_call(regs, unr); + if (likely(nr < IA32_NR_syscalls)) { + nr =3D array_index_nospec(nr, IA32_NR_syscalls); + regs->ax =3D ia32_sys_call(regs, (unsigned int)nr); } } =20 @@ -126,7 +122,7 @@ static __always_inline bool int80_is_external(void) */ __visible noinstr void do_int80_emulation(struct pt_regs *regs) { - int nr; + long nr; =20 /* Kernel does not use INT $0x80! */ if (unlikely(!user_mode(regs))) { @@ -205,7 +201,7 @@ __visible noinstr void do_int80_emulation(struct pt_reg= s *regs) */ DEFINE_FREDENTRY_RAW(int80_emulation) { - int nr; + long nr; =20 enter_from_user_mode_randomize_stack(regs); =20 @@ -240,7 +236,7 @@ DEFINE_FREDENTRY_RAW(int80_emulation) /* Handles int $0x80 on a 32bit kernel */ __visible noinstr void do_int80_syscall_32(struct pt_regs *regs) { - int nr =3D syscall_32_enter(regs); + long nr =3D syscall_32_enter(regs); =20 /* * Subtlety here: if ptrace pokes something larger than 2^31-1 into @@ -260,7 +256,7 @@ __visible noinstr void do_int80_syscall_32(struct pt_re= gs *regs) =20 static noinstr bool __do_fast_syscall_32(struct pt_regs *regs) { - int nr =3D syscall_32_enter(regs); + long nr =3D syscall_32_enter(regs); int res; =20 enter_from_user_mode_randomize_stack(regs); diff --git a/arch/x86/entry/syscall_64.c b/arch/x86/entry/syscall_64.c index c716e0f..9a2762e 100644 --- a/arch/x86/entry/syscall_64.c +++ b/arch/x86/entry/syscall_64.c @@ -32,6 +32,8 @@ const sys_call_ptr_t sys_call_table[] =3D { #undef __SYSCALL =20 #define __SYSCALL(nr, sym) case nr: return __x64_##sym(regs); + +/* The unsigned int @nr argument is intentional as it creates denser code = */ static noinline long x64_sys_call(const struct pt_regs *regs, unsigned int= nr) { switch (nr) { @@ -52,39 +54,29 @@ static noinline long x32_sys_call(const struct pt_regs = *regs, unsigned int nr) #endif } =20 -static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr) +static __always_inline bool do_syscall_x64(struct pt_regs *regs, unsigned = long nr) { - /* - * Convert negative numbers to very high and thus out of range - * numbers for comparisons. - */ - unsigned int unr =3D nr; - - if (likely(unr < NR_syscalls)) { - unr =3D array_index_nospec(unr, NR_syscalls); - regs->ax =3D x64_sys_call(regs, unr); + if (likely(nr < NR_syscalls)) { + nr =3D array_index_nospec(nr, NR_syscalls); + regs->ax =3D x64_sys_call(regs, (unsigned int)nr); return true; } return false; } =20 -static __always_inline void do_syscall_x32(struct pt_regs *regs, int nr) +static __always_inline void do_syscall_x32(struct pt_regs *regs, unsigned = long nr) { - /* - * Adjust the starting offset of the table, and convert numbers - * < __X32_SYSCALL_BIT to very high and thus out of range - * numbers for comparisons. - */ - unsigned int xnr =3D nr - __X32_SYSCALL_BIT; + /* Adjust the starting offset of the table */ + nr -=3D __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); + if (IS_ENABLED(CONFIG_X86_X32_ABI) && likely(nr < X32_NR_syscalls)) { + nr =3D array_index_nospec(nr, X32_NR_syscalls); + regs->ax =3D x32_sys_call(regs, (unsigned 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, long nr) { nr =3D syscall_enter_from_user_mode_randomize_stack(regs, nr); =20 diff --git a/arch/x86/include/asm/syscall.h b/arch/x86/include/asm/syscall.h index 59a4060..cfe4251 100644 --- a/arch/x86/include/asm/syscall.h +++ b/arch/x86/include/asm/syscall.h @@ -164,7 +164,7 @@ static inline int syscall_get_arch(struct task_struct *= task) ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64; } =20 -bool do_syscall_64(struct pt_regs *regs, int nr); +bool do_syscall_64(struct pt_regs *regs, long nr); void do_int80_emulation(struct pt_regs *regs); =20 #endif /* CONFIG_X86_32 */