Skip to content

Commit 685d982

Browse files
committed
Merge tag 'x86-core-2024-03-11' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull core x86 updates from Ingo Molnar: - The biggest change is the rework of the percpu code, to support the 'Named Address Spaces' GCC feature, by Uros Bizjak: - This allows C code to access GS and FS segment relative memory via variables declared with such attributes, which allows the compiler to better optimize those accesses than the previous inline assembly code. - The series also includes a number of micro-optimizations for various percpu access methods, plus a number of cleanups of %gs accesses in assembly code. - These changes have been exposed to linux-next testing for the last ~5 months, with no known regressions in this area. - Fix/clean up __switch_to()'s broken but accidentally working handling of FPU switching - which also generates better code - Propagate more RIP-relative addressing in assembly code, to generate slightly better code - Rework the CPU mitigations Kconfig space to be less idiosyncratic, to make it easier for distros to follow & maintain these options - Rework the x86 idle code to cure RCU violations and to clean up the logic - Clean up the vDSO Makefile logic - Misc cleanups and fixes * tag 'x86-core-2024-03-11' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (52 commits) x86/idle: Select idle routine only once x86/idle: Let prefer_mwait_c1_over_halt() return bool x86/idle: Cleanup idle_setup() x86/idle: Clean up idle selection x86/idle: Sanitize X86_BUG_AMD_E400 handling sched/idle: Conditionally handle tick broadcast in default_idle_call() x86: Increase brk randomness entropy for 64-bit systems x86/vdso: Move vDSO to mmap region x86/vdso/kbuild: Group non-standard build attributes and primary object file rules together x86/vdso: Fix rethunk patching for vdso-image-{32,64}.o x86/retpoline: Ensure default return thunk isn't used at runtime x86/vdso: Use CONFIG_COMPAT_32 to specify vdso32 x86/vdso: Use $(addprefix ) instead of $(foreach ) x86/vdso: Simplify obj-y addition x86/vdso: Consolidate targets and clean-files x86/bugs: Rename CONFIG_RETHUNK => CONFIG_MITIGATION_RETHUNK x86/bugs: Rename CONFIG_CPU_SRSO => CONFIG_MITIGATION_SRSO x86/bugs: Rename CONFIG_CPU_IBRS_ENTRY => CONFIG_MITIGATION_IBRS_ENTRY x86/bugs: Rename CONFIG_CPU_UNRET_ENTRY => CONFIG_MITIGATION_UNRET_ENTRY x86/bugs: Rename CONFIG_SLS => CONFIG_MITIGATION_SLS ...
2 parents fcc1965 + 35ce649 commit 685d982

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+667
-562
lines changed

Documentation/admin-guide/hw-vuln/spectre.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ Spectre variant 2
473473
-mindirect-branch=thunk-extern -mindirect-branch-register options.
474474
If the kernel is compiled with a Clang compiler, the compiler needs
475475
to support -mretpoline-external-thunk option. The kernel config
476-
CONFIG_RETPOLINE needs to be turned on, and the CPU needs to run with
477-
the latest updated microcode.
476+
CONFIG_MITIGATION_RETPOLINE needs to be turned on, and the CPU needs
477+
to run with the latest updated microcode.
478478

479479
On Intel Skylake-era systems the mitigation covers most, but not all,
480480
cases. See :ref:`[3] <spec_ref3>` for more details.
@@ -609,8 +609,8 @@ kernel command line.
609609
Selecting 'on' will, and 'auto' may, choose a
610610
mitigation method at run time according to the
611611
CPU, the available microcode, the setting of the
612-
CONFIG_RETPOLINE configuration option, and the
613-
compiler with which the kernel was built.
612+
CONFIG_MITIGATION_RETPOLINE configuration option,
613+
and the compiler with which the kernel was built.
614614

615615
Selecting 'on' will also enable the mitigation
616616
against user space to user space task attacks.

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6036,8 +6036,8 @@
60366036
Selecting 'on' will, and 'auto' may, choose a
60376037
mitigation method at run time according to the
60386038
CPU, the available microcode, the setting of the
6039-
CONFIG_RETPOLINE configuration option, and the
6040-
compiler with which the kernel was built.
6039+
CONFIG_MITIGATION_RETPOLINE configuration option,
6040+
and the compiler with which the kernel was built.
60416041

60426042
Selecting 'on' will also enable the mitigation
60436043
against user space to user space task attacks.

Documentation/arch/x86/pti.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ comments in pti.c).
2626

2727
This approach helps to ensure that side-channel attacks leveraging
2828
the paging structures do not function when PTI is enabled. It can be
29-
enabled by setting CONFIG_PAGE_TABLE_ISOLATION=y at compile time.
30-
Once enabled at compile-time, it can be disabled at boot with the
31-
'nopti' or 'pti=' kernel parameters (see kernel-parameters.txt).
29+
enabled by setting CONFIG_MITIGATION_PAGE_TABLE_ISOLATION=y at compile
30+
time. Once enabled at compile-time, it can be disabled at boot with
31+
the 'nopti' or 'pti=' kernel parameters (see kernel-parameters.txt).
3232

3333
Page Table Management
3434
=====================

arch/x86/Kconfig

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ config X86
147147
select EDAC_ATOMIC_SCRUB
148148
select EDAC_SUPPORT
149149
select GENERIC_CLOCKEVENTS_BROADCAST if X86_64 || (X86_32 && X86_LOCAL_APIC)
150+
select GENERIC_CLOCKEVENTS_BROADCAST_IDLE if GENERIC_CLOCKEVENTS_BROADCAST
150151
select GENERIC_CLOCKEVENTS_MIN_ADJUST
151152
select GENERIC_CMOS_UPDATE
152153
select GENERIC_CPU_AUTOPROBE
@@ -2430,6 +2431,18 @@ source "kernel/livepatch/Kconfig"
24302431

24312432
endmenu
24322433

2434+
config CC_HAS_NAMED_AS
2435+
def_bool CC_IS_GCC && GCC_VERSION >= 120100
2436+
2437+
config USE_X86_SEG_SUPPORT
2438+
def_bool y
2439+
depends on CC_HAS_NAMED_AS
2440+
#
2441+
# -fsanitize=kernel-address (KASAN) is at the moment incompatible
2442+
# with named address spaces - see GCC PR sanitizer/111736.
2443+
#
2444+
depends on !KASAN
2445+
24332446
config CC_HAS_SLS
24342447
def_bool $(cc-option,-mharden-sls=all)
24352448

@@ -2461,12 +2474,12 @@ config CALL_PADDING
24612474

24622475
config FINEIBT
24632476
def_bool y
2464-
depends on X86_KERNEL_IBT && CFI_CLANG && RETPOLINE
2477+
depends on X86_KERNEL_IBT && CFI_CLANG && MITIGATION_RETPOLINE
24652478
select CALL_PADDING
24662479

24672480
config HAVE_CALL_THUNKS
24682481
def_bool y
2469-
depends on CC_HAS_ENTRY_PADDING && RETHUNK && OBJTOOL
2482+
depends on CC_HAS_ENTRY_PADDING && MITIGATION_RETHUNK && OBJTOOL
24702483

24712484
config CALL_THUNKS
24722485
def_bool n
@@ -2488,7 +2501,7 @@ menuconfig SPECULATION_MITIGATIONS
24882501

24892502
if SPECULATION_MITIGATIONS
24902503

2491-
config PAGE_TABLE_ISOLATION
2504+
config MITIGATION_PAGE_TABLE_ISOLATION
24922505
bool "Remove the kernel mapping in user mode"
24932506
default y
24942507
depends on (X86_64 || X86_PAE)
@@ -2499,7 +2512,7 @@ config PAGE_TABLE_ISOLATION
24992512

25002513
See Documentation/arch/x86/pti.rst for more details.
25012514

2502-
config RETPOLINE
2515+
config MITIGATION_RETPOLINE
25032516
bool "Avoid speculative indirect branches in kernel"
25042517
select OBJTOOL if HAVE_OBJTOOL
25052518
default y
@@ -2509,9 +2522,9 @@ config RETPOLINE
25092522
branches. Requires a compiler with -mindirect-branch=thunk-extern
25102523
support for full protection. The kernel may run slower.
25112524

2512-
config RETHUNK
2525+
config MITIGATION_RETHUNK
25132526
bool "Enable return-thunks"
2514-
depends on RETPOLINE && CC_HAS_RETURN_THUNK
2527+
depends on MITIGATION_RETPOLINE && CC_HAS_RETURN_THUNK
25152528
select OBJTOOL if HAVE_OBJTOOL
25162529
default y if X86_64
25172530
help
@@ -2520,14 +2533,14 @@ config RETHUNK
25202533
Requires a compiler with -mfunction-return=thunk-extern
25212534
support for full protection. The kernel may run slower.
25222535

2523-
config CPU_UNRET_ENTRY
2536+
config MITIGATION_UNRET_ENTRY
25242537
bool "Enable UNRET on kernel entry"
2525-
depends on CPU_SUP_AMD && RETHUNK && X86_64
2538+
depends on CPU_SUP_AMD && MITIGATION_RETHUNK && X86_64
25262539
default y
25272540
help
25282541
Compile the kernel with support for the retbleed=unret mitigation.
25292542

2530-
config CALL_DEPTH_TRACKING
2543+
config MITIGATION_CALL_DEPTH_TRACKING
25312544
bool "Mitigate RSB underflow with call depth tracking"
25322545
depends on CPU_SUP_INTEL && HAVE_CALL_THUNKS
25332546
select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
@@ -2547,7 +2560,7 @@ config CALL_DEPTH_TRACKING
25472560

25482561
config CALL_THUNKS_DEBUG
25492562
bool "Enable call thunks and call depth tracking debugging"
2550-
depends on CALL_DEPTH_TRACKING
2563+
depends on MITIGATION_CALL_DEPTH_TRACKING
25512564
select FUNCTION_ALIGNMENT_32B
25522565
default n
25532566
help
@@ -2558,14 +2571,14 @@ config CALL_THUNKS_DEBUG
25582571
Only enable this when you are debugging call thunks as this
25592572
creates a noticeable runtime overhead. If unsure say N.
25602573

2561-
config CPU_IBPB_ENTRY
2574+
config MITIGATION_IBPB_ENTRY
25622575
bool "Enable IBPB on kernel entry"
25632576
depends on CPU_SUP_AMD && X86_64
25642577
default y
25652578
help
25662579
Compile the kernel with support for the retbleed=ibpb mitigation.
25672580

2568-
config CPU_IBRS_ENTRY
2581+
config MITIGATION_IBRS_ENTRY
25692582
bool "Enable IBRS on kernel entry"
25702583
depends on CPU_SUP_INTEL && X86_64
25712584
default y
@@ -2574,14 +2587,14 @@ config CPU_IBRS_ENTRY
25742587
This mitigates both spectre_v2 and retbleed at great cost to
25752588
performance.
25762589

2577-
config CPU_SRSO
2590+
config MITIGATION_SRSO
25782591
bool "Mitigate speculative RAS overflow on AMD"
2579-
depends on CPU_SUP_AMD && X86_64 && RETHUNK
2592+
depends on CPU_SUP_AMD && X86_64 && MITIGATION_RETHUNK
25802593
default y
25812594
help
25822595
Enable the SRSO mitigation needed on AMD Zen1-4 machines.
25832596

2584-
config SLS
2597+
config MITIGATION_SLS
25852598
bool "Mitigate Straight-Line-Speculation"
25862599
depends on CC_HAS_SLS && X86_64
25872600
select OBJTOOL if HAVE_OBJTOOL
@@ -2591,7 +2604,7 @@ config SLS
25912604
against straight line speculation. The kernel image might be slightly
25922605
larger.
25932606

2594-
config GDS_FORCE_MITIGATION
2607+
config MITIGATION_GDS_FORCE
25952608
bool "Force GDS Mitigation"
25962609
depends on CPU_SUP_INTEL
25972610
default n

arch/x86/Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ RETPOLINE_VDSO_CFLAGS := -mretpoline
2222
endif
2323
RETPOLINE_CFLAGS += $(call cc-option,-mindirect-branch-cs-prefix)
2424

25-
ifdef CONFIG_RETHUNK
25+
ifdef CONFIG_MITIGATION_RETHUNK
2626
RETHUNK_CFLAGS := -mfunction-return=thunk-extern
2727
RETPOLINE_CFLAGS += $(RETHUNK_CFLAGS)
2828
endif
@@ -195,7 +195,7 @@ KBUILD_CFLAGS += -Wno-sign-compare
195195
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
196196

197197
# Avoid indirect branches in kernel to deal with Spectre
198-
ifdef CONFIG_RETPOLINE
198+
ifdef CONFIG_MITIGATION_RETPOLINE
199199
KBUILD_CFLAGS += $(RETPOLINE_CFLAGS)
200200
# Additionally, avoid generating expensive indirect jumps which
201201
# are subject to retpolines for small number of switch cases.
@@ -208,7 +208,7 @@ ifdef CONFIG_RETPOLINE
208208
endif
209209
endif
210210

211-
ifdef CONFIG_SLS
211+
ifdef CONFIG_MITIGATION_SLS
212212
KBUILD_CFLAGS += -mharden-sls=all
213213
endif
214214

@@ -299,12 +299,11 @@ install:
299299

300300
vdso-install-$(CONFIG_X86_64) += arch/x86/entry/vdso/vdso64.so.dbg
301301
vdso-install-$(CONFIG_X86_X32_ABI) += arch/x86/entry/vdso/vdsox32.so.dbg
302-
vdso-install-$(CONFIG_X86_32) += arch/x86/entry/vdso/vdso32.so.dbg
303-
vdso-install-$(CONFIG_IA32_EMULATION) += arch/x86/entry/vdso/vdso32.so.dbg
302+
vdso-install-$(CONFIG_COMPAT_32) += arch/x86/entry/vdso/vdso32.so.dbg
304303

305304
archprepare: checkbin
306305
checkbin:
307-
ifdef CONFIG_RETPOLINE
306+
ifdef CONFIG_MITIGATION_RETPOLINE
308307
ifeq ($(RETPOLINE_CFLAGS),)
309308
@echo "You are building kernel with non-retpoline compiler." >&2
310309
@echo "Please update your compiler." >&2

arch/x86/boot/compressed/ident_map_64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* Copyright (C) 2016 Kees Cook
99
*/
1010

11-
/* No PAGE_TABLE_ISOLATION support needed either: */
12-
#undef CONFIG_PAGE_TABLE_ISOLATION
11+
/* No MITIGATION_PAGE_TABLE_ISOLATION support needed either: */
12+
#undef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
1313

1414
#include "error.h"
1515
#include "misc.h"

arch/x86/configs/i386_defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CONFIG_EFI_STUB=y
4242
CONFIG_HZ_1000=y
4343
CONFIG_KEXEC=y
4444
CONFIG_CRASH_DUMP=y
45-
# CONFIG_RETHUNK is not set
45+
# CONFIG_MITIGATION_RETHUNK is not set
4646
CONFIG_HIBERNATION=y
4747
CONFIG_PM_DEBUG=y
4848
CONFIG_PM_TRACE_RTC=y

arch/x86/entry/calling.h

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ For 32-bit we have the following conventions - kernel is built with
147147
.endif
148148
.endm
149149

150-
#ifdef CONFIG_PAGE_TABLE_ISOLATION
150+
#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
151151

152152
/*
153-
* PAGE_TABLE_ISOLATION PGDs are 8k. Flip bit 12 to switch between the two
153+
* MITIGATION_PAGE_TABLE_ISOLATION PGDs are 8k. Flip bit 12 to switch between the two
154154
* halves:
155155
*/
156156
#define PTI_USER_PGTABLE_BIT PAGE_SHIFT
@@ -165,7 +165,7 @@ For 32-bit we have the following conventions - kernel is built with
165165

166166
.macro ADJUST_KERNEL_CR3 reg:req
167167
ALTERNATIVE "", "SET_NOFLUSH_BIT \reg", X86_FEATURE_PCID
168-
/* Clear PCID and "PAGE_TABLE_ISOLATION bit", point CR3 at kernel pagetables: */
168+
/* Clear PCID and "MITIGATION_PAGE_TABLE_ISOLATION bit", point CR3 at kernel pagetables: */
169169
andq $(~PTI_USER_PGTABLE_AND_PCID_MASK), \reg
170170
.endm
171171

@@ -178,7 +178,7 @@ For 32-bit we have the following conventions - kernel is built with
178178
.endm
179179

180180
#define THIS_CPU_user_pcid_flush_mask \
181-
PER_CPU_VAR(cpu_tlbstate) + TLB_STATE_user_pcid_flush_mask
181+
PER_CPU_VAR(cpu_tlbstate + TLB_STATE_user_pcid_flush_mask)
182182

