From: Thomas Gleixner <tglx@linutronix.de>
To: speck@linutronix.de
Subject: [patch V5 07/10] KVM magic # 7
Date: Mon, 02 Jul 2018 17:44:33 +0200 [thread overview]
Message-ID: <20180702160529.070705478@linutronix.de> (raw)
In-Reply-To: 20180702154426.910579106@linutronix.de
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [patch V5 07/10] 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>
---
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
@@ -2421,9 +2421,20 @@ static void clear_atomic_switch_msr_spec
vm_exit_controls_clearbit(vmx, exit);
}
+static int find_msr(struct vmx_msrs *m, unsigned 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) {
@@ -2444,11 +2455,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;
@@ -2472,7 +2480,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) {
@@ -2507,16 +2515,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);
next prev parent reply other threads:[~2018-07-02 16:13 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-02 15:44 [patch V5 00/10] KVM magic # 0 Thomas Gleixner
2018-07-02 15:44 ` [patch V5 01/10] KVM magic # 1 Thomas Gleixner
2018-07-02 16:22 ` [MODERATED] " Konrad Rzeszutek Wilk
2018-07-02 17:10 ` Thomas Gleixner
2018-07-02 16:25 ` [MODERATED] " Borislav Petkov
2018-07-02 15:44 ` [patch V5 02/10] KVM magic # 2 Thomas Gleixner
2018-07-02 15:44 ` [patch V5 03/10] KVM magic # 3 Thomas Gleixner
2018-07-02 23:42 ` [MODERATED] " Jon Masters
2018-07-02 15:44 ` [patch V5 04/10] KVM magic # 4 Thomas Gleixner
2018-07-02 15:44 ` [patch V5 05/10] KVM magic # 5 Thomas Gleixner
2018-07-02 16:35 ` [MODERATED] " Konrad Rzeszutek Wilk
2018-07-02 17:01 ` Thomas Gleixner
2018-07-02 17:24 ` [MODERATED] " Paolo Bonzini
2018-07-03 15:21 ` Thomas Gleixner
2018-07-02 21:19 ` [MODERATED] Re: ***UNCHECKED*** " Alexander Graf
2018-07-02 23:45 ` Andrew Cooper
2018-07-03 1:33 ` Linus Torvalds
2018-07-03 8:23 ` Paolo Bonzini
2018-07-03 14:29 ` [MODERATED] Re: ***UNCHECKED*** " Alexander Graf
2018-07-05 19:08 ` Jon Masters
2018-07-05 21:43 ` Paolo Bonzini
2018-07-05 21:50 ` Linus Torvalds
2018-07-02 15:44 ` [patch V5 06/10] KVM magic # 6 Thomas Gleixner
2018-07-02 15:44 ` Thomas Gleixner [this message]
2018-07-02 15:44 ` [patch V5 08/10] KVM magic # 8 Thomas Gleixner
2018-07-02 15:44 ` [patch V5 09/10] KVM magic # 9 Thomas Gleixner
2018-07-02 15:44 ` [patch V5 10/10] KVM magic # 10 Thomas Gleixner
2018-07-02 17:29 ` [MODERATED] " Paolo Bonzini
2018-07-02 17:41 ` Thomas Gleixner
2018-07-02 22:11 ` Thomas Gleixner
2018-07-03 9:05 ` [MODERATED] " Paolo Bonzini
2018-07-02 16:25 ` [patch V5 00/10] KVM magic # 0 Thomas Gleixner
2018-07-02 22:14 ` [MODERATED] [patch v5 11/10] Linux+KVM magic # 1 Jiri Kosina
2018-07-05 23:56 ` [MODERATED] " Josh Poimboeuf
2018-07-06 11:54 ` Jiri Kosina
2018-07-06 13:05 ` Konrad Rzeszutek Wilk
2018-07-06 15:11 ` Jon Masters
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180702160529.070705478@linutronix.de \
--to=tglx@linutronix.de \
--cc=speck@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.