mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] iscsi/iser-target: Fix
@ 2013-11-13  2:11 Nicholas A. Bellinger
  2013-11-13  2:11 ` [PATCH 1/2] iscsi-target: Fix mutex_trylock usage in iscsit_increment_maxcmdsn Nicholas A. Bellinger
  2013-11-13  2:11 ` [PATCH 2/2] ib_isert: Avoid duplicate iscsit_increment_maxcmdsn call Nicholas A. Bellinger
  0 siblings, 2 replies; 3+ messages in thread
From: Nicholas A. Bellinger @ 2013-11-13  2:11 UTC (permalink / raw)
  To: target-devel
  Cc: linux-scsi, linux-kernel, Moussa Ba, Or Gerlitz, Mike Christie,
	Nicholas Bellinger

From: Nicholas Bellinger <nab@linux-iscsi.org>

Hi folks,

Here are the two patches to address the regression bug that Moussa
has recently been hitting with ib_isert ports + mtip32xx backends.

In the end, this bug was due to an incorrect usage of mutex_trylock(),
that was originally introduced to avoid an ib_isert specific nested
deadlock from an exception path, that inadvertently allowed normal
per RX/TX process context contention to increment sess->max_cmd_sn +
post a response + receive a new command in RX context with a CmdSN
larger than the last MaxCmdSN sychronized across RX/TX contexts.

This patch simply avoids the ib_isert callback in lio_queue_status()
for the special iscsi_execute_cmd() exception cases to avoid the
dead-lock, which allows the problematic mutex_trylock() usage in
iscsit_increment_maxcmdsn() to go away entirely.

I'll be including both of these with a CC' to stable for v3.10+

Special thanks to Moussa for helping track this bug down.

--nab

Nicholas Bellinger (2):
  iscsi-target: Fix mutex_trylock usage in iscsit_increment_maxcmdsn
  ib_isert: Avoid duplicate iscsit_increment_maxcmdsn call

 drivers/infiniband/ulp/isert/ib_isert.c      |    6 +-----
 drivers/target/iscsi/iscsi_target_configfs.c |    5 +++++
 drivers/target/iscsi/iscsi_target_device.c   |    6 +-----
 3 files changed, 7 insertions(+), 10 deletions(-)

-- 
1.7.10.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] iscsi-target: Fix mutex_trylock usage in iscsit_increment_maxcmdsn
  2013-11-13  2:11 [PATCH 0/2] iscsi/iser-target: Fix Nicholas A. Bellinger
@ 2013-11-13  2:11 ` Nicholas A. Bellinger
  2013-11-13  2:11 ` [PATCH 2/2] ib_isert: Avoid duplicate iscsit_increment_maxcmdsn call Nicholas A. Bellinger
  1 sibling, 0 replies; 3+ messages in thread
From: Nicholas A. Bellinger @ 2013-11-13  2:11 UTC (permalink / raw)
  To: target-devel
  Cc: linux-scsi, linux-kernel, Moussa Ba, Or Gerlitz, Mike Christie,
	Nicholas Bellinger

From: Nicholas Bellinger <nab@linux-iscsi.org>

This patch fixes a >= v3.10 regression bug with mutex_trylock() usage
within iscsit_increment_maxcmdsn(), that was originally added to allow
for a special case where ->cmdsn_mutex was already held from the
iscsit_execute_cmd() exception path for ib_isert.

When !mutex_trylock() was occuring under contention during normal RX/TX
process context codepaths, the bug was manifesting itself as the following
protocol error:

  Received CmdSN: 0x000fcbb7 is greater than MaxCmdSN: 0x000fcbb6, protocol error.
  Received CmdSN: 0x000fcbb8 is greater than MaxCmdSN: 0x000fcbb6, protocol error.

This patch simply avoids the direct ib_isert callback in lio_queue_status()
for the special iscsi_execute_cmd() exception cases, that allows the problematic
mutex_trylock() usage in iscsit_increment_maxcmdsn() to go away.

Reported-by: Moussa Ba <moussaba@micron.com>
Tested-by: Moussa Ba <moussaba@micron.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
 drivers/target/iscsi/iscsi_target_configfs.c |    5 +++++
 drivers/target/iscsi/iscsi_target_device.c   |    6 +-----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c
index 1eec37c..fde3624 100644
--- a/drivers/target/iscsi/iscsi_target_configfs.c
+++ b/drivers/target/iscsi/iscsi_target_configfs.c
@@ -1790,6 +1790,11 @@ static int lio_queue_status(struct se_cmd *se_cmd)
 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
 
 	cmd->i_state = ISTATE_SEND_STATUS;
+
+	if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
+		iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
+		return 0;
+	}
 	cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
 
 	return 0;
diff --git a/drivers/target/iscsi/iscsi_target_device.c b/drivers/target/iscsi/iscsi_target_device.c
index 6c7a510..7087c73 100644
--- a/drivers/target/iscsi/iscsi_target_device.c
+++ b/drivers/target/iscsi/iscsi_target_device.c
@@ -58,11 +58,7 @@ void iscsit_increment_maxcmdsn(struct iscsi_cmd *cmd, struct iscsi_session *sess
 
 	cmd->maxcmdsn_inc = 1;
 
-	if (!mutex_trylock(&sess->cmdsn_mutex)) {
-		sess->max_cmd_sn += 1;
-		pr_debug("Updated MaxCmdSN to 0x%08x\n", sess->max_cmd_sn);
-		return;
-	}
+	mutex_lock(&sess->cmdsn_mutex);
 	sess->max_cmd_sn += 1;
 	pr_debug("Updated MaxCmdSN to 0x%08x\n", sess->max_cmd_sn);
 	mutex_unlock(&sess->cmdsn_mutex);
-- 
1.7.10.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] ib_isert: Avoid duplicate iscsit_increment_maxcmdsn call
  2013-11-13  2:11 [PATCH 0/2] iscsi/iser-target: Fix Nicholas A. Bellinger
  2013-11-13  2:11 ` [PATCH 1/2] iscsi-target: Fix mutex_trylock usage in iscsit_increment_maxcmdsn Nicholas A. Bellinger
@ 2013-11-13  2:11 ` Nicholas A. Bellinger
  1 sibling, 0 replies; 3+ messages in thread
From: Nicholas A. Bellinger @ 2013-11-13  2:11 UTC (permalink / raw)
  To: target-devel
  Cc: linux-scsi, linux-kernel, Moussa Ba, Or Gerlitz, Mike Christie,
	Nicholas Bellinger

From: Nicholas Bellinger <nab@linux-iscsi.org>

This patch avoids a duplicate iscsit_increment_maxcmdsn() call for
ISER_IB_RDMA_WRITE within isert_map_rdma() + isert_reg_rdma_frwr(),
which will already be occuring once during isert_put_datain() ->
iscsit_build_rsp_pdu() operation.

It also removes the local conn->stat_sn assignment + increment,
and changes the third parameter to iscsit_build_rsp_pdu() to
signal this should be done by iscsi_target_mode code.

Tested-by: Moussa Ba <moussaba@micron.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
 drivers/infiniband/ulp/isert/ib_isert.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index bbd86e8..5661075 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -2029,8 +2029,6 @@ isert_map_rdma(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
 
 	if (wr->iser_ib_op == ISER_IB_RDMA_WRITE) {
 		data_left = se_cmd->data_length;
-		iscsit_increment_maxcmdsn(cmd, conn->sess);
-		cmd->stat_sn = conn->stat_sn++;
 	} else {
 		sg_off = cmd->write_data_done / PAGE_SIZE;
 		data_left = se_cmd->data_length - cmd->write_data_done;
@@ -2242,8 +2240,6 @@ isert_reg_rdma_frwr(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
 
 	if (wr->iser_ib_op == ISER_IB_RDMA_WRITE) {
 		data_left = se_cmd->data_length;
-		iscsit_increment_maxcmdsn(cmd, conn->sess);
-		cmd->stat_sn = conn->stat_sn++;
 	} else {
 		sg_off = cmd->write_data_done / PAGE_SIZE;
 		data_left = se_cmd->data_length - cmd->write_data_done;
@@ -2352,7 +2348,7 @@ isert_put_datain(struct iscsi_conn *conn, struct iscsi_cmd *cmd)
 	 * Build isert_conn->tx_desc for iSCSI response PDU and attach
 	 */
 	isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc);
-	iscsit_build_rsp_pdu(cmd, conn, false, (struct iscsi_scsi_rsp *)
+	iscsit_build_rsp_pdu(cmd, conn, true, (struct iscsi_scsi_rsp *)
 			     &isert_cmd->tx_desc.iscsi_header);
 	isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc);
 	isert_init_send_wr(isert_conn, isert_cmd,
-- 
1.7.10.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-13  2:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-13  2:11 [PATCH 0/2] iscsi/iser-target: Fix Nicholas A. Bellinger
2013-11-13  2:11 ` [PATCH 1/2] iscsi-target: Fix mutex_trylock usage in iscsit_increment_maxcmdsn Nicholas A. Bellinger
2013-11-13  2:11 ` [PATCH 2/2] ib_isert: Avoid duplicate iscsit_increment_maxcmdsn call Nicholas A. Bellinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®