Re: KVM: MMU: bail out pagewalk on kvm_read_guest error

2010-01-17 Thread Avi Kivity

On 01/14/2010 09:41 PM, Marcelo Tosatti wrote:

Exit the guest pagetable walk loop if reading gpte failed. Otherwise its
possible to enter an endless loop processing the previous present pte.

Cc: sta...@kernel.org
Signed-off-by: Marcelo Tosattimtosa...@redhat.com

diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index 58a0f1e..ede2131 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -150,7 +150,9 @@ walk:
walker-table_gfn[walker-level - 1] = table_gfn;
walker-pte_gpa[walker-level - 1] = pte_gpa;

-   kvm_read_guest(vcpu-kvm, pte_gpa,pte, sizeof(pte));
+   if (kvm_read_guest(vcpu-kvm, pte_gpa,pte, sizeof(pte)))
+   goto not_present;
+
   


On real hardware, if you place a pte at non-existing memory, you aren't 
guaranteed to get the present bit clear, so why is this necessary?


We should be able to survive any garbage the pte previously contained.

--
error compiling committee.c: too many arguments to function

--
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


[PATCHv2 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Gleb Natapov

Signed-off-by: Gleb Natapov g...@redhat.com
Signed-off-by: Vadim Rozenfeld vroze...@redhat.com
---
 arch/x86/include/asm/kvm_host.h |2 +
 arch/x86/kvm/lapic.c|   31 +
 arch/x86/kvm/lapic.h|8 +++
 arch/x86/kvm/x86.c  |   41 --
 include/linux/kvm.h |1 +
 5 files changed, 80 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 67d19e4..a1f0b5d 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -363,6 +363,8 @@ struct kvm_vcpu_arch {
/* used for guest single stepping over the given code position */
u16 singlestep_cs;
unsigned long singlestep_rip;
+   /* fields used by HYPER-V emulation */
+   u64 hv_vapic;
 };
 
 struct kvm_mem_alias {
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index ba8c045..4b224f9 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1246,3 +1246,34 @@ int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, 
u64 *data)
 
return 0;
 }
+
+int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 reg, u64 data)
+{
+   struct kvm_lapic *apic = vcpu-arch.apic;
+
+   if (!irqchip_in_kernel(vcpu-kvm))
+   return 1;
+
+   /* if this is ICR write vector before command */
+   if (reg == APIC_ICR)
+   apic_reg_write(apic, APIC_ICR2, (u32)(data  32));
+   return apic_reg_write(apic, reg, (u32)data);
+}
+
+int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 reg, u64 *data)
+{
+   struct kvm_lapic *apic = vcpu-arch.apic;
+   u32 low, high = 0;
+
+   if (!irqchip_in_kernel(vcpu-kvm))
+   return 1;
+
+   if (apic_reg_read(apic, reg, 4, low))
+   return 1;
+   if (reg == APIC_ICR)
+   apic_reg_read(apic, APIC_ICR2, 4, high);
+
+   *data = (((u64)high)  32) | low;
+
+   return 0;
+}
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index 40010b0..d081cb6 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -48,4 +48,12 @@ void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);
 
 int kvm_x2apic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data);
 int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
+
+int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data);
+int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
+
+static inline bool kvm_hv_vapic_enabled(struct kvm_vcpu *vcpu)
+{
+   return !!(vcpu-arch.hv_vapic  HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE);
+}
 #endif
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index db0b2b1..2fe555c 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -632,6 +632,7 @@ static u32 msrs_to_save[] = {
 #endif
MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
+   HV_X64_MSR_APIC_ASSIST_PAGE,
 };
 
 static unsigned num_msrs_to_save;
@@ -1063,10 +1064,37 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 
msr, u64 data)
 
 static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 {
-   pr_unimpl(vcpu, HYPER-V unimplemented wrmsr: 0x%x data 0x%llx\n,
- msr, data);
+   switch (msr) {
+   case HV_X64_MSR_APIC_ASSIST_PAGE: {
+   unsigned long vaddr;
+   void *addr;
+   struct page *page;
+   vcpu-arch.hv_vapic = data;
+   if (!kvm_hv_vapic_enabled(vcpu))
+   break;
+   vaddr = gfn_to_hva(vcpu-kvm, data 
+ HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT);
+   if (kvm_is_error_hva(vaddr))
+   return 1;
+   page = virt_to_page(vaddr);
+   addr = kmap_atomic(page, KM_USER0);
+   clear_user_page(addr, vaddr, page);
+   kunmap_atomic(addr, KM_USER0);
+   break;
+   }
+   case HV_X64_MSR_EOI:
+   return kvm_hv_vapic_msr_write(vcpu, APIC_EOI, data);
+   case HV_X64_MSR_ICR:
+   return kvm_hv_vapic_msr_write(vcpu, APIC_ICR, data);
+   case HV_X64_MSR_TPR:
+   return kvm_hv_vapic_msr_write(vcpu, APIC_TASKPRI, data);
+   default:
+   pr_unimpl(vcpu, HYPER-V unimplemented wrmsr: 0x%x 
+ data 0x%llx\n, msr, data);
+   return 1;
+   }
 
-   return 1;
+   return 0;
 }
 
 int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
