linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: Denis Efremov <efremov@linux.com>,
	Cornelia Huck <cohuck@redhat.com>,
	kvm@vger.kernel.org, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 7/7] vfio_pci: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END
Date: Mon, 12 Aug 2019 14:52:28 -0600	[thread overview]
Message-ID: <20190812145228.0e194a3b@x1.home> (raw)
In-Reply-To: <20190812200234.GE11785@google.com>

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
> >   


  reply	other threads:[~2019-08-12 20:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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:07 ` [PATCH 2/7] s390/pci: Replace PCI_BAR_COUNT with PCI_STD_NUM_BARS Denis Efremov
2019-08-12 20:02   ` Bjorn Helgaas
2019-08-12 21:06     ` Denis Efremov
2019-08-11 15:07 ` [PATCH 3/7] x86/PCI: Use PCI_STD_NUM_BARS in loops instead of PCI_STD_RESOURCE_END Denis Efremov
2019-08-11 15:08 ` [PATCH 4/7] PCI/net: " Denis Efremov
2019-08-12 20:02   ` Bjorn Helgaas
2019-08-11 15:08 ` [PATCH 5/7] rapidio/tsi721: use " Denis Efremov
2019-08-11 15:08 ` [PATCH 6/7] efifb: Use " Denis Efremov
2019-08-13 12:48   ` Bartlomiej Zolnierkiewicz
2019-08-11 15:08 ` [PATCH 7/7] vfio_pci: " Denis Efremov
2019-08-12 20:02   ` Bjorn Helgaas
2019-08-12 20:52     ` Alex Williamson [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190812145228.0e194a3b@x1.home \
    --to=alex.williamson@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=efremov@linux.com \
    --cc=helgaas@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).