All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roman Bolshakov <r.bolshakov@yadro.com>
To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Cc: linux@yadro.com, Roman Bolshakov <r.bolshakov@yadro.com>,
	Quinn Tran <qutran@marvell.com>,
	Himanshu Madhani <hmadhani@marvell.com>
Subject: [PATCH v2 15/15] scsi: qla2xxx: Handle ABTS according to FCP spec for logged out ports
Date: Wed, 20 Nov 2019 22:27:23 +0000	[thread overview]
Message-ID: <20191120222723.27779-16-r.bolshakov@yadro.com> (raw)
In-Reply-To: <20191120222723.27779-1-r.bolshakov@yadro.com>

Fibre Channel Protocol for SCSI, Fourth Version (FCP-4) 12.3.3, "Target
FCP_Port response to Exchange termination" states:

  When an ABTS-LS is received at the target FCP_Port, it shall abort the
  designated Exchange and return one of the following responses:

    a) the target FCP_Port shall discard the ABTS-LS and transmit a LOGO ELS if
       the Nx_Port issuing the ABTS-LS is not currently logged in (i.e., no
       N_Port Login exists);

However, current implementation tries to send a real BA_RJT in response to ABTS
from logged-out ports. The oparation fails because N_Port handle was freed
shortly after logout and ABTS Recieved IOCB contains 0xFFFF N_Port handle.
Existing implementation doesn't send LOGO at all.

The correct way to discard ABTS-LS frame when N_Port handle wasn't found is to
set Terminate ABTS Exchange bit in control flags of ABTS Response IOCB.
LOGO is sent after that.

To avoid a deadlock in qla2x00_start_sp(), hardware_lock should be released.
The unlocking should be safe because ABTS Recieved IOCB is not needed after
s_id is saved on the stack and qlt_24xx_send_abts_resp() is invoked.

Fixes: 2d70c103fd2a ("[SCSI] qla2xxx: Add LLD target-mode infrastructure for >= 24xx series")
Cc: Quinn Tran <qutran@marvell.com>
Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
---
 drivers/scsi/qla2xxx/qla_target.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index 0f2bc4cd562f..331e7adf4b15 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -1800,7 +1800,7 @@ static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd *mcmd)
  */
 static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair,
 	struct abts_recv_from_24xx *abts, uint32_t status,
-	bool ids_reversed)
+	bool ids_reversed, bool term_exchange)
 {
 	struct scsi_qla_host *vha = qpair->vha;
 	struct qla_hw_data *ha = vha->hw;
@@ -1825,6 +1825,10 @@ static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair,
 	resp->handle = QLA_TGT_SKIP_HANDLE;
 	resp->entry_count = 1;
 	resp->nport_handle = abts->nport_handle;
+	if (term_exchange)
+		resp->control_flags = cpu_to_le16(ABTS_CONTR_FLG_TERM_EXCHG);
+	else
+		resp->control_flags = 0;
 	resp->vp_index = vha->vp_idx;
 	resp->sof_type = abts->sof_type;
 	resp->exchange_address = abts->exchange_address;
@@ -1940,7 +1944,7 @@ static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha,
 		qlt_build_abts_resp_iocb(mcmd);
 	else
 		qlt_24xx_send_abts_resp(qpair,
-		    (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true);
+		    (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true, false);
 
 }
 
@@ -2134,7 +2138,7 @@ static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
 		    "qla_target(%d): ABTS: Abort Sequence not "
 		    "supported\n", vha->vp_idx);
 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
-		    false);
+		    false, false);
 		return;
 	}
 
@@ -2143,7 +2147,7 @@ static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
 		    "qla_target(%d): ABTS: Unknown Exchange "
 		    "Address received\n", vha->vp_idx);
 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
-		    false);
+		    false, false);
 		return;
 	}
 
@@ -2163,8 +2167,16 @@ static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
 		    vha->vp_idx);
 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
 
+		/*
+		 * According to FCP-4 12.3.3,
+		 * ABTS-LS frame shall be discarded
+		 */
 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
-			    false);
+			    false, true);
+		spin_unlock_irqrestore(&ha->hardware_lock, flags);
+		/* and LOGO ELS transmitted */
+		qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, be_to_port_id(s_id), false);
+		spin_lock_irqsave(&ha->hardware_lock, flags);
 		return;
 	}
 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
@@ -2172,7 +2184,7 @@ static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
 
 	if (sess->deleted) {
 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
-		    false);
+		    false, false);
 		return;
 	}
 
@@ -2182,7 +2194,7 @@ static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
 		    "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
 		    vha->vp_idx, rc);
 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
-		    false);
+		    false, false);
 		return;
 	}
 }
@@ -6213,7 +6225,7 @@ static void qlt_abort_work(struct qla_tgt *tgt,
 out_term:
 	spin_lock_irqsave(&ha->hardware_lock, flags);
 	qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts,
-	    FCP_TMF_REJECTED, false);
+	    FCP_TMF_REJECTED, false, false);
 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
 }
 
