Skip to contentSkip to conversation

Add support for Xen access to vmport

RFC PATCH Superseded Don Slutz 2 participants 4 messages Sep 26, 2014 – Oct 2, 2014

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Don Slutz

author
#0 lore raw

cover Add support for Xen access to vmport

Note: to use this with Xen either a version of:

[Qemu-devel] [PATCH] -machine vmport=off: Allow disabling of VMWare ioport emulation

And a manual adjustment so that QEMU is started with vmport=1

or

Quoted 1 line

From f70663d9fb86914144ba340b6186cb1e67ac6eec Mon Sep 17 00:00:00 2001

From: Don Slutz <[email protected]>
Date: Fri, 26 Sep 2014 08:11:39 -0400
Subject: [PATCH 1/2] hack: force enable vmport

---
 hw/i386/pc_piix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/pc_piix.c +1 -1
index 103d756..b76dfbc 100644
@@ -234,7 +234,7 @@ static void pc_init1(MachineState *machine,
     pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
 
     /* init basic PC hardware */
-    pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, xen_enabled(),
+    pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, false,
         0x4);
 
     pc_nic_init(isa_bus, pci_bus);
Signature · 17 lines
1.8.4

needs to be done to QEMU.

Don Slutz (1):
  Add IOREQ_TYPE_VMWARE_PORT

 xen/arch/x86/hvm/emulate.c        | 58 +++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/hvm/io.c             | 19 +++++++++++++
 xen/arch/x86/hvm/vmware/vmport.c  | 24 +++++++++++++++-
 xen/include/asm-x86/hvm/emulate.h |  2 ++
 xen/include/asm-x86/hvm/vcpu.h    |  1 +
 xen/include/public/hvm/ioreq.h    |  5 ++++
 6 files changed, 108 insertions(+), 1 deletion(-)

-- 
1.8.4
author
#1 lore raw

RFC PATCH 1/1 Add IOREQ_TYPE_VMWARE_PORT

---
 xen/arch/x86/hvm/emulate.c        | 58 +++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/hvm/io.c             | 19 +++++++++++++
 xen/arch/x86/hvm/vmware/vmport.c  | 24 +++++++++++++++-
 xen/include/asm-x86/hvm/emulate.h |  2 ++
 xen/include/asm-x86/hvm/vcpu.h    |  1 +
 xen/include/public/hvm/ioreq.h    |  5 ++++
 6 files changed, 108 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/emulate.c +58 -0
index 6ab06e0..e442070 100644
@@ -49,6 +49,64 @@ static void hvmtrace_io_assist(int is_mmio, ioreq_t *p)
     trace_var(event, 0/*!cycles*/, size, buffer);
 }
 
+int hvmemul_do_vmport(struct cpu_user_regs *regs)
+{
+    struct vcpu *curr = current;
+    struct hvm_vcpu_io *vio = &curr->arch.hvm_vcpu.hvm_io;
+    ioreq_t p = {
+        .type = IOREQ_TYPE_VMWARE_PORT,
+        .dir = IOREQ_READ,
+        .addr = ((uint64_t)regs->rax << 32) | (uint32_t)regs->rbx,
+        .count = regs->rcx,
+        .size = regs->rdx,
+        .data = ((uint64_t)regs->rsi << 32) | (uint32_t)regs->rdi,
+        .df = 0,
+        .data_is_ptr = 0,
+    };
+
+    switch ( vio->io_state )
+    {
+    case HVMIO_none:
+        break;
+    case HVMIO_completed:
+        vio->io_state = HVMIO_none;
+        goto finish_access_vmport;
+    case HVMIO_dispatched:
+        /* May have to wait for previous cycle of a multi-write to complete. */
+    default:
+        return X86EMUL_UNHANDLEABLE;
+    }
+
+    if ( hvm_io_pending(curr) )
+    {
+        gdprintk(XENLOG_WARNING, "WARNING: io already pending?\n");
+        return X86EMUL_UNHANDLEABLE;
+    }
+
+    vio->io_state = HVMIO_handle_vmport_awaiting_completion;
+    vio->io_size = 4;
+
+    /* If there is no backing DM, just ignore accesses */
+    if ( !hvm_has_dm(curr->domain) )
+    {
+        vio->io_state = HVMIO_none;
+        vio->io_data = ~0ul;
+    }
+    else
+    {
+        if ( !hvm_send_assist_req(&p) )
+            vio->io_state = HVMIO_none;
+        return X86EMUL_RETRY;
+    }
+
+ finish_access_vmport:
+    hvmtrace_io_assist(0, &p);
+
+    memcpy(&regs->rax, &vio->io_data, vio->io_size);
+
+    return X86EMUL_OKAY;
+}
+
 static int hvmemul_do_io(
     int is_mmio, paddr_t addr, unsigned long *reps, int size,
     paddr_t ram_gpa, int dir, int df, void *p_data)
xen/arch/x86/hvm/io.c +19 -0
index 9f565d6..96ef3ff 100644
@@ -206,6 +206,25 @@ void hvm_io_assist(ioreq_t *p)
         else
             memcpy(&guest_cpu_user_regs()->rax, &p->data, vio->io_size);
         break;
+    case HVMIO_handle_vmport_awaiting_completion:
+    {
+        struct cpu_user_regs *regs = guest_cpu_user_regs();
+
+        /* Always zero extension for eax */
+        regs->rax = (uint32_t)(p->addr >> 32);
+        /* Only zero extension if 32bit register changed */
+        if ( (uint32_t)regs->rbx != (uint32_t)p->addr )
+            regs->rbx = (uint32_t)p->addr;
+        if ( (uint32_t)regs->rcx != (uint32_t)p->count )
+            regs->rcx = (uint32_t)p->count;
+        if ( (uint32_t)regs->rdx != (uint32_t)p->size )
+            regs->rdx = (uint32_t)p->size;
+        if ( (uint32_t)regs->rsi != (uint32_t)(p->data >> 32) )
+            regs->rsi = (uint32_t)(p->data >> 32);
+        if ( (uint32_t)regs->rdi != (uint32_t)p->data )
+            regs->rdi = (uint32_t)p->data;
+    }
+        break;
     default:
         break;
     }
xen/arch/x86/hvm/vmware/vmport.c +23 -1
index 962ee32..f79295e 100644
@@ -147,9 +147,31 @@ int vmport_ioport(int dir, uint32_t port, uint32_t bytes, uint32_t *val)
             regs->rax = 0x0;
             break;
         default:
+        {   /* Let backing DM handle */
+            int rc;
+
             HVMTRACE_ND(VMPORT_UNKNOWN, 0, 1/*cycles*/, 6,
-                        (bytes << 8) + dir, cmd, regs->rbx,
+                        (bytes << 8) | dir, cmd, regs->rbx,
                         regs->rcx, regs->rsi, regs->rdi);
+            rc = hvmemul_do_vmport(regs);
+            switch (rc)
+            {
+            case X86EMUL_OKAY:
+                break;
+            case X86EMUL_RETRY:
+            {
+                struct hvm_vcpu_io *vio = &current->arch.hvm_vcpu.hvm_io;
+
+                if ( vio->io_state != HVMIO_handle_vmport_awaiting_completion )
+                    return 0;
+                break;
+            }
+            default:
+                gdprintk(XENLOG_ERR, "Weird HVM ioemulation status %d.\n", rc);
+                domain_crash(current->domain);
+                break;
+            }
+        }
             break;
         }
 
xen/include/asm-x86/hvm/emulate.h +2 -0
index efff97e..9887f7e 100644
@@ -55,4 +55,6 @@ int hvmemul_do_pio(
     unsigned long port, unsigned long *reps, int size,
     paddr_t ram_gpa, int dir, int df, void *p_data);
 
+int hvmemul_do_vmport(struct cpu_user_regs *regs);
+
 #endif /* __ASM_X86_HVM_EMULATE_H__ */
xen/include/asm-x86/hvm/vcpu.h +1 -0
index 01e0665..1e63d7f 100644
@@ -36,6 +36,7 @@ enum hvm_io_state {
     HVMIO_awaiting_completion,
     HVMIO_handle_mmio_awaiting_completion,
     HVMIO_handle_pio_awaiting_completion,
+    HVMIO_handle_vmport_awaiting_completion,
     HVMIO_completed
 };
 
xen/include/public/hvm/ioreq.h +5 -0
index 5b5fedf..ddb4cce 100644
@@ -35,6 +35,7 @@
 #define IOREQ_TYPE_PIO          0 /* pio */
 #define IOREQ_TYPE_COPY         1 /* mmio ops */
 #define IOREQ_TYPE_PCI_CONFIG   2
+#define IOREQ_TYPE_VMWARE_PORT  3
 #define IOREQ_TYPE_TIMEOFFSET   7
 #define IOREQ_TYPE_INVALIDATE   8 /* mapcache */
 
@@ -48,6 +49,10 @@
  * 
  * 63....48|47..40|39..35|34..32|31........0
  * SEGMENT |BUS   |DEV   |FN    |OFFSET
