Commit 685d9821 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

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
  ...
parents fcc19657 35ce6492
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -473,8 +473,8 @@ Spectre variant 2
   -mindirect-branch=thunk-extern -mindirect-branch-register options.
   If the kernel is compiled with a Clang compiler, the compiler needs
   to support -mretpoline-external-thunk option.  The kernel config
   CONFIG_RETPOLINE needs to be turned on, and the CPU needs to run with
   the latest updated microcode.
   CONFIG_MITIGATION_RETPOLINE needs to be turned on, and the CPU needs
   to run with the latest updated microcode.

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

		Selecting 'on' will also enable the mitigation
		against user space to user space task attacks.
+2 −2
Original line number Diff line number Diff line
@@ -6036,8 +6036,8 @@
			Selecting 'on' will, and 'auto' may, choose a
			mitigation method at run time according to the
			CPU, the available microcode, the setting of the
			CONFIG_RETPOLINE configuration option, and the
			compiler with which the kernel was built.
			CONFIG_MITIGATION_RETPOLINE configuration option,
			and the compiler with which the kernel was built.

			Selecting 'on' will also enable the mitigation
			against user space to user space task attacks.
+3 −3
Original line number Diff line number Diff line
@@ -26,9 +26,9 @@ comments in pti.c).

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

Page Table Management
=====================
+29 −16
Original line number Diff line number Diff line
@@ -147,6 +147,7 @@ config X86
	select EDAC_ATOMIC_SCRUB
	select EDAC_SUPPORT
	select GENERIC_CLOCKEVENTS_BROADCAST	if X86_64 || (X86_32 && X86_LOCAL_APIC)
	select GENERIC_CLOCKEVENTS_BROADCAST_IDLE	if GENERIC_CLOCKEVENTS_BROADCAST
	select GENERIC_CLOCKEVENTS_MIN_ADJUST
	select GENERIC_CMOS_UPDATE
	select GENERIC_CPU_AUTOPROBE
@@ -2430,6 +2431,18 @@ source "kernel/livepatch/Kconfig"

endmenu

config CC_HAS_NAMED_AS
	def_bool CC_IS_GCC && GCC_VERSION >= 120100

config USE_X86_SEG_SUPPORT
	def_bool y
	depends on CC_HAS_NAMED_AS
	#
	# -fsanitize=kernel-address (KASAN) is at the moment incompatible
	# with named address spaces - see GCC PR sanitizer/111736.
	#
	depends on !KASAN

config CC_HAS_SLS
	def_bool $(cc-option,-mharden-sls=all)

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

config FINEIBT
	def_bool y
	depends on X86_KERNEL_IBT && CFI_CLANG && RETPOLINE
	depends on X86_KERNEL_IBT && CFI_CLANG && MITIGATION_RETPOLINE
	select CALL_PADDING

config HAVE_CALL_THUNKS
	def_bool y
	depends on CC_HAS_ENTRY_PADDING && RETHUNK && OBJTOOL
	depends on CC_HAS_ENTRY_PADDING && MITIGATION_RETHUNK && OBJTOOL

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

if SPECULATION_MITIGATIONS

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

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

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

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

config CPU_UNRET_ENTRY
config MITIGATION_UNRET_ENTRY
	bool "Enable UNRET on kernel entry"
	depends on CPU_SUP_AMD && RETHUNK && X86_64
	depends on CPU_SUP_AMD && MITIGATION_RETHUNK && X86_64
	default y
	help
	  Compile the kernel with support for the retbleed=unret mitigation.

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

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

config CPU_IBPB_ENTRY
config MITIGATION_IBPB_ENTRY
	bool "Enable IBPB on kernel entry"
	depends on CPU_SUP_AMD && X86_64
	default y
	help
	  Compile the kernel with support for the retbleed=ibpb mitigation.

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

config CPU_SRSO
config MITIGATION_SRSO
	bool "Mitigate speculative RAS overflow on AMD"
	depends on CPU_SUP_AMD && X86_64 && RETHUNK
	depends on CPU_SUP_AMD && X86_64 && MITIGATION_RETHUNK
	default y
	help
	  Enable the SRSO mitigation needed on AMD Zen1-4 machines.

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

config GDS_FORCE_MITIGATION
config MITIGATION_GDS_FORCE
	bool "Force GDS Mitigation"
	depends on CPU_SUP_INTEL
	default n
+5 −6
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ RETPOLINE_VDSO_CFLAGS := -mretpoline
endif
RETPOLINE_CFLAGS	+= $(call cc-option,-mindirect-branch-cs-prefix)

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

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

ifdef CONFIG_SLS
ifdef CONFIG_MITIGATION_SLS
  KBUILD_CFLAGS += -mharden-sls=all
endif

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

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

archprepare: checkbin
checkbin:
ifdef CONFIG_RETPOLINE
ifdef CONFIG_MITIGATION_RETPOLINE
ifeq ($(RETPOLINE_CFLAGS),)
	@echo "You are building kernel with non-retpoline compiler." >&2
	@echo "Please update your compiler." >&2
Loading