Skip to content

Commit a780a3e

Browse files
Wanpeng Libonzini
authored andcommitted
KVM: X86: Fix reserved bits check for MOV to CR3
MSB of CR3 is a reserved bit if the PCIDE bit is not set in CR4. It should be checked when PCIDE bit is not set, however commit 'd1cd3ce900441 ("KVM: MMU: check guest CR3 reserved bits based on its physical address width")' removes the bit 63 checking unconditionally. This patch fixes it by checking bit 63 of CR3 when PCIDE bit is not set in CR4. Fixes: d1cd3ce (KVM: MMU: check guest CR3 reserved bits based on its physical address width) Cc: Paolo Bonzini <[email protected]> Cc: Radim Krčmář <[email protected]> Cc: Liran Alon <[email protected]> Cc: [email protected] Reviewed-by: Junaid Shahid <[email protected]> Signed-off-by: Wanpeng Li <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 64f7a11 commit a780a3e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

arch/x86/kvm/emulate.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4189,7 +4189,9 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
41894189
maxphyaddr = eax & 0xff;
41904190
else
41914191
maxphyaddr = 36;
4192-
rsvd = rsvd_bits(maxphyaddr, 62);
4192+
rsvd = rsvd_bits(maxphyaddr, 63);
4193+
if (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_PCIDE)
4194+
rsvd &= ~CR3_PCID_INVD;
41934195
}
41944196

41954197
if (new_val & rsvd)

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
856856
}
857857

858858
if (is_long_mode(vcpu) &&
859-
(cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 62)))
859+
(cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 63)))
860860
return 1;
861861
else if (is_pae(vcpu) && is_paging(vcpu) &&
862862
!load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3))

0 commit comments

Comments
 (0)