Skip to contentSkip to conversation

Fix SAS wildcard scan on smartpqi and other controllers

PATCH Applied Martin Wilck 5 participants 10 messages May 13 – Jun 9

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover Fix SAS wildcard scan on smartpqi and other controllers

commit 37c4e72b0651 ("scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans") modified the way SAS drivers handle the common way of rescanning SCSI devices using "echo - - - >/sys/class/scsi_host/host$N/scan". Before this patch, SAS drivers would only scan channel 0 for this "wildcard scan" scenario; after this patch, it would scan all channels up to shost->max_channel.

This can cause massive resource usage for some drivers, as the driver needs to send an INQUIRY to LUN 0 to every supported ID and e.g. smartpqi sets shost->max_id to 0xffffffff. These INQUIRYs mostly fail, but the kernel needs to set up queues, tag sets, etc. before sending the INQUIRY. Also, some SAS drivers assign special meaning to SCSI channels such as channel 0 for physical and channel 1 for logical devices, and thus don't support "normal" SCSI scanning of these channels anyway.

With smartpqi and hisi_sas, actual kernel crashes due to resource exhaustion have been observed.

v1 and v2 of this patch set proposed leveraging the functions scan_start() and scan_finished() provided by some SAS drivers for fixing this issue. But the review of the v2 series by Sashiko showed that this is a complex and error-prone endeavor. Therefore I asked for some guidance on the ML [1]. I am now proposing a different, simpler solution to the issues we observed, which is simply reverting commit 37c4e72b0651 ("scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans").

This revert will require a different solution for the wildcard scan with mpi3mr and mpt3sas with "Tri-mode" enabled. But it seems wrong in the first place that adding the support for this special mode of operation for some drivers broke wildcard scan for other drivers.

The first patch is a minor fix for smartpqi.

[1] https://lore.kernel.org/linux-scsi/[email protected]/

----
Changes v2 -> v3:

- Removed patch 2 and replaced it by a revert of 37c4e72b0651

Changes v1 -> v2 (obsolete)

- export and call do_scsi_scan_host() instead of duplicating its code (Hannes Reinecke)

Martin Wilck (2):
scsi: smartpqi: use shost_to_hba() in pqi_scan_finished() Revert "scsi: Fix sas_user_scan() to handle wildcard and multi-channel
scans"

 drivers/scsi/scsi_scan.c              |  2 +-
 drivers/scsi/scsi_transport_sas.c     | 60 ++++++---------------------
 drivers/scsi/smartpqi/smartpqi_init.c |  2 +-
 3 files changed, 14 insertions(+), 50 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH v3 1/2 scsi: smartpqi: use shost_to_hba() in pqi_scan_finished()

From: Martin Wilck <[email protected]>

shost_to_hba() is used everywhere except to obtain pqi_ctrl_info from shosti, except in pqi_scan_finished(), where shost_priv() is used. This causes one pointer dereference to be missed, as shost->hostdata is a pointer in smartpqi. Fix it.

Fixes 6c223761eb54 ("smartpqi: initial commit of Microsemi smartpqi driver")
Cc Don Brace <[email protected]>
---
 drivers/scsi/smartpqi/smartpqi_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/smartpqi/smartpqi_init.c +1 -1
index 2026ac645d6a..5ec583dc2e7d 100644
@@ -2642,7 +2642,7 @@ static int pqi_scan_finished(struct Scsi_Host *shost,
 {
 	struct pqi_ctrl_info *ctrl_info;
 
-	ctrl_info = shost_priv(shost);
+	ctrl_info = shost_to_hba(shost);
 
 	return !mutex_is_locked(&ctrl_info->scan_mutex);
 }
Signature · 1 line
2.54.0
Reviewed-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] scsi: smartpqi: use shost_to_hba() in pqi_scan_finished()

Quoted 22 lines · Martin Wilck

From: Martin Wilck <[email protected]>

shost_to_hba() is used everywhere except to obtain pqi_ctrl_info from shosti, except in pqi_scan_finished(), where shost_priv() is used. This causes one pointer dereference to be missed, as shost->hostdata is a pointer in smartpqi. Fix it.

Fixes 6c223761eb54 ("smartpqi: initial commit of Microsemi smartpqi driver")
Cc Don Brace <[email protected]>
---
  drivers/scsi/smartpqi/smartpqi_init.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/smartpqi/smartpqi_init.c +0 -0
index 2026ac645d6a..5ec583dc2e7d 100644

drivers/scsi/smartpqi/smartpqi_init.c static int pqi_scan_finished(struct Scsi_Host *shost, · line 2648

Quoted 8 lines
drivers/scsi/smartpqi/smartpqi_init.c +1 -1
@@ -2642,7 +2642,7 @@ static int pqi_scan_finished(struct Scsi_Host *shost,
  {
  	struct pqi_ctrl_info *ctrl_info;
 
-	ctrl_info = shost_priv(shost);
+	ctrl_info = shost_to_hba(shost);
 
  	return !mutex_is_locked(&ctrl_info->scan_mutex);
  }

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
#3 lore raw

PATCH v3 2/2 Revert "scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans"

In reply to Martin Wilck

This reverts commit 37c4e72b0651e7697eb338cd1fb09feef472cc1a.

Said commit causes excessive resource usage and even system freeze with some controllers, e.g. smartpqi and hisi_sas. The justification provided by the patch authors [1] was supporting a special mode of the mpi3mr and mpt3sas, so-called "Tri-mode", in which NVMe drives are exposed as SCSI devices on a separate channel. While that's useful for these drivers, it seems wrong to cause major breakage for other drivers for the sake of this feature.

[1] https://lore.kernel.org/linux-scsi/CAFdVvOwjy+2ORJ6uJkspiLTPF05481U7gcS4QohFOFGPqAs8ig@mail.gmail.com/

Fixes 37c4e72b0651 ("scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans")
Cc Don Brace <[email protected]>
Cc Ranjan Kumar <[email protected]>
Cc Sathya Prakash Veerichetty <[email protected]>
Cc Kashyap Desai <[email protected]>
Cc Sumit Saxena <[email protected]>
Cc Yihang Li <[email protected]
---
 drivers/scsi/scsi_scan.c          |  2 +-
 drivers/scsi/scsi_transport_sas.c | 60 +++++++------------------------
 2 files changed, 13 insertions(+), 49 deletions(-)
drivers/scsi/scsi_scan.c +1 -1
index ef22a4228b85..b118ed0bf53f 100644
@@ -1910,7 +1910,7 @@ int scsi_scan_host_selected(struct Scsi_Host *shost, unsigned int channel,
 
 	return 0;
 }
-EXPORT_SYMBOL(scsi_scan_host_selected);
+
 static void scsi_sysfs_add_devices(struct Scsi_Host *shost)
 {
 	struct scsi_device *sdev;
drivers/scsi/scsi_transport_sas.c +12 -48

83 lines not on this page · raw message

Signature · 1 line
2.54.0
#4 lore raw

Re: [PATCH v3 2/2] Revert "scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans"

Quoted 23 lines · Martin Wilck

This reverts commit 37c4e72b0651e7697eb338cd1fb09feef472cc1a.

Said commit causes excessive resource usage and even system freeze with some controllers, e.g. smartpqi and hisi_sas. The justification provided by the patch authors [1] was supporting a special mode of the mpi3mr and mpt3sas, so-called "Tri-mode", in which NVMe drives are exposed as SCSI devices on a separate channel. While that's useful for these drivers, it seems wrong to cause major breakage for other drivers for the sake of this feature.

[1] https://lore.kernel.org/linux-scsi/CAFdVvOwjy+2ORJ6uJkspiLTPF05481U7gcS4QohFOFGPqAs8ig@mail.gmail.com/

Fixes 37c4e72b0651 ("scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans")
Cc Don Brace <[email protected]>
Cc Ranjan Kumar <[email protected]>
Cc Sathya Prakash Veerichetty <[email protected]>
Cc Kashyap Desai <[email protected]>
Cc Sumit Saxena <[email protected]>
Cc Yihang Li <[email protected]
Quoted 5 lines
---
  drivers/scsi/scsi_scan.c          |  2 +-
  drivers/scsi/scsi_transport_sas.c | 60 +++++++------------------------
  2 files changed, 13 insertions(+), 49 deletions(-)

While I'm generally in favour of keeping things simple, reverting the mentioned commit might cause regressions with te mpi3mr and/or mpt3sas controller.
Have you tested with these controllers?

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
#5 lore raw

Re: [PATCH v3 2/2] Revert "scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans"

Quoted 38 lines · Hannes Reinecke
Quoted 31 lines · Martin Wilck

This reverts commit 37c4e72b0651e7697eb338cd1fb09feef472cc1a.

Said commit causes excessive resource usage and even system freeze with
some controllers, e.g. smartpqi and hisi_sas. The justification provided
by the patch authors [1] was supporting a special mode of the mpi3mr and
mpt3sas, so-called "Tri-mode", in which NVMe drives are exposed as SCSI
devices on a separate channel. While that's useful for these drivers, it
seems wrong to cause major breakage for other drivers for the sake of
this feature.

[1]
https://lore.kernel.org/linux-scsi/CAFdVvOwjy+2ORJ6uJkspiLTPF05481U7gcS4QohFOFGPqAs8ig@mail.gmail.com/

Fixes 37c4e72b0651 ("scsi: Fix sas_user_scan() to handle wildcard

and multi-channel scans")

Cc Don Brace <[email protected]>
Cc Ranjan Kumar <[email protected]>
Cc Sathya Prakash Veerichetty <[email protected]>
Cc Kashyap Desai <[email protected]>
Cc Sumit Saxena <[email protected]>
Cc Yihang Li <[email protected]
Quoted 6 lines

---
  drivers/scsi/scsi_scan.c          |  2 +- drivers/scsi/scsi_transport_sas.c | 60 +++++++-------------------
-----

  2 files changed, 13 insertions(+), 49 deletions(-)
Quoted 4 lines

While I'm generally in favour of keeping things simple, reverting the mentioned commit might cause regressions with te mpi3mr and/or mpt3sas controller.
Have you tested with these controllers?

Frankly, no. There isn't much to test. Reverting 37c4e72b0651 restores the pre-6.17 state. Which means that the wildcard scan for NVMe devices on mpt3sas and mpi3mr, which was implemented by that commit, will not work any more. As written before, I propose the revert because this commit has severe side effects for wild-card scanning on other drivers.

The way forward remains to be clarified. This is why I have included the mpi3mr/mpt3sas maintainers on the CC list of my patches from v1.

A relatively simple option would be to allow SAS drivers to override the sas_user_scan() function with driver-specific code, and do that for mpi3mr.

Some guidance on the matter would be appreciated.

Regards
Martin

#6 lore raw

Re: [PATCH v3 2/2] Revert "scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans"

Quoted 5 lines · Martin Wilck

Frankly, no. There isn't much to test. Reverting 37c4e72b0651 restores the pre-6.17 state. Which means that the wildcard scan for NVMe devices on mpt3sas and mpi3mr, which was implemented by that commit, will not work any more. As written before, I propose the revert because this commit has severe side effects for wild-card scanning on other drivers.

And that's a good thing. We should never have added this crap in the first place, and Broadcom should have never done this stupid think of hiding NVMe devices behind their HBA instead of just exposing it through a real or fake PCIe switch.

#8 lore raw
In reply to Martin Wilck

Martin,

Quoted 6 lines

commit 37c4e72b0651 ("scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans") modified the way SAS drivers handle the common way of rescanning SCSI devices using "echo - - -

Quoted 1 line

/sys/class/scsi_host/host$N/scan". Before this patch, SAS drivers

would only scan channel 0 for this "wildcard scan" scenario; after this patch, it would scan all channels up to shost->max_channel.

Applied to 7.2/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen
#9 lore raw
In reply to Martin Wilck
Quoted 8 lines · Martin Wilck

commit 37c4e72b0651 ("scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans") modified the way SAS drivers handle the common way of rescanning SCSI devices using "echo - - - >/sys/class/scsi_host/host$N/scan". Before this patch, SAS drivers would only scan channel 0 for this "wildcard scan" scenario; after this patch, it would scan all channels up to shost->max_channel.

[...]

Applied to 7.2/scsi-queue, thanks!

[1/2] scsi: smartpqi: use shost_to_hba() in pqi_scan_finished()

      https://git.kernel.org/mkp/scsi/c/57db1307afb1
[2/2] Revert "scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans"
      https://git.kernel.org/mkp/scsi/c/8c292e89bd83
Signature · 1 line
Martin K. Petersen