2019-08-11 15:11:05

by Denis Efremov (Oracle)

[permalink] [raw]
Subject: [PATCH 0/7] Add definition for the number of standard PCI BARs

Code that iterates over all standard PCI BARs typically uses
PCI_STD_RESOURCE_END, but this is error-prone because it requires
"i <= PCI_STD_RESOURCE_END" rather than something like
"i < PCI_STD_NUM_BARS". We could add such a definition and use it the same
way PCI_SRIOV_NUM_BARS is used. There is already the definition
PCI_BAR_COUNT for s390 only. Thus, this patchset introduces it globally.

The patch is splitted into 7 parts for different drivers/subsystems for
easy readability.

Denis Efremov (7):
PCI: Add define for the number of standard PCI BARs
s390/pci: Replace PCI_BAR_COUNT with PCI_STD_NUM_BARS
x86/PCI: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
PCI/net: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
rapidio/tsi721: use PCI_STD_NUM_BARS in loops instead of
PCI_STD_RESOURCE_END
efifb: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
vfio_pci: Use PCI_STD_NUM_BARS in loops instead of
PCI_STD_RESOURCE_END

arch/s390/include/asm/pci.h | 5 +----
arch/s390/include/asm/pci_clp.h | 6 +++---
arch/s390/pci/pci.c | 16 ++++++++--------
arch/s390/pci/pci_clp.c | 6 +++---
arch/x86/pci/common.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 4 ++--
drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c | 2 +-
drivers/pci/quirks.c | 2 +-
drivers/rapidio/devices/tsi721.c | 2 +-
drivers/vfio/pci/vfio_pci.c | 4 ++--
drivers/vfio/pci/vfio_pci_config.c | 2 +-
drivers/vfio/pci/vfio_pci_private.h | 4 ++--
drivers/video/fbdev/efifb.c | 2 +-
include/linux/pci.h | 2 +-
include/uapi/linux/pci_regs.h | 1 +
15 files changed, 29 insertions(+), 31 deletions(-)

--
2.21.0


2019-08-11 15:11:05

by Denis Efremov (Oracle)

[permalink] [raw]
Subject: [PATCH 3/7] x86/PCI: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END

This patch refactors the loop condition scheme from
'i <= PCI_STD_RESOURCE_END' to 'i < PCI_STD_NUM_BARS'.

Signed-off-by: Denis Efremov <[email protected]>
---
arch/x86/pci/common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
index 9acab6ac28f5..1e59df041456 100644
--- a/arch/x86/pci/common.c
+++ b/arch/x86/pci/common.c
@@ -135,7 +135,7 @@ static void pcibios_fixup_device_resources(struct pci_dev *dev)
* resource so the kernel doesn't attempt to assign
* it later on in pci_assign_unassigned_resources
*/
- for (bar = 0; bar <= PCI_STD_RESOURCE_END; bar++) {
+ for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
bar_r = &dev->resource[bar];
if (bar_r->start == 0 && bar_r->end != 0) {
bar_r->flags = 0;
--
2.21.0

2019-08-11 15:11:31

by Denis Efremov (Oracle)

[permalink] [raw]
Subject: [PATCH 4/7] PCI/net: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END

This patch refactors the loop condition scheme from
'i <= PCI_STD_RESOURCE_END' to 'i < PCI_STD_NUM_BARS'.

Signed-off-by: Denis Efremov <[email protected]>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 4 ++--
drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
index 86f9c07a38cf..cfe496cdd78b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
@@ -258,7 +258,7 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
}

/* Get the base address of device */
- for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
+ for (i = 0; i < PCI_STD_NUM_BARS; i++) {
if (pci_resource_len(pdev, i) == 0)
continue;
ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
@@ -296,7 +296,7 @@ static void stmmac_pci_remove(struct pci_dev *pdev)

stmmac_dvr_remove(&pdev->dev);

- for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
+ for (i = 0; i < PCI_STD_NUM_BARS; i++) {
if (pci_resource_len(pdev, i) == 0)
continue;
pcim_iounmap_regions(pdev, BIT(i));
diff --git a/drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c b/drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c
index 386bafe74c3f..fa8604d7b797 100644
--- a/drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c
+++ b/drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c
@@ -34,7 +34,7 @@ static int xlgmac_probe(struct pci_dev *pcidev, const struct pci_device_id *id)
return ret;
}

- for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
+ for (i = 0; i < PCI_STD_NUM_BARS; i++) {
if (pci_resource_len(pcidev, i) == 0)
continue;
ret = pcim_iomap_regions(pcidev, BIT(i), XLGMAC_DRV_NAME);
--
2.21.0

2019-08-11 15:12:14

by Denis Efremov (Oracle)

[permalink] [raw]
Subject: [PATCH 5/7] rapidio/tsi721: use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END

This patch refactors the loop condition scheme from
'i <= PCI_STD_RESOURCE_END' to 'i < PCI_STD_NUM_BARS'.

Signed-off-by: Denis Efremov <[email protected]>
---
drivers/rapidio/devices/tsi721.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rapidio/devices/tsi721.c b/drivers/rapidio/devices/tsi721.c
index 125a173bed45..4dd31dd9feea 100644
--- a/drivers/rapidio/devices/tsi721.c
+++ b/drivers/rapidio/devices/tsi721.c
@@ -2755,7 +2755,7 @@ static int tsi721_probe(struct pci_dev *pdev,
{
int i;

- for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
+ for (i = 0; i < PCI_STD_NUM_BARS; i++) {
tsi_debug(INIT, &pdev->dev, "res%d %pR",
i, &pdev->resource[i]);
}
--
2.21.0

2019-08-11 15:12:45

by Denis Efremov (Oracle)

[permalink] [raw]
Subject: [PATCH 6/7] efifb: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END

This patch refactors the loop condition scheme from
'i <= PCI_STD_RESOURCE_END' to 'i < PCI_STD_NUM_BARS'.

Signed-off-by: Denis Efremov <[email protected]>
---
drivers/video/fbdev/efifb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
index 04a22663b4fb..6c72b825e92a 100644
--- a/drivers/video/fbdev/efifb.c
+++ b/drivers/video/fbdev/efifb.c
@@ -668,7 +668,7 @@ static void efifb_fixup_resources(struct pci_dev *dev)
if (!base)
return;

- for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
+ for (i = 0; i < PCI_STD_NUM_BARS; i++) {
struct resource *res = &dev->resource[i];

if (!(res->flags & IORESOURCE_MEM))
--
2.21.0

2019-08-11 15:14:26

by Denis Efremov (Oracle)

[permalink] [raw]
Subject: [PATCH 7/7] vfio_pci: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END

This patch refactors the loop condition scheme from
'i <= PCI_STD_RESOURCE_END' to 'i < PCI_STD_NUM_BARS'.

Signed-off-by: Denis Efremov <[email protected]>
---
drivers/vfio/pci/vfio_pci.c | 4 ++--
drivers/vfio/pci/vfio_pci_config.c | 2 +-
drivers/vfio/pci/vfio_pci_private.h | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index 703948c9fbe1..13f5430e3f3c 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -115,7 +115,7 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_device *vdev)

INIT_LIST_HEAD(&vdev->dummy_resources_list);

- for (bar = PCI_STD_RESOURCES; bar <= PCI_STD_RESOURCE_END; bar++) {
+ for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
res = vdev->pdev->resource + bar;

if (!IS_ENABLED(CONFIG_VFIO_PCI_MMAP))
@@ -399,7 +399,7 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev)

vfio_config_free(vdev);

- for (bar = PCI_STD_RESOURCES; bar <= PCI_STD_RESOURCE_END; bar++) {
+ for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
if (!vdev->barmap[bar])
continue;
pci_iounmap(pdev, vdev->barmap[bar]);
diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
index f0891bd8444c..6035a2961160 100644
--- a/drivers/vfio/pci/vfio_pci_config.c
+++ b/drivers/vfio/pci/vfio_pci_config.c
@@ -455,7 +455,7 @@ static void vfio_bar_fixup(struct vfio_pci_device *vdev)

bar = (__le32 *)&vdev->vconfig[PCI_BASE_ADDRESS_0];

- for (i = PCI_STD_RESOURCES; i <= PCI_STD_RESOURCE_END; i++, bar++) {
+ for (i = 0; i < PCI_STD_NUM_BARS; i++, bar++) {
if (!pci_resource_start(pdev, i)) {
*bar = 0; /* Unmapped by host = unimplemented to user */
continue;
diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h
index ee6ee91718a4..8a2c7607d513 100644
--- a/drivers/vfio/pci/vfio_pci_private.h
+++ b/drivers/vfio/pci/vfio_pci_private.h
@@ -86,8 +86,8 @@ struct vfio_pci_reflck {

struct vfio_pci_device {
struct pci_dev *pdev;
- void __iomem *barmap[PCI_STD_RESOURCE_END + 1];
- bool bar_mmap_supported[PCI_STD_RESOURCE_END + 1];
+ void __iomem *barmap[PCI_STD_NUM_BARS];
+ bool bar_mmap_supported[PCI_STD_NUM_BARS];
u8 *pci_config_map;
u8 *vconfig;
struct perm_bits *msi_perm;
--
2.21.0

2019-08-12 09:07:42

by Andrew Murray

[permalink] [raw]
Subject: Re: [PATCH 0/7] Add definition for the number of standard PCI BARs

On Sun, Aug 11, 2019 at 06:07:55PM +0300, Denis Efremov wrote:
> Code that iterates over all standard PCI BARs typically uses
> PCI_STD_RESOURCE_END, but this is error-prone because it requires
> "i <= PCI_STD_RESOURCE_END" rather than something like
> "i < PCI_STD_NUM_BARS". We could add such a definition and use it the same
> way PCI_SRIOV_NUM_BARS is used. There is already the definition
> PCI_BAR_COUNT for s390 only. Thus, this patchset introduces it globally.
>
> The patch is splitted into 7 parts for different drivers/subsystems for
> easy readability.
>
> Denis Efremov (7):
> PCI: Add define for the number of standard PCI BARs
> s390/pci: Replace PCI_BAR_COUNT with PCI_STD_NUM_BARS
> x86/PCI: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
> PCI/net: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
> rapidio/tsi721: use PCI_STD_NUM_BARS in loops instead of
> PCI_STD_RESOURCE_END
> efifb: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
> vfio_pci: Use PCI_STD_NUM_BARS in loops instead of
> PCI_STD_RESOURCE_END
>
> arch/s390/include/asm/pci.h | 5 +----
> arch/s390/include/asm/pci_clp.h | 6 +++---
> arch/s390/pci/pci.c | 16 ++++++++--------
> arch/s390/pci/pci_clp.c | 6 +++---
> arch/x86/pci/common.c | 2 +-
> drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 4 ++--
> drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c | 2 +-
> drivers/pci/quirks.c | 2 +-
> drivers/rapidio/devices/tsi721.c | 2 +-
> drivers/vfio/pci/vfio_pci.c | 4 ++--
> drivers/vfio/pci/vfio_pci_config.c | 2 +-
> drivers/vfio/pci/vfio_pci_private.h | 4 ++--
> drivers/video/fbdev/efifb.c | 2 +-
> include/linux/pci.h | 2 +-
> include/uapi/linux/pci_regs.h | 1 +

Hi Denis,

You could also fix up a few cases where the number of BARs is hard coded in
loops, e.g.

drivers/pci/controller/pci-hyperv.c - look for uses of probed_bar in loops
drivers/pci/pci.c - pci_release_selected_regions and __pci_request_selected_regions
drivers/pci/quirks.c - quirk_alder_ioapic

Thanks,

Andrew Murray

> 15 files changed, 29 insertions(+), 31 deletions(-)
>
> --
> 2.21.0
>

2019-08-12 20:05:33

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH 7/7] vfio_pci: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END

On Sun, Aug 11, 2019 at 06:08:04PM +0300, Denis Efremov wrote:
> This patch refactors the loop condition scheme from
> 'i <= PCI_STD_RESOURCE_END' to 'i < PCI_STD_NUM_BARS'.
>
> Signed-off-by: Denis Efremov <[email protected]>
> ---
> drivers/vfio/pci/vfio_pci.c | 4 ++--
> drivers/vfio/pci/vfio_pci_config.c | 2 +-
> drivers/vfio/pci/vfio_pci_private.h | 4 ++--
> 3 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index 703948c9fbe1..13f5430e3f3c 100644
> --- a/drivers/vfio/pci/vfio_pci.c
> +++ b/drivers/vfio/pci/vfio_pci.c
> @@ -115,7 +115,7 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_device *vdev)
>
> INIT_LIST_HEAD(&vdev->dummy_resources_list);
>
> - for (bar = PCI_STD_RESOURCES; bar <= PCI_STD_RESOURCE_END; bar++) {
> + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
> res = vdev->pdev->resource + bar;

PCI_STD_RESOURCES is indeed 0, but since the original went to the
trouble of avoiding that assumption, I would probably do this:

for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
res = vdev->pdev->resource + bar + PCI_STD_RESOURCES;

or maybe even this:

res = &vdev->pdev->resource[bar + PCI_STD_RESOURCES];

which is more common outside vfio. But I wouldn't change to using the
&dev->resource[] form if other vfio code that you're *not* changing
uses the dev->resource + bar form.

> if (!IS_ENABLED(CONFIG_VFIO_PCI_MMAP))
> @@ -399,7 +399,7 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev)
>
> vfio_config_free(vdev);
>
> - for (bar = PCI_STD_RESOURCES; bar <= PCI_STD_RESOURCE_END; bar++) {
> + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
> if (!vdev->barmap[bar])
> continue;
> pci_iounmap(pdev, vdev->barmap[bar]);
> diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> index f0891bd8444c..6035a2961160 100644
> --- a/drivers/vfio/pci/vfio_pci_config.c
> +++ b/drivers/vfio/pci/vfio_pci_config.c
> @@ -455,7 +455,7 @@ static void vfio_bar_fixup(struct vfio_pci_device *vdev)
>
> bar = (__le32 *)&vdev->vconfig[PCI_BASE_ADDRESS_0];
>
> - for (i = PCI_STD_RESOURCES; i <= PCI_STD_RESOURCE_END; i++, bar++) {
> + for (i = 0; i < PCI_STD_NUM_BARS; i++, bar++) {
> if (!pci_resource_start(pdev, i)) {
> *bar = 0; /* Unmapped by host = unimplemented to user */
> continue;
> diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h
> index ee6ee91718a4..8a2c7607d513 100644
> --- a/drivers/vfio/pci/vfio_pci_private.h
> +++ b/drivers/vfio/pci/vfio_pci_private.h
> @@ -86,8 +86,8 @@ struct vfio_pci_reflck {
>
> struct vfio_pci_device {
> struct pci_dev *pdev;
> - void __iomem *barmap[PCI_STD_RESOURCE_END + 1];
> - bool bar_mmap_supported[PCI_STD_RESOURCE_END + 1];
> + void __iomem *barmap[PCI_STD_NUM_BARS];
> + bool bar_mmap_supported[PCI_STD_NUM_BARS];
> u8 *pci_config_map;
> u8 *vconfig;
> struct perm_bits *msi_perm;
> --
> 2.21.0
>

2019-08-12 20:12:32

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH 0/7] Add definition for the number of standard PCI BARs

On Mon, 12 Aug 2019, Bjorn Helgaas wrote:

> On Sun, Aug 11, 2019 at 06:07:55PM +0300, Denis Efremov wrote:
> > Code that iterates over all standard PCI BARs typically uses
> > PCI_STD_RESOURCE_END, but this is error-prone because it requires
> > "i <= PCI_STD_RESOURCE_END" rather than something like
> > "i < PCI_STD_NUM_BARS". We could add such a definition and use it the same
> > way PCI_SRIOV_NUM_BARS is used. There is already the definition
> > PCI_BAR_COUNT for s390 only. Thus, this patchset introduces it globally.
> >
> > The patch is splitted into 7 parts for different drivers/subsystems for
> > easy readability.
>
> This looks good. I can take all these together, since they all depend
> on the first patch. I have a few comments on the individual patches.
>
> > Denis Efremov (7):
> > PCI: Add define for the number of standard PCI BARs
> > s390/pci: Replace PCI_BAR_COUNT with PCI_STD_NUM_BARS
> > x86/PCI: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END

Fine with me for the x86 part. That's your turf anyway :)

Thanks,

tglx

2019-08-12 20:55:09

by Alex Williamson

[permalink] [raw]
Subject: Re: [PATCH 7/7] vfio_pci: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END

On Mon, 12 Aug 2019 15:02:34 -0500
Bjorn Helgaas <[email protected]> wrote:

> On Sun, Aug 11, 2019 at 06:08:04PM +0300, Denis Efremov wrote:
> > This patch refactors the loop condition scheme from
> > 'i <= PCI_STD_RESOURCE_END' to 'i < PCI_STD_NUM_BARS'.
> >
> > Signed-off-by: Denis Efremov <[email protected]>
> > ---
> > drivers/vfio/pci/vfio_pci.c | 4 ++--
> > drivers/vfio/pci/vfio_pci_config.c | 2 +-
> > drivers/vfio/pci/vfio_pci_private.h | 4 ++--
> > 3 files changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> > index 703948c9fbe1..13f5430e3f3c 100644
> > --- a/drivers/vfio/pci/vfio_pci.c
> > +++ b/drivers/vfio/pci/vfio_pci.c
> > @@ -115,7 +115,7 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_device *vdev)
> >
> > INIT_LIST_HEAD(&vdev->dummy_resources_list);
> >
> > - for (bar = PCI_STD_RESOURCES; bar <= PCI_STD_RESOURCE_END; bar++) {
> > + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
> > res = vdev->pdev->resource + bar;
>
> PCI_STD_RESOURCES is indeed 0, but since the original went to the
> trouble of avoiding that assumption, I would probably do this:
>
> for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
> res = vdev->pdev->resource + bar + PCI_STD_RESOURCES;
>
> or maybe even this:
>
> res = &vdev->pdev->resource[bar + PCI_STD_RESOURCES];
>
> which is more common outside vfio. But I wouldn't change to using the
> &dev->resource[] form if other vfio code that you're *not* changing
> uses the dev->resource + bar form.

I don't think we have any other instances like that, so the latter form
is fine with me if it's more broadly used. I do spot one use of [bar]
in drivers/vfio/pci/vfio_pci_rdwr.c that could also take on this form
to void the same assumption though. Thanks,

Alex

> > if (!IS_ENABLED(CONFIG_VFIO_PCI_MMAP))
> > @@ -399,7 +399,7 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev)
> >
> > vfio_config_free(vdev);
> >
> > - for (bar = PCI_STD_RESOURCES; bar <= PCI_STD_RESOURCE_END; bar++) {
> > + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
> > if (!vdev->barmap[bar])
> > continue;
> > pci_iounmap(pdev, vdev->barmap[bar]);
> > diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> > index f0891bd8444c..6035a2961160 100644
> > --- a/drivers/vfio/pci/vfio_pci_config.c
> > +++ b/drivers/vfio/pci/vfio_pci_config.c
> > @@ -455,7 +455,7 @@ static void vfio_bar_fixup(struct vfio_pci_device *vdev)
> >
> > bar = (__le32 *)&vdev->vconfig[PCI_BASE_ADDRESS_0];
> >
> > - for (i = PCI_STD_RESOURCES; i <= PCI_STD_RESOURCE_END; i++, bar++) {
> > + for (i = 0; i < PCI_STD_NUM_BARS; i++, bar++) {
> > if (!pci_resource_start(pdev, i)) {
> > *bar = 0; /* Unmapped by host = unimplemented to user */
> > continue;
> > diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h
> > index ee6ee91718a4..8a2c7607d513 100644
> > --- a/drivers/vfio/pci/vfio_pci_private.h
> > +++ b/drivers/vfio/pci/vfio_pci_private.h
> > @@ -86,8 +86,8 @@ struct vfio_pci_reflck {
> >
> > struct vfio_pci_device {
> > struct pci_dev *pdev;
> > - void __iomem *barmap[PCI_STD_RESOURCE_END + 1];
> > - bool bar_mmap_supported[PCI_STD_RESOURCE_END + 1];
> > + void __iomem *barmap[PCI_STD_NUM_BARS];
> > + bool bar_mmap_supported[PCI_STD_NUM_BARS];
> > u8 *pci_config_map;
> > u8 *vconfig;
> > struct perm_bits *msi_perm;
> > --
> > 2.21.0
> >

2019-08-12 21:34:05

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH 0/7] Add definition for the number of standard PCI BARs

On Sun, Aug 11, 2019 at 06:07:55PM +0300, Denis Efremov wrote:
> Code that iterates over all standard PCI BARs typically uses
> PCI_STD_RESOURCE_END, but this is error-prone because it requires
> "i <= PCI_STD_RESOURCE_END" rather than something like
> "i < PCI_STD_NUM_BARS". We could add such a definition and use it the same
> way PCI_SRIOV_NUM_BARS is used. There is already the definition
> PCI_BAR_COUNT for s390 only. Thus, this patchset introduces it globally.
>
> The patch is splitted into 7 parts for different drivers/subsystems for
> easy readability.

This looks good. I can take all these together, since they all depend
on the first patch. I have a few comments on the individual patches.

> Denis Efremov (7):
> PCI: Add define for the number of standard PCI BARs
> s390/pci: Replace PCI_BAR_COUNT with PCI_STD_NUM_BARS
> x86/PCI: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
> PCI/net: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
> rapidio/tsi721: use PCI_STD_NUM_BARS in loops instead of
> PCI_STD_RESOURCE_END
> efifb: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
> vfio_pci: Use PCI_STD_NUM_BARS in loops instead of
> PCI_STD_RESOURCE_END
>
> arch/s390/include/asm/pci.h | 5 +----
> arch/s390/include/asm/pci_clp.h | 6 +++---
> arch/s390/pci/pci.c | 16 ++++++++--------
> arch/s390/pci/pci_clp.c | 6 +++---
> arch/x86/pci/common.c | 2 +-
> drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 4 ++--
> drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c | 2 +-
> drivers/pci/quirks.c | 2 +-
> drivers/rapidio/devices/tsi721.c | 2 +-
> drivers/vfio/pci/vfio_pci.c | 4 ++--
> drivers/vfio/pci/vfio_pci_config.c | 2 +-
> drivers/vfio/pci/vfio_pci_private.h | 4 ++--
> drivers/video/fbdev/efifb.c | 2 +-
> include/linux/pci.h | 2 +-
> include/uapi/linux/pci_regs.h | 1 +
> 15 files changed, 29 insertions(+), 31 deletions(-)
>
> --
> 2.21.0
>

2019-08-12 21:34:12

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH 4/7] PCI/net: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END

The subject can be simply:

<prefix>: Loop using PCI_STD_NUM_BARS

to keep them a little shorter so "git log --online" doesn't wrap.

On Sun, Aug 11, 2019 at 06:08:00PM +0300, Denis Efremov wrote:
> This patch refactors the loop condition scheme from
> 'i <= PCI_STD_RESOURCE_END' to 'i < PCI_STD_NUM_BARS'.

Refactor loops to use 'i < PCI_STD_NUM_BARS' instead of 'i <=
PCI_STD_RESOURCE_END'.

See https://chris.beams.io/posts/git-commit/

> Signed-off-by: Denis Efremov <[email protected]>
> ---
> drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 4 ++--
> drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)

This patch touches two unrelated drivers and should be split up.
When you do that, pay attention to the convention for commit log
prefixes, e.g.,

$ git log --oneline drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
37e9c087c814 stmmac: pci: Fix typo in IOT2000 comment
d4a62ea411f9 stmmac: pci: Use pci_dev_id() helper
e0c1d14a1a32 stmmac: pci: Adjust IOT2000 matching

$ git log --oneline drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c
ea8c1c642ea5 net: dwc-xlgmac: declaration of dual license in headers
65e0ace2c5cd net: dwc-xlgmac: Initial driver for DesignWare Enterprise Ethernet

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
> index 86f9c07a38cf..cfe496cdd78b 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
> @@ -258,7 +258,7 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
> }
>
> /* Get the base address of device */
> - for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
> + for (i = 0; i < PCI_STD_NUM_BARS; i++) {
> if (pci_resource_len(pdev, i) == 0)
> continue;
> ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
> @@ -296,7 +296,7 @@ static void stmmac_pci_remove(struct pci_dev *pdev)
>
> stmmac_dvr_remove(&pdev->dev);
>
> - for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
> + for (i = 0; i < PCI_STD_NUM_BARS; i++) {
> if (pci_resource_len(pdev, i) == 0)
> continue;
> pcim_iounmap_regions(pdev, BIT(i));
> diff --git a/drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c b/drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c
> index 386bafe74c3f..fa8604d7b797 100644
> --- a/drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c
> +++ b/drivers/net/ethernet/synopsys/dwc-xlgmac-pci.c
> @@ -34,7 +34,7 @@ static int xlgmac_probe(struct pci_dev *pcidev, const struct pci_device_id *id)
> return ret;
> }
>
> - for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
> + for (i = 0; i < PCI_STD_NUM_BARS; i++) {
> if (pci_resource_len(pcidev, i) == 0)
> continue;
> ret = pcim_iomap_regions(pcidev, BIT(i), XLGMAC_DRV_NAME);
> --
> 2.21.0
>

2019-08-12 21:36:56

by Denis Efremov (Oracle)

[permalink] [raw]
Subject: Re: [PATCH 0/7] Add definition for the number of standard PCI BARs

On 12.08.2019 12:06, Andrew Murray wrote:
>
> Hi Denis,

Hi!

>
> You could also fix up a few cases where the number of BARs is hard coded in
> loops, e.g.
>
> drivers/pci/controller/pci-hyperv.c - look for uses of probed_bar in loops
> drivers/pci/pci.c - pci_release_selected_regions and __pci_request_selected_regions
> drivers/pci/quirks.c - quirk_alder_ioapic
>

Thanks for pointing me on that. I will take this into account in v2.

Denis

Subject: Re: [PATCH 6/7] efifb: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END


On 8/11/19 5:08 PM, Denis Efremov wrote:
> This patch refactors the loop condition scheme from
> 'i <= PCI_STD_RESOURCE_END' to 'i < PCI_STD_NUM_BARS'.
>
> Signed-off-by: Denis Efremov <[email protected]>

Acked-by: Bartlomiej Zolnierkiewicz <[email protected]>

> ---
> drivers/video/fbdev/efifb.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
> index 04a22663b4fb..6c72b825e92a 100644
> --- a/drivers/video/fbdev/efifb.c
> +++ b/drivers/video/fbdev/efifb.c
> @@ -668,7 +668,7 @@ static void efifb_fixup_resources(struct pci_dev *dev)
> if (!base)
> return;
>
> - for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
> + for (i = 0; i < PCI_STD_NUM_BARS; i++) {
> struct resource *res = &dev->resource[i];
>
> if (!(res->flags & IORESOURCE_MEM))

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics