]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: nVMX: Use vmx_segment_cache_clear() instead of open coded equivalent
authorMaxim Levitsky <mlevitsk@redhat.com>
Thu, 25 Jul 2024 17:52:31 +0000 (13:52 -0400)
committerSean Christopherson <seanjc@google.com>
Thu, 22 Aug 2024 18:35:17 +0000 (11:35 -0700)
In prepare_vmcs02_rare(), call vmx_segment_cache_clear() instead of
setting segment_cache.bitmask directly.  Using the helper minimizes the
chances of prepare_vmcs02_rare() doing the wrong thing in the future, e.g.
if KVM ends up doing more than just zero the bitmask when purging the
cache.

No functional change intended.

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Link: https://lore.kernel.org/r/20240725175232.337266-2-mlevitsk@redhat.com
[sean: massage changelog]
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/vmx/nested.c
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/vmx/vmx.h

index 674f7089cc449ae4a84d2e8b700e038575927788..867de342df33dbaa3df2c9333c3f8a9738a86258 100644 (file)
@@ -2470,6 +2470,7 @@ static void prepare_vmcs02_rare(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12)
 
        if (!hv_evmcs || !(hv_evmcs->hv_clean_fields &
                           HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2)) {
+
                vmcs_write16(GUEST_ES_SELECTOR, vmcs12->guest_es_selector);
                vmcs_write16(GUEST_CS_SELECTOR, vmcs12->guest_cs_selector);
                vmcs_write16(GUEST_SS_SELECTOR, vmcs12->guest_ss_selector);
@@ -2507,7 +2508,7 @@ static void prepare_vmcs02_rare(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12)
                vmcs_writel(GUEST_GDTR_BASE, vmcs12->guest_gdtr_base);
                vmcs_writel(GUEST_IDTR_BASE, vmcs12->guest_idtr_base);
 
-               vmx->segment_cache.bitmask = 0;
+               vmx_segment_cache_clear(vmx);
        }
 
        if (!hv_evmcs || !(hv_evmcs->hv_clean_fields &
index f18c2d8c7476e180005cef514953ab0e2ecb80bb..594db9afbc0fb40ad0ff21ca42bffed11d943f15 100644 (file)
@@ -525,10 +525,6 @@ static const struct kvm_vmx_segment_field {
        VMX_SEGMENT_FIELD(LDTR),
 };
 
-static inline void vmx_segment_cache_clear(struct vcpu_vmx *vmx)
-{
-       vmx->segment_cache.bitmask = 0;
-}
 
 static unsigned long host_idt_base;
 
index 42498fa63abbe567009f7be70b3254ad2c754dc4..11b1b70faef29f7081d0e576870d3ce5951e6667 100644 (file)
@@ -756,4 +756,9 @@ static inline bool vmx_can_use_ipiv(struct kvm_vcpu *vcpu)
        return  lapic_in_kernel(vcpu) && enable_ipiv;
 }
 
+static inline void vmx_segment_cache_clear(struct vcpu_vmx *vmx)
+{
+       vmx->segment_cache.bitmask = 0;
+}
+
 #endif /* __KVM_X86_VMX_H */