Skip to contentSkip to conversation

MSI-X mask bit acceleration

PATCH New Qing He 1 participant 3 messages Feb 26, 2009

lore
Share & tools
lore

Qing He

author
#0 lore raw

cover MSI-X mask bit acceleration

This patch set adds a new MMIO intercept handler in Xen to efficiently handle mask/unmask operation of guest passthrough MSI-X interrupts.

It is known that certain guests, like 2.6.18 will do mask/unmask for each MSI-X interrupt received, which impacts the performance considerably at high interrupt rate. Handling mask/unmask in the hypervisor avoids extensive exiting to QEmu thus improves response time and reduces overall load.

In order to do this, the patch adds a new MMIO intercept handler, and lock its content with rcu lock to get better mask/unmask performance. It also adds a new hypercall parameter to bind_pt_irq to inform Xen the guest physical address of MSI-X table so the handler can check MMIO access against it. On guest PCI BAR rebalancing, it will rebind the irq, allowing the handler to use new gpa of MSI-X table

Thanks,
Qing

---

[PATCH 1/2] hvm: passthrough MSI-X mask bit acceleration [PATCH 2/2] ioemu: passthrough: MSI-X mask bit acceleration

author
#1 lore raw

PATCH 1/2 hvm: passthrough MSI-X mask bit acceleration

Add a new parameter to DOMCTL_bind_pt_irq to allow Xen to know the guest physical address of MSI-X table. Also add a new MMIO intercept handler to intercept that gpa in order to handle MSI-X vector mask bit operation in the hypervisor. This reduces the load of device model considerably if the guest does mask and unmask frequently

---
 tools/libxc/xc_domain.c          |    4 
 tools/libxc/xenctrl.h            |    3 
 xen/arch/x86/hvm/hvm.c           |    7 
 xen/arch/x86/hvm/intercept.c     |    6 
 xen/arch/x86/hvm/vmsi.c          |  280 +++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/msi.c               |   20 ++
 xen/drivers/passthrough/io.c     |    6 
 xen/include/asm-x86/hvm/domain.h |    4 
 xen/include/asm-x86/msi.h        |    2 
 xen/include/public/domctl.h      |    1 
 xen/include/xen/pci.h            |    3 
 11 files changed, 331 insertions(+), 5 deletions(-)
tools/libxc/xc_domain.c +3 -1
diff -r f8187a343ad2 tools/libxc/xc_domain.c
@@ -920,7 +920,8 @@ int xc_domain_update_msi_irq(
     uint32_t domid,
     uint32_t gvec,
     uint32_t pirq,
-    uint32_t gflags)
+    uint32_t gflags,
+    uint64_t gtable)
 {
     int rc;
     xen_domctl_bind_pt_irq_t *bind;
@@ -936,6 +937,7 @@ int xc_domain_update_msi_irq(
     bind->machine_irq = pirq;
     bind->u.msi.gvec = gvec;
     bind->u.msi.gflags = gflags;
+    bind->u.msi.gtable = gtable;
 
     rc = do_domctl(xc_handle, &domctl);
     return rc;
tools/libxc/xenctrl.h +2 -1
diff -r f8187a343ad2 tools/libxc/xenctrl.h
@@ -1092,7 +1092,8 @@ int xc_domain_update_msi_irq(
     uint32_t domid,
     uint32_t gvec,
     uint32_t pirq,
-    uint32_t gflags);
+    uint32_t gflags,
+    uint64_t gtable);
 
 int xc_domain_unbind_msi_irq(int xc_handle,
                              uint32_t domid,
xen/arch/x86/hvm/hvm.c +7 -0
diff -r f8187a343ad2 xen/arch/x86/hvm/hvm.c
@@ -308,6 +308,9 @@ int hvm_domain_initialise(struct domain 
     spin_lock_init(&d->arch.hvm_domain.irq_lock);
     spin_lock_init(&d->arch.hvm_domain.uc_lock);
 
+    INIT_LIST_HEAD(&d->arch.hvm_domain.msixtbl_list);
+    spin_lock_init(&d->arch.hvm_domain.msixtbl_list_lock);
+
     hvm_init_guest_time(d);
 
     d->arch.hvm_domain.params[HVM_PARAM_HPET_ENABLED] = 1;
@@ -348,10 +351,14 @@ int hvm_domain_initialise(struct domain 
     return rc;
 }
 
+extern void msixtbl_pt_cleanup(struct domain *d);
+
 void hvm_domain_relinquish_resources(struct domain *d)
 {
     hvm_destroy_ioreq_page(d, &d->arch.hvm_domain.ioreq);
     hvm_destroy_ioreq_page(d, &d->arch.hvm_domain.buf_ioreq);
+
+    msixtbl_pt_cleanup(d);
 
     /* Stop all asynchronous timer actions. */
     rtc_deinit(d);
xen/arch/x86/hvm/intercept.c +4 -2
diff -r f8187a343ad2 xen/arch/x86/hvm/intercept.c
@@ -35,14 +35,16 @@ extern struct hvm_mmio_handler hpet_mmio
 extern struct hvm_mmio_handler hpet_mmio_handler;
 extern struct hvm_mmio_handler vlapic_mmio_handler;
 extern struct hvm_mmio_handler vioapic_mmio_handler;
+extern struct hvm_mmio_handler msixtbl_mmio_handler;
 
-#define HVM_MMIO_HANDLER_NR 3
+#define HVM_MMIO_HANDLER_NR 4
 
 static struct hvm_mmio_handler *hvm_mmio_handlers[HVM_MMIO_HANDLER_NR] =
 {
     &hpet_mmio_handler,
     &vlapic_mmio_handler,
-    &vioapic_mmio_handler
+    &vioapic_mmio_handler,
+    &msixtbl_mmio_handler
 };
 
 static int hvm_mmio_access(struct vcpu *v,
xen/arch/x86/hvm/vmsi.c +280 -0

283 lines not on this page · raw message

xen/arch/x86/msi.c +20 -0
diff -r f8187a343ad2 xen/arch/x86/msi.c
@@ -839,3 +839,23 @@ int pci_restore_msi_state(struct pci_dev
     return 0;
 }
 
+unsigned int pci_msix_get_table_len(struct pci_dev *pdev)
+{
+    int pos;
+    u16 control;
+    u8 bus, slot, func;
+    unsigned int len;
+
+    bus = pdev->bus;
+    slot = PCI_SLOT(pdev->devfn);
+    func = PCI_FUNC(pdev->devfn);
+
+    pos = pci_find_cap_offset(bus, slot, func, PCI_CAP_ID_MSIX);
+    if ( !pos )
+        return 0;
+
+    control = pci_conf_read16(bus, slot, func, msix_control_reg(pos));
+    len = msix_table_size(control) * PCI_MSIX_ENTRY_SIZE;
+
+    return len;
+}
xen/drivers/passthrough/io.c +6 -0
diff -r f8187a343ad2 xen/drivers/passthrough/io.c
@@ -58,6 +58,9 @@ static void pt_irq_time_out(void *data)
     pirq_guest_eoi(irq_map->dom, machine_gsi);
 }
 
+extern int msixtbl_pt_register(struct domain *d, int pirq, uint64_t gtable);
+extern int msixtbl_pt_unregister(struct domain *d, int pirq);
+
 int pt_irq_create_bind_vtd(
     struct domain *d, xen_domctl_bind_pt_irq_t *pt_irq_bind)
 {
@@ -115,6 +118,8 @@ int pt_irq_create_bind_vtd(
                 spin_unlock(&d->event_lock);
                 return rc;
             }
+            if ( pt_irq_bind->u.msi.gtable )
+                msixtbl_pt_register(d, pirq, pt_irq_bind->u.msi.gtable);
         }
         else if (hvm_irq_dpci->mirq[pirq].gmsi.gvec != pt_irq_bind->u.msi.gvec
                 ||hvm_irq_dpci->msi_gvec_pirq[pt_irq_bind->u.msi.gvec] != pirq)
@@ -259,6 +264,7 @@ int pt_irq_destroy_bind_vtd(
         if ( list_empty(&hvm_irq_dpci->mirq[machine_gsi].digl_list) )
         {
             pirq_guest_unbind(d, machine_gsi);
+            msixtbl_pt_unregister(d, machine_gsi);
             if ( pt_irq_need_timer(hvm_irq_dpci->mirq[machine_gsi].flags) )
                 kill_timer(&hvm_irq_dpci->hvm_timer[domain_irq_to_vector(d, machine_gsi)]);
             hvm_irq_dpci->mirq[machine_gsi].dom   = NULL;
xen/include/asm-x86/hvm/domain.h +4 -0
diff -r f8187a343ad2 xen/include/asm-x86/hvm/domain.h
@@ -75,6 +75,10 @@ struct hvm_domain {
     /* Pass-through */
     struct hvm_iommu       hvm_iommu;
 
+    /* hypervisor intercepted msix table */
+    struct list_head       msixtbl_list;
+    spinlock_t             msixtbl_list_lock;
+
     struct viridian_domain viridian;
 
     bool_t                 hap_enabled;
xen/include/asm-x86/msi.h +2 -0
diff -r f8187a343ad2 xen/include/asm-x86/msi.h
@@ -80,6 +80,8 @@ extern void teardown_msi_vector(int vect
 extern void teardown_msi_vector(int vector);
 extern int msi_free_vector(struct msi_desc *entry);
 extern int pci_restore_msi_state(struct pci_dev *pdev);
+
+extern unsigned int pci_msix_get_table_len(struct pci_dev *pdev);
 
 struct msi_desc {
 	struct {
xen/include/public/domctl.h +1 -0
diff -r f8187a343ad2 xen/include/public/domctl.h
@@ -485,6 +485,7 @@ struct xen_domctl_bind_pt_irq {
         struct {
             uint8_t gvec;
             uint32_t gflags;
+            uint64_t gtable;
         } msi;
     } u;
 };
xen/include/xen/pci.h +2 -1
diff -r f8187a343ad2 xen/include/xen/pci.h
@@ -29,7 +29,8 @@
 #define PCI_BDF(b,d,f)  ((((b) & 0xff) << 8) | PCI_DEVFN(d,f))
 #define PCI_BDF2(b,df)  ((((b) & 0xff) << 8) | ((df) & 0xff))
 
-#define MAX_MSIX_TABLE_PAGES    8    /* 2048 entries */
+#define MAX_MSIX_TABLE_ENTRIES  2048
+#define MAX_MSIX_TABLE_PAGES    8
 struct pci_dev {
     struct list_head alldevs_list;
     struct list_head domain_list;
author
#2 lore raw

PATCH 2/2 ioemu: passthrough: MSI-X mask bit acceleration

In reply to Qing He

Read MSI-X mask bit directly from the device, since buffered version may not be up-to-date when MSI-X mask bit interception is working. Also rebind every MSI-X vector on guest PCI BAR rebalancing so that MSI-X mask bit intercept handler can get the correct gpa

---
 pass-through.c |    3 +++
 pt-msi.c       |   41 ++++++++++++++++++++++++++++++++++++++---
 pt-msi.h       |    3 +++
 3 files changed, 44 insertions(+), 3 deletions(-)
hw/pass-through.c +3 -0
index 96e7160..df6bd1e 100644
@@ -983,6 +983,9 @@ void pt_iomem_map(PCIDevice *d, int i, uint32_t e_phys, uint32_t e_size,
         ret = remove_msix_mapping(assigned_device, i);
         if ( ret != 0 )
             PT_LOG("Error: remove MSI-X mmio mapping failed!\n");
+
+        if ( old_ebase != e_phys && old_ebase != -1 )
+            pt_msix_update_remap(assigned_device, i);
     }
 }
 
hw/pt-msi.c +38 -3

71 lines not on this page · raw message

hw/pt-msi.h +3 -0
index dea0848..d9c3f88 100644
@@ -95,6 +95,9 @@ void
 pt_disable_msi_translate(struct pt_dev *dev);
 
 int
+pt_msi_update_remap(struct pt_dev *d, int bar_index);
+
+int
 pt_msix_update(struct pt_dev *dev);
 
 void