]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
scsi: libsas: Add LUN number check in .slave_alloc callback
authorYufen Yu <yuyufen@huawei.com>
Tue, 22 Jun 2021 03:40:37 +0000 (11:40 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Jul 2021 09:13:44 +0000 (11:13 +0200)
[ Upstream commit 49da96d77938db21864dae6b7736b71e96c1d203 ]

Offlining a SATA device connected to a hisi SAS controller and then
scanning the host will result in detecting 255 non-existent devices:

  # lsscsi
  [2:0:0:0]    disk    ATA      Samsung SSD 860  2B6Q  /dev/sda
  [2:0:1:0]    disk    ATA      WDC WD2003FYYS-3 1D01  /dev/sdb
  [2:0:2:0]    disk    SEAGATE  ST600MM0006      B001  /dev/sdc
  # echo "offline" > /sys/block/sdb/device/state
  # echo "- - -" > /sys/class/scsi_host/host2/scan
  # lsscsi
  [2:0:0:0]    disk    ATA      Samsung SSD 860  2B6Q  /dev/sda
  [2:0:1:0]    disk    ATA      WDC WD2003FYYS-3 1D01  /dev/sdb
  [2:0:1:1]    disk    ATA      WDC WD2003FYYS-3 1D01  /dev/sdh
  ...
  [2:0:1:255]  disk    ATA      WDC WD2003FYYS-3 1D01  /dev/sdjb

After a REPORT LUN command issued to the offline device fails, the SCSI
midlayer tries to do a sequential scan of all devices whose LUN number is
not 0. However, SATA does not support LUN numbers at all.

Introduce a generic sas_slave_alloc() handler which will return -ENXIO for
SATA devices if the requested LUN number is larger than 0 and make libsas
drivers use this function as their .slave_alloc callback.

Link: https://lore.kernel.org/r/20210622034037.1467088-1-yuyufen@huawei.com
Reported-by: Wu Bo <wubo40@huawei.com>
Suggested-by: John Garry <john.garry@huawei.com>
Reviewed-by: John Garry <john.garry@huawei.com>
Reviewed-by: Jason Yan <yanaijie@huawei.com>
Signed-off-by: Yufen Yu <yuyufen@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/scsi/aic94xx/aic94xx_init.c
drivers/scsi/hisi_sas/hisi_sas_v1_hw.c
drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
drivers/scsi/isci/init.c
drivers/scsi/libsas/sas_scsi_host.c
drivers/scsi/mvsas/mv_init.c
drivers/scsi/pm8001/pm8001_init.c

index 702da909cee5e8a8c23207dde6e5f6b8a4f63614..ad8a65ab489cf8b5ed627f616ecf4f19222919b1 100644 (file)
@@ -71,6 +71,7 @@ static struct scsi_host_template aic94xx_sht = {
        .use_clustering         = ENABLE_CLUSTERING,
        .eh_device_reset_handler        = sas_eh_device_reset_handler,
        .eh_target_reset_handler        = sas_eh_target_reset_handler,
+       .slave_alloc            = sas_slave_alloc,
        .target_destroy         = sas_target_destroy,
        .ioctl                  = sas_ioctl,
        .track_queue_depth      = 1,
index 8aa3222fe48659356679e1c2ea36965dd2b84ade..fea26edd505e1fffad5d10922efce8a809152f5f 100644 (file)
@@ -1814,6 +1814,7 @@ static struct scsi_host_template sht_v1_hw = {
        .use_clustering         = ENABLE_CLUSTERING,
        .eh_device_reset_handler = sas_eh_device_reset_handler,
        .eh_target_reset_handler = sas_eh_target_reset_handler,
+       .slave_alloc            = sas_slave_alloc,
        .target_destroy         = sas_target_destroy,
        .ioctl                  = sas_ioctl,
        .shost_attrs            = host_attrs,
index ebc984ffe6a22cb49bf3c273826d77326470dfe8..7be94319760419dbce0703ad947de7694d494b35 100644 (file)
@@ -3565,6 +3565,7 @@ static struct scsi_host_template sht_v2_hw = {
        .use_clustering         = ENABLE_CLUSTERING,
        .eh_device_reset_handler = sas_eh_device_reset_handler,
        .eh_target_reset_handler = sas_eh_target_reset_handler,
+       .slave_alloc            = sas_slave_alloc,
        .target_destroy         = sas_target_destroy,
        .ioctl                  = sas_ioctl,
        .shost_attrs            = host_attrs,
index ce2f232b3df382089e524be179391235f3b40d91..16b7ea556118651905ab76e144bd77add126fff8 100644 (file)
@@ -2115,6 +2115,7 @@ static struct scsi_host_template sht_v3_hw = {
        .use_clustering         = ENABLE_CLUSTERING,
        .eh_device_reset_handler = sas_eh_device_reset_handler,
        .eh_target_reset_handler = sas_eh_target_reset_handler,
+       .slave_alloc            = sas_slave_alloc,
        .target_destroy         = sas_target_destroy,
        .ioctl                  = sas_ioctl,
        .shost_attrs            = host_attrs,
index dde84f7443136eaabd95aba80af83ef638308600..07de94ea3819266294d5bd39ecdc1a7cf695f2f7 100644 (file)
@@ -167,6 +167,7 @@ static struct scsi_host_template isci_sht = {
        .eh_abort_handler               = sas_eh_abort_handler,
        .eh_device_reset_handler        = sas_eh_device_reset_handler,
        .eh_target_reset_handler        = sas_eh_target_reset_handler,
+       .slave_alloc                    = sas_slave_alloc,
        .target_destroy                 = sas_target_destroy,
        .ioctl                          = sas_ioctl,
        .shost_attrs                    = isci_host_attrs,
index 33229348dcb6adc88fe11de596708776a4ee04e2..316a1118355537bd50af5e077c63fe71fac4d54d 100644 (file)
@@ -942,6 +942,14 @@ void sas_task_abort(struct sas_task *task)
        }
 }
 
+int sas_slave_alloc(struct scsi_device *sdev)
+{
+       if (dev_is_sata(sdev_to_domain_dev(sdev)) && sdev->lun)
+               return -ENXIO;
+
+       return 0;
+}
+
 void sas_target_destroy(struct scsi_target *starget)
 {
        struct domain_device *found_dev = starget->hostdata;
@@ -988,5 +996,6 @@ EXPORT_SYMBOL_GPL(sas_task_abort);
 EXPORT_SYMBOL_GPL(sas_phy_reset);
 EXPORT_SYMBOL_GPL(sas_eh_device_reset_handler);
 EXPORT_SYMBOL_GPL(sas_eh_target_reset_handler);
+EXPORT_SYMBOL_GPL(sas_slave_alloc);
 EXPORT_SYMBOL_GPL(sas_target_destroy);
 EXPORT_SYMBOL_GPL(sas_ioctl);
index 8c91637cd598d971afd11b2ae5e4aceb024a7b22..98d6608068abd3ac68355140ae6cddbf853e2046 100644 (file)
@@ -62,6 +62,7 @@ static struct scsi_host_template mvs_sht = {
        .use_clustering         = ENABLE_CLUSTERING,
        .eh_device_reset_handler = sas_eh_device_reset_handler,
        .eh_target_reset_handler = sas_eh_target_reset_handler,
+       .slave_alloc            = sas_slave_alloc,
        .target_destroy         = sas_target_destroy,
        .ioctl                  = sas_ioctl,
        .shost_attrs            = mvst_host_attrs,
index 1d59d7447a1c8e65ec5c008994df4161f9d44681..9547cf516d39401b918a2a1eb25bd40959eed31e 100644 (file)
@@ -87,6 +87,7 @@ static struct scsi_host_template pm8001_sht = {
        .use_clustering         = ENABLE_CLUSTERING,
        .eh_device_reset_handler = sas_eh_device_reset_handler,
        .eh_target_reset_handler = sas_eh_target_reset_handler,
+       .slave_alloc            = sas_slave_alloc,
        .target_destroy         = sas_target_destroy,
        .ioctl                  = sas_ioctl,
        .shost_attrs            = pm8001_host_attrs,