public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	Mauricio Faria de Oliveira <mauricfo@linux.vnet.ibm.com>,
	Sreekanth Reddy <Sreekanth.Reddy@broadcom.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Subject: [PATCH 4.15 09/11] scsi: mpt3sas: fix oops in error handlers after shutdown/unload
Date: Fri,  9 Mar 2018 16:19:23 -0800	[thread overview]
Message-ID: <20180310001835.061798273@linuxfoundation.org> (raw)
In-Reply-To: <20180310001834.560857664@linuxfoundation.org>

4.15-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Mauricio Faria de Oliveira <mauricfo@linux.vnet.ibm.com>

commit 9ff549ffb4fb4cc9a4b24d1de9dc3e68287797c4 upstream.

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 dbec4c9040ed ("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: Mauricio Faria de Oliveira <mauricfo@linux.vnet.ibm.com>
Acked-by: Sreekanth Reddy <Sreekanth.Reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -2998,7 +2998,8 @@ scsih_abort(struct scsi_cmnd *scmd)
 	_scsih_tm_display_info(ioc, scmd);
 
 	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,
 			"device been deleted! scmd(%p)\n", scmd);
 		scmd->result = DID_NO_CONNECT << 16;
@@ -3060,7 +3061,8 @@ scsih_dev_reset(struct scsi_cmnd *scmd)
 	_scsih_tm_display_info(ioc, scmd);
 
 	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,
 			"device been deleted! scmd(%p)\n", scmd);
 		scmd->result = DID_NO_CONNECT << 16;
@@ -3122,7 +3124,8 @@ scsih_target_reset(struct scsi_cmnd *scm
 	_scsih_tm_display_info(ioc, scmd);
 
 	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",
 			scmd);
 		scmd->result = DID_NO_CONNECT << 16;
@@ -3179,7 +3182,7 @@ scsih_host_reset(struct scsi_cmnd *scmd)
 	    ioc->name, 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",
 		    ioc->name);
 		r = FAILED;

  parent reply	other threads:[~2018-03-10  0:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-10  0:19 [PATCH 4.15 00/11] 4.15.9-stable review Greg Kroah-Hartman
2018-03-10  0:19 ` [PATCH 4.15 01/11] bpf: fix mlock precharge on arraymaps Greg Kroah-Hartman
2018-03-10  0:19 ` [PATCH 4.15 02/11] bpf: fix memory leak in lpm_trie map_free callback function Greg Kroah-Hartman
2018-03-10  0:19 ` [PATCH 4.15 03/11] bpf: fix rcu lockdep warning for lpm_trie map_free callback Greg Kroah-Hartman
2018-03-10  0:19 ` [PATCH 4.15 04/11] bpf, x64: implement retpoline for tail call Greg Kroah-Hartman
2018-03-10  0:19 ` [PATCH 4.15 05/11] bpf, arm64: fix out of bounds access in " Greg Kroah-Hartman
2018-03-10  0:19 ` [PATCH 4.15 06/11] bpf: add schedule points in percpu arrays management Greg Kroah-Hartman
2018-03-10  0:19 ` [PATCH 4.15 07/11] bpf: allow xadd only on aligned memory Greg Kroah-Hartman
2018-03-10  0:19 ` [PATCH 4.15 08/11] bpf, ppc64: fix out of bounds access in tail call Greg Kroah-Hartman
2018-03-10  0:19 ` Greg Kroah-Hartman [this message]
2018-03-10  0:19 ` [PATCH 4.15 10/11] scsi: mpt3sas: wait for and flush running commands on shutdown/unload Greg Kroah-Hartman
2018-03-10  0:19 ` [PATCH 4.15 11/11] KVM: x86: fix backward migration with async_PF Greg Kroah-Hartman
2018-03-10  5:10 ` [PATCH 4.15 00/11] 4.15.9-stable review Shuah Khan
2018-03-10 14:54   ` Greg Kroah-Hartman
2018-03-10  5:59 ` kernelci.org bot
2018-03-10 15:45 ` Guenter Roeck
2018-03-10 19:48   ` Greg Kroah-Hartman
2018-03-12  7:10 ` Naresh Kamboju
2018-03-12  9:34   ` Naresh Kamboju

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180310001835.061798273@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=Sreekanth.Reddy@broadcom.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mauricfo@linux.vnet.ibm.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox