Linux virtualization list
 help / color / mirror / Atom feed
From: Li Wang <liwang@kylinos.cn>
To: Miklos Szeredi <miklos@szeredi.hu>,
	German Maglione <gmaglione@redhat.com>,
	Vivek Goyal <vgoyal@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Cc: "Eugenio Pérez" <eperezma@redhat.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	fuse-devel@lists.linux.dev, virtualization@lists.linux.dev,
	linux-fsdevel@vger.kernel.org, virtio-fs@lists.linux.dev,
	"Li Wang" <liwang@kylinos.cn>,
	stable@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH] virtiofs: fix lost reply due to unaligned cache line sharing
Date: Wed, 25 Nov 2026 17:39:08 +0800	[thread overview]
Message-ID: <20261125093908.48619-1-liwang@kylinos.cn> (raw)

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


             reply	other threads:[~2026-11-25  9:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  9:39 Li Wang [this message]
2026-11-25  9:53 ` [PATCH] virtiofs: fix lost reply due to unaligned cache line sharing sashiko-bot

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=20261125093908.48619-1-liwang@kylinos.cn \
    --to=liwang@kylinos.cn \
    --cc=eperezma@redhat.com \
    --cc=fuse-devel@lists.linux.dev \
    --cc=gmaglione@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=mst@redhat.com \
    --cc=sashiko-bot@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stefanha@redhat.com \
    --cc=vgoyal@redhat.com \
    --cc=virtio-fs@lists.linux.dev \
    --cc=virtualization@lists.linux.dev \
    /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