Skip to content

Commit 41ab0d5

Browse files
Maxim Levitskysean-jc
authored andcommitted
KVM: nVMX: Use vmx_segment_cache_clear() instead of open coded equivalent
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>
1 parent 653ea44 commit 41ab0d5

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,7 @@ static void prepare_vmcs02_rare(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12)
24702470

24712471
if (!hv_evmcs || !(hv_evmcs->hv_clean_fields &
24722472
HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2)) {
2473+
24732474
vmcs_write16(GUEST_ES_SELECTOR, vmcs12->guest_es_selector);
24742475
vmcs_write16(GUEST_CS_SELECTOR, vmcs12->guest_cs_selector);
24752476
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)
25072508
vmcs_writel(GUEST_GDTR_BASE, vmcs12->guest_gdtr_base);
25082509
vmcs_writel(GUEST_IDTR_BASE, vmcs12->guest_idtr_base);
25092510

2510-
vmx->segment_cache.bitmask = 0;
2511+
vmx_segment_cache_clear(vmx);
25112512
}
25122513

25132514
if (!hv_evmcs || !(hv_evmcs->hv_clean_fields &

arch/x86/kvm/vmx/vmx.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,6 @@ static const struct kvm_vmx_segment_field {
525525
VMX_SEGMENT_FIELD(LDTR),
526526
};
527527

528-
static inline void vmx_segment_cache_clear(struct vcpu_vmx *vmx)
529-
{
530-
vmx->segment_cache.bitmask = 0;
531-
}
532528

533529
static unsigned long host_idt_base;
534530

arch/x86/kvm/vmx/vmx.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,4 +756,9 @@ static inline bool vmx_can_use_ipiv(struct kvm_vcpu *vcpu)
756756
return lapic_in_kernel(vcpu) && enable_ipiv;
757757
}
758758

759+
static inline void vmx_segment_cache_clear(struct vcpu_vmx *vmx)
760+
{
761+
vmx->segment_cache.bitmask = 0;
762+
}
763+
759764
#endif /* __KVM_X86_VMX_H */

0 commit comments

Comments
 (0)