@@ -1326,6 +1354,12 @@ static int get_msr_hyperv(struct kvm_vcpu *vcpu, u32 
msr, u64 *pdata)
data = r;
break;
}
+   case HV_X64_MSR_EOI:
+   return kvm_hv_vapic_msr_read(vcpu, APIC_EOI, pdata);
+   case HV_X64_MSR_ICR:
+   return kvm_hv_vapic_msr_read(vcpu, APIC_ICR, 

[PATCHv2 1/4] Add HYPE-V header file.

2010-01-17 Thread Gleb Natapov

Signed-off-by: Gleb Natapov g...@redhat.com
Signed-off-by: Vadim Rozenfeld vroze...@redhat.com
---
 arch/x86/include/asm/hyperv.h |  187 +
 1 files changed, 187 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/include/asm/hyperv.h

diff --git a/arch/x86/include/asm/hyperv.h b/arch/x86/include/asm/hyperv.h
new file mode 100644
index 000..91211f3
--- /dev/null
+++ b/arch/x86/include/asm/hyperv.h
@@ -0,0 +1,187 @@
+#ifndef _ASM_X86_KVM_HYPERV_H
+#define _ASM_X86_KVM_HYPERV_H
+
+#include linux/types.h
+
+/*
+ * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
+ * is set by CPUID(HvCpuIdFunctionVersionAndFeatures).
+ */
+#define HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS  0x4000
+#define HYPERV_CPUID_INTERFACE 0x4001
+#define HYPERV_CPUID_VERSION   0x4002
+#define HYPERV_CPUID_FEATURES  0x4003
+#define HYPERV_CPUID_ENLIGHTMENT_INFO  0x4004
+#define HYPERV_CPUID_IMPLEMENT_LIMITS  0x4005
+
+/*
+ * Feature identification. EAX indicates which features are available
+ * to the partition based upon the current partition privileges.
+ */
+
+/* VP Runtime (HV_X64_MSR_VP_RUNTIME) available */
+#define HV_X64_MSR_VP_RUNTIME_AVAILABLE(1  0)
+/* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/
+#define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE(1  1)
+/*
+ * Basic SynIC MSRs (HV_X64_MSR_SCONTROL through HV_X64_MSR_EOM
+ * and HV_X64_MSR_SINT0 through HV_X64_MSR_SINT15) available
+ */
+#define HV_X64_MSR_SYNIC_AVAILABLE (1  2)
+/*
+ * Synthetic Timer MSRs (HV_X64_MSR_STIMER0_CONFIG through
+ * HV_X64_MSR_STIMER3_COUNT) available
+ */
+#define HV_X64_MSR_SYNTIMER_AVAILABLE  (1  3)
+/*
+ * APIC access MSRs (HV_X64_MSR_EOI, HV_X64_MSR_ICR and HV_X64_MSR_TPR)
+ * are available
+ */
+#define HV_X64_MSR_APIC_ACCESS_AVAILABLE   (1  4)
+/* Hypercall MSRs (HV_X64_MSR_GUEST_OS_ID and HV_X64_MSR_HYPERCALL) available*/
+#define HV_X64_MSR_HYPERCALL_AVAILABLE (1  5)
+/* Access virtual processor index MSR (HV_X64_MSR_VP_INDEX) available*/
+#define HV_X64_MSR_VP_INDEX_AVAILABLE  (1  6)
+/* Virtual system reset MSR (HV_X64_MSR_RESET) is available*/
+#define HV_X64_MSR_RESET_AVAILABLE (1  7)
+ /*
+  * Access statistics pages MSRs (HV_X64_MSR_STATS_PARTITION_RETAIL_PAGE,
+  * HV_X64_MSR_STATS_PARTITION_INTERNAL_PAGE, HV_X64_MSR_STATS_VP_RETAIL_PAGE,
+  * HV_X64_MSR_STATS_VP_INTERNAL_PAGE) available
+  */
+#define HV_X64_MSR_STAT_PAGES_AVAILABLE(1  8)
+
+/*
+ * Feature identification: EBX indicates which flags were specified at
+ * partition creation. The format is the same as the partition creation
+ * flag structure defined in section Partition Creation Flags.
+ */
+#define HV_X64_CREATE_PARTITIONS   (1  0)
+#define HV_X64_ACCESS_PARTITION_ID (1  1)
+#define HV_X64_ACCESS_MEMORY_POOL  (1  2)
+#define HV_X64_ADJUST_MESSAGE_BUFFERS  (1  3)
+#define HV_X64_POST_MESSAGES   (1  4)
+#define HV_X64_SIGNAL_EVENTS   (1  5)
+#define HV_X64_CREATE_PORT (1  6)
+#define HV_X64_CONNECT_PORT(1  7)
+#define HV_X64_ACCESS_STATS(1  8)
+#define HV_X64_DEBUGGING   (1  11)
+#define HV_X64_CPU_POWER_MANAGEMENT(1  12)
+#define HV_X64_CONFIGURE_PROFILER  (1  13)
+
+/*
+ * Feature identification. EDX indicates which miscellaneous features
+ * are available to the partition.
+ */
+/* The MWAIT instruction is available (per section MONITOR / MWAIT) */
+#define HV_X64_MWAIT_AVAILABLE (1  0)
+/* Guest debugging support is available */
+#define HV_X64_GUEST_DEBUGGING_AVAILABLE   (1  1)
+/* Performance Monitor support is available*/
+#define HV_X64_PERF_MONITOR_AVAILABLE  (1  2)
+/* Support for physical CPU dynamic partitioning events is available*/
+#define HV_X64_CPU_DYNAMIC_PARTITIONING_AVAILABLE  (1  3)
+/*
+ * Support for passing hypercall input parameter block via XMM
+ * registers is available
+ */
+#define HV_X64_HYPERCALL_PARAMS_XMM_AVAILABLE  (1  4)
+/* Support for a virtual guest idle state is available */
+#define HV_X64_GUEST_IDLE_STATE_AVAILABLE  (1  5)
+
+/*
+ * Implementation recommendations. Indicates which behaviors the hypervisor
+ * recommends the OS implement for optimal performance.
+ */
+ /*
+  * Recommend using hypercall for address space switches rather
+  * than MOV to CR3 instruction
+  */
+#define HV_X64_MWAIT_RECOMMENDED   (1  0)
+/* Recommend using hypercall for local TLB flushes rather
+ * than INVLPG or MOV to CR3 instructions */
+#define HV_X64_LOCAL_TLB_FLUSH_RECOMMENDED (1  1)
+/*
+ * Recommend using hypercall for remote TLB flushes rather
+ * than inter-processor interrupts
+ */
+#define 

[PATCHv2 2/4] Implement bare minimum of HYPER-V MSRs.

2010-01-17 Thread Gleb Natapov
Minimum HYPER-V implementation should have GUEST_OS_ID, HYPERCALL and
VP_INDEX MSRs.

Signed-off-by: Gleb Natapov g...@redhat.com
Signed-off-by: Vadim Rozenfeld vroze...@redhat.com
---
 arch/x86/include/asm/kvm_host.h |4 +
 arch/x86/include/asm/kvm_para.h |1 +
 arch/x86/kvm/trace.h|   32 +++
 arch/x86/kvm/x86.c  |  184 ++-
 include/linux/kvm.h |1 +
 5 files changed, 221 insertions(+), 1 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 93bee7a..67d19e4 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -413,6 +413,10 @@ struct kvm_arch {
s64 kvmclock_offset;
 
struct kvm_xen_hvm_config xen_hvm_config;
+
+   /* fields used by HYPER-V emulation */
+   u64 hv_guest_os_id;
+   u64 hv_hypercall;
 };
 
 struct kvm_vm_stat {
diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
index c584076..ffae142 100644
--- a/arch/x86/include/asm/kvm_para.h
+++ b/arch/x86/include/asm/kvm_para.h
@@ -2,6 +2,7 @@
 #define _ASM_X86_KVM_PARA_H
 
 #include linux/types.h
+#include asm/hyperv.h
 
 /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx.  It
  * should be used to determine that a VM is running under KVM.
diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
index 816e044..1cb3d0e 100644
--- a/arch/x86/kvm/trace.h
+++ b/arch/x86/kvm/trace.h
@@ -56,6 +56,38 @@ TRACE_EVENT(kvm_hypercall,
 );
 
 /*
+ * Tracepoint for hypercall.
+ */
+TRACE_EVENT(kvm_hv_hypercall,
+   TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx,
+__u64 ingpa, __u64 outgpa),
+   TP_ARGS(code, fast, rep_cnt, rep_idx, ingpa, outgpa),
+
+   TP_STRUCT__entry(
+   __field(__u16,  code)
+   __field(bool,   fast)
+   __field(__u16,  rep_cnt )
+   __field(__u16,  rep_idx )
+   __field(__u64,  ingpa   )
+   __field(__u64,  outgpa  )
+   ),
+
+   TP_fast_assign(
+   __entry-code   = code;
+   __entry-fast   = fast;
+   __entry-rep_cnt= rep_cnt;
+   __entry-rep_idx= rep_idx;
+   __entry-ingpa  = ingpa;
+   __entry-outgpa = outgpa;
+   ),
+
+   TP_printk(code 0x%x %s cnt 0x%x idx 0x%x in 0x%llx out 0x%llx,
+ __entry-code, __entry-fast ? fast : slow,
+ __entry-rep_cnt, __entry-rep_idx,  __entry-ingpa,
+ __entry-outgpa)
+);
+
+/*
  * Tracepoint for PIO.
  */
 TRACE_EVENT(kvm_pio,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 4d835b6..db0b2b1 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -630,7 +630,8 @@ static u32 msrs_to_save[] = {
 #ifdef CONFIG_X86_64
MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
 #endif
-   MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA
+   MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
+   HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
 };
 
 static unsigned num_msrs_to_save;
@@ -1005,6 +1006,69 @@ out:
return r;
 }
 
+static bool kvm_hv_hypercall_enabled(struct kvm *kvm)
+{
+   return kvm-arch.hv_hypercall  HV_X64_MSR_HYPERCALL_ENABLE;
+}
+
+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:
+   r = true;
+   break;
+   }
+
+   return r;
+}
+
+static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+{
+   struct kvm *kvm = vcpu-kvm;
+
+   switch (msr) {
+   case HV_X64_MSR_GUEST_OS_ID:
+   kvm-arch.hv_guest_os_id = data;
+   /* setting guest os id to zero disables hypercall page */
+   if (!kvm-arch.hv_guest_os_id)
+   kvm-arch.hv_hypercall = ~HV_X64_MSR_HYPERCALL_ENABLE;
+   break;
+   case HV_X64_MSR_HYPERCALL: {
+   u64 gfn;
+   unsigned long addr;
+   /* if guest os id is not set hypercall should remain disabled */
+   if (!kvm-arch.hv_guest_os_id  data)
+   break;
+   kvm-arch.hv_hypercall = data;
+   if (!kvm_hv_hypercall_enabled(kvm))
+   break;
+   gfn = kvm-arch.hv_hypercall 
+   HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
+   addr = gfn_to_hva(kvm, gfn);
+   if (kvm_is_error_hva(addr))
+   return 1;
+   kvm_x86_ops-patch_hypercall(vcpu, (unsigned char *)addr);
+   ((unsigned char *)addr)[3] = 

[PATCHv2 0/4] Add support for some HYPER-V PV features

2010-01-17 Thread Gleb Natapov
HYPER-V provides PV capabilities for its guests and most new MS Windows
detect and use them automatically. Older Windows guests need additional
drivers to uses PV. This patch series implements some PV capabilities
defined by HYPER-V spec for KVM. Windows guests running on KVM will be
able to take advantage of them.

Changelog:
 v1-v2
  rename kvm_hyperv.h into hyperv.h and move into separate patch
  minor style fixes
  use clear_user-page(0 to zero userspace page 
  use APIC register names when calling kvm_hv_vapic_msr_(read|write)()

Gleb Natapov (4):
  Add HYPE-V header file.
  Implement bare minimum of HYPER-V MSRs.
  Add HYPER-V apic access MSRs.
  Implement NotifyLongSpinWait HYPER-V hypercall.

 arch/x86/include/asm/hyperv.h   |  187 
 arch/x86/include/asm/kvm_host.h |6 +
 arch/x86/include/asm/kvm_para.h |1 +
 arch/x86/kvm/lapic.c|   31 ++
 arch/x86/kvm/lapic.h|8 ++
 arch/x86/kvm/trace.h|   32 ++
 arch/x86/kvm/x86.c  |  227 ++-
 include/linux/kvm.h |3 +
 8 files changed, 494 insertions(+), 1 deletions(-)
 create mode 100644 arch/x86/include/asm/hyperv.h

--
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: [PATCHv2 2/4] Implement bare minimum of HYPER-V MSRs.

2010-01-17 Thread Avi Kivity

On 01/17/2010 11:03 AM, Gleb Natapov wrote:

Minimum HYPER-V implementation should have GUEST_OS_ID, HYPERCALL and
VP_INDEX MSRs.


  TRACE_EVENT(kvm_pio,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 4d835b6..db0b2b1 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -630,7 +630,8 @@ static u32 msrs_to_save[] = {
  #ifdef CONFIG_X86_64
MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
  #endif
-   MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA
+   MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
+   HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
  };
   


These will be disabled since the msrs don't exist on the host.  See the 
comment above and KVM_SAVE_MSRS_BEGIN.



+   case HV_X64_MSR_HYPERCALL: {
+   u64 gfn;
+   unsigned long addr;
+   /* if guest os id is not set hypercall should remain disabled */
+   if (!kvm-arch.hv_guest_os_id  data)
+   break;
+   kvm-arch.hv_hypercall = data;
+   if (!kvm_hv_hypercall_enabled(kvm))
+   break;
+   gfn = kvm-arch.hv_hypercall
+   HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
+   addr = gfn_to_hva(kvm, gfn);
+   if (kvm_is_error_hva(addr))
+   return 1;
   


Should di the error check before assigning, perhaps.


+   kvm_x86_ops-patch_hypercall(vcpu, (unsigned char *)addr);
+   ((unsigned char *)addr)[3] = 0xc3; /* ret */
   


kvm_write_guest(), this can fault.


+int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
+{
+   u64 param, ingpa, outgpa, ret;
+   uint16_t code, rep_idx, rep_cnt, res = HV_STATUS_SUCCESS, rep_done = 0;
+   bool fast, longmode;
+   int cs_db, cs_l;
+
+   /*
+* hypercall generates UD from non zero cpl and real mode
+* per HYPER-V spec
+*/
+   if (kvm_x86_ops-get_cpl(vcpu) != 0 || !(vcpu-arch.cr0  X86_CR0_PE)) {
   


Use kvm_read_cr0_bits() to avoid caching.


--
error compiling committee.c: too many arguments to function

--
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: [PATCHv2 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Avi Kivity

On 01/17/2010 11:03 AM, Gleb Natapov wrote:


Signed-off-by: Gleb Natapovg...@redhat.com
Signed-off-by: Vadim Rozenfeldvroze...@redhat.com
   


Changelog entry.



  struct kvm_mem_alias {
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index ba8c045..4b224f9 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1246,3 +1246,34 @@ int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, 
u64 *data)

return 0;
  }
+
+int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 reg, u64 data)
+{
+   struct kvm_lapic *apic = vcpu-arch.apic;
+
+   if (!irqchip_in_kernel(vcpu-kvm))
+   return 1;
+
+   /* if this is ICR write vector before command */
+   if (reg == APIC_ICR)
+   apic_reg_write(apic, APIC_ICR2, (u32)(data  32));
+   return apic_reg_write(apic, reg, (u32)data);
+}
+
+int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 reg, u64 *data)
+{
+   struct kvm_lapic *apic = vcpu-arch.apic;
+   u32 low, high = 0;
+
+   if (!irqchip_in_kernel(vcpu-kvm))
+   return 1;
+
+   if (apic_reg_read(apic, reg, 4,low))
+   return 1;
+   if (reg == APIC_ICR)
+   apic_reg_read(apic, APIC_ICR2, 4,high);
+
+   *data = (((u64)high)  32) | low;
+
+   return 0;
+}
   


I prefer putting this in x86.c (maybe later split into hyperv.c).


diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index 40010b0..d081cb6 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -48,4 +48,12 @@ void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);

  int kvm_x2apic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data);
  int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
+
+int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data);
+int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
+
+static inline bool kvm_hv_vapic_enabled(struct kvm_vcpu *vcpu)
+{
+   return !!(vcpu-arch.hv_vapic  HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE);
+}
   


Are you sure that vapic enabled is equivalent to apic assist page enable?

!! not required.


  #endif
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index db0b2b1..2fe555c 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -632,6 +632,7 @@ static u32 msrs_to_save[] = {
  #endif
MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
+   HV_X64_MSR_APIC_ASSIST_PAGE,
  };

   


Will be dropped by msr validation.


  static unsigned num_msrs_to_save;
@@ -1063,10 +1064,37 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 
msr, u64 data)

  static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
  {
-   pr_unimpl(vcpu, HYPER-V unimplemented wrmsr: 0x%x data 0x%llx\n,
- msr, data);
+   switch (msr) {
+   case HV_X64_MSR_APIC_ASSIST_PAGE: {
+   unsigned long vaddr;
+   void *addr;
+   struct page *page;
+   vcpu-arch.hv_vapic = data;
+   if (!kvm_hv_vapic_enabled(vcpu))
+   break;
+   vaddr = gfn_to_hva(vcpu-kvm, data
+ HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT);
+   if (kvm_is_error_hva(vaddr))
+   return 1;
+   page = virt_to_page(vaddr);
   


virt_to_page() takes a kernel address, not a user address.  This is 
get_user_pages().  But I think the whole thing is done better with 
put_user().



+   addr = kmap_atomic(page, KM_USER0);
+   clear_user_page(addr, vaddr, page);
+   kunmap_atomic(addr, KM_USER0);
   


Surprising that clear_user_page needs kmap_atomic() (but true).

--
error compiling committee.c: too many arguments to function

--
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: [PATCHv2 4/4] Implement NotifyLongSpinWait HYPER-V hypercall.

2010-01-17 Thread Avi Kivity

On 01/17/2010 11:03 AM, Gleb Natapov wrote:

Signed-off-by: Gleb Natapovg...@redhat.com
Signed-off-by: Vadim Rozenfeldvroze...@redhat.com
   


Changelog entry.

--
error compiling committee.c: too many arguments to function

--
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] KVM: remove redundant NULL tests

2010-01-17 Thread Avi Kivity

On 01/14/2010 07:05 PM, Roel Kluin wrote:

kvm_get_exit_data() cannot return a NULL pointer.
   


Applied, thanks.

--
error compiling committee.c: too many arguments to function

--
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: KVM: fix cleanup_srcu_struct use-after-free

2010-01-17 Thread Avi Kivity

On 01/16/2010 04:00 AM, Marcelo Tosatti wrote:

kvm_destroy_vm should free struct kvm after cleanup_srcu_struct.

Signed-off-by: Marcelo Tosattimtosa...@redhat.com

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e0a591d..c828a39 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -509,8 +509,8 @@ static void kvm_destroy_vm(struct kvm *kvm)
  #else
kvm_arch_flush_shadow(kvm);
  #endif
-   kvm_arch_destroy_vm(kvm);
cleanup_srcu_struct(kvm-srcu);
+   kvm_arch_destroy_vm(kvm);
hardware_disable_all();
mmdrop(mm);
  }
   


Applied, thanks.

--
error compiling committee.c: too many arguments to function

--
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: [PATCHv2 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Christoph Hellwig
On Sun, Jan 17, 2010 at 02:20:32PM +0200, Avi Kivity wrote:
 +addr = kmap_atomic(page, KM_USER0);
 +clear_user_page(addr, vaddr, page);
 +kunmap_atomic(addr, KM_USER0);


 Surprising that clear_user_page needs kmap_atomic() (but true).

There's a clear_user_highpage helper to take care of it for you.

--
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 0/6] KVM: PPC: FPU/Altivec/VSX bringup

2010-01-17 Thread Avi Kivity

On 01/15/2010 03:49 PM, Alexander Graf wrote:

Right now the code to use external providers (FPU/Altivec/FSX) is rather hacky.

We just set the respective feature bit in the guest MSR when the guest requests
it and declare it as good. Now, Linux wants to mess around there too, so
whenever a process switch occurs, it saves the external provider state and
reloads the current thread ones'.

Unfortunately, we didn't tell Linux about our guest state. So Linux doesn't even
get the chance to swap any of our registers around which means it ends up
restoring registers from random processes - and we lose all state.

This patchset makes at least FPU and Altivec work. I don't have a VSX machine to
test that extension on. While at it, it also fixes some issues I've stumbled
across during debug.

The basic ideas on how this should work come from Benjamin Herrenschmidt.
Thanks a lot for giving input on this one (and all the other times)!
   


Applied all, thanks.

--
error compiling committee.c: too many arguments to function

--
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] KVM: Add missing emulation failure report in kvm_mmu_page_fault()

2010-01-17 Thread Avi Kivity

On 01/15/2010 10:44 AM, Sheng Yang wrote:

Currently we only have handle_invalid_guest_state() reported emulation 
failure...

Signed-off-by: Sheng Yangsh...@linux.intel.com
---
  arch/x86/kvm/mmu.c |1 +
  1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 4f5508c..037e52a 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -2791,6 +2791,7 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, 
u32 error_code)
++vcpu-stat.mmio_exits;
return 0;
case EMULATE_FAIL:
+   kvm_report_emulation_failure(vcpu, emulation failure);
vcpu-run-exit_reason = KVM_EXIT_INTERNAL_ERROR;
vcpu-run-internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
vcpu-run-internal.ndata = 0;
   


This is intentional - instead of spamming dmesg, we exit with an 
internal error.  Modern qemu-kvm will halt and allow the user to inspect 
the guest with the built-in disassembler.


--
error compiling committee.c: too many arguments to function

--
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: [PATCHv2 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Vadim Rozenfeld
On Sun, 2010-01-17 at 14:20 +0200, Avi Kivity wrote:
 On 01/17/2010 11:03 AM, Gleb Natapov wrote:
 
  Signed-off-by: Gleb Natapovg...@redhat.com
  Signed-off-by: Vadim Rozenfeldvroze...@redhat.com
 
 
 Changelog entry.
 
 
struct kvm_mem_alias {
  diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
  index ba8c045..4b224f9 100644
  --- a/arch/x86/kvm/lapic.c
  +++ b/arch/x86/kvm/lapic.c
  @@ -1246,3 +1246,34 @@ int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 
  msr, u64 *data)
 
  return 0;
}
  +
  +int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 reg, u64 data)
  +{
  +   struct kvm_lapic *apic = vcpu-arch.apic;
  +
  +   if (!irqchip_in_kernel(vcpu-kvm))
  +   return 1;
  +
  +   /* if this is ICR write vector before command */
  +   if (reg == APIC_ICR)
  +   apic_reg_write(apic, APIC_ICR2, (u32)(data  32));
  +   return apic_reg_write(apic, reg, (u32)data);
  +}
  +
  +int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 reg, u64 *data)
  +{
  +   struct kvm_lapic *apic = vcpu-arch.apic;
  +   u32 low, high = 0;
  +
  +   if (!irqchip_in_kernel(vcpu-kvm))
  +   return 1;
  +
  +   if (apic_reg_read(apic, reg, 4,low))
  +   return 1;
  +   if (reg == APIC_ICR)
  +   apic_reg_read(apic, APIC_ICR2, 4,high);
  +
  +   *data = (((u64)high)  32) | low;
  +
  +   return 0;
  +}
 
 
 I prefer putting this in x86.c (maybe later split into hyperv.c).
 
  diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
  index 40010b0..d081cb6 100644
  --- a/arch/x86/kvm/lapic.h
  +++ b/arch/x86/kvm/lapic.h
  @@ -48,4 +48,12 @@ void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);
 
int kvm_x2apic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data);
int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
  +
  +int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data);
  +int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
  +
  +static inline bool kvm_hv_vapic_enabled(struct kvm_vcpu *vcpu)
  +{
  +   return !!(vcpu-arch.hv_vapic  HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE);
  +}
 
 
 Are you sure that vapic enabled is equivalent to apic assist page enable?
At least, when it is disable, the EOI interception mechanism won't
work.   
 
 !! not required.
 
#endif
  diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
  index db0b2b1..2fe555c 100644
  --- a/arch/x86/kvm/x86.c
  +++ b/arch/x86/kvm/x86.c
  @@ -632,6 +632,7 @@ static u32 msrs_to_save[] = {
#endif
  MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
  HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
  +   HV_X64_MSR_APIC_ASSIST_PAGE,
};
 
 
 
 Will be dropped by msr validation.
 
static unsigned num_msrs_to_save;
  @@ -1063,10 +1064,37 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, 
  u32 msr, u64 data)
 
static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
{
  -   pr_unimpl(vcpu, HYPER-V unimplemented wrmsr: 0x%x data 0x%llx\n,
  - msr, data);
  +   switch (msr) {
  +   case HV_X64_MSR_APIC_ASSIST_PAGE: {
  +   unsigned long vaddr;
  +   void *addr;
  +   struct page *page;
  +   vcpu-arch.hv_vapic = data;
  +   if (!kvm_hv_vapic_enabled(vcpu))
  +   break;
  +   vaddr = gfn_to_hva(vcpu-kvm, data
  + HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT);
  +   if (kvm_is_error_hva(vaddr))
  +   return 1;
  +   page = virt_to_page(vaddr);
 
 
 virt_to_page() takes a kernel address, not a user address.  This is 
 get_user_pages().  But I think the whole thing is done better with 
 put_user().
 
  +   addr = kmap_atomic(page, KM_USER0);
  +   clear_user_page(addr, vaddr, page);
  +   kunmap_atomic(addr, KM_USER0);
 
 
 Surprising that clear_user_page needs kmap_atomic() (but true).
 


--
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: [PATCHv2 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Gleb Natapov
On Sun, Jan 17, 2010 at 02:20:32PM +0200, Avi Kivity wrote:
 On 01/17/2010 11:03 AM, Gleb Natapov wrote:
 
 Signed-off-by: Gleb Natapovg...@redhat.com
 Signed-off-by: Vadim Rozenfeldvroze...@redhat.com
 
 Changelog entry.
 
 
   struct kvm_mem_alias {
 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
 index ba8c045..4b224f9 100644
 --- a/arch/x86/kvm/lapic.c
 +++ b/arch/x86/kvm/lapic.c
 @@ -1246,3 +1246,34 @@ int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 
 msr, u64 *data)
 
  return 0;
   }
 +
 +int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 reg, u64 data)
 +{
 +struct kvm_lapic *apic = vcpu-arch.apic;
 +
 +if (!irqchip_in_kernel(vcpu-kvm))
 +return 1;
 +
 +/* if this is ICR write vector before command */
 +if (reg == APIC_ICR)
 +apic_reg_write(apic, APIC_ICR2, (u32)(data  32));
 +return apic_reg_write(apic, reg, (u32)data);
 +}
 +
 +int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 reg, u64 *data)
 +{
 +struct kvm_lapic *apic = vcpu-arch.apic;
 +u32 low, high = 0;
 +
 +if (!irqchip_in_kernel(vcpu-kvm))
 +return 1;
 +
 +if (apic_reg_read(apic, reg, 4,low))
 +return 1;
 +if (reg == APIC_ICR)
 +apic_reg_read(apic, APIC_ICR2, 4,high);
 +
 +*data = (((u64)high)  32) | low;
 +
 +return 0;
 +}
 
 I prefer putting this in x86.c (maybe later split into hyperv.c).
 
This implements part of apic behaviour. It uses internal lapic functions
like apic_reg_read()/apic_reg_write(). Why move it from lapic.c?

 diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
 index 40010b0..d081cb6 100644
 --- a/arch/x86/kvm/lapic.h
 +++ b/arch/x86/kvm/lapic.h
 @@ -48,4 +48,12 @@ void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);
 
   int kvm_x2apic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data);
   int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
 +
 +int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data);
 +int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
 +
 +static inline bool kvm_hv_vapic_enabled(struct kvm_vcpu *vcpu)
 +{
 +return !!(vcpu-arch.hv_vapic  HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE);
 +}
 
 Are you sure that vapic enabled is equivalent to apic assist page enable?
 
 !! not required.
 
