genirq: s390/pci: Migrate MSI interrupts to irqdomain API
v5 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 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 | 4 + arch/s390/pci/pci_bus.c | 21 ++- arch/s390/pci/pci_irq.c | 333 +++++++++++++++++++++++++++----------------- include/linux/irqdesc.h | 6 +- kernel/irq/irqdesc.c | 6 +- 6 files changed, 233 insertions(+), 138 deletions(-)
---
base-commit: 82ef9f0fac73cca3e7d776b095b5a7de1b0b88fc
change-id: 20251104-implement-msi-domain-dc1ea014580e
Best regards,
Signature · 1 line
Tobias Schumacher <[email protected]>
PATCH v5 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
PATCH v5 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 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 PCI function id and the MSI index.
--- arch/s390/Kconfig | 1 + arch/s390/include/asm/pci.h | 4 + arch/s390/pci/pci_bus.c | 21 ++- arch/s390/pci/pci_irq.c | 333 +++++++++++++++++++++++++++----------------- 4 files changed, 227 insertions(+), 132 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 +4 -0
@@ -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 +16 -5
@@ -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>
@@ -189,7 +190,7 @@ static bool zpci_bus_is_multifunction_root(struct zpci_dev *zdev)static int zpci_bus_create_pci_bus (struct zpci_bus *zbus,struct zpci_dev *fr,struct pci_ops *ops) {struct pci_bus *bus; -int domain; +int domain, rc; domain =zpci_alloc_domain ((u16 )fr->uid);if (domain <0 )
@@ -199,19 +200,28 @@ 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) + 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 -EFAULT ; }static void zpci_bus_release (struct kref *kref)
@@ -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 +206 -127
434 lines not on this page · raw message
Signature · 1 line
2.48.1
Heiko Carstens
maintainerRe: [PATCH v5 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API
Quoted 3 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:
...
Quoted 7 lines
Signed-off-by Tobias Schumacher <[email protected]>--- arch/s390/Kconfig | 1 + arch/s390/include/asm/pci.h | 4 + arch/s390/pci/pci_bus.c | 21 ++- arch/s390/pci/pci_irq.c | 333 +++++++++++++++++++++++++++----------------- 4 files changed, 227 insertions(+), 132 deletions(-)
...
arch/s390/pci/pci_irq.c static int zpci_set_irq(struct zpci_dev *zdev) · line 141
Quoted 6 lines
static struct
irq_chipzpci_irq_chip= {arch/s390/pci/pci_irq.c +1
-2.name = "PCI-MSI", - .irq_unmask = pci_msi_unmask_irq, - .irq_mask = pci_msi_mask_irq, + .irq_compose_msi_msg = zpci_compose_msi_msg };
C99 initializers are supposed to end with a comma. If new initializers would be added with subsequent patches, this makes the patches smaller (adding the extra "," to the existing line is just noise).
arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 310
Quoted 6 lines
arch/s390/pci/pci_irq.c +2
-3-if (msi_vecs < nvec) { -pr_info ("%s requested %d irqs, allocate system limit of %d" , +if (msi_vecs < nvec) +pr_info ("%s requested %d IRQs, allocate system limit of %d\n" ,pci_name (pdev), nvec, zdev->max_msi); - }
Bodies of if-statements with more than one line are supposed to come with brackets for readability reasons, like it used to be before your change.
Note that for new s390 code we mostly follow the coding style guideline as described in Documentation/process/maintainer-tip.rst. Maybe it makes sense to spend the effort to add an s390 specific variant of that document...
Anyway, I'll change your code accordingly when applying - no need for a version.
Gerd Bayer
maintainerRe: [PATCH v5 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API
In reply to Tobias SchumacherHi Tobias,
sorry for being late with my comments...
Quoted 29 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 inprepare().
-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 ofzpci_msi_alloc()and
-zpci_msi_teardown()reverts the effects ofzpci_msi_prepare(). This is called once when all IRQs are freed before a device is removed.
Quoted 6 lines
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.
This is no longer true with the per-PCI-domain irq domains! But you encode the hwirq with the devfn within the PCI domain, instead.
Quoted 15 lines
Reviewed-by Niklas Schnelle <[email protected]>Reviewed-by Farhan Ali <[email protected]>Signed-off-by Tobias Schumacher <[email protected]>--- arch/s390/Kconfig | 1 + arch/s390/include/asm/pci.h | 4 + arch/s390/pci/pci_bus.c | 21 ++- arch/s390/pci/pci_irq.c | 333 +++++++++++++++++++++++++++----------------- 4 files changed, 227 insertions(+), 132 deletions(-)arch/s390/Kconfig +0
-0
arch/s390/Kconfig config S390 · line 254
Quoted 4 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
Nit: There's precedence for both versions (above and below!) but I personally would prefer to indent the pre-condition "if PCI" so it stands out. Maybe that's a generic clean-up task for this arch-specific file...
Quoted 54 lines
arch/s390/Kconfig +0
-0select KASAN_VMALLOC if KASAN select LOCK_MM_AND_FIND_VMA select MMU_GATHER_MERGE_VMASarch/s390/include/asm/pci.h +4
-0@@ -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 +2
-1@@ -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> @@ -189,7 +190,7 @@ static bool zpci_bus_is_multifunction_root(struct zpci_dev *zdev)static int zpci_bus_create_pci_bus (struct zpci_bus *zbus,struct zpci_dev *fr,struct pci_ops *ops) {struct pci_bus *bus; -int domain; +int domain, rc; domain =zpci_alloc_domain ((u16 )fr->uid);if (domain <0 )
arch/s390/pci/pci_bus.c static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s · line 206
Quoted 7 lines
arch/s390/pci/pci_bus.c +4
-0@@ -199,19 +200,28 @@ 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) + goto out_free_domain; +
If you shortened this to use the call to zpci_create_parent_msi_domain() as predicate for "if" you could do without the additional rc.
arch/s390/pci/pci_bus.c static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s · line 213
Quoted 12 lines
arch/s390/pci/pci_bus.c +2
-4/* * 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;
Or do you want to set rc to -EFAULT here, and return the "original" rc in the error exits?
Quoted 35 lines
arch/s390/pci/pci_bus.c +8
-0zbus->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 -EFAULT ; }static void zpci_bus_release (struct kref *kref)@@ -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 +1
-0@@ -7,6 +7,7 @@#include <linux/kernel_stat.h> #include <linux/pci.h> #include <linux/msi.h> +#include <linux/irqchip/irq-msi-lib.h> #include <linux/smp.h> #include <asm/isc.h>
arch/s390/pci/pci_irq.c static int zpci_set_irq(struct zpci_dev *zdev) · line 114
Quoted 5 lines
arch/s390/pci/pci_irq.c +0
-2@@ -110,43 +111,41 @@ static int zpci_set_irq(struct zpci_dev *zdev)return rc; } -/* Clear adapter interruptions */ -static int zpci_clear_irq (struct zpci_dev *zdev)
Any specific reason, why you removed zpci_clear_irq() indirecting to airq vs. directed_irq - but kept zpci_set_irq()? Just saying this is imbalanced now.
Quoted 57 lines
arch/s390/pci/pci_irq.c +19
-19+static int zpci_set_irq_affinity (struct irq_data *data,const struct cpumask *dest, +bool force) { -int rc; - -if (irq_delivery ==DIRECTED ) - rc =zpci_clear_directed_irq (zdev); -else - rc =zpci_clear_airq (zdev); - -return rc; +irq_data_update_affinity (data, dest); +return IRQ_SET_MASK_OK ; } -static int zpci_set_irq_affinity (struct irq_data *data,const struct cpumask *dest, -bool force) +static void zpci_compose_msi_msg (struct irq_data *data,struct msi_msg *msg) { -struct msi_desc *entry =irq_data_get_msi_desc (data); -struct msi_msg msg = entry->msg; -int cpu_addr =smp_cpu_get_cpu_address (cpumask_first (dest)); +struct msi_desc *desc =irq_data_get_msi_desc (data); +struct zpci_dev *zdev =to_zpci_dev (desc->dev); - msg.address_lo &=0xff0000ff ; - msg.address_lo |= (cpu_addr <<8 ); -pci_write_msi_msg (data->irq, &msg); +if (irq_delivery ==DIRECTED ) { +int cpu =cpumask_first (irq_data_get_affinity_mask (data)); -return IRQ_SET_MASK_OK ; + msg->address_lo = zdev->msi_addr &0xff0000ff ; + msg->address_lo |= (smp_cpu_get_cpu_address (cpu) <<8 ); + }else { + msg->address_lo = zdev->msi_addr &0xffffffff ; + } + msg->address_hi = zdev->msi_addr >>32 ; + msg->data = data->hwirq &0xffffffff ; }static struct irq_chip zpci_irq_chip = { .name ="PCI-MSI" , - .irq_unmask = pci_msi_unmask_irq, - .irq_mask = pci_msi_mask_irq, + .irq_compose_msi_msg = zpci_compose_msi_msg };static void zpci_handle_cpu_local_irq (bool rescan) {struct airq_iv *dibv = zpci_ibv[smp_processor_id ()];union zpci_sic_iib iib = {{0 }}; +struct irq_domain *msi_domain; +irq_hw_number_t hwirq;unsigned long bit;int irqs_on =0 ;
[... snip ...]
Quoted 30 lines
arch/s390/pci/pci_irq.c +13
-9@@ -290,146 +297,217 @@ 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; - zdev->aisb =-1UL ; - zdev->msi_first_bit =-1U ; +zpci_set_irq (zdev); +return true; +} + +static struct airq_struct zpci_airq = { + .handler = zpci_floating_irq_handler, + .isc =PCI_ISC , +}; + +/* +* 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
arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 325
Quoted 10 lines
arch/s390/pci/pci_irq.c +10
-0+* 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; +} + +static inline u16 zpci_decode_hwirq_msi_index (irq_hw_number_t irq) +{ +return irq &GENMASK_U16 (15 ,0 );
Please don't use GENMASK_U16. It is harder to read than any explicit constant like 0x00FF, especially since its parameters contradict the architecture's endianess.
But then, is this called anywhere?
Quoted 58 lines
arch/s390/pci/pci_irq.c +19
-32+} + +static int zpci_msi_prepare (struct irq_domain *domain, +struct device *dev,int nvec, +msi_alloc_info_t *info) +{ +struct zpci_dev *zdev =to_zpci_dev (dev); +struct pci_dev *pdev =to_pci_dev (dev); +unsigned long bit; +int msi_vecs, rc; msi_vecs = min_t(unsigned int, nvec, zdev->max_msi); -if (msi_vecs < nvec) { -pr_info ("%s requested %d irqs, allocate system limit of %d" , +if (msi_vecs < nvec) +pr_info ("%s requested %d IRQs, allocate system limit of %d\n" ,pci_name (pdev), nvec, zdev->max_msi); - } rc =__alloc_airq (zdev, msi_vecs, &bit); -if (rc <0 ) +if (rc) { +pr_err ("Allocating adapter IRQs for %s failed\n" ,pci_name (pdev));return rc; + } -/* -* Request MSI interrupts: -* When using MSI, nvec_used interrupt sources and their irq -* descriptors are controlled through one msi descriptor. -* Thus the outer loop over msi descriptors shall run only once, -* while two inner loops iterate over the interrupt vectors. -* When using MSI-X, each interrupt vector/irq descriptor -* is bound to exactly one msi descriptor (nvec_used is one). -* So the inner loops are executed once, while the outer iterates -* over the MSI-X descriptors. -*/ - hwirq = bit; -msi_for_each_desc (msi, &pdev->dev,MSI_DESC_NOTASSOCIATED ) { -if (hwirq - bit >= msi_vecs) -break ; - irqs_per_msi = min_t(unsigned int, msi_vecs, msi->nvec_used); - irq =__irq_alloc_descs (-1 ,0 , irqs_per_msi,0 ,THIS_MODULE , - (irq_delivery ==DIRECTED ) ? - msi->affinity :NULL ); -if (irq <0 ) -return -ENOMEM ; - -for (i =0 ; i < irqs_per_msi; i++) { - rc =irq_set_msi_desc_off (irq, i, msi); -if (rc) -return rc; -irq_set_chip_and_handler (irq + i, &zpci_irq_chip, - handle_percpu_irq); + zdev->msi_first_bit = bit; + zdev->msi_nr_irqs = msi_vecs; + rc =zpci_set_irq (zdev); +if (rc) {
arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 361
Quoted 10 lines
arch/s390/pci/pci_irq.c +10
-0+pr_err ("Registering adapter IRQs for %s failed\n" , +pci_name (pdev)); +if (irq_delivery ==DIRECTED ) { +airq_iv_free (zpci_ibv[0 ], zdev->msi_first_bit, msi_vecs); + }else { +zpci_clear_airq (zdev); +airq_iv_release (zdev->aibv); + zdev->aibv =NULL ; +airq_iv_free_bit (zpci_sbv, zdev->aisb); + zdev->aisb =-1UL ;
These two failure clean-ups look a lot like zpci_msi_teardown_directed/_floating() below. Could these be called instead of duplicating the code?
Quoted 34 lines
arch/s390/pci/pci_irq.c +22
-9} + zdev->msi_first_bit =-1U ; +return rc; + } - msg.data = hwirq - bit; -if (irq_delivery ==DIRECTED ) { -if (msi->affinity) - cpu =cpumask_first (&msi->affinity->mask); -else - cpu =0 ; - cpu_addr =smp_cpu_get_cpu_address (cpu); +return 0 ; +} + +static void zpci_msi_teardown_directed (struct zpci_dev *zdev) +{ +zpci_clear_directed_irq (zdev); +airq_iv_free (zpci_ibv[0 ], zdev->msi_first_bit, zdev->max_msi); + zdev->msi_first_bit =-1U ; +} + +static void zpci_msi_teardown_floating (struct zpci_dev *zdev) +{ +zpci_clear_airq (zdev); +airq_iv_release (zdev->aibv); + zdev->aibv =NULL ; +airq_iv_free_bit (zpci_sbv, zdev->aisb); + zdev->aisb =-1UL ; + zdev->msi_first_bit =-1U ; +} - msg.address_lo = zdev->msi_addr &0xff0000ff ; - msg.address_lo |= (cpu_addr <<8 );
arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 396
Quoted 10 lines
arch/s390/pci/pci_irq.c +9
-0+static void zpci_msi_teardown (struct irq_domain *domain,msi_alloc_info_t *arg) +{ +struct zpci_dev *zdev =to_zpci_dev (domain->dev); +if (irq_delivery ==DIRECTED ) +zpci_msi_teardown_directed (zdev); +else +zpci_msi_teardown_floating (zdev); +} +
[... snip ...]
No more findings at this point in time.
Thanks for your work!
Gerd
Heiko Carstens
maintainerRe: [PATCH v5 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API
Quoted 15 lines · Gerd Bayer
arch/s390/pci/pci_bus.c static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s · line 213
Quoted 7 lines
arch/s390/pci/pci_bus.c +2
-4bus =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;Or do you want to set rc to
-EFAULThere, and return the "original" rc in the error exits?Quoted 4 lines
arch/s390/pci/pci_bus.c +1
-0zbus->bus = bus; +dev_set_msi_domain (&zbus->bus->dev, zbus->msi_parent_domain);
Quoted 8 lines
arch/s390/pci/pci_bus.c static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s · line 225
Quoted 8 lines
arch/s390/pci/pci_bus.c +6
-0return 0 ; + +out_remove_msi_domain: +zpci_remove_parent_msi_domain (zbus); +out_free_domain: +zpci_free_domain (zbus->domain_nr); +return -EFAULT ; }
Oh, just realized this oddity with Gerd's reply: -EFAULT should _only_ be used for page faults. Looks like this return code is not passed to user space, but please change this to something more appropriate. E.g. -ENOMEM, or whatever fits here.
Given that Gerd had quite a few more comments, please send a new version with my comments also addressed :)
Re: [PATCH v5 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API
Quoted 30 lines · Heiko Carstens
Quoted 15 lines · Gerd Bayer
arch/s390/pci/pci_bus.c static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s · line 213
Quoted 7 lines
arch/s390/pci/pci_bus.c +2
-4bus =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;Or do you want to set rc to
-EFAULThere, and return the "original" rc in the error exits?Quoted 4 lines
arch/s390/pci/pci_bus.c +1
-0zbus->bus = bus; +dev_set_msi_domain (&zbus->bus->dev, zbus->msi_parent_domain);Quoted 8 lines
arch/s390/pci/pci_bus.c static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s · line 225
Quoted 8 lines
arch/s390/pci/pci_bus.c +6
-0return 0 ; + +out_remove_msi_domain: +zpci_remove_parent_msi_domain (zbus); +out_free_domain: +zpci_free_domain (zbus->domain_nr); +return -EFAULT ; }Oh, just realized this oddity with Gerd's reply:
-EFAULTshould _only_ be used for page faults. Looks like this return code is not passed to user space, but please change this to something more appropriate. E.g.-ENOMEM, or whatever fits here.
Quoted 2 lines
Given that Gerd had quite a few more comments, please send a new version with my comments also addressed :)
Sure, will do
Thanks,
Tobias
Re: [PATCH v5 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API
In reply to Gerd BayerQuoted 38 lines · Gerd Bayer
Hi Tobias,
sorry for being late with my comments...
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 inprepare().
-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 ofzpci_msi_alloc()and
-zpci_msi_teardown()reverts the effects ofzpci_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
Quoted 5 lines
Quoted 2 lines
encoding the hwirq using the PCI function id and the MSI index.
This is no longer true with the per-PCI-domain irq domains! But you encode the hwirq with the devfn within the PCI domain, instead.
Correct, will fix that.
Quoted 10 lines
Quoted 10 lines
Reviewed-by Niklas Schnelle <[email protected]>Reviewed-by Farhan Ali <[email protected]>Signed-off-by Tobias Schumacher <[email protected]>--- arch/s390/Kconfig | 1 + arch/s390/include/asm/pci.h | 4 + arch/s390/pci/pci_bus.c | 21 ++- arch/s390/pci/pci_irq.c | 333 +++++++++++++++++++++++++++----------------- 4 files changed, 227 insertions(+), 132 deletions(-)
Quoted 14 lines
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 PCINit: There's precedence for both versions (above and below!) but I personally would prefer to indent the pre-condition "if PCI" so it stands out. Maybe that's a generic clean-up task for this arch-specific file...
Since at least the 'if PCI' preconditions are indented in this file, I'll also do it for this line.
Quoted 13 lines
Quoted 13 lines
arch/s390/Kconfig +1
-1@@ -189,7 +190,7 @@ static bool zpci_bus_is_multifunction_root(struct zpci_dev *zdev) static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, struct pci_ops *ops) { struct pci_bus *bus; - int domain; + int domain, rc; domain = zpci_alloc_domain((u16)fr->uid); if (domain < 0)@@ -199,19 +200,28 @@ 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;
Quoted 8 lines
arch/s390/Kconfig static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s · line 206
Quoted 4 lines
arch/s390/Kconfig +4
-0+ rc = zpci_create_parent_msi_domain(zbus); + if (rc) + goto out_free_domain; +If you shortened this to use the call to
zpci_create_parent_msi_domain()as predicate for "if" you could do without the additional rc.
Will do.
Quoted 6 lines
Quoted 6 lines
arch/s390/Kconfig +0
-1/* * 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) {
Quoted 8 lines
arch/s390/Kconfig static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s · line 213
Quoted 5 lines
arch/s390/Kconfig +2
-3- zpci_free_domain(zbus->domain_nr); - return -EFAULT; - } + if (!bus) + goto out_remove_msi_domain;Or do you want to set rc to
-EFAULThere, and return the "original" rc in the error exits?
As Heiko mentioned, -EFAULT shouldn't be returned anyways I'd change it to -ENOMEM for all error cases.
--- snip ---
Quoted 16 lines
Quoted 16 lines
arch/s390/pci/pci_irq.c +1
-0@@ -7,6 +7,7 @@#include <linux/kernel_stat.h> #include <linux/pci.h> #include <linux/msi.h> +#include <linux/irqchip/irq-msi-lib.h> #include <linux/smp.h> #include <asm/isc.h> @@ -110,43 +111,41 @@ static int zpci_set_irq(struct zpci_dev *zdev)return rc; }
Quoted 7 lines
arch/s390/pci/pci_irq.c static int zpci_set_irq(struct zpci_dev *zdev) · line 114
Quoted 2 lines
arch/s390/pci/pci_irq.c +0
-2-/* Clear adapter interruptions */ -static int zpci_clear_irq (struct zpci_dev *zdev)Any specific reason, why you removed
zpci_clear_irq()indirecting to airq vs.directed_irq- but keptzpci_set_irq()? Just saying this is imbalanced now.
I removed it because it was only required in zpci_msi_teardown(), which already has the distinction between directed and floating IRQs. So having a separate zpci_clear_irq() seemed redundant.
--- snip ---
Quoted 9 lines
arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 325
Quoted 3 lines
arch/s390/pci/pci_irq.c +3
-0+static inline u16 zpci_decode_hwirq_msi_index (irq_hw_number_t irq) +{ +return irq &GENMASK_U16 (15 ,0 );Please don't use
GENMASK_U16. It is harder to read than any explicit constant like0x00FF, especially since its parameters contradict the architecture's endianess.
But then, is this called anywhere?
Right, it's not used anymore, I'll remove it completely.
--- snip ---
Quoted 62 lines
Quoted 62 lines
arch/s390/pci/pci_irq.c +23
-32+static int zpci_msi_prepare (struct irq_domain *domain, +struct device *dev,int nvec, +msi_alloc_info_t *info) +{ +struct zpci_dev *zdev =to_zpci_dev (dev); +struct pci_dev *pdev =to_pci_dev (dev); +unsigned long bit; +int msi_vecs, rc; msi_vecs = min_t(unsigned int, nvec, zdev->max_msi); -if (msi_vecs < nvec) { -pr_info ("%s requested %d irqs, allocate system limit of %d" , +if (msi_vecs < nvec) +pr_info ("%s requested %d IRQs, allocate system limit of %d\n" ,pci_name (pdev), nvec, zdev->max_msi); - } rc =__alloc_airq (zdev, msi_vecs, &bit); -if (rc <0 ) +if (rc) { +pr_err ("Allocating adapter IRQs for %s failed\n" ,pci_name (pdev));return rc; + } -/* -* Request MSI interrupts: -* When using MSI, nvec_used interrupt sources and their irq -* descriptors are controlled through one msi descriptor. -* Thus the outer loop over msi descriptors shall run only once, -* while two inner loops iterate over the interrupt vectors. -* When using MSI-X, each interrupt vector/irq descriptor -* is bound to exactly one msi descriptor (nvec_used is one). -* So the inner loops are executed once, while the outer iterates -* over the MSI-X descriptors. -*/ - hwirq = bit; -msi_for_each_desc (msi, &pdev->dev,MSI_DESC_NOTASSOCIATED ) { -if (hwirq - bit >= msi_vecs) -break ; - irqs_per_msi = min_t(unsigned int, msi_vecs, msi->nvec_used); - irq =__irq_alloc_descs (-1 ,0 , irqs_per_msi,0 ,THIS_MODULE , - (irq_delivery ==DIRECTED ) ? - msi->affinity :NULL ); -if (irq <0 ) -return -ENOMEM ; - -for (i =0 ; i < irqs_per_msi; i++) { - rc =irq_set_msi_desc_off (irq, i, msi); -if (rc) -return rc; -irq_set_chip_and_handler (irq + i, &zpci_irq_chip, - handle_percpu_irq); + zdev->msi_first_bit = bit; + zdev->msi_nr_irqs = msi_vecs; + rc =zpci_set_irq (zdev); +if (rc) { +pr_err ("Registering adapter IRQs for %s failed\n" , +pci_name (pdev)); +if (irq_delivery ==DIRECTED ) { +airq_iv_free (zpci_ibv[0 ], zdev->msi_first_bit, msi_vecs); + }else { +zpci_clear_airq (zdev);
Quoted 8 lines
arch/s390/pci/pci_irq.c static int __alloc_airq(struct zpci_dev *zdev, int msi_vecs, · line 361
Quoted 4 lines
arch/s390/pci/pci_irq.c +4
-0+airq_iv_release (zdev->aibv); + zdev->aibv =NULL ; +airq_iv_free_bit (zpci_sbv, zdev->aisb); + zdev->aisb =-1UL ;These two failure clean-ups look a lot like zpci_msi_teardown_directed/_floating() below. Could these be called instead of duplicating the code?
Yes they are similar, only that zpci_msi_teardown_directed/_floating() also call zpci_clear_directed_irq()/zpci_clear_airq(), respectively. Considering your other comment above, it might be cleaner to add zpci_clear_irq() again, call this directly from zpci_msi_teardown() and then use zpci_msi_teardown_directed/_floating() here as suggested.
Thanks,
Tobias
Niklas Schnelle
maintainerQuoted 28 lines · Tobias Schumacher
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()andarch_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 ofzpci_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 ofzpci_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
Quoted 5 lines
Since patch 1 changes common APIs, some build tests were done for
x86_64and arm64.Signed-off-by Tobias Schumacher <[email protected]>---
@Heiko, @Vasily, @Alexander, from my point of view this series is ready to be picked up for the s390 tree and would also benefit from time on linux-next etc.
Thanks,
Niklas