Merge tag 'x86-urgent-2024-04-28' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 28 Apr 2024 18:58:16 +0000 (11:58 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 28 Apr 2024 18:58:16 +0000 (11:58 -0700)
Pull x86 fixes from Ingo Molnar:

 - Make the CPU_MITIGATIONS=n interaction with conflicting
   mitigation-enabling boot parameters a bit saner.

 - Re-enable CPU mitigations by default on non-x86

 - Fix TDX shared bit propagation on mprotect()

 - Fix potential show_regs() system hang when PKE initialization
   is not fully finished yet.

 - Add the 0x10-0x1f model IDs to the Zen5 range

 - Harden #VC instruction emulation some more

* tag 'x86-urgent-2024-04-28' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  cpu: Ignore "mitigations" kernel parameter if CPU_MITIGATIONS=n
  cpu: Re-enable CPU mitigations by default for !X86 architectures
  x86/tdx: Preserve shared bit on mprotect()
  x86/cpu: Fix check for RDPKRU in __show_regs()
  x86/CPU/AMD: Add models 0x10-0x1f to the Zen5 range
  x86/sev: Check for MWAITX and MONITORX opcodes in the #VC handler

Documentation/admin-guide/kernel-parameters.txt
arch/Kconfig
arch/x86/Kconfig
arch/x86/include/asm/coco.h
arch/x86/include/asm/pgtable_types.h
arch/x86/kernel/cpu/amd.c
arch/x86/kernel/process_64.c
arch/x86/kernel/sev-shared.c
include/linux/cpu.h
kernel/cpu.c

index 902ecd92a29fbe83df18d32d1a8fe652c8277132..213d0719e2b7a68e4daa12482a4c60361e19e3c4 100644 (file)
                        arch-independent options, each of which is an
                        aggregation of existing arch-specific options.
 
+                       Note, "mitigations" is supported if and only if the
+                       kernel was built with CPU_MITIGATIONS=y.
+
                        off
                                Disable all optional CPU mitigations.  This
                                improves system performance, but it may also
index 65afb1de48b36e843bd665a91df6b33badfd23d1..30f7930275d8388d6fca8ddcd97fbd56ec007873 100644 (file)
@@ -9,6 +9,14 @@
 #
 source "arch/$(SRCARCH)/Kconfig"
 
+config ARCH_CONFIGURES_CPU_MITIGATIONS
+       bool
+
+if !ARCH_CONFIGURES_CPU_MITIGATIONS
+config CPU_MITIGATIONS
+       def_bool y
+endif
+
 menu "General architecture-dependent options"
 
 config ARCH_HAS_SUBPAGE_FAULTS
index 4474bf32d0a4970daec7fad3f12f8aa4a9e43871..928820e61cb5020a1eeb3bcc99b0a72227ae6c82 100644 (file)
@@ -62,6 +62,7 @@ config X86
        select ACPI_HOTPLUG_CPU                 if ACPI_PROCESSOR && HOTPLUG_CPU
        select ARCH_32BIT_OFF_T                 if X86_32
        select ARCH_CLOCKSOURCE_INIT
+       select ARCH_CONFIGURES_CPU_MITIGATIONS
        select ARCH_CORRECT_STACKTRACE_ON_KRETPROBE
        select ARCH_ENABLE_HUGEPAGE_MIGRATION if X86_64 && HUGETLB_PAGE && MIGRATION
        select ARCH_ENABLE_MEMORY_HOTPLUG if X86_64
@@ -2488,17 +2489,21 @@ config PREFIX_SYMBOLS
        def_bool y
        depends on CALL_PADDING && !CFI_CLANG
 
-menuconfig SPECULATION_MITIGATIONS
-       bool "Mitigations for speculative execution vulnerabilities"
+menuconfig CPU_MITIGATIONS
+       bool "Mitigations for CPU vulnerabilities"
        default y
        help
-         Say Y here to enable options which enable mitigations for
-         speculative execution hardware vulnerabilities.
+         Say Y here to enable options which enable mitigations for hardware
+         vulnerabilities (usually related to speculative execution).
+         Mitigations can be disabled or restricted to SMT systems at runtime
+         via the "mitigations" kernel parameter.
 
-         If you say N, all mitigations will be disabled. You really
-         should know what you are doing to say so.
+         If you say N, all mitigations will be disabled.  This CANNOT be
+         overridden at runtime.
 
-if SPECULATION_MITIGATIONS
+         Say 'Y', unless you really know what you are doing.
+
+if CPU_MITIGATIONS
 
 config MITIGATION_PAGE_TABLE_ISOLATION
        bool "Remove the kernel mapping in user mode"
index c086699b0d0c59fc62834bb457963f1b81b541d3..aa6c8f8ca9588e90894750ce4f93226c05af9c23 100644 (file)
@@ -25,6 +25,7 @@ u64 cc_mkdec(u64 val);
 void cc_random_init(void);
 #else
 #define cc_vendor (CC_VENDOR_NONE)
+static const u64 cc_mask = 0;
 
 static inline u64 cc_mkenc(u64 val)
 {
index 0b748ee16b3d94ea09516ee14e187dbebae0bf4a..9abb8cc4cd4747f4982655d425df997852b1553b 100644 (file)
 #define _COMMON_PAGE_CHG_MASK  (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \
                                 _PAGE_SPECIAL | _PAGE_ACCESSED |       \
                                 _PAGE_DIRTY_BITS | _PAGE_SOFT_DIRTY |  \
-                                _PAGE_DEVMAP | _PAGE_ENC | _PAGE_UFFD_WP)
+                                _PAGE_DEVMAP | _PAGE_CC | _PAGE_UFFD_WP)
 #define _PAGE_CHG_MASK (_COMMON_PAGE_CHG_MASK | _PAGE_PAT)
 #define _HPAGE_CHG_MASK (_COMMON_PAGE_CHG_MASK | _PAGE_PSE | _PAGE_PAT_LARGE)
 
