Skip to contentSkip to conversation

spapr_pci: Disable IRQFD resampling on XIVE

PATCH In review Alexey Kardashevskiy 2 participants 6 messages Apr 27, 2022 – Apr 28, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spapr_pci: Disable IRQFD resampling on XIVE

VFIO-PCI has an "KVM_IRQFD_FLAG_RESAMPLE" optimization for INTx EOI handling when KVM can unmask PCI INTx (level triggered interrupt) without switching to the userspace (==QEMU).

Unfortunately XIVE does not support level interrupts, QEMU emulates them and therefore there is no existing code path to kick the resamplefd. The problem appears when passing through a PCI adapter with the "pci=nomsi" kernel parameter - the adapter's interrupt interrupt count in /proc/interrupts will stuck at "1".

This disables resampler when the XIVE interrupt controller is configured. This should not be very visible though KVM already exits to QEMU for INTx and XIVE-capable boxes (POWER9 and newer) do not seem to have performance-critical INTx-only capable devices.

---

Cédric, this is what I meant when I said that spapr_pci.c was unaware of the interrupt controller type, neither xics nor xive was mentioned in the file before.

---
 hw/ppc/spapr_pci.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +11 -3
index 5bfd4aa9e5aa..2675052601db 100644
@@ -729,11 +729,19 @@ static void pci_spapr_set_irq(void *opaque, int irq_num, int level)
 
 static PCIINTxRoute spapr_route_intx_pin_to_irq(void *opaque, int pin)
 {
+    SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
     SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(opaque);
-    PCIINTxRoute route;
+    PCIINTxRoute route = { .mode = PCI_INTX_DISABLED };
 
-    route.mode = PCI_INTX_ENABLED;
-    route.irq = sphb->lsi_table[pin].irq;
+    /*
+     * Disable IRQFD resampler on XIVE as it does not support LSI and QEMU
+     * emulates those so the KVM kernel resamplefd kick is skipped and EOI
+     * is not delivered to VFIO-PCI.
+     */
+    if (!spapr->xive) {
+        route.mode = PCI_INTX_ENABLED;
+        route.irq = sphb->lsi_table[pin].irq;
+    }
 
     return route;
 }
Signature · 1 line
2.30.2
#1 lore raw

Hello Alexey,

Quoted 5 lines · Alexey Kardashevskiy

VFIO-PCI has an "KVM_IRQFD_FLAG_RESAMPLE" optimization for INTx EOI handling when KVM can unmask PCI INTx (level triggered interrupt) without switching to the userspace (==QEMU).

Unfortunately XIVE does not support level interrupts,

That's not correctly phrased I think.

The QEMU XIVE device support LSIs but the POWER9 kernel-irqchips, KVM XICS-on-XIVE and XIVE native devices, are broken with respect to passthrough adapters using INTx.

Quoted 35 lines

QEMU emulates them
and therefore there is no existing code path to kick the resamplefd. The problem appears when passing through a PCI adapter with the "pci=nomsi" kernel parameter - the adapter's interrupt interrupt count in /proc/interrupts will stuck at "1".

This disables resampler when the XIVE interrupt controller is configured. This should not be very visible though KVM already exits to QEMU for INTx and XIVE-capable boxes (POWER9 and newer) do not seem to have performance-critical INTx-only capable devices.

---

Cédric, this is what I meant when I said that spapr_pci.c was unaware of the interrupt controller type, neither xics nor xive was mentioned in the file before.

---
  hw/ppc/spapr_pci.c | 14 +++++++++++---
  1 file changed, 11 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +1 -1
index 5bfd4aa9e5aa..2675052601db 100644
@@ -729,11 +729,19 @@ static void pci_spapr_set_irq(void *opaque, int irq_num, int level)
 
  static PCIINTxRoute spapr_route_intx_pin_to_irq(void *opaque, int pin)
  {
+    SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
      SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(opaque);
-    PCIINTxRoute route;

hw/ppc/spapr_pci.c static void pci_spapr_set_irq(void *opaque, int irq_num, int level) · line 741

Quoted 10 lines
hw/ppc/spapr_pci.c +7 -2
+    PCIINTxRoute route = { .mode = PCI_INTX_DISABLED };
 
-    route.mode = PCI_INTX_ENABLED;
-    route.irq = sphb->lsi_table[pin].irq;
+    /*
+     * Disable IRQFD resampler on XIVE as it does not support LSI and QEMU
+     * emulates those so the KVM kernel resamplefd kick is skipped and EOI
+     * is not delivered to VFIO-PCI.
+     */
+    if (!spapr->xive) {

This is testing the availability of the XIVE interrupt mode, but not the activate controller. See spapr_irq_init() which is called very early in the machine initialization.

Is that what we want ? Is everything fine if we start the machine with ic-mode=xics ? On a POWER9 host, this would use the KVM XICS-on-XIVE device which is broken also AFAICT.

You should extend the SpaprInterruptControllerClass (for a routine) or simply SpaprIrq (for a bool) if you need to handle IRQ matters from a device model.

Thanks,

C.

Quoted 6 lines
hw/ppc/spapr_pci.c +3 -0
+        route.mode = PCI_INTX_ENABLED;
+        route.irq = sphb->lsi_table[pin].irq;
+    }
 
      return route;
  }
#2 lore raw
Quoted 10 lines · Cédric Le Goater

Hello Alexey,

Quoted 5 lines · Alexey Kardashevskiy

VFIO-PCI has an "KVM_IRQFD_FLAG_RESAMPLE" optimization for INTx EOI handling when KVM can unmask PCI INTx (level triggered interrupt) without switching to the userspace (==QEMU).

Unfortunately XIVE does not support level interrupts,

That's not correctly phrased I think.

My bad, I meant "XIVE hardware".

Quoted 57 lines

The QEMU XIVE device support LSIs but the POWER9 kernel-irqchips, KVM XICS-on-XIVE and XIVE native devices, are broken with respect to passthrough adapters using INTx.

Quoted 40 lines

QEMU emulates them
and therefore there is no existing code path to kick the resamplefd. The problem appears when passing through a PCI adapter with the "pci=nomsi" kernel parameter - the adapter's interrupt interrupt count in /proc/interrupts will stuck at "1".

This disables resampler when the XIVE interrupt controller is configured. This should not be very visible though KVM already exits to QEMU for INTx and XIVE-capable boxes (POWER9 and newer) do not seem to have performance-critical INTx-only capable devices.

---

Cédric, this is what I meant when I said that spapr_pci.c was unaware of the interrupt controller type, neither xics nor xive was mentioned in the file before.

---
  hw/ppc/spapr_pci.c | 14 +++++++++++---

  1 file changed, 11 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +4 -3
index 5bfd4aa9e5aa..2675052601db 100644
@@ -729,11 +729,19 @@ static void pci_spapr_set_irq(void *opaque, int 
 irq_num, int level)
   static PCIINTxRoute spapr_route_intx_pin_to_irq(void *opaque, int pin)
   {
+    SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
       SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(opaque);
-    PCIINTxRoute route;
+    PCIINTxRoute route = { .mode = PCI_INTX_DISABLED };
-    route.mode = PCI_INTX_ENABLED;
-    route.irq = sphb->lsi_table[pin].irq;
+    /*
+     * Disable IRQFD resampler on XIVE as it does not support LSI and 
Quoted 6 lines

QEMU
+     * emulates those so the KVM kernel resamplefd kick is skipped and EOI
+     * is not delivered to VFIO-PCI.
+     */
+    if (!spapr->xive) {

This is testing the availability of the XIVE interrupt mode, but not the activate controller. See spapr_irq_init() which is called very early in the machine initialization.

Quoted 3 lines

Is that what we want ? Is everything fine if we start the machine with ic-mode=xics ? On a POWER9 host, this would use the KVM XICS-on-XIVE device which is broken also AFAICT.

I should probably fix that in KVM, just not quite sure yet how for the realmode handlers, or just drop those on P9 and then the fix is trivial.

Quoted 3 lines

You should extend the SpaprInterruptControllerClass (for a routine) or simply SpaprIrq (for a bool) if you need to handle IRQ matters from a device model.

It is a property of KVM rather than the interrupt controller so it probably makes more sense to just stop advertising KVM_CAP_IRQFD_RESAMPLE. Hmmm...

Quoted 11 lines

Thanks,

C.

Quoted 5 lines

+        route.mode = PCI_INTX_ENABLED;
+        route.irq = sphb->lsi_table[pin].irq;
+    }
      return route;
  }

#3 lore raw
Quoted 10 lines · Alexey Kardashevskiy
Quoted 7 lines · Cédric Le Goater

Hello Alexey,

Quoted 4 lines · Alexey Kardashevskiy

VFIO-PCI has an "KVM_IRQFD_FLAG_RESAMPLE" optimization for INTx EOI handling when KVM can unmask PCI INTx (level triggered interrupt) without switching to the userspace (==QEMU).

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Unfortunately XIVE does not support level interrupts,

That's not correctly phrased I think.

My bad, I meant "XIVE hardware".

ok. It makes more sense.

PSIHB and PHBs have internal latches to maintain the assertion level. XIVE has none.

Quoted 59 lines
Quoted 55 lines

The QEMU XIVE device support LSIs but the POWER9 kernel-irqchips, KVM XICS-on-XIVE and XIVE native devices, are broken with respect to passthrough adapters using INTx.

Quoted 33 lines

QEMU emulates them
and therefore there is no existing code path to kick the resamplefd. The problem appears when passing through a PCI adapter with the "pci=nomsi" kernel parameter - the adapter's interrupt interrupt count in /proc/interrupts will stuck at "1".

This disables resampler when the XIVE interrupt controller is configured. This should not be very visible though KVM already exits to QEMU for INTx and XIVE-capable boxes (POWER9 and newer) do not seem to have performance-critical INTx-only capable devices.

---

Cédric, this is what I meant when I said that spapr_pci.c was unaware of the interrupt controller type, neither xics nor xive was mentioned in the file before.

---
  hw/ppc/spapr_pci.c | 14 +++++++++++---

  1 file changed, 11 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +1 -0
