[PATCH v4 0/2] btrfs: fix dirtying of folios that lost their private

From: listout

Date: Fri Dec 04 2026 - 01:33:24 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 2 is the fix. btrfs_data_dirty_folio() now re-attaches the
private with GFP_NOFS | __GFP_NOFAIL, the same way iomap_dirty_folio()
allocates its per-folio state, and syncs the uptodate bitmap with the
folio flag.

Patch 1 fixes a NULL dereference in the -EUCLEAN path of
extent_writepage() for a dirty folio without private, which predates
this series. It is unchanged from v3.

Both patches are build tested only. syzbot has no reproducer.

The series was written with the help of an AI coding assistant (Claude).

v4:
- Use GFP_NOFS | __GFP_NOFAIL like iomap, and drop the GFP_NOWAIT
failure handling and the extent_writepage() fallback (Qu). This also
resolves the v3 open question about losing fixup ranges when the
allocation fails.
- Drop v3 patch 2 and sync the uptodate bitmap only in
btrfs_data_dirty_folio() (Qu)

v3: https://lore.kernel.org/linux-btrfs/20261203133059.2193197-1-listout@xxxxxxxxxxx/
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 (2):
btrfs: don't dereference a missing folio private on writeback error
btrfs: re-attach folio private when a released folio gets dirtied

fs/btrfs/extent_io.c | 24 +++++++++++++++++++-----
fs/btrfs/extent_io.h | 1 +
fs/btrfs/inode.c | 23 +++++++++++++++++++++++
fs/btrfs/subpage.c | 5 +++--
fs/btrfs/subpage.h | 3 ++-
5 files changed, 48 insertions(+), 8 deletions(-)


base-commit: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106
--
2.56.1