From: Liran Alon Subject: Re: [PATCH v2] KVM: X86: Allow userspace to define the microcode version Date: Mon, 26 Feb 2018 02:31:24 -0800 (PST) Message-ID: <0e0d4ea1-a246-4d6d-ad24-d2d00561a27f@default> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: , , , To: Return-path: Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org ----- kernellwp@gmail.com wrote: > From: Wanpeng Li >=20 > Linux (among the others) has checks to make sure that certain features >=20 > aren't enabled on a certain family/model/stepping if the microcode > version=20 > isn't greater than or equal to a known good version. >=20 > 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. >=20 > Suggested-by: Filippo Sironi > Cc: Paolo Bonzini > Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 > Cc: Liran Alon > Signed-off-by: Wanpeng Li > --- > v1 -> v2: > * add MSR_IA32_UCODE_REV to emulated_msrs >=20 > arch/x86/include/asm/kvm_host.h | 1 + > arch/x86/kvm/x86.c | 9 +++++++-- > 2 files changed, 8 insertions(+), 2 deletions(-) >=20 > diff --git a/arch/x86/include/asm/kvm_host.h > b/arch/x86/include/asm/kvm_host.h > index 938d453..6e13f2f 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -507,6 +507,7 @@ struct kvm_vcpu_arch { > =09u64 smi_count; > =09bool tpr_access_reporting; > =09u64 ia32_xss; > +=09u32 microcode_version; > =20 > =09/* > =09 * Paging state of the vcpu > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 1a3ed81..4ae9517 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -1047,6 +1047,7 @@ static u32 emulated_msrs[] =3D { > =09MSR_SMI_COUNT, > =09MSR_PLATFORM_INFO, > =09MSR_MISC_FEATURES_ENABLES, > +=09MSR_IA32_UCODE_REV, > }; > =20 > static unsigned num_emulated_msrs; > @@ -2247,7 +2248,6 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, > struct msr_data *msr_info) > =20 > =09switch (msr) { > =09case MSR_AMD64_NB_CFG: > -=09case MSR_IA32_UCODE_REV: > =09case MSR_IA32_UCODE_WRITE: > =09case MSR_VM_HSAVE_PA: > =09case MSR_AMD64_PATCH_LOADER: > @@ -2255,6 +2255,10 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, > struct msr_data *msr_info) > =09case MSR_AMD64_DC_CFG: > =09=09break; > =20 > +=09case MSR_IA32_UCODE_REV: > +=09=09if (msr_info->host_initiated) > +=09=09=09vcpu->arch.microcode_version =3D data >> 32; > +=09=09break; > =09case MSR_EFER: > =09=09return set_efer(vcpu, data); > =09case MSR_K7_HWCR: > @@ -2550,7 +2554,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, > struct msr_data *msr_info) > =09=09msr_info->data =3D 0; > =09=09break; > =09case MSR_IA32_UCODE_REV: > -=09=09msr_info->data =3D 0x100000000ULL; > +=09=09msr_info->data =3D (u64)vcpu->arch.microcode_version << 32; > =09=09break; > =09case MSR_MTRRcap: > =09case 0x200 ... 0x2ff: > @@ -8232,6 +8236,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool > init_event) > =09vcpu->arch.regs_dirty =3D ~0; > =20 > =09vcpu->arch.ia32_xss =3D 0; > +=09vcpu->arch.microcode_version =3D 0x1; > =20 > =09kvm_x86_ops->vcpu_reset(vcpu, init_event); > } > --=20 > 2.7.4 Reviewed-by: Liran Alon