Skip to content

Commit 0bd2937

Browse files
committed
KVM: VMX: Dedup code for removing MSR from VMCS's auto-load list
Add a helper to remove an MSR from an auto-{load,store} list to dedup the msr_autoload code, and in anticipation of adding similar functionality for msr_autostore. No functional change intended. Tested-by: Manali Shukla <manali.shukla@amd.com> Link: https://patch.msgid.link/20251206001720.468579-38-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 58f21a0 commit 0bd2937

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

arch/x86/kvm/vmx/vmx.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,22 @@ static int vmx_find_loadstore_msr_slot(struct vmx_msrs *m, u32 msr)
10401040
return -ENOENT;
10411041
}
10421042

1043-
static void clear_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr)
1043+
static void vmx_remove_auto_msr(struct vmx_msrs *m, u32 msr,
1044+
unsigned long vmcs_count_field)
10441045
{
10451046
int i;
1047+
1048+
i = vmx_find_loadstore_msr_slot(m, msr);
1049+
if (i < 0)
1050+
return;
1051+
1052+
--m->nr;
1053+
m->val[i] = m->val[m->nr];
1054+
vmcs_write32(vmcs_count_field, m->nr);
1055+
}
1056+
1057+
static void clear_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr)
1058+
{
10461059
struct msr_autoload *m = &vmx->msr_autoload;
10471060

10481061
switch (msr) {
@@ -1063,21 +1076,9 @@ static void clear_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr)
10631076
}
10641077
break;
10651078
}
1066-
i = vmx_find_loadstore_msr_slot(&m->guest, msr);
1067-
if (i < 0)
1068-
goto skip_guest;
1069-
--m->guest.nr;
1070-
m->guest.val[i] = m->guest.val[m->guest.nr];
1071-
vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, m->guest.nr);
1072-
1073-
skip_guest:
1074-
i = vmx_find_loadstore_msr_slot(&m->host, msr);
1075-
if (i < 0)
1076-
return;
10771079

1078-
--m->host.nr;
1079-
m->host.val[i] = m->host.val[m->host.nr];
1080-
vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, m->host.nr);
1080+
vmx_remove_auto_msr(&m->guest, msr, VM_ENTRY_MSR_LOAD_COUNT);
1081+
vmx_remove_auto_msr(&m->host, msr, VM_EXIT_MSR_LOAD_COUNT);
10811082
}
10821083

10831084
static __always_inline void add_atomic_switch_msr_special(struct vcpu_vmx *vmx,

0 commit comments

Comments
 (0)