Skip to contentSkip to conversation

nvme: add cache flush in get/set_features

PATCH New Neil Armstrong 3 participants 5 messages Feb 26, 2021 – Mar 2, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: add cache flush in get/set_features

On Amlogic G12A platforms, the NVME probe timeouts at get/set_feature(), adding a cache flush solves the timeout.

---
 drivers/nvme/nvme.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/nvme/nvme.c +4 -3
index 5d6331ad34..44c00a0309 100644
@@ -487,11 +487,11 @@ int nvme_get_features(struct nvme_dev *dev, unsigned fid, unsigned nsid,
 	c.features.nsid = cpu_to_le32(nsid);
 	c.features.prp1 = cpu_to_le64(dma_addr);
 	c.features.fid = cpu_to_le32(fid);
-
 	/*
-	 * TODO: add cache invalidate operation when the size of
+	 * TODO: add better cache invalidate operation when the size of
 	 * the DMA buffer is known
 	 */
+	invalidate_dcache_all();
 
 	return nvme_submit_admin_cmd(dev, &c, result);
 }
@@ -508,9 +508,10 @@ int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11,
 	c.features.dword11 = cpu_to_le32(dword11);
 
 	/*
-	 * TODO: add cache flush operation when the size of
+	 * TODO: add better cache flush operation when the size of
 	 * the DMA buffer is known
 	 */
+	invalidate_dcache_all();
 
 	return nvme_submit_admin_cmd(dev, &c, result);
 }
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 nvme: add cache flush in get/set_features

Hi Neil,

Quoted 9 lines · Neil Armstrong

On Amlogic G12A platforms, the NVME probe timeouts at get/set_feature(), adding a cache flush solves the timeout.

---
 drivers/nvme/nvme.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Does below patch fix your issue?
http://patchwork.ozlabs.org/project/uboot/patch/20210208133154.12645-1-andre.przywara at arm.com/

REgards,
Bin

#2 lore raw

PATCH 1/1 nvme: add cache flush in get/set_features

In reply to Neil Armstrong

On 26/02/2021 14:13, Neil Armstrong wrote:

Hi,

Quoted 2 lines

On Amlogic G12A platforms, the NVME probe timeouts at get/set_feature(), adding a cache flush solves the timeout.

I am puzzled how this is supposed to work ...

Quoted 11 lines
---
 drivers/nvme/nvme.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/nvme/nvme.c +0 -0
index 5d6331ad34..44c00a0309 100644

drivers/nvme/nvme.c int nvme_get_features(struct nvme_dev *dev, unsigned fid, unsigned nsid, · line 494

Quoted 10 lines
drivers/nvme/nvme.c +2 -2
@@ -487,11 +487,11 @@ int nvme_get_features(struct nvme_dev *dev, unsigned fid, unsigned nsid,
 	c.features.nsid = cpu_to_le32(nsid);
 	c.features.prp1 = cpu_to_le64(dma_addr);
 	c.features.fid = cpu_to_le32(fid);
-
 	/*
-	 * TODO: add cache invalidate operation when the size of
+	 * TODO: add better cache invalidate operation when the size of
 	 * the DMA buffer is known
 	 */
+	invalidate_dcache_all();

Why is this? Isn't it totally dangerous, because we kill all the information in dirty cache lines? We have extra checks in place to prevent invalidating extra cache lines, when invalidating a single buffer, but this is blanketly killing all of the cache?

And just ignoring for a minute that cache operations by set/way are mostly wrong anyway? They are just meant to initialise the cache after power state changes.

But more importantly: I don't see a single user of nvme_get_features() in the tree? So this would never be called?

drivers/nvme/nvme.c int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11, · line 514

Quoted 12 lines
drivers/nvme/nvme.c +2 -1
 	return nvme_submit_admin_cmd(dev, &c, result);
 }
@@ -508,9 +508,10 @@ int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11,
 	c.features.dword11 = cpu_to_le32(dword11);
 
 	/*
-	 * TODO: add cache flush operation when the size of
+	 * TODO: add better cache flush operation when the size of
 	 * the DMA buffer is known
 	 */
+	invalidate_dcache_all();

Same comment as above, first part: Dangerous and mostly wrong.
Besides: the comment speaks of "flush", not invalidate. So would be extra wrong.
Also: there is exactly one caller in the whole tree, in this very same file. And this one is passing a dma_addr of 0, apparently because it doesn't actually use any buffer, instead passes the single piece of information (the queue count) in the dword11 field.

So how is this supposed to work?

And if this seems to fix something, how?

Cheers,
Andre

Quoted 4 lines
drivers/nvme/nvme.c +0 -0
 	return nvme_submit_admin_cmd(dev, &c, result);
 }
 
#3 lore raw

PATCH 1/1 nvme: add cache flush in get/set_features

Hi Andre, Bin,

Quoted 4 lines · Andr? Przywara

On 26/02/2021 14:13, Neil Armstrong wrote:

Hi,

[..]

Quoted 2 lines

And if this seems to fix something, how?

Good question... sorry for the noise my patch is totally wrong, but it fixed something somehow.

But, "nvme: Always invalidate whole cqes[] array" fixes (correctly) the issue !

Thanks,

Neil

Quoted 9 lines

Cheers,
Andre

Quoted 4 lines

return nvme_submit_admin_cmd(dev, &c, result);
}

#4 lore raw

PATCH 1/1 nvme: add cache flush in get/set_features

On Fri, 26 Feb 2021 17:11:07 +0100
Neil Armstrong <[email protected]> wrote:

Hi Neil,

Quoted 11 lines · Andr? Przywara
Quoted 4 lines · Neil Armstrong

Hi,

[..]

Quoted 2 lines

And if this seems to fix something, how?

Good question... sorry for the noise my patch is totally wrong, but it fixed something somehow.

No worries, the comments sound indeed promising!
I made a patch to clarify the situation.

Quoted 1 line

But, "nvme: Always invalidate whole cqes[] array" fixes (correctly) the issue !

That great to know! Thanks for trying this!

Cheers,
Andre

Quoted 6 lines
Quoted 5 lines
Quoted 4 lines

return nvme_submit_admin_cmd(dev, &c, result);
}