-- 
2.24.0

WARNING: multiple messages have this Message-ID (diff)
From: Roman Bolshakov <r.bolshakov@yadro.com>
To: <linux-scsi@vger.kernel.org>, <target-devel@vger.kernel.org>
Cc: <linux@yadro.com>, Roman Bolshakov <r.bolshakov@yadro.com>,
	Quinn Tran <qutran@marvell.com>,
	Himanshu Madhani <hmadhani@marvell.com>
Subject: [PATCH v2 15/15] scsi: qla2xxx: Handle ABTS according to FCP spec for logged out ports
Date: Thu, 21 Nov 2019 01:27:23 +0300	[thread overview]
Message-ID: <20191120222723.27779-16-r.bolshakov@yadro.com> (raw)
In-Reply-To: <20191120222723.27779-1-r.bolshakov@yadro.com>

Fibre Channel Protocol for SCSI, Fourth Version (FCP-4) 12.3.3, "Target
FCP_Port response to Exchange termination" states:

  When an ABTS-LS is received at the target FCP_Port, it shall abort the
  designated Exchange and return one of the following responses:

    a) the target FCP_Port shall discard the ABTS-LS and transmit a LOGO ELS if
       the Nx_Port issuing the ABTS-LS is not currently logged in (i.e., no
       N_Port Login exists);

However, current implementation tries to send a real BA_RJT in response to ABTS
from logged-out ports. The oparation fails because N_Port handle was freed
shortly after logout and ABTS Recieved IOCB contains 0xFFFF N_Port handle.
Existing implementation doesn't send LOGO at all.

The correct way to discard ABTS-LS frame when N_Port handle wasn't found is to
set Terminate ABTS Exchange bit in control flags of ABTS Response IOCB.
LOGO is sent after that.

To avoid a deadlock in qla2x00_start_sp(), hardware_lock should be released.
The unlocking should be safe because ABTS Recieved IOCB is not needed after
s_id is saved on the stack and qlt_24xx_send_abts_resp() is invoked.

Fixes: 2d70c103fd2a ("[SCSI] qla2xxx: Add LLD target-mode infrastructure for >= 24xx series")
Cc: Quinn Tran <qutran@marvell.com>
Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
---
 drivers/scsi/qla2xxx/qla_target.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index 0f2bc4cd562f..331e7adf4b15 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -1800,7 +1800,7 @@ static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd *mcmd)
  */
 static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair,
 	struct abts_recv_from_24xx *abts, uint32_t status,
-	bool ids_reversed)
+	bool ids_reversed, bool term_exchange)
 {
 	struct scsi_qla_host *vha = qpair->vha;
 	struct qla_hw_data *ha = vha->hw;
@@ -1825,6 +1825,10 @@ static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair,
 	resp->handle = QLA_TGT_SKIP_HANDLE;
 	resp->entry_count = 1;
 	resp->nport_handle = abts->nport_handle;
+	if (term_exchange)
+		resp->control_flags = cpu_to_le16(ABTS_CONTR_FLG_TERM_EXCHG);
+	else
+		resp->control_flags = 0;
 	resp->vp_index = vha->vp_idx;
 	resp->sof_type = abts->sof_type;
 	resp->exchange_address = abts->exchange_address;
@@ -1940,7 +1944,7 @@ static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha,
 		qlt_build_abts_resp_iocb(mcmd);
 	else
 		qlt_24xx_send_abts_resp(qpair,
-		    (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true);
+		    (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true, false);
 
 }
 
@@ -2134,7 +2138,7 @@ static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
 		    "qla_target(%d): ABTS: Abort Sequence not "
 		    "supported\n", vha->vp_idx);
 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
-		    false);
+		    false, false);
 		return;
 	}
 
@@ -2143,7 +2147,7 @@ static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
 		    "qla_target(%d): ABTS: Unknown Exchange "
 		    "Address received\n", vha->vp_idx);
 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
-		    false);
+		    false, false);
 		return;
 	}
 
@@ -2163,8 +2167,16 @@ static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
 		    vha->vp_idx);
 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
 
+		/*
+		 * According to FCP-4 12.3.3,
+		 * ABTS-LS frame shall be discarded
+		 */
 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
-			    false);
+			    false, true);
+		spin_unlock_irqrestore(&ha->hardware_lock, flags);
+		/* and LOGO ELS transmitted */
+		qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, be_to_port_id(s_id), false);
+		spin_lock_irqsave(&ha->hardware_lock, flags);
 		return;
 	}
 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
@@ -2172,7 +2184,7 @@ static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
 
 	if (sess->deleted) {
 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
-		    false);
+		    false, false);
 		return;
 	}
 
@@ -2182,7 +2194,7 @@ static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
 		    "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
 		    vha->vp_idx, rc);
 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
-		    false);
+		    false, false);
 		return;
 	}
 }
