linux/arch/s390
Niklas Schnelle 0b13525c20 s390/pci: fix leak of PCI device structure
In commit 05bc1be6db ("s390/pci: create zPCI bus") we removed the
pci_dev_put() call matching the earlier pci_get_slot() done as part of
__zpci_event_availability(). This was based on the wrong understanding
that the device_put() done as part of pci_destroy_device() would counter
the pci_get_slot() when it only counters the initial reference. This
same understanding and existing bad example also lead to not doing
a pci_dev_put() in zpci_remove_device().

Since releasing the PCI devices, unlike releasing the PCI slot, does not
print any debug message for testing I added one in pci_release_dev().
This revealed that we are indeed leaking the PCI device on PCI
hotunplug. Further testing also revealed another missing pci_dev_put() in
disable_slot().

Fix this by adding the missing pci_dev_put() in disable_slot() and fix
zpci_remove_device() with the correct pci_dev_put() calls. Also instead
of calling pci_get_slot() in __zpci_event_availability() to determine if
a PCI device is registered and then doing the same again in
zpci_remove_device() do this once in zpci_remove_device() which makes
sure that the pdev in __zpci_event_availability() is only used for the
result of pci_scan_single_device() which does not need a reference count
decremnt as its ownership goes to the PCI bus.

Also move the check if zdev->zbus->bus is set into zpci_remove_device()
since it may be that we're removing a device with devfn != 0 which never
had a PCI bus. So we can still set the pdev->error_state to indicate
that the device is not usable anymore, add a flag to set the error state.

Fixes: 05bc1be6db ("s390/pci: create zPCI bus")
Cc: <stable@vger.kernel.org> # 5.8+: e1bff843cd s390/pci: remove superfluous zdev->zbus check
Cc: <stable@vger.kernel.org> # 5.8+: ba764dd703 s390/pci: refactor zpci_create_device()
Cc: <stable@vger.kernel.org> # 5.8+
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-03-15 19:10:56 +01:00
..
appldata s390/appldata: use struct_size() helper 2020-06-29 16:32:34 +02:00
boot s390: uv: Fix sysfs max number of VCPUs reporting 2021-01-27 13:00:04 +01:00
configs s390: remove IBM_PARTITION and CONFIGFS_FS from zfcpdump defconfig 2021-03-08 10:46:30 +01:00
crypto Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6 2021-02-21 17:23:56 -08:00
hypfs s390/hypfs: use store_tod_clock_ext() 2021-02-13 17:17:55 +01:00
include s390/pci: fix leak of PCI device structure 2021-03-15 19:10:56 +01:00
kernel s390/vtime: fix increased steal time accounting 2021-03-15 19:09:25 +01:00
kvm s390/time,idle: get rid of unsigned long long 2021-03-08 10:46:27 +01:00
lib s390: convert to generic entry 2021-01-19 12:29:26 +01:00
mm s390 updates for the 5.12 merge window #2 2021-02-26 14:12:32 -08:00
net bpf: Rename BPF_XADD and prepare to encode other atomics in .imm 2021-01-14 18:34:29 -08:00
pci s390/pci: fix leak of PCI device structure 2021-03-15 19:10:56 +01:00
purgatory - Add support for the hugetlb_cma command line option to allocate gigantic 2020-12-14 16:22:26 -08:00
tools s390/opcodes: rename selhhhr to selfhr 2021-02-24 00:31:22 +01:00
Kbuild s390/numa: move code to arch/s390/kernel 2020-08-11 18:16:55 +02:00
Kconfig Rework of the X86 irq stack handling: 2021-02-24 16:32:23 -08:00
Kconfig.debug s390: convert to generic entry 2021-01-19 12:29:26 +01:00
Makefile arch: s390: Remove CONFIG_OPROFILE support 2021-01-29 10:05:51 +05:30