Re: [kvm-devel] [PATCH] kvm/qemu: Fix ia64 build broken.

2007-12-26 Thread Akio Takebe
Hi, Xiantao

diff --git a/qemu/target-ia64/cpu.h b/qemu/target-ia64/cpu.h
index be409c7..2d91cb9 100644
--- a/qemu/target-ia64/cpu.h
+++ b/qemu/target-ia64/cpu.h
@@ -30,11 +30,11 @@
 
 #define TARGET_LONG_BITS 64
 
-
-#define TARGET_PAGE_BITS 14
+#define TARGET_PAGE_BITS 16
 
Do we need to use CONFIG_IA64_PAGE_SIZE_64KB in .config of kernel?
Cannot we use CONFIG_IA64_PAGE_SIZE_16KB?

Best Regards,

Akio Takebe


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] README: How to run kvm guests on IA64

2007-12-26 Thread Akio Takebe
Hi, Xiantao

Akio Takebe wrote:
 Hi,
 
 Run guests with the command :
 /usr/local/bin/qemu-system-ia64 -hda your.img -m 512
 
 If you have any question, please feel free to contact me!
 Can I use the guest image of Xen?
 Or do I need to clean-install Linux or Windows on KVM guest?
Hi, Akio
Thank you for your try!
In addition, If you want to boot windows up on Open GFW, you also need
to pick up the patch I sent to xen-ia64 mailing list, and built it with
latest efi-vfirmware.hg source. 
I attached it in this mail.
Thank you. Your README doesn't explain about GFW.
How do we specify GFW as qemu's option?
Or must we put GFW in somewhere?

Best Regards,

Akio Takebe


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] README: How to run kvm guests on IA64

2007-12-26 Thread Zhang, Xiantao
Akio Takebe wrote:
 Hi, Xiantao
 
 Akio Takebe wrote:
 Hi,
 
 Run guests with the command :
 /usr/local/bin/qemu-system-ia64 -hda your.img -m 512
 
 If you have any question, please feel free to contact me!
 Can I use the guest image of Xen?
 Or do I need to clean-install Linux or Windows on KVM guest?
 Hi, Akio
 Thank you for your try!
 In addition, If you want to boot windows up on Open GFW, you also
 need to pick up the patch I sent to xen-ia64 mailing list, and built
 it with latest efi-vfirmware.hg source.
 I attached it in this mail.
 Thank you. Your README doesn't explain about GFW.
 How do we specify GFW as qemu's option?
 Or must we put GFW in somewhere?

I will update to kvm wiki.  We should put GFW named as Flash.fd to
/usr/local/share/qemu/ :) 

Xiantao


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH] kvm/qemu: Fix ia64 build broken.

2007-12-26 Thread Zhang, Xiantao
Akio Takebe wrote:
 Hi, Xiantao
 
 diff --git a/qemu/target-ia64/cpu.h b/qemu/target-ia64/cpu.h index
 be409c7..2d91cb9 100644 --- a/qemu/target-ia64/cpu.h
 +++ b/qemu/target-ia64/cpu.h
 @@ -30,11 +30,11 @@
 
 #define TARGET_LONG_BITS 64
 
 -
 -#define TARGET_PAGE_BITS 14
 +#define TARGET_PAGE_BITS 16
 
 Do we need to use CONFIG_IA64_PAGE_SIZE_64KB in .config of kernel?
 Cannot we use CONFIG_IA64_PAGE_SIZE_16KB?CONFIG_IA64_PAGE_SIZE_16KB

Since current kvm/ia64 doesn't support build in userspace source,
userspace qemu built can't reference kernel's autoconf.h now. Once
userspace built supported, we can let it use CONFIG_IA64_PAGE_SIZE_16KB
or CONFIG_IA64_PAGE_SIZE_64KB in autoconf.h to define TARGET_PAGE_BITS. 
Now, I added a page size check in ipf_pci_init, and let user know the
mismatch. :)

Xiantao


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 46/55] KVM: Change kvm_{read, write}_guest() to use copy_{from, to}_user()

2007-12-26 Thread Avi Kivity
From: Izik Eidus [EMAIL PROTECTED]

This changes kvm_write_guest_page/kvm_read_guest_page to use
copy_to_user/read_from_user, as a result we get better speed
and better dirty bit tracking.

Signed-off-by: Izik Eidus [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c |   38 ++
 1 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index d318c28..99ad04f 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -630,20 +630,15 @@ static int next_segment(unsigned long len, int offset)
 int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
int len)
 {
-   void *page_virt;
-   struct page *page;
+   int r;
+   unsigned long addr;
 
-   page = gfn_to_page(kvm, gfn);
-   if (is_error_page(page)) {
-   kvm_release_page(page);
+   addr = gfn_to_hva(kvm, gfn);
+   if (kvm_is_error_hva(addr))
+   return -EFAULT;
+   r = copy_from_user(data, (void __user *)addr + offset, len);
+   if (r)
return -EFAULT;
-   }
-   page_virt = kmap_atomic(page, KM_USER0);
-
-   memcpy(data, page_virt + offset, len);
-
-   kunmap_atomic(page_virt, KM_USER0);
-   kvm_release_page(page);
return 0;
 }
 EXPORT_SYMBOL_GPL(kvm_read_guest_page);
@@ -671,21 +666,16 @@ EXPORT_SYMBOL_GPL(kvm_read_guest);
 int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
 int offset, int len)
 {
-   void *page_virt;
-   struct page *page;
+   int r;
+   unsigned long addr;
 
-   page = gfn_to_page(kvm, gfn);
-   if (is_error_page(page)) {
-   kvm_release_page(page);
+   addr = gfn_to_hva(kvm, gfn);
+   if (kvm_is_error_hva(addr))
+   return -EFAULT;
+   r = copy_to_user((void __user *)addr + offset, data, len);
+   if (r)
return -EFAULT;
-   }
-   page_virt = kmap_atomic(page, KM_USER0);
-
-   memcpy(page_virt + offset, data, len);
-
-   kunmap_atomic(page_virt, KM_USER0);
mark_page_dirty(kvm, gfn);
-   kvm_release_page(page);
return 0;
 }
 EXPORT_SYMBOL_GPL(kvm_write_guest_page);
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 35/55] KVM: Portability: Move x86 vcpu ioctl handlers to x86.c

2007-12-26 Thread Avi Kivity
From: Hollis Blanchard [EMAIL PROTECTED]

Signed-off-by: Hollis Blanchard [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |   10 +
 drivers/kvm/kvm_main.c |  442 +---
 drivers/kvm/x86.c  |  427 ++
 3 files changed, 443 insertions(+), 436 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 469ca42..3f5ffc3 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -636,6 +636,16 @@ void kvm_arch_destroy_vm(struct kvm *kvm);
 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
 int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
 
+int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
+int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
+int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
+ struct kvm_sregs *sregs);
+int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
+ struct kvm_sregs *sregs);
+int kvm_arch_vcpu_ioctl_debug_guest(struct kvm_vcpu *vcpu,
+   struct kvm_debug_guest *dbg);
+int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
+
 __init void kvm_arch_init(void);
 
 static inline void kvm_guest_enter(void)
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 4620885..e12bdc1 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -779,422 +779,6 @@ void kvm_resched(struct kvm_vcpu *vcpu)
 EXPORT_SYMBOL_GPL(kvm_resched);
 
 /*
- * Check if userspace requested an interrupt window, and that the
- * interrupt window is open.
- *
- * No need to exit to userspace if we already have an interrupt queued.
- */
-static int dm_request_for_irq_injection(struct kvm_vcpu *vcpu,
- struct kvm_run *kvm_run)
-{
-   return (!vcpu-irq_summary 
-   kvm_run-request_interrupt_window 
-   vcpu-interrupt_window_open 
-   (kvm_x86_ops-get_rflags(vcpu)  X86_EFLAGS_IF));
-}
-
-static void post_kvm_run_save(struct kvm_vcpu *vcpu,
- struct kvm_run *kvm_run)
-{
-   kvm_run-if_flag = (kvm_x86_ops-get_rflags(vcpu)  X86_EFLAGS_IF) != 0;
-   kvm_run-cr8 = get_cr8(vcpu);
-   kvm_run-apic_base = kvm_get_apic_base(vcpu);
-   if (irqchip_in_kernel(vcpu-kvm))
-   kvm_run-ready_for_interrupt_injection = 1;
-   else
-   kvm_run-ready_for_interrupt_injection =
-   (vcpu-interrupt_window_open 
-vcpu-irq_summary == 0);
-}
-
-static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
-{
-   int r;
-
-   if (unlikely(vcpu-mp_state == VCPU_MP_STATE_SIPI_RECEIVED)) {
-   pr_debug(vcpu %d received sipi with vector # %x\n,
-  vcpu-vcpu_id, vcpu-sipi_vector);
-   kvm_lapic_reset(vcpu);
-   r = kvm_x86_ops-vcpu_reset(vcpu);
-   if (r)
-   return r;
-   vcpu-mp_state = VCPU_MP_STATE_RUNNABLE;
-   }
-
-preempted:
-   if (vcpu-guest_debug.enabled)
-   kvm_x86_ops-guest_debug_pre(vcpu);
-
-again:
-   r = kvm_mmu_reload(vcpu);
-   if (unlikely(r))
-   goto out;
-
-   kvm_inject_pending_timer_irqs(vcpu);
-
-   preempt_disable();
-
-   kvm_x86_ops-prepare_guest_switch(vcpu);
-   kvm_load_guest_fpu(vcpu);
-
-   local_irq_disable();
-
-   if (signal_pending(current)) {
-   local_irq_enable();
-   preempt_enable();
-   r = -EINTR;
-   kvm_run-exit_reason = KVM_EXIT_INTR;
-   ++vcpu-stat.signal_exits;
-   goto out;
-   }
-
-   if (irqchip_in_kernel(vcpu-kvm))
-   kvm_x86_ops-inject_pending_irq(vcpu);
-   else if (!vcpu-mmio_read_completed)
-   kvm_x86_ops-inject_pending_vectors(vcpu, kvm_run);
-
-   vcpu-guest_mode = 1;
-   kvm_guest_enter();
-
-   if (vcpu-requests)
-   if (test_and_clear_bit(KVM_REQ_TLB_FLUSH, vcpu-requests))
-   kvm_x86_ops-tlb_flush(vcpu);
-
-   kvm_x86_ops-run(vcpu, kvm_run);
-
-   vcpu-guest_mode = 0;
-   local_irq_enable();
-
-   ++vcpu-stat.exits;
-
-   /*
-* We must have an instruction between local_irq_enable() and
-* kvm_guest_exit(), so the timer interrupt isn't delayed by
-* the interrupt shadow.  The stat.exits increment will do nicely.
-* But we need to prevent reordering, hence this barrier():
-*/
-   barrier();
-
-   kvm_guest_exit();
-
-   preempt_enable();
-
-   /*
-* Profile KVM exit RIPs:
-*/
-   if (unlikely(prof_on == KVM_PROFILING)) {
-   

[kvm-devel] [PATCH 55/55] KVM: Portability: Make kvm_vcpu_ioctl_translate arch dependent

2007-12-26 Thread Avi Kivity
From: Zhang Xiantao [EMAIL PROTECTED]

Move kvm_vcpu_ioctl_translate to arch, since mmu would be put under arch.

Signed-off-by: Zhang Xiantao [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |3 +++
 drivers/kvm/kvm_main.c |   24 +---
 drivers/kvm/x86.c  |   22 ++
 3 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index a7be073..e34e246 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -642,6 +642,9 @@ void kvm_arch_destroy_vm(struct kvm *kvm);
 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
 int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
 
+int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
+   struct kvm_translation *tr);
+
 int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
 int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
 int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 9d63a10..bce4216 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -761,28 +761,6 @@ void kvm_resched(struct kvm_vcpu *vcpu)
 }
 EXPORT_SYMBOL_GPL(kvm_resched);
 
-/*
- * Translate a guest virtual address to a guest physical address.
- */
-static int kvm_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
-   struct kvm_translation *tr)
-{
-   unsigned long vaddr = tr-linear_address;
-   gpa_t gpa;
-
-   vcpu_load(vcpu);
-   mutex_lock(vcpu-kvm-lock);
-   gpa = vcpu-mmu.gva_to_gpa(vcpu, vaddr);
-   tr-physical_address = gpa;
-   tr-valid = gpa != UNMAPPED_GVA;
-   tr-writeable = 1;
-   tr-usermode = 0;
-   mutex_unlock(vcpu-kvm-lock);
-   vcpu_put(vcpu);
-
-   return 0;
-}
-
 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
struct kvm_interrupt *irq)
 {
@@ -986,7 +964,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
r = -EFAULT;
if (copy_from_user(tr, argp, sizeof tr))
goto out;
-   r = kvm_vcpu_ioctl_translate(vcpu, tr);
+   r = kvm_arch_vcpu_ioctl_translate(vcpu, tr);
if (r)
goto out;
r = -EFAULT;
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 6097926..f1746af 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -2318,6 +2318,28 @@ struct fxsave {
 #endif
 };
 
+/*
+ * Translate a guest virtual address to a guest physical address.
+ */
+int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
+   struct kvm_translation *tr)
+{
+   unsigned long vaddr = tr-linear_address;
+   gpa_t gpa;
+
+   vcpu_load(vcpu);
+   mutex_lock(vcpu-kvm-lock);
+   gpa = vcpu-mmu.gva_to_gpa(vcpu, vaddr);
+   tr-physical_address = gpa;
+   tr-valid = gpa != UNMAPPED_GVA;
+   tr-writeable = 1;
+   tr-usermode = 0;
+   mutex_unlock(vcpu-kvm-lock);
+   vcpu_put(vcpu);
+
+   return 0;
+}
+
 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
 {
struct fxsave *fxsave = (struct fxsave *)vcpu-guest_fx_image;
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 20/55] KVM: Portability: move get/set_apic_base to x86.c

2007-12-26 Thread Avi Kivity
From: Carsten Otte [EMAIL PROTECTED]

This patch moves the implementation of get_apic_base and set_apic_base
from kvm_main.c to x86.c

Signed-off-by: Carsten Otte [EMAIL PROTECTED]
Reviewed-by: Christian Borntraeger [EMAIL PROTECTED]
Acked-by: Hollis Blanchard [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c |   19 ---
 drivers/kvm/x86.c  |   19 +++
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 00f9c9e..d6545a7 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -556,25 +556,6 @@ unsigned long get_cr8(struct kvm_vcpu *vcpu)
 }
 EXPORT_SYMBOL_GPL(get_cr8);
 
-u64 kvm_get_apic_base(struct kvm_vcpu *vcpu)
-{
-   if (irqchip_in_kernel(vcpu-kvm))
-   return vcpu-apic_base;
-   else
-   return vcpu-apic_base;
-}
-EXPORT_SYMBOL_GPL(kvm_get_apic_base);
-
-void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data)
-{
-   /* TODO: reserve bits check */
-   if (irqchip_in_kernel(vcpu-kvm))
-   kvm_lapic_set_base(vcpu, data);
-   else
-   vcpu-apic_base = data;
-}
-EXPORT_SYMBOL_GPL(kvm_set_apic_base);
-
 void fx_init(struct kvm_vcpu *vcpu)
 {
unsigned after_mxcsr_mask;
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 5a95922..c26e371 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -59,6 +59,25 @@ unsigned long segment_base(u16 selector)
 }
 EXPORT_SYMBOL_GPL(segment_base);
 
+u64 kvm_get_apic_base(struct kvm_vcpu *vcpu)
+{
+   if (irqchip_in_kernel(vcpu-kvm))
+   return vcpu-apic_base;
+   else
+   return vcpu-apic_base;
+}
+EXPORT_SYMBOL_GPL(kvm_get_apic_base);
+
+void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data)
+{
+   /* TODO: reserve bits check */
+   if (irqchip_in_kernel(vcpu-kvm))
+   kvm_lapic_set_base(vcpu, data);
+   else
+   vcpu-apic_base = data;
+}
+EXPORT_SYMBOL_GPL(kvm_set_apic_base);
+
 /*
  * List of msr numbers which we expose to userspace through KVM_GET_MSRS
  * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 24/55] KVM: Portability: Move kvm_get/set_msr[_common] to x86.c

2007-12-26 Thread Avi Kivity
From: Carsten Otte [EMAIL PROTECTED]

This patch moves the implementation of the functions of kvm_get/set_msr,
kvm_get/set_msr_common, and set_efer from kvm_main.c to x86.c. The
definition of EFER_RESERVED_BITS is moved too.

Signed-off-by: Carsten Otte [EMAIL PROTECTED]
Acked-by: Hollis Blanchard [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c |  133 ---
 drivers/kvm/x86.c  |  134 
 2 files changed, 134 insertions(+), 133 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 7186791..5eccf27 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -90,8 +90,6 @@ static struct kvm_stats_debugfs_item {
 
 static struct dentry *debugfs_dir;
 
-#define EFER_RESERVED_BITS 0xf2fe
-
 static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
   unsigned long arg);
 
@@ -1356,137 +1354,6 @@ void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, 
unsigned long val,
}
 }
 
-int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
-{
-   u64 data;
-
-   switch (msr) {
-   case 0xc0010010: /* SYSCFG */
-   case 0xc0010015: /* HWCR */
-   case MSR_IA32_PLATFORM_ID:
-   case MSR_IA32_P5_MC_ADDR:
-   case MSR_IA32_P5_MC_TYPE:
-   case MSR_IA32_MC0_CTL:
-   case MSR_IA32_MCG_STATUS:
-   case MSR_IA32_MCG_CAP:
-   case MSR_IA32_MC0_MISC:
-   case MSR_IA32_MC0_MISC+4:
-   case MSR_IA32_MC0_MISC+8:
-   case MSR_IA32_MC0_MISC+12:
-   case MSR_IA32_MC0_MISC+16:
-   case MSR_IA32_UCODE_REV:
-   case MSR_IA32_PERF_STATUS:
-   case MSR_IA32_EBL_CR_POWERON:
-   /* MTRR registers */
-   case 0xfe:
-   case 0x200 ... 0x2ff:
-   data = 0;
-   break;
-   case 0xcd: /* fsb frequency */
-   data = 3;
-   break;
-   case MSR_IA32_APICBASE:
-   data = kvm_get_apic_base(vcpu);
-   break;
-   case MSR_IA32_MISC_ENABLE:
-   data = vcpu-ia32_misc_enable_msr;
-   break;
-#ifdef CONFIG_X86_64
-   case MSR_EFER:
-   data = vcpu-shadow_efer;
-   break;
-#endif
-   default:
-   pr_unimpl(vcpu, unhandled rdmsr: 0x%x\n, msr);
-   return 1;
-   }
-   *pdata = data;
-   return 0;
-}
-EXPORT_SYMBOL_GPL(kvm_get_msr_common);
-
-/*
- * Reads an msr value (of 'msr_index') into 'pdata'.
- * Returns 0 on success, non-0 otherwise.
- * Assumes vcpu_load() was already called.
- */
-int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
-{
-   return kvm_x86_ops-get_msr(vcpu, msr_index, pdata);
-}
-
-#ifdef CONFIG_X86_64
-
-static void set_efer(struct kvm_vcpu *vcpu, u64 efer)
-{
-   if (efer  EFER_RESERVED_BITS) {
-   printk(KERN_DEBUG set_efer: 0x%llx #GP, reserved bits\n,
-  efer);
-   inject_gp(vcpu);
-   return;
-   }
-
-   if (is_paging(vcpu)
-(vcpu-shadow_efer  EFER_LME) != (efer  EFER_LME)) {
-   printk(KERN_DEBUG set_efer: #GP, change LME while paging\n);
-   inject_gp(vcpu);
-   return;
-   }
-
-   kvm_x86_ops-set_efer(vcpu, efer);
-
-   efer = ~EFER_LMA;
-   efer |= vcpu-shadow_efer  EFER_LMA;
-
-   vcpu-shadow_efer = efer;
-}
-
-#endif
-
-int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
-{
-   switch (msr) {
-#ifdef CONFIG_X86_64
-   case MSR_EFER:
-   set_efer(vcpu, data);
-   break;
-#endif
-   case MSR_IA32_MC0_STATUS:
-   pr_unimpl(vcpu, %s: MSR_IA32_MC0_STATUS 0x%llx, nop\n,
-  __FUNCTION__, data);
-   break;
-   case MSR_IA32_MCG_STATUS:
-   pr_unimpl(vcpu, %s: MSR_IA32_MCG_STATUS 0x%llx, nop\n,
-   __FUNCTION__, data);
-   break;
-   case MSR_IA32_UCODE_REV:
-   case MSR_IA32_UCODE_WRITE:
-   case 0x200 ... 0x2ff: /* MTRRs */
-   break;
-   case MSR_IA32_APICBASE:
-   kvm_set_apic_base(vcpu, data);
-   break;
-   case MSR_IA32_MISC_ENABLE:
-   vcpu-ia32_misc_enable_msr = data;
-   break;
-   default:
-   pr_unimpl(vcpu, unhandled wrmsr: 0x%x\n, msr);
-   return 1;
-   }
-   return 0;
-}
-EXPORT_SYMBOL_GPL(kvm_set_msr_common);
-
-/*
- * Writes msr value into into the appropriate register.
- * Returns 0 on success, non-0 otherwise.
- * Assumes vcpu_load() was already called.
- */
-int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
-{
-   return kvm_x86_ops-set_msr(vcpu, msr_index, data);
-}
-
 void kvm_resched(struct kvm_vcpu *vcpu)
 {
if (!need_resched())
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 

[kvm-devel] [PATCH 32/55] KVM: Portability: Make exported debugfs data architecture-specific

2007-12-26 Thread Avi Kivity
From: Hollis Blanchard [EMAIL PROTECTED]

Signed-off-by: Hollis Blanchard [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |7 +++
 drivers/kvm/kvm_main.c |   25 -
 drivers/kvm/x86.c  |   22 ++
 3 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 22317d6..d030a82 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -761,4 +761,11 @@ static inline u32 get_rdx_init_val(void)
 #define TSS_REDIRECTION_SIZE (256 / 8)
 #define RMODE_TSS_SIZE (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 
1)
 
+struct kvm_stats_debugfs_item {
+   const char *name;
+   int offset;
+   struct dentry *dentry;
+};
+extern struct kvm_stats_debugfs_item debugfs_entries[];
+
 #endif
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index ad4c84c..11580be 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -63,31 +63,6 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
 
 static __read_mostly struct preempt_ops kvm_preempt_ops;
 
-#define STAT_OFFSET(x) offsetof(struct kvm_vcpu, stat.x)
-
-static struct kvm_stats_debugfs_item {
-   const char *name;
-   int offset;
-   struct dentry *dentry;
-} debugfs_entries[] = {
-   { pf_fixed, STAT_OFFSET(pf_fixed) },
-   { pf_guest, STAT_OFFSET(pf_guest) },
-   { tlb_flush, STAT_OFFSET(tlb_flush) },
-   { invlpg, STAT_OFFSET(invlpg) },
-   { exits, STAT_OFFSET(exits) },
-   { io_exits, STAT_OFFSET(io_exits) },
-   { mmio_exits, STAT_OFFSET(mmio_exits) },
-   { signal_exits, STAT_OFFSET(signal_exits) },
-   { irq_window, STAT_OFFSET(irq_window_exits) },
-   { halt_exits, STAT_OFFSET(halt_exits) },
-   { halt_wakeup, STAT_OFFSET(halt_wakeup) },
-   { request_irq, STAT_OFFSET(request_irq_exits) },
-   { irq_exits, STAT_OFFSET(irq_exits) },
-   { light_exits, STAT_OFFSET(light_exits) },
-   { efer_reload, STAT_OFFSET(efer_reload) },
-   { NULL }
-};
-
 static struct dentry *debugfs_dir;
 
 static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index f75e7d7..c1f10e5 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -40,6 +40,28 @@
 #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)
 #define EFER_RESERVED_BITS 0xf2fe
 
+#define STAT_OFFSET(x) offsetof(struct kvm_vcpu, stat.x)
+
+struct kvm_stats_debugfs_item debugfs_entries[] = {
+   { pf_fixed, STAT_OFFSET(pf_fixed) },
+   { pf_guest, STAT_OFFSET(pf_guest) },
+   { tlb_flush, STAT_OFFSET(tlb_flush) },
+   { invlpg, STAT_OFFSET(invlpg) },
+   { exits, STAT_OFFSET(exits) },
+   { io_exits, STAT_OFFSET(io_exits) },
+   { mmio_exits, STAT_OFFSET(mmio_exits) },
+   { signal_exits, STAT_OFFSET(signal_exits) },
+   { irq_window, STAT_OFFSET(irq_window_exits) },
+   { halt_exits, STAT_OFFSET(halt_exits) },
+   { halt_wakeup, STAT_OFFSET(halt_wakeup) },
+   { request_irq, STAT_OFFSET(request_irq_exits) },
+   { irq_exits, STAT_OFFSET(irq_exits) },
+   { light_exits, STAT_OFFSET(light_exits) },
+   { efer_reload, STAT_OFFSET(efer_reload) },
+   { NULL }
+};
+
+
 unsigned long segment_base(u16 selector)
 {
struct descriptor_table gdt;
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 01/55] KVM: Portability: Split kvm_vcpu into arch dependent and independent parts (part 1)

2007-12-26 Thread Avi Kivity
From: Zhang Xiantao [EMAIL PROTECTED]

First step to split kvm_vcpu.  Currently, we just use an macro to define
the common fields in kvm_vcpu for all archs, and all archs need to define
its own kvm_vcpu struct.

Signed-off-by: Zhang Xiantao [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/ioapic.c  |2 +
 drivers/kvm/irq.c |1 +
 drivers/kvm/kvm.h |  154 -
 drivers/kvm/kvm_main.c|4 +-
 drivers/kvm/lapic.c   |2 +
 drivers/kvm/mmu.c |1 +
 drivers/kvm/svm.c |2 +-
 drivers/kvm/vmx.c |1 +
 drivers/kvm/x86.h |  117 ++
 drivers/kvm/x86_emulate.c |1 +
 10 files changed, 155 insertions(+), 130 deletions(-)

diff --git a/drivers/kvm/ioapic.c b/drivers/kvm/ioapic.c
index 8503d99..e14b7c7 100644
--- a/drivers/kvm/ioapic.c
+++ b/drivers/kvm/ioapic.c
@@ -27,6 +27,8 @@
  */
 
 #include kvm.h
+#include x86.h
+
 #include linux/kvm.h
 #include linux/mm.h
 #include linux/highmem.h
diff --git a/drivers/kvm/irq.c b/drivers/kvm/irq.c
index 7628c7f..59b47c5 100644
--- a/drivers/kvm/irq.c
+++ b/drivers/kvm/irq.c
@@ -22,6 +22,7 @@
 #include linux/module.h
 
 #include kvm.h
+#include x86.h
 #include irq.h
 
 /*
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index eb006ed..db18d27 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -308,93 +308,37 @@ struct kvm_io_device *kvm_io_bus_find_dev(struct 
kvm_io_bus *bus, gpa_t addr);
 void kvm_io_bus_register_dev(struct kvm_io_bus *bus,
 struct kvm_io_device *dev);
 
-struct kvm_vcpu {
-   struct kvm *kvm;
-   struct preempt_notifier preempt_notifier;
-   int vcpu_id;
-   struct mutex mutex;
-   int   cpu;
-   u64 host_tsc;
-   struct kvm_run *run;
-   int interrupt_window_open;
-   int guest_mode;
-   unsigned long requests;
-   unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */
-   DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);
-   unsigned long regs[NR_VCPU_REGS]; /* for rsp: vcpu_load_rsp_rip() */
-   unsigned long rip;  /* needs vcpu_load_rsp_rip() */
-
-   unsigned long cr0;
-   unsigned long cr2;
-   unsigned long cr3;
-   unsigned long cr4;
-   unsigned long cr8;
-   u64 pdptrs[4]; /* pae */
-   u64 shadow_efer;
-   u64 apic_base;
-   struct kvm_lapic *apic;/* kernel irqchip context */
-#define VCPU_MP_STATE_RUNNABLE  0
-#define VCPU_MP_STATE_UNINITIALIZED 1
-#define VCPU_MP_STATE_INIT_RECEIVED 2
-#define VCPU_MP_STATE_SIPI_RECEIVED 3
-#define VCPU_MP_STATE_HALTED4
-   int mp_state;
-   int sipi_vector;
-   u64 ia32_misc_enable_msr;
-
-   struct kvm_mmu mmu;
-
-   struct kvm_mmu_memory_cache mmu_pte_chain_cache;
-   struct kvm_mmu_memory_cache mmu_rmap_desc_cache;
-   struct kvm_mmu_memory_cache mmu_page_cache;
-   struct kvm_mmu_memory_cache mmu_page_header_cache;
-
-   gfn_t last_pt_write_gfn;
-   int   last_pt_write_count;
-   u64  *last_pte_updated;
-
-   struct kvm_guest_debug guest_debug;
-
-   struct i387_fxsave_struct host_fx_image;
-   struct i387_fxsave_struct guest_fx_image;
-   int fpu_active;
-   int guest_fpu_loaded;
-
-   int mmio_needed;
-   int mmio_read_completed;
-   int mmio_is_write;
-   int mmio_size;
-   unsigned char mmio_data[8];
+#ifdef CONFIG_HAS_IOMEM
+#define KVM_VCPU_MMIO  \
+   int mmio_needed;\
+   int mmio_read_completed;\
+   int mmio_is_write;  \
+   int mmio_size;  \
+   unsigned char mmio_data[8]; \
gpa_t mmio_phys_addr;
-   gva_t mmio_fault_cr2;
-   struct kvm_pio_request pio;
-   void *pio_data;
-   wait_queue_head_t wq;
 
-   int sigset_active;
-   sigset_t sigset;
+#else
+#define KVM_VCPU_MMIO
 
-   struct kvm_stat stat;
+#endif
 
-   struct {
-   int active;
-   u8 save_iopl;
-   struct kvm_save_segment {
-   u16 selector;
-   unsigned long base;
-   u32 limit;
-   u32 ar;
-   } tr, es, ds, fs, gs;
-   } rmode;
-   int halt_request; /* real mode on Intel only */
-
-   int cpuid_nent;
-   struct kvm_cpuid_entry cpuid_entries[KVM_MAX_CPUID_ENTRIES];
-
-   /* emulate context */
-
-   struct x86_emulate_ctxt emulate_ctxt;
-};
+#define KVM_VCPU_COMM  \
+   struct kvm *kvm;\
+   struct preempt_notifier preempt_notifier;   \
+   int vcpu_id;\
+   struct mutex mutex; \
+   int   cpu;  \
+   struct kvm_run *run;   

[kvm-devel] [PATCH 04/55] KVM: Export PIC reset for kernel device reset

2007-12-26 Thread Avi Kivity
From: Eddie Dong [EMAIL PROTECTED]

Signed-off-by: Yaozu (Eddie) Dong [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/i8259.c |6 ++
 drivers/kvm/irq.h   |1 +
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/kvm/i8259.c b/drivers/kvm/i8259.c
index a679157..f0dc2ee 100644
--- a/drivers/kvm/i8259.c
+++ b/drivers/kvm/i8259.c
@@ -181,10 +181,8 @@ int kvm_pic_read_irq(struct kvm_pic *s)
return intno;
 }
 
-static void pic_reset(void *opaque)
+void kvm_pic_reset(struct kvm_kpic_state *s)
 {
-   struct kvm_kpic_state *s = opaque;
-
s-last_irr = 0;
s-irr = 0;
s-imr = 0;
@@ -209,7 +207,7 @@ static void pic_ioport_write(void *opaque, u32 addr, u32 
val)
addr = 1;
if (addr == 0) {
if (val  0x10) {
-   pic_reset(s);   /* init */
+   kvm_pic_reset(s);   /* init */
/*
 * deassert a pending interrupt
 */
diff --git a/drivers/kvm/irq.h b/drivers/kvm/irq.h
index 508280e..e08ae10 100644
--- a/drivers/kvm/irq.h
+++ b/drivers/kvm/irq.h
@@ -139,6 +139,7 @@ int kvm_apic_accept_pic_intr(struct kvm_vcpu *vcpu);
 int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu);
 int kvm_create_lapic(struct kvm_vcpu *vcpu);
 void kvm_lapic_reset(struct kvm_vcpu *vcpu);
+void kvm_pic_reset(struct kvm_kpic_state *s);
 void kvm_free_lapic(struct kvm_vcpu *vcpu);
 u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu);
 void kvm_lapic_set_tpr(struct kvm_vcpu *vcpu, unsigned long cr8);
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 02/55] KVM: Move vmx_vcpu_reset() out of vmx_vcpu_setup()

2007-12-26 Thread Avi Kivity
Split guest reset code out of vmx_vcpu_setup().  Besides being cleaner, this
moves the realmode tss setup (which can sleep) outside vmx_vcpu_setup()
(which is executed with preemption enabled).

[izik: remove unused variable]

Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |2 +-
 drivers/kvm/kvm_main.c |8 ++-
 drivers/kvm/svm.c  |4 +-
 drivers/kvm/vmx.c  |  178 
 4 files changed, 99 insertions(+), 93 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index db18d27..f7181a4 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -412,7 +412,7 @@ struct kvm_x86_ops {
/* Create, but do not attach this VCPU */
struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id);
void (*vcpu_free)(struct kvm_vcpu *vcpu);
-   void (*vcpu_reset)(struct kvm_vcpu *vcpu);
+   int (*vcpu_reset)(struct kvm_vcpu *vcpu);
 
void (*prepare_guest_switch)(struct kvm_vcpu *vcpu);
void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 41d4a93..ff77175 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -2122,7 +2122,9 @@ static int __vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
pr_debug(vcpu %d received sipi with vector # %x\n,
   vcpu-vcpu_id, vcpu-sipi_vector);
kvm_lapic_reset(vcpu);
-   kvm_x86_ops-vcpu_reset(vcpu);
+   r = kvm_x86_ops-vcpu_reset(vcpu);
+   if (r)
+   return r;
vcpu-mp_state = VCPU_MP_STATE_RUNNABLE;
}
 
