KVM Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/7] Add definition for the number of standard PCI BARs
@ 2019-08-11 15:07 Denis Efremov
  2019-08-11 15:07 ` [PATCH 1/7] PCI: Add define " Denis Efremov
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Denis Efremov @ 2019-08-11 15:07 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Denis Efremov, Sebastian Ott, Gerald Schaefer, H. Peter Anvin,
	Giuseppe Cavallaro, Alexandre Torgue, Matt Porter,
	Alexandre Bounine, Peter Jones, Bartlomiej Zolnierkiewicz,
	Cornelia Huck, Alex Williamson, kvm, linux-fbdev, netdev, x86,
	linux-s390, linux-pci, linux-kernel

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/7] PCI: Add define for the number of standard PCI BARs
  2019-08-11 15:07 [PATCH 0/7] Add definition for the number of standard PCI BARs Denis Efremov
@ 2019-08-11 15:07 ` " Denis Efremov
  2019-08-11 15:08 ` [PATCH 7/7] vfio_pci: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END Denis Efremov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Denis Efremov @ 2019-08-11 15:07 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Denis Efremov, Sebastian Ott, Gerald Schaefer, H. Peter Anvin,
	Giuseppe Cavallaro, Alexandre Torgue, Matt Porter,
	Alexandre Bounine, Peter Jones, Bartlomiej Zolnierkiewicz,
	Cornelia Huck, Alex Williamson, kvm, linux-fbdev, netdev, x86,
	linux-s390, linux-pci, linux-kernel

Code that iterates over all standard PCI BARs typically uses
PCI_STD_RESOURCE_END. However, it requires the "unusual" loop condition
"i <= PCI_STD_RESOURCE_END" rather than something more standard like
"i < PCI_STD_NUM_BARS".

This patch adds the definition PCI_STD_NUM_BARS which is equivalent to
"PCI_STD_RESOURCE_END + 1" and updates loop conditions to use it.

Signed-off-by: Denis Efremov <efremov@linux.com>
---
 drivers/pci/quirks.c          | 2 +-
 include/linux/pci.h           | 2 +-
 include/uapi/linux/pci_regs.h | 1 +
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 208aacf39329..02bdf3a0231e 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -475,7 +475,7 @@ static void quirk_extend_bar_to_page(struct pci_dev *dev)
 {
 	int i;
 
-	for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
+	for (i = 0; i < PCI_STD_NUM_BARS; i++) {
 		struct resource *r = &dev->resource[i];
 
 		if (r->flags & IORESOURCE_MEM && resource_size(r) < PAGE_SIZE) {
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 9e700d9f9f28..7b9590d5dc2d 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -76,7 +76,7 @@ enum pci_mmap_state {
 enum {
 	/* #0-5: standard PCI resources */
 	PCI_STD_RESOURCES,
-	PCI_STD_RESOURCE_END = 5,
+	PCI_STD_RESOURCE_END = PCI_STD_RESOURCES + PCI_STD_NUM_BARS - 1,
 
 	/* #6: expansion ROM resource */
 	PCI_ROM_RESOURCE,
diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
index f28e562d7ca8..68b571d491eb 100644
--- a/include/uapi/linux/pci_regs.h
+++ b/include/uapi/linux/pci_regs.h
@@ -34,6 +34,7 @@
  * of which the first 64 bytes are standardized as follows:
  */
 #define PCI_STD_HEADER_SIZEOF	64
+#define PCI_STD_NUM_BARS	6	/* Number of standard BARs */
 #define PCI_VENDOR_ID		0x00	/* 16 bits */
 #define PCI_DEVICE_ID		0x02	/* 16 bits */
 #define PCI_COMMAND		0x04	/* 16 bits */
-- 
2.21.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 7/7] vfio_pci: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
  2019-08-11 15:07 [PATCH 0/7] Add definition for the number of standard PCI BARs Denis Efremov
  2019-08-11 15:07 ` [PATCH 1/7] PCI: Add define " Denis Efremov
@ 2019-08-11 15:08 ` Denis Efremov
  2019-08-12 20:02   ` Bjorn Helgaas
  2019-08-12  9:06 ` [PATCH 0/7] Add definition for the number of standard PCI BARs Andrew Murray
  2019-08-12 20:01 ` Bjorn Helgaas
  3 siblings, 1 reply; 9+ messages in thread
From: Denis Efremov @ 2019-08-11 15:08 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Denis Efremov, Cornelia Huck, Alex Williamson, kvm, linux-pci,
	linux-kernel

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

Signed-off-by: Denis Efremov <efremov@linux.com>
---
 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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/7] Add definition for the number of standard PCI BARs
  2019-08-11 15:07 [PATCH 0/7] Add definition for the number of standard PCI BARs Denis Efremov
  2019-08-11 15:07 ` [PATCH 1/7] PCI: Add define " Denis Efremov
  2019-08-11 15:08 ` [PATCH 7/7] vfio_pci: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END Denis Efremov
