[PATCH v3 0/3] btrfs: fix dirtying of folios that lost their private
From: Brahmajit Das
Date: Thu Dec 03 2026 - 08:31:19 EST
From: Brahmajit Das <bdas@xxxxxxx>
syzbot hit an ASSERT() in wait_subpage_spinlock() when writeback
invalidates a beyond-EOF folio that has no folio::private. The folio
lost its private while it stayed in the page cache, pinned by an
O_DIRECT read, from btrfs_release_folio() during a partial invalidation
or a failed large folio split. When the read completed, the folio was
dirtied again through btrfs_data_dirty_folio(), still without private.
Patch 3 is the fix: it re-attaches the private in
btrfs_data_dirty_folio() with GFP_NOWAIT, and as a fallback in the
beyond-EOF branch of extent_writepage().
Patches 1 and 2 fix problems that already exist and that patch 3 relies
on. Both were found by Sashiko AI review of v2:
- Patch 1: the -EUCLEAN path of extent_writepage() for a dirty folio
without private dereferences the NULL private for the bs < folio
size case. After patch 3, this path is reached if the GFP_NOWAIT
allocation fails for a folio inside EOF.
- Patch 2: attaching a new folio state to a released folio that is still
uptodate leaves its uptodate bitmap empty. This is now synced in
btrfs_attach_folio_state() for all callers instead of only in
btrfs_data_dirty_folio().
Open question: if the GFP_NOWAIT allocation fails for a folio inside
EOF, and some other path such as btrfs_page_mkwrite() attaches the
private before writeback, the folio passes the -EUCLEAN check but only
the caller's range is marked dirty. The rest of the data written by
the O_DIRECT read is then silently not written back. This was already
the case before this series for any folio dirtied without private. I
can mark the in-EOF range for fixup in btrfs_attach_folio_state() if
the folio is already dirty, if that is wanted.
The series is build tested only. syzbot has no reproducer.
It was written with the help of an AI coding assistant (Claude).
v3:
- Split into a series, adding patches 1 and 2 (Sashiko AI review)
- Drop the explicit uptodate bitmap sync from btrfs_data_dirty_folio(),
now done by patch 2
v2: https://lore.kernel.org/linux-btrfs/20261202041853.4184717-1-listout@xxxxxxxxxxx/
v1: https://lore.kernel.org/linux-btrfs/20261130182637.468143-1-listout@xxxxxxxxxxx/
Brahmajit Das (3):
btrfs: don't dereference a missing folio private on writeback error
btrfs: sync the uptodate bitmap when attaching a data folio state
btrfs: re-attach folio private when a released folio gets dirtied
fs/btrfs/extent_io.c | 35 ++++++++++++++++++++++++++++++-----
fs/btrfs/extent_io.h | 1 +
fs/btrfs/inode.c | 16 +++++++++++++++-
fs/btrfs/subpage.c | 18 ++++++++++++++++--
fs/btrfs/subpage.h | 3 ++-
5 files changed, 64 insertions(+), 9 deletions(-)
base-commit: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106
--
2.56.1