Skip to contentSkip to conversation

genirq: s390/pci: Migrate MSI interrupts to irqdomain API

PATCH Superseded Tobias Schumacher 4 participants 11 messages Nov 27, 2025 – Dec 3, 2025

Subsystems (3)

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v7 cover genirq: s390/pci: Migrate MSI interrupts to irqdomain API

This patch series reworks the PCIe interrupt handling on s390 by migrating it to use a proper MSI parent domain. Introducing a dedicated MSI domain hierarchy aligns s390 PCIe support with the generic Linux IRQ domain model. Currently s390 is one of the last architectures still using the legacy API.

The migration splits the existing code in the legacy functions arch_setup_msi_irqs() and arch_teardown_msi_irqs() into different callbacks of the newly created MSI parent domain:

- zpci_msi_prepare(): prepare the allocation of per-device MSI IRQs. will be called once for each device before allocating individual IRQs and sets up for example the adapter aisb and aibv.
- zpci_msi_teardown(): reverts the effects of zpci_msi_prepare() and is called after all MSI IRQs are freed.
- zpci_msi_domain_alloc(): the allocation function for interrupts
- zpci_msi_domain_free(): revert the effects of zpci_msi_domain_alloc()
- zpci_compose_msi_msg(): create the MSI message to be written into the corresponding PCI config space.

* Patch 1 fixes an inconsistency in the irqdomain API. Internally, hw irqs are represented by an unsigned long int (irq_hw_number_t) while the external API in some cases takes an unsigned int as parameter. This fix was required in V2 of the patchset. Due to conceptual changes in patch 2 it is not required anymore for s390, but still seems sensible.
* Patch 2 implements IRQ domains for s390 PCI

Since patch 1 changes common APIs, some build tests were done for x86_64 and arm64.

---
Changes in v7:
- call zpci_set_irq() in zpci_reenable_device() to fix recovery after
zpcictl --reset-fw
- add commas at end of initializers
- remove unused variables in free()
- removed R-b for patch 2 because of bug fixes
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- removed obsolete function zpci_decode_hwirq_msi_index()
- removed some code duplication
- fixed some coding style issues
- corrected hwirq encoding in commit message
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- removed two lines of superfluous code
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- remove flag MSI_FLAG_PCI_MSI_MASK_PARENT and mask/unmask callbacks
- use goto statements in zpci_bus_create_pci_bus()
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- implement one MSI parent domain per PCI domain to further align the
implementation with other architectures.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- fix directed interrupt setup and handling
- add flag MSI_FLAG_NO_AFFINITY in case of floating interrupts
- style adjustments according to review comments
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Tobias Schumacher (2):
genirq: Change hwirq parameter to irq_hw_number_t s390/pci: Migrate s390 IRQ logic to IRQ domain API

 arch/s390/Kconfig           |   1 +
 arch/s390/include/asm/pci.h |   5 +
 arch/s390/pci/pci.c         |   6 +
 arch/s390/pci/pci_bus.c     |  18 ++-
 arch/s390/pci/pci_irq.c     | 310 ++++++++++++++++++++++++++++----------------
 include/linux/irqdesc.h     |   6 +-
 kernel/irq/irqdesc.c        |   6 +-
 7 files changed, 230 insertions(+), 122 deletions(-)

---
base-commit: 82ef9f0fac73cca3e7d776b095b5a7de1b0b88fc
change-id: 20251104-implement-msi-domain-dc1ea014580e

Best regards,

Signature · 1 line
Tobias Schumacher <[email protected]>
#1 lore raw

PATCH v7 1/2 genirq: Change hwirq parameter to irq_hw_number_t

The irqdomain implementation internally represents hardware IRQs as irq_hw_number_t, which is defined as unsigned long int. When providing an irq_hw_number_t to the generic_handle_domain() functions that expect and unsigned int hwirq, this can lead to a loss of information. Change the hwirq parameter to irq_hw_number_t to support the full range of hwirqs.

---
 include/linux/irqdesc.h | 6 +++---
 kernel/irq/irqdesc.c    | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
include/linux/irqdesc.h +3 -3
index fd091c35d5721eee37a2fd3d5526559671d5048d..03b63aea73bb21ae1456910afa534d60f9cfa94d 100644
@@ -183,9 +183,9 @@ int generic_handle_irq_safe(unsigned int irq);
  * and handle the result interrupt number. Return -EINVAL if
  * conversion failed.
  */
-int generic_handle_domain_irq(struct irq_domain *domain, unsigned int hwirq);
-int generic_handle_domain_irq_safe(struct irq_domain *domain, unsigned int hwirq);
-int generic_handle_domain_nmi(struct irq_domain *domain, unsigned int hwirq);
+int generic_handle_domain_irq(struct irq_domain *domain, irq_hw_number_t hwirq);
+int generic_handle_domain_irq_safe(struct irq_domain *domain, irq_hw_number_t hwirq);
+int generic_handle_domain_nmi(struct irq_domain *domain, irq_hw_number_t hwirq);
 #endif
 
 /* Test to see if a driver has successfully requested an irq */
kernel/irq/irqdesc.c +3 -3
index db714d3014b5f7b62403ea04b80331ec6b1dc642..0cd3198496bc0766c81c353c3ff80ea184793d6a 100644
@@ -720,7 +720,7 @@ EXPORT_SYMBOL_GPL(generic_handle_irq_safe);
  * 		This function must be called from an IRQ context with irq regs
  * 		initialized.
  */
-int generic_handle_domain_irq(struct irq_domain *domain, unsigned int hwirq)
+int generic_handle_domain_irq(struct irq_domain *domain, irq_hw_number_t hwirq)
 {
 	return handle_irq_desc(irq_resolve_mapping(domain, hwirq));
 }
@@ -738,7 +738,7 @@ EXPORT_SYMBOL_GPL(generic_handle_domain_irq);
  * context). If the interrupt is marked as 'enforce IRQ-context only' then
  * the function must be invoked from hard interrupt context.
  */
-int generic_handle_domain_irq_safe(struct irq_domain *domain, unsigned int hwirq)
+int generic_handle_domain_irq_safe(struct irq_domain *domain, irq_hw_number_t hwirq)
 {
 	unsigned long flags;
 	int ret;
@@ -761,7 +761,7 @@ EXPORT_SYMBOL_GPL(generic_handle_domain_irq_safe);
  * 		This function must be called from an NMI context with irq regs
  * 		initialized.
  **/
-int generic_handle_domain_nmi(struct irq_domain *domain, unsigned int hwirq)
+int generic_handle_domain_nmi(struct irq_domain *domain, irq_hw_number_t hwirq)
 {
 	WARN_ON_ONCE(!in_nmi());
 	return handle_irq_desc(irq_resolve_mapping(domain, hwirq));
Signature · 1 line
2.51.0
#2 lore raw

PATCH v7 2/2 s390/pci: Migrate s390 IRQ logic to IRQ domain API

In reply to Tobias Schumacher

s390 is one of the last architectures using the legacy API for setup and teardown of PCI MSI IRQs. Migrate the s390 IRQ allocation and teardown to the MSI parent domain API. For details, see:

https://lore.kernel.org/lkml/[email protected]

In detail, create an MSI parent domain for each PCI domain. When a PCI device sets up MSI or MSI-X IRQs, the library creates a per-device IRQ domain for this device, which is used by the device for allocating and freeing IRQs.

The per-device domain delegates this allocation and freeing to the parent-domain. In the end, the corresponding callbacks of the parent domain are responsible for allocating and freeing the IRQs.

The allocation is split into two parts:
- zpci_msi_prepare() is called once for each device and allocates the required resources. On s390, each PCI function has its own airq vector and a summary bit, which must be configured once per function. This is done in prepare().
- zpci_msi_alloc() can be called multiple times for allocating one or more MSI/MSI-X IRQs. This creates a mapping between the virtual IRQ number in the kernel and the hardware IRQ number.

Freeing is split into two counterparts:
- zpci_msi_free() reverts the effects of zpci_msi_alloc() and
- zpci_msi_teardown() reverts the effects of zpci_msi_prepare(). This is called once when all IRQs are freed before a device is removed.

Since the parent domain in the end allocates the IRQs, the hwirq encoding must be unambiguous for all IRQs of all devices. This is achieved by encoding the hwirq using the devfn and the MSI index.

---
 arch/s390/Kconfig           |   1 +
 arch/s390/include/asm/pci.h |   5 +
 arch/s390/pci/pci.c         |   6 +
 arch/s390/pci/pci_bus.c     |  18 ++-
 arch/s390/pci/pci_irq.c     | 310 ++++++++++++++++++++++++++++----------------
 5 files changed, 224 insertions(+), 116 deletions(-)
arch/s390/Kconfig +1 -0
index 778ce20d34046cad84dd4ef57cab5a662e5796d9..fc82dd4f893d78f12837f36ab82a05f2c52e0501 100644
@@ -251,6 +251,7 @@ config S390
 	select HOTPLUG_SMT
 	select IOMMU_HELPER		if PCI
 	select IOMMU_SUPPORT		if PCI
+	select IRQ_MSI_LIB		if PCI
 	select KASAN_VMALLOC if KASAN
 	select LOCK_MM_AND_FIND_VMA
 	select MMU_GATHER_MERGE_VMAS
arch/s390/include/asm/pci.h +5 -0
index a32f465ecf73a5cc3408a312d94ec888d62848cc..0aa6915346a50077f22868cef39638919979d478 100644
@@ -5,6 +5,7 @@
 #include <linux/pci.h>
 #include <linux/mutex.h>
 #include <linux/iommu.h>
+#include <linux/irqdomain.h>
 #include <linux/pci_hotplug.h>
 #include <asm/pci_clp.h>
 #include <asm/pci_debug.h>
@@ -109,6 +110,7 @@ struct zpci_bus {
 	struct list_head	resources;
 	struct list_head	bus_next;
 	struct resource		bus_resource;
+	struct irq_domain       *msi_parent_domain;
 	int			topo;		/* TID if topo_is_tid, PCHID otherwise */
 	int			domain_nr;
 	u8			multifunction	: 1;
@@ -310,6 +312,9 @@ int zpci_dma_exit_device(struct zpci_dev *zdev);
 /* IRQ */
 int __init zpci_irq_init(void);
 void __init zpci_irq_exit(void);
+int zpci_set_irq(struct zpci_dev *zdev);
+int zpci_create_parent_msi_domain(struct zpci_bus *zbus);
+void zpci_remove_parent_msi_domain(struct zpci_bus *zbus);
 
 /* FMB */
 int zpci_fmb_enable_device(struct zpci_dev *);
arch/s390/pci/pci.c +6 -0
index c82c577db2bcd2143476cb8189fd89b9a4dc9836..2e47bf6a3289615307c71cae7b04ef77d964144a 100644
@@ -709,6 +709,12 @@ int zpci_reenable_device(struct zpci_dev *zdev)
 	if (rc)
 		return rc;
 
+	if (zdev->msi_nr_irqs > 0) {
+		rc = zpci_set_irq(zdev);
+		if (rc)
+			return rc;
+	}
+
 	rc = zpci_iommu_register_ioat(zdev, &status);
 	if (rc)
 		zpci_disable_device(zdev);
arch/s390/pci/pci_bus.c +14 -4
index be8c697fea0cc755cfdb4fb0a9e3b95183bec0dc..2d7b389f36e8682c3f0a10befe87698751596584 100644
@@ -15,6 +15,7 @@
 #include <linux/err.h>
 #include <linux/delay.h>
 #include <linux/seq_file.h>
+#include <linux/irqdomain.h>
 #include <linux/jump_label.h>
 #include <linux/pci.h>
 #include <linux/printk.h>
@@ -199,19 +200,27 @@ static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s
 	zbus->multifunction = zpci_bus_is_multifunction_root(fr);
 	zbus->max_bus_speed = fr->max_bus_speed;
 
+	if (zpci_create_parent_msi_domain(zbus))
+		goto out_free_domain;
+
 	/*
 	 * Note that the zbus->resources are taken over and zbus->resources
 	 * is empty after a successful call
 	 */
 	bus = pci_create_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resources);
-	if (!bus) {
-		zpci_free_domain(zbus->domain_nr);
-		return -EFAULT;
-	}
+	if (!bus)
+		goto out_remove_msi_domain;
 
 	zbus->bus = bus;
+	dev_set_msi_domain(&zbus->bus->dev, zbus->msi_parent_domain);
 
 	return 0;
+
+out_remove_msi_domain:
+	zpci_remove_parent_msi_domain(zbus);
+out_free_domain:
+	zpci_free_domain(zbus->domain_nr);
+	return -ENOMEM;
 }
 
 static void zpci_bus_release(struct kref *kref)
@@ -232,6 +241,7 @@ static void zpci_bus_release(struct kref *kref)
 	mutex_lock(&zbus_list_lock);
 	list_del(&zbus->bus_next);
 	mutex_unlock(&zbus_list_lock);
+	zpci_remove_parent_msi_domain(zbus);
 	kfree(zbus);
 }
 
arch/s390/pci/pci_irq.c +198 -112

