diff mbox

[v4,20/28] xen/pt: when binding guest msi, accept the whole msi message

Message ID 1510899755-40237-21-git-send-email-chao.gao@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chao Gao Nov. 17, 2017, 6:22 a.m. UTC
... rather than a filtered one. Previously, some fields (reserved or
unalterable) are filtered by QEMU. These fields are useless for the
legacy interrupt format (i.e. non remappable format). However, these
fields are meaningful to remappable format. Accepting the whole msi
message will significantly reduce the efforts to support binding
remappable format msi.

Signed-off-by: Chao Gao <chao.gao@intel.com>
Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
---
v4:
 - new
---
 tools/libxc/include/xenctrl.h |  7 ++++---
 tools/libxc/xc_domain.c       | 14 ++++++++------
 xen/arch/x86/hvm/vmsi.c       | 12 ++++++------
 xen/drivers/passthrough/io.c  | 36 +++++++++++++++++-------------------
 xen/include/asm-x86/hvm/irq.h |  5 +++--
 xen/include/public/domctl.h   |  8 ++------
 6 files changed, 40 insertions(+), 42 deletions(-)
diff mbox

Patch

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 666db0b..8ade90c 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -1756,16 +1756,17 @@  int xc_domain_ioport_mapping(xc_interface *xch,
 int xc_domain_update_msi_irq(
     xc_interface *xch,
     uint32_t domid,
-    uint32_t gvec,
     uint32_t pirq,
+    uint64_t addr,
+    uint32_t data,
     uint32_t gflags,
     uint64_t gtable);
 
 int xc_domain_unbind_msi_irq(xc_interface *xch,
                              uint32_t domid,
-                             uint32_t gvec,
                              uint32_t pirq,
-                             uint32_t gflags);
+                             uint64_t addr,
+                             uint32_t data);
 
 int xc_domain_bind_pt_irq(xc_interface *xch,
                           uint32_t domid,
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index 3ccd27f..f7baf11 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -1735,8 +1735,9 @@  int xc_deassign_dt_device(
 int xc_domain_update_msi_irq(
     xc_interface *xch,
     uint32_t domid,
-    uint32_t gvec,
     uint32_t pirq,
+    uint64_t addr,
+    uint32_t data,
     uint32_t gflags,
     uint64_t gtable)
 {
@@ -1750,7 +1751,8 @@  int xc_domain_update_msi_irq(
     bind = &(domctl.u.bind_pt_irq);
     bind->irq_type = PT_IRQ_TYPE_MSI;
     bind->machine_irq = pirq;
-    bind->u.msi.gvec = gvec;
+    bind->u.msi.addr = addr;
+    bind->u.msi.data = data;
     bind->u.msi.gflags = gflags;
     bind->u.msi.gtable = gtable;
 
@@ -1761,9 +1763,9 @@  int xc_domain_update_msi_irq(
 int xc_domain_unbind_msi_irq(
     xc_interface *xch,
     uint32_t domid,
-    uint32_t gvec,
     uint32_t pirq,
-    uint32_t gflags)
+    uint64_t addr,
+    uint32_t data)
 {
     int rc;
     struct xen_domctl_bind_pt_irq *bind;
@@ -1775,8 +1777,8 @@  int xc_domain_unbind_msi_irq(
     bind = &(domctl.u.bind_pt_irq);
     bind->irq_type = PT_IRQ_TYPE_MSI;
     bind->machine_irq = pirq;
-    bind->u.msi.gvec = gvec;
-    bind->u.msi.gflags = gflags;
+    bind->u.msi.addr = addr;
+    bind->u.msi.data = data;
 
     rc = do_domctl(xch, &domctl);
     return rc;
diff --git a/xen/arch/x86/hvm/vmsi.c b/xen/arch/x86/hvm/vmsi.c
index 7126de7..5edb0e7 100644
--- a/xen/arch/x86/hvm/vmsi.c
+++ b/xen/arch/x86/hvm/vmsi.c
@@ -101,12 +101,12 @@  int vmsi_deliver(
 
 void vmsi_deliver_pirq(struct domain *d, const struct hvm_pirq_dpci *pirq_dpci)
 {
-    uint32_t flags = pirq_dpci->gmsi.gflags;
-    int vector = pirq_dpci->gmsi.gvec;
-    uint8_t dest = (uint8_t)flags;
-    bool dest_mode = flags & XEN_DOMCTL_VMSI_X86_DM_MASK;
-    uint8_t delivery_mode = MASK_EXTR(flags, XEN_DOMCTL_VMSI_X86_DELIV_MASK);
-    bool trig_mode = flags & XEN_DOMCTL_VMSI_X86_TRIG_MASK;
+    uint8_t vector = pirq_dpci->gmsi.data & MSI_DATA_VECTOR_MASK;
+    uint8_t dest = MASK_EXTR(pirq_dpci->gmsi.addr, MSI_ADDR_DEST_ID_MASK);
+    bool dest_mode = pirq_dpci->gmsi.addr & MSI_ADDR_DESTMODE_MASK;
+    uint8_t delivery_mode = MASK_EXTR(pirq_dpci->gmsi.data,
+                                      MSI_DATA_DELIVERY_MODE_MASK);
+    bool trig_mode = pirq_dpci->gmsi.data & MSI_DATA_TRIGGER_MASK;
 
     HVM_DBG_LOG(DBG_LEVEL_IOAPIC,
                 "msi: dest=%x dest_mode=%x delivery_mode=%x "
diff --git a/xen/drivers/passthrough/io.c b/xen/drivers/passthrough/io.c
index 8f16e6c..d8c66bf 100644
--- a/xen/drivers/passthrough/io.c
+++ b/xen/drivers/passthrough/io.c
@@ -339,19 +339,17 @@  int pt_irq_create_bind(
     {
     case PT_IRQ_TYPE_MSI:
     {
-        uint8_t dest, delivery_mode;
+        uint8_t dest, delivery_mode, gvec;
         bool dest_mode;
         int dest_vcpu_id;
         const struct vcpu *vcpu;
-        uint32_t gflags = pt_irq_bind->u.msi.gflags &
-                          ~XEN_DOMCTL_VMSI_X86_UNMASKED;
 
         if ( !(pirq_dpci->flags & HVM_IRQ_DPCI_MAPPED) )
         {
             pirq_dpci->flags = HVM_IRQ_DPCI_MAPPED | HVM_IRQ_DPCI_MACH_MSI |
                                HVM_IRQ_DPCI_GUEST_MSI;
-            pirq_dpci->gmsi.gvec = pt_irq_bind->u.msi.gvec;
-            pirq_dpci->gmsi.gflags = gflags;
+            pirq_dpci->gmsi.data = pt_irq_bind->u.msi.data;
+            pirq_dpci->gmsi.addr = pt_irq_bind->u.msi.addr;
             /*
              * 'pt_irq_create_bind' can be called after 'pt_irq_destroy_bind'.
              * The 'pirq_cleanup_check' which would free the structure is only
@@ -383,8 +381,8 @@  int pt_irq_create_bind(
             }
             if ( unlikely(rc) )
             {
-                pirq_dpci->gmsi.gflags = 0;
-                pirq_dpci->gmsi.gvec = 0;
+                pirq_dpci->gmsi.addr = 0;
+                pirq_dpci->gmsi.data = 0;
                 pirq_dpci->dom = NULL;
                 pirq_dpci->flags = 0;
                 pirq_cleanup_check(info, d);
@@ -403,22 +401,23 @@  int pt_irq_create_bind(
             }
 
             /* If pirq is already mapped as vmsi, update guest data/addr. */
-            if ( pirq_dpci->gmsi.gvec != pt_irq_bind->u.msi.gvec ||
-                 pirq_dpci->gmsi.gflags != gflags )
+            if ( pirq_dpci->gmsi.data != pt_irq_bind->u.msi.data ||
+                 pirq_dpci->gmsi.addr != pt_irq_bind->u.msi.addr )
             {
                 /* Directly clear pending EOIs before enabling new MSI info. */
                 pirq_guest_eoi(info);
 
-                pirq_dpci->gmsi.gvec = pt_irq_bind->u.msi.gvec;
-                pirq_dpci->gmsi.gflags = gflags;
+                pirq_dpci->gmsi.data = pt_irq_bind->u.msi.data;
+                pirq_dpci->gmsi.addr = pt_irq_bind->u.msi.addr;
             }
         }
         /* Calculate dest_vcpu_id for MSI-type pirq migration. */
-        dest = MASK_EXTR(pirq_dpci->gmsi.gflags,
-                         XEN_DOMCTL_VMSI_X86_DEST_ID_MASK);
-        dest_mode = pirq_dpci->gmsi.gflags & XEN_DOMCTL_VMSI_X86_DM_MASK;
-        delivery_mode = MASK_EXTR(pirq_dpci->gmsi.gflags,
-                                  XEN_DOMCTL_VMSI_X86_DELIV_MASK);
+        dest = MASK_EXTR(pirq_dpci->gmsi.addr, MSI_ADDR_DEST_ID_MASK);
+        dest_mode = pirq_dpci->gmsi.addr & MSI_ADDR_DESTMODE_MASK;
+        delivery_mode = MASK_EXTR(pirq_dpci->gmsi.data,
+                                  MSI_DATA_DELIVERY_MODE_MASK);
+        gvec = pirq_dpci->gmsi.data & MSI_DATA_VECTOR_MASK;
+        pirq_dpci->gmsi.gvec = gvec;
 
         dest_vcpu_id = hvm_girq_dest_2_vcpu_id(d, dest, dest_mode);
         pirq_dpci->gmsi.dest_vcpu_id = dest_vcpu_id;
@@ -837,9 +836,8 @@  static int _hvm_dpci_msi_eoi(struct domain *d,
     if ( (pirq_dpci->flags & HVM_IRQ_DPCI_MACH_MSI) &&
          (pirq_dpci->gmsi.gvec == vector) )
     {
-        unsigned int dest = MASK_EXTR(pirq_dpci->gmsi.gflags,
-                                      XEN_DOMCTL_VMSI_X86_DEST_ID_MASK);
-        bool dest_mode = pirq_dpci->gmsi.gflags & XEN_DOMCTL_VMSI_X86_DM_MASK;
+        uint32_t dest = MASK_EXTR(pirq_dpci->gmsi.addr, MSI_ADDR_DEST_ID_MASK);
+        bool dest_mode = pirq_dpci->gmsi.addr & MSI_ADDR_DESTMODE_MASK;
 
         if ( vlapic_match_dest(vcpu_vlapic(current), NULL, 0, dest,
                                dest_mode) )
diff --git a/xen/include/asm-x86/hvm/irq.h b/xen/include/asm-x86/hvm/irq.h
index 3b6b4bd..3a8832c 100644
--- a/xen/include/asm-x86/hvm/irq.h
+++ b/xen/include/asm-x86/hvm/irq.h
@@ -132,9 +132,10 @@  struct dev_intx_gsi_link {
 #define HVM_IRQ_DPCI_TRANSLATE       (1u << _HVM_IRQ_DPCI_TRANSLATE_SHIFT)
 
 struct hvm_gmsi_info {
-    uint32_t gvec;
-    uint32_t gflags;
+    uint32_t data;
     int dest_vcpu_id; /* -1 :multi-dest, non-negative: dest_vcpu_id */
+    uint64_t addr;
+    uint8_t gvec;
     bool posted; /* directly deliver to guest via VT-d PI? */
 };
 
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 9f6f0aa..2717c68 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -536,15 +536,11 @@  struct xen_domctl_bind_pt_irq {
             uint8_t intx;
         } pci;
         struct {
-            uint8_t gvec;
             uint32_t gflags;
-#define XEN_DOMCTL_VMSI_X86_DEST_ID_MASK 0x0000ff
-#define XEN_DOMCTL_VMSI_X86_RH_MASK      0x000100
-#define XEN_DOMCTL_VMSI_X86_DM_MASK      0x000200
-#define XEN_DOMCTL_VMSI_X86_DELIV_MASK   0x007000
-#define XEN_DOMCTL_VMSI_X86_TRIG_MASK    0x008000
 #define XEN_DOMCTL_VMSI_X86_UNMASKED     0x010000
 
+            uint32_t data;
+            uint64_t addr;
             uint64_aligned_t gtable;
         } msi;
         struct {