public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Patrick Wildt <patrick@blueri.se>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] nvme: flush dcache on both r/w, and the prp list
Date: Wed, 16 Oct 2019 23:22:50 +0200	[thread overview]
Message-ID: <20191016212250.GA33184@nox.fritz.box> (raw)
In-Reply-To: <20191016153500.GA3532@ryzen.blueri.se>

It's possible that the data cache for the buffer still holds data
to be flushed to memory, since the buffer was probably used as stack
before.  Thus we need to make sure to flush it also on reads, since
it's possible that the cache is automatically flused to memory after
the NVMe DMA transfer happened, thus overwriting the NVMe transfer's
data.  Also add a missing dcache flush for the prp list.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
---
 drivers/nvme/nvme.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c
index dee92b613d..f915817aaa 100644
--- a/drivers/nvme/nvme.c
+++ b/drivers/nvme/nvme.c
@@ -123,6 +123,9 @@ static int nvme_setup_prps(struct nvme_dev *dev, u64 *prp2,
 	}
 	*prp2 = (ulong)dev->prp_pool;
 
+	flush_dcache_range((ulong)dev->prp_pool, (ulong)dev->prp_pool +
+			   dev->prp_entry_num * sizeof(u64));
+
 	return 0;
 }
 
@@ -717,9 +720,8 @@ static ulong nvme_blk_rw(struct udevice *udev, lbaint_t blknr,
 	u16 lbas = 1 << (dev->max_transfer_shift - ns->lba_shift);
 	u64 total_lbas = blkcnt;
 
-	if (!read)
-		flush_dcache_range((unsigned long)buffer,
-				   (unsigned long)buffer + total_len);
+	flush_dcache_range((unsigned long)buffer,
+			   (unsigned long)buffer + total_len);
 
 	c.rw.opcode = read ? nvme_cmd_read : nvme_cmd_write;
 	c.rw.flags = 0;
-- 
2.23.0

  reply	other threads:[~2019-10-16 21:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14 11:11 [U-Boot] [PATCH] nvme: add more cache flushes Patrick Wildt
2019-10-16 10:11 ` Bin Meng
2019-10-16 15:35   ` Patrick Wildt
2019-10-16 21:22     ` Patrick Wildt [this message]
2019-10-17  9:28       ` [U-Boot] [PATCH] nvme: flush dcache on both r/w, and the prp list Bin Meng
2019-11-01 13:31       ` Tom Rini
2019-10-17  2:55     ` [U-Boot] [PATCH] nvme: add more cache flushes Bin Meng
2019-10-17  6:44       ` Patrick Wildt
2019-10-17  6:58         ` Simon Goldschmidt
2019-10-17  7:08         ` Bin Meng
2019-10-17  7:12           ` Patrick Wildt
2019-10-17 15:46             ` J. William Campbell

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=20191016212250.GA33184@nox.fritz.box \
    --to=patrick@blueri.se \
    --cc=u-boot@lists.denx.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox