linux-kernel.vger.kernel.org archive mirror
 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, Chris Leech <cleech@redhat.com>,
	Prashantha Subbarao <psubbara@us.ibm.com>,
	"Guilherme G. Piccoli" <gpiccoli@linux.vnet.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Subject: [PATCH 4.10 20/27] scsi: libiscsi: add lock around task lists to fix list corruption regression
Date: Fri, 24 Mar 2017 18:58:38 +0100	[thread overview]
Message-ID: <20170324151227.260070471@linuxfoundation.org> (raw)
In-Reply-To: <20170324151225.973768798@linuxfoundation.org>

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

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

From: Chris Leech <cleech@redhat.com>

commit 6f8830f5bbab16e54f261de187f3df4644a5b977 upstream.

There's a rather long standing regression from the commit "libiscsi:
Reduce locking contention in fast path"

Depending on iSCSI target behavior, it's possible to hit the case in
iscsi_complete_task where the task is still on a pending list
(!list_empty(&task->running)).  When that happens the task is removed
from the list while holding the session back_lock, but other task list
modification occur under the frwd_lock.  That leads to linked list
corruption and eventually a panicked system.

Rather than back out the session lock split entirely, in order to try
and keep some of the performance gains this patch adds another lock to
maintain the task lists integrity.

Major enterprise supported kernels have been backing out the lock split
for while now, thanks to the efforts at IBM where a lab setup has the
most reliable reproducer I've seen on this issue.  This patch has been
tested there successfully.

Signed-off-by: Chris Leech <cleech@redhat.com>
Fixes: 659743b02c41 ("[SCSI] libiscsi: Reduce locking contention in fast path")
Reported-by: Prashantha Subbarao <psubbara@us.ibm.com>
Reviewed-by: Guilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/scsi/libiscsi.c |   26 +++++++++++++++++++++++++-
 include/scsi/libiscsi.h |    1 +
 2 files changed, 26 insertions(+), 1 deletion(-)

--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -560,8 +560,12 @@ static void iscsi_complete_task(struct i
 	WARN_ON_ONCE(task->state == ISCSI_TASK_FREE);
 	task->state = state;
 
-	if (!list_empty(&task->running))
+	spin_lock_bh(&conn->taskqueuelock);
+	if (!list_empty(&task->running)) {
+		pr_debug_once("%s while task on list", __func__);
 		list_del_init(&task->running);
+	}
+	spin_unlock_bh(&conn->taskqueuelock);
 
 	if (conn->task == task)
 		conn->task = NULL;
@@ -783,7 +787,9 @@ __iscsi_conn_send_pdu(struct iscsi_conn
 		if (session->tt->xmit_task(task))
 			goto free_task;
 	} else {
+		spin_lock_bh(&conn->taskqueuelock);
 		list_add_tail(&task->running, &conn->mgmtqueue);
+		spin_unlock_bh(&conn->taskqueuelock);
 		iscsi_conn_queue_work(conn);
 	}
 
@@ -1474,8 +1480,10 @@ void iscsi_requeue_task(struct iscsi_tas
 	 * this may be on the requeue list already if the xmit_task callout
 	 * is handling the r2ts while we are adding new ones
 	 */
+	spin_lock_bh(&conn->taskqueuelock);
 	if (list_empty(&task->running))
 		list_add_tail(&task->running, &conn->requeue);
+	spin_unlock_bh(&conn->taskqueuelock);
 	iscsi_conn_queue_work(conn);
 }
 EXPORT_SYMBOL_GPL(iscsi_requeue_task);
@@ -1512,22 +1520,26 @@ static int iscsi_data_xmit(struct iscsi_
 	 * only have one nop-out as a ping from us and targets should not
 	 * overflow us with nop-ins
 	 */
+	spin_lock_bh(&conn->taskqueuelock);
 check_mgmt:
 	while (!list_empty(&conn->mgmtqueue)) {
 		conn->task = list_entry(conn->mgmtqueue.next,
 					 struct iscsi_task, running);
 		list_del_init(&conn->task->running);
+		spin_unlock_bh(&conn->taskqueuelock);
 		if (iscsi_prep_mgmt_task(conn, conn->task)) {
 			/* regular RX path uses back_lock */
 			spin_lock_bh(&conn->session->back_lock);
 			__iscsi_put_task(conn->task);
 			spin_unlock_bh(&conn->session->back_lock);
 			conn->task = NULL;
+			spin_lock_bh(&conn->taskqueuelock);
 			continue;
 		}
 		rc = iscsi_xmit_task(conn);
 		if (rc)
 			goto done;
+		spin_lock_bh(&conn->taskqueuelock);
 	}
 
 	/* process pending command queue */
@@ -1535,19 +1547,24 @@ check_mgmt:
 		conn->task = list_entry(conn->cmdqueue.next, struct iscsi_task,
 					running);
 		list_del_init(&conn->task->running);
+		spin_unlock_bh(&conn->taskqueuelock);
 		if (conn->session->state == ISCSI_STATE_LOGGING_OUT) {
 			fail_scsi_task(conn->task, DID_IMM_RETRY);
+			spin_lock_bh(&conn->taskqueuelock);
 			continue;
 		}
 		rc = iscsi_prep_scsi_cmd_pdu(conn->task);
 		if (rc) {
 			if (rc == -ENOMEM || rc == -EACCES) {
+				spin_lock_bh(&conn->taskqueuelock);
 				list_add_tail(&conn->task->running,
 					      &conn->cmdqueue);
 				conn->task = NULL;
+				spin_unlock_bh(&conn->taskqueuelock);
 				goto done;
 			} else
 				fail_scsi_task(conn->task, DID_ABORT);
+			spin_lock_bh(&conn->taskqueuelock);
 			continue;
 		}
 		rc = iscsi_xmit_task(conn);
@@ -1558,6 +1575,7 @@ check_mgmt:
 		 * we need to check the mgmt queue for nops that need to
 		 * be sent to aviod starvation
 		 */
+		spin_lock_bh(&conn->taskqueuelock);
 		if (!list_empty(&conn->mgmtqueue))
 			goto check_mgmt;
 	}
@@ -1577,12 +1595,15 @@ check_mgmt:
 		conn->task = task;
 		list_del_init(&conn->task->running);
 		conn->task->state = ISCSI_TASK_RUNNING;
+		spin_unlock_bh(&conn->taskqueuelock);
 		rc = iscsi_xmit_task(conn);
 		if (rc)
 			goto done;
+		spin_lock_bh(&conn->taskqueuelock);
 		if (!list_empty(&conn->mgmtqueue))
 			goto check_mgmt;
 	}
+	spin_unlock_bh(&conn->taskqueuelock);
 	spin_unlock_bh(&conn->session->frwd_lock);
 	return -ENODATA;
 
@@ -1738,7 +1759,9 @@ int iscsi_queuecommand(struct Scsi_Host
 			goto prepd_reject;
 		}
 	} else {
+		spin_lock_bh(&conn->taskqueuelock);
 		list_add_tail(&task->running, &conn->cmdqueue);
+		spin_unlock_bh(&conn->taskqueuelock);
 		iscsi_conn_queue_work(conn);
 	}
 
@@ -2897,6 +2920,7 @@ iscsi_conn_setup(struct iscsi_cls_sessio
 	INIT_LIST_HEAD(&conn->mgmtqueue);
 	INIT_LIST_HEAD(&conn->cmdqueue);
 	INIT_LIST_HEAD(&conn->requeue);
+	spin_lock_init(&conn->taskqueuelock);
 	INIT_WORK(&conn->xmitwork, iscsi_xmitworker);
 
 	/* allocate login_task used for the login/text sequences */
--- a/include/scsi/libiscsi.h
+++ b/include/scsi/libiscsi.h
@@ -196,6 +196,7 @@ struct iscsi_conn {
 	struct iscsi_task	*task;		/* xmit task in progress */
 
 	/* xmit */
+	spinlock_t		taskqueuelock;  /* protects the next three lists */
 	struct list_head	mgmtqueue;	/* mgmt (control) xmit queue */
 	struct list_head	cmdqueue;	/* data-path cmd queue */
 	struct list_head	requeue;	/* tasks needing another run */

  parent reply	other threads:[~2017-03-24 18:23 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-24 17:58 [PATCH 4.10 00/27] 4.10.6-stable review Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 01/27] give up on gcc ilog2() constant optimizations Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 02/27] qla2xxx: Fix memory leak for abts processing Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 03/27] qla2xxx: Fix request queue corruption Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 04/27] parisc: Optimize flush_kernel_vmap_range and invalidate_kernel_vmap_range Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 05/27] parisc: support R_PARISC_SECREL32 relocation in modules Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 06/27] parisc: Fix system shutdown halt Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 07/27] perf/core: Fix use-after-free in perf_release() Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 08/27] perf/core: Fix event inheritance on fork() Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 09/27] md/r5cache: fix set_syndrome_sources() for data in cache Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 10/27] xprtrdma: Squelch kbuild sparse complaint Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 11/27] NFS prevent double free in async nfs4_exchange_id Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 12/27] cpufreq: Fix and clean up show_cpuinfo_cur_freq() Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 13/27] powerpc/boot: Fix zImage TOC alignment Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 14/27] hwrng: omap - write registers after enabling the clock Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 15/27] hwrng: omap - use devm_clk_get() instead of of_clk_get() Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 16/27] hwrng: omap - Do not access INTMASK_REG on EIP76 Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 17/27] md/raid1/10: fix potential deadlock Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 18/27] target/pscsi: Fix TYPE_TAPE + TYPE_MEDIMUM_CHANGER export Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 19/27] scsi: lpfc: Add shutdown method for kexec Greg Kroah-Hartman
2017-03-24 17:58 ` Greg Kroah-Hartman [this message]
2017-03-24 17:58 ` [PATCH 4.10 21/27] scsi: mpt3sas: Avoid sleeping in interrupt context Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 22/27] target: Fix VERIFY_16 handling in sbc_parse_cdb Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 23/27] isdn/gigaset: fix NULL-deref at probe Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 24/27] gfs2: Avoid alignment hole in struct lm_lockname Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 25/27] percpu: acquire pcpu_lock when updating pcpu_nr_empty_pop_pages Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 26/27] cgroup/pids: remove spurious suspicious RCU usage warning Greg Kroah-Hartman
2017-03-25  0:00 ` [PATCH 4.10 00/27] 4.10.6-stable review Shuah Khan
2017-03-26  8:19   ` Greg Kroah-Hartman
2017-03-25  4:18 ` Guenter Roeck
2017-03-26  8:51   ` Greg Kroah-Hartman

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=20170324151227.260070471@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=cleech@redhat.com \
    --cc=gpiccoli@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=psubbara@us.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;
as well as URLs for NNTP newsgroup(s).