linux-stable/drivers/pci
Hari Vyas 44bda4b7d2 PCI: Fix is_added/is_busmaster race condition
When a PCI device is detected, pdev->is_added is set to 1 and proc and
sysfs entries are created.

When the device is removed, pdev->is_added is checked for one and then
device is detached with clearing of proc and sys entries and at end,
pdev->is_added is set to 0.

is_added and is_busmaster are bit fields in pci_dev structure sharing same
memory location.

A strange issue was observed with multiple removal and rescan of a PCIe
NVMe device using sysfs commands where is_added flag was observed as zero
instead of one while removing device and proc,sys entries are not cleared.
This causes issue in later device addition with warning message
"proc_dir_entry" already registered.

Debugging revealed a race condition between the PCI core setting the
is_added bit in pci_bus_add_device() and the NVMe driver reset work-queue
setting the is_busmaster bit in pci_set_master().  As these fields are not
handled atomically, that clears the is_added bit.

Move the is_added bit to a separate private flag variable and use atomic
functions to set and retrieve the device addition state.  This avoids the
race because is_added no longer shares a memory location with is_busmaster.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=200283
Signed-off-by: Hari Vyas <hari.vyas@broadcom.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Lukas Wunner <lukas@wunner.de>
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
2018-07-31 11:27:54 -05:00
..
controller PCI: mobiveil: Avoid integer overflow in IB_WIN_SIZE 2018-07-27 17:10:39 -05:00
endpoint PCI: endpoint: Fix NULL pointer dereference error when CONFIGFS is disabled 2018-07-09 15:19:51 -05:00
hotplug PCI: Fix is_added/is_busmaster race condition 2018-07-31 11:27:54 -05:00
pcie PCI/AER: Work around use-after-free in pcie_do_fatal_recovery() 2018-07-26 12:13:04 -05:00
switch vfs: do bulk POLL* -> EPOLL* replacement 2018-02-11 14:34:03 -08:00
access.c Merge branch 'pci/vpd' 2018-04-04 13:28:40 -05:00
ats.c PCI: Add "pci=noats" boot parameter 2018-05-10 17:56:02 -05:00
bus.c PCI: Fix is_added/is_busmaster race condition 2018-07-31 11:27:54 -05:00
ecam.c PCI: Add SPDX GPL-2.0 to replace GPL v2 boilerplate 2018-01-28 15:48:29 -06:00
host-bridge.c PCI: Tidy comments 2018-03-19 14:20:43 -05:00
iov.c PCI/IOV: Reset total_VFs limit after detaching PF driver 2018-06-29 15:08:52 -05:00
irq.c PCI: Add wrappers for dev_printk() 2018-01-18 12:55:24 -06:00
Kconfig PCI: Collect all native drivers under drivers/pci/controller/ 2018-06-08 07:50:11 -05:00
Makefile PCI: Initialize endpoint library before controllers 2018-06-26 15:37:37 -05:00
mmap.c PCI: Tidy comments 2018-03-19 14:20:43 -05:00
msi.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
of.c PCI: OF: Fix I/O space page leak 2018-07-18 15:40:26 -05:00
pci-acpi.c PCI: shpchp: Add shpchp_is_native() 2018-06-04 12:08:06 -05:00
pci-driver.c PCI/IOV: Reset total_VFs limit after detaching PF driver 2018-06-29 15:08:52 -05:00
pci-label.c PCI: Tidy comments 2018-03-19 14:20:43 -05:00
pci-mid.c PCI: Add SPDX GPL-2.0 to replace GPL v2 boilerplate 2018-01-28 15:48:29 -06:00
pci-pf-stub.c PCI/IOV: Add pci-pf-stub driver for PFs that only enable VFs 2018-04-24 16:47:16 -05:00
pci-stub.c PCI: Tidy comments 2018-03-19 14:20:43 -05:00
pci-sysfs.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
pci.c PCI: OF: Fix I/O space page leak 2018-07-18 15:40:26 -05:00
pci.h PCI: Fix is_added/is_busmaster race condition 2018-07-31 11:27:54 -05:00
probe.c PCI: Fix is_added/is_busmaster race condition 2018-07-31 11:27:54 -05:00
proc.c proc: introduce proc_create_seq{,_data} 2018-05-16 07:23:35 +02:00
quirks.c Merge branch 'pci/trivial' 2018-06-06 16:10:51 -05:00
remove.c PCI: Fix is_added/is_busmaster race condition 2018-07-31 11:27:54 -05:00
rom.c PCI: Tidy comments 2018-03-19 14:20:43 -05:00
search.c PCI: Tidy comments 2018-03-19 14:20:43 -05:00
setup-bus.c PCI: Move resource distribution for single bridge outside loop 2018-06-04 12:08:06 -05:00
setup-irq.c PCI: Tidy comments 2018-03-19 14:20:43 -05:00
setup-res.c PCI: Remove messages about reassigning resources 2018-04-11 08:46:50 -05:00
slot.c Merge branch 'pci/misc' 2018-04-04 13:27:45 -05:00
syscall.c PCI: Tidy comments 2018-03-19 14:20:43 -05:00
vc.c Merge branch 'pci/spdx' into next 2018-02-01 11:40:07 -06:00
vpd.c pci-v4.17-changes 2018-04-06 18:31:06 -07:00
xen-pcifront.c PCI: Tidy comments 2018-03-19 14:20:43 -05:00