2021-12-06 22:29:39

by Thomas Gleixner

[permalink] [raw]
Subject: [patch V2 23/23] PCI/MSI: Move descriptor counting on allocation fail to the legacy code

The irqdomain code already returns the information. Move the loop to the
legacy code.

Signed-off-by: Thomas Gleixner <[email protected]>
Tested-by: Juergen Gross <[email protected]>
Reviewed-by: Jason Gunthorpe <[email protected]>
---
drivers/pci/msi/legacy.c | 20 +++++++++++++++++++-
drivers/pci/msi/msi.c | 19 +------------------
2 files changed, 20 insertions(+), 19 deletions(-)

--- a/drivers/pci/msi/legacy.c
+++ b/drivers/pci/msi/legacy.c
@@ -50,9 +50,27 @@ void __weak arch_teardown_msi_irqs(struc
}
}

+static int pci_msi_setup_check_result(struct pci_dev *dev, int type, int ret)
+{
+ struct msi_desc *entry;
+ int avail = 0;
+
+ if (type != PCI_CAP_ID_MSIX || ret >= 0)
+ return ret;
+
+ /* Scan the MSI descriptors for successfully allocated ones. */
+ for_each_pci_msi_entry(entry, dev) {
+ if (entry->irq != 0)
+ avail++;
+ }
+ return avail ? avail : ret;
+}
+
int pci_msi_legacy_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
{
- return arch_setup_msi_irqs(dev, nvec, type);
+ int ret = arch_setup_msi_irqs(dev, nvec, type);
+
+ return pci_msi_setup_check_result(dev, type, ret);
}

void pci_msi_legacy_teardown_msi_irqs(struct pci_dev *dev)
--- a/drivers/pci/msi/msi.c
+++ b/drivers/pci/msi/msi.c
@@ -609,7 +609,7 @@ static int msix_capability_init(struct p

ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);
if (ret)
- goto out_avail;
+ goto out_free;

/* Check if all MSI entries honor device restrictions */
ret = msi_verify_entries(dev);
@@ -634,23 +634,6 @@ static int msix_capability_init(struct p
pcibios_free_irq(dev);
return 0;

-out_avail:
- if (ret < 0) {
- /*
- * If we had some success, report the number of IRQs
- * we succeeded in setting up.
- */
- struct msi_desc *entry;
- int avail = 0;
-
- for_each_pci_msi_entry(entry, dev) {
- if (entry->irq != 0)
- avail++;
- }
- if (avail != 0)
- ret = avail;
- }
-
out_free:
free_msi_irqs(dev);




2021-12-07 07:48:44

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [patch V2 23/23] PCI/MSI: Move descriptor counting on allocation fail to the legacy code

On Mon, Dec 06, 2021 at 11:28:00PM +0100, Thomas Gleixner wrote:
> The irqdomain code already returns the information. Move the loop to the
> legacy code.
>
> Signed-off-by: Thomas Gleixner <[email protected]>
> Tested-by: Juergen Gross <[email protected]>
> Reviewed-by: Jason Gunthorpe <[email protected]>

Reviewed-by: Greg Kroah-Hartman <[email protected]>



2021-12-07 21:02:51

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [patch V2 23/23] PCI/MSI: Move descriptor counting on allocation fail to the legacy code

On Mon, Dec 06, 2021 at 11:28:00PM +0100, Thomas Gleixner wrote:
> The irqdomain code already returns the information. Move the loop to the
> legacy code.
>
> Signed-off-by: Thomas Gleixner <[email protected]>
> Tested-by: Juergen Gross <[email protected]>
> Reviewed-by: Jason Gunthorpe <[email protected]>

Acked-by: Bjorn Helgaas <[email protected]>

> ---
> drivers/pci/msi/legacy.c | 20 +++++++++++++++++++-
> drivers/pci/msi/msi.c | 19 +------------------
> 2 files changed, 20 insertions(+), 19 deletions(-)
>
> --- a/drivers/pci/msi/legacy.c
> +++ b/drivers/pci/msi/legacy.c
> @@ -50,9 +50,27 @@ void __weak arch_teardown_msi_irqs(struc
> }
> }
>
> +static int pci_msi_setup_check_result(struct pci_dev *dev, int type, int ret)
> +{
> + struct msi_desc *entry;
> + int avail = 0;
> +
> + if (type != PCI_CAP_ID_MSIX || ret >= 0)
> + return ret;
> +
> + /* Scan the MSI descriptors for successfully allocated ones. */
> + for_each_pci_msi_entry(entry, dev) {
> + if (entry->irq != 0)
> + avail++;
> + }
> + return avail ? avail : ret;
> +}
> +
> int pci_msi_legacy_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
> {
> - return arch_setup_msi_irqs(dev, nvec, type);
> + int ret = arch_setup_msi_irqs(dev, nvec, type);
> +
> + return pci_msi_setup_check_result(dev, type, ret);
> }
>
> void pci_msi_legacy_teardown_msi_irqs(struct pci_dev *dev)
> --- a/drivers/pci/msi/msi.c
> +++ b/drivers/pci/msi/msi.c
> @@ -609,7 +609,7 @@ static int msix_capability_init(struct p
>
> ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);
> if (ret)
> - goto out_avail;
> + goto out_free;
>
> /* Check if all MSI entries honor device restrictions */
> ret = msi_verify_entries(dev);
> @@ -634,23 +634,6 @@ static int msix_capability_init(struct p
> pcibios_free_irq(dev);
> return 0;
>
> -out_avail:
> - if (ret < 0) {
> - /*
> - * If we had some success, report the number of IRQs
> - * we succeeded in setting up.
> - */
> - struct msi_desc *entry;
> - int avail = 0;
> -
> - for_each_pci_msi_entry(entry, dev) {
> - if (entry->irq != 0)
> - avail++;
> - }
> - if (avail != 0)
> - ret = avail;
> - }
> -
> out_free:
> free_msi_irqs(dev);
>
>

Subject: [tip: irq/msi] PCI/MSI: Move descriptor counting on allocation fail to the legacy code

The following commit has been merged into the irq/msi branch of tip:

Commit-ID: 60bf9b33c82c0e040a98272d7ff4f5a52e7469d6
Gitweb: https://git.kernel.org/tip/60bf9b33c82c0e040a98272d7ff4f5a52e7469d6
Author: Thomas Gleixner <[email protected]>
AuthorDate: Mon, 06 Dec 2021 23:28:00 +01:00
Committer: Thomas Gleixner <[email protected]>
CommitterDate: Thu, 09 Dec 2021 11:52:23 +01:00

PCI/MSI: Move descriptor counting on allocation fail to the legacy code

The irqdomain code already returns the information. Move the loop to the
legacy code.

Signed-off-by: Thomas Gleixner <[email protected]>
Tested-by: Juergen Gross <[email protected]>
Reviewed-by: Jason Gunthorpe <[email protected]>
Reviewed-by: Greg Kroah-Hartman <[email protected]>
Link: https://lore.kernel.org/r/[email protected]

---
drivers/pci/msi/legacy.c | 20 +++++++++++++++++++-
drivers/pci/msi/msi.c | 19 +------------------
2 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/drivers/pci/msi/legacy.c b/drivers/pci/msi/legacy.c
index 023de20..d52cff1 100644
--- a/drivers/pci/msi/legacy.c
+++ b/drivers/pci/msi/legacy.c
@@ -50,9 +50,27 @@ void __weak arch_teardown_msi_irqs(struct pci_dev *dev)
}
}

+static int pci_msi_setup_check_result(struct pci_dev *dev, int type, int ret)
+{
+ struct msi_desc *entry;
+ int avail = 0;
+
+ if (type != PCI_CAP_ID_MSIX || ret >= 0)
+ return ret;
+
+ /* Scan the MSI descriptors for successfully allocated ones. */
+ for_each_pci_msi_entry(entry, dev) {
+ if (entry->irq != 0)
+ avail++;
+ }
+ return avail ? avail : ret;
+}
+
int pci_msi_legacy_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
{
- return arch_setup_msi_irqs(dev, nvec, type);
+ int ret = arch_setup_msi_irqs(dev, nvec, type);
+
+ return pci_msi_setup_check_result(dev, type, ret);
}

void pci_msi_legacy_teardown_msi_irqs(struct pci_dev *dev)
diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c
index 443a16c..8b4d529 100644
--- a/drivers/pci/msi/msi.c
+++ b/drivers/pci/msi/msi.c
@@ -609,7 +609,7 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,

ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);
if (ret)
- goto out_avail;
+ goto out_free;

/* Check if all MSI entries honor device restrictions */
ret = msi_verify_entries(dev);
@@ -634,23 +634,6 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
pcibios_free_irq(dev);
return 0;

-out_avail:
- if (ret < 0) {
- /*
- * If we had some success, report the number of IRQs
- * we succeeded in setting up.
- */
- struct msi_desc *entry;
- int avail = 0;
-
- for_each_pci_msi_entry(entry, dev) {
- if (entry->irq != 0)
- avail++;
- }
- if (avail != 0)
- ret = avail;
- }
-
out_free:
free_msi_irqs(dev);