Skip to content
Permalink
Browse files
megaraid_sas: Early detection of VD deletion through RaidMap update
Consider in a case, when a VD is deleted and the targetID of
that VD is assigned to a newly created VD. If the sequence of
deletion/addition of VD happens very quickly, there is a possibility
that second event(VD add) occurs even before the driver processes the
first event(VD delete).
As event processing is done in deferred context the device list
remains same(but targetID is re-used) so driver will not learn the
VD deletion/additon and IOs meant for older VD will be directed to
new VD which may lead to data corruption.

In new design, driver will detect the deleted VD as soon as possible
based on the RaidMap update and blocks further IOs to that device.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Chandrakanth Patil <chandrakanth.patil@broadcom.com>
  • Loading branch information
cp890582 authored and intel-lab-lkp committed Mar 17, 2021
1 parent dc42c8d commit dadb835ed01309bcd9a8d51a01ad4467dc71aea6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
@@ -2023,6 +2023,7 @@ union megasas_frame {
struct MR_PRIV_DEVICE {
bool is_tm_capable;
bool tm_busy;
bool device_removed_by_fw;
atomic_t r1_ldio_hint;
u8 interface_type;
u8 task_abort_tmo;
@@ -2323,6 +2324,8 @@ struct megasas_instance {
struct megasas_pd_list pd_list[MEGASAS_MAX_PD];
struct megasas_pd_list local_pd_list[MEGASAS_MAX_PD];
u8 ld_ids[MEGASAS_MAX_LD_IDS];
u8 ld_ids_prev[MEGASAS_MAX_LD_IDS];
u8 ld_ids_from_raidmap[MEGASAS_MAX_LD_IDS];
s8 init_id;

u16 max_num_sge;
@@ -426,6 +426,12 @@ megasas_decode_evt(struct megasas_instance *instance)
(class_locale.members.locale),
format_class(class_locale.members.class),
evt_detail->description);

if (megasas_dbg_lvl & LD_PD_DEBUG)
dev_info(&instance->pdev->dev,
"evt_detail.args.ld.target_id/index %d/%d\n",
evt_detail->args.ld.target_id, evt_detail->args.ld.ld_index);

}

/*
@@ -1802,7 +1808,8 @@ megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
}

mr_device_priv_data = scmd->device->hostdata;
if (!mr_device_priv_data) {
if (!mr_device_priv_data ||
mr_device_priv_data->device_removed_by_fw) {
scmd->result = DID_NO_CONNECT << 16;
scmd->scsi_done(scmd);
return 0;
@@ -3491,6 +3498,39 @@ megasas_complete_abort(struct megasas_instance *instance,
}
}

void
megasas_set_sdev_removed_by_fw(struct megasas_instance *instance)
{
struct scsi_device *sdev;
struct MR_PRIV_DEVICE *mr_device_priv_data;
uint channel, id, i;

for (i = 0; (i < MEGASAS_MAX_LD_IDS); i++) {
if (instance->ld_ids_prev[i] != 0xff &&
instance->ld_ids_from_raidmap[i] == 0xff) {
channel = MEGASAS_MAX_PD_CHANNELS +
(instance->ld_ids_prev[i] /
MEGASAS_MAX_DEV_PER_CHANNEL);
id = (instance->ld_ids_prev[i] %
MEGASAS_MAX_DEV_PER_CHANNEL);

if (megasas_dbg_lvl & LD_PD_DEBUG)
dev_info(&instance->pdev->dev,
"index %d old 0x%x new 0x%x from %s\n",
i, instance->ld_ids_prev[i],
instance->ld_ids_from_raidmap[i],
__func__);

sdev = scsi_device_lookup(instance->host, channel, id, 0);
if (sdev) {
mr_device_priv_data = sdev->hostdata;
mr_device_priv_data->device_removed_by_fw = true;
scsi_device_put(sdev);
}
}
}
}

/**
* megasas_complete_cmd - Completes a command
* @instance: Adapter soft state
@@ -3656,6 +3696,10 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd,
megasas_sync_map_info(instance);
spin_unlock_irqrestore(instance->host->host_lock,
flags);

if (instance->adapter_type >= INVADER_SERIES)
megasas_set_sdev_removed_by_fw(instance);

break;
}
if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO ||
@@ -8764,8 +8808,10 @@ megasas_aen_polling(struct work_struct *work)
union megasas_evt_class_locale class_locale;
int event_type = 0;
u32 seq_num;
u16 ld_target_id;
int error;
u8 dcmd_ret = DCMD_SUCCESS;
struct scsi_device *sdev1;

if (!instance) {
printk(KERN_ERR "invalid instance!\n");
@@ -8788,12 +8834,23 @@ megasas_aen_polling(struct work_struct *work)
break;

case MR_EVT_LD_OFFLINE:
case MR_EVT_CFG_CLEARED:
case MR_EVT_LD_DELETED:
ld_target_id = instance->evt_detail->args.ld.target_id;
sdev1 = scsi_device_lookup(instance->host,
MEGASAS_MAX_PD_CHANNELS +
(ld_target_id / MEGASAS_MAX_DEV_PER_CHANNEL),
(ld_target_id - MEGASAS_MAX_DEV_PER_CHANNEL),
0);
if (sdev1)
megasas_remove_scsi_device(sdev1);

event_type = SCAN_VD_CHANNEL;
break;
case MR_EVT_LD_CREATED:
event_type = SCAN_VD_CHANNEL;
break;

case MR_EVT_CFG_CLEARED:
case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED:
case MR_EVT_FOREIGN_CFG_IMPORTED:
case MR_EVT_LD_STATE_CHANGE:
@@ -349,6 +349,10 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance, u64 map_id)

num_lds = le16_to_cpu(drv_map->raidMap.ldCount);

memcpy(instance->ld_ids_prev,
instance->ld_ids_from_raidmap,
sizeof(instance->ld_ids_from_raidmap));
memset(instance->ld_ids_from_raidmap, 0xff, MEGASAS_MAX_LD_IDS);
/*Convert Raid capability values to CPU arch */
for (i = 0; (num_lds > 0) && (i < MAX_LOGICAL_DRIVES_EXT); i++) {
ld = MR_TargetIdToLdGet(i, drv_map);
@@ -359,7 +363,7 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance, u64 map_id)

raid = MR_LdRaidGet(ld, drv_map);
le32_to_cpus((u32 *)&raid->capability);

instance->ld_ids_from_raidmap[ld] = i;
num_lds--;
}

0 comments on commit dadb835

Please sign in to comment.