Blob Blame History Raw
From: Mike Christie <michael.christie@oracle.com>
Date: Thu, 7 Apr 2022 19:13:12 -0500
Subject: scsi: iscsi: Fix NOP handling during conn recovery
Git-commit: 44ac97109e42f87b1a34954704b81b6c8eca80c4
Patch-mainline: v5.18-rc3
References: bsc#1197685

If a offload driver doesn't use the xmit workqueue, then when we are doing
ep_disconnect libiscsi can still inject PDUs to the driver. This adds a
check for if the connection is bound before trying to inject PDUs.

[lduncan: updated to work without upstream commit 5bd856256f8c03e32, which
 normally adds the "flags" field, but broke the kABI]

Link: https://lore.kernel.org/r/20220408001314.5014-9-michael.christie@oracle.com
Tested-by: Manish Rangankar <mrangankar@marvell.com>
Reviewed-by: Lee Duncan <lduncan@suse.com>
Reviewed-by: Chris Leech <cleech@redhat.com>
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Acked-by: Lee Duncan <lduncan@suse.com>
---
 drivers/scsi/libiscsi.c |    7 ++++++-
 include/scsi/libiscsi.h |   13 +++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -678,7 +678,8 @@ __iscsi_conn_send_pdu(struct iscsi_conn
 	struct iscsi_task *task;
 	itt_t itt;
 
-	if (session->state == ISCSI_STATE_TERMINATE)
+	if (session->state == ISCSI_STATE_TERMINATE ||
+	    !test_bit(ISCSI_CONN_FLAG_BOUND, &conn->flags))
 		return NULL;
 
 	if (opcode == ISCSI_OP_LOGIN || opcode == ISCSI_OP_TEXT) {
@@ -2214,6 +2215,8 @@ void iscsi_conn_unbind(struct iscsi_cls_
 	iscsi_suspend_tx(conn);
 
 	spin_lock_bh(&session->frwd_lock);
+	clear_bit(ISCSI_CONN_FLAG_BOUND, &conn->flags);
+
 	if (!is_active) {
 		/*
 		 * if logout timed out before userspace could even send a PDU
@@ -3310,6 +3313,8 @@ int iscsi_conn_bind(struct iscsi_cls_ses
 	spin_lock_bh(&session->frwd_lock);
 	if (is_leading)
 		session->leadconn = conn;
+
+	set_bit(ISCSI_CONN_FLAG_BOUND, &conn->flags);
 	spin_unlock_bh(&session->frwd_lock);
 
 	/*
--- a/include/scsi/libiscsi.h
+++ b/include/scsi/libiscsi.h
@@ -52,9 +52,19 @@ enum {
 
 #define ISID_SIZE			6
 
+/*
+ * the "suspend" bit is used for the suspend_rx and
+ * suspend_tx fields, for kABI compatability, and
+ * the newer "bound" flag uses the newer "flags"
+ * field
+ */
+
 /* Connection suspend "bit" */
 #define ISCSI_SUSPEND_BIT		1
 
+/* Connection flags */
+#define ISCSI_CONN_FLAG_BOUND		BIT(2)
+
 #define ISCSI_ITT_MASK			0x1fff
 #define ISCSI_TOTAL_CMDS_MAX		4096
 /* this must be a power of two greater than ISCSI_MGMT_CMDS_MAX */
@@ -244,6 +254,9 @@ struct iscsi_conn {
 	/* custom statistics */
 	uint32_t		eh_abort_cnt;
 	uint32_t		fmr_unalign_cnt;
+#ifndef __GENKSYMS__
+	unsigned long		flags;		/* ISCSI_CONN_FLAGs */
+#endif
 };
 
 struct iscsi_pool {