* [PATCH] ext4: Fix stale xarray tags after writeback
@ 2026-02-05 9:22 Jan Kara
2026-03-26 11:57 ` Theodore Ts'o
0 siblings, 1 reply; 2+ messages in thread
From: Jan Kara @ 2026-02-05 9:22 UTC (permalink / raw)
To: Ted Tso; +Cc: linux-ext4, Gerald Yang, Jan Kara
There are cases where ext4_bio_write_page() gets called for a page which
has no buffers to submit. This happens e.g. when the part of the file is
actually a hole, when we cannot allocate blocks due to being called from
jbd2, or in data=journal mode when checkpointing writes the buffers
earlier. In these cases we just return from ext4_bio_write_page()
however if the page didn't need redirtying, we will leave stale DIRTY
and/or TOWRITE tags in xarray because those get cleared only in
__folio_start_writeback(). As a result we can leave these tags set in
mappings even after a final sync on filesystem that's getting remounted
read-only or that's being frozen. Various assertions can then get upset
when writeback is started on such filesystems (Gerald reported assertion
in ext4_journal_check_start() firing).
Fix the problem by cycling the page through writeback state even if we
decide nothing needs to be written for it so that xarray tags get
properly updated. This is slightly silly (we could update the xarray
tags directly) but I don't think a special helper messing with xarray
tags is really worth it in this relatively rare corner case.
Reported-by: Gerald Yang <gerald.yang@canonical.com>
Link: https://lore.kernel.org/all/20260128074515.2028982-1-gerald.yang@canonical.com
Fixes: dff4ac75eeee ("ext4: move keep_towrite handling to ext4_bio_write_page()")
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/ext4/page-io.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 39abfeec5f36..0a3ef9bd6803 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -523,9 +523,15 @@ int ext4_bio_write_folio(struct ext4_io_submit *io, struct folio *folio,
nr_to_submit++;
} while ((bh = bh->b_this_page) != head);
- /* Nothing to submit? Just unlock the folio... */
- if (!nr_to_submit)
+ if (!nr_to_submit) {
+ /*
+ * We have nothing to submit. Just cycle the folio through
+ * writeback state to properly update xarray tags.
+ */
+ __folio_start_writeback(folio, keep_towrite);
+ folio_end_writeback(folio);
return 0;
+ }
bh = head = folio_buffers(folio);
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] ext4: Fix stale xarray tags after writeback
2026-02-05 9:22 [PATCH] ext4: Fix stale xarray tags after writeback Jan Kara
@ 2026-03-26 11:57 ` Theodore Ts'o
0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2026-03-26 11:57 UTC (permalink / raw)
To: Jan Kara; +Cc: Theodore Ts'o, linux-ext4, Gerald Yang
On Thu, 05 Feb 2026 10:22:24 +0100, Jan Kara wrote:
> There are cases where ext4_bio_write_page() gets called for a page which
> has no buffers to submit. This happens e.g. when the part of the file is
> actually a hole, when we cannot allocate blocks due to being called from
> jbd2, or in data=journal mode when checkpointing writes the buffers
> earlier. In these cases we just return from ext4_bio_write_page()
> however if the page didn't need redirtying, we will leave stale DIRTY
> and/or TOWRITE tags in xarray because those get cleared only in
> __folio_start_writeback(). As a result we can leave these tags set in
> mappings even after a final sync on filesystem that's getting remounted
> read-only or that's being frozen. Various assertions can then get upset
> when writeback is started on such filesystems (Gerald reported assertion
> in ext4_journal_check_start() firing).
>
> [...]
Applied, thanks!
[1/1] ext4: Fix stale xarray tags after writeback
commit: bc6874ab41809f210c3e966576374d0778e144ff
Best regards,
--
Theodore Ts'o <tytso@mit.edu>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-26 11:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-05 9:22 [PATCH] ext4: Fix stale xarray tags after writeback Jan Kara
2026-03-26 11:57 ` Theodore Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox