* [MODERATED] [PATCH v4 5/8] [PATCH v4 5/8] Linux Patch #5
@ 2018-06-23 13:54 konrad.wilk
2018-06-27 16:42 ` [MODERATED] " Borislav Petkov
0 siblings, 1 reply; 2+ messages in thread
From: konrad.wilk @ 2018-06-23 13:54 UTC (permalink / raw)
To: speck
.. to help find the MSR on either the guest or host
MSR list.
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
arch/x86/kvm/vmx.c | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 3649bf3b3b82..f9d70b3e9fcd 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2376,9 +2376,20 @@ static void clear_atomic_switch_msr_special(struct vcpu_vmx *vmx,
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) {
@@ -2399,11 +2410,8 @@ static void clear_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr)
}
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;
@@ -2427,7 +2435,7 @@ static void add_atomic_switch_msr_special(struct vcpu_vmx *vmx,
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) {
@@ -2462,16 +2470,13 @@ static void add_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr,
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);
--
2.14.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [MODERATED] Re: [PATCH v4 5/8] [PATCH v4 5/8] Linux Patch #5
2018-06-23 13:54 [MODERATED] [PATCH v4 5/8] [PATCH v4 5/8] Linux Patch #5 konrad.wilk
@ 2018-06-27 16:42 ` Borislav Petkov
0 siblings, 0 replies; 2+ messages in thread
From: Borislav Petkov @ 2018-06-27 16:42 UTC (permalink / raw)
To: speck
On Sat, Jun 23, 2018 at 09:54:19AM -0400, speck for konrad.wilk_at_oracle.com wrote:
> 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>
> ---
> arch/x86/kvm/vmx.c | 31 ++++++++++++++++++-------------
> 1 file changed, 18 insertions(+), 13 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 3649bf3b3b82..f9d70b3e9fcd 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -2376,9 +2376,20 @@ static void clear_atomic_switch_msr_special(struct vcpu_vmx *vmx,
> vm_exit_controls_clearbit(vmx, exit);
> }
>
> +static int find_msr(struct vmx_msrs *m, unsigned msr)
WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
#31: FILE: arch/x86/kvm/vmx.c:2379:
+static int find_msr(struct vmx_msrs *m, unsigned msr)
Please integrate scripts/checkpatch.pl into your patch creation
workflow. Some of the warnings/errors *actually* make sense.
> +{
> + 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) {
> @@ -2399,11 +2410,8 @@ static void clear_atomic_switch_msr(struct vcpu_vmx *vmx, unsigned msr)
> }
> 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;
<---- newline here.
> --m->guest.nr;
> --m->host.nr;
--
Regards/Gruss,
Boris.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
--
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-06-27 16:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-23 13:54 [MODERATED] [PATCH v4 5/8] [PATCH v4 5/8] Linux Patch #5 konrad.wilk
2018-06-27 16:42 ` [MODERATED] " Borislav Petkov
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.