From: Bart Van Assche <bvanassche@acm.org>
To: Chaohai Chen <wdhh66@163.com>, martin.petersen@oracle.com
Cc: James.Bottomley@HansenPartnership.com,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: fix missing lock protection
Date: Wed, 19 Feb 2025 10:06:07 -0800 [thread overview]
Message-ID: <03b1b927-fb33-46e8-b38d-08e986f45672@acm.org> (raw)
In-Reply-To: <20250219081119.203295-1-wdhh66@163.com>
On 2/19/25 12:11 AM, Chaohai Chen wrote:
> async_scan_lock is designed to protect the scanning_hosts list,
> but there is no protection here.
>
> Signed-off-by: Chaohai Chen <wdhh66@163.com>
> ---
> drivers/scsi/scsi_scan.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
> index 087fcbfc9aaa..9a90e6ba5603 100644
> --- a/drivers/scsi/scsi_scan.c
> +++ b/drivers/scsi/scsi_scan.c
> @@ -151,8 +151,12 @@ int scsi_complete_async_scans(void)
> struct async_scan_data *data;
>
> do {
> - if (list_empty(&scanning_hosts))
> + spin_lock(&async_scan_lock);
> + if (list_empty(&scanning_hosts)) {
> + spin_unlock(&async_scan_lock);
> return 0;
> + }
> + spin_unlock(&async_scan_lock);
> /* If we can't get memory immediately, that's OK. Just
> * sleep a little. Even if we never get memory, the async
> * scans will finish eventually.
Has it been considered to use scoped_guard() as in the untested patch
below?
Thanks,
Bart.
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 087fcbfc9aaa..efc90571ab47 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -151,8 +151,9 @@ int scsi_complete_async_scans(void)
struct async_scan_data *data;
do {
- if (list_empty(&scanning_hosts))
- return 0;
+ scoped_guard(spinlock, &async_scan_lock)
+ if (list_empty(&scanning_hosts))
+ return 0;
/* If we can't get memory immediately, that's OK. Just
* sleep a little. Even if we never get memory, the async
* scans will finish eventually.
WARNING: multiple messages have this Message-ID
From: Chaohai Chen <wdhh66@163.com>
To: wdhh66@163.com, martin.petersen@oracle.com
Cc: James.Bottomley@HansenPartnership.com,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Bart Van Assche <bvanassche@acm.org>
Subject: Re: [PATCH] scsi: fix missing lock protection
Date: Thu, 20 Feb 2025 11:01:46 +0800 [thread overview]
Message-ID: <03b1b927-fb33-46e8-b38d-08e986f45672@acm.org> (raw)
Message-ID: <20250220030146.3WSLgMIcQ_pEIxLeCC_gAZMKgkd5OfEumCLm1zCzPqg@z> (raw)
In-Reply-To: <20250219081119.203295-1-wdhh66@163.com>
From: Bart Van Assche <bvanassche@acm.org>
On 2/19/25 12:11 AM, Chaohai Chen wrote:
>> async_scan_lock is designed to protect the scanning_hosts list,
>> but there is no protection here.
>>
>> Signed-off-by: Chaohai Chen <wdhh66@163.com>
>> ---
>> drivers/scsi/scsi_scan.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
>> index 087fcbfc9aaa..9a90e6ba5603 100644
>> --- a/drivers/scsi/scsi_scan.c
>> +++ b/drivers/scsi/scsi_scan.c
>> @@ -151,8 +151,12 @@ int scsi_complete_async_scans(void)
>> struct async_scan_data *data;
>>
>> do {
>> - if (list_empty(&scanning_hosts))
>> + spin_lock(&async_scan_lock);
>> + if (list_empty(&scanning_hosts)) {
>> + spin_unlock(&async_scan_lock);
>> return 0;
>> + }
>> + spin_unlock(&async_scan_lock);
>> /* If we can't get memory immediately, that's OK. Just
>> * sleep a little. Even if we never get memory, the async
>> * scans will finish eventually.
>
>Has it been considered to use scoped_guard() as in the untested patch
>below?
>
>Thanks,
>
>Bart.
>
>
>diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
>index 087fcbfc9aaa..efc90571ab47 100644
>--- a/drivers/scsi/scsi_scan.c
>+++ b/drivers/scsi/scsi_scan.c
>@@ -151,8 +151,9 @@ int scsi_complete_async_scans(void)
> struct async_scan_data *data;
>
> do {
>- if (list_empty(&scanning_hosts))
>- return 0;
>+ scoped_guard(spinlock, &async_scan_lock)
>+ if (list_empty(&scanning_hosts))
>+ return 0;
> /* If we can't get memory immediately, that's OK. Just
> * sleep a little. Even if we never get memory, the async
> * scans will finish eventually.
>
>
Of course, it looks nice, thanks.
Chaohai
next prev parent reply other threads:[~2025-02-19 18:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-19 8:11 Chaohai Chen
2025-02-19 18:06 ` Bart Van Assche [this message]
2025-02-20 3:01 ` Chaohai Chen
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=03b1b927-fb33-46e8-b38d-08e986f45672@acm.org \
--to=bvanassche@acm.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=wdhh66@163.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
all inboxes | Powered by JetHome®