index 5bfd4aa9e5aa..2675052601db 100644
@@ -729,11 +729,19 @@ static void pci_spapr_set_irq(void *opaque, int irq_num, int level)
   static PCIINTxRoute spapr_route_intx_pin_to_irq(void *opaque, int pin)
   {
+    SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
       SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(opaque);

hw/ppc/spapr_pci.c static void pci_spapr_set_irq(void *opaque, int irq_num, int level) · line 739

Quoted 10 lines
hw/ppc/spapr_pci.c +7 -3
-    PCIINTxRoute route;
+    PCIINTxRoute route = { .mode = PCI_INTX_DISABLED };
-    route.mode = PCI_INTX_ENABLED;
-    route.irq = sphb->lsi_table[pin].irq;
+    /*
+     * Disable IRQFD resampler on XIVE as it does not support LSI and QEMU
+     * emulates those so the KVM kernel resamplefd kick is skipped and EOI
+     * is not delivered to VFIO-PCI.
+     */
+    if (!spapr->xive) {

This is testing the availability of the XIVE interrupt mode, but not the activate controller. See spapr_irq_init() which is called very early in the machine initialization.

Quoted 3 lines

Is that what we want ? Is everything fine if we start the machine with ic-mode=xics ? On a POWER9 host, this would use the KVM XICS-on-XIVE device which is broken also AFAICT.

Quoted 8 lines

I should probably fix that in KVM, just not quite sure yet how for the realmode handlers, or just drop those on P9 and then the fix is trivial.

Quoted 3 lines

You should extend the SpaprInterruptControllerClass (for a routine) or simply SpaprIrq (for a bool) if you need to handle IRQ matters from a device model.

It is a property of KVM rather than the interrupt controller so it probably makes more sense to just stop advertising KVM_CAP_IRQFD_RESAMPLE. Hmmm...

I would fix the realmode handlers of the the KVM XICS-on-XIVE device first. The problem has been there for a while.

Then, for the XIVE native mode, I would simply handle it at the QEMU level with a 'resample' bool in SpaprIrq. It would be tested in spapr pci when configuring the INTx routing.

Thanks,

C.

#4 lore raw
Quoted 89 lines · Cédric Le Goater
Quoted 10 lines · Alexey Kardashevskiy
Quoted 7 lines · Cédric Le Goater

Hello Alexey,

Quoted 4 lines · Alexey Kardashevskiy

VFIO-PCI has an "KVM_IRQFD_FLAG_RESAMPLE" optimization for INTx EOI handling when KVM can unmask PCI INTx (level triggered interrupt) without switching to the userspace (==QEMU).

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Unfortunately XIVE does not support level interrupts,

That's not correctly phrased I think.

My bad, I meant "XIVE hardware".

ok. It makes more sense.

PSIHB and PHBs have internal latches to maintain the assertion level. XIVE has none.

Quoted 65 lines
Quoted 58 lines

The QEMU XIVE device support LSIs but the POWER9 kernel-irqchips, KVM XICS-on-XIVE and XIVE native devices, are broken with respect to passthrough adapters using INTx.

Quoted 40 lines

QEMU emulates them
and therefore there is no existing code path to kick the resamplefd. The problem appears when passing through a PCI adapter with the "pci=nomsi" kernel parameter - the adapter's interrupt interrupt count in /proc/interrupts will stuck at "1".

This disables resampler when the XIVE interrupt controller is configured. This should not be very visible though KVM already exits to QEMU for INTx and XIVE-capable boxes (POWER9 and newer) do not seem to have performance-critical INTx-only capable devices.

---

Cédric, this is what I meant when I said that spapr_pci.c was unaware of the interrupt controller type, neither xics nor xive was mentioned in the file before.

---
  hw/ppc/spapr_pci.c | 14 +++++++++++---

  1 file changed, 11 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +4 -3
index 5bfd4aa9e5aa..2675052601db 100644
@@ -729,11 +729,19 @@ static void pci_spapr_set_irq(void *opaque, 
 int irq_num, int level)
   static PCIINTxRoute spapr_route_intx_pin_to_irq(void *opaque, int pin)
   {
+    SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
       SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(opaque);
-    PCIINTxRoute route;
+    PCIINTxRoute route = { .mode = PCI_INTX_DISABLED };
-    route.mode = PCI_INTX_ENABLED;
-    route.irq = sphb->lsi_table[pin].irq;
+    /*
+     * Disable IRQFD resampler on XIVE as it does not support LSI 
Quoted 6 lines

and QEMU
+     * emulates those so the KVM kernel resamplefd kick is skipped and EOI
+     * is not delivered to VFIO-PCI.
+     */
+    if (!spapr->xive) {

This is testing the availability of the XIVE interrupt mode, but not the activate controller. See spapr_irq_init() which is called very early in the machine initialization.

Quoted 3 lines

Is that what we want ? Is everything fine if we start the machine with ic-mode=xics ? On a POWER9 host, this would use the KVM XICS-on-XIVE device which is broken also AFAICT.

I should probably fix that in KVM, just not quite sure yet how for the realmode handlers, or just drop those on P9 and then the fix is trivial.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

You should extend the SpaprInterruptControllerClass (for a routine) or simply SpaprIrq (for a bool) if you need to handle IRQ matters from a device model.

It is a property of KVM rather than the interrupt controller so it probably makes more sense to just stop advertising KVM_CAP_IRQFD_RESAMPLE. Hmmm...

I would fix the realmode handlers of the the KVM XICS-on-XIVE device first. The problem has been there for a while.

Are they really used on POWER9? TCE ones are not.

Quoted 3 lines

Then, for the XIVE native mode, I would simply handle it at the QEMU level with a 'resample' bool in SpaprIrq. It  would be tested in spapr pci when configuring the INTx routing.

But there is a dedicated CAP advertised by the KVM already which is not correct as we know that KVM won't resample.

Quoted 6 lines

Thanks,

C.

#5 lore raw
Quoted 93 lines · Alexey Kardashevskiy
Quoted 90 lines · Cédric Le Goater
Quoted 10 lines · Alexey Kardashevskiy
Quoted 7 lines · Cédric Le Goater

Hello Alexey,

Quoted 4 lines · Alexey Kardashevskiy

VFIO-PCI has an "KVM_IRQFD_FLAG_RESAMPLE" optimization for INTx EOI handling when KVM can unmask PCI INTx (level triggered interrupt) without switching to the userspace (==QEMU).

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Unfortunately XIVE does not support level interrupts,

That's not correctly phrased I think.

My bad, I meant "XIVE hardware".

ok. It makes more sense.

PSIHB and PHBs have internal latches to maintain the assertion level. XIVE has none.

Quoted 66 lines
Quoted 55 lines

The QEMU XIVE device support LSIs but the POWER9 kernel-irqchips, KVM XICS-on-XIVE and XIVE native devices, are broken with respect to passthrough adapters using INTx.

Quoted 33 lines

QEMU emulates them
and therefore there is no existing code path to kick the resamplefd. The problem appears when passing through a PCI adapter with the "pci=nomsi" kernel parameter - the adapter's interrupt interrupt count in /proc/interrupts will stuck at "1".

This disables resampler when the XIVE interrupt controller is configured. This should not be very visible though KVM already exits to QEMU for INTx and XIVE-capable boxes (POWER9 and newer) do not seem to have performance-critical INTx-only capable devices.

---

Cédric, this is what I meant when I said that spapr_pci.c was unaware of the interrupt controller type, neither xics nor xive was mentioned in the file before.

---
  hw/ppc/spapr_pci.c | 14 +++++++++++---

  1 file changed, 11 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +1 -0
index 5bfd4aa9e5aa..2675052601db 100644
@@ -729,11 +729,19 @@ static void pci_spapr_set_irq(void *opaque, int irq_num, int level)
   static PCIINTxRoute spapr_route_intx_pin_to_irq(void *opaque, int pin)
   {
+    SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
       SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(opaque);

hw/ppc/spapr_pci.c static void pci_spapr_set_irq(void *opaque, int irq_num, int level) · line 739

Quoted 10 lines
hw/ppc/spapr_pci.c +7 -3
-    PCIINTxRoute route;
+    PCIINTxRoute route = { .mode = PCI_INTX_DISABLED };
-    route.mode = PCI_INTX_ENABLED;
-    route.irq = sphb->lsi_table[pin].irq;
+    /*
+     * Disable IRQFD resampler on XIVE as it does not support LSI and QEMU
+     * emulates those so the KVM kernel resamplefd kick is skipped and EOI
+     * is not delivered to VFIO-PCI.
+     */
+    if (!spapr->xive) {

This is testing the availability of the XIVE interrupt mode, but not the activate controller. See spapr_irq_init() which is called very early in the machine initialization.

Quoted 3 lines

Is that what we want ? Is everything fine if we start the machine with ic-mode=xics ? On a POWER9 host, this would use the KVM XICS-on-XIVE device which is broken also AFAICT.

I should probably fix that in KVM, just not quite sure yet how for the realmode handlers, or just drop those on P9 and then the fix is trivial.

Quoted 3 lines

You should extend the SpaprInterruptControllerClass (for a routine) or simply SpaprIrq (for a bool) if you need to handle IRQ matters from a device model.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

It is a property of KVM rather than the interrupt controller so it probably makes more sense to just stop advertising KVM_CAP_IRQFD_RESAMPLE. Hmmm...

I would fix the realmode handlers of the the KVM XICS-on-XIVE device first. The problem has been there for a while.

Are they really used on POWER9? TCE ones are not.

The HCALLs should be.

Quoted 6 lines
Quoted 3 lines

Then, for the XIVE native mode, I would simply handle it at the QEMU level with a 'resample' bool in SpaprIrq. It  would be tested in spapr pci when configuring the INTx routing.

But there is a dedicated CAP advertised by the KVM already which is not correct as we know that KVM won't resample.

You know more that I do in that area now.

C.

Quoted 7 lines
Quoted 7 lines

Thanks,

C.