git: f52122f7687b - releng/15.1 - dbuf: restore BP_IS_HOLE() recheck after dnode_block_freed()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 17 Nov 2026 17:07:58 UTC
The branch releng/15.1 has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=f52122f7687b1ca90d7f7e20d506000dc5456322
commit f52122f7687b1ca90d7f7e20d506000dc5456322
Author: Cyrille C. <18537428+CrochetFeve0251@users.noreply.github.com>
AuthorDate: 2026-10-06 23:11:09 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-15 17:57:38 +0000
dbuf: restore BP_IS_HOLE() recheck after dnode_block_freed()
Commit 79cf54582 ("Fix reads for blocks freed after being cloned")
reworked the level-0 check in dbuf_read_hole() and dropped the
BP_IS_HOLE() recheck that followed dnode_block_freed(), together with
the comment explaining it. That recheck was not about overrides: it
closes a race with dnode_sync().
dnode_sync_free_ranges() drops dn_mtx, clears the bps through
dnode_sync_free_range_impl() -> free_blocks(), then retakes dn_mtx and
removes the range from dn_free_ranges. For blkptrs held in the dnode
(dn_nlevels == 1), free_blocks() writes the bp without the parent's
db_rwlock, so holding that lock in dbuf_read() does not serialize
against it. A reader that saw a non-hole bp, then waited on dn_mtx in
dnode_block_freed() until the range was removed, gets "not freed" while
the bp it is about to copy is already a hole (with HOLE_BIRTH, lsize
and birth preserved). dbuf_read_impl() then hands that hole to
arc_read(): no child I/O is issued, checksum verification fails with
EINVAL, and without ZIO_FLAG_CANFAIL the pool is suspended.
Restore the recheck for the non-override path. The override path
(block clone / Direct I/O) checks the overriding bp, which
free_blocks() does not touch, so it is left as is.
Reproduced on 2.3.9 with a test-only delay widening the window between
the first BP_IS_HOLE() and dnode_block_freed(): reads of punched
single-block files return EINVAL with the same ereport as in #19185.
With this change, the same test returns no error.
This change, its analysis and its description were prepared with the
help of an AI assistant (Claude), then reviewed and tested by the
submitter.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Cyrille C. <coquardcyr@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Fixes: a6f557c2cb58 ("Fix reads for blocks freed after being cloned")
Closes #19185
Closes #19234
Approved by: so
Security: FreeBSD-EN-26:32.zfs
Approved by: kevans (mentor)
(cherry picked from commit f1f96f5e7b01c791add67b27e8014e3986d10513)
(cherry picked from commit 78ca640f79c585ea737c03a0c427bfe53582fd30)
---
sys/contrib/openzfs/module/zfs/dbuf.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/sys/contrib/openzfs/module/zfs/dbuf.c b/sys/contrib/openzfs/module/zfs/dbuf.c
index 2417f7577f73..aeb697eb1645 100644
--- a/sys/contrib/openzfs/module/zfs/dbuf.c
+++ b/sys/contrib/openzfs/module/zfs/dbuf.c
@@ -1485,6 +1485,13 @@ dbuf_read_hole(dmu_buf_impl_t *db, dnode_t *dn, blkptr_t *bp)
* find frees from TXGs before the override, which should not make
* the block appear freed. Instead, check only free ranges from
* TXGs after the override.
+ *
+ * Otherwise, recheck BP_IS_HOLE() after dnode_block_freed():
+ * dnode_sync_free_ranges() clears the bp before it removes the
+ * free range, and free_blocks() does not take the parent's
+ * db_rwlock for blkptrs held in the dnode. If we wait for dn_mtx
+ * while that happens, block_freed says "no" but bp is now a hole,
+ * which must not be handed to arc_read().
*/
if (!is_hole && db->db_level == 0) {
dbuf_dirty_record_t *dr = list_head(&db->db_dirty_records);
@@ -1493,7 +1500,8 @@ dbuf_read_hole(dmu_buf_impl_t *db, dnode_t *dn, blkptr_t *bp)
is_hole = dnode_block_freed_after(dn,
db->db_blkid, dr->dr_txg);
} else {
- is_hole = dnode_block_freed(dn, db->db_blkid);
+ is_hole = dnode_block_freed(dn, db->db_blkid) ||
+ BP_IS_HOLE(bp);
}
}