Skip to content

Commit ca83b4a

Browse files
konradwilkKAGA-KOKO
authored andcommitted
x86/KVM/VMX: Add find_msr() helper function
.. to help find the MSR on either the guest or host MSR list. Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 33966dd commit ca83b4a

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

arch/x86/kvm/vmx.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,9 +2421,20 @@ static void clear_atomic_switch_msr_special(struct vcpu_vmx *vmx,
24212421
vm_exit_controls_clearbit(vmx, exit);
24222422
}
24232423

2424+
static int find_msr(struct vmx_msrs *m, unsigned int msr)
2425+
{
2426+
unsigned int i;
2427+
2428+
for (i = 0; i < m->nr; ++i) {
2429+
if (m->val[i].index == msr)
2430+
return i;
2431+
}
2432+
return -ENOENT;
2433+
}
2434+
24242435
static void clear_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr)
24252436
{
2426-
unsigned i;
2437+
int i;
24272438
struct msr_autoload *m = &vmx->msr_autoload;
24282439

24292440
switch (msr) {
@@ -2444,11 +2455,8 @@ static void clear_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr)
24442455
}
24452456
break;
24462457
}
2447-
for (i = 0; i < m->guest.nr; ++i)
2448-
if (m->guest.val[i].index == msr)
2449-
break;
2450-
2451-
if (i == m->guest.nr)
2458+
i = find_msr(&m->guest, msr);
2459+
if (i < 0)
24522460
return;
24532461
--m->guest.nr;
24542462
--m->host.nr;
@@ -2472,7 +2480,7 @@ static void add_atomic_switch_msr_special(struct vcpu_vmx *vmx,
24722480
static void add_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr,
24732481
u64 guest_val, u64 host_val)
24742482
{
2475-
unsigned i;
2483+
int i;
24762484
struct msr_autoload *m = &vmx->msr_autoload;
24772485

24782486
switch (msr) {
@@ -2507,16 +2515,13 @@ static void add_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr,
25072515
wrmsrl(MSR_IA32_PEBS_ENABLE, 0);
25082516
}
25092517

2510-
for (i = 0; i < m->guest.nr; ++i)
2511-
if (m->guest.val[i].index == msr)
2512-
break;
2513-
2518+
i = find_msr(&m->guest, msr);
25142519
if (i == NR_AUTOLOAD_MSRS) {
25152520
printk_once(KERN_WARNING "Not enough msr switch entries. "
25162521
"Can't add msr %x\n", msr);
25172522
return;
2518-
} else if (i == m->guest.nr) {
2519-
++m->guest.nr;
2523+
} else if (i < 0) {
2524+
i = m->guest.nr++;
25202525
++m->host.nr;
25212526
vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, m->guest.nr);
25222527
vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, m->host.nr);

0 commit comments

Comments
 (0)