@@ -2637,7 +2639,9 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int 
n)
BUG_ON((unsigned long)vcpu-host_fx_image  0xF);
 
vcpu_load(vcpu);
-   r = kvm_mmu_setup(vcpu);
+   r = kvm_x86_ops-vcpu_reset(vcpu);
+   if (r == 0)
+   r = kvm_mmu_setup(vcpu);
vcpu_put(vcpu);
if (r  0)
goto free_vcpu;
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 09c4b14..4a70168 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -557,7 +557,7 @@ static void init_vmcb(struct vmcb *vmcb)
/* rdx = ?? */
 }
 
-static void svm_vcpu_reset(struct kvm_vcpu *vcpu)
+static int svm_vcpu_reset(struct kvm_vcpu *vcpu)
 {
struct vcpu_svm *svm = to_svm(vcpu);
 
@@ -568,6 +568,8 @@ static void svm_vcpu_reset(struct kvm_vcpu *vcpu)
svm-vmcb-save.cs.base = svm-vcpu.sipi_vector  12;
svm-vmcb-save.cs.selector = svm-vcpu.sipi_vector  8;
}
+
+   return 0;
 }
 
 static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 828d3cb..77083e4 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1433,92 +1433,15 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
unsigned long a;
struct descriptor_table dt;
int i;
-   int ret = 0;
unsigned long kvm_vmx_return;
-   u64 msr;
u32 exec_control;
 
-   if (!init_rmode_tss(vmx-vcpu.kvm)) {
-   ret = -ENOMEM;
-   goto out;
-   }
-
-   vmx-vcpu.rmode.active = 0;
-
-   vmx-vcpu.regs[VCPU_REGS_RDX] = get_rdx_init_val();
-   set_cr8(vmx-vcpu, 0);
-   msr = 0xfee0 | MSR_IA32_APICBASE_ENABLE;
-   if (vmx-vcpu.vcpu_id == 0)
-   msr |= MSR_IA32_APICBASE_BSP;
-   kvm_set_apic_base(vmx-vcpu, msr);
-
-   fx_init(vmx-vcpu);
-
-   /*
-* GUEST_CS_BASE should really be 0x, but VT vm86 mode
-* insists on having GUEST_CS_BASE == GUEST_CS_SELECTOR  4.  Sigh.
-*/
-   if (vmx-vcpu.vcpu_id == 0) {
-   vmcs_write16(GUEST_CS_SELECTOR, 0xf000);
-   vmcs_writel(GUEST_CS_BASE, 0x000f);
-   } else {
-   vmcs_write16(GUEST_CS_SELECTOR, vmx-vcpu.sipi_vector  8);
-   vmcs_writel(GUEST_CS_BASE, vmx-vcpu.sipi_vector  12);
-   }
-   vmcs_write32(GUEST_CS_LIMIT, 0x);
-   vmcs_write32(GUEST_CS_AR_BYTES, 0x9b);
-
-   seg_setup(VCPU_SREG_DS);
-   seg_setup(VCPU_SREG_ES);
-   seg_setup(VCPU_SREG_FS);
-   seg_setup(VCPU_SREG_GS);
-   seg_setup(VCPU_SREG_SS);
-
-   vmcs_write16(GUEST_TR_SELECTOR, 0);
-   vmcs_writel(GUEST_TR_BASE, 0);
-   vmcs_write32(GUEST_TR_LIMIT, 0x);
-   vmcs_write32(GUEST_TR_AR_BYTES, 0x008b);
-
-   vmcs_write16(GUEST_LDTR_SELECTOR, 0);
-   vmcs_writel(GUEST_LDTR_BASE, 0);
-   vmcs_write32(GUEST_LDTR_LIMIT, 0x);
-   vmcs_write32(GUEST_LDTR_AR_BYTES, 0x00082);
-
-   vmcs_write32(GUEST_SYSENTER_CS, 0);
-   vmcs_writel(GUEST_SYSENTER_ESP, 0);
-   vmcs_writel(GUEST_SYSENTER_EIP, 0);
-
-   vmcs_writel(GUEST_RFLAGS, 0x02);
-   if (vmx-vcpu.vcpu_id == 0)
-   vmcs_writel(GUEST_RIP, 0xfff0);
-   else
-   

[kvm-devel] [PATCH 06/55] KVM: Per-architecture hypercall definitions

2007-12-26 Thread Avi Kivity
From: Christian Borntraeger [EMAIL PROTECTED]

Currently kvm provides hypercalls only for x86* architectures. To
provide hypercall infrastructure for other kvm architectures I split
kvm_para.h into a generic header file and architecture specific
definitions.

Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 include/asm-x86/kvm_para.h |  105 
 include/linux/kvm_para.h   |  105 +---
 2 files changed, 117 insertions(+), 93 deletions(-)
 create mode 100644 include/asm-x86/kvm_para.h

diff --git a/include/asm-x86/kvm_para.h b/include/asm-x86/kvm_para.h
new file mode 100644
index 000..c6f3fd8
--- /dev/null
+++ b/include/asm-x86/kvm_para.h
@@ -0,0 +1,105 @@
+#ifndef __X86_KVM_PARA_H
+#define __X86_KVM_PARA_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.
+ */
+#define KVM_CPUID_SIGNATURE0x4000
+
+/* This CPUID returns a feature bitmap in eax.  Before enabling a particular
+ * paravirtualization, the appropriate feature bit should be checked.
+ */
+#define KVM_CPUID_FEATURES 0x4001
+
+#ifdef __KERNEL__
+#include asm/processor.h
+
+/* This instruction is vmcall.  On non-VT architectures, it will generate a
+ * trap that we will then rewrite to the appropriate instruction.
+ */
+#define KVM_HYPERCALL .byte 0x0f,0x01,0xc1
+
+/* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
+ * instruction.  The hypervisor may replace it with something else but only the
+ * instructions are guaranteed to be supported.
+ *
+ * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
+ * The hypercall number should be placed in rax and the return value will be
+ * placed in rax.  No other registers will be clobbered unless explicited
+ * noted by the particular hypercall.
+ */
+
+static inline long kvm_hypercall0(unsigned int nr)
+{
+   long ret;
+   asm volatile(KVM_HYPERCALL
+: =a(ret)
+: a(nr));
+   return ret;
+}
+
+static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
+{
+   long ret;
+   asm volatile(KVM_HYPERCALL
+: =a(ret)
+: a(nr), b(p1));
+   return ret;
+}
+
+static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
+ unsigned long p2)
+{
+   long ret;
+   asm volatile(KVM_HYPERCALL
+: =a(ret)
+: a(nr), b(p1), c(p2));
+   return ret;
+}
+
+static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
+ unsigned long p2, unsigned long p3)
+{
+   long ret;
+   asm volatile(KVM_HYPERCALL
+: =a(ret)
+: a(nr), b(p1), c(p2), d(p3));
+   return ret;
+}
+
+static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
+ unsigned long p2, unsigned long p3,
+ unsigned long p4)
+{
+   long ret;
+   asm volatile(KVM_HYPERCALL
+: =a(ret)
+: a(nr), b(p1), c(p2), d(p3), S(p4));
+   return ret;
+}
+
+static inline int kvm_para_available(void)
+{
+   unsigned int eax, ebx, ecx, edx;
+   char signature[13];
+
+   cpuid(KVM_CPUID_SIGNATURE, eax, ebx, ecx, edx);
+   memcpy(signature + 0, ebx, 4);
+   memcpy(signature + 4, ecx, 4);
+   memcpy(signature + 8, edx, 4);
+   signature[12] = 0;
+
+   if (strcmp(signature, KVMKVMKVM) == 0)
+   return 1;
+
+   return 0;
+}
+
+static inline unsigned int kvm_arch_para_features(void)
+{
+   return cpuid_eax(KVM_CPUID_FEATURES);
+}
+
+#endif
+
+#endif
diff --git a/include/linux/kvm_para.h b/include/linux/kvm_para.h
index cc5dfb4..e4db25f 100644
--- a/include/linux/kvm_para.h
+++ b/include/linux/kvm_para.h
@@ -1,110 +1,29 @@
 #ifndef __LINUX_KVM_PARA_H
 #define __LINUX_KVM_PARA_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.
+/*
+ * This header file provides a method for making a hypercall to the host
+ * Architectures should define:
+ * - kvm_hypercall0, kvm_hypercall1...
+ * - kvm_arch_para_features
+ * - kvm_para_available
  */
-#define KVM_CPUID_SIGNATURE0x4000
-
-/* This CPUID returns a feature bitmap in eax.  Before enabling a particular
- * paravirtualization, the appropriate feature bit should be checked.
- */
-#define KVM_CPUID_FEATURES 0x4001
 
 /* Return values for hypercalls */
 #define KVM_ENOSYS 1000
 
 #ifdef __KERNEL__
-#include asm/processor.h
-
-/* This instruction is vmcall.  On non-VT architectures, it will generate a
- * trap that we will then rewrite to the appropriate instruction.
- */
-#define 

[kvm-devel] [PATCH 00/55] KVM patch queue review for 2.6.25 merge window (part II)

2007-12-26 Thread Avi Kivity
The second 2.6.25 kvm patch series, for your review.  Three more to go.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 14/55] KVM: SVM: Let gcc to choose which registers to save (i386)

2007-12-26 Thread Avi Kivity
From: Laurent Vivier [EMAIL PROTECTED]

This patch lets GCC to determine which registers to save when we
switch to/from a VCPU in the case of AMD i386

* Original code saves following registers:

ebx, ecx, edx, esi, edi, ebp

* Patched code:

  - informs GCC that we modify following registers
using the clobber description:

ebx, ecx, edx, esi, edi

  - rbp is saved (pop/push) because GCC seems to ignore its use in the clobber
description.

Signed-off-by: Laurent Vivier [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/svm.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 1298bde..cdd4fd2 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -1501,8 +1501,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
 #ifdef CONFIG_X86_64
push %%rbp; \n\t
 #else
-   push %%ebx; push %%ecx; push %%edx;
-   push %%esi; push %%edi; push %%ebp;
+   push %%ebp; \n\t
 #endif
 
 #ifdef CONFIG_X86_64
@@ -1573,8 +1572,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
mov %%edi, %c[rdi](%[svm]) \n\t
mov %%ebp, %c[rbp](%[svm]) \n\t
 
-   pop  %%ebp; pop  %%edi; pop  %%esi;
-   pop  %%edx; pop  %%ecx; pop  %%ebx; \n\t
+   pop  %%ebp; \n\t
 #endif
:
: [svm]a(svm),
@@ -1599,6 +1597,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
 #ifdef CONFIG_X86_64
, rbx, rcx, rdx, rsi, rdi
, r8, r9, r10, r11 , r12, r13, r14, r15
+#else
+   , ebx, ecx, edx , esi, edi
 #endif
);
 
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 11/55] KVM: VMX: Let gcc to choose which registers to save (x86_64)

2007-12-26 Thread Avi Kivity
From: Laurent Vivier [EMAIL PROTECTED]

This patch lets GCC to determine which registers to save when we
switch to/from a VCPU in the case of intel x86_64.

* Original code saves following registers:

rax, rbx, rcx, rdx, rsi, rdi, rbp,
r8, r9, r10, r11, r12, r13, r14, r15

* Patched code:

  - informs GCC that we modify following registers
using the clobber description:

rbx, rdi, rsi,
r8, r9, r10, r11, r12, r13, r14, r15

  - doesn't save rax because it is an output operand (vmx-fail)

  - cannot put rcx in clobber description because it is an input operand,
but as we modify it and we want to keep its value (vcpu), we must
save it (pop/push)

  - rbp is saved (pop/push) because GCC seems to ignore its use in the clobber
description.

  - rdx is saved (pop/push) because it is reserved by GCC (REGPARM) and
cannot be put in the clobber description.

  - line mov (%%rsp), %3 \n\t has been removed because %3
is rcx and rcx is restored just after.

  - line ASM_VMX_VMWRITE_RSP_RDX() is moved out of the ifdef/else/endif

Signed-off-by: Laurent Vivier [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/vmx.c |   21 +
 1 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 50c151e..3a58a2a 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -2265,16 +2265,12 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
asm(
/* Store host registers */
 #ifdef CONFIG_X86_64
-   push %%rax; push %%rbx; push %%rdx;
-   push %%rsi; push %%rdi; push %%rbp;
-   push %%r8;  push %%r9;  push %%r10; push %%r11;
-   push %%r12; push %%r13; push %%r14; push %%r15;
+   push %%rdx; push %%rbp;
push %%rcx \n\t
-   ASM_VMX_VMWRITE_RSP_RDX \n\t
 #else
pusha; push %%ecx \n\t
-   ASM_VMX_VMWRITE_RSP_RDX \n\t
 #endif
+   ASM_VMX_VMWRITE_RSP_RDX \n\t
/* Check if vmlaunch of vmresume is needed */
cmp $0, %1 \n\t
/* Load guest registers.  Don't clobber flags. */
@@ -2333,12 +2329,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
mov %%r15, %c[r15](%3) \n\t
mov %%cr2, %%rax   \n\t
mov %%rax, %c[cr2](%3) \n\t
-   mov (%%rsp), %3 \n\t
 
-   pop  %%rcx; pop  %%r15; pop  %%r14; pop  %%r13; pop  %%r12;
-   pop  %%r11; pop  %%r10; pop  %%r9;  pop  %%r8;
-   pop  %%rbp; pop  %%rdi; pop  %%rsi;
-   pop  %%rdx; pop  %%rbx; pop  %%rax \n\t
+   pop  %%rcx; pop  %%rbp; pop  %%rdx \n\t
 #else
xchg %3, (%%esp) \n\t
mov %%eax, %c[rax](%3) \n\t
@@ -2376,7 +2368,12 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
[r15]i(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R15])),
 #endif
[cr2]i(offsetof(struct kvm_vcpu, cr2))
- : cc, memory);
+ : cc, memory
+#ifdef CONFIG_X86_64
+   , rbx, rdi, rsi
+   , r8, r9, r10, r11, r12, r13, r14, r15
+#endif
+ );
 
vcpu-interrupt_window_open =
(vmcs_read32(GUEST_INTERRUPTIBILITY_INFO)  3) == 0;
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 13/55] KVM: SVM: Let gcc to choose which registers to save (x86_64)

2007-12-26 Thread Avi Kivity
From: Laurent Vivier [EMAIL PROTECTED]

This patch lets GCC to determine which registers to save when we
switch to/from a VCPU in the case of AMD x86_64.

* Original code saves following registers:

rbx, rcx, rdx, rsi, rdi, rbp,
r8, r9, r10, r11, r12, r13, r14, r15

* Patched code:

  - informs GCC that we modify following registers
using the clobber description:

rbx, rcx, rdx, rsi, rdi
r8, r9, r10, r11, r12, r13, r14, r15

  - rbp is saved (pop/push) because GCC seems to ignore its use in the clobber
description.

Signed-off-by: Laurent Vivier [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/svm.c |   17 -
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 56d1ad6..1298bde 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -1499,10 +1499,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
 
asm volatile (
 #ifdef CONFIG_X86_64
-   push %%rbx; push %%rcx; push %%rdx;
-   push %%rsi; push %%rdi; push %%rbp;
-   push %%r8;  push %%r9;  push %%r10; push %%r11;
-   push %%r12; push %%r13; push %%r14; push %%r15;
+   push %%rbp; \n\t
 #else
push %%ebx; push %%ecx; push %%edx;
push %%esi; push %%edi; push %%ebp;
@@ -1567,10 +1564,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
mov %%r14, %c[r14](%[svm]) \n\t
mov %%r15, %c[r15](%[svm]) \n\t
 
-   pop  %%r15; pop  %%r14; pop  %%r13; pop  %%r12;
-   pop  %%r11; pop  %%r10; pop  %%r9;  pop  %%r8;
-   pop  %%rbp; pop  %%rdi; pop  %%rsi;
-   pop  %%rdx; pop  %%rcx; pop  %%rbx; \n\t
+   pop  %%rbp; \n\t
 #else
mov %%ebx, %c[rbx](%[svm]) \n\t
mov %%ecx, %c[rcx](%[svm]) \n\t
@@ -1601,7 +1595,12 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
  [r14]i(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_R14])),
  [r15]i(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_R15]))
 #endif
