lkml.org 
[lkml]   [2018]   [Aug]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 4.18 41/79] x86/KVM/VMX: Add find_msr() helper function
Date
4.18-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

.. 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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
arch/x86/kvm/vmx.c | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)

--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2432,9 +2432,20 @@ static void clear_atomic_switch_msr_spec
vm_exit_controls_clearbit(vmx, exit);
}

+static int find_msr(struct vmx_msrs *m, unsigned int msr)
+{
+ unsigned int i;
+
+ for (i = 0; i < m->nr; ++i) {
+ if (m->val[i].index == msr)
+ return i;
+ }
+ return -ENOENT;
+}
+
static void clear_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr)
{
- unsigned i;
+ int i;
struct msr_autoload *m = &vmx->msr_autoload;

switch (msr) {
@@ -2455,11 +2466,8 @@ static void clear_atomic_switch_msr(stru
}
break;
}
- for (i = 0; i < m->guest.nr; ++i)
- if (m->guest.val[i].index == msr)
- break;
-
- if (i == m->guest.nr)
+ i = find_msr(&m->guest, msr);
+ if (i < 0)
return;
--m->guest.nr;
--m->host.nr;
@@ -2483,7 +2491,7 @@ static void add_atomic_switch_msr_specia
static void add_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr,
u64 guest_val, u64 host_val)
{
- unsigned i;
+ int i;
struct msr_autoload *m = &vmx->msr_autoload;

switch (msr) {
@@ -2518,16 +2526,13 @@ static void add_atomic_switch_msr(struct
wrmsrl(MSR_IA32_PEBS_ENABLE, 0);
}

- for (i = 0; i < m->guest.nr; ++i)
- if (m->guest.val[i].index == msr)
- break;
-
+ i = find_msr(&m->guest, msr);
if (i == NR_AUTOLOAD_MSRS) {
printk_once(KERN_WARNING "Not enough msr switch entries. "
"Can't add msr %x\n", msr);
return;
- } else if (i == m->guest.nr) {
- ++m->guest.nr;
+ } else if (i < 0) {
+ i = m->guest.nr++;
++m->host.nr;
vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, m->guest.nr);
vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, m->host.nr);

\
 
 \ /
  Last update: 2018-08-14 20:12    [W:0.302 / U:0.384 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site