All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-scsi@vger.kernel.org
Cc: "James E.J. Bottomley" <JBottomley@odin.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	rt@linutronix.de,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	QLogic-Storage-Upstream@qlogic.com,
	Christoph Hellwig <hch@lst.de>
Subject: [PATCH 10/11] scsi: bnx2fc: fix hotplug race in bnx2fc_process_new_cqes()
Date: Fri, 11 Mar 2016 16:29:02 +0100	[thread overview]
Message-ID: <1457710143-29182-11-git-send-email-bigeasy@linutronix.de> (raw)
In-Reply-To: <1457710143-29182-1-git-send-email-bigeasy@linutronix.de>

The ->iothread is accessed without holding the lock. Take this:

 CPU A                                  CPU B
-------                                -------
bnx2fc_process_new_cqes()               bnx2fc_percpu_thread_destroy()
 spin_lock_bh(fp_work_lock);
 fps->iothread != NULL
 list_add_tail(work)
 spin_unlock_bh(&fps->fp_work_lock);     spin_lock_bh(&fps->fp_work_lock);
                                         fps->iothread = NULL
 if (fps->iothread && work)
	...
 else
  bnx2fc_process_cq_compl(work)          bnx2fc_process_cq_compl(work);

CPU A will process wqe despite having it added to the work list of CPU
B which will at the same time clean up the queued wqe.

The fix is to add the item to the list and wakeup the thread while still
holding the lock. If the item was not added to the list then the
`process' variable is still true in which case we have to do manually.

Cc: QLogic-Storage-Upstream@qlogic.com
Cc: "James E.J. Bottomley" <JBottomley@odin.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/scsi/bnx2fc/bnx2fc_hwi.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/bnx2fc/bnx2fc_hwi.c b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
index 28c671b609b2..1427062e86f0 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_hwi.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
@@ -1045,6 +1045,7 @@ int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt)
 			struct bnx2fc_work *work = NULL;
 			struct bnx2fc_percpu_s *fps = NULL;
 			unsigned int cpu = wqe % num_possible_cpus();
+			bool process = true;
 
 			fps = &per_cpu(bnx2fc_percpu, cpu);
 			spin_lock_bh(&fps->fp_work_lock);
@@ -1052,16 +1053,16 @@ int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt)
 				goto unlock;
 
 			work = bnx2fc_alloc_work(tgt, wqe);
-			if (work)
+			if (work) {
 				list_add_tail(&work->list,
 					      &fps->work_list);
+				wake_up_process(fps->iothread);
+				process = false;
+			}
 unlock:
 			spin_unlock_bh(&fps->fp_work_lock);
 
-			/* Pending work request completion */
-			if (fps->iothread && work)
-				wake_up_process(fps->iothread);
-			else
+			if (process)
 				bnx2fc_process_cq_compl(tgt, wqe);
 			num_free_sqes++;
 		}
-- 
2.7.0


  parent reply	other threads:[~2016-03-11 15:29 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-11 15:28 [PATCH 00/11] SCSI smpboot thread conversion Sebastian Andrzej Siewior
2016-03-11 15:28 ` [PATCH 01/11] scsi/fcoe: lock online CPUs in fcoe_percpu_clean() Sebastian Andrzej Siewior
2016-03-11 16:17   ` Christoph Hellwig
2016-03-11 16:32     ` Sebastian Andrzej Siewior
2016-03-15  8:19       ` Christoph Hellwig
2016-04-08 13:30         ` Sebastian Andrzej Siewior
2016-04-08 18:14           ` Sebastian Andrzej Siewior
2016-04-12 15:16         ` [PATCH v2] scsi/fcoe: convert to kworker Sebastian Andrzej Siewior
2016-04-22 15:27           ` [PREEMPT-RT] " Sebastian Andrzej Siewior
2016-04-22 15:49             ` James Bottomley
2016-04-22 16:39               ` Laurence Oberman
     [not found]                 ` <186981952.31194082.1461343179889.JavaMail.zimbra-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-06-09 13:09                   ` Sebastian Andrzej Siewior
2016-06-09 13:15                     ` Laurence Oberman
2016-06-09 13:22                       ` Sebastian Andrzej Siewior
2016-06-10 10:38           ` Johannes Thumshirn
     [not found]             ` <20160610103812.ojgzop6qdv3mos5d-3LAbnSA0sDC4fIQPS+WK3rNAH6kLmebB@public.gmane.org>
2016-07-01 19:09               ` Bynoe, Ronald J
2016-07-04  8:23             ` Sebastian Andrzej Siewior
2016-03-11 15:28 ` [PATCH 02/11] scsi/fcoe: remove CONFIG_SMP in fcoe_percpu_thread_destroy() Sebastian Andrzej Siewior
2016-03-11 15:28 ` [PATCH 03/11] scsi/fcoe: drop locking in fcoe_percpu_thread_destroy() if cpu == targ_cpu Sebastian Andrzej Siewior
2016-03-11 15:28 ` [PATCH 04/11] scsi/fcoe: rename p0 to p_target in fcoe_percpu_thread_destroy() Sebastian Andrzej Siewior
2016-03-11 15:28 ` [PATCH 05/11] scsi/fcoe: drop the p_target lock earlier if there is no thread online Sebastian Andrzej Siewior
2016-03-11 15:28 ` [PATCH 06/11] scsi/fcoe: use skb_queue_splice_tail() intead of manual job Sebastian Andrzej Siewior
2016-03-11 15:28 ` [PATCH 07/11] scsi/fcoe: drop the crc_eof page early Sebastian Andrzej Siewior
2016-03-11 15:29 ` [PATCH 08/11] scsi/fcoe: convert to smpboot thread Sebastian Andrzej Siewior
2016-03-11 15:29 ` [PATCH 09/11] scsi: bnx2i: " Sebastian Andrzej Siewior
2016-03-11 15:29 ` Sebastian Andrzej Siewior [this message]
2016-03-11 15:29 ` [PATCH 11/11] scsi: bnx2fc: " Sebastian Andrzej Siewior

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=1457710143-29182-11-git-send-email-bigeasy@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=JBottomley@odin.com \
    --cc=QLogic-Storage-Upstream@qlogic.com \
    --cc=hch@lst.de \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=rt@linutronix.de \
    /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.