From: Liu Jiang <liuj97@gmail.com>
To: Yinghai Lu <yinghai@kernel.org>
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>
Subject: Re: [PATCH v3, part2 01/20] PCI: introduce hotplug-safe PCI bus iterators
Date: Tue, 28 May 2013 23:06:22 +0800 [thread overview]
Message-ID: <51A4C7EE.8060506@gmail.com> (raw)
In-Reply-To: <CAE9FiQUBQRrkiub_EGZ1TZ-iccLts7hDff3kOz70uq=McjpoGg@mail.gmail.com>
On Tue 28 May 2013 12:22:29 PM CST, Yinghai Lu wrote:
> On Sun, May 26, 2013 at 8:52 AM, Jiang Liu <liuj97@gmail.com> wrote:
>> Introduce hotplug-safe PCI bus iterators as below, which hold a
>> reference on the returned PCI bus object.
>> bool pci_bus_exists(int domain, int busnr);
>> struct pci_bus *pci_get_bus(int domain, int busnr);
>> struct pci_bus *pci_get_next_bus(struct pci_bus *from);
>> struct pci_bus *pci_get_next_root_bus(struct pci_bus *from);
>> #define for_each_pci_bus(b) for (b = NULL; (b = pci_get_next_bus(b)); )
>> #define for_each_pci_root_bus(b) \
>> for (b = NULL; (b = pci_get_next_root_bus(b)); )
>>
>> The long-term goal is to remove hotplug-unsafe pci_find_bus(),
>> pci_find_next_bus() and the global pci_root_buses list.
>>
>> These new interfaces may be a littler slower than existing interfaces,
>> but it should be acceptable because they are not used on hot paths.
>
> looks like go over all buses to find out several root buses is not good.
>
>
>>
>> Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
>> Acked-by: Yinghai Lu <yinghai@kernel.org>
>
> I take that back.
>
>> Cc: linux-pci@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> ---
>> drivers/pci/pci.h | 1 +
>> drivers/pci/probe.c | 2 +-
>> drivers/pci/search.c | 159 +++++++++++++++++++++++++++++++++++++++++----------
>> include/linux/pci.h | 23 +++++++-
>> 4 files changed, 153 insertions(+), 32 deletions(-)
>>
>> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
>> index 68678ed..8fe15f6 100644
>> --- a/drivers/pci/pci.h
>> +++ b/drivers/pci/pci.h
>> @@ -126,6 +126,7 @@ static inline void pci_remove_legacy_files(struct pci_bus *bus) { return; }
>>
>> /* Lock for read/write access to pci device and bus lists */
>> extern struct rw_semaphore pci_bus_sem;
>> +extern struct class pcibus_class;
>>
>> extern raw_spinlock_t pci_lock;
>>
>> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
>> index 2830070..1004a05 100644
>> --- a/drivers/pci/probe.c
>> +++ b/drivers/pci/probe.c
>> @@ -93,7 +93,7 @@ static void release_pcibus_dev(struct device *dev)
>> kfree(pci_bus);
>> }
>>
>> -static struct class pcibus_class = {
>> +struct class pcibus_class = {
>> .name = "pci_bus",
>> .dev_release = &release_pcibus_dev,
>> .dev_attrs = pcibus_dev_attrs,
> ...
>> +static int pci_match_next_root_bus(struct device *dev, const void *data)
>> +{
>> + return pci_is_root_bus(to_pci_bus(dev));
>> }
> ...
>> +
>> +/**
>> + * pci_find_next_root_bus - begin or continue searching for a PCI root bus
>> + * @from: Previous PCI bus found, or %NULL for new search.
>> + *
>> + * Iterates through the list of known PCI root busses. If a PCI bus is found,
>> + * the reference count to the root bus is incremented and a pointer to it is
>> + * returned. Otherwise, %NULL is returned. A new search is initiated by
>> + * passing %NULL as the @from argument. Otherwise if @from is not %NULL,
>> + * searches continue from next root bus on the global list. The reference
>> + * count for @from is always decremented if it is not %NULL.
>> + */
>> +struct pci_bus *pci_get_next_root_bus(struct pci_bus *from)
>> +{
>> + struct device *dev = from ? &from->dev : NULL;
>> +
>> + WARN_ON(in_interrupt());
>> + dev = class_find_device(&pcibus_class, dev, NULL,
>> + &pci_match_next_root_bus);
>> + pci_bus_put(from);
>> + if (dev)
>> + return to_pci_bus(dev);
>> +
>> + return NULL;
>> }
>> +EXPORT_SYMBOL(pci_get_next_root_bus);
>
> this patchset is most doing same thing like my for_each_host_bridge patchset.
> that patchset add bus_type for host_bridge and loop with each_...bus
> to find host_bridge
> and to its bus.
>
> looks like for each host bridge should be right direction.
>
> also late we could add per host bridge lock instead of whole pci bus sem etc.
>
> Thanks
>
> Yinghai
Hi Yinghai,
Thanks for review! Actually this patchset is inspired by your
for_each_host_bridge()
patchset but trying to close some race windows.
Currently pci_root_bus holds a reference to pci_host_bridge,
so it's always safe to
reference pci_root_bus->bridge. And pci_host_bridge doesn't hold
reference to pci_root_bus,
so we can't safely reference pci_host_bridge->bus. And it's hard to
make pci_host_bridge
to hold a reference to pci_root_bus because that will cause loop.
So we try to achieve the same goal with this patchset, but
with some level of inefficiency
to search all PCI buses for root buses.
The third patchset of this series is to introduce a PCI bus
lock mechanism to solve
many risk conditions in PCI host bridge/device hotplug we are facing
recently. We have
done basic tests against the new lock mechanism and seems it has solved
all those
risk conditions found by us and Gu Zheng. But we are still working on
improving the
third patchset.
To all, seems we are trying to achieve the same goal with
different approaches.
Regards!
Gerry
next prev parent reply other threads:[~2013-05-28 15:06 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-26 15:52 [PATCH v3, part2 00/20] Introduce hotplug-safe PCI bus iterators Jiang Liu
2013-05-26 15:52 ` [PATCH v3, part2 01/20] PCI: introduce " Jiang Liu
2013-05-28 4:22 ` Yinghai Lu
2013-05-28 15:06 ` Liu Jiang [this message]
2013-06-17 20:06 ` Bjorn Helgaas
2013-06-18 16:23 ` Jiang Liu
2013-06-20 16:18 ` Jiang Liu
2013-06-26 2:58 ` Bjorn Helgaas
2013-05-26 15:52 ` [PATCH v3, part2 02/20] PCI, core: use hotplug-safe iterators to walk PCI buses Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 03/20] PCI, hotplug: " Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 04/20] PCI, IOV: hold a reference to PCI bus when creating virtual PCI devices Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 05/20] PCI, Alpha: use hotplug-safe iterators to walk PCI buses Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 06/20] PCI, FRV: " Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 07/20] PCI, IA64: " Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 08/20] PCI, Microblaze: " Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 09/20] PCI, mn10300: " Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 10/20] PCI, PPC: " Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 11/20] PCI, SPARC: " Jiang Liu
2013-05-26 17:11 ` David Miller
2013-05-26 15:53 ` [PATCH v3, part2 12/20] PCI, x86: " Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 13/20] PCI, ACPI: " Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 14/20] PCI, DRM: " Jiang Liu
2013-06-17 18:08 ` Bjorn Helgaas
2013-05-26 15:53 ` [PATCH v3, part2 15/20] PCI, EDAC: use hotplug-safe PCI bus " Jiang Liu
2013-06-17 20:18 ` Bjorn Helgaas
2013-06-18 16:33 ` Jiang Liu
2013-06-26 3:00 ` Bjorn Helgaas
2013-05-26 15:53 ` [PATCH v3, part2 16/20] PCI, via-camera: use hotplug-safe " Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 17/20] PCI, iommu: " Jiang Liu
2013-06-17 20:20 ` Bjorn Helgaas
2013-06-17 20:34 ` Don Dutile
2013-06-18 16:34 ` Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 18/20] PCI, eeepc-laptop: " Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 19/20] PCI, asus-wmi: " Jiang Liu
2013-05-26 15:53 ` [PATCH v3, part2 20/20] PCI, ARM: use hotplug-safe PCI bus " Jiang Liu
2013-06-17 18:24 ` Bjorn Helgaas
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=51A4C7EE.8060506@gmail.com \
--to=liuj97@gmail.com \
--cc=bhelgaas@google.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=myron.stowe@redhat.com \
--cc=rjw@sisk.pl \
--cc=toshi.kani@hp.com \
--cc=wangyijing@huawei.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).