mirror of
https://github.com/torvalds/linux.git
synced 2026-05-31 10:33:41 +02:00
KVM: VMX: Dedup code for adding MSR to VMCS's auto list
Add a helper to add an MSR to a VMCS's "auto" list to deduplicate the code in add_atomic_switch_msr(), and so that the functionality can be used in the future for managing the MSR auto-store list. No functional change intended. Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com> Tested-by: Manali Shukla <manali.shukla@amd.com> Link: https://patch.msgid.link/20251206001720.468579-43-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
2239d137a7
commit
c3d6a7210a
|
|
@ -1093,12 +1093,28 @@ static __always_inline void add_atomic_switch_msr_special(struct vcpu_vmx *vmx,
|
||||||
vm_exit_controls_setbit(vmx, exit);
|
vm_exit_controls_setbit(vmx, exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void vmx_add_auto_msr(struct vmx_msrs *m, u32 msr, u64 value,
|
||||||
|
unsigned long vmcs_count_field, struct kvm *kvm)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = vmx_find_loadstore_msr_slot(m, msr);
|
||||||
|
if (i < 0) {
|
||||||
|
if (KVM_BUG_ON(m->nr == MAX_NR_LOADSTORE_MSRS, kvm))
|
||||||
|
return;
|
||||||
|
|
||||||
|
i = m->nr++;
|
||||||
|
m->val[i].index = msr;
|
||||||
|
vmcs_write32(vmcs_count_field, m->nr);
|
||||||
|
}
|
||||||
|
m->val[i].value = value;
|
||||||
|
}
|
||||||
|
|
||||||
static void add_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr,
|
static void add_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr,
|
||||||
u64 guest_val, u64 host_val)
|
u64 guest_val, u64 host_val)
|
||||||
{
|
{
|
||||||
struct msr_autoload *m = &vmx->msr_autoload;
|
struct msr_autoload *m = &vmx->msr_autoload;
|
||||||
struct kvm *kvm = vmx->vcpu.kvm;
|
struct kvm *kvm = vmx->vcpu.kvm;
|
||||||
int i;
|
|
||||||
|
|
||||||
switch (msr) {
|
switch (msr) {
|
||||||
case MSR_EFER:
|
case MSR_EFER:
|
||||||
|
|
@ -1132,27 +1148,8 @@ static void add_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr,
|
||||||
wrmsrq(MSR_IA32_PEBS_ENABLE, 0);
|
wrmsrq(MSR_IA32_PEBS_ENABLE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
i = vmx_find_loadstore_msr_slot(&m->guest, msr);
|
vmx_add_auto_msr(&m->guest, msr, guest_val, VM_ENTRY_MSR_LOAD_COUNT, kvm);
|
||||||
if (i < 0) {
|
vmx_add_auto_msr(&m->guest, msr, host_val, VM_EXIT_MSR_LOAD_COUNT, kvm);
|
||||||
if (KVM_BUG_ON(m->guest.nr == MAX_NR_LOADSTORE_MSRS, kvm))
|
|
||||||
return;
|
|
||||||
|
|
||||||
i = m->guest.nr++;
|
|
||||||
m->guest.val[i].index = msr;
|
|
||||||
vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, m->guest.nr);
|
|
||||||
}
|
|
||||||
m->guest.val[i].value = guest_val;
|
|
||||||
|
|
||||||
i = vmx_find_loadstore_msr_slot(&m->host, msr);
|
|
||||||
if (i < 0) {
|
|
||||||
if (KVM_BUG_ON(m->host.nr == MAX_NR_LOADSTORE_MSRS, kvm))
|
|
||||||
return;
|
|
||||||
|
|
||||||
i = m->host.nr++;
|
|
||||||
m->host.val[i].index = msr;
|
|
||||||
vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, m->host.nr);
|
|
||||||
}
|
|
||||||
m->host.val[i].value = host_val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool update_transition_efer(struct vcpu_vmx *vmx)
|
static bool update_transition_efer(struct vcpu_vmx *vmx)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user