Skip to content

Commit 4224ad0

Browse files
author
Mete Durlu
committed
s390/pci: Fix potential double remove of hotplug slot
JIRA: https://issues.redhat.com/browse/RHEL-94944 commit c4a585e Author: Niklas Schnelle <schnelle@linux.ibm.com> Date: Mon Nov 25 16:02:38 2024 +0100 s390/pci: Fix potential double remove of hotplug slot In commit 6ee600b ("s390/pci: remove hotplug slot when releasing the device") the zpci_exit_slot() was moved from zpci_device_reserved() to zpci_release_device() with the intention of keeping the hotplug slot around until the device is actually removed. Now zpci_release_device() is only called once all references are dropped. Since the zPCI subsystem only drops its reference once the device is in the reserved state it follows that zpci_release_device() must only deal with devices in the reserved state. Despite that it contains code to tear down from both configured and standby state. For the standby case this already includes the removal of the hotplug slot so would cause a double removal if a device was ever removed in either configured or standby state. Instead of causing a potential double removal in a case that should never happen explicitly WARN_ON() if a device in non-reserved state is released and get rid of the dead code cases. Fixes: 6ee600b ("s390/pci: remove hotplug slot when releasing the device") Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com> Reviewed-by: Gerd Bayer <gbayer@linux.ibm.com> Tested-by: Gerd Bayer <gbayer@linux.ibm.com> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Mete Durlu <mdurlu@redhat.com>
1 parent 6a6fa8e commit 4224ad0

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

arch/s390/pci/pci.c

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -940,39 +940,23 @@ void zpci_device_reserved(struct zpci_dev *zdev)
940940
void zpci_release_device(struct kref *kref)
941941
{
942942
struct zpci_dev *zdev = container_of(kref, struct zpci_dev, kref);
943-
int ret;
944943

945-
if (zdev->has_hp_slot)
946-
zpci_exit_slot(zdev);
944+
WARN_ON(zdev->state != ZPCI_FN_STATE_RESERVED);
947945

948946
if (zdev->zbus->bus)
949947
zpci_bus_remove_device(zdev, false);
950948

951949
if (zdev_enabled(zdev))
952950
zpci_disable_device(zdev);
953951

954-
switch (zdev->state) {
955-
case ZPCI_FN_STATE_CONFIGURED:
956-
ret = sclp_pci_deconfigure(zdev->fid);
957-
zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret);
958-
fallthrough;
959-
case ZPCI_FN_STATE_STANDBY:
960-
if (zdev->has_hp_slot)
961-
zpci_exit_slot(zdev);
962-
spin_lock(&zpci_list_lock);
963-
list_del(&zdev->entry);
964-
spin_unlock(&zpci_list_lock);
965-
zpci_dbg(3, "rsv fid:%x\n", zdev->fid);
966-
fallthrough;
967-
case ZPCI_FN_STATE_RESERVED:
968-
if (zdev->has_resources)
969-
zpci_cleanup_bus_resources(zdev);
970-
zpci_bus_device_unregister(zdev);
971-
zpci_destroy_iommu(zdev);
972-
fallthrough;
973-
default:
974-
break;
975-
}
952+
if (zdev->has_hp_slot)
953+
zpci_exit_slot(zdev);
954+
955+
if (zdev->has_resources)
956+
zpci_cleanup_bus_resources(zdev);
957+
958+
zpci_bus_device_unregister(zdev);
959+
zpci_destroy_iommu(zdev);
976960
zpci_dbg(3, "rem fid:%x\n", zdev->fid);
977961
kfree_rcu(zdev, rcu);
978962
}

0 commit comments

Comments
 (0)