417 lines not on this page · raw message

Signature · 1 line
2.51.0
maintainer Reviewed-by on v7 2/2
#3 lore raw

Re: [PATCH v7 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API

Quoted 33 lines · Tobias Schumacher

s390 is one of the last architectures using the legacy API for setup and teardown of PCI MSI IRQs. Migrate the s390 IRQ allocation and teardown to the MSI parent domain API. For details, see:

https://lore.kernel.org/lkml/[email protected]

In detail, create an MSI parent domain for each PCI domain. When a PCI device sets up MSI or MSI-X IRQs, the library creates a per-device IRQ domain for this device, which is used by the device for allocating and freeing IRQs.

The per-device domain delegates this allocation and freeing to the parent-domain. In the end, the corresponding callbacks of the parent domain are responsible for allocating and freeing the IRQs.

The allocation is split into two parts:
- zpci_msi_prepare() is called once for each device and allocates the required resources. On s390, each PCI function has its own airq vector and a summary bit, which must be configured once per function. This is done in prepare().
- zpci_msi_alloc() can be called multiple times for allocating one or more MSI/MSI-X IRQs. This creates a mapping between the virtual IRQ number in the kernel and the hardware IRQ number.

Freeing is split into two counterparts:
- zpci_msi_free() reverts the effects of zpci_msi_alloc() and
- zpci_msi_teardown() reverts the effects of zpci_msi_prepare(). This is called once when all IRQs are freed before a device is removed.

Since the parent domain in the end allocates the IRQs, the hwirq encoding must be unambiguous for all IRQs of all devices. This is achieved by encoding the hwirq using the devfn and the MSI index.

Quoted 9 lines
---
 arch/s390/Kconfig           |   1 +
 arch/s390/include/asm/pci.h |   5 +
 arch/s390/pci/pci.c         |   6 +
 arch/s390/pci/pci_bus.c     |  18 ++-
 arch/s390/pci/pci_irq.c     | 310 ++++++++++++++++++++++++++++----------------
 5 files changed, 224 insertions(+), 116 deletions(-)

--- snip ---

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+static inline u16 zpci_decode_hwirq_msi_index(u32 hwirq)

I think the parameter's type should by irq_hw_number_t here. It doesn't matter for correctness since we're only using 32 bits now and the cast just cuts off the upper 32 bits but I'd like to preserve the type until you explicitly mask off the bits we don't use.

I also considered making zpci_encode_hwirq()'s return type irq_hw_number_t but I think it's not needed. This is because there we're still in the process of encoding the hwirq and want to emphasize that our encoding output uses 32 bits.

arch/s390/pci/pci_irq.c static int zpci_clear_irq(struct zpci_dev *zdev) · line 147

Quoted 4 lines
arch/s390/pci/pci_irq.c +3 -0
+{
+	return hwirq & 0xffff;
+}

The changes versus v6 look good to me and I agree that putting the zpci_set_irq() in zpci_reenable_device() looks like the cleanest fix for the recovery issue. Also good catch on the msg->data assignment. So feel free to (re-)add my R-b as per below.

#4 lore raw

Re: [PATCH v7 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API

Quoted 45 lines · Niklas Schnelle
Quoted 33 lines · Tobias Schumacher

s390 is one of the last architectures using the legacy API for setup and teardown of PCI MSI IRQs. Migrate the s390 IRQ allocation and teardown to the MSI parent domain API. For details, see:

https://lore.kernel.org/lkml/[email protected]

In detail, create an MSI parent domain for each PCI domain. When a PCI device sets up MSI or MSI-X IRQs, the library creates a per-device IRQ domain for this device, which is used by the device for allocating and freeing IRQs.

The per-device domain delegates this allocation and freeing to the parent-domain. In the end, the corresponding callbacks of the parent domain are responsible for allocating and freeing the IRQs.

The allocation is split into two parts:
- zpci_msi_prepare() is called once for each device and allocates the required resources. On s390, each PCI function has its own airq vector and a summary bit, which must be configured once per function. This is done in prepare().
- zpci_msi_alloc() can be called multiple times for allocating one or more MSI/MSI-X IRQs. This creates a mapping between the virtual IRQ number in the kernel and the hardware IRQ number.

Freeing is split into two counterparts:
- zpci_msi_free() reverts the effects of zpci_msi_alloc() and
- zpci_msi_teardown() reverts the effects of zpci_msi_prepare(). This is called once when all IRQs are freed before a device is removed.

Since the parent domain in the end allocates the IRQs, the hwirq encoding must be unambiguous for all IRQs of all devices. This is achieved by encoding the hwirq using the devfn and the MSI index.

Quoted 9 lines
---
 arch/s390/Kconfig           |   1 +
 arch/s390/include/asm/pci.h |   5 +
 arch/s390/pci/pci.c         |   6 +
 arch/s390/pci/pci_bus.c     |  18 ++-
 arch/s390/pci/pci_irq.c     | 310 ++++++++++++++++++++++++++++----------------
 5 files changed, 224 insertions(+), 116 deletions(-)

--- snip ---

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+static inline u16 zpci_decode_hwirq_msi_index(u32 hwirq)

I think the parameter's type should by irq_hw_number_t here. It doesn't matter for correctness since we're only using 32 bits now and the cast just cuts off the upper 32 bits but I'd like to preserve the type until you explicitly mask off the bits we don't use.

Makes sense, I'll change that.

Quoted 4 lines

I also considered making zpci_encode_hwirq()'s return type irq_hw_number_t but I think it's not needed. This is because there we're still in the process of encoding the hwirq and want to emphasize that our encoding output uses 32 bits.

Agreed.

Quoted 11 lines

arch/s390/pci/pci_irq.c static int zpci_clear_irq(struct zpci_dev *zdev) · line 147

Quoted 4 lines
arch/s390/pci/pci_irq.c +3 -0
+{
+	return hwirq & 0xffff;
+}

The changes versus v6 look good to me and I agree that putting the zpci_set_irq() in zpci_reenable_device() looks like the cleanest fix for the recovery issue. Also good catch on the msg->data assignment. So feel free to (re-)add my R-b as per below.

Thanks, since this is only a minor change let's wait if Gerd and Farhan want to add anything before sending a new version.

Tobias

Reviewed-by on v7 2/2
#5 lore raw

Re: [PATCH v7 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API

In reply to Tobias Schumacher
Quoted 33 lines · Tobias Schumacher

s390 is one of the last architectures using the legacy API for setup and teardown of PCI MSI IRQs. Migrate the s390 IRQ allocation and teardown to the MSI parent domain API. For details, see:

https://lore.kernel.org/lkml/[email protected]

In detail, create an MSI parent domain for each PCI domain. When a PCI device sets up MSI or MSI-X IRQs, the library creates a per-device IRQ domain for this device, which is used by the device for allocating and freeing IRQs.

The per-device domain delegates this allocation and freeing to the parent-domain. In the end, the corresponding callbacks of the parent domain are responsible for allocating and freeing the IRQs.

The allocation is split into two parts:
- zpci_msi_prepare() is called once for each device and allocates the required resources. On s390, each PCI function has its own airq vector and a summary bit, which must be configured once per function. This is done in prepare().
- zpci_msi_alloc() can be called multiple times for allocating one or more MSI/MSI-X IRQs. This creates a mapping between the virtual IRQ number in the kernel and the hardware IRQ number.

Freeing is split into two counterparts:
- zpci_msi_free() reverts the effects of zpci_msi_alloc() and
- zpci_msi_teardown() reverts the effects of zpci_msi_prepare(). This is called once when all IRQs are freed before a device is removed.

Since the parent domain in the end allocates the IRQs, the hwirq encoding must be unambiguous for all IRQs of all devices. This is achieved by encoding the hwirq using the devfn and the MSI index.

Quoted 8 lines
---
  arch/s390/Kconfig           |   1 +
  arch/s390/include/asm/pci.h |   5 +
  arch/s390/pci/pci.c         |   6 +
  arch/s390/pci/pci_bus.c     |  18 ++-
  arch/s390/pci/pci_irq.c     | 310 ++++++++++++++++++++++++++++----------------
  5 files changed, 224 insertions(+), 116 deletions(-)

LGTM and testing this patch it does fix the issue found in v6.

maintainer
#6 lore raw

Re: [PATCH v7 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API

In reply to Tobias Schumacher
Quoted 42 lines · Tobias Schumacher

s390 is one of the last architectures using the legacy API for setup and teardown of PCI MSI IRQs. Migrate the s390 IRQ allocation and teardown to the MSI parent domain API. For details, see:

https://lore.kernel.org/lkml/[email protected]

In detail, create an MSI parent domain for each PCI domain. When a PCI device sets up MSI or MSI-X IRQs, the library creates a per-device IRQ domain for this device, which is used by the device for allocating and freeing IRQs.

The per-device domain delegates this allocation and freeing to the parent-domain. In the end, the corresponding callbacks of the parent domain are responsible for allocating and freeing the IRQs.

The allocation is split into two parts:
- zpci_msi_prepare() is called once for each device and allocates the required resources. On s390, each PCI function has its own airq vector and a summary bit, which must be configured once per function. This is done in prepare().
- zpci_msi_alloc() can be called multiple times for allocating one or more MSI/MSI-X IRQs. This creates a mapping between the virtual IRQ number in the kernel and the hardware IRQ number.

Freeing is split into two counterparts:
- zpci_msi_free() reverts the effects of zpci_msi_alloc() and
- zpci_msi_teardown() reverts the effects of zpci_msi_prepare(). This is called once when all IRQs are freed before a device is removed.

Since the parent domain in the end allocates the IRQs, the hwirq encoding must be unambiguous for all IRQs of all devices. This is achieved by encoding the hwirq using the devfn and the MSI index.

---
 arch/s390/Kconfig           |   1 +
 arch/s390/include/asm/pci.h |   5 +
 arch/s390/pci/pci.c         |   6 +
 arch/s390/pci/pci_bus.c     |  18 ++-
 arch/s390/pci/pci_irq.c     | 310 ++++++++++++++++++++++++++++----------------
 5 files changed, 224 insertions(+), 116 deletions(-)

[ ... snip ... ]

Quoted 13 lines
arch/s390/pci/pci_irq.c +1 -2
index e73be96ce5fe6473fc193d65b8f0ff635d6a98ba..2ac0fab605a83a2f06be6a0a68718e528125ced6 100644
@@ -290,146 +325,196 @@ static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs,
 	return 0;
 }
 
-int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
+bool arch_restore_msi_irqs(struct pci_dev *pdev)
 {
-	unsigned int hwirq, msi_vecs, irqs_per_msi, i, cpu;
 	struct zpci_dev *zdev = to_zpci(pdev);

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 335

Quoted 10 lines
arch/s390/pci/pci_irq.c +3 -5
-	struct msi_desc *msi;
-	struct msi_msg msg;
-	unsigned long bit;
-	int cpu_addr;
-	int rc, irq;
 
+	zpci_set_irq(zdev);
+	return true;
+}
 

It's always a little tricky to distinguish which code handles both MSI and MSI-X or just MSI proper when routines have _msi_ in their name. But apparently, both __pci_restore_msi_state() and __pci_restore_msix_state() inside pci_restore_msi_state() do call arch_restore_msi_irqs() - so life is good!

[ ... snip ... ]

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 451

Quoted 10 lines
arch/s390/pci/pci_irq.c +8 -1
+static void zpci_msi_domain_free(struct irq_domain *domain, unsigned int virq,
+				 unsigned int nr_irqs)
+{
+	struct irq_data *d;
+	int i;
 
-	return (zdev->msi_nr_irqs == nvec) ? 0 : zdev->msi_nr_irqs;
+	for (i = 0; i < nr_irqs; i++) {
+		d = irq_domain_get_irq_data(domain, virq + i);
+		irq_domain_reset_irq_data(d);

Question: zpci_msi_alloc_domain() did modify airq data, can this be left as is in zpci_msi_domain_free()?

Quoted 3 lines
arch/s390/pci/pci_irq.c +1 -0
+	}
 }
 

[ ... snip ... ]

Quoted 15 lines
arch/s390/pci/pci_irq.c +10 -4
+
+int zpci_create_parent_msi_domain(struct zpci_bus *zbus)
+{
+	char fwnode_name[18];
 
-	if (zdev->aisb != -1UL) {
-		zpci_ibv[zdev->aisb] = NULL;
-		airq_iv_free_bit(zpci_sbv, zdev->aisb);
-		zdev->aisb = -1UL;
+	snprintf(fwnode_name, sizeof(fwnode_name), "ZPCI_MSI_DOM_%04x", zbus->domain_nr);
+	struct irq_domain_info info = {
+		.fwnode		= irq_domain_alloc_named_fwnode(fwnode_name),
+		.ops		= &zpci_msi_domain_ops,
+	};
+

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 498

Quoted 10 lines
arch/s390/pci/pci_irq.c +6 -3
+	if (!info.fwnode) {
+		pr_err("Failed to allocate fwnode for MSI IRQ domain\n");
+		return -ENOMEM;
 	}
-	if (zdev->aibv) {
-		airq_iv_release(zdev->aibv);
-		zdev->aibv = NULL;
+
+	if (irq_delivery == FLOATING)
+		zpci_msi_parent_ops.required_flags |= MSI_FLAG_NO_AFFINITY;

Add empty line here, so the intent is clear that the following assignment is executed unconditionally.

Quoted 12 lines
arch/s390/pci/pci_irq.c +6 -2
+	zbus->msi_parent_domain = msi_create_parent_irq_domain(&info, &zpci_msi_parent_ops);
+	if (!zbus->msi_parent_domain) {
+		irq_domain_free_fwnode(info.fwnode);
+		pr_err("Failed to create MSI IRQ domain\n");
+		return -ENOMEM;
 	}
 
-	if ((irq_delivery == DIRECTED) && zdev->msi_first_bit != -1U)
-		airq_iv_free(zpci_ibv[0], zdev->msi_first_bit, zdev->msi_nr_irqs);
+	return 0;
 }

[ ... snip ... ]

arch/s390/pci/pci_irq.c static int __init zpci_directed_irq_init(void) · line 557

Quoted 8 lines
arch/s390/pci/pci_irq.c +1 -0
@@ -466,6 +551,7 @@ static int __init zpci_directed_irq_init(void)
 		 * is only done on the first vector.
 		 */
 		zpci_ibv[cpu] = airq_iv_create(cache_line_size() * BITS_PER_BYTE,
+					       AIRQ_IV_PTR |
 					       AIRQ_IV_DATA |
 					       AIRQ_IV_CACHELINE |
 					       (!cpu ? AIRQ_IV_ALLOC : 0), NULL);

This looks very good to me already. Unfortunately, I was unable to relieve my MSI vs. MSI-X anxiety regarding arch_restore_msi_irqs() with a test since the only MSI-using PCI function (ISM) is not supporting PCI auto-recovery :(

But a mlx5 VF now recovers just fine!

Thanks,
Gerd

#7 lore raw

Re: [PATCH v7 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API

Quoted 22 lines · Gerd Bayer

On Thu, 2025-11-27 at 16:07 +0100, Tobias Schumacher wrote:
[ ... snip ... ]

Quoted 19 lines
arch/s390/pci/pci_irq.c +1 -7
index e73be96ce5fe6473fc193d65b8f0ff635d6a98ba..2ac0fab605a83a2f06be6a0a68718e528125ced6 100644
@@ -290,146 +325,196 @@ static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs,
 	return 0;
 }
 
-int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
+bool arch_restore_msi_irqs(struct pci_dev *pdev)
 {
-	unsigned int hwirq, msi_vecs, irqs_per_msi, i, cpu;
 	struct zpci_dev *zdev = to_zpci(pdev);
-	struct msi_desc *msi;
-	struct msi_msg msg;
-	unsigned long bit;
-	int cpu_addr;
-	int rc, irq;
 
Quoted 10 lines

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 377

Quoted 4 lines
arch/s390/pci/pci_irq.c +3 -0
+	zpci_set_irq(zdev);
+	return true;
+}
 

It's always a little tricky to distinguish which code handles both MSI and MSI-X or just MSI proper when routines have _msi_ in their name. But apparently, both __pci_restore_msi_state() and __pci_restore_msix_state() inside pci_restore_msi_state() do call arch_restore_msi_irqs() - so life is good!

Regarding arch_restore_msi_irqs() the main change in the patchset is that it is now also conditionally called from zpci_reenable_device(). This is becasue in the recovery case, __pci_restore_msix_state() does not call arch_restore_msi_irqs(), it exits directly at the beginning because dev->msix_enabled evaluates to false.

With the legacy API, IRQs are later re-enabled using arch_setup_msi_irqs(), which also registers the airq with the hw. With the MSI parent domain, zpci_msi_prepare() would register the airq, but is not called in the recovery path. This is why it is now added to zpci_reenable_device()

Quoted 8 lines

[ ... snip ... ]

Quoted 6 lines
arch/s390/pci/pci_irq.c +5 -0
+static void zpci_msi_domain_free(struct irq_domain *domain, unsigned int virq,
+				 unsigned int nr_irqs)
+{
+	struct irq_data *d;
+	int i;
Quoted 7 lines

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 451

Quoted 4 lines
arch/s390/pci/pci_irq.c +3 -1
-	return (zdev->msi_nr_irqs == nvec) ? 0 : zdev->msi_nr_irqs;
+	for (i = 0; i < nr_irqs; i++) {
+		d = irq_domain_get_irq_data(domain, virq + i);
+		irq_domain_reset_irq_data(d);

Question: zpci_msi_alloc_domain() did modify airq data, can this be left as is in zpci_msi_domain_free()?

I was thinking about this myself and came to the conclusion that it is fine. zpci_msi_domain_alloc() sets the ptr to the msi parent domain and data to the encoded hwirq. Both fields are only required in the IRQ handler.
* When free() is called, the corresponding interrupt was already deactivated by the hardware, so hardware shouldn't generate it anymore anyway.
* If, for whatever reason, hw still generates the interrupt, generic_handle_domain_irq returns an error since the hwirq cannot be resolved.
* If the IRQ gets allocated again, the fields are written again before the IRQ is activated. The data written will even be the same as it was before.

Quoted 23 lines
   [ ... snip ... ]
Quoted 20 lines
arch/s390/pci/pci_irq.c +13 -5
+
+int zpci_create_parent_msi_domain(struct zpci_bus *zbus)
+{
+	char fwnode_name[18];
 
-	if (zdev->aisb != -1UL) {
-		zpci_ibv[zdev->aisb] = NULL;
-		airq_iv_free_bit(zpci_sbv, zdev->aisb);
-		zdev->aisb = -1UL;
+	snprintf(fwnode_name, sizeof(fwnode_name), "ZPCI_MSI_DOM_%04x", zbus->domain_nr);
+	struct irq_domain_info info = {
+		.fwnode		= irq_domain_alloc_named_fwnode(fwnode_name),
+		.ops		= &zpci_msi_domain_ops,
+	};
+
+	if (!info.fwnode) {
+		pr_err("Failed to allocate fwnode for MSI IRQ domain\n");
+		return -ENOMEM;
 	}
-	if (zdev->aibv) {
Quoted 8 lines

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 498

Quoted 5 lines
arch/s390/pci/pci_irq.c +3 -2
-		airq_iv_release(zdev->aibv);
-		zdev->aibv = NULL;
+
+	if (irq_delivery == FLOATING)
+		zpci_msi_parent_ops.required_flags |= MSI_FLAG_NO_AFFINITY;

Add empty line here, so the intent is clear that the following assignment is executed unconditionally.

Ok.

Quoted 17 lines
   [ ... snip ... ]

arch/s390/pci/pci_irq.c static int __init zpci_directed_irq_init(void) · line 557

Quoted 8 lines
arch/s390/pci/pci_irq.c +1 -0
@@ -466,6 +551,7 @@ static int __init zpci_directed_irq_init(void)
 		 * is only done on the first vector.
 		 */
 		zpci_ibv[cpu] = airq_iv_create(cache_line_size() * BITS_PER_BYTE,
+					       AIRQ_IV_PTR |
 					       AIRQ_IV_DATA |
 					       AIRQ_IV_CACHELINE |
 					       (!cpu ? AIRQ_IV_ALLOC : 0), NULL);

This looks very good to me already. Unfortunately, I was unable to relieve my MSI vs. MSI-X anxiety regarding arch_restore_msi_irqs() with a test since the only MSI-using PCI function (ISM) is not supporting PCI auto-recovery :(

Quoted 1 line

But a mlx5 VF now recovers just fine!

Did my expanation above help with this?

Thanks
Tobias

maintainer
#8 lore raw

Re: [PATCH v7 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API

Quoted 34 lines · Tobias Schumacher
Quoted 22 lines · Gerd Bayer

On Thu, 2025-11-27 at 16:07 +0100, Tobias Schumacher wrote:
[ ... snip ... ]

Quoted 19 lines
arch/s390/pci/pci_irq.c +1 -7
index e73be96ce5fe6473fc193d65b8f0ff635d6a98ba..2ac0fab605a83a2f06be6a0a68718e528125ced6 100644
@@ -290,146 +325,196 @@ static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs,
 	return 0;
 }
 
-int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
+bool arch_restore_msi_irqs(struct pci_dev *pdev)
 {
-	unsigned int hwirq, msi_vecs, irqs_per_msi, i, cpu;
 	struct zpci_dev *zdev = to_zpci(pdev);
-	struct msi_desc *msi;
-	struct msi_msg msg;
-	unsigned long bit;
-	int cpu_addr;
-	int rc, irq;
 
Quoted 10 lines

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 377

Quoted 4 lines
arch/s390/pci/pci_irq.c +3 -0
+	zpci_set_irq(zdev);
+	return true;
+}
 

It's always a little tricky to distinguish which code handles both MSI and MSI-X or just MSI proper when routines have _msi_ in their name. But apparently, both __pci_restore_msi_state() and __pci_restore_msix_state() inside pci_restore_msi_state() do call arch_restore_msi_irqs() - so life is good!

Quoted 2 lines

Regarding arch_restore_msi_irqs() the main change in the patchset is that it is now also conditionally called from zpci_reenable_device().

Sorry, I don't follow: This patch adds a conditional call to zpci_set_irg() to zpci_reenable_device() - not arch_restore_msi_irqs().

Quoted 3 lines

This is becasue in the recovery case, __pci_restore_msix_state() does not call arch_restore_msi_irqs(), it exits directly at the beginning because dev->msix_enabled evaluates to false.

Does that mean arch_restore_msi_irqs() is dead code?
After re-reading pci_save_state()/pci_restore_state(), it sounds as if arch_restore_msi_irqs() may be useful afterall, with device drivers that consider the MSI/MSI-X interrupt setup part of their save/restore snapshot? And we just happen to have not executed any of those, maybe?

So probably just leave it in.

Quoted 23 lines

With the legacy API, IRQs are later re-enabled using arch_setup_msi_irqs(), which also registers the airq with the hw. With the MSI parent domain, zpci_msi_prepare() would register the airq, but is not called in the recovery path. This is why it is now added to zpci_reenable_device()

Quoted 8 lines

[ ... snip ... ]

Quoted 6 lines
arch/s390/pci/pci_irq.c +5 -0
+static void zpci_msi_domain_free(struct irq_domain *domain, unsigned int virq,
+				 unsigned int nr_irqs)
+{
+	struct irq_data *d;
+	int i;
Quoted 7 lines

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 451

Quoted 4 lines
arch/s390/pci/pci_irq.c +3 -1
-	return (zdev->msi_nr_irqs == nvec) ? 0 : zdev->msi_nr_irqs;
+	for (i = 0; i < nr_irqs; i++) {
+		d = irq_domain_get_irq_data(domain, virq + i);
+		irq_domain_reset_irq_data(d);

Question: zpci_msi_alloc_domain() did modify airq data, can this be left as is in zpci_msi_domain_free()?

Quoted 13 lines

I was thinking about this myself and came to the conclusion that it is fine. zpci_msi_domain_alloc() sets the ptr to the msi parent domain and data to the encoded hwirq. Both fields are only required in the IRQ handler.
* When free() is called, the corresponding interrupt was already deactivated by the hardware, so hardware shouldn't generate it anymore anyway.
* If, for whatever reason, hw still generates the interrupt, generic_handle_domain_irq returns an error since the hwirq cannot be resolved.
* If the IRQ gets allocated again, the fields are written again before the IRQ is activated. The data written will even be the same as it was before.

Well, this is all assuming no further errors in the code... I'd still vote to clean up airq resources when they are no longer needed - just act defensively in case some weird (future) path still tries to use these after they got put to rest - or you have to do some post-mortem dump analysis and try to make sense of this "garbage".

Quoted 52 lines
Quoted 24 lines
   [ ... snip ... ]
Quoted 20 lines
arch/s390/pci/pci_irq.c +13 -5
+
+int zpci_create_parent_msi_domain(struct zpci_bus *zbus)
+{
+	char fwnode_name[18];
 
-	if (zdev->aisb != -1UL) {
-		zpci_ibv[zdev->aisb] = NULL;
-		airq_iv_free_bit(zpci_sbv, zdev->aisb);
-		zdev->aisb = -1UL;
+	snprintf(fwnode_name, sizeof(fwnode_name), "ZPCI_MSI_DOM_%04x", zbus->domain_nr);
+	struct irq_domain_info info = {
+		.fwnode		= irq_domain_alloc_named_fwnode(fwnode_name),
+		.ops		= &zpci_msi_domain_ops,
+	};
+
+	if (!info.fwnode) {
+		pr_err("Failed to allocate fwnode for MSI IRQ domain\n");
+		return -ENOMEM;
 	}
-	if (zdev->aibv) {
Quoted 8 lines

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 498

Quoted 5 lines
arch/s390/pci/pci_irq.c +3 -2
-		airq_iv_release(zdev->aibv);
-		zdev->aibv = NULL;
+
+	if (irq_delivery == FLOATING)
+		zpci_msi_parent_ops.required_flags |= MSI_FLAG_NO_AFFINITY;

Add empty line here, so the intent is clear that the following assignment is executed unconditionally.

Ok.

Quoted 17 lines
   [ ... snip ... ]

arch/s390/pci/pci_irq.c static int __init zpci_directed_irq_init(void) · line 557

Quoted 8 lines
arch/s390/pci/pci_irq.c +1 -0
@@ -466,6 +551,7 @@ static int __init zpci_directed_irq_init(void)
 		 * is only done on the first vector.
 		 */
 		zpci_ibv[cpu] = airq_iv_create(cache_line_size() * BITS_PER_BYTE,
+					       AIRQ_IV_PTR |
 					       AIRQ_IV_DATA |
 					       AIRQ_IV_CACHELINE |
 					       (!cpu ? AIRQ_IV_ALLOC : 0), NULL);

This looks very good to me already. Unfortunately, I was unable to relieve my MSI vs. MSI-X anxiety regarding arch_restore_msi_irqs() with a test since the only MSI-using PCI function (ISM) is not supporting PCI auto-recovery :(

Quoted 3 lines
Quoted 1 line

But a mlx5 VF now recovers just fine!

Did my expanation above help with this?

Yes, thank you. But I still would request to address the airq cleanup in zpci_msi_domain_free().

Quoted 2 lines

Thanks
Tobias

Thanks,
Gerd

#9 lore raw

Re: [PATCH v7 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API

Quoted 35 lines · Gerd Bayer
Quoted 34 lines · Tobias Schumacher
Quoted 32 lines · Gerd Bayer

On Thu, 2025-11-27 at 16:07 +0100, Tobias Schumacher wrote:
[ ... snip ... ]

Quoted 13 lines
arch/s390/pci/pci_irq.c +1 -2
index e73be96ce5fe6473fc193d65b8f0ff635d6a98ba..2ac0fab605a83a2f06be6a0a68718e528125ced6 100644
@@ -290,146 +325,196 @@ static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs,
 	return 0;
 }
 
-int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
+bool arch_restore_msi_irqs(struct pci_dev *pdev)
 {
-	unsigned int hwirq, msi_vecs, irqs_per_msi, i, cpu;
 	struct zpci_dev *zdev = to_zpci(pdev);

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 335

Quoted 10 lines
arch/s390/pci/pci_irq.c +3 -5
-	struct msi_desc *msi;
-	struct msi_msg msg;
-	unsigned long bit;
-	int cpu_addr;
-	int rc, irq;
 
+	zpci_set_irq(zdev);
+	return true;
+}
 

It's always a little tricky to distinguish which code handles both MSI and MSI-X or just MSI proper when routines have _msi_ in their name. But apparently, both __pci_restore_msi_state() and __pci_restore_msix_state() inside pci_restore_msi_state() do call arch_restore_msi_irqs() - so life is good!

Quoted 2 lines
Quoted 2 lines

Regarding arch_restore_msi_irqs() the main change in the patchset is that it is now also conditionally called from zpci_reenable_device().

Right, sorry.

Quoted 7 lines

Sorry, I don't follow: This patch adds a conditional call to zpci_set_irg() to zpci_reenable_device() - not arch_restore_msi_irqs().

Quoted 3 lines

This is becasue in the recovery case, __pci_restore_msix_state() does not call arch_restore_msi_irqs(), it exits directly at the beginning because dev->msix_enabled evaluates to false.

Quoted 7 lines

Does that mean arch_restore_msi_irqs() is dead code?
After re-reading pci_save_state()/pci_restore_state(), it sounds as if arch_restore_msi_irqs() may be useful afterall, with device drivers that consider the MSI/MSI-X interrupt setup part of their save/restore snapshot? And we just happen to have not executed any of those, maybe?

So probably just leave it in.

No, it's not dead code. After the zpcictl --reset-fw, MSI-X interrupts are shutdown before the pci_restore_state(), which is why arch_restore_msi_irqs() is not called. But a driver can still call pci_save_state() and pci_restore_state() without shutting down MSI IRQs before, in which case arch_restore_msi_irqs() is called.

Quoted 37 lines
Quoted 23 lines

With the legacy API, IRQs are later re-enabled using arch_setup_msi_irqs(), which also registers the airq with the hw. With the MSI parent domain, zpci_msi_prepare() would register the airq, but is not called in the recovery path. This is why it is now added to zpci_reenable_device()

Quoted 8 lines

[ ... snip ... ]

Quoted 6 lines
arch/s390/pci/pci_irq.c +5 -0
+static void zpci_msi_domain_free(struct irq_domain *domain, unsigned int virq,
+				 unsigned int nr_irqs)
+{
+	struct irq_data *d;
+	int i;
Quoted 7 lines

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 451

Quoted 4 lines
arch/s390/pci/pci_irq.c +3 -1
-	return (zdev->msi_nr_irqs == nvec) ? 0 : zdev->msi_nr_irqs;
+	for (i = 0; i < nr_irqs; i++) {
+		d = irq_domain_get_irq_data(domain, virq + i);
+		irq_domain_reset_irq_data(d);

Question: zpci_msi_alloc_domain() did modify airq data, can this be left as is in zpci_msi_domain_free()?

Quoted 13 lines

I was thinking about this myself and came to the conclusion that it is fine. zpci_msi_domain_alloc() sets the ptr to the msi parent domain and data to the encoded hwirq. Both fields are only required in the IRQ handler.
* When free() is called, the corresponding interrupt was already deactivated by the hardware, so hardware shouldn't generate it anymore anyway.
* If, for whatever reason, hw still generates the interrupt, generic_handle_domain_irq returns an error since the hwirq cannot be resolved.
* If the IRQ gets allocated again, the fields are written again before the IRQ is activated. The data written will even be the same as it was before.

Quoted 5 lines

Well, this is all assuming no further errors in the code... I'd still vote to clean up airq resources when they are no longer needed - just act defensively in case some weird (future) path still tries to use these after they got put to rest - or you have to do some post-mortem dump analysis and try to make sense of this "garbage".

Ok, I can do that.

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
   [ ... snip ... ]

arch/s390/pci/pci_irq.c static int __init zpci_directed_irq_init(void) · line 557

Quoted 8 lines
arch/s390/pci/pci_irq.c +1 -0
@@ -466,6 +551,7 @@ static int __init zpci_directed_irq_init(void)
 		 * is only done on the first vector.
 		 */
 		zpci_ibv[cpu] = airq_iv_create(cache_line_size() * BITS_PER_BYTE,
+					       AIRQ_IV_PTR |
 					       AIRQ_IV_DATA |
 					       AIRQ_IV_CACHELINE |
 					       (!cpu ? AIRQ_IV_ALLOC : 0), NULL);

This looks very good to me already. Unfortunately, I was unable to relieve my MSI vs. MSI-X anxiety regarding arch_restore_msi_irqs() with a test since the only MSI-using PCI function (ISM) is not supporting PCI auto-recovery :(

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

But a mlx5 VF now recovers just fine!

Did my expanation above help with this?

Yes, thank you. But I still would request to address the airq cleanup in zpci_msi_domain_free().

Ok, will do.

Thanks
Tobias

maintainer
#10 lore raw

Re: [PATCH v7 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API

Quoted 54 lines · Tobias Schumacher
Quoted 35 lines · Gerd Bayer
Quoted 34 lines · Tobias Schumacher
Quoted 32 lines · Gerd Bayer

On Thu, 2025-11-27 at 16:07 +0100, Tobias Schumacher wrote:
[ ... snip ... ]

Quoted 13 lines
arch/s390/pci/pci_irq.c +1 -2
index e73be96ce5fe6473fc193d65b8f0ff635d6a98ba..2ac0fab605a83a2f06be6a0a68718e528125ced6 100644
@@ -290,146 +325,196 @@ static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs,
 	return 0;
 }
 
-int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
+bool arch_restore_msi_irqs(struct pci_dev *pdev)
 {
-	unsigned int hwirq, msi_vecs, irqs_per_msi, i, cpu;
 	struct zpci_dev *zdev = to_zpci(pdev);

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 335

Quoted 10 lines
arch/s390/pci/pci_irq.c +3 -5
-	struct msi_desc *msi;
-	struct msi_msg msg;
-	unsigned long bit;
-	int cpu_addr;
-	int rc, irq;
 
+	zpci_set_irq(zdev);
+	return true;
+}
 

It's always a little tricky to distinguish which code handles both MSI and MSI-X or just MSI proper when routines have _msi_ in their name. But apparently, both __pci_restore_msi_state() and __pci_restore_msix_state() inside pci_restore_msi_state() do call arch_restore_msi_irqs() - so life is good!

Quoted 2 lines
Quoted 2 lines

Regarding arch_restore_msi_irqs() the main change in the patchset is that it is now also conditionally called from zpci_reenable_device().

Right, sorry.

Quoted 13 lines

Sorry, I don't follow: This patch adds a conditional call to zpci_set_irg() to zpci_reenable_device() - not arch_restore_msi_irqs().

Quoted 3 lines

This is becasue in the recovery case, __pci_restore_msix_state() does not call arch_restore_msi_irqs(), it exits directly at the beginning because dev->msix_enabled evaluates to false.

Does that mean arch_restore_msi_irqs() is dead code?
After re-reading pci_save_state()/pci_restore_state(), it sounds as if arch_restore_msi_irqs() may be useful afterall, with device drivers that consider the MSI/MSI-X interrupt setup part of their save/restore snapshot? And we just happen to have not executed any of those, maybe?

Quoted 7 lines
Quoted 1 line

So probably just leave it in.

No, it's not dead code. After the zpcictl --reset-fw, MSI-X interrupts are shutdown before the pci_restore_state(), which is why arch_restore_msi_irqs() is not called. But a driver can still call pci_save_state() and pci_restore_state() without shutting down MSI IRQs before, in which case arch_restore_msi_irqs() is called.

Yes, that's the scenario that I thought of when I wrote that device drivers (other than mlx5_core) may want to have their MSI/MSI-X interrupt setup be restored through pci_restore_state()

Quoted 62 lines
Quoted 37 lines
Quoted 23 lines

With the legacy API, IRQs are later re-enabled using arch_setup_msi_irqs(), which also registers the airq with the hw. With the MSI parent domain, zpci_msi_prepare() would register the airq, but is not called in the recovery path. This is why it is now added to zpci_reenable_device()

Quoted 8 lines

[ ... snip ... ]

Quoted 6 lines
arch/s390/pci/pci_irq.c +5 -0
+static void zpci_msi_domain_free(struct irq_domain *domain, unsigned int virq,
+				 unsigned int nr_irqs)
+{
+	struct irq_data *d;
+	int i;
Quoted 7 lines

arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 451

Quoted 4 lines
arch/s390/pci/pci_irq.c +3 -1
-	return (zdev->msi_nr_irqs == nvec) ? 0 : zdev->msi_nr_irqs;
+	for (i = 0; i < nr_irqs; i++) {
+		d = irq_domain_get_irq_data(domain, virq + i);
+		irq_domain_reset_irq_data(d);

Question: zpci_msi_alloc_domain() did modify airq data, can this be left as is in zpci_msi_domain_free()?

Quoted 13 lines

I was thinking about this myself and came to the conclusion that it is fine. zpci_msi_domain_alloc() sets the ptr to the msi parent domain and data to the encoded hwirq. Both fields are only required in the IRQ handler.
* When free() is called, the corresponding interrupt was already deactivated by the hardware, so hardware shouldn't generate it anymore anyway.
* If, for whatever reason, hw still generates the interrupt, generic_handle_domain_irq returns an error since the hwirq cannot be resolved.
* If the IRQ gets allocated again, the fields are written again before the IRQ is activated. The data written will even be the same as it was before.

Quoted 5 lines

Well, this is all assuming no further errors in the code... I'd still vote to clean up airq resources when they are no longer needed - just act defensively in case some weird (future) path still tries to use these after they got put to rest - or you have to do some post-mortem dump analysis and try to make sense of this "garbage".

Ok, I can do that.

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
   [ ... snip ... ]

arch/s390/pci/pci_irq.c static int __init zpci_directed_irq_init(void) · line 557

Quoted 8 lines
arch/s390/pci/pci_irq.c +1 -0
@@ -466,6 +551,7 @@ static int __init zpci_directed_irq_init(void)
 		 * is only done on the first vector.
 		 */
 		zpci_ibv[cpu] = airq_iv_create(cache_line_size() * BITS_PER_BYTE,
+					       AIRQ_IV_PTR |
 					       AIRQ_IV_DATA |
 					       AIRQ_IV_CACHELINE |
 					       (!cpu ? AIRQ_IV_ALLOC : 0), NULL);

This looks very good to me already. Unfortunately, I was unable to relieve my MSI vs. MSI-X anxiety regarding arch_restore_msi_irqs() with a test since the only MSI-using PCI function (ISM) is not supporting PCI auto-recovery :(

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

But a mlx5 VF now recovers just fine!

Did my expanation above help with this?

Yes, thank you. But I still would request to address the airq cleanup in zpci_msi_domain_free().

Ok, will do.

Thank you,
Gerd