linux-stable/arch/s390
Niklas Schnelle 38c74f2f23 s390/pci: fix leak of PCI device structure
commit 0b13525c20 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-03-25 09:04:05 +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-02-03 23:28:39 +01:00
configs s390: update defconfigs 2020-11-12 12:10:36 +01:00
crypto mm, treewide: rename kzfree() to kfree_sensitive() 2020-08-07 11:33:22 -07:00
hypfs fs_parse: fold fs_parameter_desc/fs_parameter_spec 2020-02-07 14:48:37 -05:00
include s390/pci: fix leak of PCI device structure 2021-03-25 09:04:05 +01:00
kernel s390/vtime: fix increased steal time accounting 2021-03-25 09:04:05 +01:00
kvm KVM: s390: remove diag318 reset code 2020-11-11 09:31:52 +01:00
lib s390/test_unwind: fix CALL_ON_STACK tests 2020-12-30 11:53:56 +01:00
mm KVM: s390: pv: Mark mm as protected after the set secure parameters and improve cleanup 2020-11-11 09:31:48 +01:00
net s390/bpf: Fix multiple tail calls 2020-09-14 18:21:31 -07:00
oprofile s390/unwind: introduce stack unwind API 2019-05-02 13:54:11 +02:00
pci s390/pci: fix leak of PCI device structure 2021-03-25 09:04:05 +01:00
purgatory s390/kexec_file: fix diag308 subcode when loading crash kernel 2020-12-30 11:54:08 +01:00
tools .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
Kbuild s390/numa: move code to arch/s390/kernel 2020-08-11 18:16:55 +02:00
Kconfig vhost,vdpa,virtio: cleanups, fixes 2020-10-23 11:00:57 -07:00
Kconfig.debug s390/mm,ptdump: convert to generic page table dumper 2020-09-14 11:38:34 +02:00
Makefile kbuild: remove cc-option test of -ffreestanding 2020-07-07 11:13:10 +09:00