git: 95c7b9eaa9ec - main - vfs: fail VOP_DEALLOCATE passes that make no progress

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 21:11:25 UTC
The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=95c7b9eaa9ecc874333ff4cc97ad1c4d816223e4

commit 95c7b9eaa9ecc874333ff4cc97ad1c4d816223e4
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2026-11-17 21:10:38 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-11-17 21:11:05 +0000

    vfs: fail VOP_DEALLOCATE passes that make no progress
    
    VOP_DEALLOCATE(9) permits a filesystem to return a partial result, and
    vn_deallocate_impl() simply loops until the range is consumed.  If a
    filesystem returns success without shrinking the remaining length, we
    spin forever with the rangelock held and no way to interrupt the thread.
    
    Return EIO if a pass doesn't make progress so that a buggy filesystem
    doesn't wedge the caller.
    
    Document the progress requirement in VOP_DEALLOCATE(9) and the new EIO
    condition in fspacectl(2).
    
    I did wonder if this should be made interruptible for, e.g., slow I/O
    over NFS, but I've declined to touch it for now.
    
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D61496
---
 lib/libc/gen/exterr_cat_filenames.h |  1 +
 lib/libsys/fspacectl.2              |  4 +++-
 share/man/man9/VOP_DEALLOCATE.9     |  9 +++++++--
 sys/kern/vfs_vnops.c                | 18 ++++++++++++++++--
 sys/sys/exterr_cat.h                |  1 +
 5 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/lib/libc/gen/exterr_cat_filenames.h b/lib/libc/gen/exterr_cat_filenames.h
index 690d5d33fbf8..9e5eddc39d9d 100644
--- a/lib/libc/gen/exterr_cat_filenames.h
+++ b/lib/libc/gen/exterr_cat_filenames.h
@@ -20,6 +20,7 @@
 	[EXTERR_CAT_VFSBIO] = "kern/vfs_bio.c",
 	[EXTERR_CAT_INOTIFY] = "kern/vfs_inotify.c",
 	[EXTERR_CAT_VFSSYSCALL] = "kern/vfs_syscalls.c",
+	[EXTERR_CAT_VFSVNOPS] = "kern/vfs_vnops.c",
 	[EXTERR_CAT_BRIDGE] = "net/if_bridge.c",
 	[EXTERR_CAT_SWAP] = "vm/swap_pager.c",
 	[EXTERR_CAT_MMAP] = "vm/vm_mmap.c",
diff --git a/lib/libsys/fspacectl.2 b/lib/libsys/fspacectl.2
index 911c24101785..84775e5f8158 100644
--- a/lib/libsys/fspacectl.2
+++ b/lib/libsys/fspacectl.2
@@ -27,7 +27,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd August 25, 2021
+.Dd November 12, 2026
 .Dt FSPACECTL 2
 .Os
 .Sh NAME
@@ -169,6 +169,8 @@ or a non-NULL
 argument point outside the process' allocated address space.
 .It Bq Er EIO
 An I/O error occurred while reading from or writing to a file system.
+.It Bq Er EIO
+The file system failed to make progress on the requested operation range.
 .It Bq Er EINTEGRITY
 Corrupted data was detected while reading from the file system.
 .It Bq Er ENODEV
diff --git a/share/man/man9/VOP_DEALLOCATE.9 b/share/man/man9/VOP_DEALLOCATE.9
index 0db4d07ad2f0..8c6a2f01c710 100644
--- a/share/man/man9/VOP_DEALLOCATE.9
+++ b/share/man/man9/VOP_DEALLOCATE.9
@@ -27,7 +27,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd August 25, 2021
+.Dd November 12, 2026
 .Dt VOP_DEALLOCATE 9
 .Os
 .Sh NAME
@@ -73,7 +73,12 @@ and
 .Fa *len
 are updated to reflect the portion of the range that
 still needs to be zeroed/deallocated on return.
-Partial result is considered a successful operation.
+Partial result is considered a successful operation, provided that some
+progress was made:
+a successful return must decrease
+.Fa *len ,
+or the caller will fail the request with
+.Er EIO .
 For a non-partial successful completion,
 .Fa *len
 is updated to be the value 0, and
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index 88de7ac5b4c0..fa579de2b83a 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -43,11 +43,13 @@
 #include "opt_hwpmc_hooks.h"
 #include "opt_hwt_hooks.h"
 
+#define	EXTERR_CATEGORY	EXTERR_CAT_VFSVNOPS
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/buf.h>
 #include <sys/disk.h>
 #include <sys/dirent.h>
+#include <sys/exterrvar.h>
 #include <sys/fail.h>
 #include <sys/fcntl.h>
 #include <sys/file.h>
@@ -4008,7 +4010,7 @@ vn_deallocate_impl(struct vnode *vp, off_t *offset, off_t *length, int flags,
 {
 	struct mount *mp;
 	void *rl_cookie;
-	off_t off, len;
+	off_t len, off, olen;
 	int error;
 #ifdef AUDIT
 	bool audited_vnode1 = false;
@@ -4049,10 +4051,22 @@ vn_deallocate_impl(struct vnode *vp, off_t *offset, off_t *length, int flags,
 			error = mac_vnode_check_write(active_cred, file_cred,
 			    vp);
 #endif
-		if (error == 0)
+		if (error == 0) {
+			olen = len;
 			error = VOP_DEALLOCATE(vp, &off, &len, flags, ioflag,
 			    cred);
 
+			/*
+			 * A partial result is permitted, but each pass must
+			 * make some progress or we would spin here forever.
+			 */
+			if (error == 0 && len >= olen) {
+				error = EXTERROR(EIO,
+				    "no progress on vp %p (off %jd)",
+				    vp, (intmax_t)off);
+			}
+		}
+
 		if ((ioflag & IO_NODELOCKED) == 0) {
 			VOP_UNLOCK(vp);
 			if (mp != NULL) {
diff --git a/sys/sys/exterr_cat.h b/sys/sys/exterr_cat.h
index 235238a562ec..6b716b41448e 100644
--- a/sys/sys/exterr_cat.h
+++ b/sys/sys/exterr_cat.h
@@ -58,5 +58,6 @@
 #define	EXTERR_CAT_HWPMC_MOD	21
 #define	EXTERR_CAT_TTY		22
 #define	EXTERR_CAT_GEOMZONED	23
+#define	EXTERR_CAT_VFSVNOPS	24
 
 #endif