Skip to content

Commit f782201

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: core: Revert "Make sure that targets outlive devices"
Revert the patch series "Call blk_mq_free_tag_set() earlier" because it introduces a deadlock if the scsi_remove_host() caller holds a reference on a device, target or host. Link: https://lore.kernel.org/r/[email protected] Fixes: fe44260 ("scsi: core: Make sure that targets outlive devices") Reported-by: [email protected] Tested-by: Kenneth R. Crudup <[email protected]> Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent d94b2d0 commit f782201

File tree

3 files changed

+3
-21
lines changed

3 files changed

+3
-21
lines changed

drivers/scsi/scsi_scan.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,6 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
521521
starget->state = STARGET_CREATED;
522522
starget->scsi_level = SCSI_2;
523523
starget->max_target_blocked = SCSI_DEFAULT_TARGET_BLOCKED;
524-
init_waitqueue_head(&starget->sdev_wq);
525-
526524
retry:
527525
spin_lock_irqsave(shost->host_lock, flags);
528526

drivers/scsi/scsi_sysfs.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,7 @@ static void scsi_device_cls_release(struct device *class_dev)
443443

444444
static void scsi_device_dev_release_usercontext(struct work_struct *work)
445445
{
446-
struct scsi_device *sdev = container_of(work, struct scsi_device,
447-
ew.work);
448-
struct scsi_target *starget = sdev->sdev_target;
446+
struct scsi_device *sdev;
449447
struct device *parent;
450448
struct list_head *this, *tmp;
451449
struct scsi_vpd *vpd_pg80 = NULL, *vpd_pg83 = NULL;
@@ -454,6 +452,8 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
454452
unsigned long flags;
455453
struct module *mod;
456454

455+
sdev = container_of(work, struct scsi_device, ew.work);
456+
457457
mod = sdev->host->hostt->module;
458458

459459
scsi_dh_release_device(sdev);
@@ -516,9 +516,6 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
516516
kfree(sdev->inquiry);
517517
kfree(sdev);
518518

519-
if (starget && atomic_dec_return(&starget->sdev_count) == 0)
520-
wake_up(&starget->sdev_wq);
521-
522519
if (parent)
523520
put_device(parent);
524521
module_put(mod);
@@ -1538,14 +1535,6 @@ static void __scsi_remove_target(struct scsi_target *starget)
15381535
goto restart;
15391536
}
15401537
spin_unlock_irqrestore(shost->host_lock, flags);
1541-
1542-
/*
1543-
* After scsi_remove_target() returns its caller can remove resources
1544-
* associated with @starget, e.g. an rport or session. Wait until all
1545-
* devices associated with @starget have been removed to prevent that
1546-
* a SCSI error handling callback function triggers a use-after-free.
1547-
*/
1548-
wait_event(starget->sdev_wq, atomic_read(&starget->sdev_count) == 0);
15491538
}
15501539

15511540
/**
@@ -1656,9 +1645,6 @@ void scsi_sysfs_device_initialize(struct scsi_device *sdev)
16561645
list_add_tail(&sdev->same_target_siblings, &starget->devices);
16571646
list_add_tail(&sdev->siblings, &shost->__devices);
16581647
spin_unlock_irqrestore(shost->host_lock, flags);
1659-
1660-
atomic_inc(&starget->sdev_count);
1661-
16621648
/*
16631649
* device can now only be removed via __scsi_remove_device() so hold
16641650
* the target. Target will be held in CREATED state until something

include/scsi/scsi_device.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,6 @@ struct scsi_target {
309309
struct list_head devices;
310310
struct device dev;
311311
struct kref reap_ref; /* last put renders target invisible */
312-
atomic_t sdev_count;
313-
wait_queue_head_t sdev_wq;
314312
unsigned int channel;
315313
unsigned int id; /* target id ... replace
316314
* scsi_device.id eventually */

0 commit comments

Comments
 (0)