[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230621160111.1433521-1-yukuai1@huaweicloud.com>
Date: Thu, 22 Jun 2023 00:01:11 +0800
From: Yu Kuai <yukuai1@...weicloud.com>
To: hch@....de, chaitanyak@...dia.com, shinichiro.kawasaki@....com,
dgilbert@...erlog.com, jejb@...ux.ibm.com,
martin.petersen@...cle.com, yukuai3@...wei.com, axboe@...nel.dk
Cc: linux-scsi@...r.kernel.org, linux-kernel@...r.kernel.org,
yukuai1@...weicloud.com, yi.zhang@...wei.com, yangerkun@...wei.com
Subject: [PATCH] scsi/sg: don't grab scsi host module reference
From: Yu Kuai <yukuai3@...wei.com>
In order to prevent request_queue to be freed before cleaning up
blktrace debugfs entries, commit db59133e9279 ("scsi: sg: fix blktrace
debugfs entries leakage") use scsi_device_get(), however,
scsi_device_get() will also grab scsi module reference and scsi module
can't be removed.
It's reported that blktests can't unload scsi_debug after block/001:
blktests (master) # ./check block
block/001 (stress device hotplugging) [failed]
+++ /root/blktests/results/nodev/block/001.out.bad 2023-06-19
Running block/001
Stressing sd
+modprobe: FATAL: Module scsi_debug is in use.
Fix this problem by grabbing request_queue reference directly, so that
scsi host module can still be unloaded while request_queue will be
pinged by sg device.
Reported-by: Chaitanya Kulkarni <chaitanyak@...dia.com>
Link: https://lore.kernel.org/all/1760da91-876d-fc9c-ab51-999a6f66ad50@nvidia.com/
Fixes: db59133e9279 ("scsi: sg: fix blktrace debugfs entries leakage")
Signed-off-by: Yu Kuai <yukuai3@...wei.com>
---
drivers/scsi/sg.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 2433eeef042a..dcb73787c29d 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1497,7 +1497,7 @@ sg_add_device(struct device *cl_dev)
int error;
unsigned long iflags;
- error = scsi_device_get(scsidp);
+ error = blk_get_queue(scsidp->request_queue);
if (error)
return error;
@@ -1558,7 +1558,7 @@ sg_add_device(struct device *cl_dev)
out:
if (cdev)
cdev_del(cdev);
- scsi_device_put(scsidp);
+ blk_put_queue(scsidp->request_queue);
return error;
}
@@ -1575,7 +1575,7 @@ sg_device_destroy(struct kref *kref)
*/
blk_trace_remove(q);
- scsi_device_put(sdp->device);
+ blk_put_queue(q);
write_lock_irqsave(&sg_index_lock, flags);
idr_remove(&sg_index_idr, sdp->index);
--
2.39.2
Powered by blists - more mailing lists