linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Uma Krishnan <ukrishn@linux.vnet.ibm.com>
To: linux-scsi@vger.kernel.org,
	James Bottomley <jejb@linux.vnet.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	"Matthew R. Ochs" <mrochs@linux.vnet.ibm.com>,
	"Manoj N. Kumar" <manoj@linux.vnet.ibm.com>
Cc: Brian King <brking@linux.vnet.ibm.com>,
	linuxppc-dev@lists.ozlabs.org, Ian Munsie <imunsie@au1.ibm.com>,
	Andrew Donnellan <andrew.donnellan@au1.ibm.com>,
	Frederic Barrat <fbarrat@linux.vnet.ibm.com>,
	Christophe Lombard <clombard@linux.vnet.ibm.com>
Subject: [PATCH v2 09/14] cxlflash: Wait for active AFU commands to timeout upon tear down
Date: Mon, 28 Nov 2016 18:42:33 -0600	[thread overview]
Message-ID: <1480380153-60497-1-git-send-email-ukrishn@linux.vnet.ibm.com> (raw)
In-Reply-To: <1480379984-60114-1-git-send-email-ukrishn@linux.vnet.ibm.com>

From: "Matthew R. Ochs" <mrochs@linux.vnet.ibm.com>

With the removal of the static private command pool, the ability to
'complete' outstanding commands was lost. While not an issue for the
commands originating outside the driver, internal AFU commands are
synchronous and therefore have a timeout associated with them. To
avoid a stale memory access, the tear down sequence needs to ensure
that there are not any active commands before proceeding. As these
internal AFU commands are rare events, the simplest way to accomplish
this is detecting the activity and waiting for it to timeout.

Signed-off-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>
---
 drivers/scsi/cxlflash/common.h | 1 +
 drivers/scsi/cxlflash/main.c   | 6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/cxlflash/common.h b/drivers/scsi/cxlflash/common.h
index 7e4ba31..6211677 100644
--- a/drivers/scsi/cxlflash/common.h
+++ b/drivers/scsi/cxlflash/common.h
@@ -180,6 +180,7 @@ struct afu {
 	u64 *hrrq_end;
 	u64 *hrrq_curr;
 	bool toggle;
+	atomic_t cmds_active;	/* Number of currently active AFU commands */
 	s64 room;
 	spinlock_t rrin_slock; /* Lock to rrin queuing and cmd_room updates */
 	u64 hb;
diff --git a/drivers/scsi/cxlflash/main.c b/drivers/scsi/cxlflash/main.c
index 19156ad..839eca4 100644
--- a/drivers/scsi/cxlflash/main.c
+++ b/drivers/scsi/cxlflash/main.c
@@ -531,7 +531,7 @@ static void free_mem(struct cxlflash_cfg *cfg)
  *
  * Safe to call with AFU in a partially allocated/initialized state.
  *
- * Cleans up all state associated with the command queue, and unmaps
+ * Waits for any active internal AFU commands to timeout and then unmaps
  * the MMIO space.
  */
 static void stop_afu(struct cxlflash_cfg *cfg)
@@ -539,6 +539,8 @@ static void stop_afu(struct cxlflash_cfg *cfg)
 	struct afu *afu = cfg->afu;
 
 	if (likely(afu)) {
+		while (atomic_read(&afu->cmds_active))
+			ssleep(1);
 		if (likely(afu->afu_map)) {
 			cxl_psa_unmap((void __iomem *)afu->afu_map);
 			afu->afu_map = NULL;
@@ -1721,6 +1723,7 @@ int cxlflash_afu_sync(struct afu *afu, ctx_hndl_t ctx_hndl_u,
 	}
 
 	mutex_lock(&sync_active);
+	atomic_inc(&afu->cmds_active);
 	buf = kzalloc(sizeof(*cmd) + __alignof__(*cmd) - 1, GFP_KERNEL);
 	if (unlikely(!buf)) {
 		dev_err(dev, "%s: no memory for command\n", __func__);
@@ -1762,6 +1765,7 @@ int cxlflash_afu_sync(struct afu *afu, ctx_hndl_t ctx_hndl_u,
 		     (cmd->sa.host_use_b[0] & B_ERROR)))
 		rc = -1;
 out:
+	atomic_dec(&afu->cmds_active);
 	mutex_unlock(&sync_active);
 	kfree(buf);
 	pr_debug("%s: returning rc=%d\n", __func__, rc);
-- 
2.1.0

  parent reply	other threads:[~2016-11-29  0:42 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-29  0:39 [PATCH v2 00/14] cxlflash: Fixes, enhancements, cleanup and staging Uma Krishnan
2016-11-29  0:41 ` [PATCH v2 01/14] cxlflash: Set sg_tablesize to 1 instead of SG_NONE Uma Krishnan
2016-11-29  0:41 ` [PATCH v2 02/14] cxlflash: Fix crash in cxlflash_restore_luntable() Uma Krishnan
2016-11-29  0:41 ` [PATCH v2 03/14] cxlflash: Improve context_reset() logic Uma Krishnan
2016-11-29  0:41 ` [PATCH v2 04/14] cxlflash: Avoid command room violation Uma Krishnan
2016-11-29 17:04   ` Matthew R. Ochs
2016-11-29  0:42 ` [PATCH v2 05/14] cxlflash: Remove unused buffer from AFU command Uma Krishnan
2016-11-30 22:03   ` Uma Krishnan
2016-11-29  0:42 ` [PATCH v2 06/14] cxlflash: Allocate memory instead of using command pool for AFU sync Uma Krishnan
2016-11-30 22:04   ` Uma Krishnan
2016-11-29  0:42 ` [PATCH v2 07/14] cxlflash: Use cmd_size for private commands Uma Krishnan
2016-11-30 22:05   ` Uma Krishnan
2016-11-29  0:42 ` [PATCH v2 08/14] cxlflash: Remove private command pool Uma Krishnan
2016-11-30 22:11   ` Uma Krishnan
2016-11-29  0:42 ` Uma Krishnan [this message]
2016-11-30 22:11   ` [PATCH v2 09/14] cxlflash: Wait for active AFU commands to timeout upon tear down Uma Krishnan
2016-11-29  0:42 ` [PATCH v2 10/14] cxlflash: Remove AFU command lock Uma Krishnan
2016-11-30 22:12   ` Uma Krishnan
2016-11-29  0:42 ` [PATCH v2 11/14] cxlflash: Cleanup send_tmf() Uma Krishnan
2016-11-30 22:12   ` Uma Krishnan
2016-11-29  0:43 ` [PATCH v2 12/14] cxlflash: Cleanup queuecommand() Uma Krishnan
2016-11-30 22:13   ` Uma Krishnan
2016-11-29  0:43 ` [PATCH v2 13/14] cxlflash: Migrate IOARRIN specific routines to function pointers Uma Krishnan
2016-11-30 22:13   ` Uma Krishnan
2016-11-29  0:43 ` [PATCH v2 14/14] cxlflash: Migrate scsi command pointer to AFU command Uma Krishnan
2016-11-30 22:14   ` Uma Krishnan
2016-11-30 16:42 ` [PATCH v2 00/14] cxlflash: Fixes, enhancements, cleanup and staging Martin K. Petersen
2016-12-01  0:55 ` Martin K. Petersen

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=1480380153-60497-1-git-send-email-ukrishn@linux.vnet.ibm.com \
    --to=ukrishn@linux.vnet.ibm.com \
    --cc=andrew.donnellan@au1.ibm.com \
    --cc=brking@linux.vnet.ibm.com \
    --cc=clombard@linux.vnet.ibm.com \
    --cc=fbarrat@linux.vnet.ibm.com \
    --cc=imunsie@au1.ibm.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=manoj@linux.vnet.ibm.com \
    --cc=martin.petersen@oracle.com \
    --cc=mrochs@linux.vnet.ibm.com \
    /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).