<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/drivers/pci/iov.c, branch linux-5.10.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.</subtitle>
<id>https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-5.10.y</id>
<link rel='self' href='https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-5.10.y'/>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/'/>
<updated>2026-03-04T12:20:21Z</updated>
<entry>
<title>PCI/IOV: Fix race between SR-IOV enable/disable and hotplug</title>
<updated>2026-03-04T12:20:21Z</updated>
<author>
<name>Niklas Schnelle</name>
<email>schnelle@linux.ibm.com</email>
</author>
<published>2025-12-16T22:14:03Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=3cddde484471c602bea04e6f384819d336a1ff84'/>
<id>urn:sha1:3cddde484471c602bea04e6f384819d336a1ff84</id>
<content type='text'>
[ Upstream commit a5338e365c4559d7b4d7356116b0eb95b12e08d5 ]

Commit 05703271c3cd ("PCI/IOV: Add PCI rescan-remove locking when
enabling/disabling SR-IOV") tried to fix a race between the VF removal
inside sriov_del_vfs() and concurrent hot unplug by taking the PCI
rescan/remove lock in sriov_del_vfs(). Similarly the PCI rescan/remove lock
was also taken in sriov_add_vfs() to protect addition of VFs.

This approach however causes deadlock on trying to remove PFs with SR-IOV
enabled because PFs disable SR-IOV during removal and this removal happens
under the PCI rescan/remove lock. So the original fix had to be reverted.

Instead of taking the PCI rescan/remove lock in sriov_add_vfs() and
sriov_del_vfs(), fix the race that occurs with SR-IOV enable and disable vs
hotplug higher up in the callchain by taking the lock in
sriov_numvfs_store() before calling into the driver's sriov_configure()
callback.

Fixes: 05703271c3cd ("PCI/IOV: Add PCI rescan-remove locking when enabling/disabling SR-IOV")
Reported-by: Benjamin Block &lt;bblock@linux.ibm.com&gt;
Signed-off-by: Niklas Schnelle &lt;schnelle@linux.ibm.com&gt;
Signed-off-by: Bjorn Helgaas &lt;bhelgaas@google.com&gt;
Reviewed-by: Benjamin Block &lt;bblock@linux.ibm.com&gt;
Reviewed-by: Gerd Bayer &lt;gbayer@linux.ibm.com&gt;
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20251216-revert_sriov_lock-v3-2-dac4925a7621@linux.ibm.com
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>Revert "PCI/IOV: Add PCI rescan-remove locking when enabling/disabling SR-IOV"</title>
<updated>2026-03-04T12:20:21Z</updated>
<author>
<name>Niklas Schnelle</name>
<email>schnelle@linux.ibm.com</email>
</author>
<published>2025-12-16T22:14:02Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=f61cdd7e9b67bb8961b0a81bf294b78343e5db05'/>
<id>urn:sha1:f61cdd7e9b67bb8961b0a81bf294b78343e5db05</id>
<content type='text'>
[ Upstream commit 2fa119c0e5e528453ebae9e70740e8d2d8c0ed5a ]

This reverts commit 05703271c3cd ("PCI/IOV: Add PCI rescan-remove locking
when enabling/disabling SR-IOV"), which causes a deadlock by recursively
taking pci_rescan_remove_lock when sriov_del_vfs() is called as part of
pci_stop_and_remove_bus_device(). For example with the following sequence
of commands:

  $ echo &lt;NUM&gt; &gt; /sys/bus/pci/devices/&lt;pf&gt;/sriov_numvfs
  $ echo 1 &gt; /sys/bus/pci/devices/&lt;pf&gt;/remove

A trimmed trace of the deadlock on a mlx5 device is as below:

  zsh/5715 is trying to acquire lock:
  000002597926ef50 (pci_rescan_remove_lock){+.+.}-{3:3}, at: sriov_disable+0x34/0x140

  but task is already holding lock:
  000002597926ef50 (pci_rescan_remove_lock){+.+.}-{3:3}, at: pci_stop_and_remove_bus_device_locked+0x24/0x80
  ...
  Call Trace:
   [&lt;00000259778c4f90&gt;] dump_stack_lvl+0xc0/0x110
   [&lt;00000259779c844e&gt;] print_deadlock_bug+0x31e/0x330
   [&lt;00000259779c1908&gt;] __lock_acquire+0x16c8/0x32f0
   [&lt;00000259779bffac&gt;] lock_acquire+0x14c/0x350
   [&lt;00000259789643a6&gt;] __mutex_lock_common+0xe6/0x1520
   [&lt;000002597896413c&gt;] mutex_lock_nested+0x3c/0x50
   [&lt;00000259784a07e4&gt;] sriov_disable+0x34/0x140
   [&lt;00000258f7d6dd80&gt;] mlx5_sriov_disable+0x50/0x80 [mlx5_core]
   [&lt;00000258f7d5745e&gt;] remove_one+0x5e/0xf0 [mlx5_core]
   [&lt;00000259784857fc&gt;] pci_device_remove+0x3c/0xa0
   [&lt;000002597851012e&gt;] device_release_driver_internal+0x18e/0x280
   [&lt;000002597847ae22&gt;] pci_stop_bus_device+0x82/0xa0
   [&lt;000002597847afce&gt;] pci_stop_and_remove_bus_device_locked+0x5e/0x80
   [&lt;00000259784972c2&gt;] remove_store+0x72/0x90
   [&lt;0000025977e6661a&gt;] kernfs_fop_write_iter+0x15a/0x200
   [&lt;0000025977d7241c&gt;] vfs_write+0x24c/0x300
   [&lt;0000025977d72696&gt;] ksys_write+0x86/0x110
   [&lt;000002597895b61c&gt;] __do_syscall+0x14c/0x400
   [&lt;000002597896e0ee&gt;] system_call+0x6e/0x90

This alone is not a complete fix as it restores the issue the cited commit
tried to solve. A new fix will be provided as a follow on.

Fixes: 05703271c3cd ("PCI/IOV: Add PCI rescan-remove locking when enabling/disabling SR-IOV")
Reported-by: Benjamin Block &lt;bblock@linux.ibm.com&gt;
Signed-off-by: Niklas Schnelle &lt;schnelle@linux.ibm.com&gt;
Signed-off-by: Bjorn Helgaas &lt;bhelgaas@google.com&gt;
Reviewed-by: Benjamin Block &lt;bblock@linux.ibm.com&gt;
Acked-by: Gerd Bayer &lt;gbayer@linux.ibm.com&gt;
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20251216-revert_sriov_lock-v3-1-dac4925a7621@linux.ibm.com
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>PCI/IOV: Add PCI rescan-remove locking when enabling/disabling SR-IOV</title>
<updated>2025-10-29T13:01:12Z</updated>
<author>
<name>Niklas Schnelle</name>
<email>schnelle@linux.ibm.com</email>
</author>
<published>2025-08-26T08:52:08Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=1e8a80290f964bdbad225221c8a1594c7e01c8fd'/>
<id>urn:sha1:1e8a80290f964bdbad225221c8a1594c7e01c8fd</id>
<content type='text'>
commit 05703271c3cdcc0f2a8cf6ebdc45892b8ca83520 upstream.

Before disabling SR-IOV via config space accesses to the parent PF,
sriov_disable() first removes the PCI devices representing the VFs.

Since commit 9d16947b7583 ("PCI: Add global pci_lock_rescan_remove()")
such removal operations are serialized against concurrent remove and
rescan using the pci_rescan_remove_lock. No such locking was ever added
in sriov_disable() however. In particular when commit 18f9e9d150fc
("PCI/IOV: Factor out sriov_add_vfs()") factored out the PCI device
removal into sriov_del_vfs() there was still no locking around the
pci_iov_remove_virtfn() calls.

On s390 the lack of serialization in sriov_disable() may cause double
remove and list corruption with the below (amended) trace being observed:

  PSW:  0704c00180000000 0000000c914e4b38 (klist_put+56)
  GPRS: 000003800313fb48 0000000000000000 0000000100000001 0000000000000001
	00000000f9b520a8 0000000000000000 0000000000002fbd 00000000f4cc9480
	0000000000000001 0000000000000000 0000000000000000 0000000180692828
	00000000818e8000 000003800313fe2c 000003800313fb20 000003800313fad8
  #0 [3800313fb20] device_del at c9158ad5c
  #1 [3800313fb88] pci_remove_bus_device at c915105ba
  #2 [3800313fbd0] pci_iov_remove_virtfn at c9152f198
  #3 [3800313fc28] zpci_iov_remove_virtfn at c90fb67c0
  #4 [3800313fc60] zpci_bus_remove_device at c90fb6104
  #5 [3800313fca0] __zpci_event_availability at c90fb3dca
  #6 [3800313fd08] chsc_process_sei_nt0 at c918fe4a2
  #7 [3800313fd60] crw_collect_info at c91905822
  #8 [3800313fe10] kthread at c90feb390
  #9 [3800313fe68] __ret_from_fork at c90f6aa64
  #10 [3800313fe98] ret_from_fork at c9194f3f2.

This is because in addition to sriov_disable() removing the VFs, the
platform also generates hot-unplug events for the VFs. This being the
reverse operation to the hotplug events generated by sriov_enable() and
handled via pdev-&gt;no_vf_scan. And while the event processing takes
pci_rescan_remove_lock and checks whether the struct pci_dev still exists,
the lack of synchronization makes this checking racy.

Other races may also be possible of course though given that this lack of
locking persisted so long observable races seem very rare. Even on s390 the
list corruption was only observed with certain devices since the platform
events are only triggered by config accesses after the removal, so as long
as the removal finished synchronously they would not race. Either way the
locking is missing so fix this by adding it to the sriov_del_vfs() helper.

Just like PCI rescan-remove, locking is also missing in sriov_add_vfs()
including for the error case where pci_stop_and_remove_bus_device() is
called without the PCI rescan-remove lock being held. Even in the non-error
case, adding new PCI devices and buses should be serialized via the PCI
rescan-remove lock. Add the necessary locking.

Fixes: 18f9e9d150fc ("PCI/IOV: Factor out sriov_add_vfs()")
Signed-off-by: Niklas Schnelle &lt;schnelle@linux.ibm.com&gt;
Signed-off-by: Bjorn Helgaas &lt;bhelgaas@google.com&gt;
Reviewed-by: Benjamin Block &lt;bblock@linux.ibm.com&gt;
Reviewed-by: Farhan Ali &lt;alifm@linux.ibm.com&gt;
Reviewed-by: Julian Ruess &lt;julianr@linux.ibm.com&gt;
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20250826-pci_fix_sriov_disable-v1-1-2d0bc938f2a3@linux.ibm.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>PCI/IOV: Mark VFs as not implementing PCI_COMMAND_MEMORY</title>
<updated>2020-09-21T20:42:11Z</updated>
<author>
<name>Matthew Rosato</name>
<email>mjrosato@linux.ibm.com</email>
</author>
<published>2020-09-10T14:59:55Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=12856e7acde4702b7c3238c15fcba86ff6aa507f'/>
<id>urn:sha1:12856e7acde4702b7c3238c15fcba86ff6aa507f</id>
<content type='text'>
For VFs, the Memory Space Enable bit in the Command Register is
hard-wired to 0.

Add a new bit to signify devices where the Command Register Memory
Space Enable bit does not control the device's response to MMIO
accesses.

Fixes: abafbc551fdd ("vfio-pci: Invalidate mmaps and block MMIO access on disabled memory")
Signed-off-by: Matthew Rosato &lt;mjrosato@linux.ibm.com&gt;
Acked-by: Bjorn Helgaas &lt;bhelgaas@google.com&gt;
Signed-off-by: Alex Williamson &lt;alex.williamson@redhat.com&gt;
</content>
</entry>
<entry>
<title>s390/pci: create links between PFs and VFs</title>
<updated>2020-05-20T08:22:51Z</updated>
<author>
<name>Niklas Schnelle</name>
<email>schnelle@linux.ibm.com</email>
</author>
<published>2020-04-28T09:54:46Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=e5794cf1a270d813a5b9373a6876487d4d154195'/>
<id>urn:sha1:e5794cf1a270d813a5b9373a6876487d4d154195</id>
<content type='text'>
On s390 PCI Virtual Functions (VFs) are scanned by firmware and are made
available to Linux via the hot-plug interface. As such the common code
path of doing the scan directly using the parent Physical Function (PF)
is not used and fenced off with the no_vf_scan attribute.

Even if the partition created the VFs itself e.g. using the sriov_numvfs
attribute of a PF, the PF/VF links thus need to be established after the
fact. To do this when a VF is plugged we scan through all functions on
the same zbus and test whether they are the parent PF in which case we
establish the necessary links.

With these links established there is now no more need to fence off
pci_iov_remove_virtfn() for pdev-&gt;no_vf_scan as the common code now
works fine.

Signed-off-by: Niklas Schnelle &lt;schnelle@linux.ibm.com&gt;
Acked-by: Bjorn Helgaas &lt;bhelgaas@google.com&gt;
Reviewed-by: Pierre Morel &lt;pmorel@linux.ibm.com&gt;
Link: https://lore.kernel.org/r/20200506154139.90609-3-schnelle@linux.ibm.com
Signed-off-by: Vasily Gorbik &lt;gor@linux.ibm.com&gt;
</content>
</entry>
<entry>
<title>PCI/IOV: Introduce pci_iov_sysfs_link() function</title>
<updated>2020-05-20T08:22:50Z</updated>
<author>
<name>Niklas Schnelle</name>
<email>schnelle@linux.ibm.com</email>
</author>
<published>2020-04-27T14:25:27Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=a1ceea67f2e5b73cebd456e7fb463b3052bc6344'/>
<id>urn:sha1:a1ceea67f2e5b73cebd456e7fb463b3052bc6344</id>
<content type='text'>
Currently pci_iov_add_virtfn() scans the SR-IOV BARs, adds the VF to the
bus and also creates the sysfs links between the newly added VF and its
parent PF.

With pdev-&gt;no_vf_scan fencing off the entire pci_iov_add_virtfn() call
s390 as the sole pdev-&gt;no_vf_scan user thus ends up missing these sysfs
links which are required for example by QEMU/libvirt.

Instead of duplicating the code refactor pci_iov_add_virtfn() to make
sysfs link creation callable separately.

Signed-off-by: Niklas Schnelle &lt;schnelle@linux.ibm.com&gt;
Acked-by: Bjorn Helgaas &lt;bhelgaas@google.com&gt;
Reviewed-by: Pierre Morel &lt;pmorel@linux.ibm.com&gt;
Link: https://lore.kernel.org/r/20200506154139.90609-1-schnelle@linux.ibm.com
Signed-off-by: Vasily Gorbik &lt;gor@linux.ibm.com&gt;
</content>
</entry>
<entry>
<title>PCI/IOV: Fix memory leak in pci_iov_add_virtfn()</title>
<updated>2019-12-09T21:51:32Z</updated>
<author>
<name>Navid Emamdoost</name>
<email>navid.emamdoost@gmail.com</email>
</author>
<published>2019-11-25T19:52:52Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=8c386cc817878588195dde38e919aa6ba9409d58'/>
<id>urn:sha1:8c386cc817878588195dde38e919aa6ba9409d58</id>
<content type='text'>
In the implementation of pci_iov_add_virtfn() the allocated virtfn is
leaked if pci_setup_device() fails. The error handling is not calling
pci_stop_and_remove_bus_device(). Change the goto label to failed2.

Fixes: 156c55325d30 ("PCI: Check for pci_setup_device() failure in pci_iov_add_virtfn()")
Link: https://lore.kernel.org/r/20191125195255.23740-1-navid.emamdoost@gmail.com
Signed-off-by: Navid Emamdoost &lt;navid.emamdoost@gmail.com&gt;
Signed-off-by: Bjorn Helgaas &lt;bhelgaas@google.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'pci/trivial'</title>
<updated>2019-11-28T14:54:55Z</updated>
<author>
<name>Bjorn Helgaas</name>
<email>bhelgaas@google.com</email>
</author>
<published>2019-11-28T14:54:55Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=7e124c40517218e079e580909de2652bddb60ff5'/>
<id>urn:sha1:7e124c40517218e079e580909de2652bddb60ff5</id>
<content type='text'>
  - Fix typos and comments (Bjorn Helgaas)

  - Fix Kconfig whitespace errors (Krzysztof Kozlowski)

* pci/trivial:
  PCI: Fix indentation
  PCI: Fix typos
  PCI: Remove useless comments and tidy others
  PCI: Remove unnecessary includes

# Conflicts:
#	drivers/pci/probe.c
</content>
</entry>
<entry>
<title>PCI: Remove unnecessary includes</title>
<updated>2019-10-17T20:18:44Z</updated>
<author>
<name>Bjorn Helgaas</name>
<email>bhelgaas@google.com</email>
</author>
<published>2019-10-01T22:51:59Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=eceb86028d23f19d88202153de13201b92300b27'/>
<id>urn:sha1:eceb86028d23f19d88202153de13201b92300b27</id>
<content type='text'>
Remove unnecessary includes.

Signed-off-by: Bjorn Helgaas &lt;bhelgaas@google.com&gt;
</content>
</entry>
<entry>
<title>PCI/IOV: Serialize sysfs sriov_numvfs reads vs writes</title>
<updated>2019-10-15T21:39:12Z</updated>
<author>
<name>Pierre Crégut</name>
<email>pierre.cregut@orange.com</email>
</author>
<published>2019-09-11T07:27:36Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=35ff867b76576e32f34c698ccd11343f7d616204'/>
<id>urn:sha1:35ff867b76576e32f34c698ccd11343f7d616204</id>
<content type='text'>
When sriov_numvfs is being updated, we call the driver-&gt;sriov_configure()
function, which may enable VFs and call probe functions, which may make new
devices visible.  This all happens before before sriov_numvfs_store()
updates sriov-&gt;num_VFs, so previously, concurrent sysfs reads of
sriov_numvfs returned stale values.

Serialize the sysfs read vs the write so the read returns the correct
num_VFs value.

[bhelgaas: hold device_lock instead of checking mutex_is_locked()]
Link: https://bugzilla.kernel.org/show_bug.cgi?id=202991
Link: https://lore.kernel.org/r/20190911072736.32091-1-pierre.cregut@orange.com
Signed-off-by: Pierre Crégut &lt;pierre.cregut@orange.com&gt;
Signed-off-by: Bjorn Helgaas &lt;bhelgaas@google.com&gt;
</content>
</entry>
</feed>
