Skip to contentSkip to conversation

Generic PCIe host bridge INTx determination for INTx routing

PATCH Applied Eric Auger 3 participants 6 messages Sep 13, 2017 – Sep 14, 2017

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

v4 cover Generic PCIe host bridge INTx determination for INTx routing

This series implements INTx to gsi routing for ARM VIRT/Gpex. This is a respin of [1] which was lost in limbo.

ARM virt uses GPEX PCIe bridge. This latter does not implement INTx to GSI routing. PCIe/INTx assignment works but the consequence is irqfd is not used along with INTx interrupts and VFIO INTx handlers are executed on userspace leading to an important performance degradation.

This issue is witnessed by the following messages;

qemu-system-aarch64: -device vfio-pci,host=0006:90:00.0: PCI: Bug - unimplemented PCI INTx routing (gpex-pcihost)
qemu-system-aarch64: PCI: Bug - unimplemented PCI INTx routing (gpex-pcihost)
qemu-system-aarch64: PCI: Bug - unimplemented PCI INTx routing (gpex-pcihost)

So with this series, irqfd is set up for PCIe/INTx passthrough and we get the optimal performance. Also we get rid of the above messages.

This series can be found at:
https://github.com/eauger/qemu/tree/v2.10.0-gpex-v4

References:
[1] Generic PCIe host bridge INTx determination for INTx routing
https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg04975.html

History:
v3 -> v3:
- use int instead of uint32_t for gsis
- added Drew's R-b
- Added Feng's T-b

Pranavkumar Sawargaonkar (3):
hw/pci-host/gpex: Set INTx index/gsi mapping
hw/arm/virt: Set INTx/gsi mapping
hw/pci-host/gpex: Implement PCI INTx routing

 hw/arm/virt.c              |  1 +
 hw/pci-host/gpex.c         | 22 ++++++++++++++++++++++
 include/hw/pci-host/gpex.h |  3 +++
 3 files changed, 26 insertions(+)
Signature · 1 line
2.5.5
author
#1 lore raw

PATCH v4 1/3 hw/pci-host/gpex: Set INTx index/gsi mapping

From: Pranavkumar Sawargaonkar <[email protected]>

To implement INTx to gsi routing we need to pass the gpex host bridge the gsi associated to each INTx index. Let's introduce irq_num array and gpex_set_irq_num setter function.

---

v3 -> v4:
- use int for gsi

---
 hw/pci-host/gpex.c         | 10 ++++++++++
 include/hw/pci-host/gpex.h |  3 +++
 2 files changed, 13 insertions(+)
hw/pci-host/gpex.c +10 -0
index 83084b9..41a884d 100644
@@ -43,6 +43,16 @@ static void gpex_set_irq(void *opaque, int irq_num, int level)
     qemu_set_irq(s->irq[irq_num], level);
 }
 
+int gpex_set_irq_num(GPEXHost *s, int index, int gsi)
+{
+    if (index >= GPEX_NUM_IRQS) {
+        return -EINVAL;
+    }
+
+    s->irq_num[index] = gsi;
+    return 0;
+}
+
 static void gpex_host_realize(DeviceState *dev, Error **errp)
 {
     PCIHostState *pci = PCI_HOST_BRIDGE(dev);
include/hw/pci-host/gpex.h +3 -0
index 68c9348..aef38b8 100644
@@ -51,6 +51,9 @@ typedef struct GPEXHost {
     MemoryRegion io_ioport;
     MemoryRegion io_mmio;
     qemu_irq irq[GPEX_NUM_IRQS];
+    int irq_num[GPEX_NUM_IRQS];
 } GPEXHost;
 
+int gpex_set_irq_num(GPEXHost *s, int index, int gsi);
+
 #endif /* HW_GPEX_H */
Signature · 1 line
2.5.5
Reviewed-by on v4 1/3
#2 lore raw

Re: [Qemu-arm] [PATCH v4 1/3] hw/pci-host/gpex: Set INTx index/gsi mapping

Quoted 58 lines · Eric Auger

From: Pranavkumar Sawargaonkar <[email protected]>

To implement INTx to gsi routing we need to pass the gpex host bridge the gsi associated to each INTx index. Let's introduce irq_num array and gpex_set_irq_num setter function.

---

v3 -> v4:
- use int for gsi

---
 hw/pci-host/gpex.c         | 10 ++++++++++
 include/hw/pci-host/gpex.h |  3 +++
 2 files changed, 13 insertions(+)
hw/pci-host/gpex.c +10 -0
index 83084b9..41a884d 100644
@@ -43,6 +43,16 @@ static void gpex_set_irq(void *opaque, int irq_num, int level)
     qemu_set_irq(s->irq[irq_num], level);
 }
 
+int gpex_set_irq_num(GPEXHost *s, int index, int gsi)
+{
+    if (index >= GPEX_NUM_IRQS) {
+        return -EINVAL;
+    }
+
+    s->irq_num[index] = gsi;
+    return 0;
+}
+
 static void gpex_host_realize(DeviceState *dev, Error **errp)
 {
     PCIHostState *pci = PCI_HOST_BRIDGE(dev);
include/hw/pci-host/gpex.h +3 -0
index 68c9348..aef38b8 100644
@@ -51,6 +51,9 @@ typedef struct GPEXHost {
     MemoryRegion io_ioport;
     MemoryRegion io_mmio;
     qemu_irq irq[GPEX_NUM_IRQS];
+    int irq_num[GPEX_NUM_IRQS];
 } GPEXHost;
 
+int gpex_set_irq_num(GPEXHost *s, int index, int gsi);
+
 #endif /* HW_GPEX_H */
Signature · 1 line
2.5.5
author
#3 lore raw

PATCH v4 2/3 hw/arm/virt: Set INTx/gsi mapping

In reply to Eric Auger

From: Pranavkumar Sawargaonkar <[email protected]>

Let's provide the GPEX host bridge with the INTx/gsi mapping. This is needed for INTx/gsi routing.

---

v3 -> v4:
- don't use GPEXHost *s anymore
- added Drew's R-b

---
 hw/arm/virt.c | 1 +
 1 file changed, 1 insertion(+)
hw/arm/virt.c +1 -0
index fe96557..cfd834d 100644
@@ -1057,6 +1057,7 @@ static void create_pcie(const VirtMachineState *vms, qemu_irq *pic)
 
     for (i = 0; i < GPEX_NUM_IRQS; i++) {
         sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, pic[irq + i]);
+        gpex_set_irq_num(GPEX_HOST(dev), i, irq + i);
     }
 
     pci = PCI_HOST_BRIDGE(dev);
Signature · 1 line
2.5.5
author
#4 lore raw

PATCH v4 3/3 hw/pci-host/gpex: Implement PCI INTx routing

In reply to Eric Auger

From: Pranavkumar Sawargaonkar <[email protected]>

Now we are able to retrieve the gsi from the INTx pin, let's enable intx_to_irq routing. From that point on, irqfd becomes usable along with INTx when assigning a PCIe device.

---

v3 -> v4:
- remove the cast to int
- added Drew's R-b

---
 hw/pci-host/gpex.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/pci-host/gpex.c +12 -0
index 41a884d..be25245 100644
@@ -53,6 +53,17 @@ int gpex_set_irq_num(GPEXHost *s, int index, int gsi)
     return 0;
 }
 
+static PCIINTxRoute gpex_route_intx_pin_to_irq(void *opaque, int pin)
+{
+    PCIINTxRoute route;
+    GPEXHost *s = opaque;
+
+    route.mode = PCI_INTX_ENABLED;
+    route.irq = s->irq_num[pin];
+
+    return route;
+}
+
 static void gpex_host_realize(DeviceState *dev, Error **errp)
 {
     PCIHostState *pci = PCI_HOST_BRIDGE(dev);
@@ -77,6 +88,7 @@ static void gpex_host_realize(DeviceState *dev, Error **errp)
                                 &s->io_ioport, 0, 4, TYPE_PCIE_BUS);
 
     qdev_set_parent_bus(DEVICE(&s->gpex_root), BUS(pci->bus));
+    pci_bus_set_route_irq_fn(pci->bus, gpex_route_intx_pin_to_irq);
     qdev_init_nofail(DEVICE(&s->gpex_root));
 }
 
Signature · 1 line
2.5.5
#5 lore raw
In reply to Eric Auger
Quoted 18 lines · Eric Auger

This series implements INTx to gsi routing for ARM VIRT/Gpex. This is a respin of [1] which was lost in limbo.

ARM virt uses GPEX PCIe bridge. This latter does not implement INTx to GSI routing. PCIe/INTx assignment works but the consequence is irqfd is not used along with INTx interrupts and VFIO INTx handlers are executed on userspace leading to an important performance degradation.

This issue is witnessed by the following messages;

qemu-system-aarch64: -device vfio-pci,host=0006:90:00.0: PCI: Bug - unimplemented PCI INTx routing (gpex-pcihost)
qemu-system-aarch64: PCI: Bug - unimplemented PCI INTx routing (gpex-pcihost)
qemu-system-aarch64: PCI: Bug - unimplemented PCI INTx routing (gpex-pcihost)

So with this series, irqfd is set up for PCIe/INTx passthrough and we get the optimal performance. Also we get rid of the above messages.

Quoted 6 lines

This series can be found at:
https://github.com/eauger/qemu/tree/v2.10.0-gpex-v4

References:
[1] Generic PCIe host bridge INTx determination for INTx routing
https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg04975.html

Applied to target-arm.next, thanks.

-- PMM