Skip to content

Commit 70e8d05

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: core: Revert "Simplify LLD module reference counting"
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: 1a92837 ("scsi: core: Simplify LLD module reference counting") 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 2b36209 commit 70e8d05

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

drivers/scsi/scsi.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,10 @@ EXPORT_SYMBOL(scsi_device_get);
586586
*/
587587
void scsi_device_put(struct scsi_device *sdev)
588588
{
589-
/*
590-
* Decreasing the module reference count before the device reference
591-
* count is safe since scsi_remove_host() only returns after all
592-
* devices have been removed.
593-
*/
594-
module_put(sdev->host->hostt->module);
589+
struct module *mod = sdev->host->hostt->module;
590+
595591
put_device(&sdev->sdev_gendev);
592+
module_put(mod);
596593
}
597594
EXPORT_SYMBOL(scsi_device_put);
598595

drivers/scsi/scsi_sysfs.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
452452
struct scsi_vpd *vpd_pg0 = NULL, *vpd_pg89 = NULL;
453453
struct scsi_vpd *vpd_pgb0 = NULL, *vpd_pgb1 = NULL, *vpd_pgb2 = NULL;
454454
unsigned long flags;
455+
struct module *mod;
456+
457+
mod = sdev->host->hostt->module;
455458

456459
scsi_dh_release_device(sdev);
457460

@@ -518,11 +521,17 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
518521

519522
if (parent)
520523
put_device(parent);
524+
module_put(mod);
521525
}
522526

523527
static void scsi_device_dev_release(struct device *dev)
524528
{
525529
struct scsi_device *sdp = to_scsi_device(dev);
530+
531+
/* Set module pointer as NULL in case of module unloading */
532+
if (!try_module_get(sdp->host->hostt->module))
533+
sdp->host->hostt->module = NULL;
534+
526535
execute_in_process_context(scsi_device_dev_release_usercontext,
527536
&sdp->ew);
528537
}

0 commit comments

Comments
 (0)