Skip to content

Commit fd3edd4

Browse files
committed
KVM: nVMX: cleanup and fix host 64-bit mode checks
KVM was incorrectly checking vmcs12->host_ia32_efer even if the "load IA32_EFER" exit control was reset. Also, some checks were not using the new CC macro for tracing. Cleanup everything so that the vCPU's 64-bit mode is determined directly from EFER_LMA and the VMCS checks are based on that, which matches section 26.2.4 of the SDM. Cc: Sean Christopherson <[email protected]> Cc: Krish Sadhukhan <[email protected]> Fixes: 5845038 Reviewed-by: Jim Mattson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent cab0185 commit fd3edd4

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,8 +2664,23 @@ static int nested_vmx_check_host_state(struct kvm_vcpu *vcpu,
26642664
CC(!kvm_pat_valid(vmcs12->host_ia32_pat)))
26652665
return -EINVAL;
26662666

2667-
ia32e = (vmcs12->vm_exit_controls &
2668-
VM_EXIT_HOST_ADDR_SPACE_SIZE) != 0;
2667+
#ifdef CONFIG_X86_64
2668+
ia32e = !!(vcpu->arch.efer & EFER_LMA);
2669+
#else
2670+
ia32e = false;
2671+
#endif
2672+
2673+
if (ia32e) {
2674+
if (CC(!(vmcs12->vm_exit_controls & VM_EXIT_HOST_ADDR_SPACE_SIZE)) ||
2675+
CC(!(vmcs12->host_cr4 & X86_CR4_PAE)))
2676+
return -EINVAL;
2677+
} else {
2678+
if (CC(vmcs12->vm_exit_controls & VM_EXIT_HOST_ADDR_SPACE_SIZE) ||
2679+
CC(vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE) ||
2680+
CC(vmcs12->host_cr4 & X86_CR4_PCIDE) ||
2681+
CC((vmcs12->host_rip) >> 32))
2682+
return -EINVAL;
2683+
}
26692684

26702685
if (CC(vmcs12->host_cs_selector & (SEGMENT_RPL_MASK | SEGMENT_TI_MASK)) ||
26712686
CC(vmcs12->host_ss_selector & (SEGMENT_RPL_MASK | SEGMENT_TI_MASK)) ||
@@ -2684,35 +2699,8 @@ static int nested_vmx_check_host_state(struct kvm_vcpu *vcpu,
26842699
CC(is_noncanonical_address(vmcs12->host_gs_base, vcpu)) ||
26852700
CC(is_noncanonical_address(vmcs12->host_gdtr_base, vcpu)) ||
26862701
CC(is_noncanonical_address(vmcs12->host_idtr_base, vcpu)) ||
2687-
CC(is_noncanonical_address(vmcs12->host_tr_base, vcpu)))
2688-
return -EINVAL;
2689-
2690-
if (!(vmcs12->host_ia32_efer & EFER_LMA) &&
2691-
((vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE) ||
2692-
(vmcs12->vm_exit_controls & VM_EXIT_HOST_ADDR_SPACE_SIZE))) {
2693-
return -EINVAL;
2694-
}
2695-
2696-
if ((vmcs12->host_ia32_efer & EFER_LMA) &&
2697-
!(vmcs12->vm_exit_controls & VM_EXIT_HOST_ADDR_SPACE_SIZE)) {
2698-
return -EINVAL;
2699-
}
2700-
2701-
if (!(vmcs12->vm_exit_controls & VM_EXIT_HOST_ADDR_SPACE_SIZE) &&
2702-
((vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE) ||
2703-
(vmcs12->host_cr4 & X86_CR4_PCIDE) ||
2704-
(((vmcs12->host_rip) >> 32) & 0xffffffff))) {
2705-
return -EINVAL;
2706-
}
2707-
2708-
if ((vmcs12->vm_exit_controls & VM_EXIT_HOST_ADDR_SPACE_SIZE) &&
2709-
((!(vmcs12->host_cr4 & X86_CR4_PAE)) ||
2710-
(is_noncanonical_address(vmcs12->host_rip, vcpu)))) {
2711-
return -EINVAL;
2712-
}
2713-
#else
2714-
if (vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE ||
2715-
vmcs12->vm_exit_controls & VM_EXIT_HOST_ADDR_SPACE_SIZE)
2702+
CC(is_noncanonical_address(vmcs12->host_tr_base, vcpu)) ||
2703+
CC(is_noncanonical_address(vmcs12->host_rip, vcpu)))
27162704
return -EINVAL;
27172705
#endif
27182706

0 commit comments

Comments
 (0)