All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nilesh Javali <njavali@marvell.com>
To: <martin.petersen@oracle.com>
Cc: <linux-scsi@vger.kernel.org>,
	<GR-QLogic-Storage-Upstream@marvell.com>, <bhazarika@marvell.com>,
	<agurumurthy@marvell.com>, <sdeodhar@marvell.com>
Subject: [PATCH v2 6/7] qla2xxx: Wait for io return on terminate rport
Date: Fri, 28 Apr 2023 00:53:38 -0700	[thread overview]
Message-ID: <20230428075339.32551-7-njavali@marvell.com> (raw)
In-Reply-To: <20230428075339.32551-1-njavali@marvell.com>

From: Quinn Tran <qutran@marvell.com>

System crash due to use after free.
Current code allows terminate_rport_io to exit before making
sure all IOs has returned. For FCP-2 device, IO's can hang
on in HW because driver has not tear down the session in FW at
first sign of cable pull. When dev_loss_tmo timer pops,
terminate_rport_io is called and upper layer is about to
free various resources. Terminate_rport_io trigger qla to do
the final cleanup, but the cleanup might not be fast enough where it
leave qla still holding on to the same resource.

Wait for IO's to return to upper layer before resources are freed.

Cc: stable@vger.kernel.org
Signed-off-by: Quinn Tran <qutran@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
---
 drivers/scsi/qla2xxx/qla_attr.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 70cfc94c3d43..b00222459607 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -2750,6 +2750,7 @@ static void
 qla2x00_terminate_rport_io(struct fc_rport *rport)
 {
 	fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
+	scsi_qla_host_t *vha;
 
 	if (!fcport)
 		return;
@@ -2759,9 +2760,12 @@ qla2x00_terminate_rport_io(struct fc_rport *rport)
 
 	if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
 		return;
+	vha = fcport->vha;
 
 	if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
 		qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
+		qla2x00_eh_wait_for_pending_commands(fcport->vha, fcport->d_id.b24,
+			0, WAIT_TARGET);
 		return;
 	}
 	/*
@@ -2786,6 +2790,15 @@ qla2x00_terminate_rport_io(struct fc_rport *rport)
 			qla2x00_port_logout(fcport->vha, fcport);
 		}
 	}
+
+	/* check for any straggling io left behind */
+	if (qla2x00_eh_wait_for_pending_commands(fcport->vha, fcport->d_id.b24, 0, WAIT_TARGET)) {
+		ql_log(ql_log_warn, vha, 0x300b,
+		       "IO not return.  Resetting. \n");
+		set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
+		qla2xxx_wake_dpc(vha);
+		qla2x00_wait_for_chip_reset(vha);
+	}
 }
 
 static int
-- 
2.23.1


  parent reply	other threads:[~2023-04-28  7:54 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28  7:53 [PATCH v2 0/7] qla2xxx driver update Nilesh Javali
2023-04-28  7:53 ` [PATCH v2 1/7] qla2xxx: Multi-que support for TMF Nilesh Javali
2023-05-01 15:06   ` Himanshu Madhani
2023-04-28  7:53 ` [PATCH v2 2/7] qla2xxx: Fix task management cmd failure Nilesh Javali
2023-05-01 15:07   ` Himanshu Madhani
2023-04-28  7:53 ` [PATCH v2 3/7] qla2xxx: Fix task management cmd fail due to unavailable resource Nilesh Javali
2023-05-01 15:08   ` Himanshu Madhani
2023-04-28  7:53 ` [PATCH v2 4/7] qla2xxx: Fix hang in task management Nilesh Javali
2023-05-01 15:08   ` Himanshu Madhani
2023-04-28  7:53 ` [PATCH v2 5/7] qla2xxx: Fix mem access after free Nilesh Javali
2023-05-01 15:10   ` Himanshu Madhani
2023-04-28  7:53 ` Nilesh Javali [this message]
2023-05-01 15:10   ` [PATCH v2 6/7] qla2xxx: Wait for io return on terminate rport Himanshu Madhani
2023-04-28  7:53 ` [PATCH v2 7/7] qla2xxx: Update version to 10.02.08.300-k Nilesh Javali
2023-05-01 15:11   ` Himanshu Madhani
2023-05-06 22:35 ` [PATCH v2 0/7] qla2xxx driver update Martin K. Petersen
2023-05-17  2:12 ` Martin K. Petersen

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=20230428075339.32551-7-njavali@marvell.com \
    --to=njavali@marvell.com \
    --cc=GR-QLogic-Storage-Upstream@marvell.com \
    --cc=agurumurthy@marvell.com \
    --cc=bhazarika@marvell.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=sdeodhar@marvell.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.