Skip to contentSkip to conversation

Qemu: Add Xen vIOMMU support

RFC PATCH In review Lan Tianyu 8 participants 21 messages Mar 17, 2017 – Mar 30, 2017

lore
Share & tools
lore

Lan Tianyu

author
#0 lore raw

cover Qemu: Add Xen vIOMMU support

This patchset is to add Xen vIOMMU device model and handle irq remapping stuffs. Xen vIOMMU emulation is in the Xen hypervisor and the new device module in Qemu works as hypercall wrappers to create and destroy vIOMMU in hypervisor.

Xen only supports emulated I440 and so we enable vIOMMU with emulated I440 chipset. This works on Linux and Windows guest.

Chao Gao (4):
I440: Allow adding sysbus devices with -device on I440
Xen: add a dummy vIOMMU to create/destroy vIOMMU in Xen
xen-pt: bind/unbind interrupt remapping format MSI
msi: taking interrupt format into consideration during judging a pirq
is binded with a event channel

 hw/i386/pc_piix.c             |   1 +
 hw/pci/msi.c                  |   5 +-
 hw/pci/msix.c                 |   4 +-
 hw/xen/Makefile.objs          |   1 +
 hw/xen/xen_pt_msi.c           |  38 ++++++++++----
 hw/xen/xen_viommu.c           | 116 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/i386/apic-msidef.h |   1 +
 include/hw/xen/xen.h          |   2 +-
 xen-hvm-stub.c                |   2 +-
 xen-hvm.c                     |   7 ++-
 10 files changed, 162 insertions(+), 15 deletions(-)
 create mode 100644 hw/xen/xen_viommu.c
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#1 lore raw

RFC PATCH 1/4 I440: Allow adding sysbus devices with -device on I440

From: Chao Gao <[email protected]>

xen-viommu will be a sysbus device and the device model will be enabled via "-device" parameter.

---
 hw/i386/pc_piix.c | 1 +
 1 file changed, 1 insertion(+)
hw/i386/pc_piix.c +1 -0
index a07dc81..3289593 100644
@@ -436,6 +436,7 @@ static void pc_i440fx_machine_options(MachineClass *m)
     m->hot_add_cpu = pc_hot_add_cpu;
     m->default_machine_opts = "firmware=bios-256k.bin";
     m->default_display = "std";
+    m->has_dynamic_sysbus = true;
 }
 
 static void pc_i440fx_2_7_machine_options(MachineClass *m)
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [Qemu-devel] [RFC PATCH 1/4] I440: Allow adding sysbus devices with -device on I440

Quoted 7 lines · Lan Tianyu

From: Chao Gao <[email protected]>

xen-viommu will be a sysbus device and the device model will be enabled via "-device" parameter.

I'm worried about the bugs we may expose by accepting all the other sysbus devices in the command-line in addition to xen-viommu.

I am working on a RFC to replace "has_dynamic_sysbus" with a whitelist of sysbus device classes. This way we could enable only xen-viommu on i440fx, instead of suddenly enabling all sysbus devices just because of xen-viommu.

Quoted 19 lines
---
 hw/i386/pc_piix.c | 1 +
 1 file changed, 1 insertion(+)
hw/i386/pc_piix.c +1 -0
index a07dc81..3289593 100644
@@ -436,6 +436,7 @@ static void pc_i440fx_machine_options(MachineClass *m)
     m->hot_add_cpu = pc_hot_add_cpu;
     m->default_machine_opts = "firmware=bios-256k.bin";
     m->default_display = "std";
+    m->has_dynamic_sysbus = true;
 }
 
 static void pc_i440fx_2_7_machine_options(MachineClass *m)
Signature · 1 line
1.8.3.1
Signature · 1 line
Eduardo
author
#3 lore raw

Re: [Qemu-devel] [RFC PATCH 1/4] I440: Allow adding sysbus devices with -device on I440

Hi Eduardo:
Thanks for your review.

Quoted 9 lines · Eduardo Habkost
Quoted 7 lines · Lan Tianyu

From: Chao Gao <[email protected]>

xen-viommu will be a sysbus device and the device model will be enabled via "-device" parameter.

Quoted 8 lines

I'm worried about the bugs we may expose by accepting all the other sysbus devices in the command-line in addition to xen-viommu.

I am working on a RFC to replace "has_dynamic_sysbus" with a whitelist of sysbus device classes. This way we could enable only xen-viommu on i440fx, instead of suddenly enabling all sysbus devices just because of xen-viommu.

That sounds reasonable. Thanks for the job and we rebase on your patches.

Quoted 21 lines
Quoted 20 lines
---
 hw/i386/pc_piix.c | 1 +
 1 file changed, 1 insertion(+)
hw/i386/pc_piix.c +1 -0
index a07dc81..3289593 100644
@@ -436,6 +436,7 @@ static void pc_i440fx_machine_options(MachineClass *m)
     m->hot_add_cpu = pc_hot_add_cpu;
     m->default_machine_opts = "firmware=bios-256k.bin";
     m->default_display = "std";
+    m->has_dynamic_sysbus = true;
 }
 
 static void pc_i440fx_2_7_machine_options(MachineClass *m)
Signature · 1 line
1.8.3.1
Signature · 2 lines
Best regards
Tianyu Lan
author
#4 lore raw

RFC PATCH 2/4 Xen: add a dummy vIOMMU to create/destroy vIOMMU in Xen

In reply to Lan Tianyu

From: Chao Gao <[email protected]>

Since adding a dynamic sysbus device is forbidden, so choose TYPE_DEVICE as parent class.

---
 hw/xen/Makefile.objs |   1 +
 hw/xen/xen_viommu.c  | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)
 create mode 100644 hw/xen/xen_viommu.c
hw/xen/Makefile.objs +1 -0
index d367094..e37d808 100644
@@ -3,3 +3,4 @@ common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o
 
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_graphics.o xen_pt_msi.o
+obj-$(CONFIG_XEN) += xen_viommu.o
hw/xen/xen_viommu.c new file +116 -0

116 lines not on this page · raw message

Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#5 lore raw

Re: [Qemu-devel] [RFC PATCH 2/4] Xen: add a dummy vIOMMU to create/destroy vIOMMU in Xen

Hi,

Quoted 70 lines · Lan Tianyu

From: Chao Gao <[email protected]>

Since adding a dynamic sysbus device is forbidden, so choose TYPE_DEVICE as parent class.

---
 hw/xen/Makefile.objs |   1 +
 hw/xen/xen_viommu.c  | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)
 create mode 100644 hw/xen/xen_viommu.c
hw/xen/Makefile.objs +1 -0
index d367094..e37d808 100644
@@ -3,3 +3,4 @@ common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o
 
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_graphics.o xen_pt_msi.o
+obj-$(CONFIG_XEN) += xen_viommu.o
hw/xen/xen_viommu.c new file +42 -0
new file mode 100644
index 0000000..9bf9158
@@ -0,0 +1,116 @@
+/*
+ * Xen virtual IOMMU (virtual VT-D)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+
+#include "hw/qdev-core.h"
+#include "hw/sysbus.h"
+#include "hw/xen/xen.h"
+#include "hw/xen/xen_backend.h"
+
+#define TYPE_XEN_VIOMMU_DEVICE "xen_viommu"
+#define  XEN_VIOMMU_DEVICE(obj) \
+    OBJECT_CHECK(XenVIOMMUState, (obj), TYPE_XEN_VIOMMU_DEVICE)
+
+typedef struct XenVIOMMUState XenVIOMMUState;
+
+struct XenVIOMMUState {
+    DeviceState dev;
+    uint32_t id;
+    uint64_t cap;
+    uint64_t base_addr;
+};
+
+static void xen_viommu_realize(DeviceState *dev, Error **errp)
+{
+    int rc;
+    uint64_t cap;

hw/xen/xen_viommu.c line 52

Quoted 10 lines
hw/xen/xen_viommu.c new file +10 -0
+    char *dom;
+    char viommu_path[1024];
+    XenVIOMMUState *s = XEN_VIOMMU_DEVICE(dev);
+
+    s->id = -1;
+    
+    /* Read vIOMMU attributes from Xenstore. */
+    dom = xs_get_domain_path(xenstore, xen_domid);
+    snprintf(viommu_path, sizeof(viommu_path), "%s/viommu", dom);
+    rc = xenstore_read_uint64(viommu_path, "base_addr", &s->base_addr);  

Could these informations (base_addr and cap) be read from the command line instead of via xenstore?
Any reason for these informations to be on xenstore?

hw/xen/xen_viommu.c line 54

Quoted 2 lines
hw/xen/xen_viommu.c new file +2 -0
+    if (rc) {
+        error_report("Can't get base address of vIOMMU");

I think error_setg should be used instead of error_report.

hw/xen/xen_viommu.c line 55

Quoted 1 line
hw/xen/xen_viommu.c new file +1 -0
+        exit(1);

Also, exit should be remove, and return instead. error_setg would be enough to signal that the device can not work.

hw/xen/xen_viommu.c line 64

Quoted 9 lines
hw/xen/xen_viommu.c new file +9 -0
+    }
+
+    rc = xenstore_read_uint64(viommu_path, "cap", &s->cap);
+    if (rc) {
+        error_report("Can't get capabilities of vIOMMU");
+        exit(1);
+    }
+
+    rc = xc_viommu_query_cap(xen_xc, xen_domid, &cap);

Since xc_viommu_* seems to be new, you should use xendevicemodel_viommu_* instead, also you will need to define a stub for them to be able to compile QEMU against older version of Xen.

The patch looks good otherwise.

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#6 lore raw

Re: [Qemu-devel] [RFC PATCH 2/4] Xen: add a dummy vIOMMU to create/destroy vIOMMU in Xen

Quoted 26 lines · Anthony PERARD

Hi,

Quoted 23 lines · Lan Tianyu

From: Chao Gao <[email protected]>

Since adding a dynamic sysbus device is forbidden, so choose TYPE_DEVICE as parent class.

---
 hw/xen/Makefile.objs |   1 +
 hw/xen/xen_viommu.c  | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)
 create mode 100644 hw/xen/xen_viommu.c
