From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Bjorn Helgaas <helgaas@kernel.org>, linux-pci@vger.kernel.org
Cc: Hari Vyas <hari.vyas@broadcom.com>,
Ray Jui <ray.jui@broadcom.com>,
Srinath Mannam <srinath.mannam@broadcom.com>,
Guenter Roeck <linux@roeck-us.net>, Jens Axboe <axboe@kernel.dk>,
Lukas Wunner <lukas@wunner.de>,
Konstantin Khlebnikov <khlebnikov@yandex-team.ru>,
Marta Rybczynska <mrybczyn@kalray.eu>,
Pierre-Yves Kerbrat <pkerbrat@kalray.eu>,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 1/6] Revert "PCI: Fix is_added/is_busmaster race condition"
Date: Fri, 17 Aug 2018 14:57:08 +1000 [thread overview]
Message-ID: <65c8e4cb4732f9331fb320f6fd7910756c14fc35.camel@kernel.crashing.org> (raw)
In-Reply-To: <20180817044902.31420-2-benh@kernel.crashing.org>
On Fri, 2018-08-17 at 14:48 +1000, Benjamin Herrenschmidt wrote:
> This reverts commit 44bda4b7d26e9fffed6d7152d98a2e9edaeb2a76.
>
> The new pci state mutex provides a simpler way of addressing
> this race and avoids the relative includes added to the powerpc
> code.
Ignore the cset comment, my "fix" no longer relies on a state mutex,
I'll re-post with a better comment after discussions.
The actual fix is in patch 2:
[RFC PATCH 2/6] pci: Set pci_dev->is_added before calling device_add
(and yes that was supposed be device_attach ... ugh, not enough
caffeine today).
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
> arch/powerpc/kernel/pci-common.c | 4 +---
> arch/powerpc/platforms/powernv/pci-ioda.c | 3 +--
> arch/powerpc/platforms/pseries/setup.c | 3 +--
> drivers/pci/bus.c | 6 +++---
> drivers/pci/hotplug/acpiphp_glue.c | 2 +-
> drivers/pci/pci.h | 11 -----------
> drivers/pci/probe.c | 4 ++--
> drivers/pci/remove.c | 5 ++---
> include/linux/pci.h | 1 +
> 9 files changed, 12 insertions(+), 27 deletions(-)
>
> diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
> index 471aac313b89..fe9733ffffaa 100644
> --- a/arch/powerpc/kernel/pci-common.c
> +++ b/arch/powerpc/kernel/pci-common.c
> @@ -42,8 +42,6 @@
> #include <asm/ppc-pci.h>
> #include <asm/eeh.h>
>
> -#include "../../../drivers/pci/pci.h"
> -
> /* hose_spinlock protects accesses to the the phb_bitmap. */
> static DEFINE_SPINLOCK(hose_spinlock);
> LIST_HEAD(hose_list);
> @@ -1016,7 +1014,7 @@ void pcibios_setup_bus_devices(struct pci_bus *bus)
> /* Cardbus can call us to add new devices to a bus, so ignore
> * those who are already fully discovered
> */
> - if (pci_dev_is_added(dev))
> + if (dev->is_added)
> continue;
>
> pcibios_setup_device(dev);
> diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
> index 70b2e1e0f23c..5bd0eb6681bc 100644
> --- a/arch/powerpc/platforms/powernv/pci-ioda.c
> +++ b/arch/powerpc/platforms/powernv/pci-ioda.c
> @@ -46,7 +46,6 @@
>
> #include "powernv.h"
> #include "pci.h"
> -#include "../../../../drivers/pci/pci.h"
>
> #define PNV_IODA1_M64_NUM 16 /* Number of M64 BARs */
> #define PNV_IODA1_M64_SEGS 8 /* Segments per M64 BAR */
> @@ -3139,7 +3138,7 @@ static void pnv_pci_ioda_fixup_iov_resources(struct pci_dev *pdev)
> struct pci_dn *pdn;
> int mul, total_vfs;
>
> - if (!pdev->is_physfn || pci_dev_is_added(pdev))
> + if (!pdev->is_physfn || pdev->is_added)
> return;
>
> pdn = pci_get_pdn(pdev);
> diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
> index 8a4868a3964b..139f0af6c3d9 100644
> --- a/arch/powerpc/platforms/pseries/setup.c
> +++ b/arch/powerpc/platforms/pseries/setup.c
> @@ -71,7 +71,6 @@
> #include <asm/security_features.h>
>
> #include "pseries.h"
> -#include "../../../../drivers/pci/pci.h"
>
> int CMO_PrPSP = -1;
> int CMO_SecPSP = -1;
> @@ -665,7 +664,7 @@ static void pseries_pci_fixup_iov_resources(struct pci_dev *pdev)
> const int *indexes;
> struct device_node *dn = pci_device_to_OF_node(pdev);
>
> - if (!pdev->is_physfn || pci_dev_is_added(pdev))
> + if (!pdev->is_physfn || pdev->is_added)
> return;
> /*Firmware must support open sriov otherwise dont configure*/
> indexes = of_get_property(dn, "ibm,open-sriov-vf-bar-info", NULL);
> diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
> index 5cb40b2518f9..35b7fc87eac5 100644
> --- a/drivers/pci/bus.c
> +++ b/drivers/pci/bus.c
> @@ -330,7 +330,7 @@ void pci_bus_add_device(struct pci_dev *dev)
> return;
> }
>
> - pci_dev_assign_added(dev, true);
> + dev->is_added = 1;
> }
> EXPORT_SYMBOL_GPL(pci_bus_add_device);
>
> @@ -347,14 +347,14 @@ void pci_bus_add_devices(const struct pci_bus *bus)
>
> list_for_each_entry(dev, &bus->devices, bus_list) {
> /* Skip already-added devices */
> - if (pci_dev_is_added(dev))
> + if (dev->is_added)
> continue;
> pci_bus_add_device(dev);
> }
>
> list_for_each_entry(dev, &bus->devices, bus_list) {
> /* Skip if device attach failed */
> - if (!pci_dev_is_added(dev))
> + if (!dev->is_added)
> continue;
> child = dev->subordinate;
> if (child)
> diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
> index ef0b1b6ba86f..3a17b290df5d 100644
> --- a/drivers/pci/hotplug/acpiphp_glue.c
> +++ b/drivers/pci/hotplug/acpiphp_glue.c
> @@ -509,7 +509,7 @@ static void enable_slot(struct acpiphp_slot *slot)
>
> list_for_each_entry(dev, &bus->devices, bus_list) {
> /* Assume that newly added devices are powered on already. */
> - if (!pci_dev_is_added(dev))
> + if (!dev->is_added)
> dev->current_state = PCI_D0;
> }
>
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index 6e0d1528d471..473aa10a5dbf 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -295,7 +295,6 @@ struct pci_sriov {
>
> /* pci_dev priv_flags */
> #define PCI_DEV_DISCONNECTED 0
> -#define PCI_DEV_ADDED 1
>
> static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused)
> {
> @@ -308,16 +307,6 @@ static inline bool pci_dev_is_disconnected(const struct pci_dev *dev)
> return test_bit(PCI_DEV_DISCONNECTED, &dev->priv_flags);
> }
>
> -static inline void pci_dev_assign_added(struct pci_dev *dev, bool added)
> -{
> - assign_bit(PCI_DEV_ADDED, &dev->priv_flags, added);
> -}
> -
> -static inline bool pci_dev_is_added(const struct pci_dev *dev)
> -{
> - return test_bit(PCI_DEV_ADDED, &dev->priv_flags);
> -}
> -
> #ifdef CONFIG_PCIEAER
> #include <linux/aer.h>
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index ec784009a36b..440445ac7dfa 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -2525,13 +2525,13 @@ int pci_scan_slot(struct pci_bus *bus, int devfn)
> dev = pci_scan_single_device(bus, devfn);
> if (!dev)
> return 0;
> - if (!pci_dev_is_added(dev))
> + if (!dev->is_added)
> nr++;
>
> for (fn = next_fn(bus, dev, 0); fn > 0; fn = next_fn(bus, dev, fn)) {
> dev = pci_scan_single_device(bus, devfn + fn);
> if (dev) {
> - if (!pci_dev_is_added(dev))
> + if (!dev->is_added)
> nr++;
> dev->multifunction = 1;
> }
> diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
> index 461e7fd2756f..01ec7fcb5634 100644
> --- a/drivers/pci/remove.c
> +++ b/drivers/pci/remove.c
> @@ -18,12 +18,11 @@ static void pci_stop_dev(struct pci_dev *dev)
> {
> pci_pme_active(dev, false);
>
> - if (pci_dev_is_added(dev)) {
> + if (dev->is_added) {
> device_release_driver(&dev->dev);
> pci_proc_detach_device(dev);
> pci_remove_sysfs_dev_files(dev);
> -
> - pci_dev_assign_added(dev, false);
> + dev->is_added = 0;
> }
>
> if (dev->bus->self)
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 9b87f1936906..9799109c5e25 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -373,6 +373,7 @@ struct pci_dev {
> unsigned int transparent:1; /* Subtractive decode bridge */
> unsigned int multifunction:1; /* Multi-function device */
>
> + unsigned int is_added:1;
> unsigned int is_busmaster:1; /* Is busmaster */
> unsigned int no_msi:1; /* May not use MSI */
> unsigned int no_64bit_msi:1; /* May only use 32-bit MSIs */
next prev parent reply other threads:[~2018-08-17 4:57 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-17 4:48 [RFC PATCH 0/6] pci: Rework is_added race fix and address bridge enable races Benjamin Herrenschmidt
2018-08-17 4:48 ` [RFC PATCH 1/6] Revert "PCI: Fix is_added/is_busmaster race condition" Benjamin Herrenschmidt
2018-08-17 4:57 ` Benjamin Herrenschmidt [this message]
2018-08-17 15:44 ` Bjorn Helgaas
2018-08-18 3:24 ` Benjamin Herrenschmidt
2018-08-19 2:24 ` Bjorn Helgaas
2018-08-20 2:10 ` Benjamin Herrenschmidt
2018-08-20 6:25 ` Hari Vyas
2018-08-20 11:09 ` Benjamin Herrenschmidt
2018-08-20 11:43 ` Hari Vyas
2018-08-20 7:17 ` Lukas Wunner
2018-08-20 11:12 ` Benjamin Herrenschmidt
2018-08-17 4:48 ` [RFC PATCH 2/6] pci: Set pci_dev->is_added before calling device_add Benjamin Herrenschmidt
2018-08-17 4:57 ` Benjamin Herrenschmidt
2018-08-17 16:25 ` Bjorn Helgaas
2018-08-17 18:15 ` Lukas Wunner
2018-08-18 3:41 ` Benjamin Herrenschmidt
2018-08-18 3:28 ` Benjamin Herrenschmidt
2018-08-17 4:48 ` [RFC PATCH 3/6] pci: Remove priv_flags and use dev->error_state for "disconnected" status Benjamin Herrenschmidt
2018-08-17 5:13 ` [RFC PATCH v2 " Benjamin Herrenschmidt
2018-08-17 4:49 ` [RFC PATCH 4/6] pci: Add a mutex to pci_dev to protect device state Benjamin Herrenschmidt
2018-08-17 4:49 ` [RFC PATCH 5/6] pci: Protect the enable/disable state of pci_dev using the state mutex Benjamin Herrenschmidt
2018-08-17 8:09 ` Marta Rybczynska
2018-08-17 8:30 ` Benjamin Herrenschmidt
2018-08-17 9:00 ` Hari Vyas
2018-08-17 9:39 ` Benjamin Herrenschmidt
2018-08-17 10:10 ` Hari Vyas
2018-08-17 10:24 ` Benjamin Herrenschmidt
2018-08-17 4:49 ` [RFC PATCH 6/6] pci: Protect is_busmaster using the state lock Benjamin Herrenschmidt
2018-08-17 5:03 ` [RFC PATCH 0/6] pci: Rework is_added race fix and address bridge enable races Benjamin Herrenschmidt
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=65c8e4cb4732f9331fb320f6fd7910756c14fc35.camel@kernel.crashing.org \
--to=benh@kernel.crashing.org \
--cc=axboe@kernel.dk \
--cc=hari.vyas@broadcom.com \
--cc=helgaas@kernel.org \
--cc=khlebnikov@yandex-team.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=lukas@wunner.de \
--cc=mrybczyn@kalray.eu \
--cc=pkerbrat@kalray.eu \
--cc=ray.jui@broadcom.com \
--cc=srinath.mannam@broadcom.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 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).