All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: Jiang Liu <liuj97@gmail.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	Jiang Liu <jiang.liu@huawei.com>,
	"Rafael J . Wysocki" <rjw@sisk.pl>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Gu Zheng <guz.fnst@cn.fujitsu.com>,
	Toshi Kani <toshi.kani@hp.com>,
	Myron Stowe <myron.stowe@redhat.com>,
	Yijing Wang <wangyijing@huawei.com>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Donald Dutile <ddutile@redhat.com>, Ram Pai <linuxram@us.ibm.com>
Subject: Re: [PATCH v3, part1 09/10] PCI, IOV: simplify IOV implementation
Date: Mon, 27 May 2013 19:00:26 -0700	[thread overview]
Message-ID: <CAE9FiQX-3=U7YpEnRsL46Kn0Dyvk_+A1NC7UYijHe91KWjrKDA@mail.gmail.com> (raw)
In-Reply-To: <1369489718-25869-10-git-send-email-jiang.liu@huawei.com>

On Sat, May 25, 2013 at 6:48 AM, Jiang Liu <liuj97@gmail.com> wrote:
> Trivial changes to IOV:
> 1) use new PCI interfaces to simplify IOV implementation
> 2) fix some reference count related race windows
>
> Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
> Cc: Donald Dutile <ddutile@redhat.com>
> Cc: Yinghai Lu <yinghai@kernel.org>
> Cc: Ram Pai <linuxram@us.ibm.com>
> Cc: linux-pci@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/pci/iov.c | 58 +++++++++++++++++++++----------------------------------
>  1 file changed, 22 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index 8f1e117..3e33499 100644
> --- a/drivers/pci/iov.c
> +++ b/drivers/pci/iov.c
> @@ -51,43 +51,30 @@ static struct pci_bus *virtfn_add_bus(struct pci_bus *bus, int busnr)
>         return child;
>  }
>
> -static void virtfn_remove_bus(struct pci_bus *bus, int busnr)
> +static void virtfn_remove_bus(struct pci_bus *physbus, struct pci_bus *virtbus)
>  {
> -       struct pci_bus *child;
> -
> -       if (bus->number == busnr)
> -               return;
> -
> -       child = pci_find_bus(pci_domain_nr(bus), busnr);
> -       BUG_ON(!child);
> -
> -       if (list_empty(&child->devices))
> -               pci_remove_bus(child);
> +       if (physbus != virtbus && list_empty(&virtbus->devices))
> +               pci_remove_bus(virtbus);
>  }
>
>  static int virtfn_add(struct pci_dev *dev, int id, int reset)
>  {
>         int i;
> -       int rc;
> +       int rc = -ENOMEM;
>         u64 size;
>         char buf[VIRTFN_ID_LEN];
> -       struct pci_dev *virtfn;
> +       struct pci_dev *virtfn = NULL;
>         struct resource *res;
>         struct pci_sriov *iov = dev->sriov;
>         struct pci_bus *bus;
>
> -       virtfn = pci_alloc_dev(NULL);
> -       if (!virtfn)
> -               return -ENOMEM;
> -
>         mutex_lock(&iov->dev->sriov->lock);
>         bus = virtfn_add_bus(dev->bus, virtfn_bus(dev, id));
> -       if (!bus) {
> -               kfree(virtfn);
> -               mutex_unlock(&iov->dev->sriov->lock);
> -               return -ENOMEM;
> -       }
> -       virtfn->bus = pci_bus_get(bus);
> +       if (bus)
> +               virtfn = pci_alloc_dev(bus);
> +       if (!virtfn)
> +               goto failed0;
> +
>         virtfn->devfn = virtfn_devfn(dev, id);
>         virtfn->vendor = dev->vendor;
>         pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_DID, &virtfn->device);
> @@ -136,7 +123,8 @@ failed1:
>         pci_dev_put(dev);
>         mutex_lock(&iov->dev->sriov->lock);
>         pci_stop_and_remove_bus_device(virtfn);
> -       virtfn_remove_bus(dev->bus, virtfn_bus(dev, id));
> +       virtfn_remove_bus(dev->bus, bus);
> +failed0:

need to swap above two lines. otherwise virtual bus could not be removed.

>         mutex_unlock(&iov->dev->sriov->lock);
>
>         return rc;
> @@ -145,20 +133,15 @@ failed1:
>  static void virtfn_remove(struct pci_dev *dev, int id, int reset)
>  {
>         char buf[VIRTFN_ID_LEN];
> -       struct pci_bus *bus;
>         struct pci_dev *virtfn;
>         struct pci_sriov *iov = dev->sriov;
>
> -       bus = pci_find_bus(pci_domain_nr(dev->bus), virtfn_bus(dev, id));
> -       if (!bus)
> -               return;
> -
> -       virtfn = pci_get_slot(bus, virtfn_devfn(dev, id));
> +       virtfn = pci_get_domain_bus_and_slot(pci_domain_nr(dev->bus),
> +                                            virtfn_bus(dev, id),
> +                                            virtfn_devfn(dev, id));
>         if (!virtfn)
>                 return;
>
> -       pci_dev_put(virtfn);
> -
>         if (reset) {
>                 device_release_driver(&virtfn->dev);
>                 __pci_reset_function(virtfn);
> @@ -176,9 +159,11 @@ static void virtfn_remove(struct pci_dev *dev, int id, int reset)
>
>         mutex_lock(&iov->dev->sriov->lock);
>         pci_stop_and_remove_bus_device(virtfn);
> -       virtfn_remove_bus(dev->bus, virtfn_bus(dev, id));
> +       virtfn_remove_bus(dev->bus, virtfn->bus);
>         mutex_unlock(&iov->dev->sriov->lock);
>
> +       /* balance pci_get_domain_bus_and_slot() */
> +       pci_dev_put(virtfn);
>         pci_dev_put(dev);
>  }
>
> @@ -335,13 +320,14 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
>                 if (!pdev)
>                         return -ENODEV;
>
> -               pci_dev_put(pdev);
> -
> -               if (!pdev->is_physfn)
> +               if (!pdev->is_physfn) {
> +                       pci_dev_put(pdev);
>                         return -ENODEV;
> +               }
>
>                 rc = sysfs_create_link(&dev->dev.kobj,
>                                         &pdev->dev.kobj, "dep_link");
> +               pci_dev_put(pdev);
>                 if (rc)
>                         return rc;
>         }
> --
> 1.8.1.2
>

  reply	other threads:[~2013-05-28  2:00 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-25 13:48 [PATCH v3, part1 00/10] Prepare for introducing PCI bus lock interfaces Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 01/10] PCI: introduce pci_bus_{get|put}() to manage PCI bus reference count Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 02/10] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev() Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 03/10] PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus) instead Jiang Liu
2013-05-25 13:48   ` Jiang Liu
2013-05-25 13:48   ` Jiang Liu
2013-06-05 20:07   ` Bjorn Helgaas
2013-06-05 20:07     ` Bjorn Helgaas
2013-06-05 20:07     ` Bjorn Helgaas
2013-06-06 16:16     ` Jiang Liu
2013-06-06 16:16       ` Jiang Liu
2013-06-06 16:16       ` Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 04/10] PCI: mark pci_scan_bus_parented() as __deprecated Jiang Liu
2013-05-31 20:12   ` Chris Metcalf
2013-06-05 20:04   ` Bjorn Helgaas
2013-06-06 16:32     ` Jiang Liu
2013-06-07 14:37       ` Konrad Rzeszutek Wilk
2013-06-07 15:11         ` Jiang Liu
2013-06-07 15:30         ` Jiang Liu
2013-06-07 20:37           ` Bjorn Helgaas
2013-05-25 13:48 ` [PATCH v3, part1 05/10] PCI, IA64: minor code clean up Jiang Liu
2013-05-25 13:48   ` Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 06/10] PCI: make PCI host bridge/bus creating and destroying logic symmetric Jiang Liu
2013-06-05 20:14   ` Bjorn Helgaas
2013-06-06 17:10     ` [PATCH 1/2] PCI: fix a double free issue in pci_create_root_bus() error recovery path Jiang Liu
2013-06-08  1:42       ` Bjorn Helgaas
2013-06-06 17:10     ` [PATCH 2/2] PCI: make PCI host bridge/bus creating and destroying logic symmetric Jiang Liu
2013-06-06 20:01       ` Yinghai Lu
2013-06-08  1:51         ` Bjorn Helgaas
2013-06-08  7:01           ` Yinghai Lu
2013-06-14 23:53             ` Bjorn Helgaas
2013-06-15  1:46               ` Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 07/10] PCI, unicore, m68k: remove redundant call of pci_bus_add_devices() Jiang Liu
2013-06-05 21:31   ` Bjorn Helgaas
2013-06-05 21:31     ` Bjorn Helgaas
2013-06-06  6:54     ` Greg Ungerer
2013-06-06  6:54       ` Greg Ungerer
2013-06-05 21:31   ` Bjorn Helgaas
2013-05-25 13:48 ` [PATCH v3, part1 08/10] PCI, IOV: don't touch bus->is_added flag Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 09/10] PCI, IOV: simplify IOV implementation Jiang Liu
2013-05-28  2:00   ` Yinghai Lu [this message]
2013-05-28 14:48     ` Liu Jiang
2013-05-30  4:31   ` [PATCH] PCI, IOV: fix a resource leakage on error recovery path Jiang Liu
2013-05-30 18:24     ` Bjorn Helgaas
2013-05-25 13:48 ` [PATCH v3, part1 10/10] PCI, IOV: hide remove and rescan sysfs interfaces for SR-IOV virtual functions Jiang Liu

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='CAE9FiQX-3=U7YpEnRsL46Kn0Dyvk_+A1NC7UYijHe91KWjrKDA@mail.gmail.com' \
    --to=yinghai@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=ddutile@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=guz.fnst@cn.fujitsu.com \
    --cc=jiang.liu@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxram@us.ibm.com \
    --cc=liuj97@gmail.com \
    --cc=myron.stowe@redhat.com \
    --cc=rjw@sisk.pl \
    --cc=toshi.kani@hp.com \
    --cc=wangyijing@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.