x86/entry: Break up common.c
Subsystems (4)
cover x86/entry: Break up common.c
The syscall dispatch code originally was put into entry/common.c so that common code for entry from and exit to userspace could be inlined. That entry code has since been moved to the core kernel. There is no longer a need to keep this code together, so move it to more appropriate places.
This is code reorganization only, no functional changes.
Brian Gerst (5):
x86/xen: Move Xen upcall handler x86/syscall/32: Move 32-bit syscall dispatch code x86/syscall/64: Move 64-bit syscall dispatch code x86/syscall/x32: Move x32 syscall table x86/syscall: Move sys_ni_syscall()
arch/x86/entry/Makefile | 8 +- arch/x86/entry/common.c | 524 ----------------------------------- arch/x86/entry/syscall_32.c | 336 +++++++++++++++++++++- arch/x86/entry/syscall_64.c | 116 +++++++- arch/x86/entry/syscall_x32.c | 25 -- arch/x86/kernel/process.c | 5 + arch/x86/xen/enlighten_pv.c | 46 +++ include/xen/xen-ops.h | 19 ++ 8 files changed, 522 insertions(+), 557 deletions(-) delete mode 100644 arch/x86/entry/common.c delete mode 100644 arch/x86/entry/syscall_x32.c
base-commit: d08c0d55110b7cbac186e5fa94b0c6d5f4d7905e
Signature · 1 line
2.48.1
PATCH 1/5 x86/xen: Move Xen upcall handler
Move the upcall handler to Xen-specific files.
No functional changes.
--- arch/x86/entry/common.c | 72 ------------------------------------- arch/x86/xen/enlighten_pv.c | 46 ++++++++++++++++++++++++ include/xen/xen-ops.h | 19 ++++++++++ 3 files changed, 65 insertions(+), 72 deletions(-)
arch/x86/entry/common.c +0 -72
@@ -21,11 +21,6 @@#include <linux/uaccess.h> #include <linux/init.h> -#ifdef CONFIG_XEN_PV -#include <xen/xen-ops.h> -#include <xen/events.h> -#endif -#include <asm/apic.h> #include <asm/desc.h> #include <asm/traps.h>
@@ -455,70 +450,3 @@ SYSCALL_DEFINE0(ni_syscall) {return -ENOSYS ; } - -#ifdef CONFIG_XEN_PV -#ifndef CONFIG_PREEMPTION -/* -* Some hypercalls issued by the toolstack can take many 10s of -* seconds. Allow tasks running hypercalls via the privcmd driver to -* be voluntarily preempted even if full kernel preemption is -* disabled. -* -* Such preemptible hypercalls are bracketed by -* xen_preemptible_hcall_begin() and xen_preemptible_hcall_end() -* calls. -*/ -DEFINE_PER_CPU (bool, xen_in_preemptible_hcall); -EXPORT_SYMBOL_GPL (xen_in_preemptible_hcall); - -/* -* In case of scheduling the flag must be cleared and restored after -* returning from schedule as the task might move to a different CPU. -*/ -static __always_inline bool get_and_clear_inhcall(void) -{ -bool inhcall =__this_cpu_read (xen_in_preemptible_hcall); - -__this_cpu_write (xen_in_preemptible_hcall, false); -return inhcall; -} - -static __always_inline void restore_inhcall(bool inhcall) -{ -__this_cpu_write (xen_in_preemptible_hcall, inhcall); -} -#else -static __always_inline bool get_and_clear_inhcall(void) { return false; } -static __always_inline void restore_inhcall(bool inhcall) { } -#endif - -static void __xen_pv_evtchn_do_upcall (struct pt_regs *regs) -{ -struct pt_regs *old_regs =set_irq_regs (regs); - -inc_irq_stat (irq_hv_callback_count); - -xen_evtchn_do_upcall (); - -set_irq_regs (old_regs); -} - -__visible noinstr void xen_pv_evtchn_do_upcall(struct pt_regs *regs) -{ -irqentry_state_t state =irqentry_enter (regs); -bool inhcall; - -instrumentation_begin (); -run_sysvec_on_irqstack_cond (__xen_pv_evtchn_do_upcall, regs); - - inhcall =get_and_clear_inhcall (); -if (inhcall && !WARN_ON_ONCE (state.exit_rcu)) { -irqentry_exit_cond_resched (); -instrumentation_end (); -restore_inhcall (inhcall); - }else { -instrumentation_end (); -irqentry_exit (regs, state); - } -} -#endif /* CONFIG_XEN_PV */
arch/x86/xen/enlighten_pv.c +46 -0
64 lines not on this page · raw message
include/xen/xen-ops.h +19 -0
@@ -208,10 +208,29 @@ static inline void xen_preemptible_hcall_end(void) __this_cpu_write(xen_in_preemptible_hcall, false); } +/* +* In case of scheduling the flag must be cleared and restored after +* returning from schedule as the task might move to a different CPU. +*/ +static __always_inline bool get_and_clear_inhcall(void) +{ +bool inhcall =__this_cpu_read (xen_in_preemptible_hcall); + +__this_cpu_write (xen_in_preemptible_hcall, false); +return inhcall; +} + +static __always_inline void restore_inhcall(bool inhcall) +{ +__this_cpu_write (xen_in_preemptible_hcall, inhcall); +} +#else static inline void xen_preemptible_hcall_begin (void ) { }static inline void xen_preemptible_hcall_end (void ) { } +static __always_inline bool get_and_clear_inhcall(void) { return false; } +static __always_inline void restore_inhcall(bool inhcall) { }#endif /* CONFIG_XEN_PV && !CONFIG_PREEMPTION */
Signature · 1 line
2.48.1
Juergen Gross
maintainerRe: [PATCH 1/5] x86/xen: Move Xen upcall handler
Quoted 195 lines · Brian Gerst
Move the upcall handler to Xen-specific files.
No functional changes.
Signed-off-by Brian Gerst <[email protected]>Cc Juergen Gross <[email protected]>Cc Boris Ostrovsky <[email protected]>--- arch/x86/entry/common.c | 72 ------------------------------------- arch/x86/xen/enlighten_pv.c | 46 ++++++++++++++++++++++++ include/xen/xen-ops.h | 19 ++++++++++ 3 files changed, 65 insertions(+), 72 deletions(-)arch/x86/entry/common.c +0
-72@@ -21,11 +21,6 @@#include <linux/uaccess.h> #include <linux/init.h> -#ifdef CONFIG_XEN_PV -#include <xen/xen-ops.h> -#include <xen/events.h> -#endif -#include <asm/apic.h> #include <asm/desc.h> #include <asm/traps.h> @@ -455,70 +450,3 @@ SYSCALL_DEFINE0(ni_syscall) {return -ENOSYS ; } - -#ifdef CONFIG_XEN_PV -#ifndef CONFIG_PREEMPTION -/* -* Some hypercalls issued by the toolstack can take many 10s of -* seconds. Allow tasks running hypercalls via the privcmd driver to -* be voluntarily preempted even if full kernel preemption is -* disabled. -* -* Such preemptible hypercalls are bracketed by -* xen_preemptible_hcall_begin() and xen_preemptible_hcall_end() -* calls. -*/ -DEFINE_PER_CPU (bool, xen_in_preemptible_hcall); -EXPORT_SYMBOL_GPL (xen_in_preemptible_hcall); - -/* -* In case of scheduling the flag must be cleared and restored after -* returning from schedule as the task might move to a different CPU. -*/ -static __always_inline bool get_and_clear_inhcall(void) -{ -bool inhcall =__this_cpu_read (xen_in_preemptible_hcall); - -__this_cpu_write (xen_in_preemptible_hcall, false); -return inhcall; -} - -static __always_inline void restore_inhcall(bool inhcall) -{ -__this_cpu_write (xen_in_preemptible_hcall, inhcall); -} -#else -static __always_inline bool get_and_clear_inhcall(void) { return false; } -static __always_inline void restore_inhcall(bool inhcall) { } -#endif - -static void __xen_pv_evtchn_do_upcall (struct pt_regs *regs) -{ -struct pt_regs *old_regs =set_irq_regs (regs); - -inc_irq_stat (irq_hv_callback_count); - -xen_evtchn_do_upcall (); - -set_irq_regs (old_regs); -} - -__visible noinstr void xen_pv_evtchn_do_upcall(struct pt_regs *regs) -{ -irqentry_state_t state =irqentry_enter (regs); -bool inhcall; - -instrumentation_begin (); -run_sysvec_on_irqstack_cond (__xen_pv_evtchn_do_upcall, regs); - - inhcall =get_and_clear_inhcall (); -if (inhcall && !WARN_ON_ONCE (state.exit_rcu)) { -irqentry_exit_cond_resched (); -instrumentation_end (); -restore_inhcall (inhcall); - }else { -instrumentation_end (); -irqentry_exit (regs, state); - } -} -#endif /* CONFIG_XEN_PV */ arch/x86/xen/enlighten_pv.c +46
-0@@ -73,6 +73,7 @@#include <asm/mwait.h> #include <asm/pci_x86.h> #include <asm/cpu.h> +#include <asm/irq_stack.h> #ifdef CONFIG_X86_IOPL_IOPERM #include <asm/io_bitmap.h> #endif @@ -94,6 +95,21 @@ void *xen_initial_gdt;static int xen_cpu_up_prepare_pv (unsigned int cpu);static int xen_cpu_dead_pv (unsigned int cpu); +#ifndef CONFIG_PREEMPTION +/* +* Some hypercalls issued by the toolstack can take many 10s of +* seconds. Allow tasks running hypercalls via the privcmd driver to +* be voluntarily preempted even if full kernel preemption is +* disabled. +* +* Such preemptible hypercalls are bracketed by +* xen_preemptible_hcall_begin() and xen_preemptible_hcall_end() +* calls. +*/ +DEFINE_PER_CPU (bool, xen_in_preemptible_hcall); +EXPORT_SYMBOL_GPL (xen_in_preemptible_hcall); +#endif +struct tls_descs {struct desc_struct desc[3 ]; };@@ -687,6 +703,36 @@ DEFINE_IDTENTRY_RAW(xenpv_exc_machine_check) }#endif +static void __xen_pv_evtchn_do_upcall (struct pt_regs *regs) +{ +struct pt_regs *old_regs =set_irq_regs (regs); + +inc_irq_stat (irq_hv_callback_count); + +xen_evtchn_do_upcall (); + +set_irq_regs (old_regs); +} + +__visible noinstr void xen_pv_evtchn_do_upcall(struct pt_regs *regs) +{ +irqentry_state_t state =irqentry_enter (regs); +bool inhcall; + +instrumentation_begin (); +run_sysvec_on_irqstack_cond (__xen_pv_evtchn_do_upcall, regs); + + inhcall =get_and_clear_inhcall (); +if (inhcall && !WARN_ON_ONCE (state.exit_rcu)) { +irqentry_exit_cond_resched (); +instrumentation_end (); +restore_inhcall (inhcall); + }else { +instrumentation_end (); +irqentry_exit (regs, state); + } +} +struct trap_array_entry {void (*orig)(void );void (*xen)(void );include/xen/xen-ops.h +16
-0@@ -208,10 +208,29 @@ static inline void xen_preemptible_hcall_end(void)__this_cpu_write (xen_in_preemptible_hcall, false); } +/* +* In case of scheduling the flag must be cleared and restored after +* returning from schedule as the task might move to a different CPU. +*/ +static __always_inline bool get_and_clear_inhcall(void) +{ +bool inhcall =__this_cpu_read (xen_in_preemptible_hcall); + +__this_cpu_write (xen_in_preemptible_hcall, false); +return inhcall; +} + +static __always_inline void restore_inhcall(bool inhcall) +{ +__this_cpu_write (xen_in_preemptible_hcall, inhcall); +}
include/xen/xen-ops.h static inline void xen_preemptible_hcall_end(void) · line 236
Quoted 10 lines
include/xen/xen-ops.h +3
-0+#else static inline void xen_preemptible_hcall_begin (void ) { }static inline void xen_preemptible_hcall_end (void ) { } +static __always_inline bool get_and_clear_inhcall(void) { return false; } +static __always_inline void restore_inhcall(bool inhcall) { }#endif /* CONFIG_XEN_PV && !CONFIG_PREEMPTION */
I don't see a reason to put those two functions into xen_ops.h, as they are used by xen_pv_evtchn_do_upcall() only.
Please move them to enlighten_pv.c, too.
Juergen
[tip: x86/cpu] x86/xen: Move Xen upcall handler to Xen specific code files
In reply to Brian GerstThe following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 827dc2e36172e978d6b1c701b04bee56881f54bf Gitweb: https://git.kernel.org/tip/827dc2e36172e978d6b1c701b04bee56881f54bf Author: Brian Gerst <[email protected]> AuthorDate: Thu, 13 Mar 2025 14:22:32 -04:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 14 Mar 2025 10:32:51 +01:00
x86/xen: Move Xen upcall handler to Xen specific code files
Move the upcall handler to Xen-specific files.
No functional changes.
--- arch/x86/entry/common.c | 72 +------------------------------------ arch/x86/xen/enlighten_pv.c | 46 +++++++++++++++++++++++- include/xen/xen-ops.h | 19 ++++++++++- 3 files changed, 65 insertions(+), 72 deletions(-)
arch/x86/entry/common.c +0 -72
@@ -21,11 +21,6 @@#include <linux/uaccess.h> #include <linux/init.h> -#ifdef CONFIG_XEN_PV -#include <xen/xen-ops.h> -#include <xen/events.h> -#endif -#include <asm/apic.h> #include <asm/desc.h> #include <asm/traps.h>
@@ -455,70 +450,3 @@ SYSCALL_DEFINE0(ni_syscall) {return -ENOSYS ; } - -#ifdef CONFIG_XEN_PV -#ifndef CONFIG_PREEMPTION -/* -* Some hypercalls issued by the toolstack can take many 10s of -* seconds. Allow tasks running hypercalls via the privcmd driver to -* be voluntarily preempted even if full kernel preemption is -* disabled. -* -* Such preemptible hypercalls are bracketed by -* xen_preemptible_hcall_begin() and xen_preemptible_hcall_end() -* calls. -*/ -DEFINE_PER_CPU (bool, xen_in_preemptible_hcall); -EXPORT_SYMBOL_GPL (xen_in_preemptible_hcall); - -/* -* In case of scheduling the flag must be cleared and restored after -* returning from schedule as the task might move to a different CPU. -*/ -static __always_inline bool get_and_clear_inhcall(void) -{ -bool inhcall =__this_cpu_read (xen_in_preemptible_hcall); - -__this_cpu_write (xen_in_preemptible_hcall, false); -return inhcall; -} - -static __always_inline void restore_inhcall(bool inhcall) -{ -__this_cpu_write (xen_in_preemptible_hcall, inhcall); -} -#else -static __always_inline bool get_and_clear_inhcall(void) { return false; } -static __always_inline void restore_inhcall(bool inhcall) { } -#endif - -static void __xen_pv_evtchn_do_upcall (struct pt_regs *regs) -{ -struct pt_regs *old_regs =set_irq_regs (regs); - -inc_irq_stat (irq_hv_callback_count); - -xen_evtchn_do_upcall (); - -set_irq_regs (old_regs); -} - -__visible noinstr void xen_pv_evtchn_do_upcall(struct pt_regs *regs) -{ -irqentry_state_t state =irqentry_enter (regs); -bool inhcall; - -instrumentation_begin (); -run_sysvec_on_irqstack_cond (__xen_pv_evtchn_do_upcall, regs); - - inhcall =get_and_clear_inhcall (); -if (inhcall && !WARN_ON_ONCE (state.exit_rcu)) { -irqentry_exit_cond_resched (); -instrumentation_end (); -restore_inhcall (inhcall); - }else { -instrumentation_end (); -irqentry_exit (regs, state); - } -} -#endif /* CONFIG_XEN_PV */
arch/x86/xen/enlighten_pv.c +46 -0
64 lines not on this page · raw message
include/xen/xen-ops.h +19 -0
@@ -208,10 +208,29 @@ static inline void xen_preemptible_hcall_end(void) __this_cpu_write(xen_in_preemptible_hcall, false); } +/* +* In case of scheduling the flag must be cleared and restored after +* returning from schedule as the task might move to a different CPU. +*/ +static __always_inline bool get_and_clear_inhcall(void) +{ +bool inhcall =__this_cpu_read (xen_in_preemptible_hcall); + +__this_cpu_write (xen_in_preemptible_hcall, false); +return inhcall; +} + +static __always_inline void restore_inhcall(bool inhcall) +{ +__this_cpu_write (xen_in_preemptible_hcall, inhcall); +} +#else static inline void xen_preemptible_hcall_begin (void ) { }static inline void xen_preemptible_hcall_end (void ) { } +static __always_inline bool get_and_clear_inhcall(void) { return false; } +static __always_inline void restore_inhcall(bool inhcall) { }#endif /* CONFIG_XEN_PV && !CONFIG_PREEMPTION */
Jürgen Groß
maintainerRe: [tip: x86/cpu] x86/xen: Move Xen upcall handler to Xen specific code files
Quoted 15 lines · On 14.03.25 10:47, tip-bot2 for Brian Gerst wrote:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 827dc2e36172e978d6b1c701b04bee56881f54bf Gitweb: https://git.kernel.org/tip/827dc2e36172e978d6b1c701b04bee56881f54bf Author: Brian Gerst <[email protected]> AuthorDate: Thu, 13 Mar 2025 14:22:32 -04:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 14 Mar 2025 10:32:51 +01:00x86/xen: Move Xen upcall handler to Xen specific code files
Move the upcall handler to Xen-specific files.
No functional changes.
Quoted 9 lines
Signed-off-by Brian Gerst <[email protected]>Signed-off-by Ingo Molnar <[email protected]>Reviewed-by Sohil Mehta <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Juergen Gross <[email protected]>Cc H. Peter Anvin <[email protected]>Cc Linus Torvalds <[email protected]>Cc Josh Poimboeuf <[email protected]>
Why do I even request changes if such a request is being ignored?
Please note that my request wasn't about something which should be handled in a followup patch. I was asking to NOT move the code into multiple files, but to keep it in one file as it was originally.
Juergen
Re: [tip: x86/cpu] x86/xen: Move Xen upcall handler to Xen specific code files
Quoted 26 lines · Jürgen Groß
Quoted 15 lines · On 14.03.25 10:47, tip-bot2 for Brian Gerst wrote:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 827dc2e36172e978d6b1c701b04bee56881f54bf Gitweb: https://git.kernel.org/tip/827dc2e36172e978d6b1c701b04bee56881f54bf Author: Brian Gerst <[email protected]> AuthorDate: Thu, 13 Mar 2025 14:22:32 -04:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 14 Mar 2025 10:32:51 +01:00x86/xen: Move Xen upcall handler to Xen specific code files
Move the upcall handler to Xen-specific files.
No functional changes.
Quoted 9 lines
Signed-off-by Brian Gerst <[email protected]>Signed-off-by Ingo Molnar <[email protected]>Reviewed-by Sohil Mehta <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Juergen Gross <[email protected]>Cc H. Peter Anvin <[email protected]>Cc Linus Torvalds <[email protected]>Cc Josh Poimboeuf <[email protected]>
Quoted 1 line
Why do I even request changes if such a request is being ignored?
I missed your mail, sorry.
Quoted 3 lines
Please note that my request wasn't about something which should be handled in a followup patch. I was asking to NOT move the code into multiple files, but to keep it in one file as it was originally.
I agree with you that this code looks better in enlighten_pv.c, but there's no reason to keep arch/x86/entry/common.c, agreed?
I've rolled back these changes and will wait for -v2.
Thanks,
Ingo
Jürgen Groß
maintainerRe: [tip: x86/cpu] x86/xen: Move Xen upcall handler to Xen specific code files
Quoted 31 lines · Ingo Molnar
Quoted 26 lines · Jürgen Groß
Quoted 15 lines · On 14.03.25 10:47, tip-bot2 for Brian Gerst wrote:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 827dc2e36172e978d6b1c701b04bee56881f54bf Gitweb: https://git.kernel.org/tip/827dc2e36172e978d6b1c701b04bee56881f54bf Author: Brian Gerst <[email protected]> AuthorDate: Thu, 13 Mar 2025 14:22:32 -04:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 14 Mar 2025 10:32:51 +01:00x86/xen: Move Xen upcall handler to Xen specific code files
Move the upcall handler to Xen-specific files.
No functional changes.
Quoted 9 lines
Signed-off-by Brian Gerst <[email protected]>Signed-off-by Ingo Molnar <[email protected]>Reviewed-by Sohil Mehta <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Juergen Gross <[email protected]>Cc H. Peter Anvin <[email protected]>Cc Linus Torvalds <[email protected]>Cc Josh Poimboeuf <[email protected]>Quoted 1 line
Why do I even request changes if such a request is being ignored?
Quoted 8 lines
I missed your mail, sorry.
Quoted 3 lines
Please note that my request wasn't about something which should be handled in a followup patch. I was asking to NOT move the code into multiple files, but to keep it in one file as it was originally.
I agree with you that this code looks better in
enlighten_pv.c, but there's no reason to keeparch/x86/entry/common.c, agreed?
Absolutely.
Quoted 2 lines
I've rolled back these changes and will wait for -v2.
Thanks
Juergen
PATCH 2/5 x86/syscall/32: Move 32-bit syscall dispatch code
In reply to Brian GerstMove the 32-bit syscall dispatch code to syscall_32.c.
No functional changes.
--- arch/x86/entry/Makefile | 2 + arch/x86/entry/common.c | 321 ---------------------------------- arch/x86/entry/syscall_32.c | 336 +++++++++++++++++++++++++++++++++++- 3 files changed, 336 insertions(+), 323 deletions(-)
arch/x86/entry/Makefile +2 -0
@@ -8,8 +8,10 @@ UBSAN_SANITIZE := n KCOV_INSTRUMENT := n CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_syscall_32.o = $(CC_FLAGS_FTRACE) CFLAGS_common.o += -fno-stack-protector +CFLAGS_syscall_32.o += -fno-stack-protector obj-y := entry.o entry_$(BITS).o syscall_$(BITS).o obj-y += common.o
arch/x86/entry/common.c +0 -321
327 lines not on this page · raw message
arch/x86/entry/syscall_32.c +334 -2
347 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH 2/5] x86/syscall/32: Move 32-bit syscall dispatch code
Quoted 8 lines · Brian Gerst
SYSCALL_DEFINE0(ni_syscall)
{arch/x86/entry/common.c +0
-0return -ENOSYS ;arch/x86/entry/syscall_32.c +0
-0
arch/x86/entry/syscall_32.c line 8
Quoted 10 lines
arch/x86/entry/syscall_32.c +8
-2@@ -1,10 +1,23 @@ -// SPDX-License-Identifier: GPL-2.0 -/* System call table for i386. */ +// SPDX-License-Identifier: GPL-2.0-only +/* +* 32-bit system call dispatch +* +* Copyright (c) 2015 Andrew Lutomirski +* +* Based on asm and ptrace code by many authors. The code here originated +* in ptrace.c and signal.c.
Wondering if we can skip copying over some of these old comments? As the file grows, it's hard to discerne what specific code originated where. For example, the FRED code is all new.
Quoted 143 lines
arch/x86/entry/syscall_32.c +143
-0+#ifdef CONFIG_IA32_EMULATION +static __always_inline bool int80_is_external(void) +{ + const unsigned int offs = (0x80 / 32) * 0x10; + const u32 bit = BIT(0x80 % 32); + + /* The local APIC on XENPV guests is fake */ + if (cpu_feature_enabled(X86_FEATURE_XENPV)) + return false; + + /* + * If vector 0x80 is set in the APIC ISR then this is an external + * interrupt. Either from broken hardware or injected by a VMM. + * + * Note: In guest mode this is only valid for secure guests where + * the secure module fully controls the vAPIC exposed to the guest. + */ + return apic_read(APIC_ISR + offs) & bit; +} + +/** + * do_int80_emulation - 32-bit legacy syscall C entry from asm + * @regs: syscall arguments in struct pt_args on the stack. + * + * This entry point can be used by 32-bit and 64-bit programs to perform + * 32-bit system calls. Instances of INT $0x80 can be found inline in + * various programs and libraries. It is also used by the vDSO's + * __kernel_vsyscall fallback for hardware that doesn't support a faster + * entry method. Restarted 32-bit system calls also fall back to INT + * $0x80 regardless of what instruction was originally used to do the + * system call. + * + * This is considered a slow path. It is not used by most libc + * implementations on modern hardware except during process startup. + * + * The arguments for the INT $0x80 based syscall are on stack in the + * pt_regs structure: + * eax: system call number + * ebx, ecx, edx, esi, edi, ebp: arg1 - arg 6 + */ +__visible noinstr void do_int80_emulation(struct pt_regs *regs) +{ + int nr; + + /* Kernel does not use INT $0x80! */ + if (unlikely(!user_mode(regs))) { + irqentry_enter(regs); + instrumentation_begin(); + panic("Unexpected external interrupt 0x80\n"); + } + + /* + * Establish kernel context for instrumentation, including for + * int80_is_external() below which calls into the APIC driver. + * Identical for soft and external interrupts. + */ + enter_from_user_mode(regs); + + instrumentation_begin(); + add_random_kstack_offset(); + + /* Validate that this is a soft interrupt to the extent possible */ + if (unlikely(int80_is_external())) + panic("Unexpected external interrupt 0x80\n"); + + /* + * The low level idtentry code pushed -1 into regs::orig_ax + * and regs::ax contains the syscall number. + * + * User tracing code (ptrace or signal handlers) might assume + * that the regs::orig_ax contains a 32-bit number on invoking + * a 32-bit syscall. + * + * Establish the syscall convention by saving the 32bit truncated + * syscall number in regs::orig_ax and by invalidating regs::ax. + */ + regs->orig_ax = regs->ax & GENMASK(31, 0); + regs->ax = -ENOSYS; + + nr = syscall_32_enter(regs); + + local_irq_enable(); + nr = syscall_enter_from_user_mode_work(regs, nr); + do_syscall_32_irqs_on(regs, nr); + + instrumentation_end(); + syscall_exit_to_user_mode(regs); +} + +#ifdef CONFIG_X86_FRED +/* + * A FRED-specific INT80 handler is warranted for the follwing reasons: + * + * 1) As INT instructions and hardware interrupts are separate event + * types, FRED does not preclude the use of vector 0x80 for external + * interrupts. As a result, the FRED setup code does not reserve + * vector 0x80 and calling int80_is_external() is not merely + * suboptimal but actively incorrect: it could cause a system call + * to be incorrectly ignored. + * + * 2) It is called only for handling vector 0x80 of event type + * EVENT_TYPE_SWINT and will never be called to handle any external + * interrupt (event type EVENT_TYPE_EXTINT). + * + * 3) FRED has separate entry flows depending on if the event came from + * user space or kernel space, and because the kernel does not use + * INT insns, the FRED kernel entry handler fred_entry_from_kernel() + * falls through to fred_bad_type() if the event type is + * EVENT_TYPE_SWINT, i.e., INT insns. So if the kernel is handling + * an INT insn, it can only be from a user level. + * + * 4) int80_emulation() does a CLEAR_BRANCH_HISTORY. While FRED will + * likely take a different approach if it is ever needed: it + * probably belongs in either fred_intx()/ fred_other() or + * asm_fred_entrypoint_user(), depending on if this ought to be done + * for all entries from userspace or only system + * calls. + * + * 5) INT $0x80 is the fast path for 32-bit system calls under FRED. + */ +DEFINE_FREDENTRY_RAW(int80_emulation) +{ + int nr; + + enter_from_user_mode(regs); + + instrumentation_begin(); + add_random_kstack_offset(); + + /* + * FRED pushed 0 into regs::orig_ax and regs::ax contains the + * syscall number. + * + * User tracing code (ptrace or signal handlers) might assume + * that the regs::orig_ax contains a 32-bit number on invoking + * a 32-bit syscall. + * + * Establish the syscall convention by saving the 32bit truncated + * syscall number in regs::orig_ax and by invalidating regs::ax. + */ + regs->orig_ax = regs->ax & GENMASK(31, 0); + regs->ax = -ENOSYS; +
arch/x86/entry/syscall_32.c long ia32_sys_call(const struct pt_regs *regs, unsigned int nr) · line 248
Quoted 10 lines
arch/x86/entry/syscall_32.c +10
-0+ nr =syscall_32_enter (regs); + +local_irq_enable (); + nr =syscall_enter_from_user_mode_work (regs, nr); +do_syscall_32_irqs_on (regs, nr); + +instrumentation_end (); + syscall_exit_to_user_mode(regs); +} +#endif
Nit: Would it be useful to add /* CONFIG_X86_FRED */ here since there are nested #ifdefs?
Quoted 23 lines
arch/x86/entry/syscall_32.c +23
-0+#else /* CONFIG_IA32_EMULATION */ + +/* Handles int $0x80 on a 32bit kernel */ +__visible noinstr void do_int80_syscall_32(struct pt_regs *regs) +{ +int nr =syscall_32_enter (regs); + +add_random_kstack_offset (); +/* +* Subtlety here: if ptrace pokes something larger than 2^31-1 into +* orig_ax, the int return value truncates it. This matches +* the semantics of syscall_get_nr(). +*/ + nr =syscall_enter_from_user_mode (regs, nr); +instrumentation_begin (); + +do_syscall_32_irqs_on (regs, nr); + +instrumentation_end (); +syscall_exit_to_user_mode (regs); +} +#endif /* !CONFIG_IA32_EMULATION */ +
Re: [PATCH 2/5] x86/syscall/32: Move 32-bit syscall dispatch code
Quoted 17 lines · Sohil Mehta
Quoted 14 lines · Brian Gerst
SYSCALL_DEFINE0(ni_syscall){ return -ENOSYS;arch/x86/entry/syscall_32.c +4
-2@@ -1,10 +1,23 @@ -// SPDX-License-Identifier: GPL-2.0 -/* System call table for i386. */ +// SPDX-License-Identifier: GPL-2.0-only +/* +* 32-bit system call dispatch +*
Quoted 8 lines
arch/x86/entry/syscall_32.c line 8
Quoted 4 lines
arch/x86/entry/syscall_32.c +4
-0+* Copyright (c) 2015 Andrew Lutomirski +* +* Based on asm and ptrace code by many authors. The code here originated +* in ptrace.c and signal.c. Wondering if we can skip copying over some of these old comments? As the file grows, it's hard to discerne what specific code originated where. For example, the FRED code is all new.
I wasn't sure what the appropriate thing would be so I just copied it over. The git history is probably a better way to attribute this though.
Quoted 149 lines
Quoted 149 lines
arch/x86/entry/syscall_32.c +148
-0+#ifdef CONFIG_IA32_EMULATION +static __always_inline bool int80_is_external(void) +{ + const unsigned int offs = (0x80 / 32) * 0x10; + const u32 bit = BIT(0x80 % 32); + + /* The local APIC on XENPV guests is fake */ + if (cpu_feature_enabled(X86_FEATURE_XENPV)) + return false; + + /* + * If vector 0x80 is set in the APIC ISR then this is an external + * interrupt. Either from broken hardware or injected by a VMM. + * + * Note: In guest mode this is only valid for secure guests where + * the secure module fully controls the vAPIC exposed to the guest. + */ + return apic_read(APIC_ISR + offs) & bit; +} + +/** + * do_int80_emulation - 32-bit legacy syscall C entry from asm + * @regs: syscall arguments in struct pt_args on the stack. + * + * This entry point can be used by 32-bit and 64-bit programs to perform + * 32-bit system calls. Instances of INT $0x80 can be found inline in + * various programs and libraries. It is also used by the vDSO's + * __kernel_vsyscall fallback for hardware that doesn't support a faster + * entry method. Restarted 32-bit system calls also fall back to INT + * $0x80 regardless of what instruction was originally used to do the + * system call. + * + * This is considered a slow path. It is not used by most libc + * implementations on modern hardware except during process startup. + * + * The arguments for the INT $0x80 based syscall are on stack in the + * pt_regs structure: + * eax: system call number + * ebx, ecx, edx, esi, edi, ebp: arg1 - arg 6 + */ +__visible noinstr void do_int80_emulation(struct pt_regs *regs) +{ + int nr; + + /* Kernel does not use INT $0x80! */ + if (unlikely(!user_mode(regs))) { + irqentry_enter(regs); + instrumentation_begin(); + panic("Unexpected external interrupt 0x80\n"); + } + + /* + * Establish kernel context for instrumentation, including for + * int80_is_external() below which calls into the APIC driver. + * Identical for soft and external interrupts. + */ + enter_from_user_mode(regs); + + instrumentation_begin(); + add_random_kstack_offset(); + + /* Validate that this is a soft interrupt to the extent possible */ + if (unlikely(int80_is_external())) + panic("Unexpected external interrupt 0x80\n"); + + /* + * The low level idtentry code pushed -1 into regs::orig_ax + * and regs::ax contains the syscall number. + * + * User tracing code (ptrace or signal handlers) might assume + * that the regs::orig_ax contains a 32-bit number on invoking + * a 32-bit syscall. + * + * Establish the syscall convention by saving the 32bit truncated + * syscall number in regs::orig_ax and by invalidating regs::ax. + */ + regs->orig_ax = regs->ax & GENMASK(31, 0); + regs->ax = -ENOSYS; + + nr = syscall_32_enter(regs); + + local_irq_enable(); + nr = syscall_enter_from_user_mode_work(regs, nr); + do_syscall_32_irqs_on(regs, nr); + + instrumentation_end(); + syscall_exit_to_user_mode(regs); +} + +#ifdef CONFIG_X86_FRED +/* + * A FRED-specific INT80 handler is warranted for the follwing reasons: + * + * 1) As INT instructions and hardware interrupts are separate event + * types, FRED does not preclude the use of vector 0x80 for external + * interrupts. As a result, the FRED setup code does not reserve + * vector 0x80 and calling int80_is_external() is not merely + * suboptimal but actively incorrect: it could cause a system call + * to be incorrectly ignored. + * + * 2) It is called only for handling vector 0x80 of event type + * EVENT_TYPE_SWINT and will never be called to handle any external + * interrupt (event type EVENT_TYPE_EXTINT). + * + * 3) FRED has separate entry flows depending on if the event came from + * user space or kernel space, and because the kernel does not use + * INT insns, the FRED kernel entry handler fred_entry_from_kernel() + * falls through to fred_bad_type() if the event type is + * EVENT_TYPE_SWINT, i.e., INT insns. So if the kernel is handling + * an INT insn, it can only be from a user level. + * + * 4) int80_emulation() does a CLEAR_BRANCH_HISTORY. While FRED will + * likely take a different approach if it is ever needed: it + * probably belongs in either fred_intx()/ fred_other() or + * asm_fred_entrypoint_user(), depending on if this ought to be done + * for all entries from userspace or only system + * calls. + * + * 5) INT $0x80 is the fast path for 32-bit system calls under FRED. + */ +DEFINE_FREDENTRY_RAW(int80_emulation) +{ + int nr; + + enter_from_user_mode(regs); + + instrumentation_begin(); + add_random_kstack_offset(); + + /* + * FRED pushed 0 into regs::orig_ax and regs::ax contains the + * syscall number. + * + * User tracing code (ptrace or signal handlers) might assume + * that the regs::orig_ax contains a 32-bit number on invoking + * a 32-bit syscall. + * + * Establish the syscall convention by saving the 32bit truncated + * syscall number in regs::orig_ax and by invalidating regs::ax. + */ + regs->orig_ax = regs->ax & GENMASK(31, 0); + regs->ax = -ENOSYS; + + nr = syscall_32_enter(regs); + + local_irq_enable(); + nr = syscall_enter_from_user_mode_work(regs, nr); + do_syscall_32_irqs_on(regs, nr);
Quoted 8 lines
arch/x86/entry/syscall_32.c long ia32_sys_call(const struct pt_regs *regs, unsigned int nr) · line 248
Quoted 5 lines
arch/x86/entry/syscall_32.c +5
-0+ +instrumentation_end (); + syscall_exit_to_user_mode(regs); +} +#endif Nit: Would it be useful to add /*
CONFIG_X86_FRED*/ here since there are nested #ifdefs?
These patches should be as close to a copy and paste as possible, so that it's easy to prove that nothing changes. This could be a followup patch later though.
Brian Gerst
Re: [PATCH 2/5] x86/syscall/32: Move 32-bit syscall dispatch code
Quoted 27 lines · Brian Gerst
Quoted 17 lines · Sohil Mehta
Quoted 14 lines · Brian Gerst
SYSCALL_DEFINE0(ni_syscall){ return -ENOSYS;arch/x86/entry/syscall_32.c +4
-2@@ -1,10 +1,23 @@ -// SPDX-License-Identifier: GPL-2.0 -/* System call table for i386. */ +// SPDX-License-Identifier: GPL-2.0-only +/* +* 32-bit system call dispatch +* Quoted 8 lines
arch/x86/entry/syscall_32.c line 8
Quoted 4 lines
arch/x86/entry/syscall_32.c +4
-0+* Copyright (c) 2015 Andrew Lutomirski +* +* Based on asm and ptrace code by many authors. The code here originated +* in ptrace.c and signal.c. Wondering if we can skip copying over some of these old comments? As the file grows, it's hard to discerne what specific code originated where. For example, the FRED code is all new.
Quoted 3 lines
I wasn't sure what the appropriate thing would be so I just copied it over. The git history is probably a better way to attribute this though.
I suppose we could trim some of the old comments in followup patches, as they'll be preserved in the Git log and often aren't really accurate or particularly informative in the current code context.
Thanks,
Ingo
[tip: x86/cpu] x86/syscall/32: Move the 32-bit syscall dispatch code to arch/x86/entry/syscall_32.c
In reply to Brian GerstThe following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: beea77e898b2a6a0d67b01ae24dcfa46a3dfc089 Gitweb: https://git.kernel.org/tip/beea77e898b2a6a0d67b01ae24dcfa46a3dfc089 Author: Brian Gerst <[email protected]> AuthorDate: Thu, 13 Mar 2025 14:22:33 -04:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 14 Mar 2025 10:32:51 +01:00
x86/syscall/32: Move the 32-bit syscall dispatch code to arch/x86/entry/syscall_32.c
Move the 32-bit syscall dispatch code to syscall_32.c.
No functional changes.
--- arch/x86/entry/Makefile | 2 +- arch/x86/entry/common.c | 321 +--------------------------------- arch/x86/entry/syscall_32.c | 336 ++++++++++++++++++++++++++++++++++- 3 files changed, 336 insertions(+), 323 deletions(-)
arch/x86/entry/Makefile +2 -0
@@ -8,8 +8,10 @@ UBSAN_SANITIZE := n KCOV_INSTRUMENT := n CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_syscall_32.o = $(CC_FLAGS_FTRACE) CFLAGS_common.o += -fno-stack-protector +CFLAGS_syscall_32.o += -fno-stack-protector obj-y := entry.o entry_$(BITS).o syscall_$(BITS).o obj-y += common.o
arch/x86/entry/common.c +0 -321
327 lines not on this page · raw message
arch/x86/entry/syscall_32.c +334 -2
347 lines not on this page · raw message
PATCH 3/5 x86/syscall/64: Move 64-bit syscall dispatch code
In reply to Brian GerstMove the 64-bit syscall dispatch code to syscall_64.c.
No functional changes.
--- arch/x86/entry/Makefile | 2 + arch/x86/entry/common.c | 93 -------------------------------- arch/x86/entry/syscall_64.c | 103 +++++++++++++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 95 deletions(-)
arch/x86/entry/Makefile +2 -0
@@ -9,9 +9,11 @@ KCOV_INSTRUMENT := n CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_syscall_32.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_syscall_64.o = $(CC_FLAGS_FTRACE) CFLAGS_common.o += -fno-stack-protector CFLAGS_syscall_32.o += -fno-stack-protector +CFLAGS_syscall_64.o += -fno-stack-protector obj-y := entry.o entry_$(BITS).o syscall_$(BITS).o obj-y += common.o
arch/x86/entry/common.c +0 -93
99 lines not on this page · raw message
arch/x86/entry/syscall_64.c +101 -2
114 lines not on this page · raw message
Signature · 1 line
2.48.1
[tip: x86/cpu] x86/syscall/64: Move the 64-bit syscall dispatch code to arch/x86/entry/syscall_64.c
The following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: daffd8a21847b2a37da6b4d23753a4581543c575 Gitweb: https://git.kernel.org/tip/daffd8a21847b2a37da6b4d23753a4581543c575 Author: Brian Gerst <[email protected]> AuthorDate: Thu, 13 Mar 2025 14:22:34 -04:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 14 Mar 2025 10:32:51 +01:00
x86/syscall/64: Move the 64-bit syscall dispatch code to arch/x86/entry/syscall_64.c
Move the 64-bit syscall dispatch code to syscall_64.c.
No functional changes.
--- arch/x86/entry/Makefile | 2 +- arch/x86/entry/common.c | 93 +-------------------------------- arch/x86/entry/syscall_64.c | 103 ++++++++++++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 95 deletions(-)
arch/x86/entry/Makefile +2 -0
@@ -9,9 +9,11 @@ KCOV_INSTRUMENT := n CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_syscall_32.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_syscall_64.o = $(CC_FLAGS_FTRACE) CFLAGS_common.o += -fno-stack-protector CFLAGS_syscall_32.o += -fno-stack-protector +CFLAGS_syscall_64.o += -fno-stack-protector obj-y := entry.o entry_$(BITS).o syscall_$(BITS).o obj-y += common.o
arch/x86/entry/common.c +0 -93
99 lines not on this page · raw message
arch/x86/entry/syscall_64.c +101 -2
114 lines not on this page · raw message
PATCH 4/5 x86/syscall/x32: Move x32 syscall table
In reply to Brian GerstSince commit:
2e958a8a510d ("x86/entry/x32: Rename __x32_compat_sys_* to
__x64_compat_sys_*"),
the ABI prefix for x32 syscalls is the same as native 64-bit syscalls. Move the x32 syscall table to syscall_64.c
No functional changes.
--- arch/x86/entry/Makefile | 1 - arch/x86/entry/syscall_64.c | 13 +++++++++++++ arch/x86/entry/syscall_x32.c | 25 ------------------------- 3 files changed, 13 insertions(+), 26 deletions(-) delete mode 100644 arch/x86/entry/syscall_x32.c
arch/x86/entry/Makefile +0 -1
@@ -27,4 +27,3 @@ CFLAGS_REMOVE_entry_fred.o += -pg $(CC_FLAGS_FTRACE) obj-$(CONFIG_X86_FRED) += entry_64_fred.o entry_fred.o obj-$(CONFIG_IA32_EMULATION) += entry_64_compat.o syscall_32.o -obj-$(CONFIG_X86_X32_ABI) += syscall_x32.o
arch/x86/entry/syscall_64.c +13 -0
@@ -19,6 +19,9 @@#define __SYSCALL (nr, sym) extern long __x64_##sym(const struct pt_regs *);#define __SYSCALL_NORETURN (nr, sym) extern long __noreturn __x64_##sym(const struct pt_regs *);#include <asm/syscalls_64.h> +#ifdef CONFIG_X86_X32_ABI +#include <asm/syscalls_x32.h> +#endif #undef __SYSCALL#undef __SYSCALL_NORETURN
@@ -44,6 +47,16 @@ long x64_sys_call(const struct pt_regs *regs, unsigned int nr) } }; +#ifdef CONFIG_X86_X32_ABI +long x32_sys_call (const struct pt_regs *regs,unsigned int nr) +{ +switch (nr) { +#include <asm/syscalls_x32.h> +default :return __x64_sys_ni_syscall (regs); + } +}; +#endif + static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr) {/*
arch/x86/entry/syscall_x32.c deleted +0 -25
@@ -1,25 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* System call table for x32 ABI. */ - -#include <linux/linkage.h> -#include <linux/sys.h> -#include <linux/cache.h> -#include <linux/syscalls.h> -#include <asm/syscall.h> - -#define __SYSCALL (nr, sym) extern long __x64_##sym(const struct pt_regs *); -#define __SYSCALL_NORETURN (nr, sym) extern long __noreturn __x64_##sym(const struct pt_regs *); -#include <asm/syscalls_x32.h> -#undef __SYSCALL - -#undef __SYSCALL_NORETURN -#define __SYSCALL_NORETURN __SYSCALL - -#define __SYSCALL (nr, sym) case nr: return __x64_##sym(regs); -long x32_sys_call (const struct pt_regs *regs,unsigned int nr) -{ -switch (nr) { -#include <asm/syscalls_x32.h> -default :return __x64_sys_ni_syscall (regs); - } -};
Signature · 1 line
2.48.1
Re: [PATCH 4/5] x86/syscall/x32: Move x32 syscall table
Quoted 43 lines · Brian Gerst
Since commit:
2e958a8a510d("x86/entry/x32: Rename __x32_compat_sys_* to__x64_compat_sys_*"),the ABI prefix for x32 syscalls is the same as native 64-bit syscalls. Move the x32 syscall table to
syscall_64.cNo functional changes.
Signed-off-by Brian Gerst <[email protected]>--- arch/x86/entry/Makefile | 1 - arch/x86/entry/syscall_64.c | 13 +++++++++++++ arch/x86/entry/syscall_x32.c | 25 ------------------------- 3 files changed, 13 insertions(+), 26 deletions(-) delete mode 100644 arch/x86/entry/syscall_x32.carch/x86/entry/Makefile +0
-1@@ -27,4 +27,3 @@ CFLAGS_REMOVE_entry_fred.o += -pg $(CC_FLAGS_FTRACE) obj-$(CONFIG_X86_FRED) += entry_64_fred.o entry_fred.o obj-$(CONFIG_IA32_EMULATION) += entry_64_compat.o syscall_32.o -obj-$(CONFIG_X86_X32_ABI) += syscall_x32.oarch/x86/entry/syscall_64.c +3
-0@@ -19,6 +19,9 @@#define __SYSCALL (nr, sym) extern long __x64_##sym(const struct pt_regs *);#define __SYSCALL_NORETURN (nr, sym) extern long __noreturn __x64_##sym(const struct pt_regs *);#include <asm/syscalls_64.h> +#ifdef CONFIG_X86_X32_ABI +#include <asm/syscalls_x32.h> +#endif #undef __SYSCALL#undef __SYSCALL_NORETURN@@ -44,6 +47,16 @@ long x64_sys_call(const struct pt_regs *regs, unsigned int nr) }
arch/x86/entry/syscall_64.c long x64_sys_call(const struct pt_regs *regs, unsigned int nr) · line 57
Quoted 10 lines
arch/x86/entry/syscall_64.c +8
-0}; +#ifdef CONFIG_X86_X32_ABI +long x32_sys_call (const struct pt_regs *regs,unsigned int nr) +{ +switch (nr) { +#include <asm/syscalls_x32.h> +default :return __x64_sys_ni_syscall (regs); + } +};
There seems to be a stray semicolon here. The original code also has it but it doesn't seem necessary.
Quoted 36 lines
arch/x86/entry/syscall_64.c +2
-0+#endif + static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr) {/* arch/x86/entry/syscall_x32.c deleted +0
-25@@ -1,25 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* System call table for x32 ABI. */ - -#include <linux/linkage.h> -#include <linux/sys.h> -#include <linux/cache.h> -#include <linux/syscalls.h> -#include <asm/syscall.h> - -#define __SYSCALL (nr, sym) extern long __x64_##sym(const struct pt_regs *); -#define __SYSCALL_NORETURN (nr, sym) extern long __noreturn __x64_##sym(const struct pt_regs *); -#include <asm/syscalls_x32.h> -#undef __SYSCALL - -#undef __SYSCALL_NORETURN -#define __SYSCALL_NORETURN __SYSCALL - -#define __SYSCALL (nr, sym) case nr: return __x64_##sym(regs); -long x32_sys_call (const struct pt_regs *regs,unsigned int nr) -{ -switch (nr) { -#include <asm/syscalls_x32.h> -default :return __x64_sys_ni_syscall (regs); - } -};
Re: [PATCH 4/5] x86/syscall/x32: Move x32 syscall table
Quoted 11 lines · Sohil Mehta
arch/x86/entry/syscall_64.c long x64_sys_call(const struct pt_regs *regs, unsigned int nr) · line 57
Quoted 8 lines
arch/x86/entry/syscall_64.c +8
-0+#ifdef CONFIG_X86_X32_ABI +long x32_sys_call (const struct pt_regs *regs,unsigned int nr) +{ +switch (nr) { +#include <asm/syscalls_x32.h> +default :return __x64_sys_ni_syscall (regs); + } +};There seems to be a stray semicolon here. The original code also has it but it doesn't seem necessary.
Yeah, and this should be done in a followup patch.
Thanks,
Ingo
Re: [PATCH 4/5] x86/syscall/x32: Move x32 syscall table
In reply to Sohil MehtaQuoted 11 lines · Sohil Mehta
arch/x86/entry/syscall_64.c long x64_sys_call(const struct pt_regs *regs, unsigned int nr) · line 57
Quoted 8 lines
arch/x86/entry/syscall_64.c +8
-0+#ifdef CONFIG_X86_X32_ABI +long x32_sys_call (const struct pt_regs *regs,unsigned int nr) +{ +switch (nr) { +#include <asm/syscalls_x32.h> +default :return __x64_sys_ni_syscall (regs); + } +};There seems to be a stray semicolon here. The original code also has it but it doesn't seem necessary.
BTW., seeing that you've gone through this series with a fine comb I've added your Reviewed-by tag to the series (with the caveat that the details you've pointed out will be addressed in followup patches). Let me know if that's not OK.
Thanks,
Ingo
Re: [PATCH 4/5] x86/syscall/x32: Move x32 syscall table
Quoted 15 lines · Ingo Molnar
Quoted 11 lines · Sohil Mehta
arch/x86/entry/syscall_64.c long x64_sys_call(const struct pt_regs *regs, unsigned int nr) · line 57
Quoted 8 lines
arch/x86/entry/syscall_64.c +8
-0+#ifdef CONFIG_X86_X32_ABI +long x32_sys_call (const struct pt_regs *regs,unsigned int nr) +{ +switch (nr) { +#include <asm/syscalls_x32.h> +default :return __x64_sys_ni_syscall (regs); + } +};There seems to be a stray semicolon here. The original code also has it but it doesn't seem necessary.
Quoted 5 lines
BTW., seeing that you've gone through this series with a fine comb I've added your Reviewed-by tag to the series (with the caveat that the details you've pointed out will be addressed in followup patches). Let me know if that's not OK.
Thanks, that would have been fine with me. Reviewing the v2 series now.
Quoted 4 lines
Thanks,
Ingo
[tip: x86/cpu] x86/syscall/x32: Move the x32 syscall table to arch/x86/entry/syscall_64.c
In reply to Brian GerstThe following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 8b24877200a8d3c01d67b968dfbe58228909cc1b Gitweb: https://git.kernel.org/tip/8b24877200a8d3c01d67b968dfbe58228909cc1b Author: Brian Gerst <[email protected]> AuthorDate: Thu, 13 Mar 2025 14:22:35 -04:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 14 Mar 2025 10:32:51 +01:00
x86/syscall/x32: Move the x32 syscall table to arch/x86/entry/syscall_64.c
Since commit:
2e958a8a510d ("x86/entry/x32: Rename __x32_compat_sys_* to __x64_compat_sys_*")
the ABI prefix for x32 syscalls is the same as native 64-bit syscalls. Move the x32 syscall table to syscall_64.c
No functional changes.
--- arch/x86/entry/Makefile | 1 - arch/x86/entry/syscall_64.c | 13 +++++++++++++ arch/x86/entry/syscall_x32.c | 25 ------------------------- 3 files changed, 13 insertions(+), 26 deletions(-) delete mode 100644 arch/x86/entry/syscall_x32.c
arch/x86/entry/Makefile +0 -1
@@ -27,4 +27,3 @@ CFLAGS_REMOVE_entry_fred.o += -pg $(CC_FLAGS_FTRACE) obj-$(CONFIG_X86_FRED) += entry_64_fred.o entry_fred.o obj-$(CONFIG_IA32_EMULATION) += entry_64_compat.o syscall_32.o -obj-$(CONFIG_X86_X32_ABI) += syscall_x32.o
arch/x86/entry/syscall_64.c +13 -0
@@ -19,6 +19,9 @@#define __SYSCALL (nr, sym) extern long __x64_##sym(const struct pt_regs *);#define __SYSCALL_NORETURN (nr, sym) extern long __noreturn __x64_##sym(const struct pt_regs *);#include <asm/syscalls_64.h> +#ifdef CONFIG_X86_X32_ABI +#include <asm/syscalls_x32.h> +#endif #undef __SYSCALL#undef __SYSCALL_NORETURN
@@ -44,6 +47,16 @@ long x64_sys_call(const struct pt_regs *regs, unsigned int nr) } }; +#ifdef CONFIG_X86_X32_ABI +long x32_sys_call (const struct pt_regs *regs,unsigned int nr) +{ +switch (nr) { +#include <asm/syscalls_x32.h> +default :return __x64_sys_ni_syscall (regs); + } +}; +#endif + static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr) {/*
arch/x86/entry/syscall_x32.c deleted +0 -25
@@ -1,25 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* System call table for x32 ABI. */ - -#include <linux/linkage.h> -#include <linux/sys.h> -#include <linux/cache.h> -#include <linux/syscalls.h> -#include <asm/syscall.h> - -#define __SYSCALL (nr, sym) extern long __x64_##sym(const struct pt_regs *); -#define __SYSCALL_NORETURN (nr, sym) extern long __noreturn __x64_##sym(const struct pt_regs *); -#include <asm/syscalls_x32.h> -#undef __SYSCALL - -#undef __SYSCALL_NORETURN -#define __SYSCALL_NORETURN __SYSCALL - -#define __SYSCALL (nr, sym) case nr: return __x64_##sym(regs); -long x32_sys_call (const struct pt_regs *regs,unsigned int nr) -{ -switch (nr) { -#include <asm/syscalls_x32.h> -default :return __x64_sys_ni_syscall (regs); - } -};
PATCH 5/5 x86/syscall: Move sys_ni_syscall()
In reply to Brian GerstMove sys_ni_syscall() to kernel/process.c, and remove the now empty entry/common.c
No functional changes.
--- arch/x86/entry/Makefile | 3 --- arch/x86/entry/common.c | 38 -------------------------------------- arch/x86/kernel/process.c | 5 +++++ 3 files changed, 5 insertions(+), 41 deletions(-) delete mode 100644 arch/x86/entry/common.c
arch/x86/entry/Makefile +0 -3
@@ -7,16 +7,13 @@ KASAN_SANITIZE := n UBSAN_SANITIZE := n KCOV_INSTRUMENT := n -CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_syscall_32.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_syscall_64.o = $(CC_FLAGS_FTRACE) -CFLAGS_common.o += -fno-stack-protector CFLAGS_syscall_32.o += -fno-stack-protector CFLAGS_syscall_64.o += -fno-stack-protector obj-y := entry.o entry_$(BITS).o syscall_$(BITS).o -obj-y += common.o obj-y += vdso/ obj-y += vsyscall/
arch/x86/entry/common.c deleted +0 -38
@@ -1,38 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* -* common.c - C code for kernel entry and exit -* Copyright (c) 2015 Andrew Lutomirski -* -* Based on asm and ptrace code by many authors. The code here originated -* in ptrace.c and signal.c. -*/ - -#include <linux/kernel.h> -#include <linux/sched.h> -#include <linux/sched/task_stack.h> -#include <linux/entry-common.h> -#include <linux/mm.h> -#include <linux/smp.h> -#include <linux/errno.h> -#include <linux/ptrace.h> -#include <linux/export.h> -#include <linux/nospec.h> -#include <linux/syscalls.h> -#include <linux/uaccess.h> -#include <linux/init.h> - -#include <asm/apic.h> -#include <asm/desc.h> -#include <asm/traps.h> -#include <asm/vdso.h> -#include <asm/cpufeature.h> -#include <asm/fpu/api.h> -#include <asm/nospec-branch.h> -#include <asm/io_bitmap.h> -#include <asm/syscall.h> -#include <asm/irq_stack.h> - -SYSCALL_DEFINE0 (ni_syscall) -{ -return -ENOSYS ; -}
arch/x86/kernel/process.c +5 -0
@@ -1068,3 +1068,8 @@ SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2)return -EINVAL ; } + +SYSCALL_DEFINE0 (ni_syscall) +{ +return -ENOSYS ; +}
Signature · 1 line
2.48.1
[tip: x86/cpu] x86/syscall: Move sys_ni_syscall() to arch/x86/kernel/process.c
The following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 83d5563952e6634826f831a9b91c62c7cab4ca4d Gitweb: https://git.kernel.org/tip/83d5563952e6634826f831a9b91c62c7cab4ca4d Author: Brian Gerst <[email protected]> AuthorDate: Thu, 13 Mar 2025 14:22:36 -04:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 14 Mar 2025 10:32:51 +01:00
x86/syscall: Move sys_ni_syscall() to arch/x86/kernel/process.c
Move sys_ni_syscall() to kernel/process.c, and remove the now empty entry/common.c
No functional changes.
--- arch/x86/entry/Makefile | 3 +--- arch/x86/entry/common.c | 38 +-------------------------------------- arch/x86/kernel/process.c | 5 +++++- 3 files changed, 5 insertions(+), 41 deletions(-) delete mode 100644 arch/x86/entry/common.c
arch/x86/entry/Makefile +0 -3
@@ -7,16 +7,13 @@ KASAN_SANITIZE := n UBSAN_SANITIZE := n KCOV_INSTRUMENT := n -CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_syscall_32.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_syscall_64.o = $(CC_FLAGS_FTRACE) -CFLAGS_common.o += -fno-stack-protector CFLAGS_syscall_32.o += -fno-stack-protector CFLAGS_syscall_64.o += -fno-stack-protector obj-y := entry.o entry_$(BITS).o syscall_$(BITS).o -obj-y += common.o obj-y += vdso/ obj-y += vsyscall/
arch/x86/entry/common.c deleted +0 -38
@@ -1,38 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* -* common.c - C code for kernel entry and exit -* Copyright (c) 2015 Andrew Lutomirski -* -* Based on asm and ptrace code by many authors. The code here originated -* in ptrace.c and signal.c. -*/ - -#include <linux/kernel.h> -#include <linux/sched.h> -#include <linux/sched/task_stack.h> -#include <linux/entry-common.h> -#include <linux/mm.h> -#include <linux/smp.h> -#include <linux/errno.h> -#include <linux/ptrace.h> -#include <linux/export.h> -#include <linux/nospec.h> -#include <linux/syscalls.h> -#include <linux/uaccess.h> -#include <linux/init.h> - -#include <asm/apic.h> -#include <asm/desc.h> -#include <asm/traps.h> -#include <asm/vdso.h> -#include <asm/cpufeature.h> -#include <asm/fpu/api.h> -#include <asm/nospec-branch.h> -#include <asm/io_bitmap.h> -#include <asm/syscall.h> -#include <asm/irq_stack.h> - -SYSCALL_DEFINE0 (ni_syscall) -{ -return -ENOSYS ; -}
arch/x86/kernel/process.c +5 -0
@@ -1060,3 +1060,8 @@ long do_arch_prctl_common(int option, unsigned long arg2)return -EINVAL ; } + +SYSCALL_DEFINE0 (ni_syscall) +{ +return -ENOSYS ; +}