From: Martin Wilck <martin.wilck@suse.com>
To: "Martin K. Petersen" <martin.petersen@oracle.com>,
Christoph Hellwig <hch@lst.de>,
Don Brace <don.brace@microchip.com>
Cc: linux-scsi@vger.kernel.org, Hannes Reinecke <hare@suse.de>,
Lee Duncan <lduncan@suse.com>, Martin Wilck <mwilck@suse.com>,
storagedev@microchip.com,
Ranjan Kumar <ranjan.kumar@broadcom.com>,
Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>,
Kashyap Desai <kashyap.desai@broadcom.com>,
Sumit Saxena <sumit.saxena@broadcom.com>,
mpi3mr-linuxdrv.pdl@broadcom.com,
MPT-FusionLinux.pdl@broadcom.com,
Yihang Li <liyihang9@h-partners.com>,
Jack Wang <jinpu.wang@cloud.ionos.com>,
John Garry <john.g.garry@oracle.com>
Subject: [PATCH v2 2/2] scsi: sas_user_scan: use scan_start if available
Date: Tue, 21 Apr 2026 22:20:18 +0200 [thread overview]
Message-ID: <20260421202018.511388-3-mwilck@suse.com> (raw)
In-Reply-To: <20260421202018.511388-1-mwilck@suse.com>
Since 37c4e72b0651 ("scsi: Fix sas_user_scan() to handle wildcard and
multi-channel scans"), a wildcard scan on a SAS host scans all channels.
This can cause excessive resource usage and even system freeze with
some controllers, e.g. smartpqi. smartpqi and other drivers provide
the scan_start() and scan_finished() methods to scan devices
efficiently. Instead of blindly scanning every device, use these
methods to do the wildcard scan when available. Use the existing
function do_scsi_scan_host() for this purpose, which therefore needs
to be exported.
Fixes: 37c4e72b0651 ("scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans")
Signed-off-by: Martin Wilck <mwilck@suse.com>
Cc: Don Brace <don.brace@microchip.com>
Cc: storagedev@microchip.com
Cc: Ranjan Kumar <ranjan.kumar@broadcom.com>
Cc: Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>
Cc: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: Sumit Saxena <sumit.saxena@broadcom.com>
Cc: mpi3mr-linuxdrv.pdl@broadcom.com
Cc: MPT-FusionLinux.pdl@broadcom.com
Cc: Yihang Li <liyihang9@h-partners.com>
Cc: Jack Wang <jinpu.wang@cloud.ionos.com>
Cc: John Garry <john.g.garry@oracle.com>
----
This patch has been tested successfully with smartpqi, but it would
affect other drivers that provide scan_start(), and we don't have
hardware to test them all. Affected drivers are aic94xx, hisi_sas,
hpsa, isci, mpi3mr, mpt3sas, mvsas, pm8001, and smartpqi.
I cc'd the maintainers of these drivers above.
---
drivers/scsi/scsi_scan.c | 3 ++-
drivers/scsi/scsi_transport_sas.c | 19 +++++++++++++++++++
include/scsi/scsi_host.h | 1 +
3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 7b11bc7de0e3..05e0e50b6e42 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -2029,7 +2029,7 @@ static void scsi_finish_async_scan(struct async_scan_data *data)
kfree(data);
}
-static void do_scsi_scan_host(struct Scsi_Host *shost)
+void do_scsi_scan_host(struct Scsi_Host *shost)
{
if (shost->hostt->scan_finished) {
unsigned long start = jiffies;
@@ -2043,6 +2043,7 @@ static void do_scsi_scan_host(struct Scsi_Host *shost)
SCAN_WILD_CARD, SCSI_SCAN_INITIAL);
}
}
+EXPORT_SYMBOL(do_scsi_scan_host);
static void do_scan_async(void *_data, async_cookie_t c)
{
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index 13412702188e..15600394dc31 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -1702,6 +1702,20 @@ static void scan_channel_zero(struct Scsi_Host *shost, uint id, u64 lun)
}
}
+/*
+ * For wildcard scans on hosts that provide a scan_start method,
+ * use that instead of blindly scanning everything.
+ */
+static int sas_user_scan_with_scan_start(struct Scsi_Host *shost)
+{
+ if (!shost->hostt->scan_finished || !shost->hostt->scan_start)
+ return 1;
+
+ /* scan_finished exists, thus do_scsi_scan_host() will use it */
+ do_scsi_scan_host(shost);
+ return 0;
+}
+
/*
* SCSI scan helper
*/
@@ -1721,6 +1735,11 @@ static int sas_user_scan(struct Scsi_Host *shost, uint channel,
break;
case SCAN_WILD_CARD:
+
+ if (id == SCAN_WILD_CARD && lun == SCAN_WILD_CARD
+ && !sas_user_scan_with_scan_start(shost))
+ return 0;
+
mutex_lock(&sas_host->lock);
scan_channel_zero(shost, id, lun);
mutex_unlock(&sas_host->lock);
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index f6e12565a81d..9717559c5171 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -805,6 +805,7 @@ scsi_template_proc_dir(const struct scsi_host_template *sht);
#else
#define scsi_template_proc_dir(sht) NULL
#endif
+extern void do_scsi_scan_host(struct Scsi_Host *shost);
extern void scsi_scan_host(struct Scsi_Host *);
extern int scsi_resume_device(struct scsi_device *sdev);
extern int scsi_rescan_device(struct scsi_device *sdev);
--
2.53.0
next prev parent reply other threads:[~2026-04-21 20:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 20:20 [PATCH v2 0/2] Fix SAS wildcard scan on smartpqi and other controllers Martin Wilck
2026-04-21 20:20 ` [PATCH v2 1/2] scsi: smartpqi: use shost_to_hba() in pqi_scan_finished() Martin Wilck
2026-04-21 20:20 ` Martin Wilck [this message]
2026-04-30 16:30 ` [PATCH v2 0/2] Fix SAS wildcard scan on smartpqi and other controllers Martin K. Petersen
2026-05-04 16:58 ` Martin Wilck
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=20260421202018.511388-3-mwilck@suse.com \
--to=martin.wilck@suse.com \
--cc=MPT-FusionLinux.pdl@broadcom.com \
--cc=don.brace@microchip.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=jinpu.wang@cloud.ionos.com \
--cc=john.g.garry@oracle.com \
--cc=kashyap.desai@broadcom.com \
--cc=lduncan@suse.com \
--cc=linux-scsi@vger.kernel.org \
--cc=liyihang9@h-partners.com \
--cc=martin.petersen@oracle.com \
--cc=mpi3mr-linuxdrv.pdl@broadcom.com \
--cc=mwilck@suse.com \
--cc=ranjan.kumar@broadcom.com \
--cc=sathya.prakash@broadcom.com \
--cc=storagedev@microchip.com \
--cc=sumit.saxena@broadcom.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