Skip to content

Commit 831e340

Browse files
Ming Leimartinkpetersen
authored andcommitted
scsi: core: Don't start concurrent async scan on same host
The current scanning mechanism is supposed to fall back to a synchronous host scan if an asynchronous scan is in progress. However, this rule isn't strictly respected, scsi_prep_async_scan() doesn't hold scan_mutex when checking shost->async_scan. When scsi_scan_host() is called concurrently, two async scans on same host can be started and a hang in do_scan_async() is observed. Fixes this issue by checking & setting shost->async_scan atomically with shost->scan_mutex. Link: https://lore.kernel.org/r/20201010032539.426615-1-ming.lei@redhat.com Cc: Christoph Hellwig <hch@lst.de> Cc: Ewan D. Milne <emilne@redhat.com> Cc: Hannes Reinecke <hare@suse.de> Cc: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Lee Duncan <lduncan@suse.com> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 3650b22 commit 831e340

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

drivers/scsi/scsi_scan.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,15 +1714,16 @@ static void scsi_sysfs_add_devices(struct Scsi_Host *shost)
17141714
*/
17151715
static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost)
17161716
{
1717-
struct async_scan_data *data;
1717+
struct async_scan_data *data = NULL;
17181718
unsigned long flags;
17191719

17201720
if (strncmp(scsi_scan_type, "sync", 4) == 0)
17211721
return NULL;
17221722

1723+
mutex_lock(&shost->scan_mutex);
17231724
if (shost->async_scan) {
17241725
shost_printk(KERN_DEBUG, shost, "%s called twice\n", __func__);
1725-
return NULL;
1726+
goto err;
17261727
}
17271728

17281729
data = kmalloc(sizeof(*data), GFP_KERNEL);
@@ -1733,7 +1734,6 @@ static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost)
17331734
goto err;
17341735
init_completion(&data->prev_finished);
17351736

1736-
mutex_lock(&shost->scan_mutex);
17371737
spin_lock_irqsave(shost->host_lock, flags);
17381738
shost->async_scan = 1;
17391739
spin_unlock_irqrestore(shost->host_lock, flags);
@@ -1748,6 +1748,7 @@ static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost)
17481748
return data;
17491749

17501750
err:
1751+
mutex_unlock(&shost->scan_mutex);
17511752
kfree(data);
17521753
return NULL;
17531754
}

0 commit comments

Comments
 (0)