From: Bjorn Helgaas <helgaas@kernel.org>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Hari Vyas <hari.vyas@broadcom.com>,
bhelgaas@google.com, linux-pci@vger.kernel.org,
Ray Jui <ray.jui@broadcom.com>,
linux-kernel@vger.kernel.org,
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>
Subject: Re: [RFC PATCH] pci: Proof of concept at fixing pci_enable_device/bridge races
Date: Thu, 16 Aug 2018 22:07:41 -0500 [thread overview]
Message-ID: <20180817030741.GC10316@bhelgaas-glaptop.roam.corp.google.com> (raw)
In-Reply-To: <08bc40a6af3e614e97a78fbaab688bfcd14520ac.camel@kernel.crashing.org>
[+cc Srinath, Guenter, Jens, Lukas, Konstantin, Marta, Pierre-Yves]
On Thu, Aug 16, 2018 at 07:50:13AM +1000, Benjamin Herrenschmidt wrote:
> [Note: This isn't meant to be merged, it need splitting at the very
> least, see below]
>
> This is something I cooked up quickly today to test if that would fix
> my problems with large number of switch and NVME devices on POWER.
>
> So far it does...
>
> The issue (as discussed in the Re: PCIe enable device races thread) is
> that pci_enable_device and related functions along with pci_set_master
> and pci_enable_bridge are fundamentally racy.
>
> There is no lockign protecting the state of the device in pci_dev and
> if multiple devices under the same bridge try to enable it simultaneously
> one some of them will potentially start accessing it before it has actually
> been enabled.
>
> Now there are a LOT more fields in pci_dev that aren't covered by any
> form of locking.
Most of the PCI core relies on the assumption that only a single
thread touches a device at a time. This is generally true of the core
during enumeration because enumeration is single-threaded. It's
generally true in normal driver operation because the core shouldn't
touch a device after a driver claims it.
But there are several exceptions, and I think we need to understand
those scenarios before applying locks willy-nilly.
One big exception is that enabling device A may also touch an upstream
bridge B. That causes things like your issue and Srinath's issue
where drivers simultaneously enabling two devices below the same
bridge corrupt the bridge's state [1]. Marta reported essentially the
same issue [2].
Hari's issue [3] seems related to a race between a driver work queue
and the core enumerating the device. I should have pushed harder to
understand this; I feel like we papered over the immediate problem
without clearing up the larger issue of why the core enumeration path
(pci_bus_add_device()) is running at the same time as a driver.
DPC/AER error handling adds more cases where the core potentially
accesses devices asynchronously to the driver.
User-mode sysfs controls like ASPM are also asynchronous to drivers.
Even setpci is a potential issue, though I don't know how far we want
to go to protect it. I think we should make setpci taint the kernel
anyway.
It might be nice if we had some sort of writeup of the locking
strategy as a whole.
[1] https://lkml.kernel.org/r/1501858648-22228-1-git-send-email-srinath.mannam@broadcom.com
[2] https://lkml.kernel.org/r/744877924.5841545.1521630049567.JavaMail.zimbra@kalray.eu
[3] https://lkml.kernel.org/r/1530608741-30664-2-git-send-email-hari.vyas@broadcom.com
next prev parent reply other threads:[~2018-08-17 6:09 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-03 9:05 [PATCH v3] PCI: Data corruption happening due to race condition Hari Vyas
2018-07-03 9:05 ` Hari Vyas
2018-07-03 9:13 ` Lukas Wunner
2018-07-18 23:29 ` Bjorn Helgaas
2018-07-19 4:18 ` Benjamin Herrenschmidt
2018-07-19 14:04 ` Hari Vyas
2018-07-19 18:55 ` Lukas Wunner
2018-07-20 4:27 ` Benjamin Herrenschmidt
2018-07-27 22:25 ` Bjorn Helgaas
2018-07-28 0:45 ` Benjamin Herrenschmidt
2018-07-31 11:21 ` Michael Ellerman
2018-07-19 17:41 ` Bjorn Helgaas
2018-07-20 9:16 ` Hari Vyas
2018-07-20 12:20 ` Bjorn Helgaas
2018-07-31 16:37 ` Bjorn Helgaas
2018-08-15 3:35 ` PCIe enable device races (Was: [PATCH v3] PCI: Data corruption happening due to race condition) Benjamin Herrenschmidt
2018-08-15 4:16 ` Benjamin Herrenschmidt
2018-08-15 4:44 ` Benjamin Herrenschmidt
2018-08-15 5:21 ` [RFC PATCH] pci: Proof of concept at fixing pci_enable_device/bridge races Benjamin Herrenschmidt
2018-08-15 19:09 ` PCIe enable device races (Was: [PATCH v3] PCI: Data corruption happening due to race condition) Bjorn Helgaas
2018-08-15 21:50 ` [RFC PATCH] pci: Proof of concept at fixing pci_enable_device/bridge races Benjamin Herrenschmidt
2018-08-15 22:40 ` Guenter Roeck
2018-08-15 23:38 ` Benjamin Herrenschmidt
2018-08-20 1:31 ` Guenter Roeck
2018-08-17 3:07 ` Bjorn Helgaas [this message]
2018-08-17 3:42 ` Benjamin Herrenschmidt
2018-08-15 18:50 ` PCIe enable device races (Was: [PATCH v3] PCI: Data corruption happening due to race condition) Bjorn Helgaas
2018-08-15 21:52 ` Benjamin Herrenschmidt
2018-08-15 23:23 ` Benjamin Herrenschmidt
2018-08-16 7:58 ` Konstantin Khlebnikov
2018-08-16 8:02 ` Benjamin Herrenschmidt
2018-08-16 9:22 ` Hari Vyas
2018-08-16 10:10 ` Benjamin Herrenschmidt
2018-08-16 10:11 ` Benjamin Herrenschmidt
2018-08-16 10:26 ` Lukas Wunner
2018-08-16 10:47 ` Hari Vyas
2018-08-16 23:20 ` Benjamin Herrenschmidt
2018-08-16 23:17 ` Benjamin Herrenschmidt
2018-08-17 0:43 ` Benjamin Herrenschmidt
2018-08-16 19:43 ` Jens Axboe
2018-08-16 21:37 ` Benjamin Herrenschmidt
2018-08-16 21:56 ` Jens Axboe
2018-08-16 23:09 ` Benjamin Herrenschmidt
2018-08-17 0:14 ` Jens Axboe
2018-08-16 12:28 ` Lukas Wunner
2018-08-16 23:25 ` Benjamin Herrenschmidt
2018-08-17 1:12 ` Benjamin Herrenschmidt
2018-08-17 16:39 ` Lukas Wunner
2018-08-18 3:37 ` Benjamin Herrenschmidt
2018-08-18 9:22 ` Lukas Wunner
2018-08-18 13:11 ` 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=20180817030741.GC10316@bhelgaas-glaptop.roam.corp.google.com \
--to=helgaas@kernel.org \
--cc=axboe@kernel.dk \
--cc=benh@kernel.crashing.org \
--cc=bhelgaas@google.com \
--cc=hari.vyas@broadcom.com \
--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).