Skip to contentSkip to conversation

megaraid_sas: device scan on logical target with invalid LUN ID deletes that target from the OS

PATCH In review Chandrakanth patil 2 participants 3 messages Mar 24, 2022 – Mar 30, 2022

Subsystems (2)
lore
Share & tools
lore

Chandrakanth patil

author maintainer
#0 lore raw

PATCH 1/1 megaraid_sas: device scan on logical target with invalid LUN ID deletes that target from the OS

The megaraid_sas driver supports single LUN, that is LUN 0. And all other LUNs are unsupported.
When a device scan on logical target with invalid lun is invoked through sysfs that target itself is getting removed from the OS. So added a LUN ID validation in the slave destroy to avoid the target deletion.

---
 drivers/scsi/megaraid/megaraid_sas.h      | 3 +++
 drivers/scsi/megaraid/megaraid_sas_base.c | 7 +++++++
 2 files changed, 10 insertions(+)
drivers/scsi/megaraid/megaraid_sas.h +3 -0
index 611871ef15b5..4919ea54b827 100644
@@ -2560,6 +2560,9 @@ struct megasas_instance_template {
 #define MEGASAS_IS_LOGICAL(sdev)					\
 	((sdev->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1)
 
+#define MEGASAS_IS_LUN_VALID(sdev)					\
+	(((sdev)->lun == 0) ? 1 : 0)
+
 #define MEGASAS_DEV_INDEX(scp)						\
 	(((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) +	\
 	scp->device->id)
drivers/scsi/megaraid/megaraid_sas_base.c +7 -0
index 8bf72dbc33b7..db6793608447 100644
@@ -2126,6 +2126,9 @@ static int megasas_slave_alloc(struct scsi_device *sdev)
 			goto scan_target;
 		}
 		return -ENXIO;
+	} else if (!MEGASAS_IS_LUN_VALID(sdev)) {
+		sdev_printk(KERN_INFO, sdev, "%s: invalid LUN\n", __func__);
+		return -ENXIO;
 	}
 
 scan_target:
@@ -2156,6 +2159,10 @@ static void megasas_slave_destroy(struct scsi_device *sdev)
 	instance = megasas_lookup_instance(sdev->host->host_no);
 
 	if (MEGASAS_IS_LOGICAL(sdev)) {
+		if (!MEGASAS_IS_LUN_VALID(sdev)) {
+			sdev_printk(KERN_INFO, sdev, "%s: invalid LUN\n", __func__);
+			return;
+		}
 		ld_tgt_id = MEGASAS_TARGET_ID(sdev);
 		instance->ld_tgtid_status[ld_tgt_id] = LD_TARGET_ID_DELETED;
 		if (megasas_dbg_lvl & LD_PD_DEBUG)
Signature · 1 line
2.27.0
#1 lore raw
Quoted 5 lines · Chandrakanth patil

The megaraid_sas driver supports single LUN, that is LUN 0. And all other LUNs are unsupported.
When a device scan on logical target with invalid lun is invoked through sysfs that target itself is getting removed from the OS. So added a LUN ID validation in the slave destroy to avoid the target deletion.

Please set the max_lun member ins the host template isntead of papering over this in the driver.

author maintainer
#2 lore raw

Hi Christoph,

in shost, we set the max_lun to 8 during load and that is meant for NON_RAID devices.
whereas RAID device supports only a single LUN so this patch takes care of that.

-ckp

Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Chandrakanth patil

The megaraid_sas driver supports single LUN, that is LUN 0. And all other LUNs are unsupported.
When a device scan on logical target with invalid lun is invoked through sysfs that target itself is getting removed from the OS. So added a LUN ID validation in the slave destroy to avoid the target deletion.

Please set the max_lun member ins the host template isntead of papering over this in the driver.

Signature · 2 lines
Regards,
Chandrakanth Patil