183183
.macro SWITCH_TO_USER_CR3 scratch_reg:req scratch_reg2:req
184184
mov %cr3, \scratch_reg
@@ -274,7 +274,7 @@ For 32-bit we have the following conventions - kernel is built with
274274
.Lend_\@:
275275
.endm
276276

277-
#else /* CONFIG_PAGE_TABLE_ISOLATION=n: */
277+
#else /* CONFIG_MITIGATION_PAGE_TABLE_ISOLATION=n: */
278278

279279
.macro SWITCH_TO_KERNEL_CR3 scratch_reg:req
280280
.endm
@@ -302,7 +302,7 @@ For 32-bit we have the following conventions - kernel is built with
302302
* Assumes x86_spec_ctrl_{base,current} to have SPEC_CTRL_IBRS set.
303303
*/
304304
.macro IBRS_ENTER save_reg
305-
#ifdef CONFIG_CPU_IBRS_ENTRY
305+
#ifdef CONFIG_MITIGATION_IBRS_ENTRY
306306
ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_KERNEL_IBRS
307307
movl $MSR_IA32_SPEC_CTRL, %ecx
308308

@@ -331,7 +331,7 @@ For 32-bit we have the following conventions - kernel is built with
331331
* regs. Must be called after the last RET.
332332
*/
333333
.macro IBRS_EXIT save_reg
334-
#ifdef CONFIG_CPU_IBRS_ENTRY
334+
#ifdef CONFIG_MITIGATION_IBRS_ENTRY
335335
ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_KERNEL_IBRS
336336
movl $MSR_IA32_SPEC_CTRL, %ecx
337337

@@ -425,3 +425,63 @@ For 32-bit we have the following conventions - kernel is built with
425425
.endm
426426

427427
#endif /* CONFIG_SMP */
428+
429+
#ifdef CONFIG_X86_64
430+
431+
/* rdi: arg1 ... normal C conventions. rax is saved/restored. */
432+
.macro THUNK name, func
433+
SYM_FUNC_START(\name)
434+
pushq %rbp
435+
movq %rsp, %rbp
436+
437+
pushq %rdi
438+
pushq %rsi
439+
pushq %rdx
440+
pushq %rcx
441+
pushq %rax
442+
pushq %r8
443+
pushq %r9
444+
pushq %r10
445+
pushq %r11
446+
447+
call \func
448+
449+
popq %r11
450+
popq %r10
451+
popq %r9
452+
popq %r8
453+
popq %rax
454+
popq %rcx
455+
popq %rdx
456+
popq %rsi
457+
popq %rdi
458+
popq %rbp
459+
RET
460+
SYM_FUNC_END(\name)
461+
_ASM_NOKPROBE(\name)
462+
.endm
463+
464+
#else /* CONFIG_X86_32 */
465+
466+
/* put return address in eax (arg1) */
467+
.macro THUNK name, func, put_ret_addr_in_eax=0
468+
SYM_CODE_START_NOALIGN(\name)
469+
pushl %eax
470+
pushl %ecx
471+
pushl %edx
472+
473+
.if \put_ret_addr_in_eax
474+
/* Place EIP in the arg1 */
475+
movl 3*4(%esp), %eax
476+
.endif
477+
478+
call \func
479+
popl %edx
480+
popl %ecx
481+
popl %eax
482+
RET
483+
_ASM_NOKPROBE(\name)
484+
SYM_CODE_END(\name)
485+
.endm
486+
487+
#endif

arch/x86/entry/entry.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <asm/segment.h>
1111
#include <asm/cache.h>
1212

13+
#include "calling.h"
14+
1315
.pushsection .noinstr.text, "ax"
1416

1517
SYM_FUNC_START(entry_ibpb)
@@ -43,3 +45,4 @@ EXPORT_SYMBOL_GPL(mds_verw_sel);
4345

4446
.popsection
4547

48+
THUNK warn_thunk_thunk, __warn_thunk

arch/x86/entry/entry_32.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@
305305
.macro CHECK_AND_APPLY_ESPFIX
306306
#ifdef CONFIG_X86_ESPFIX32
307307
#define GDT_ESPFIX_OFFSET (GDT_ENTRY_ESPFIX_SS * 8)
308-
#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + GDT_ESPFIX_OFFSET
308+
#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page + GDT_ESPFIX_OFFSET)
309309

310310
ALTERNATIVE "jmp .Lend_\@", "", X86_BUG_ESPFIX
311311

0 commit comments

Comments
 (0)