Skip to content

Commit f49ecf5

Browse files
H. Peter Anvinhansendc
authored andcommitted
x86/cpufeature: Replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32
In most cases, the use of "fast 32-bit system call" depends either on X86_FEATURE_SEP or X86_FEATURE_SYSENTER32 || X86_FEATURE_SYSCALL32. However, nearly all the logic for both is identical. Define X86_FEATURE_SYSFAST32 which indicates that *either* SYSENTER32 or SYSCALL32 should be used, for either 32- or 64-bit kernels. This defaults to SYSENTER; use SYSCALL if the SYSCALL32 bit is also set. As this removes ALL existing uses of X86_FEATURE_SYSENTER32, which is a kernel-only synthetic feature bit, simply remove it and replace it with X86_FEATURE_SYSFAST32. This leaves an unused alternative for a true 32-bit kernel, but that should really not matter in any way. The clearing of X86_FEATURE_SYSCALL32 can be removed once the patches for automatically clearing disabled features has been merged. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://patch.msgid.link/20251216212606.1325678-10-hpa@zytor.com
1 parent a0636d4 commit f49ecf5

11 files changed

Lines changed: 42 additions & 31 deletions

File tree

arch/x86/Kconfig.cpufeatures

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ config X86_REQUIRED_FEATURE_MOVBE
5656
def_bool y
5757
depends on MATOM
5858

59+
config X86_REQUIRED_FEATURE_SYSFAST32
60+
def_bool y
61+
depends on X86_64 && !X86_FRED
62+
5963
config X86_REQUIRED_FEATURE_CPUID
6064
def_bool y
6165
depends on X86_64
@@ -120,6 +124,10 @@ config X86_DISABLED_FEATURE_CENTAUR_MCR
120124
def_bool y
121125
depends on X86_64
122126

127+
config X86_DISABLED_FEATURE_SYSCALL32
128+
def_bool y
129+
depends on !X86_64
130+
123131
config X86_DISABLED_FEATURE_PCID
124132
def_bool y
125133
depends on !X86_64

arch/x86/entry/vdso/vdso32/system_call.S

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,9 @@ __kernel_vsyscall:
5252
#define SYSENTER_SEQUENCE "movl %esp, %ebp; sysenter"
5353
#define SYSCALL_SEQUENCE "movl %ecx, %ebp; syscall"
5454

55-
#ifdef BUILD_VDSO32_64
5655
/* If SYSENTER (Intel) or SYSCALL32 (AMD) is available, use it. */
57-
ALTERNATIVE_2 "", SYSENTER_SEQUENCE, X86_FEATURE_SYSENTER32, \
58-
SYSCALL_SEQUENCE, X86_FEATURE_SYSCALL32
59-
#else
60-
ALTERNATIVE "", SYSENTER_SEQUENCE, X86_FEATURE_SEP
61-
#endif
56+
ALTERNATIVE_2 "", SYSENTER_SEQUENCE, X86_FEATURE_SYSFAST32, \
57+
SYSCALL_SEQUENCE, X86_FEATURE_SYSCALL32
6258

6359
/* Enter using int $0x80 */
6460
int $0x80

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
#define X86_FEATURE_PEBS ( 3*32+12) /* "pebs" Precise-Event Based Sampling */
8585
#define X86_FEATURE_BTS ( 3*32+13) /* "bts" Branch Trace Store */
8686
#define X86_FEATURE_SYSCALL32 ( 3*32+14) /* syscall in IA32 userspace */
87-
#define X86_FEATURE_SYSENTER32 ( 3*32+15) /* sysenter in IA32 userspace */
87+
#define X86_FEATURE_SYSFAST32 ( 3*32+15) /* sysenter/syscall in IA32 userspace */
8888
#define X86_FEATURE_REP_GOOD ( 3*32+16) /* "rep_good" REP microcode works well */
8989
#define X86_FEATURE_AMD_LBR_V2 ( 3*32+17) /* "amd_lbr_v2" AMD Last Branch Record Extension Version 2 */
9090
#define X86_FEATURE_CLEAR_CPU_BUF ( 3*32+18) /* Clear CPU buffers using VERW */

arch/x86/kernel/cpu/centaur.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ static void early_init_centaur(struct cpuinfo_x86 *c)
102102
(c->x86 >= 7))
103103
set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
104104

105-
#ifdef CONFIG_X86_64
106-
set_cpu_cap(c, X86_FEATURE_SYSENTER32);
107-
#endif
108105
if (c->x86_power & (1 << 8)) {
109106
set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
110107
set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);

arch/x86/kernel/cpu/common.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,9 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
10681068
init_scattered_cpuid_features(c);
10691069
init_speculation_control(c);
10701070

