Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scsi: core: Drop using the host_lock to protect async_scan race condition

Previously, host_lock was used to prevent bit-set conflicts in async_scan,
but this approach introduced naked reads in some code paths.

Convert async_scan from a bitfield to a bool type to eliminate bit-level
conflicts entirely. Use __guarded_by(&scan_mutex) to indicate that the
async_scan variable is protected by scan_mutex.

Signed-off-by: Chaohai Chen <wdhh6@aliyun.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Link: https://patch.msgid.link/20260305025125.3649517-1-wdhh6@aliyun.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Chaohai Chen and committed by
Martin K. Petersen
7a3aff16 1bf5c303

+6 -11
+2 -8
drivers/scsi/scsi_scan.c
··· 1943 1943 static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost) 1944 1944 { 1945 1945 struct async_scan_data *data = NULL; 1946 - unsigned long flags; 1947 1946 1948 1947 if (strncmp(scsi_scan_type, "sync", 4) == 0) 1949 1948 return NULL; ··· 1961 1962 goto err; 1962 1963 init_completion(&data->prev_finished); 1963 1964 1964 - spin_lock_irqsave(shost->host_lock, flags); 1965 - shost->async_scan = 1; 1966 - spin_unlock_irqrestore(shost->host_lock, flags); 1965 + shost->async_scan = true; 1967 1966 mutex_unlock(&shost->scan_mutex); 1968 1967 1969 1968 spin_lock(&async_scan_lock); ··· 1989 1992 static void scsi_finish_async_scan(struct async_scan_data *data) 1990 1993 { 1991 1994 struct Scsi_Host *shost; 1992 - unsigned long flags; 1993 1995 1994 1996 if (!data) 1995 1997 return; ··· 2008 2012 2009 2013 scsi_sysfs_add_devices(shost); 2010 2014 2011 - spin_lock_irqsave(shost->host_lock, flags); 2012 - shost->async_scan = 0; 2013 - spin_unlock_irqrestore(shost->host_lock, flags); 2015 + shost->async_scan = false; 2014 2016 2015 2017 mutex_unlock(&shost->scan_mutex); 2016 2018
+4 -3
include/scsi/scsi_host.h
··· 660 660 */ 661 661 unsigned nr_hw_queues; 662 662 unsigned nr_maps; 663 + 664 + /* Asynchronous scan in progress */ 665 + bool async_scan __guarded_by(&scan_mutex); 666 + 663 667 unsigned active_mode:2; 664 668 665 669 /* ··· 681 677 682 678 /* Task mgmt function in progress */ 683 679 unsigned tmf_in_progress:1; 684 - 685 - /* Asynchronous scan in progress */ 686 - unsigned async_scan:1; 687 680 688 681 /* Don't resume host in EH */ 689 682 unsigned eh_noresume:1;