Skip to content

Commit 64f7a11

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: vmx: update sec exec controls for UMIP iff emulating UMIP
Update SECONDARY_EXEC_DESC for UMIP emulation if and only UMIP is actually being emulated. Skipping the VMCS update eliminates unnecessary VMREAD/VMWRITE when UMIP is supported in hardware, and on platforms that don't have SECONDARY_VM_EXEC_CONTROL. The latter case resolves a bug where KVM would fill the kernel log with warnings due to failed VMWRITEs on older platforms. Fixes: 0367f20 ("KVM: vmx: add support for emulating UMIP") Cc: [email protected] #4.16 Reported-by: Paolo Zeppegno <[email protected]> Suggested-by: Paolo Bonzini <[email protected]> Suggested-by: Radim KrÄmář <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent c19986f commit 64f7a11

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

arch/x86/kvm/vmx.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,12 @@ static inline bool cpu_has_vmx_vmfunc(void)
14941494
SECONDARY_EXEC_ENABLE_VMFUNC;
14951495
}
14961496

1497+
static bool vmx_umip_emulated(void)
1498+
{
1499+
return vmcs_config.cpu_based_2nd_exec_ctrl &
1500+
SECONDARY_EXEC_DESC;
1501+
}
1502+
14971503
static inline bool report_flexpriority(void)
14981504
{
14991505
return flexpriority_enabled;
@@ -4761,14 +4767,16 @@ static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
47614767
else
47624768
hw_cr4 |= KVM_PMODE_VM_CR4_ALWAYS_ON;
47634769

4764-
if ((cr4 & X86_CR4_UMIP) && !boot_cpu_has(X86_FEATURE_UMIP)) {
4765-
vmcs_set_bits(SECONDARY_VM_EXEC_CONTROL,
4766-
SECONDARY_EXEC_DESC);
4767-
hw_cr4 &= ~X86_CR4_UMIP;
4768-
} else if (!is_guest_mode(vcpu) ||
4769-
!nested_cpu_has2(get_vmcs12(vcpu), SECONDARY_EXEC_DESC))
4770-
vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL,
4770+
if (!boot_cpu_has(X86_FEATURE_UMIP) && vmx_umip_emulated()) {
4771+
if (cr4 & X86_CR4_UMIP) {
4772+
vmcs_set_bits(SECONDARY_VM_EXEC_CONTROL,
47714773
SECONDARY_EXEC_DESC);
4774+
hw_cr4 &= ~X86_CR4_UMIP;
4775+
} else if (!is_guest_mode(vcpu) ||
4776+
!nested_cpu_has2(get_vmcs12(vcpu), SECONDARY_EXEC_DESC))
4777+
vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL,
4778+
SECONDARY_EXEC_DESC);
4779+
}
47724780

47734781
if (cr4 & X86_CR4_VMXE) {
47744782
/*
@@ -9497,12 +9505,6 @@ static bool vmx_xsaves_supported(void)
94979505
SECONDARY_EXEC_XSAVES;
94989506
}
94999507

9500-
static bool vmx_umip_emulated(void)
9501-
{
9502-
return vmcs_config.cpu_based_2nd_exec_ctrl &
9503-
SECONDARY_EXEC_DESC;
9504-
}
9505-
95069508
static void vmx_recover_nmi_blocking(struct vcpu_vmx *vmx)
95079509
{
95089510
u32 exit_intr_info;

0 commit comments

Comments
 (0)