[no subject]

2015-09-01 Thread Wei Xu
subscribe kvm
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/8] KVM: extend in-kernel mmio to handle 8 byte transactions

2011-03-29 Thread Wei Xu
Avi,

Really appreciate your help! Anything if you need help let me know. I am
working on qemu-kvm now and willing to help out...

Wei Xu


On 3/29/11 5:53 AM, Avi Kivity a...@redhat.com wrote:

 Needed for coalesced mmio using sse.
 
 Signed-off-by: Avi Kivity a...@redhat.com
 ---
  arch/x86/kvm/x86.c |   58 +--
  1 files changed, 46 insertions(+), 12 deletions(-)
 
 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
 index bfd7763..e6bcc97 100644
 --- a/arch/x86/kvm/x86.c
 +++ b/arch/x86/kvm/x86.c
 @@ -3596,20 +3596,43 @@ static void kvm_init_msr_list(void)
  static int vcpu_mmio_write(struct kvm_vcpu *vcpu, gpa_t addr, int len,
   const void *v)
  {
 - if (vcpu-arch.apic 
 - !kvm_iodevice_write(vcpu-arch.apic-dev, addr, len, v))
 -  return 0;
 + int handled = 0;
 + int n;
 +
 + do {
 +  n = min(len, 8);
 +  if (!(vcpu-arch.apic 
 +!kvm_iodevice_write(vcpu-arch.apic-dev, addr, n, v))
 +   kvm_io_bus_write(vcpu-kvm, KVM_MMIO_BUS, addr, n, v))
 +   break;
 +  handled += n;
 +  addr += n;
 +  len -= n;
 +  v += n;
 + } while (len);
  
 - return kvm_io_bus_write(vcpu-kvm, KVM_MMIO_BUS, addr, len, v);
 + return handled;
  }
  
  static int vcpu_mmio_read(struct kvm_vcpu *vcpu, gpa_t addr, int len, void
 *v)
  {
 - if (vcpu-arch.apic 
 - !kvm_iodevice_read(vcpu-arch.apic-dev, addr, len, v))
 -  return 0;
 + int handled = 0;
 + int n;
 +
 + do {
 +  n = min(len, 8);
 +  if (!(vcpu-arch.apic 
 +!kvm_iodevice_read(vcpu-arch.apic-dev, addr, n, v))
 +   kvm_io_bus_read(vcpu-kvm, KVM_MMIO_BUS, addr, n, v))
 +   break;
 +  trace_kvm_mmio(KVM_TRACE_MMIO_READ, n, addr, *(u64 *)v);
 +  handled += n;
 +  addr += n;
 +  len -= n;
 +  v += n;
 + } while (len);
  
 - return kvm_io_bus_read(vcpu-kvm, KVM_MMIO_BUS, addr, len, v);
 + return handled;
  }
  
  static void kvm_set_segment(struct kvm_vcpu *vcpu,
 @@ -3769,6 +3792,7 @@ static int emulator_read_emulated(unsigned long addr,
  struct kvm_vcpu *vcpu)
  {
 gpa_t gpa;
 + int handled;
  
 if (vcpu-mmio_read_completed) {
 memcpy(val, vcpu-mmio_data, bytes);
 @@ -3795,10 +3819,14 @@ mmio:
 /*
 * Is this MMIO handled locally?
 */
 - if (!vcpu_mmio_read(vcpu, gpa, bytes, val)) {
 -  trace_kvm_mmio(KVM_TRACE_MMIO_READ, bytes, gpa, *(u64 *)val);
 + handled = vcpu_mmio_read(vcpu, gpa, bytes, val);
 +
 + if (handled == bytes)
 return X86EMUL_CONTINUE;
 - }
 +
 + gpa += handled;
 + bytes -= handled;
 + val += handled;
  
 trace_kvm_mmio(KVM_TRACE_MMIO_READ_UNSATISFIED, bytes, gpa, 0);
  
 @@ -3830,6 +3858,7 @@ static int emulator_write_emulated_onepage(unsigned long
 addr,
   struct kvm_vcpu *vcpu)
  {
 gpa_t gpa;
 + int handled;
  
 gpa = kvm_mmu_gva_to_gpa_write(vcpu, addr, exception);
  
 @@ -3848,9 +3877,14 @@ mmio:
 /*
 * Is this MMIO handled locally?
 */
 - if (!vcpu_mmio_write(vcpu, gpa, bytes, val))
 + handled = vcpu_mmio_write(vcpu, gpa, bytes, val);
 + if (handled == bytes)
 return X86EMUL_CONTINUE;
  
 + gpa += handled;
 + bytes -= handled;
 + val += handled;
 +
 vcpu-mmio_needed = 1;
 vcpu-run-exit_reason = KVM_EXIT_MMIO;
 vcpu-run-mmio.phys_addr = vcpu-mmio_phys_addr = gpa;

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


Re: KVM internal error. Suberror: 1 with ancient 2.4 kernel as guest

2011-03-28 Thread Wei Xu
Avi, 

That's why I also attached the mmx-qemu.patch for user space...

Wei


On 3/28/11 2:23 AM, Avi Kivity a...@redhat.com wrote:

 On 03/28/2011 02:53 AM, Wei Xu wrote:
  +++ linux/contents/include/linux/kvm.h 2011-03-21 09:16:39.0 -0700
  @@ -152,7 +152,7 @@
  /* KVM_EXIT_MMIO */
  struct {
  __u64 phys_addr;
  -   __u8  data[8];
  +   __u8  data[16];
  __u32 len;
  __u8  is_write;
  } mmio;
 
  This breaks the userspace interface.  My implementation split the I/O
  into two separate 64-bit writes.
 
 WeiIt will not break the user interface -- the len tells user space qemu
 how many bytes need to be copied; and qemu mmio logic can handle more than
 64-bit writes.
 
 But the location of the 'len' field changes.  You have to recompile your
 userspace so the code is aware of the new location.

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


Re: KVM internal error. Suberror: 1 with ancient 2.4 kernel as guest

2011-03-28 Thread Wei Xu
Avi, 

Thanks for quick response! Let me know when it's done.

Wei


On 3/28/11 9:33 AM, Avi Kivity a...@redhat.com wrote:

 On 03/28/2011 06:31 PM, Wei Xu wrote:
 Avi,
 
 That's why I also attached the mmx-qemu.patch for user space...
 
 
 We can't ask users to rebuild their qemus when they upgrade a kernel.
 
 I pushed a new version as tag sse-mmio-v2; unfortunately there's quite a
 bit of work remaining.

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


Re: KVM internal error. Suberror: 1 with ancient 2.4 kernel as guest

2011-03-27 Thread Wei Xu
Avi,

See my comment below with Wei.


On 3/27/11 4:57 AM, Avi Kivity a...@redhat.com wrote:

 On 03/26/2011 12:12 AM, Wei Xu wrote:
 Jiri  Avi:
 
 I attached the patched I did for movq and movdqa emulation. Please note:
 (1) I only implemented those two. Other instructions like addq may be
 following same way.
 (2) I use same guest_fx_image to hold value and fxsave/fxrstor to copy
 to/from registers. This is not very efficient I admit.
 Any suggestions let me know.
 
 
 Patch is severely whitespace damaged.  Please observe the kernel
 whitespace style.
 
 I just remembered that I implemented this once - see the (very old)
 branch sse-mmio in kvm.git.
 
 
 Index: linux/contents/arch/x86/include/asm/kvm_emulate.h
 ===
 --- linux.orig/contents/arch/x86/include/asm/kvm_emulate.h 2010-07-19
 06:42:26.0 -0700
 +++ linux/contents/arch/x86/include/asm/kvm_emulate.h 2011-03-21
 09:16:39.0 -0700
 @@ -116,6 +116,7 @@
 enum { OP_REG, OP_MEM, OP_IMM, OP_NONE } type;
 unsigned int bytes;
 unsigned long val, orig_val, *ptr;
 +unsigned long val_simd[2];
   };
 
 Breaks on i386 (ulong is 32-bit).
 
 
 if (c-src.type == OP_MEM) {
 +void *val;
 c-src.ptr = (unsigned long *)memop;
 c-src.val = 0;
 +if (c-src.bytes  8) { /* movdq case */
 +c-src.val_simd[0] = c-src.val_simd[1] = 0;
 +val = c-src.val_simd;
 +} else {
 +val =c-src.val;
 +}
 
 We have a union there for that purpose.
 
 @@ -2506,6 +2529,55 @@
 if (!test_cc(c-b, ctxt-eflags))
 c-dst.type = OP_NONE; /* no writeback */
 break;
 +case 0x6f: /* movq from mm/m64 to mm; movdqa from xmm/m128 to xmm */
 +if (c-op_bytes == 8){
 +ctxt-vcpu-arch.guest_fx_image.st_space[c-modrm_reg2] =
 +(c-src.val  0x0);
 +ctxt-vcpu-arch.guest_fx_image.st_space[(c-modrm_reg2)+1] =
 +(c-src.val  32);
 +kvm_fx_restore(ctxt-vcpu-arch.guest_fx_image);
 +c-dst.type = OP_NONE; /* Disable writeback. */
 +break;
 +} else { /* movdqa */
 +ctxt-vcpu-arch.guest_fx_image.xmm_space[c-modrm_reg2] =
 +(c-src.val_simd[0]  0x0);
 +ctxt-vcpu-arch.guest_fx_image.xmm_space[(c-modrm_reg2)+1] =
 +(c-src.val_simd[0]  32);
 +ctxt-vcpu-arch.guest_fx_image.xmm_space[(c-modrm_reg2)+2] =
 +(c-src.val_simd[1]  0x0);
 +ctxt-vcpu-arch.guest_fx_image.xmm_space[(c-modrm_reg2)+3] =
 +(c-src.val_simd[1]  32);
 +kvm_fx_restore(ctxt-vcpu-arch.guest_fx_image);
 +c-dst.type = OP_NONE; /* Disable writeback. */
 +break;
 +}
 +case 0x7f: /* movq from mm to mm/m64; movdqa from xmm to xmm/m128 */
 +if (c-op_bytes == 8) { /* movq */
 +kvm_fx_save(ctxt-vcpu-arch.guest_fx_image);
 +if (c-dst.type == OP_MEM) {
 +unsigned long lval,uval;
 +lval =
 ctxt-vcpu-arch.guest_fx_image.st_space[c-modrm_reg2];
 +uval =
 ctxt-vcpu-arch.guest_fx_image.st_space[(c-modrm_reg2)+1];
 +c-dst.val = (uval32) + lval;
 +} else {
 +c-dst.type = OP_NONE; /* Disable writeback. */
 +}
 +break;
 +} else { /* movdqa */
 +kvm_fx_save(ctxt-vcpu-arch.guest_fx_image);
 +if (c-dst.type == OP_MEM) {
 +unsigned long lval,uval;
 +lval =
 ctxt-vcpu-arch.guest_fx_image.xmm_space[c-modrm_reg2];
 +uval =
 ctxt-vcpu-arch.guest_fx_image.xmm_space[(c-modrm_reg2)+1];
 +c-dst.val_simd[0] = (uval32) + lval;
 +lval =
 ctxt-vcpu-arch.guest_fx_image.xmm_space[(c-modrm_reg2)+2];
 +uval =
 ctxt-vcpu-arch.guest_fx_image.xmm_space[(c-modrm_reg2)+3];
 +c-dst.val_simd[1] = (uval32) + lval;
 +} else {
 +c-dst.type = OP_NONE; /* Disable writeback. */
 +}
 +break;
 +}
 
 In my implementation, I just forced the guest mmu to be active, and used
 the sse instructions directly.
 Index: linux/contents/include/linux/kvm.h
 ===
 --- linux.orig/contents/include/linux/kvm.h 2010-07-19 06:42:23.0
 -0700
 +++ linux/contents/include/linux/kvm.h 2011-03-21 09:16:39.0 -0700
 @@ -152,7 +152,7 @@
 /* KVM_EXIT_MMIO */
 struct {
 __u64 phys_addr;
 -   __u8  data[8];
 +   __u8  data[16];
 __u32 len;
 __u8  is_write;
 } mmio;
 
 This breaks the userspace interface.  My implementation split the I/O
 into two separate 64-bit writes.

WeiIt will not break the user interface -- the len tells user space qemu
how many bytes need to be copied; and qemu mmio logic can handle more than
64-bit writes. 

 
 I guess I'll have to rebase it.

--
To unsubscribe from

Re: KVM internal error. Suberror: 1 with ancient 2.4 kernel as guest

2011-03-27 Thread Wei Xu
Avi, 

Are you sure there is a sse-mmio branch? I could not find it anywhere...

Wei Xu


On 3/27/11 4:57 AM, Avi Kivity a...@redhat.com wrote:

 On 03/26/2011 12:12 AM, Wei Xu wrote:
 Jiri  Avi:
 
 I attached the patched I did for movq and movdqa emulation. Please note:
 (1) I only implemented those two. Other instructions like addq may be
 following same way.
 (2) I use same guest_fx_image to hold value and fxsave/fxrstor to copy
 to/from registers. This is not very efficient I admit.
 Any suggestions let me know.
 
 
 Patch is severely whitespace damaged.  Please observe the kernel
 whitespace style.
 
 I just remembered that I implemented this once - see the (very old)
 branch sse-mmio in kvm.git.
 
 
 Index: linux/contents/arch/x86/include/asm/kvm_emulate.h
 ===
 --- linux.orig/contents/arch/x86/include/asm/kvm_emulate.h 2010-07-19
 06:42:26.0 -0700
 +++ linux/contents/arch/x86/include/asm/kvm_emulate.h 2011-03-21
 09:16:39.0 -0700
 @@ -116,6 +116,7 @@
 enum { OP_REG, OP_MEM, OP_IMM, OP_NONE } type;
 unsigned int bytes;
 unsigned long val, orig_val, *ptr;
 +unsigned long val_simd[2];
   };
 
 Breaks on i386 (ulong is 32-bit).
 
 
 if (c-src.type == OP_MEM) {
 +void *val;
 c-src.ptr = (unsigned long *)memop;
 c-src.val = 0;
 +if (c-src.bytes  8) { /* movdq case */
 +c-src.val_simd[0] = c-src.val_simd[1] = 0;
 +val = c-src.val_simd;
 +} else {
 +val =c-src.val;
 +}
 
 We have a union there for that purpose.
 
 @@ -2506,6 +2529,55 @@
 if (!test_cc(c-b, ctxt-eflags))
 c-dst.type = OP_NONE; /* no writeback */
 break;
 +case 0x6f: /* movq from mm/m64 to mm; movdqa from xmm/m128 to xmm */
 +if (c-op_bytes == 8){
 +ctxt-vcpu-arch.guest_fx_image.st_space[c-modrm_reg2] =
 +(c-src.val  0x0);
 +ctxt-vcpu-arch.guest_fx_image.st_space[(c-modrm_reg2)+1] =
 +(c-src.val  32);
 +kvm_fx_restore(ctxt-vcpu-arch.guest_fx_image);
 +c-dst.type = OP_NONE; /* Disable writeback. */
 +break;
 +} else { /* movdqa */
 +ctxt-vcpu-arch.guest_fx_image.xmm_space[c-modrm_reg2] =
 +(c-src.val_simd[0]  0x0);
 +ctxt-vcpu-arch.guest_fx_image.xmm_space[(c-modrm_reg2)+1] =
 +(c-src.val_simd[0]  32);
 +ctxt-vcpu-arch.guest_fx_image.xmm_space[(c-modrm_reg2)+2] =
 +(c-src.val_simd[1]  0x0);
 +ctxt-vcpu-arch.guest_fx_image.xmm_space[(c-modrm_reg2)+3] =
 +(c-src.val_simd[1]  32);
 +kvm_fx_restore(ctxt-vcpu-arch.guest_fx_image);
 +c-dst.type = OP_NONE; /* Disable writeback. */
 +break;
 +}
 +case 0x7f: /* movq from mm to mm/m64; movdqa from xmm to xmm/m128 */
 +if (c-op_bytes == 8) { /* movq */
 +kvm_fx_save(ctxt-vcpu-arch.guest_fx_image);
 +if (c-dst.type == OP_MEM) {
 +unsigned long lval,uval;
 +lval =
 ctxt-vcpu-arch.guest_fx_image.st_space[c-modrm_reg2];
 +uval =
 ctxt-vcpu-arch.guest_fx_image.st_space[(c-modrm_reg2)+1];
 +c-dst.val = (uval32) + lval;
 +} else {
 +c-dst.type = OP_NONE; /* Disable writeback. */
 +}
 +break;
 +} else { /* movdqa */
 +kvm_fx_save(ctxt-vcpu-arch.guest_fx_image);
 +if (c-dst.type == OP_MEM) {
 +unsigned long lval,uval;
 +lval =
 ctxt-vcpu-arch.guest_fx_image.xmm_space[c-modrm_reg2];
 +uval =
 ctxt-vcpu-arch.guest_fx_image.xmm_space[(c-modrm_reg2)+1];
 +c-dst.val_simd[0] = (uval32) + lval;
 +lval =
 ctxt-vcpu-arch.guest_fx_image.xmm_space[(c-modrm_reg2)+2];
 +uval =
 ctxt-vcpu-arch.guest_fx_image.xmm_space[(c-modrm_reg2)+3];
 +c-dst.val_simd[1] = (uval32) + lval;
 +} else {
 +c-dst.type = OP_NONE; /* Disable writeback. */
 +}
 +break;
 +}
 
 In my implementation, I just forced the guest mmu to be active, and used
 the sse instructions directly.
 Index: linux/contents/include/linux/kvm.h
 ===
 --- linux.orig/contents/include/linux/kvm.h 2010-07-19 06:42:23.0
 -0700
 +++ linux/contents/include/linux/kvm.h 2011-03-21 09:16:39.0 -0700
 @@ -152,7 +152,7 @@
 /* KVM_EXIT_MMIO */
 struct {
 __u64 phys_addr;
 -   __u8  data[8];
 +   __u8  data[16];
 __u32 len;
 __u8  is_write;
 } mmio;
 
 This breaks the userspace interface.  My implementation split the I/O
 into two separate 64-bit writes.
 
 I guess I'll have to rebase it.

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

Re: KVM internal error. Suberror: 1 with ancient 2.4 kernel as guest

2011-03-25 Thread Wei Xu
Jiri  Avi:

I attached the patched I did for movq and movdqa emulation. Please note:
(1) I only implemented those two. Other instructions like addq may be
following same way.
(2) I use same guest_fx_image to hold value and fxsave/fxrstor to copy
to/from registers. This is not very efficient I admit.
Any suggestions let me know.

Thanks!
Wei Xu


On 3/21/11 2:23 PM, Wei Xu we...@cisco.com wrote:

 Avi and Jiri:
 
 I implemented emulation of movq(64bit) and movdqa(128 bit). If you guys still
 need it let me know and I can post somewhere...
 
 Wei Xu
 
 
 On 8/31/10 9:30 AM, Avi Kivity a...@redhat.com wrote:
 
 
   On 08/31/2010 06:49 PM, Avi Kivity wrote:
  On 08/31/2010 05:32 PM, Jiri Kosina wrote:
 (qemu) x/5i $eip
 0xc027a841:  movq   (%esi),%mm0
 0xc027a844:  movq   0x8(%esi),%mm1
 0xc027a848:  movq   0x10(%esi),%mm2
 0xc027a84c:  movq   0x18(%esi),%mm3
 0xc027a850:  movq   %mm0,(%edx)
 ===
 
 Is there any issue with emulating MMX?
 
 
 Yes.  MMX is not currently emulated.
 
 If there's a command line option to disable the use of MMX you can try
 it, otherwise wait for it to be implemented (or implement it
 yourself).  I'll try to do it for 2.6.37, but can't promise anything.
 
 You can also run qemu with -cpu qemu32,-mmx.  That will expose a cpu
 without mmx support; hopefully the guest kernel will see that and avoid
 mmx instructions.



mmx-kvm.patch
Description: Binary data


mmx-qemu.patch
Description: Binary data


Re: KVM internal error. Suberror: 1 with ancient 2.4 kernel as guest

2011-03-21 Thread Wei Xu
Avi and Jiri:

I implemented emulation of movq(64bit) and movdqa(128 bit). If you guys
still need it let me know and I can post somewhere...

Wei Xu


On 8/31/10 9:30 AM, Avi Kivity a...@redhat.com wrote:

 
   On 08/31/2010 06:49 PM, Avi Kivity wrote:
  On 08/31/2010 05:32 PM, Jiri Kosina wrote:
 (qemu) x/5i $eip
 0xc027a841:  movq   (%esi),%mm0
 0xc027a844:  movq   0x8(%esi),%mm1
 0xc027a848:  movq   0x10(%esi),%mm2
 0xc027a84c:  movq   0x18(%esi),%mm3
 0xc027a850:  movq   %mm0,(%edx)
 ===
 
 Is there any issue with emulating MMX?
 
 
 Yes.  MMX is not currently emulated.
 
 If there's a command line option to disable the use of MMX you can try
 it, otherwise wait for it to be implemented (or implement it
 yourself).  I'll try to do it for 2.6.37, but can't promise anything.
 
 You can also run qemu with -cpu qemu32,-mmx.  That will expose a cpu
 without mmx support; hopefully the guest kernel will see that and avoid
 mmx instructions.

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