-   : cc, memory);
+   : cc, memory
+#ifdef CONFIG_X86_64
+   , rbx, rcx, rdx, rsi, rdi
+   , r8, r9, r10, r11 , r12, r13, r14, r15
+#endif
+   );
 
if ((svm-vmcb-save.dr7  0xff))
load_db_regs(svm-host_db_regs);
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 09/55] KVM: Add kernel-internal memory slots

2007-12-26 Thread Avi Kivity
From: Izik Eidus [EMAIL PROTECTED]

Reserve a few memory slots for kernel internal use.  This is good for case
you have to register memory region and you want to be sure it was not
registered from userspace, and for case you want to register a memory region
that won't be seen from userspace.

Signed-off-by: Izik Eidus [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |6 +-
 drivers/kvm/kvm_main.c |   22 +-
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index f3dda08..82c3b13 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -41,6 +41,8 @@
 #define KVM_MAX_VCPUS 4
 #define KVM_ALIAS_SLOTS 4
 #define KVM_MEMORY_SLOTS 8
+/* memory slots that does not exposed to userspace */
+#define KVM_PRIVATE_MEM_SLOTS 4
 #define KVM_PERMILLE_MMU_PAGES 20
 #define KVM_MIN_ALLOC_MMU_PAGES 64
 #define KVM_NUM_MMU_PAGES 1024
@@ -361,7 +363,8 @@ struct kvm {
int naliases;
struct kvm_mem_alias aliases[KVM_ALIAS_SLOTS];
int nmemslots;
-   struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS];
+   struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS +
+   KVM_PRIVATE_MEM_SLOTS];
/*
 * Hash table of struct kvm_mmu_page.
 */
@@ -529,6 +532,7 @@ int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void 
*data,
 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
 int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
 struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
+int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
 void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
 
 enum emulation_result {
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 16176a2..bc8334b 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -660,7 +660,7 @@ int kvm_set_memory_region(struct kvm *kvm,
goto out;
if (mem-guest_phys_addr  (PAGE_SIZE - 1))
goto out;
-   if (mem-slot = KVM_MEMORY_SLOTS)
+   if (mem-slot = KVM_MEMORY_SLOTS + KVM_PRIVATE_MEM_SLOTS)
goto out;
if (mem-guest_phys_addr + mem-memory_size  mem-guest_phys_addr)
goto out;
@@ -797,6 +797,8 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
  kvm_userspace_memory_region *mem,
  int user_alloc)
 {
+   if (mem-slot = KVM_MEMORY_SLOTS)
+   return -EINVAL;
return kvm_set_memory_region(kvm, mem, user_alloc);
 }
 
@@ -1010,6 +1012,22 @@ struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, 
gfn_t gfn)
return __gfn_to_memslot(kvm, gfn);
 }
 