@ 2019-08-12  9:06 ` Andrew Murray
  2019-08-12 21:00   ` Denis Efremov
  2019-08-12 20:01 ` Bjorn Helgaas
  3 siblings, 1 reply; 9+ messages in thread
From: Andrew Murray @ 2019-08-12  9:06 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Bjorn Helgaas, Sebastian Ott, Gerald Schaefer, H. Peter Anvin,
	Giuseppe Cavallaro, Alexandre Torgue, Matt Porter,
	Alexandre Bounine, Peter Jones, Bartlomiej Zolnierkiewicz,
	Cornelia Huck, Alex Williamson, kvm, linux-fbdev, netdev, x86,
	linux-s390, linux-pci, linux-kernel

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
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/7] Add definition for the number of standard PCI BARs
  2019-08-11 15:07 [PATCH 0/7] Add definition for the number of standard PCI BARs Denis Efremov
                   ` (2 preceding siblings ...)
  2019-08-12  9:06 ` [PATCH 0/7] Add definition for the number of standard PCI BARs Andrew Murray
@ 2019-08-12 20:01 ` Bjorn Helgaas
  2019-08-12 20:11   ` Thomas Gleixner
  3 siblings, 1 reply; 9+ messages in thread
From: Bjorn Helgaas @ 2019-08-12 20:01 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Sebastian Ott, Gerald Schaefer, H. Peter Anvin,
	Giuseppe Cavallaro, Alexandre Torgue, Matt Porter,
	Alexandre Bounine, Peter Jones, Bartlomiej Zolnierkiewicz,
	Cornelia Huck, Alex Williamson, kvm, linux-fbdev, netdev, x86,
	linux-s390, linux-pci, linux-kernel

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
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 7/7] vfio_pci: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
  2019-08-11 15:08 ` [PATCH 7/7] vfio_pci: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END Denis Efremov
@ 2019-08-12 20:02   ` Bjorn Helgaas
  2019-08-12 20:52     ` Alex Williamson
  0 siblings, 1 reply; 9+ messages in thread
From: Bjorn Helgaas @ 2019-08-12 20:02 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Cornelia Huck, Alex Williamson, kvm, linux-pci, linux-kernel

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 <efremov@linux.com>
> ---
>  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
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/7] Add definition for the number of standard PCI BARs
  2019-08-12 20:01 ` Bjorn Helgaas
@ 2019-08-12 20:11   ` Thomas Gleixner
  0 siblings, 0 replies; 9+ messages in thread
From: Thomas Gleixner @ 2019-08-12 20:11 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Denis Efremov, Sebastian Ott, Gerald Schaefer, H. Peter Anvin,
	Giuseppe Cavallaro, Alexandre Torgue, Matt Porter,
	Alexandre Bounine, Peter Jones, Bartlomiej Zolnierkiewicz,
	Cornelia Huck, Alex Williamson, kvm, linux-fbdev, netdev, x86,
	linux-s390, linux-pci, linux-kernel

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 7/7] vfio_pci: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
  2019-08-12 20:02   ` Bjorn Helgaas
@ 2019-08-12 20:52     ` Alex Williamson
  0 siblings, 0 replies; 9+ messages in thread
From: Alex Williamson @ 2019-08-12 20:52 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: Denis Efremov, Cornelia Huck, kvm, linux-pci, linux-kernel

On Mon, 12 Aug 2019 15:02:34 -0500
Bjorn Helgaas <helgaas@kernel.org> 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 <efremov@linux.com>
> > ---
> >  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
> >   


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/7] Add definition for the number of standard PCI BARs
  2019-08-12  9:06 ` [PATCH 0/7] Add definition for the number of standard PCI BARs Andrew Murray
@ 2019-08-12 21:00   ` Denis Efremov
  0 siblings, 0 replies; 9+ messages in thread
From: Denis Efremov @ 2019-08-12 21:00 UTC (permalink / raw)
  To: Andrew Murray
  Cc: Bjorn Helgaas, Sebastian Ott, Gerald Schaefer, H. Peter Anvin,
	Giuseppe Cavallaro, Alexandre Torgue, Matt Porter,
	Alexandre Bounine, Peter Jones, Bartlomiej Zolnierkiewicz,
	Cornelia Huck, Alex Williamson, kvm, linux-fbdev, netdev, x86,
	linux-s390, linux-pci, linux-kernel

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-11 15:07 [PATCH 0/7] Add definition for the number of standard PCI BARs Denis Efremov
2019-08-11 15:07 ` [PATCH 1/7] PCI: Add define " Denis Efremov
2019-08-11 15:08 ` [PATCH 7/7] vfio_pci: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END Denis Efremov
2019-08-12 20:02   ` Bjorn Helgaas
2019-08-12 20:52     ` Alex Williamson
2019-08-12  9:06 ` [PATCH 0/7] Add definition for the number of standard PCI BARs Andrew Murray
2019-08-12 21:00   ` Denis Efremov
2019-08-12 20:01 ` Bjorn Helgaas
2019-08-12 20:11   ` Thomas Gleixner

KVM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kvm/0 kvm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kvm kvm/ https://lore.kernel.org/kvm \
		kvm@vger.kernel.org kvm@archiver.kernel.org
	public-inbox-index kvm


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.kvm


AGPL code for this site: git clone https://public-inbox.org/ public-inbox