Skip to content

Commit aec147c

Browse files
committed
Merge tag 'x86-urgent-2024-04-28' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
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
2 parents 8d62e9b + ce0abef commit aec147c

File tree

10 files changed

+53
-17
lines changed

10 files changed

+53
-17
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,6 +3423,9 @@
34233423
arch-independent options, each of which is an
34243424
aggregation of existing arch-specific options.
34253425

3426+
Note, "mitigations" is supported if and only if the
3427+
kernel was built with CPU_MITIGATIONS=y.
3428+
34263429
off
34273430
Disable all optional CPU mitigations. This
34283431
improves system performance, but it may also

arch/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
#
1010
source "arch/$(SRCARCH)/Kconfig"
1111

12+
config ARCH_CONFIGURES_CPU_MITIGATIONS
13+
bool
14+
15+
if !ARCH_CONFIGURES_CPU_MITIGATIONS
16+
config CPU_MITIGATIONS
17+
def_bool y
18+
endif
19+
1220
menu "General architecture-dependent options"
1321

1422
config ARCH_HAS_SUBPAGE_FAULTS

arch/x86/Kconfig

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ config X86
6262
select ACPI_HOTPLUG_CPU if ACPI_PROCESSOR && HOTPLUG_CPU
6363
select ARCH_32BIT_OFF_T if X86_32
6464
select ARCH_CLOCKSOURCE_INIT
65+
select ARCH_CONFIGURES_CPU_MITIGATIONS
6566
select ARCH_CORRECT_STACKTRACE_ON_KRETPROBE
6667
select ARCH_ENABLE_HUGEPAGE_MIGRATION if X86_64 && HUGETLB_PAGE && MIGRATION
6768
select ARCH_ENABLE_MEMORY_HOTPLUG if X86_64
@@ -2488,17 +2489,21 @@ config PREFIX_SYMBOLS
24882489
def_bool y
24892490
depends on CALL_PADDING && !CFI_CLANG
24902491

2491-
menuconfig SPECULATION_MITIGATIONS
2492-
bool "Mitigations for speculative execution vulnerabilities"
2492+
menuconfig CPU_MITIGATIONS
2493+
bool "Mitigations for CPU vulnerabilities"
24932494
default y
24942495
help
2495-
Say Y here to enable options which enable mitigations for
2496-
speculative execution hardware vulnerabilities.
2496+
Say Y here to enable options which enable mitigations for hardware
2497+
vulnerabilities (usually related to speculative execution).
2498+
Mitigations can be disabled or restricted to SMT systems at runtime
2499+
via the "mitigations" kernel parameter.
24972500

2498-
If you say N, all mitigations will be disabled. You really
2499-
should know what you are doing to say so.
2501+
If you say N, all mitigations will be disabled. This CANNOT be
2502+
overridden at runtime.
25002503

2501-
if SPECULATION_MITIGATIONS
2504+
Say 'Y', unless you really know what you are doing.
2505+
2506+
if CPU_MITIGATIONS
25022507

25032508
config MITIGATION_PAGE_TABLE_ISOLATION
25042509
bool "Remove the kernel mapping in user mode"

arch/x86/include/asm/coco.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ u64 cc_mkdec(u64 val);
2525
void cc_random_init(void);
2626
#else
2727
#define cc_vendor (CC_VENDOR_NONE)
28+
static const u64 cc_mask = 0;
2829

2930
static inline u64 cc_mkenc(u64 val)
3031
{

arch/x86/include/asm/pgtable_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
#define _COMMON_PAGE_CHG_MASK (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \
149149
_PAGE_SPECIAL | _PAGE_ACCESSED | \
150150
_PAGE_DIRTY_BITS | _PAGE_SOFT_DIRTY | \
151-
_PAGE_DEVMAP | _PAGE_ENC | _PAGE_UFFD_WP)
151+
_PAGE_DEVMAP | _PAGE_CC | _PAGE_UFFD_WP)
152152
#define _PAGE_CHG_MASK (_COMMON_PAGE_CHG_MASK | _PAGE_PAT)
153153
#define _HPAGE_CHG_MASK (_COMMON_PAGE_CHG_MASK | _PAGE_PSE | _PAGE_PAT_LARGE)
154154

@@ -173,6 +173,7 @@ enum page_cache_mode {
173173
};
174174
#endif
175175

176+
#define _PAGE_CC (_AT(pteval_t, cc_mask))
176177
#define _PAGE_ENC (_AT(pteval_t, sme_me_mask))
177178

178179
#define _PAGE_CACHE_MASK (_PAGE_PWT | _PAGE_PCD | _PAGE_PAT)