+int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn)
+{
+   int i;
+
+   gfn = unalias_gfn(kvm, gfn);
+   for (i = 0; i  KVM_MEMORY_SLOTS; ++i) {
+   struct kvm_memory_slot *memslot = kvm-memslots[i];
+
+   if (gfn = memslot-base_gfn
+gfn  memslot-base_gfn + memslot-npages)
+   return 1;
+   }
+   return 0;
+}
+EXPORT_SYMBOL_GPL(kvm_is_visible_gfn);
+
 struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn)
 {
struct kvm_memory_slot *slot;
@@ -3087,6 +3105,8 @@ static struct page *kvm_vm_nopage(struct vm_area_struct 
*vma,
struct page *page;
 
pgoff = ((address - vma-vm_start)  PAGE_SHIFT) + vma-vm_pgoff;
+   if (!kvm_is_visible_gfn(kvm, pgoff))
+   return NOPAGE_SIGBUS;
page = gfn_to_page(kvm, pgoff);
if (is_error_page(page)) {
kvm_release_page(page);
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 03/55] KVM: Add a might_sleep() annotation to gfn_to_page()

2007-12-26 Thread Avi Kivity
This will help trap accesses to guest memory in atomic context.

Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index ff77175..005f2d5 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -993,6 +993,8 @@ struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn)
struct page *page[1];
int npages;
 
+   might_sleep();
+
gfn = unalias_gfn(kvm, gfn);
slot = __gfn_to_memslot(kvm, gfn);
if (!slot) {
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 10/55] KVM: Add ioctl to tss address from userspace,

2007-12-26 Thread Avi Kivity
From: Izik Eidus [EMAIL PROTECTED]

Currently kvm has a wart in that it requires three extra pages for use
as a tss when emulating real mode on Intel.  This patch moves the allocation
internally, only requiring userspace to tell us where in the physical address
space we can place the tss.

Signed-off-by: Izik Eidus [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |3 +++
 drivers/kvm/kvm_main.c |   16 
 drivers/kvm/svm.c  |7 +++
 drivers/kvm/vmx.c  |   27 +--
 include/linux/kvm.h|2 ++
 5 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 82c3b13..3d07d9b 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -382,6 +382,7 @@ struct kvm {
struct kvm_pic *vpic;
struct kvm_ioapic *vioapic;
int round_robin_prev_vcpu;
+   unsigned int tss_addr;
 };
 
 static inline struct kvm_pic *pic_irqchip(struct kvm *kvm)
@@ -467,6 +468,8 @@ struct kvm_x86_ops {
void (*inject_pending_irq)(struct kvm_vcpu *vcpu);
void (*inject_pending_vectors)(struct kvm_vcpu *vcpu,
   struct kvm_run *run);
+
+   int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
 };
 
 extern struct kvm_x86_ops *kvm_x86_ops;
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index bc8334b..26a6399 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -2661,6 +2661,16 @@ static int create_vcpu_fd(struct kvm_vcpu *vcpu)
return fd;
 }
 
+static int kvm_vm_ioctl_set_tss_addr(struct kvm *kvm, unsigned long addr)
+{
+   int ret;
+
+   if (addr  (unsigned int)(-3 * PAGE_SIZE))
+   return -1;
+   ret = kvm_x86_ops-set_tss_addr(kvm, addr);
+   return ret;
+}
+
 /*
  * Creates some virtual cpus.  Good luck creating more than one.
  */
@@ -2957,6 +2967,11 @@ static long kvm_vm_ioctl(struct file *filp,
int r = -EINVAL;
 
switch (ioctl) {
+   case KVM_SET_TSS_ADDR:
+   r = kvm_vm_ioctl_set_tss_addr(kvm, arg);
+   if (r  0)
+   goto out;
+   break;
case KVM_CREATE_VCPU:
r = kvm_vm_ioctl_create_vcpu(kvm, arg);
if (r  0)
@@ -3183,6 +3198,7 @@ static long kvm_dev_ioctl(struct file *filp,
case KVM_CAP_HLT:
case KVM_CAP_MMU_SHADOW_CACHE_CONTROL:
case KVM_CAP_USER_MEMORY:
+   case KVM_CAP_SET_TSS_ADDR:
r = 1;
break;
default:
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 4a70168..56d1ad6 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -1439,6 +1439,11 @@ static void do_interrupt_requests(struct kvm_vcpu *vcpu,
control-intercept = ~(1ULL  INTERCEPT_VINTR);
 }
 
+static int svm_set_tss_addr(struct kvm *kvm, unsigned int addr)
+{
+   return 0;
+}
+
 static void save_db_regs(unsigned long *db_regs)
 {
asm volatile (mov %%dr0, %0 : =r(db_regs[0]));
@@ -1744,6 +1749,8 @@ static struct kvm_x86_ops svm_x86_ops = {
.set_irq = svm_set_irq,
.inject_pending_irq = svm_intr_assist,
.inject_pending_vectors = do_interrupt_requests,
+
+   .set_tss_addr = svm_set_tss_addr,
 };
 
 static int __init svm_init(void)
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 77083e4..50c151e 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1105,8 +1105,12 @@ static void enter_pmode(struct kvm_vcpu *vcpu)
 
 static gva_t rmode_tss_base(struct kvm *kvm)
 {
-   gfn_t base_gfn = kvm-memslots[0].base_gfn + kvm-memslots[0].npages - 
3;
-   return base_gfn  PAGE_SHIFT;
+   if (!kvm-tss_addr) {
+   gfn_t base_gfn = kvm-memslots[0].base_gfn +
+kvm-memslots[0].npages - 3;
+   return base_gfn  PAGE_SHIFT;
+   }
+   return kvm-tss_addr;
 }
 
 static void fix_rmode_seg(int seg, struct kvm_save_segment *save)
@@ -1735,6 +1739,23 @@ static void do_interrupt_requests(struct kvm_vcpu *vcpu,
vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
 }
 
+static int vmx_set_tss_addr(struct kvm *kvm, unsigned int addr)
+{
+   int ret;
+   struct kvm_userspace_memory_region tss_mem = {
+   .slot = 8,
+   .guest_phys_addr = addr,
+   .memory_size = PAGE_SIZE * 3,
+   .flags = 0,
+   };
+
+   ret = kvm_set_memory_region(kvm, tss_mem, 0);
+   if (ret)
+   return ret;
+   kvm-tss_addr = addr;
+   return 0;
+}
+
 static void kvm_guest_debug_pre(struct kvm_vcpu *vcpu)
 {
struct kvm_guest_debug *dbg = vcpu-guest_debug;
@@ -2543,6 +2564,8 @@ static struct kvm_x86_ops vmx_x86_ops = {
.set_irq = vmx_inject_irq,
.inject_pending_irq = vmx_intr_assist,
.inject_pending_vectors = 

[kvm-devel] [PATCH 12/55] KVM: VMX: Let gcc to choose which registers to save (i386)

2007-12-26 Thread Avi Kivity
From: Laurent Vivier [EMAIL PROTECTED]

This patch lets GCC to determine which registers to save when we
switch to/from a VCPU in the case of intel i386.

* Original code saves following registers:

eax, ebx, ecx, edx, edi, esi, ebp (using popa)

* Patched code:

  - informs GCC that we modify following registers
using the clobber description:

ebx, edi, rsi

  - doesn't save eax because it is an output operand (vmx-fail)

  - cannot put ecx in clobber description because it is an input operand,
but as we modify it and we want to keep its value (vcpu), we must
save it (pop/push)

  - ebp is saved (pop/push) because GCC seems to ignore its use the clobber
description.

  - edx is saved (pop/push) because it is reserved by GCC (REGPARM) and
cannot be put in the clobber description.

  - line mov (%%esp), %3 \n\t has been removed because %3
is ecx and ecx is restored just after.

Signed-off-by: Laurent Vivier [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/vmx.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 3a58a2a..f76677d 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -2268,7 +2268,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
push %%rdx; push %%rbp;
push %%rcx \n\t
 #else
-   pusha; push %%ecx \n\t
+   push %%edx; push %%ebp;
+   push %%ecx \n\t
 #endif
ASM_VMX_VMWRITE_RSP_RDX \n\t
/* Check if vmlaunch of vmresume is needed */
@@ -2342,9 +2343,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
mov %%ebp, %c[rbp](%3) \n\t
mov %%cr2, %%eax  \n\t
mov %%eax, %c[cr2](%3) \n\t
-   mov (%%esp), %3 \n\t
 
-   pop %%ecx; popa \n\t
+   pop %%ecx; pop %%ebp; pop %%edx \n\t
 #endif
setbe %0 \n\t
  : =q (vmx-fail)
@@ -2372,6 +2372,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
 #ifdef CONFIG_X86_64
, rbx, rdi, rsi
, r8, r9, r10, r11, r12, r13, r14, r15
+#else
+   , ebx, edi, rsi
 #endif
  );
 
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 16/55] KVM: Move page fault processing to common code

2007-12-26 Thread Avi Kivity
The code that dispatches the page fault and emulates if we failed to map
is duplicated across vmx and svm.  Merge it to simplify further bugfixing.

Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/mmu.c |   36 
 drivers/kvm/svm.c |   33 +
 drivers/kvm/vmx.c |   29 +
 drivers/kvm/x86.h |6 +-
 4 files changed, 39 insertions(+), 65 deletions(-)

diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index d9c5950..ace3cb8 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -1347,6 +1347,42 @@ void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
}
 }
 
+int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code)
+{
+   int r;
+   enum emulation_result er;
+
+   mutex_lock(vcpu-kvm-lock);
+   r = vcpu-mmu.page_fault(vcpu, cr2, error_code);
+   if (r  0)
+   goto out;
+
+   if (!r) {
+   r = 1;
+   goto out;
+   }
+
+   er = emulate_instruction(vcpu, vcpu-run, cr2, error_code, 0);
+   mutex_unlock(vcpu-kvm-lock);
+
+   switch (er) {
+   case EMULATE_DONE:
+   return 1;
+   case EMULATE_DO_MMIO:
+   ++vcpu-stat.mmio_exits;
+   return 0;
+   case EMULATE_FAIL:
+   kvm_report_emulation_failure(vcpu, pagetable);
+   return 1;
+   default:
+   BUG();
+   }
+out:
+   mutex_unlock(vcpu-kvm-lock);
+   return r;
+}
+EXPORT_SYMBOL_GPL(kvm_mmu_page_fault);
+
 static void free_mmu_pages(struct kvm_vcpu *vcpu)
 {
struct kvm_mmu_page *page;
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index cdd4fd2..991e77d 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -933,45 +933,14 @@ static int pf_interception(struct vcpu_svm *svm, struct 
kvm_run *kvm_run)
struct kvm *kvm = svm-vcpu.kvm;
u64 fault_address;
u32 error_code;
-   enum emulation_result er;
-   int r;
 
if (!irqchip_in_kernel(kvm) 
is_external_interrupt(exit_int_info))
push_irq(svm-vcpu, exit_int_info  SVM_EVTINJ_VEC_MASK);
 
-   mutex_lock(kvm-lock);
-
fault_address  = svm-vmcb-control.exit_info_2;
error_code = svm-vmcb-control.exit_info_1;
-   r = kvm_mmu_page_fault(svm-vcpu, fault_address, error_code);
-   if (r  0) {
-   mutex_unlock(kvm-lock);
-   return r;
-   }
-   if (!r) {
-   mutex_unlock(kvm-lock);
-   return 1;
-   }
-   er = emulate_instruction(svm-vcpu, kvm_run, fault_address,
-error_code, 0);
-   mutex_unlock(kvm-lock);
-
-   switch (er) {
-   case EMULATE_DONE:
-   return 1;
-   case EMULATE_DO_MMIO:
-   ++svm-vcpu.stat.mmio_exits;
-   return 0;
-   case EMULATE_FAIL:
-   kvm_report_emulation_failure(svm-vcpu, pagetable);
-   break;
-   default:
-   BUG();
-   }
-
-   kvm_run-exit_reason = KVM_EXIT_UNKNOWN;
-   return 0;
+   return kvm_mmu_page_fault(svm-vcpu, fault_address, error_code);
 }
 
 static int ud_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index f76677d..265df86 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1796,7 +1796,6 @@ static int handle_exception(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
unsigned long cr2, rip;
u32 vect_info;
enum emulation_result er;
-   int r;
 
vect_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
@@ -1834,33 +1833,7 @@ static int handle_exception(struct kvm_vcpu *vcpu, 
struct kvm_run *kvm_run)
error_code = vmcs_read32(VM_EXIT_INTR_ERROR_CODE);
if (is_page_fault(intr_info)) {
cr2 = vmcs_readl(EXIT_QUALIFICATION);
-
-   mutex_lock(vcpu-kvm-lock);
-   r = kvm_mmu_page_fault(vcpu, cr2, error_code);
-   if (r  0) {
-   mutex_unlock(vcpu-kvm-lock);
-   return r;
-   }
-   if (!r) {
-   mutex_unlock(vcpu-kvm-lock);
-   return 1;
-   }
-
-   er = emulate_instruction(vcpu, kvm_run, cr2, error_code, 0);
-   mutex_unlock(vcpu-kvm-lock);
-
-   switch (er) {
-   case EMULATE_DONE:
-   return 1;
-   case EMULATE_DO_MMIO:
-   ++vcpu-stat.mmio_exits;
-   return 0;
-   case EMULATE_FAIL:
-   kvm_report_emulation_failure(vcpu, pagetable);
-   break;
-   default:
-   BUG();
-   }
+   return kvm_mmu_page_fault(vcpu, cr2, 

[kvm-devel] [PATCH 27/55] KVM: x86 emulator: Extract the common code of SrcReg and DstReg

2007-12-26 Thread Avi Kivity
Share the common parts of SrcReg and DstReg decoding.

Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/x86_emulate.c |   80 +---
 1 files changed, 31 insertions(+), 49 deletions(-)

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index 087a820..58ceb66 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -520,6 +520,34 @@ static int test_cc(unsigned int condition, unsigned int 
flags)
return (!!rc ^ (condition  1));
 }
 
+static void decode_register_operand(struct operand *op,
+   struct decode_cache *c,
+   int highbyte_regs,
+   int inhibit_bytereg)
+{
+   op-type = OP_REG;
+   if ((c-d  ByteOp)  !inhibit_bytereg) {
+   op-ptr = decode_register(c-modrm_reg, c-regs, highbyte_regs);
+   op-val = *(u8 *)op-ptr;
+   op-bytes = 1;
+   } else {
+   op-ptr = decode_register(c-modrm_reg, c-regs, 0);
+   op-bytes = c-op_bytes;
+   switch (op-bytes) {
+   case 2:
+   op-val = *(u16 *)op-ptr;
+   break;
+   case 4:
+   op-val = *(u32 *)op-ptr;
+   break;
+   case 8:
+   op-val = *(u64 *) op-ptr;
+   break;
+   }
+   }
+   op-orig_val = op-val;
+}
+
 int
 x86_decode_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
 {
@@ -809,31 +837,7 @@ modrm_done:
case SrcNone:
break;
case SrcReg:
-   c-src.type = OP_REG;
-   if (c-d  ByteOp) {
-   c-src.ptr =
-   decode_register(c-modrm_reg, c-regs,
- (rex_prefix == 0));
-   c-src.val = c-src.orig_val = *(u8 *)c-src.ptr;
-   c-src.bytes = 1;
-   } else {
-   c-src.ptr =
-   decode_register(c-modrm_reg, c-regs, 0);
-   switch ((c-src.bytes = c-op_bytes)) {
-   case 2:
-   c-src.val = c-src.orig_val =
-  *(u16 *) c-src.ptr;
-   break;
-   case 4:
-   c-src.val = c-src.orig_val =
-  *(u32 *) c-src.ptr;
-   break;
-   case 8:
-   c-src.val = c-src.orig_val =
-  *(u64 *) c-src.ptr;
-   break;
-   }
-   }
+   decode_register_operand(c-src, c, rex_prefix == 0, 0);
break;
case SrcMem16:
c-src.bytes = 2;
@@ -891,30 +895,8 @@ modrm_done:
/* Special instructions do their own operand decoding. */
return 0;
case DstReg:
-   c-dst.type = OP_REG;
-   if ((c-d  ByteOp)
-!(c-twobyte 
-   (c-b == 0xb6 || c-b == 0xb7))) {
-   c-dst.ptr =
-   decode_register(c-modrm_reg, c-regs,
- (rex_prefix == 0));
-   c-dst.val = *(u8 *) c-dst.ptr;
-   c-dst.bytes = 1;
-   } else {
-   c-dst.ptr =
-   decode_register(c-modrm_reg, c-regs, 0);
-   switch ((c-dst.bytes = c-op_bytes)) {
-   case 2:
-   c-dst.val = *(u16 *)c-dst.ptr;
-   break;
-   case 4:
-   c-dst.val = *(u32 *)c-dst.ptr;
-   break;
-   case 8:
-   c-dst.val = *(u64 *)c-dst.ptr;
-   break;
-   }
-   }
+   decode_register_operand(c-dst, c, rex_prefix == 0,
+c-twobyte  (c-b == 0xb6 || c-b == 0xb7));
break;
case DstMem:
if ((c-d  ModRM)  c-modrm_mod == 3) {
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 23/55] KVM: Fix gfn_to_page() acquiring mmap_sem twice

2007-12-26 Thread Avi Kivity
From: Anthony Liguori [EMAIL PROTECTED]

KVM's nopage handler calls gfn_to_page() which acquires the mmap_sem when
calling out to get_user_pages().  nopage handlers are already invoked with the
mmap_sem held though.  Introduce a __gfn_to_page() for use by the nopage
handler which requires the lock to already be held.

This was noticed by tglx.

Signed-off-by: Anthony Liguori [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c |   22 ++
 1 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index c3dc24f..7186791 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -633,7 +633,10 @@ int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn)
 }
 EXPORT_SYMBOL_GPL(kvm_is_visible_gfn);
 
-struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn)
+/*
+ * Requires current-mm-mmap_sem to be held
+ */
+static struct page *__gfn_to_page(struct kvm *kvm, gfn_t gfn)
 {
struct kvm_memory_slot *slot;
struct page *page[1];
@@ -648,12 +651,10 @@ struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn)
return bad_page;
}
 
-   down_read(current-mm-mmap_sem);
npages = get_user_pages(current, current-mm,
slot-userspace_addr
+ (gfn - slot-base_gfn) * PAGE_SIZE, 1,
1, 1, page, NULL);
-   up_read(current-mm-mmap_sem);
if (npages != 1) {
get_page(bad_page);
return bad_page;
@@ -661,6 +662,18 @@ struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn)
 
return page[0];
 }
+
+struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn)
+{
+   struct page *page;
+
+   down_read(current-mm-mmap_sem);
+   page = __gfn_to_page(kvm, gfn);
+   up_read(current-mm-mmap_sem);
+
+   return page;
+}
+
 EXPORT_SYMBOL_GPL(gfn_to_page);
 
 void kvm_release_page(struct page *page)
@@ -2621,7 +2634,8 @@ static struct page *kvm_vm_nopage(struct vm_area_struct 
*vma,
pgoff = ((address - vma-vm_start)  PAGE_SHIFT) + vma-vm_pgoff;
if (!kvm_is_visible_gfn(kvm, pgoff))
return NOPAGE_SIGBUS;
-   page = gfn_to_page(kvm, pgoff);
+   /* current-mm-mmap_sem is already held so call lockless version */
+   page = __gfn_to_page(kvm, pgoff);
if (is_error_page(page)) {
kvm_release_page(page);
return NOPAGE_SIGBUS;
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 29/55] KVM: Simplify decode_register_operand() calling convention

2007-12-26 Thread Avi Kivity
Now that rex_prefix is part of the decode cache, there is no need to pass
it along.

Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/x86_emulate.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index 884e4a2..b352a6c 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -518,10 +518,10 @@ static int test_cc(unsigned int condition, unsigned int 
flags)
 
 static void decode_register_operand(struct operand *op,
struct decode_cache *c,
-   int highbyte_regs,
int inhibit_bytereg)
 {
unsigned reg = c-modrm_reg;
+   int highbyte_regs = c-rex_prefix == 0;
 
if (!(c-d  ModRM))
reg = (c-b  7) | ((c-rex_prefix  1)  3);
@@ -837,7 +837,7 @@ modrm_done:
case SrcNone:
break;
case SrcReg:
-   decode_register_operand(c-src, c, c-rex_prefix == 0, 0);
+   decode_register_operand(c-src, c, 0);
break;
case SrcMem16:
c-src.bytes = 2;
@@ -895,7 +895,7 @@ modrm_done:
/* Special instructions do their own operand decoding. */
return 0;
case DstReg:
-   decode_register_operand(c-dst, c, c-rex_prefix == 0,
+   decode_register_operand(c-dst, c,
 c-twobyte  (c-b == 0xb6 || c-b == 0xb7));
break;
case DstMem:
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 19/55] KVM: Portability: Move memory segmentation to x86.c

2007-12-26 Thread Avi Kivity
From: Carsten Otte [EMAIL PROTECTED]

This patch moves the definition of segment_descriptor_64 for AMD64 and
EM64T from kvm_main.c to segment_descriptor.h. It also adds a proper
#ifndef...#define...#endif around that header file.
The implementation of segment_base is moved from kvm_main.c to x86.c.

Signed-off-by: Carsten Otte [EMAIL PROTECTED]
Reviewed-by: Christian Borntraeger [EMAIL PROTECTED]
Acked-by: Hollis Blanchard [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c   |   42 --
 drivers/kvm/segment_descriptor.h |   12 ++
 drivers/kvm/x86.c|   33 +
 3 files changed, 45 insertions(+), 42 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 9c0175d..00f9c9e 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -18,7 +18,6 @@
 #include kvm.h
 #include x86.h
 #include x86_emulate.h
-#include segment_descriptor.h
 #include irq.h
 
 #include linux/kvm.h
@@ -104,50 +103,9 @@ static struct dentry *debugfs_dir;
 #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)
 #define EFER_RESERVED_BITS 0xf2fe
 
-#ifdef CONFIG_X86_64
-/* LDT or TSS descriptor in the GDT. 16 bytes. */
-struct segment_descriptor_64 {
-   struct segment_descriptor s;
-   u32 base_higher;
-   u32 pad_zero;
-};
-
-#endif
-
 static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
   unsigned long arg);
 
-unsigned long segment_base(u16 selector)
-{
-   struct descriptor_table gdt;
-   struct segment_descriptor *d;
-   unsigned long table_base;
-   unsigned long v;
-
-   if (selector == 0)
-   return 0;
-
-   asm(sgdt %0 : =m(gdt));
-   table_base = gdt.base;
-
-   if (selector  4) {   /* from ldt */
-   u16 ldt_selector;
-
-   asm(sldt %0 : =g(ldt_selector));
-   table_base = segment_base(ldt_selector);
-   }
-   d = (struct segment_descriptor *)(table_base + (selector  ~7));
-   v = d-base_low | ((unsigned long)d-base_mid  16) |
-   ((unsigned long)d-base_high  24);
-#ifdef CONFIG_X86_64
-   if (d-system == 0  (d-type == 2 || d-type == 9 || d-type == 11))
-   v |= ((unsigned long) \
- ((struct segment_descriptor_64 *)d)-base_higher)  32;
-#endif
-   return v;
-}
-EXPORT_SYMBOL_GPL(segment_base);
-
 static inline int valid_vcpu(int n)
 {
return likely(n = 0  n  KVM_MAX_VCPUS);
diff --git a/drivers/kvm/segment_descriptor.h b/drivers/kvm/segment_descriptor.h
index 71fdf45..56fc4c8 100644
--- a/drivers/kvm/segment_descriptor.h
+++ b/drivers/kvm/segment_descriptor.h
@@ -1,3 +1,6 @@
+#ifndef __SEGMENT_DESCRIPTOR_H
+#define __SEGMENT_DESCRIPTOR_H
+
 struct segment_descriptor {
u16 limit_low;
u16 base_low;
@@ -14,4 +17,13 @@ struct segment_descriptor {
u8  base_high;
 } __attribute__((packed));
 
+#ifdef CONFIG_X86_64
+/* LDT or TSS descriptor in the GDT. 16 bytes. */
+struct segment_descriptor_64 {
+   struct segment_descriptor s;
+   u32 base_higher;
+   u32 pad_zero;
+};
 
+#endif
+#endif
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index b84cb67..5a95922 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -16,16 +16,49 @@
 
 #include kvm.h
 #include x86.h
+#include segment_descriptor.h
 #include irq.h
 
 #include linux/kvm.h
 #include linux/fs.h
 #include linux/vmalloc.h
+#include linux/module.h
 
 #include asm/uaccess.h
 
 #define MAX_IO_MSRS 256
 
+unsigned long segment_base(u16 selector)
+{
+   struct descriptor_table gdt;
+   struct segment_descriptor *d;
+   unsigned long table_base;
+   unsigned long v;
+
+   if (selector == 0)
+   return 0;
+
+   asm(sgdt %0 : =m(gdt));
+   table_base = gdt.base;
+
+   if (selector  4) {   /* from ldt */
+   u16 ldt_selector;
+
+   asm(sldt %0 : =g(ldt_selector));
+   table_base = segment_base(ldt_selector);
+   }
+   d = (struct segment_descriptor *)(table_base + (selector  ~7));
+   v = d-base_low | ((unsigned long)d-base_mid  16) |
+   ((unsigned long)d-base_high  24);
+#ifdef CONFIG_X86_64
+   if (d-system == 0  (d-type == 2 || d-type == 9 || d-type == 11))
+   v |= ((unsigned long) \
+ ((struct segment_descriptor_64 *)d)-base_higher)  32;
+#endif
+   return v;
+}
+EXPORT_SYMBOL_GPL(segment_base);
+
 /*
  * List of msr numbers which we expose to userspace through KVM_GET_MSRS
  * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___

[kvm-devel] [PATCH 17/55] KVM: MMU: Topup the mmu memory preallocation caches before emulating an insn

2007-12-26 Thread Avi Kivity
Emulation may cause a shadow pte to be instantiated, which requires
memory resources.  Make sure the caches are filled to avoid an oops.

Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/mmu.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index ace3cb8..9be54a5 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -1362,6 +1362,10 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, 
u32 error_code)
goto out;
}
 
+   r = mmu_topup_memory_caches(vcpu);
+   if (r)
+   goto out;
+
er = emulate_instruction(vcpu, vcpu-run, cr2, error_code, 0);
mutex_unlock(vcpu-kvm-lock);
 
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 30/55] KVM: Make mark_page_dirty() work for aliased pages too.

2007-12-26 Thread Avi Kivity
From: Uri Lublin [EMAIL PROTECTED]

Recommended by Izik Eidus.

Signed-off-by: Uri Lublin [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 27f3a6e..ad4c84c 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -796,11 +796,11 @@ int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned 
long len)
 }
 EXPORT_SYMBOL_GPL(kvm_clear_guest);
 
-/* WARNING: Does not work on aliased pages. */
 void mark_page_dirty(struct kvm *kvm, gfn_t gfn)
 {
struct kvm_memory_slot *memslot;
 
+   gfn = unalias_gfn(kvm, gfn);
memslot = __gfn_to_memslot(kvm, gfn);
if (memslot  memslot-dirty_bitmap) {
unsigned long rel_gfn = gfn - memslot-base_gfn;
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 38/55] KVM: VMX: Read store IDT_VECTORING_INFO_FIELD

2007-12-26 Thread Avi Kivity
We'll want to write to it in order to fix real-mode irq injection problems,
but it is a read-only field.  Storing it in a variable solves that issue.

Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/vmx.c |   17 -
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 1166132..bde2d07 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -48,6 +48,7 @@ struct vcpu_vmx {
struct kvm_vcpu   vcpu;
int   launched;
u8fail;
+   u32   idt_vectoring_info;
struct kvm_msr_entry *guest_msrs;
struct kvm_msr_entry *host_msrs;
int   nmsrs;
@@ -863,9 +864,10 @@ static int set_guest_debug(struct kvm_vcpu *vcpu, struct 
kvm_debug_guest *dbg)
 
 static int vmx_get_irq(struct kvm_vcpu *vcpu)
 {
+   struct vcpu_vmx *vmx = to_vmx(vcpu);
u32 idtv_info_field;
 
-   idtv_info_field = vmcs_read32(IDT_VECTORING_INFO_FIELD);
+   idtv_info_field = vmx-idt_vectoring_info;
if (idtv_info_field  INTR_INFO_VALID_MASK) {
if (is_external_interrupt(idtv_info_field))
return idtv_info_field  VECTORING_INFO_VECTOR_MASK;
@@ -1817,12 +1819,13 @@ static int handle_rmode_exception(struct kvm_vcpu *vcpu,
 
 static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 {
+   struct vcpu_vmx *vmx = to_vmx(vcpu);
u32 intr_info, error_code;
unsigned long cr2, rip;
u32 vect_info;
enum emulation_result er;
 
-   vect_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
+   vect_info = vmx-idt_vectoring_info;
intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
 
if ((vect_info  VECTORING_INFO_VALID_MASK) 
@@ -2171,9 +2174,9 @@ static const int kvm_vmx_max_exit_handlers =
  */
 static int kvm_handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 {
-   u32 vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
u32 exit_reason = vmcs_read32(VM_EXIT_REASON);
struct vcpu_vmx *vmx = to_vmx(vcpu);
+   u32 vectoring_info = vmx-idt_vectoring_info;
 
if (unlikely(vmx-fail)) {
kvm_run-exit_reason = KVM_EXIT_FAIL_ENTRY;
@@ -2228,6 +2231,7 @@ static void enable_irq_window(struct kvm_vcpu *vcpu)
 
 static void vmx_intr_assist(struct kvm_vcpu *vcpu)
 {
+   struct vcpu_vmx *vmx = to_vmx(vcpu);
u32 idtv_info_field, intr_info_field;
int has_ext_irq, interrupt_window_open;
int vector;
@@ -2236,7 +2240,7 @@ static void vmx_intr_assist(struct kvm_vcpu *vcpu)
 
has_ext_irq = kvm_cpu_has_interrupt(vcpu);
intr_info_field = vmcs_read32(VM_ENTRY_INTR_INFO_FIELD);
-   idtv_info_field = vmcs_read32(IDT_VECTORING_INFO_FIELD);
+   idtv_info_field = vmx-idt_vectoring_info;
if (intr_info_field  INTR_INFO_VALID_MASK) {
if (idtv_info_field  INTR_INFO_VALID_MASK) {
/* TODO: fault when IDT_Vectoring */
@@ -2396,6 +2400,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
 #endif
  );
 
+   vmx-idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
+
vcpu-interrupt_window_open =
(vmcs_read32(GUEST_INTERRUPTIBILITY_INFO)  3) == 0;
 
@@ -2413,7 +2419,8 @@ static void vmx_inject_page_fault(struct kvm_vcpu *vcpu,
  unsigned long addr,
  u32 err_code)
 {
-   u32 vect_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
+   struct vcpu_vmx *vmx = to_vmx(vcpu);
+   u32 vect_info = vmx-idt_vectoring_info;
 
++vcpu-stat.pf_guest;
 
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 28/55] KVM: x86 emulator: centralize decoding of one-byte register access insns

2007-12-26 Thread Avi Kivity
Instructions like 'inc reg' that have the register operand encoded
in the opcode are currently specially decoded.  Extend
decode_register_operand() to handle that case, indicated by having
DstReg or SrcReg without ModRM.

Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/x86_emulate.c |  103 -
 drivers/kvm/x86_emulate.h |1 +
 2 files changed, 47 insertions(+), 57 deletions(-)

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index 58ceb66..884e4a2 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -99,17 +99,13 @@ static u16 opcode_table[256] = {
ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
0, 0, 0, 0,
/* 0x40 - 0x47 */
-   ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
-   ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
+   DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, DstReg,
/* 0x48 - 0x4F */
-   ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
-   ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
+   DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, DstReg,
/* 0x50 - 0x57 */
-   ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
-   ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
+   SrcReg, SrcReg, SrcReg, SrcReg, SrcReg, SrcReg, SrcReg, SrcReg,
/* 0x58 - 0x5F */
-   ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
-   ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
+   DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, DstReg,
/* 0x60 - 0x67 */
0, 0, 0, DstReg | SrcMem32 | ModRM | Mov /* movsxd (x86/64) */ ,
0, 0, 0, 0,
@@ -525,13 +521,17 @@ static void decode_register_operand(struct operand *op,
int highbyte_regs,
int inhibit_bytereg)
 {
+   unsigned reg = c-modrm_reg;
+
+   if (!(c-d  ModRM))
+   reg = (c-b  7) | ((c-rex_prefix  1)  3);
op-type = OP_REG;
if ((c-d  ByteOp)  !inhibit_bytereg) {
-   op-ptr = decode_register(c-modrm_reg, c-regs, highbyte_regs);
+   op-ptr = decode_register(reg, c-regs, highbyte_regs);
op-val = *(u8 *)op-ptr;
op-bytes = 1;
} else {
-   op-ptr = decode_register(c-modrm_reg, c-regs, 0);
+   op-ptr = decode_register(reg, c-regs, 0);
op-bytes = c-op_bytes;
switch (op-bytes) {
case 2:
@@ -552,7 +552,7 @@ int
 x86_decode_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
 {
struct decode_cache *c = ctxt-decode;
-   u8 sib, rex_prefix = 0;
+   u8 sib;
int rc = 0;
int mode = ctxt-mode;
int index_reg = 0, base_reg = 0, scale, rip_relative = 0;
@@ -616,7 +616,7 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt, struct 
x86_emulate_ops *ops)
case 0x40 ... 0x4f: /* REX */
if (mode != X86EMUL_MODE_PROT64)
goto done_prefixes;
-   rex_prefix = c-b;
+   c-rex_prefix = c-b;
continue;
case 0xf0:  /* LOCK */
c-lock_prefix = 1;
@@ -631,18 +631,18 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt, struct 
x86_emulate_ops *ops)
 
/* Any legacy prefix after a REX prefix nullifies its effect. */
 
-   rex_prefix = 0;
+   c-rex_prefix = 0;
}
 
 done_prefixes:
 
/* REX prefix. */
-   if (rex_prefix) {
-   if (rex_prefix  8)
+   if (c-rex_prefix) {
+   if (c-rex_prefix  8)
c-op_bytes = 8;/* REX.W */
-   c-modrm_reg = (rex_prefix  4)  1;   /* REX.R */
-   index_reg = (rex_prefix  2)  2; /* REX.X */
-   c-modrm_rm = base_reg = (rex_prefix  1)  3; /* REG.B */
+   c-modrm_reg = (c-rex_prefix  4)  1;/* REX.R */
+   index_reg = (c-rex_prefix  2)  2; /* REX.X */
+   c-modrm_rm = base_reg = (c-rex_prefix  1)  3; /* REG.B */
}
 
/* Opcode byte(s). */
@@ -837,7 +837,7 @@ modrm_done:
case SrcNone:
break;
case SrcReg:
-   decode_register_operand(c-src, c, rex_prefix == 0, 0);
+   decode_register_operand(c-src, c, c-rex_prefix == 0, 0);
break;
case SrcMem16:
c-src.bytes = 2;
@@ -895,7 +895,7 @@ modrm_done:
/* Special instructions do their own operand decoding. */
return 0;
case DstReg:
-   decode_register_operand(c-dst, c, rex_prefix == 0,
+   decode_register_operand(c-dst, c, c-rex_prefix == 0,
 c-twobyte  (c-b == 0xb6 || c-b == 0xb7));
break;
case 

[kvm-devel] [PATCH 37/55] KVM: VMX: Use vmx to inject real-mode interrupts

2007-12-26 Thread Avi Kivity
Instead of injecting real-mode interrupts by writing the interrupt frame into
guest memory, abuse vmx by injecting a software interrupt.  We need to
pretend the software interrupt instruction had a length  0, so we have to
adjust rip backward.

This lets us not to mess with writing guest memory, which is complex and also
sleeps.

Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/vmx.c |   53 -
 drivers/kvm/vmx.h |1 +
 2 files changed, 5 insertions(+), 49 deletions(-)

diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 6fc981d..1166132 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1709,58 +1709,13 @@ out:
return ret;
 }
 
-static void inject_rmode_irq(struct kvm_vcpu *vcpu, int irq)
-{
-   u16 ent[2];
-   u16 cs;
-   u16 ip;
-   unsigned long flags;
-   unsigned long ss_base = vmcs_readl(GUEST_SS_BASE);
-   u16 sp =  vmcs_readl(GUEST_RSP);
-   u32 ss_limit = vmcs_read32(GUEST_SS_LIMIT);
-
-   if (sp  ss_limit || sp  6) {
-   vcpu_printf(vcpu, %s: #SS, rsp 0x%lx ss 0x%lx limit 0x%x\n,
-   __FUNCTION__,
-   vmcs_readl(GUEST_RSP),
-   vmcs_readl(GUEST_SS_BASE),
-   vmcs_read32(GUEST_SS_LIMIT));
-   return;
-   }
-
-   if (emulator_read_std(irq * sizeof(ent), ent, sizeof(ent), vcpu) !=
-   X86EMUL_CONTINUE) {
-   vcpu_printf(vcpu, %s: read guest err\n, __FUNCTION__);
-   return;
-   }
-
-   flags =  vmcs_readl(GUEST_RFLAGS);
-   cs =  vmcs_readl(GUEST_CS_BASE)  4;
-   ip =  vmcs_readl(GUEST_RIP);
-
-
-   if (emulator_write_emulated(
-   ss_base + sp - 2, flags, 2, vcpu) != X86EMUL_CONTINUE ||
-   emulator_write_emulated(
-   ss_base + sp - 4, cs, 2, vcpu) != X86EMUL_CONTINUE ||
-   emulator_write_emulated(
-   ss_base + sp - 6, ip, 2, vcpu) != X86EMUL_CONTINUE) {
-   vcpu_printf(vcpu, %s: write guest err\n, __FUNCTION__);
-   return;
-   }
-
-   vmcs_writel(GUEST_RFLAGS, flags 
-   ~(X86_EFLAGS_IF | X86_EFLAGS_AC | X86_EFLAGS_TF));
-   vmcs_write16(GUEST_CS_SELECTOR, ent[1]) ;
-   vmcs_writel(GUEST_CS_BASE, ent[1]  4);
-   vmcs_writel(GUEST_RIP, ent[0]);
-   vmcs_writel(GUEST_RSP, (vmcs_readl(GUEST_RSP)  ~0x) | (sp - 6));
-}
-
 static void vmx_inject_irq(struct kvm_vcpu *vcpu, int irq)
 {
if (vcpu-rmode.active) {
-   inject_rmode_irq(vcpu, irq);
+   vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
+irq | INTR_TYPE_SOFT_INTR | INTR_INFO_VALID_MASK);
+   vmcs_write32(VM_ENTRY_INSTRUCTION_LEN, 1);
+   vmcs_writel(GUEST_RIP, vmcs_readl(GUEST_RIP) - 1);
return;
}
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
diff --git a/drivers/kvm/vmx.h b/drivers/kvm/vmx.h
index c84bd37..d757b36 100644
--- a/drivers/kvm/vmx.h
+++ b/drivers/kvm/vmx.h
@@ -233,6 +233,7 @@ enum vmcs_field {
 
 #define INTR_TYPE_EXT_INTR  (0  8) /* external interrupt */
 #define INTR_TYPE_EXCEPTION (3  8) /* processor exception */
+#define INTR_TYPE_SOFT_INTR (4  8) /* software interrupt */
 
 /*
  * Exit Qualifications for MOV for Control Register Access
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 33/55] KVM: Portability: Move x86 instruction emulation code to x86.c

2007-12-26 Thread Avi Kivity
From: Hollis Blanchard [EMAIL PROTECTED]

Signed-off-by: Hollis Blanchard [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |1 +
 drivers/kvm/kvm_main.c |  177 +---
 drivers/kvm/x86.c  |  175 +++
 3 files changed, 177 insertions(+), 176 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index d030a82..ef2a6a8 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -591,6 +591,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 
data);
 
 void fx_init(struct kvm_vcpu *vcpu);
 
+void kvm_vcpu_block(struct kvm_vcpu *vcpu);
 void kvm_resched(struct kvm_vcpu *vcpu);
 void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
 void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 11580be..a779d42 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -789,7 +789,7 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn)
 /*
  * The vCPU has executed a HLT instruction with in-kernel mode enabled.
  */
-static void kvm_vcpu_block(struct kvm_vcpu *vcpu)
+void kvm_vcpu_block(struct kvm_vcpu *vcpu)
 {
DECLARE_WAITQUEUE(wait, current);
 
@@ -812,144 +812,6 @@ static void kvm_vcpu_block(struct kvm_vcpu *vcpu)
remove_wait_queue(vcpu-wq, wait);
 }
 
-int kvm_emulate_halt(struct kvm_vcpu *vcpu)
-{
-   ++vcpu-stat.halt_exits;
-   if (irqchip_in_kernel(vcpu-kvm)) {
-   vcpu-mp_state = VCPU_MP_STATE_HALTED;
-   kvm_vcpu_block(vcpu);
-   if (vcpu-mp_state != VCPU_MP_STATE_RUNNABLE)
-   return -EINTR;
-   return 1;
-   } else {
-   vcpu-run-exit_reason = KVM_EXIT_HLT;
-   return 0;
-   }
-}
-EXPORT_SYMBOL_GPL(kvm_emulate_halt);
-
-int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
-{
-   unsigned long nr, a0, a1, a2, a3, ret;
-
-   kvm_x86_ops-cache_regs(vcpu);
-
-   nr = vcpu-regs[VCPU_REGS_RAX];
-   a0 = vcpu-regs[VCPU_REGS_RBX];
-   a1 = vcpu-regs[VCPU_REGS_RCX];
-   a2 = vcpu-regs[VCPU_REGS_RDX];
-   a3 = vcpu-regs[VCPU_REGS_RSI];
-
-   if (!is_long_mode(vcpu)) {
-   nr = 0x;
-   a0 = 0x;
-   a1 = 0x;
-   a2 = 0x;
-   a3 = 0x;
-   }
-
-   switch (nr) {
-   default:
-   ret = -KVM_ENOSYS;
-   break;
-   }
-   vcpu-regs[VCPU_REGS_RAX] = ret;
-   kvm_x86_ops-decache_regs(vcpu);
-   return 0;
-}
-EXPORT_SYMBOL_GPL(kvm_emulate_hypercall);
-
-int kvm_fix_hypercall(struct kvm_vcpu *vcpu)
-{
-   char instruction[3];
-   int ret = 0;
-
-   mutex_lock(vcpu-kvm-lock);
-
-   /*
-* Blow out the MMU to ensure that no other VCPU has an active mapping
-* to ensure that the updated hypercall appears atomically across all
-* VCPUs.
-*/
-   kvm_mmu_zap_all(vcpu-kvm);
-
-   kvm_x86_ops-cache_regs(vcpu);
-   kvm_x86_ops-patch_hypercall(vcpu, instruction);
-   if (emulator_write_emulated(vcpu-rip, instruction, 3, vcpu)
-   != X86EMUL_CONTINUE)
-   ret = -EFAULT;
-
-   mutex_unlock(vcpu-kvm-lock);
-
-   return ret;
-}
-
-static u64 mk_cr_64(u64 curr_cr, u32 new_val)
-{
-   return (curr_cr  ~((1ULL  32) - 1)) | new_val;
-}
-
-void realmode_lgdt(struct kvm_vcpu *vcpu, u16 limit, unsigned long base)
-{
-   struct descriptor_table dt = { limit, base };
-
-   kvm_x86_ops-set_gdt(vcpu, dt);
-}
-
-void realmode_lidt(struct kvm_vcpu *vcpu, u16 limit, unsigned long base)
-{
-   struct descriptor_table dt = { limit, base };
-
-   kvm_x86_ops-set_idt(vcpu, dt);
-}
-
-void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw,
-  unsigned long *rflags)
-{
-   lmsw(vcpu, msw);
-   *rflags = kvm_x86_ops-get_rflags(vcpu);
-}
-
-unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr)
-{
-   kvm_x86_ops-decache_cr4_guest_bits(vcpu);
-   switch (cr) {
-   case 0:
-   return vcpu-cr0;
-   case 2:
-   return vcpu-cr2;
-   case 3:
-   return vcpu-cr3;
-   case 4:
-   return vcpu-cr4;
-   default:
-   vcpu_printf(vcpu, %s: unexpected cr %u\n, __FUNCTION__, cr);
-   return 0;
-   }
-}
-
-void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long val,
-unsigned long *rflags)
-{
-   switch (cr) {
-   case 0:
-   set_cr0(vcpu, mk_cr_64(vcpu-cr0, val));
-   *rflags = kvm_x86_ops-get_rflags(vcpu);
-   break;
-   case 2:
-   vcpu-cr2 = val;
-   break;
-   case 3:
-   set_cr3(vcpu, val);
-   break;
-   case 4:
-   set_cr4(vcpu, mk_cr_64(vcpu-cr4, val));
-   break;

[kvm-devel] [PATCH 41/55] KVM: VMX: wbinvd exiting

2007-12-26 Thread Avi Kivity
From: Eddie Dong [EMAIL PROTECTED]

Add wbinvd VM Exit support to prepare for pass-through
device cache emulation and also enhance real time
responsiveness.

Signed-off-by: Yaozu (Eddie) Dong [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/vmx.c |   11 ++-
 drivers/kvm/vmx.h |2 ++
 2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 63c230d..ad16865 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -980,7 +980,8 @@ static __init int setup_vmcs_config(struct vmcs_config 
*vmcs_conf)
 #endif
if (_cpu_based_exec_control  CPU_BASED_ACTIVATE_SECONDARY_CONTROLS) {
min = 0;
-   opt = SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES;
+   opt = SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES |
+   SECONDARY_EXEC_WBINVD_EXITING;
if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_PROCBASED_CTLS2,
_cpu_based_2nd_exec_control)  0)
return -EIO;
@@ -2133,6 +2134,13 @@ static int handle_vmcall(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
return 1;
 }
 
+static int handle_wbinvd(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
+{
+   skip_emulated_instruction(vcpu);
+   /* TODO: Add support for VT-d/pass-through device */
+   return 1;
+}
+
 static int handle_apic_access(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 {
u64 exit_qualification;
@@ -2174,6 +2182,7 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu 
*vcpu,
[EXIT_REASON_VMCALL]  = handle_vmcall,
[EXIT_REASON_TPR_BELOW_THRESHOLD] = handle_tpr_below_threshold,
[EXIT_REASON_APIC_ACCESS] = handle_apic_access,
+   [EXIT_REASON_WBINVD]  = handle_wbinvd,
 };
 
 static const int kvm_vmx_max_exit_handlers =
diff --git a/drivers/kvm/vmx.h b/drivers/kvm/vmx.h
index 6d32bc6..d52ae8d 100644
--- a/drivers/kvm/vmx.h
+++ b/drivers/kvm/vmx.h
@@ -49,6 +49,7 @@
  * Definitions of Secondary Processor-Based VM-Execution Controls.
  */
 #define SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES 0x0001
+#define SECONDARY_EXEC_WBINVD_EXITING  0x0040
 
 
 #define PIN_BASED_EXT_INTR_MASK 0x0001
@@ -223,6 +224,7 @@ enum vmcs_field {
 #define EXIT_REASON_MWAIT_INSTRUCTION   36
 #define EXIT_REASON_TPR_BELOW_THRESHOLD 43
 #define EXIT_REASON_APIC_ACCESS 44
+#define EXIT_REASON_WBINVD 54
 
 /*
  * Interruption-information format
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 45/55] KVM: introduce gfn_to_hva()

2007-12-26 Thread Avi Kivity
From: Izik Eidus [EMAIL PROTECTED]

Convert a guest frame number to the corresponding host virtual address.

Signed-off-by: Izik Eidus [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c |   25 +
 1 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index e3c7f3b..d318c28 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -559,28 +559,37 @@ int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn)
 }
 EXPORT_SYMBOL_GPL(kvm_is_visible_gfn);
 
+static unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn)
+{
+   struct kvm_memory_slot *slot;
+
+   gfn = unalias_gfn(kvm, gfn);
+   slot = __gfn_to_memslot(kvm, gfn);
+   if (!slot)
+   return bad_hva();
+   return (slot-userspace_addr + (gfn - slot-base_gfn) * PAGE_SIZE);
+}
+
 /*
  * Requires current-mm-mmap_sem to be held
  */
 static struct page *__gfn_to_page(struct kvm *kvm, gfn_t gfn)
 {
-   struct kvm_memory_slot *slot;
struct page *page[1];
+   unsigned long addr;
int npages;
 
might_sleep();
 
-   gfn = unalias_gfn(kvm, gfn);
-   slot = __gfn_to_memslot(kvm, gfn);
-   if (!slot) {
+   addr = gfn_to_hva(kvm, gfn);
+   if (kvm_is_error_hva(addr)) {
get_page(bad_page);
return bad_page;
}
 
-   npages = get_user_pages(current, current-mm,
-   slot-userspace_addr
-   + (gfn - slot-base_gfn) * PAGE_SIZE, 1,
-   1, 1, page, NULL);
+   npages = get_user_pages(current, current-mm, addr, 1, 1, 1, page,
+   NULL);
+
if (npages != 1) {
get_page(bad_page);
return bad_page;
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 40/55] KVM: VMX: Comment VMX primary/secondary exec ctl definitions

2007-12-26 Thread Avi Kivity
From: Eddie Dong [EMAIL PROTECTED]

Add comments for secondary/primary Processor-Based VM-execution controls.

Signed-off-by: Yaozu (Eddie) Dong [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/vmx.h |   10 --
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/kvm/vmx.h b/drivers/kvm/vmx.h
index d757b36..6d32bc6 100644
--- a/drivers/kvm/vmx.h
+++ b/drivers/kvm/vmx.h
@@ -25,6 +25,9 @@
  *
  */
 
+/*
+ * Definitions of Primary Processor-Based VM-Execution Controls.
+ */
 #define CPU_BASED_VIRTUAL_INTR_PENDING  0x0004
 #define CPU_BASED_USE_TSC_OFFSETING 0x0008
 #define CPU_BASED_HLT_EXITING   0x0080
@@ -42,6 +45,11 @@
 #define CPU_BASED_MONITOR_EXITING   0x2000
 #define CPU_BASED_PAUSE_EXITING 0x4000
 #define CPU_BASED_ACTIVATE_SECONDARY_CONTROLS   0x8000
+/*
+ * Definitions of Secondary Processor-Based VM-Execution Controls.
+ */
+#define SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES 0x0001
+
 
 #define PIN_BASED_EXT_INTR_MASK 0x0001
 #define PIN_BASED_NMI_EXITING   0x0008
@@ -54,8 +62,6 @@
 #define VM_ENTRY_SMM0x0400
 #define VM_ENTRY_DEACT_DUAL_MONITOR 0x0800
 
-#define SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES 0x0001
-
 /* VMCS Encodings */
 enum vmcs_field {
GUEST_ES_SELECTOR   = 0x0800,
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 39/55] KVM: Fix faults during injection of real-mode interrupts

2007-12-26 Thread Avi Kivity
If vmx fails to inject a real-mode interrupt while fetching the interrupt
redirection table, it fails to record this in the vectoring information
field.  So we detect this condition and do it ourselves.

Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/vmx.c |   51 +--
 1 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index bde2d07..63c230d 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -65,7 +65,13 @@ struct vcpu_vmx {
int   fs_reload_needed;
int   guest_efer_loaded;
} host_state;
-
+   struct {
+   struct {
+   bool pending;
+   u8 vector;
+   unsigned rip;
+   } irq;
+   } rmode;
 };
 
 static inline struct vcpu_vmx *to_vmx(struct kvm_vcpu *vcpu)
@@ -1713,11 +1719,16 @@ out:
 
 static void vmx_inject_irq(struct kvm_vcpu *vcpu, int irq)
 {
+   struct vcpu_vmx *vmx = to_vmx(vcpu);
+
if (vcpu-rmode.active) {
+   vmx-rmode.irq.pending = true;
+   vmx-rmode.irq.vector = irq;
+   vmx-rmode.irq.rip = vmcs_readl(GUEST_RIP);
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
 irq | INTR_TYPE_SOFT_INTR | INTR_INFO_VALID_MASK);
vmcs_write32(VM_ENTRY_INSTRUCTION_LEN, 1);
-   vmcs_writel(GUEST_RIP, vmcs_readl(GUEST_RIP) - 1);
+   vmcs_writel(GUEST_RIP, vmx-rmode.irq.rip - 1);
return;
}
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
@@ -2251,6 +2262,17 @@ static void vmx_intr_assist(struct kvm_vcpu *vcpu)
return;
}
if (unlikely(idtv_info_field  INTR_INFO_VALID_MASK)) {
+   if ((idtv_info_field  VECTORING_INFO_TYPE_MASK)
+   == INTR_TYPE_EXT_INTR
+vcpu-rmode.active) {
+   u8 vect = idtv_info_field  VECTORING_INFO_VECTOR_MASK;
+
+   vmx_inject_irq(vcpu, vect);
+   if (unlikely(has_ext_irq))
+   enable_irq_window(vcpu);
+   return;
+   }
+
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, idtv_info_field);
vmcs_write32(VM_ENTRY_INSTRUCTION_LEN,
vmcs_read32(VM_EXIT_INSTRUCTION_LEN));
@@ -2275,6 +2297,29 @@ static void vmx_intr_assist(struct kvm_vcpu *vcpu)
enable_irq_window(vcpu);
 }
 
+/*
+ * Failure to inject an interrupt should give us the information
+ * in IDT_VECTORING_INFO_FIELD.  However, if the failure occurs
+ * when fetching the interrupt redirection bitmap in the real-mode
+ * tss, this doesn't happen.  So we do it ourselves.
+ */
+static void fixup_rmode_irq(struct vcpu_vmx *vmx)
+{
+   vmx-rmode.irq.pending = 0;
+   if (vmcs_readl(GUEST_RIP) + 1 != vmx-rmode.irq.rip)
+   return;
+   vmcs_writel(GUEST_RIP, vmx-rmode.irq.rip);
+   if (vmx-idt_vectoring_info  VECTORING_INFO_VALID_MASK) {
+   vmx-idt_vectoring_info = ~VECTORING_INFO_TYPE_MASK;
+   vmx-idt_vectoring_info |= INTR_TYPE_EXT_INTR;
+   return;
+   }
+   vmx-idt_vectoring_info =
+   VECTORING_INFO_VALID_MASK
+   | INTR_TYPE_EXT_INTR
+   | vmx-rmode.irq.vector;
+}
+
 static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 {
struct vcpu_vmx *vmx = to_vmx(vcpu);
@@ -2401,6 +2446,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
  );
 
vmx-idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
+   if (vmx-rmode.irq.pending)
+   fixup_rmode_irq(vmx);
 
vcpu-interrupt_window_open =
(vmcs_read32(GUEST_INTERRUPTIBILITY_INFO)  3) == 0;
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 42/55] KVM: x86 emulator: remove 8 bytes operands emulator for call near instruction

2007-12-26 Thread Avi Kivity
From: Izik Eidus [EMAIL PROTECTED]

it is removed beacuse it isnt supported on a real host

Signed-off-by: Izik Eidus [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/x86_emulate.c |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index 64888a6..e697947 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -1558,9 +1558,6 @@ special_insn:
case 4:
rel = insn_fetch(s32, 4, c-eip);
break;
-   case 8:
-   rel = insn_fetch(s64, 8, c-eip);
-   break;
default:
DPRINTF(Call: Invalid op_bytes\n);
goto cannot_emulate;
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 18/55] KVM: Portability: Split kvm_vm_ioctl v3

2007-12-26 Thread Avi Kivity
From: Carsten Otte [EMAIL PROTECTED]

This patch splits kvm_vm_ioctl into archtecture independent parts, and
x86 specific parts which go to kvm_arch_vcpu_ioctl in x86.c.
The patch is unchanged since last submission.

Common ioctls for all architectures are:
KVM_CREATE_VCPU, KVM_GET_DIRTY_LOG, KVM_SET_USER_MEMORY_REGION

x86 specific ioctls are:
KVM_SET_MEMORY_REGION,
KVM_GET/SET_NR_MMU_PAGES, KVM_SET_MEMORY_ALIAS, KVM_CREATE_IRQCHIP,
KVM_CREATE_IRQ_LINE, KVM_GET/SET_IRQCHIP
KVM_SET_TSS_ADDR

Signed-off-by: Carsten Otte [EMAIL PROTECTED]
Reviewed-by: Christian Borntraeger [EMAIL PROTECTED]
Acked-by: Hollis Blanchard [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |7 ++
 drivers/kvm/kvm_main.c |  255 +--
 drivers/kvm/x86.c  |  258 
 3 files changed, 271 insertions(+), 249 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 3d07d9b..516f79f 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -620,6 +620,13 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 unsigned int ioctl, unsigned long arg);
 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
+int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
+  struct
+  kvm_userspace_memory_region *mem,
+  int user_alloc);
+long kvm_arch_vm_ioctl(struct file *filp,
+  unsigned int ioctl, unsigned long arg);
+void kvm_arch_destroy_vm(struct kvm *kvm);
 
 __init void kvm_arch_init(void);
 
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 26a6399..9c0175d 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -792,36 +792,16 @@ out:
 }
 EXPORT_SYMBOL_GPL(kvm_set_memory_region);
 
-static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
- struct
- kvm_userspace_memory_region *mem,
- int user_alloc)
+int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
+  struct
+  kvm_userspace_memory_region *mem,
+  int user_alloc)
 {
if (mem-slot = KVM_MEMORY_SLOTS)
return -EINVAL;
return kvm_set_memory_region(kvm, mem, user_alloc);
 }
 
-static int kvm_vm_ioctl_set_nr_mmu_pages(struct kvm *kvm,
- u32 kvm_nr_mmu_pages)
-{
-   if (kvm_nr_mmu_pages  KVM_MIN_ALLOC_MMU_PAGES)
-   return -EINVAL;
-
-   mutex_lock(kvm-lock);
-
-   kvm_mmu_change_mmu_pages(kvm, kvm_nr_mmu_pages);
-   kvm-n_requested_mmu_pages = kvm_nr_mmu_pages;
-
-   mutex_unlock(kvm-lock);
-   return 0;
-}
-
-static int kvm_vm_ioctl_get_nr_mmu_pages(struct kvm *kvm)
-{
-   return kvm-n_alloc_mmu_pages;
-}
-
 /*
  * Get (and clear) the dirty memory log for a memory slot.
  */
@@ -867,111 +847,6 @@ out:
return r;
 }
 
-/*
- * Set a new alias region.  Aliases map a portion of physical memory into
- * another portion.  This is useful for memory windows, for example the PC
- * VGA region.
- */
-static int kvm_vm_ioctl_set_memory_alias(struct kvm *kvm,
-struct kvm_memory_alias *alias)
-{
-   int r, n;
-   struct kvm_mem_alias *p;
-
-   r = -EINVAL;
-   /* General sanity checks */
-   if (alias-memory_size  (PAGE_SIZE - 1))
-   goto out;
-   if (alias-guest_phys_addr  (PAGE_SIZE - 1))
-   goto out;
-   if (alias-slot = KVM_ALIAS_SLOTS)
-   goto out;
-   if (alias-guest_phys_addr + alias-memory_size
-alias-guest_phys_addr)
-   goto out;
-   if (alias-target_phys_addr + alias-memory_size
-alias-target_phys_addr)
-   goto out;
-
-   mutex_lock(kvm-lock);
-
-   p = kvm-aliases[alias-slot];
-   p-base_gfn = alias-guest_phys_addr  PAGE_SHIFT;
-   p-npages = alias-memory_size  PAGE_SHIFT;
-   p-target_gfn = alias-target_phys_addr  PAGE_SHIFT;
-
-   for (n = KVM_ALIAS_SLOTS; n  0; --n)
-   if (kvm-aliases[n - 1].npages)
-   break;
-   kvm-naliases = n;
-
-   kvm_mmu_zap_all(kvm);
-
-   mutex_unlock(kvm-lock);
-
-   return 0;
-
-out:
-   return r;
-}
-
-static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
-{
-   int r;
-
-   r = 0;
-   switch (chip-chip_id) {
-   case KVM_IRQCHIP_PIC_MASTER:
-   memcpy(chip-chip.pic,
-   pic_irqchip(kvm)-pics[0],
-   sizeof(struct kvm_pic_state));
-   break;
-   case KVM_IRQCHIP_PIC_SLAVE:
-   memcpy(chip-chip.pic,
-   

[kvm-devel] [PATCH 15/55] KVM: x86 emulator: don't depend on cr2 for mov abs emulation

2007-12-26 Thread Avi Kivity
The 'mov abs' instruction family (opcodes 0xa0 - 0xa3) still depends on cr2
provided by the page fault handler.  This is wrong for several reasons:

- if an instruction accessed misaligned data that crosses a page boundary,
  and if the fault happened on the second page, cr2 will point at the
  second page, not the data itself.

- if we're emulating in real mode, or due to a FlexPriority exit, there
  is no cr2 generated.

So, this change adds decoding for this instruction form and drops reliance
on cr2.

Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/x86_emulate.c |   50 +++--
 1 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index 73e3580..087a820 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -63,8 +63,9 @@
 /* Destination is only written; never read. */
 #define Mov (17)
 #define BitOp   (18)
+#define MemAbs  (19)  /* Memory operand is absolute displacement */
 
-static u8 opcode_table[256] = {
+static u16 opcode_table[256] = {
/* 0x00 - 0x07 */
ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
@@ -134,8 +135,8 @@ static u8 opcode_table[256] = {
/* 0x90 - 0x9F */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ImplicitOps, ImplicitOps, 0, 0,
/* 0xA0 - 0xA7 */
-   ByteOp | DstReg | SrcMem | Mov, DstReg | SrcMem | Mov,
-   ByteOp | DstMem | SrcReg | Mov, DstMem | SrcReg | Mov,
+   ByteOp | DstReg | SrcMem | Mov | MemAbs, DstReg | SrcMem | Mov | MemAbs,
+   ByteOp | DstMem | SrcReg | Mov | MemAbs, DstMem | SrcReg | Mov | MemAbs,
ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
ByteOp | ImplicitOps, ImplicitOps,
/* 0xA8 - 0xAF */
@@ -755,16 +756,6 @@ done_prefixes:
break;
}
}
-   if (!c-override_base)
-   c-override_base = ctxt-ds_base;
-   if (mode == X86EMUL_MODE_PROT64 
-   c-override_base != ctxt-fs_base 
-   c-override_base != ctxt-gs_base)
-   c-override_base = NULL;
-
-   if (c-override_base)
-   c-modrm_ea += *c-override_base;
-
if (rip_relative) {
c-modrm_ea += c-eip;
switch (c-d  SrcMask) {
@@ -781,12 +772,35 @@ done_prefixes:
c-modrm_ea += c-op_bytes;
}
}
-   if (c-ad_bytes != 8)
-   c-modrm_ea = (u32)c-modrm_ea;
 modrm_done:
;
+   } else if (c-d  MemAbs) {
+   switch (c-ad_bytes) {
+   case 2:
+   c-modrm_ea = insn_fetch(u16, 2, c-eip);
+   break;
+   case 4:
+   c-modrm_ea = insn_fetch(u32, 4, c-eip);
+   break;
+   case 8:
+   c-modrm_ea = insn_fetch(u64, 8, c-eip);
+   break;
+   }
+
}
 
+   if (!c-override_base)
+   c-override_base = ctxt-ds_base;
+   if (mode == X86EMUL_MODE_PROT64 
+   c-override_base != ctxt-fs_base 
+   c-override_base != ctxt-gs_base)
+   c-override_base = NULL;
+
+   if (c-override_base)
+   c-modrm_ea += *c-override_base;
+
+   if (c-ad_bytes != 8)
+   c-modrm_ea = (u32)c-modrm_ea;
/*
 * Decode and fetch the source operand: register, memory
 * or immediate.
@@ -1171,7 +1185,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct 
x86_emulate_ops *ops)
memcpy(c-regs, ctxt-vcpu-regs, sizeof c-regs);
saved_eip = c-eip;
 
-   if ((c-d  ModRM)  (c-modrm_mod != 3))
+   if (((c-d  ModRM)  (c-modrm_mod != 3)) || (c-d  MemAbs))
cr2 = c-modrm_ea;
 
if (c-src.type == OP_MEM) {
@@ -1326,13 +1340,9 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct 
x86_emulate_ops *ops)
case 0xa0 ... 0xa1: /* mov */
c-dst.ptr = (unsigned long *)c-regs[VCPU_REGS_RAX];
c-dst.val = c-src.val;
-   /* skip src displacement */
-   c-eip += c-ad_bytes;
break;
case 0xa2 ... 0xa3: /* mov */
c-dst.val = (unsigned long)c-regs[VCPU_REGS_RAX];
-   /* skip c-dst displacement */
-   c-eip += c-ad_bytes;
break;
case 0xc0 ... 0xc1:
emulate_grp2(ctxt);
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/

[kvm-devel] [PATCH 21/55] KVM: Portability: Move control register helper functions to x86.c

2007-12-26 Thread Avi Kivity
From: Carsten Otte [EMAIL PROTECTED]

This patch moves the definitions of CR0_RESERVED_BITS,
CR4_RESERVED_BITS, and CR8_RESERVED_BITS along with the following
functions from kvm_main.c to x86.c:
set_cr0(), set_cr3(), set_cr4(), set_cr8(), get_cr8(), lmsw(),
load_pdptrs()
The static function wrapper inject_gp is duplicated in kvm_main.c and
x86.c for now, the version in kvm_main.c should disappear once the last
user of it is gone too.
The function load_pdptrs is no longer static, and now defined in x86.h
for the time being, until the last user of it is gone from kvm_main.c.

Signed-off-by: Carsten Otte [EMAIL PROTECTED]
Reviewed-by: Christian Borntraeger [EMAIL PROTECTED]
Acked-by: Hollis Blanchard [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c |  219 --
 drivers/kvm/x86.c  |  224 
 drivers/kvm/x86.h  |2 +-
 3 files changed, 225 insertions(+), 220 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index d6545a7..af4b470 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -90,17 +90,6 @@ static struct kvm_stats_debugfs_item {
 
 static struct dentry *debugfs_dir;
 
-#define CR0_RESERVED_BITS  \
-   (~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \
- | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM \
- | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
-#define CR4_RESERVED_BITS  \
-   (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
- | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
- | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR  \
- | X86_CR4_OSXMMEXCPT | X86_CR4_VMXE))
-
-#define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)
 #define EFER_RESERVED_BITS 0xf2fe
 
 static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
@@ -348,214 +337,6 @@ static void inject_gp(struct kvm_vcpu *vcpu)
kvm_x86_ops-inject_gp(vcpu, 0);
 }
 
-/*
- * Load the pae pdptrs.  Return true is they are all valid.
- */
-static int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3)
-{
-   gfn_t pdpt_gfn = cr3  PAGE_SHIFT;
-   unsigned offset = ((cr3  (PAGE_SIZE-1))  5)  2;
-   int i;
-   int ret;
-   u64 pdpte[ARRAY_SIZE(vcpu-pdptrs)];
-
-   mutex_lock(vcpu-kvm-lock);
-   ret = kvm_read_guest_page(vcpu-kvm, pdpt_gfn, pdpte,
- offset * sizeof(u64), sizeof(pdpte));
-   if (ret  0) {
-   ret = 0;
-   goto out;
-   }
-   for (i = 0; i  ARRAY_SIZE(pdpte); ++i) {
-   if ((pdpte[i]  1)  (pdpte[i]  0xfff001e6ull)) {
-   ret = 0;
-   goto out;
-   }
-   }
-   ret = 1;
-
-   memcpy(vcpu-pdptrs, pdpte, sizeof(vcpu-pdptrs));
-out:
-   mutex_unlock(vcpu-kvm-lock);
-
-   return ret;
-}
-
-void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
-{
-   if (cr0  CR0_RESERVED_BITS) {
-   printk(KERN_DEBUG set_cr0: 0x%lx #GP, reserved bits 0x%lx\n,
-  cr0, vcpu-cr0);
-   inject_gp(vcpu);
-   return;
-   }
-
-   if ((cr0  X86_CR0_NW)  !(cr0  X86_CR0_CD)) {
-   printk(KERN_DEBUG set_cr0: #GP, CD == 0  NW == 1\n);
-   inject_gp(vcpu);
-   return;
-   }
-
-   if ((cr0  X86_CR0_PG)  !(cr0  X86_CR0_PE)) {
-   printk(KERN_DEBUG set_cr0: #GP, set PG flag 
-  and a clear PE flag\n);
-   inject_gp(vcpu);
-   return;
-   }
-
-   if (!is_paging(vcpu)  (cr0  X86_CR0_PG)) {
-#ifdef CONFIG_X86_64
-   if ((vcpu-shadow_efer  EFER_LME)) {
-   int cs_db, cs_l;
-
-   if (!is_pae(vcpu)) {
-   printk(KERN_DEBUG set_cr0: #GP, start paging 
-  in long mode while PAE is disabled\n);
-   inject_gp(vcpu);
-   return;
-   }
-   kvm_x86_ops-get_cs_db_l_bits(vcpu, cs_db, cs_l);
-   if (cs_l) {
-   printk(KERN_DEBUG set_cr0: #GP, start paging 
-  in long mode while CS.L == 1\n);
-   inject_gp(vcpu);
-   return;
-
-   }
-   } else
-#endif
-   if (is_pae(vcpu)  !load_pdptrs(vcpu, vcpu-cr3)) {
-   printk(KERN_DEBUG set_cr0: #GP, pdptrs 
-  reserved bits\n);
-   inject_gp(vcpu);
-   return;
- 

[kvm-devel] [PATCH 36/55] KVM: Add make_page_dirty() to kvm_clear_guest_page()

2007-12-26 Thread Avi Kivity
From: Dor Laor [EMAIL PROTECTED]

Every write access to guest pages should be tracked.

Signed-off-by: Dor Laor [EMAIL PROTECTED]
Signed-off-by: Izik Eidus [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index e12bdc1..302473d 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -706,6 +706,7 @@ int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int 
offset, int len)
 
kunmap_atomic(page_virt, KM_USER0);
kvm_release_page(page);
+   mark_page_dirty(kvm, gfn);
return 0;
 }
 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 26/55] KVM: Portability: Move pio emulation functions to x86.c

2007-12-26 Thread Avi Kivity
From: Carsten Otte [EMAIL PROTECTED]

This patch moves implementation of the following functions from
kvm_main.c to x86.c:
free_pio_guest_pages, vcpu_find_pio_dev, pio_copy_data, complete_pio,
kernel_pio, pio_string_write, kvm_emulate_pio, kvm_emulate_pio_string

The function inject_gp, which was duplicated by yesterday's patch
series, is removed from kvm_main.c now because it is not needed anymore.

Signed-off-by: Carsten Otte [EMAIL PROTECTED]
Acked-by: Hollis Blanchard [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c |  248 
 drivers/kvm/x86.c  |  243 +++
 drivers/kvm/x86.h  |1 +
 3 files changed, 244 insertions(+), 248 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 2c5529c..27f3a6e 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -271,17 +271,6 @@ static void kvm_free_physmem(struct kvm *kvm)
kvm_free_physmem_slot(kvm-memslots[i], NULL);
 }
 
-static void free_pio_guest_pages(struct kvm_vcpu *vcpu)
-{
-   int i;
-
-   for (i = 0; i  ARRAY_SIZE(vcpu-pio.guest_pages); ++i)
-   if (vcpu-pio.guest_pages[i]) {
-   kvm_release_page(vcpu-pio.guest_pages[i]);
-   vcpu-pio.guest_pages[i] = NULL;
-   }
-}
-
 static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu)
 {
vcpu_load(vcpu);
@@ -330,11 +319,6 @@ static int kvm_vm_release(struct inode *inode, struct file 
*filp)
return 0;
 }
 
-static void inject_gp(struct kvm_vcpu *vcpu)
-{
-   kvm_x86_ops-inject_gp(vcpu, 0);
-}
-
 void fx_init(struct kvm_vcpu *vcpu)
 {
unsigned after_mxcsr_mask;
@@ -827,12 +811,6 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn)
}
 }
 
-static struct kvm_io_device *vcpu_find_pio_dev(struct kvm_vcpu *vcpu,
-  gpa_t addr)
-{
-   return kvm_io_bus_find_dev(vcpu-kvm-pio_bus, addr);
-}
-
 /*
  * The vCPU has executed a HLT instruction with in-kernel mode enabled.
  */
@@ -1042,232 +1020,6 @@ void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)
 }
 EXPORT_SYMBOL_GPL(kvm_emulate_cpuid);
 
-static int pio_copy_data(struct kvm_vcpu *vcpu)
-{
-   void *p = vcpu-pio_data;
-   void *q;
-   unsigned bytes;
-   int nr_pages = vcpu-pio.guest_pages[1] ? 2 : 1;
-
-   q = vmap(vcpu-pio.guest_pages, nr_pages, VM_READ|VM_WRITE,
-PAGE_KERNEL);
-   if (!q) {
-   free_pio_guest_pages(vcpu);
-   return -ENOMEM;
-   }
-   q += vcpu-pio.guest_page_offset;
-   bytes = vcpu-pio.size * vcpu-pio.cur_count;
-   if (vcpu-pio.in)
-   memcpy(q, p, bytes);
-   else
-   memcpy(p, q, bytes);
-   q -= vcpu-pio.guest_page_offset;
-   vunmap(q);
-   free_pio_guest_pages(vcpu);
-   return 0;
-}
-
-static int complete_pio(struct kvm_vcpu *vcpu)
-{
-   struct kvm_pio_request *io = vcpu-pio;
-   long delta;
-   int r;
-
-   kvm_x86_ops-cache_regs(vcpu);
-
-   if (!io-string) {
-   if (io-in)
-   memcpy(vcpu-regs[VCPU_REGS_RAX], vcpu-pio_data,
-  io-size);
-   } else {
-   if (io-in) {
-   r = pio_copy_data(vcpu);
-   if (r) {
-   kvm_x86_ops-cache_regs(vcpu);
-   return r;
-   }
-   }
-
-   delta = 1;
-   if (io-rep) {
-   delta *= io-cur_count;
-   /*
-* The size of the register should really depend on
-* current address size.
-*/
-   vcpu-regs[VCPU_REGS_RCX] -= delta;
-   }
-   if (io-down)
-   delta = -delta;
-   delta *= io-size;
-   if (io-in)
-   vcpu-regs[VCPU_REGS_RDI] += delta;
-   else
-   vcpu-regs[VCPU_REGS_RSI] += delta;
-   }
-
-   kvm_x86_ops-decache_regs(vcpu);
-
-   io-count -= io-cur_count;
-   io-cur_count = 0;
-
-   return 0;
-}
-
-static void kernel_pio(struct kvm_io_device *pio_dev,
-  struct kvm_vcpu *vcpu,
-  void *pd)
-{
-   /* TODO: String I/O for in kernel device */
-
-   mutex_lock(vcpu-kvm-lock);
-   if (vcpu-pio.in)
-   kvm_iodevice_read(pio_dev, vcpu-pio.port,
- vcpu-pio.size,
- pd);
-   else
-   kvm_iodevice_write(pio_dev, vcpu-pio.port,
-  vcpu-pio.size,
-  pd);
-   mutex_unlock(vcpu-kvm-lock);
-}
-
-static void pio_string_write(struct kvm_io_device 

[kvm-devel] [PATCH 44/55] KVM: add kvm_is_error_hva()

2007-12-26 Thread Avi Kivity
From: Izik Eidus [EMAIL PROTECTED]

Check for the error hva, an address outside the user address space that
signals a bad gfn.

Signed-off-by: Izik Eidus [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |1 +
 drivers/kvm/kvm_main.c |   11 +++
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 3f5ffc3..6498324 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -520,6 +520,7 @@ struct page *gva_to_page(struct kvm_vcpu *vcpu, gva_t gva);
 extern struct page *bad_page;
 
 int is_error_page(struct page *page);
+int kvm_is_error_hva(unsigned long addr);
 int kvm_set_memory_region(struct kvm *kvm,
  struct kvm_userspace_memory_region *mem,
  int user_alloc);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index dacdc66..e3c7f3b 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -498,6 +498,17 @@ int is_error_page(struct page *page)
 }
 EXPORT_SYMBOL_GPL(is_error_page);
 
+static inline unsigned long bad_hva(void)
+{
+   return PAGE_OFFSET;
+}
+
+int kvm_is_error_hva(unsigned long addr)
+{
+   return addr == bad_hva();
+}
+EXPORT_SYMBOL_GPL(kvm_is_error_hva);
+
 gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn)
 {
int i;
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 50/55] KVM: Portability: Combine kvm_init and kvm_init_x86

2007-12-26 Thread Avi Kivity
From: Zhang Xiantao [EMAIL PROTECTED]

Will be called once arch module registers itself.

Signed-off-by: Zhang Xiantao [EMAIL PROTECTED]
Acked-by: Carsten Otte [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |4 +-
 drivers/kvm/kvm_main.c |   61 +--
 drivers/kvm/svm.c  |4 +-
 drivers/kvm/vmx.c  |4 +-
 4 files changed, 28 insertions(+), 45 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index bca07c6..5e7be15 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -495,9 +495,9 @@ void vcpu_put(struct kvm_vcpu *vcpu);
 void decache_vcpus_on_cpu(int cpu);
 
 
-int kvm_init_x86(struct kvm_x86_ops *ops, unsigned int vcpu_size,
+int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size,
  struct module *module);
-void kvm_exit_x86(void);
+void kvm_exit(void);
 
 int kvm_mmu_module_init(void);
 void kvm_mmu_module_exit(void);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 2610046..510f2d1 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1434,12 +1434,27 @@ static void kvm_sched_out(struct preempt_notifier *pn,
kvm_arch_vcpu_put(vcpu);
 }
 
-int kvm_init_x86(struct kvm_x86_ops *ops, unsigned int vcpu_size,
+int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size,
  struct module *module)
 {
int r;
int cpu;
 
+   r = kvm_mmu_module_init();
+   if (r)
+   goto out4;
+
+   kvm_init_debug();
+
+   kvm_arch_init();
+
+   bad_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
+
+   if (bad_page == NULL) {
+   r = -ENOMEM;
+   goto out;
+   }
+
if (kvm_x86_ops) {
printk(KERN_ERR kvm: already loaded the other module\n);
return -EEXIST;
@@ -1520,11 +1535,14 @@ out_free_0:
kvm_arch_hardware_unsetup();
 out:
kvm_x86_ops = NULL;
+   kvm_exit_debug();
+   kvm_mmu_module_exit();
+out4:
return r;
 }
-EXPORT_SYMBOL_GPL(kvm_init_x86);
+EXPORT_SYMBOL_GPL(kvm_init);
 
-void kvm_exit_x86(void)
+void kvm_exit(void)
 {
misc_deregister(kvm_dev);
kmem_cache_destroy(kvm_vcpu_cache);
@@ -1535,43 +1553,8 @@ void kvm_exit_x86(void)
on_each_cpu(hardware_disable, NULL, 0, 1);
kvm_arch_hardware_unsetup();
kvm_x86_ops = NULL;
-}
-EXPORT_SYMBOL_GPL(kvm_exit_x86);
-
-static __init int kvm_init(void)
-{
-   int r;
-
-   r = kvm_mmu_module_init();
-   if (r)
-   goto out4;
-
-   kvm_init_debug();
-
-   kvm_arch_init();
-
-   bad_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
-
-   if (bad_page == NULL) {
-   r = -ENOMEM;
-   goto out;
-   }
-
-   return 0;
-
-out:
-   kvm_exit_debug();
-   kvm_mmu_module_exit();
-out4:
-   return r;
-}
-
-static __exit void kvm_exit(void)
-{
kvm_exit_debug();
__free_page(bad_page);
kvm_mmu_module_exit();
 }
-
-module_init(kvm_init)
-module_exit(kvm_exit)
+EXPORT_SYMBOL_GPL(kvm_exit);
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 991e77d..0f0958d 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -1723,13 +1723,13 @@ static struct kvm_x86_ops svm_x86_ops = {
 
 static int __init svm_init(void)
 {
-   return kvm_init_x86(svm_x86_ops, sizeof(struct vcpu_svm),
+   return kvm_init(svm_x86_ops, sizeof(struct vcpu_svm),
  THIS_MODULE);
 }
 
 static void __exit svm_exit(void)
 {
-   kvm_exit_x86();
+   kvm_exit();
 }
 
 module_init(svm_init)
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index ad16865..18fd918 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -2677,7 +2677,7 @@ static int __init vmx_init(void)
memset(iova, 0xff, PAGE_SIZE);
kunmap(vmx_io_bitmap_b);
 
-   r = kvm_init_x86(vmx_x86_ops, sizeof(struct vcpu_vmx), THIS_MODULE);
+   r = kvm_init(vmx_x86_ops, sizeof(struct vcpu_vmx), THIS_MODULE);
if (r)
goto out1;
 
@@ -2698,7 +2698,7 @@ static void __exit vmx_exit(void)
__free_page(vmx_io_bitmap_b);
__free_page(vmx_io_bitmap_a);
 
-   kvm_exit_x86();
+   kvm_exit();
 }
 
 module_init(vmx_init)
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 51/55] KVM: Portability: Move x86 specific code from kvm_init() to kvm_arch()

2007-12-26 Thread Avi Kivity
From: Zhang Xiantao [EMAIL PROTECTED]

Signed-off-by: Zhang Xiantao [EMAIL PROTECTED]
Acked-by: Carsten Otte [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |5 +++--
 drivers/kvm/kvm_main.c |   26 ++
 drivers/kvm/x86.c  |   27 ++-
 3 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 5e7be15..96d9c7d 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -495,7 +495,7 @@ void vcpu_put(struct kvm_vcpu *vcpu);
 void decache_vcpus_on_cpu(int cpu);
 
 
-int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size,
+int kvm_init(void *opaque, unsigned int vcpu_size,
  struct module *module);
 void kvm_exit(void);
 
@@ -649,7 +649,8 @@ int kvm_arch_vcpu_ioctl_debug_guest(struct kvm_vcpu *vcpu,
struct kvm_debug_guest *dbg);
 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
 
-__init void kvm_arch_init(void);
+int kvm_arch_init(void *opaque);
+void kvm_arch_exit(void);
 
 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
 void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 510f2d1..5d6d5d4 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1434,7 +1434,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
kvm_arch_vcpu_put(vcpu);
 }
 
-int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size,
+int kvm_init(void *opaque, unsigned int vcpu_size,
  struct module *module)
 {
int r;
@@ -1446,7 +1446,9 @@ int kvm_init(struct kvm_x86_ops *ops, unsigned int 
vcpu_size,
 
kvm_init_debug();
 
-   kvm_arch_init();
+   r = kvm_arch_init(opaque);
+   if (r)
+   goto out4;
 
bad_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
 
@@ -1455,22 +1457,6 @@ int kvm_init(struct kvm_x86_ops *ops, unsigned int 
vcpu_size,
goto out;
}
 
-   if (kvm_x86_ops) {
-   printk(KERN_ERR kvm: already loaded the other module\n);
-   return -EEXIST;
-   }
-
-   if (!ops-cpu_has_kvm_support()) {
-   printk(KERN_ERR kvm: no hardware support\n);
-   return -EOPNOTSUPP;
-   }
-   if (ops-disabled_by_bios()) {
-   printk(KERN_ERR kvm: disabled by bios\n);
-   return -EOPNOTSUPP;
-   }
-
-   kvm_x86_ops = ops;
-
r = kvm_arch_hardware_setup();
if (r  0)
goto out;
@@ -1534,7 +1520,7 @@ out_free_1:
 out_free_0:
kvm_arch_hardware_unsetup();
 out:
-   kvm_x86_ops = NULL;
+   kvm_arch_exit();
kvm_exit_debug();
kvm_mmu_module_exit();
 out4:
@@ -1552,7 +1538,7 @@ void kvm_exit(void)
unregister_cpu_notifier(kvm_cpu_notifier);
on_each_cpu(hardware_disable, NULL, 0, 1);
kvm_arch_hardware_unsetup();
-   kvm_x86_ops = NULL;
+   kvm_arch_exit();
kvm_exit_debug();
__free_page(bad_page);
kvm_mmu_module_exit();
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 4902b35..bbfa810 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -1645,11 +1645,36 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, 
struct kvm_run *run, int in,
 }
 EXPORT_SYMBOL_GPL(kvm_emulate_pio_string);
 
-__init void kvm_arch_init(void)
+int kvm_arch_init(void *opaque)
 {
+   struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
+
kvm_init_msr_list();
+
+   if (kvm_x86_ops) {
+   printk(KERN_ERR kvm: already loaded the other module\n);
+   return -EEXIST;
+   }
+
+   if (!ops-cpu_has_kvm_support()) {
+   printk(KERN_ERR kvm: no hardware support\n);
+   return -EOPNOTSUPP;
+   }
+   if (ops-disabled_by_bios()) {
+   printk(KERN_ERR kvm: disabled by bios\n);
+   return -EOPNOTSUPP;
+   }
+
+   kvm_x86_ops = ops;
+
+   return 0;
 }
 
+void kvm_arch_exit(void)
+{
+   kvm_x86_ops = NULL;
+ }
+
 int kvm_emulate_halt(struct kvm_vcpu *vcpu)
 {
++vcpu-stat.halt_exits;
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 25/55] KVM: Portability: Move x86 emulation and mmio device hook to x86.c

2007-12-26 Thread Avi Kivity
From: Carsten Otte [EMAIL PROTECTED]

This patch moves the following functions to from kvm_main.c to x86.c:
emulator_read/write_std, vcpu_find_pervcpu_dev, vcpu_find_mmio_dev,
emulator_read/write_emulated, emulator_write_phys,
emulator_write_emulated_onepage, emulator_cmpxchg_emulated,
get_setment_base, emulate_invlpg, emulate_clts, emulator_get/set_dr,
kvm_report_emulation_failure, emulate_instruction

The following data type is moved to x86.c:
struct x86_emulate_ops emulate_ops

Signed-off-by: Carsten Otte [EMAIL PROTECTED]
Acked-by: Hollis Blanchard [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c |  357 ---
 drivers/kvm/x86.c  |  358 
 2 files changed, 358 insertions(+), 357 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 5eccf27..2c5529c 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -827,369 +827,12 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn)
}
 }
 
-int emulator_read_std(unsigned long addr,
-void *val,
-unsigned int bytes,
-struct kvm_vcpu *vcpu)
-{
-   void *data = val;
-
-   while (bytes) {
-   gpa_t gpa = vcpu-mmu.gva_to_gpa(vcpu, addr);
-   unsigned offset = addr  (PAGE_SIZE-1);
-   unsigned tocopy = min(bytes, (unsigned)PAGE_SIZE - offset);
-   int ret;
-
-   if (gpa == UNMAPPED_GVA)
-   return X86EMUL_PROPAGATE_FAULT;
-   ret = kvm_read_guest(vcpu-kvm, gpa, data, tocopy);
-   if (ret  0)
-   return X86EMUL_UNHANDLEABLE;
-
-   bytes -= tocopy;
-   data += tocopy;
-   addr += tocopy;
-   }
-
-   return X86EMUL_CONTINUE;
-}
-EXPORT_SYMBOL_GPL(emulator_read_std);
-
-static int emulator_write_std(unsigned long addr,
- const void *val,
- unsigned int bytes,
- struct kvm_vcpu *vcpu)
-{
-   pr_unimpl(vcpu, emulator_write_std: addr %lx n %d\n, addr, bytes);
-   return X86EMUL_UNHANDLEABLE;
-}
-
-/*
- * Only apic need an MMIO device hook, so shortcut now..
- */
-static struct kvm_io_device *vcpu_find_pervcpu_dev(struct kvm_vcpu *vcpu,
-   gpa_t addr)
-{
-   struct kvm_io_device *dev;
-
-   if (vcpu-apic) {
-   dev = vcpu-apic-dev;
-   if (dev-in_range(dev, addr))
-   return dev;
-   }
-   return NULL;
-}
-
-static struct kvm_io_device *vcpu_find_mmio_dev(struct kvm_vcpu *vcpu,
-   gpa_t addr)
-{
-   struct kvm_io_device *dev;
-
-   dev = vcpu_find_pervcpu_dev(vcpu, addr);
-   if (dev == NULL)
-   dev = kvm_io_bus_find_dev(vcpu-kvm-mmio_bus, addr);
-   return dev;
-}
-
 static struct kvm_io_device *vcpu_find_pio_dev(struct kvm_vcpu *vcpu,
   gpa_t addr)
 {
return kvm_io_bus_find_dev(vcpu-kvm-pio_bus, addr);
 }
 
-static int emulator_read_emulated(unsigned long addr,
- void *val,
- unsigned int bytes,
- struct kvm_vcpu *vcpu)
-{
-   struct kvm_io_device *mmio_dev;
-   gpa_t gpa;
-
-   if (vcpu-mmio_read_completed) {
-   memcpy(val, vcpu-mmio_data, bytes);
-   vcpu-mmio_read_completed = 0;
-   return X86EMUL_CONTINUE;
-   }
-
-   gpa = vcpu-mmu.gva_to_gpa(vcpu, addr);
-
-   /* For APIC access vmexit */
-   if ((gpa  PAGE_MASK) == APIC_DEFAULT_PHYS_BASE)
-   goto mmio;
-
-   if (emulator_read_std(addr, val, bytes, vcpu)
-   == X86EMUL_CONTINUE)
-   return X86EMUL_CONTINUE;
-   if (gpa == UNMAPPED_GVA)
-   return X86EMUL_PROPAGATE_FAULT;
-
-mmio:
-   /*
-* Is this MMIO handled locally?
-*/
-   mmio_dev = vcpu_find_mmio_dev(vcpu, gpa);
-   if (mmio_dev) {
-   kvm_iodevice_read(mmio_dev, gpa, bytes, val);
-   return X86EMUL_CONTINUE;
-   }
-
-   vcpu-mmio_needed = 1;
-   vcpu-mmio_phys_addr = gpa;
-   vcpu-mmio_size = bytes;
-   vcpu-mmio_is_write = 0;
-
-   return X86EMUL_UNHANDLEABLE;
-}
-
-static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
-  const void *val, int bytes)
-{
-   int ret;
-
-   ret = kvm_write_guest(vcpu-kvm, gpa, val, bytes);
-   if (ret  0)
-   return 0;
-   kvm_mmu_pte_write(vcpu, gpa, val, bytes);
-   return 1;
-}
-
-static int emulator_write_emulated_onepage(unsigned long addr,
-  const void 

[kvm-devel] [PATCH 49/55] KVM: Portability: Add vcpu and hardware management arch hooks

2007-12-26 Thread Avi Kivity
From: Zhang Xiantao [EMAIL PROTECTED]

Add the following hooks:

  void decache_vcpus_on_cpu(int cpu);
  int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
  void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu);
  void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu);
  void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
  void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
  struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id);
  void kvm_arch_vcpu_destory(struct kvm_vcpu *vcpu);
  int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu);
  void kvm_arch_hardware_enable(void *garbage);
  void kvm_arch_hardware_disable(void *garbage);
  int kvm_arch_hardware_setup(void);
  void kvm_arch_hardware_unsetup(void);
  void kvm_arch_check_processor_compat(void *rtn);

Signed-off-by: Zhang Xiantao [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |   19 ++
 drivers/kvm/kvm_main.c |  113 ++-
 drivers/kvm/x86.c  |  157 
 drivers/kvm/x86.h  |3 +
 4 files changed, 197 insertions(+), 95 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 6498324..bca07c6 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -492,6 +492,8 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
 void vcpu_load(struct kvm_vcpu *vcpu);
 void vcpu_put(struct kvm_vcpu *vcpu);
 
+void decache_vcpus_on_cpu(int cpu);
+
 
 int kvm_init_x86(struct kvm_x86_ops *ops, unsigned int vcpu_size,
  struct module *module);
@@ -649,6 +651,23 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run);
 
 __init void kvm_arch_init(void);
 
+int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
+void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu);
+
+void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu);
+void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
+void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
+struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id);
+void kvm_arch_vcpu_destory(struct kvm_vcpu *vcpu);
+
+int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu);
+void kvm_arch_hardware_enable(void *garbage);
+void kvm_arch_hardware_disable(void *garbage);
+int kvm_arch_hardware_setup(void);
+void kvm_arch_hardware_unsetup(void);
+void kvm_arch_check_processor_compat(void *rtn);
+
+
 static inline void kvm_guest_enter(void)
 {
account_system_vtime(current);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 7808189..2610046 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -50,8 +50,8 @@
 MODULE_AUTHOR(Qumranet);
 MODULE_LICENSE(GPL);
 
-static DEFINE_SPINLOCK(kvm_lock);
-static LIST_HEAD(vm_list);
+DEFINE_SPINLOCK(kvm_lock);
+LIST_HEAD(vm_list);
 
 static cpumask_t cpus_hardware_enabled;
 
@@ -124,13 +124,8 @@ int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, 
unsigned id)
 
mutex_init(vcpu-mutex);
vcpu-cpu = -1;
-   vcpu-mmu.root_hpa = INVALID_PAGE;
vcpu-kvm = kvm;
vcpu-vcpu_id = id;
-   if (!irqchip_in_kernel(kvm) || id == 0)
-   vcpu-mp_state = VCPU_MP_STATE_RUNNABLE;
-   else
-   vcpu-mp_state = VCPU_MP_STATE_UNINITIALIZED;
init_waitqueue_head(vcpu-wq);
 
page = alloc_page(GFP_KERNEL | __GFP_ZERO);
@@ -140,29 +135,11 @@ int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, 
unsigned id)
}
vcpu-run = page_address(page);
 
-   page = alloc_page(GFP_KERNEL | __GFP_ZERO);
-   if (!page) {
-   r = -ENOMEM;
-   goto fail_free_run;
-   }
-   vcpu-pio_data = page_address(page);
-
-   r = kvm_mmu_create(vcpu);
+   r = kvm_arch_vcpu_init(vcpu);
if (r  0)
-   goto fail_free_pio_data;
-
-   if (irqchip_in_kernel(kvm)) {
-   r = kvm_create_lapic(vcpu);
-   if (r  0)
-   goto fail_mmu_destroy;
-   }
-
+   goto fail_free_run;
return 0;
 
-fail_mmu_destroy:
-   kvm_mmu_destroy(vcpu);
-fail_free_pio_data:
-   free_page((unsigned long)vcpu-pio_data);
 fail_free_run:
free_page((unsigned long)vcpu-run);
 fail:
@@ -172,9 +149,7 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_init);
 
 void kvm_vcpu_uninit(struct kvm_vcpu *vcpu)
 {
-   kvm_free_lapic(vcpu);
-   kvm_mmu_destroy(vcpu);
-   free_page((unsigned long)vcpu-pio_data);
+   kvm_arch_vcpu_uninit(vcpu);
free_page((unsigned long)vcpu-run);
 }
 EXPORT_SYMBOL_GPL(kvm_vcpu_uninit);
@@ -240,7 +215,7 @@ static void kvm_free_vcpus(struct kvm *kvm)
kvm_unload_vcpu_mmu(kvm-vcpus[i]);
for (i = 0; i  KVM_MAX_VCPUS; ++i) {
if (kvm-vcpus[i]) {
-   kvm_x86_ops-vcpu_free(kvm-vcpus[i]);
+   kvm_arch_vcpu_free(kvm-vcpus[i]);
kvm-vcpus[i] = NULL;
}
}
@@ -900,28 +875,17 @@ static int 

[kvm-devel] [PATCH 05/55] KVM: Split IOAPIC reset function and export for kernel RESET

2007-12-26 Thread Avi Kivity
From: Eddie Dong [EMAIL PROTECTED]

Signed-off-by: Yaozu (Eddie) Dong [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/ioapic.c |   17 +
 drivers/kvm/irq.h|1 +
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/kvm/ioapic.c b/drivers/kvm/ioapic.c
index e14b7c7..cf1d50b 100644
--- a/drivers/kvm/ioapic.c
+++ b/drivers/kvm/ioapic.c
@@ -371,18 +371,27 @@ static void ioapic_mmio_write(struct kvm_io_device *this, 
gpa_t addr, int len,
}
 }
 
+void kvm_ioapic_reset(struct kvm_ioapic *ioapic)
+{
+   int i;
+
+   for (i = 0; i  IOAPIC_NUM_PINS; i++)
+   ioapic-redirtbl[i].fields.mask = 1;
+   ioapic-base_address = IOAPIC_DEFAULT_BASE_ADDRESS;
+   ioapic-ioregsel = 0;
+   ioapic-irr = 0;
+   ioapic-id = 0;
+}
+
 int kvm_ioapic_init(struct kvm *kvm)
 {
struct kvm_ioapic *ioapic;
-   int i;
 
ioapic = kzalloc(sizeof(struct kvm_ioapic), GFP_KERNEL);
if (!ioapic)
return -ENOMEM;
kvm-vioapic = ioapic;
-   for (i = 0; i  IOAPIC_NUM_PINS; i++)
-   ioapic-redirtbl[i].fields.mask = 1;
-   ioapic-base_address = IOAPIC_DEFAULT_BASE_ADDRESS;
+   kvm_ioapic_reset(ioapic);
ioapic-dev.read = ioapic_mmio_read;
ioapic-dev.write = ioapic_mmio_write;
ioapic-dev.in_range = ioapic_in_range;
diff --git a/drivers/kvm/irq.h b/drivers/kvm/irq.h
index e08ae10..5ad3cfd 100644
--- a/drivers/kvm/irq.h
+++ b/drivers/kvm/irq.h
@@ -140,6 +140,7 @@ int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu);
 int kvm_create_lapic(struct kvm_vcpu *vcpu);
 void kvm_lapic_reset(struct kvm_vcpu *vcpu);
 void kvm_pic_reset(struct kvm_kpic_state *s);
+void kvm_ioapic_reset(struct kvm_ioapic *ioapic);
 void kvm_free_lapic(struct kvm_vcpu *vcpu);
 u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu);
 void kvm_lapic_set_tpr(struct kvm_vcpu *vcpu, unsigned long cr8);
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] README: How to run kvm guests on IA64

2007-12-26 Thread Akio Takebe
Hi, Xiantao

Akio Takebe wrote:
 Hi, Xiantao
 
 Akio Takebe wrote:
 Hi,
 
 Run guests with the command :
 /usr/local/bin/qemu-system-ia64 -hda your.img -m 512
 
 If you have any question, please feel free to contact me!
 Can I use the guest image of Xen?
 Or do I need to clean-install Linux or Windows on KVM guest?
 Hi, Akio
 Thank you for your try!
 In addition, If you want to boot windows up on Open GFW, you also
 need to pick up the patch I sent to xen-ia64 mailing list, and built
 it with latest efi-vfirmware.hg source.
 I attached it in this mail.
 Thank you. Your README doesn't explain about GFW.
 How do we specify GFW as qemu's option?
 Or must we put GFW in somewhere?

I will update to kvm wiki.  We should put GFW named as Flash.fd to
/usr/local/share/qemu/ :) 
Thank you for your advice.
Although I may still have some wrong steps,
I can boot up RHEL5.1 guest on kvm-ia64. :)
It works fine now!

Best Regards,

Akio Takebe


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 34/55] KVM: Portability: Move x86 FPU handling to x86.c

2007-12-26 Thread Avi Kivity
From: Hollis Blanchard [EMAIL PROTECTED]

Signed-off-by: Hollis Blanchard [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |3 +
 drivers/kvm/kvm_main.c |  107 +---
 drivers/kvm/x86.c  |  103 ++
 3 files changed, 108 insertions(+), 105 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index ef2a6a8..469ca42 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -633,6 +633,9 @@ long kvm_arch_vm_ioctl(struct file *filp,
   unsigned int ioctl, unsigned long arg);
 void kvm_arch_destroy_vm(struct kvm *kvm);
 
+int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
+int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
+
 __init void kvm_arch_init(void);
 
 static inline void kvm_guest_enter(void)
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index a779d42..4620885 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -73,28 +73,6 @@ static inline int valid_vcpu(int n)
return likely(n = 0  n  KVM_MAX_VCPUS);
 }
 
-void kvm_load_guest_fpu(struct kvm_vcpu *vcpu)
-{
-   if (!vcpu-fpu_active || vcpu-guest_fpu_loaded)
-   return;
-
-   vcpu-guest_fpu_loaded = 1;
-   fx_save(vcpu-host_fx_image);
-   fx_restore(vcpu-guest_fx_image);
-}
-EXPORT_SYMBOL_GPL(kvm_load_guest_fpu);
-
-void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
-{
-   if (!vcpu-guest_fpu_loaded)
-   return;
-
-   vcpu-guest_fpu_loaded = 0;
-   fx_save(vcpu-guest_fx_image);
-   fx_restore(vcpu-host_fx_image);
-}
-EXPORT_SYMBOL_GPL(kvm_put_guest_fpu);
-
 /*
  * Switches to specified vcpu, until a matching vcpu_put()
  */
@@ -294,26 +272,6 @@ static int kvm_vm_release(struct inode *inode, struct file 
*filp)
return 0;
 }
 
-void fx_init(struct kvm_vcpu *vcpu)
-{
-   unsigned after_mxcsr_mask;
-
-   /* Initialize guest FPU by resetting ours and saving into guest's */
-   preempt_disable();
-   fx_save(vcpu-host_fx_image);
-   fpu_init();
-   fx_save(vcpu-guest_fx_image);
-   fx_restore(vcpu-host_fx_image);
-   preempt_enable();
-
-   vcpu-cr0 |= X86_CR0_ET;
-   after_mxcsr_mask = offsetof(struct i387_fxsave_struct, st_space);
-   vcpu-guest_fx_image.mxcsr = 0x1f80;
-   memset((void *)vcpu-guest_fx_image + after_mxcsr_mask,
-  0, sizeof(struct i387_fxsave_struct) - after_mxcsr_mask);
-}
-EXPORT_SYMBOL_GPL(fx_init);
-
 /*
  * Allocate some memory and give it an address in the guest physical address
  * space.
@@ -1422,67 +1380,6 @@ static int kvm_vcpu_ioctl_set_sigmask(struct kvm_vcpu 
*vcpu, sigset_t *sigset)
return 0;
 }
 
-/*
- * fxsave fpu state.  Taken from x86_64/processor.h.  To be killed when
- * we have asm/x86/processor.h
- */
-struct fxsave {
-   u16 cwd;
-   u16 swd;
-   u16 twd;
-   u16 fop;
-   u64 rip;
-   u64 rdp;
-   u32 mxcsr;
-   u32 mxcsr_mask;
-   u32 st_space[32];   /* 8*16 bytes for each FP-reg = 128 bytes */
-#ifdef CONFIG_X86_64
-   u32 xmm_space[64];  /* 16*16 bytes for each XMM-reg = 256 bytes */
-#else
-   u32 xmm_space[32];  /* 8*16 bytes for each XMM-reg = 128 bytes */
-#endif
-};
-
-static int kvm_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
-{
-   struct fxsave *fxsave = (struct fxsave *)vcpu-guest_fx_image;
-
-   vcpu_load(vcpu);
-
-   memcpy(fpu-fpr, fxsave-st_space, 128);
-   fpu-fcw = fxsave-cwd;
-   fpu-fsw = fxsave-swd;
-   fpu-ftwx = fxsave-twd;
-   fpu-last_opcode = fxsave-fop;
-   fpu-last_ip = fxsave-rip;
-   fpu-last_dp = fxsave-rdp;
-   memcpy(fpu-xmm, fxsave-xmm_space, sizeof fxsave-xmm_space);
-
-   vcpu_put(vcpu);
-
-   return 0;
-}
-
-static int kvm_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
-{
-   struct fxsave *fxsave = (struct fxsave *)vcpu-guest_fx_image;
-
-   vcpu_load(vcpu);
-
-   memcpy(fxsave-st_space, fpu-fpr, 128);
-   fxsave-cwd = fpu-fcw;
-   fxsave-swd = fpu-fsw;
-   fxsave-twd = fpu-ftwx;
-   fxsave-fop = fpu-last_opcode;
-   fxsave-rip = fpu-last_ip;
-   fxsave-rdp = fpu-last_dp;
-   memcpy(fxsave-xmm_space, fpu-xmm, sizeof fxsave-xmm_space);
-
-   vcpu_put(vcpu);
-
-   return 0;
-}
-
 static long kvm_vcpu_ioctl(struct file *filp,
   unsigned int ioctl, unsigned long arg)
 {
@@ -1613,7 +1510,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
struct kvm_fpu fpu;
 
memset(fpu, 0, sizeof fpu);
-   r = kvm_vcpu_ioctl_get_fpu(vcpu, fpu);
+   r = kvm_arch_vcpu_ioctl_get_fpu(vcpu, fpu);
if (r)
goto out;
r = -EFAULT;
@@ -1628,7 +1525,7 @@ static long kvm_vcpu_ioctl(struct 

[kvm-devel] [PATCH 47/55] KVM: Portability: Move some includes to x86.c

2007-12-26 Thread Avi Kivity
From: Zhang Xiantao [EMAIL PROTECTED]

Move some includes to x86.c from kvm_main.c, since the related functions
have been moved to x86.c

Signed-off-by: Zhang Xiantao [EMAIL PROTECTED]
Acked-by: Carsten Otte [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm_main.c |2 --
 drivers/kvm/x86.c  |2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 99ad04f..31dafa3 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -17,7 +17,6 @@
 
 #include kvm.h
 #include x86.h
-#include x86_emulate.h
 #include irq.h
 
 #include linux/kvm.h
@@ -44,7 +43,6 @@
 #include linux/mman.h
 
 #include asm/processor.h
-#include asm/msr.h
 #include asm/io.h
 #include asm/uaccess.h
 #include asm/desc.h
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 394da66..4282a0f 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -16,6 +16,7 @@
 
 #include kvm.h
 #include x86.h
+#include x86_emulate.h
 #include segment_descriptor.h
 #include irq.h
 
@@ -25,6 +26,7 @@
 #include linux/module.h
 
 #include asm/uaccess.h
+#include asm/msr.h
 
 #define MAX_IO_MSRS 256
 #define CR0_RESERVED_BITS  \
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 53/55] KVM: Portability: move KVM_CHECK_EXTENSION

2007-12-26 Thread Avi Kivity
From: Zhang Xiantao [EMAIL PROTECTED]

Make KVM_CHECK_EXTENSION code into a function, all archs can define its
capability independently.

Signed-off-by: Zhang Xiantao [EMAIL PROTECTED]
Acked-by: Carsten Otte [EMAIL PROTECTED]
Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/kvm.h  |3 +++
 drivers/kvm/kvm_main.c |   18 ++
 drivers/kvm/x86.c  |   20 
 3 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 96d9c7d..a7be073 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -628,6 +628,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 unsigned int ioctl, unsigned long arg);
 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
+
+int kvm_dev_ioctl_check_extension(long ext);
+
 int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
   struct
   kvm_userspace_memory_region *mem,
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 5d6d5d4..9d63a10 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1198,23 +1198,9 @@ static long kvm_dev_ioctl(struct file *filp,
goto out;
r = kvm_dev_ioctl_create_vm();
break;
-   case KVM_CHECK_EXTENSION: {
-   int ext = (long)argp;
-
-   switch (ext) {
-   case KVM_CAP_IRQCHIP:
-   case KVM_CAP_HLT:
-   case KVM_CAP_MMU_SHADOW_CACHE_CONTROL:
-   case KVM_CAP_USER_MEMORY:
-   case KVM_CAP_SET_TSS_ADDR:
-   r = 1;
-   break;
-   default:
-   r = 0;
-   break;
-   }
+   case KVM_CHECK_EXTENSION:
+   r = kvm_dev_ioctl_check_extension((long)argp);
break;
-   }
case KVM_GET_VCPU_MMAP_SIZE:
r = -EINVAL;
if (arg)
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index bbfa810..6097926 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -599,6 +599,26 @@ void decache_vcpus_on_cpu(int cpu)
spin_unlock(kvm_lock);
 }
 
+int kvm_dev_ioctl_check_extension(long ext)
+{
+   int r;
+
+   switch (ext) {
+   case KVM_CAP_IRQCHIP:
+   case KVM_CAP_HLT:
+   case KVM_CAP_MMU_SHADOW_CACHE_CONTROL:
+   case KVM_CAP_USER_MEMORY:
+   case KVM_CAP_SET_TSS_ADDR:
+   r = 1;
+   break;
+   default:
+   r = 0;
+   break;
+   }
+   return r;
+
+}
+
 long kvm_arch_dev_ioctl(struct file *filp,
unsigned int ioctl, unsigned long arg)
 {
-- 
1.5.3.7


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 54/55] KVM: VMX: Consolidate register usage in vmx_vcpu_run()

2007-12-26 Thread Avi Kivity
We pass vcpu, vmx-fail, and vmx-launched to assembly code, but all three
are fields within vmx.  Consolidate by only passing in vmx and offsets for
the rest.

Signed-off-by: Avi Kivity [EMAIL PROTECTED]
---
 drivers/kvm/vmx.c |  146 ++--
 1 files changed, 73 insertions(+), 73 deletions(-)

diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 18fd918..30220ea 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -2350,36 +2350,36 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
 #endif
ASM_VMX_VMWRITE_RSP_RDX \n\t
/* Check if vmlaunch of vmresume is needed */
-   cmp $0, %1 \n\t
+   cmpl $0, %c[launched](%0) \n\t
/* Load guest registers.  Don't clobber flags. */
 #ifdef CONFIG_X86_64
-   mov %c[cr2](%3), %%rax \n\t
+   mov %c[cr2](%0), %%rax \n\t
mov %%rax, %%cr2 \n\t
-   mov %c[rax](%3), %%rax \n\t
-   mov %c[rbx](%3), %%rbx \n\t
-   mov %c[rdx](%3), %%rdx \n\t
-   mov %c[rsi](%3), %%rsi \n\t
-   mov %c[rdi](%3), %%rdi \n\t
-   mov %c[rbp](%3), %%rbp \n\t
-   mov %c[r8](%3),  %%r8  \n\t
-   mov %c[r9](%3),  %%r9  \n\t
-   mov %c[r10](%3), %%r10 \n\t
-   mov %c[r11](%3), %%r11 \n\t
-   mov %c[r12](%3), %%r12 \n\t
-   mov %c[r13](%3), %%r13 \n\t
-   mov %c[r14](%3), %%r14 \n\t
-   mov %c[r15](%3), %%r15 \n\t
-   mov %c[rcx](%3), %%rcx \n\t /* kills %3 (rcx) */
+   mov %c[rax](%0), %%rax \n\t
+   mov %c[rbx](%0), %%rbx \n\t
+   mov %c[rdx](%0), %%rdx \n\t
+   mov %c[rsi](%0), %%rsi \n\t
+   mov %c[rdi](%0), %%rdi \n\t
+   mov %c[rbp](%0), %%rbp \n\t
+   mov %c[r8](%0),  %%r8  \n\t
+   mov %c[r9](%0),  %%r9  \n\t
+   mov %c[r10](%0), %%r10 \n\t
+   mov %c[r11](%0), %%r11 \n\t
+   mov %c[r12](%0), %%r12 \n\t
+   mov %c[r13](%0), %%r13 \n\t
+   mov %c[r14](%0), %%r14 \n\t
+   mov %c[r15](%0), %%r15 \n\t
+   mov %c[rcx](%0), %%rcx \n\t /* kills %0 (rcx) */
 #else
-   mov %c[cr2](%3), %%eax \n\t
+   mov %c[cr2](%0), %%eax \n\t
mov %%eax,   %%cr2 \n\t
-   mov %c[rax](%3), %%eax \n\t
-   mov %c[rbx](%3), %%ebx \n\t
-   mov %c[rdx](%3), %%edx \n\t
-   mov %c[rsi](%3), %%esi \n\t
-   mov %c[rdi](%3), %%edi \n\t
-   mov %c[rbp](%3), %%ebp \n\t
-   mov %c[rcx](%3), %%ecx \n\t /* kills %3 (ecx) */
+   mov %c[rax](%0), %%eax \n\t
+   mov %c[rbx](%0), %%ebx \n\t
+   mov %c[rdx](%0), %%edx \n\t
+   mov %c[rsi](%0), %%esi \n\t
+   mov %c[rdi](%0), %%edi \n\t
+   mov %c[rbp](%0), %%ebp \n\t
+   mov %c[rcx](%0), %%ecx \n\t /* kills %0 (ecx) */
 #endif
/* Enter guest mode */
jne .Llaunched \n\t
@@ -2389,62 +2389,62 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
.Lkvm_vmx_return: 
/* Save guest registers, load host registers, keep flags */
 #ifdef CONFIG_X86_64
-   xchg %3, (%%rsp) \n\t
-   mov %%rax, %c[rax](%3) \n\t
-   mov %%rbx, %c[rbx](%3) \n\t
-   pushq (%%rsp); popq %c[rcx](%3) \n\t
-   mov %%rdx, %c[rdx](%3) \n\t
-   mov %%rsi, %c[rsi](%3) \n\t
-   mov %%rdi, %c[rdi](%3) \n\t
-   mov %%rbp, %c[rbp](%3) \n\t
-   mov %%r8,  %c[r8](%3) \n\t
-   mov %%r9,  %c[r9](%3) \n\t
-   mov %%r10, %c[r10](%3) \n\t
-   mov %%r11, %c[r11](%3) \n\t
-   mov %%r12, %c[r12](%3) \n\t
-   mov %%r13, %c[r13](%3) \n\t
-   mov %%r14, %c[r14](%3) \n\t
-   mov %%r15, %c[r15](%3) \n\t
+   xchg %0, (%%rsp) \n\t
+   mov %%rax, %c[rax](%0) \n\t
+   mov %%rbx, %c[rbx](%0) \n\t
+   pushq (%%rsp); popq %c[rcx](%0) \n\t
+   mov %%rdx, %c[rdx](%0) \n\t
+   mov %%rsi, %c[rsi](%0) \n\t
+   mov %%rdi, %c[rdi](%0) \n\t
+   mov %%rbp, %c[rbp](%0) \n\t
+   mov %%r8,  %c[r8](%0) \n\t
+   mov %%r9,  %c[r9](%0) \n\t
+   mov %%r10, %c[r10](%0) \n\t
+   mov %%r11, %c[r11](%0) \n\t
+   mov %%r12, %c[r12](%0) \n\t
+   mov %%r13, %c[r13](%0) \n\t
+   mov %%r14, %c[r14](%0) \n\t
+   mov %%r15, %c[r15](%0) \n\t
mov %%cr2, %%rax   \n\t
-   mov %%rax, %c[cr2](%3) \n\t
+   mov %%rax, %c[cr2](%0) \n\t
 
-   

Re: [kvm-devel] README: How to run kvm guests on IA64

2007-12-26 Thread Zhang, Xiantao
Akio Takebe wrote:
 Hi, Xiantao
 
 Akio Takebe wrote:
 Hi, Xiantao
 
 Akio Takebe wrote:
 Hi,
 
 Run guests with the command :
 /usr/local/bin/qemu-system-ia64 -hda your.img -m 512
 
 If you have any question, please feel free to contact me!
 Can I use the guest image of Xen?
 Or do I need to clean-install Linux or Windows on KVM guest?
 Hi, Akio
 Thank you for your try!
 In addition, If you want to boot windows up on Open GFW, you also
 need to pick up the patch I sent to xen-ia64 mailing list, and
 built it with latest efi-vfirmware.hg source.
 I attached it in this mail.
 Thank you. Your README doesn't explain about GFW.
 How do we specify GFW as qemu's option?
 Or must we put GFW in somewhere?
 
 I will update to kvm wiki.  We should put GFW named as Flash.fd to
 /usr/local/share/qemu/ :)
 Thank you for your advice.
 Although I may still have some wrong steps,
 I can boot up RHEL5.1 guest on kvm-ia64. :)
 It works fine now!
Hi, Akio
Good news!  Glad to see you are successful to boot it up. Maybe
you can also try windows 2003, it should works fine as well :)
Xiantao

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] keeping time

2007-12-26 Thread Yves Dorfsman

What is the recommended way to keep the time correct on a UNIX KVM machine ?

I am using Linux x86_64 (gentoo) both as a host and as a guest, and can't 
keep the time straight on the guest. Ntpd eventually gives up because the 
clock is too wanky.

I run into this problem both with versions 28 and 57.

Thanks.


Yves.

PS: I realize this is for kvm developers, but could not find a KVM user 
list - please point me towards the apropriate list if this is the wrong 
choice.

Yves Dorfsman [EMAIL PROTECTED]
http://www.SollerS.ca


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] NFS problems

2007-12-26 Thread Yves Dorfsman

I built my virtual machines on KVM version 28 back in july. One of them 
runs gentoo x86_64 (as guest) and a small web server with apache 2, 
serving pages from an NFS directory. Never had a problem with it.

This week I upgraded KVM to version 57. Everything looked like it worked, 
but I run into the following problem: after serving a few pages ( 20) the 
machine gets into 0% user, 0% idle 100% wait and apache stop serving any 
page. I can kill most apache processes except two. ls and df on the 
nfs filesystem still works. I reboot the virtual box and try to run 
emerge (gentoo package management) that uses NFS heavily, and it hangs, 
and the machine is the state describe above.

