From: Thomas Gleixner <hidden> Date: 2021-12-10 22:19:11
This is the second part of [PCI]MSI refactoring which aims to provide the
ability of expanding MSI-X vectors after enabling MSI-X.
This is based on the first part of this work which can be found here:
https://lore.kernel.org/r/20211206210147.872865823@linutronix.de
and has been applied to:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq/msi
This second part has the following important changes:
1) Cleanup of the MSI related data in struct device
struct device contains at the moment various MSI related parts. Some
of them (the irq domain pointer) cannot be moved out, but the rest
can be allocated on first use. This is in preparation of adding more
per device MSI data later on.
2) Consolidation of sysfs handling
As a first step this moves the sysfs pointer from struct msi_desc
into the new per device MSI data structure where it belongs.
Later changes will cleanup this code further, but that's not possible
at this point.
3) Use PCI device properties instead of looking up MSI descriptors and
analysing their data.
4) Provide a function to retrieve the Linux interrupt number for a given
MSI index similar to pci_irq_vector() and cleanup all open coded
variants.
It's also available from git:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git msi-v3-part-2
Part 3 of this effort is available on top
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git msi-v3-part-3
Part 3 is not going to be reposted as there is no change vs. V2.
V2 of part 2 can be found here:
https://lore.kernel.org/r/20211206210307.625116253@linutronix.de
Changes versus V2:
- Use PCI device properties instead of creating a new set - Jason
- Picked up Reviewed/Tested/Acked-by tags as appropriate
Thanks,
tglx
---
arch/powerpc/platforms/cell/axon_msi.c | 5
arch/powerpc/platforms/pseries/msi.c | 38 +---
arch/x86/kernel/apic/msi.c | 5
arch/x86/pci/xen.c | 11 -
drivers/base/platform-msi.c | 152 ++++++++-----------
drivers/bus/fsl-mc/dprc-driver.c | 8 -
drivers/bus/fsl-mc/fsl-mc-allocator.c | 9 -
drivers/bus/fsl-mc/fsl-mc-msi.c | 26 +--
drivers/dma/mv_xor_v2.c | 16 --
drivers/dma/qcom/hidma.c | 44 ++---
drivers/dma/ti/k3-udma-private.c | 6
drivers/dma/ti/k3-udma.c | 14 -
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 23 --
drivers/irqchip/irq-mbigen.c | 4
drivers/irqchip/irq-mvebu-icu.c | 12 -
drivers/irqchip/irq-ti-sci-inta.c | 2
drivers/mailbox/bcm-flexrm-mailbox.c | 9 -
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 4
drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c | 4
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c | 5
drivers/pci/msi/irqdomain.c | 20 ++
drivers/pci/msi/legacy.c | 6
drivers/pci/msi/msi.c | 133 ++++++----------
drivers/pci/xen-pcifront.c | 2
drivers/perf/arm_smmuv3_pmu.c | 5
drivers/soc/fsl/dpio/dpio-driver.c | 8 -
drivers/soc/ti/k3-ringacc.c | 6
drivers/soc/ti/ti_sci_inta_msi.c | 22 --
drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c | 4
include/linux/device.h | 25 ++-
include/linux/fsl/mc.h | 4
include/linux/msi.h | 95 ++++--------
include/linux/pci.h | 1
include/linux/soc/ti/ti_sci_inta_msi.h | 1
kernel/irq/msi.c | 158 +++++++++++++++-----
35 files changed, 429 insertions(+), 458 deletions(-)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:19:14
There are quite some places which retrieve the first MSI descriptor to
evaluate whether the setup is for MSI or MSI-X. That's required because
pci_dev::msi[x]_enabled is only set when the setup completed successfully.
There is no real reason why msi[x]_enabled can't be set at the beginning of
the setup sequence and cleared in case of a failure.
Implement that so the MSI descriptor evaluations can be converted to simple
property queries.
Signed-off-by: Thomas Gleixner <redacted>
---
V3: New patch
---
drivers/pci/msi/msi.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
@@ -421,11 +421,18 @@ static int msi_capability_init(struct pcstructmsi_desc*entry;intret;-pci_msi_set_enable(dev,0);/* Disable MSI during set up */+/*+*DisableMSIduringsetupinthehardware,butmarkitenabled+*sothatsetupcodecanevaluateit.+*/+pci_msi_set_enable(dev,0);+dev->msi_enabled=1;entry=msi_setup_entry(dev,nvec,affd);-if(!entry)-return-ENOMEM;+if(!entry){+ret=-ENOMEM;+gotofail;+}/* All MSIs are unmasked by default; mask them all */pci_msi_mask(entry,msi_multi_mask(entry));
@@ -452,7 +459,6 @@ static int msi_capability_init(struct pc/* Set MSI enabled bits */pci_intx_for_msi(dev,0);pci_msi_set_enable(dev,1);-dev->msi_enabled=1;pcibios_free_irq(dev);dev->irq=entry->irq;
@@ -461,6 +467,8 @@ static int msi_capability_init(struct pcerr:pci_msi_unmask(entry,msi_multi_mask(entry));free_msi_irqs(dev);+fail:+dev->msi_enabled=0;returnret;}
@@ -589,6 +597,9 @@ static int msix_capability_init(struct ppci_msix_clear_and_set_ctrl(dev,0,PCI_MSIX_FLAGS_MASKALL|PCI_MSIX_FLAGS_ENABLE);+/* Mark it enabled so setup functions can query it */+dev->msix_enabled=1;+pci_read_config_word(dev,dev->msix_cap+PCI_MSIX_FLAGS,&control);/* Request & Map MSI-X table region */tsize=msix_table_size(control);
@@ -626,9 +637,8 @@ static int msix_capability_init(struct pdev->msi_irq_groups=groups;-/* Set MSI-X enabled bits and unmask the function */+/* Disable INTX and unmask MSI-X */pci_intx_for_msi(dev,0);-dev->msix_enabled=1;pci_msix_clear_and_set_ctrl(dev,PCI_MSIX_FLAGS_MASKALL,0);pcibios_free_irq(dev);
@@ -638,6 +648,7 @@ static int msix_capability_init(struct pfree_msi_irqs(dev);out_disable:+dev->msix_enabled=0;pci_msix_clear_and_set_ctrl(dev,PCI_MSIX_FLAGS_ENABLE,0);returnret;
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:19:24
From: Thomas Gleixner <redacted>
instead of fiddling with MSI descriptors.
Signed-off-by: Thomas Gleixner <redacted>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
V3: Use pci_dev property - Jason
V2: Invoke the function with the correct number of arguments - Andy
---
arch/powerpc/platforms/cell/axon_msi.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:19:26
From: Thomas Gleixner <redacted>
to determine whether this is MSI or MSIX instead of consulting MSI
descriptors.
Signed-off-by: Thomas Gleixner <redacted>
---
V2: Use PCI device property - Jason
---
kernel/irq/msi.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
--- a/kernel/irq/msi.c+++ b/kernel/irq/msi.c
@@ -77,21 +77,8 @@ EXPORT_SYMBOL_GPL(get_cached_msi_msg);staticssize_tmsi_mode_show(structdevice*dev,structdevice_attribute*attr,char*buf){-structmsi_desc*entry;-boolis_msix=false;-unsignedlongirq;-intretval;--retval=kstrtoul(attr->attr.name,10,&irq);-if(retval)-returnretval;--entry=irq_get_msi_desc(irq);-if(!entry)-return-ENODEV;--if(dev_is_pci(dev))-is_msix=entry->pci.msi_attrib.is_msix;+/* MSI vs. MSIX is per device not per interrupt */+boolis_msix=dev_is_pci(dev)?to_pci_dev(dev)->msix_enabled:false;returnsysfs_emit(buf,"%s\n",is_msix?"msix":"msi");}
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:19:31
From: Thomas Gleixner <redacted>
The only unconditional part of MSI data in struct device is the irqdomain
pointer. Everything else can be allocated on demand. Create a data
structure and move the irqdomain pointer into it. The other MSI specific
parts are going to be removed from struct device in later steps.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/base/platform-msi.c | 12 ++++++------
drivers/dma/ti/k3-udma.c | 4 ++--
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +-
drivers/irqchip/irq-mvebu-icu.c | 6 +++---
drivers/soc/ti/k3-ringacc.c | 4 ++--
drivers/soc/ti/ti_sci_inta_msi.c | 2 +-
include/linux/device.h | 20 ++++++++++++++------
7 files changed, 29 insertions(+), 21 deletions(-)
@@ -5279,9 +5279,9 @@ static int udma_probe(struct platform_deif(IS_ERR(ud->ringacc))returnPTR_ERR(ud->ringacc);-dev->msi_domain=of_msi_get_domain(dev,dev->of_node,+dev->msi.domain=of_msi_get_domain(dev,dev->of_node,DOMAIN_BUS_TI_SCI_INTA_MSI);-if(!dev->msi_domain){+if(!dev->msi.domain){dev_err(dev,"Failed to get MSI domain\n");return-EPROBE_DEFER;}---a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c+++b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -3170,7 +3170,7 @@ static void arm_smmu_setup_msis(struct aif(!(smmu->features&ARM_SMMU_FEAT_MSI))return;-if(!dev->msi_domain){+if(!dev->msi.domain){dev_info(smmu->dev,"msi_domain absent - falling back to wired irqs\n");return;}---a/drivers/irqchip/irq-mvebu-icu.c+++b/drivers/irqchip/irq-mvebu-icu.c
@@ -314,12 +314,12 @@ static int mvebu_icu_subset_probe(structmsi_data->subset_data=of_device_get_match_data(dev);}-dev->msi_domain=of_msi_get_domain(dev,dev->of_node,+dev->msi.domain=of_msi_get_domain(dev,dev->of_node,DOMAIN_BUS_PLATFORM_MSI);-if(!dev->msi_domain)+if(!dev->msi.domain)return-EPROBE_DEFER;-msi_parent_dn=irq_domain_get_of_node(dev->msi_domain);+msi_parent_dn=irq_domain_get_of_node(dev->msi.domain);if(!msi_parent_dn)return-ENODEV;---a/drivers/soc/ti/k3-ringacc.c+++b/drivers/soc/ti/k3-ringacc.c
@@ -1356,9 +1356,9 @@ static int k3_ringacc_init(struct platfostructresource*res;intret,i;-dev->msi_domain=of_msi_get_domain(dev,dev->of_node,+dev->msi.domain=of_msi_get_domain(dev,dev->of_node,DOMAIN_BUS_TI_SCI_INTA_MSI);-if(!dev->msi_domain){+if(!dev->msi.domain){dev_err(dev,"Failed to get MSI domain\n");return-EPROBE_DEFER;}---a/drivers/soc/ti/ti_sci_inta_msi.c+++b/drivers/soc/ti/ti_sci_inta_msi.c
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:19:37
From: Thomas Gleixner <redacted>
Create struct msi_device_data and add a pointer of that type to struct
dev_msi_info, which is part of struct device. Provide an allocator function
which can be invoked from the MSI interrupt allocation code pathes.
Add a properties field to the data structure as a first member so the
allocation size is not zero bytes. The field will be uses later on.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
include/linux/device.h | 5 +++++
include/linux/msi.h | 18 ++++++++++++++++++
kernel/irq/msi.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+)
@@ -384,6 +400,8 @@ enum {MSI_FLAG_MUST_REACTIVATE=(1<<5),/* Is level-triggered capable, using two messages */MSI_FLAG_LEVEL_CAPABLE=(1<<6),+/* Populate sysfs on alloc() and destroy it on free() */+MSI_FLAG_DEV_SYSFS=(1<<7),};intmsi_domain_set_affinity(structirq_data*data,conststructcpumask*mask,---a/kernel/irq/msi.c+++b/kernel/irq/msi.c
@@ -73,6 +73,38 @@ void get_cached_msi_msg(unsigned int irq}EXPORT_SYMBOL_GPL(get_cached_msi_msg);+staticvoidmsi_device_data_release(structdevice*dev,void*res)+{+WARN_ON_ONCE(!list_empty(&dev->msi_list));+dev->msi.data=NULL;+}++/**+*msi_setup_device_data-SetupMSIdevicedata+*@dev:DeviceforwhichMSIdevicedatashouldbesetup+*+*Return:0onsuccess,appropriateerrorcodeotherwise+*+*Thiscanbecalledmorethanoncefor@dev.IftheMSIdevicedatais+*alreadyallocatedthecallsucceeds.Theallocatedmemoryis+*automaticallyreleasedwhenthedeviceisdestroyed.+*/+intmsi_setup_device_data(structdevice*dev)+{+structmsi_device_data*md;++if(dev->msi.data)+return0;++md=devres_alloc(msi_device_data_release,sizeof(*md),GFP_KERNEL);+if(!md)+return-ENOMEM;++dev->msi.data=md;+devres_add(dev,md);+return0;+}+#ifdef CONFIG_SYSFSstaticssize_tmsi_mode_show(structdevice*dev,structdevice_attribute*attr,char*buf)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:19:43
From: Thomas Gleixner <redacted>
Allocate MSI device data on first use, i.e. when a PCI driver invokes one
of the PCI/MSI enablement functions.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/msi/msi.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:19:47
From: Thomas Gleixner <redacted>
Allocate the MSI device data on first invocation of the allocation function.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Cc: Stuart Yoder <redacted>
Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
---
drivers/bus/fsl-mc/fsl-mc-msi.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:19:51
From: Thomas Gleixner <redacted>
Allocate the MSI device data on first invocation of the allocation function
for platform MSI private data.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/base/platform-msi.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
@@ -218,6 +220,10 @@ platform_msi_alloc_priv_data(struct devireturnERR_PTR(-EINVAL);}+err=msi_setup_device_data(dev);+if(err)+returnERR_PTR(err);+/* Already had a helping of MSI? Greed... */if(!list_empty(dev_to_msi_list(dev)))returnERR_PTR(-EBUSY);
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:19:55
From: Thomas Gleixner <redacted>
It's hard to distinguish what platform_msi_domain_alloc() and
platform_msi_domain_alloc_irqs() are about. Make the distinction more
explicit and add comments which explain the use cases properly.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/base/platform-msi.c | 36 +++++++++++++++++++++---------------
drivers/irqchip/irq-mbigen.c | 4 ++--
drivers/irqchip/irq-mvebu-icu.c | 6 +++---
include/linux/msi.h | 8 ++++----
4 files changed, 30 insertions(+), 24 deletions(-)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:19:58
From: Thomas Gleixner <redacted>
This allows drivers to retrieve the Linux interrupt number instead of
fiddling with MSI descriptors.
msi_get_virq() returns the Linux interrupt number or 0 in case that there
is no entry for the given MSI index.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
V2: Simplify the implementation and let PCI deal with the PCI specialities - Marc
---
include/linux/msi.h | 2 ++
kernel/irq/msi.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
@@ -105,6 +105,42 @@ int msi_setup_device_data(struct devicereturn0;}+/**+*msi_get_virq-ReturnLinuxinterruptnumberofaMSIinterrupt+*@dev:Devicetooperateon+*@index:MSIinterruptindextolookfor(0-based)+*+*Return:TheLinuxinterruptnumberonsuccess(>0),0ifnotfound+*/+unsignedintmsi_get_virq(structdevice*dev,unsignedintindex)+{+structmsi_desc*desc;+boolpcimsi;++if(!dev->msi.data)+return0;++pcimsi=dev_is_pci(dev)?to_pci_dev(dev)->msi_enabled:false;++for_each_msi_entry(desc,dev){+/* PCI-MSI has only one descriptor for multiple interrupts. */+if(pcimsi){+if(desc->irq&&index<desc->nvec_used)+returndesc->irq+index;+break;+}++/*+*PCI-MSIXandplatformMSIuseadescriptorper+*interrupt.+*/+if(desc->msi_index==index)+returndesc->irq;+}+return0;+}+EXPORT_SYMBOL_GPL(msi_get_virq);+#ifdef CONFIG_SYSFSstaticssize_tmsi_mode_show(structdevice*dev,structdevice_attribute*attr,char*buf)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:20:01
From: Thomas Gleixner <redacted>
Set the domain info flag and remove the check.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: "Cédric Le Goater" <clg@kaod.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
V2: Remove it completely - Cedric
---
arch/powerpc/platforms/pseries/msi.c | 33 ++++++++-------------------------
1 file changed, 8 insertions(+), 25 deletions(-)
@@ -321,27 +321,6 @@ static int msi_quota_for_device(struct preturnrequest;}-staticintcheck_msix_entries(structpci_dev*pdev)-{-structmsi_desc*entry;-intexpected;--/* There's no way for us to express to firmware that we want-*adiscontiguous,ornon-zerobased,rangeofMSI-Xentries.-*Sowemustrejectsuchrequests.*/--expected=0;-for_each_pci_msi_entry(entry,pdev){-if(entry->msi_index!=expected){-pr_debug("rtas_msi: bad MSI-X entries.\n");-return-EINVAL;-}-expected++;-}--return0;-}-staticvoidrtas_hack_32bit_msi_gen2(structpci_dev*pdev){u32addr_hi,addr_lo;
@@ -380,9 +359,6 @@ static int rtas_prepare_msi_irqs(structif(quota&"a<nvec)returnquota;-if(type==PCI_CAP_ID_MSIX&&check_msix_entries(pdev))-return-EINVAL;-/**Firmwarecurrentlyrefuseanynonpoweroftwoallocation*soweroundupifthequotawillallowit.
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:20:05
From: Thomas Gleixner <redacted>
Use msi_get_vector() and handle the return value to be compatible.
No functional change intended.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
V2: Handle the INTx case directly instead of trying to be overly smart - Marc
---
drivers/pci/msi/msi.c | 25 +++++--------------------
1 file changed, 5 insertions(+), 20 deletions(-)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:20:12
From: Thomas Gleixner <redacted>
Storing a pointer to the MSI descriptor just to keep track of the Linux
interrupt number is daft. Use msi_get_virq() instead.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Cc: Vinod Koul <vkoul@kernel.org>
Cc: dmaengine@vger.kernel.org
---
drivers/dma/mv_xor_v2.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:20:21
From: Thomas Gleixner <redacted>
Storing a pointer to the MSI descriptor just to track the Linux interrupt
number is daft. Just store the interrupt number and be done with it.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Cc: Stuart Yoder <redacted>
Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
---
drivers/bus/fsl-mc/dprc-driver.c | 8 ++++----
drivers/bus/fsl-mc/fsl-mc-allocator.c | 9 ++-------
drivers/bus/fsl-mc/fsl-mc-msi.c | 6 +++---
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 4 ++--
drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c | 4 +---
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c | 5 ++---
drivers/soc/fsl/dpio/dpio-driver.c | 8 ++++----
drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c | 4 ++--
include/linux/fsl/mc.h | 4 ++--
9 files changed, 22 insertions(+), 30 deletions(-)
@@ -177,8 +176,7 @@ static int dpaa2_ptp_probe(struct fsl_mcgotoerr_unmap;}-irq=mc_dev->irqs[0];-ptp_qoriq->irq=irq->msi_desc->irq;+ptp_qoriq->irq=mc_dev->irqs[0]->virq;err=request_threaded_irq(ptp_qoriq->irq,NULL,dpaa2_ptp_irq_handler_thread,---a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c+++b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
@@ -1553,8 +1553,7 @@ static int dpaa2_switch_setup_irqs(strucirq=sw_dev->irqs[DPSW_IRQ_INDEX_IF];-err=devm_request_threaded_irq(dev,irq->msi_desc->irq,-NULL,+err=devm_request_threaded_irq(dev,irq->virq,NULL,dpaa2_switch_irq0_handler_thread,IRQF_NO_SUSPEND|IRQF_ONESHOT,dev_name(dev),dev);
@@ -1580,7 +1579,7 @@ static int dpaa2_switch_setup_irqs(strucreturn0;free_devm_irq:-devm_free_irq(dev,irq->msi_desc->irq,dev);+devm_free_irq(dev,irq->virq,dev);free_irq:fsl_mc_free_irqs(sw_dev);returnerr;---a/drivers/soc/fsl/dpio/dpio-driver.c+++b/drivers/soc/fsl/dpio/dpio-driver.c
@@ -88,7 +88,7 @@ static void unregister_dpio_irq_handlersirq=dpio_dev->irqs[0];/* clear the affinity hint */-irq_set_affinity_hint(irq->msi_desc->irq,NULL);+irq_set_affinity_hint(irq->virq,NULL);}staticintregister_dpio_irq_handlers(structfsl_mc_device*dpio_dev,intcpu)
@@ -98,7 +98,7 @@ static int register_dpio_irq_handlers(stirq=dpio_dev->irqs[0];error=devm_request_irq(&dpio_dev->dev,-irq->msi_desc->irq,+irq->virq,dpio_irq_handler,0,dev_name(&dpio_dev->dev),
@@ -111,10 +111,10 @@ static int register_dpio_irq_handlers(st}/* set the affinity hint */-if(irq_set_affinity_hint(irq->msi_desc->irq,cpumask_of(cpu)))+if(irq_set_affinity_hint(irq->virq,cpumask_of(cpu)))dev_err(&dpio_dev->dev,"irq_set_affinity failed irq %d cpu %d\n",-irq->msi_desc->irq,cpu);+irq->virq,cpu);return0;}---a/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c+++b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c
@@ -67,7 +67,7 @@ static int vfio_set_trigger(struct vfio_inthwirq;intret;-hwirq=vdev->mc_dev->irqs[index]->msi_desc->irq;+hwirq=vdev->mc_dev->irqs[index]->virq;if(irq->trigger){free_irq(hwirq,irq);kfree(irq->name);
@@ -137,7 +137,7 @@ static int vfio_fsl_mc_set_irq_trigger(sreturnvfio_set_trigger(vdev,index,fd);}-hwirq=vdev->mc_dev->irqs[index]->msi_desc->irq;+hwirq=vdev->mc_dev->irqs[index]->virq;irq=&vdev->mc_irqs[index];---a/include/linux/fsl/mc.h+++b/include/linux/fsl/mc.h
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:20:24
From: Thomas Gleixner <redacted>
No point in retrieving the MSI descriptors. Just query the Linux interrupt
number.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Cc: Jassi Brar <jassisinghbrar@gmail.com>
---
drivers/mailbox/bcm-flexrm-mailbox.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
@@ -1497,7 +1497,6 @@ static int flexrm_mbox_probe(struct platintindex,ret=0;void__iomem*regs;void__iomem*regs_end;-structmsi_desc*desc;structresource*iomem;structflexrm_ring*ring;structflexrm_mbox*mbox;
@@ -1608,10 +1607,8 @@ static int flexrm_mbox_probe(struct platgotofail_destroy_cmpl_pool;/* Save alloced IRQ numbers for each ring */-for_each_msi_entry(desc,dev){-ring=&mbox->rings[desc->msi_index];-ring->irq=desc->irq;-}+for(index=0;index<mbox->num_rings;index++)+mbox->rings[index].irq=msi_get_virq(dev,index);/* Check availability of debugfs */if(!debugfs_initialized())
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:20:27
From: Thomas Gleixner <redacted>
There is no reason to walk the MSI descriptors to retrieve the interrupt
number for a device. Use msi_get_virq() instead.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Sinan Kaya <okaya@kernel.org>
Cc: dmaengine@vger.kernel.org
---
drivers/dma/qcom/hidma.c | 42 ++++++++++++++++++------------------------
1 file changed, 18 insertions(+), 24 deletions(-)
@@ -692,45 +694,37 @@ static int hidma_request_msi(struct hidmstructplatform_device*pdev){#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN-intrc;-structmsi_desc*desc;-structmsi_desc*failed_desc=NULL;+intrc,i,virq;rc=platform_msi_domain_alloc_irqs(&pdev->dev,HIDMA_MSI_INTS,hidma_write_msi_msg);if(rc)returnrc;-for_each_msi_entry(desc,&pdev->dev){-if(!desc->msi_index)-dmadev->msi_virqbase=desc->irq;--rc=devm_request_irq(&pdev->dev,desc->irq,+for(i=0;i<HIDMA_MSI_INTS;i++){+virq=msi_get_virq(&pdev->dev,i);+rc=devm_request_irq(&pdev->dev,virq,hidma_chirq_handler_msi,0,"qcom-hidma-msi",&dmadev->lldev);-if(rc){-failed_desc=desc;+if(rc)break;-}+if(!i)+dmadev->msi_virqbase=virq;}if(rc){/* free allocated MSI interrupts above */-for_each_msi_entry(desc,&pdev->dev){-if(desc==failed_desc)-break;-devm_free_irq(&pdev->dev,desc->irq,-&dmadev->lldev);+for(--i;i>=0;i--){+virq=msi_get_virq(&pdev->dev,i);+devm_free_irq(&pdev->dev,virq,&dmadev->lldev);}+dev_warn(&pdev->dev,+"failed to request MSI irq, falling back to wired IRQ\n");}else{/* Add callback to free MSIs on teardown */hidma_ll_setup_irq(dmadev->lldev,true);-}-if(rc)-dev_warn(&pdev->dev,-"failed to request MSI irq, falling back to wired IRQ\n");returnrc;#elsereturn-EINVAL;
@@ -168,8 +168,7 @@ int xudma_pktdma_tflow_get_irq(struct ud{conststructudma_oes_offsets*oes=&ud->soc_data->oes;-returnti_sci_inta_msi_get_virq(ud->dev,udma_tflow_id+-oes->pktdma_tchan_flow);+returnmsi_get_virq(ud->dev,udma_tflow_id+oes->pktdma_tchan_flow);}EXPORT_SYMBOL(xudma_pktdma_tflow_get_irq);
@@ -177,7 +176,6 @@ int xudma_pktdma_rflow_get_irq(struct ud{conststructudma_oes_offsets*oes=&ud->soc_data->oes;-returnti_sci_inta_msi_get_virq(ud->dev,udma_rflow_id+-oes->pktdma_rchan_flow);+returnmsi_get_virq(ud->dev,udma_rflow_id+oes->pktdma_rchan_flow);}EXPORT_SYMBOL(xudma_pktdma_rflow_get_irq);---a/drivers/dma/ti/k3-udma.c+++b/drivers/dma/ti/k3-udma.c
@@ -2313,8 +2313,7 @@ static int udma_alloc_chan_resources(str/* Event from UDMA (TR events) only needed for slave TR mode channels */if(is_slave_direction(uc->config.dir)&&!uc->config.pkt_mode){-uc->irq_num_udma=ti_sci_inta_msi_get_virq(ud->dev,-irq_udma_idx);+uc->irq_num_udma=msi_get_virq(ud->dev,irq_udma_idx);if(uc->irq_num_udma<=0){dev_err(ud->dev,"Failed to get udma irq (index: %u)\n",irq_udma_idx);
@@ -2486,7 +2485,7 @@ static int bcdma_alloc_chan_resources(stuc->psil_paired=true;}-uc->irq_num_ring=ti_sci_inta_msi_get_virq(ud->dev,irq_ring_idx);+uc->irq_num_ring=msi_get_virq(ud->dev,irq_ring_idx);if(uc->irq_num_ring<=0){dev_err(ud->dev,"Failed to get ring irq (index: %u)\n",irq_ring_idx);
@@ -2503,8 +2502,7 @@ static int bcdma_alloc_chan_resources(st/* Event from BCDMA (TR events) only needed for slave channels */if(is_slave_direction(uc->config.dir)){-uc->irq_num_udma=ti_sci_inta_msi_get_virq(ud->dev,-irq_udma_idx);+uc->irq_num_udma=msi_get_virq(ud->dev,irq_udma_idx);if(uc->irq_num_udma<=0){dev_err(ud->dev,"Failed to get bcdma irq (index: %u)\n",irq_udma_idx);
@@ -2672,7 +2670,7 @@ static int pktdma_alloc_chan_resources(suc->psil_paired=true;-uc->irq_num_ring=ti_sci_inta_msi_get_virq(ud->dev,irq_ring_idx);+uc->irq_num_ring=msi_get_virq(ud->dev,irq_ring_idx);if(uc->irq_num_ring<=0){dev_err(ud->dev,"Failed to get ring irq (index: %u)\n",irq_ring_idx);---a/drivers/soc/ti/k3-ringacc.c+++b/drivers/soc/ti/k3-ringacc.c
@@ -647,7 +647,7 @@ int k3_ringacc_get_ring_irq_num(struct kif(!ring)return-EINVAL;-irq_num=ti_sci_inta_msi_get_virq(ring->parent->dev,ring->ring_id);+irq_num=msi_get_virq(ring->parent->dev,ring->ring_id);if(irq_num<=0)irq_num=-EINVAL;returnirq_num;---a/drivers/soc/ti/ti_sci_inta_msi.c+++b/drivers/soc/ti/ti_sci_inta_msi.c
@@ -1061,26 +1061,20 @@ EXPORT_SYMBOL(pci_irq_vector);*/conststructcpumask*pci_irq_get_affinity(structpci_dev*dev,intnr){-if(dev->msix_enabled){-structmsi_desc*entry;+intirq=pci_irq_vector(dev,nr);+structmsi_desc*desc;-for_each_pci_msi_entry(entry,dev){-if(entry->msi_index==nr)-return&entry->affinity->mask;-}-WARN_ON_ONCE(1);+if(WARN_ON_ONCE(irq<=0))returnNULL;-}elseif(dev->msi_enabled){-structmsi_desc*entry=first_pci_msi_entry(dev);-if(WARN_ON_ONCE(!entry||!entry->affinity||-nr>=entry->nvec_used))-returnNULL;--return&entry->affinity[nr].mask;-}else{+desc=irq_get_msi_desc(irq);+/* Non-MSI does not have the information handy */+if(!desc)returncpu_possible_mask;-}++if(WARN_ON_ONCE(!desc->affinity))+returnNULL;+return&desc->affinity[nr].mask;}EXPORT_SYMBOL(pci_irq_get_affinity);
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:20:37
From: Thomas Gleixner <redacted>
Provide a domain info flag which makes the core code check for a contiguous
MSI-X index on allocation. That's simpler than checking it at some other
domain callback in architecture code.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/msi/irqdomain.c | 16 ++++++++++++++--
include/linux/msi.h | 2 ++
2 files changed, 16 insertions(+), 2 deletions(-)
@@ -89,9 +89,21 @@ static int pci_msi_domain_check_cap(struif(pci_msi_desc_is_multi_msi(desc)&&!(info->flags&MSI_FLAG_MULTI_PCI_MSI))return1;-elseif(desc->pci.msi_attrib.is_msix&&!(info->flags&MSI_FLAG_PCI_MSIX))-return-ENOTSUPP;+if(desc->pci.msi_attrib.is_msix){+if(!(info->flags&MSI_FLAG_PCI_MSIX))+return-ENOTSUPP;++if(info->flags&MSI_FLAG_MSIX_CONTIGUOUS){+unsignedintidx=0;++/* Check for gaps in the entry indices */+for_each_msi_entry(desc,dev){+if(desc->msi_index!=idx++)+return-ENOTSUPP;+}+}+}return0;}---a/include/linux/msi.h+++b/include/linux/msi.h
@@ -361,6 +361,8 @@ enum {MSI_FLAG_LEVEL_CAPABLE=(1<<6),/* Populate sysfs on alloc() and destroy it on free() */MSI_FLAG_DEV_SYSFS=(1<<7),+/* MSI-X entries must be contiguous */+MSI_FLAG_MSIX_CONTIGUOUS=(1<<8),};intmsi_domain_set_affinity(structirq_data*data,conststructcpumask*mask,
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:20:41
From: Thomas Gleixner <redacted>
The usage of msi_desc::pci::entry_nr is confusing at best. It's the index
into the MSI[X] descriptor table.
Use msi_desc::msi_index which is shared between all MSI incarnations
instead of having a PCI specific storage for no value.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
arch/powerpc/platforms/pseries/msi.c | 4 ++--
arch/x86/pci/xen.c | 2 +-
drivers/pci/msi/irqdomain.c | 2 +-
drivers/pci/msi/msi.c | 20 ++++++++------------
drivers/pci/xen-pcifront.c | 2 +-
include/linux/msi.h | 2 --
6 files changed, 13 insertions(+), 19 deletions(-)
@@ -263,7 +263,7 @@ static int pci_frontend_enable_msix(strui=0;for_each_pci_msi_entry(entry,dev){-op.msix_entries[i].entry=entry->pci.msi_attrib.entry_nr;+op.msix_entries[i].entry=entry->msi_index;/* Vector is useless at this point. */op.msix_entries[i].vector=-1;i++;---a/include/linux/msi.h+++b/include/linux/msi.h
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:20:55
From: Thomas Gleixner <redacted>
Use the common msi_index member and get rid of the pointless wrapper struct.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Cc: Stuart Yoder <redacted>
Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
---
drivers/bus/fsl-mc/fsl-mc-allocator.c | 2 +-
drivers/bus/fsl-mc/fsl-mc-msi.c | 6 +++---
include/linux/msi.h | 10 ----------
3 files changed, 4 insertions(+), 14 deletions(-)
@@ -1609,7 +1609,7 @@ static int flexrm_mbox_probe(struct plat/* Save alloced IRQ numbers for each ring */for_each_msi_entry(desc,dev){-ring=&mbox->rings[desc->platform.msi_index];+ring=&mbox->rings[desc->msi_index];ring->irq=desc->irq;}---a/include/linux/msi.h+++b/include/linux/msi.h
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:21:01
From: Thomas Gleixner <redacted>
All non PCI/MSI usage variants have data structures in struct msi_desc with
only one member: xxx_index. PCI/MSI has a entry_nr member.
Add a common msi_index member to struct msi_desc so all implementations can
share it which allows further consolidation.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
include/linux/msi.h | 2 ++
1 file changed, 2 insertions(+)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:21:04
From: Thomas Gleixner <redacted>
Storing the platform private data in a MSI descriptor is sloppy at
best. The data belongs to the device and not to the descriptor.
Add a pointer to struct msi_device_data and store the pointer there.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/base/platform-msi.c | 79 +++++++++++++++++---------------------------
include/linux/msi.h | 4 +-
2 files changed, 34 insertions(+), 49 deletions(-)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:21:06
From: Thomas Gleixner <redacted>
No more users. Refactor the core code accordingly and move the global
interface under CONFIG_PCI_MSI_ARCH_FALLBACKS.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
include/linux/msi.h | 29 +++++++---------------------
kernel/irq/msi.c | 53 +++++++++++++++++++---------------------------------
2 files changed, 28 insertions(+), 54 deletions(-)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:21:12
From: Thomas Gleixner <redacted>
Set the domain info flag and remove the local sysfs code.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/base/platform-msi.c | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:21:16
From: Thomas Gleixner <redacted>
Set the domain info flag which makes the core code handle sysfs groups and
put an explicit invocation into the legacy code.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/msi/irqdomain.c | 2 +-
drivers/pci/msi/legacy.c | 6 +++++-
drivers/pci/msi/msi.c | 23 -----------------------
include/linux/pci.h | 1 -
4 files changed, 6 insertions(+), 26 deletions(-)
From: Thomas Gleixner <hidden> Date: 2021-12-10 22:21:19
From: Thomas Gleixner <redacted>
Add new allocation functions which can be activated by domain info
flags. They store the groups pointer in struct msi_device_data.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
include/linux/msi.h | 4 ++++
kernel/irq/msi.c | 42 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 44 insertions(+), 2 deletions(-)
On Fri, Dec 10, 2021 at 11:18 PM Thomas Gleixner [off-list ref] wrote:
From: Thomas Gleixner <redacted>
instead of fiddling with MSI descriptors.
Signed-off-by: Thomas Gleixner <redacted>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
On Fri, Dec 10, 2021 at 11:18 PM Thomas Gleixner [off-list ref] wrote:
From: Thomas Gleixner <redacted>
The only unconditional part of MSI data in struct device is the irqdomain
pointer. Everything else can be allocated on demand. Create a data
structure and move the irqdomain pointer into it. The other MSI specific
parts are going to be removed from struct device in later steps.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
On Fri, Dec 10, 2021 at 11:19 PM Thomas Gleixner [off-list ref] wrote:
From: Thomas Gleixner <redacted>
Just use the core function msi_get_virq().
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Cc: Peter Ujfalusi <redacted>
Cc: Vinod Koul <vkoul@kernel.org>
Cc: dmaengine@vger.kernel.org
On Fri, Dec 10, 2021 at 11:19 PM Thomas Gleixner [off-list ref] wrote:
From: Thomas Gleixner <redacted>
Allocate the MSI device data on first invocation of the allocation function.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Cc: Nishanth Menon <nm@ti.com>
Cc: Tero Kristo <kristo@kernel.org>
Cc: Santosh Shilimkar <ssantosh@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
From: Thomas Gleixner <redacted>
Storing a pointer to the MSI descriptor just to keep track of the Linux
interrupt number is daft. Use msi_get_virq() instead.
From: Thomas Gleixner <redacted>
There is no reason to walk the MSI descriptors to retrieve the interrupt
number for a device. Use msi_get_virq() instead.
From: Jason Gunthorpe <jgg@nvidia.com> Date: 2021-12-13 13:37:42
On Fri, Dec 10, 2021 at 11:18:44PM +0100, Thomas Gleixner wrote:
There are quite some places which retrieve the first MSI descriptor to
evaluate whether the setup is for MSI or MSI-X. That's required because
pci_dev::msi[x]_enabled is only set when the setup completed successfully.
There is no real reason why msi[x]_enabled can't be set at the beginning of
the setup sequence and cleared in case of a failure.
Implement that so the MSI descriptor evaluations can be converted to simple
property queries.
Signed-off-by: Thomas Gleixner <redacted>
---
V3: New patch
---
drivers/pci/msi/msi.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Jason
From: Jason Gunthorpe <jgg@nvidia.com> Date: 2021-12-13 13:59:54
On Fri, Dec 10, 2021 at 11:18:49PM +0100, Thomas Gleixner wrote:
From: Thomas Gleixner <redacted>
to determine whether this is MSI or MSIX instead of consulting MSI
descriptors.
Signed-off-by: Thomas Gleixner <redacted>
---
V2: Use PCI device property - Jason
---
kernel/irq/msi.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Jason
From: Jason Gunthorpe <jgg@nvidia.com> Date: 2021-12-13 14:01:27
On Fri, Dec 10, 2021 at 11:18:51PM +0100, Thomas Gleixner wrote:
From: Thomas Gleixner <redacted>
instead of fiddling with MSI descriptors.
Signed-off-by: Thomas Gleixner <redacted>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
V3: Use pci_dev property - Jason
V2: Invoke the function with the correct number of arguments - Andy
---
arch/powerpc/platforms/cell/axon_msi.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Jason
@@ -448,8 +448,7 @@ static int pseries_msi_ops_prepare(strucintnvec,msi_alloc_info_t*arg){structpci_dev*pdev=to_pci_dev(dev);-structmsi_desc*desc=first_pci_msi_entry(pdev);-inttype=desc->pci.msi_attrib.is_msix?PCI_CAP_ID_MSIX:PCI_CAP_ID_MSI;+inttype=pdev->msix_enabled?PCI_CAP_ID_MSIX:PCI_CAP_ID_MSI;
Long term it probably makes sense to change the msi_domain_ops so that
it has PCI versions of the ops to use in places like this that hard
assume PCI is the only kind of MSI at all.
If the non-PCI op isn't provided then things like IMS would be denied
- and the PCI op can directly pass in a pci_dev * so we don't have all
these to_pci_devs() in drivers.
Jason
From: Jason Gunthorpe <jgg@nvidia.com> Date: 2021-12-13 14:06:06
On Fri, Dec 10, 2021 at 11:19:22PM +0100, Thomas Gleixner wrote:
From: Thomas Gleixner <redacted>
Set the domain info flag and remove the check.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: "Cédric Le Goater" <clg@kaod.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
V2: Remove it completely - Cedric
---
arch/powerpc/platforms/pseries/msi.c | 33 ++++++++-------------------------
1 file changed, 8 insertions(+), 25 deletions(-)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Jason
From: Jason Gunthorpe <jgg@nvidia.com> Date: 2021-12-13 14:22:58
On Fri, Dec 10, 2021 at 11:19:23PM +0100, Thomas Gleixner wrote:
From: Thomas Gleixner <redacted>
This allows drivers to retrieve the Linux interrupt number instead of
fiddling with MSI descriptors.
msi_get_virq() returns the Linux interrupt number or 0 in case that there
is no entry for the given MSI index.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
V2: Simplify the implementation and let PCI deal with the PCI specialities - Marc
---
include/linux/msi.h | 2 ++
kernel/irq/msi.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Jason
From: Jason Gunthorpe <jgg@nvidia.com> Date: 2021-12-13 14:23:27
On Fri, Dec 10, 2021 at 11:19:25PM +0100, Thomas Gleixner wrote:
From: Thomas Gleixner <redacted>
Use msi_get_vector() and handle the return value to be compatible.
No functional change intended.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
V2: Handle the INTx case directly instead of trying to be overly smart - Marc
---
drivers/pci/msi/msi.c | 25 +++++--------------------
1 file changed, 5 insertions(+), 20 deletions(-)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Jason
From: Thomas Gleixner <redacted>
Allocate the MSI device data on first invocation of the allocation function.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Cc: Nishanth Menon <nm@ti.com>
Cc: Tero Kristo <kristo@kernel.org>
Cc: Santosh Shilimkar <ssantosh@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
From: Thomas Gleixner <redacted>
Use the common msi_index member and get rid of the pointless wrapper struct.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Cc: Nishanth Menon <nm@ti.com>
Cc: Tero Kristo <kristo@kernel.org>
Cc: Santosh Shilimkar <ssantosh@kernel.org>
Cc: Thomas Gleixner <redacted>
Cc: linux-arm-kernel@lists.infradead.org
From: Thomas Gleixner <redacted>
Just use the core function msi_get_virq().
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Cc: Peter Ujfalusi <redacted>
Cc: Vinod Koul <vkoul@kernel.org>
Cc: dmaengine@vger.kernel.org
From: Thomas Gleixner <hidden> Date: 2021-12-14 09:41:14
On Mon, Dec 13 2021 at 12:29, Nishanth Menon wrote:
On 23:18-20211210, Thomas Gleixner wrote:
Also while testing on TI K3 platforms, I noticed:
msi_device_data_release/msi_device_destroy_sysfs in am64xx-evm / j7200
The warning complains about a device being released with MSI descriptors
still attached to the device. This was added by:
5b012cede0f7 ("device: Add device::msi_data pointer and struct msi_device_data")
That's not a regression caused by this commit. The warning is just
exposing an already existing problem in the iwlwifi driver, which seems
to do:
probe()
setup_pci_msi[x]_interrupts()
start_drv()
if (try_to_load_firmware() == FAIL)
device_release_driver()
...
msi_device_data_release()
WARN()
Thanks,
tglx
On Mon, Dec 13 2021 at 12:29, Nishanth Menon wrote:
quoted
On 23:18-20211210, Thomas Gleixner wrote:
Also while testing on TI K3 platforms, I noticed:
msi_device_data_release/msi_device_destroy_sysfs in am64xx-evm / j7200
The warning complains about a device being released with MSI descriptors
still attached to the device. This was added by:
5b012cede0f7 ("device: Add device::msi_data pointer and struct msi_device_data")
That's not a regression caused by this commit. The warning is just
exposing an already existing problem in the iwlwifi driver, which seems
to do:
probe()
setup_pci_msi[x]_interrupts()
start_drv()
if (try_to_load_firmware() == FAIL)
device_release_driver()
...
msi_device_data_release()
WARN()
Agreed that the warning is fine, the null pointer exception that follows
[1] [2] it however does'nt look right and it can be trivially fixed with the
following fixup for ee90787487bc ("genirq/msi: Provide
msi_device_populate/destroy_sysfs()") below, with that the log looks
like [3] - the warn is good, the null pointer exception and resultant
crash could be avoided (not saying this is the best solution):
From: Thomas Gleixner <hidden> Date: 2021-12-14 16:36:06
On Tue, Dec 14 2021 at 10:22, Nishanth Menon wrote:
On 10:41-20211214, Thomas Gleixner wrote:
Agreed that the warning is fine, the null pointer exception that follows
[1] [2] it however does'nt look right and it can be trivially fixed with the
following fixup for ee90787487bc ("genirq/msi: Provide
msi_device_populate/destroy_sysfs()") below, with that the log looks
like [3] - the warn is good, the null pointer exception and resultant
crash could be avoided (not saying this is the best solution):
Aaargh.
[ 13.478122] Call trace:
[ 13.509042] msi_device_destroy_sysfs+0x18/0x88
[ 13.509058] msi_domain_free_irqs+0x34/0x58
[ 13.509064] pci_msi_teardown_msi_irqs+0x30/0x3c
[ 13.509072] free_msi_irqs+0x78/0xd4
[ 13.509077] pci_disable_msix+0x138/0x164
[ 13.529930] pcim_release+0x70/0x238
[ 13.529942] devres_release_all+0x9c/0xfc
[ 13.529951] device_release_driver_internal+0x1a0/0x244
[ 13.542725] device_release_driver+0x18/0x24
[ 13.542741] iwl_req_fw_callback+0x1a28/0x1ddc [iwlwifi]
[ 13.552308] request_firmware_work_func+0x50/0x9c
[ 13.552320] process_one_work+0x194/0x25c
That's not a driver problem, that's an ordering issue vs. the devres
muck. Let me go back to the drawing board. Sigh...
Thanks,
tglx
From: Thomas Gleixner <hidden> Date: 2021-12-14 17:03:55
On Tue, Dec 14 2021 at 17:36, Thomas Gleixner wrote:
On Tue, Dec 14 2021 at 10:22, Nishanth Menon wrote:
quoted
On 10:41-20211214, Thomas Gleixner wrote:
[ 13.478122] Call trace:
[ 13.509042] msi_device_destroy_sysfs+0x18/0x88
[ 13.509058] msi_domain_free_irqs+0x34/0x58
[ 13.509064] pci_msi_teardown_msi_irqs+0x30/0x3c
[ 13.509072] free_msi_irqs+0x78/0xd4
[ 13.509077] pci_disable_msix+0x138/0x164
[ 13.529930] pcim_release+0x70/0x238
[ 13.529942] devres_release_all+0x9c/0xfc
[ 13.529951] device_release_driver_internal+0x1a0/0x244
[ 13.542725] device_release_driver+0x18/0x24
[ 13.542741] iwl_req_fw_callback+0x1a28/0x1ddc [iwlwifi]
[ 13.552308] request_firmware_work_func+0x50/0x9c
[ 13.552320] process_one_work+0x194/0x25c
That's not a driver problem, that's an ordering issue vs. the devres
muck. Let me go back to the drawing board. Sigh...
Which is pretty obvious why:
pcim_enable_device()
devres_alloc(pcim_release...);
...
pci_irq_alloc()
msi_setup_device_data()
devres_alloc(msi_device_data_release, ...)
and once the device is released:
msi_device_data_release()
...
pcim_release()
pci_disable_msi[x]()
Groan....
I think I managed to distangle this. Can you please give:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git msi-v4-part-2
and/or the full pile:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git msi-v4-part-3
a test ride?
Thanks,
tglx
I think I managed to distangle this. Can you please give:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git msi-v4-part-2
Umm.. I am not entirely sure what is going on.. but all kinds of weird
corruption seems to occur with msi-v4-part-2 that does'nt seem to be
present in v5.16-rc5. (I use NFS since ethernet in K3 platforms use
inta/intr and dma that is impacted by this series).
I will try and rebase your patches on v5.16-rc4 to be sure as well and
report back later today once i get some time.
[1] https://gist.github.com/nmenon/a66e022926c4c15313c45d44313d860c msi-v4-part-2
[2] https://gist.github.com/nmenon/43085664d69ad846d596e76a06ed0656 v5.16-rc5
--
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3 1A34 DDB5 849D 1736 249D
From: Thomas Gleixner <hidden> Date: 2021-12-14 21:20:13
Nishanth,
On Tue, Dec 14 2021 at 14:56, Nishanth Menon wrote:
On 21:15-20211214, Thomas Gleixner wrote:
quoted
I think I managed to distangle this. Can you please give:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git msi-v4-part-2
Umm.. I am not entirely sure what is going on.. but all kinds of weird
corruption seems to occur with msi-v4-part-2 that does'nt seem to be
present in v5.16-rc5. (I use NFS since ethernet in K3 platforms use
inta/intr and dma that is impacted by this series).
I will try and rebase your patches on v5.16-rc4 to be sure as well and
report back later today once i get some time.
[1] https://gist.github.com/nmenon/a66e022926c4c15313c45d44313d860c msi-v4-part-2
[2] https://gist.github.com/nmenon/43085664d69ad846d596e76a06ed0656 v5.16-rc5
thanks for trying. I'll have a look again with brain awake tomorrow
morning.
Thanks,
tglx
From: Thomas Gleixner <hidden> Date: 2021-12-15 16:18:18
On Tue, Dec 14 2021 at 22:19, Thomas Gleixner wrote:
On Tue, Dec 14 2021 at 14:56, Nishanth Menon wrote:
thanks for trying. I'll have a look again with brain awake tomorrow
morning.
Morning was busy with other things, but I found what my sleepy brain
managed to do wrong yesterday evening.
Let me reintegrate the pile and I'll send you an update.
Thanks,
tglx
From: Thomas Gleixner <hidden> Date: 2021-12-15 16:35:51
On Wed, Dec 15 2021 at 17:18, Thomas Gleixner wrote:
On Tue, Dec 14 2021 at 22:19, Thomas Gleixner wrote:
quoted
On Tue, Dec 14 2021 at 14:56, Nishanth Menon wrote:
thanks for trying. I'll have a look again with brain awake tomorrow
morning.
Morning was busy with other things, but I found what my sleepy brain
managed to do wrong yesterday evening.
Let me reintegrate the pile and I'll send you an update.
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git msi-v4.1-part-2
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git msi-v4.2-part-3
That should cure the problem.
From: Thomas Gleixner <hidden> Date: 2021-12-15 17:16:49
The MSI core will introduce runtime allocation of MSI related data. This
data will be devres managed and has to be set up before enabling
PCI/MSI[-X]. This would introduce an ordering issue vs. pcim_release().
The setup order is:
pcim_enable_device()
devres_alloc(pcim_release...);
...
pci_irq_alloc()
msi_setup_device_data()
devres_alloc(msi_device_data_release, ...)
and once the device is released these release functions are invoked in the
opposite order:
msi_device_data_release()
...
pcim_release()
pci_disable_msi[x]()
which is obviously wrong, because pci_disable_msi[x]() requires the MSI
data to be available to tear down the MSI[-X] interrupts.
Remove the MSI[-X] teardown from pcim_release() and add an explicit action
to be installed on the attempt of enabling PCI/MSI[-X].
This allows the MSI core data allocation to be ordered correctly in a
subsequent step.
Reported-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Thomas Gleixner <redacted>
---
V4: New patch
---
drivers/pci/msi/msi.c | 33 +++++++++++++++++++++++++++++++++
drivers/pci/pci.c | 5 -----
include/linux/pci.h | 3 ++-
3 files changed, 35 insertions(+), 6 deletions(-)
From: Thomas Gleixner <hidden> Date: 2021-12-15 17:19:53
Allocate MSI device data on first use, i.e. when a PCI driver invokes one
of the PCI/MSI enablement functions.
Add a wrapper function to ensure that the ordering vs. pcim_msi_release()
is correct.
Signed-off-by: Thomas Gleixner <redacted>
---
V4: Adopted to ensure devres ordering
---
drivers/pci/msi/msi.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
On Wed, Dec 15, 2021 at 06:16:44PM +0100, Thomas Gleixner wrote:
The MSI core will introduce runtime allocation of MSI related data. This
data will be devres managed and has to be set up before enabling
PCI/MSI[-X]. This would introduce an ordering issue vs. pcim_release().
The setup order is:
pcim_enable_device()
devres_alloc(pcim_release...);
...
pci_irq_alloc()
msi_setup_device_data()
devres_alloc(msi_device_data_release, ...)
and once the device is released these release functions are invoked in the
opposite order:
msi_device_data_release()
...
pcim_release()
pci_disable_msi[x]()
which is obviously wrong, because pci_disable_msi[x]() requires the MSI
data to be available to tear down the MSI[-X] interrupts.
Remove the MSI[-X] teardown from pcim_release() and add an explicit action
to be installed on the attempt of enabling PCI/MSI[-X].
This allows the MSI core data allocation to be ordered correctly in a
subsequent step.
Reported-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Thomas Gleixner <redacted>
---
V4: New patch
On Wed, Dec 15, 2021 at 06:19:49PM +0100, Thomas Gleixner wrote:
Allocate MSI device data on first use, i.e. when a PCI driver invokes one
of the PCI/MSI enablement functions.
Add a wrapper function to ensure that the ordering vs. pcim_msi_release()
is correct.
Signed-off-by: Thomas Gleixner <redacted>
As you helped offline, summarizing the details on part3 of the series:
I was seeing failure[1] of NFS(DMA) on all TI K3 platforms:
[ 1.013258] ti-bcdma 485c0100.dma-controller: Number of rings: 68
[ 1.019963] ti-bcdma 485c0100.dma-controller: Failed to allocate IRQs -28
[ 1.026938] ti-bcdma 485c0100.dma-controller: Failed to allocate MSI interrupts
Rationale as you explained:
"
-28 is ENOSPC, which is returned when the interrupt allocation in the
MSI domain fails. Fix below.
"
Which turned out to be the fixup[2] you suggested and I confirm that
fixes the problem for me.
With the fixup in place:
Tested-by: Nishanth Menon <nm@ti.com>
for part 3 of the series as well.
Thanks once again for your help. Hope we can roll in the fixes for
part3.
[1] https://gist.github.com/nmenon/5971ab27aa626c022e276cc946e4b6c3
[2]
From: Michael Kelley (LINUX) <hidden> Date: 2021-12-16 06:14:47
From: Thomas Gleixner <redacted> Sent: Wednesday, December 15, 2021 8:36 AM
On Wed, Dec 15 2021 at 17:18, Thomas Gleixner wrote:
quoted
On Tue, Dec 14 2021 at 22:19, Thomas Gleixner wrote:
quoted
On Tue, Dec 14 2021 at 14:56, Nishanth Menon wrote:
thanks for trying. I'll have a look again with brain awake tomorrow
morning.
Morning was busy with other things, but I found what my sleepy brain
managed to do wrong yesterday evening.
Let me reintegrate the pile and I'll send you an update.
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git msi-v4.1-part-2
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git msi-v4.2-part-3
That should cure the problem.
Tested the msi-v4.2-part-3 tag in two different Azure/Hyper-V VMs. One
is a Generation 1 VM that has legacy PCI devices and one is a Generation 2
VM with no legacy PCI devices. Tested hot add and remove of Mellanox
CX-3 and CX-4 SR-IOV NIC virtual functions that are directly mapped into the
VM. Also tested local NVMe devices directly mapped into one of the VMs.
No issues encountered. So for Azure/Hyper-V specifically,
Tested-by: Michael Kelley <redacted>
Hi Thomas,
On Fri, Dec 10, 2021 at 11:19:26PM +0100, Thomas Gleixner wrote:
From: Thomas Gleixner <redacted>
Replace open coded MSI descriptor chasing and use the proper accessor
functions instead.
Signed-off-by: Thomas Gleixner <redacted>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Apologies if this has already been reported somewhere else or already
fixed, I did a search of all of lore and did not see anything similar to
it and I did not see any new commits in -tip around this.
I just bisected a boot failure on my AMD test desktop to this patch as
commit f48235900182 ("PCI/MSI: Simplify pci_irq_get_affinity()") in
-next. It looks like there is a problem with the NVMe drive after this
change according to the logs. Given that the hard drive is not getting
mounted for journald to write logs to, I am not really sure how to get
them from the machine so I have at least taken a picture of what I see
on my screen; open to ideas on that front!
https://github.com/nathanchance/bug-files/blob/0d25d78b5bc1d5e9c15192b3bc80676364de8287/f48235900182/crash.jpg
Please let me know what information I can provide to make debugging this
easier and I am more than happy to apply and test patches as needed.
Cheers,
Nathan