Skip to content

Commit cc41f11

Browse files
sreekanthbrcmmartinkpetersen
authored andcommitted
scsi: mpt3sas: Fix kernel panic observed on soft HBA unplug
Generic protection fault type kernel panic is observed when user performs soft (ordered) HBA unplug operation while IOs are running on drives connected to HBA. When user performs ordered HBA removal operation, the kernel calls PCI device's .remove() call back function where driver is flushing out all the outstanding SCSI IO commands with DID_NO_CONNECT host byte and also unmaps sg buffers allocated for these IO commands. However, in the ordered HBA removal case (unlike of real HBA hot removal), HBA device is still alive and hence HBA hardware is performing the DMA operations to those buffers on the system memory which are already unmapped while flushing out the outstanding SCSI IO commands and this leads to kernel panic. Don't flush out the outstanding IOs from .remove() path in case of ordered removal since HBA will be still alive in this case and it can complete the outstanding IOs. Flush out the outstanding IOs only in case of 'physical HBA hot unplug' where there won't be any communication with the HBA. During shutdown also it is possible that HBA hardware can perform DMA operations on those outstanding IO buffers which are completed with DID_NO_CONNECT by the driver from .shutdown(). So same above fix is applied in shutdown path as well. It is safe to drop the outstanding commands when HBA is inaccessible such as when permanent PCI failure happens, when HBA is in non-operational state, or when someone does a real HBA hot unplug operation. Since driver knows that HBA is inaccessible during these cases, it is safe to drop the outstanding commands instead of waiting for SCSI error recovery to kick in and clear these outstanding commands. Link: https://lore.kernel.org/r/[email protected] Fixes: c666d3b ("scsi: mpt3sas: wait for and flush running commands on shutdown/unload") Cc: [email protected] #v4.14.174+ Signed-off-by: Sreekanth Reddy <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 1764fa2 commit cc41f11

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/scsi/mpt3sas/mpt3sas_scsih.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9908,8 +9908,8 @@ static void scsih_remove(struct pci_dev *pdev)
99089908

99099909
ioc->remove_host = 1;
99109910

9911-
mpt3sas_wait_for_commands_to_complete(ioc);
9912-
_scsih_flush_running_cmds(ioc);
9911+
if (!pci_device_is_present(pdev))
9912+
_scsih_flush_running_cmds(ioc);
99139913

99149914
_scsih_fw_event_cleanup_queue(ioc);
99159915

@@ -9992,8 +9992,8 @@ scsih_shutdown(struct pci_dev *pdev)
99929992

99939993
ioc->remove_host = 1;
99949994

9995-
mpt3sas_wait_for_commands_to_complete(ioc);
9996-
_scsih_flush_running_cmds(ioc);
9995+
if (!pci_device_is_present(pdev))
9996+
_scsih_flush_running_cmds(ioc);
99979997

99989998
_scsih_fw_event_cleanup_queue(ioc);
99999999

0 commit comments

Comments
 (0)