From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Jiang Liu <liuj97@gmail.com>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>,
xen-devel@lists.xensource.com, Toshi Kani <toshi.kani@hp.com>,
Jiang Liu <jiang.liu@huawei.com>,
Myron Stowe <myron.stowe@redhat.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org,
"Rafael J . Wysocki" <rjw@sisk.pl>,
Gu Zheng <guz.fnst@cn.fujitsu.com>,
Yijing Wang <wangyijing@huawei.com>,
linux-pci@vger.kernel.org, Bjorn Helgaas <bhelgaas@google.com>,
Yinghai Lu <yinghai@kernel.org>
Subject: Re: [RFC PATCH v2, part3 07/11] PCI, xen-pcifront: use new PCI interfaces to simplify implementation
Date: Fri, 7 Jun 2013 10:50:24 -0400 [thread overview]
Message-ID: <20130607145024.GA16631@phenom.dumpdata.com> (raw)
In-Reply-To: <1368719459-24800-8-git-send-email-jiang.liu@huawei.com>
On Thu, May 16, 2013 at 11:50:55PM +0800, Jiang Liu wrote:
> Use new PCI interfaces to simplify xen-pcifront implementation:
> 1) Use pci_create_root_bus() instead of pci_scan_bus_parented()
> because pci_scan_bus_parented() is marked as __deprecated.This
> also gets rid of a duplicated call of pci_bus_start_devices().
> 2) Use pci_stop_root_bus() and pci_remove_root_bus() instead of
> open-coded private implementation.
> 3) Use pci_set_host_bridge_release() to release data structures
> associated with PCI root buses.
> 4) Use pci_bus_get()/pci_bus_put() to manage PCI root bus reference
> count.
>
> This is also a preparation for coming PCI bus lock enhancement.
>
> Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Jeremy Fitzhardinge <jeremy@goop.org>
> Cc: xen-devel@lists.xensource.com
> Cc: virtualization@lists.linux-foundation.org
> Cc: linux-pci@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
> drivers/pci/xen-pcifront.c | 81 ++++++++++++++++++++++------------------------
> 1 file changed, 39 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
> index 816cf94..6aa2c0f 100644
> --- a/drivers/pci/xen-pcifront.c
> +++ b/drivers/pci/xen-pcifront.c
> @@ -25,11 +25,6 @@
> #define INVALID_GRANT_REF (0)
> #define INVALID_EVTCHN (-1)
>
> -struct pci_bus_entry {
> - struct list_head list;
> - struct pci_bus *bus;
> -};
> -
> #define _PDEVB_op_active (0)
> #define PDEVB_op_active (1 << (_PDEVB_op_active))
>
> @@ -47,12 +42,12 @@ struct pcifront_device {
> struct xen_pci_sharedinfo *sh_info;
> struct work_struct op_work;
> unsigned long flags;
> -
> };
>
> struct pcifront_sd {
> int domain;
> struct pcifront_device *pdev;
> + struct resource busn_res;
> };
>
> static inline struct pcifront_device *
> @@ -67,6 +62,12 @@ static inline void pcifront_init_sd(struct pcifront_sd *sd,
> {
> sd->domain = domain;
> sd->pdev = pdev;
> +
> + /* Xen pci-backend doesn't export P2P bridges */
> + sd->busn_res.start = bus;
> + sd->busn_res.end = bus;
> + sd->busn_res.flags = IORESOURCE_BUS;
> + sd->busn_res.name = "PCI busn";
> }
>
> static DEFINE_SPINLOCK(pcifront_dev_lock);
> @@ -441,12 +442,19 @@ static int pcifront_scan_bus(struct pcifront_device *pdev,
> return 0;
> }
>
> +static void pcifront_release_sd(struct pci_host_bridge *bridge)
> +{
> + struct pcifront_sd *sd = bridge->release_data;
> +
> + kfree(sd);
> +}
> +
> static int pcifront_scan_root(struct pcifront_device *pdev,
> unsigned int domain, unsigned int bus)
> {
> struct pci_bus *b;
> struct pcifront_sd *sd = NULL;
> - struct pci_bus_entry *bus_entry = NULL;
> + LIST_HEAD(resources);
> int err = 0;
>
> #ifndef CONFIG_PCI_DOMAINS
> @@ -463,16 +471,18 @@ static int pcifront_scan_root(struct pcifront_device *pdev,
> dev_info(&pdev->xdev->dev, "Creating PCI Frontend Bus %04x:%02x\n",
> domain, bus);
>
> - bus_entry = kmalloc(sizeof(*bus_entry), GFP_KERNEL);
> - sd = kmalloc(sizeof(*sd), GFP_KERNEL);
> - if (!bus_entry || !sd) {
> + sd = kzalloc(sizeof(*sd), GFP_KERNEL);
> + if (!sd) {
> err = -ENOMEM;
> goto err_out;
> }
> pcifront_init_sd(sd, domain, bus, pdev);
>
> - b = pci_scan_bus_parented(&pdev->xdev->dev, bus,
> - &pcifront_bus_ops, sd);
> + pci_add_resource(&resources, &ioport_resource);
> + pci_add_resource(&resources, &iomem_resource);
> + pci_add_resource(&resources, &sd->busn_res);
> + b = pci_create_root_bus(&pdev->xdev->dev, bus, &pcifront_bus_ops,
> + sd, &resources);
> if (!b) {
> dev_err(&pdev->xdev->dev,
> "Error creating PCI Frontend Bus!\n");
> @@ -480,12 +490,14 @@ static int pcifront_scan_root(struct pcifront_device *pdev,
> goto err_out;
> }
>
> - bus_entry->bus = b;
> + pci_set_host_bridge_release(to_pci_host_bridge(b->bridge),
> + pcifront_release_sd, sd);
>
> - list_add(&bus_entry->list, &pdev->root_buses);
> -
> - /* pci_scan_bus_parented skips devices which do not have a have
> - * devfn==0. The pcifront_scan_bus enumerates all devfn. */
> + /*
> + * Every PCI physical device should have function 0, but that's not
> + * true for xen.
That is incorrect. There are two types of backends - one of them will
start at zero, but the other might not.
> + * So use pcifront_scan_bus() instead of pci_scan_child_bus().
> + */
> err = pcifront_scan_bus(pdev, domain, bus, b);
>
> /* Claim resources before going "live" with our devices */
> @@ -497,7 +509,6 @@ static int pcifront_scan_root(struct pcifront_device *pdev,
> return err;
>
> err_out:
> - kfree(bus_entry);
> kfree(sd);
>
> return err;
> @@ -539,35 +550,19 @@ static int pcifront_rescan_root(struct pcifront_device *pdev,
> return err;
> }
>
> -static void free_root_bus_devs(struct pci_bus *bus)
> -{
> - struct pci_dev *dev;
> -
> - while (!list_empty(&bus->devices)) {
> - dev = container_of(bus->devices.next, struct pci_dev,
> - bus_list);
> - dev_dbg(&dev->dev, "removing device\n");
> - pci_stop_and_remove_bus_device(dev);
> - }
> -}
> -
> static void pcifront_free_roots(struct pcifront_device *pdev)
> {
> - struct pci_bus_entry *bus_entry, *t;
> + struct pcifront_sd *sd;
> + struct pci_bus *bus;
>
> dev_dbg(&pdev->xdev->dev, "cleaning up root buses\n");
>
> - list_for_each_entry_safe(bus_entry, t, &pdev->root_buses, list) {
> - list_del(&bus_entry->list);
> -
> - free_root_bus_devs(bus_entry->bus);
> -
> - kfree(bus_entry->bus->sysdata);
> -
> - device_unregister(bus_entry->bus->bridge);
> - pci_remove_bus(bus_entry->bus);
> -
> - kfree(bus_entry);
> + for_each_pci_root_bus(bus) {
> + sd = bus->sysdata;
> + if (sd->pdev == pdev) {
> + pci_stop_root_bus(bus);
> + pci_remove_root_bus(bus);
> + }
> }
> }
>
> @@ -670,6 +665,7 @@ static irqreturn_t pcifront_handler_aer(int irq, void *dev)
> schedule_pcifront_aer_op(pdev);
> return IRQ_HANDLED;
> }
> +
Stray
> static int pcifront_connect_and_init_dma(struct pcifront_device *pdev)
> {
> int err = 0;
> @@ -705,6 +701,7 @@ static void pcifront_disconnect(struct pcifront_device *pdev)
>
> spin_unlock(&pcifront_dev_lock);
> }
> +
Stray
> static struct pcifront_device *alloc_pdev(struct xenbus_device *xdev)
> {
> struct pcifront_device *pdev;
> --
> 1.8.1.2
>
next prev parent reply other threads:[~2013-06-07 14:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1368719459-24800-1-git-send-email-jiang.liu@huawei.com>
2013-05-16 15:50 ` [RFC PATCH v2, part3 07/11] PCI, xen-pcifront: use new PCI interfaces to simplify implementation Jiang Liu
2013-06-07 14:50 ` Konrad Rzeszutek Wilk [this message]
2013-06-07 15:17 ` Jiang Liu
2013-06-07 15:38 ` Konrad Rzeszutek Wilk
2013-06-07 16:50 ` Jiang Liu
2013-06-07 17:07 ` Konrad Rzeszutek Wilk
2013-06-09 16:50 ` Jiang Liu
2013-06-10 16:58 ` Konrad Rzeszutek Wilk
2013-06-10 17:08 ` Jiang Liu
2013-06-14 18:07 ` Konrad Rzeszutek Wilk
2013-06-07 15:50 ` Jiang Liu
2013-05-16 15:50 ` [RFC PATCH v2, part3 08/11] PCI, xen-pcifront: use PCI bus lock to protect PCI device hotplug 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=20130607145024.GA16631@phenom.dumpdata.com \
--to=konrad.wilk@oracle.com \
--cc=bhelgaas@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=guz.fnst@cn.fujitsu.com \
--cc=jeremy@goop.org \
--cc=jiang.liu@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=liuj97@gmail.com \
--cc=myron.stowe@redhat.com \
--cc=rjw@sisk.pl \
--cc=toshi.kani@hp.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=wangyijing@huawei.com \
--cc=xen-devel@lists.xensource.com \
--cc=yinghai@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).