Just rename, no functional changes intended. vmx_umip_emulated() comes from the ancient time when there was a kvm_x86_ops::umip_emulated(), which originally simply returned false. (66336cab3531d "KVM: x86: add support for emulating UMIP"). Afterwards, its body changed and moved from vmx.c to the dedicated capabilities.h, but kept its old name which looks weired among cpu_has_vmx_XXX() group. Rename it to align with other analogous functions, the new name is more accurate for what it does. And, vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_DESC just means it has the capability of emulating UMIP, not *umip-being-emulated*, e.g. if host has caps of UMIP, it's actually not emulated. On the other hand, UMIP concerned instructions are just subset of those SECONDARY_EXEC_DESC intercepts [1][2]. [1] SDM. Vol.3 Table 25-7. Definitions of Secondary Processor-Based VM-Execution Controls SECONDARY_EXEC_DESC "determines whether executions of LGDT, LIDT, LLDT, LTR, SGDT, SIDT, SLDT, and STR cause VM exits." [2] SDM. Vol.3 2.5 Control Registers CR4.UMIP is about SGDT, SIDT, SLDT, SMSW, and STR. Signed-off-by: Robert Hoo <robert.hu@xxxxxxxxx> --- arch/x86/kvm/vmx/capabilities.h | 2 +- arch/x86/kvm/vmx/nested.c | 4 ++-- arch/x86/kvm/vmx/vmx.c | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index 45162c1bcd8f..afa116063acd 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -150,7 +150,7 @@ static inline bool cpu_has_vmx_ept(void) SECONDARY_EXEC_ENABLE_EPT; } -static inline bool vmx_umip_emulated(void) +static inline bool cpu_has_vmx_desc(void) { return vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_DESC; diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 7c4f5ca405c7..6804b4fcf2b9 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -2322,7 +2322,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct loaded_vmcs *vmcs0 * Preset *DT exiting when emulating UMIP, so that vmx_set_cr4() * will not have to rewrite the controls just for this bit. */ - if (!boot_cpu_has(X86_FEATURE_UMIP) && vmx_umip_emulated() && + if (!boot_cpu_has(X86_FEATURE_UMIP) && cpu_has_vmx_desc() && (vmcs12->guest_cr4 & X86_CR4_UMIP)) exec_control |= SECONDARY_EXEC_DESC; @@ -6984,7 +6984,7 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_caps) rdmsrl(MSR_IA32_VMX_CR0_FIXED1, msrs->cr0_fixed1); rdmsrl(MSR_IA32_VMX_CR4_FIXED1, msrs->cr4_fixed1); - if (vmx_umip_emulated()) + if (cpu_has_vmx_desc()) msrs->cr4_fixed1 |= X86_CR4_UMIP; msrs->vmcs_enum = nested_vmx_calc_vmcs_enum_msr(); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index bcac3efcde41..96f7c9f37afd 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -3431,7 +3431,13 @@ void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) else hw_cr4 |= KVM_PMODE_VM_CR4_ALWAYS_ON; - if (!boot_cpu_has(X86_FEATURE_UMIP) && vmx_umip_emulated()) { + /* + * Emulate UMIP via enable secondary_exec_control.DESC + * It can get here means it has passed valid_cr4() check, i.e. + * guest been exposed with UMIP feature, i.e. either host has cap + * of UMIP or vmx_set_cpu_caps() set it because of cpu_has_vmx_desc() + */ + if (!boot_cpu_has(X86_FEATURE_UMIP) && cpu_has_vmx_desc()) { if (cr4 & X86_CR4_UMIP) { secondary_exec_controls_setbit(vmx, SECONDARY_EXEC_DESC); hw_cr4 &= ~X86_CR4_UMIP; @@ -7820,7 +7826,7 @@ static __init void vmx_set_cpu_caps(void) kvm_cpu_cap_clear(X86_FEATURE_SGX2); } - if (vmx_umip_emulated()) + if (cpu_has_vmx_desc()) kvm_cpu_cap_set(X86_FEATURE_UMIP); /* CPUID 0xD.1 */ -- 2.31.1