Commit 9ff549ff authored by Mauricio Faria de Oliveira's avatar Mauricio Faria de Oliveira Committed by Martin K. Petersen

scsi: mpt3sas: fix oops in error handlers after shutdown/unload

This patch adds checks for 'ioc->remove_host' in the SCSI error handlers, so
not to access pointers/resources potentially freed in the PCI shutdown/module
unload path.  The error handlers may be invoked after shutdown/unload,
depending on other components.

This problem was observed with kexec on a system with a mpt3sas based adapter
and an infiniband adapter which takes long enough to shutdown:

The mpt3sas driver finished shutting down / disabled interrupt handling, thus
some commands have not finished and timed out.

Since the system was still running (waiting for the infiniband adapter to
shutdown), the scsi error handler for task abort of mpt3sas was invoked, and
hit an oops -- either in scsih_abort() because 'ioc->scsi_lookup' was NULL
without commit dbec4c90 ("scsi: mpt3sas: lockless command submission"), or
later up in scsih_host_reset() (with or without that commit), because it
eventually called mpt3sas_base_get_iocstate().

After the above commit, the oops in scsih_abort() does not occur anymore
(_scsih_scsi_lookup_find_by_scmd() is no longer called), but that commit is
too big and out of the scope of linux-stable, where this patch might help, so
still go for the changes.

Also, this might help to prevent similar errors in the future, in case code
changes and possibly tries to access freed stuff.

Note the fix in scsih_host_reset() is still important anyway.
Signed-off-by: default avatarMauricio Faria de Oliveira <mauricfo@linux.vnet.ibm.com>
Acked-by: default avatarSreekanth Reddy <Sreekanth.Reddy@broadcom.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 9cfad4a5
...@@ -2835,7 +2835,8 @@ scsih_abort(struct scsi_cmnd *scmd) ...@@ -2835,7 +2835,8 @@ scsih_abort(struct scsi_cmnd *scmd)
_scsih_tm_display_info(ioc, scmd); _scsih_tm_display_info(ioc, scmd);
sas_device_priv_data = scmd->device->hostdata; sas_device_priv_data = scmd->device->hostdata;
if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
ioc->remove_host) {
sdev_printk(KERN_INFO, scmd->device, sdev_printk(KERN_INFO, scmd->device,
"device been deleted! scmd(%p)\n", scmd); "device been deleted! scmd(%p)\n", scmd);
scmd->result = DID_NO_CONNECT << 16; scmd->result = DID_NO_CONNECT << 16;
...@@ -2898,7 +2899,8 @@ scsih_dev_reset(struct scsi_cmnd *scmd) ...@@ -2898,7 +2899,8 @@ scsih_dev_reset(struct scsi_cmnd *scmd)
_scsih_tm_display_info(ioc, scmd); _scsih_tm_display_info(ioc, scmd);
sas_device_priv_data = scmd->device->hostdata; sas_device_priv_data = scmd->device->hostdata;
if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
ioc->remove_host) {
sdev_printk(KERN_INFO, scmd->device, sdev_printk(KERN_INFO, scmd->device,
"device been deleted! scmd(%p)\n", scmd); "device been deleted! scmd(%p)\n", scmd);
scmd->result = DID_NO_CONNECT << 16; scmd->result = DID_NO_CONNECT << 16;
...@@ -2961,7 +2963,8 @@ scsih_target_reset(struct scsi_cmnd *scmd) ...@@ -2961,7 +2963,8 @@ scsih_target_reset(struct scsi_cmnd *scmd)
_scsih_tm_display_info(ioc, scmd); _scsih_tm_display_info(ioc, scmd);
sas_device_priv_data = scmd->device->hostdata; sas_device_priv_data = scmd->device->hostdata;
if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
ioc->remove_host) {
starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n", starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
scmd); scmd);
scmd->result = DID_NO_CONNECT << 16; scmd->result = DID_NO_CONNECT << 16;
...@@ -3019,7 +3022,7 @@ scsih_host_reset(struct scsi_cmnd *scmd) ...@@ -3019,7 +3022,7 @@ scsih_host_reset(struct scsi_cmnd *scmd)
ioc->name, scmd); ioc->name, scmd);
scsi_print_command(scmd); scsi_print_command(scmd);
if (ioc->is_driver_loading) { if (ioc->is_driver_loading || ioc->remove_host) {
pr_info(MPT3SAS_FMT "Blocking the host reset\n", pr_info(MPT3SAS_FMT "Blocking the host reset\n",
ioc->name); ioc->name);
r = FAILED; r = FAILED;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment