All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] iomap/fuse: add helper to keep uptodate bitmap in sync
@ 2026-07-07 22:04 Joanne Koong
  2026-07-07 22:04 ` [PATCH v3 1/3] fuse: don't clear folio uptodate on writethrough errors Joanne Koong
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Joanne Koong @ 2026-07-07 22:04 UTC (permalink / raw)
  To: brauner; +Cc: djwong, hch, miklos, willy, linux-fsdevel, fuse-devel

Filesystems that use iomap normally mark folios uptodate through the iomap
read/write paths, which keep iomap's internal uptodate bitmap in sync.
However, some filesystems need to write data directly into the page cache
outside of those paths (eg fuse, which may need to write server-pushed data
straight into the page cache for servicing notify stores). These filesystems
need a way to mark a folio uptodate that also updates the iomap bitmap so
they're kept in sync.

This series adds iomap_folio_mark_uptodate() for filesystems to do that and
updates the relevant fuse call paths to use this. This is needed before fuse
can enable large folios.

Patch 1 ("fuse: don't clear folio uptodate on writethrough errors") was
originally submitted to the fuse tree [1] but patch 3 ("fuse: use iomap helper
to mark folio uptodate") has a dependency on it, so to make cross-coordination
between trees easier, patch 1 is now part of this series and submitted to the
vfs tree. This series is based on top of the vfs-7.3.iomap branch (head commit
e1b77fb85836e ("Merge patch series "iomap: add simple dio path...")).

Thanks,
Joanne

[1] https://lore.kernel.org/fuse-devel/20260624205201.842714-1-joannelkoong@gmail.com/

Changelog
---------
v2: https://lore.kernel.org/linux-fsdevel/20260624212925.1668662-1-joannelkoong@gmail.com/
* add Reviewed-by tags and rebase onto the vfs-7.3.iomap branch 
* include patch 1 from [1], to ensure ordering between patches for bisectability

v1: https://lore.kernel.org/linux-fsdevel/20260623202843.2064992-1-joannelkoong@gmail.com/
v1 -> v2:
* drop helper for clearing uptodate state, as per Matthew and Christoph's
  comments

Joanne Koong (3):
  fuse: don't clear folio uptodate on writethrough errors
  iomap: add helper to mark folio uptodate
  fuse: use iomap helper to mark folio uptodate

 fs/fuse/file.c         | 20 ++------------------
 fs/fuse/notify.c       |  4 +++-
 fs/iomap/buffered-io.c |  6 ++++++
 include/linux/iomap.h  |  1 +
 4 files changed, 12 insertions(+), 19 deletions(-)

-- 
2.52.0


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

* [PATCH v3 1/3] fuse: don't clear folio uptodate on writethrough errors
  2026-07-07 22:04 [PATCH v3 0/3] iomap/fuse: add helper to keep uptodate bitmap in sync Joanne Koong
@ 2026-07-07 22:04 ` Joanne Koong
  2026-07-08  7:49   ` Christoph Hellwig
  2026-07-08  9:15   ` Miklos Szeredi
  2026-07-07 22:04 ` [PATCH v3 2/3] iomap: add helper to mark folio uptodate Joanne Koong
  2026-07-07 22:04 ` [PATCH v3 3/3] fuse: use iomap " Joanne Koong
  2 siblings, 2 replies; 10+ messages in thread
From: Joanne Koong @ 2026-07-07 22:04 UTC (permalink / raw)
  To: brauner; +Cc: djwong, hch, miklos, willy, linux-fsdevel, fuse-devel

In the writethrough path (fuse_send_write_pages()), if the write to the
server failed or was a short write, the uptodate flag on the folios are
cleared.

As explained by Matthew in [1], this is dangerous because the folio may
be mapped into userspace. The mm code has the invariant that a
non-uptodate folio must never be visible to userspace (to avoid
potentially leaking confidental information to userspace) and has checks
in place for this that if violated can bring down the whole machine.

Practically speaking, the effect of this change for the fuse
writethrough error path is that if an application does a write and then
the server fails to persist the data or only services a short write, the
page cache folio keeps the data the application wrote instead of being
reverted to the server's contents on the next read. The failure is still
reported to the application synchronously through the short count /
error return of the write() syscall. Folios that were only partially
written are unaffected since they were never marked uptodate in the
first place (fuse_fill_write_page() only marks a folio as uptodate if
the whole folio was written to).

[1] https://lore.kernel.org/linux-fsdevel/ajtPMgO65FA1TXhi@casper.infradead.org/

Suggested-by: Matthew Wilcox <willy@infradead.org>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
 fs/fuse/file.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index e052a0d44dee..a72959dbcf12 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1227,8 +1227,7 @@ static ssize_t fuse_send_write_pages(struct fuse_io_args *ia,
 	struct file *file = iocb->ki_filp;
 	struct fuse_file *ff = file->private_data;
 	struct fuse_mount *fm = ff->fm;
-	unsigned int offset, i;
-	bool short_write;
+	unsigned int i;
 	int err;
 
 	for (i = 0; i < ap->num_folios; i++)
@@ -1243,24 +1242,9 @@ static ssize_t fuse_send_write_pages(struct fuse_io_args *ia,
 	if (!err && ia->write.out.size > count)
 		err = -EIO;
 
-	short_write = ia->write.out.size < count;
-	offset = ap->descs[0].offset;
-	count = ia->write.out.size;
 	for (i = 0; i < ap->num_folios; i++) {
 		struct folio *folio = ap->folios[i];
 
-		if (err) {
-			folio_clear_uptodate(folio);
-		} else {
-			if (count >= folio_size(folio) - offset)
-				count -= folio_size(folio) - offset;
-			else {
-				if (short_write)
-					folio_clear_uptodate(folio);
-				count = 0;
-			}
-			offset = 0;
-		}
 		if (ia->write.folio_locked && (i == ap->num_folios - 1))
 			folio_unlock(folio);
 		folio_put(folio);
-- 
2.52.0


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

* [PATCH v3 2/3] iomap: add helper to mark folio uptodate
  2026-07-07 22:04 [PATCH v3 0/3] iomap/fuse: add helper to keep uptodate bitmap in sync Joanne Koong
  2026-07-07 22:04 ` [PATCH v3 1/3] fuse: don't clear folio uptodate on writethrough errors Joanne Koong
@ 2026-07-07 22:04 ` Joanne Koong
  2026-07-08  9:17   ` Miklos Szeredi
  2026-07-07 22:04 ` [PATCH v3 3/3] fuse: use iomap " Joanne Koong
  2 siblings, 1 reply; 10+ messages in thread
From: Joanne Koong @ 2026-07-07 22:04 UTC (permalink / raw)
  To: brauner; +Cc: djwong, hch, miklos, willy, linux-fsdevel, fuse-devel

Add an exported helper iomap_folio_mark_uptodate() to mark a folio as
uptodate and update its uptodate bitmap if the folio has iomap state
data attached.

This is needed because there are some filesystems (eg fuse) that have
paths outside of conventional iomap calls that need to mark a folio as
uptodate (eg writing server-pushed data directly into the page cache)
and need the iomap-internal uptodate bitmap to be in sync with the
uptodate state of the folio.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
 fs/iomap/buffered-io.c | 6 ++++++
 include/linux/iomap.h  | 1 +
 2 files changed, 7 insertions(+)

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 27bc2455a98d..f6040199d114 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -105,6 +105,12 @@ static void iomap_set_range_uptodate(struct folio *folio, size_t off,
 		folio_mark_uptodate(folio);
 }
 
+void iomap_folio_mark_uptodate(struct folio *folio)
+{
+	iomap_set_range_uptodate(folio, 0, folio_size(folio));
+}
+EXPORT_SYMBOL_GPL(iomap_folio_mark_uptodate);
+
 /*
  * Find the next dirty block in the folio. end_blk is inclusive.
  * If no dirty block is found, this will return end_blk + 1.
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 3582ed1fe236..21e73cb9c51e 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -365,6 +365,7 @@ struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len);
 bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags);
 void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len);
 bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio);
+void iomap_folio_mark_uptodate(struct folio *folio);
 int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
 		const struct iomap_ops *ops,
 		const struct iomap_write_ops *write_ops);
-- 
2.52.0


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

* [PATCH v3 3/3] fuse: use iomap helper to mark folio uptodate
  2026-07-07 22:04 [PATCH v3 0/3] iomap/fuse: add helper to keep uptodate bitmap in sync Joanne Koong
  2026-07-07 22:04 ` [PATCH v3 1/3] fuse: don't clear folio uptodate on writethrough errors Joanne Koong
  2026-07-07 22:04 ` [PATCH v3 2/3] iomap: add helper to mark folio uptodate Joanne Koong
@ 2026-07-07 22:04 ` Joanne Koong
  2026-07-08  7:50   ` Christoph Hellwig
  2026-07-08  9:18   ` Miklos Szeredi
  2 siblings, 2 replies; 10+ messages in thread
From: Joanne Koong @ 2026-07-07 22:04 UTC (permalink / raw)
  To: brauner; +Cc: djwong, hch, miklos, willy, linux-fsdevel, fuse-devel

When fuse enables large folios, a large folio will be backed by
iomap_folio_state that keeps track of uptodate and dirty state in an
internal bitmap.

Fuse writethrough and notify store paths currently set folio uptodate
state with folio_mark_uptodate(), which touches only the folio-level
flag, but on an iomap-backed folio, that leaves the uptodate bitmap out
of sync.

Use the iomap_folio_mark_uptodate() helper to update both the folio
uptodate state and the iomap uptodate bitmap.

Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
 fs/fuse/file.c   | 2 +-
 fs/fuse/notify.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index a72959dbcf12..ea4a15a7635a 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1319,7 +1319,7 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
 
 		/* If we copied full folio, mark it uptodate */
 		if (tmp == folio_size(folio))
-			folio_mark_uptodate(folio);
+			iomap_folio_mark_uptodate(folio);
 
 		if (folio_test_uptodate(folio)) {
 			folio_unlock(folio);
diff --git a/fs/fuse/notify.c b/fs/fuse/notify.c
index 29578104ae6c..1ba763705d91 100644
--- a/fs/fuse/notify.c
+++ b/fs/fuse/notify.c
@@ -2,6 +2,8 @@
 
 #include "dev.h"
 #include "fuse_i.h"
+
+#include <linux/iomap.h>
 #include <linux/pagemap.h>
 
 static int fuse_notify_poll(struct fuse_conn *fc, unsigned int size,
@@ -192,7 +194,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
 		if (!folio_test_uptodate(folio) && !err && folio_offset == 0 &&
 		    (nr_bytes == folio_size(folio) || file_size == end)) {
 			folio_zero_segment(folio, nr_bytes, folio_size(folio));
-			folio_mark_uptodate(folio);
+			iomap_folio_mark_uptodate(folio);
 		}
 		folio_unlock(folio);
 		folio_put(folio);
-- 
2.52.0


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

* Re: [PATCH v3 1/3] fuse: don't clear folio uptodate on writethrough errors
  2026-07-07 22:04 ` [PATCH v3 1/3] fuse: don't clear folio uptodate on writethrough errors Joanne Koong
@ 2026-07-08  7:49   ` Christoph Hellwig
  2026-07-08  9:15   ` Miklos Szeredi
  1 sibling, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2026-07-08  7:49 UTC (permalink / raw)
  To: Joanne Koong; +Cc: brauner, djwong, miklos, willy, linux-fsdevel, fuse-devel

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH v3 3/3] fuse: use iomap helper to mark folio uptodate
  2026-07-07 22:04 ` [PATCH v3 3/3] fuse: use iomap " Joanne Koong
@ 2026-07-08  7:50   ` Christoph Hellwig
  2026-07-08  9:18   ` Miklos Szeredi
  1 sibling, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2026-07-08  7:50 UTC (permalink / raw)
  To: Joanne Koong; +Cc: brauner, djwong, miklos, willy, linux-fsdevel, fuse-devel

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH v3 1/3] fuse: don't clear folio uptodate on writethrough errors
  2026-07-07 22:04 ` [PATCH v3 1/3] fuse: don't clear folio uptodate on writethrough errors Joanne Koong
  2026-07-08  7:49   ` Christoph Hellwig
@ 2026-07-08  9:15   ` Miklos Szeredi
  1 sibling, 0 replies; 10+ messages in thread
From: Miklos Szeredi @ 2026-07-08  9:15 UTC (permalink / raw)
  To: Joanne Koong; +Cc: brauner, djwong, hch, willy, linux-fsdevel, fuse-devel

On Wed, 8 Jul 2026 at 00:05, Joanne Koong <joannelkoong@gmail.com> wrote:
>
> In the writethrough path (fuse_send_write_pages()), if the write to the
> server failed or was a short write, the uptodate flag on the folios are
> cleared.
>
> As explained by Matthew in [1], this is dangerous because the folio may
> be mapped into userspace. The mm code has the invariant that a
> non-uptodate folio must never be visible to userspace (to avoid
> potentially leaking confidental information to userspace) and has checks
> in place for this that if violated can bring down the whole machine.
>
> Practically speaking, the effect of this change for the fuse
> writethrough error path is that if an application does a write and then
> the server fails to persist the data or only services a short write, the
> page cache folio keeps the data the application wrote instead of being
> reverted to the server's contents on the next read. The failure is still
> reported to the application synchronously through the short count /
> error return of the write() syscall. Folios that were only partially
> written are unaffected since they were never marked uptodate in the
> first place (fuse_fill_write_page() only marks a folio as uptodate if
> the whole folio was written to).
>
> [1] https://lore.kernel.org/linux-fsdevel/ajtPMgO65FA1TXhi@casper.infradead.org/
>
> Suggested-by: Matthew Wilcox <willy@infradead.org>
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>

Acked-by: Miklos Szeredi <mszeredi@redhat.com>

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

* Re: [PATCH v3 2/3] iomap: add helper to mark folio uptodate
  2026-07-07 22:04 ` [PATCH v3 2/3] iomap: add helper to mark folio uptodate Joanne Koong
@ 2026-07-08  9:17   ` Miklos Szeredi
  2026-07-08 18:29     ` Joanne Koong
  0 siblings, 1 reply; 10+ messages in thread
From: Miklos Szeredi @ 2026-07-08  9:17 UTC (permalink / raw)
  To: Joanne Koong; +Cc: brauner, djwong, hch, willy, linux-fsdevel, fuse-devel

On Wed, 8 Jul 2026 at 00:05, Joanne Koong <joannelkoong@gmail.com> wrote:
>
> Add an exported helper iomap_folio_mark_uptodate() to mark a folio as
> uptodate and update its uptodate bitmap if the folio has iomap state
> data attached.

Sashiko has a non-regression comment about this:

https://sashiko.dev/#/patchset/20260707220450.1200943-1-joannelkoong%40gmail.com

Can you have a look, please?

Thanks,
Miklos

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

* Re: [PATCH v3 3/3] fuse: use iomap helper to mark folio uptodate
  2026-07-07 22:04 ` [PATCH v3 3/3] fuse: use iomap " Joanne Koong
  2026-07-08  7:50   ` Christoph Hellwig
@ 2026-07-08  9:18   ` Miklos Szeredi
  1 sibling, 0 replies; 10+ messages in thread
From: Miklos Szeredi @ 2026-07-08  9:18 UTC (permalink / raw)
  To: Joanne Koong; +Cc: brauner, djwong, hch, willy, linux-fsdevel, fuse-devel

On Wed, 8 Jul 2026 at 00:05, Joanne Koong <joannelkoong@gmail.com> wrote:
>
> When fuse enables large folios, a large folio will be backed by
> iomap_folio_state that keeps track of uptodate and dirty state in an
> internal bitmap.
>
> Fuse writethrough and notify store paths currently set folio uptodate
> state with folio_mark_uptodate(), which touches only the folio-level
> flag, but on an iomap-backed folio, that leaves the uptodate bitmap out
> of sync.
>
> Use the iomap_folio_mark_uptodate() helper to update both the folio
> uptodate state and the iomap uptodate bitmap.
>
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>

Acked-by: Miklos Szeredi <mszeredi@redhat.com>

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

* Re: [PATCH v3 2/3] iomap: add helper to mark folio uptodate
  2026-07-08  9:17   ` Miklos Szeredi
@ 2026-07-08 18:29     ` Joanne Koong
  0 siblings, 0 replies; 10+ messages in thread
From: Joanne Koong @ 2026-07-08 18:29 UTC (permalink / raw)
  To: Miklos Szeredi
  Cc: brauner, djwong, hch, willy, linux-fsdevel, fuse-devel, Zhang Yi

On Wed, Jul 8, 2026 at 2:17 AM Miklos Szeredi <miklos@szeredi.hu> wrote:
>
> On Wed, 8 Jul 2026 at 00:05, Joanne Koong <joannelkoong@gmail.com> wrote:
> >
> > Add an exported helper iomap_folio_mark_uptodate() to mark a folio as
> > uptodate and update its uptodate bitmap if the folio has iomap state
> > data attached.
>
> Sashiko has a non-regression comment about this:
>
> https://sashiko.dev/#/patchset/20260707220450.1200943-1-joannelkoong%40gmail.com
>
> Can you have a look, please?

I think this underflow issue was fixed by Zhang's patch in [1] that he
sent out in May but I don't think that has been merged yet. I'll
follow up on his series about the status of it.

Thanks,
Joanne

[1] https://lore.kernel.org/linux-fsdevel/20260514062955.1183976-5-yi.zhang@huaweicloud.com/

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

end of thread, other threads:[~2026-07-08 18:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07 22:04 [PATCH v3 0/3] iomap/fuse: add helper to keep uptodate bitmap in sync Joanne Koong
2026-07-07 22:04 ` [PATCH v3 1/3] fuse: don't clear folio uptodate on writethrough errors Joanne Koong
2026-07-08  7:49   ` Christoph Hellwig
2026-07-08  9:15   ` Miklos Szeredi
2026-07-07 22:04 ` [PATCH v3 2/3] iomap: add helper to mark folio uptodate Joanne Koong
2026-07-08  9:17   ` Miklos Szeredi
2026-07-08 18:29     ` Joanne Koong
2026-07-07 22:04 ` [PATCH v3 3/3] fuse: use iomap " Joanne Koong
2026-07-08  7:50   ` Christoph Hellwig
2026-07-08  9:18   ` Miklos Szeredi

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.