@@ -6213,7 +6225,7 @@ static void qlt_abort_work(struct qla_tgt *tgt,
 out_term:
 	spin_lock_irqsave(&ha->hardware_lock, flags);
 	qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts,
-	    FCP_TMF_REJECTED, false);
+	    FCP_TMF_REJECTED, false, false);
 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
 }
 
-- 
2.24.0


  parent reply	other threads:[~2019-11-20 22:27 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-20 22:27 [PATCH v2 00/15] scsi: qla2xxx: Bug fixes Roman Bolshakov
2019-11-20 22:27 ` Roman Bolshakov
2019-11-20 22:27 ` [PATCH v2 01/15] scsi: qla2xxx: Ignore NULL pointer in tcm_qla2xxx_free_mcmd Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-20 22:27 ` [PATCH v2 02/15] scsi: qla2xxx: Initialize free_work before flushing it Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-20 22:27 ` [PATCH v2 03/15] scsi: qla2xxx: Drop superfluous INIT_WORK of del_work Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-20 22:27 ` [PATCH v2 04/15] scsi: qla2xxx: Change discovery state before PLOGI Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-20 22:27 ` [PATCH v2 05/15] scsi: qla2xxx: Allow PLOGI in target mode Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-20 22:52   ` [EXT] " Quinn Tran
2019-11-21 16:38     ` Himanshu Madhani
2019-11-21 16:38       ` Himanshu Madhani
2019-11-20 22:27 ` [PATCH v2 06/15] scsi: qla2xxx: Don't call qlt_async_event twice Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-21 15:43   ` Himanshu Madhani
2019-11-21 15:43     ` Himanshu Madhani
2019-11-20 22:27 ` [PATCH v2 07/15] scsi: qla2xxx: Fix PLOGI payload and ELS IOCB dump length Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-21 16:39   ` [EXT] " Himanshu Madhani
2019-11-21 16:39     ` Himanshu Madhani
2019-11-20 22:27 ` [PATCH v2 08/15] scsi: qla2xxx: Configure local loop for N2N target Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-20 23:06   ` [EXT] " Quinn Tran
2019-11-21 16:39   ` Himanshu Madhani
2019-11-21 16:39     ` Himanshu Madhani
2019-11-20 22:27 ` [PATCH v2 09/15] scsi: qla2xxx: Send Notify ACK after N2N PLOGI Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-20 23:53   ` [EXT] " Quinn Tran
2019-11-21 16:40   ` Himanshu Madhani
2019-11-21 16:40     ` Himanshu Madhani
2019-11-20 22:27 ` [PATCH v2 10/15] scsi: qla2xxx: Don't defer relogin unconditonally Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-21  0:03   ` [EXT] " Quinn Tran
2019-11-20 22:27 ` [PATCH v2 11/15] scsi: qla2xxx: Ignore PORT UPDATE after N2N PLOGI Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-20 22:27 ` [PATCH v2 12/15] scsi: qla2xxx: Use explicit LOGO in target mode Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-23  4:58   ` kbuild test robot
2019-11-23  4:58     ` kbuild test robot
2019-11-23  4:58     ` kbuild test robot
2019-11-20 22:27 ` [PATCH v2 13/15] scsi: qla2xxx: Add async mode for qla24xx_els_dcmd_iocb Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-21 22:50   ` [EXT] " Quinn Tran
2019-11-22  5:04     ` Mark Harvey
2019-11-22  5:04       ` Mark Harvey
2019-11-22 17:00       ` Quinn Tran
2019-11-22 17:00         ` Quinn Tran
2019-11-24 19:15       ` Roman Bolshakov
2019-11-24 19:15         ` Roman Bolshakov
2019-11-20 22:27 ` [PATCH v2 14/15] scsi: qla2xxx: Add debug dump of LOGO payload and ELS IOCB Roman Bolshakov
2019-11-20 22:27   ` Roman Bolshakov
2019-11-21 16:37   ` Himanshu Madhani
2019-11-21 16:37     ` Himanshu Madhani
2019-11-21 22:52   ` [EXT] " Quinn Tran
2019-11-20 22:27 ` Roman Bolshakov [this message]
2019-11-20 22:27   ` [PATCH v2 15/15] scsi: qla2xxx: Handle ABTS according to FCP spec for logged out ports Roman Bolshakov
2019-11-23  5:57   ` kbuild test robot
2019-11-23  5:57     ` kbuild test robot
2019-11-23  5:57     ` kbuild test robot
2019-11-22  9:14 ` [PATCH v2 00/15] scsi: qla2xxx: Bug fixes Hannes Reinecke
2019-11-22  9:14   ` Hannes Reinecke
2019-11-22 21:36   ` Martin Wilck
2019-11-22 21:36     ` Martin Wilck
2019-11-24 18:31     ` Roman Bolshakov
2019-11-24 18:31       ` Roman Bolshakov

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=20191120222723.27779-16-r.bolshakov@yadro.com \
    --to=r.bolshakov@yadro.com \
    --cc=hmadhani@marvell.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux@yadro.com \
    --cc=qutran@marvell.com \
    --cc=target-devel@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 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.