Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH] virtiofs: fix lost reply due to unaligned cache line sharing
@ 2026-11-25  9:39 Li Wang
  2026-11-25  9:53 ` sashiko-bot
  2026-11-25 10:46 ` Michael S. Tsirkin
  0 siblings, 2 replies; 3+ messages in thread
From: Li Wang @ 2026-11-25  9:39 UTC (permalink / raw)
  To: Miklos Szeredi, German Maglione, Vivek Goyal, Stefan Hajnoczi
  Cc: Eugenio Pérez, Michael S . Tsirkin, fuse-devel,
	virtualization, linux-fsdevel, virtio-fs, Li Wang, stable,
	Sashiko

virtio_fs_enqueue_req() maps fuse_req::out.h for DMA_FROM_DEVICE in
place. fuse_req comes from the "fuse_request" slab with no DMA-granule
alignment, so out.h shares a CPU cache line with the waitq field.
request_wait_answer() updates waitq while the DMA is active.

Note: Sashiko correctly identified the bug, but the resulting behavior
is not as described. Sashiko reported that unmap invalidates this shared
cache line and drops the waitq updates made by request_wait_answer(),
so wake_up() walks a damaged list, the waiter never runs, and a later
wait-queue operation can panic. That is not what current arm64 does for
this buffer. fuse_out_header is 16 bytes and does not cover a whole cache
line. dcache_inval_poc() uses dc civac on that partial line: a dirty line
is written back and then invalidated. The waitq update is kept, but the
out.h written by the device is lost and reverts to its initial all-zero
values. virtio_fs_verify_response() rejects that header, because
its unique and length do not match, and the request finishes with -EIO.

Place out.h on its own DMA granule and start waitq on the following
one. Allocate the slab at __alignof__(struct fuse_req) so those
offsets are granule-aligned in memory. Coherent architectures keep
ARCH_DMA_MINALIGN at the natural alignment, so fuse_req does not grow
there. The padding is compiled in only when virtiofs is enabled.

Fixes: a62a8ef9d97d ("virtio-fs: add virtiofs filesystem")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-41eaaf0f-0eb9-4809-99cf-5f83439eb848
Signed-off-by: Li Wang <liwang@kylinos.cn>
---
 fs/fuse/dev.c        |  3 ++-
 fs/fuse/fuse_dev_i.h | 18 ++++++++++++++++--
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index b198cc729cba..00e637d5e552 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2342,7 +2342,8 @@ int __init fuse_dev_init(void)
 	int err = -ENOMEM;
 	fuse_req_cachep = kmem_cache_create("fuse_request",
 					    sizeof(struct fuse_req),
-					    0, 0, NULL);
+					    __alignof__(struct fuse_req),
+					    0, NULL);
 	if (!fuse_req_cachep)
 		goto out;
 
diff --git a/fs/fuse/fuse_dev_i.h b/fs/fuse/fuse_dev_i.h
index a8eba46a3e51..e42f3dc30d3b 100644
--- a/fs/fuse/fuse_dev_i.h
+++ b/fs/fuse/fuse_dev_i.h
@@ -12,6 +12,18 @@
 #include <linux/wait.h>
 #include <linux/workqueue.h>
 #include <linux/fs.h>
+#include <linux/cache.h>
+
+/*
+ * virtiofs DMA-maps fuse_req::out.h for DMA_FROM_DEVICE in place.
+ * Put @out on its own granule and start @waitq on the next one.
+ * fuse_dev_init() allocates the slab at this alignment.
+ */
+#if IS_ENABLED(CONFIG_VIRTIO_FS)
+#define FUSE_REQ_DMA_ALIGN __aligned(ARCH_DMA_MINALIGN)
+#else
+#define FUSE_REQ_DMA_ALIGN
+#endif
 
 /* Ordinary requests have even IDs, while interrupts IDs are odd */
 #define FUSE_INT_REQ_BIT (1ULL << 0)
@@ -94,10 +106,10 @@ struct fuse_req {
 	struct {
 		/** @out.h: The request output header */
 		struct fuse_out_header h;
-	} out;
+	} out FUSE_REQ_DMA_ALIGN;
 
 	/** @waitq: Used to wake up the task waiting for completion of request */
-	wait_queue_head_t waitq;
+	wait_queue_head_t waitq FUSE_REQ_DMA_ALIGN;
 
 #if IS_ENABLED(CONFIG_VIRTIO_FS)
 	/**
@@ -118,6 +130,8 @@ struct fuse_req {
 	unsigned long create_time;
 };
 
+#undef FUSE_REQ_DMA_ALIGN
+
 /* One forget request */
 struct fuse_forget_link {
 	struct fuse_forget_one forget_one;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-25 10:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  9:39 [PATCH] virtiofs: fix lost reply due to unaligned cache line sharing Li Wang
2026-11-25  9:53 ` sashiko-bot
2026-11-25 10:46 ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox