Skip to contentSkip to conversation

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

PATCH Superseded Tobias Schumacher 3 participants 6 messages Nov 18, 2025 – Nov 19, 2025 1 message not in the archive

Subsystems (3)

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v3 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 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 |   4 +
 arch/s390/pci/pci_bus.c     |  11 ++
 arch/s390/pci/pci_irq.c     | 334 +++++++++++++++++++++++++++-----------------
 include/linux/irqdesc.h     |   6 +-
 kernel/irq/irqdesc.c        |   6 +-
 6 files changed, 231 insertions(+), 131 deletions(-)

---
base-commit: 882489402b556fa6d916cba86051276fcc9a8953
change-id: 20251104-implement-msi-domain-dc1ea014580e

Best regards,

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

PATCH v3 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.48.1
#2 lore raw

PATCH v3 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 zpci which is used by all PCI devices. 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 callend 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 PCI function id and the MSI index.

---
 arch/s390/Kconfig           |   1 +
 arch/s390/include/asm/pci.h |   4 +
 arch/s390/pci/pci_bus.c     |  11 ++
 arch/s390/pci/pci_irq.c     | 334 +++++++++++++++++++++++++++-----------------
 4 files changed, 225 insertions(+), 125 deletions(-)
arch/s390/Kconfig +1 -0
index df22b10d91415e1ed183cc8add9ad0ac4293c50e..48cd6a12bd04dfe4dd61ecc79d3401ba685c51bb 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 +4 -0
index a32f465ecf73a5cc3408a312d94ec888d62848cc..60abc84cf14fe6fb1ee149df688eea94f0983ed0 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,8 @@ int zpci_dma_exit_device(struct zpci_dev *zdev);
 /* IRQ */
 int __init zpci_irq_init(void);
 void __init zpci_irq_exit(void);
+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_bus.c +11 -0
index be8c697fea0cc755cfdb4fb0a9e3b95183bec0dc..4849420d4f72c886edbe9c5e32cf0b1513d0b555 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>
@@ -190,6 +191,7 @@ static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s
 {
 	struct pci_bus *bus;
 	int domain;
+	int rc;
 
 	domain = zpci_alloc_domain((u16)fr->uid);
 	if (domain < 0)
@@ -199,6 +201,12 @@ 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;
 
+	rc = zpci_create_parent_msi_domain(zbus);
+	if (rc) {
+		zpci_free_domain(zbus->domain_nr);
+		return -EFAULT;
+	}
+
 	/*
 	 * Note that the zbus->resources are taken over and zbus->resources
 	 * is empty after a successful call
@@ -206,10 +214,12 @@ static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s
 	bus = pci_create_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resources);
 	if (!bus) {
 		zpci_free_domain(zbus->domain_nr);
+		zpci_remove_parent_msi_domain(zbus);
 		return -EFAULT;
 	}
 
 	zbus->bus = bus;
+	dev_set_msi_domain(&zbus->bus->dev, zbus->msi_parent_domain);
 
 	return 0;
 }
@@ -232,6 +242,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 +209 -125

437 lines not on this page · raw message

Signature · 1 line
2.48.1
#3 lore raw

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

Quoted 4 lines · Tobias Schumacher

static struct irq_chip zpci_irq_chip = {

(quoted diff) +0 -0
 	.name = "PCI-MSI",
 	.irq_unmask = pci_msi_unmask_irq,
 	.irq_mask = pci_msi_mask_irq,

Review

Quoted 10 lines
(quoted diff) +8 -0
+	.irq_compose_msi_msg = zpci_compose_msi_msg
 };
 
+static struct msi_parent_ops zpci_msi_parent_ops = {
+	.supported_flags   = MSI_GENERIC_FLAGS_MASK	|
+			     MSI_FLAG_PCI_MSIX		|
+			     MSI_FLAG_MULTI_PCI_MSI,
+	.required_flags	   = MSI_FLAG_USE_DEF_DOM_OPS  |
+			     MSI_FLAG_USE_DEF_CHIP_OPS |
+			     MSI_FLAG_PCI_MSI_MASK_PARENT,

That MASK_PARENT flag is really only necessary if you want to avoid masking/unmasking at the PCI level during operation (disable/enable_irq()). See

f09c1d63e895 ("irqchip/msi-lib: Honor the MSI_FLAG_PCI_MSI_MASK_PARENT flag")

for a detailed explanation.

But as s390 does not seem to provide mask/unmask at a different level of the interrupt transport, setting this flag and the mask/unmask callbacks above is pointless.

If the flag is not set the PCI core will use pci_msi_[un]mask_irq() for the per device chip at the top of the hierarchy, which avoids the indirection to the parent chip.

Thanks,

tglx

#4 lore raw

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

In reply to Tobias Schumacher
Quoted 8 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 zpci which is used by all PCI devices.

I think this statement would need to be updated with the new approach of MSI parent domain per zpci domain?

Quoted 110 lines

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 callend 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 PCI function id and the MSI index.

---
  arch/s390/Kconfig           |   1 +
  arch/s390/include/asm/pci.h |   4 +
  arch/s390/pci/pci_bus.c     |  11 ++
  arch/s390/pci/pci_irq.c     | 334 +++++++++++++++++++++++++++-----------------
  4 files changed, 225 insertions(+), 125 deletions(-)
arch/s390/Kconfig +1 -0
index df22b10d91415e1ed183cc8add9ad0ac4293c50e..48cd6a12bd04dfe4dd61ecc79d3401ba685c51bb 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 +4 -0
index a32f465ecf73a5cc3408a312d94ec888d62848cc..60abc84cf14fe6fb1ee149df688eea94f0983ed0 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,8 @@ int zpci_dma_exit_device(struct zpci_dev *zdev);
  /* IRQ */
  int __init zpci_irq_init(void);
  void __init zpci_irq_exit(void);
+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_bus.c +8 -0
index be8c697fea0cc755cfdb4fb0a9e3b95183bec0dc..4849420d4f72c886edbe9c5e32cf0b1513d0b555 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>
@@ -190,6 +191,7 @@ static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s
  {
  	struct pci_bus *bus;
  	int domain;
+	int rc;
 
  	domain = zpci_alloc_domain((u16)fr->uid);
  	if (domain < 0)
@@ -199,6 +201,12 @@ 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;
 
+	rc = zpci_create_parent_msi_domain(zbus);
+	if (rc) {
+		zpci_free_domain(zbus->domain_nr);
+		return -EFAULT;
+	}
+
  	/*
  	 * Note that the zbus->resources are taken over and zbus->resources
  	 * is empty after a successful call

arch/s390/pci/pci_bus.c static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s · line 220

Quoted 7 lines
arch/s390/pci/pci_bus.c +1 -0
@@ -206,10 +214,12 @@ static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s
  	bus = pci_create_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resources);
  	if (!bus) {
  		zpci_free_domain(zbus->domain_nr);
+		zpci_remove_parent_msi_domain(zbus);
  		return -EFAULT;
  	}
 

Nit: I wonder if it would be more readable if we used goto statements here and above.

<..snip..>

arch/s390/pci/pci_bus.c static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s

Quoted 9 lines
arch/s390/pci/pci_bus.c +9 -0
+
+/*
+ * Encode the hwirq number for the parent domain. The encoding must be unique
+ * for each IRQ of each device in the parent domain, so it uses the devfn to
+ * identify the device and the msi_index to identify the IRQ within that device.
+ */
+static inline u32 zpci_encode_hwirq(u8 devfn, u16 msi_index)
+{
+	return (devfn << 16) | msi_index;

I see we have changed the encoding from using the fid to using the devfn, any reason for changing it? AFAIU the fid is unique for every function within the system.

Also thinking it out loud, is it this going to be unique if we have multiple IRQ (if nr_irqs in zpci_msi_domain_alloc() is > 1) per MSI descriptor, unless I missed something?

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

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

Quoted 7 lines · Tobias Schumacher

Am 2025-11-18 22:49, schrieb Farhan Ali:

Quoted 3 lines

Also thinking it out loud, is it this going to be unique if we have multiple IRQ (if nr_irqs in zpci_msi_domain_alloc() is > 1) per MSI descriptor, unless I missed something?

AFAIU also for MSI there is one MSI descriptor per IRQ (allocated in msi_domain_alloc_simple_msi_descs()).

Correct because MSI only stores the MSI message for the index=0. If there are multiple interrupts in the device then the MSI controller adds the index of the interrupt to be raised in the lower bits of msi_msg::data

Quoted 4 lines

The MSI index is incremented with each descriptor. We could iterate these descriptors, but since the index is incremented with each desc alloc() simply implements a for loop that increments the hwirq number for each irq.

That's correct because the MSI controller in the PCI device requires that the hardware interrupt numbers are consecutive due to the above.

Thanks,

tglx