Re: [PATCH 5.15] fuse: Fix race condition in writethrough path A race

Miklos Szeredi
2025-10-14T16:15:39Z

[-- Attachment #1: Type: text/plain, Size: 279 bytes --]

On Tue, 14 Oct 2025 at 14:43, Miklos Szeredi <miklos@szeredi.hu> wrote:

> Will try the idea of marking folios writeback for the duration of the write.

Attaching a test patch, minimally tested.

Guangming, can you please test if this fixes the cache corruption?

Thanks,
Miklos

[-- Attachment #2: fuse-write-through-set-writeback.patch --]
[-- Type: text/x-patch, Size: 1023 bytes --]

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 905726ac3a7a..2f12a501df9d 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1121,9 +1121,6 @@ static ssize_t fuse_send_write_pages(struct fuse_io_args *ia,
bool short_write;
int err;

- for (i = 0; i < ap->num_folios; i++)
- folio_wait_writeback(ap->folios[i]);
-
fuse_write_args_fill(ia, ff, pos, count);
ia->write.in.flags = fuse_write_flags(iocb);
if (fm->fc->handle_killpriv_v2 && !capable(CAP_FSETID))
@@ -1153,6 +1150,8 @@ static ssize_t fuse_send_write_pages(struct fuse_io_args *ia,
}
if (ia->write.folio_locked && (i == ap->num_folios - 1))
folio_unlock(folio);
+ else
+ folio_end_writeback_no_dropbehind(folio);
folio_put(folio);
}

@@ -1232,6 +1231,8 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
folio_mark_uptodate(folio);

if (folio_test_uptodate(folio)) {
+ folio_wait_writeback(folio);
+ folio_start_writeback(folio);
folio_unlock(folio);
} else {
ia->write.folio_locked = true;