* [PATCH] scsi: fix missing lock protection
@ 2025-02-19 8:11 Chaohai Chen
2025-02-19 18:06 ` Bart Van Assche
0 siblings, 1 reply; 3+ messages in thread
From: Chaohai Chen @ 2025-02-19 8:11 UTC (permalink / raw)
To: martin.petersen; +Cc: James.Bottomley, linux-scsi, linux-kernel, Chaohai Chen
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.
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] scsi: fix missing lock protection
2025-02-19 8:11 [PATCH] scsi: fix missing lock protection Chaohai Chen
@ 2025-02-19 18:06 ` Bart Van Assche
2025-02-20 3:01 ` Chaohai Chen
0 siblings, 1 reply; 3+ messages in thread
From: Bart Van Assche @ 2025-02-19 18:06 UTC (permalink / raw)
To: Chaohai Chen, martin.petersen; +Cc: James.Bottomley, linux-scsi, linux-kernel
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] scsi: fix missing lock protection
2025-02-19 18:06 ` Bart Van Assche
@ 2025-02-20 3:01 ` Chaohai Chen
0 siblings, 0 replies; 3+ messages in thread
From: Chaohai Chen @ 2025-02-20 3:01 UTC (permalink / raw)
To: wdhh66, martin.petersen
Cc: James.Bottomley, linux-scsi, linux-kernel, Bart Van Assche
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-20 3:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-19 8:11 [PATCH] scsi: fix missing lock protection Chaohai Chen
2025-02-19 18:06 ` Bart Van Assche
2025-02-20 3:01 ` Chaohai Chen
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®