diff options
-rw-r--r-- | arch/x86/include/asm/cpufeatures.h | 2 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/bugs.c | 13 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/common.c | 9 | ||||
-rw-r--r-- | arch/x86/kvm/cpuid.c | 10 | ||||
-rw-r--r-- | arch/x86/kvm/svm.c | 8 |
5 files changed, 28 insertions, 14 deletions
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index fb00a2fca990..5701f5cecd31 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h | |||
@@ -282,7 +282,9 @@ | |||
282 | #define X86_FEATURE_AMD_IBPB (13*32+12) /* "" Indirect Branch Prediction Barrier */ | 282 | #define X86_FEATURE_AMD_IBPB (13*32+12) /* "" Indirect Branch Prediction Barrier */ |
283 | #define X86_FEATURE_AMD_IBRS (13*32+14) /* "" Indirect Branch Restricted Speculation */ | 283 | #define X86_FEATURE_AMD_IBRS (13*32+14) /* "" Indirect Branch Restricted Speculation */ |
284 | #define X86_FEATURE_AMD_STIBP (13*32+15) /* "" Single Thread Indirect Branch Predictors */ | 284 | #define X86_FEATURE_AMD_STIBP (13*32+15) /* "" Single Thread Indirect Branch Predictors */ |
285 | #define X86_FEATURE_AMD_SSBD (13*32+24) /* "" Speculative Store Bypass Disable */ | ||
285 | #define X86_FEATURE_VIRT_SSBD (13*32+25) /* Virtualized Speculative Store Bypass Disable */ | 286 | #define X86_FEATURE_VIRT_SSBD (13*32+25) /* Virtualized Speculative Store Bypass Disable */ |
287 | #define X86_FEATURE_AMD_SSB_NO (13*32+26) /* "" Speculative Store Bypass is fixed in hardware. */ | ||
286 | 288 | ||
287 | /* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */ | 289 | /* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */ |
288 | #define X86_FEATURE_DTHERM (14*32+ 0) /* Digital Thermal Sensor */ | 290 | #define X86_FEATURE_DTHERM (14*32+ 0) /* Digital Thermal Sensor */ |
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 7416fc206b4a..cd0fda1fff6d 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c | |||
@@ -529,18 +529,15 @@ static enum ssb_mitigation __init __ssb_select_mitigation(void) | |||
529 | if (mode == SPEC_STORE_BYPASS_DISABLE) { | 529 | if (mode == SPEC_STORE_BYPASS_DISABLE) { |
530 | setup_force_cpu_cap(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE); | 530 | setup_force_cpu_cap(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE); |
531 | /* | 531 | /* |
532 | * Intel uses the SPEC CTRL MSR Bit(2) for this, while AMD uses | 532 | * Intel uses the SPEC CTRL MSR Bit(2) for this, while AMD may |
533 | * a completely different MSR and bit dependent on family. | 533 | * use a completely different MSR and bit dependent on family. |
534 | */ | 534 | */ |
535 | switch (boot_cpu_data.x86_vendor) { | 535 | if (!static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL)) |
536 | case X86_VENDOR_INTEL: | 536 | x86_amd_ssb_disable(); |
537 | else { | ||
537 | x86_spec_ctrl_base |= SPEC_CTRL_SSBD; | 538 | x86_spec_ctrl_base |= SPEC_CTRL_SSBD; |
538 | x86_spec_ctrl_mask |= SPEC_CTRL_SSBD; | 539 | x86_spec_ctrl_mask |= SPEC_CTRL_SSBD; |
539 | wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); | 540 | wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); |
540 | break; | ||
541 | case X86_VENDOR_AMD: | ||
542 | x86_amd_ssb_disable(); | ||
543 | break; | ||
544 | } | 541 | } |
545 | } | 542 | } |
546 | 543 | ||
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 95c8e507580d..910b47ee8078 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c | |||
@@ -803,6 +803,12 @@ static void init_speculation_control(struct cpuinfo_x86 *c) | |||
803 | set_cpu_cap(c, X86_FEATURE_STIBP); | 803 | set_cpu_cap(c, X86_FEATURE_STIBP); |
804 | set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL); | 804 | set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL); |
805 | } | 805 | } |
806 | |||
807 | if (cpu_has(c, X86_FEATURE_AMD_SSBD)) { | ||
808 | set_cpu_cap(c, X86_FEATURE_SSBD); | ||
809 | set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL); | ||
810 | clear_cpu_cap(c, X86_FEATURE_VIRT_SSBD); | ||
811 | } | ||
806 | } | 812 | } |
807 | 813 | ||
808 | void get_cpu_cap(struct cpuinfo_x86 *c) | 814 | void get_cpu_cap(struct cpuinfo_x86 *c) |
@@ -992,7 +998,8 @@ static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c) | |||
992 | rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap); | 998 | rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap); |
993 | 999 | ||
994 | if (!x86_match_cpu(cpu_no_spec_store_bypass) && | 1000 | if (!x86_match_cpu(cpu_no_spec_store_bypass) && |
995 | !(ia32_cap & ARCH_CAP_SSB_NO)) | 1001 | !(ia32_cap & ARCH_CAP_SSB_NO) && |
1002 | !cpu_has(c, X86_FEATURE_AMD_SSB_NO)) | ||
996 | setup_force_cpu_bug(X86_BUG_SPEC_STORE_BYPASS); | 1003 | setup_force_cpu_bug(X86_BUG_SPEC_STORE_BYPASS); |
997 | 1004 | ||
998 | if (x86_match_cpu(cpu_no_meltdown)) | 1005 | if (x86_match_cpu(cpu_no_meltdown)) |
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 92bf2f2e7cdd..f4f30d0c25c4 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c | |||
@@ -379,7 +379,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, | |||
379 | 379 | ||
380 | /* cpuid 0x80000008.ebx */ | 380 | /* cpuid 0x80000008.ebx */ |
381 | const u32 kvm_cpuid_8000_0008_ebx_x86_features = | 381 | const u32 kvm_cpuid_8000_0008_ebx_x86_features = |
382 | F(AMD_IBPB) | F(AMD_IBRS) | F(VIRT_SSBD); | 382 | F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) | |
383 | F(AMD_SSB_NO); | ||
383 | 384 | ||
384 | /* cpuid 0xC0000001.edx */ | 385 | /* cpuid 0xC0000001.edx */ |
385 | const u32 kvm_cpuid_C000_0001_edx_x86_features = | 386 | const u32 kvm_cpuid_C000_0001_edx_x86_features = |
@@ -664,7 +665,12 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, | |||
664 | entry->ebx |= F(VIRT_SSBD); | 665 | entry->ebx |= F(VIRT_SSBD); |
665 | entry->ebx &= kvm_cpuid_8000_0008_ebx_x86_features; | 666 | entry->ebx &= kvm_cpuid_8000_0008_ebx_x86_features; |
666 | cpuid_mask(&entry->ebx, CPUID_8000_0008_EBX); | 667 | cpuid_mask(&entry->ebx, CPUID_8000_0008_EBX); |
667 | if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD)) | 668 | /* |
669 | * The preference is to use SPEC CTRL MSR instead of the | ||
670 | * VIRT_SPEC MSR. | ||
671 | */ | ||
672 | if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD) && | ||
673 | !boot_cpu_has(X86_FEATURE_AMD_SSBD)) | ||
668 | entry->ebx |= F(VIRT_SSBD); | 674 | entry->ebx |= F(VIRT_SSBD); |
669 | break; | 675 | break; |
670 | } | 676 | } |
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 26110c202b19..950ec50f77c3 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c | |||
@@ -4115,7 +4115,8 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) | |||
4115 | break; | 4115 | break; |
4116 | case MSR_IA32_SPEC_CTRL: | 4116 | case MSR_IA32_SPEC_CTRL: |
4117 | if (!msr_info->host_initiated && | 4117 | if (!msr_info->host_initiated && |
4118 | !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS)) | 4118 | !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS) && |
4119 | !guest_cpuid_has(vcpu, X86_FEATURE_AMD_SSBD)) | ||
4119 | return 1; | 4120 | return 1; |
4120 | 4121 | ||
4121 | msr_info->data = svm->spec_ctrl; | 4122 | msr_info->data = svm->spec_ctrl; |
@@ -4217,11 +4218,12 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) | |||
4217 | break; | 4218 | break; |
4218 | case MSR_IA32_SPEC_CTRL: | 4219 | case MSR_IA32_SPEC_CTRL: |
4219 | if (!msr->host_initiated && | 4220 | if (!msr->host_initiated && |
4220 | !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS)) | 4221 | !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS) && |
4222 | !guest_cpuid_has(vcpu, X86_FEATURE_AMD_SSBD)) | ||
4221 | return 1; | 4223 | return 1; |
4222 | 4224 | ||
4223 | /* The STIBP bit doesn't fault even if it's not advertised */ | 4225 | /* The STIBP bit doesn't fault even if it's not advertised */ |
4224 | if (data & ~(SPEC_CTRL_IBRS | SPEC_CTRL_STIBP)) | 4226 | if (data & ~(SPEC_CTRL_IBRS | SPEC_CTRL_STIBP | SPEC_CTRL_SSBD)) |
4225 | return 1; | 4227 | return 1; |
4226 | 4228 | ||
4227 | svm->spec_ctrl = data; | 4229 | svm->spec_ctrl = data; |