* [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* Re: [PATCH] virtiofs: fix lost reply due to unaligned cache line sharing
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
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-25 9:53 UTC (permalink / raw)
To: Li Wang; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] fuse: FUSE_REQ_DMA_ALIGN macro on struct fuse_req breaks
kernel-doc parsing
--
commit 3bc673b953140f81a8cc8d09ee9dceb6e21e9096
Author: Li Wang <liwang@kylinos.cn>
virtiofs: fix lost reply due to unaligned cache line sharing
This commit aligns struct fuse_req::out and struct fuse_req::waitq to
ARCH_DMA_MINALIGN when CONFIG_VIRTIO_FS is enabled and creates the
fuse_request slab cache with struct fuse_req alignment so DMA unmapping
of out.h does not share a cache line with waitq.
> diff --git a/fs/fuse/fuse_dev_i.h b/fs/fuse/fuse_dev_i.h
> index a8eba46a3e51d..e42f3dc30d3b6 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;
[Severity: Low]
Does placing FUSE_REQ_DMA_ALIGN after the member names break kernel-doc
parsing for struct fuse_req?
scripts/kernel-doc strips known attributes such as __aligned(...) from
struct members (via CTransforms.struct_xforms in
tools/lib/python/kdoc/xforms_lists.py), but it does not expand custom
wrapper macros. As a result, kernel-doc parses FUSE_REQ_DMA_ALIGN as the
member identifier instead of out and waitq, emitting warnings for an
undescribed FUSE_REQ_DMA_ALIGN member and excess descriptions for out,
out.h, and waitq.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125093908.48619-1-liwang@kylinos.cn?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] virtiofs: fix lost reply due to unaligned cache line sharing
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
1 sibling, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2026-11-25 10:46 UTC (permalink / raw)
To: Li Wang
Cc: Miklos Szeredi, German Maglione, Vivek Goyal, Stefan Hajnoczi,
Eugenio Pérez, fuse-devel, virtualization, linux-fsdevel,
virtio-fs, stable, Sashiko
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
^ permalink raw reply [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