Shutting down the virtual box and replacing kvm v57 by kvm v28 fixes the 
problem.

Anybody run into a comparable problem ?

Thanks.


Yves.

Yves Dorfsman [EMAIL PROTECTED]
http://www.SollerS.ca


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] keeping time

2007-12-26 Thread Izik Eidus
Yves Dorfsman wrote:
 What is the recommended way to keep the time correct on a UNIX KVM machine ?
   
what happen when you try:
-no-kvm-irqchip -tdf ?
(you arent runing it with -no-kvm-irqchip right now right?, if you dont 
it is probably bug)
 I am using Linux x86_64 (gentoo) both as a host and as a guest, and can't 
 keep the time straight on the guest. Ntpd eventually gives up because the 
 clock is too wanky.

 I run into this problem both with versions 28 and 57.

 Thanks.


 Yves.

 PS: I realize this is for kvm developers, but could not find a KVM user 
 list - please point me towards the apropriate list if this is the wrong 
 choice.
 
 Yves Dorfsman [EMAIL PROTECTED]
 http://www.SollerS.ca


 -
 This SF.net email is sponsored by: Microsoft
 Defy all challenges. Microsoft(R) Visual Studio 2005.
 http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
 ___
 kvm-devel mailing list
 kvm-devel@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/kvm-devel
   


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] NFS problems

2007-12-26 Thread Avi Kivity
Yves Dorfsman wrote:
 I built my virtual machines on KVM version 28 back in july. One of them 
 runs gentoo x86_64 (as guest) and a small web server with apache 2, 
 serving pages from an NFS directory. Never had a problem with it.

 This week I upgraded KVM to version 57. Everything looked like it worked, 
 but I run into the following problem: after serving a few pages ( 20) the 
 machine gets into 0% user, 0% idle 100% wait and apache stop serving any 
 page. I can kill most apache processes except two. ls and df on the 
 nfs filesystem still works. I reboot the virtual box and try to run 
 emerge (gentoo package management) that uses NFS heavily, and it hangs, 
 and the machine is the state describe above.

 Shutting down the virtual box and replacing kvm v57 by kvm v28 fixes the 
 problem.

 Anybody run into a comparable problem ?
   

What virtual nic are you using?  ne2k is broken; try rtl8139 (which 
gives better performance anyway).

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


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] keeping time

2007-12-26 Thread Avi Kivity
Yves Dorfsman wrote:
 What is the recommended way to keep the time correct on a UNIX KVM machine ?

 I am using Linux x86_64 (gentoo) both as a host and as a guest, and can't 
 keep the time straight on the guest. Ntpd eventually gives up because the 
 clock is too wanky.

   

ntp is too clever for virtual machines.  What happens if you don't 
enable it?

Please provide the guest's /proc/interrupts.


 PS: I realize this is for kvm developers, but could not find a KVM user 
 list - please point me towards the apropriate list if this is the wrong 
 choice.
   

This is the right place to report bugs.

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


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] README: How to run kvm guests on IA64

2007-12-26 Thread Amit Shah
On Wednesday 19 December 2007 17:52:01 Zhang, Xiantao wrote:
   KVM/IA64 HOWTO
 This is the notes about how to enalbe kvm on Itanium series of
 processors
 suppoting VT. Since fully userspace built is not supported yet, so we
 have to
 build qemu, and kernel module separately.
 The step-by-step is as following:

 Kernel module built:

 Download kvm source tree.
 1. Apply kernel.patch to your kernel source.
 2. Make menuconfig to enable virtulization support in kernel.
 3. Build and install kernel. Reboot with new kernel.
 4. Insert kvm.ko kvm-intel.ko to kernel.