+ *
+ * For I/O type IOREQ_TYPE_VMWARE_PORT the 4 fields addr, data,
+ * count and size are used to transport the 32bit parts of eax, ebx,
+ * ecx, edx, esi, and edi.
  */
 struct ioreq {
     uint64_t addr;          /* physical address */
Signature · 1 line
1.8.4
#2 lore raw

Re: [RFC][PATCH 1/1] Add IOREQ_TYPE_VMWARE_PORT

Il 26/09/2014 20:51, Don Slutz ha scritto:

Quoted 1 line

+ memcpy(&regs->rax, &vio->io_data, vio->io_size);

Shouldn't this match the code you use below for case HVMIO_handle_vmport_awaiting_completion?

Paolo

Quoted 32 lines
xen/arch/x86/hvm/emulate.c +3 -0
+    return X86EMUL_OKAY;
+}
+
 static int hvmemul_do_io(
     int is_mmio, paddr_t addr, unsigned long *reps, int size,
     paddr_t ram_gpa, int dir, int df, void *p_data)
xen/arch/x86/hvm/io.c +18 -0
index 9f565d6..96ef3ff 100644
@@ -206,6 +206,25 @@ void hvm_io_assist(ioreq_t *p)
         else
             memcpy(&guest_cpu_user_regs()->rax, &p->data, vio->io_size);
         break;
+    case HVMIO_handle_vmport_awaiting_completion:
+    {
+        struct cpu_user_regs *regs = guest_cpu_user_regs();
+
+        /* Always zero extension for eax */
+        regs->rax = (uint32_t)(p->addr >> 32);
+        /* Only zero extension if 32bit register changed */
+        if ( (uint32_t)regs->rbx != (uint32_t)p->addr )
+            regs->rbx = (uint32_t)p->addr;
+        if ( (uint32_t)regs->rcx != (uint32_t)p->count )
+            regs->rcx = (uint32_t)p->count;
+        if ( (uint32_t)regs->rdx != (uint32_t)p->size )
+            regs->rdx = (uint32_t)p->size;
+        if ( (uint32_t)regs->rsi != (uint32_t)(p->data >> 32) )
+            regs->rsi = (uint32_t)(p->data >> 32);
+        if ( (uint32_t)regs->rdi != (uint32_t)p->data )
+            regs->rdi = (uint32_t)p->data;
+    }
author
#3 lore raw

Re: [RFC][PATCH 1/1] Add IOREQ_TYPE_VMWARE_PORT

Quoted 4 lines · Paolo Bonzini

Il 26/09/2014 20:51, Don Slutz ha scritto:

Quoted 1 line

+ memcpy(&regs->rax, &vio->io_data, vio->io_size);

Shouldn't this match the code you use below for case HVMIO_handle_vmport_awaiting_completion?

Nope. This path is either:

vio->io_state == HVMIO_completed at entry or the the error path for "If there is no backing DM". In both cases what to put in rax is in vio->io_data with vio->io_size set also.

This code comes from hvmemul_do_io().

-Don Slutz

Quoted 34 lines

Paolo

Quoted 32 lines
xen/arch/x86/hvm/emulate.c +3 -0
+    return X86EMUL_OKAY;
+}
+
  static int hvmemul_do_io(
      int is_mmio, paddr_t addr, unsigned long *reps, int size,
      paddr_t ram_gpa, int dir, int df, void *p_data)
xen/arch/x86/hvm/io.c +18 -0
index 9f565d6..96ef3ff 100644
@@ -206,6 +206,25 @@ void hvm_io_assist(ioreq_t *p)
          else
              memcpy(&guest_cpu_user_regs()->rax, &p->data, vio->io_size);
          break;
+    case HVMIO_handle_vmport_awaiting_completion:
+    {
+        struct cpu_user_regs *regs = guest_cpu_user_regs();
+
+        /* Always zero extension for eax */
+        regs->rax = (uint32_t)(p->addr >> 32);
+        /* Only zero extension if 32bit register changed */
+        if ( (uint32_t)regs->rbx != (uint32_t)p->addr )
+            regs->rbx = (uint32_t)p->addr;
+        if ( (uint32_t)regs->rcx != (uint32_t)p->count )
+            regs->rcx = (uint32_t)p->count;
+        if ( (uint32_t)regs->rdx != (uint32_t)p->size )
+            regs->rdx = (uint32_t)p->size;
+        if ( (uint32_t)regs->rsi != (uint32_t)(p->data >> 32) )
+            regs->rsi = (uint32_t)(p->data >> 32);
+        if ( (uint32_t)regs->rdi != (uint32_t)p->data )
+            regs->rdi = (uint32_t)p->data;
+    }