From: "Michael S. Tsirkin" <mst@redhat.com>
To: Li Wang <liwang@kylinos.cn>
Cc: "Miklos Szeredi" <miklos@szeredi.hu>,
"German Maglione" <gmaglione@redhat.com>,
"Vivek Goyal" <vgoyal@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
fuse-devel@lists.linux.dev, virtualization@lists.linux.dev,
linux-fsdevel@vger.kernel.org, virtio-fs@lists.linux.dev,
stable@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH] virtiofs: fix lost reply due to unaligned cache line sharing
Date: Wed, 25 Nov 2026 05:46:09 -0500 [thread overview]
Message-ID: <20261125053116-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20261125093908.48619-1-liwang@kylinos.cn>
Thanks for the patch! yet something to improve:
On Wed, Nov 25, 2026 at 05:39:08PM +0800, Li Wang wrote:
> 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.
Is this not all completely theoretical for when virtio fs
device is on a real hardware chip as opposed to running
on a cache coherent cpu? With LLMs hallucinating real life
impact?
But anyway, this is not how one should write commit logs.
Should be, for example:
Currently .... as a result, when ... then ...
but ... so we can not ... . To fix ... as a result ....
Tested by ...
> Fixes: a62a8ef9d97d ("virtio-fs: add virtiofs filesystem")
theoretical cleanups, as I suspect this one is, do not need a fixes tag.
> Cc: stable@vger.kernel.org
and accordingly it is not appropriate for stable.
> 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
virtio fs specific code in fuse headers. not good.
>
> /* 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;
Ugh.
You want __dma_from_device_group_begin/end
Maybe. If it even is ok to dma here directly.
>
> /** @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
prev parent reply other threads:[~2026-11-25 10:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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=20261125053116-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=eperezma@redhat.com \
--cc=fuse-devel@lists.linux.dev \
--cc=gmaglione@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=liwang@kylinos.cn \
--cc=miklos@szeredi.hu \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.