Commit 0c4ff086 authored by Sean Christopherson's avatar Sean Christopherson
Browse files

KVM: VMX: Set MSR index auto-load entry if and only if entry is "new"



When adding an MSR to the auto-load lists, update the MSR index in the
list entry if and only if a new entry is being inserted, as 'i' can only
be non-negative if vmx_find_loadstore_msr_slot() found an entry with the
MSR's index.  Unnecessarily setting the index is benign, but it makes it
harder to see that updating the value is necessary even when an existing
entry for the MSR was found.

No functional change intended.

Reviewed-by: default avatarDapeng Mi <dapeng1.mi@linux.intel.com>
Tested-by: default avatarManali Shukla <manali.shukla@amd.com>
Link: https://patch.msgid.link/20251206001720.468579-41-seanjc@google.com


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 2ed57bb8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1141,16 +1141,16 @@ static void add_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr,

	if (i < 0) {
		i = m->guest.nr++;
		m->guest.val[i].index = msr;
		vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, m->guest.nr);
	}
	m->guest.val[i].index = msr;
	m->guest.val[i].value = guest_val;

	if (j < 0) {
		j = m->host.nr++;
		m->host.val[j].index = msr;
		vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, m->host.nr);
	}
	m->host.val[j].index = msr;
	m->host.val[j].value = host_val;
}