From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liran Alon Subject: Re: [PATCH 1/2] KVM: X86: Fix CR3 reserve bits Date: Sun, 13 May 2018 00:53:10 -0700 (PDT) Message-ID: 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 > MSB of CR3 is a reserved bit if the PCIDE bit is not set in CR4.=20 > It should be checked when PCIDE bit is not set, however commit=20 > 'd1cd3ce900441 ("KVM: MMU: check guest CR3 reserved bits based on=20 > its physical address width")' removes the bit 63 checking=20 > unconditionally. This patch fixes it by checking bit 63 of CR3=20 > when PCIDE bit is not set in CR4. >=20 > Fixes: d1cd3ce900441 (KVM: MMU: check guest CR3 reserved bits based on > its physical address width) > Cc: Paolo Bonzini > Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 > Cc: Junaid Shahid > Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/emulate.c | 4 +++- > arch/x86/kvm/x86.c | 2 +- > 2 files changed, 4 insertions(+), 2 deletions(-) >=20 > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > index b3705ae..b21f427 100644 > --- a/arch/x86/kvm/emulate.c > +++ b/arch/x86/kvm/emulate.c > @@ -4189,7 +4189,9 @@ static int check_cr_write(struct > x86_emulate_ctxt *ctxt) > =09=09=09=09maxphyaddr =3D eax & 0xff; > =09=09=09else > =09=09=09=09maxphyaddr =3D 36; > -=09=09=09rsvd =3D rsvd_bits(maxphyaddr, 62); > +=09=09=09if (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_PCIDE) > +=09=09=09=09new_val &=3D ~CR3_PCID_INVD; > +=09=09=09rsvd =3D rsvd_bits(maxphyaddr, 63); I would prefer instead to do this: if (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_PCIDE) rsvd &=3D ~CR3_PCID_INVD; It makes more sense as opposed to temporary removing the CR3_PCID_INVD bit = from new_val. > =09=09} > =20 > =09=09if (new_val & rsvd) > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 87e4805..9a90668 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -863,7 +863,7 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned > long cr3) > =09} > =20 > =09if (is_long_mode(vcpu) && > -=09 (cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 62))) > +=09 (cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 63))) > =09=09return 1; > =09else if (is_pae(vcpu) && is_paging(vcpu) && > =09=09 !load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3)) > --=20 > 2.7.4