Skip to content

Commit 518e7b9

Browse files
Wanpeng Lirkrcmar
authored andcommitted
KVM: X86: Allow userspace to define the microcode version
Linux (among the others) has checks to make sure that certain features aren't enabled on a certain family/model/stepping if the microcode version isn't greater than or equal to a known good version. By exposing the real microcode version, we're preventing buggy guests that don't check that they are running virtualized (i.e., they should trust the hypervisor) from disabling features that are effectively not buggy. Suggested-by: Filippo Sironi <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Radim Krčmář <[email protected]> Cc: Liran Alon <[email protected]> Cc: Nadav Amit <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Tom Lendacky <[email protected]> Signed-off-by: Wanpeng Li <[email protected]> Reviewed-by: Paolo Bonzini <[email protected]> Signed-off-by: Radim Krčmář <[email protected]>
1 parent 66421c1 commit 518e7b9

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ struct kvm_vcpu_arch {
507507
u64 smi_count;
508508
bool tpr_access_reporting;
509509
u64 ia32_xss;
510+
u64 microcode_version;
510511

511512
/*
512513
* Paging state of the vcpu

arch/x86/kvm/svm.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,7 @@ static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
19071907
u32 dummy;
19081908
u32 eax = 1;
19091909

1910+
vcpu->arch.microcode_version = 0x01000065;
19101911
svm->spec_ctrl = 0;
19111912

19121913
if (!init_event) {
@@ -3962,9 +3963,6 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
39623963

39633964
msr_info->data = svm->spec_ctrl;
39643965
break;
3965-
case MSR_IA32_UCODE_REV:
3966-
msr_info->data = 0x01000065;
3967-
break;
39683966
case MSR_F15H_IC_CFG: {
39693967

39703968
int family, model;

arch/x86/kvm/vmx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5771,6 +5771,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
57715771
vmx->rmode.vm86_active = 0;
57725772
vmx->spec_ctrl = 0;
57735773

5774+
vcpu->arch.microcode_version = 0x100000000ULL;
57745775
vmx->vcpu.arch.regs[VCPU_REGS_RDX] = get_rdx_init_val();
57755776
kvm_set_cr8(vcpu, 0);
57765777

arch/x86/kvm/x86.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,13 +1055,17 @@ static unsigned num_emulated_msrs;
10551055
*/
10561056
static u32 msr_based_features[] = {
10571057
MSR_F10H_DECFG,
1058+
MSR_IA32_UCODE_REV,
10581059
};
10591060

10601061
static unsigned int num_msr_based_features;
10611062

10621063
static int kvm_get_msr_feature(struct kvm_msr_entry *msr)
10631064
{
10641065
switch (msr->index) {
1066+
case MSR_IA32_UCODE_REV:
1067+
rdmsrl(msr->index, msr->data);
1068+
break;
10651069
default:
10661070
if (kvm_x86_ops->get_msr_feature(msr))
10671071
return 1;
@@ -2257,14 +2261,17 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
22572261

22582262
switch (msr) {
22592263
case MSR_AMD64_NB_CFG:
2260-
case MSR_IA32_UCODE_REV:
22612264
case MSR_IA32_UCODE_WRITE:
22622265
case MSR_VM_HSAVE_PA:
22632266
case MSR_AMD64_PATCH_LOADER:
22642267
case MSR_AMD64_BU_CFG2:
22652268
case MSR_AMD64_DC_CFG:
22662269
break;
22672270

2271+
case MSR_IA32_UCODE_REV:
2272+
if (msr_info->host_initiated)
2273+
vcpu->arch.microcode_version = data;
2274+
break;
22682275
case MSR_EFER:
22692276
return set_efer(vcpu, data);
22702277
case MSR_K7_HWCR:
@@ -2560,7 +2567,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
25602567
msr_info->data = 0;
25612568
break;
25622569
case MSR_IA32_UCODE_REV:
2563-
msr_info->data = 0x100000000ULL;
2570+
msr_info->data = vcpu->arch.microcode_version;
25642571
break;
25652572
case MSR_MTRRcap:
25662573
case 0x200 ... 0x2ff:

0 commit comments

Comments
 (0)