hw/xen/xen_viommu.c new file +10 -0
+static void xen_viommu_realize(DeviceState *dev, Error **errp)
+{
+    int rc;
+    uint64_t cap;
+    char *dom;
+    char viommu_path[1024];
+    XenVIOMMUState *s = XEN_VIOMMU_DEVICE(dev);
+
+    s->id = -1;
+    
Quoted 8 lines

hw/xen/xen_viommu.c line 52

Quoted 4 lines
hw/xen/xen_viommu.c new file +4 -0
+    /* Read vIOMMU attributes from Xenstore. */
+    dom = xs_get_domain_path(xenstore, xen_domid);
+    snprintf(viommu_path, sizeof(viommu_path), "%s/viommu", dom);
+    rc = xenstore_read_uint64(viommu_path, "base_addr", &s->base_addr);  

Could these informations (base_addr and cap) be read from the command line instead of via xenstore?
Any reason for these informations to be on xenstore?

Actually, we passed both via command line at first. We just concerned whether it was ok to pass a address through command line since we find no device does the similar thing.

Quoted 11 lines

hw/xen/xen_viommu.c line 54

Quoted 3 lines
hw/xen/xen_viommu.c new file +2 -0
+    if (rc) {
+        error_report("Can't get base address of vIOMMU");

I think error_setg should be used instead of error_report.

Quoted 1 line

+ exit(1);

Also, exit should be remove, and return instead. error_setg would be enough to signal that the device can not work.

Quoted 13 lines

hw/xen/xen_viommu.c line 64

Quoted 9 lines
hw/xen/xen_viommu.c new file +9 -0
+    }
+
+    rc = xenstore_read_uint64(viommu_path, "cap", &s->cap);
+    if (rc) {
+        error_report("Can't get capabilities of vIOMMU");
+        exit(1);
+    }
+
+    rc = xc_viommu_query_cap(xen_xc, xen_domid, &cap);

Since xc_viommu_* seems to be new, you should use xendevicemodel_viommu_* instead, also you will need to define a stub for them to be able to compile QEMU against older version of Xen.

Will follow your suggestions above.

Thanks
Chao

Quoted 8 lines

The patch looks good otherwise.

Thanks,

Signature · 1 line
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#7 lore raw

RFC PATCH 3/4 xen-pt: bind/unbind interrupt remapping format MSI

In reply to Lan Tianyu

From: Chao Gao <[email protected]>

If a vIOMMU is exposed to guest, guest will configure the msi to remapping format. The original code isn't suitable to the new format. A new pair bind/unbind interfaces are added for this usage. This patch recognizes this case and use new interfaces to bind/unbind msi.

---
 hw/xen/xen_pt_msi.c           | 36 ++++++++++++++++++++++++++++--------
 include/hw/i386/apic-msidef.h |  1 +
 2 files changed, 29 insertions(+), 8 deletions(-)
hw/xen/xen_pt_msi.c +28 -8
index 62add06..8b0d7fc 100644
@@ -161,6 +161,7 @@ static int msi_msix_update(XenPCIPassthroughState *s,
     uint8_t gvec = msi_vector(data);
     uint32_t gflags = msi_gflags(data, addr);
     int rc = 0;
+    bool ir = !!(addr & MSI_ADDR_IM_MASK);
     uint64_t table_addr = 0;
 
     XEN_PT_LOG(d, "Updating MSI%s with pirq %d gvec %#x gflags %#x"
@@ -171,8 +172,14 @@ static int msi_msix_update(XenPCIPassthroughState *s,
         table_addr = s->msix->mmio_base_addr;
     }
 
-    rc = xc_domain_update_msi_irq(xen_xc, xen_domid, gvec,
+    if (ir) {
+        rc = xc_domain_update_msi_irq_remapping(xen_xc, xen_domid, pirq,
+                                    d->devfn, data, addr, table_addr);
+    }
+    else {
+        rc = xc_domain_update_msi_irq(xen_xc, xen_domid, gvec,
                                   pirq, gflags, table_addr);
+    }
 
     if (rc) {
         XEN_PT_ERR(d, "Updating of MSI%s failed. (err: %d)\n",
@@ -204,13 +211,26 @@ static int msi_msix_disable(XenPCIPassthroughState *s,
     }
 
     if (is_binded) {
-        XEN_PT_LOG(d, "Unbind MSI%s with pirq %d, gvec %#x\n",
-                   is_msix ? "-X" : "", pirq, gvec);
-        rc = xc_domain_unbind_msi_irq(xen_xc, xen_domid, gvec, pirq, gflags);
-        if (rc) {
-            XEN_PT_ERR(d, "Unbinding of MSI%s failed. (err: %d, pirq: %d, gvec: %#x)\n",
-                       is_msix ? "-X" : "", errno, pirq, gvec);
-            return rc;
+        if ( addr & MSI_ADDR_IM_MASK ) {
+            XEN_PT_LOG(d, "Unbinding of MSI%s . ( pirq: %d, data: %x, addr: %lx)\n",
+                       is_msix ? "-X" : "", pirq, data, addr);
+            rc = xc_domain_unbind_msi_irq_remapping(xen_xc, xen_domid, pirq,
+                                                    d->devfn, data, addr);
+            if (rc) {
+                XEN_PT_ERR(d, "Unbinding of MSI%s . (error: %d, pirq: %d, data: %x, addr: %lx)\n",
+                           is_msix ? "-X" : "", rc, pirq, data, addr);
+                return rc;
+            }
+
+        } else {
+            XEN_PT_LOG(d, "Unbind MSI%s with pirq %d, gvec %#x\n",
+                       is_msix ? "-X" : "", pirq, gvec);
+            rc = xc_domain_unbind_msi_irq(xen_xc, xen_domid, gvec, pirq, gflags);
+            if (rc) {
+                XEN_PT_ERR(d, "Unbinding of MSI%s failed. (err: %d, pirq: %d, gvec: %#x)\n",
+                           is_msix ? "-X" : "", errno, pirq, gvec);
+                return rc;
+            }
         }
     }
 
include/hw/i386/apic-msidef.h +1 -0
index 8b4d4cc..08b584f 100644
@@ -27,5 +27,6 @@
 #define MSI_ADDR_DEST_ID_SHIFT          12
 #define MSI_ADDR_DEST_IDX_SHIFT         4
 #define  MSI_ADDR_DEST_ID_MASK          0x00ffff0
+#define  MSI_ADDR_IM_MASK               0x00000010
 
 #endif /* HW_APIC_MSIDEF_H */
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#8 lore raw

Re: [Qemu-devel] [RFC PATCH 3/4] xen-pt: bind/unbind interrupt remapping format MSI

Quoted 27 lines · Lan Tianyu

From: Chao Gao <[email protected]>

If a vIOMMU is exposed to guest, guest will configure the msi to remapping format. The original code isn't suitable to the new format. A new pair bind/unbind interfaces are added for this usage. This patch recognizes this case and use new interfaces to bind/unbind msi.

---
 hw/xen/xen_pt_msi.c           | 36 ++++++++++++++++++++++++++++--------
 include/hw/i386/apic-msidef.h |  1 +
 2 files changed, 29 insertions(+), 8 deletions(-)
hw/xen/xen_pt_msi.c +1 -0
index 62add06..8b0d7fc 100644
@@ -161,6 +161,7 @@ static int msi_msix_update(XenPCIPassthroughState *s,
     uint8_t gvec = msi_vector(data);
     uint32_t gflags = msi_gflags(data, addr);
     int rc = 0;
+    bool ir = !!(addr & MSI_ADDR_IM_MASK);
     uint64_t table_addr = 0;
 
     XEN_PT_LOG(d, "Updating MSI%s with pirq %d gvec %#x gflags %#x"

hw/xen/xen_pt_msi.c static int msi_msix_update(XenPCIPassthroughState *s, · line 175

Quoted 5 lines
hw/xen/xen_pt_msi.c +1 -1
@@ -171,8 +172,14 @@ static int msi_msix_update(XenPCIPassthroughState *s,
         table_addr = s->msix->mmio_base_addr;
     }
 
-    rc = xc_domain_update_msi_irq(xen_xc, xen_domid, gvec,
+    if (ir) {

You could maybe use add&MSI_ADDR_IM_MASK instead of going through a variable.

hw/xen/xen_pt_msi.c static int msi_msix_update(XenPCIPassthroughState *s, · line 177

Quoted 2 lines
hw/xen/xen_pt_msi.c +2 -0
+        rc = xc_domain_update_msi_irq_remapping(xen_xc, xen_domid, pirq,
+                                    d->devfn, data, addr, table_addr);

Do you also want to update the XEN_PT_LOG above? Since it does not always reflect the update_msi call anymore.

Quoted 11 lines
hw/xen/xen_pt_msi.c +4 -0
+    }
+    else {
+        rc = xc_domain_update_msi_irq(xen_xc, xen_domid, gvec,
                                   pirq, gflags, table_addr);
+    }
 
     if (rc) {
         XEN_PT_ERR(d, "Updating of MSI%s failed. (err: %d)\n",
@@ -204,13 +211,26 @@ static int msi_msix_disable(XenPCIPassthroughState *s,
     }
 

hw/xen/xen_pt_msi.c static int msi_msix_disable(XenPCIPassthroughState *s, · line 215

Quoted 10 lines
hw/xen/xen_pt_msi.c +2 -7
     if (is_binded) {
-        XEN_PT_LOG(d, "Unbind MSI%s with pirq %d, gvec %#x\n",
-                   is_msix ? "-X" : "", pirq, gvec);
-        rc = xc_domain_unbind_msi_irq(xen_xc, xen_domid, gvec, pirq, gflags);
-        if (rc) {
-            XEN_PT_ERR(d, "Unbinding of MSI%s failed. (err: %d, pirq: %d, gvec: %#x)\n",
-                       is_msix ? "-X" : "", errno, pirq, gvec);
-            return rc;
+        if ( addr & MSI_ADDR_IM_MASK ) {
+            XEN_PT_LOG(d, "Unbinding of MSI%s . ( pirq: %d, data: %x, addr: %lx)\n",

For addr, it should be PRIx64 instead of %lx.

Quoted 26 lines
hw/xen/xen_pt_msi.c +18 -0
+                       is_msix ? "-X" : "", pirq, data, addr);
+            rc = xc_domain_unbind_msi_irq_remapping(xen_xc, xen_domid, pirq,
+                                                    d->devfn, data, addr);
+            if (rc) {
+                XEN_PT_ERR(d, "Unbinding of MSI%s . (error: %d, pirq: %d, data: %x, addr: %lx)\n",
+                           is_msix ? "-X" : "", rc, pirq, data, addr);
+                return rc;
+            }
+
+        } else {
+            XEN_PT_LOG(d, "Unbind MSI%s with pirq %d, gvec %#x\n",
+                       is_msix ? "-X" : "", pirq, gvec);
+            rc = xc_domain_unbind_msi_irq(xen_xc, xen_domid, gvec, pirq, gflags);
+            if (rc) {
+                XEN_PT_ERR(d, "Unbinding of MSI%s failed. (err: %d, pirq: %d, gvec: %#x)\n",
+                           is_msix ? "-X" : "", errno, pirq, gvec);
+                return rc;
+            }
         }
     }
 
include/hw/i386/apic-msidef.h +0 -0
index 8b4d4cc..08b584f 100644

include/hw/i386/apic-msidef.h line 29

Quoted 3 lines
include/hw/i386/apic-msidef.h +0 -0
@@ -27,5 +27,6 @@
 #define MSI_ADDR_DEST_ID_SHIFT          12
 #define MSI_ADDR_DEST_IDX_SHIFT         4
 #define  MSI_ADDR_DEST_ID_MASK          0x00ffff0

Could you add a 0 to dest_id here? So their will be 8 digit and it those not look weird when compared to the next define.

include/hw/i386/apic-msidef.h line 30

Quoted 1 line
include/hw/i386/apic-msidef.h +1 -0
+#define  MSI_ADDR_IM_MASK               0x00000010

Is the definition of MSI_ADDR_IM_MASK available somewhere? In the Intel SDM I've only found this bit to be reserved.

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#9 lore raw

Re: [Qemu-devel] [RFC PATCH 3/4] xen-pt: bind/unbind interrupt remapping format MSI

Quoted 37 lines · Anthony PERARD
Quoted 27 lines · Lan Tianyu

From: Chao Gao <[email protected]>

If a vIOMMU is exposed to guest, guest will configure the msi to remapping format. The original code isn't suitable to the new format. A new pair bind/unbind interfaces are added for this usage. This patch recognizes this case and use new interfaces to bind/unbind msi.

---
 hw/xen/xen_pt_msi.c           | 36 ++++++++++++++++++++++++++++--------
 include/hw/i386/apic-msidef.h |  1 +
 2 files changed, 29 insertions(+), 8 deletions(-)
hw/xen/xen_pt_msi.c +1 -0
index 62add06..8b0d7fc 100644
@@ -161,6 +161,7 @@ static int msi_msix_update(XenPCIPassthroughState *s,
     uint8_t gvec = msi_vector(data);
     uint32_t gflags = msi_gflags(data, addr);
     int rc = 0;
+    bool ir = !!(addr & MSI_ADDR_IM_MASK);
     uint64_t table_addr = 0;
 
     XEN_PT_LOG(d, "Updating MSI%s with pirq %d gvec %#x gflags %#x"

hw/xen/xen_pt_msi.c static int msi_msix_update(XenPCIPassthroughState *s, · line 175

Quoted 5 lines
hw/xen/xen_pt_msi.c +1 -1
@@ -171,8 +172,14 @@ static int msi_msix_update(XenPCIPassthroughState *s,
         table_addr = s->msix->mmio_base_addr;
     }
 
-    rc = xc_domain_update_msi_irq(xen_xc, xen_domid, gvec,
+    if (ir) {

You could maybe use add&MSI_ADDR_IM_MASK instead of going through a variable.

Quoted 5 lines

hw/xen/xen_pt_msi.c static int msi_msix_update(XenPCIPassthroughState *s, · line 177

Quoted 2 lines
hw/xen/xen_pt_msi.c +2 -0
+        rc = xc_domain_update_msi_irq_remapping(xen_xc, xen_domid, pirq,
+                                    d->devfn, data, addr, table_addr);

Do you also want to update the XEN_PT_LOG above? Since it does not always reflect the update_msi call anymore.

Yes. I adjust the output.

Quoted 46 lines
Quoted 12 lines
hw/xen/xen_pt_msi.c +4 -0
+    }
+    else {
+        rc = xc_domain_update_msi_irq(xen_xc, xen_domid, gvec,
                                   pirq, gflags, table_addr);
+    }
 
     if (rc) {
         XEN_PT_ERR(d, "Updating of MSI%s failed. (err: %d)\n",
@@ -204,13 +211,26 @@ static int msi_msix_disable(XenPCIPassthroughState *s,
     }
 

hw/xen/xen_pt_msi.c static int msi_msix_disable(XenPCIPassthroughState *s, · line 215

Quoted 10 lines
hw/xen/xen_pt_msi.c +2 -7
     if (is_binded) {
-        XEN_PT_LOG(d, "Unbind MSI%s with pirq %d, gvec %#x\n",
-                   is_msix ? "-X" : "", pirq, gvec);
-        rc = xc_domain_unbind_msi_irq(xen_xc, xen_domid, gvec, pirq, gflags);
-        if (rc) {
-            XEN_PT_ERR(d, "Unbinding of MSI%s failed. (err: %d, pirq: %d, gvec: %#x)\n",
-                       is_msix ? "-X" : "", errno, pirq, gvec);
-            return rc;
+        if ( addr & MSI_ADDR_IM_MASK ) {
+            XEN_PT_LOG(d, "Unbinding of MSI%s . ( pirq: %d, data: %x, addr: %lx)\n",

For addr, it should be PRIx64 instead of %lx.

Quoted 21 lines
hw/xen/xen_pt_msi.c +18 -0
+                       is_msix ? "-X" : "", pirq, data, addr);
+            rc = xc_domain_unbind_msi_irq_remapping(xen_xc, xen_domid, pirq,
+                                                    d->devfn, data, addr);
+            if (rc) {
+                XEN_PT_ERR(d, "Unbinding of MSI%s . (error: %d, pirq: %d, data: %x, addr: %lx)\n",
+                           is_msix ? "-X" : "", rc, pirq, data, addr);
+                return rc;
+            }
+
+        } else {
+            XEN_PT_LOG(d, "Unbind MSI%s with pirq %d, gvec %#x\n",
+                       is_msix ? "-X" : "", pirq, gvec);
+            rc = xc_domain_unbind_msi_irq(xen_xc, xen_domid, gvec, pirq, gflags);
+            if (rc) {
+                XEN_PT_ERR(d, "Unbinding of MSI%s failed. (err: %d, pirq: %d, gvec: %#x)\n",
+                           is_msix ? "-X" : "", errno, pirq, gvec);
+                return rc;
+            }
         }
     }
 
Quoted 12 lines

include/hw/i386/apic-msidef.h line 29

Quoted 8 lines
include/hw/i386/apic-msidef.h +0 -0
index 8b4d4cc..08b584f 100644
@@ -27,5 +27,6 @@
 #define MSI_ADDR_DEST_ID_SHIFT          12
 #define MSI_ADDR_DEST_IDX_SHIFT         4
 #define  MSI_ADDR_DEST_ID_MASK          0x00ffff0

Could you add a 0 to dest_id here? So their will be 8 digit and it those not look weird when compared to the next define.

Will do.

Quoted 4 lines

include/hw/i386/apic-msidef.h line 30

Quoted 1 line
include/hw/i386/apic-msidef.h +1 -0
+#define  MSI_ADDR_IM_MASK               0x00000010

Is the definition of MSI_ADDR_IM_MASK available somewhere? In the Intel SDM I've only found this bit to be reserved.

Yes, it is defined in VT-d spec 5.1.5.2 MSI and MSI-X Register Programming. I made a mistake here. I should use MSI_ADDR_IF_MASK.

Thanks
Chao

Quoted 5 lines

Thanks,

Signature · 1 line
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#10 lore raw

RFC PATCH 4/4 msi: taking interrupt format into consideration during judging a pirq is binded with a event channel

In reply to Lan Tianyu

From: Chao Gao <[email protected]>

As remapping format interrupt has been introduced, the vector in msi remapping format can also be 0, same as a interrupt is binded with a event channel. So we can't just use whether vector is 0 or not to judge a msi is binded to a event channel or not.

This patch takes the msi interrupt format into consideration.

---
 hw/pci/msi.c         | 5 +++--
 hw/pci/msix.c        | 4 +++-
 hw/xen/xen_pt_msi.c  | 2 +-
 include/hw/xen/xen.h | 2 +-
 xen-hvm-stub.c       | 2 +-
 xen-hvm.c            | 7 ++++++-
 6 files changed, 15 insertions(+), 7 deletions(-)
hw/pci/msi.c +3 -2
index a87b227..8d1ac9e 100644
@@ -289,7 +289,7 @@ void msi_reset(PCIDevice *dev)
 static bool msi_is_masked(const PCIDevice *dev, unsigned int vector)
 {
     uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev));
-    uint32_t mask, data;
+    uint32_t mask, data, addr_lo;
     bool msi64bit = flags & PCI_MSI_FLAGS_64BIT;
     assert(vector < PCI_MSI_VECTORS_MAX);
 
@@ -298,7 +298,8 @@ static bool msi_is_masked(const PCIDevice *dev, unsigned int vector)
     }
 
     data = pci_get_word(dev->config + msi_data_off(dev, msi64bit));
-    if (xen_is_pirq_msi(data)) {
+    addr_lo = pci_get_word(dev->config + msi_address_lo_off(dev));
+    if (xen_is_pirq_msi(data, addr_lo)) {
         return false;
     }
 
hw/pci/msix.c +3 -1
index 0ec1cb1..6b8045a 100644
@@ -81,9 +81,11 @@ static bool msix_vector_masked(PCIDevice *dev, unsigned int vector, bool fmask)
 {
     unsigned offset = vector * PCI_MSIX_ENTRY_SIZE;
     uint8_t *data = &dev->msix_table[offset + PCI_MSIX_ENTRY_DATA];
+    uint8_t *addr_lo = &dev->msix_table[offset + PCI_MSIX_ENTRY_LOWER_ADDR];
     /* MSIs on Xen can be remapped into pirqs. In those cases, masking
      * and unmasking go through the PV evtchn path. */
-    if (xen_enabled() && xen_is_pirq_msi(pci_get_long(data))) {
+    if (xen_enabled() && xen_is_pirq_msi(pci_get_long(data),
+                                         pci_get_long(addr_lo))) {
         return false;
     }
     return fmask || dev->msix_table[offset + PCI_MSIX_ENTRY_VECTOR_CTRL] &
hw/xen/xen_pt_msi.c +1 -1
index 8b0d7fc..f799fed 100644
@@ -114,7 +114,7 @@ static int msi_msix_setup(XenPCIPassthroughState *s,
 
     assert((!is_msix && msix_entry == 0) || is_msix);
 
-    if (xen_is_pirq_msi(data)) {
+    if (xen_is_pirq_msi(data, (uint32_t)(addr & 0xffffffff))) {
         *ppirq = msi_ext_dest_id(addr >> 32) | msi_dest_id(addr);
         if (!*ppirq) {
             /* this probably identifies an misconfiguration of the guest,
include/hw/xen/xen.h +1 -1
index a8f3afb..c15beb5 100644
@@ -33,7 +33,7 @@ int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
 void xen_piix3_set_irq(void *opaque, int irq_num, int level);
 void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
 void xen_hvm_inject_msi(uint64_t addr, uint32_t data);
-int xen_is_pirq_msi(uint32_t msi_data);
+int xen_is_pirq_msi(uint32_t msi_data, uint32_t msi_addr_lo);
 
 qemu_irq *xen_interrupt_controller_init(void);
 
xen-hvm-stub.c +1 -1
index c500325..dae421c 100644
@@ -31,7 +31,7 @@ void xen_hvm_inject_msi(uint64_t addr, uint32_t data)
 {
 }
 
-int xen_is_pirq_msi(uint32_t msi_data)
+int xen_is_pirq_msi(uint32_t msi_data, uint32_t msi_addr_lo)
 {
     return 0;
 }
xen-hvm.c +6 -1
index 2f348ed..9e78b23 100644
@@ -146,8 +146,13 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
     }
 }
 
-int xen_is_pirq_msi(uint32_t msi_data)
+int xen_is_pirq_msi(uint32_t msi_data, uint32_t msi_addr_lo)
 {
+    /* If msi address is configurate to remapping format, the msi will not
+     * remapped into a pirq.
+     */
+    if ( msi_addr_lo & 0x10 )
+        return 0;
     /* If vector is 0, the msi is remapped into a pirq, passed as
      * dest_id.
      */
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#11 lore raw

Re: [Qemu-devel] [RFC PATCH 4/4] msi: taking interrupt format into consideration during judging a pirq is binded with a event channel

Quoted 3 lines · Lan Tianyu

From: Chao Gao <[email protected]>
Subject: msi: taking interrupt format into consideration during judging a pirq is binded with a event channel

This is quite a long title, I think we can make it shorter. Maybe "msi:
Handle MSI remapping format.

Quoted 33 lines

As remapping format interrupt has been introduced, the vector in msi remapping format can also be 0, same as a interrupt is binded with a event channel. So we can't just use whether vector is 0 or not to judge a msi is binded to a event channel or not.

This patch takes the msi interrupt format into consideration.

---
 hw/pci/msi.c         | 5 +++--
 hw/pci/msix.c        | 4 +++-
 hw/xen/xen_pt_msi.c  | 2 +-
 include/hw/xen/xen.h | 2 +-
 xen-hvm-stub.c       | 2 +-
 xen-hvm.c            | 7 ++++++-
 6 files changed, 15 insertions(+), 7 deletions(-)
hw/pci/msi.c +1 -1
index a87b227..8d1ac9e 100644
@@ -289,7 +289,7 @@ void msi_reset(PCIDevice *dev)
 static bool msi_is_masked(const PCIDevice *dev, unsigned int vector)
 {
     uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev));
-    uint32_t mask, data;
+    uint32_t mask, data, addr_lo;
     bool msi64bit = flags & PCI_MSI_FLAGS_64BIT;
     assert(vector < PCI_MSI_VECTORS_MAX);
 

hw/pci/msi.c static bool msi_is_masked(const PCIDevice *dev, unsigned int vector) · line 301

Quoted 5 lines
hw/pci/msi.c +1 -1
@@ -298,7 +298,8 @@ static bool msi_is_masked(const PCIDevice *dev, unsigned int vector)
     }
 
     data = pci_get_word(dev->config + msi_data_off(dev, msi64bit));
-    if (xen_is_pirq_msi(data)) {
+    addr_lo = pci_get_word(dev->config + msi_address_lo_off(dev));

This could be get_long, so addr_lo will actually have the all low bits of the addr.

Quoted 26 lines
hw/pci/msi.c +1 -0
+    if (xen_is_pirq_msi(data, addr_lo)) {
         return false;
     }
 
hw/pci/msix.c +3 -1
index 0ec1cb1..6b8045a 100644
@@ -81,9 +81,11 @@ static bool msix_vector_masked(PCIDevice *dev, unsigned int vector, bool fmask)
 {
     unsigned offset = vector * PCI_MSIX_ENTRY_SIZE;
     uint8_t *data = &dev->msix_table[offset + PCI_MSIX_ENTRY_DATA];
+    uint8_t *addr_lo = &dev->msix_table[offset + PCI_MSIX_ENTRY_LOWER_ADDR];
     /* MSIs on Xen can be remapped into pirqs. In those cases, masking
      * and unmasking go through the PV evtchn path. */
-    if (xen_enabled() && xen_is_pirq_msi(pci_get_long(data))) {
+    if (xen_enabled() && xen_is_pirq_msi(pci_get_long(data),
+                                         pci_get_long(addr_lo))) {
         return false;
     }
     return fmask || dev->msix_table[offset + PCI_MSIX_ENTRY_VECTOR_CTRL] &
hw/xen/xen_pt_msi.c +0 -0
index 8b0d7fc..f799fed 100644

hw/xen/xen_pt_msi.c static int msi_msix_setup(XenPCIPassthroughState *s, · line 117

Quoted 5 lines
hw/xen/xen_pt_msi.c +1 -1
@@ -114,7 +114,7 @@ static int msi_msix_setup(XenPCIPassthroughState *s,
 
     assert((!is_msix && msix_entry == 0) || is_msix);
 
-    if (xen_is_pirq_msi(data)) {
+    if (xen_is_pirq_msi(data, (uint32_t)(addr & 0xffffffff))) {

I don't think the cast is necessary. Also the & 0xffffffff is probably not needed as well.

Quoted 34 lines
hw/xen/xen_pt_msi.c +0 -0
         *ppirq = msi_ext_dest_id(addr >> 32) | msi_dest_id(addr);
         if (!*ppirq) {
             /* this probably identifies an misconfiguration of the guest,
include/hw/xen/xen.h +1 -1
index a8f3afb..c15beb5 100644
@@ -33,7 +33,7 @@ int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
 void xen_piix3_set_irq(void *opaque, int irq_num, int level);
 void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
 void xen_hvm_inject_msi(uint64_t addr, uint32_t data);
-int xen_is_pirq_msi(uint32_t msi_data);
+int xen_is_pirq_msi(uint32_t msi_data, uint32_t msi_addr_lo);
 
 qemu_irq *xen_interrupt_controller_init(void);
 
xen-hvm-stub.c +1 -1
index c500325..dae421c 100644
@@ -31,7 +31,7 @@ void xen_hvm_inject_msi(uint64_t addr, uint32_t data)
 {
 }
 
-int xen_is_pirq_msi(uint32_t msi_data)
+int xen_is_pirq_msi(uint32_t msi_data, uint32_t msi_addr_lo)
 {
     return 0;
 }
xen-hvm.c +0 -0
index 2f348ed..9e78b23 100644

xen-hvm.c void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) · line 154

Quoted 10 lines
xen-hvm.c +5 -1
@@ -146,8 +146,13 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
     }
 }
 
-int xen_is_pirq_msi(uint32_t msi_data)
+int xen_is_pirq_msi(uint32_t msi_data, uint32_t msi_addr_lo)
 {
+    /* If msi address is configurate to remapping format, the msi will not
+     * remapped into a pirq.
+     */
+    if ( msi_addr_lo & 0x10 )

That's a magic number, is 0x10 MSI_ADDR_IM_MASK?

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#12 lore raw

Re: [Qemu-devel] [RFC PATCH 4/4] msi: taking interrupt format into consideration during judging a pirq is binded with a event channel

Quoted 7 lines · Anthony PERARD
Quoted 3 lines · Lan Tianyu

From: Chao Gao <[email protected]>
Subject: msi: taking interrupt format into consideration during judging a pirq is binded with a event channel

This is quite a long title, I think we can make it shorter. Maybe "msi:
Handle MSI remapping format.

OK.

Quoted 7 lines

hw/pci/msi.c static bool msi_is_masked(const PCIDevice *dev, unsigned int vector) · line 301

Quoted 4 lines
     data = pci_get_word(dev->config + msi_data_off(dev, msi64bit));
hw/pci/msi.c +1 -1
-    if (xen_is_pirq_msi(data)) {
+    addr_lo = pci_get_word(dev->config + msi_address_lo_off(dev));

This could be get_long, so addr_lo will actually have the all low bits of the addr.

yes.

Quoted 9 lines

xen-hvm.c void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) · line 154

Quoted 7 lines
xen-hvm.c +5 -0
+int xen_is_pirq_msi(uint32_t msi_data, uint32_t msi_addr_lo)
 {
+    /* If msi address is configurate to remapping format, the msi will not
+     * remapped into a pirq.
+     */
+    if ( msi_addr_lo & 0x10 )

That's a magic number, is 0x10 MSI_ADDR_IM_MASK?

Yes.

Really thanks for your comments.

Quoted 5 lines

Thanks,

Signature · 1 line
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#13 lore raw
In reply to Lan Tianyu
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Subject: [Qemu-devel] [RFC PATCH 0/4] Qemu: Add Xen vIOMMU support
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
0f16022 msi: taking interrupt format into consideration during judging a pirq is binded with a event channel 62b6353 xen-pt: bind/unbind interrupt remapping format MSI
0900f2b Xen: add a dummy vIOMMU to create/destroy vIOMMU in Xen
7cb3e06 I440: Allow adding sysbus devices with -device on I440

=== OUTPUT BEGIN ===
Checking PATCH 1/4: I440: Allow adding sysbus devices with -device on I440... Checking PATCH 2/4: Xen: add a dummy vIOMMU to create/destroy vIOMMU in Xen...
ERROR: trailing whitespace
#75: FILE: hw/xen/xen_viommu.c:48:
+ $

ERROR: trailing whitespace
#79: FILE: hw/xen/xen_viommu.c:52:
+ rc = xenstore_read_uint64(viommu_path, "base_addr", &s->base_addr); $

ERROR: trailing whitespace
#116: FILE: hw/xen/xen_viommu.c:89:
+ rc = xc_viommu_destroy(xen_xc, xen_domid, s->id); $

ERROR: trailing whitespace
#140: FILE: hw/xen/xen_viommu.c:113:
+ type_register_static(&xen_viommu_info); $

total: 4 errors, 0 warnings, 120 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 3/4: xen-pt: bind/unbind interrupt remapping format MSI...
ERROR: else should follow close brace '}'
#36: FILE: hw/xen/xen_pt_msi.c:179:
+ }
+ else {

ERROR: space prohibited after that open parenthesis '(' #54: FILE: hw/xen/xen_pt_msi.c:214:
+ if ( addr & MSI_ADDR_IM_MASK ) {

ERROR: space prohibited before that close parenthesis ')' #54: FILE: hw/xen/xen_pt_msi.c:214:
+ if ( addr & MSI_ADDR_IM_MASK ) {

WARNING: line over 80 characters
#55: FILE: hw/xen/xen_pt_msi.c:215:
+ XEN_PT_LOG(d, "Unbinding of MSI%s . ( pirq: %d, data: %x, addr: %lx)\n",

ERROR: line over 90 characters
#60: FILE: hw/xen/xen_pt_msi.c:220:
+ XEN_PT_ERR(d, "Unbinding of MSI%s . (error: %d, pirq: %d, data: %x, addr: %lx)\n",

WARNING: line over 80 characters
#68: FILE: hw/xen/xen_pt_msi.c:228:
+ rc = xc_domain_unbind_msi_irq(xen_xc, xen_domid, gvec, pirq, gflags);

ERROR: line over 90 characters
#70: FILE: hw/xen/xen_pt_msi.c:230:
+ XEN_PT_ERR(d, "Unbinding of MSI%s failed. (err: %d, pirq: %d, gvec: %#x)\n",

total: 5 errors, 2 warnings, 61 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 4/4: msi: taking interrupt format into consideration during judging a pirq is binded with a event channel...
ERROR: space prohibited after that open parenthesis '('
#111: FILE: xen-hvm.c:154:
+ if ( msi_addr_lo & 0x10 )

ERROR: space prohibited before that close parenthesis ')' #111: FILE: xen-hvm.c:154:
+ if ( msi_addr_lo & 0x10 )

ERROR: braces {} are necessary for all arms of this statement #111: FILE: xen-hvm.c:154:
+ if ( msi_addr_lo & 0x10 )
[...]

total: 3 errors, 0 warnings, 67 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#14 lore raw
In reply to Lan Tianyu
Quoted 7 lines · Lan Tianyu

This patchset is to add Xen vIOMMU device model and handle irq remapping stuffs. Xen vIOMMU emulation is in the Xen hypervisor and the new device module in Qemu works as hypercall wrappers to create and destroy vIOMMU in hypervisor.

Xen only supports emulated I440 and so we enable vIOMMU with emulated I440 chipset. This works on Linux and Windows guest.

Any plans to change this? Why is Xen not able to use Q35 with Intel IOMMU, with only special hooks for interrupt remapping?

Paolo

Quoted 6 lines

Chao Gao (4):
I440: Allow adding sysbus devices with -device on I440
Xen: add a dummy vIOMMU to create/destroy vIOMMU in Xen
xen-pt: bind/unbind interrupt remapping format MSI
msi: taking interrupt format into consideration during judging a pirq
is binded with a event channel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#15 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 7 lines · Lan Tianyu

This patchset is to add Xen vIOMMU device model and handle irq remapping stuffs. Xen vIOMMU emulation is in the Xen hypervisor and the new device module in Qemu works as hypercall wrappers to create and destroy vIOMMU in hypervisor.

Xen only supports emulated I440 and so we enable vIOMMU with emulated I440 chipset. This works on Linux and Windows guest.

Any plans to change this? Why is Xen not able to use Q35 with Intel IOMMU, with only special hooks for interrupt remapping?

CC'ing Anthony that worked on it in the past

Quoted 7 lines
Quoted 6 lines

Chao Gao (4):
I440: Allow adding sysbus devices with -device on I440
Xen: add a dummy vIOMMU to create/destroy vIOMMU in Xen
xen-pt: bind/unbind interrupt remapping format MSI
msi: taking interrupt format into consideration during judging a pirq
is binded with a event channel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#16 lore raw
In reply to Paolo Bonzini
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Lan Tianyu

This patchset is to add Xen vIOMMU device model and handle irq remapping stuffs. Xen vIOMMU emulation is in the Xen hypervisor and the new device module in Qemu works as hypercall wrappers to create and destroy vIOMMU in hypervisor.

Quoted 8 lines
Quoted 2 lines

Xen only supports emulated I440 and so we enable vIOMMU with emulated I440 chipset. This works on Linux and Windows guest.

Any plans to change this? Why is Xen not able to use Q35 with Intel IOMMU, with only special hooks for interrupt remapping?

Paolo

Hi Paolo:
Thanks for review. For Xen side, we won't reuse Intel IOMMU device model in Qemu and create counterpart in Xen hypervisor. The reasons are
1) Avoid round trips between Qemu and Xen hypervisor
2) Ease of integration with the rest part of the hypervisor(vIOAPIC,
vMSI and so on).

We don't have plan to enable Q35 for Xen now. There is no dependency between Q35 emulation and vIOMMU implementation from our test. As Stefano mentioned, Anthony worked on the Q35 support before. These two tasks can be done in parallel.

Signature · 7 lines
Best regards
Tianyu Lan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#17 lore raw
Quoted 5 lines · Lan Tianyu
Quoted 5 lines
Quoted 2 lines

Xen only supports emulated I440 and so we enable vIOMMU with emulated I440 chipset. This works on Linux and Windows guest.

Any plans to change this? Why is Xen not able to use Q35 with Intel IOMMU, with only special hooks for interrupt remapping?

Quoted 8 lines
Quoted 2 lines

Paolo

Hi Paolo:
Thanks for review. For Xen side, we won't reuse Intel IOMMU device model in Qemu and create counterpart in Xen hypervisor. The reasons are
1) Avoid round trips between Qemu and Xen hypervisor
2) Ease of integration with the rest part of the hypervisor(vIOAPIC,
vMSI and so on).

Fair enough, though I'd be worried about increasing the attack surface of the hypervisor. For KVM, for example, IOMMU emulation requires using the "split irqchip" feature to move the PIC and IOAPIC out of the kernel and back to QEMU.

Also, I think this series is missing changes to support IOMMU translation in the vIOMMU device model.

Paolo

Quoted 4 lines

We don't have plan to enable Q35 for Xen now. There is no dependency between Q35 emulation and vIOMMU implementation from our test. As Stefano mentioned, Anthony worked on the Q35 support before. These two tasks can be done in parallel.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#18 lore raw
Quoted 17 lines · Paolo Bonzini
Quoted 5 lines · Lan Tianyu
Quoted 5 lines
Quoted 2 lines

Xen only supports emulated I440 and so we enable vIOMMU with emulated I440 chipset. This works on Linux and Windows guest.

Any plans to change this? Why is Xen not able to use Q35 with Intel IOMMU, with only special hooks for interrupt remapping?

Quoted 8 lines
Quoted 2 lines

Paolo

Hi Paolo:
Thanks for review. For Xen side, we won't reuse Intel IOMMU device model in Qemu and create counterpart in Xen hypervisor. The reasons are
1) Avoid round trips between Qemu and Xen hypervisor
2) Ease of integration with the rest part of the hypervisor(vIOAPIC,
vMSI and so on).

Quoted 4 lines

Fair enough, though I'd be worried about increasing the attack surface of the hypervisor. For KVM, for example, IOMMU emulation requires using the "split irqchip" feature to move the PIC and IOAPIC out of the kernel and back to QEMU.

Yes, that's right, we are increasing the surface of attack. But Xen also needs it in order to support APIC IDs > 255 on PVH guests (that have a local APIC but no QEMU).

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#19 lore raw
Quoted 6 lines · Roger Pau Monné
Quoted 6 lines
Quoted 6 lines

Hi Paolo:
Thanks for review. For Xen side, we won't reuse Intel IOMMU device model in Qemu and create counterpart in Xen hypervisor. The reasons are
1) Avoid round trips between Qemu and Xen hypervisor
2) Ease of integration with the rest part of the hypervisor(vIOAPIC,
vMSI and so on).

Quoted 7 lines
Quoted 4 lines

Fair enough, though I'd be worried about increasing the attack surface of the hypervisor. For KVM, for example, IOMMU emulation requires using the "split irqchip" feature to move the PIC and IOAPIC out of the kernel and back to QEMU.

Yes, that's right, we are increasing the surface of attack. But Xen also needs it in order to support APIC IDs > 255 on PVH guests (that have a local APIC but no QEMU).

Not necessarily, you only need x2APIC support for that in the local APIC emulation. The MSI hypercalls (similar to KVM's MSI ioctls) can be extended to accept x2APIC VCPU ids.

Paolo

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#20 lore raw
In reply to Paolo Bonzini
Quoted 4 lines · Paolo Bonzini

Fair enough, though I'd be worried about increasing the attack surface of the hypervisor. For KVM, for example, IOMMU emulation requires using the "split irqchip" feature to move the PIC and IOAPIC out of the kernel and back to QEMU.

Yes, just like Roger mentioned we also need to support no-qemu mode on Xen and this is tradeoff result.

Quoted 3 lines

Also, I think this series is missing changes to support IOMMU translation in the vIOMMU device model.

Yes, this series just enabled vIOMMU's irq remapping function and we need to pass virtual device's DMA request to Xen hypervisor for translation when enable DMA translation.

Signature · 7 lines
Best regards
Tianyu Lan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel