mirror-linux/arch/s390
Benjamin Block 4cb92fa763 s390/pci: Fix cyclic dead-lock in zpci_zdev_put() and zpci_scan_devices()
When triggering PCI device recovery by writing into the SysFS attribute
`recover` of a Physical Function with existing child SR-IOV Virtual
Functions, lockdep is reporting a possible deadlock between three
threads:

         Thread (A)             Thread (B)             Thread (C)
             |                      |                      |
      recover_store()      zpci_scan_devices()    zpci_scan_devices()
lock(pci_rescan_remove_lock)        |                      |
             |                      |                      |
             |                      |            zpci_bus_scan_busses()
             |                      |             lock(zbus_list_lock)
             |              zpci_add_device()              |
             |          lock(zpci_add_remove_lock)         |
             |                      |                      ┴
             |                      |             zpci_bus_scan_bus()
             |                      |         lock(pci_rescan_remove_lock)
             ┴                      |
      zpci_zdev_put()               |
 lock(zpci_add_remove_lock)         |
                                    ┴
                              zpci_bus_get()
                           lock(zbus_list_lock)

In zpci_bus_scan_busses() the `zbus_list_lock` is taken for the whole
duration of the function, which also includes taking
`pci_rescan_remove_lock`, among other things. But `zbus_list_lock` only
really needs to protect the modification of the global registration
`zbus_list`, it can be dropped while the functions within the list
iteration run; this way we break the cycle above.

Break up zpci_bus_scan_busses() into an "iterator" zpci_bus_get_next()
that iterates over `zbus_list` element by element, and acquires and
releases `zbus_list_lock` as necessary, but never keep holding it.
References to `zpci_bus` objects are also acquired and released.

The reference counting on `zpci_bus` objects is also changed so that all
put() and get() operations are done under the protection of
`zbus_list_lock`, and if the operation results in a modification of
`zpci_bus_list`, this modification is done in the same critical section
(apart the very first initialization). This way objects are never seen
on the list that are about to be released and/or half-initialized.

Fixes: 14c87ba812 ("s390/pci: separate zbus registration from scanning")
Suggested-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Niklas Schnelle <schnelle@linux.ibm.com>
Reviewed-by: Gerd Bayer <gbayer@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2025-12-14 11:03:58 +01:00
..
appldata s390: Remove KMSG_COMPONENT macro 2025-11-24 11:45:21 +01:00
boot s390/boot: Use entire page for PTEs 2025-12-07 16:15:19 +01:00
configs This update includes the following changes: 2025-12-03 11:28:38 -08:00
crypto Crypto library updates for 6.19 2025-12-02 18:01:03 -08:00
hypfs Some filesystems use a kinda-sorta controlled dentry refcount leak to pin 2025-12-05 14:36:21 -08:00
include s390/ipl: Clear SBP flag when bootprog is set 2025-12-14 11:03:57 +01:00
kernel s390/ipl: Clear SBP flag when bootprog is set 2025-12-14 11:03:57 +01:00
kvm ARM: 2025-12-05 17:01:20 -08:00
lib s390: Remove superfluous newlines from inline assemblies 2025-09-29 13:52:08 +02:00
mm KVM: s390: Fix gmap_helper_zap_one_page() again 2025-12-08 13:06:14 +01:00
net bpf-next-6.19 2025-12-03 16:54:54 -08:00
pci s390/pci: Fix cyclic dead-lock in zpci_zdev_put() and zpci_scan_devices() 2025-12-14 11:03:58 +01:00
purgatory kbuild: Add '-fms-extensions' to areas with dedicated CFLAGS 2025-10-30 21:26:28 -04:00
tools s390: Add Dat-Enhancement facility 1 to architecture level set 2025-11-06 14:12:30 +01:00
Kbuild - An extensive rework of kexec and crash Kconfig from Eric DeVolder 2023-08-29 14:53:51 -07:00
Kconfig s390/pci: Migrate s390 IRQ logic to IRQ domain API 2025-12-07 16:15:23 +01:00
Kconfig.debug s390/mm: Add configurable STRICT_MM_TYPECHECKS 2025-03-11 15:27:34 +01:00
Makefile s390 updates for 6.19 merge window 2025-12-02 16:37:00 -08:00
Makefile.postlink kbuild: Create intermediate vmlinux build with relocations preserved 2025-03-17 00:29:50 +09:00