From: "Marc Hartmayer" <mhartmay@linux.ibm.com>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
yi.zhang@huawei.com, yangerkun@huawei.com, hch@lst.de,
chaitanyak@nvidia.com, shinichiro.kawasaki@wdc.com,
dgilbert@interlog.com, jejb@linux.ibm.com,
martin.petersen@oracle.com, axboe@kernel.dk,
Benjamin Block <bblock@linux.ibm.com>,
"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH] scsi/sg: don't grab scsi host module reference
Date: Wed, 05 Jul 2023 08:13:08 +0200 [thread overview]
Message-ID: <87bkgqkhsb.fsf@linux.ibm.com> (raw)
In-Reply-To: <1efb3d4d-a05b-2eb2-a140-a76981b662a4@huaweicloud.com>
On Wed, Jul 05, 2023 at 10:28 AM +0800, Yu Kuai <yukuai1@huaweicloud.com> wrote:
> Hi,
>
> 在 2023/07/05 9:43, Yu Kuai 写道:
>> Hi,
>>
>> 在 2023/07/05 1:04, Marc Hartmayer 写道:
>>> On Thu, Jun 22, 2023 at 12:01 AM +0800, Yu Kuai
>>> <yukuai1@huaweicloud.com> wrote:
>>>> From: Yu Kuai <yukuai3@huawei.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@nvidia.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@huawei.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
>>>
>>> Hi,
>>>
>>> This change (bisected) triggers a regression in our KVM on s390x CI. The
>>> symptom is that a “scsi_debug device” does not bind to the scsi_generic
>>> driver. On s390x you can reproduce the problem as follows (I have not
>>> tested on x86):
>>>
>>> With this patch applied:
>>>
>>> $ sudo modprobe scsi_debug
>>> $ # Get the 'scsi_host,channel,target_number,LUN' tuple for the
>>> scsi_debug device
>>> $ lsscsi |grep scsi_debug |awk '{ print $1 }'
>>> [0:0:0:0]
>>> $ sudo stat /sys/bus/scsi/devices/0:0:0:0/scsi_generic
>>> stat: cannot statx '/sys/bus/scsi/devices/0:0:0:0/scsi_generic': No
>>> such file or directory
>>>
>>>
>>> Patch reverted:
>>>
>>
>> I didn't figure out the root cause, howver, have you tried to reviert
>> this patch as well?
>>
>> db59133e9279 ("scsi: sg: fix blktrace debugfs entries leakage"
>
> Never mind this, root cause is that the checking of return value of
> blk_get_queue() is wrong.
>
> This shoud be fixed by following patch:
>
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 89fa046c7158..0d8afffd1683 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -1497,9 +1497,10 @@ sg_add_device(struct device *cl_dev)
> int error;
> unsigned long iflags;
>
> - error = blk_get_queue(scsidp->request_queue);
> - if (error)
> - return error;
> + if (!blk_get_queue(scsidp->request_queue)) {
> + pr_warn("%s: get scsi_device queue failed\n", __func__);
> + return -ENODEV;
> + }
Hi Kuai,
I just tried your fix and it works - thanks.
Tested-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Marc
[…snip]
prev parent reply other threads:[~2023-07-05 6:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-21 16:01 [PATCH] scsi/sg: don't grab scsi host module reference Yu Kuai
2023-06-21 15:47 ` Bart Van Assche
2023-06-21 16:06 ` Bart Van Assche
2023-06-23 5:44 ` Christoph Hellwig
2023-06-23 14:28 ` Jens Axboe
2023-07-04 17:04 ` Marc Hartmayer
2023-07-04 18:51 ` Benjamin Block
2023-07-05 2:16 ` Yu Kuai
2023-07-05 2:26 ` Yu Kuai
2023-07-05 1:43 ` Yu Kuai
2023-07-05 2:28 ` Yu Kuai
2023-07-05 6:13 ` Marc Hartmayer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bkgqkhsb.fsf@linux.ibm.com \
--to=mhartmay@linux.ibm.com \
--cc=axboe@kernel.dk \
--cc=bblock@linux.ibm.com \
--cc=chaitanyak@nvidia.com \
--cc=dgilbert@interlog.com \
--cc=hch@lst.de \
--cc=jejb@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=shinichiro.kawasaki@wdc.com \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yukuai1@huaweicloud.com \
--cc=yukuai3@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).