arch/x86/kernel/cpu/amd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,7 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
459459

460460
case 0x1a:
461461
switch (c->x86_model) {
462-
case 0x00 ... 0x0f:
463-
case 0x20 ... 0x2f:
462+
case 0x00 ... 0x2f:
464463
case 0x40 ... 0x4f:
465464
case 0x70 ... 0x7f:
466465
setup_force_cpu_cap(X86_FEATURE_ZEN5);

arch/x86/kernel/process_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void __show_regs(struct pt_regs *regs, enum show_regs_mode mode,
139139
log_lvl, d3, d6, d7);
140140
}
141141

142-
if (cpu_feature_enabled(X86_FEATURE_OSPKE))
142+
if (cr4 & X86_CR4_PKE)
143143
printk("%sPKRU: %08x\n", log_lvl, read_pkru());
144144
}
145145

arch/x86/kernel/sev-shared.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,12 +1203,14 @@ static enum es_result vc_check_opcode_bytes(struct es_em_ctxt *ctxt,
12031203
break;
12041204

12051205
case SVM_EXIT_MONITOR:
1206-
if (opcode == 0x010f && modrm == 0xc8)
1206+
/* MONITOR and MONITORX instructions generate the same error code */
1207+
if (opcode == 0x010f && (modrm == 0xc8 || modrm == 0xfa))
12071208
return ES_OK;
12081209
break;
12091210

12101211
case SVM_EXIT_MWAIT:
1211-
if (opcode == 0x010f && modrm == 0xc9)
1212+
/* MWAIT and MWAITX instructions generate the same error code */
1213+
if (opcode == 0x010f && (modrm == 0xc9 || modrm == 0xfb))
12121214
return ES_OK;
12131215
break;
12141216

include/linux/cpu.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,18 @@ void cpuhp_report_idle_dead(void);
221221
static inline void cpuhp_report_idle_dead(void) { }
222222
#endif /* #ifdef CONFIG_HOTPLUG_CPU */
223223

224+
#ifdef CONFIG_CPU_MITIGATIONS
224225
extern bool cpu_mitigations_off(void);
225226
extern bool cpu_mitigations_auto_nosmt(void);
227+
#else
228+
static inline bool cpu_mitigations_off(void)
229+
{
230+
return true;
231+
}
232+
static inline bool cpu_mitigations_auto_nosmt(void)
233+
{
234+
return false;
235+
}
236+
#endif
226237

227238
#endif /* _LINUX_CPU_H_ */

kernel/cpu.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,6 +3196,7 @@ void __init boot_cpu_hotplug_init(void)
31963196
this_cpu_write(cpuhp_state.target, CPUHP_ONLINE);
31973197
}
31983198

3199+
#ifdef CONFIG_CPU_MITIGATIONS
31993200
/*
32003201
* These are used for a global "mitigations=" cmdline option for toggling
32013202
* optional CPU mitigations.
@@ -3206,9 +3207,7 @@ enum cpu_mitigations {
32063207
CPU_MITIGATIONS_AUTO_NOSMT,
32073208
};
32083209

3209-
static enum cpu_mitigations cpu_mitigations __ro_after_init =
3210-
IS_ENABLED(CONFIG_SPECULATION_MITIGATIONS) ? CPU_MITIGATIONS_AUTO :
3211-
CPU_MITIGATIONS_OFF;
3210+
static enum cpu_mitigations cpu_mitigations __ro_after_init = CPU_MITIGATIONS_AUTO;
32123211

32133212
static int __init mitigations_parse_cmdline(char *arg)
32143213
{
@@ -3224,7 +3223,6 @@ static int __init mitigations_parse_cmdline(char *arg)
32243223

32253224
return 0;
32263225
}
3227-
early_param("mitigations", mitigations_parse_cmdline);
32283226

32293227
/* mitigations=off */
32303228
bool cpu_mitigations_off(void)
@@ -3239,3 +3237,11 @@ bool cpu_mitigations_auto_nosmt(void)
32393237
return cpu_mitigations == CPU_MITIGATIONS_AUTO_NOSMT;
32403238
}
32413239
EXPORT_SYMBOL_GPL(cpu_mitigations_auto_nosmt);
3240+
#else
3241+
static int __init mitigations_parse_cmdline(char *arg)
3242+
{
3243+
pr_crit("Kernel compiled without mitigations, ignoring 'mitigations'; system may still be vulnerable\n");
3244+
return 0;
3245+
}
3246+
#endif
3247+
early_param("mitigations", mitigations_parse_cmdline);

0 commit comments

Comments
 (0)