Skip to content

Commit 0548721

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: x86: Don't attempt to load PDPTRs when 64-bit mode is enabled
Don't attempt to load PDPTRs if EFER.LME=1, i.e. if 64-bit mode is enabled. A recent change to reload the PDTPRs when CR0.CD or CR0.NW is toggled botched the EFER.LME handling and sends KVM down the PDTPR path when is_paging() is true, i.e. when the guest toggles CD/NW in 64-bit mode. Split the CR0 checks for 64-bit vs. 32-bit PAE into separate paths. The 64-bit path is specifically checking state when paging is toggled on, i.e. CR0.PG transititions from 0->1. The PDPTR path now needs to run if the new CR0 state has paging enabled, irrespective of whether paging was already enabled. Trying to shave a few cycles to make the PDPTR path an "else if" case is a mess. Fixes: d42e3fa ("kvm: x86: Read PDPTEs on CR0.CD and CR0.NW changes") Cc: Jim Mattson <[email protected]> Cc: Oliver Upton <[email protected]> Cc: Peter Shier <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Reviewed-by: Jim Mattson <[email protected]> Reviewed-by: Maxim Levitsky <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 06a81c1 commit 0548721

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

arch/x86/kvm/x86.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -820,22 +820,22 @@ int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
820820
if ((cr0 & X86_CR0_PG) && !(cr0 & X86_CR0_PE))
821821
return 1;
822822

823-
if (cr0 & X86_CR0_PG) {
824823
#ifdef CONFIG_X86_64
825-
if (!is_paging(vcpu) && (vcpu->arch.efer & EFER_LME)) {
826-
int cs_db, cs_l;
824+
if ((vcpu->arch.efer & EFER_LME) && !is_paging(vcpu) &&
825+
(cr0 & X86_CR0_PG)) {
826+
int cs_db, cs_l;
827827

828-
if (!is_pae(vcpu))
829-
return 1;
830-
kvm_x86_ops.get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
831-
if (cs_l)
832-
return 1;
833-
} else
834-
#endif
835-
if (is_pae(vcpu) && ((cr0 ^ old_cr0) & pdptr_bits) &&
836-
!load_pdptrs(vcpu, vcpu->arch.walk_mmu, kvm_read_cr3(vcpu)))
828+
if (!is_pae(vcpu))
829+
return 1;
830+
kvm_x86_ops.get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
831+
if (cs_l)
837832
return 1;
838833
}
834+
#endif
835+
if (!(vcpu->arch.efer & EFER_LME) && (cr0 & X86_CR0_PG) &&
836+
is_pae(vcpu) && ((cr0 ^ old_cr0) & pdptr_bits) &&
837+
!load_pdptrs(vcpu, vcpu->arch.walk_mmu, kvm_read_cr3(vcpu)))
838+
return 1;
839839

840840
if (!(cr0 & X86_CR0_PG) && kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE))
841841
return 1;

0 commit comments

Comments
 (0)