linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/1] iomap: fix iomap_read_end() for already uptodate folios
@ 2025-11-18 21:11 Joanne Koong
  2025-11-18 21:11 ` [PATCH v2 1/1] " Joanne Koong
  2025-11-19 10:12 ` [PATCH v2 0/1] " Christian Brauner
  0 siblings, 2 replies; 3+ messages in thread
From: Joanne Koong @ 2025-11-18 21:11 UTC (permalink / raw)
  To: brauner; +Cc: djwong, hch, linux-fsdevel, willy

This is a fix for commit f8eaf79406fe in the 'vfs-6.19.iomap' branch. It
would be great if this could get folded up into that original commit, if it's
not too late to do so.

Thanks,
Joanne

v1: https://lore.kernel.org/linux-fsdevel/20251118004421.3500340-1-joannelkoong@gmail.com/
v1 -> v2:
* Improve readability and formatting (pointed out by Christoph)
* Add Matthew's "Tested-by" and Christoph's "Reviewed-by"

Joanne Koong (1):
  iomap: fix iomap_read_end() for already uptodate folios

 fs/iomap/buffered-io.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

-- 
2.47.3


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

* [PATCH v2 1/1] iomap: fix iomap_read_end() for already uptodate folios
  2025-11-18 21:11 [PATCH v2 0/1] iomap: fix iomap_read_end() for already uptodate folios Joanne Koong
@ 2025-11-18 21:11 ` Joanne Koong
  2025-11-19 10:12 ` [PATCH v2 0/1] " Christian Brauner
  1 sibling, 0 replies; 3+ messages in thread
From: Joanne Koong @ 2025-11-18 21:11 UTC (permalink / raw)
  To: brauner; +Cc: djwong, hch, linux-fsdevel, willy, Christoph Hellwig

There are some cases where when iomap_read_end() is called, the folio
may already have been marked uptodate. For example, if the iomap block
needed zeroing, then the folio may have been marked uptodate after the
zeroing.

iomap_read_end() should unlock the folio instead of calling
folio_end_read(), which is how these cases were handled prior to commit
f8eaf79406fe ("iomap: simplify ->read_folio_range() error handling for
reads"). Calling folio_end_read() on an uptodate folio leads to buggy
behavior where marking an already uptodate folio as uptodate will XOR it
to be marked nonuptodate.

Fixes: f8eaf79406fe ("iomap: simplify ->read_folio_range() error handling for reads")
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Reported-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/iomap/buffered-io.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 0475d949e5a0..c3e73203809d 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -459,25 +459,26 @@ static void iomap_read_end(struct folio *folio, size_t bytes_submitted)
 		spin_lock_irq(&ifs->state_lock);
 		if (!ifs->read_bytes_pending) {
 			WARN_ON_ONCE(bytes_submitted);
-			end_read = true;
-		} else {
-			/*
-			 * Subtract any bytes that were initially accounted to
-			 * read_bytes_pending but skipped for IO. The +1
-			 * accounts for the bias we added in iomap_read_init().
-			 */
-			size_t bytes_not_submitted = folio_size(folio) + 1 -
-					bytes_submitted;
-			ifs->read_bytes_pending -= bytes_not_submitted;
-			/*
-			 * If !ifs->read_bytes_pending, this means all pending
-			 * reads by the IO helper have already completed, which
-			 * means we need to end the folio read here. If
-			 * ifs->read_bytes_pending != 0, the IO helper will end
-			 * the folio read.
-			 */
-			end_read = !ifs->read_bytes_pending;
+			spin_unlock_irq(&ifs->state_lock);
+			folio_unlock(folio);
+			return;
 		}
+
+		/*
+		 * Subtract any bytes that were initially accounted to
+		 * read_bytes_pending but skipped for IO. The +1 accounts for
+		 * the bias we added in iomap_read_init().
+		 */
+		ifs->read_bytes_pending -=
+			(folio_size(folio) + 1 - bytes_submitted);
+
+		/*
+		 * If !ifs->read_bytes_pending, this means all pending reads by
+		 * the IO helper have already completed, which means we need to
+		 * end the folio read here. If ifs->read_bytes_pending != 0,
+		 * the IO helper will end the folio read.
+		 */
+		end_read = !ifs->read_bytes_pending;
 		if (end_read)
 			uptodate = ifs_is_fully_uptodate(folio, ifs);
 		spin_unlock_irq(&ifs->state_lock);
-- 
2.47.3


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

* Re: [PATCH v2 0/1] iomap: fix iomap_read_end() for already uptodate folios
  2025-11-18 21:11 [PATCH v2 0/1] iomap: fix iomap_read_end() for already uptodate folios Joanne Koong
  2025-11-18 21:11 ` [PATCH v2 1/1] " Joanne Koong
@ 2025-11-19 10:12 ` Christian Brauner
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2025-11-19 10:12 UTC (permalink / raw)
  To: Joanne Koong; +Cc: Christian Brauner, djwong, hch, linux-fsdevel, willy

On Tue, 18 Nov 2025 13:11:10 -0800, Joanne Koong wrote:
> This is a fix for commit f8eaf79406fe in the 'vfs-6.19.iomap' branch. It
> would be great if this could get folded up into that original commit, if it's
> not too late to do so.
> 
> Thanks,
> Joanne
> 
> [...]

Applied to the vfs-6.19.iomap branch of the vfs/vfs.git tree.
Patches in the vfs-6.19.iomap branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.19.iomap

[1/1] iomap: fix iomap_read_end() for already uptodate folios
      https://git.kernel.org/vfs/vfs/c/2e7278a6e951

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

end of thread, other threads:[~2025-11-19 10:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-18 21:11 [PATCH v2 0/1] iomap: fix iomap_read_end() for already uptodate folios Joanne Koong
2025-11-18 21:11 ` [PATCH v2 1/1] " Joanne Koong
2025-11-19 10:12 ` [PATCH v2 0/1] " Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).