Skip to content

Commit d42e3fa

Browse files
jsmattsonjrbonzini
authored andcommitted
kvm: x86: Read PDPTEs on CR0.CD and CR0.NW changes
According to the SDM, when PAE paging would be in use following a MOV-to-CR0 that modifies any of CR0.CD, CR0.NW, or CR0.PG, then the PDPTEs are loaded from the address in CR3. Previously, kvm only loaded the PDPTEs when PAE paging would be in use following a MOV-to-CR0 that modified CR0.PG. Signed-off-by: Jim Mattson <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Reviewed-by: Peter Shier <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 9a3c05e commit d42e3fa

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

arch/x86/kvm/x86.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ EXPORT_SYMBOL_GPL(pdptrs_changed);
798798
int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
799799
{
800800
unsigned long old_cr0 = kvm_read_cr0(vcpu);
801+
unsigned long pdptr_bits = X86_CR0_CD | X86_CR0_NW | X86_CR0_PG;
801802
unsigned long update_bits = X86_CR0_PG | X86_CR0_WP;
802803

803804
cr0 |= X86_CR0_ET;
@@ -815,9 +816,9 @@ int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
815816
if ((cr0 & X86_CR0_PG) && !(cr0 & X86_CR0_PE))
816817
return 1;
817818

818-
if (!is_paging(vcpu) && (cr0 & X86_CR0_PG)) {
819+
if (cr0 & X86_CR0_PG) {
819820
#ifdef CONFIG_X86_64
820-
if ((vcpu->arch.efer & EFER_LME)) {
821+
if (!is_paging(vcpu) && (vcpu->arch.efer & EFER_LME)) {
821822
int cs_db, cs_l;
822823

823824
if (!is_pae(vcpu))
@@ -827,8 +828,8 @@ int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
827828
return 1;
828829
} else
829830
#endif
830-
if (is_pae(vcpu) && !load_pdptrs(vcpu, vcpu->arch.walk_mmu,
831-
kvm_read_cr3(vcpu)))
831+
if (is_pae(vcpu) && ((cr0 ^ old_cr0) & pdptr_bits) &&
832+
!load_pdptrs(vcpu, vcpu->arch.walk_mmu, kvm_read_cr3(vcpu)))
832833
return 1;
833834
}
834835

0 commit comments

Comments
 (0)