Re: [PATCH 01/11] kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file

2015-06-25 Thread Denis V. Lunev

On 22/06/15 19:04, Denis V. Lunev wrote:

From: Andrey Smetanin asmeta...@virtuozzo.com

This patch introduces Hyper-V related source code file - hyperv.c and
per vm and per vcpu hyperv context structures.
All Hyper-V MSR's and hypercall code moved into hyperv.c.
All hyper-v kvm/vcpu fields moved into appropriate hyperv context
structures.
Copyrights and authors information copied from x86.c to hyperv.c.

Signed-off-by: Andrey Smetanin asmeta...@virtuozzo.com
Signed-off-by: Denis V. Lunev d...@openvz.org
CC: Paolo Bonzini pbonz...@redhat.com
CC: Gleb Natapov g...@kernel.org


Paolo, Gleb,

we are very sensitive on the first patch. Could you
suggest which tree we should be based on?
For now I think that we should use

https://git.kernel.org/cgit/virt/kvm/kvm.git/

but the branch here could also matters.

Den
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/11] kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file

2015-06-25 Thread Paolo Bonzini


On 25/06/2015 12:25, Denis V. Lunev wrote:
 
 Paolo, Gleb,
 
 we are very sensitive on the first patch. Could you
 suggest which tree we should be based on?
 For now I think that we should use
 
 https://git.kernel.org/cgit/virt/kvm/kvm.git/
 
 but the branch here could also matters.

You can use Linus's tree right now, but in general you should use branch
next in that tree.

Paolo
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/11] kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file

2015-06-22 Thread Denis V. Lunev
From: Andrey Smetanin asmeta...@virtuozzo.com

This patch introduces Hyper-V related source code file - hyperv.c and
per vm and per vcpu hyperv context structures.
All Hyper-V MSR's and hypercall code moved into hyperv.c.
All hyper-v kvm/vcpu fields moved into appropriate hyperv context
structures.
Copyrights and authors information copied from x86.c to hyperv.c.

Signed-off-by: Andrey Smetanin asmeta...@virtuozzo.com
Signed-off-by: Denis V. Lunev d...@openvz.org
CC: Paolo Bonzini pbonz...@redhat.com
CC: Gleb Natapov g...@kernel.org
---
 arch/x86/include/asm/kvm_host.h |  20 ++-
 arch/x86/kvm/Makefile   |   2 +-
 arch/x86/kvm/hyperv.c   | 303 
 arch/x86/kvm/hyperv.h   |  31 
 arch/x86/kvm/lapic.h|   2 +-
 arch/x86/kvm/x86.c  | 263 +-
 arch/x86/kvm/x86.h  |   5 +
 7 files changed, 358 insertions(+), 268 deletions(-)
 create mode 100644 arch/x86/kvm/hyperv.c
 create mode 100644 arch/x86/kvm/hyperv.h

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index f4a555b..717a03c 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -344,6 +344,11 @@ enum {
KVM_DEBUGREG_RELOAD = 4,
 };
 
+/* Hyper-V per vcpu emulation context */
+struct kvm_vcpu_arch_hyperv {
+   u64 hv_vapic;
+};
+
 struct kvm_vcpu_arch {
/*
 * rip and regs accesses must go through
@@ -498,8 +503,7 @@ struct kvm_vcpu_arch {
/* used for guest single stepping over the given code position */
unsigned long singlestep_rip;
 
-   /* fields used by HYPER-V emulation */
-   u64 hv_vapic;
+   struct kvm_vcpu_arch_hyperv hyperv;
 
cpumask_var_t wbinvd_dirty_mask;
 
@@ -570,6 +574,13 @@ struct kvm_apic_map {
struct kvm_lapic *logical_map[16][16];
 };
 
+/* Hyper-V emulation context */
+struct kvm_arch_hyperv {
+   u64 hv_guest_os_id;
+   u64 hv_hypercall;
+   u64 hv_tsc_page;
+};
+
 struct kvm_arch {
unsigned int n_used_mmu_pages;
unsigned int n_requested_mmu_pages;
@@ -627,10 +638,7 @@ struct kvm_arch {
/* reads protected by irq_srcu, writes by irq_lock */
struct hlist_head mask_notifier_list;
 
-   /* fields used by HYPER-V emulation */
-   u64 hv_guest_os_id;
-   u64 hv_hypercall;
-   u64 hv_tsc_page;
+   struct kvm_arch_hyperv hyperv;
 
#ifdef CONFIG_KVM_MMU_AUDIT
int audit_point;
diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
index 16e8f96..944c8c8 100644
--- a/arch/x86/kvm/Makefile
+++ b/arch/x86/kvm/Makefile
@@ -12,7 +12,7 @@ kvm-y += $(KVM)/kvm_main.o 
$(KVM)/coalesced_mmio.o \
 kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o
 
 kvm-y  += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \
-  i8254.o ioapic.o irq_comm.o cpuid.o pmu.o
+  i8254.o ioapic.o irq_comm.o cpuid.o pmu.o hyperv.o
 kvm-$(CONFIG_KVM_DEVICE_ASSIGNMENT)+= assigned-dev.o iommu.o
 kvm-intel-y+= vmx.o
 kvm-amd-y  += svm.o
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
new file mode 100644
index 000..0d24d9a
--- /dev/null
+++ b/arch/x86/kvm/hyperv.c
@@ -0,0 +1,303 @@
+/*
+ * KVM Microsoft Hyper-V emulation
+ *
+ * Copyright (C) 2006 Qumranet, Inc.
+ * Copyright (C) 2008 Qumranet, Inc.
+ * Copyright IBM Corporation, 2008
+ * Copyright 2010 Red Hat, Inc. and/or its affiliates.
+ * Copyright (C) 2015 Andrey Smetanin asmeta...@virtuozzo.com
+ *
+ * Authors:
+ *   Avi Kivity   a...@qumranet.com
+ *   Yaniv Kamay  ya...@qumranet.com
+ *   Amit Shahamit.s...@qumranet.com
+ *   Ben-Ami Yassour ben...@il.ibm.com
+ *   Andrey Smetanin asmeta...@virtuozzo.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include x86.h
+#include lapic.h
+#include hyperv.h
+
+#include linux/kvm_host.h
+#include trace/events/kvm.h
+
+#include trace.h
+
+static bool kvm_hv_msr_partition_wide(u32 msr)
+{
+   bool r = false;
+
+   switch (msr) {
+   case HV_X64_MSR_GUEST_OS_ID:
+   case HV_X64_MSR_HYPERCALL:
+   case HV_X64_MSR_REFERENCE_TSC:
+   case HV_X64_MSR_TIME_REF_COUNT:
+   r = true;
+   break;
+   }
+
+   return r;
+}
+
+static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+{
+   struct kvm *kvm = vcpu-kvm;
+   struct kvm_arch_hyperv *hv = kvm-arch.hyperv;
+
+   switch (msr) {
+   case HV_X64_MSR_GUEST_OS_ID:
+   hv-hv_guest_os_id = data;
+   /* setting guest os id to zero disables hypercall page */
+   if (!hv-hv_guest_os_id)
+   hv-hv_hypercall = ~HV_X64_MSR_HYPERCALL_ENABLE;
+   break;
+   case HV_X64_MSR_HYPERCALL: {
+   u64 gfn;
+   unsigned long addr;