@@ -173,6 +173,7 @@ enum page_cache_mode {
 };
 #endif
 
+#define _PAGE_CC               (_AT(pteval_t, cc_mask))
 #define _PAGE_ENC              (_AT(pteval_t, sme_me_mask))
 
 #define _PAGE_CACHE_MASK       (_PAGE_PWT | _PAGE_PCD | _PAGE_PAT)
index cb9eece55904d049edc600960bdaa0db58765459..307302af0aeee22d0f3871d06ee117bd6c82818d 100644 (file)
@@ -459,8 +459,7 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
 
        case 0x1a:
                switch (c->x86_model) {
-               case 0x00 ... 0x0f:
-               case 0x20 ... 0x2f:
+               case 0x00 ... 0x2f:
                case 0x40 ... 0x4f:
                case 0x70 ... 0x7f:
                        setup_force_cpu_cap(X86_FEATURE_ZEN5);
index 7062b84dd467d62ac1aed8c4fe4bdb86d5a7ac61..6d3d20e3e43a9b005f725d1e89dcc8fd81560dcd 100644 (file)
@@ -139,7 +139,7 @@ void __show_regs(struct pt_regs *regs, enum show_regs_mode mode,
                       log_lvl, d3, d6, d7);
        }
 
-       if (cpu_feature_enabled(X86_FEATURE_OSPKE))
+       if (cr4 & X86_CR4_PKE)
                printk("%sPKRU: %08x\n", log_lvl, read_pkru());
 }
 
index 8b04958da5e7d6c4bd096cffdaa4874e73433846..b4f8fa0f722cd6749079ba81d69458200c5051bb 100644 (file)
@@ -1203,12 +1203,14 @@ static enum es_result vc_check_opcode_bytes(struct es_em_ctxt *ctxt,
                break;
 
        case SVM_EXIT_MONITOR:
-               if (opcode == 0x010f && modrm == 0xc8)
+               /* MONITOR and MONITORX instructions generate the same error code */
+               if (opcode == 0x010f && (modrm == 0xc8 || modrm == 0xfa))
                        return ES_OK;
                break;
 
        case SVM_EXIT_MWAIT:
-               if (opcode == 0x010f && modrm == 0xc9)
+               /* MWAIT and MWAITX instructions generate the same error code */
+               if (opcode == 0x010f && (modrm == 0xc9 || modrm == 0xfb))
                        return ES_OK;
                break;
 
index 272e4e79e15c48db487feba3b7e6103e71b21e8d..861c3bfc5f1700db69d90168c239a935ebad76ca 100644 (file)
@@ -221,7 +221,18 @@ void cpuhp_report_idle_dead(void);
 static inline void cpuhp_report_idle_dead(void) { }
 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
 
+#ifdef CONFIG_CPU_MITIGATIONS
 extern bool cpu_mitigations_off(void);
 extern bool cpu_mitigations_auto_nosmt(void);
+#else
+static inline bool cpu_mitigations_off(void)
+{
+       return true;
+}
+static inline bool cpu_mitigations_auto_nosmt(void)
+{
+       return false;
+}
+#endif
 
 #endif /* _LINUX_CPU_H_ */
index 07ad53b7f11952080e890ed91f99f3e762bf984d..63447eb85dab6bd0fa2ab23c25bffdf788a2b9c1 100644 (file)
@@ -3196,6 +3196,7 @@ void __init boot_cpu_hotplug_init(void)
        this_cpu_write(cpuhp_state.target, CPUHP_ONLINE);
 }
 
+#ifdef CONFIG_CPU_MITIGATIONS
 /*
  * These are used for a global "mitigations=" cmdline option for toggling
  * optional CPU mitigations.
@@ -3206,9 +3207,7 @@ enum cpu_mitigations {
        CPU_MITIGATIONS_AUTO_NOSMT,
 };
 
-static enum cpu_mitigations cpu_mitigations __ro_after_init =
-       IS_ENABLED(CONFIG_SPECULATION_MITIGATIONS) ? CPU_MITIGATIONS_AUTO :
-                                                    CPU_MITIGATIONS_OFF;
+static enum cpu_mitigations cpu_mitigations __ro_after_init = CPU_MITIGATIONS_AUTO;
 
 static int __init mitigations_parse_cmdline(char *arg)
 {
@@ -3224,7 +3223,6 @@ static int __init mitigations_parse_cmdline(char *arg)
 
        return 0;
 }
-early_param("mitigations", mitigations_parse_cmdline);
 
 /* mitigations=off */
 bool cpu_mitigations_off(void)
@@ -3239,3 +3237,11 @@ bool cpu_mitigations_auto_nosmt(void)
        return cpu_mitigations == CPU_MITIGATIONS_AUTO_NOSMT;
 }
 EXPORT_SYMBOL_GPL(cpu_mitigations_auto_nosmt);
+#else
+static int __init mitigations_parse_cmdline(char *arg)
+{
+       pr_crit("Kernel compiled without mitigations, ignoring 'mitigations'; system may still be vulnerable\n");
+       return 0;
+}
+#endif
+early_param("mitigations", mitigations_parse_cmdline);