The function is not used to check if vapic is enabled, so the name
should be changed.

   #endif
 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
 index db0b2b1..2fe555c 100644
 --- a/arch/x86/kvm/x86.c
 +++ b/arch/x86/kvm/x86.c
 @@ -632,6 +632,7 @@ static u32 msrs_to_save[] = {
   #endif
  MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
  HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
 +HV_X64_MSR_APIC_ASSIST_PAGE,
   };
 
 
 Will be dropped by msr validation.
 
   static unsigned num_msrs_to_save;
 @@ -1063,10 +1064,37 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, 
 u32 msr, u64 data)
 
   static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
   {
 -pr_unimpl(vcpu, HYPER-V unimplemented wrmsr: 0x%x data 0x%llx\n,
 -  msr, data);
 +switch (msr) {
 +case HV_X64_MSR_APIC_ASSIST_PAGE: {
 +unsigned long vaddr;
 +void *addr;
 +struct page *page;
 +vcpu-arch.hv_vapic = data;
 +if (!kvm_hv_vapic_enabled(vcpu))
 +break;
 +vaddr = gfn_to_hva(vcpu-kvm, data
 +  HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT);
 +if (kvm_is_error_hva(vaddr))
 +return 1;
 +page = virt_to_page(vaddr);
 
 virt_to_page() takes a kernel address, not a user address.  This is
 get_user_pages().  But I think the whole thing is done better with
 put_user().
 
So there is no function to get struct page from user virtual address?

 +addr = kmap_atomic(page, KM_USER0);
 +clear_user_page(addr, vaddr, page);
 +kunmap_atomic(addr, KM_USER0);
 
 Surprising that clear_user_page needs kmap_atomic() (but true).
 
 -- 
 error compiling committee.c: too many arguments to function

--
Gleb.
--
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] eventfd - allow atomic read and waitqueue remove

2010-01-17 Thread Avi Kivity

On 01/13/2010 07:34 PM, Davide Libenzi wrote:

KVM needs a wait to atomically remove themselves from the eventfd -poll()
wait queue head, in order to handle correctly their IRQfd deassign
operation.
This patch introduces such API, plus a way to read an eventfd from its
context.
Andrew, they prefer to have this go through Avi's KVM tree, in order to
keep dependencies localized. So you just ignore this.
Avi, this fixes a few checkpatch warnings, so you should get this instead
of the one posted previously.


   


Applied, thanks.

--
error compiling committee.c: too many arguments to function

--
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: [PATCHv2 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Gleb Natapov
On Sun, Jan 17, 2010 at 07:32:32AM -0500, Christoph Hellwig wrote:
 On Sun, Jan 17, 2010 at 02:20:32PM +0200, Avi Kivity wrote:
  +  addr = kmap_atomic(page, KM_USER0);
  +  clear_user_page(addr, vaddr, page);
  +  kunmap_atomic(addr, KM_USER0);
 
 
  Surprising that clear_user_page needs kmap_atomic() (but true).
 
 There's a clear_user_highpage helper to take care of it for you.
I copied code from the instead of using helper faction for
some unknown to me reason. Anyway if I can't get struct page from
user virtual address I can't use it. Actually I am not sure the page
should be zeroed at all. Spec only descries first dword of the page and
doesn't require zeroing the reset as far as I see.

--
Gleb.
--
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 0/2] kvm: fix spurious interrupt with irqfd

2010-01-17 Thread Avi Kivity

On 01/13/2010 07:12 PM, Michael S. Tsirkin wrote:

Deassigning irqfd and assigning back caused spurious interrupt. fix this
by clearing the counter on deassign.  This is on top of davidel's patch
which makes clearing eventfd counter from modules possible.
   


Applied both, thanks.

--
error compiling committee.c: too many arguments to function

--
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: [PATCHv2 2/4] Implement bare minimum of HYPER-V MSRs.

2010-01-17 Thread Gleb Natapov
On Sun, Jan 17, 2010 at 02:10:45PM +0200, Avi Kivity wrote:
 On 01/17/2010 11:03 AM, Gleb Natapov wrote:
 Minimum HYPER-V implementation should have GUEST_OS_ID, HYPERCALL and
 VP_INDEX MSRs.
 
 
   TRACE_EVENT(kvm_pio,
 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
 index 4d835b6..db0b2b1 100644
 --- a/arch/x86/kvm/x86.c
 +++ b/arch/x86/kvm/x86.c
 @@ -630,7 +630,8 @@ static u32 msrs_to_save[] = {
   #ifdef CONFIG_X86_64
  MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
   #endif
 -MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA
 +MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
 +HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
   };
 
 These will be disabled since the msrs don't exist on the host.  See
 the comment above and KVM_SAVE_MSRS_BEGIN.
 
I see. Why not have two arrays?

 +case HV_X64_MSR_HYPERCALL: {
 +u64 gfn;
 +unsigned long addr;
 +/* if guest os id is not set hypercall should remain disabled */
 +if (!kvm-arch.hv_guest_os_id  data)
 +break;
 +kvm-arch.hv_hypercall = data;
 +if (!kvm_hv_hypercall_enabled(kvm))
 +break;
 +gfn = kvm-arch.hv_hypercall
 +HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
 +addr = gfn_to_hva(kvm, gfn);
 +if (kvm_is_error_hva(addr))
 +return 1;
 
 Should di the error check before assigning, perhaps.
 
Spec doesn't tell. And guest will get #GP and BSOD anyway.

 +kvm_x86_ops-patch_hypercall(vcpu, (unsigned char *)addr);
 +((unsigned char *)addr)[3] = 0xc3; /* ret */
 
 kvm_write_guest(), this can fault.
 
 +int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 +{
 +u64 param, ingpa, outgpa, ret;
 +uint16_t code, rep_idx, rep_cnt, res = HV_STATUS_SUCCESS, rep_done = 0;
 +bool fast, longmode;
 +int cs_db, cs_l;
 +
 +/*
 + * hypercall generates UD from non zero cpl and real mode
 + * per HYPER-V spec
 + */
 +if (kvm_x86_ops-get_cpl(vcpu) != 0 || !(vcpu-arch.cr0  X86_CR0_PE)) {
 
 Use kvm_read_cr0_bits() to avoid caching.
 
 
 -- 
 error compiling committee.c: too many arguments to function

--
Gleb.
--
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: [PATCHv2 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Christoph Hellwig
On Sun, Jan 17, 2010 at 02:41:42PM +0200, Gleb Natapov wrote:
 I copied code from the instead of using helper faction for
 some unknown to me reason. Anyway if I can't get struct page from
 user virtual address I can't use it. Actually I am not sure the page
 should be zeroed at all. Spec only descries first dword of the page and
 doesn't require zeroing the reset as far as I see.

There's a clear_user() function that just takes a user virtual address
and a size.

--
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: [PATCHv2 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Avi Kivity

On 01/17/2010 02:36 PM, Gleb Natapov wrote:

+

+int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 reg, u64 *data)
+{
+   struct kvm_lapic *apic = vcpu-arch.apic;
+   u32 low, high = 0;
+
+   if (!irqchip_in_kernel(vcpu-kvm))
+   return 1;
+
+   if (apic_reg_read(apic, reg, 4,low))
+   return 1;
+   if (reg == APIC_ICR)
+   apic_reg_read(apic, APIC_ICR2, 4,high);
+
+   *data = (((u64)high)   32) | low;
+
+   return 0;
+}
   

I prefer putting this in x86.c (maybe later split into hyperv.c).

 

This implements part of apic behaviour. It uses internal lapic functions
like apic_reg_read()/apic_reg_write(). Why move it from lapic.c?
   


The new functions implement hyper-v behaviour.  Why scatter them all around?

Maybe apic_reg_{read,write} need to be exported.


  static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
  {
-   pr_unimpl(vcpu, HYPER-V unimplemented wrmsr: 0x%x data 0x%llx\n,
- msr, data);
+   switch (msr) {
+   case HV_X64_MSR_APIC_ASSIST_PAGE: {
+   unsigned long vaddr;
+   void *addr;
+   struct page *page;
+   vcpu-arch.hv_vapic = data;
+   if (!kvm_hv_vapic_enabled(vcpu))
+   break;
+   vaddr = gfn_to_hva(vcpu-kvm, data
+ HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT);
+   if (kvm_is_error_hva(vaddr))
+   return 1;
+   page = virt_to_page(vaddr);
   

virt_to_page() takes a kernel address, not a user address.  This is
get_user_pages().  But I think the whole thing is done better with
put_user().

 

So there is no function to get struct page from user virtual address?
   


get_user_pages_fast().


--
error compiling committee.c: too many arguments to function

--
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: [PATCHv2 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Gleb Natapov
On Sun, Jan 17, 2010 at 07:44:57AM -0500, Christoph Hellwig wrote:
 On Sun, Jan 17, 2010 at 02:41:42PM +0200, Gleb Natapov wrote:
  I copied code from the instead of using helper faction for
  some unknown to me reason. Anyway if I can't get struct page from
  user virtual address I can't use it. Actually I am not sure the page
  should be zeroed at all. Spec only descries first dword of the page and
  doesn't require zeroing the reset as far as I see.
 
 There's a clear_user() function that just takes a user virtual address
 and a size.
Precisely what I need. Thanks!

--
Gleb.
--
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: [PATCHv2 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Avi Kivity

On 01/17/2010 02:46 PM, Gleb Natapov wrote:

On Sun, Jan 17, 2010 at 07:44:57AM -0500, Christoph Hellwig wrote:
   

On Sun, Jan 17, 2010 at 02:41:42PM +0200, Gleb Natapov wrote:
 

I copied code from the instead of using helper faction for
some unknown to me reason. Anyway if I can't get struct page from
user virtual address I can't use it. Actually I am not sure the page
should be zeroed at all. Spec only descries first dword of the page and
doesn't require zeroing the reset as far as I see.
   

There's a clear_user() function that just takes a user virtual address
and a size.
 

Precisely what I need. Thanks!

   


But clear_user_page() is confusingly named.  I assume it deals with 
virtually tagged caches on archs that have them?


--
error compiling committee.c: too many arguments to function

--
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: [PATCHv2 2/4] Implement bare minimum of HYPER-V MSRs.

2010-01-17 Thread Avi Kivity

On 01/17/2010 02:44 PM, Gleb Natapov wrote:

On Sun, Jan 17, 2010 at 02:10:45PM +0200, Avi Kivity wrote:
   

On 01/17/2010 11:03 AM, Gleb Natapov wrote:
 

Minimum HYPER-V implementation should have GUEST_OS_ID, HYPERCALL and
VP_INDEX MSRs.


  TRACE_EVENT(kvm_pio,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 4d835b6..db0b2b1 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -630,7 +630,8 @@ static u32 msrs_to_save[] = {
  #ifdef CONFIG_X86_64
MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
  #endif
-   MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA
+   MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
+   HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
  };
   

These will be disabled since the msrs don't exist on the host.  See
the comment above and KVM_SAVE_MSRS_BEGIN.

 

I see. Why not have two arrays?
   


Clearly better.


+   case HV_X64_MSR_HYPERCALL: {
+   u64 gfn;
+   unsigned long addr;
+   /* if guest os id is not set hypercall should remain disabled */
+   if (!kvm-arch.hv_guest_os_id   data)
+   break;
+   kvm-arch.hv_hypercall = data;
+   if (!kvm_hv_hypercall_enabled(kvm))
+   break;
+   gfn = kvm-arch.hv_hypercall
+   HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
+   addr = gfn_to_hva(kvm, gfn);
+   if (kvm_is_error_hva(addr))
+   return 1;
   

Should di the error check before assigning, perhaps.

 

Spec doesn't tell. And guest will get #GP and BSOD anyway.
   


Well, all msrs I know of either #GP, or store the value and do what 
they're supposed to do, never both.



--
error compiling committee.c: too many arguments to function

--
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: [PATCHv2 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Gleb Natapov
On Sun, Jan 17, 2010 at 02:46:46PM +0200, Avi Kivity wrote:
 On 01/17/2010 02:36 PM, Gleb Natapov wrote:
 +
 +int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 reg, u64 *data)
 +{
 +  struct kvm_lapic *apic = vcpu-arch.apic;
 +  u32 low, high = 0;
 +
 +  if (!irqchip_in_kernel(vcpu-kvm))
 +  return 1;
 +
 +  if (apic_reg_read(apic, reg, 4,low))
 +  return 1;
 +  if (reg == APIC_ICR)
 +  apic_reg_read(apic, APIC_ICR2, 4,high);
 +
 +  *data = (((u64)high)   32) | low;
 +
 +  return 0;
 +}
 I prefer putting this in x86.c (maybe later split into hyperv.c).
 
 This implements part of apic behaviour. It uses internal lapic functions
 like apic_reg_read()/apic_reg_write(). Why move it from lapic.c?
 
 The new functions implement hyper-v behaviour.  Why scatter them all around?
 
Each hyper-v extension is pretty much independent one from another, so
why not group things by functionality instead. All apic related code in
lapic.c.

 Maybe apic_reg_{read,write} need to be exported.
 
This is really internal API. It doesn't even check if apic is created.

   static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
   {
 -  pr_unimpl(vcpu, HYPER-V unimplemented wrmsr: 0x%x data 0x%llx\n,
 -msr, data);
 +  switch (msr) {
 +  case HV_X64_MSR_APIC_ASSIST_PAGE: {
 +  unsigned long vaddr;
 +  void *addr;
 +  struct page *page;
 +  vcpu-arch.hv_vapic = data;
 +  if (!kvm_hv_vapic_enabled(vcpu))
 +  break;
 +  vaddr = gfn_to_hva(vcpu-kvm, data
 +HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT);
 +  if (kvm_is_error_hva(vaddr))
 +  return 1;
 +  page = virt_to_page(vaddr);
 virt_to_page() takes a kernel address, not a user address.  This is
 get_user_pages().  But I think the whole thing is done better with
 put_user().
 
 So there is no function to get struct page from user virtual address?
 
 get_user_pages_fast().
 
Doh.

--
Gleb.
--
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: [PATCHv2 2/4] Implement bare minimum of HYPER-V MSRs.

2010-01-17 Thread Gleb Natapov
On Sun, Jan 17, 2010 at 02:49:30PM +0200, Avi Kivity wrote:
 On 01/17/2010 02:44 PM, Gleb Natapov wrote:
 On Sun, Jan 17, 2010 at 02:10:45PM +0200, Avi Kivity wrote:
 On 01/17/2010 11:03 AM, Gleb Natapov wrote:
 Minimum HYPER-V implementation should have GUEST_OS_ID, HYPERCALL and
 VP_INDEX MSRs.
 
 
   TRACE_EVENT(kvm_pio,
 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
 index 4d835b6..db0b2b1 100644
 --- a/arch/x86/kvm/x86.c
 +++ b/arch/x86/kvm/x86.c
 @@ -630,7 +630,8 @@ static u32 msrs_to_save[] = {
   #ifdef CONFIG_X86_64
MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
   #endif
 -  MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA
 +  MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
 +  HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
   };
 These will be disabled since the msrs don't exist on the host.  See
 the comment above and KVM_SAVE_MSRS_BEGIN.
 
 I see. Why not have two arrays?
 
 Clearly better.
 
 +  case HV_X64_MSR_HYPERCALL: {
 +  u64 gfn;
 +  unsigned long addr;
 +  /* if guest os id is not set hypercall should remain disabled */
 +  if (!kvm-arch.hv_guest_os_id   data)
 +  break;
 +  kvm-arch.hv_hypercall = data;
 +  if (!kvm_hv_hypercall_enabled(kvm))
 +  break;
 +  gfn = kvm-arch.hv_hypercall
 +  HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
 +  addr = gfn_to_hva(kvm, gfn);
 +  if (kvm_is_error_hva(addr))
 +  return 1;
 Should di the error check before assigning, perhaps.
 
 Spec doesn't tell. And guest will get #GP and BSOD anyway.
 
 Well, all msrs I know of either #GP, or store the value and do what
 they're supposed to do, never both.
 
 
Make sense. Will fix.

--
Gleb.
--
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: New kvm-related qemu patch queue

2010-01-17 Thread Avi Kivity

On 01/11/2010 05:30 PM, Anthony Liguori wrote:

On 01/10/2010 06:02 AM, Avi Kivity wrote:
In order to improve qemu.git kvm integration quality wrt performance, 
features, and reliability Marcelo and I will begin to maintain a 
patch queue based on qemu.git containing kvm-related patches.  We 
will review and apply patches to this queue, test them using the same 
test suite that is used for qemu-kvm.git, and regularly submit them 
for inclusion in qemu.git, mimicking the relationship between kvm.git 
and Linus' linux-2.6.git.


Thanks for setting this up Avi!

I just want to stress that everyone continue CC'ing qemu-devel on all 
KVM patches.  Even if the patch is qemu-kvm specific for the moment, I 
think it's important for qemu-devel to be exposed to the refactoring 
work.


It might be good to prefix qemu-kvm.git patches in some manner to make 
it clear which repository they belong to.


[patch kvm] - qemu-kvm.git uq/master
[patch qemu-kvm] - qemu-kvm.git master
[patch kvm stable-0.12] - qemu-kvm uq/stable-0.12

etc.

--
error compiling committee.c: too many arguments to function

--
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: [PATCHv2 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Avi Kivity

On 01/17/2010 02:50 PM, Gleb Natapov wrote:

I prefer putting this in x86.c (maybe later split into hyperv.c).

 

This implements part of apic behaviour. It uses internal lapic functions
like apic_reg_read()/apic_reg_write(). Why move it from lapic.c?
   

The new functions implement hyper-v behaviour.  Why scatter them all around?

 

Each hyper-v extension is pretty much independent one from another, so
why not group things by functionality instead. All apic related code in
lapic.c.

   

Maybe apic_reg_{read,write} need to be exported.

 

This is really internal API. It doesn't even check if apic is created.
   


Okay.  We can rethink it later when the code grows some more.


--
error compiling committee.c: too many arguments to function

--
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: KVM: properly check max PIC pin in irq route setup

2010-01-17 Thread Avi Kivity

On 01/12/2010 08:42 PM, Marcelo Tosatti wrote:

Otherwise memory beyond irq_states[16] might be accessed.

Noticed by Juan Quintela.

   


Applied and queued; thanks.

--
error compiling committee.c: too many arguments to function

--
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] KVM: PPC: E500 compile fix

2010-01-17 Thread Avi Kivity

On 01/10/2010 07:01 PM, Alexander Graf wrote:

While trying to compile an E500 vmlinux, I stumbled across a compilation bug
that was obviously there before I touched any of the code. A trace point
doesn't get the correct arguments.

Since that shouldn't be any critical to the functionality of the code, my quick
workaround is to #if 0 it out. I would very much appreciate someone fixing it
properly though.

Liu, it would be nice if you could be the one doing that.
   


Applied, thanks.

--
error compiling committee.c: too many arguments to function

--
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


[PATCHv3 0/4] Add support for some HYPER-V PV features

2010-01-17 Thread Gleb Natapov
HYPER-V provides PV capabilities for its guests and most new MS Windows
detect and use them automatically. Older Windows guests need additional
drivers to uses PV. This patch series implements some PV capabilities
defined by HYPER-V spec for KVM. Windows guests running on KVM will be
able to take advantage of them.

Changelog:
 v1-v2
  rename kvm_hyperv.h into hyperv.h and move into separate patch
  minor style fixes
  use clear_user-page(0 to zero userspace page
  use APIC register names when calling kvm_hv_vapic_msr_(read|write)()
 v2-v3
  fix msrs_to_save[] handling
  fix access to guests memory
  use kvm_read_cr0_bits() instead of direct access to cr0
 
Gleb Natapov (4):
  Add HYPE-V header file.
  Implement bare minimum of HYPER-V MSRs.
  Add HYPER-V apic access MSRs.
  Implement NotifyLongSpinWait HYPER-V hypercall.

 arch/x86/include/asm/hyperv.h   |  187 +++
 arch/x86/include/asm/kvm_host.h |6 +
 arch/x86/include/asm/kvm_para.h |1 +
 arch/x86/kvm/lapic.c|   31 +
 arch/x86/kvm/lapic.h|8 ++
 arch/x86/kvm/trace.h|   32 ++
 arch/x86/kvm/x86.c  |  232 ++-
 include/linux/kvm.h |3 +
 8 files changed, 499 insertions(+), 1 deletions(-)
 create mode 100644 arch/x86/include/asm/hyperv.h

--
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


[PATCHv3 4/4] Implement NotifyLongSpinWait HYPER-V hypercall.

2010-01-17 Thread Gleb Natapov
Windows issues this hypercall after guest was spinning on a spinlock
for too many iterations.

Signed-off-by: Gleb Natapov g...@redhat.com
Signed-off-by: Vadim Rozenfeld vroze...@redhat.com
---
 arch/x86/kvm/x86.c  |   10 +-
 include/linux/kvm.h |1 +
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 99d1d6c..642f2d7 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1565,6 +1565,7 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_VCPU_EVENTS:
case KVM_CAP_HYPERV:
case KVM_CAP_HYPERV_VAPIC:
+   case KVM_CAP_HYPERV_SPIN:
r = 1;
break;
case KVM_CAP_COALESCED_MMIO:
@@ -3825,7 +3826,14 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 
trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa);
 
-   res = HV_STATUS_INVALID_HYPERCALL_CODE;
+   switch (code) {
+   case HV_X64_HV_NOTIFY_LONG_SPIN_WAIT:
+   kvm_vcpu_on_spin(vcpu);
+   break;
+   default:
+   res = HV_STATUS_INVALID_HYPERCALL_CODE;
+   break;
+   }
 
ret = res | (((u64)rep_done  0xfff)  32);
if (longmode) {
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 5ce6173..4c4937e 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -499,6 +499,7 @@ struct kvm_ioeventfd {
 #define KVM_CAP_PPC_SEGSTATE 43
 #define KVM_CAP_HYPERV 44
 #define KVM_CAP_HYPERV_VAPIC 45
+#define KVM_CAP_HYPERV_SPIN 46
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
-- 
1.6.5

--
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


[PATCHv3 1/4] Add HYPER-V header file.

2010-01-17 Thread Gleb Natapov
Provide HYPER-V related defines that will be uses by following patches.

Signed-off-by: Gleb Natapov g...@redhat.com
Signed-off-by: Vadim Rozenfeld vroze...@redhat.com
---
 arch/x86/include/asm/hyperv.h |  187 +
 1 files changed, 187 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/include/asm/hyperv.h

diff --git a/arch/x86/include/asm/hyperv.h b/arch/x86/include/asm/hyperv.h
new file mode 100644
index 000..91211f3
--- /dev/null
+++ b/arch/x86/include/asm/hyperv.h
@@ -0,0 +1,187 @@
+#ifndef _ASM_X86_KVM_HYPERV_H
+#define _ASM_X86_KVM_HYPERV_H
+
+#include linux/types.h
+
+/*
+ * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
+ * is set by CPUID(HvCpuIdFunctionVersionAndFeatures).
+ */
+#define HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS  0x4000
+#define HYPERV_CPUID_INTERFACE 0x4001
+#define HYPERV_CPUID_VERSION   0x4002
+#define HYPERV_CPUID_FEATURES  0x4003
+#define HYPERV_CPUID_ENLIGHTMENT_INFO  0x4004
+#define HYPERV_CPUID_IMPLEMENT_LIMITS  0x4005
+
+/*
+ * Feature identification. EAX indicates which features are available
+ * to the partition based upon the current partition privileges.
+ */
+
+/* VP Runtime (HV_X64_MSR_VP_RUNTIME) available */
+#define HV_X64_MSR_VP_RUNTIME_AVAILABLE(1  0)
+/* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/
+#define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE(1  1)
+/*
+ * Basic SynIC MSRs (HV_X64_MSR_SCONTROL through HV_X64_MSR_EOM
+ * and HV_X64_MSR_SINT0 through HV_X64_MSR_SINT15) available
+ */
+#define HV_X64_MSR_SYNIC_AVAILABLE (1  2)
+/*
+ * Synthetic Timer MSRs (HV_X64_MSR_STIMER0_CONFIG through
+ * HV_X64_MSR_STIMER3_COUNT) available
+ */
+#define HV_X64_MSR_SYNTIMER_AVAILABLE  (1  3)
+/*
+ * APIC access MSRs (HV_X64_MSR_EOI, HV_X64_MSR_ICR and HV_X64_MSR_TPR)
+ * are available
+ */
+#define HV_X64_MSR_APIC_ACCESS_AVAILABLE   (1  4)
+/* Hypercall MSRs (HV_X64_MSR_GUEST_OS_ID and HV_X64_MSR_HYPERCALL) available*/
+#define HV_X64_MSR_HYPERCALL_AVAILABLE (1  5)
+/* Access virtual processor index MSR (HV_X64_MSR_VP_INDEX) available*/
+#define HV_X64_MSR_VP_INDEX_AVAILABLE  (1  6)
+/* Virtual system reset MSR (HV_X64_MSR_RESET) is available*/
+#define HV_X64_MSR_RESET_AVAILABLE (1  7)
+ /*
+  * Access statistics pages MSRs (HV_X64_MSR_STATS_PARTITION_RETAIL_PAGE,
+  * HV_X64_MSR_STATS_PARTITION_INTERNAL_PAGE, HV_X64_MSR_STATS_VP_RETAIL_PAGE,
+  * HV_X64_MSR_STATS_VP_INTERNAL_PAGE) available
+  */
+#define HV_X64_MSR_STAT_PAGES_AVAILABLE(1  8)
+
+/*
+ * Feature identification: EBX indicates which flags were specified at
+ * partition creation. The format is the same as the partition creation
+ * flag structure defined in section Partition Creation Flags.
+ */
+#define HV_X64_CREATE_PARTITIONS   (1  0)
+#define HV_X64_ACCESS_PARTITION_ID (1  1)
+#define HV_X64_ACCESS_MEMORY_POOL  (1  2)
+#define HV_X64_ADJUST_MESSAGE_BUFFERS  (1  3)
+#define HV_X64_POST_MESSAGES   (1  4)
+#define HV_X64_SIGNAL_EVENTS   (1  5)
+#define HV_X64_CREATE_PORT (1  6)
+#define HV_X64_CONNECT_PORT(1  7)
+#define HV_X64_ACCESS_STATS(1  8)
+#define HV_X64_DEBUGGING   (1  11)
+#define HV_X64_CPU_POWER_MANAGEMENT(1  12)
+#define HV_X64_CONFIGURE_PROFILER  (1  13)
+
+/*
+ * Feature identification. EDX indicates which miscellaneous features
+ * are available to the partition.
+ */
+/* The MWAIT instruction is available (per section MONITOR / MWAIT) */
+#define HV_X64_MWAIT_AVAILABLE (1  0)
+/* Guest debugging support is available */
+#define HV_X64_GUEST_DEBUGGING_AVAILABLE   (1  1)
+/* Performance Monitor support is available*/
+#define HV_X64_PERF_MONITOR_AVAILABLE  (1  2)
+/* Support for physical CPU dynamic partitioning events is available*/
+#define HV_X64_CPU_DYNAMIC_PARTITIONING_AVAILABLE  (1  3)
+/*
+ * Support for passing hypercall input parameter block via XMM
+ * registers is available
+ */
+#define HV_X64_HYPERCALL_PARAMS_XMM_AVAILABLE  (1  4)
+/* Support for a virtual guest idle state is available */
+#define HV_X64_GUEST_IDLE_STATE_AVAILABLE  (1  5)
+
+/*
+ * Implementation recommendations. Indicates which behaviors the hypervisor
+ * recommends the OS implement for optimal performance.
+ */
+ /*
+  * Recommend using hypercall for address space switches rather
+  * than MOV to CR3 instruction
+  */
+#define HV_X64_MWAIT_RECOMMENDED   (1  0)
+/* Recommend using hypercall for local TLB flushes rather
+ * than INVLPG or MOV to CR3 instructions */
+#define HV_X64_LOCAL_TLB_FLUSH_RECOMMENDED (1  1)
+/*
+ * Recommend using hypercall for remote TLB flushes rather

[PATCHv3 2/4] Implement bare minimum of HYPER-V MSRs.

2010-01-17 Thread Gleb Natapov
Minimum HYPER-V implementation should have GUEST_OS_ID, HYPERCALL and
VP_INDEX MSRs.

Signed-off-by: Gleb Natapov g...@redhat.com
Signed-off-by: Vadim Rozenfeld vroze...@redhat.com
---
 arch/x86/include/asm/kvm_host.h |4 +
 arch/x86/include/asm/kvm_para.h |1 +
 arch/x86/kvm/trace.h|   32 +++
 arch/x86/kvm/x86.c  |  190 ++-
 include/linux/kvm.h |1 +
 5 files changed, 227 insertions(+), 1 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 93bee7a..67d19e4 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -413,6 +413,10 @@ struct kvm_arch {
s64 kvmclock_offset;
 
struct kvm_xen_hvm_config xen_hvm_config;
+
+   /* fields used by HYPER-V emulation */
+   u64 hv_guest_os_id;
+   u64 hv_hypercall;
 };
 
 struct kvm_vm_stat {
diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
index c584076..ffae142 100644
--- a/arch/x86/include/asm/kvm_para.h
+++ b/arch/x86/include/asm/kvm_para.h
@@ -2,6 +2,7 @@
 #define _ASM_X86_KVM_PARA_H
 
 #include linux/types.h
+#include asm/hyperv.h
 
 /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx.  It
  * should be used to determine that a VM is running under KVM.
diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
index 816e044..1cb3d0e 100644
--- a/arch/x86/kvm/trace.h
+++ b/arch/x86/kvm/trace.h
@@ -56,6 +56,38 @@ TRACE_EVENT(kvm_hypercall,
 );
 
 /*
+ * Tracepoint for hypercall.
+ */
+TRACE_EVENT(kvm_hv_hypercall,
+   TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx,
+__u64 ingpa, __u64 outgpa),
+   TP_ARGS(code, fast, rep_cnt, rep_idx, ingpa, outgpa),
+
+   TP_STRUCT__entry(
+   __field(__u16,  code)
+   __field(bool,   fast)
+   __field(__u16,  rep_cnt )
+   __field(__u16,  rep_idx )
+   __field(__u64,  ingpa   )
+   __field(__u64,  outgpa  )
+   ),
+
+   TP_fast_assign(
+   __entry-code   = code;
+   __entry-fast   = fast;
+   __entry-rep_cnt= rep_cnt;
+   __entry-rep_idx= rep_idx;
+   __entry-ingpa  = ingpa;
+   __entry-outgpa = outgpa;
+   ),
+
+   TP_printk(code 0x%x %s cnt 0x%x idx 0x%x in 0x%llx out 0x%llx,
+ __entry-code, __entry-fast ? fast : slow,
+ __entry-rep_cnt, __entry-rep_idx,  __entry-ingpa,
+ __entry-outgpa)
+);
+
+/*
  * Tracepoint for PIO.
  */
 TRACE_EVENT(kvm_pio,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 4d835b6..7d19ee5 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -622,9 +622,10 @@ static inline u32 bit(int bitno)
  * kvm-specific. Those are put in the beginning of the list.
  */
 
-#define KVM_SAVE_MSRS_BEGIN2
+#define KVM_SAVE_MSRS_BEGIN4
 static u32 msrs_to_save[] = {
MSR_KVM_SYSTEM_TIME, MSR_KVM_WALL_CLOCK,
+   HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP,
MSR_K6_STAR,
 #ifdef CONFIG_X86_64
@@ -1005,6 +1006,74 @@ out:
return r;
 }
 
+static bool kvm_hv_hypercall_enabled(struct kvm *kvm)
+{
+   return kvm-arch.hv_hypercall  HV_X64_MSR_HYPERCALL_ENABLE;
+}
+
+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:
+   r = true;
+   break;
+   }
+
+   return r;
+}
+
+static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+{
+   struct kvm *kvm = vcpu-kvm;
+
+   switch (msr) {
+   case HV_X64_MSR_GUEST_OS_ID:
+   kvm-arch.hv_guest_os_id = data;
+   /* setting guest os id to zero disables hypercall page */
+   if (!kvm-arch.hv_guest_os_id)
+   kvm-arch.hv_hypercall = ~HV_X64_MSR_HYPERCALL_ENABLE;
+   break;
+   case HV_X64_MSR_HYPERCALL: {
+   u64 gfn;
+   unsigned long addr;
+   u8 instructions[4];
+
+   /* if guest os id is not set hypercall should remain disabled */
+   if (!kvm-arch.hv_guest_os_id)
+   break;
+   if (!(data  HV_X64_MSR_HYPERCALL_ENABLE)) {
+   kvm-arch.hv_hypercall = data;
+   break;
+   }
+   gfn = data  HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
+   addr = gfn_to_hva(kvm, gfn);
+   if (kvm_is_error_hva(addr))
+   return 1;
+   

[PATCHv3 3/4] Add HYPER-V apic access MSRs.

2010-01-17 Thread Gleb Natapov
Implement HYPER-V apic MSRs. Spec defines three MSRs that speed-up
access to EOI/TPR/ICR apic registers for PV guests.

Signed-off-by: Gleb Natapov g...@redhat.com
Signed-off-by: Vadim Rozenfeld vroze...@redhat.com
---
 arch/x86/include/asm/kvm_host.h |2 +
 arch/x86/kvm/lapic.c|   31 
 arch/x86/kvm/lapic.h|8 +++
 arch/x86/kvm/x86.c  |   42 +++---
 include/linux/kvm.h |1 +
 5 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 67d19e4..a1f0b5d 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -363,6 +363,8 @@ struct kvm_vcpu_arch {
/* used for guest single stepping over the given code position */
u16 singlestep_cs;
unsigned long singlestep_rip;
+   /* fields used by HYPER-V emulation */
+   u64 hv_vapic;
 };
 
 struct kvm_mem_alias {
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index ba8c045..4b224f9 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1246,3 +1246,34 @@ int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, 
u64 *data)
 
return 0;
 }
+
+int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 reg, u64 data)
+{
+   struct kvm_lapic *apic = vcpu-arch.apic;
+
+   if (!irqchip_in_kernel(vcpu-kvm))
+   return 1;
+
+   /* if this is ICR write vector before command */
+   if (reg == APIC_ICR)
+   apic_reg_write(apic, APIC_ICR2, (u32)(data  32));
+   return apic_reg_write(apic, reg, (u32)data);
+}
+
+int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 reg, u64 *data)
+{
+   struct kvm_lapic *apic = vcpu-arch.apic;
+   u32 low, high = 0;
+
+   if (!irqchip_in_kernel(vcpu-kvm))
+   return 1;
+
+   if (apic_reg_read(apic, reg, 4, low))
+   return 1;
+   if (reg == APIC_ICR)
+   apic_reg_read(apic, APIC_ICR2, 4, high);
+
+   *data = (((u64)high)  32) | low;
+
+   return 0;
+}
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index 40010b0..f5fe32c 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -48,4 +48,12 @@ void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);
 
 int kvm_x2apic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data);
 int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
+
+int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data);
+int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
+
+static inline bool kvm_hv_vapic_assist_page_enabled(struct kvm_vcpu *vcpu)
+{
+   return vcpu-arch.hv_vapic  HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE;
+}
 #endif
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 7d19ee5..99d1d6c 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -622,10 +622,11 @@ static inline u32 bit(int bitno)
  * kvm-specific. Those are put in the beginning of the list.
  */
 
-#define KVM_SAVE_MSRS_BEGIN4
+#define KVM_SAVE_MSRS_BEGIN5
 static u32 msrs_to_save[] = {
MSR_KVM_SYSTEM_TIME, MSR_KVM_WALL_CLOCK,
HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
+   HV_X64_MSR_APIC_ASSIST_PAGE,
MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP,
MSR_K6_STAR,
 #ifdef CONFIG_X86_64
@@ -1068,10 +1069,36 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 
msr, u64 data)
 
 static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 {
-   pr_unimpl(vcpu, HYPER-V unimplemented wrmsr: 0x%x data 0x%llx\n,
- msr, data);
+   switch (msr) {
+   case HV_X64_MSR_APIC_ASSIST_PAGE: {
+   unsigned long addr;
 
-   return 1;
+   if (!(data  HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE)) {
+   vcpu-arch.hv_vapic = data;
+   break;
+   }
+   addr = gfn_to_hva(vcpu-kvm, data 
+ HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT);
+   if (kvm_is_error_hva(addr))
+   return 1;
+   if (clear_user((void __user *)addr, PAGE_SIZE))
+   return 1;
+   vcpu-arch.hv_vapic = data;
+   break;
+   }
+   case HV_X64_MSR_EOI:
+   return kvm_hv_vapic_msr_write(vcpu, APIC_EOI, data);
+   case HV_X64_MSR_ICR:
+   return kvm_hv_vapic_msr_write(vcpu, APIC_ICR, data);
+   case HV_X64_MSR_TPR:
+   return kvm_hv_vapic_msr_write(vcpu, APIC_TASKPRI, data);
+   default:
+   pr_unimpl(vcpu, HYPER-V unimplemented wrmsr: 0x%x 
+ data 0x%llx\n, msr, data);
+   return 1;
+   }
+
+   return 0;
 }
 
 int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
@@ -1331,6 +1358,12 @@ static int get_msr_hyperv(struct kvm_vcpu *vcpu, u32 
msr, u64 *pdata)
  

Re: [PATCHv3 0/4] Add support for some HYPER-V PV features

2010-01-17 Thread Avi Kivity

On 01/17/2010 03:51 PM, Gleb Natapov wrote:

HYPER-V provides PV capabilities for its guests and most new MS Windows
detect and use them automatically. Older Windows guests need additional
drivers to uses PV. This patch series implements some PV capabilities
defined by HYPER-V spec for KVM. Windows guests running on KVM will be
able to take advantage of them.
   


Applied, thanks.

--
error compiling committee.c: too many arguments to function

--
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 v3 04/12] Add handle page fault PV helper.

2010-01-17 Thread Gleb Natapov
On Thu, Jan 14, 2010 at 06:31:07PM +0100, Peter Zijlstra wrote:
 On Tue, 2010-01-05 at 16:12 +0200, Gleb Natapov wrote:
  Allow paravirtualized guest to do special handling for some page faults.
  
  The patch adds one 'if' to do_page_fault() function. The call is patched
  out when running on physical HW. I ran kernbech on the kernel with and
  without that additional 'if' and result were rawly the same:
 
 So why not program a different handler address for the #PF/#GP faults
 and avoid the if all together?
I would gladly use fault vector reserved by x86 architecture, but I am
not sure Intel will be happy about it.

--
Gleb.
--
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] KVM test: Unattended install logging improvements

2010-01-17 Thread Lucas Meneghel Rodrigues
Log useful information during unattended install
execution, such as timeout set and total time
elapsed during test.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/tests/unattended_install.py |   14 ++
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/client/tests/kvm/tests/unattended_install.py 
b/client/tests/kvm/tests/unattended_install.py
index d33d4f1..18561f6 100644
--- a/client/tests/kvm/tests/unattended_install.py
+++ b/client/tests/kvm/tests/unattended_install.py
@@ -15,15 +15,18 @@ def run_unattended_install(test, params, env):
 
 vm = kvm_test_utils.get_living_vm(env, params.get(main_vm))
 
-logging.info(Starting unattended install watch process)
 server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 server.bind(('', 12323))
 server.listen(1)
 
-end_time = time.time() + float(params.get(timeout, 3000))
+install_timeout = params.get(timeout, 3000)
+logging.info(Starting unattended install watch process. 
+ Timeout set to %ss (%s min), install_timeout,
+ install_timeout/60)
+start_time = time.time()
 
 while True:
-server.settimeout(end_time - time.time())
+server.settimeout(float(install_timeout))
 try:
 (client, addr) = server.accept()
 except socket.timeout:
@@ -33,7 +36,10 @@ def run_unattended_install(test, params, env):
 msg = client.recv(1024)
 logging.debug(Received '%s' from %s, msg, addr)
 if msg == 'done':
-logging.info('Guest reported successful installation')
+end_time = time.time()
+time_elapsed = int(end_time - start_time)
+logging.info('Guest reported successful installation after %ss '
+ '(%s min)', time_elapsed, time_elapsed/60)
 server.close()
 break
 else:
-- 
1.6.5.2

--
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 v3 04/12] Add handle page fault PV helper.

2010-01-17 Thread Peter Zijlstra
On Sun, 2010-01-17 at 16:44 +0200, Gleb Natapov wrote:
 On Thu, Jan 14, 2010 at 06:31:07PM +0100, Peter Zijlstra wrote:
  On Tue, 2010-01-05 at 16:12 +0200, Gleb Natapov wrote:
   Allow paravirtualized guest to do special handling for some page faults.
   
   The patch adds one 'if' to do_page_fault() function. The call is patched
   out when running on physical HW. I ran kernbech on the kernel with and
   without that additional 'if' and result were rawly the same:
  
  So why not program a different handler address for the #PF/#GP faults
  and avoid the if all together?
 I would gladly use fault vector reserved by x86 architecture, but I am
 not sure Intel will be happy about it.

Whatever are we doing to end up in do_page_fault() as it stands? Surely
we can tell the CPU to go elsewhere to handle faults?

Isn't that as simple as calling set_intr_gate(14, my_page_fault)
somewhere on the cpuinit instead of the regular page_fault handler?
--
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 v3 04/12] Add handle page fault PV helper.

2010-01-17 Thread Gleb Natapov
On Sun, Jan 17, 2010 at 04:09:40PM +0100, Peter Zijlstra wrote:
 On Sun, 2010-01-17 at 16:44 +0200, Gleb Natapov wrote:
  On Thu, Jan 14, 2010 at 06:31:07PM +0100, Peter Zijlstra wrote:
   On Tue, 2010-01-05 at 16:12 +0200, Gleb Natapov wrote:
Allow paravirtualized guest to do special handling for some page faults.

The patch adds one 'if' to do_page_fault() function. The call is patched
out when running on physical HW. I ran kernbech on the kernel with and
without that additional 'if' and result were rawly the same:
   
   So why not program a different handler address for the #PF/#GP faults
   and avoid the if all together?
  I would gladly use fault vector reserved by x86 architecture, but I am
  not sure Intel will be happy about it.
 
 Whatever are we doing to end up in do_page_fault() as it stands? Surely
 we can tell the CPU to go elsewhere to handle faults?
 
 Isn't that as simple as calling set_intr_gate(14, my_page_fault)
 somewhere on the cpuinit instead of the regular page_fault handler?
 
Hmm, good idea. I'll look into that. Thanks.

--
Gleb.
--
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] KVM test: Enable qemu upstream testing

2010-01-17 Thread Lucas Meneghel Rodrigues
qemu upstream has slight differences regarding qemu-kvm
on the set of flags it supports. One of the most important
differences is that on qemu we have to set -enable-kvm
explicitely. Take this into consideration on the base
configuration files and enable people to test qemu upstream
more easily.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/tests.cfg.sample  |   10 ++
 client/tests/kvm/tests_base.cfg.sample |6 ++
 2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/client/tests/kvm/tests.cfg.sample 
b/client/tests/kvm/tests.cfg.sample
index 74c94b4..c6a66a4 100644
--- a/client/tests/kvm/tests.cfg.sample
+++ b/client/tests/kvm/tests.cfg.sample
@@ -20,11 +20,17 @@ include cdkeys.cfg
 #cdrom.* ?= /tmp/kvm_autotest_root/
 #steps ?= /tmp/kvm_autotest_root/
 
+# You will notice that in all test definition blocks we have 'only qemu-kvm'
+# set. This means that qemu-kvm command line syntax will be used. If you
+# intend to test qemu upstream, you'll have to change that to 'only qemu'.
 variants:
 - @full:
+only qemu-kvm
 - @sample1:
+only qemu-kvm
 only Fedora Windows
 - @sample2:
+only qemu-kvm
 only qcow2
 only ide
 only default
@@ -32,9 +38,11 @@ variants:
 only Fedora.9.* RHEL.5.* Windows
 only rtl8139
 - @sample3:
+only qemu-kvm
 only qcow2.*ide.*default.*up.*Ubuntu-8.10-server.*(autotest.sleeptest)
 only rtl8139
 - @fc8_step:
+only qemu-kvm
 only qcow2
 only ide
 only default
@@ -44,6 +52,7 @@ variants:
 only rtl8139
 only hugepages
 - @winXP_32_unattended:
+only qemu-kvm
 only qcow2
 only ide
 only default
@@ -54,6 +63,7 @@ variants:
 only unattended_install setup boot shutdown
 only rtl8139
 - @fc11_kickstart:
+only qemu-kvm
 only qcow2
 only ide
 only default
diff --git a/client/tests/kvm/tests_base.cfg.sample 
b/client/tests/kvm/tests_base.cfg.sample
index a63cc52..b1b1539 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -891,6 +891,12 @@ linux_s3:
 
 
 variants:
+- @qemu-kvm:
+- qemu:
+extra_params +=  -enable-kvm
+
+
+variants:
 - @up:
 no autotest.npb
 - smp2:
-- 
1.6.5.2

--
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 v3 06/12] Add get_user_pages() variant that fails if major fault is required.

2010-01-17 Thread Christoph Hellwig
On Tue, Jan 05, 2010 at 04:12:48PM +0200, Gleb Natapov wrote:
 This patch add get_user_pages() variant that only succeeds if getting
 a reference to a page doesn't require major fault.

  
 +int get_user_pages_noio(struct task_struct *tsk, struct mm_struct *mm,
 + unsigned long start, int nr_pages, int write, int force,
 + struct page **pages, struct vm_area_struct **vmas)
 +{
 + int flags = FOLL_TOUCH | FOLL_MINOR;
 +
 + if (pages)
 + flags |= FOLL_GET;
 + if (write)
 + flags |= FOLL_WRITE;
 + if (force)
 + flags |= FOLL_FORCE;
 +
 + return __get_user_pages(tsk, mm, start, nr_pages, flags, pages, vmas);

Wouldn't it be better to just export __get_user_pages as a proper user
interface, maybe replacing get_user_pages by it entirely?

--
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 v3 05/12] Export __get_user_pages_fast.

2010-01-17 Thread Christoph Hellwig
On Tue, Jan 05, 2010 at 04:12:47PM +0200, Gleb Natapov wrote:
 KVM will use it to try and find a page without falling back to slow
 gup. That is why get_user_pages_fast() is not enough.

Btw, it seems like currently is declared unconditionally in linux/mm.h
but only implemented by x86, and you code using it needs ifdefs for
that.  I think you should just introduce a stub that always returns
an error here.

--
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] kvm_stat profiler: Format exception to string

2010-01-17 Thread Lucas Meneghel Rodrigues
There's a small mistake on the kvm_stat profiler:
The contents of the exception message were not
converted to a string before checking if the
problem was due to debugfs not mounted. Let's
fix that.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/profilers/kvm_stat/kvm_stat.py |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/client/profilers/kvm_stat/kvm_stat.py 
b/client/profilers/kvm_stat/kvm_stat.py
index 8180868..7568a03 100644
--- a/client/profilers/kvm_stat/kvm_stat.py
+++ b/client/profilers/kvm_stat/kvm_stat.py
@@ -25,11 +25,11 @@ class kvm_stat(profiler.profiler):
 try:
 utils.system_output(%s --batch % self.stat_path)
 except error.CmdError, e:
-if 'debugfs' in e:
+if 'debugfs' in str(e):
 utils.system('mount -t debugfs debugfs /sys/kernel/debug')
 else:
 raise error.AutotestError('kvm_stat failed due to an '
-  'unknown reason: %s' % e)
+  'unknown reason: %s' % str(e))
 
 
 def start(self, test):
-- 
1.6.5.2

--
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] KVM test: Unattended install logging improvements

2010-01-17 Thread Lucas Meneghel Rodrigues
Log useful information during unattended install
execution, such as timeout set and total time
elapsed during test.

Note: Slightly modified version of the 1st patch sent.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/tests/unattended_install.py |   14 ++
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/client/tests/kvm/tests/unattended_install.py 
b/client/tests/kvm/tests/unattended_install.py
index d33d4f1..e3df72a 100644
--- a/client/tests/kvm/tests/unattended_install.py
+++ b/client/tests/kvm/tests/unattended_install.py
@@ -15,15 +15,18 @@ def run_unattended_install(test, params, env):
 
 vm = kvm_test_utils.get_living_vm(env, params.get(main_vm))
 
-logging.info(Starting unattended install watch process)
 server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 server.bind(('', 12323))
 server.listen(1)
 
-end_time = time.time() + float(params.get(timeout, 3000))
+install_timeout = float(params.get(timeout, 3000))
+logging.info(Starting unattended install watch process. 
+ Timeout set to %ds (%d min), install_timeout,
+ install_timeout/60)
+start_time = time.time()
 
 while True:
-server.settimeout(end_time - time.time())
+server.settimeout(install_timeout)
 try:
 (client, addr) = server.accept()
 except socket.timeout:
@@ -33,7 +36,10 @@ def run_unattended_install(test, params, env):
 msg = client.recv(1024)
 logging.debug(Received '%s' from %s, msg, addr)
 if msg == 'done':
-logging.info('Guest reported successful installation')
+end_time = time.time()
+time_elapsed = int(end_time - start_time)
+logging.info('Guest reported successful installation after %ds '
+ '(%d min)', time_elapsed, time_elapsed/60)
 server.close()
 break
 else:
-- 
1.6.5.2

--
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 1/2] KVM test: Add a new (optional) extra param to VM, cdrom_extra

2010-01-17 Thread Lucas Meneghel Rodrigues
In order to support windows install through unattended method
(we need to setup rss.exe on the hosts), add an additional
(and optional) parameter to tests, cdrom_extra, to make
possible to boot a VM with 2 CDs.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/kvm_vm.py |   10 +-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index ed6d5ad..483204c 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -268,7 +268,15 @@ class VM:
 iso = params.get(cdrom)
 if iso:
 iso = kvm_utils.get_path(root_dir, iso)
-qemu_cmd +=  -cdrom %s % iso
+qemu_cmd +=  -drive file=%s,index=2,media=cdrom % iso
+
+# Even though this is not a really scalable approach,
+# it doesn't seem like we are going to need more than
+# 2 CDs active on the same VM.
+iso_extra = params.get(cdrom_extra)
+if iso_extra:
+iso_extra = kvm_utils.get_path(root_dir, iso_extra)
+qemu_cmd +=  -drive file=%s,index=3,media=cdrom % iso_extra
 
 # We may want to add {floppy_otps} parameter for -fda
 # {fat:floppy:}/path/. However vvfat is not usually recommended
-- 
1.6.5.2

--
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 2/2] Fix windows unattended setup for rss.exe

2010-01-17 Thread Lucas Meneghel Rodrigues
Make unattended install for windows guests
use the extra cd, so it's possible to setup
rss.exe for remote connection.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/tests_base.cfg.sample |1 +
 client/tests/kvm/unattended/win2003-32.sif |   13 +++--
 client/tests/kvm/unattended/win2003-64.sif |3 ++-
 .../kvm/unattended/win2008-32-autounattend.xml |4 
 .../kvm/unattended/win2008-64-autounattend.xml |   10 +++---
 .../kvm/unattended/win2008-r2-autounattend.xml |   10 +++---
 .../tests/kvm/unattended/win7-32-autounattend.xml  |   10 +++---
 .../tests/kvm/unattended/win7-64-autounattend.xml  |   10 +++---
 .../kvm/unattended/winvista-32-autounattend.xml|   16 ++--
 .../kvm/unattended/winvista-64-autounattend.xml|4 ++--
 client/tests/kvm/unattended/winxp32.sif|5 +++--
 11 files changed, 57 insertions(+), 29 deletions(-)

diff --git a/client/tests/kvm/tests_base.cfg.sample 
b/client/tests/kvm/tests_base.cfg.sample
index c42386d..b1b1539 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -602,6 +602,7 @@ variants:
 unattended_install:
 timeout = 7200
 finish_program = deps/finish.exe
+cdrom_extra = windows/winutils.iso
 migrate:
 migration_test_command = ver  vol
 migration_bg_command = start ping -t localhost
diff --git a/client/tests/kvm/unattended/win2003-32.sif 
b/client/tests/kvm/unattended/win2003-32.sif
index 374d4c4..5b9bf0e 100644
--- a/client/tests/kvm/unattended/win2003-32.sif
+++ b/client/tests/kvm/unattended/win2003-32.sif
@@ -14,7 +14,7 @@ WaitForReboot = no
 Repartition = yes
 
 [GuiUnattended]
-AdminPassword = 123456
+AdminPassword = 1q2w3eP
 AutoLogon = Yes
 AutoLogonCount = 5
 OEMSkipRegional = 1
@@ -34,7 +34,7 @@ AutoUsers=15
 [Identification]
DoOldStyleDomainJoin = YES
DomainAdmin=Administrator
-   DomainAdminPassword=123456
+   DomainAdminPassword=1q2w3eP
 JoinWorkgroup=WORKGROUP
JoinDomain=qe.redhat.com
 
@@ -56,7 +56,8 @@ Mode = 0
 local=Local Area Connection
 
 [GuiRunOnce]
-Command0=sc config TlntSvr start= auto
-Command1=netsh firewall set opmode disable
-Command2=net start telnet
-Command3=cmd /c netsh interface ip set address local static 10.0.2.15 
255.255.255.0 10.0.2.2 1  ping 10.0.2.2 -n 20  A:\finish.exe 10.0.2.2
+Command0=cmd /c sc config TlntSvr start= auto
+Command1=cmd /c netsh firewall set opmode disable
+Command2=cmd /c net start telnet
+Command3=cmd /c E:\setuprss.bat
+Command4=cmd /c netsh interface ip set address local static 10.0.2.15 
255.255.255.0 10.0.2.2 1  ping 10.0.2.2 -n 20  A:\finish.exe 10.0.2.2
diff --git a/client/tests/kvm/unattended/win2003-64.sif 
b/client/tests/kvm/unattended/win2003-64.sif
index fe468cb..aca24fe 100644
--- a/client/tests/kvm/unattended/win2003-64.sif
+++ b/client/tests/kvm/unattended/win2003-64.sif
@@ -58,4 +58,5 @@ local=Local Area Connection
 Command0=cmd /c sc config TlntSvr start= auto
 Command1=cmd /c netsh firewall set opmode disable
 Command2=cmd /c net start telnet
-Command3=cmd /c netsh interface ip set address local static 10.0.2.15 
255.255.255.0 10.0.2.2 1  ping 10.0.2.2 -n 20  A:\finish.exe 10.0.2.2
+Command3=cmd /c E:\setuprss.bat
+Command4=cmd /c netsh interface ip set address local static 10.0.2.15 
255.255.255.0 10.0.2.2 1  ping 10.0.2.2 -n 20  A:\finish.exe 10.0.2.2
diff --git a/client/tests/kvm/unattended/win2008-32-autounattend.xml 
b/client/tests/kvm/unattended/win2008-32-autounattend.xml
index b8f3a56..0498e99 100644
--- a/client/tests/kvm/unattended/win2008-32-autounattend.xml
+++ b/client/tests/kvm/unattended/win2008-32-autounattend.xml
@@ -113,6 +113,10 @@
  /SynchronousCommand
  SynchronousCommand wcm:action=add
 Order5/Order
+CommandLine%WINDIR%\System32\cmd /c 
E:\setuprss.bat/CommandLine
+ /SynchronousCommand
+ SynchronousCommand wcm:action=add
+Order6/Order
 CommandLine%WINDIR%\System32\cmd /c netsh interface ip 
set address Local Area Connection static 10.0.2.15 255.255.255.0 10.0.2.2 1 
#38;#38; ping 10.0.2.2 -n 20 #38;#38; A:\finish.exe 10.0.2.2/CommandLine
  /SynchronousCommand
 /FirstLogonCommands
diff --git a/client/tests/kvm/unattended/win2008-64-autounattend.xml 
b/client/tests/kvm/unattended/win2008-64-autounattend.xml
index 345165a..77c4999 100644
--- a/client/tests/kvm/unattended/win2008-64-autounattend.xml
+++ b/client/tests/kvm/unattended/win2008-64-autounattend.xml
@@ -120,14 +120,18 @@
 /SynchronousCommand
 SynchronousCommand wcm:action=add
 Order5/Order
+CommandLine%WINDIR%\System32\cmd /c 
E:\setuprss.bat/CommandLine
+

[PATCH] KVM test: unattended script: Check qemu-img bin path

2010-01-17 Thread Lucas Meneghel Rodrigues
Just to be safe, if the qemu-img path is not an absolute
path, return the path of the symbolic link that is set.

Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/scripts/unattended.py |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/client/tests/kvm/scripts/unattended.py 
b/client/tests/kvm/scripts/unattended.py
index ee20b60..13f431a 100755
--- a/client/tests/kvm/scripts/unattended.py
+++ b/client/tests/kvm/scripts/unattended.py
@@ -54,6 +54,8 @@ class UnattendedInstall(object):
 self.unattended_file = os.environ['KVM_TEST_unattended_file']
 
 self.qemu_img_bin = os.environ['KVM_TEST_qemu_img_binary']
+if not os.path.isabs(self.qemu_img_bin):
+self.qemu_img_bin = os.path.join(kvm_test_dir, self.qemu_img_bin)
 self.cdrom_iso = os.path.join(kvm_test_dir, cdrom_iso)
 self.floppy_mount = tempfile.mkdtemp(prefix='floppy_', dir='/tmp')
 self.cdrom_mount = tempfile.mkdtemp(prefix='cdrom_', dir='/tmp')
-- 
1.6.5.2

--
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] KVM test: Build subtest - Fix load of extra modules from conf file

2010-01-17 Thread Lucas Meneghel Rodrigues
Signed-off-by: Lucas Meneghel Rodrigues l...@redhat.com
---
 client/tests/kvm/tests/build.py |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/client/tests/kvm/tests/build.py b/client/tests/kvm/tests/build.py
index 789373b..f5f67ad 100644
--- a/client/tests/kvm/tests/build.py
+++ b/client/tests/kvm/tests/build.py
@@ -444,7 +444,7 @@ class GitInstaller:
 elif load_modules == 'no':
 self.load_modules = False
 
-self.extra_modules = params.get(extra_modules, None)
+self.extra_modules = eval(params.get(extra_modules, None))
 
 kernel_repo = params.get(git_repo)
 user_repo = params.get(user_git_repo)
-- 
1.6.5.2

--
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: qemu-kvm.git build problem

2010-01-17 Thread Paul E. McKenney
On Fri, Jan 15, 2010 at 09:58:40AM +0100, Jan Kiszka wrote:
 Paul E. McKenney wrote:
  On Thu, Jan 14, 2010 at 01:11:33AM +0100, Jan Kiszka wrote:
  Paul E. McKenney wrote:
  On Tue, Jan 12, 2010 at 09:28:15AM +0100, Jan Kiszka wrote:
  If so, I will try to write something like this the next days. Will
  surely appreciate your review afterwards!
  Sounds good!
 
  Here we go, find the commit inlined below. You may be primarily
  interested in kvm_synchronize_sched_expedited() and the helper thread
  function kvm_rcu_sync_thread. As I use a dedicated thread I simplified
  some parts compared to upstream. Light testing indicates that it works.
  
  Cool!!!
  
  Have you had a chance to run rcutorture on this implementation?
  
 
 No, this would mean backporting rcutorture - is it straightforward
 (limited time...)?

If you aren't backporting too far, the following commit should do it for
you: 804bb8370522a569bd3a732b9de5fbd55e26f155

I do not believe that you should need to run rcutorture on all possible
old versions -- instead, pick some recent ones.  Please let me know if
this does not work out for you.

Thanx, Paul
--
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 0/6] KVM: PPC: FPU/Altivec/VSX bringup

2010-01-17 Thread Avi Kivity

On 01/15/2010 03:49 PM, Alexander Graf wrote:

Right now the code to use external providers (FPU/Altivec/FSX) is rather hacky.

We just set the respective feature bit in the guest MSR when the guest requests
it and declare it as good. Now, Linux wants to mess around there too, so
whenever a process switch occurs, it saves the external provider state and
reloads the current thread ones'.

Unfortunately, we didn't tell Linux about our guest state. So Linux doesn't even
get the chance to swap any of our registers around which means it ends up
restoring registers from random processes - and we lose all state.

This patchset makes at least FPU and Altivec work. I don't have a VSX machine to
test that extension on. While at it, it also fixes some issues I've stumbled
across during debug.

The basic ideas on how this should work come from Benjamin Herrenschmidt.
Thanks a lot for giving input on this one (and all the other times)!
   


Applied all, thanks.

--
error compiling committee.c: too many arguments to function

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


Re: [PATCH] KVM: PPC: E500 compile fix

2010-01-17 Thread Avi Kivity

On 01/10/2010 07:01 PM, Alexander Graf wrote:

While trying to compile an E500 vmlinux, I stumbled across a compilation bug
that was obviously there before I touched any of the code. A trace point
doesn't get the correct arguments.

Since that shouldn't be any critical to the functionality of the code, my quick
workaround is to #if 0 it out. I would very much appreciate someone fixing it
properly though.

Liu, it would be nice if you could be the one doing that.
   


Applied, thanks.

--
error compiling committee.c: too many arguments to function

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