From nobody Tue Nov 17 17:07:57 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jTWQ62XGHz71SHK for ; Tue, 17 Nov 2026 17:07:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jTWQ56wH2z4MYf for ; Tue, 17 Nov 2026 17:07:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935278; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+IIyM5czMCMa/BZ24u2YYx+La0WIecjCc634O4baRjY=; b=tqs82B1ALQTJzuC/vQjqzUGlOjjHwRJQrMPxrSDsPjwfY//6ctPirdQzVtGAoHHm7WVL0K YFw66m6bzf7dh43XFlV3PbVDhhuUJ/pt2e3J6TM2E+CLqfD4M54ifw7M3SfyrzlpTZk0iD Gu5/KRZzFNOUPgiQQ1e1yJY8caZ4sRfeySqz2Pin5+xVUxLSCXIlqrFsqeL42tfR/XY6vd thgFNdFrQsgBSQelYkxxbNVtxcQm2Cc1izyQ3akGU+uIfJQugz+GfVfQTBs1GD1arsVouA 9h5bcPO4sYJy2rz5AqrhenPPXpH2OSWB66ST2QU5IJJJ0J5G//gxH9KSmk29OQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794935278; b=lYIPYjIZ55bJd3QMgX3HYoi7CwL1wRX5nx86YbNaMgNnCZyRn4tUAJQoX4NWiYz6e8Hya9 zkvFjNdeJE4B+cXPJm+yZ8a7iUW77tueP9FiQc4iPPQwkkqU6QdK92eyrnnSE8KzjFR8yp E6cEwGPyaKcc292Ulap5BPaFdwsr39ZkADVJ259F44c2ap6L9feTFc2RCCccAfSr3FITZP 9eZD78FwkKS/Y69n7aA7UDb/lCwkY2mNcv9zhzpYyviFfHt392jSZTAcRbpinhBh2xqNsD XK8Za0B8WZAq8mNtwgnkdD918EXPPPuJs5hU5n3Bg6KybuLN5OyTfXU83KyUgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935278; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+IIyM5czMCMa/BZ24u2YYx+La0WIecjCc634O4baRjY=; b=kcwjTnc7Gwi+eJ2DBaTBoG8a/Qe0Mn+5+fr61j9q6j3HaELBzOIPn0fzcGu8sLSgqodaWW LH8EWGwlGQMHt51585gKR5TKrcoU5XlB+JaKBt/kryeUaCa0QwlwYazqDn4sgXP5hL07YM YkY0DTX1DQ/AQ9cQtvBDcB+xD5gX7x7YsqLWvczB7N/xBMLKg0kRKRpBDTPVr8aABBR4yc fqslmdzPTZBB001avwU4gMyppa6hYuP6ks/uutaKLTYH0rW6yfmFcU7ZD/VlqCK9x5Ovc3 rth//z2HjgZxOq7r+JatdCf0hodY5HwXXphtsNtgBLnQLNZAfyppAE2LQgLEaQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jTWQ5605jzrvj for ; Tue, 17 Nov 2026 17:07:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1ffb9 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:07:57 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Alexander Motin From: Mark Johnston Subject: git: cf35f6f88aea - releng/15.1 - Fix reads for blocks freed after being cloned List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/releng/15.1 X-Git-Reftype: branch X-Git-Commit: cf35f6f88aeada4db0f303f40d27f545122a42c9 Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:07:57 +0000 Message-Id: <6afc89ed.1ffb9.70c6efda@gitrepo.freebsd.org> The branch releng/15.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=cf35f6f88aeada4db0f303f40d27f545122a42c9 commit cf35f6f88aeada4db0f303f40d27f545122a42c9 Author: Alexander Motin AuthorDate: 2026-07-15 18:02:32 +0000 Commit: Mark Johnston CommitDate: 2026-11-15 17:57:38 +0000 Fix reads for blocks freed after being cloned PR #18421 fixed a case when reads for blocks cloned after being freed could return zeroes. But it created an opposite problem, when reads for blocks freed after being cloned could return non- zero content from the cloning. This patch fixes the problem by creating a more specialized form of dnode_block_freed(), taking into account the TXG when the cloning has happened and checking frees only in TXGs after. Reviewed-by: Brian Behlendorf Reviewed-by: Gary Guo Signed-off-by: Alexander Motin Closes #18421 Closes #18724 Approved by: so Security: FreeBSD-EN-26:32.zfs (cherry picked from commit a6f557c2cb58499dc3e09f5b91b1b3e4aa9b0c4f) --- sys/contrib/openzfs/include/sys/dnode.h | 2 ++ sys/contrib/openzfs/module/zfs/dbuf.c | 26 +++++++++++++++++--------- sys/contrib/openzfs/module/zfs/dnode.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/sys/contrib/openzfs/include/sys/dnode.h b/sys/contrib/openzfs/include/sys/dnode.h index b9ded73efe33..78dd0dc4f37b 100644 --- a/sys/contrib/openzfs/include/sys/dnode.h +++ b/sys/contrib/openzfs/include/sys/dnode.h @@ -449,6 +449,8 @@ void dnode_diduse_space(dnode_t *dn, int64_t space); void dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t have_read, boolean_t force); uint64_t dnode_block_freed(dnode_t *dn, uint64_t blkid); +uint64_t dnode_block_freed_after(dnode_t *dn, uint64_t blkid, + uint64_t override_txg); void dnode_init(void); void dnode_fini(void); int dnode_next_offset(dnode_t *dn, int flags, uint64_t *off, diff --git a/sys/contrib/openzfs/module/zfs/dbuf.c b/sys/contrib/openzfs/module/zfs/dbuf.c index ee9a2270a86c..2417f7577f73 100644 --- a/sys/contrib/openzfs/module/zfs/dbuf.c +++ b/sys/contrib/openzfs/module/zfs/dbuf.c @@ -1477,17 +1477,25 @@ dbuf_read_hole(dmu_buf_impl_t *db, dnode_t *dn, blkptr_t *bp) int is_hole = bp == NULL || BP_IS_HOLE(bp); /* - * For level 0 blocks only, if the above check fails: - * Recheck BP_IS_HOLE() after dnode_block_freed() in case dnode_sync() - * processes the delete record and clears the bp while we are waiting - * for the dn_mtx (resulting in a "no" from block_freed). + * For level 0 blocks only, if the above check didn't find a hole, + * consult dnode_block_freed() to check for pending frees. * - * If bp != db->db_blkptr, it means that it was overridden (by a block - * clone or direct I/O write). We cannot rely on dnode_block_freed as - * the range can be freed in an earlier TXG but overridden in later. + * If the block has been overridden by a block clone or direct I/O + * write, we can't use dnode_block_freed() directly because it would + * 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. */ - if (!is_hole && db->db_level == 0 && bp == db->db_blkptr) - is_hole = dnode_block_freed(dn, db->db_blkid) || BP_IS_HOLE(bp); + if (!is_hole && db->db_level == 0) { + dbuf_dirty_record_t *dr = list_head(&db->db_dirty_records); + if (dr != NULL && + (dr->dt.dl.dr_brtwrite || dr->dt.dl.dr_diowrite)) { + is_hole = dnode_block_freed_after(dn, + db->db_blkid, dr->dr_txg); + } else { + is_hole = dnode_block_freed(dn, db->db_blkid); + } + } if (is_hole) { db_data = dbuf_alloc_arcbuf(db); diff --git a/sys/contrib/openzfs/module/zfs/dnode.c b/sys/contrib/openzfs/module/zfs/dnode.c index be0e3de9bb23..9c1b615c263c 100644 --- a/sys/contrib/openzfs/module/zfs/dnode.c +++ b/sys/contrib/openzfs/module/zfs/dnode.c @@ -2468,6 +2468,37 @@ dnode_block_freed(dnode_t *dn, uint64_t blkid) return (i < TXG_SIZE); } +/* + * Check if a level-0 block was freed in a TXG after override_txg. + * + * When a block has been overridden (e.g., by block clone or direct I/O), + * we can't use dnode_block_freed() because it checks all active TXGs. + * A free from a TXG *before* the override should not make the block appear + * freed. + */ +uint64_t +dnode_block_freed_after(dnode_t *dn, uint64_t blkid, uint64_t override_txg) +{ + ASSERT(blkid != DMU_BONUS_BLKID); + ASSERT(blkid != DMU_SPILL_BLKID); + + if (dn->dn_free_txg) + return (TRUE); + + mutex_enter(&dn->dn_mtx); + uint64_t open = spa_open_txg(dmu_objset_spa(dn->dn_objset)); + for (uint64_t txg = override_txg + 1; txg <= open; txg++) { + int i = txg & TXG_MASK; + if (dn->dn_free_ranges[i] != NULL && + zfs_range_tree_contains(dn->dn_free_ranges[i], blkid, 1)) { + mutex_exit(&dn->dn_mtx); + return (TRUE); + } + } + mutex_exit(&dn->dn_mtx); + return (FALSE); +} + /* call from syncing context when we actually write/free space for this dnode */ void dnode_diduse_space(dnode_t *dn, int64_t delta)