genirq: s390/pci: Migrate MSI interrupts to irqdomain API
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 correspoding 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 must be fixed to allow for the hwirq encoding used for s390.
* Patch 2 implements IRQ domains for s390 PCI
Since patch 1 changes common APIs, some build tests were done for x86_64 and arm64.
---
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 | 1 + arch/s390/pci/pci_bus.c | 1 + arch/s390/pci/pci_irq.c | 323 +++++++++++++++++++++++++++----------------- include/linux/irqdesc.h | 6 +- kernel/irq/irqdesc.c | 6 +- 6 files changed, 209 insertions(+), 129 deletions(-)
---
base-commit: 882489402b556fa6d916cba86051276fcc9a8953
change-id: 20251104-implement-msi-domain-dc1ea014580e
Best regards,
Signature · 1 line
Tobias Schumacher <[email protected]>
PATCH 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
@@ -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
@@ -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
Re: [PATCH 1/2] genirq: Change hwirq parameter to irq_hw_number_t
Quoted 8 lines · Tobias Schumacher
The irqdomain implementation internally represents hardware IRQs as
irq_hw_number_t, which is defined as unsigned long int. When providing anirq_hw_number_tto thegeneric_handle_domain()functions that expect and unsigned int hwirq, this can lead to a loss of information. Change the hwirq parameter toirq_hw_number_tto support the full range of hwirqs.Signed-off-by Tobias Schumacher <[email protected]>
Assuming this goes through the s390 tree:
PATCH 2/2 s390/pci: Migrate s390 IRQ logic to IRQ domain API
In reply to Tobias Schumachers390 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 be 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 | 1 + arch/s390/pci/pci_bus.c | 1 + arch/s390/pci/pci_irq.c | 323 +++++++++++++++++++++++++++----------------- 4 files changed, 203 insertions(+), 123 deletions(-)
arch/s390/Kconfig +1 -0
@@ -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 +1 -0
@@ -310,6 +310,7 @@ int zpci_dma_exit_device(struct zpci_dev *zdev);/* IRQ */ int __init zpci_irq_init (void );void __init zpci_irq_exit (void ); +void zpci_set_msi_parent_domain (struct zpci_bus *zbus);/* FMB */ int zpci_fmb_enable_device (struct zpci_dev *);
arch/s390/pci/pci_bus.c +1 -0
@@ -210,6 +210,7 @@ static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s } zbus->bus = bus; +zpci_set_msi_parent_domain (zbus);return 0 ; }
arch/s390/pci/pci_irq.c +200 -123
452 lines not on this page · raw message
Signature · 1 line
2.48.1
Niklas Schnelle
maintainerRe: [PATCH 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API
Quoted 10 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. When a PCI device sets up MSI or MSI-X IRQs, the library creates a per-device IRQ domain for this device, which is be used by the device for allocating and freeing IRQs.
Nit: superfluous word "be"
Quoted 4 lines
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.
--- snip ---
arch/s390/Kconfig config S390 · line 254
Quoted 9 lines
arch/s390/Kconfig +1
-0@@ -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
The indentation is wrong here, instead of two spaces you want one tab to match the context.
arch/s390/Kconfig config S390 · line 257
Quoted 3 lines
arch/s390/Kconfig +0
-0select KASAN_VMALLOC if KASAN select LOCK_MM_AND_FIND_VMA select MMU_GATHER_MERGE_VMAS
--- snip ---
arch/s390/Kconfig
Quoted 5 lines
arch/s390/Kconfig +5
-0+ +static int zpci_msi_prepare(struct irq_domain *domain, + struct device *dev, int nvec, + msi_alloc_info_t *info) +{
--- snip ---
arch/s390/Kconfig
Quoted 7 lines
arch/s390/Kconfig +5
-2- - msg.data = hwirq - bit; + zdev->msi_first_bit = bit; + rc = zpci_set_irq(zdev); + if (rc) { + pr_err("Registering floating adapter interruptions for %s failed\n", + pci_name(pdev));
The error message is misleading as this could also happen for directed. I'd just drop the "floating" in there. Also the wording is inconsistent with the error message for allocation. I don't really have a preference between "AIRQ" and "adapter interruptions" but from a Linux point of view I think IRQ would be what I'd be grepping for which finds the former.
arch/s390/Kconfig
Quoted 2 lines
arch/s390/Kconfig +0
-1if (irq_delivery == DIRECTED) { - if (msi->affinity)
--- snip ---
arch/s390/Kconfig
Quoted 7 lines
arch/s390/Kconfig +6
-0+static int __init zpci_create_parent_msi_domain(void) +{ + struct irq_domain_info info = { + .fwnode = irq_domain_alloc_named_fwnode("zpci_msi"), + .ops = &zpci_msi_domain_ops + };
Nit: Missing empty line as the above is a variable definition
Quoted 7 lines
arch/s390/Kconfig +5
-0+ if (!info.fwnode) { + pr_err("Failed to allocate fwnode for MSI IRQ domain\n"); + return -ENOMEM; + } +
arch/s390/Kconfig
Quoted 10 lines
arch/s390/Kconfig +10
-0+ zpci_msi_parent_domain = msi_create_parent_irq_domain(&info, &zpci_msi_parent_ops); + if (!zpci_msi_parent_domain) { + irq_domain_free_fwnode(info.fwnode); + pr_err("Failed to create MSI IRQ domain\n"); + return -ENOMEM; + } + + return 0; +} +
--- snip ---
arch/s390/Kconfig void __init zpci_irq_exit(void) · line 631
Quoted 8 lines
arch/s390/Kconfig +1
-0@@ -549,6 +625,7 @@ void __init zpci_irq_exit(void) } } kfree(zpci_ibv); + irq_domain_remove(zpci_msi_parent_domain); if (zpci_sbv) airq_iv_release(zpci_sbv); unregister_adapter_interrupt(&zpci_airq);
Shouldn't zpci_irq_exit() also call irq_domain_free_fwnode() with zpci_msi_parent_domain->fwnode? Otherwise I think a potential subsequent zpci_irq_init() would fail because the fwnode already exists. Not that we currently ever do that but still it should be all undone.
Overall this looks great to me. I did run into an issue with my experimental directed IRQ setup, we can work off list to solve this before v2.
Thanks,
Niklas