mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: joannelkoong@gmail.com
Cc: willy@infradead.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, Sasha Levin <sashal@kernel.org>
Subject: [RFC PATCH 0/1] iomap: fix race between iomap_set_range_uptodate and folio_end_read
Date: Tue, 23 Dec 2025 17:30:16 -0500	[thread overview]
Message-ID: <20251223223018.3295372-1-sashal@kernel.org> (raw)
In-Reply-To: <20250926002609.1302233-13-joannelkoong@gmail.com>

Hi Joanne,

While testing with your FUSE iomap patchset that recently landed upstream,
I ran into a warning in ifs_free() where the folio's uptodate flag didn't
match the ifs per-block uptodate bitmap. The warning was triggered during
FUSE-based filesystem unmount when running the LTP writev03 test.

After some investigation, I believe the root cause is a race condition
that has existed since commit 7a4847e54cc1 ("iomap: use folio_end_read()")
but was difficult to trigger until now. The issue is that folio_end_read()
uses XOR semantics to set the uptodate bit, so if iomap_set_range_uptodate()
calls folio_mark_uptodate() while a read is in progress, the subsequent
folio_end_read() will XOR and clear the uptodate bit.

The FUSE iomap enablement seems to have created the right conditions to
expose this race - likely due to different file extent patterns in
FUSE-based filesystems (like NTFS-3G) compared to native filesystems
like XFS/ext4.

The fix checks read_bytes_pending under the state_lock in
iomap_set_range_uptodate() and skips calling folio_mark_uptodate() if a
read is in progress, letting the read completion path handle it.

I'm not very familiar with the iomap internals, so I'd really appreciate
your review and feedback on whether this approach is correct.

Thanks,
Sasha

Sasha Levin (1):
  iomap: fix race between iomap_set_range_uptodate and folio_end_read

 fs/fuse/dev.c          |  3 +-
 fs/fuse/file.c         |  6 ++--
 fs/iomap/buffered-io.c | 65 +++++++++++++++++++++++++++++++++++++++---
 include/linux/iomap.h  |  2 ++
 4 files changed, 68 insertions(+), 8 deletions(-)

-- 
2.51.0


       reply	other threads:[~2025-12-23 22:30 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250926002609.1302233-13-joannelkoong@gmail.com>
2025-12-23 22:30 ` Sasha Levin [this message]
2025-12-23 22:30   ` [RFC PATCH 1/1] " Sasha Levin
2025-12-24  1:12     ` Joanne Koong
2025-12-24  1:31       ` Sasha Levin
2026-02-07  7:16         ` Wei Gao
2026-02-09 19:08           ` Joanne Koong
2026-02-10  0:12             ` Wei Gao
2026-02-10  0:20               ` Joanne Koong
2026-02-10  0:40                 ` Wei Gao
2026-02-10 22:18                   ` Joanne Koong
2026-02-11  0:00                     ` Sasha Levin
2026-02-11  3:11                     ` Matthew Wilcox
2026-02-11 19:33                       ` Joanne Koong
2026-02-11 21:03                         ` Matthew Wilcox
2026-02-11 23:13                           ` Joanne Koong
2026-02-12 19:31                             ` Matthew Wilcox
2026-02-13  0:53                               ` Joanne Koong
2025-12-24  2:10       ` Matthew Wilcox
2025-12-24 15:43         ` Sasha Levin
2025-12-24 17:27           ` Matthew Wilcox
2025-12-24 21:21             ` Sasha Levin
2025-12-30  0:58               ` Joanne Koong

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=20251223223018.3295372-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=joannelkoong@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=willy@infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®