1071+
if (IS_ENABLED(CONFIG_X86_64) || cpu_has(c, X86_FEATURE_SEP))
1072+
set_cpu_cap(c, X86_FEATURE_SYSFAST32);
1073+
10711074
/*
10721075
* Clear/Set all flags overridden by options, after probe.
10731076
* This needs to happen each time we re-probe, which may happen
@@ -1813,6 +1816,11 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
18131816
* that it can't be enabled in 32-bit mode.
18141817
*/
18151818
setup_clear_cpu_cap(X86_FEATURE_PCID);
1819+
1820+
/*
1821+
* Never use SYSCALL on a 32-bit kernel
1822+
*/
1823+
setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);
18161824
#endif
18171825

18181826
/*

arch/x86/kernel/cpu/intel.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ static void early_init_intel(struct cpuinfo_x86 *c)
236236
clear_cpu_cap(c, X86_FEATURE_PSE);
237237
}
238238

239-
#ifdef CONFIG_X86_64
240-
set_cpu_cap(c, X86_FEATURE_SYSENTER32);
241-
#else
239+
#ifndef CONFIG_X86_64
242240
/* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
243241
if (c->x86 == 15 && c->x86_cache_alignment == 64)
244242
c->x86_cache_alignment = 128;

arch/x86/kernel/cpu/zhaoxin.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ static void early_init_zhaoxin(struct cpuinfo_x86 *c)
5959
{
6060
if (c->x86 >= 0x6)
6161
set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
62-
#ifdef CONFIG_X86_64
63-
set_cpu_cap(c, X86_FEATURE_SYSENTER32);
64-
#endif
62+
6563
if (c->x86_power & (1 << 8)) {
6664
set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
6765
set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);

arch/x86/kernel/fred.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void cpu_init_fred_exceptions(void)
6868
idt_invalidate();
6969

7070
/* Use int $0x80 for 32-bit system calls in FRED mode */
71-
setup_clear_cpu_cap(X86_FEATURE_SYSENTER32);
71+
setup_clear_cpu_cap(X86_FEATURE_SYSFAST32);
7272
setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);
7373
}
7474

arch/x86/xen/setup.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -990,13 +990,6 @@ static int register_callback(unsigned type, const void *func)
990990
return HYPERVISOR_callback_op(CALLBACKOP_register, &callback);
991991
}
992992

993-
void xen_enable_sysenter(void)
994-
{
995-
if (cpu_feature_enabled(X86_FEATURE_SYSENTER32) &&
996-
register_callback(CALLBACKTYPE_sysenter, xen_entry_SYSENTER_compat))
997-
setup_clear_cpu_cap(X86_FEATURE_SYSENTER32);
998-
}
999-
1000993
void xen_enable_syscall(void)
1001994
{
1002995
int ret;
@@ -1008,11 +1001,27 @@ void xen_enable_syscall(void)
10081001
mechanism for syscalls. */
10091002
}
10101003

1011-
if (cpu_feature_enabled(X86_FEATURE_SYSCALL32) &&
1012-
register_callback(CALLBACKTYPE_syscall32, xen_entry_SYSCALL_compat))
1004+
if (!cpu_feature_enabled(X86_FEATURE_SYSFAST32))
1005+
return;
1006+
1007+
if (cpu_feature_enabled(X86_FEATURE_SYSCALL32)) {
1008+
/* Use SYSCALL32 */
1009+
ret = register_callback(CALLBACKTYPE_syscall32,
1010+
xen_entry_SYSCALL_compat);
1011+
1012+
} else {
1013+
/* Use SYSENTER32 */
1014+
ret = register_callback(CALLBACKTYPE_sysenter,
1015+
xen_entry_SYSENTER_compat);
1016+
}
1017+
1018+
if (ret) {
10131019
setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);
1020+
setup_clear_cpu_cap(X86_FEATURE_SYSFAST32);
1021+
}
10141022
}
10151023

1024+
10161025
static void __init xen_pvmmu_arch_setup(void)
10171026
{
10181027
HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
@@ -1022,7 +1031,6 @@ static void __init xen_pvmmu_arch_setup(void)
10221031
register_callback(CALLBACKTYPE_failsafe, xen_failsafe_callback))
10231032
BUG();
10241033

1025-
xen_enable_sysenter();
10261034
xen_enable_syscall();
10271035
}
10281036

arch/x86/xen/smp_pv.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ static void cpu_bringup(void)
6565
touch_softlockup_watchdog();
6666

6767
/* PVH runs in ring 0 and allows us to do native syscalls. Yay! */
68-
if (!xen_feature(XENFEAT_supervisor_mode_kernel)) {
69-
xen_enable_sysenter();
68+
if (!xen_feature(XENFEAT_supervisor_mode_kernel))
7069
xen_enable_syscall();
71-
}
70+
7271
cpu = smp_processor_id();
7372
identify_secondary_cpu(cpu);
7473
set_cpu_sibling_map(cpu);

0 commit comments

Comments
 (0)