kvm-intel is the name of the module fox x86-intel. Do we have a collision 
here? Or is this supposed to load the x86 one on x86 and ia64 one on  ia64?

OK, I just saw your patches for Kconfig and Makefiles and we use 
CONFIG_KVM_INTEL for ia64 as well as x86. We should separate out these two 
before we run into troubles.

 Userspace built:

 1. Download kvm-userspace source.
 2. ./configure

./configure --with-patched-kernel in case you want to use the modules from the 
kernel that was built as mentioned above.

 3. cd kernel
 4. make sync LINUX= Your kvm kernel source directory.

This step isn't needed if you build and install the kernel and plan to use the 
same modules. This is only needed if you want to upgrade kvm without 
upgrading the kernel or rebooting.

 5. make qemu
 6. make install

 Run guests with the command :
 /usr/local/bin/qemu-system-ia64 -hda your.img -m 512

 If you have any question, please feel free to contact me!

 Thanks

 Zhang Xiantao [EMAIL PROTECTED] 2007.12.19



-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] keeping time

2007-12-26 Thread Yves Dorfsman

On Wed, 26 Dec 2007, Avi Kivity wrote:

 ntp is too clever for virtual machines.  What happens if you don't enable it?

Same thing.


 Please provide the guest's /proc/interrupts.

more  /proc/interrupts
CPU0
   0:  27066XT-PIC-XTtimer
   1:  9XT-PIC-XTi8042
   2:  0XT-PIC-XTcascade
   8:  0XT-PIC-XTrtc
  11:393XT-PIC-XTeth0
  12:110XT-PIC-XTi8042
  14:   1670XT-PIC-XTide0
  15: 48XT-PIC-XTide1
NMI:  0 
LOC:  18300 
ERR:  0

This is with -no-kvm-irqchip -tdf which made no difference.

Now, because of my mother board, I have to start linux with acpi=off, 
could that be a problem ?

Yves.

Yves Dorfsman [EMAIL PROTECTED]
http://www.SollerS.ca


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] keeping time

2007-12-26 Thread Izik Eidus
Yves Dorfsman wrote:
 On Wed, 26 Dec 2007, Avi Kivity wrote:

   
 ntp is too clever for virtual machines.  What happens if you don't enable it?
 

 Same thing.

   
 Please provide the guest's /proc/interrupts.
 

 more  /proc/interrupts
 CPU0
0:  27066XT-PIC-XTtimer
1:  9XT-PIC-XTi8042
2:  0XT-PIC-XTcascade
8:  0XT-PIC-XTrtc
   11:393XT-PIC-XTeth0
   12:110XT-PIC-XTi8042
   14:   1670XT-PIC-XTide0
   15: 48XT-PIC-XTide1
 NMI:  0 
 LOC:  18300 
 ERR:  0

 This is with -no-kvm-irqchip -tdf which made no difference.
   
ohhh i forgat to mention to boot the linux without apic when you run the 
-tdf (if i remember it is noapic)
but there is still bug here
 Now, because of my mother board, I have to start linux with acpi=off, 
 could that be a problem ?

 Yves.
 
 Yves Dorfsman [EMAIL PROTECTED]
 http://www.SollerS.ca

   


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] NFS problems

2007-12-26 Thread Yves Dorfsman

On Wed, 26 Dec 2007, Avi Kivity wrote:

 Yves Dorfsman wrote:

  This week I upgraded KVM to version 57. Everything looked like it worked,
  but I run into the following problem: after serving a few pages ( 20) the
  machine gets into 0% user, 0% idle 100% wait and apache stop serving any
  page. I can kill most apache processes except two. ls and df on the

 What virtual nic are you using?  ne2k is broken; try rtl8139 (which gives 
 better performance anyway).

I was usign rtl8020 (I think), anyway, not ne2k. I am now using rtl8139 
and have the same problem. I am using the linux 8139too though, which I 
understand is old, I am trying to replace it with the newer one 8139cp, 
but have shoot myself in the foot by doing so on one of my vm :-)

Anyway, same nfs issue with 8139cp and kvm 58.


Yves.


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] keeping time

2007-12-26 Thread Yves Dorfsman

On Wed, 26 Dec 2007, Izik Eidus wrote:

 ohhh i forgat to mention to boot the linux without apic when you run the -tdf 
 (if i remember it is noapic)

Yes I verified, noapic. Now that's weird the clock is a little bit 
fast (as opposed to very slow previously). It got 7 second too fast, in 
about 10 minutes/

I think this is something ntpd could cope with. Can/should I run ntpd on a 
kvm vm, or not ? Is there a consensus on this ?

Since the host runs on time, is there anyway to tell kvm to just use the 
host clock ?


Yves.

Yves Dorfsman [EMAIL PROTECTED]
 http://www.SollerS.ca


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH 06/55] KVM: Per-architecture hypercall definitions

2007-12-26 Thread Pavel Machek
Hi!

 Currently kvm provides hypercalls only for x86* architectures. To
 provide hypercall infrastructure for other kvm architectures I split
 kvm_para.h into a generic header file and architecture specific
 definitions.
 
 Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
 Signed-off-by: Avi Kivity [EMAIL PROTECTED]
 ---
  include/asm-x86/kvm_para.h |  105 
 
  include/linux/kvm_para.h   |  105 
 +---
  2 files changed, 117 insertions(+), 93 deletions(-)
  create mode 100644 include/asm-x86/kvm_para.h
 
 diff --git a/include/asm-x86/kvm_para.h b/include/asm-x86/kvm_para.h
 new file mode 100644
 index 000..c6f3fd8
 --- /dev/null
 +++ b/include/asm-x86/kvm_para.h
 @@ -0,0 +1,105 @@
 +#ifndef __X86_KVM_PARA_H
 +#define __X86_KVM_PARA_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.
 + */
 +#define KVM_CPUID_SIGNATURE  0x4000

so it returns 'KVMKVMKVM' in %rax, too? 

 +/* For KVM hypercalls, a three-byte sequence of either the vmrun or the 
 vmmrun
 + * instruction.  The hypervisor may replace it with something else but only 
 the
 + * instructions are guaranteed to be supported.
 + *
 + * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
 + * The hypercall number should be placed in rax and the return

rax? First, this file is shared with i386, AFAICT.

 + * placed in rax.  No other registers will be clobbered unless explicited
 + * noted by the particular hypercall.
 + */
 +
 +static inline long kvm_hypercall0(unsigned int nr)
 +{
 + long ret;
 + asm volatile(KVM_HYPERCALL
 +  : =a(ret)
 +  : a(nr));

Second, if it is to be placed in rax, nr should be unsigned long?


 +static inline int kvm_para_available(void)
 +{
 + unsigned int eax, ebx, ecx, edx;
 + char signature[13];
 +
 + cpuid(KVM_CPUID_SIGNATURE, eax, ebx, ecx, edx);
 + memcpy(signature + 0, ebx, 4);
 + memcpy(signature + 4, ecx, 4);
 + memcpy(signature + 8, edx, 4);

 + signature[12] = 0;
 +
   ebx|ecx|ed
 + if (strcmp(signature, KVMKVMKVM) == 0)
 + return 1;

Should the comment say

 +/* This CPUID returns the signature 'KVMKVMKVM\0\0\0' in ebx, ecx, and edx.  
 It
 + * should be used to determine that a VM is running under KVM.
 + */

Plus, I'd use memcmp, and actually test for those zeros, too.

...which probably can be done later, as this is pure move...
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH 00/55] KVM patch queue review for 2.6.25 merge window (part II)

2007-12-26 Thread Sam Ravnborg
On Wed, Dec 26, 2007 at 01:05:05PM +0200, Avi Kivity wrote:
 The second 2.6.25 kvm patch series, for your review.  Three more to go.

Hi Avi.

A diffstat in your introduction mail would be nice so one does not
have to check 50+ patches to see if it touches any file I can give
feedback on.

Sam

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] NFS problems

2007-12-26 Thread Yves Dorfsman

On Wed, 26 Dec 2007, Yves Dorfsman wrote:

 I was usign rtl8020 (I think), anyway, not ne2k. I am now using rtl8139 and 
 have the same problem. I am using the linux 8139too though, which I 
 understand is old, I am trying to replace it with the newer one 8139cp, but 
 have shoot myself in the foot by doing so on one of my vm :-)

 Anyway, same nfs issue with 8139cp and kvm 58.

Sorry I meant 8139too.

I got my vm back up, and added 8139cp (had to select experimental driver), 
and nfs is working fine with kvm 58. I'm not sure what the usual (*buntu, 
fedorea, etc...) distros ship with, but I suspect 8139too, so it might be 
a good idea to add this one to the FAQ.


Thanks.

Yves.

Yves Dorfsman [EMAIL PROTECTED]
http://www.SollerS.ca


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] keeping time

2007-12-26 Thread Yang, Sheng
On Wednesday 26 December 2007 22:35:29 Yves Dorfsman wrote:
 What is the recommended way to keep the time correct on a UNIX KVM machine
 ?

 I am using Linux x86_64 (gentoo) both as a host and as a guest, and can't
 keep the time straight on the guest. Ntpd eventually gives up because the
 clock is too wanky.

What's your guest kernel version? 

When I debug my in kernel PIT(not sent yet, though kept for months), I found 
the kernel version have something to do with the timer accuracy. On my 
limited test, the kernel 2.6.18, 2.6.20, 2.6.22 with default kernel 
parameters works well with my PIT patch. But for kernel 2.6.9, I have to 
use clock=pit, otherwise the timer is much faster.

And for current KVM, I found 2.6.18 is very slow compared to host. 2.6.20 is 
about 1/3 slow. (host: 30s, guest: 40s, using sleep), and 2.6.22 is OK.


 I run into this problem both with versions 28 and 57.

 Thanks.


 Yves.

 PS: I realize this is for kvm developers, but could not find a KVM user
 list - please point me towards the apropriate list if this is the wrong
 choice.
 
 Yves Dorfsman [EMAIL PROTECTED]
 http://www.SollerS.ca


 -
 This SF.net email is sponsored by: Microsoft
 Defy all challenges. Microsoft(R) Visual Studio 2005.
 http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
 ___
 kvm-devel mailing list
 kvm-devel@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/kvm-devel



-- 
Thanks
Yang, Sheng

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] README: How to run kvm guests on IA64

2007-12-26 Thread Zhang, Xiantao

 4. Insert kvm.ko kvm-intel.ko to kernel.
 
 kvm-intel is the name of the module fox x86-intel. Do we have a
 collision here? Or is this supposed to load the x86 one on x86 and
 ia64 one on  ia64? 
 
 OK, I just saw your patches for Kconfig and Makefiles and we use
 CONFIG_KVM_INTEL for ia64 as well as x86. We should separate out
 these two before we run into troubles.


It shouldn't have any confilicts, since they belong to different archs.
Currently, you know source code is placed at arch/{$arch}/kvm, and
Makefile and Kconfig aslo there. 
So, it doesn't impact any issues, since ia64 and x86_64 are totally
different archs.  For example, you can define HAS_IO_PORT macro for ia64
and x86, but they don't invoke any conficlts.:)

 Userspace built:
 
 1. Download kvm-userspace source.
 2. ./configure
 
 ./configure --with-patched-kernel in case you want to use the modules
 from the kernel that was built as mentioned above.

 3. cd kernel
 4. make sync LINUX= Your kvm kernel source directory.
 
 This step isn't needed if you build and install the kernel and plan
 to use the same modules. This is only needed if you want to upgrade
 kvm without upgrading the kernel or rebooting.

I think it should be necessary, since some common header files are need
to sync to userspace, such as kvm.h, kvm_para.h :)

Xiantao

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] README: How to run kvm guests on IA64

2007-12-26 Thread Amit Shah
On Thursday 27 December 2007 08:00:49 Zhang, Xiantao wrote:
  4. Insert kvm.ko kvm-intel.ko to kernel.
 
  kvm-intel is the name of the module fox x86-intel. Do we have a
  collision here? Or is this supposed to load the x86 one on x86 and
  ia64 one on  ia64?
 
  OK, I just saw your patches for Kconfig and Makefiles and we use
  CONFIG_KVM_INTEL for ia64 as well as x86. We should separate out
  these two before we run into troubles.

 It shouldn't have any confilicts, since they belong to different archs.
 Currently, you know source code is placed at arch/{$arch}/kvm, and
 Makefile and Kconfig aslo there.
 So, it doesn't impact any issues, since ia64 and x86_64 are totally
 different archs.  For example, you can define HAS_IO_PORT macro for ia64
 and x86, but they don't invoke any conficlts.:)

What about files that get shared?

  Userspace built:
 
  1. Download kvm-userspace source.
  2. ./configure
 
  ./configure --with-patched-kernel in case you want to use the modules
  from the kernel that was built as mentioned above.
 
  3. cd kernel
  4. make sync LINUX= Your kvm kernel source directory.
 
  This step isn't needed if you build and install the kernel and plan
  to use the same modules. This is only needed if you want to upgrade
  kvm without upgrading the kernel or rebooting.

 I think it should be necessary, since some common header files are need
 to sync to userspace, such as kvm.h, kvm_para.h :)

The build system should pick up the relevant files 
from /lib/modules/`uname -r`/build/ If it doesn't, it's a bug. (It works for 
me on x86.)


 Xiantao

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH 00/55] KVM patch queue review for 2.6.25 merge window (part II)

2007-12-26 Thread Avi Kivity
Sam Ravnborg wrote:
 On Wed, Dec 26, 2007 at 01:05:05PM +0200, Avi Kivity wrote:
   
 The second 2.6.25 kvm patch series, for your review.  Three more to go.
 

 Hi Avi.

 A diffstat in your introduction mail would be nice so one does not
 have to check 50+ patches to see if it touches any file I can give
 feedback on.

   

Right, sorry for not including it originally:

(this is the diffstat for the entire patchset, not just this batch)

 arch/x86/Kconfig   |6 +
 arch/x86/Makefile  |2 +
 {drivers = arch/x86}/kvm/Kconfig  |4 +-
 {drivers = arch/x86}/kvm/Makefile |6 +-
 {drivers = arch/x86}/kvm/i8259.c  |8 +-
 {drivers = arch/x86}/kvm/irq.c|   22 +-
 arch/x86/kvm/irq.h |   88 +
 {drivers = arch/x86}/kvm/kvm_svm.h|2 +-
 {drivers = arch/x86}/kvm/lapic.c  |  141 +-
 arch/x86/kvm/lapic.h   |   44 +
 {drivers = arch/x86}/kvm/mmu.c| 1016 --
 arch/x86/kvm/mmu.h |   44 +
 {drivers = arch/x86}/kvm/paging_tmpl.h|  410 +--
 arch/x86/kvm/segment_descriptor.h  |   29 +
 {drivers = arch/x86}/kvm/svm.c|  347 +-
 {drivers = arch/x86}/kvm/svm.h|3 +-
 {drivers = arch/x86}/kvm/vmx.c| 1068 +++---
 {drivers = arch/x86}/kvm/vmx.h|   26 +-
 drivers/kvm/kvm_main.c = arch/x86/kvm/x86.c   | 4099 
+---
 arch/x86/kvm/x86_emulate.c | 1912 +
 drivers/Kconfig|2 -
 drivers/Makefile   |1 -
 drivers/kvm/irq.h  |  165 -
 drivers/kvm/segment_descriptor.h   |   17 -
 drivers/kvm/x86_emulate.c  | 1662 
 include/asm-x86/Kbuild |1 +
 include/asm-x86/kvm.h  |  176 +
 drivers/kvm/kvm.h = include/asm-x86/kvm_host.h|  530 +--
 include/asm-x86/kvm_para.h |  105 +
 .../asm-x86/kvm_x86_emulate.h  |   69 +-
 include/linux/Kbuild   |2 +-
 include/linux/kvm.h|  162 +-
 include/linux/kvm_host.h   |  290 ++
 include/linux/kvm_para.h   |   80 +-
 include/linux/kvm_types.h  |   54 +
 kernel/fork.c  |1 +
 {drivers = virt}/kvm/ioapic.c |   99 +-
 virt/kvm/ioapic.h  |   95 +
 virt/kvm/iodev.h   |   63 +
 virt/kvm/kvm_main.c| 1393 +++
 40 files changed, 8139 insertions(+), 6105 deletions(-)

As you can see, the {drivers/ - virt/, arch/x86/} transition dominates 
the diffstat.  Note that this does not include ia64 support, which is 
planned for the 2.6.25 merge window and only awaits a bit of paperwork.

The Kconfig/Makefile changes which are probably most of interest to you 
should arrive in the last batch.

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


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] keeping time

2007-12-26 Thread Yves Dorfsman

On Thu, 27 Dec 2007, Yang, Sheng wrote:

 What's your guest kernel version?

2.6.22

 When I debug my in kernel PIT(not sent yet, though kept for months), I found
 the kernel version have something to do with the timer accuracy. On my
 limited test, the kernel 2.6.18, 2.6.20, 2.6.22 with default kernel
 parameters works well with my PIT patch. But for kernel 2.6.9, I have to
 use clock=pit, otherwise the timer is much faster.

I have added clock=pit, but it does not help. Do you need a specific patch 
for this, or do all kernels accept it ?


Yves.


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] keeping time

2007-12-26 Thread Yang, Sheng
On Thursday 27 December 2007 14:51:06 Yves Dorfsman wrote:
 On Thu, 27 Dec 2007, Yang, Sheng wrote:
  What's your guest kernel version?

 2.6.22

  When I debug my in kernel PIT(not sent yet, though kept for months), I
  found the kernel version have something to do with the timer accuracy. On
  my limited test, the kernel 2.6.18, 2.6.20, 2.6.22 with default kernel
  parameters works well with my PIT patch. But for kernel 2.6.9, I have to
  use clock=pit, otherwise the timer is much faster.

 I have added clock=pit, but it does not help. Do you need a specific patch
 for this, or do all kernels accept it ?

Oh, this is a kernel parameter, but currently:
1. The latest kernel using clocksource= instead of clock=. You can check 
the Documentation/kernel-parameters.txt
2. I haven't sent out the in-kernel PIT patch... At present, KVM still using 
PIT from userspace/QEMU.

I guesses you are under heavy workload? For sleep in bash seems ok on 2.6.22
(x86_64, using RHEL5 as guest distro). 



 Yves.


 -
 This SF.net email is sponsored by: Microsoft
 Defy all challenges. Microsoft(R) Visual Studio 2005.
 http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
 ___
 kvm-devel mailing list
 kvm-devel@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/kvm-devel



-- 
Thanks
Yang, Sheng

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH 06/55] KVM: Per-architecture hypercall definitions

2007-12-26 Thread Avi Kivity
[copying Anthony, the original author]

Pavel Machek wrote:
 Hi!

   
 Currently kvm provides hypercalls only for x86* architectures. To
 provide hypercall infrastructure for other kvm architectures I split
 kvm_para.h into a generic header file and architecture specific
 definitions.
 

 diff --git a/include/asm-x86/kvm_para.h b/include/asm-x86/kvm_para.h
 new file mode 100644
 index 000..c6f3fd8
 --- /dev/null
 +++ b/include/asm-x86/kvm_para.h
 @@ -0,0 +1,105 @@
 +#ifndef __X86_KVM_PARA_H
 +#define __X86_KVM_PARA_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.
 + */
 +#define KVM_CPUID_SIGNATURE 0x4000
 

 so it returns 'KVMKVMKVM' in %rax, too? 

   

No, as documented. 'KVMKVMKVM' is spread among all three registers (9 
bytes won't fit into one...)

 +/* For KVM hypercalls, a three-byte sequence of either the vmrun or the 
 vmmrun
 + * instruction.  The hypervisor may replace it with something else but only 
 the
 + * instructions are guaranteed to be supported.
 + *
 + * Up to four arguments may be passed in rbx, rcx, rdx, and rsi 
 respectively.
 + * The hypercall number should be placed in rax and the return
 

 rax? First, this file is shared with i386, AFAICT.
   

rax is used here in the sense of 'rax on x86-64, eax on i386'.  I guess 
this should be documented.

   
 + * placed in rax.  No other registers will be clobbered unless explicited
 + * noted by the particular hypercall.
 + */
 +
 +static inline long kvm_hypercall0(unsigned int nr)
 +{
 +long ret;
 +asm volatile(KVM_HYPERCALL
 + : =a(ret)
 + : a(nr));
 

 Second, if it is to be placed in rax, nr should be unsigned long?


   

Hm.  Since hypercall numbers are shared with i386, we can't have 4G of 
them.  So the hypercall number should be redefined to be in eax, 
regardless of arch (while the arguments still are unsigned longs).

 +static inline int kvm_para_available(void)
 +{
 +unsigned int eax, ebx, ecx, edx;
 +char signature[13];
 +
 +cpuid(KVM_CPUID_SIGNATURE, eax, ebx, ecx, edx);
 +memcpy(signature + 0, ebx, 4);
 +memcpy(signature + 4, ecx, 4);
 +memcpy(signature + 8, edx, 4);
 

   
 +signature[12] = 0;
 +
 
ebx|ecx|ed
   
 +if (strcmp(signature, KVMKVMKVM) == 0)
 +return 1;
 

 Should the comment say

   
 +/* This CPUID returns the signature 'KVMKVMKVM\0\0\0' in ebx, ecx, and edx. 
  It
 + * should be used to determine that a VM is running under KVM.
 + */
 

 Plus, I'd use memcmp, and actually test for those zeros, too.

 ...which probably can be done later, as this is pure move...
   Pavel
   

Or maybe direct 32-bit compares, and document the 32-bit values of the 
registers directly, to avoid any chance of confusion.

Thanks for the comments, I'll update the patches.


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


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] keeping time

2007-12-26 Thread Dong, Eddie
Using PIT to get guest timer faster is a known issue for unmodified Linux of 
early version such as 2.6.9.
that is why we introduced some extra complicated logic in Xen to try to fix it 
but not perfect. 
pv timer should fix this in future, and ntpd is also a good way.

BTW, Yves's case, can u check more on APIC case? Specifically
I want to know how guest TSC is calibrated? How APIC timer IRQ
is delivered after a specific duration. (cat /proc/interrupts before  after 
sleep 10s).
thx,eddie


-Original Message-
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of 
Yang, Sheng
Sent: 2007年12月27日 10:29
To: Yves Dorfsman
Cc: kvm-devel@lists.sourceforge.net
Subject: Re: [kvm-devel] keeping time

On Wednesday 26 December 2007 22:35:29 Yves Dorfsman wrote:
 What is the recommended way to keep the time correct on a 
UNIX KVM machine
 ?

 I am using Linux x86_64 (gentoo) both as a host and as a 
guest, and can't
 keep the time straight on the guest. Ntpd eventually gives 
up because the
 clock is too wanky.

What's your guest kernel version? 

When I debug my in kernel PIT(not sent yet, though kept for 
months), I found 
the kernel version have something to do with the timer accuracy. On my 
limited test, the kernel 2.6.18, 2.6.20, 2.6.22 with default kernel 
parameters works well with my PIT patch. But for kernel 2.6.9, 
I have to 
use clock=pit, otherwise the timer is much faster.

And for current KVM, I found 2.6.18 is very slow compared to 
host. 2.6.20 is 
about 1/3 slow. (host: 30s, guest: 40s, using sleep), and 
2.6.22 is OK.


 I run into this problem both with versions 28 and 57.

 Thanks.


 Yves.

 PS: I realize this is for kvm developers, but could not find 
a KVM user
 list - please point me towards the apropriate list if this 
is the wrong
 choice.
 
 Yves Dorfsman 
[EMAIL PROTECTED]
 
http://www.SollerS.ca


 
---
--
 This SF.net email is sponsored by: Microsoft
 Defy all challenges. Microsoft(R) Visual Studio 2005.
 http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
 ___
 kvm-devel mailing list
 kvm-devel@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/kvm-devel



-- 
Thanks
Yang, Sheng

---
--
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] README: How to run kvm guests on IA64

2007-12-26 Thread Zhang, Xiantao

 It shouldn't have any confilicts, since they belong to different
 archs. Currently, you know source code is placed at
 arch/{$arch}/kvm, and Makefile and Kconfig aslo there.
 So, it doesn't impact any issues, since ia64 and x86_64 are totally
 different archs.  For example, you can define HAS_IO_PORT macro for
 ia64 and x86, but they don't invoke any conficlts.:)
 
 What about files that get shared?

I think common files shouldn't use KVM_CONFIG_INTEL.


 The build system should pick up the relevant files
 from /lib/modules/`uname -r`/build/ If it doesn't, it's a bug. (It
 works for me on x86.)

If we built on target machine,  you are right. But if the build machine
is not target machine, how to build ?

Xiantao


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel