AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/11/25 16:34 flow patch-triage
29m Args:
null

Results:
{
  "EnableConfigs": [
    "XFS_FS",
    "FS_VERITY",
    "XFS_ONLINE_SCRUB",
    "XFS_ONLINE_REPAIR"
  ],
  "FocusSymbols": [
    "xfs_fsverity_begin_enable",
    "xfs_fsverity_end_enable",
    "xfs_fsverity_get_descriptor",
    "xfs_fsverity_read_merkle",
    "xfs_fsverity_write_merkle",
    "xfs_fsverity_metadata_offset",
    "xfs_fsverity_is_file_data",
    "xfs_end_fsverity_io_read",
    "xchk_inode_setup_verity",
    "xchk_inode_verity_broken",
    "xrep_inode_verity",
    "xfs_dinode_verify"
  ],
  "KMSANReasoning": "The patch series adds fs-verity support to XFS, including filesystem format feature flags, fsverity operations (enable, descriptor read/write, Merkle tree read/write/readahead), ioctl routing (FS_IOC_ENABLE_VERITY, FS_IOC_MEASURE_VERITY, FS_IOC_READ_VERITY_METADATA), iomap integration, post-EOF Merkle tree management, and scrub/repair hooks.\n\nAnalysis of memory initialization and user-space exposure:\n1. All heap allocations (e.g., `struct xfs_fsverity_ioend` from the dedicated mempool) have all fields (`ioend`, `work`) immediately and fully initialized before use.\n2. User-facing data structures returned via ioctls (such as `xfs_fsop_geom` in `xfs_fs_geometry` and bulkstat structures) continue to be explicitly zeroed via `memset` before flags are populated.\n3. Reading of the fs-verity descriptor via `xfs_fsverity_get_descriptor()` reads exact byte counts (`desc_size`) from the page cache into the caller-provided buffer via `fsverity_pagecache_read()`, leaving no uninitialized buffer ranges.\n4. No uninitialized stack or heap variables are introduced, and no conditional logic branches on uninitialized memory.\n5. Potential bugs introduced by this patch primarily involve file offset/bounds calculations, extent manipulation, locking hierarchies (e.g. `IOLOCK`, `ILOCK`, `MMAPLOCK`), and refcounting, all of which are covered by standard KASAN and LOCKDEP configurations.\n\nBecause no uninitialized memory risks or kernel-to-user information leaks are introduced, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch adds fs-verity support to XFS, enabling file sealing and Merkle tree storage/verification beyond EOF. It adds new fsverity operations, read completion handling, unmapping changes in __xfs_bunmapi, and online scrub/repair checks for verity inodes. This code is fully reachable via ioctls (such as FS_IOC_ENABLE_VERITY) and normal file operations in virtualized environments.",
  "WorthFuzzing": true
}

1/1 2026/11/25 16:34 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 74ac4fac1d6d7863985e11a962c39f9386871361\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Wed Nov 25 16:34:45 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/fs/xfs/Makefile b/fs/xfs/Makefile\nindex 399a207f2d0e71..9edb2850f09413 100644\n--- a/fs/xfs/Makefile\n+++ b/fs/xfs/Makefile\n@@ -59,6 +59,7 @@ xfs-y\t\t\t\t+= $(addprefix libxfs/, \\\n \t\t\t\t   xfs_trans_resv.o \\\n \t\t\t\t   xfs_trans_space.o \\\n \t\t\t\t   xfs_types.o \\\n+\t\t\t\t   xfs_verity.o \\\n \t\t\t\t   )\n # xfs_rtbitmap is shared with libxfs\n xfs-$(CONFIG_XFS_RT)\t\t+= $(addprefix libxfs/, \\\n@@ -150,6 +151,7 @@ xfs-$(CONFIG_XFS_POSIX_ACL)\t+= xfs_acl.o\n xfs-$(CONFIG_SYSCTL)\t\t+= xfs_sysctl.o\n xfs-$(CONFIG_COMPAT)\t\t+= xfs_ioctl32.o\n xfs-$(CONFIG_EXPORTFS_BLOCK_OPS)\t+= xfs_pnfs.o\n+xfs-$(CONFIG_FS_VERITY)\t\t+= xfs_fsverity.o\n \n # notify failure\n ifeq ($(CONFIG_MEMORY_FAILURE),y)\ndiff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c\nindex 050522c58b168f..667b693aacb810 100644\n--- a/fs/xfs/libxfs/xfs_bmap.c\n+++ b/fs/xfs/libxfs/xfs_bmap.c\n@@ -4414,7 +4414,7 @@ xfs_bmapi_convert_one_delalloc(\n \t * the extent.  Just return the real extent at this offset.\n \t */\n \tif (!isnullstartblock(bma.got.br_startblock)) {\n-\t\txfs_bmbt_to_iomap(ip, iomap, \u0026bma.got, 0, flags,\n+\t\txfs_bmbt_to_iomap(ip, iomap, \u0026bma.got, offset, 0, flags,\n \t\t\t\txfs_iomap_inode_sequence(ip, flags));\n \t\tif (seq)\n \t\t\t*seq = READ_ONCE(ifp-\u003eif_seq);\n@@ -4462,7 +4462,7 @@ xfs_bmapi_convert_one_delalloc(\n \tXFS_STATS_INC(mp, xs_xstrat_quick);\n \n \tASSERT(!isnullstartblock(bma.got.br_startblock));\n-\txfs_bmbt_to_iomap(ip, iomap, \u0026bma.got, 0, flags,\n+\txfs_bmbt_to_iomap(ip, iomap, \u0026bma.got, offset, 0, flags,\n \t\t\t\txfs_iomap_inode_sequence(ip, flags));\n \tif (seq)\n \t\t*seq = READ_ONCE(ifp-\u003eif_seq);\n@@ -5220,6 +5220,22 @@ __xfs_bunmapi(\n \tASSERT(len \u003e 0);\n \tASSERT(nexts \u003e= 0);\n \n+\t/*\n+\t * XFS_BMAPI_UNWRITTEN is only used by fs-verity to drop unwritten\n+\t * blocks past EOF while keeping written ones (fsverity metadata).\n+\t *\n+\t * The XFS_BMAPI_UNWRITTEN could not be used with realtime inodes with\n+\t * realtime extent larger than 1 filesystem block. This is because the\n+\t * realtime inode with larger extents could have EOF in the middle of\n+\t * the extent. Removing these unwritten extent beyond EOF could lead to\n+\t * removal of data before EOF.\n+\t *\n+\t * fs-verity is not allowed to be enabled on realtime files whose\n+\t * extent size is larger than 1.\n+\t */\n+\tASSERT(!((flags \u0026 XFS_BMAPI_UNWRITTEN) \u0026\u0026\n+\t\t xfs_inode_has_bigrtalloc(ip)));\n+\n \terror = xfs_iread_extents(tp, ip, whichfork);\n \tif (error)\n \t\treturn error;\n@@ -5281,6 +5297,10 @@ __xfs_bunmapi(\n \t\tif (del.br_startoff + del.br_blockcount \u003e end + 1)\n \t\t\tdel.br_blockcount = end + 1 - del.br_startoff;\n \n+\t\tif ((flags \u0026 XFS_BMAPI_UNWRITTEN) \u0026\u0026\n+\t\t    del.br_state != XFS_EXT_UNWRITTEN)\n+\t\t\tgoto skip;\n+\n \t\tif (!isrt || (flags \u0026 XFS_BMAPI_REMAP))\n \t\t\tgoto delete;\n \n@@ -5415,7 +5435,7 @@ __xfs_bunmapi(\n \t\t\tif (error)\n \t\t\t\tgoto error0;\n \t\t}\n-\n+skip:\n \t\tend = del.br_startoff - 1;\n nodelete:\n \t\t/*\ndiff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h\nindex fb7481e8190c64..f1df6b4b695e0b 100644\n--- a/fs/xfs/libxfs/xfs_bmap.h\n+++ b/fs/xfs/libxfs/xfs_bmap.h\n@@ -97,6 +97,9 @@ struct xfs_bmalloca {\n  */\n #define XFS_BMAPI_CONVERT_ONLY\t(1u \u003c\u003c 12)\n \n+/* Process unwritten extents only. Used for unmapping */\n+#define XFS_BMAPI_UNWRITTEN\t(1u \u003c\u003c 13)\n+\n #define XFS_BMAPI_FLAGS \\\n \t{ XFS_BMAPI_ENTIRE,\t\"ENTIRE\" }, \\\n \t{ XFS_BMAPI_METADATA,\t\"METADATA\" }, \\\n@@ -110,7 +113,8 @@ struct xfs_bmalloca {\n \t{ XFS_BMAPI_NODISCARD,\t\"NODISCARD\" }, \\\n \t{ XFS_BMAPI_NORMAP,\t\"NORMAP\" },\\\n \t{ XFS_BMAPI_EXTSZALIGN,\t\"EXTSZALIGN\" }, \\\n-\t{ XFS_BMAPI_CONVERT_ONLY,\t\"CONVERT_ONLY\" }\n+\t{ XFS_BMAPI_CONVERT_ONLY,\t\"CONVERT_ONLY\" }, \\\n+\t{ XFS_BMAPI_UNWRITTEN,\t\"UNWRITTEN\" }\n \n \n static inline int xfs_bmapi_aflag(int w)\ndiff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h\nindex 469e879149ac21..16d6e8931df069 100644\n--- a/fs/xfs/libxfs/xfs_format.h\n+++ b/fs/xfs/libxfs/xfs_format.h\n@@ -374,11 +374,13 @@ xfs_sb_has_compat_feature(\n #define XFS_SB_FEAT_RO_COMPAT_RMAPBT   (1 \u003c\u003c 1)\t\t/* reverse map btree */\n #define XFS_SB_FEAT_RO_COMPAT_REFLINK  (1 \u003c\u003c 2)\t\t/* reflinked files */\n #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 \u003c\u003c 3)\t\t/* inobt block counts */\n+#define XFS_SB_FEAT_RO_COMPAT_VERITY   (1 \u003c\u003c 4)\t\t/* fs-verity */\n #define XFS_SB_FEAT_RO_COMPAT_ALL \\\n \t\t(XFS_SB_FEAT_RO_COMPAT_FINOBT | \\\n \t\t XFS_SB_FEAT_RO_COMPAT_RMAPBT | \\\n-\t\t XFS_SB_FEAT_RO_COMPAT_REFLINK| \\\n-\t\t XFS_SB_FEAT_RO_COMPAT_INOBTCNT)\n+\t\t XFS_SB_FEAT_RO_COMPAT_REFLINK | \\\n+\t\t XFS_SB_FEAT_RO_COMPAT_INOBTCNT | \\\n+\t\t XFS_SB_FEAT_RO_COMPAT_VERITY)\n #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN\t~XFS_SB_FEAT_RO_COMPAT_ALL\n static inline bool\n xfs_sb_has_ro_compat_feature(\n@@ -1234,16 +1236,21 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)\n  */\n #define XFS_DIFLAG2_METADATA_BIT\t5\n \n+/* inodes sealed with fs-verity */\n+#define XFS_DIFLAG2_VERITY_BIT\t\t6\n+\n #define XFS_DIFLAG2_DAX\t\t(1ULL \u003c\u003c XFS_DIFLAG2_DAX_BIT)\n #define XFS_DIFLAG2_REFLINK\t(1ULL \u003c\u003c XFS_DIFLAG2_REFLINK_BIT)\n #define XFS_DIFLAG2_COWEXTSIZE\t(1ULL \u003c\u003c XFS_DIFLAG2_COWEXTSIZE_BIT)\n #define XFS_DIFLAG2_BIGTIME\t(1ULL \u003c\u003c XFS_DIFLAG2_BIGTIME_BIT)\n #define XFS_DIFLAG2_NREXT64\t(1ULL \u003c\u003c XFS_DIFLAG2_NREXT64_BIT)\n #define XFS_DIFLAG2_METADATA\t(1ULL \u003c\u003c XFS_DIFLAG2_METADATA_BIT)\n+#define XFS_DIFLAG2_VERITY\t(1ULL \u003c\u003c XFS_DIFLAG2_VERITY_BIT)\n \n #define XFS_DIFLAG2_ANY \\\n \t(XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \\\n-\t XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA)\n+\t XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA | \\\n+\t XFS_DIFLAG2_VERITY)\n \n static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)\n {\n@@ -2031,4 +2038,22 @@ struct xfs_acl {\n #define SGI_ACL_FILE_SIZE\t(sizeof(SGI_ACL_FILE)-1)\n #define SGI_ACL_DEFAULT_SIZE\t(sizeof(SGI_ACL_DEFAULT)-1)\n \n+/*\n+ * fs-verity stores the Merkle tree in the data fork past EOF, so the file data\n+ * blocks and the tree blocks share the inode's xfs_fileoff_t address space.\n+ * Cap a verity file at half of the addressable file-offset range (in filesystem\n+ * blocks) so the Merkle tree always fits in the other half.\n+ */\n+#define XFS_FSVERITY_LARGEST_FILE_FSB(mp) \\\n+\t(XFS_B_TO_FSBT((mp), MAX_LFS_FILESIZE) \u003e\u003e 1)\n+\n+/*\n+ * Alignment of the fsverity metadata placement. This is largest supported PAGE\n+ * SIZE for fsverity. This is used to space out data and metadata in page cache.\n+ * The spacing is necessary for non-exposure of metadata to userspace and\n+ * correct merkle tree synthesis in the iomap.\n+ */\n+#define XFS_FSVERITY_START_ALIGN\t(65536)\n+\n+\n #endif /* __XFS_FORMAT_H__ */\ndiff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h\nindex 185f09f327c00c..84d62b7506a9ad 100644\n--- a/fs/xfs/libxfs/xfs_fs.h\n+++ b/fs/xfs/libxfs/xfs_fs.h\n@@ -250,6 +250,7 @@ typedef struct xfs_fsop_resblks {\n #define XFS_FSOP_GEOM_FLAGS_PARENT\t(1 \u003c\u003c 25) /* linux parent pointers */\n #define XFS_FSOP_GEOM_FLAGS_METADIR\t(1 \u003c\u003c 26) /* metadata directories */\n #define XFS_FSOP_GEOM_FLAGS_ZONED\t(1 \u003c\u003c 27) /* zoned rt device */\n+#define XFS_FSOP_GEOM_FLAGS_VERITY\t(1 \u003c\u003c 28) /* fs-verity */\n \n /*\n  * Minimum and maximum sizes need for growth checks.\n@@ -421,6 +422,7 @@ struct xfs_bulkstat {\n #define XFS_BS_SICK_SYMLINK\t(1 \u003c\u003c 6)  /* symbolic link remote target */\n #define XFS_BS_SICK_PARENT\t(1 \u003c\u003c 7)  /* parent pointers */\n #define XFS_BS_SICK_DIRTREE\t(1 \u003c\u003c 8)  /* directory tree structure */\n+#define XFS_BS_SICK_FSVERITY\t(1 \u003c\u003c 9)  /* fsverity metadata */\n \n /*\n  * Project quota id helpers (previously projid was 16bit only\ndiff --git a/fs/xfs/libxfs/xfs_health.h b/fs/xfs/libxfs/xfs_health.h\nindex 1d45cf5789e864..932b447190da76 100644\n--- a/fs/xfs/libxfs/xfs_health.h\n+++ b/fs/xfs/libxfs/xfs_health.h\n@@ -104,6 +104,7 @@ struct xfs_rtgroup;\n /* Don't propagate sick status to ag health summary during inactivation */\n #define XFS_SICK_INO_FORGET\t(1 \u003c\u003c 12)\n #define XFS_SICK_INO_DIRTREE\t(1 \u003c\u003c 13)  /* directory tree structure */\n+#define XFS_SICK_INO_FSVERITY\t(1 \u003c\u003c 14)  /* fsverity metadata */\n \n /* Primary evidence of health problems in a given group. */\n #define XFS_SICK_FS_PRIMARY\t(XFS_SICK_FS_COUNTERS | \\\n@@ -140,7 +141,8 @@ struct xfs_rtgroup;\n \t\t\t\t XFS_SICK_INO_XATTR | \\\n \t\t\t\t XFS_SICK_INO_SYMLINK | \\\n \t\t\t\t XFS_SICK_INO_PARENT | \\\n-\t\t\t\t XFS_SICK_INO_DIRTREE)\n+\t\t\t\t XFS_SICK_INO_DIRTREE | \\\n+\t\t\t\t XFS_SICK_INO_FSVERITY)\n \n #define XFS_SICK_INO_ZAPPED\t(XFS_SICK_INO_BMBTD_ZAPPED | \\\n \t\t\t\t XFS_SICK_INO_BMBTA_ZAPPED | \\\ndiff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c\nindex 8c9d296ebfe97f..fdcfc1f3f472b5 100644\n--- a/fs/xfs/libxfs/xfs_inode_buf.c\n+++ b/fs/xfs/libxfs/xfs_inode_buf.c\n@@ -758,6 +758,25 @@ xfs_dinode_verify(\n \t    !xfs_has_rtreflink(mp))\n \t\treturn __this_address;\n \n+\t/* only regular files can have fsverity */\n+\tif (flags2 \u0026 XFS_DIFLAG2_VERITY) {\n+\t\tif (!xfs_has_verity(mp))\n+\t\t\treturn __this_address;\n+\t\tif (!S_ISREG(mode))\n+\t\t\treturn __this_address;\n+\t\t/*\n+\t\t * fs-verity stores the Merkle tree past EOF, so it cannot\n+\t\t * coexist with a realtime allocation unit larger than a single\n+\t\t * filesystem block. This is because we remove any unwritten\n+\t\t * extents beyond EOF for fs-verity inodes. The realtime inode\n+\t\t * with larger extents could have EOF in the middle of the\n+\t\t * extent. Enabling fsverity on such inode could lead to removal\n+\t\t * of data before EOF.\n+\t\t */\n+\t\tif ((flags \u0026 XFS_DIFLAG_REALTIME) \u0026\u0026 mp-\u003em_sb.sb_rextsize \u003e 1)\n+\t\t\treturn __this_address;\n+\t}\n+\n \tif (xfs_has_zoned(mp) \u0026\u0026\n \t    dip-\u003edi_metatype == cpu_to_be16(XFS_METAFILE_RTRMAP)) {\n \t\tif (be32_to_cpu(dip-\u003edi_used_blocks) \u003e mp-\u003em_sb.sb_rgextents)\ndiff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c\nindex f486b23a9b5230..a717b19558afab 100644\n--- a/fs/xfs/libxfs/xfs_inode_util.c\n+++ b/fs/xfs/libxfs/xfs_inode_util.c\n@@ -73,7 +73,8 @@ xfs_flags2diflags2(\n \tuint64_t\t\tdi_flags2 =\n \t\t(ip-\u003ei_diflags2 \u0026 (XFS_DIFLAG2_REFLINK |\n \t\t\t\t   XFS_DIFLAG2_BIGTIME |\n-\t\t\t\t   XFS_DIFLAG2_NREXT64));\n+\t\t\t\t   XFS_DIFLAG2_NREXT64 |\n+\t\t\t\t   XFS_DIFLAG2_VERITY));\n \n \tif (xflags \u0026 FS_XFLAG_DAX)\n \t\tdi_flags2 |= XFS_DIFLAG2_DAX;\n@@ -125,6 +126,8 @@ xfs_ip2xflags(\n \t\t\tflags |= FS_XFLAG_DAX;\n \t\tif (ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_COWEXTSIZE)\n \t\t\tflags |= FS_XFLAG_COWEXTSIZE;\n+\t\tif (ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_VERITY)\n+\t\t\tflags |= FS_XFLAG_VERITY;\n \t}\n \n \tif (xfs_inode_has_attr_fork(ip))\ndiff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c\nindex ce44123c98cef6..3323b8dcc7939b 100644\n--- a/fs/xfs/libxfs/xfs_sb.c\n+++ b/fs/xfs/libxfs/xfs_sb.c\n@@ -164,6 +164,8 @@ xfs_sb_version_to_features(\n \t\tfeatures |= XFS_FEAT_REFLINK;\n \tif (sbp-\u003esb_features_ro_compat \u0026 XFS_SB_FEAT_RO_COMPAT_INOBTCNT)\n \t\tfeatures |= XFS_FEAT_INOBTCNT;\n+\tif (sbp-\u003esb_features_ro_compat \u0026 XFS_SB_FEAT_RO_COMPAT_VERITY)\n+\t\tfeatures |= XFS_FEAT_VERITY;\n \tif (sbp-\u003esb_features_incompat \u0026 XFS_SB_FEAT_INCOMPAT_FTYPE)\n \t\tfeatures |= XFS_FEAT_FTYPE;\n \tif (sbp-\u003esb_features_incompat \u0026 XFS_SB_FEAT_INCOMPAT_SPINODES)\n@@ -1544,6 +1546,8 @@ xfs_fs_geometry(\n \t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_METADIR;\n \tif (xfs_has_zoned(mp))\n \t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_ZONED;\n+\tif (xfs_has_verity(mp))\n+\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_VERITY;\n \tgeo-\u003ertsectsize = sbp-\u003esb_blocksize;\n \tgeo-\u003edirblocksize = xfs_dir2_dirblock_bytes(sbp);\n \ndiff --git a/fs/xfs/libxfs/xfs_verity.c b/fs/xfs/libxfs/xfs_verity.c\nnew file mode 100644\nindex 00000000000000..c1731b89a5a12c\n--- /dev/null\n+++ b/fs/xfs/libxfs/xfs_verity.c\n@@ -0,0 +1,20 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Copyright (C) 2026 Red Hat, Inc.\n+ */\n+#include \"xfs_platform.h\"\n+#include \"xfs_fs.h\"\n+#include \"xfs_shared.h\"\n+#include \"xfs_format.h\"\n+#include \"xfs_log_format.h\"\n+#include \"xfs_trans_resv.h\"\n+#include \"xfs_mount.h\"\n+#include \"xfs_inode.h\"\n+#include \"xfs_verity.h\"\n+\n+loff_t\n+xfs_fsverity_metadata_offset(\n+\tconst struct xfs_inode\t*ip)\n+{\n+\treturn round_up(i_size_read(VFS_IC(ip)), XFS_FSVERITY_START_ALIGN);\n+}\ndiff --git a/fs/xfs/libxfs/xfs_verity.h b/fs/xfs/libxfs/xfs_verity.h\nnew file mode 100644\nindex 00000000000000..da90f798faa8d6\n--- /dev/null\n+++ b/fs/xfs/libxfs/xfs_verity.h\n@@ -0,0 +1,13 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Copyright (C) 2026 Red Hat, Inc.\n+ */\n+#ifndef __XFS_VERITY_H__\n+#define __XFS_VERITY_H__\n+\n+#include \"xfs_platform.h\"\n+#include \u003clinux/fsverity.h\u003e\n+\n+loff_t xfs_fsverity_metadata_offset(const struct xfs_inode *ip);\n+\n+#endif\t/* __XFS_VERITY_H__ */\ndiff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c\nindex cbfe5e6f779dfc..fb0ae227df54a8 100644\n--- a/fs/xfs/scrub/common.c\n+++ b/fs/xfs/scrub/common.c\n@@ -45,6 +45,8 @@\n #include \"scrub/health.h\"\n #include \"scrub/tempfile.h\"\n \n+#include \u003clinux/fsverity.h\u003e\n+\n /* Common code for the metadata scrubbers. */\n \n /*\n@@ -1765,3 +1767,54 @@ xchk_inode_count_blocks(\n \treturn xfs_bmap_count_blocks(sc-\u003etp, sc-\u003eip, whichfork, nextents,\n \t\t\tcount);\n }\n+\n+/*\n+ * If this inode has S_VERITY set on it, read the verity info. If the reading\n+ * fails with anything other than ENOMEM, the file is corrupt, which we can\n+ * detect later with fsverity_active.\n+ *\n+ * Callers must hold the IOLOCK and must not hold the ILOCK of sc-\u003eip because\n+ * activation reads inode data.\n+ */\n+int\n+xchk_inode_setup_verity(\n+\tstruct xfs_scrub\t*sc)\n+{\n+\tint\t\t\terror;\n+\n+\tif (!fsverity_active(VFS_I(sc-\u003eip)))\n+\t\treturn 0;\n+\n+\terror = fsverity_ensure_verity_info(VFS_I(sc-\u003eip));\n+\tswitch (error) {\n+\tcase 0:\n+\t\t/* fsverity is active */\n+\t\tbreak;\n+\tcase -ENODATA:\n+\tcase -EMSGSIZE:\n+\tcase -EFSCORRUPTED:\n+\tcase -ERANGE:\n+\tcase -EBADMSG:\n+\t\t/*\n+\t\t * The nonzero errno codes above are the error codes that can\n+\t\t * be returned from fsverity on metadata validation errors.\n+\t\t */\n+\t\treturn 0;\n+\tdefault:\n+\t\t/* runtime errors */\n+\t\treturn error;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Is this a verity file that failed to activate?  Callers must have tried to\n+ * activate fsverity via xchk_inode_setup_verity.\n+ */\n+bool\n+xchk_inode_verity_broken(\n+\tstruct xfs_inode\t*ip)\n+{\n+\treturn fsverity_active(VFS_I(ip)) \u0026\u0026 !fsverity_get_info(VFS_I(ip));\n+}\ndiff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h\nindex 181028f0c65526..b59d4792a80507 100644\n--- a/fs/xfs/scrub/common.h\n+++ b/fs/xfs/scrub/common.h\n@@ -261,6 +261,8 @@ int xchk_inode_is_allocated(struct xfs_scrub *sc, xfs_agino_t agino,\n \t\tbool *inuse);\n int xchk_inode_count_blocks(struct xfs_scrub *sc, int whichfork,\n \t\txfs_extnum_t *nextents, xfs_filblks_t *count);\n+int xchk_inode_setup_verity(struct xfs_scrub *sc);\n+bool xchk_inode_verity_broken(struct xfs_inode *ip);\n \n bool xchk_inode_is_dirtree_root(const struct xfs_inode *ip);\n bool xchk_inode_is_sb_rooted(const struct xfs_inode *ip);\ndiff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c\nindex bb8d2bc008e019..931c677d7ac8d4 100644\n--- a/fs/xfs/scrub/inode.c\n+++ b/fs/xfs/scrub/inode.c\n@@ -33,9 +33,28 @@ xchk_prepare_iscrub(\n \tstruct xfs_scrub\t*sc)\n {\n \tint\t\t\terror;\n+\tstruct xfs_inode\t*ip = sc-\u003eip;\n \n \txchk_ilock(sc, XFS_IOLOCK_EXCL);\n \n+\terror = xchk_inode_setup_verity(sc);\n+\tif (error)\n+\t\treturn error;\n+\n+\t/*\n+\t * If we're going to repair a file whose fsverity descriptor cannot be\n+\t * activated, drop the stale Merkle tree folios. Once the\n+\t * post-EOF Merkle extents are freed during repair, those uptodate\n+\t * folios would otherwise sit over a hole and could be exposed as file\n+\t * data by a later extending write or truncate.\n+\t *\n+\t * The lock would be unlocked by global scrub machinery.\n+\t */\n+\tif (xchk_could_repair(sc) \u0026\u0026 xchk_inode_verity_broken(ip)) {\n+\t\txchk_ilock(sc, XFS_MMAPLOCK_EXCL);\n+\t\ttruncate_inode_pages(VFS_I(ip)-\u003ei_mapping, XFS_ISIZE(ip));\n+\t}\n+\n \terror = xchk_trans_alloc(sc, 0);\n \tif (error)\n \t\treturn error;\n@@ -833,6 +852,9 @@ xchk_inode(\n \tif (S_ISREG(VFS_I(sc-\u003eip)-\u003ei_mode))\n \t\txchk_inode_check_reflink_iflag(sc, I_INO(sc-\u003eip));\n \n+\tif (xchk_inode_verity_broken(sc-\u003eip))\n+\t\txchk_ino_set_corrupt(sc, sc-\u003esm-\u003esm_ino);\n+\n \txchk_inode_check_unlinked(sc);\n \n \txchk_inode_xref(sc, I_INO(sc-\u003eip), \u0026di);\ndiff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c\nindex a9ccf763c05969..ddf3c3dce2f939 100644\n--- a/fs/xfs/scrub/inode_repair.c\n+++ b/fs/xfs/scrub/inode_repair.c\n@@ -577,6 +577,8 @@ xrep_dinode_flags(\n \t\tdip-\u003edi_nrext64_pad = 0;\n \telse if (dip-\u003edi_version \u003e= 3)\n \t\tdip-\u003edi_v3_pad = 0;\n+\tif (!xfs_has_verity(mp) || !S_ISREG(mode))\n+\t\tflags2 \u0026= ~XFS_DIFLAG2_VERITY;\n \n \tif (flags2 \u0026 XFS_DIFLAG2_METADATA) {\n \t\txfs_failaddr_t\tfa;\n@@ -1659,6 +1661,10 @@ xrep_dinode_core(\n \tif (iget_error)\n \t\treturn iget_error;\n \n+\terror = xchk_inode_setup_verity(sc);\n+\tif (error)\n+\t\treturn error;\n+\n \terror = xchk_trans_alloc(sc, 0);\n \tif (error)\n \t\treturn error;\n@@ -2198,6 +2204,40 @@ xrep_inode_reset_dquots(\n # define xrep_inode_reset_dquots(sc)\t\t(0)\n #endif\n \n+/*\n+ * If this file is a fsverity file, xchk_prepare_iscrub or xrep_dinode_core\n+ * should have activated it.  If it's still not active, then there's something\n+ * wrong with the verity descriptor, so turn verity off and free the orphaned\n+ * Merkle tree that XFS keeps in extents beyond EOF.\n+ */\n+STATIC int\n+xrep_inode_verity(\n+\tstruct xfs_scrub\t*sc)\n+{\n+\tstruct inode\t\t*inode = VFS_I(sc-\u003eip);\n+\tstruct xfs_mount\t*mp = sc-\u003emp;\n+\tint\t\t\terror;\n+\n+\tif (!xchk_inode_verity_broken(sc-\u003eip))\n+\t\treturn 0;\n+\n+\t/*\n+\t * The fsverity descriptor cannot be activated, so disable verity and\n+\t * free the Merkle tree, which XFS stores in beyond EOF. The stale\n+\t * Merkle tree page cache was already dropped during scrub setup.\n+\t */\n+\terror = xfs_bunmapi_range(\u0026sc-\u003etp, sc-\u003eip, 0,\n+\t\t\tXFS_B_TO_FSB(mp, XFS_ISIZE(sc-\u003eip)), XFS_MAX_FILEOFF);\n+\tif (error)\n+\t\treturn error;\n+\n+\tsc-\u003eip-\u003ei_diflags2 \u0026= ~XFS_DIFLAG2_VERITY;\n+\tinode_set_flags(inode, 0, S_VERITY);\n+\n+\txfs_trans_log_inode(sc-\u003etp, sc-\u003eip, XFS_ILOG_CORE);\n+\treturn 0;\n+}\n+\n /* Repair an inode's fields. */\n int\n xrep_inode(\n@@ -2247,6 +2287,15 @@ xrep_inode(\n \t\t\treturn error;\n \t}\n \n+\t/*\n+\t * Disable fsverity if it cannot be activated.  Activation failure\n+\t * prohibits the file from being opened, so there cannot be another\n+\t * program with an open fd to what it thinks is a verity file.\n+\t */\n+\terror = xrep_inode_verity(sc);\n+\tif (error)\n+\t\treturn error;\n+\n \t/* Reconnect incore unlinked list */\n \terror = xrep_inode_unlinked(sc);\n \tif (error)\ndiff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c\nindex 1db6f3640c53bd..971be3c0973161 100644\n--- a/fs/xfs/xfs_aops.c\n+++ b/fs/xfs/xfs_aops.c\n@@ -23,6 +23,8 @@\n #include \"xfs_ioend.h\"\n #include \"xfs_zone_alloc.h\"\n #include \"xfs_rtgroup.h\"\n+#include \"xfs_verity.h\"\n+#include \"xfs_fsverity.h\"\n \n struct xfs_writepage_ctx {\n \tstruct iomap_writepage_ctx ctx;\n@@ -265,7 +267,8 @@ xfs_map_blocks(\n \t    isnullstartblock(imap.br_startblock))\n \t\tgoto allocate_blocks;\n \n-\txfs_bmbt_to_iomap(ip, \u0026wpc-\u003eiomap, \u0026imap, 0, 0, XFS_WPC(wpc)-\u003edata_seq);\n+\txfs_bmbt_to_iomap(ip, \u0026wpc-\u003eiomap, \u0026imap, offset, 0, 0,\n+\t\t\t  XFS_WPC(wpc)-\u003edata_seq);\n \ttrace_xfs_map_blocks_found(ip, offset, count, whichfork, \u0026imap);\n \treturn 0;\n allocate_blocks:\n@@ -441,7 +444,7 @@ xfs_zoned_map_blocks(\n \t\timap.br_startblock = HOLESTARTBLOCK;\n \t\timap.br_state = XFS_EXT_NORM;\n \t\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n-\t\txfs_bmbt_to_iomap(ip, \u0026wpc-\u003eiomap, \u0026imap, 0, 0, 0);\n+\t\txfs_bmbt_to_iomap(ip, \u0026wpc-\u003eiomap, \u0026imap, offset, 0, 0, 0);\n \t\treturn 0;\n \t}\n \tend_fsb = min(end_fsb, imap.br_startoff + imap.br_blockcount);\n@@ -585,7 +588,7 @@ xfs_bio_submit_read(\n {\n \txfs_ioend_submit_read(iter-\u003einode, ctx-\u003eread_ctx,\n \t\t\tctx-\u003eread_ctx_file_offset,\n-\t\t\tiomap_ioend_flags(\u0026iter-\u003eiomap));\n+\t\t\tiomap_ioend_flags(\u0026iter-\u003eiomap), ctx-\u003evi);\n \tctx-\u003eread_ctx = NULL;\n }\n \n@@ -597,11 +600,13 @@ static const struct iomap_read_ops xfs_iomap_read_ops = {\n \n static inline const struct iomap_read_ops *\n xfs_get_iomap_read_ops(\n-\tconst struct address_space\t*mapping)\n+\tconst struct address_space\t*mapping,\n+\tloff_t\t\t\t\tpos)\n {\n \tstruct xfs_inode\t\t*ip = XFS_I(mapping-\u003ehost);\n \n-\tif (bdev_has_integrity_csum(xfs_inode_buftarg(ip)-\u003ebt_bdev))\n+\tif (bdev_has_integrity_csum(xfs_inode_buftarg(ip)-\u003ebt_bdev) ||\n+\t    xfs_fsverity_is_file_data(ip, pos))\n \t\treturn \u0026xfs_iomap_read_ops;\n \treturn \u0026iomap_bio_read_ops;\n }\n@@ -613,7 +618,7 @@ xfs_vm_read_folio(\n {\n \tstruct iomap_read_folio_ctx\tctx = { .cur_folio = folio };\n \n-\tctx.ops = xfs_get_iomap_read_ops(folio-\u003emapping);\n+\tctx.ops = xfs_get_iomap_read_ops(folio-\u003emapping, folio_pos(folio));\n \tiomap_read_folio(xfs_read_iomap_next, \u0026ctx, NULL);\n \treturn 0;\n }\n@@ -624,7 +629,7 @@ xfs_vm_readahead(\n {\n \tstruct iomap_read_folio_ctx\tctx = { .rac = rac };\n \n-\tctx.ops = xfs_get_iomap_read_ops(rac-\u003emapping),\n+\tctx.ops = xfs_get_iomap_read_ops(rac-\u003emapping, readahead_pos(rac));\n \tiomap_readahead(xfs_read_iomap_next, \u0026ctx, NULL);\n }\n \ndiff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c\nindex 865aec3ae5ab32..d6130cfc8246d9 100644\n--- a/fs/xfs/xfs_bmap_util.c\n+++ b/fs/xfs/xfs_bmap_util.c\n@@ -31,6 +31,7 @@\n #include \"xfs_rtbitmap.h\"\n #include \"xfs_rtgroup.h\"\n #include \"xfs_zone_alloc.h\"\n+#include \u003clinux/fsverity.h\u003e\n \n /* Kernel only BMAP related definitions and functions */\n \n@@ -553,6 +554,17 @@ xfs_can_free_eofblocks(\n \tif (last_fsb \u003c= end_fsb)\n \t\treturn false;\n \n+\t/*\n+\t * Don't clean fsverity inodes as they already have been cleaned up and\n+\t * are read-only. Skip inodes which have merkle tree being built, the\n+\t * merkle tree is written beyond EOF. Skip inodes which have\n+\t * XFS_DIFLAG2_VERITY in case this kernel has fsverity disabled.\n+\t */\n+\tif (fsverity_active(VFS_IC(ip)) ||\n+\t    fsverity_is_building(VFS_I(ip)) ||\n+\t    ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_VERITY)\n+\t\treturn false;\n+\n \t/*\n \t * Check if there is an post-EOF extent to free.  If there are any\n \t * delalloc blocks attached to the inode (data fork delalloc\n@@ -579,6 +591,8 @@ xfs_free_eofblocks(\n \tstruct xfs_trans\t*tp;\n \tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n \tint\t\t\terror;\n+\tint\t\t\tbmapi_flags = XFS_BMAPI_NODISCARD;\n+\tbool\t\t\tverity = fsverity_is_building(VFS_I(ip));\n \n \t/* Attach the dquots to the inode up front. */\n \terror = xfs_qm_dqattach(ip);\n@@ -593,15 +607,20 @@ xfs_free_eofblocks(\n \t *\n \t * Note that this means we also leave speculative preallocations in\n \t * place for preallocated files.\n+\t *\n+\t * Clean up delalloc reservations for fsverity too as those won't be\n+\t * used\n \t */\n-\tif (ip-\u003ei_diflags \u0026 (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) {\n+\tif (ip-\u003ei_diflags \u0026 (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND) ||\n+\t\t\tverity) {\n \t\tif (ip-\u003ei_delayed_blks) {\n \t\t\txfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK,\n \t\t\t\tround_up(XFS_ISIZE(ip), mp-\u003em_sb.sb_blocksize),\n \t\t\t\tLLONG_MAX, NULL);\n \t\t}\n \t\txfs_inode_clear_eofblocks_tag(ip);\n-\t\treturn 0;\n+\t\tif (!verity)\n+\t\t\treturn 0;\n \t}\n \n \terror = xfs_trans_alloc(mp, \u0026M_RES(mp)-\u003etr_itruncate, 0, 0, 0, \u0026tp);\n@@ -613,6 +632,13 @@ xfs_free_eofblocks(\n \txfs_ilock(ip, XFS_ILOCK_EXCL);\n \txfs_trans_ijoin(tp, ip, 0);\n \n+\t/*\n+\t * While fs-verity writes metadata after EOF, it can leave unwritten\n+\t * preallocations.  Clear all that out.\n+\t */\n+\tif (verity)\n+\t\tbmapi_flags |= XFS_BMAPI_UNWRITTEN;\n+\n \t/*\n \t * Do not update the on-disk file size.  If we update the on-disk file\n \t * size and then the system crashes before the contents of the file are\n@@ -620,7 +646,7 @@ xfs_free_eofblocks(\n \t * bug).\n \t */\n \terror = xfs_itruncate_extents_flags(\u0026tp, ip, XFS_DATA_FORK,\n-\t\t\t\tXFS_ISIZE(ip), XFS_BMAPI_NODISCARD);\n+\t\t\t\tXFS_ISIZE(ip), bmapi_flags);\n \tif (error)\n \t\tgoto err_cancel;\n \ndiff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c\nindex d61ea8e2c8e40c..94835d6153420b 100644\n--- a/fs/xfs/xfs_file.c\n+++ b/fs/xfs/xfs_file.c\n@@ -38,6 +38,7 @@\n #include \u003clinux/mount.h\u003e\n #include \u003clinux/filelock.h\u003e\n #include \u003clinux/bio-integrity.h\u003e\n+#include \u003clinux/fsverity.h\u003e\n \n static const struct vm_operations_struct xfs_file_vm_ops;\n \n@@ -181,7 +182,8 @@ xfs_dio_read_bounce_submit_io(\n \tloff_t\t\t\tfile_offset)\n {\n \txfs_ioend_submit_read(iter-\u003einode, bio, file_offset,\n-\t\t\tiomap_ioend_flags(\u0026iter-\u003eiomap) | IOMAP_IOEND_DIRECT);\n+\t\t\tiomap_ioend_flags(\u0026iter-\u003eiomap) | IOMAP_IOEND_DIRECT,\n+\t\t\tNULL);\n }\n \n static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {\n@@ -189,6 +191,25 @@ static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {\n \t.bio_set\t= \u0026iomap_ioend_bioset,\n };\n \n+STATIC ssize_t\n+xfs_file_buffered_read(\n+\tstruct kiocb\t\t*iocb,\n+\tstruct iov_iter\t\t*to)\n+{\n+\tstruct xfs_inode\t*ip = XFS_I(file_inode(iocb-\u003eki_filp));\n+\tssize_t\t\t\tret;\n+\n+\ttrace_xfs_file_buffered_read(iocb, to);\n+\n+\tret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);\n+\tif (ret)\n+\t\treturn ret;\n+\tret = generic_file_read_iter(iocb, to);\n+\txfs_iunlock(ip, XFS_IOLOCK_SHARED);\n+\n+\treturn ret;\n+}\n+\n STATIC ssize_t\n xfs_file_dio_read(\n \tstruct kiocb\t\t*iocb,\n@@ -207,6 +228,17 @@ xfs_file_dio_read(\n \tret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);\n \tif (ret)\n \t\treturn ret;\n+\n+\t/*\n+\t * Re-check verity status after acquiring lock. This prevents TOCTOU in\n+\t * xfs_file_read_iter() while falling back from DIO to buffered I/O as\n+\t * now we are holding a lock\n+\t */\n+\tif (fsverity_active(VFS_I(ip))) {\n+\t\txfs_iunlock(ip, XFS_IOLOCK_SHARED);\n+\t\tiocb-\u003eki_flags \u0026= ~IOCB_DIRECT;\n+\t\treturn xfs_file_buffered_read(iocb, to);\n+\t}\n \tif (mapping_stable_writes(iocb-\u003eki_filp-\u003ef_mapping)) {\n \t\tret = iomap_dio_rw(iocb, to, xfs_read_iomap_next,\n \t\t\t\t\u0026xfs_dio_read_bounce_ops, 0, NULL, 0);\n@@ -226,7 +258,8 @@ xfs_file_dax_read(\n \tstruct kiocb\t\t*iocb,\n \tstruct iov_iter\t\t*to)\n {\n-\tstruct xfs_inode\t*ip = XFS_I(iocb-\u003eki_filp-\u003ef_mapping-\u003ehost);\n+\tstruct inode\t\t*inode = iocb-\u003eki_filp-\u003ef_mapping-\u003ehost;\n+\tstruct xfs_inode\t*ip = XFS_I(inode);\n \tssize_t\t\t\tret = 0;\n \n \ttrace_xfs_file_dax_read(iocb, to);\n@@ -244,25 +277,6 @@ xfs_file_dax_read(\n \treturn ret;\n }\n \n-STATIC ssize_t\n-xfs_file_buffered_read(\n-\tstruct kiocb\t\t*iocb,\n-\tstruct iov_iter\t\t*to)\n-{\n-\tstruct xfs_inode\t*ip = XFS_I(file_inode(iocb-\u003eki_filp));\n-\tssize_t\t\t\tret;\n-\n-\ttrace_xfs_file_buffered_read(iocb, to);\n-\n-\tret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);\n-\tif (ret)\n-\t\treturn ret;\n-\tret = generic_file_read_iter(iocb, to);\n-\txfs_iunlock(ip, XFS_IOLOCK_SHARED);\n-\n-\treturn ret;\n-}\n-\n STATIC ssize_t\n xfs_file_read_iter(\n \tstruct kiocb\t\t*iocb,\n@@ -277,6 +291,14 @@ xfs_file_read_iter(\n \tif (xfs_is_shutdown(mp))\n \t\treturn -EIO;\n \n+\t/*\n+\t * In case fs-verity is enabled, we also fallback to the buffered read\n+\t * from the direct read path. Therefore, IOCB_DIRECT is set and need to\n+\t * be cleared (see generic_file_read_iter())\n+\t */\n+\tif (fsverity_active(inode))\n+\t\tiocb-\u003eki_flags \u0026= ~IOCB_DIRECT;\n+\n \tif (IS_DAX(inode))\n \t\tret = xfs_file_dax_read(iocb, to);\n \telse if (iocb-\u003eki_flags \u0026 IOCB_DIRECT)\n@@ -1731,11 +1753,18 @@ xfs_file_open(\n \tstruct inode\t*inode,\n \tstruct file\t*file)\n {\n+\tint\t\terror;\n+\n \tif (xfs_is_shutdown(XFS_M(inode-\u003ei_sb)))\n \t\treturn -EIO;\n \tfile-\u003ef_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT;\n \tif (xfs_get_atomic_write_min(XFS_I(inode)) \u003e 0)\n \t\tfile-\u003ef_mode |= FMODE_CAN_ATOMIC_WRITE;\n+\n+\terror = fsverity_file_open(inode, file);\n+\tif (error)\n+\t\treturn error;\n+\n \treturn generic_file_open(inode, file);\n }\n \ndiff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c\nnew file mode 100644\nindex 00000000000000..36520a187a2c70\n--- /dev/null\n+++ b/fs/xfs/xfs_fsverity.c\n@@ -0,0 +1,509 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Copyright (C) 2026 Red Hat, Inc.\n+ */\n+#include \"xfs_platform.h\"\n+#include \"xfs_fs.h\"\n+#include \"xfs_shared.h\"\n+#include \"xfs_format.h\"\n+#include \"xfs_trans_resv.h\"\n+#include \"xfs_mount.h\"\n+#include \"xfs_inode.h\"\n+#include \"xfs_log_format.h\"\n+#include \"xfs_trans.h\"\n+#include \"xfs_trace.h\"\n+#include \"xfs_quota.h\"\n+#include \"xfs_fsverity.h\"\n+#include \"xfs_iomap.h\"\n+#include \"xfs_error.h\"\n+#include \"xfs_health.h\"\n+#include \"xfs_bmap_util.h\"\n+#include \"xfs_icache.h\"\n+#include \u003clinux/fsverity.h\u003e\n+#include \u003clinux/iomap.h\u003e\n+#include \u003clinux/pagemap.h\u003e\n+\n+struct kmem_cache *xfs_fsverity_ioend_cache;\n+mempool_t xfs_fsverity_ioend_pool;\n+\n+#define XFS_FSVERITY_IOEND_POOL_MIN\t128\n+\n+/*\n+ * Back the fsverity ioend allocations with a mempool so that read I/O\n+ * completion always makes forward progress and cannot deadlock\n+ */\n+int\n+xfs_fsverity_init(void)\n+{\n+\treturn mempool_init_slab_pool(\u0026xfs_fsverity_ioend_pool,\n+\t\t\tXFS_FSVERITY_IOEND_POOL_MIN, xfs_fsverity_ioend_cache);\n+}\n+\n+void\n+xfs_fsverity_exit(void)\n+{\n+\tmempool_exit(\u0026xfs_fsverity_ioend_pool);\n+}\n+\n+bool\n+xfs_fsverity_is_file_data(\n+\tconst struct xfs_inode\t*ip,\n+\tloff_t\t\t\toffset)\n+{\n+\treturn fsverity_active(VFS_IC(ip)) \u0026\u0026\n+\t\t\toffset \u003c xfs_fsverity_metadata_offset(ip);\n+}\n+\n+/*\n+ * Retrieve the verity descriptor.\n+ */\n+static int\n+xfs_fsverity_get_descriptor(\n+\tstruct inode\t\t*inode,\n+\tvoid\t\t\t*buf,\n+\tsize_t\t\t\tbuf_size)\n+{\n+\tstruct xfs_inode\t*ip = XFS_I(inode);\n+\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n+\t__be32\t\t\td_desc_size;\n+\tu32\t\t\tdesc_size;\n+\tu64\t\t\tdesc_size_pos;\n+\tint\t\t\terror;\n+\tu64\t\t\tdesc_pos;\n+\tstruct xfs_bmbt_irec\trec;\n+\tint\t\t\tis_empty;\n+\tuint32_t\t\tblocksize = i_blocksize(VFS_I(ip));\n+\txfs_fileoff_t\t\tlast_block_offset;\n+\n+\t/*\n+\t * fs-verity cannot be used when the filesystem block size exceeds the\n+\t * page size, as the Merkle tree folios are compound and PG_checked is\n+\t * not supported on compound folios.  Reject such inodes so that they\n+\t * cannot be opened and read as verity files.\n+\t */\n+\tif (mp-\u003em_sb.sb_blocksize \u003e PAGE_SIZE)\n+\t\treturn -EOPNOTSUPP;\n+\n+\txfs_ilock(ip, XFS_ILOCK_EXCL);\n+\t/*\n+\t * Serialize reading of inode-\u003ei_flags with xfs_scrub clearing of this\n+\t * flag if inode is corrupted.\n+\t */\n+\tif (!(inode-\u003ei_flags \u0026 S_VERITY)) {\n+\t\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n+\t\treturn -ENODATA;\n+\t}\n+\terror = xfs_bmap_last_extent(NULL, ip, XFS_DATA_FORK, \u0026rec, \u0026is_empty);\n+\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n+\tif (error)\n+\t\treturn error;\n+\n+\tif (is_empty) {\n+\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n+\t\treturn -ENODATA;\n+\t}\n+\n+\t/*\n+\t * Make sure we can open large file on a 32-bit kernel\n+\t */\n+\tif (rec.br_startoff + rec.br_blockcount \u003e\n+\t\t\tXFS_B_TO_FSB(mp, inode-\u003ei_sb-\u003es_maxbytes))\n+\t\treturn -EFBIG;\n+\n+\tlast_block_offset =\n+\t\tXFS_FSB_TO_B(mp, rec.br_startoff + rec.br_blockcount);\n+\tif (last_block_offset \u003c= xfs_fsverity_metadata_offset(ip)) {\n+\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n+\t\treturn -ENODATA;\n+\t}\n+\n+\tdesc_size_pos = last_block_offset - sizeof(__be32);\n+\terror = fsverity_pagecache_read(inode, (char *)\u0026d_desc_size,\n+\t\t\tsizeof(d_desc_size), desc_size_pos);\n+\tif (error)\n+\t\treturn error;\n+\n+\tdesc_size = be32_to_cpu(d_desc_size);\n+\tif (XFS_IS_CORRUPT(mp, desc_size \u003e FS_VERITY_MAX_DESCRIPTOR_SIZE)) {\n+\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n+\t\treturn -ERANGE;\n+\t}\n+\n+\tif (XFS_IS_CORRUPT(mp, desc_size \u003e desc_size_pos)) {\n+\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n+\t\treturn -ERANGE;\n+\t}\n+\n+\tif (!buf_size)\n+\t\treturn desc_size;\n+\n+\tif (XFS_IS_CORRUPT(mp, desc_size \u003e buf_size)) {\n+\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n+\t\treturn -ERANGE;\n+\t}\n+\n+\tdesc_pos = round_down(desc_size_pos - desc_size, blocksize);\n+\tif (desc_pos \u003c xfs_fsverity_metadata_offset(ip)) {\n+\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n+\t\treturn -ERANGE;\n+\t}\n+\n+\terror = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);\n+\tif (error)\n+\t\treturn error;\n+\n+\treturn desc_size;\n+}\n+\n+static int\n+xfs_fsverity_write_descriptor(\n+\tstruct file\t\t*file,\n+\tconst void\t\t*desc,\n+\tu32\t\t\tdesc_size,\n+\tu64\t\t\tmerkle_tree_size)\n+{\n+\tint\t\t\terror;\n+\tstruct inode\t\t*inode = file_inode(file);\n+\tstruct xfs_inode\t*ip = XFS_I(inode);\n+\tunsigned int\t\tblksize = ip-\u003ei_mount-\u003em_sb.sb_blocksize;\n+\tu64\t\t\ttree_last_block =\n+\t\t\txfs_fsverity_metadata_offset(ip) + merkle_tree_size;\n+\tu64\t\t\tdesc_pos =\n+\t\t\tround_up(tree_last_block, XFS_FSVERITY_START_ALIGN);\n+\tu64\t\t\tdesc_end = desc_pos + desc_size;\n+\t__be32\t\t\tdesc_size_disk = cpu_to_be32(desc_size);\n+\tu64\t\t\tdesc_size_pos =\n+\t\t\tround_up(desc_end + sizeof(desc_size_disk), blksize) -\n+\t\t\tsizeof(desc_size_disk);\n+\n+\tif (desc_size_pos + sizeof(desc_size_disk) \u003e inode-\u003ei_sb-\u003es_maxbytes)\n+\t\treturn -EFBIG;\n+\n+\terror = iomap_fsverity_write(file, desc_size_pos, sizeof(__be32),\n+\t\t\t(const void *)\u0026desc_size_disk,\n+\t\t\txfs_buffered_write_iomap_next,\n+\t\t\t\u0026xfs_iomap_write_ops);\n+\tif (error)\n+\t\treturn error;\n+\n+\treturn iomap_fsverity_write(file, desc_pos, desc_size, desc,\n+\t\t\txfs_buffered_write_iomap_next,\n+\t\t\t\u0026xfs_iomap_write_ops);\n+}\n+\n+/*\n+ * Try to remove all the fsverity metadata after a failed enablement.\n+ */\n+static int\n+xfs_fsverity_delete_metadata(\n+\tstruct xfs_inode\t*ip)\n+{\n+\tstruct xfs_trans\t*tp;\n+\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n+\tint\t\t\terror;\n+\n+\txfs_ilock(ip, XFS_MMAPLOCK_EXCL);\n+\ttruncate_inode_pages(VFS_I(ip)-\u003ei_mapping, XFS_ISIZE(ip));\n+\n+\terror = xfs_trans_alloc(mp, \u0026M_RES(mp)-\u003etr_itruncate, 0, 0, 0, \u0026tp);\n+\tif (error) {\n+\t\txfs_iunlock(ip, XFS_MMAPLOCK_EXCL);\n+\t\treturn error;\n+\t}\n+\n+\txfs_ilock(ip, XFS_ILOCK_EXCL);\n+\txfs_trans_ijoin(tp, ip, 0);\n+\n+\t/*\n+\t * We remove post EOF data, no need to update i_size as fsverity\n+\t * didn't move i_size in the first place\n+\t */\n+\terror = xfs_itruncate_extents(\u0026tp, ip, XFS_DATA_FORK, XFS_ISIZE(ip));\n+\tif (error)\n+\t\tgoto err_cancel;\n+\n+\terror = xfs_trans_commit(tp);\n+\txfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);\n+\treturn error;\n+err_cancel:\n+\txfs_trans_cancel(tp);\n+\txfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);\n+\treturn error;\n+}\n+\n+static int\n+xfs_fsverity_reset_inode(\n+\tstruct xfs_inode\t*ip)\n+{\n+\tint\t\t\terror;\n+\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n+\tstruct xfs_trans\t*tp;\n+\n+\terror = xfs_fsverity_delete_metadata(ip);\n+\tif (error)\n+\t\treturn error;\n+\n+\t/*\n+\t * First, let's clean in-memory fsverity flag and then reset it on the\n+\t * disk\n+\t */\n+\tinode_set_flags(VFS_I(ip), 0, S_VERITY);\n+\n+\t/*\n+\t * Set fsverity inode flag\n+\t */\n+\terror = xfs_trans_alloc_inode(ip, \u0026M_RES(mp)-\u003etr_ichange,\n+\t\t\t0, 0, false, \u0026tp);\n+\tif (error)\n+\t\treturn error;\n+\n+\tip-\u003ei_diflags2 \u0026= ~XFS_DIFLAG2_VERITY;\n+\n+\txfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);\n+\txfs_trans_set_sync(tp);\n+\n+\terror = xfs_trans_commit(tp);\n+\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n+\treturn error;\n+}\n+\n+/*\n+ * Prepare to enable fsverity by clearing old metadata.\n+ */\n+static int\n+xfs_fsverity_begin_enable(\n+\tstruct file\t\t*filp)\n+{\n+\tstruct inode\t\t*inode = file_inode(filp);\n+\tstruct xfs_inode\t*ip = XFS_I(inode);\n+\tint\t\t\terror;\n+\n+\txfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);\n+\n+\tif (IS_DAX(inode) || ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_DAX)\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * fs-verity tracks verified Merkle tree pages using PG_checked, which\n+\t * is only valid on single-page (non-compound) folios.  When the\n+\t * filesystem block size is larger than the page size, the page cache\n+\t * enforces a minimum folio order \u003e 0, so all Merkle tree folios are\n+\t * compound. fs-verity cannot be used on such filesystems.\n+\t */\n+\tif (ip-\u003ei_mount-\u003em_sb.sb_blocksize \u003e PAGE_SIZE)\n+\t\treturn -EOPNOTSUPP;\n+\n+\t/*\n+\t * fs-verity doesn't work on zoned\n+\t */\n+\tif (xfs_is_zoned_inode(ip))\n+\t\treturn -EOPNOTSUPP;\n+\n+\t/*\n+\t * fs-verity stores the Merkle tree past EOF in units of the filesystem\n+\t * block size, so it cannot support realtime files whose allocation unit\n+\t * (extent size) is larger than the block size.\n+\t */\n+\tif (xfs_inode_has_bigrtalloc(ip))\n+\t\treturn -EINVAL;\n+\n+\tif (XFS_B_TO_FSB(ip-\u003ei_mount, inode-\u003ei_size) \u003e\n+\t\t\tXFS_FSVERITY_LARGEST_FILE_FSB(ip-\u003ei_mount))\n+\t\treturn -EFBIG;\n+\n+\t/*\n+\t * Flush pagecache before building Merkle tree. Inode is locked and no\n+\t * further writes will happen to the file except fsverity metadata\n+\t */\n+\terror = filemap_write_and_wait(inode-\u003ei_mapping);\n+\tif (error)\n+\t\treturn error;\n+\n+\terror = xfs_qm_dqattach(ip);\n+\tif (error)\n+\t\treturn error;\n+\n+\treturn xfs_fsverity_delete_metadata(ip);\n+}\n+\n+/*\n+ * Complete (or fail) the process of enabling fsverity.\n+ */\n+static int\n+xfs_fsverity_end_enable(\n+\tstruct file\t\t*file,\n+\tconst void\t\t*desc,\n+\tsize_t\t\t\tdesc_size,\n+\tu64\t\t\tmerkle_tree_size)\n+{\n+\tstruct inode\t\t*inode = file_inode(file);\n+\tstruct xfs_inode\t*ip = XFS_I(inode);\n+\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n+\tstruct xfs_trans\t*tp;\n+\tint\t\t\terror = 0;\n+\tint\t\t\terror2;\n+\tloff_t\t\t\trange_start = xfs_fsverity_metadata_offset(ip);\n+\n+\txfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);\n+\n+\t/* fs-verity failed, just cleanup */\n+\tif (desc == NULL)\n+\t\tgoto out;\n+\n+\terror = xfs_fsverity_write_descriptor(file, desc, desc_size,\n+\t\t\tmerkle_tree_size);\n+\tif (error)\n+\t\tgoto out;\n+\n+\t/*\n+\t * Wait for Merkle tree get written to disk before setting on-disk inode\n+\t * flag and clearing I_VERITY_BUILDING\n+\t */\n+\terror = filemap_write_and_wait_range(inode-\u003ei_mapping, range_start,\n+\t\t\tLLONG_MAX);\n+\tif (error)\n+\t\tgoto out;\n+\n+\t/*\n+\t * Proactively remove unwritten extents left by COW preallocations and\n+\t * write preallocation in the merkle tree holes and past descriptor,\n+\t * and any delayed preallocations\n+\t */\n+\terror = xfs_free_eofblocks(ip);\n+\tif (error)\n+\t\tgoto out;\n+\n+\t/*\n+\t * Set fsverity inode flag\n+\t */\n+\terror = xfs_trans_alloc_inode(ip, \u0026M_RES(mp)-\u003etr_ichange,\n+\t\t\t0, 0, false, \u0026tp);\n+\tif (error)\n+\t\tgoto out;\n+\n+\t/*\n+\t * Ensure that we've persisted the verity information before we enable\n+\t * it on the inode and tell the caller we have sealed the inode.\n+\t */\n+\tip-\u003ei_diflags2 |= XFS_DIFLAG2_VERITY;\n+\n+\txfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);\n+\txfs_trans_set_sync(tp);\n+\n+\terror = xfs_trans_commit(tp);\n+\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n+\tif (error)\n+\t\tgoto out;\n+\n+\tinode_set_flags(inode, S_VERITY, S_VERITY);\n+\treturn error;\n+\n+out:\n+\terror2 = xfs_fsverity_reset_inode(ip);\n+\tif (error2)\n+\t\txfs_alert(ip-\u003ei_mount,\n+\"ino 0x%llx failed to clean up new fsverity metadata, err %d\",\n+\t\t\t\tI_INO(ip), error2);\n+\n+\treturn error;\n+}\n+\n+/*\n+ * Retrieve a merkle tree block.\n+ */\n+static struct page *\n+xfs_fsverity_read_merkle(\n+\tstruct inode\t\t*inode,\n+\tpgoff_t\t\t\tindex)\n+{\n+\tindex += xfs_fsverity_metadata_offset(XFS_I(inode)) \u003e\u003e PAGE_SHIFT;\n+\n+\treturn generic_read_merkle_tree_page(inode, index);\n+}\n+\n+/*\n+ * Retrieve a merkle tree block.\n+ */\n+static void\n+xfs_fsverity_readahead_merkle_tree(\n+\tstruct inode\t\t*inode,\n+\tpgoff_t\t\t\tindex,\n+\tunsigned long\t\tnr_pages)\n+{\n+\tindex += xfs_fsverity_metadata_offset(XFS_I(inode)) \u003e\u003e PAGE_SHIFT;\n+\n+\tgeneric_readahead_merkle_tree(inode, index, nr_pages);\n+}\n+\n+static inline bool\n+xfs_fsverity_is_hashes_of_zeroed_blocks(\n+\tstruct xfs_inode\t*ip,\n+\tconst void\t\t*buf,\n+\tunsigned int\t\tsize,\n+\tconst u8\t\t*zero_digest,\n+\tunsigned int\t\tdigest_size)\n+{\n+\t/*\n+\t * If this is a block full of hashes of zeroed blocks, don't bother\n+\t * storing the block. We can synthesize them later.\n+\t *\n+\t * However, do this only in case Merkle tree block == fs block size.\n+\t * Iomap synthesizes these blocks based on holes in the merkle tree. We\n+\t * won't be able to tell if something need to be synthesizes for the\n+\t * range in the fs block. For example, for 4k filesystem block\n+\t *\n+\t *\t[ 1k | zero hashes | zero hashes | 1k ]\n+\t *\n+\t * Iomap won't know about these empty blocks.\n+\t */\n+\tif (size != ip-\u003ei_mount-\u003em_sb.sb_blocksize)\n+\t\treturn false;\n+\t/*\n+\t * First digest is zero_digest\n+\t */\n+\tif (memcmp(buf, zero_digest, digest_size))\n+\t\treturn false;\n+\t/*\n+\t * Every digest is same as previous, thus all are\n+\t * zero_digest\n+\t */\n+\treturn memcmp(buf + digest_size, buf, size - digest_size) == 0;\n+}\n+\n+/*\n+ * Write a merkle tree block.\n+ */\n+static int\n+xfs_fsverity_write_merkle(\n+\tstruct file\t\t*file,\n+\tconst void\t\t*buf,\n+\tu64\t\t\tpos,\n+\tunsigned int\t\tsize,\n+\tconst u8\t\t*zero_digest,\n+\tunsigned int\t\tdigest_size)\n+{\n+\tstruct inode\t\t*inode = file_inode(file);\n+\tstruct xfs_inode\t*ip = XFS_I(inode);\n+\tloff_t\t\t\tposition = pos +\n+\t\txfs_fsverity_metadata_offset(ip);\n+\n+\tif (position + size \u003e inode-\u003ei_sb-\u003es_maxbytes)\n+\t\treturn -EFBIG;\n+\n+\tif (xfs_fsverity_is_hashes_of_zeroed_blocks(ip, buf, size, zero_digest,\n+\t\t\t\t\t\t    digest_size))\n+\t\treturn 0;\n+\n+\treturn iomap_fsverity_write(file, position, size, buf,\n+\t\t\txfs_buffered_write_iomap_next,\n+\t\t\t\u0026xfs_iomap_write_ops);\n+}\n+\n+const struct fsverity_operations xfs_fsverity_ops = {\n+\t.begin_enable_verity\t\t= xfs_fsverity_begin_enable,\n+\t.end_enable_verity\t\t= xfs_fsverity_end_enable,\n+\t.get_verity_descriptor\t\t= xfs_fsverity_get_descriptor,\n+\t.read_merkle_tree_page\t\t= xfs_fsverity_read_merkle,\n+\t.readahead_merkle_tree\t\t= xfs_fsverity_readahead_merkle_tree,\n+\t.write_merkle_tree_block\t= xfs_fsverity_write_merkle,\n+};\ndiff --git a/fs/xfs/xfs_fsverity.h b/fs/xfs/xfs_fsverity.h\nnew file mode 100644\nindex 00000000000000..43f8ef62e12a1a\n--- /dev/null\n+++ b/fs/xfs/xfs_fsverity.h\n@@ -0,0 +1,42 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Copyright (C) 2026 Red Hat, Inc.\n+ */\n+#ifndef __XFS_FSVERITY_H__\n+#define __XFS_FSVERITY_H__\n+\n+#include \"xfs_platform.h\"\n+#include \"xfs_verity.h\"\n+#include \u003clinux/iomap.h\u003e\n+#include \u003clinux/fsverity.h\u003e\n+#include \u003clinux/mempool.h\u003e\n+\n+#ifdef CONFIG_FS_VERITY\n+extern const struct fsverity_operations xfs_fsverity_ops;\n+int xfs_fsverity_init(void);\n+void xfs_fsverity_exit(void);\n+bool xfs_fsverity_is_file_data(const struct xfs_inode *ip, loff_t offset);\n+#else\n+static inline int xfs_fsverity_init(void)\n+{\n+\treturn 0;\n+}\n+static inline void xfs_fsverity_exit(void)\n+{\n+}\n+static inline bool xfs_fsverity_is_file_data(const struct xfs_inode *ip,\n+\t\t\t\t\t    loff_t offset)\n+{\n+\treturn false;\n+}\n+#endif\t/* CONFIG_FS_VERITY */\n+\n+struct xfs_fsverity_ioend {\n+\tstruct iomap_ioend\t*ioend;\n+\tstruct work_struct\twork;\n+};\n+\n+extern struct kmem_cache *xfs_fsverity_ioend_cache;\n+extern mempool_t xfs_fsverity_ioend_pool;\n+\n+#endif\t/* __XFS_FSVERITY_H__ */\ndiff --git a/fs/xfs/xfs_health.c b/fs/xfs/xfs_health.c\nindex 239b843e83d42a..be66760fb120f7 100644\n--- a/fs/xfs/xfs_health.c\n+++ b/fs/xfs/xfs_health.c\n@@ -625,6 +625,7 @@ static const struct ioctl_sick_map ino_map[] = {\n \t{ XFS_SICK_INO_DIR_ZAPPED,\tXFS_BS_SICK_DIR },\n \t{ XFS_SICK_INO_SYMLINK_ZAPPED,\tXFS_BS_SICK_SYMLINK },\n \t{ XFS_SICK_INO_DIRTREE,\tXFS_BS_SICK_DIRTREE },\n+\t{ XFS_SICK_INO_FSVERITY,\tXFS_BS_SICK_FSVERITY },\n };\n \n /* Fill out bulkstat health info. */\ndiff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c\nindex de8be344e987d0..ca74c9b4f8d383 100644\n--- a/fs/xfs/xfs_icache.c\n+++ b/fs/xfs/xfs_icache.c\n@@ -28,7 +28,7 @@\n #include \"xfs_da_format.h\"\n #include \"xfs_dir2.h\"\n #include \"xfs_metafile.h\"\n-\n+#include \u003clinux/fsverity.h\u003e\n #include \u003clinux/iversion.h\u003e\n \n /* Radix tree tags for incore inode tree. */\n@@ -1260,6 +1260,15 @@ xfs_inode_free_eofblocks(\n \tif (xfs_can_free_eofblocks(ip))\n \t\treturn xfs_free_eofblocks(ip);\n \n+\t/*\n+\t * The above xfs_free_eofblocks() is skipped for inodes with fsverity\n+\t * tree is being built. However, we don't want to clear EOF tag in this\n+\t * case. If building the tree fails, inode will have EOF blocks which\n+\t * needs removal.\n+\t */\n+\tif (fsverity_is_building(VFS_IC(ip)))\n+\t\treturn 0;\n+\n \t/* inode could be preallocated */\n \ttrace_xfs_inode_free_eofblocks_invalid(ip);\n \txfs_inode_clear_eofblocks_tag(ip);\ndiff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c\nindex f81b6e52ac403d..2d0a2d37e71cf8 100644\n--- a/fs/xfs/xfs_ioctl.c\n+++ b/fs/xfs/xfs_ioctl.c\n@@ -49,6 +49,7 @@\n \n #include \u003clinux/mount.h\u003e\n #include \u003clinux/fileattr.h\u003e\n+#include \u003clinux/fsverity.h\u003e\n \n /* Return 0 on success or positive error */\n int\n@@ -562,6 +563,14 @@ xfs_ioctl_setattr_xflags(\n \t\tif (xfs_inode_has_filedata(ip))\n \t\t\treturn -EINVAL;\n \n+\t\t/*\n+\t\t * fs-verity is incompatible with a realtime allocation unit\n+\t\t * larger than a single filesystem block, so don't let a file be\n+\t\t * converted to realtime while verity is being enabled.\n+\t\t */\n+\t\tif (fsverity_is_building(VFS_IC(ip)))\n+\t\t\treturn -EINVAL;\n+\n \t\t/*\n \t\t * If S_DAX is enabled on this file, we can only switch the\n \t\t * device if both support fsdax.  We can't update S_DAX because\n@@ -574,6 +583,17 @@ xfs_ioctl_setattr_xflags(\n \t\t\treturn -EINVAL;\n \t}\n \n+\t/*\n+\t * fs-verity is incompatible with DAX, and xfs_fsverity_begin_enable()\n+\t * verified the inode was not DAX under the inode lock.  That lock is\n+\t * dropped while the Merkle tree is built, so reject enabling DAX while\n+\t * verity is being enabled.\n+\t */\n+\tif ((fa-\u003efsx_xflags \u0026 FS_XFLAG_DAX) \u0026\u0026\n+\t    !(ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_DAX) \u0026\u0026\n+\t    fsverity_is_building(VFS_IC(ip)))\n+\t\treturn -EINVAL;\n+\n \tif (rtflag) {\n \t\t/* If realtime flag is set then must have realtime device */\n \t\tif (mp-\u003em_sb.sb_rblocks == 0 || mp-\u003em_sb.sb_rextsize == 0 ||\n@@ -1575,6 +1595,19 @@ xfs_file_ioctl(\n \tcase XFS_IOC_VERIFY_MEDIA:\n \t\treturn xfs_ioc_verify_media(filp, arg);\n \n+\tcase FS_IOC_ENABLE_VERITY:\n+\t\tif (!xfs_has_verity(mp))\n+\t\t\treturn -EOPNOTSUPP;\n+\t\treturn fsverity_ioctl_enable(filp, arg);\n+\tcase FS_IOC_MEASURE_VERITY:\n+\t\tif (!xfs_has_verity(mp))\n+\t\t\treturn -EOPNOTSUPP;\n+\t\treturn fsverity_ioctl_measure(filp, arg);\n+\tcase FS_IOC_READ_VERITY_METADATA:\n+\t\tif (!xfs_has_verity(mp))\n+\t\t\treturn -EOPNOTSUPP;\n+\t\treturn fsverity_ioctl_read_metadata(filp, arg);\n+\n \tdefault:\n \t\treturn -ENOTTY;\n \t}\ndiff --git a/fs/xfs/xfs_ioend.c b/fs/xfs/xfs_ioend.c\nindex 7f4a4a95afe50d..61f211a3b8052b 100644\n--- a/fs/xfs/xfs_ioend.c\n+++ b/fs/xfs/xfs_ioend.c\n@@ -18,7 +18,26 @@\n #include \"xfs_ioend.h\"\n #include \"xfs_error.h\"\n #include \"xfs_errortag.h\"\n+#include \"xfs_fsverity.h\"\n #include \u003clinux/bio-integrity.h\u003e\n+#include \u003clinux/fsverity.h\u003e\n+\n+static void\n+xfs_end_fsverity_io_read(\n+\tstruct work_struct\t\t*work)\n+{\n+\tstruct xfs_fsverity_ioend\t*fsv_ioend =\n+\t\t\tcontainer_of(work, struct xfs_fsverity_ioend, work);\n+\tstruct iomap_ioend\t\t*ioend = fsv_ioend-\u003eioend;\n+\tstruct bio\t\t\t*bio = \u0026ioend-\u003eio_bio;\n+\n+\tmempool_free(fsv_ioend, \u0026xfs_fsverity_ioend_pool);\n+\n+\tif (!bio-\u003ebi_status)\n+\t\tfsverity_verify_bio(ioend-\u003eio_vi, bio);\n+\n+\tiomap_finish_ioends(ioend, blk_status_to_errno(bio-\u003ebi_status));\n+}\n \n static void\n xfs_dio_bounce_end_io(\n@@ -93,12 +112,14 @@ xfs_read_bounce_and_resubmit(\n \n static void\n xfs_end_io_read(\n-\tstruct bio\t\t*bio)\n+\tstruct bio\t\t\t*bio)\n {\n-\tstruct iomap_ioend\t*ioend = iomap_ioend_from_bio(bio);\n-\tstruct xfs_inode\t*ip = XFS_I(ioend-\u003eio_inode);\n-\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n-\tint\t\t\terror = blk_status_to_errno(bio-\u003ebi_status);\n+\tstruct iomap_ioend\t\t*ioend = iomap_ioend_from_bio(bio);\n+\tstruct xfs_inode\t\t*ip = XFS_I(ioend-\u003eio_inode);\n+\tstruct xfs_mount\t\t*mp = ip-\u003ei_mount;\n+\tint\t\t\t\terror =\n+\t\t\tblk_status_to_errno(bio-\u003ebi_status);\n+\tstruct xfs_fsverity_ioend\t*fsv_ioend;\n \n \tif (!error \u0026\u0026 (ioend-\u003eio_flags \u0026 IOMAP_IOEND_INTEGRITY)) {\n \t\terror = iomap_ioend_integrity_verify(ioend);\n@@ -117,6 +138,24 @@ xfs_end_io_read(\n \t\t}\n \t}\n \n+\t/*\n+\t * If we have fsverity on this bio, we need to run fsverity verification\n+\t * of data folios from a separate fsverity workqueue. This is necessary\n+\t * to avoid deadlocking due to fsverity issuing more reads of fsverity\n+\t * metadata which would be processed by the same worker in the BIO\n+\t * completion workqueue.\n+\t */\n+\tif (IS_ENABLED(CONFIG_FS_VERITY) \u0026\u0026 !error \u0026\u0026 ioend-\u003eio_vi \u0026\u0026\n+\t\t\txfs_fsverity_is_file_data(ip, ioend-\u003eio_offset)) {\n+\t\tfsv_ioend = mempool_alloc(\u0026xfs_fsverity_ioend_pool,\n+\t\t\t\tGFP_NOFS);\n+\t\tfsv_ioend-\u003eioend = ioend;\n+\t\tINIT_WORK(\u0026fsv_ioend-\u003ework, xfs_end_fsverity_io_read);\n+\n+\t\tfsverity_enqueue_verify_work(\u0026fsv_ioend-\u003ework);\n+\t\treturn;\n+\t}\n+\n \tiomap_finish_ioends(ioend, error);\n }\n \n@@ -125,13 +164,15 @@ xfs_ioend_submit_read(\n \tstruct inode\t\t*inode,\n \tstruct bio\t\t*bio,\n \tloff_t\t\t\tfile_offset,\n-\tu16\t\t\tioend_flags)\n+\tu16\t\t\tioend_flags,\n+\tstruct fsverity_info\t*vi)\n {\n \tstruct xfs_inode\t*ip = XFS_I(inode);\n \tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n \tstruct iomap_ioend\t*ioend;\n \n \tioend = iomap_init_ioend(inode, bio, file_offset, ioend_flags);\n+\tioend-\u003eio_vi = vi;\n \tif ((ioend_flags \u0026 IOMAP_IOEND_DIRECT) \u0026\u0026\n \t    READ_ONCE(mp-\u003em_read_bounce) == XFS_READ_BOUNCE_ALWAYS) {\n \t\tiomap_bounce_read(ioend, bdev_logical_block_size(bio-\u003ebi_bdev),\ndiff --git a/fs/xfs/xfs_ioend.h b/fs/xfs/xfs_ioend.h\nindex 7c2a1ea3e6eddc..992c248a693aaf 100644\n--- a/fs/xfs/xfs_ioend.h\n+++ b/fs/xfs/xfs_ioend.h\n@@ -2,6 +2,8 @@\n #ifndef __XFS_IOEND_H\n #define __XFS_IOEND_H\n \n+#include \u003clinux/fsverity.h\u003e\n+\n /*\n  * Fast and loose check if this write could update the on-disk inode size.\n  */\n@@ -13,6 +15,6 @@ static inline bool xfs_ioend_is_append(struct iomap_ioend *ioend)\n \n void xfs_end_bio(struct bio *bio);\n void xfs_ioend_submit_read(struct inode *inode, struct bio *bio,\n-\t\tloff_t file_offset, u16 ioend_flags);\n+\t\tloff_t file_offset, u16 ioend_flags, struct fsverity_info *vi);\n \n #endif /* __XFS_IOEND_H */\ndiff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c\nindex 50eae7ff614534..5117704530f69c 100644\n--- a/fs/xfs/xfs_iomap.c\n+++ b/fs/xfs/xfs_iomap.c\n@@ -32,6 +32,8 @@\n #include \"xfs_rtbitmap.h\"\n #include \"xfs_icache.h\"\n #include \"xfs_zone_alloc.h\"\n+#include \"xfs_verity.h\"\n+#include \u003clinux/fsverity.h\u003e\n \n #define XFS_ALLOC_ALIGN(mp, off) \\\n \t(((off) \u003e\u003e mp-\u003em_allocsize_log) \u003c\u003c mp-\u003em_allocsize_log)\n@@ -54,6 +56,15 @@ xfs_alert_fsblock_zero(\n \treturn -EFSCORRUPTED;\n }\n \n+static bool\n+xfs_iomap_is_fsverity_metadata(\n+\tstruct xfs_inode\t*ip,\n+\tloff_t\t\t\toffset)\n+{\n+\treturn offset \u003e= xfs_fsverity_metadata_offset(ip) \u0026\u0026\n+\t       (fsverity_is_building(VFS_I(ip)) || fsverity_active(VFS_I(ip)));\n+}\n+\n u64\n xfs_iomap_inode_sequence(\n \tstruct xfs_inode\t*ip,\n@@ -101,6 +112,7 @@ xfs_bmbt_to_iomap(\n \tstruct xfs_inode\t*ip,\n \tstruct iomap\t\t*iomap,\n \tstruct xfs_bmbt_irec\t*imap,\n+\tloff_t\t\t\toffset,\n \tunsigned int\t\tmapping_flags,\n \tu16\t\t\tiomap_flags,\n \tu64\t\t\tsequence_cookie)\n@@ -152,6 +164,15 @@ xfs_bmbt_to_iomap(\n \t\t\tiomap-\u003eflags |= IOMAP_F_INTEGRITY;\n \t}\n \n+\t/*\n+\t * Tell iomap when this I/O covers fs-verity metadata so it handles size\n+\t * updates and post-EOF folios correctly.  The attr fork uses a separate\n+\t * offset space, so exclude it.\n+\t */\n+\tif (!(iomap_flags \u0026 IOMAP_F_XATTR) \u0026\u0026\n+\t    xfs_iomap_is_fsverity_metadata(ip, offset))\n+\t\tiomap-\u003eflags |= IOMAP_F_FSVERITY;\n+\n \t/*\n \t * If the inode is dirty for datasync purposes, let iomap know so it\n \t * doesn't elide the IO completion journal flushes on O_DSYNC IO.\n@@ -1006,7 +1027,8 @@ xfs_direct_write_iomap_begin(\n \tseq = xfs_iomap_inode_sequence(ip, iomap_flags);\n \txfs_iunlock(ip, lockmode);\n \ttrace_xfs_iomap_found(ip, offset, length, XFS_DATA_FORK, \u0026imap);\n-\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026imap, flags, iomap_flags, seq);\n+\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026imap, offset, flags, iomap_flags,\n+\t\t\tseq);\n \n allocate_blocks:\n \terror = -EAGAIN;\n@@ -1037,7 +1059,7 @@ xfs_direct_write_iomap_begin(\n \t\treturn error;\n \n \ttrace_xfs_iomap_alloc(ip, offset, length, XFS_DATA_FORK, \u0026imap);\n-\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026imap, flags,\n+\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026imap, offset, flags,\n \t\t\t\t iomap_flags | IOMAP_F_NEW, seq);\n \n out_found_cow:\n@@ -1045,13 +1067,15 @@ xfs_direct_write_iomap_begin(\n \ttrace_xfs_iomap_found(ip, offset, length - offset, XFS_COW_FORK, \u0026cmap);\n \tif (imap.br_startblock != HOLESTARTBLOCK) {\n \t\tseq = xfs_iomap_inode_sequence(ip, 0);\n-\t\terror = xfs_bmbt_to_iomap(ip, srcmap, \u0026imap, flags, 0, seq);\n+\t\terror = xfs_bmbt_to_iomap(ip, srcmap, \u0026imap, offset, flags,\n+\t\t\t\t0, seq);\n \t\tif (error)\n \t\t\tgoto out_unlock;\n \t}\n \tseq = xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED);\n \txfs_iunlock(ip, lockmode);\n-\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026cmap, flags, IOMAP_F_SHARED, seq);\n+\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026cmap, offset, flags,\n+\t\t\tIOMAP_F_SHARED, seq);\n \n out_unlock:\n \tif (lockmode)\n@@ -1270,7 +1294,8 @@ xfs_atomic_write_cow_iomap_begin(\n \ttrace_xfs_iomap_found(ip, offset, length, XFS_COW_FORK, \u0026cmap);\n \tseq = xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED);\n \txfs_iunlock(ip, XFS_ILOCK_EXCL);\n-\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026cmap, flags, IOMAP_F_SHARED, seq);\n+\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026cmap, offset, flags,\n+\t\t\tIOMAP_F_SHARED, seq);\n \n convert_delay:\n \txfs_iunlock(ip, XFS_ILOCK_EXCL);\n@@ -1622,8 +1647,9 @@ xfs_zoned_fill_srcmap(\n \t */\n \txfs_trim_extent(\u0026smap, offset_fsb, *end_fsb - offset_fsb);\n \t*end_fsb = min(*end_fsb, smap.br_startoff + smap.br_blockcount);\n-\treturn xfs_bmbt_to_iomap(ip, srcmap, \u0026smap, flags, 0,\n-\t\t\txfs_iomap_inode_sequence(ip, 0));\n+\treturn xfs_bmbt_to_iomap(ip, srcmap, \u0026smap,\n+\t\t\tXFS_FSB_TO_B(ip-\u003ei_mount, offset_fsb), flags,\n+\t\t\t0, xfs_iomap_inode_sequence(ip, 0));\n }\n \n static int\n@@ -1796,7 +1822,7 @@ xfs_zoned_buffered_write_iomap_begin(\n \ttrace_xfs_iomap_alloc(ip, offset, XFS_FSB_TO_B(mp, count_fsb),\n \t\t\tXFS_COW_FORK, \u0026got);\n done:\n-\terror = xfs_bmbt_to_iomap(ip, iomap, \u0026got, flags, iomap_flags,\n+\terror = xfs_bmbt_to_iomap(ip, iomap, \u0026got, offset, flags, iomap_flags,\n \t\t\txfs_iomap_inode_sequence(ip, IOMAP_F_SHARED));\n out_unlock:\n \txfs_iunlock(ip, lockmode);\n@@ -2104,7 +2130,8 @@ xfs_buffered_write_iomap_begin(\n found_imap:\n \tseq = xfs_iomap_inode_sequence(ip, iomap_flags);\n \txfs_iunlock(ip, lockmode);\n-\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026imap, flags, iomap_flags, seq);\n+\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026imap, offset, flags, iomap_flags,\n+\t\t\tseq);\n \n convert_delay:\n \txfs_iunlock(ip, lockmode);\n@@ -2119,8 +2146,8 @@ xfs_buffered_write_iomap_begin(\n \n found_cow:\n \tif (imap.br_startoff \u003c= offset_fsb) {\n-\t\terror = xfs_bmbt_to_iomap(ip, srcmap, \u0026imap, flags, 0,\n-\t\t\t\txfs_iomap_inode_sequence(ip, 0));\n+\t\terror = xfs_bmbt_to_iomap(ip, srcmap, \u0026imap, offset, flags,\n+\t\t\t\t0, xfs_iomap_inode_sequence(ip, 0));\n \t\tif (error)\n \t\t\tgoto out_unlock;\n \t} else {\n@@ -2131,7 +2158,8 @@ xfs_buffered_write_iomap_begin(\n \tiomap_flags |= IOMAP_F_SHARED;\n \tseq = xfs_iomap_inode_sequence(ip, iomap_flags);\n \txfs_iunlock(ip, lockmode);\n-\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026cmap, flags, iomap_flags, seq);\n+\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026cmap, offset, flags, iomap_flags,\n+\t\t\tseq);\n \n out_unlock:\n \txfs_iunlock(ip, lockmode);\n@@ -2238,7 +2266,7 @@ xfs_read_iomap_begin(\n \tif (error)\n \t\treturn error;\n \ttrace_xfs_iomap_found(ip, offset, length, XFS_DATA_FORK, \u0026imap);\n-\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026imap, flags,\n+\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026imap, offset, flags,\n \t\t\t\t shared ? IOMAP_F_SHARED : 0, seq);\n }\n \n@@ -2298,7 +2326,7 @@ xfs_seek_iomap_begin(\n \t\t\tend_fsb = min(end_fsb, data_fsb);\n \t\txfs_trim_extent(\u0026cmap, offset_fsb, end_fsb - offset_fsb);\n \t\tseq = xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED);\n-\t\terror = xfs_bmbt_to_iomap(ip, iomap, \u0026cmap, flags,\n+\t\terror = xfs_bmbt_to_iomap(ip, iomap, \u0026cmap, offset, flags,\n \t\t\t\tIOMAP_F_SHARED, seq);\n \t\t/*\n \t\t * This is a COW extent, so we must probe the page cache\n@@ -2322,7 +2350,7 @@ xfs_seek_iomap_begin(\n done:\n \tseq = xfs_iomap_inode_sequence(ip, 0);\n \txfs_trim_extent(\u0026imap, offset_fsb, end_fsb - offset_fsb);\n-\terror = xfs_bmbt_to_iomap(ip, iomap, \u0026imap, flags, 0, seq);\n+\terror = xfs_bmbt_to_iomap(ip, iomap, \u0026imap, offset, flags, 0, seq);\n out_unlock:\n \txfs_iunlock(ip, lockmode);\n \treturn error;\n@@ -2370,7 +2398,8 @@ xfs_xattr_iomap_begin(\n \tif (error)\n \t\treturn error;\n \tASSERT(nimaps);\n-\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026imap, flags, IOMAP_F_XATTR, seq);\n+\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026imap, offset, flags,\n+\t\t\tIOMAP_F_XATTR, seq);\n }\n \n DEFINE_IOMAP_ITER_NEXT(xfs_xattr_iomap_next, xfs_xattr_iomap_begin);\ndiff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h\nindex 071fff6665070e..c9bd6de1bfda5a 100644\n--- a/fs/xfs/xfs_iomap.h\n+++ b/fs/xfs/xfs_iomap.h\n@@ -22,8 +22,9 @@ xfs_fileoff_t xfs_iomap_eof_align_last_fsb(struct xfs_inode *ip,\n \n u64 xfs_iomap_inode_sequence(struct xfs_inode *ip, u16 iomap_flags);\n int xfs_bmbt_to_iomap(struct xfs_inode *ip, struct iomap *iomap,\n-\t\tstruct xfs_bmbt_irec *imap, unsigned int mapping_flags,\n-\t\tu16 iomap_flags, u64 sequence_cookie);\n+\t\tstruct xfs_bmbt_irec *imap, loff_t offset,\n+\t\tunsigned int mapping_flags, u16 iomap_flags,\n+\t\tu64 sequence_cookie);\n \n int xfs_zero_range(struct xfs_inode *ip, loff_t pos, loff_t len,\n \t\tstruct xfs_zone_alloc_ctx *ac, bool *did_zero);\ndiff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c\nindex 6c5633db30daea..ff34f392dd557e 100644\n--- a/fs/xfs/xfs_iops.c\n+++ b/fs/xfs/xfs_iops.c\n@@ -35,6 +35,7 @@\n #include \u003clinux/security.h\u003e\n #include \u003clinux/iversion.h\u003e\n #include \u003clinux/fiemap.h\u003e\n+#include \u003clinux/fsverity.h\u003e\n \n /*\n  * Directories have different lock order w.r.t. mmap_lock compared to regular\n@@ -579,6 +580,18 @@ xfs_report_dioalign(\n \tstruct block_device\t*bdev = target-\u003ebt_bdev;\n \n \tstat-\u003eresult_mask |= STATX_DIOALIGN | STATX_DIO_READ_ALIGN;\n+\n+\t/*\n+\t * The STATX_DIOALIGN | STATX_DIO_READ_ALIGN flags are used to\n+\t * explicitly report if DIO is supported or not. They can not indicate\n+\t * that fallback to the buffered IO is used for fsverity.\n+\t *\n+\t * Return zero alignment values which also mean that DIO is not\n+\t * supported on this file, see statx(2).\n+\t */\n+\tif (fsverity_active(VFS_I(ip)))\n+\t\treturn;\n+\n \tstat-\u003edio_mem_align = bdev_dma_alignment(bdev) + 1;\n \n \t/*\n@@ -1387,6 +1400,8 @@ xfs_inode_should_enable_dax(\n \t\treturn false;\n \tif (!xfs_inode_supports_dax(ip))\n \t\treturn false;\n+\tif (ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_VERITY)\n+\t\treturn false;\n \tif (xfs_has_dax_always(ip-\u003ei_mount))\n \t\treturn true;\n \tif (ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_DAX)\n@@ -1415,12 +1430,15 @@ xfs_diflags_to_iflags(\n \t\tflags |= S_NOATIME;\n \tif (init \u0026\u0026 xfs_inode_should_enable_dax(ip))\n \t\tflags |= S_DAX;\n+\tif (xflags \u0026 FS_XFLAG_VERITY)\n+\t\tflags |= S_VERITY;\n \n \t/*\n \t * S_DAX can only be set during inode initialization and is never set by\n \t * the VFS, so we cannot mask off S_DAX in i_flags.\n \t */\n-\tinode-\u003ei_flags \u0026= ~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME);\n+\tinode-\u003ei_flags \u0026=\n+\t\t~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME | S_VERITY);\n \tinode-\u003ei_flags |= flags;\n }\n \ndiff --git a/fs/xfs/xfs_message.c b/fs/xfs/xfs_message.c\nindex 0243e509a46891..44b13d46049c62 100644\n--- a/fs/xfs/xfs_message.c\n+++ b/fs/xfs/xfs_message.c\n@@ -149,6 +149,10 @@ xfs_warn_experimental(\n \t\t\t.opstate\t= XFS_OPSTATE_WARNED_LARP,\n \t\t\t.name\t\t= \"logged extended attributes\",\n \t\t},\n+\t\t[XFS_EXPERIMENTAL_FSVERITY] = {\n+\t\t\t.opstate\t= XFS_OPSTATE_WARNED_FSVERITY,\n+\t\t\t.name\t\t= \"fsverity\",\n+\t\t},\n \t};\n \tASSERT(feat \u003e= 0 \u0026\u0026 feat \u003c XFS_EXPERIMENTAL_MAX);\n \tBUILD_BUG_ON(ARRAY_SIZE(features) != XFS_EXPERIMENTAL_MAX);\ndiff --git a/fs/xfs/xfs_message.h b/fs/xfs/xfs_message.h\nindex 811b885f41c35a..364fcc7e42b084 100644\n--- a/fs/xfs/xfs_message.h\n+++ b/fs/xfs/xfs_message.h\n@@ -93,6 +93,7 @@ void xfs_buf_alert_ratelimited(struct xfs_buf *bp, const char *rlmsg,\n enum xfs_experimental_feat {\n \tXFS_EXPERIMENTAL_SHRINK,\n \tXFS_EXPERIMENTAL_LARP,\n+\tXFS_EXPERIMENTAL_FSVERITY,\n \n \tXFS_EXPERIMENTAL_MAX,\n };\ndiff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h\nindex cbcfb89c67a440..0b64636635996f 100644\n--- a/fs/xfs/xfs_mount.h\n+++ b/fs/xfs/xfs_mount.h\n@@ -403,6 +403,7 @@ typedef struct xfs_mount {\n #define XFS_FEAT_EXCHANGE_RANGE\t(1ULL \u003c\u003c 27)\t/* exchange range */\n #define XFS_FEAT_METADIR\t(1ULL \u003c\u003c 28)\t/* metadata directory tree */\n #define XFS_FEAT_ZONED\t\t(1ULL \u003c\u003c 29)\t/* zoned RT device */\n+#define XFS_FEAT_VERITY\t\t(1ULL \u003c\u003c 30)\t/* fs-verity */\n \n /* Mount features */\n #define XFS_FEAT_NOLIFETIME\t(1ULL \u003c\u003c 47)\t/* disable lifetime hints */\n@@ -460,6 +461,7 @@ __XFS_HAS_FEAT(exchange_range, EXCHANGE_RANGE)\n __XFS_HAS_FEAT(metadir, METADIR)\n __XFS_HAS_FEAT(zoned, ZONED)\n __XFS_HAS_FEAT(nolifetime, NOLIFETIME)\n+__XFS_HAS_FEAT(verity, VERITY)\n \n static inline bool xfs_has_rtgroups(const struct xfs_mount *mp)\n {\n@@ -597,6 +599,8 @@ __XFS_HAS_FEAT(nouuid, NOUUID)\n #define XFS_OPSTATE_RESUMING_QUOTAON\t18\n /* (Zoned) GC is in progress */\n #define XFS_OPSTATE_ZONEGC_RUNNING\t20\n+/* Kernel has logged a warning about fsverity support */\n+#define XFS_OPSTATE_WARNED_FSVERITY\t21\n \n #define __XFS_IS_OPSTATE(name, NAME) \\\n static inline bool xfs_is_ ## name (struct xfs_mount *mp) \\\ndiff --git a/fs/xfs/xfs_pnfs.c b/fs/xfs/xfs_pnfs.c\nindex 065875c8b7dab8..ff097400d064fd 100644\n--- a/fs/xfs/xfs_pnfs.c\n+++ b/fs/xfs/xfs_pnfs.c\n@@ -256,7 +256,7 @@ xfs_fs_map_blocks(\n \t}\n \txfs_iunlock(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);\n \n-\terror = xfs_bmbt_to_iomap(ip, iomap, \u0026imap, 0, 0, seq);\n+\terror = xfs_bmbt_to_iomap(ip, iomap, \u0026imap, offset, 0, 0, seq);\n \t*device_generation = mp-\u003em_generation;\n \treturn error;\n out_unlock:\ndiff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c\nindex 5a06132aa38466..890fa5727d56e6 100644\n--- a/fs/xfs/xfs_super.c\n+++ b/fs/xfs/xfs_super.c\n@@ -30,6 +30,7 @@\n #include \"xfs_filestream.h\"\n #include \"xfs_quota.h\"\n #include \"xfs_sysfs.h\"\n+#include \"xfs_fsverity.h\"\n #include \"xfs_ondisk.h\"\n #include \"xfs_rmap_item.h\"\n #include \"xfs_refcount_item.h\"\n@@ -50,6 +51,7 @@\n #include \"xfs_rtalloc.h\"\n #include \"xfs_zone_alloc.h\"\n #include \"xfs_healthmon.h\"\n+#include \"xfs_fsverity.h\"\n #include \"scrub/stats.h\"\n #include \"scrub/rcbag_btree.h\"\n \n@@ -1736,6 +1738,9 @@ xfs_fs_fill_super(\n \tsb-\u003es_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;\n #endif\n \tsb-\u003es_op = \u0026xfs_super_operations;\n+#ifdef CONFIG_FS_VERITY\n+\tsb-\u003es_vop = \u0026xfs_fsverity_ops;\n+#endif\n \n \t/*\n \t * Delay mount work if the debug hook is set. This is debug\n@@ -1988,6 +1993,9 @@ xfs_fs_fill_super(\n \tif (error)\n \t\tgoto out_filestream_unmount;\n \n+\tif (xfs_has_verity(mp))\n+\t\txfs_warn_experimental(mp, XFS_EXPERIMENTAL_FSVERITY);\n+\n \troot = igrab(VFS_I(mp-\u003em_rootip));\n \tif (!root) {\n \t\terror = -ENOENT;\n@@ -2516,8 +2524,20 @@ xfs_init_caches(void)\n \tif (!xfs_parent_args_cache)\n \t\tgoto out_destroy_xmi_cache;\n \n+#ifdef CONFIG_FS_VERITY\n+\txfs_fsverity_ioend_cache = kmem_cache_create(\"xfs_fsverity_ioend\",\n+\t\t\t\t\t     sizeof(struct xfs_fsverity_ioend),\n+\t\t\t\t\t     0, 0, NULL);\n+\tif (!xfs_fsverity_ioend_cache)\n+\t\tgoto out_destroy_parent_args_cache;\n+#endif\n+\n \treturn 0;\n \n+#ifdef CONFIG_FS_VERITY\n+ out_destroy_parent_args_cache:\n+\tkmem_cache_destroy(xfs_parent_args_cache);\n+#endif\n  out_destroy_xmi_cache:\n \tkmem_cache_destroy(xfs_xmi_cache);\n  out_destroy_xmd_cache:\n@@ -2580,6 +2600,9 @@ xfs_destroy_caches(void)\n \t * destroy caches.\n \t */\n \trcu_barrier();\n+#ifdef CONFIG_FS_VERITY\n+\tkmem_cache_destroy(xfs_fsverity_ioend_cache);\n+#endif\n \tkmem_cache_destroy(xfs_parent_args_cache);\n \tkmem_cache_destroy(xfs_xmd_cache);\n \tkmem_cache_destroy(xfs_xmi_cache);\n@@ -2660,10 +2683,14 @@ init_xfs_fs(void)\n \tif (error)\n \t\tgoto out;\n \n-\terror = xfs_init_workqueues();\n+\terror = xfs_fsverity_init();\n \tif (error)\n \t\tgoto out_destroy_caches;\n \n+\terror = xfs_init_workqueues();\n+\tif (error)\n+\t\tgoto out_fsverity_exit;\n+\n \terror = xfs_mru_cache_init();\n \tif (error)\n \t\tgoto out_destroy_wq;\n@@ -2740,6 +2767,8 @@ init_xfs_fs(void)\n \txfs_mru_cache_uninit();\n  out_destroy_wq:\n \txfs_destroy_workqueues();\n+ out_fsverity_exit:\n+\txfs_fsverity_exit();\n  out_destroy_caches:\n \txfs_destroy_caches();\n  out:\n@@ -2763,6 +2792,7 @@ exit_xfs_fs(void)\n \txfs_cleanup_procfs();\n \txfs_mru_cache_uninit();\n \txfs_destroy_workqueues();\n+\txfs_fsverity_exit();\n \txfs_destroy_caches();\n \txfs_uuid_table_free();\n }\n"
}

2/1 2026/11/25 16:34 agent patch-evaluator
24m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "XFS_FS",
    "FS_VERITY",
    "XFS_ONLINE_SCRUB",
    "XFS_ONLINE_REPAIR"
  ],
  "FocusSymbols": [
    "xfs_fsverity_begin_enable",
    "xfs_fsverity_end_enable",
    "xfs_fsverity_get_descriptor",
    "xfs_fsverity_read_merkle",
    "xfs_fsverity_write_merkle",
    "xfs_fsverity_metadata_offset",
    "xfs_fsverity_is_file_data",
    "xfs_end_fsverity_io_read",
    "xchk_inode_setup_verity",
    "xchk_inode_verity_broken",
    "xrep_inode_verity",
    "xfs_dinode_verify"
  ],
  "Reasoning": "The patch adds fs-verity support to XFS, enabling file sealing and Merkle tree storage/verification beyond EOF. It adds new fsverity operations, read completion handling, unmapping changes in __xfs_bunmapi, and online scrub/repair checks for verity inodes. This code is fully reachable via ioctls (such as FS_IOC_ENABLE_VERITY) and normal file operations in virtualized environments.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 74ac4fac1d6d7863985e11a962c39f9386871361
Author: syz-cluster <triage@syzkaller.com>
Date:   Wed Nov 25 16:34:45 2026 +0000

    syz-cluster: applied patch under review

diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index 399a207f2d0e71..9edb2850f09413 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -59,6 +59,7 @@ xfs-y				+= $(addprefix libxfs/, \
 				   xfs_trans_resv.o \
 				   xfs_trans_space.o \
 				   xfs_types.o \
+				   xfs_verity.o \
 				   )
 # xfs_rtbitmap is shared with libxfs
 xfs-$(CONFIG_XFS_RT)		+= $(addprefix libxfs/, \
@@ -150,6 +151,7 @@ xfs-$(CONFIG_XFS_POSIX_ACL)	+= xfs_acl.o
 xfs-$(CONFIG_SYSCTL)		+= xfs_sysctl.o
 xfs-$(CONFIG_COMPAT)		+= xfs_ioctl32.o
 xfs-$(CONFIG_EXPORTFS_BLOCK_OPS)	+= xfs_pnfs.o
+xfs-$(CONFIG_FS_VERITY)		+= xfs_fsverity.o
 
 # notify failure
 ifeq ($(CONFIG_MEMORY_FAILURE),y)
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 050522c58b168f..667b693aacb810 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -4414,7 +4414,7 @@ xfs_bmapi_convert_one_delalloc(
 	 * the extent.  Just return the real extent at this offset.
 	 */
 	if (!isnullstartblock(bma.got.br_startblock)) {
-		xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags,
+		xfs_bmbt_to_iomap(ip, iomap, &bma.got, offset, 0, flags,
 				xfs_iomap_inode_sequence(ip, flags));
 		if (seq)
 			*seq = READ_ONCE(ifp->if_seq);
@@ -4462,7 +4462,7 @@ xfs_bmapi_convert_one_delalloc(
 	XFS_STATS_INC(mp, xs_xstrat_quick);
 
 	ASSERT(!isnullstartblock(bma.got.br_startblock));
-	xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags,
+	xfs_bmbt_to_iomap(ip, iomap, &bma.got, offset, 0, flags,
 				xfs_iomap_inode_sequence(ip, flags));
 	if (seq)
 		*seq = READ_ONCE(ifp->if_seq);
@@ -5220,6 +5220,22 @@ __xfs_bunmapi(
 	ASSERT(len > 0);
 	ASSERT(nexts >= 0);
 
+	/*
+	 * XFS_BMAPI_UNWRITTEN is only used by fs-verity to drop unwritten
+	 * blocks past EOF while keeping written ones (fsverity metadata).
+	 *
+	 * The XFS_BMAPI_UNWRITTEN could not be used with realtime inodes with
+	 * realtime extent larger than 1 filesystem block. This is because the
+	 * realtime inode with larger extents could have EOF in the middle of
+	 * the extent. Removing these unwritten extent beyond EOF could lead to
+	 * removal of data before EOF.
+	 *
+	 * fs-verity is not allowed to be enabled on realtime files whose
+	 * extent size is larger than 1.
+	 */
+	ASSERT(!((flags & XFS_BMAPI_UNWRITTEN) &&
+		 xfs_inode_has_bigrtalloc(ip)));
+
 	error = xfs_iread_extents(tp, ip, whichfork);
 	if (error)
 		return error;
@@ -5281,6 +5297,10 @@ __xfs_bunmapi(
 		if (del.br_startoff + del.br_blockcount > end + 1)
 			del.br_blockcount = end + 1 - del.br_startoff;
 
+		if ((flags & XFS_BMAPI_UNWRITTEN) &&
+		    del.br_state != XFS_EXT_UNWRITTEN)
+			goto skip;
+
 		if (!isrt || (flags & XFS_BMAPI_REMAP))
 			goto delete;
 
@@ -5415,7 +5435,7 @@ __xfs_bunmapi(
 			if (error)
 				goto error0;
 		}
-
+skip:
 		end = del.br_startoff - 1;
 nodelete:
 		/*
diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h
index fb7481e8190c64..f1df6b4b695e0b 100644
--- a/fs/xfs/libxfs/xfs_bmap.h
+++ b/fs/xfs/libxfs/xfs_bmap.h
@@ -97,6 +97,9 @@ struct xfs_bmalloca {
  */
 #define XFS_BMAPI_CONVERT_ONLY	(1u << 12)
 
+/* Process unwritten extents only. Used for unmapping */
+#define XFS_BMAPI_UNWRITTEN	(1u << 13)
+
 #define XFS_BMAPI_FLAGS \
 	{ XFS_BMAPI_ENTIRE,	"ENTIRE" }, \
 	{ XFS_BMAPI_METADATA,	"METADATA" }, \
@@ -110,7 +113,8 @@ struct xfs_bmalloca {
 	{ XFS_BMAPI_NODISCARD,	"NODISCARD" }, \
 	{ XFS_BMAPI_NORMAP,	"NORMAP" },\
 	{ XFS_BMAPI_EXTSZALIGN,	"EXTSZALIGN" }, \
-	{ XFS_BMAPI_CONVERT_ONLY,	"CONVERT_ONLY" }
+	{ XFS_BMAPI_CONVERT_ONLY,	"CONVERT_ONLY" }, \
+	{ XFS_BMAPI_UNWRITTEN,	"UNWRITTEN" }
 
 
 static inline int xfs_bmapi_aflag(int w)
diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 469e879149ac21..16d6e8931df069 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -374,11 +374,13 @@ xfs_sb_has_compat_feature(
 #define XFS_SB_FEAT_RO_COMPAT_RMAPBT   (1 << 1)		/* reverse map btree */
 #define XFS_SB_FEAT_RO_COMPAT_REFLINK  (1 << 2)		/* reflinked files */
 #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)		/* inobt block counts */
+#define XFS_SB_FEAT_RO_COMPAT_VERITY   (1 << 4)		/* fs-verity */
 #define XFS_SB_FEAT_RO_COMPAT_ALL \
 		(XFS_SB_FEAT_RO_COMPAT_FINOBT | \
 		 XFS_SB_FEAT_RO_COMPAT_RMAPBT | \
-		 XFS_SB_FEAT_RO_COMPAT_REFLINK| \
-		 XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
+		 XFS_SB_FEAT_RO_COMPAT_REFLINK | \
+		 XFS_SB_FEAT_RO_COMPAT_INOBTCNT | \
+		 XFS_SB_FEAT_RO_COMPAT_VERITY)
 #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN	~XFS_SB_FEAT_RO_COMPAT_ALL
 static inline bool
 xfs_sb_has_ro_compat_feature(
@@ -1234,16 +1236,21 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
  */
 #define XFS_DIFLAG2_METADATA_BIT	5
 
+/* inodes sealed with fs-verity */
+#define XFS_DIFLAG2_VERITY_BIT		6
+
 #define XFS_DIFLAG2_DAX		(1ULL << XFS_DIFLAG2_DAX_BIT)
 #define XFS_DIFLAG2_REFLINK	(1ULL << XFS_DIFLAG2_REFLINK_BIT)
 #define XFS_DIFLAG2_COWEXTSIZE	(1ULL << XFS_DIFLAG2_COWEXTSIZE_BIT)
 #define XFS_DIFLAG2_BIGTIME	(1ULL << XFS_DIFLAG2_BIGTIME_BIT)
 #define XFS_DIFLAG2_NREXT64	(1ULL << XFS_DIFLAG2_NREXT64_BIT)
 #define XFS_DIFLAG2_METADATA	(1ULL << XFS_DIFLAG2_METADATA_BIT)
+#define XFS_DIFLAG2_VERITY	(1ULL << XFS_DIFLAG2_VERITY_BIT)
 
 #define XFS_DIFLAG2_ANY \
 	(XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \
-	 XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA)
+	 XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA | \
+	 XFS_DIFLAG2_VERITY)
 
 static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)
 {
@@ -2031,4 +2038,22 @@ struct xfs_acl {
 #define SGI_ACL_FILE_SIZE	(sizeof(SGI_ACL_FILE)-1)
 #define SGI_ACL_DEFAULT_SIZE	(sizeof(SGI_ACL_DEFAULT)-1)
 
+/*
+ * fs-verity stores the Merkle tree in the data fork past EOF, so the file data
+ * blocks and the tree blocks share the inode's xfs_fileoff_t address space.
+ * Cap a verity file at half of the addressable file-offset range (in filesystem
+ * blocks) so the Merkle tree always fits in the other half.
+ */
+#define XFS_FSVERITY_LARGEST_FILE_FSB(mp) \
+	(XFS_B_TO_FSBT((mp), MAX_LFS_FILESIZE) >> 1)
+
+/*
+ * Alignment of the fsverity metadata placement. This is largest supported PAGE
+ * SIZE for fsverity. This is used to space out data and metadata in page cache.
+ * The spacing is necessary for non-exposure of metadata to userspace and
+ * correct merkle tree synthesis in the iomap.
+ */
+#define XFS_FSVERITY_START_ALIGN	(65536)
+
+
 #endif /* __XFS_FORMAT_H__ */
diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h
index 185f09f327c00c..84d62b7506a9ad 100644
--- a/fs/xfs/libxfs/xfs_fs.h
+++ b/fs/xfs/libxfs/xfs_fs.h
@@ -250,6 +250,7 @@ typedef struct xfs_fsop_resblks {
 #define XFS_FSOP_GEOM_FLAGS_PARENT	(1 << 25) /* linux parent pointers */
 #define XFS_FSOP_GEOM_FLAGS_METADIR	(1 << 26) /* metadata directories */
 #define XFS_FSOP_GEOM_FLAGS_ZONED	(1 << 27) /* zoned rt device */
+#define XFS_FSOP_GEOM_FLAGS_VERITY	(1 << 28) /* fs-verity */
 
 /*
  * Minimum and maximum sizes need for growth checks.
@@ -421,6 +422,7 @@ struct xfs_bulkstat {
 #define XFS_BS_SICK_SYMLINK	(1 << 6)  /* symbolic link remote target */
 #define XFS_BS_SICK_PARENT	(1 << 7)  /* parent pointers */
 #define XFS_BS_SICK_DIRTREE	(1 << 8)  /* directory tree structure */
+#define XFS_BS_SICK_FSVERITY	(1 << 9)  /* fsverity metadata */
 
 /*
  * Project quota id helpers (previously projid was 16bit only
diff --git a/fs/xfs/libxfs/xfs_health.h b/fs/xfs/libxfs/xfs_health.h
index 1d45cf5789e864..932b447190da76 100644
--- a/fs/xfs/libxfs/xfs_health.h
+++ b/fs/xfs/libxfs/xfs_health.h
@@ -104,6 +104,7 @@ struct xfs_rtgroup;
 /* Don't propagate sick status to ag health summary during inactivation */
 #define XFS_SICK_INO_FORGET	(1 << 12)
 #define XFS_SICK_INO_DIRTREE	(1 << 13)  /* directory tree structure */
+#define XFS_SICK_INO_FSVERITY	(1 << 14)  /* fsverity metadata */
 
 /* Primary evidence of health problems in a given group. */
 #define XFS_SICK_FS_PRIMARY	(XFS_SICK_FS_COUNTERS | \
@@ -140,7 +141,8 @@ struct xfs_rtgroup;
 				 XFS_SICK_INO_XATTR | \
 				 XFS_SICK_INO_SYMLINK | \
 				 XFS_SICK_INO_PARENT | \
-				 XFS_SICK_INO_DIRTREE)
+				 XFS_SICK_INO_DIRTREE | \
+				 XFS_SICK_INO_FSVERITY)
 
 #define XFS_SICK_INO_ZAPPED	(XFS_SICK_INO_BMBTD_ZAPPED | \
 				 XFS_SICK_INO_BMBTA_ZAPPED | \
diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c
index 8c9d296ebfe97f..fdcfc1f3f472b5 100644
--- a/fs/xfs/libxfs/xfs_inode_buf.c
+++ b/fs/xfs/libxfs/xfs_inode_buf.c
@@ -758,6 +758,25 @@ xfs_dinode_verify(
 	    !xfs_has_rtreflink(mp))
 		return __this_address;
 
+	/* only regular files can have fsverity */
+	if (flags2 & XFS_DIFLAG2_VERITY) {
+		if (!xfs_has_verity(mp))
+			return __this_address;
+		if (!S_ISREG(mode))
+			return __this_address;
+		/*
+		 * fs-verity stores the Merkle tree past EOF, so it cannot
+		 * coexist with a realtime allocation unit larger than a single
+		 * filesystem block. This is because we remove any unwritten
+		 * extents beyond EOF for fs-verity inodes. The realtime inode
+		 * with larger extents could have EOF in the middle of the
+		 * extent. Enabling fsverity on such inode could lead to removal
+		 * of data before EOF.
+		 */
+		if ((flags & XFS_DIFLAG_REALTIME) && mp->m_sb.sb_rextsize > 1)
+			return __this_address;
+	}
+
 	if (xfs_has_zoned(mp) &&
 	    dip->di_metatype == cpu_to_be16(XFS_METAFILE_RTRMAP)) {
 		if (be32_to_cpu(dip->di_used_blocks) > mp->m_sb.sb_rgextents)
diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c
index f486b23a9b5230..a717b19558afab 100644
--- a/fs/xfs/libxfs/xfs_inode_util.c
+++ b/fs/xfs/libxfs/xfs_inode_util.c
@@ -73,7 +73,8 @@ xfs_flags2diflags2(
 	uint64_t		di_flags2 =
 		(ip->i_diflags2 & (XFS_DIFLAG2_REFLINK |
 				   XFS_DIFLAG2_BIGTIME |
-				   XFS_DIFLAG2_NREXT64));
+				   XFS_DIFLAG2_NREXT64 |
+				   XFS_DIFLAG2_VERITY));
 
 	if (xflags & FS_XFLAG_DAX)
 		di_flags2 |= XFS_DIFLAG2_DAX;
@@ -125,6 +126,8 @@ xfs_ip2xflags(
 			flags |= FS_XFLAG_DAX;
 		if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE)
 			flags |= FS_XFLAG_COWEXTSIZE;
+		if (ip->i_diflags2 & XFS_DIFLAG2_VERITY)
+			flags |= FS_XFLAG_VERITY;
 	}
 
 	if (xfs_inode_has_attr_fork(ip))
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index ce44123c98cef6..3323b8dcc7939b 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -164,6 +164,8 @@ xfs_sb_version_to_features(
 		features |= XFS_FEAT_REFLINK;
 	if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
 		features |= XFS_FEAT_INOBTCNT;
+	if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_VERITY)
+		features |= XFS_FEAT_VERITY;
 	if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_FTYPE)
 		features |= XFS_FEAT_FTYPE;
 	if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_SPINODES)
@@ -1544,6 +1546,8 @@ xfs_fs_geometry(
 		geo->flags |= XFS_FSOP_GEOM_FLAGS_METADIR;
 	if (xfs_has_zoned(mp))
 		geo->flags |= XFS_FSOP_GEOM_FLAGS_ZONED;
+	if (xfs_has_verity(mp))
+		geo->flags |= XFS_FSOP_GEOM_FLAGS_VERITY;
 	geo->rtsectsize = sbp->sb_blocksize;
 	geo->dirblocksize = xfs_dir2_dirblock_bytes(sbp);
 
diff --git a/fs/xfs/libxfs/xfs_verity.c b/fs/xfs/libxfs/xfs_verity.c
new file mode 100644
index 00000000000000..c1731b89a5a12c
--- /dev/null
+++ b/fs/xfs/libxfs/xfs_verity.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#include "xfs_platform.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_log_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_inode.h"
+#include "xfs_verity.h"
+
+loff_t
+xfs_fsverity_metadata_offset(
+	const struct xfs_inode	*ip)
+{
+	return round_up(i_size_read(VFS_IC(ip)), XFS_FSVERITY_START_ALIGN);
+}
diff --git a/fs/xfs/libxfs/xfs_verity.h b/fs/xfs/libxfs/xfs_verity.h
new file mode 100644
index 00000000000000..da90f798faa8d6
--- /dev/null
+++ b/fs/xfs/libxfs/xfs_verity.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#ifndef __XFS_VERITY_H__
+#define __XFS_VERITY_H__
+
+#include "xfs_platform.h"
+#include <linux/fsverity.h>
+
+loff_t xfs_fsverity_metadata_offset(const struct xfs_inode *ip);
+
+#endif	/* __XFS_VERITY_H__ */
diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c
index cbfe5e6f779dfc..fb0ae227df54a8 100644
--- a/fs/xfs/scrub/common.c
+++ b/fs/xfs/scrub/common.c
@@ -45,6 +45,8 @@
 #include "scrub/health.h"
 #include "scrub/tempfile.h"
 
+#include <linux/fsverity.h>
+
 /* Common code for the metadata scrubbers. */
 
 /*
@@ -1765,3 +1767,54 @@ xchk_inode_count_blocks(
 	return xfs_bmap_count_blocks(sc->tp, sc->ip, whichfork, nextents,
 			count);
 }
+
+/*
+ * If this inode has S_VERITY set on it, read the verity info. If the reading
+ * fails with anything other than ENOMEM, the file is corrupt, which we can
+ * detect later with fsverity_active.
+ *
+ * Callers must hold the IOLOCK and must not hold the ILOCK of sc->ip because
+ * activation reads inode data.
+ */
+int
+xchk_inode_setup_verity(
+	struct xfs_scrub	*sc)
+{
+	int			error;
+
+	if (!fsverity_active(VFS_I(sc->ip)))
+		return 0;
+
+	error = fsverity_ensure_verity_info(VFS_I(sc->ip));
+	switch (error) {
+	case 0:
+		/* fsverity is active */
+		break;
+	case -ENODATA:
+	case -EMSGSIZE:
+	case -EFSCORRUPTED:
+	case -ERANGE:
+	case -EBADMSG:
+		/*
+		 * The nonzero errno codes above are the error codes that can
+		 * be returned from fsverity on metadata validation errors.
+		 */
+		return 0;
+	default:
+		/* runtime errors */
+		return error;
+	}
+
+	return 0;
+}
+
+/*
+ * Is this a verity file that failed to activate?  Callers must have tried to
+ * activate fsverity via xchk_inode_setup_verity.
+ */
+bool
+xchk_inode_verity_broken(
+	struct xfs_inode	*ip)
+{
+	return fsverity_active(VFS_I(ip)) && !fsverity_get_info(VFS_I(ip));
+}
diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h
index 181028f0c65526..b59d4792a80507 100644
--- a/fs/xfs/scrub/common.h
+++ b/fs/xfs/scrub/common.h
@@ -261,6 +261,8 @@ int xchk_inode_is_allocated(struct xfs_scrub *sc, xfs_agino_t agino,
 		bool *inuse);
 int xchk_inode_count_blocks(struct xfs_scrub *sc, int whichfork,
 		xfs_extnum_t *nextents, xfs_filblks_t *count);
+int xchk_inode_setup_verity(struct xfs_scrub *sc);
+bool xchk_inode_verity_broken(struct xfs_inode *ip);
 
 bool xchk_inode_is_dirtree_root(const struct xfs_inode *ip);
 bool xchk_inode_is_sb_rooted(const struct xfs_inode *ip);
diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c
index bb8d2bc008e019..931c677d7ac8d4 100644
--- a/fs/xfs/scrub/inode.c
+++ b/fs/xfs/scrub/inode.c
@@ -33,9 +33,28 @@ xchk_prepare_iscrub(
 	struct xfs_scrub	*sc)
 {
 	int			error;
+	struct xfs_inode	*ip = sc->ip;
 
 	xchk_ilock(sc, XFS_IOLOCK_EXCL);
 
+	error = xchk_inode_setup_verity(sc);
+	if (error)
+		return error;
+
+	/*
+	 * If we're going to repair a file whose fsverity descriptor cannot be
+	 * activated, drop the stale Merkle tree folios. Once the
+	 * post-EOF Merkle extents are freed during repair, those uptodate
+	 * folios would otherwise sit over a hole and could be exposed as file
+	 * data by a later extending write or truncate.
+	 *
+	 * The lock would be unlocked by global scrub machinery.
+	 */
+	if (xchk_could_repair(sc) && xchk_inode_verity_broken(ip)) {
+		xchk_ilock(sc, XFS_MMAPLOCK_EXCL);
+		truncate_inode_pages(VFS_I(ip)->i_mapping, XFS_ISIZE(ip));
+	}
+
 	error = xchk_trans_alloc(sc, 0);
 	if (error)
 		return error;
@@ -833,6 +852,9 @@ xchk_inode(
 	if (S_ISREG(VFS_I(sc->ip)->i_mode))
 		xchk_inode_check_reflink_iflag(sc, I_INO(sc->ip));
 
+	if (xchk_inode_verity_broken(sc->ip))
+		xchk_ino_set_corrupt(sc, sc->sm->sm_ino);
+
 	xchk_inode_check_unlinked(sc);
 
 	xchk_inode_xref(sc, I_INO(sc->ip), &di);
diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c
index a9ccf763c05969..ddf3c3dce2f939 100644
--- a/fs/xfs/scrub/inode_repair.c
+++ b/fs/xfs/scrub/inode_repair.c
@@ -577,6 +577,8 @@ xrep_dinode_flags(
 		dip->di_nrext64_pad = 0;
 	else if (dip->di_version >= 3)
 		dip->di_v3_pad = 0;
+	if (!xfs_has_verity(mp) || !S_ISREG(mode))
+		flags2 &= ~XFS_DIFLAG2_VERITY;
 
 	if (flags2 & XFS_DIFLAG2_METADATA) {
 		xfs_failaddr_t	fa;
@@ -1659,6 +1661,10 @@ xrep_dinode_core(
 	if (iget_error)
 		return iget_error;
 
+	error = xchk_inode_setup_verity(sc);
+	if (error)
+		return error;
+
 	error = xchk_trans_alloc(sc, 0);
 	if (error)
 		return error;
@@ -2198,6 +2204,40 @@ xrep_inode_reset_dquots(
 # define xrep_inode_reset_dquots(sc)		(0)
 #endif
 
+/*
+ * If this file is a fsverity file, xchk_prepare_iscrub or xrep_dinode_core
+ * should have activated it.  If it's still not active, then there's something
+ * wrong with the verity descriptor, so turn verity off and free the orphaned
+ * Merkle tree that XFS keeps in extents beyond EOF.
+ */
+STATIC int
+xrep_inode_verity(
+	struct xfs_scrub	*sc)
+{
+	struct inode		*inode = VFS_I(sc->ip);
+	struct xfs_mount	*mp = sc->mp;
+	int			error;
+
+	if (!xchk_inode_verity_broken(sc->ip))
+		return 0;
+
+	/*
+	 * The fsverity descriptor cannot be activated, so disable verity and
+	 * free the Merkle tree, which XFS stores in beyond EOF. The stale
+	 * Merkle tree page cache was already dropped during scrub setup.
+	 */
+	error = xfs_bunmapi_range(&sc->tp, sc->ip, 0,
+			XFS_B_TO_FSB(mp, XFS_ISIZE(sc->ip)), XFS_MAX_FILEOFF);
+	if (error)
+		return error;
+
+	sc->ip->i_diflags2 &= ~XFS_DIFLAG2_VERITY;
+	inode_set_flags(inode, 0, S_VERITY);
+
+	xfs_trans_log_inode(sc->tp, sc->ip, XFS_ILOG_CORE);
+	return 0;
+}
+
 /* Repair an inode's fields. */
 int
 xrep_inode(
@@ -2247,6 +2287,15 @@ xrep_inode(
 			return error;
 	}
 
+	/*
+	 * Disable fsverity if it cannot be activated.  Activation failure
+	 * prohibits the file from being opened, so there cannot be another
+	 * program with an open fd to what it thinks is a verity file.
+	 */
+	error = xrep_inode_verity(sc);
+	if (error)
+		return error;
+
 	/* Reconnect incore unlinked list */
 	error = xrep_inode_unlinked(sc);
 	if (error)
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 1db6f3640c53bd..971be3c0973161 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -23,6 +23,8 @@
 #include "xfs_ioend.h"
 #include "xfs_zone_alloc.h"
 #include "xfs_rtgroup.h"
+#include "xfs_verity.h"
+#include "xfs_fsverity.h"
 
 struct xfs_writepage_ctx {
 	struct iomap_writepage_ctx ctx;
@@ -265,7 +267,8 @@ xfs_map_blocks(
 	    isnullstartblock(imap.br_startblock))
 		goto allocate_blocks;
 
-	xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, 0, 0, XFS_WPC(wpc)->data_seq);
+	xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, offset, 0, 0,
+			  XFS_WPC(wpc)->data_seq);
 	trace_xfs_map_blocks_found(ip, offset, count, whichfork, &imap);
 	return 0;
 allocate_blocks:
@@ -441,7 +444,7 @@ xfs_zoned_map_blocks(
 		imap.br_startblock = HOLESTARTBLOCK;
 		imap.br_state = XFS_EXT_NORM;
 		xfs_iunlock(ip, XFS_ILOCK_EXCL);
-		xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, 0, 0, 0);
+		xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, offset, 0, 0, 0);
 		return 0;
 	}
 	end_fsb = min(end_fsb, imap.br_startoff + imap.br_blockcount);
@@ -585,7 +588,7 @@ xfs_bio_submit_read(
 {
 	xfs_ioend_submit_read(iter->inode, ctx->read_ctx,
 			ctx->read_ctx_file_offset,
-			iomap_ioend_flags(&iter->iomap));
+			iomap_ioend_flags(&iter->iomap), ctx->vi);
 	ctx->read_ctx = NULL;
 }
 
@@ -597,11 +600,13 @@ static const struct iomap_read_ops xfs_iomap_read_ops = {
 
 static inline const struct iomap_read_ops *
 xfs_get_iomap_read_ops(
-	const struct address_space	*mapping)
+	const struct address_space	*mapping,
+	loff_t				pos)
 {
 	struct xfs_inode		*ip = XFS_I(mapping->host);
 
-	if (bdev_has_integrity_csum(xfs_inode_buftarg(ip)->bt_bdev))
+	if (bdev_has_integrity_csum(xfs_inode_buftarg(ip)->bt_bdev) ||
+	    xfs_fsverity_is_file_data(ip, pos))
 		return &xfs_iomap_read_ops;
 	return &iomap_bio_read_ops;
 }
@@ -613,7 +618,7 @@ xfs_vm_read_folio(
 {
 	struct iomap_read_folio_ctx	ctx = { .cur_folio = folio };
 
-	ctx.ops = xfs_get_iomap_read_ops(folio->mapping);
+	ctx.ops = xfs_get_iomap_read_ops(folio->mapping, folio_pos(folio));
 	iomap_read_folio(xfs_read_iomap_next, &ctx, NULL);
 	return 0;
 }
@@ -624,7 +629,7 @@ xfs_vm_readahead(
 {
 	struct iomap_read_folio_ctx	ctx = { .rac = rac };
 
-	ctx.ops = xfs_get_iomap_read_ops(rac->mapping),
+	ctx.ops = xfs_get_iomap_read_ops(rac->mapping, readahead_pos(rac));
 	iomap_readahead(xfs_read_iomap_next, &ctx, NULL);
 }
 
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 865aec3ae5ab32..d6130cfc8246d9 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -31,6 +31,7 @@
 #include "xfs_rtbitmap.h"
 #include "xfs_rtgroup.h"
 #include "xfs_zone_alloc.h"
+#include <linux/fsverity.h>
 
 /* Kernel only BMAP related definitions and functions */
 
@@ -553,6 +554,17 @@ xfs_can_free_eofblocks(
 	if (last_fsb <= end_fsb)
 		return false;
 
+	/*
+	 * Don't clean fsverity inodes as they already have been cleaned up and
+	 * are read-only. Skip inodes which have merkle tree being built, the
+	 * merkle tree is written beyond EOF. Skip inodes which have
+	 * XFS_DIFLAG2_VERITY in case this kernel has fsverity disabled.
+	 */
+	if (fsverity_active(VFS_IC(ip)) ||
+	    fsverity_is_building(VFS_I(ip)) ||
+	    ip->i_diflags2 & XFS_DIFLAG2_VERITY)
+		return false;
+
 	/*
 	 * Check if there is an post-EOF extent to free.  If there are any
 	 * delalloc blocks attached to the inode (data fork delalloc
@@ -579,6 +591,8 @@ xfs_free_eofblocks(
 	struct xfs_trans	*tp;
 	struct xfs_mount	*mp = ip->i_mount;
 	int			error;
+	int			bmapi_flags = XFS_BMAPI_NODISCARD;
+	bool			verity = fsverity_is_building(VFS_I(ip));
 
 	/* Attach the dquots to the inode up front. */
 	error = xfs_qm_dqattach(ip);
@@ -593,15 +607,20 @@ xfs_free_eofblocks(
 	 *
 	 * Note that this means we also leave speculative preallocations in
 	 * place for preallocated files.
+	 *
+	 * Clean up delalloc reservations for fsverity too as those won't be
+	 * used
 	 */
-	if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) {
+	if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND) ||
+			verity) {
 		if (ip->i_delayed_blks) {
 			xfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK,
 				round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize),
 				LLONG_MAX, NULL);
 		}
 		xfs_inode_clear_eofblocks_tag(ip);
-		return 0;
+		if (!verity)
+			return 0;
 	}
 
 	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
@@ -613,6 +632,13 @@ xfs_free_eofblocks(
 	xfs_ilock(ip, XFS_ILOCK_EXCL);
 	xfs_trans_ijoin(tp, ip, 0);
 
+	/*
+	 * While fs-verity writes metadata after EOF, it can leave unwritten
+	 * preallocations.  Clear all that out.
+	 */
+	if (verity)
+		bmapi_flags |= XFS_BMAPI_UNWRITTEN;
+
 	/*
 	 * Do not update the on-disk file size.  If we update the on-disk file
 	 * size and then the system crashes before the contents of the file are
@@ -620,7 +646,7 @@ xfs_free_eofblocks(
 	 * bug).
 	 */
 	error = xfs_itruncate_extents_flags(&tp, ip, XFS_DATA_FORK,
-				XFS_ISIZE(ip), XFS_BMAPI_NODISCARD);
+				XFS_ISIZE(ip), bmapi_flags);
 	if (error)
 		goto err_cancel;
 
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index d61ea8e2c8e40c..94835d6153420b 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -38,6 +38,7 @@
 #include <linux/mount.h>
 #include <linux/filelock.h>
 #include <linux/bio-integrity.h>
+#include <linux/fsverity.h>
 
 static const struct vm_operations_struct xfs_file_vm_ops;
 
@@ -181,7 +182,8 @@ xfs_dio_read_bounce_submit_io(
 	loff_t			file_offset)
 {
 	xfs_ioend_submit_read(iter->inode, bio, file_offset,
-			iomap_ioend_flags(&iter->iomap) | IOMAP_IOEND_DIRECT);
+			iomap_ioend_flags(&iter->iomap) | IOMAP_IOEND_DIRECT,
+			NULL);
 }
 
 static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {
@@ -189,6 +191,25 @@ static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {
 	.bio_set	= &iomap_ioend_bioset,
 };
 
+STATIC ssize_t
+xfs_file_buffered_read(
+	struct kiocb		*iocb,
+	struct iov_iter		*to)
+{
+	struct xfs_inode	*ip = XFS_I(file_inode(iocb->ki_filp));
+	ssize_t			ret;
+
+	trace_xfs_file_buffered_read(iocb, to);
+
+	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
+	if (ret)
+		return ret;
+	ret = generic_file_read_iter(iocb, to);
+	xfs_iunlock(ip, XFS_IOLOCK_SHARED);
+
+	return ret;
+}
+
 STATIC ssize_t
 xfs_file_dio_read(
 	struct kiocb		*iocb,
@@ -207,6 +228,17 @@ xfs_file_dio_read(
 	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
 	if (ret)
 		return ret;
+
+	/*
+	 * Re-check verity status after acquiring lock. This prevents TOCTOU in
+	 * xfs_file_read_iter() while falling back from DIO to buffered I/O as
+	 * now we are holding a lock
+	 */
+	if (fsverity_active(VFS_I(ip))) {
+		xfs_iunlock(ip, XFS_IOLOCK_SHARED);
+		iocb->ki_flags &= ~IOCB_DIRECT;
+		return xfs_file_buffered_read(iocb, to);
+	}
 	if (mapping_stable_writes(iocb->ki_filp->f_mapping)) {
 		ret = iomap_dio_rw(iocb, to, xfs_read_iomap_next,
 				&xfs_dio_read_bounce_ops, 0, NULL, 0);
@@ -226,7 +258,8 @@ xfs_file_dax_read(
 	struct kiocb		*iocb,
 	struct iov_iter		*to)
 {
-	struct xfs_inode	*ip = XFS_I(iocb->ki_filp->f_mapping->host);
+	struct inode		*inode = iocb->ki_filp->f_mapping->host;
+	struct xfs_inode	*ip = XFS_I(inode);
 	ssize_t			ret = 0;
 
 	trace_xfs_file_dax_read(iocb, to);
@@ -244,25 +277,6 @@ xfs_file_dax_read(
 	return ret;
 }
 
-STATIC ssize_t
-xfs_file_buffered_read(
-	struct kiocb		*iocb,
-	struct iov_iter		*to)
-{
-	struct xfs_inode	*ip = XFS_I(file_inode(iocb->ki_filp));
-	ssize_t			ret;
-
-	trace_xfs_file_buffered_read(iocb, to);
-
-	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
-	if (ret)
-		return ret;
-	ret = generic_file_read_iter(iocb, to);
-	xfs_iunlock(ip, XFS_IOLOCK_SHARED);
-
-	return ret;
-}
-
 STATIC ssize_t
 xfs_file_read_iter(
 	struct kiocb		*iocb,
@@ -277,6 +291,14 @@ xfs_file_read_iter(
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
+	/*
+	 * In case fs-verity is enabled, we also fallback to the buffered read
+	 * from the direct read path. Therefore, IOCB_DIRECT is set and need to
+	 * be cleared (see generic_file_read_iter())
+	 */
+	if (fsverity_active(inode))
+		iocb->ki_flags &= ~IOCB_DIRECT;
+
 	if (IS_DAX(inode))
 		ret = xfs_file_dax_read(iocb, to);
 	else if (iocb->ki_flags & IOCB_DIRECT)
@@ -1731,11 +1753,18 @@ xfs_file_open(
 	struct inode	*inode,
 	struct file	*file)
 {
+	int		error;
+
 	if (xfs_is_shutdown(XFS_M(inode->i_sb)))
 		return -EIO;
 	file->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT;
 	if (xfs_get_atomic_write_min(XFS_I(inode)) > 0)
 		file->f_mode |= FMODE_CAN_ATOMIC_WRITE;
+
+	error = fsverity_file_open(inode, file);
+	if (error)
+		return error;
+
 	return generic_file_open(inode, file);
 }
 
diff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c
new file mode 100644
index 00000000000000..36520a187a2c70
--- /dev/null
+++ b/fs/xfs/xfs_fsverity.c
@@ -0,0 +1,509 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#include "xfs_platform.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_inode.h"
+#include "xfs_log_format.h"
+#include "xfs_trans.h"
+#include "xfs_trace.h"
+#include "xfs_quota.h"
+#include "xfs_fsverity.h"
+#include "xfs_iomap.h"
+#include "xfs_error.h"
+#include "xfs_health.h"
+#include "xfs_bmap_util.h"
+#include "xfs_icache.h"
+#include <linux/fsverity.h>
+#include <linux/iomap.h>
+#include <linux/pagemap.h>
+
+struct kmem_cache *xfs_fsverity_ioend_cache;
+mempool_t xfs_fsverity_ioend_pool;
+
+#define XFS_FSVERITY_IOEND_POOL_MIN	128
+
+/*
+ * Back the fsverity ioend allocations with a mempool so that read I/O
+ * completion always makes forward progress and cannot deadlock
+ */
+int
+xfs_fsverity_init(void)
+{
+	return mempool_init_slab_pool(&xfs_fsverity_ioend_pool,
+			XFS_FSVERITY_IOEND_POOL_MIN, xfs_fsverity_ioend_cache);
+}
+
+void
+xfs_fsverity_exit(void)
+{
+	mempool_exit(&xfs_fsverity_ioend_pool);
+}
+
+bool
+xfs_fsverity_is_file_data(
+	const struct xfs_inode	*ip,
+	loff_t			offset)
+{
+	return fsverity_active(VFS_IC(ip)) &&
+			offset < xfs_fsverity_metadata_offset(ip);
+}
+
+/*
+ * Retrieve the verity descriptor.
+ */
+static int
+xfs_fsverity_get_descriptor(
+	struct inode		*inode,
+	void			*buf,
+	size_t			buf_size)
+{
+	struct xfs_inode	*ip = XFS_I(inode);
+	struct xfs_mount	*mp = ip->i_mount;
+	__be32			d_desc_size;
+	u32			desc_size;
+	u64			desc_size_pos;
+	int			error;
+	u64			desc_pos;
+	struct xfs_bmbt_irec	rec;
+	int			is_empty;
+	uint32_t		blocksize = i_blocksize(VFS_I(ip));
+	xfs_fileoff_t		last_block_offset;
+
+	/*
+	 * fs-verity cannot be used when the filesystem block size exceeds the
+	 * page size, as the Merkle tree folios are compound and PG_checked is
+	 * not supported on compound folios.  Reject such inodes so that they
+	 * cannot be opened and read as verity files.
+	 */
+	if (mp->m_sb.sb_blocksize > PAGE_SIZE)
+		return -EOPNOTSUPP;
+
+	xfs_ilock(ip, XFS_ILOCK_EXCL);
+	/*
+	 * Serialize reading of inode->i_flags with xfs_scrub clearing of this
+	 * flag if inode is corrupted.
+	 */
+	if (!(inode->i_flags & S_VERITY)) {
+		xfs_iunlock(ip, XFS_ILOCK_EXCL);
+		return -ENODATA;
+	}
+	error = xfs_bmap_last_extent(NULL, ip, XFS_DATA_FORK, &rec, &is_empty);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	if (error)
+		return error;
+
+	if (is_empty) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ENODATA;
+	}
+
+	/*
+	 * Make sure we can open large file on a 32-bit kernel
+	 */
+	if (rec.br_startoff + rec.br_blockcount >
+			XFS_B_TO_FSB(mp, inode->i_sb->s_maxbytes))
+		return -EFBIG;
+
+	last_block_offset =
+		XFS_FSB_TO_B(mp, rec.br_startoff + rec.br_blockcount);
+	if (last_block_offset <= xfs_fsverity_metadata_offset(ip)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ENODATA;
+	}
+
+	desc_size_pos = last_block_offset - sizeof(__be32);
+	error = fsverity_pagecache_read(inode, (char *)&d_desc_size,
+			sizeof(d_desc_size), desc_size_pos);
+	if (error)
+		return error;
+
+	desc_size = be32_to_cpu(d_desc_size);
+	if (XFS_IS_CORRUPT(mp, desc_size > FS_VERITY_MAX_DESCRIPTOR_SIZE)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	if (XFS_IS_CORRUPT(mp, desc_size > desc_size_pos)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	if (!buf_size)
+		return desc_size;
+
+	if (XFS_IS_CORRUPT(mp, desc_size > buf_size)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	desc_pos = round_down(desc_size_pos - desc_size, blocksize);
+	if (desc_pos < xfs_fsverity_metadata_offset(ip)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	error = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);
+	if (error)
+		return error;
+
+	return desc_size;
+}
+
+static int
+xfs_fsverity_write_descriptor(
+	struct file		*file,
+	const void		*desc,
+	u32			desc_size,
+	u64			merkle_tree_size)
+{
+	int			error;
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	unsigned int		blksize = ip->i_mount->m_sb.sb_blocksize;
+	u64			tree_last_block =
+			xfs_fsverity_metadata_offset(ip) + merkle_tree_size;
+	u64			desc_pos =
+			round_up(tree_last_block, XFS_FSVERITY_START_ALIGN);
+	u64			desc_end = desc_pos + desc_size;
+	__be32			desc_size_disk = cpu_to_be32(desc_size);
+	u64			desc_size_pos =
+			round_up(desc_end + sizeof(desc_size_disk), blksize) -
+			sizeof(desc_size_disk);
+
+	if (desc_size_pos + sizeof(desc_size_disk) > inode->i_sb->s_maxbytes)
+		return -EFBIG;
+
+	error = iomap_fsverity_write(file, desc_size_pos, sizeof(__be32),
+			(const void *)&desc_size_disk,
+			xfs_buffered_write_iomap_next,
+			&xfs_iomap_write_ops);
+	if (error)
+		return error;
+
+	return iomap_fsverity_write(file, desc_pos, desc_size, desc,
+			xfs_buffered_write_iomap_next,
+			&xfs_iomap_write_ops);
+}
+
+/*
+ * Try to remove all the fsverity metadata after a failed enablement.
+ */
+static int
+xfs_fsverity_delete_metadata(
+	struct xfs_inode	*ip)
+{
+	struct xfs_trans	*tp;
+	struct xfs_mount	*mp = ip->i_mount;
+	int			error;
+
+	xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
+	truncate_inode_pages(VFS_I(ip)->i_mapping, XFS_ISIZE(ip));
+
+	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
+	if (error) {
+		xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
+		return error;
+	}
+
+	xfs_ilock(ip, XFS_ILOCK_EXCL);
+	xfs_trans_ijoin(tp, ip, 0);
+
+	/*
+	 * We remove post EOF data, no need to update i_size as fsverity
+	 * didn't move i_size in the first place
+	 */
+	error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, XFS_ISIZE(ip));
+	if (error)
+		goto err_cancel;
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);
+	return error;
+err_cancel:
+	xfs_trans_cancel(tp);
+	xfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);
+	return error;
+}
+
+static int
+xfs_fsverity_reset_inode(
+	struct xfs_inode	*ip)
+{
+	int			error;
+	struct xfs_mount	*mp = ip->i_mount;
+	struct xfs_trans	*tp;
+
+	error = xfs_fsverity_delete_metadata(ip);
+	if (error)
+		return error;
+
+	/*
+	 * First, let's clean in-memory fsverity flag and then reset it on the
+	 * disk
+	 */
+	inode_set_flags(VFS_I(ip), 0, S_VERITY);
+
+	/*
+	 * Set fsverity inode flag
+	 */
+	error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_ichange,
+			0, 0, false, &tp);
+	if (error)
+		return error;
+
+	ip->i_diflags2 &= ~XFS_DIFLAG2_VERITY;
+
+	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	xfs_trans_set_sync(tp);
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	return error;
+}
+
+/*
+ * Prepare to enable fsverity by clearing old metadata.
+ */
+static int
+xfs_fsverity_begin_enable(
+	struct file		*filp)
+{
+	struct inode		*inode = file_inode(filp);
+	struct xfs_inode	*ip = XFS_I(inode);
+	int			error;
+
+	xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);
+
+	if (IS_DAX(inode) || ip->i_diflags2 & XFS_DIFLAG2_DAX)
+		return -EINVAL;
+
+	/*
+	 * fs-verity tracks verified Merkle tree pages using PG_checked, which
+	 * is only valid on single-page (non-compound) folios.  When the
+	 * filesystem block size is larger than the page size, the page cache
+	 * enforces a minimum folio order > 0, so all Merkle tree folios are
+	 * compound. fs-verity cannot be used on such filesystems.
+	 */
+	if (ip->i_mount->m_sb.sb_blocksize > PAGE_SIZE)
+		return -EOPNOTSUPP;
+
+	/*
+	 * fs-verity doesn't work on zoned
+	 */
+	if (xfs_is_zoned_inode(ip))
+		return -EOPNOTSUPP;
+
+	/*
+	 * fs-verity stores the Merkle tree past EOF in units of the filesystem
+	 * block size, so it cannot support realtime files whose allocation unit
+	 * (extent size) is larger than the block size.
+	 */
+	if (xfs_inode_has_bigrtalloc(ip))
+		return -EINVAL;
+
+	if (XFS_B_TO_FSB(ip->i_mount, inode->i_size) >
+			XFS_FSVERITY_LARGEST_FILE_FSB(ip->i_mount))
+		return -EFBIG;
+
+	/*
+	 * Flush pagecache before building Merkle tree. Inode is locked and no
+	 * further writes will happen to the file except fsverity metadata
+	 */
+	error = filemap_write_and_wait(inode->i_mapping);
+	if (error)
+		return error;
+
+	error = xfs_qm_dqattach(ip);
+	if (error)
+		return error;
+
+	return xfs_fsverity_delete_metadata(ip);
+}
+
+/*
+ * Complete (or fail) the process of enabling fsverity.
+ */
+static int
+xfs_fsverity_end_enable(
+	struct file		*file,
+	const void		*desc,
+	size_t			desc_size,
+	u64			merkle_tree_size)
+{
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	struct xfs_mount	*mp = ip->i_mount;
+	struct xfs_trans	*tp;
+	int			error = 0;
+	int			error2;
+	loff_t			range_start = xfs_fsverity_metadata_offset(ip);
+
+	xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);
+
+	/* fs-verity failed, just cleanup */
+	if (desc == NULL)
+		goto out;
+
+	error = xfs_fsverity_write_descriptor(file, desc, desc_size,
+			merkle_tree_size);
+	if (error)
+		goto out;
+
+	/*
+	 * Wait for Merkle tree get written to disk before setting on-disk inode
+	 * flag and clearing I_VERITY_BUILDING
+	 */
+	error = filemap_write_and_wait_range(inode->i_mapping, range_start,
+			LLONG_MAX);
+	if (error)
+		goto out;
+
+	/*
+	 * Proactively remove unwritten extents left by COW preallocations and
+	 * write preallocation in the merkle tree holes and past descriptor,
+	 * and any delayed preallocations
+	 */
+	error = xfs_free_eofblocks(ip);
+	if (error)
+		goto out;
+
+	/*
+	 * Set fsverity inode flag
+	 */
+	error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_ichange,
+			0, 0, false, &tp);
+	if (error)
+		goto out;
+
+	/*
+	 * Ensure that we've persisted the verity information before we enable
+	 * it on the inode and tell the caller we have sealed the inode.
+	 */
+	ip->i_diflags2 |= XFS_DIFLAG2_VERITY;
+
+	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	xfs_trans_set_sync(tp);
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	if (error)
+		goto out;
+
+	inode_set_flags(inode, S_VERITY, S_VERITY);
+	return error;
+
+out:
+	error2 = xfs_fsverity_reset_inode(ip);
+	if (error2)
+		xfs_alert(ip->i_mount,
+"ino 0x%llx failed to clean up new fsverity metadata, err %d",
+				I_INO(ip), error2);
+
+	return error;
+}
+
+/*
+ * Retrieve a merkle tree block.
+ */
+static struct page *
+xfs_fsverity_read_merkle(
+	struct inode		*inode,
+	pgoff_t			index)
+{
+	index += xfs_fsverity_metadata_offset(XFS_I(inode)) >> PAGE_SHIFT;
+
+	return generic_read_merkle_tree_page(inode, index);
+}
+
+/*
+ * Retrieve a merkle tree block.
+ */
+static void
+xfs_fsverity_readahead_merkle_tree(
+	struct inode		*inode,
+	pgoff_t			index,
+	unsigned long		nr_pages)
+{
+	index += xfs_fsverity_metadata_offset(XFS_I(inode)) >> PAGE_SHIFT;
+
+	generic_readahead_merkle_tree(inode, index, nr_pages);
+}
+
+static inline bool
+xfs_fsverity_is_hashes_of_zeroed_blocks(
+	struct xfs_inode	*ip,
+	const void		*buf,
+	unsigned int		size,
+	const u8		*zero_digest,
+	unsigned int		digest_size)
+{
+	/*
+	 * If this is a block full of hashes of zeroed blocks, don't bother
+	 * storing the block. We can synthesize them later.
+	 *
+	 * However, do this only in case Merkle tree block == fs block size.
+	 * Iomap synthesizes these blocks based on holes in the merkle tree. We
+	 * won't be able to tell if something need to be synthesizes for the
+	 * range in the fs block. For example, for 4k filesystem block
+	 *
+	 *	[ 1k | zero hashes | zero hashes | 1k ]
+	 *
+	 * Iomap won't know about these empty blocks.
+	 */
+	if (size != ip->i_mount->m_sb.sb_blocksize)
+		return false;
+	/*
+	 * First digest is zero_digest
+	 */
+	if (memcmp(buf, zero_digest, digest_size))
+		return false;
+	/*
+	 * Every digest is same as previous, thus all are
+	 * zero_digest
+	 */
+	return memcmp(buf + digest_size, buf, size - digest_size) == 0;
+}
+
+/*
+ * Write a merkle tree block.
+ */
+static int
+xfs_fsverity_write_merkle(
+	struct file		*file,
+	const void		*buf,
+	u64			pos,
+	unsigned int		size,
+	const u8		*zero_digest,
+	unsigned int		digest_size)
+{
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	loff_t			position = pos +
+		xfs_fsverity_metadata_offset(ip);
+
+	if (position + size > inode->i_sb->s_maxbytes)
+		return -EFBIG;
+
+	if (xfs_fsverity_is_hashes_of_zeroed_blocks(ip, buf, size, zero_digest,
+						    digest_size))
+		return 0;
+
+	return iomap_fsverity_write(file, position, size, buf,
+			xfs_buffered_write_iomap_next,
+			&xfs_iomap_write_ops);
+}
+
+const struct fsverity_operations xfs_fsverity_ops = {
+	.begin_enable_verity		= xfs_fsverity_begin_enable,
+	.end_enable_verity		= xfs_fsverity_end_enable,
+	.get_verity_descriptor		= xfs_fsverity_get_descriptor,
+	.read_merkle_tree_page		= xfs_fsverity_read_merkle,
+	.readahead_merkle_tree		= xfs_fsverity_readahead_merkle_tree,
+	.write_merkle_tree_block	= xfs_fsverity_write_merkle,
+};
diff --git a/fs/xfs/xfs_fsverity.h b/fs/xfs/xfs_fsverity.h
new file mode 100644
index 00000000000000..43f8ef62e12a1a
--- /dev/null
+++ b/fs/xfs/xfs_fsverity.h
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#ifndef __XFS_FSVERITY_H__
+#define __XFS_FSVERITY_H__
+
+#include "xfs_platform.h"
+#include "xfs_verity.h"
+#include <linux/iomap.h>
+#include <linux/fsverity.h>
+#include <linux/mempool.h>
+
+#ifdef CONFIG_FS_VERITY
+extern const struct fsverity_operations xfs_fsverity_ops;
+int xfs_fsverity_init(void);
+void xfs_fsverity_exit(void);
+bool xfs_fsverity_is_file_data(const struct xfs_inode *ip, loff_t offset);
+#else
+static inline int xfs_fsverity_init(void)
+{
+	return 0;
+}
+static inline void xfs_fsverity_exit(void)
+{
+}
+static inline bool xfs_fsverity_is_file_data(const struct xfs_inode *ip,
+					    loff_t offset)
+{
+	return false;
+}
+#endif	/* CONFIG_FS_VERITY */
+
+struct xfs_fsverity_ioend {
+	struct iomap_ioend	*ioend;
+	struct work_struct	work;
+};
+
+extern struct kmem_cache *xfs_fsverity_ioend_cache;
+extern mempool_t xfs_fsverity_ioend_pool;
+
+#endif	/* __XFS_FSVERITY_H__ */
diff --git a/fs/xfs/xfs_health.c b/fs/xfs/xfs_health.c
index 239b843e83d42a..be66760fb120f7 100644
--- a/fs/xfs/xfs_health.c
+++ b/fs/xfs/xfs_health.c
@@ -625,6 +625,7 @@ static const struct ioctl_sick_map ino_map[] = {
 	{ XFS_SICK_INO_DIR_ZAPPED,	XFS_BS_SICK_DIR },
 	{ XFS_SICK_INO_SYMLINK_ZAPPED,	XFS_BS_SICK_SYMLINK },
 	{ XFS_SICK_INO_DIRTREE,	XFS_BS_SICK_DIRTREE },
+	{ XFS_SICK_INO_FSVERITY,	XFS_BS_SICK_FSVERITY },
 };
 
 /* Fill out bulkstat health info. */
diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index de8be344e987d0..ca74c9b4f8d383 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -28,7 +28,7 @@
 #include "xfs_da_format.h"
 #include "xfs_dir2.h"
 #include "xfs_metafile.h"
-
+#include <linux/fsverity.h>
 #include <linux/iversion.h>
 
 /* Radix tree tags for incore inode tree. */
@@ -1260,6 +1260,15 @@ xfs_inode_free_eofblocks(
 	if (xfs_can_free_eofblocks(ip))
 		return xfs_free_eofblocks(ip);
 
+	/*
+	 * The above xfs_free_eofblocks() is skipped for inodes with fsverity
+	 * tree is being built. However, we don't want to clear EOF tag in this
+	 * case. If building the tree fails, inode will have EOF blocks which
+	 * needs removal.
+	 */
+	if (fsverity_is_building(VFS_IC(ip)))
+		return 0;
+
 	/* inode could be preallocated */
 	trace_xfs_inode_free_eofblocks_invalid(ip);
 	xfs_inode_clear_eofblocks_tag(ip);
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index f81b6e52ac403d..2d0a2d37e71cf8 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -49,6 +49,7 @@
 
 #include <linux/mount.h>
 #include <linux/fileattr.h>
+#include <linux/fsverity.h>
 
 /* Return 0 on success or positive error */
 int
@@ -562,6 +563,14 @@ xfs_ioctl_setattr_xflags(
 		if (xfs_inode_has_filedata(ip))
 			return -EINVAL;
 
+		/*
+		 * fs-verity is incompatible with a realtime allocation unit
+		 * larger than a single filesystem block, so don't let a file be
+		 * converted to realtime while verity is being enabled.
+		 */
+		if (fsverity_is_building(VFS_IC(ip)))
+			return -EINVAL;
+
 		/*
 		 * If S_DAX is enabled on this file, we can only switch the
 		 * device if both support fsdax.  We can't update S_DAX because
@@ -574,6 +583,17 @@ xfs_ioctl_setattr_xflags(
 			return -EINVAL;
 	}
 
+	/*
+	 * fs-verity is incompatible with DAX, and xfs_fsverity_begin_enable()
+	 * verified the inode was not DAX under the inode lock.  That lock is
+	 * dropped while the Merkle tree is built, so reject enabling DAX while
+	 * verity is being enabled.
+	 */
+	if ((fa->fsx_xflags & FS_XFLAG_DAX) &&
+	    !(ip->i_diflags2 & XFS_DIFLAG2_DAX) &&
+	    fsverity_is_building(VFS_IC(ip)))
+		return -EINVAL;
+
 	if (rtflag) {
 		/* If realtime flag is set then must have realtime device */
 		if (mp->m_sb.sb_rblocks == 0 || mp->m_sb.sb_rextsize == 0 ||
@@ -1575,6 +1595,19 @@ xfs_file_ioctl(
 	case XFS_IOC_VERIFY_MEDIA:
 		return xfs_ioc_verify_media(filp, arg);
 
+	case FS_IOC_ENABLE_VERITY:
+		if (!xfs_has_verity(mp))
+			return -EOPNOTSUPP;
+		return fsverity_ioctl_enable(filp, arg);
+	case FS_IOC_MEASURE_VERITY:
+		if (!xfs_has_verity(mp))
+			return -EOPNOTSUPP;
+		return fsverity_ioctl_measure(filp, arg);
+	case FS_IOC_READ_VERITY_METADATA:
+		if (!xfs_has_verity(mp))
+			return -EOPNOTSUPP;
+		return fsverity_ioctl_read_metadata(filp, arg);
+
 	default:
 		return -ENOTTY;
 	}
diff --git a/fs/xfs/xfs_ioend.c b/fs/xfs/xfs_ioend.c
index 7f4a4a95afe50d..61f211a3b8052b 100644
--- a/fs/xfs/xfs_ioend.c
+++ b/fs/xfs/xfs_ioend.c
@@ -18,7 +18,26 @@
 #include "xfs_ioend.h"
 #include "xfs_error.h"
 #include "xfs_errortag.h"
+#include "xfs_fsverity.h"
 #include <linux/bio-integrity.h>
+#include <linux/fsverity.h>
+
+static void
+xfs_end_fsverity_io_read(
+	struct work_struct		*work)
+{
+	struct xfs_fsverity_ioend	*fsv_ioend =
+			container_of(work, struct xfs_fsverity_ioend, work);
+	struct iomap_ioend		*ioend = fsv_ioend->ioend;
+	struct bio			*bio = &ioend->io_bio;
+
+	mempool_free(fsv_ioend, &xfs_fsverity_ioend_pool);
+
+	if (!bio->bi_status)
+		fsverity_verify_bio(ioend->io_vi, bio);
+
+	iomap_finish_ioends(ioend, blk_status_to_errno(bio->bi_status));
+}
 
 static void
 xfs_dio_bounce_end_io(
@@ -93,12 +112,14 @@ xfs_read_bounce_and_resubmit(
 
 static void
 xfs_end_io_read(
-	struct bio		*bio)
+	struct bio			*bio)
 {
-	struct iomap_ioend	*ioend = iomap_ioend_from_bio(bio);
-	struct xfs_inode	*ip = XFS_I(ioend->io_inode);
-	struct xfs_mount	*mp = ip->i_mount;
-	int			error = blk_status_to_errno(bio->bi_status);
+	struct iomap_ioend		*ioend = iomap_ioend_from_bio(bio);
+	struct xfs_inode		*ip = XFS_I(ioend->io_inode);
+	struct xfs_mount		*mp = ip->i_mount;
+	int				error =
+			blk_status_to_errno(bio->bi_status);
+	struct xfs_fsverity_ioend	*fsv_ioend;
 
 	if (!error && (ioend->io_flags & IOMAP_IOEND_INTEGRITY)) {
 		error = iomap_ioend_integrity_verify(ioend);
@@ -117,6 +138,24 @@ xfs_end_io_read(
 		}
 	}
 
+	/*
+	 * If we have fsverity on this bio, we need to run fsverity verification
+	 * of data folios from a separate fsverity workqueue. This is necessary
+	 * to avoid deadlocking due to fsverity issuing more reads of fsverity
+	 * metadata which would be processed by the same worker in the BIO
+	 * completion workqueue.
+	 */
+	if (IS_ENABLED(CONFIG_FS_VERITY) && !error && ioend->io_vi &&
+			xfs_fsverity_is_file_data(ip, ioend->io_offset)) {
+		fsv_ioend = mempool_alloc(&xfs_fsverity_ioend_pool,
+				GFP_NOFS);
+		fsv_ioend->ioend = ioend;
+		INIT_WORK(&fsv_ioend->work, xfs_end_fsverity_io_read);
+
+		fsverity_enqueue_verify_work(&fsv_ioend->work);
+		return;
+	}
+
 	iomap_finish_ioends(ioend, error);
 }
 
@@ -125,13 +164,15 @@ xfs_ioend_submit_read(
 	struct inode		*inode,
 	struct bio		*bio,
 	loff_t			file_offset,
-	u16			ioend_flags)
+	u16			ioend_flags,
+	struct fsverity_info	*vi)
 {
 	struct xfs_inode	*ip = XFS_I(inode);
 	struct xfs_mount	*mp = ip->i_mount;
 	struct iomap_ioend	*ioend;
 
 	ioend = iomap_init_ioend(inode, bio, file_offset, ioend_flags);
+	ioend->io_vi = vi;
 	if ((ioend_flags & IOMAP_IOEND_DIRECT) &&
 	    READ_ONCE(mp->m_read_bounce) == XFS_READ_BOUNCE_ALWAYS) {
 		iomap_bounce_read(ioend, bdev_logical_block_size(bio->bi_bdev),
diff --git a/fs/xfs/xfs_ioend.h b/fs/xfs/xfs_ioend.h
index 7c2a1ea3e6eddc..992c248a693aaf 100644
--- a/fs/xfs/xfs_ioend.h
+++ b/fs/xfs/xfs_ioend.h
@@ -2,6 +2,8 @@
 #ifndef __XFS_IOEND_H
 #define __XFS_IOEND_H
 
+#include <linux/fsverity.h>
+
 /*
  * Fast and loose check if this write could update the on-disk inode size.
  */
@@ -13,6 +15,6 @@ static inline bool xfs_ioend_is_append(struct iomap_ioend *ioend)
 
 void xfs_end_bio(struct bio *bio);
 void xfs_ioend_submit_read(struct inode *inode, struct bio *bio,
-		loff_t file_offset, u16 ioend_flags);
+		loff_t file_offset, u16 ioend_flags, struct fsverity_info *vi);
 
 #endif /* __XFS_IOEND_H */
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 50eae7ff614534..5117704530f69c 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -32,6 +32,8 @@
 #include "xfs_rtbitmap.h"
 #include "xfs_icache.h"
 #include "xfs_zone_alloc.h"
+#include "xfs_verity.h"
+#include <linux/fsverity.h>
 
 #define XFS_ALLOC_ALIGN(mp, off) \
 	(((off) >> mp->m_allocsize_log) << mp->m_allocsize_log)
@@ -54,6 +56,15 @@ xfs_alert_fsblock_zero(
 	return -EFSCORRUPTED;
 }
 
+static bool
+xfs_iomap_is_fsverity_metadata(
+	struct xfs_inode	*ip,
+	loff_t			offset)
+{
+	return offset >= xfs_fsverity_metadata_offset(ip) &&
+	       (fsverity_is_building(VFS_I(ip)) || fsverity_active(VFS_I(ip)));
+}
+
 u64
 xfs_iomap_inode_sequence(
 	struct xfs_inode	*ip,
@@ -101,6 +112,7 @@ xfs_bmbt_to_iomap(
 	struct xfs_inode	*ip,
 	struct iomap		*iomap,
 	struct xfs_bmbt_irec	*imap,
+	loff_t			offset,
 	unsigned int		mapping_flags,
 	u16			iomap_flags,
 	u64			sequence_cookie)
@@ -152,6 +164,15 @@ xfs_bmbt_to_iomap(
 			iomap->flags |= IOMAP_F_INTEGRITY;
 	}
 
+	/*
+	 * Tell iomap when this I/O covers fs-verity metadata so it handles size
+	 * updates and post-EOF folios correctly.  The attr fork uses a separate
+	 * offset space, so exclude it.
+	 */
+	if (!(iomap_flags & IOMAP_F_XATTR) &&
+	    xfs_iomap_is_fsverity_metadata(ip, offset))
+		iomap->flags |= IOMAP_F_FSVERITY;
+
 	/*
 	 * If the inode is dirty for datasync purposes, let iomap know so it
 	 * doesn't elide the IO completion journal flushes on O_DSYNC IO.
@@ -1006,7 +1027,8 @@ xfs_direct_write_iomap_begin(
 	seq = xfs_iomap_inode_sequence(ip, iomap_flags);
 	xfs_iunlock(ip, lockmode);
 	trace_xfs_iomap_found(ip, offset, length, XFS_DATA_FORK, &imap);
-	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, iomap_flags, seq);
+	return xfs_bmbt_to_iomap(ip, iomap, &imap, offset, flags, iomap_flags,
+			seq);
 
 allocate_blocks:
 	error = -EAGAIN;
@@ -1037,7 +1059,7 @@ xfs_direct_write_iomap_begin(
 		return error;
 
 	trace_xfs_iomap_alloc(ip, offset, length, XFS_DATA_FORK, &imap);
-	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags,
+	return xfs_bmbt_to_iomap(ip, iomap, &imap, offset, flags,
 				 iomap_flags | IOMAP_F_NEW, seq);
 
 out_found_cow:
@@ -1045,13 +1067,15 @@ xfs_direct_write_iomap_begin(
 	trace_xfs_iomap_found(ip, offset, length - offset, XFS_COW_FORK, &cmap);
 	if (imap.br_startblock != HOLESTARTBLOCK) {
 		seq = xfs_iomap_inode_sequence(ip, 0);
-		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, flags, 0, seq);
+		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, offset, flags,
+				0, seq);
 		if (error)
 			goto out_unlock;
 	}
 	seq = xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED);
 	xfs_iunlock(ip, lockmode);
-	return xfs_bmbt_to_iomap(ip, iomap, &cmap, flags, IOMAP_F_SHARED, seq);
+	return xfs_bmbt_to_iomap(ip, iomap, &cmap, offset, flags,
+			IOMAP_F_SHARED, seq);
 
 out_unlock:
 	if (lockmode)
@@ -1270,7 +1294,8 @@ xfs_atomic_write_cow_iomap_begin(
 	trace_xfs_iomap_found(ip, offset, length, XFS_COW_FORK, &cmap);
 	seq = xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED);
 	xfs_iunlock(ip, XFS_ILOCK_EXCL);
-	return xfs_bmbt_to_iomap(ip, iomap, &cmap, flags, IOMAP_F_SHARED, seq);
+	return xfs_bmbt_to_iomap(ip, iomap, &cmap, offset, flags,
+			IOMAP_F_SHARED, seq);
 
 convert_delay:
 	xfs_iunlock(ip, XFS_ILOCK_EXCL);
@@ -1622,8 +1647,9 @@ xfs_zoned_fill_srcmap(
 	 */
 	xfs_trim_extent(&smap, offset_fsb, *end_fsb - offset_fsb);
 	*end_fsb = min(*end_fsb, smap.br_startoff + smap.br_blockcount);
-	return xfs_bmbt_to_iomap(ip, srcmap, &smap, flags, 0,
-			xfs_iomap_inode_sequence(ip, 0));
+	return xfs_bmbt_to_iomap(ip, srcmap, &smap,
+			XFS_FSB_TO_B(ip->i_mount, offset_fsb), flags,
+			0, xfs_iomap_inode_sequence(ip, 0));
 }
 
 static int
@@ -1796,7 +1822,7 @@ xfs_zoned_buffered_write_iomap_begin(
 	trace_xfs_iomap_alloc(ip, offset, XFS_FSB_TO_B(mp, count_fsb),
 			XFS_COW_FORK, &got);
 done:
-	error = xfs_bmbt_to_iomap(ip, iomap, &got, flags, iomap_flags,
+	error = xfs_bmbt_to_iomap(ip, iomap, &got, offset, flags, iomap_flags,
 			xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED));
 out_unlock:
 	xfs_iunlock(ip, lockmode);
@@ -2104,7 +2130,8 @@ xfs_buffered_write_iomap_begin(
 found_imap:
 	seq = xfs_iomap_inode_sequence(ip, iomap_flags);
 	xfs_iunlock(ip, lockmode);
-	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, iomap_flags, seq);
+	return xfs_bmbt_to_iomap(ip, iomap, &imap, offset, flags, iomap_flags,
+			seq);
 
 convert_delay:
 	xfs_iunlock(ip, lockmode);
@@ -2119,8 +2146,8 @@ xfs_buffered_write_iomap_begin(
 
 found_cow:
 	if (imap.br_startoff <= offset_fsb) {
-		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, flags, 0,
-				xfs_iomap_inode_sequence(ip, 0));
+		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, offset, flags,
+				0, xfs_iomap_inode_sequence(ip, 0));
 		if (error)
 			goto out_unlock;
 	} else {
@@ -2131,7 +2158,8 @@ xfs_buffered_write_iomap_begin(
 	iomap_flags |= IOMAP_F_SHARED;
 	seq = xfs_iomap_inode_sequence(ip, iomap_flags);
 	xfs_iunlock(ip, lockmode);
-	return xfs_bmbt_to_iomap(ip, iomap, &cmap, flags, iomap_flags, seq);
+	return xfs_bmbt_to_iomap(ip, iomap, &cmap, offset, flags, iomap_flags,
+			seq);
 
 out_unlock:
 	xfs_iunlock(ip, lockmode);
@@ -2238,7 +2266,7 @@ xfs_read_iomap_begin(
 	if (error)
 		return error;
 	trace_xfs_iomap_found(ip, offset, length, XFS_DATA_FORK, &imap);
-	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags,
+	return xfs_bmbt_to_iomap(ip, iomap, &imap, offset, flags,
 				 shared ? IOMAP_F_SHARED : 0, seq);
 }
 
@@ -2298,7 +2326,7 @@ xfs_seek_iomap_begin(
 			end_fsb = min(end_fsb, data_fsb);
 		xfs_trim_extent(&cmap, offset_fsb, end_fsb - offset_fsb);
 		seq = xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED);
-		error = xfs_bmbt_to_iomap(ip, iomap, &cmap, flags,
+		error = xfs_bmbt_to_iomap(ip, iomap, &cmap, offset, flags,
 				IOMAP_F_SHARED, seq);
 		/*
 		 * This is a COW extent, so we must probe the page cache
@@ -2322,7 +2350,7 @@ xfs_seek_iomap_begin(
 done:
 	seq = xfs_iomap_inode_sequence(ip, 0);
 	xfs_trim_extent(&imap, offset_fsb, end_fsb - offset_fsb);
-	error = xfs_bmbt_to_iomap(ip, iomap, &imap, flags, 0, seq);
+	error = xfs_bmbt_to_iomap(ip, iomap, &imap, offset, flags, 0, seq);
 out_unlock:
 	xfs_iunlock(ip, lockmode);
 	return error;
@@ -2370,7 +2398,8 @@ xfs_xattr_iomap_begin(
 	if (error)
 		return error;
 	ASSERT(nimaps);
-	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, IOMAP_F_XATTR, seq);
+	return xfs_bmbt_to_iomap(ip, iomap, &imap, offset, flags,
+			IOMAP_F_XATTR, seq);
 }
 
 DEFINE_IOMAP_ITER_NEXT(xfs_xattr_iomap_next, xfs_xattr_iomap_begin);
diff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h
index 071fff6665070e..c9bd6de1bfda5a 100644
--- a/fs/xfs/xfs_iomap.h
+++ b/fs/xfs/xfs_iomap.h
@@ -22,8 +22,9 @@ xfs_fileoff_t xfs_iomap_eof_align_last_fsb(struct xfs_inode *ip,
 
 u64 xfs_iomap_inode_sequence(struct xfs_inode *ip, u16 iomap_flags);
 int xfs_bmbt_to_iomap(struct xfs_inode *ip, struct iomap *iomap,
-		struct xfs_bmbt_irec *imap, unsigned int mapping_flags,
-		u16 iomap_flags, u64 sequence_cookie);
+		struct xfs_bmbt_irec *imap, loff_t offset,
+		unsigned int mapping_flags, u16 iomap_flags,
+		u64 sequence_cookie);
 
 int xfs_zero_range(struct xfs_inode *ip, loff_t pos, loff_t len,
 		struct xfs_zone_alloc_ctx *ac, bool *did_zero);
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index 6c5633db30daea..ff34f392dd557e 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -35,6 +35,7 @@
 #include <linux/security.h>
 #include <linux/iversion.h>
 #include <linux/fiemap.h>
+#include <linux/fsverity.h>
 
 /*
  * Directories have different lock order w.r.t. mmap_lock compared to regular
@@ -579,6 +580,18 @@ xfs_report_dioalign(
 	struct block_device	*bdev = target->bt_bdev;
 
 	stat->result_mask |= STATX_DIOALIGN | STATX_DIO_READ_ALIGN;
+
+	/*
+	 * The STATX_DIOALIGN | STATX_DIO_READ_ALIGN flags are used to
+	 * explicitly report if DIO is supported or not. They can not indicate
+	 * that fallback to the buffered IO is used for fsverity.
+	 *
+	 * Return zero alignment values which also mean that DIO is not
+	 * supported on this file, see statx(2).
+	 */
+	if (fsverity_active(VFS_I(ip)))
+		return;
+
 	stat->dio_mem_align = bdev_dma_alignment(bdev) + 1;
 
 	/*
@@ -1387,6 +1400,8 @@ xfs_inode_should_enable_dax(
 		return false;
 	if (!xfs_inode_supports_dax(ip))
 		return false;
+	if (ip->i_diflags2 & XFS_DIFLAG2_VERITY)
+		return false;
 	if (xfs_has_dax_always(ip->i_mount))
 		return true;
 	if (ip->i_diflags2 & XFS_DIFLAG2_DAX)
@@ -1415,12 +1430,15 @@ xfs_diflags_to_iflags(
 		flags |= S_NOATIME;
 	if (init && xfs_inode_should_enable_dax(ip))
 		flags |= S_DAX;
+	if (xflags & FS_XFLAG_VERITY)
+		flags |= S_VERITY;
 
 	/*
 	 * S_DAX can only be set during inode initialization and is never set by
 	 * the VFS, so we cannot mask off S_DAX in i_flags.
 	 */
-	inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME);
+	inode->i_flags &=
+		~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME | S_VERITY);
 	inode->i_flags |= flags;
 }
 
diff --git a/fs/xfs/xfs_message.c b/fs/xfs/xfs_message.c
index 0243e509a46891..44b13d46049c62 100644
--- a/fs/xfs/xfs_message.c
+++ b/fs/xfs/xfs_message.c
@@ -149,6 +149,10 @@ xfs_warn_experimental(
 			.opstate	= XFS_OPSTATE_WARNED_LARP,
 			.name		= "logged extended attributes",
 		},
+		[XFS_EXPERIMENTAL_FSVERITY] = {
+			.opstate	= XFS_OPSTATE_WARNED_FSVERITY,
+			.name		= "fsverity",
+		},
 	};
 	ASSERT(feat >= 0 && feat < XFS_EXPERIMENTAL_MAX);
 	BUILD_BUG_ON(ARRAY_SIZE(features) != XFS_EXPERIMENTAL_MAX);
diff --git a/fs/xfs/xfs_message.h b/fs/xfs/xfs_message.h
index 811b885f41c35a..364fcc7e42b084 100644
--- a/fs/xfs/xfs_message.h
+++ b/fs/xfs/xfs_message.h
@@ -93,6 +93,7 @@ void xfs_buf_alert_ratelimited(struct xfs_buf *bp, const char *rlmsg,
 enum xfs_experimental_feat {
 	XFS_EXPERIMENTAL_SHRINK,
 	XFS_EXPERIMENTAL_LARP,
+	XFS_EXPERIMENTAL_FSVERITY,
 
 	XFS_EXPERIMENTAL_MAX,
 };
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index cbcfb89c67a440..0b64636635996f 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -403,6 +403,7 @@ typedef struct xfs_mount {
 #define XFS_FEAT_EXCHANGE_RANGE	(1ULL << 27)	/* exchange range */
 #define XFS_FEAT_METADIR	(1ULL << 28)	/* metadata directory tree */
 #define XFS_FEAT_ZONED		(1ULL << 29)	/* zoned RT device */
+#define XFS_FEAT_VERITY		(1ULL << 30)	/* fs-verity */
 
 /* Mount features */
 #define XFS_FEAT_NOLIFETIME	(1ULL << 47)	/* disable lifetime hints */
@@ -460,6 +461,7 @@ __XFS_HAS_FEAT(exchange_range, EXCHANGE_RANGE)
 __XFS_HAS_FEAT(metadir, METADIR)
 __XFS_HAS_FEAT(zoned, ZONED)
 __XFS_HAS_FEAT(nolifetime, NOLIFETIME)
+__XFS_HAS_FEAT(verity, VERITY)
 
 static inline bool xfs_has_rtgroups(const struct xfs_mount *mp)
 {
@@ -597,6 +599,8 @@ __XFS_HAS_FEAT(nouuid, NOUUID)
 #define XFS_OPSTATE_RESUMING_QUOTAON	18
 /* (Zoned) GC is in progress */
 #define XFS_OPSTATE_ZONEGC_RUNNING	20
+/* Kernel has logged a warning about fsverity support */
+#define XFS_OPSTATE_WARNED_FSVERITY	21
 
 #define __XFS_IS_OPSTATE(name, NAME) \
 static inline bool xfs_is_ ## name (struct xfs_mount *mp) \
diff --git a/fs/xfs/xfs_pnfs.c b/fs/xfs/xfs_pnfs.c
index 065875c8b7dab8..ff097400d064fd 100644
--- a/fs/xfs/xfs_pnfs.c
+++ b/fs/xfs/xfs_pnfs.c
@@ -256,7 +256,7 @@ xfs_fs_map_blocks(
 	}
 	xfs_iunlock(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
 
-	error = xfs_bmbt_to_iomap(ip, iomap, &imap, 0, 0, seq);
+	error = xfs_bmbt_to_iomap(ip, iomap, &imap, offset, 0, 0, seq);
 	*device_generation = mp->m_generation;
 	return error;
 out_unlock:
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 5a06132aa38466..890fa5727d56e6 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -30,6 +30,7 @@
 #include "xfs_filestream.h"
 #include "xfs_quota.h"
 #include "xfs_sysfs.h"
+#include "xfs_fsverity.h"
 #include "xfs_ondisk.h"
 #include "xfs_rmap_item.h"
 #include "xfs_refcount_item.h"
@@ -50,6 +51,7 @@
 #include "xfs_rtalloc.h"
 #include "xfs_zone_alloc.h"
 #include "xfs_healthmon.h"
+#include "xfs_fsverity.h"
 #include "scrub/stats.h"
 #include "scrub/rcbag_btree.h"
 
@@ -1736,6 +1738,9 @@ xfs_fs_fill_super(
 	sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
 #endif
 	sb->s_op = &xfs_super_operations;
+#ifdef CONFIG_FS_VERITY
+	sb->s_vop = &xfs_fsverity_ops;
+#endif
 
 	/*
 	 * Delay mount work if the debug hook is set. This is debug
@@ -1988,6 +1993,9 @@ xfs_fs_fill_super(
 	if (error)
 		goto out_filestream_unmount;
 
+	if (xfs_has_verity(mp))
+		xfs_warn_experimental(mp, XFS_EXPERIMENTAL_FSVERITY);
+
 	root = igrab(VFS_I(mp->m_rootip));
 	if (!root) {
 		error = -ENOENT;
@@ -2516,8 +2524,20 @@ xfs_init_caches(void)
 	if (!xfs_parent_args_cache)
 		goto out_destroy_xmi_cache;
 
+#ifdef CONFIG_FS_VERITY
+	xfs_fsverity_ioend_cache = kmem_cache_create("xfs_fsverity_ioend",
+					     sizeof(struct xfs_fsverity_ioend),
+					     0, 0, NULL);
+	if (!xfs_fsverity_ioend_cache)
+		goto out_destroy_parent_args_cache;
+#endif
+
 	return 0;
 
+#ifdef CONFIG_FS_VERITY
+ out_destroy_parent_args_cache:
+	kmem_cache_destroy(xfs_parent_args_cache);
+#endif
  out_destroy_xmi_cache:
 	kmem_cache_destroy(xfs_xmi_cache);
  out_destroy_xmd_cache:
@@ -2580,6 +2600,9 @@ xfs_destroy_caches(void)
 	 * destroy caches.
 	 */
 	rcu_barrier();
+#ifdef CONFIG_FS_VERITY
+	kmem_cache_destroy(xfs_fsverity_ioend_cache);
+#endif
 	kmem_cache_destroy(xfs_parent_args_cache);
 	kmem_cache_destroy(xfs_xmd_cache);
 	kmem_cache_destroy(xfs_xmi_cache);
@@ -2660,10 +2683,14 @@ init_xfs_fs(void)
 	if (error)
 		goto out;
 
-	error = xfs_init_workqueues();
+	error = xfs_fsverity_init();
 	if (error)
 		goto out_destroy_caches;
 
+	error = xfs_init_workqueues();
+	if (error)
+		goto out_fsverity_exit;
+
 	error = xfs_mru_cache_init();
 	if (error)
 		goto out_destroy_wq;
@@ -2740,6 +2767,8 @@ init_xfs_fs(void)
 	xfs_mru_cache_uninit();
  out_destroy_wq:
 	xfs_destroy_workqueues();
+ out_fsverity_exit:
+	xfs_fsverity_exit();
  out_destroy_caches:
 	xfs_destroy_caches();
  out:
@@ -2763,6 +2792,7 @@ exit_xfs_fs(void)
 	xfs_cleanup_procfs();
 	xfs_mru_cache_uninit();
 	xfs_destroy_workqueues();
+	xfs_fsverity_exit();
 	xfs_destroy_caches();
 	xfs_uuid_table_free();
 }

3/2 2026/11/25 16:34 llm patch-evaluator
22m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 31747
							output: 29
							thoughts: 765
						

Thoughts:
**Initial Assessment of XFS fs-verity Patch Series**

Okay, so the task at hand is to evaluate this patch series for the Linux kernel. First things first, I need to get a clear picture of what's being introduced. Right, it's fs-verity support, specifically for the XFS filesystem. That's a significant addition. Looking at the diff, it's pretty extensive – it touches a substantial number of files within the XFS subsystem.

The sheer volume of modified files immediately flags this as a potentially complex change. And XFS is a high-profile target; it's a core filesystem, frequently fuzzed, and used everywhere. From the look of things, user space can trigger operations via those fs-verity ioctls, plus standard read commands, and also in scrub and repair commands. There are modifications to core XFS functions too, like bunmap, file read iter, and other things.

Given that reachability and the potential for a variety of user-space interactions, this is definitely a high-priority area for fuzzing. The code is *definitely* reachable, so `WorthFuzzing = true`. Now, my next step is to examine the Kconfig files. I need to understand how this fs-verity feature is enabled in XFS – what configuration options are involved. Gotta check those symbols and configs to fully grasp the activation pathways.



4/2 2026/11/25 16:57 tool grepper
0m Args:
{
  "Expression": "FS_VERITY",
  "PathPrefixes": [
    "fs/xfs"
  ]
}

Results:
{
  "Output": "fs/xfs/Makefile=153=xfs-$(CONFIG_EXPORTFS_BLOCK_OPS)\t+= xfs_pnfs.o\nfs/xfs/Makefile:154:xfs-$(CONFIG_FS_VERITY)\t\t+= xfs_fsverity.o\nfs/xfs/Makefile-155-\n--\nfs/xfs/libxfs/xfs_verity.h-4- */\nfs/xfs/libxfs/xfs_verity.h:5:#ifndef __XFS_VERITY_H__\nfs/xfs/libxfs/xfs_verity.h:6:#define __XFS_VERITY_H__\nfs/xfs/libxfs/xfs_verity.h-7-\n--\nfs/xfs/libxfs/xfs_verity.h=11=loff_t xfs_fsverity_metadata_offset(const struct xfs_inode *ip);\nfs/xfs/libxfs/xfs_verity.h-12-\nfs/xfs/libxfs/xfs_verity.h:13:#endif\t/* __XFS_VERITY_H__ */\n--\nfs/xfs/xfs_fsverity.c=61=xfs_fsverity_get_descriptor(\n--\nfs/xfs/xfs_fsverity.c-126-\tdesc_size = be32_to_cpu(d_desc_size);\nfs/xfs/xfs_fsverity.c:127:\tif (XFS_IS_CORRUPT(mp, desc_size \u003e FS_VERITY_MAX_DESCRIPTOR_SIZE)) {\nfs/xfs/xfs_fsverity.c-128-\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n--\nfs/xfs/xfs_fsverity.h-13-\nfs/xfs/xfs_fsverity.h:14:#ifdef CONFIG_FS_VERITY\nfs/xfs/xfs_fsverity.h-15-extern const struct fsverity_operations xfs_fsverity_ops;\n--\nfs/xfs/xfs_fsverity.h=27=static inline bool xfs_fsverity_is_file_data(const struct xfs_inode *ip,\n--\nfs/xfs/xfs_fsverity.h-31-}\nfs/xfs/xfs_fsverity.h:32:#endif\t/* CONFIG_FS_VERITY */\nfs/xfs/xfs_fsverity.h-33-\n--\nfs/xfs/xfs_ioend.c=114=xfs_end_io_read(\n--\nfs/xfs/xfs_ioend.c-147-\t */\nfs/xfs/xfs_ioend.c:148:\tif (IS_ENABLED(CONFIG_FS_VERITY) \u0026\u0026 !error \u0026\u0026 ioend-\u003eio_vi \u0026\u0026\nfs/xfs/xfs_ioend.c-149-\t\t\txfs_fsverity_is_file_data(ip, ioend-\u003eio_offset)) {\n--\nfs/xfs/xfs_super.c=1704=xfs_fs_fill_super(\n--\nfs/xfs/xfs_super.c-1740-\tsb-\u003es_op = \u0026xfs_super_operations;\nfs/xfs/xfs_super.c:1741:#ifdef CONFIG_FS_VERITY\nfs/xfs/xfs_super.c-1742-\tsb-\u003es_vop = \u0026xfs_fsverity_ops;\n--\nfs/xfs/xfs_super.c=2362=xfs_init_caches(void)\n--\nfs/xfs/xfs_super.c-2526-\nfs/xfs/xfs_super.c:2527:#ifdef CONFIG_FS_VERITY\nfs/xfs/xfs_super.c-2528-\txfs_fsverity_ioend_cache = kmem_cache_create(\"xfs_fsverity_ioend\",\n--\nfs/xfs/xfs_super.c-2536-\nfs/xfs/xfs_super.c:2537:#ifdef CONFIG_FS_VERITY\nfs/xfs/xfs_super.c-2538- out_destroy_parent_args_cache:\n--\nfs/xfs/xfs_super.c=2596=xfs_destroy_caches(void)\n--\nfs/xfs/xfs_super.c-2602-\trcu_barrier();\nfs/xfs/xfs_super.c:2603:#ifdef CONFIG_FS_VERITY\nfs/xfs/xfs_super.c-2604-\tkmem_cache_destroy(xfs_fsverity_ioend_cache);\n"
}

5/2 2026/11/25 16:57 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34063
							output: 33
							thoughts: 36
						

Thoughts:
Here's my thought process, summarized as you requested:

**XFS and Verity Configuration Check**

Okay, let's get down to brass tacks. I need to figure out how XFS handles file-system verity, specifically from a configuration perspective. My immediate thought is to jump into the `fs/xfs/Kconfig` file. I'm hoping to find something specific to XFS, some custom configuration option, related to verity. It's possible XFS has its own nuances in how verity is enabled or disabled. However, it's equally likely (and simpler, from a maintainability standpoint) that XFS just reuses the generic `CONFIG_FS_VERITY` option. So, first thing, let's go poke around in `fs/xfs/Kconfig` and see if anything jumps out. That's the first and most direct path to understanding its current configuration dependencies.



6/2 2026/11/25 16:57 tool grepper
0m Args:
{
  "Expression": "VERITY|verity",
  "PathPrefixes": [
    "fs/xfs/Kconfig"
  ]
}

Results:
{
  "Output": "no matches"
}

7/2 2026/11/25 16:57 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34342
							output: 33
							thoughts: 23
						

Thoughts:
Here's my thought process, as if I were considering this myself:

**Investigating the Verity Configuration**

Okay, so I need to understand how `CONFIG_FS_VERITY` is being handled. My initial instinct is to dive straight into `fs/verity/Kconfig`. That's the standard place to check kernel configuration options, especially when dealing with filesystem-level features like Verity. This should reveal the dependencies, default values, and the general build behavior of this functionality. I'm expecting to find details on any required kernel features or hardware dependencies, as well as the conditions under which Verity might be enabled or disabled. Knowing this will give me a solid foundation for evaluating how and when this feature is active. I am expecting to find that it depends on other configurations too.



8/2 2026/11/25 16:58 tool read-file
0m Args:
{
  "File": "fs/verity/Kconfig",
  "FirstLine": 1,
  "LineCount": 50
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0\n   2:\t\n   3:\tconfig FS_VERITY\n   4:\t\tbool \"FS Verity (read-only file-based authenticity protection)\"\n   5:\t\t# Filesystems cache the Merkle tree at a 64K aligned offset in the\n   6:\t\t# pagecache.  That approach assumes the page size is at most 64K.\n   7:\t\tdepends on PAGE_SHIFT \u003c= 16\n   8:\t\tselect CRYPTO_HASH_INFO\n   9:\t\tselect CRYPTO_LIB_SHA256\n  10:\t\tselect CRYPTO_LIB_SHA512\n  11:\t\thelp\n  12:\t\t  This option enables fs-verity.  fs-verity is the dm-verity\n  13:\t\t  mechanism implemented at the file level.  On supported\n  14:\t\t  filesystems (currently ext4, f2fs, and btrfs), userspace can\n  15:\t\t  use an ioctl to enable verity for a file, which causes the\n  16:\t\t  filesystem to build a Merkle tree for the file.  The filesystem\n  17:\t\t  will then transparently verify any data read from the file\n  18:\t\t  against the Merkle tree.  The file is also made read-only.\n  19:\t\n  20:\t\t  This serves as an integrity check, but the availability of the\n  21:\t\t  Merkle tree root hash also allows efficiently supporting\n  22:\t\t  various use cases where normally the whole file would need to\n  23:\t\t  be hashed at once, such as: (a) auditing (logging the file's\n  24:\t\t  hash), or (b) authenticity verification (comparing the hash\n  25:\t\t  against a known good value, e.g. from a digital signature).\n  26:\t\n  27:\t\t  fs-verity is especially useful on large files where not all\n  28:\t\t  the contents may actually be needed.  Also, fs-verity verifies\n  29:\t\t  data each time it is paged back in, which provides better\n  30:\t\t  protection against malicious disks vs. an ahead-of-time hash.\n  31:\t\n  32:\t\t  If unsure, say N.\n  33:\t\n  34:\tconfig FS_VERITY_BUILTIN_SIGNATURES\n  35:\t\tbool \"FS Verity builtin signature support\"\n  36:\t\tdepends on FS_VERITY\n  37:\t\tselect SYSTEM_DATA_VERIFICATION\n  38:\t\thelp\n  39:\t\t  This option adds support for in-kernel verification of\n  40:\t\t  fs-verity builtin signatures.\n  41:\t\n  42:\t\t  Please take great care before using this feature.  It is not\n  43:\t\t  the only way to do signatures with fs-verity, and the\n  44:\t\t  alternatives (such as userspace signature verification, and\n  45:\t\t  IMA appraisal) can be much better.  For details about the\n  46:\t\t  limitations of this feature, see\n  47:\t\t  Documentation/filesystems/fsverity.rst.\n  48:\t\n  49:\t\t  If unsure, say N.\n"
}

9/2 2026/11/25 16:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35366
							output: 34
							thoughts: 92
						

Thoughts:
Okay, here's my breakdown of what I'm looking at:

**Investigating XFS Filesystem and fs-verity Integration**

Alright, let's get down to brass tacks. I need to make sure I have all the necessary components for my project. First and foremost, `CONFIG_XFS_FS` is a given; obviously, that's foundational for XFS. Next, I see that `CONFIG_FS_VERITY` is essential for incorporating fs-verity support, which is critical for the integrity checks I'm implementing. Now, it looks like there's been some recent work and modifications to the XFS scrub functionality. I can see there are changes to these core files: `fs/xfs/scrub/common.c`, `fs/xfs/scrub/inode.c`, and `fs/xfs/scrub/inode_repair.c`. Given that, I need to thoroughly examine the relevant `Kconfig` files. I need to figure out the specific configuration options related to XFS scrub and repair, to ensure everything's properly enabled and tailored for my use case. It's time to dig into the details and ensure I have everything set up correctly to take advantage of these features.



10/2 2026/11/25 16:58 tool grepper
0m Args:
{
  "Expression": "config XFS_ONLINE_",
  "PathPrefixes": [
    "fs/xfs/Kconfig"
  ]
}

Results:
{
  "Output": "fs/xfs/Kconfig=144=config XFS_BTREE_IN_MEM\n--\nfs/xfs/Kconfig-146-\nfs/xfs/Kconfig:147:config XFS_ONLINE_SCRUB\nfs/xfs/Kconfig-148-\tbool \"XFS online metadata check support\"\n--\nfs/xfs/Kconfig-163-\nfs/xfs/Kconfig:164:config XFS_ONLINE_SCRUB_STATS\nfs/xfs/Kconfig-165-\tbool \"XFS online metadata check usage data collection\"\n--\nfs/xfs/Kconfig-178-\nfs/xfs/Kconfig:179:config XFS_ONLINE_REPAIR\nfs/xfs/Kconfig-180-\tbool \"XFS online metadata repair support\"\n"
}

11/2 2026/11/25 16:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35973
							output: 32
							thoughts: 27
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**XFS Scrub/Repair Macro Location Check**

Right, let's dive straight in. My first thought is to pinpoint where the definitions for `XFS_ONLINE_SCRUB` and `XFS_ONLINE_REPAIR` are. Given my familiarity with the XFS codebase, the most likely spot to find them would be in the `fs/xfs/Makefile`. That's the typical place for build-time configuration macros related to filesystem features. So, my immediate focus is on that `Makefile`. I need to confirm their existence and precisely how they're defined within that context, as that will influence how they are subsequently used throughout the relevant source files. Understanding their build-time configuration is paramount for understanding the compile-time options related to these online maintenance features. Let's see what we find.



12/2 2026/11/25 16:58 tool grepper
0m Args:
{
  "Expression": "XFS_ONLINE_",
  "PathPrefixes": [
    "fs/xfs/Makefile"
  ]
}

Results:
{
  "Output": "fs/xfs/Makefile=164=xfs-$(CONFIG_XFS_BTREE_IN_MEM)\t+= libxfs/xfs_btree_mem.o\n--\nfs/xfs/Makefile-166-# online scrub/repair\nfs/xfs/Makefile:167:ifeq ($(CONFIG_XFS_ONLINE_SCRUB),y)\nfs/xfs/Makefile-168-\n--\nfs/xfs/Makefile=171=xfs-y\t\t\t\t+= $(addprefix scrub/, \\\n--\nfs/xfs/Makefile-202-\nfs/xfs/Makefile:203:xfs-$(CONFIG_XFS_ONLINE_SCRUB_STATS) += scrub/stats.o\nfs/xfs/Makefile-204-\n--\nfs/xfs/Makefile=213=xfs-$(CONFIG_XFS_QUOTA)\t\t+= $(addprefix scrub/, \\\n--\nfs/xfs/Makefile-219-# online repair\nfs/xfs/Makefile:220:ifeq ($(CONFIG_XFS_ONLINE_REPAIR),y)\nfs/xfs/Makefile-221-xfs-y\t\t\t\t+= $(addprefix scrub/, \\\n"
}

13/2 2026/11/25 16:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36518
							output: 33
							thoughts: 3174
						

Thoughts:
**Focusing on XFS Verity and Scrub/Repair: A Focused Review**

Okay, so the patch touches these files: `scrub/common.c`, `scrub/inode.c`, and `scrub/inode_repair.c`. This tells me that the code activated by `XFS_ONLINE_SCRUB` and `XFS_ONLINE_REPAIR` is affected. We also need to be sure that `XFS_FS`, and `FS_VERITY` are enabled.

Now, I'm diving into the code. This will be the key to identifying the right `FocusSymbols`. I need to avoid picking ubiquitous functions – no general memory allocators, page fault handlers, or core sync primitives. I'm targeting the feature-specific logic and its entrypoints.

Here's my initial list of functions added or significantly altered in the patch:

*   In `fs/xfs/xfs_fsverity.c`: I see a number of new verity ops: `xfs_fsverity_init`, `xfs_fsverity_exit`, and `xfs_fsverity_is_file_data`, and then I see the static function pointers, but don't worry, `xfs_fsverity_begin_enable`, `xfs_fsverity_end_enable`, `xfs_fsverity_get_descriptor`, `xfs_fsverity_read_merkle`, and `xfs_fsverity_write_merkle` are static, but are function pointers in a struct, meaning that the compiler has to emit code!

*   In `fs/xfs/libxfs/xfs_verity.c`: There's `xfs_fsverity_metadata_offset`.

*   In `fs/xfs/scrub/common.c`: I spot `xchk_inode_setup_verity` and `xchk_inode_verity_broken`.

*   In `fs/xfs/scrub/inode_repair.c`: We have `xrep_dinode_flags`, `xrep_dinode_core`, and the static function `xrep_inode_verity`, which is called by the modified `xrep_inode`.

*   In `fs/xfs/scrub/inode.c`: I see changes to `xchk_prepare_iscrub` and `xchk_inode`.

Let's also look in `fs/xfs/xfs_ioctl.c` for any function calls:

`fsverity_ioctl_enable` is called from `FS_IOC_ENABLE_VERITY`
`fsverity_ioctl_measure` is called from `FS_IOC_MEASURE_VERITY`
`fsverity_ioctl_read_metadata` is called from `FS_IOC_READ_VERITY_METADATA`
`xfs_ioctl_setattr_xflags` was also modified with verity checks!

Also, in `fs/xfs/xfs_ioend.c` there's `xfs_end_fsverity_io_read` (a static callback for a workqueue), and `xfs_end_io_read`, and `xfs_ioend_submit_read` have been modified, along with:

`xfs_can_free_eofblocks`, and `xfs_free_eofblocks` have modifications for fsverity,
`__xfs_bunmapi`, `xfs_bmapi_convert_one_delalloc`, `xfs_bmbt_to_iomap`, and `xfs_iomap_is_fsverity_metadata`, in `fs/xfs/libxfs/xfs_bmap.c`, `fs/xfs/xfs_iomap.c`, and `fs/xfs/libxfs/xfs_bmap.c` respectively.

Also, `xfs_file_dio_read`, `xfs_file_read_iter`, and `xfs_file_open` in `fs/xfs/xfs_file.c` have modifications, and `xfs_dinode_verify` in `fs/xfs/libxfs/xfs_inode_buf.c`

Okay, now for the crucial part: selecting the `FocusSymbols`. These must be specific entry points or logic for the verity feature and scrub/repair. I have to be very careful to avoid functions that are part of every operation. So, I will avoid `xfs_file_open`, and `xfs_file_read_iter`. Also, the scrub/repair functions are only called during


14/2 2026/11/25 16:58 tool grepper
0m Args:
{
  "Expression": "config XFS_FS",
  "PathPrefixes": [
    "fs/xfs/Kconfig"
  ]
}

Results:
{
  "Output": "fs/xfs/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\nfs/xfs/Kconfig:2:config XFS_FS\nfs/xfs/Kconfig-3-\ttristate \"XFS filesystem support\"\n"
}

15/2 2026/11/25 16:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 40823
							output: 33
							thoughts: 123
						

Thoughts:
**Investigating Filesystem Dependencies**

Okay, so I need to understand the dependencies of `XFS_FS` and `FS_VERITY`. Let's start with `FS_VERITY`. The Kconfig file in `fs/verity/` is the place to look. Right, here it is: `config FS_VERITY`... aha! It *depends on* `PAGE_SHIFT <= 16`. That's interesting, a hardware constraint it seems. And it *selects* `CRYPTO_HASH_INFO`, `CRYPTO_LIB_SHA256`, and `CRYPTO_LIB_SHA512`. So, verity is heavily reliant on cryptographic hash functionality, as one would expect.

Now, for `XFS_FS`, I'll need to check the `fs/xfs/Kconfig` file. I'll take a look at the first 50 lines.



16/2 2026/11/25 16:58 tool read-file
0m Args:
{
  "File": "fs/xfs/Kconfig",
  "FirstLine": 1,
  "LineCount": 50
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0-only\n   2:\tconfig XFS_FS\n   3:\t\ttristate \"XFS filesystem support\"\n   4:\t\tdepends on BLOCK\n   5:\t\tselect EXPORTFS\n   6:\t\tselect CRC32\n   7:\t\tselect FS_IOMAP\n   8:\t\thelp\n   9:\t\t  XFS is a high performance journaling filesystem which originated\n  10:\t\t  on the SGI IRIX platform.  It is completely multi-threaded, can\n  11:\t\t  support large files and large filesystems, extended attributes,\n  12:\t\t  variable block sizes, is extent based, and makes extensive use of\n  13:\t\t  Btrees (directories, extents, free space) to aid both performance\n  14:\t\t  and scalability.\n  15:\t\n  16:\t\t  Refer to the documentation at \u003chttp://oss.sgi.com/projects/xfs/\u003e\n  17:\t\t  for complete details.  This implementation is on-disk compatible\n  18:\t\t  with the IRIX version of XFS.\n  19:\t\n  20:\t\t  To compile this file system support as a module, choose M here: the\n  21:\t\t  module will be called xfs.  Be aware, however, that if the file\n  22:\t\t  system of your root partition is compiled as a module, you'll need\n  23:\t\t  to use an initial ramdisk (initrd) to boot.\n  24:\t\n  25:\tconfig XFS_SUPPORT_V4\n  26:\t\tbool \"Support deprecated V4 (crc=0) format\"\n  27:\t\tdepends on XFS_FS\n  28:\t\tdefault n\n  29:\t\thelp\n  30:\t\t  The V4 filesystem format lacks certain features that are supported\n  31:\t\t  by the V5 format, such as metadata checksumming, strengthened\n  32:\t\t  metadata verification, and the ability to store timestamps past the\n  33:\t\t  year 2038.  Because of this, the V4 format is deprecated.  All users\n  34:\t\t  should upgrade by backing up their files, reformatting, and restoring\n  35:\t\t  from the backup.\n  36:\t\n  37:\t\t  Administrators and users can detect a V4 filesystem by running\n  38:\t\t  xfs_info against a filesystem mountpoint and checking for a string\n  39:\t\t  beginning with \"crc=\".  If the string \"crc=0\" is found, the\n  40:\t\t  filesystem is a V4 filesystem.  If no such string is found, please\n  41:\t\t  upgrade xfsprogs to the latest version and try again.\n  42:\t\n  43:\t\t  This option became default N in September 2025.  Support for the\n  44:\t\t  V4 format will be removed entirely in September 2030.  Distributors\n  45:\t\t  can say N here to withdraw support earlier.\n  46:\t\n  47:\t\t  To continue supporting the old V4 format (crc=0), say Y.\n  48:\t\t  To close off an attack surface, say N.\n  49:\t\n  50:\tconfig XFS_SUPPORT_ASCII_CI\n"
}

17/2 2026/11/25 16:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 41982
							output: 35
							thoughts: 28
						

Thoughts:
Okay, let's dive into this. Here's my thought process on this task:

**Online Scrub/Repair Dependencies in XFS: A Kconfig Dive**

Alright, so the task at hand is to understand the dependencies for online scrub and repair functionality within the XFS filesystem. My first instinct, given the context, is to zero in on the relevant configuration options. And, given that this relates to features and capabilities, the `Kconfig` files are usually the best place to start. I'll need to know which features are enabled by what.

Specifically, I'm going to jump straight to lines 140-190 of `fs/xfs/Kconfig`. This range seems like a sensible place to begin, given that Kconfig files are often broken up into sections. Hopefully this area contains definitions or descriptions relating to online scrub and repair, or at least features directly related to those functions. I'm expecting to find `config` options, maybe some `depends on` statements, or some other build-time configuration variables that give me the needed details about what's required for these features. Time to get my hands dirty.



18/2 2026/11/25 16:58 tool read-file
0m Args:
{
  "File": "fs/xfs/Kconfig",
  "FirstLine": 140,
  "LineCount": 50
}

Results:
{
  "Contents": " 140:\t\n 141:\tconfig XFS_MEMORY_BUFS\n 142:\t\tbool\n 143:\t\n 144:\tconfig XFS_BTREE_IN_MEM\n 145:\t\tbool\n 146:\t\n 147:\tconfig XFS_ONLINE_SCRUB\n 148:\t\tbool \"XFS online metadata check support\"\n 149:\t\tdefault y\n 150:\t\tdepends on XFS_FS\n 151:\t\tdepends on TMPFS \u0026\u0026 SHMEM\n 152:\t\tselect XFS_LIVE_HOOKS\n 153:\t\tselect XFS_DRAIN_INTENTS\n 154:\t\tselect XFS_MEMORY_BUFS\n 155:\t\thelp\n 156:\t\t  If you say Y here you will be able to check metadata on a\n 157:\t\t  mounted XFS filesystem.  This feature is intended to reduce\n 158:\t\t  filesystem downtime by supplementing xfs_repair.  The key\n 159:\t\t  advantage here is to look for problems proactively so that\n 160:\t\t  they can be dealt with in a controlled manner.\n 161:\t\n 162:\t\t  See the xfs_scrub man page in section 8 for additional information.\n 163:\t\n 164:\tconfig XFS_ONLINE_SCRUB_STATS\n 165:\t\tbool \"XFS online metadata check usage data collection\"\n 166:\t\tdefault y\n 167:\t\tdepends on XFS_ONLINE_SCRUB\n 168:\t\tdepends on DEBUG_FS\n 169:\t\thelp\n 170:\t\t  If you say Y here, the kernel will gather usage data about\n 171:\t\t  the online metadata check subsystem.  This includes the number\n 172:\t\t  of invocations, the outcomes, and the results of repairs, if any.\n 173:\t\t  This may slow down scrub slightly due to the use of high precision\n 174:\t\t  timers and the need to merge per-invocation information into the\n 175:\t\t  filesystem counters.\n 176:\t\n 177:\t\t  Usage data are collected in /sys/kernel/debug/xfs/scrub.\n 178:\t\n 179:\tconfig XFS_ONLINE_REPAIR\n 180:\t\tbool \"XFS online metadata repair support\"\n 181:\t\tdefault y\n 182:\t\tdepends on XFS_FS \u0026\u0026 XFS_ONLINE_SCRUB\n 183:\t\tselect XFS_BTREE_IN_MEM\n 184:\t\thelp\n 185:\t\t  If you say Y here you will be able to repair metadata on a\n 186:\t\t  mounted XFS filesystem.  This feature is intended to reduce\n 187:\t\t  filesystem downtime by fixing minor problems before they cause the\n 188:\t\t  filesystem to go down.  However, it requires that the filesystem be\n 189:\t\t  formatted with secondary metadata, such as reverse mappings and inode\n"
}

19/2 2026/11/25 16:58 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43050
							output: 306
							thoughts: 1254
						

Thoughts:
**XFS Verity Configuration Review**

Okay, so I'm diving into this XFS Verity patch. First, I need to pinpoint the critical configurations. From a quick scan, it looks like `XFS_FS`, `FS_VERITY`, `XFS_ONLINE_SCRUB`, and `XFS_ONLINE_REPAIR` are the key ones to keep an eye on. I need to ensure there aren't any other configs subtly introduced.

Looking at `fs/xfs/Makefile`, the inclusion of `xfs_fsverity.o` and `libxfs/xfs_verity.o` under `CONFIG_FS_VERITY` confirms its direct relevance. The `xfs_pnfs.o` modification is interesting, though it's related to block ops and PNFS, so probably not directly relevant to *verity* itself, though it may be worth a very quick look.

Next, I'm checking `fs/xfs/libxfs/xfs_inode_buf.c`.  `xfs_dinode_verify` is important; it validates the `XFS_DIFLAG2_VERITY` flag on inodes, but only for regular files.  The presence of `xfs_has_verity(mp)` confirms that this is feature-gated by the superblock feature flag.

Moving on to `fs/xfs/xfs_fsverity.c`, the `fsverity_operations` struct and its functions, such as `xfs_fsverity_begin_enable`, `xfs_fsverity_end_enable`, `xfs_fsverity_get_descriptor`, `xfs_fsverity_read_merkle`, and `xfs_fsverity_write_merkle`, all seem to be central to verity operation. `xfs_fsverity_readahead_merkle_tree` is also worth checking, and I'll make sure to note that the `sb->s_vop` assignment in `xfs_super.c` is conditional on `CONFIG_FS_VERITY`.

Now, let's nail down the `FocusSymbols`.  I'm going to make sure each symbol I pick is specifically related to the introduced or modified verity logic.  `xfs_fsverity_begin_enable` and `xfs_fsverity_end_enable` are triggered by `FS_IOC_ENABLE_VERITY`. Then `xfs_fsverity_get_descriptor` for opening and reading.  `xfs_fsverity_read_merkle`, and `xfs_fsverity_write_merkle` are obvious choices. I'm noting the offset calculation function `xfs_fsverity_metadata_offset`, and the data/metadata check, `xfs_fsverity_is_file_data`.  `xfs_end_fsverity_io_read` for async reads. Finally, the scrubbing and repair functions - `xchk_inode_setup_verity`, `xchk_inode_verity_broken`, and `xrep_inode_verity` are all directly involved.

I'm checking `xfs_fsverity_init`, `xfs_fsverity_exit`, `xfs_fsverity_delete_metadata`, and `xfs_fsverity_reset_inode`. The first two are init/exit routines, not prime fuzzing targets. The latter are static and called by the begin/end functions, and thus are less interesting. `xfs_dinode_verify` is a good inclusion as it performs important on-disk validation.

All chosen focus symbols are specific to verity, which is excellent. They all appear to have direct impact on the core logic.

Time to verify `EnableConfigs`.  `XFS_FS` is required for XFS, `FS_VERITY` enables verity support, `XFS_ONLINE_SCRUB` is needed for the `xchk_*` functions, and `XFS_ONLINE_REPAIR` for the repair functions. All of these configurations make sense in the context of XFS verity.

Finally, I'm confirming the `set-results` parameters. We have the `EnableConfigs`, the `FocusSymbols`, a concise `Reasoning`, and the `WorthFuzzing` flag is definitely `true` in this case. Everything checks out perfectly. We can proceed with calling `set-results`.



20/2 2026/11/25 16:59 tool set-results
0m Args:
{
  "EnableConfigs": [
    "XFS_FS",
    "FS_VERITY",
    "XFS_ONLINE_SCRUB",
    "XFS_ONLINE_REPAIR"
  ],
  "FocusSymbols": [
    "xfs_fsverity_begin_enable",
    "xfs_fsverity_end_enable",
    "xfs_fsverity_get_descriptor",
    "xfs_fsverity_read_merkle",
    "xfs_fsverity_write_merkle",
    "xfs_fsverity_metadata_offset",
    "xfs_fsverity_is_file_data",
    "xfs_end_fsverity_io_read",
    "xchk_inode_setup_verity",
    "xchk_inode_verity_broken",
    "xrep_inode_verity",
    "xfs_dinode_verify"
  ],
  "Reasoning": "The patch adds fs-verity support to XFS, enabling file sealing and Merkle tree storage/verification beyond EOF. It adds new fsverity operations, read completion handling, unmapping changes in __xfs_bunmapi, and online scrub/repair checks for verity inodes. This code is fully reachable via ioctls (such as FS_IOC_ENABLE_VERITY) and normal file operations in virtualized environments.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "XFS_FS",
    "FS_VERITY",
    "XFS_ONLINE_SCRUB",
    "XFS_ONLINE_REPAIR"
  ],
  "FocusSymbols": [
    "xfs_fsverity_begin_enable",
    "xfs_fsverity_end_enable",
    "xfs_fsverity_get_descriptor",
    "xfs_fsverity_read_merkle",
    "xfs_fsverity_write_merkle",
    "xfs_fsverity_metadata_offset",
    "xfs_fsverity_is_file_data",
    "xfs_end_fsverity_io_read",
    "xchk_inode_setup_verity",
    "xchk_inode_verity_broken",
    "xrep_inode_verity",
    "xfs_dinode_verify"
  ],
  "Reasoning": "The patch adds fs-verity support to XFS, enabling file sealing and Merkle tree storage/verification beyond EOF. It adds new fsverity operations, read completion handling, unmapping changes in __xfs_bunmapi, and online scrub/repair checks for verity inodes. This code is fully reachable via ioctls (such as FS_IOC_ENABLE_VERITY) and normal file operations in virtualized environments.",
  "WorthFuzzing": true
}

21/1 2026/11/25 16:59 action If
4m Args:
{
  "WorthFuzzing": true
}

Results:
null

22/2 2026/11/25 16:59 agent kmsan-evaluator
4m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series adds fs-verity support to XFS, including filesystem format feature flags, fsverity operations (enable, descriptor read/write, Merkle tree read/write/readahead), ioctl routing (FS_IOC_ENABLE_VERITY, FS_IOC_MEASURE_VERITY, FS_IOC_READ_VERITY_METADATA), iomap integration, post-EOF Merkle tree management, and scrub/repair hooks.\n\nAnalysis of memory initialization and user-space exposure:\n1. All heap allocations (e.g., `struct xfs_fsverity_ioend` from the dedicated mempool) have all fields (`ioend`, `work`) immediately and fully initialized before use.\n2. User-facing data structures returned via ioctls (such as `xfs_fsop_geom` in `xfs_fs_geometry` and bulkstat structures) continue to be explicitly zeroed via `memset` before flags are populated.\n3. Reading of the fs-verity descriptor via `xfs_fsverity_get_descriptor()` reads exact byte counts (`desc_size`) from the page cache into the caller-provided buffer via `fsverity_pagecache_read()`, leaving no uninitialized buffer ranges.\n4. No uninitialized stack or heap variables are introduced, and no conditional logic branches on uninitialized memory.\n5. Potential bugs introduced by this patch primarily involve file offset/bounds calculations, extent manipulation, locking hierarchies (e.g. `IOLOCK`, `ILOCK`, `MMAPLOCK`), and refcounting, all of which are covered by standard KASAN and LOCKDEP configurations.\n\nBecause no uninitialized memory risks or kernel-to-user information leaks are introduced, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 74ac4fac1d6d7863985e11a962c39f9386871361
Author: syz-cluster <triage@syzkaller.com>
Date:   Wed Nov 25 16:34:45 2026 +0000

    syz-cluster: applied patch under review

diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index 399a207f2d0e71..9edb2850f09413 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -59,6 +59,7 @@ xfs-y				+= $(addprefix libxfs/, \
 				   xfs_trans_resv.o \
 				   xfs_trans_space.o \
 				   xfs_types.o \
+				   xfs_verity.o \
 				   )
 # xfs_rtbitmap is shared with libxfs
 xfs-$(CONFIG_XFS_RT)		+= $(addprefix libxfs/, \
@@ -150,6 +151,7 @@ xfs-$(CONFIG_XFS_POSIX_ACL)	+= xfs_acl.o
 xfs-$(CONFIG_SYSCTL)		+= xfs_sysctl.o
 xfs-$(CONFIG_COMPAT)		+= xfs_ioctl32.o
 xfs-$(CONFIG_EXPORTFS_BLOCK_OPS)	+= xfs_pnfs.o
+xfs-$(CONFIG_FS_VERITY)		+= xfs_fsverity.o
 
 # notify failure
 ifeq ($(CONFIG_MEMORY_FAILURE),y)
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 050522c58b168f..667b693aacb810 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -4414,7 +4414,7 @@ xfs_bmapi_convert_one_delalloc(
 	 * the extent.  Just return the real extent at this offset.
 	 */
 	if (!isnullstartblock(bma.got.br_startblock)) {
-		xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags,
+		xfs_bmbt_to_iomap(ip, iomap, &bma.got, offset, 0, flags,
 				xfs_iomap_inode_sequence(ip, flags));
 		if (seq)
 			*seq = READ_ONCE(ifp->if_seq);
@@ -4462,7 +4462,7 @@ xfs_bmapi_convert_one_delalloc(
 	XFS_STATS_INC(mp, xs_xstrat_quick);
 
 	ASSERT(!isnullstartblock(bma.got.br_startblock));
-	xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags,
+	xfs_bmbt_to_iomap(ip, iomap, &bma.got, offset, 0, flags,
 				xfs_iomap_inode_sequence(ip, flags));
 	if (seq)
 		*seq = READ_ONCE(ifp->if_seq);
@@ -5220,6 +5220,22 @@ __xfs_bunmapi(
 	ASSERT(len > 0);
 	ASSERT(nexts >= 0);
 
+	/*
+	 * XFS_BMAPI_UNWRITTEN is only used by fs-verity to drop unwritten
+	 * blocks past EOF while keeping written ones (fsverity metadata).
+	 *
+	 * The XFS_BMAPI_UNWRITTEN could not be used with realtime inodes with
+	 * realtime extent larger than 1 filesystem block. This is because the
+	 * realtime inode with larger extents could have EOF in the middle of
+	 * the extent. Removing these unwritten extent beyond EOF could lead to
+	 * removal of data before EOF.
+	 *
+	 * fs-verity is not allowed to be enabled on realtime files whose
+	 * extent size is larger than 1.
+	 */
+	ASSERT(!((flags & XFS_BMAPI_UNWRITTEN) &&
+		 xfs_inode_has_bigrtalloc(ip)));
+
 	error = xfs_iread_extents(tp, ip, whichfork);
 	if (error)
 		return error;
@@ -5281,6 +5297,10 @@ __xfs_bunmapi(
 		if (del.br_startoff + del.br_blockcount > end + 1)
 			del.br_blockcount = end + 1 - del.br_startoff;
 
+		if ((flags & XFS_BMAPI_UNWRITTEN) &&
+		    del.br_state != XFS_EXT_UNWRITTEN)
+			goto skip;
+
 		if (!isrt || (flags & XFS_BMAPI_REMAP))
 			goto delete;
 
@@ -5415,7 +5435,7 @@ __xfs_bunmapi(
 			if (error)
 				goto error0;
 		}
-
+skip:
 		end = del.br_startoff - 1;
 nodelete:
 		/*
diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h
index fb7481e8190c64..f1df6b4b695e0b 100644
--- a/fs/xfs/libxfs/xfs_bmap.h
+++ b/fs/xfs/libxfs/xfs_bmap.h
@@ -97,6 +97,9 @@ struct xfs_bmalloca {
  */
 #define XFS_BMAPI_CONVERT_ONLY	(1u << 12)
 
+/* Process unwritten extents only. Used for unmapping */
+#define XFS_BMAPI_UNWRITTEN	(1u << 13)
+
 #define XFS_BMAPI_FLAGS \
 	{ XFS_BMAPI_ENTIRE,	"ENTIRE" }, \
 	{ XFS_BMAPI_METADATA,	"METADATA" }, \
@@ -110,7 +113,8 @@ struct xfs_bmalloca {
 	{ XFS_BMAPI_NODISCARD,	"NODISCARD" }, \
 	{ XFS_BMAPI_NORMAP,	"NORMAP" },\
 	{ XFS_BMAPI_EXTSZALIGN,	"EXTSZALIGN" }, \
-	{ XFS_BMAPI_CONVERT_ONLY,	"CONVERT_ONLY" }
+	{ XFS_BMAPI_CONVERT_ONLY,	"CONVERT_ONLY" }, \
+	{ XFS_BMAPI_UNWRITTEN,	"UNWRITTEN" }
 
 
 static inline int xfs_bmapi_aflag(int w)
diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 469e879149ac21..16d6e8931df069 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -374,11 +374,13 @@ xfs_sb_has_compat_feature(
 #define XFS_SB_FEAT_RO_COMPAT_RMAPBT   (1 << 1)		/* reverse map btree */
 #define XFS_SB_FEAT_RO_COMPAT_REFLINK  (1 << 2)		/* reflinked files */
 #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)		/* inobt block counts */
+#define XFS_SB_FEAT_RO_COMPAT_VERITY   (1 << 4)		/* fs-verity */
 #define XFS_SB_FEAT_RO_COMPAT_ALL \
 		(XFS_SB_FEAT_RO_COMPAT_FINOBT | \
 		 XFS_SB_FEAT_RO_COMPAT_RMAPBT | \
-		 XFS_SB_FEAT_RO_COMPAT_REFLINK| \
-		 XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
+		 XFS_SB_FEAT_RO_COMPAT_REFLINK | \
+		 XFS_SB_FEAT_RO_COMPAT_INOBTCNT | \
+		 XFS_SB_FEAT_RO_COMPAT_VERITY)
 #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN	~XFS_SB_FEAT_RO_COMPAT_ALL
 static inline bool
 xfs_sb_has_ro_compat_feature(
@@ -1234,16 +1236,21 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
  */
 #define XFS_DIFLAG2_METADATA_BIT	5
 
+/* inodes sealed with fs-verity */
+#define XFS_DIFLAG2_VERITY_BIT		6
+
 #define XFS_DIFLAG2_DAX		(1ULL << XFS_DIFLAG2_DAX_BIT)
 #define XFS_DIFLAG2_REFLINK	(1ULL << XFS_DIFLAG2_REFLINK_BIT)
 #define XFS_DIFLAG2_COWEXTSIZE	(1ULL << XFS_DIFLAG2_COWEXTSIZE_BIT)
 #define XFS_DIFLAG2_BIGTIME	(1ULL << XFS_DIFLAG2_BIGTIME_BIT)
 #define XFS_DIFLAG2_NREXT64	(1ULL << XFS_DIFLAG2_NREXT64_BIT)
 #define XFS_DIFLAG2_METADATA	(1ULL << XFS_DIFLAG2_METADATA_BIT)
+#define XFS_DIFLAG2_VERITY	(1ULL << XFS_DIFLAG2_VERITY_BIT)
 
 #define XFS_DIFLAG2_ANY \
 	(XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \
-	 XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA)
+	 XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA | \
+	 XFS_DIFLAG2_VERITY)
 
 static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)
 {
@@ -2031,4 +2038,22 @@ struct xfs_acl {
 #define SGI_ACL_FILE_SIZE	(sizeof(SGI_ACL_FILE)-1)
 #define SGI_ACL_DEFAULT_SIZE	(sizeof(SGI_ACL_DEFAULT)-1)
 
+/*
+ * fs-verity stores the Merkle tree in the data fork past EOF, so the file data
+ * blocks and the tree blocks share the inode's xfs_fileoff_t address space.
+ * Cap a verity file at half of the addressable file-offset range (in filesystem
+ * blocks) so the Merkle tree always fits in the other half.
+ */
+#define XFS_FSVERITY_LARGEST_FILE_FSB(mp) \
+	(XFS_B_TO_FSBT((mp), MAX_LFS_FILESIZE) >> 1)
+
+/*
+ * Alignment of the fsverity metadata placement. This is largest supported PAGE
+ * SIZE for fsverity. This is used to space out data and metadata in page cache.
+ * The spacing is necessary for non-exposure of metadata to userspace and
+ * correct merkle tree synthesis in the iomap.
+ */
+#define XFS_FSVERITY_START_ALIGN	(65536)
+
+
 #endif /* __XFS_FORMAT_H__ */
diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h
index 185f09f327c00c..84d62b7506a9ad 100644
--- a/fs/xfs/libxfs/xfs_fs.h
+++ b/fs/xfs/libxfs/xfs_fs.h
@@ -250,6 +250,7 @@ typedef struct xfs_fsop_resblks {
 #define XFS_FSOP_GEOM_FLAGS_PARENT	(1 << 25) /* linux parent pointers */
 #define XFS_FSOP_GEOM_FLAGS_METADIR	(1 << 26) /* metadata directories */
 #define XFS_FSOP_GEOM_FLAGS_ZONED	(1 << 27) /* zoned rt device */
+#define XFS_FSOP_GEOM_FLAGS_VERITY	(1 << 28) /* fs-verity */
 
 /*
  * Minimum and maximum sizes need for growth checks.
@@ -421,6 +422,7 @@ struct xfs_bulkstat {
 #define XFS_BS_SICK_SYMLINK	(1 << 6)  /* symbolic link remote target */
 #define XFS_BS_SICK_PARENT	(1 << 7)  /* parent pointers */
 #define XFS_BS_SICK_DIRTREE	(1 << 8)  /* directory tree structure */
+#define XFS_BS_SICK_FSVERITY	(1 << 9)  /* fsverity metadata */
 
 /*
  * Project quota id helpers (previously projid was 16bit only
diff --git a/fs/xfs/libxfs/xfs_health.h b/fs/xfs/libxfs/xfs_health.h
index 1d45cf5789e864..932b447190da76 100644
--- a/fs/xfs/libxfs/xfs_health.h
+++ b/fs/xfs/libxfs/xfs_health.h
@@ -104,6 +104,7 @@ struct xfs_rtgroup;
 /* Don't propagate sick status to ag health summary during inactivation */
 #define XFS_SICK_INO_FORGET	(1 << 12)
 #define XFS_SICK_INO_DIRTREE	(1 << 13)  /* directory tree structure */
+#define XFS_SICK_INO_FSVERITY	(1 << 14)  /* fsverity metadata */
 
 /* Primary evidence of health problems in a given group. */
 #define XFS_SICK_FS_PRIMARY	(XFS_SICK_FS_COUNTERS | \
@@ -140,7 +141,8 @@ struct xfs_rtgroup;
 				 XFS_SICK_INO_XATTR | \
 				 XFS_SICK_INO_SYMLINK | \
 				 XFS_SICK_INO_PARENT | \
-				 XFS_SICK_INO_DIRTREE)
+				 XFS_SICK_INO_DIRTREE | \
+				 XFS_SICK_INO_FSVERITY)
 
 #define XFS_SICK_INO_ZAPPED	(XFS_SICK_INO_BMBTD_ZAPPED | \
 				 XFS_SICK_INO_BMBTA_ZAPPED | \
diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c
index 8c9d296ebfe97f..fdcfc1f3f472b5 100644
--- a/fs/xfs/libxfs/xfs_inode_buf.c
+++ b/fs/xfs/libxfs/xfs_inode_buf.c
@@ -758,6 +758,25 @@ xfs_dinode_verify(
 	    !xfs_has_rtreflink(mp))
 		return __this_address;
 
+	/* only regular files can have fsverity */
+	if (flags2 & XFS_DIFLAG2_VERITY) {
+		if (!xfs_has_verity(mp))
+			return __this_address;
+		if (!S_ISREG(mode))
+			return __this_address;
+		/*
+		 * fs-verity stores the Merkle tree past EOF, so it cannot
+		 * coexist with a realtime allocation unit larger than a single
+		 * filesystem block. This is because we remove any unwritten
+		 * extents beyond EOF for fs-verity inodes. The realtime inode
+		 * with larger extents could have EOF in the middle of the
+		 * extent. Enabling fsverity on such inode could lead to removal
+		 * of data before EOF.
+		 */
+		if ((flags & XFS_DIFLAG_REALTIME) && mp->m_sb.sb_rextsize > 1)
+			return __this_address;
+	}
+
 	if (xfs_has_zoned(mp) &&
 	    dip->di_metatype == cpu_to_be16(XFS_METAFILE_RTRMAP)) {
 		if (be32_to_cpu(dip->di_used_blocks) > mp->m_sb.sb_rgextents)
diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c
index f486b23a9b5230..a717b19558afab 100644
--- a/fs/xfs/libxfs/xfs_inode_util.c
+++ b/fs/xfs/libxfs/xfs_inode_util.c
@@ -73,7 +73,8 @@ xfs_flags2diflags2(
 	uint64_t		di_flags2 =
 		(ip->i_diflags2 & (XFS_DIFLAG2_REFLINK |
 				   XFS_DIFLAG2_BIGTIME |
-				   XFS_DIFLAG2_NREXT64));
+				   XFS_DIFLAG2_NREXT64 |
+				   XFS_DIFLAG2_VERITY));
 
 	if (xflags & FS_XFLAG_DAX)
 		di_flags2 |= XFS_DIFLAG2_DAX;
@@ -125,6 +126,8 @@ xfs_ip2xflags(
 			flags |= FS_XFLAG_DAX;
 		if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE)
 			flags |= FS_XFLAG_COWEXTSIZE;
+		if (ip->i_diflags2 & XFS_DIFLAG2_VERITY)
+			flags |= FS_XFLAG_VERITY;
 	}
 
 	if (xfs_inode_has_attr_fork(ip))
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index ce44123c98cef6..3323b8dcc7939b 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -164,6 +164,8 @@ xfs_sb_version_to_features(
 		features |= XFS_FEAT_REFLINK;
 	if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
 		features |= XFS_FEAT_INOBTCNT;
+	if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_VERITY)
+		features |= XFS_FEAT_VERITY;
 	if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_FTYPE)
 		features |= XFS_FEAT_FTYPE;
 	if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_SPINODES)
@@ -1544,6 +1546,8 @@ xfs_fs_geometry(
 		geo->flags |= XFS_FSOP_GEOM_FLAGS_METADIR;
 	if (xfs_has_zoned(mp))
 		geo->flags |= XFS_FSOP_GEOM_FLAGS_ZONED;
+	if (xfs_has_verity(mp))
+		geo->flags |= XFS_FSOP_GEOM_FLAGS_VERITY;
 	geo->rtsectsize = sbp->sb_blocksize;
 	geo->dirblocksize = xfs_dir2_dirblock_bytes(sbp);
 
diff --git a/fs/xfs/libxfs/xfs_verity.c b/fs/xfs/libxfs/xfs_verity.c
new file mode 100644
index 00000000000000..c1731b89a5a12c
--- /dev/null
+++ b/fs/xfs/libxfs/xfs_verity.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#include "xfs_platform.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_log_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_inode.h"
+#include "xfs_verity.h"
+
+loff_t
+xfs_fsverity_metadata_offset(
+	const struct xfs_inode	*ip)
+{
+	return round_up(i_size_read(VFS_IC(ip)), XFS_FSVERITY_START_ALIGN);
+}
diff --git a/fs/xfs/libxfs/xfs_verity.h b/fs/xfs/libxfs/xfs_verity.h
new file mode 100644
index 00000000000000..da90f798faa8d6
--- /dev/null
+++ b/fs/xfs/libxfs/xfs_verity.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#ifndef __XFS_VERITY_H__
+#define __XFS_VERITY_H__
+
+#include "xfs_platform.h"
+#include <linux/fsverity.h>
+
+loff_t xfs_fsverity_metadata_offset(const struct xfs_inode *ip);
+
+#endif	/* __XFS_VERITY_H__ */
diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c
index cbfe5e6f779dfc..fb0ae227df54a8 100644
--- a/fs/xfs/scrub/common.c
+++ b/fs/xfs/scrub/common.c
@@ -45,6 +45,8 @@
 #include "scrub/health.h"
 #include "scrub/tempfile.h"
 
+#include <linux/fsverity.h>
+
 /* Common code for the metadata scrubbers. */
 
 /*
@@ -1765,3 +1767,54 @@ xchk_inode_count_blocks(
 	return xfs_bmap_count_blocks(sc->tp, sc->ip, whichfork, nextents,
 			count);
 }
+
+/*
+ * If this inode has S_VERITY set on it, read the verity info. If the reading
+ * fails with anything other than ENOMEM, the file is corrupt, which we can
+ * detect later with fsverity_active.
+ *
+ * Callers must hold the IOLOCK and must not hold the ILOCK of sc->ip because
+ * activation reads inode data.
+ */
+int
+xchk_inode_setup_verity(
+	struct xfs_scrub	*sc)
+{
+	int			error;
+
+	if (!fsverity_active(VFS_I(sc->ip)))
+		return 0;
+
+	error = fsverity_ensure_verity_info(VFS_I(sc->ip));
+	switch (error) {
+	case 0:
+		/* fsverity is active */
+		break;
+	case -ENODATA:
+	case -EMSGSIZE:
+	case -EFSCORRUPTED:
+	case -ERANGE:
+	case -EBADMSG:
+		/*
+		 * The nonzero errno codes above are the error codes that can
+		 * be returned from fsverity on metadata validation errors.
+		 */
+		return 0;
+	default:
+		/* runtime errors */
+		return error;
+	}
+
+	return 0;
+}
+
+/*
+ * Is this a verity file that failed to activate?  Callers must have tried to
+ * activate fsverity via xchk_inode_setup_verity.
+ */
+bool
+xchk_inode_verity_broken(
+	struct xfs_inode	*ip)
+{
+	return fsverity_active(VFS_I(ip)) && !fsverity_get_info(VFS_I(ip));
+}
diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h
index 181028f0c65526..b59d4792a80507 100644
--- a/fs/xfs/scrub/common.h
+++ b/fs/xfs/scrub/common.h
@@ -261,6 +261,8 @@ int xchk_inode_is_allocated(struct xfs_scrub *sc, xfs_agino_t agino,
 		bool *inuse);
 int xchk_inode_count_blocks(struct xfs_scrub *sc, int whichfork,
 		xfs_extnum_t *nextents, xfs_filblks_t *count);
+int xchk_inode_setup_verity(struct xfs_scrub *sc);
+bool xchk_inode_verity_broken(struct xfs_inode *ip);
 
 bool xchk_inode_is_dirtree_root(const struct xfs_inode *ip);
 bool xchk_inode_is_sb_rooted(const struct xfs_inode *ip);
diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c
index bb8d2bc008e019..931c677d7ac8d4 100644
--- a/fs/xfs/scrub/inode.c
+++ b/fs/xfs/scrub/inode.c
@@ -33,9 +33,28 @@ xchk_prepare_iscrub(
 	struct xfs_scrub	*sc)
 {
 	int			error;
+	struct xfs_inode	*ip = sc->ip;
 
 	xchk_ilock(sc, XFS_IOLOCK_EXCL);
 
+	error = xchk_inode_setup_verity(sc);
+	if (error)
+		return error;
+
+	/*
+	 * If we're going to repair a file whose fsverity descriptor cannot be
+	 * activated, drop the stale Merkle tree folios. Once the
+	 * post-EOF Merkle extents are freed during repair, those uptodate
+	 * folios would otherwise sit over a hole and could be exposed as file
+	 * data by a later extending write or truncate.
+	 *
+	 * The lock would be unlocked by global scrub machinery.
+	 */
+	if (xchk_could_repair(sc) && xchk_inode_verity_broken(ip)) {
+		xchk_ilock(sc, XFS_MMAPLOCK_EXCL);
+		truncate_inode_pages(VFS_I(ip)->i_mapping, XFS_ISIZE(ip));
+	}
+
 	error = xchk_trans_alloc(sc, 0);
 	if (error)
 		return error;
@@ -833,6 +852,9 @@ xchk_inode(
 	if (S_ISREG(VFS_I(sc->ip)->i_mode))
 		xchk_inode_check_reflink_iflag(sc, I_INO(sc->ip));
 
+	if (xchk_inode_verity_broken(sc->ip))
+		xchk_ino_set_corrupt(sc, sc->sm->sm_ino);
+
 	xchk_inode_check_unlinked(sc);
 
 	xchk_inode_xref(sc, I_INO(sc->ip), &di);
diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c
index a9ccf763c05969..ddf3c3dce2f939 100644
--- a/fs/xfs/scrub/inode_repair.c
+++ b/fs/xfs/scrub/inode_repair.c
@@ -577,6 +577,8 @@ xrep_dinode_flags(
 		dip->di_nrext64_pad = 0;
 	else if (dip->di_version >= 3)
 		dip->di_v3_pad = 0;
+	if (!xfs_has_verity(mp) || !S_ISREG(mode))
+		flags2 &= ~XFS_DIFLAG2_VERITY;
 
 	if (flags2 & XFS_DIFLAG2_METADATA) {
 		xfs_failaddr_t	fa;
@@ -1659,6 +1661,10 @@ xrep_dinode_core(
 	if (iget_error)
 		return iget_error;
 
+	error = xchk_inode_setup_verity(sc);
+	if (error)
+		return error;
+
 	error = xchk_trans_alloc(sc, 0);
 	if (error)
 		return error;
@@ -2198,6 +2204,40 @@ xrep_inode_reset_dquots(
 # define xrep_inode_reset_dquots(sc)		(0)
 #endif
 
+/*
+ * If this file is a fsverity file, xchk_prepare_iscrub or xrep_dinode_core
+ * should have activated it.  If it's still not active, then there's something
+ * wrong with the verity descriptor, so turn verity off and free the orphaned
+ * Merkle tree that XFS keeps in extents beyond EOF.
+ */
+STATIC int
+xrep_inode_verity(
+	struct xfs_scrub	*sc)
+{
+	struct inode		*inode = VFS_I(sc->ip);
+	struct xfs_mount	*mp = sc->mp;
+	int			error;
+
+	if (!xchk_inode_verity_broken(sc->ip))
+		return 0;
+
+	/*
+	 * The fsverity descriptor cannot be activated, so disable verity and
+	 * free the Merkle tree, which XFS stores in beyond EOF. The stale
+	 * Merkle tree page cache was already dropped during scrub setup.
+	 */
+	error = xfs_bunmapi_range(&sc->tp, sc->ip, 0,
+			XFS_B_TO_FSB(mp, XFS_ISIZE(sc->ip)), XFS_MAX_FILEOFF);
+	if (error)
+		return error;
+
+	sc->ip->i_diflags2 &= ~XFS_DIFLAG2_VERITY;
+	inode_set_flags(inode, 0, S_VERITY);
+
+	xfs_trans_log_inode(sc->tp, sc->ip, XFS_ILOG_CORE);
+	return 0;
+}
+
 /* Repair an inode's fields. */
 int
 xrep_inode(
@@ -2247,6 +2287,15 @@ xrep_inode(
 			return error;
 	}
 
+	/*
+	 * Disable fsverity if it cannot be activated.  Activation failure
+	 * prohibits the file from being opened, so there cannot be another
+	 * program with an open fd to what it thinks is a verity file.
+	 */
+	error = xrep_inode_verity(sc);
+	if (error)
+		return error;
+
 	/* Reconnect incore unlinked list */
 	error = xrep_inode_unlinked(sc);
 	if (error)
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 1db6f3640c53bd..971be3c0973161 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -23,6 +23,8 @@
 #include "xfs_ioend.h"
 #include "xfs_zone_alloc.h"
 #include "xfs_rtgroup.h"
+#include "xfs_verity.h"
+#include "xfs_fsverity.h"
 
 struct xfs_writepage_ctx {
 	struct iomap_writepage_ctx ctx;
@@ -265,7 +267,8 @@ xfs_map_blocks(
 	    isnullstartblock(imap.br_startblock))
 		goto allocate_blocks;
 
-	xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, 0, 0, XFS_WPC(wpc)->data_seq);
+	xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, offset, 0, 0,
+			  XFS_WPC(wpc)->data_seq);
 	trace_xfs_map_blocks_found(ip, offset, count, whichfork, &imap);
 	return 0;
 allocate_blocks:
@@ -441,7 +444,7 @@ xfs_zoned_map_blocks(
 		imap.br_startblock = HOLESTARTBLOCK;
 		imap.br_state = XFS_EXT_NORM;
 		xfs_iunlock(ip, XFS_ILOCK_EXCL);
-		xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, 0, 0, 0);
+		xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, offset, 0, 0, 0);
 		return 0;
 	}
 	end_fsb = min(end_fsb, imap.br_startoff + imap.br_blockcount);
@@ -585,7 +588,7 @@ xfs_bio_submit_read(
 {
 	xfs_ioend_submit_read(iter->inode, ctx->read_ctx,
 			ctx->read_ctx_file_offset,
-			iomap_ioend_flags(&iter->iomap));
+			iomap_ioend_flags(&iter->iomap), ctx->vi);
 	ctx->read_ctx = NULL;
 }
 
@@ -597,11 +600,13 @@ static const struct iomap_read_ops xfs_iomap_read_ops = {
 
 static inline const struct iomap_read_ops *
 xfs_get_iomap_read_ops(
-	const struct address_space	*mapping)
+	const struct address_space	*mapping,
+	loff_t				pos)
 {
 	struct xfs_inode		*ip = XFS_I(mapping->host);
 
-	if (bdev_has_integrity_csum(xfs_inode_buftarg(ip)->bt_bdev))
+	if (bdev_has_integrity_csum(xfs_inode_buftarg(ip)->bt_bdev) ||
+	    xfs_fsverity_is_file_data(ip, pos))
 		return &xfs_iomap_read_ops;
 	return &iomap_bio_read_ops;
 }
@@ -613,7 +618,7 @@ xfs_vm_read_folio(
 {
 	struct iomap_read_folio_ctx	ctx = { .cur_folio = folio };
 
-	ctx.ops = xfs_get_iomap_read_ops(folio->mapping);
+	ctx.ops = xfs_get_iomap_read_ops(folio->mapping, folio_pos(folio));
 	iomap_read_folio(xfs_read_iomap_next, &ctx, NULL);
 	return 0;
 }
@@ -624,7 +629,7 @@ xfs_vm_readahead(
 {
 	struct iomap_read_folio_ctx	ctx = { .rac = rac };
 
-	ctx.ops = xfs_get_iomap_read_ops(rac->mapping),
+	ctx.ops = xfs_get_iomap_read_ops(rac->mapping, readahead_pos(rac));
 	iomap_readahead(xfs_read_iomap_next, &ctx, NULL);
 }
 
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 865aec3ae5ab32..d6130cfc8246d9 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -31,6 +31,7 @@
 #include "xfs_rtbitmap.h"
 #include "xfs_rtgroup.h"
 #include "xfs_zone_alloc.h"
+#include <linux/fsverity.h>
 
 /* Kernel only BMAP related definitions and functions */
 
@@ -553,6 +554,17 @@ xfs_can_free_eofblocks(
 	if (last_fsb <= end_fsb)
 		return false;
 
+	/*
+	 * Don't clean fsverity inodes as they already have been cleaned up and
+	 * are read-only. Skip inodes which have merkle tree being built, the
+	 * merkle tree is written beyond EOF. Skip inodes which have
+	 * XFS_DIFLAG2_VERITY in case this kernel has fsverity disabled.
+	 */
+	if (fsverity_active(VFS_IC(ip)) ||
+	    fsverity_is_building(VFS_I(ip)) ||
+	    ip->i_diflags2 & XFS_DIFLAG2_VERITY)
+		return false;
+
 	/*
 	 * Check if there is an post-EOF extent to free.  If there are any
 	 * delalloc blocks attached to the inode (data fork delalloc
@@ -579,6 +591,8 @@ xfs_free_eofblocks(
 	struct xfs_trans	*tp;
 	struct xfs_mount	*mp = ip->i_mount;
 	int			error;
+	int			bmapi_flags = XFS_BMAPI_NODISCARD;
+	bool			verity = fsverity_is_building(VFS_I(ip));
 
 	/* Attach the dquots to the inode up front. */
 	error = xfs_qm_dqattach(ip);
@@ -593,15 +607,20 @@ xfs_free_eofblocks(
 	 *
 	 * Note that this means we also leave speculative preallocations in
 	 * place for preallocated files.
+	 *
+	 * Clean up delalloc reservations for fsverity too as those won't be
+	 * used
 	 */
-	if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) {
+	if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND) ||
+			verity) {
 		if (ip->i_delayed_blks) {
 			xfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK,
 				round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize),
 				LLONG_MAX, NULL);
 		}
 		xfs_inode_clear_eofblocks_tag(ip);
-		return 0;
+		if (!verity)
+			return 0;
 	}
 
 	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
@@ -613,6 +632,13 @@ xfs_free_eofblocks(
 	xfs_ilock(ip, XFS_ILOCK_EXCL);
 	xfs_trans_ijoin(tp, ip, 0);
 
+	/*
+	 * While fs-verity writes metadata after EOF, it can leave unwritten
+	 * preallocations.  Clear all that out.
+	 */
+	if (verity)
+		bmapi_flags |= XFS_BMAPI_UNWRITTEN;
+
 	/*
 	 * Do not update the on-disk file size.  If we update the on-disk file
 	 * size and then the system crashes before the contents of the file are
@@ -620,7 +646,7 @@ xfs_free_eofblocks(
 	 * bug).
 	 */
 	error = xfs_itruncate_extents_flags(&tp, ip, XFS_DATA_FORK,
-				XFS_ISIZE(ip), XFS_BMAPI_NODISCARD);
+				XFS_ISIZE(ip), bmapi_flags);
 	if (error)
 		goto err_cancel;
 
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index d61ea8e2c8e40c..94835d6153420b 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -38,6 +38,7 @@
 #include <linux/mount.h>
 #include <linux/filelock.h>
 #include <linux/bio-integrity.h>
+#include <linux/fsverity.h>
 
 static const struct vm_operations_struct xfs_file_vm_ops;
 
@@ -181,7 +182,8 @@ xfs_dio_read_bounce_submit_io(
 	loff_t			file_offset)
 {
 	xfs_ioend_submit_read(iter->inode, bio, file_offset,
-			iomap_ioend_flags(&iter->iomap) | IOMAP_IOEND_DIRECT);
+			iomap_ioend_flags(&iter->iomap) | IOMAP_IOEND_DIRECT,
+			NULL);
 }
 
 static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {
@@ -189,6 +191,25 @@ static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {
 	.bio_set	= &iomap_ioend_bioset,
 };
 
+STATIC ssize_t
+xfs_file_buffered_read(
+	struct kiocb		*iocb,
+	struct iov_iter		*to)
+{
+	struct xfs_inode	*ip = XFS_I(file_inode(iocb->ki_filp));
+	ssize_t			ret;
+
+	trace_xfs_file_buffered_read(iocb, to);
+
+	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
+	if (ret)
+		return ret;
+	ret = generic_file_read_iter(iocb, to);
+	xfs_iunlock(ip, XFS_IOLOCK_SHARED);
+
+	return ret;
+}
+
 STATIC ssize_t
 xfs_file_dio_read(
 	struct kiocb		*iocb,
@@ -207,6 +228,17 @@ xfs_file_dio_read(
 	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
 	if (ret)
 		return ret;
+
+	/*
+	 * Re-check verity status after acquiring lock. This prevents TOCTOU in
+	 * xfs_file_read_iter() while falling back from DIO to buffered I/O as
+	 * now we are holding a lock
+	 */
+	if (fsverity_active(VFS_I(ip))) {
+		xfs_iunlock(ip, XFS_IOLOCK_SHARED);
+		iocb->ki_flags &= ~IOCB_DIRECT;
+		return xfs_file_buffered_read(iocb, to);
+	}
 	if (mapping_stable_writes(iocb->ki_filp->f_mapping)) {
 		ret = iomap_dio_rw(iocb, to, xfs_read_iomap_next,
 				&xfs_dio_read_bounce_ops, 0, NULL, 0);
@@ -226,7 +258,8 @@ xfs_file_dax_read(
 	struct kiocb		*iocb,
 	struct iov_iter		*to)
 {
-	struct xfs_inode	*ip = XFS_I(iocb->ki_filp->f_mapping->host);
+	struct inode		*inode = iocb->ki_filp->f_mapping->host;
+	struct xfs_inode	*ip = XFS_I(inode);
 	ssize_t			ret = 0;
 
 	trace_xfs_file_dax_read(iocb, to);
@@ -244,25 +277,6 @@ xfs_file_dax_read(
 	return ret;
 }
 
-STATIC ssize_t
-xfs_file_buffered_read(
-	struct kiocb		*iocb,
-	struct iov_iter		*to)
-{
-	struct xfs_inode	*ip = XFS_I(file_inode(iocb->ki_filp));
-	ssize_t			ret;
-
-	trace_xfs_file_buffered_read(iocb, to);
-
-	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
-	if (ret)
-		return ret;
-	ret = generic_file_read_iter(iocb, to);
-	xfs_iunlock(ip, XFS_IOLOCK_SHARED);
-
-	return ret;
-}
-
 STATIC ssize_t
 xfs_file_read_iter(
 	struct kiocb		*iocb,
@@ -277,6 +291,14 @@ xfs_file_read_iter(
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
+	/*
+	 * In case fs-verity is enabled, we also fallback to the buffered read
+	 * from the direct read path. Therefore, IOCB_DIRECT is set and need to
+	 * be cleared (see generic_file_read_iter())
+	 */
+	if (fsverity_active(inode))
+		iocb->ki_flags &= ~IOCB_DIRECT;
+
 	if (IS_DAX(inode))
 		ret = xfs_file_dax_read(iocb, to);
 	else if (iocb->ki_flags & IOCB_DIRECT)
@@ -1731,11 +1753,18 @@ xfs_file_open(
 	struct inode	*inode,
 	struct file	*file)
 {
+	int		error;
+
 	if (xfs_is_shutdown(XFS_M(inode->i_sb)))
 		return -EIO;
 	file->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT;
 	if (xfs_get_atomic_write_min(XFS_I(inode)) > 0)
 		file->f_mode |= FMODE_CAN_ATOMIC_WRITE;
+
+	error = fsverity_file_open(inode, file);
+	if (error)
+		return error;
+
 	return generic_file_open(inode, file);
 }
 
diff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c
new file mode 100644
index 00000000000000..36520a187a2c70
--- /dev/null
+++ b/fs/xfs/xfs_fsverity.c
@@ -0,0 +1,509 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#include "xfs_platform.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_inode.h"
+#include "xfs_log_format.h"
+#include "xfs_trans.h"
+#include "xfs_trace.h"
+#include "xfs_quota.h"
+#include "xfs_fsverity.h"
+#include "xfs_iomap.h"
+#include "xfs_error.h"
+#include "xfs_health.h"
+#include "xfs_bmap_util.h"
+#include "xfs_icache.h"
+#include <linux/fsverity.h>
+#include <linux/iomap.h>
+#include <linux/pagemap.h>
+
+struct kmem_cache *xfs_fsverity_ioend_cache;
+mempool_t xfs_fsverity_ioend_pool;
+
+#define XFS_FSVERITY_IOEND_POOL_MIN	128
+
+/*
+ * Back the fsverity ioend allocations with a mempool so that read I/O
+ * completion always makes forward progress and cannot deadlock
+ */
+int
+xfs_fsverity_init(void)
+{
+	return mempool_init_slab_pool(&xfs_fsverity_ioend_pool,
+			XFS_FSVERITY_IOEND_POOL_MIN, xfs_fsverity_ioend_cache);
+}
+
+void
+xfs_fsverity_exit(void)
+{
+	mempool_exit(&xfs_fsverity_ioend_pool);
+}
+
+bool
+xfs_fsverity_is_file_data(
+	const struct xfs_inode	*ip,
+	loff_t			offset)
+{
+	return fsverity_active(VFS_IC(ip)) &&
+			offset < xfs_fsverity_metadata_offset(ip);
+}
+
+/*
+ * Retrieve the verity descriptor.
+ */
+static int
+xfs_fsverity_get_descriptor(
+	struct inode		*inode,
+	void			*buf,
+	size_t			buf_size)
+{
+	struct xfs_inode	*ip = XFS_I(inode);
+	struct xfs_mount	*mp = ip->i_mount;
+	__be32			d_desc_size;
+	u32			desc_size;
+	u64			desc_size_pos;
+	int			error;
+	u64			desc_pos;
+	struct xfs_bmbt_irec	rec;
+	int			is_empty;
+	uint32_t		blocksize = i_blocksize(VFS_I(ip));
+	xfs_fileoff_t		last_block_offset;
+
+	/*
+	 * fs-verity cannot be used when the filesystem block size exceeds the
+	 * page size, as the Merkle tree folios are compound and PG_checked is
+	 * not supported on compound folios.  Reject such inodes so that they
+	 * cannot be opened and read as verity files.
+	 */
+	if (mp->m_sb.sb_blocksize > PAGE_SIZE)
+		return -EOPNOTSUPP;
+
+	xfs_ilock(ip, XFS_ILOCK_EXCL);
+	/*
+	 * Serialize reading of inode->i_flags with xfs_scrub clearing of this
+	 * flag if inode is corrupted.
+	 */
+	if (!(inode->i_flags & S_VERITY)) {
+		xfs_iunlock(ip, XFS_ILOCK_EXCL);
+		return -ENODATA;
+	}
+	error = xfs_bmap_last_extent(NULL, ip, XFS_DATA_FORK, &rec, &is_empty);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	if (error)
+		return error;
+
+	if (is_empty) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ENODATA;
+	}
+
+	/*
+	 * Make sure we can open large file on a 32-bit kernel
+	 */
+	if (rec.br_startoff + rec.br_blockcount >
+			XFS_B_TO_FSB(mp, inode->i_sb->s_maxbytes))
+		return -EFBIG;
+
+	last_block_offset =
+		XFS_FSB_TO_B(mp, rec.br_startoff + rec.br_blockcount);
+	if (last_block_offset <= xfs_fsverity_metadata_offset(ip)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ENODATA;
+	}
+
+	desc_size_pos = last_block_offset - sizeof(__be32);
+	error = fsverity_pagecache_read(inode, (char *)&d_desc_size,
+			sizeof(d_desc_size), desc_size_pos);
+	if (error)
+		return error;
+
+	desc_size = be32_to_cpu(d_desc_size);
+	if (XFS_IS_CORRUPT(mp, desc_size > FS_VERITY_MAX_DESCRIPTOR_SIZE)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	if (XFS_IS_CORRUPT(mp, desc_size > desc_size_pos)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	if (!buf_size)
+		return desc_size;
+
+	if (XFS_IS_CORRUPT(mp, desc_size > buf_size)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	desc_pos = round_down(desc_size_pos - desc_size, blocksize);
+	if (desc_pos < xfs_fsverity_metadata_offset(ip)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	error = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);
+	if (error)
+		return error;
+
+	return desc_size;
+}
+
+static int
+xfs_fsverity_write_descriptor(
+	struct file		*file,
+	const void		*desc,
+	u32			desc_size,
+	u64			merkle_tree_size)
+{
+	int			error;
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	unsigned int		blksize = ip->i_mount->m_sb.sb_blocksize;
+	u64			tree_last_block =
+			xfs_fsverity_metadata_offset(ip) + merkle_tree_size;
+	u64			desc_pos =
+			round_up(tree_last_block, XFS_FSVERITY_START_ALIGN);
+	u64			desc_end = desc_pos + desc_size;
+	__be32			desc_size_disk = cpu_to_be32(desc_size);
+	u64			desc_size_pos =
+			round_up(desc_end + sizeof(desc_size_disk), blksize) -
+			sizeof(desc_size_disk);
+
+	if (desc_size_pos + sizeof(desc_size_disk) > inode->i_sb->s_maxbytes)
+		return -EFBIG;
+
+	error = iomap_fsverity_write(file, desc_size_pos, sizeof(__be32),
+			(const void *)&desc_size_disk,
+			xfs_buffered_write_iomap_next,
+			&xfs_iomap_write_ops);
+	if (error)
+		return error;
+
+	return iomap_fsverity_write(file, desc_pos, desc_size, desc,
+			xfs_buffered_write_iomap_next,
+			&xfs_iomap_write_ops);
+}
+
+/*
+ * Try to remove all the fsverity metadata after a failed enablement.
+ */
+static int
+xfs_fsverity_delete_metadata(
+	struct xfs_inode	*ip)
+{
+	struct xfs_trans	*tp;
+	struct xfs_mount	*mp = ip->i_mount;
+	int			error;
+
+	xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
+	truncate_inode_pages(VFS_I(ip)->i_mapping, XFS_ISIZE(ip));
+
+	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
+	if (error) {
+		xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
+		return error;
+	}
+
+	xfs_ilock(ip, XFS_ILOCK_EXCL);
+	xfs_trans_ijoin(tp, ip, 0);
+
+	/*
+	 * We remove post EOF data, no need to update i_size as fsverity
+	 * didn't move i_size in the first place
+	 */
+	error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, XFS_ISIZE(ip));
+	if (error)
+		goto err_cancel;
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);
+	return error;
+err_cancel:
+	xfs_trans_cancel(tp);
+	xfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);
+	return error;
+}
+
+static int
+xfs_fsverity_reset_inode(
+	struct xfs_inode	*ip)
+{
+	int			error;
+	struct xfs_mount	*mp = ip->i_mount;
+	struct xfs_trans	*tp;
+
+	error = xfs_fsverity_delete_metadata(ip);
+	if (error)
+		return error;
+
+	/*
+	 * First, let's clean in-memory fsverity flag and then reset it on the
+	 * disk
+	 */
+	inode_set_flags(VFS_I(ip), 0, S_VERITY);
+
+	/*
+	 * Set fsverity inode flag
+	 */
+	error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_ichange,
+			0, 0, false, &tp);
+	if (error)
+		return error;
+
+	ip->i_diflags2 &= ~XFS_DIFLAG2_VERITY;
+
+	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	xfs_trans_set_sync(tp);
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	return error;
+}
+
+/*
+ * Prepare to enable fsverity by clearing old metadata.
+ */
+static int
+xfs_fsverity_begin_enable(
+	struct file		*filp)
+{
+	struct inode		*inode = file_inode(filp);
+	struct xfs_inode	*ip = XFS_I(inode);
+	int			error;
+
+	xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);
+
+	if (IS_DAX(inode) || ip->i_diflags2 & XFS_DIFLAG2_DAX)
+		return -EINVAL;
+
+	/*
+	 * fs-verity tracks verified Merkle tree pages using PG_checked, which
+	 * is only valid on single-page (non-compound) folios.  When the
+	 * filesystem block size is larger than the page size, the page cache
+	 * enforces a minimum folio order > 0, so all Merkle tree folios are
+	 * compound. fs-verity cannot be used on such filesystems.
+	 */
+	if (ip->i_mount->m_sb.sb_blocksize > PAGE_SIZE)
+		return -EOPNOTSUPP;
+
+	/*
+	 * fs-verity doesn't work on zoned
+	 */
+	if (xfs_is_zoned_inode(ip))
+		return -EOPNOTSUPP;
+
+	/*
+	 * fs-verity stores the Merkle tree past EOF in units of the filesystem
+	 * block size, so it cannot support realtime files whose allocation unit
+	 * (extent size) is larger than the block size.
+	 */
+	if (xfs_inode_has_bigrtalloc(ip))
+		return -EINVAL;
+
+	if (XFS_B_TO_FSB(ip->i_mount, inode->i_size) >
+			XFS_FSVERITY_LARGEST_FILE_FSB(ip->i_mount))
+		return -EFBIG;
+
+	/*
+	 * Flush pagecache before building Merkle tree. Inode is locked and no
+	 * further writes will happen to the file except fsverity metadata
+	 */
+	error = filemap_write_and_wait(inode->i_mapping);
+	if (error)
+		return error;
+
+	error = xfs_qm_dqattach(ip);
+	if (error)
+		return error;
+
+	return xfs_fsverity_delete_metadata(ip);
+}
+
+/*
+ * Complete (or fail) the process of enabling fsverity.
+ */
+static int
+xfs_fsverity_end_enable(
+	struct file		*file,
+	const void		*desc,
+	size_t			desc_size,
+	u64			merkle_tree_size)
+{
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	struct xfs_mount	*mp = ip->i_mount;
+	struct xfs_trans	*tp;
+	int			error = 0;
+	int			error2;
+	loff_t			range_start = xfs_fsverity_metadata_offset(ip);
+
+	xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);
+
+	/* fs-verity failed, just cleanup */
+	if (desc == NULL)
+		goto out;
+
+	error = xfs_fsverity_write_descriptor(file, desc, desc_size,
+			merkle_tree_size);
+	if (error)
+		goto out;
+
+	/*
+	 * Wait for Merkle tree get written to disk before setting on-disk inode
+	 * flag and clearing I_VERITY_BUILDING
+	 */
+	error = filemap_write_and_wait_range(inode->i_mapping, range_start,
+			LLONG_MAX);
+	if (error)
+		goto out;
+
+	/*
+	 * Proactively remove unwritten extents left by COW preallocations and
+	 * write preallocation in the merkle tree holes and past descriptor,
+	 * and any delayed preallocations
+	 */
+	error = xfs_free_eofblocks(ip);
+	if (error)
+		goto out;
+
+	/*
+	 * Set fsverity inode flag
+	 */
+	error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_ichange,
+			0, 0, false, &tp);
+	if (error)
+		goto out;
+
+	/*
+	 * Ensure that we've persisted the verity information before we enable
+	 * it on the inode and tell the caller we have sealed the inode.
+	 */
+	ip->i_diflags2 |= XFS_DIFLAG2_VERITY;
+
+	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	xfs_trans_set_sync(tp);
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	if (error)
+		goto out;
+
+	inode_set_flags(inode, S_VERITY, S_VERITY);
+	return error;
+
+out:
+	error2 = xfs_fsverity_reset_inode(ip);
+	if (error2)
+		xfs_alert(ip->i_mount,
+"ino 0x%llx failed to clean up new fsverity metadata, err %d",
+				I_INO(ip), error2);
+
+	return error;
+}
+
+/*
+ * Retrieve a merkle tree block.
+ */
+static struct page *
+xfs_fsverity_read_merkle(
+	struct inode		*inode,
+	pgoff_t			index)
+{
+	index += xfs_fsverity_metadata_offset(XFS_I(inode)) >> PAGE_SHIFT;
+
+	return generic_read_merkle_tree_page(inode, index);
+}
+
+/*
+ * Retrieve a merkle tree block.
+ */
+static void
+xfs_fsverity_readahead_merkle_tree(
+	struct inode		*inode,
+	pgoff_t			index,
+	unsigned long		nr_pages)
+{
+	index += xfs_fsverity_metadata_offset(XFS_I(inode)) >> PAGE_SHIFT;
+
+	generic_readahead_merkle_tree(inode, index, nr_pages);
+}
+
+static inline bool
+xfs_fsverity_is_hashes_of_zeroed_blocks(
+	struct xfs_inode	*ip,
+	const void		*buf,
+	unsigned int		size,
+	const u8		*zero_digest,
+	unsigned int		digest_size)
+{
+	/*
+	 * If this is a block full of hashes of zeroed blocks, don't bother
+	 * storing the block. We can synthesize them later.
+	 *
+	 * However, do this only in case Merkle tree block == fs block size.
+	 * Iomap synthesizes these blocks based on holes in the merkle tree. We
+	 * won't be able to tell if something need to be synthesizes for the
+	 * range in the fs block. For example, for 4k filesystem block
+	 *
+	 *	[ 1k | zero hashes | zero hashes | 1k ]
+	 *
+	 * Iomap won't know about these empty blocks.
+	 */
+	if (size != ip->i_mount->m_sb.sb_blocksize)
+		return false;
+	/*
+	 * First digest is zero_digest
+	 */
+	if (memcmp(buf, zero_digest, digest_size))
+		return false;
+	/*
+	 * Every digest is same as previous, thus all are
+	 * zero_digest
+	 */
+	return memcmp(buf + digest_size, buf, size - digest_size) == 0;
+}
+
+/*
+ * Write a merkle tree block.
+ */
+static int
+xfs_fsverity_write_merkle(
+	struct file		*file,
+	const void		*buf,
+	u64			pos,
+	unsigned int		size,
+	const u8		*zero_digest,
+	unsigned int		digest_size)
+{
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	loff_t			position = pos +
+		xfs_fsverity_metadata_offset(ip);
+
+	if (position + size > inode->i_sb->s_maxbytes)
+		return -EFBIG;
+
+	if (xfs_fsverity_is_hashes_of_zeroed_blocks(ip, buf, size, zero_digest,
+						    digest_size))
+		return 0;
+
+	return iomap_fsverity_write(file, position, size, buf,
+			xfs_buffered_write_iomap_next,
+			&xfs_iomap_write_ops);
+}
+
+const struct fsverity_operations xfs_fsverity_ops = {
+	.begin_enable_verity		= xfs_fsverity_begin_enable,
+	.end_enable_verity		= xfs_fsverity_end_enable,
+	.get_verity_descriptor		= xfs_fsverity_get_descriptor,
+	.read_merkle_tree_page		= xfs_fsverity_read_merkle,
+	.readahead_merkle_tree		= xfs_fsverity_readahead_merkle_tree,
+	.write_merkle_tree_block	= xfs_fsverity_write_merkle,
+};
diff --git a/fs/xfs/xfs_fsverity.h b/fs/xfs/xfs_fsverity.h
new file mode 100644
index 00000000000000..43f8ef62e12a1a
--- /dev/null
+++ b/fs/xfs/xfs_fsverity.h
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#ifndef __XFS_FSVERITY_H__
+#define __XFS_FSVERITY_H__
+
+#include "xfs_platform.h"
+#include "xfs_verity.h"
+#include <linux/iomap.h>
+#include <linux/fsverity.h>
+#include <linux/mempool.h>
+
+#ifdef CONFIG_FS_VERITY
+extern const struct fsverity_operations xfs_fsverity_ops;
+int xfs_fsverity_init(void);
+void xfs_fsverity_exit(void);
+bool xfs_fsverity_is_file_data(const struct xfs_inode *ip, loff_t offset);
+#else
+static inline int xfs_fsverity_init(void)
+{
+	return 0;
+}
+static inline void xfs_fsverity_exit(void)
+{
+}
+static inline bool xfs_fsverity_is_file_data(const struct xfs_inode *ip,
+					    loff_t offset)
+{
+	return false;
+}
+#endif	/* CONFIG_FS_VERITY */
+
+struct xfs_fsverity_ioend {
+	struct iomap_ioend	*ioend;
+	struct work_struct	work;
+};
+
+extern struct kmem_cache *xfs_fsverity_ioend_cache;
+extern mempool_t xfs_fsverity_ioend_pool;
+
+#endif	/* __XFS_FSVERITY_H__ */
diff --git a/fs/xfs/xfs_health.c b/fs/xfs/xfs_health.c
index 239b843e83d42a..be66760fb120f7 100644
--- a/fs/xfs/xfs_health.c
+++ b/fs/xfs/xfs_health.c
@@ -625,6 +625,7 @@ static const struct ioctl_sick_map ino_map[] = {
 	{ XFS_SICK_INO_DIR_ZAPPED,	XFS_BS_SICK_DIR },
 	{ XFS_SICK_INO_SYMLINK_ZAPPED,	XFS_BS_SICK_SYMLINK },
 	{ XFS_SICK_INO_DIRTREE,	XFS_BS_SICK_DIRTREE },
+	{ XFS_SICK_INO_FSVERITY,	XFS_BS_SICK_FSVERITY },
 };
 
 /* Fill out bulkstat health info. */
diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index de8be344e987d0..ca74c9b4f8d383 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -28,7 +28,7 @@
 #include "xfs_da_format.h"
 #include "xfs_dir2.h"
 #include "xfs_metafile.h"
-
+#include <linux/fsverity.h>
 #include <linux/iversion.h>
 
 /* Radix tree tags for incore inode tree. */
@@ -1260,6 +1260,15 @@ xfs_inode_free_eofblocks(
 	if (xfs_can_free_eofblocks(ip))
 		return xfs_free_eofblocks(ip);
 
+	/*
+	 * The above xfs_free_eofblocks() is skipped for inodes with fsverity
+	 * tree is being built. However, we don't want to clear EOF tag in this
+	 * case. If building the tree fails, inode will have EOF blocks which
+	 * needs removal.
+	 */
+	if (fsverity_is_building(VFS_IC(ip)))
+		return 0;
+
 	/* inode could be preallocated */
 	trace_xfs_inode_free_eofblocks_invalid(ip);
 	xfs_inode_clear_eofblocks_tag(ip);
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index f81b6e52ac403d..2d0a2d37e71cf8 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -49,6 +49,7 @@
 
 #include <linux/mount.h>
 #include <linux/fileattr.h>
+#include <linux/fsverity.h>
 
 /* Return 0 on success or positive error */
 int
@@ -562,6 +563,14 @@ xfs_ioctl_setattr_xflags(
 		if (xfs_inode_has_filedata(ip))
 			return -EINVAL;
 
+		/*
+		 * fs-verity is incompatible with a realtime allocation unit
+		 * larger than a single filesystem block, so don't let a file be
+		 * converted to realtime while verity is being enabled.
+		 */
+		if (fsverity_is_building(VFS_IC(ip)))
+			return -EINVAL;
+
 		/*
 		 * If S_DAX is enabled on this file, we can only switch the
 		 * device if both support fsdax.  We can't update S_DAX because
@@ -574,6 +583,17 @@ xfs_ioctl_setattr_xflags(
 			return -EINVAL;
 	}
 
+	/*
+	 * fs-verity is incompatible with DAX, and xfs_fsverity_begin_enable()
+	 * verified the inode was not DAX under the inode lock.  That lock is
+	 * dropped while the Merkle tree is built, so reject enabling DAX while
+	 * verity is being enabled.
+	 */
+	if ((fa->fsx_xflags & FS_XFLAG_DAX) &&
+	    !(ip->i_diflags2 & XFS_DIFLAG2_DAX) &&
+	    fsverity_is_building(VFS_IC(ip)))
+		return -EINVAL;
+
 	if (rtflag) {
 		/* If realtime flag is set then must have realtime device */
 		if (mp->m_sb.sb_rblocks == 0 || mp->m_sb.sb_rextsize == 0 ||
@@ -1575,6 +1595,19 @@ xfs_file_ioctl(
 	case XFS_IOC_VERIFY_MEDIA:
 		return xfs_ioc_verify_media(filp, arg);
 
+	case FS_IOC_ENABLE_VERITY:
+		if (!xfs_has_verity(mp))
+			return -EOPNOTSUPP;
+		return fsverity_ioctl_enable(filp, arg);
+	case FS_IOC_MEASURE_VERITY:
+		if (!xfs_has_verity(mp))
+			return -EOPNOTSUPP;
+		return fsverity_ioctl_measure(filp, arg);
+	case FS_IOC_READ_VERITY_METADATA:
+		if (!xfs_has_verity(mp))
+			return -EOPNOTSUPP;
+		return fsverity_ioctl_read_metadata(filp, arg);
+
 	default:
 		return -ENOTTY;
 	}
diff --git a/fs/xfs/xfs_ioend.c b/fs/xfs/xfs_ioend.c
index 7f4a4a95afe50d..61f211a3b8052b 100644
--- a/fs/xfs/xfs_ioend.c
+++ b/fs/xfs/xfs_ioend.c
@@ -18,7 +18,26 @@
 #include "xfs_ioend.h"
 #include "xfs_error.h"
 #include "xfs_errortag.h"
+#include "xfs_fsverity.h"
 #include <linux/bio-integrity.h>
+#include <linux/fsverity.h>
+
+static void
+xfs_end_fsverity_io_read(
+	struct work_struct		*work)
+{
+	struct xfs_fsverity_ioend	*fsv_ioend =
+			container_of(work, struct xfs_fsverity_ioend, work);
+	struct iomap_ioend		*ioend = fsv_ioend->ioend;
+	struct bio			*bio = &ioend->io_bio;
+
+	mempool_free(fsv_ioend, &xfs_fsverity_ioend_pool);
+
+	if (!bio->bi_status)
+		fsverity_verify_bio(ioend->io_vi, bio);
+
+	iomap_finish_ioends(ioend, blk_status_to_errno(bio->bi_status));
+}
 
 static void
 xfs_dio_bounce_end_io(
@@ -93,12 +112,14 @@ xfs_read_bounce_and_resubmit(
 
 static void
 xfs_end_io_read(
-	struct bio		*bio)
+	struct bio			*bio)
 {
-	struct iomap_ioend	*ioend = iomap_ioend_from_bio(bio);
-	struct xfs_inode	*ip = XFS_I(ioend->io_inode);
-	struct xfs_mount	*mp = ip->i_mount;
-	int			error = blk_status_to_errno(bio->bi_status);
+	struct iomap_ioend		*ioend = iomap_ioend_from_bio(bio);
+	struct xfs_inode		*ip = XFS_I(ioend->io_inode);
+	struct xfs_mount		*mp = ip->i_mount;
+	int				error =
+			blk_status_to_errno(bio->bi_status);
+	struct xfs_fsverity_ioend	*fsv_ioend;
 
 	if (!error && (ioend->io_flags & IOMAP_IOEND_INTEGRITY)) {
 		error = iomap_ioend_integrity_verify(ioend);
@@ -117,6 +138,24 @@ xfs_end_io_read(
 		}
 	}
 
+	/*
+	 * If we have fsverity on this bio, we need to run fsverity verification
+	 * of data folios from a separate fsverity workqueue. This is necessary
+	 * to avoid deadlocking due to fsverity issuing more reads of fsverity
+	 * metadata which would be processed by the same worker in the BIO
+	 * completion workqueue.
+	 */
+	if (IS_ENABLED(CONFIG_FS_VERITY) && !error && ioend->io_vi &&
+			xfs_fsverity_is_file_data(ip, ioend->io_offset)) {
+		fsv_ioend = mempool_alloc(&xfs_fsverity_ioend_pool,
+				GFP_NOFS);
+		fsv_ioend->ioend = ioend;
+		INIT_WORK(&fsv_ioend->work, xfs_end_fsverity_io_read);
+
+		fsverity_enqueue_verify_work(&fsv_ioend->work);
+		return;
+	}
+
 	iomap_finish_ioends(ioend, error);
 }
 
@@ -125,13 +164,15 @@ xfs_ioend_submit_read(
 	struct inode		*inode,
 	struct bio		*bio,
 	loff_t			file_offset,
-	u16			ioend_flags)
+	u16			ioend_flags,
+	struct fsverity_info	*vi)
 {
 	struct xfs_inode	*ip = XFS_I(inode);
 	struct xfs_mount	*mp = ip->i_mount;
 	struct iomap_ioend	*ioend;
 
 	ioend = iomap_init_ioend(inode, bio, file_offset, ioend_flags);
+	ioend->io_vi = vi;
 	if ((ioend_flags & IOMAP_IOEND_DIRECT) &&
 	    READ_ONCE(mp->m_read_bounce) == XFS_READ_BOUNCE_ALWAYS) {
 		iomap_bounce_read(ioend, bdev_logical_block_size(bio->bi_bdev),
diff --git a/fs/xfs/xfs_ioend.h b/fs/xfs/xfs_ioend.h
index 7c2a1ea3e6eddc..992c248a693aaf 100644
--- a/fs/xfs/xfs_ioend.h
+++ b/fs/xfs/xfs_ioend.h
@@ -2,6 +2,8 @@
 #ifndef __XFS_IOEND_H
 #define __XFS_IOEND_H
 
+#include <linux/fsverity.h>
+
 /*
  * Fast and loose check if this write could update the on-disk inode size.
  */
@@ -13,6 +15,6 @@ static inline bool xfs_ioend_is_append(struct iomap_ioend *ioend)
 
 void xfs_end_bio(struct bio *bio);
 void xfs_ioend_submit_read(struct inode *inode, struct bio *bio,
-		loff_t file_offset, u16 ioend_flags);
+		loff_t file_offset, u16 ioend_flags, struct fsverity_info *vi);
 
 #endif /* __XFS_IOEND_H */
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 50eae7ff614534..5117704530f69c 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -32,6 +32,8 @@
 #include "xfs_rtbitmap.h"
 #include "xfs_icache.h"
 #include "xfs_zone_alloc.h"
+#include "xfs_verity.h"
+#include <linux/fsverity.h>
 
 #define XFS_ALLOC_ALIGN(mp, off) \
 	(((off) >> mp->m_allocsize_log) << mp->m_allocsize_log)
@@ -54,6 +56,15 @@ xfs_alert_fsblock_zero(
 	return -EFSCORRUPTED;
 }
 
+static bool
+xfs_iomap_is_fsverity_metadata(
+	struct xfs_inode	*ip,
+	loff_t			offset)
+{
+	return offset >= xfs_fsverity_metadata_offset(ip) &&
+	       (fsverity_is_building(VFS_I(ip)) || fsverity_active(VFS_I(ip)));
+}
+
 u64
 xfs_iomap_inode_sequence(
 	struct xfs_inode	*ip,
@@ -101,6 +112,7 @@ xfs_bmbt_to_iomap(
 	struct xfs_inode	*ip,
 	struct iomap		*iomap,
 	struct xfs_bmbt_irec	*imap,
+	loff_t			offset,
 	unsigned int		mapping_flags,
 	u16			iomap_flags,
 	u64			sequence_cookie)
@@ -152,6 +164,15 @@ xfs_bmbt_to_iomap(
 			iomap->flags |= IOMAP_F_INTEGRITY;
 	}
 
+	/*
+	 * Tell iomap when this I/O covers fs-verity metadata so it handles size
+	 * updates and post-EOF folios correctly.  The attr fork uses a separate
+	 * offset space, so exclude it.
+	 */
+	if (!(iomap_flags & IOMAP_F_XATTR) &&
+	    xfs_iomap_is_fsverity_metadata(ip, offset))
+		iomap->flags |= IOMAP_F_FSVERITY;
+
 	/*
 	 * If the inode is dirty for datasync purposes, let iomap know so it
 	 * doesn't elide the IO completion journal flushes on O_DSYNC IO.
@@ -1006,7 +1027,8 @@ xfs_direct_write_iomap_begin(
 	seq = xfs_iomap_inode_sequence(ip, iomap_flags);
 	xfs_iunlock(ip, lockmode);
 	trace_xfs_iomap_found(ip, offset, length, XFS_DATA_FORK, &imap);
-	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, iomap_flags, seq);
+	return xfs_bmbt_to_iomap(ip, iomap, &imap, offset, flags, iomap_flags,
+			seq);
 
 allocate_blocks:
 	error = -EAGAIN;
@@ -1037,7 +1059,7 @@ xfs_direct_write_iomap_begin(
 		return error;
 
 	trace_xfs_iomap_alloc(ip, offset, length, XFS_DATA_FORK, &imap);
-	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags,
+	return xfs_bmbt_to_iomap(ip, iomap, &imap, offset, flags,
 				 iomap_flags | IOMAP_F_NEW, seq);
 
 out_found_cow:
@@ -1045,13 +1067,15 @@ xfs_direct_write_iomap_begin(
 	trace_xfs_iomap_found(ip, offset, length - offset, XFS_COW_FORK, &cmap);
 	if (imap.br_startblock != HOLESTARTBLOCK) {
 		seq = xfs_iomap_inode_sequence(ip, 0);
-		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, flags, 0, seq);
+		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, offset, flags,
+				0, seq);
 		if (error)
 			goto out_unlock;
 	}
 	seq = xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED);
 	xfs_iunlock(ip, lockmode);
-	return xfs_bmbt_to_iomap(ip, iomap, &cmap, flags, IOMAP_F_SHARED, seq);
+	return xfs_bmbt_to_iomap(ip, iomap, &cmap, offset, flags,
+			IOMAP_F_SHARED, seq);
 
 out_unlock:
 	if (lockmode)
@@ -1270,7 +1294,8 @@ xfs_atomic_write_cow_iomap_begin(
 	trace_xfs_iomap_found(ip, offset, length, XFS_COW_FORK, &cmap);
 	seq = xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED);
 	xfs_iunlock(ip, XFS_ILOCK_EXCL);
-	return xfs_bmbt_to_iomap(ip, iomap, &cmap, flags, IOMAP_F_SHARED, seq);
+	return xfs_bmbt_to_iomap(ip, iomap, &cmap, offset, flags,
+			IOMAP_F_SHARED, seq);
 
 convert_delay:
 	xfs_iunlock(ip, XFS_ILOCK_EXCL);
@@ -1622,8 +1647,9 @@ xfs_zoned_fill_srcmap(
 	 */
 	xfs_trim_extent(&smap, offset_fsb, *end_fsb - offset_fsb);
 	*end_fsb = min(*end_fsb, smap.br_startoff + smap.br_blockcount);
-	return xfs_bmbt_to_iomap(ip, srcmap, &smap, flags, 0,
-			xfs_iomap_inode_sequence(ip, 0));
+	return xfs_bmbt_to_iomap(ip, srcmap, &smap,
+			XFS_FSB_TO_B(ip->i_mount, offset_fsb), flags,
+			0, xfs_iomap_inode_sequence(ip, 0));
 }
 
 static int
@@ -1796,7 +1822,7 @@ xfs_zoned_buffered_write_iomap_begin(
 	trace_xfs_iomap_alloc(ip, offset, XFS_FSB_TO_B(mp, count_fsb),
 			XFS_COW_FORK, &got);
 done:
-	error = xfs_bmbt_to_iomap(ip, iomap, &got, flags, iomap_flags,
+	error = xfs_bmbt_to_iomap(ip, iomap, &got, offset, flags, iomap_flags,
 			xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED));
 out_unlock:
 	xfs_iunlock(ip, lockmode);
@@ -2104,7 +2130,8 @@ xfs_buffered_write_iomap_begin(
 found_imap:
 	seq = xfs_iomap_inode_sequence(ip, iomap_flags);
 	xfs_iunlock(ip, lockmode);
-	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, iomap_flags, seq);
+	return xfs_bmbt_to_iomap(ip, iomap, &imap, offset, flags, iomap_flags,
+			seq);
 
 convert_delay:
 	xfs_iunlock(ip, lockmode);
@@ -2119,8 +2146,8 @@ xfs_buffered_write_iomap_begin(
 
 found_cow:
 	if (imap.br_startoff <= offset_fsb) {
-		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, flags, 0,
-				xfs_iomap_inode_sequence(ip, 0));
+		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, offset, flags,
+				0, xfs_iomap_inode_sequence(ip, 0));
 		if (error)
 			goto out_unlock;
 	} else {
@@ -2131,7 +2158,8 @@ xfs_buffered_write_iomap_begin(
 	iomap_flags |= IOMAP_F_SHARED;
 	seq = xfs_iomap_inode_sequence(ip, iomap_flags);
 	xfs_iunlock(ip, lockmode);
-	return xfs_bmbt_to_iomap(ip, iomap, &cmap, flags, iomap_flags, seq);
+	return xfs_bmbt_to_iomap(ip, iomap, &cmap, offset, flags, iomap_flags,
+			seq);
 
 out_unlock:
 	xfs_iunlock(ip, lockmode);
@@ -2238,7 +2266,7 @@ xfs_read_iomap_begin(
 	if (error)
 		return error;
 	trace_xfs_iomap_found(ip, offset, length, XFS_DATA_FORK, &imap);
-	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags,
+	return xfs_bmbt_to_iomap(ip, iomap, &imap, offset, flags,
 				 shared ? IOMAP_F_SHARED : 0, seq);
 }
 
@@ -2298,7 +2326,7 @@ xfs_seek_iomap_begin(
 			end_fsb = min(end_fsb, data_fsb);
 		xfs_trim_extent(&cmap, offset_fsb, end_fsb - offset_fsb);
 		seq = xfs_iomap_inode_sequence(ip, IOMAP_F_SHARED);
-		error = xfs_bmbt_to_iomap(ip, iomap, &cmap, flags,
+		error = xfs_bmbt_to_iomap(ip, iomap, &cmap, offset, flags,
 				IOMAP_F_SHARED, seq);
 		/*
 		 * This is a COW extent, so we must probe the page cache
@@ -2322,7 +2350,7 @@ xfs_seek_iomap_begin(
 done:
 	seq = xfs_iomap_inode_sequence(ip, 0);
 	xfs_trim_extent(&imap, offset_fsb, end_fsb - offset_fsb);
-	error = xfs_bmbt_to_iomap(ip, iomap, &imap, flags, 0, seq);
+	error = xfs_bmbt_to_iomap(ip, iomap, &imap, offset, flags, 0, seq);
 out_unlock:
 	xfs_iunlock(ip, lockmode);
 	return error;
@@ -2370,7 +2398,8 @@ xfs_xattr_iomap_begin(
 	if (error)
 		return error;
 	ASSERT(nimaps);
-	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, IOMAP_F_XATTR, seq);
+	return xfs_bmbt_to_iomap(ip, iomap, &imap, offset, flags,
+			IOMAP_F_XATTR, seq);
 }
 
 DEFINE_IOMAP_ITER_NEXT(xfs_xattr_iomap_next, xfs_xattr_iomap_begin);
diff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h
index 071fff6665070e..c9bd6de1bfda5a 100644
--- a/fs/xfs/xfs_iomap.h
+++ b/fs/xfs/xfs_iomap.h
@@ -22,8 +22,9 @@ xfs_fileoff_t xfs_iomap_eof_align_last_fsb(struct xfs_inode *ip,
 
 u64 xfs_iomap_inode_sequence(struct xfs_inode *ip, u16 iomap_flags);
 int xfs_bmbt_to_iomap(struct xfs_inode *ip, struct iomap *iomap,
-		struct xfs_bmbt_irec *imap, unsigned int mapping_flags,
-		u16 iomap_flags, u64 sequence_cookie);
+		struct xfs_bmbt_irec *imap, loff_t offset,
+		unsigned int mapping_flags, u16 iomap_flags,
+		u64 sequence_cookie);
 
 int xfs_zero_range(struct xfs_inode *ip, loff_t pos, loff_t len,
 		struct xfs_zone_alloc_ctx *ac, bool *did_zero);
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index 6c5633db30daea..ff34f392dd557e 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -35,6 +35,7 @@
 #include <linux/security.h>
 #include <linux/iversion.h>
 #include <linux/fiemap.h>
+#include <linux/fsverity.h>
 
 /*
  * Directories have different lock order w.r.t. mmap_lock compared to regular
@@ -579,6 +580,18 @@ xfs_report_dioalign(
 	struct block_device	*bdev = target->bt_bdev;
 
 	stat->result_mask |= STATX_DIOALIGN | STATX_DIO_READ_ALIGN;
+
+	/*
+	 * The STATX_DIOALIGN | STATX_DIO_READ_ALIGN flags are used to
+	 * explicitly report if DIO is supported or not. They can not indicate
+	 * that fallback to the buffered IO is used for fsverity.
+	 *
+	 * Return zero alignment values which also mean that DIO is not
+	 * supported on this file, see statx(2).
+	 */
+	if (fsverity_active(VFS_I(ip)))
+		return;
+
 	stat->dio_mem_align = bdev_dma_alignment(bdev) + 1;
 
 	/*
@@ -1387,6 +1400,8 @@ xfs_inode_should_enable_dax(
 		return false;
 	if (!xfs_inode_supports_dax(ip))
 		return false;
+	if (ip->i_diflags2 & XFS_DIFLAG2_VERITY)
+		return false;
 	if (xfs_has_dax_always(ip->i_mount))
 		return true;
 	if (ip->i_diflags2 & XFS_DIFLAG2_DAX)
@@ -1415,12 +1430,15 @@ xfs_diflags_to_iflags(
 		flags |= S_NOATIME;
 	if (init && xfs_inode_should_enable_dax(ip))
 		flags |= S_DAX;
+	if (xflags & FS_XFLAG_VERITY)
+		flags |= S_VERITY;
 
 	/*
 	 * S_DAX can only be set during inode initialization and is never set by
 	 * the VFS, so we cannot mask off S_DAX in i_flags.
 	 */
-	inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME);
+	inode->i_flags &=
+		~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME | S_VERITY);
 	inode->i_flags |= flags;
 }
 
diff --git a/fs/xfs/xfs_message.c b/fs/xfs/xfs_message.c
index 0243e509a46891..44b13d46049c62 100644
--- a/fs/xfs/xfs_message.c
+++ b/fs/xfs/xfs_message.c
@@ -149,6 +149,10 @@ xfs_warn_experimental(
 			.opstate	= XFS_OPSTATE_WARNED_LARP,
 			.name		= "logged extended attributes",
 		},
+		[XFS_EXPERIMENTAL_FSVERITY] = {
+			.opstate	= XFS_OPSTATE_WARNED_FSVERITY,
+			.name		= "fsverity",
+		},
 	};
 	ASSERT(feat >= 0 && feat < XFS_EXPERIMENTAL_MAX);
 	BUILD_BUG_ON(ARRAY_SIZE(features) != XFS_EXPERIMENTAL_MAX);
diff --git a/fs/xfs/xfs_message.h b/fs/xfs/xfs_message.h
index 811b885f41c35a..364fcc7e42b084 100644
--- a/fs/xfs/xfs_message.h
+++ b/fs/xfs/xfs_message.h
@@ -93,6 +93,7 @@ void xfs_buf_alert_ratelimited(struct xfs_buf *bp, const char *rlmsg,
 enum xfs_experimental_feat {
 	XFS_EXPERIMENTAL_SHRINK,
 	XFS_EXPERIMENTAL_LARP,
+	XFS_EXPERIMENTAL_FSVERITY,
 
 	XFS_EXPERIMENTAL_MAX,
 };
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index cbcfb89c67a440..0b64636635996f 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -403,6 +403,7 @@ typedef struct xfs_mount {
 #define XFS_FEAT_EXCHANGE_RANGE	(1ULL << 27)	/* exchange range */
 #define XFS_FEAT_METADIR	(1ULL << 28)	/* metadata directory tree */
 #define XFS_FEAT_ZONED		(1ULL << 29)	/* zoned RT device */
+#define XFS_FEAT_VERITY		(1ULL << 30)	/* fs-verity */
 
 /* Mount features */
 #define XFS_FEAT_NOLIFETIME	(1ULL << 47)	/* disable lifetime hints */
@@ -460,6 +461,7 @@ __XFS_HAS_FEAT(exchange_range, EXCHANGE_RANGE)
 __XFS_HAS_FEAT(metadir, METADIR)
 __XFS_HAS_FEAT(zoned, ZONED)
 __XFS_HAS_FEAT(nolifetime, NOLIFETIME)
+__XFS_HAS_FEAT(verity, VERITY)
 
 static inline bool xfs_has_rtgroups(const struct xfs_mount *mp)
 {
@@ -597,6 +599,8 @@ __XFS_HAS_FEAT(nouuid, NOUUID)
 #define XFS_OPSTATE_RESUMING_QUOTAON	18
 /* (Zoned) GC is in progress */
 #define XFS_OPSTATE_ZONEGC_RUNNING	20
+/* Kernel has logged a warning about fsverity support */
+#define XFS_OPSTATE_WARNED_FSVERITY	21
 
 #define __XFS_IS_OPSTATE(name, NAME) \
 static inline bool xfs_is_ ## name (struct xfs_mount *mp) \
diff --git a/fs/xfs/xfs_pnfs.c b/fs/xfs/xfs_pnfs.c
index 065875c8b7dab8..ff097400d064fd 100644
--- a/fs/xfs/xfs_pnfs.c
+++ b/fs/xfs/xfs_pnfs.c
@@ -256,7 +256,7 @@ xfs_fs_map_blocks(
 	}
 	xfs_iunlock(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
 
-	error = xfs_bmbt_to_iomap(ip, iomap, &imap, 0, 0, seq);
+	error = xfs_bmbt_to_iomap(ip, iomap, &imap, offset, 0, 0, seq);
 	*device_generation = mp->m_generation;
 	return error;
 out_unlock:
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 5a06132aa38466..890fa5727d56e6 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -30,6 +30,7 @@
 #include "xfs_filestream.h"
 #include "xfs_quota.h"
 #include "xfs_sysfs.h"
+#include "xfs_fsverity.h"
 #include "xfs_ondisk.h"
 #include "xfs_rmap_item.h"
 #include "xfs_refcount_item.h"
@@ -50,6 +51,7 @@
 #include "xfs_rtalloc.h"
 #include "xfs_zone_alloc.h"
 #include "xfs_healthmon.h"
+#include "xfs_fsverity.h"
 #include "scrub/stats.h"
 #include "scrub/rcbag_btree.h"
 
@@ -1736,6 +1738,9 @@ xfs_fs_fill_super(
 	sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
 #endif
 	sb->s_op = &xfs_super_operations;
+#ifdef CONFIG_FS_VERITY
+	sb->s_vop = &xfs_fsverity_ops;
+#endif
 
 	/*
 	 * Delay mount work if the debug hook is set. This is debug
@@ -1988,6 +1993,9 @@ xfs_fs_fill_super(
 	if (error)
 		goto out_filestream_unmount;
 
+	if (xfs_has_verity(mp))
+		xfs_warn_experimental(mp, XFS_EXPERIMENTAL_FSVERITY);
+
 	root = igrab(VFS_I(mp->m_rootip));
 	if (!root) {
 		error = -ENOENT;
@@ -2516,8 +2524,20 @@ xfs_init_caches(void)
 	if (!xfs_parent_args_cache)
 		goto out_destroy_xmi_cache;
 
+#ifdef CONFIG_FS_VERITY
+	xfs_fsverity_ioend_cache = kmem_cache_create("xfs_fsverity_ioend",
+					     sizeof(struct xfs_fsverity_ioend),
+					     0, 0, NULL);
+	if (!xfs_fsverity_ioend_cache)
+		goto out_destroy_parent_args_cache;
+#endif
+
 	return 0;
 
+#ifdef CONFIG_FS_VERITY
+ out_destroy_parent_args_cache:
+	kmem_cache_destroy(xfs_parent_args_cache);
+#endif
  out_destroy_xmi_cache:
 	kmem_cache_destroy(xfs_xmi_cache);
  out_destroy_xmd_cache:
@@ -2580,6 +2600,9 @@ xfs_destroy_caches(void)
 	 * destroy caches.
 	 */
 	rcu_barrier();
+#ifdef CONFIG_FS_VERITY
+	kmem_cache_destroy(xfs_fsverity_ioend_cache);
+#endif
 	kmem_cache_destroy(xfs_parent_args_cache);
 	kmem_cache_destroy(xfs_xmd_cache);
 	kmem_cache_destroy(xfs_xmi_cache);
@@ -2660,10 +2683,14 @@ init_xfs_fs(void)
 	if (error)
 		goto out;
 
-	error = xfs_init_workqueues();
+	error = xfs_fsverity_init();
 	if (error)
 		goto out_destroy_caches;
 
+	error = xfs_init_workqueues();
+	if (error)
+		goto out_fsverity_exit;
+
 	error = xfs_mru_cache_init();
 	if (error)
 		goto out_destroy_wq;
@@ -2740,6 +2767,8 @@ init_xfs_fs(void)
 	xfs_mru_cache_uninit();
  out_destroy_wq:
 	xfs_destroy_workqueues();
+ out_fsverity_exit:
+	xfs_fsverity_exit();
  out_destroy_caches:
 	xfs_destroy_caches();
  out:
@@ -2763,6 +2792,7 @@ exit_xfs_fs(void)
 	xfs_cleanup_procfs();
 	xfs_mru_cache_uninit();
 	xfs_destroy_workqueues();
+	xfs_fsverity_exit();
 	xfs_destroy_caches();
 	xfs_uuid_table_free();
 }

23/3 2026/11/25 16:59 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30959
							output: 31
							thoughts: 1523
						

Thoughts:
**Analyzing the XFS fs-verity Patch for Uninitialized Memory Risks**

Okay, let's dive into this XFS patch and assess its potential for uninitialized memory exposures, warranting a KMSAN fuzzing session. The patch introduces fs-verity support for the XFS filesystem, so I need to carefully scrutinize the code for any instances where uninitialized memory could be leaked.

First, I see the typical changes: Makefiles, new definitions in headers (`xfs_format.h`, `xfs_fs.h`, etc.), and implementations (`xfs_verity.c`, `xfs_fsverity.c`, etc.). A lot of this seems like standard fs-verity integration. The code touches a lot of areas, including bmap, iomap, inode handling, and superblock operations.

My primary concern is user-space exposure. I need to identify any structures passed to user space, paying particular attention to their initialization. Looking at `xfs_fsverity_get_descriptor`, I see it reads data, potentially a variable-length descriptor, into a buffer `buf`. The size of the data read into `buf` is determined by `desc_size`, which is read from the inode.

Now, my radar is up. `fsverity_pagecache_read` populates `buf`, which is provided by the calling code. I need to see where `xfs_fsverity_get_descriptor` is used. I'll search the `fs/verity` directory to see if `fsverity_ioctl_read_metadata` or any callers of `get_descriptor` copy `buf` to user space. If the buffer is directly or indirectly copied to a user-space buffer without proper initialization, we have a clear uninitialized memory risk. I need to trace this data path to ensure that `buf` is either fully initialized before being copied or, if not, that a controlled size and content are transferred to avoid information leakage.



24/3 2026/11/25 16:59 tool grepper
0m Args:
{
  "Expression": "get_verity_descriptor",
  "PathPrefixes": [
    "fs/verity"
  ]
}

Results:
{
  "Output": "fs/verity/open.c=307=int fsverity_get_descriptor(struct inode *inode,\n--\nfs/verity/open.c-312-\nfs/verity/open.c:313:\tsize = inode-\u003ei_sb-\u003es_vop-\u003eget_verity_descriptor(inode, NULL, 0);\nfs/verity/open.c-314-\tif (size \u003c 0) {\n--\nfs/verity/open.c-327-\t\treturn -ENOMEM;\nfs/verity/open.c:328:\tres = inode-\u003ei_sb-\u003es_vop-\u003eget_verity_descriptor(inode, desc, size);\nfs/verity/open.c-329-\tif (res \u003c 0) {\n"
}

25/3 2026/11/25 16:59 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33141
							output: 34
							thoughts: 18
						

Thoughts:
Okay, here's my summary, presented as a first-person account, assuming I'm an expert in the field:

**Diving into `fsverity_ioctl_read_metadata`**

Alright, let's get down to brass tacks. I need to understand this `fsverity_ioctl_read_metadata` function inside and out. It's obviously the key to retrieving the metadata associated with FS-Verity-protected files, but the devil's in the details, as always. I want to unpack its behavior thoroughly. What does it actually *do*? What data structures are involved? What's the complete sequence of operations? I need to understand all the potential implications for security, performance, and compatibility. Time to start digging into the code and documentation!



26/3 2026/11/25 16:59 tool grepper
0m Args:
{
  "Expression": "fsverity_ioctl_read_metadata",
  "PathPrefixes": [
    "fs/verity"
  ]
}

Results:
{
  "Output": "fs/verity/read_metadata.c=128=static int fsverity_read_signature(struct inode *inode,\n--\nfs/verity/read_metadata.c-154-/**\nfs/verity/read_metadata.c:155: * fsverity_ioctl_read_metadata() - read verity metadata from a file\nfs/verity/read_metadata.c-156- * @filp: file to read the metadata from\n--\nfs/verity/read_metadata.c-160- */\nfs/verity/read_metadata.c:161:int fsverity_ioctl_read_metadata(struct file *filp, const void __user *uarg)\nfs/verity/read_metadata.c-162-{\n--\nfs/verity/read_metadata.c-209-}\nfs/verity/read_metadata.c:210:EXPORT_SYMBOL_GPL(fsverity_ioctl_read_metadata);\n"
}

27/3 2026/11/25 16:59 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33611
							output: 38
							thoughts: 29
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Analyzing `fsverity_ioctl_read_metadata` and Verity Descriptor Handling**

Right, let's dive into this `fsverity_ioctl_read_metadata` function. I need to understand exactly how the `fs/verity/` code base is dealing with descriptors and metadata. I need to refresh my understanding of how this particular ioctl operates. What are the specific data structures involved? Is it handling the descriptor directly? Or are there intermediate layers? Are there any potential concurrency issues or race conditions in accessing or updating the metadata?

I'm particularly interested in how the metadata is cached, if at all, and the implications for performance. Does it invalidate the cache correctly? What's the strategy for handling different descriptor formats? How flexible is the implementation? Is there any opportunity for optimization in the code? Does this differ based on the file system in which fs-verity is in use? I'll probably want to trace the code execution to find my answers. Are there any assumptions or corner cases within the code base which might cause issues? What are the implications if this function is called concurrently, with multiple threads reading or writing to the same verity file?



28/3 2026/11/25 17:00 tool read-file
0m Args:
{
  "File": "fs/verity/read_metadata.c",
  "FirstLine": 155,
  "LineCount": 55
}

Results:
{
  "Contents": " 155:\t * fsverity_ioctl_read_metadata() - read verity metadata from a file\n 156:\t * @filp: file to read the metadata from\n 157:\t * @uarg: user pointer to fsverity_read_metadata_arg\n 158:\t *\n 159:\t * Return: length read on success, 0 on EOF, -errno on failure\n 160:\t */\n 161:\tint fsverity_ioctl_read_metadata(struct file *filp, const void __user *uarg)\n 162:\t{\n 163:\t\tstruct inode *inode = file_inode(filp);\n 164:\t\tconst struct fsverity_info *vi;\n 165:\t\tstruct fsverity_read_metadata_arg arg;\n 166:\t\tint length;\n 167:\t\tvoid __user *buf;\n 168:\t\n 169:\t\t/*\n 170:\t\t * This ioctl returns file contents block hashes, so it should require\n 171:\t\t * read permission.  Disallow it on ioctl-only (i.e., nonstandard access\n 172:\t\t * mode 3) fds, which can in some cases be acquired without passing all\n 173:\t\t * LSM read-permission checks.  Also disallow write-only fds, which can\n 174:\t\t * refer only to non-verity files which would fail with ENODATA anyway.\n 175:\t\t */\n 176:\t\tif (!(filp-\u003ef_mode \u0026 FMODE_READ))\n 177:\t\t\treturn -EBADF;\n 178:\t\n 179:\t\tvi = fsverity_get_info(inode);\n 180:\t\tif (!vi)\n 181:\t\t\treturn -ENODATA; /* not a verity file */\n 182:\t\n 183:\t\tif (copy_from_user(\u0026arg, uarg, sizeof(arg)))\n 184:\t\t\treturn -EFAULT;\n 185:\t\n 186:\t\tif (arg.__reserved)\n 187:\t\t\treturn -EINVAL;\n 188:\t\n 189:\t\t/* offset + length must not overflow. */\n 190:\t\tif (arg.offset + arg.length \u003c arg.offset)\n 191:\t\t\treturn -EINVAL;\n 192:\t\n 193:\t\t/* Ensure that the return value will fit in INT_MAX. */\n 194:\t\tlength = min_t(u64, arg.length, INT_MAX);\n 195:\t\n 196:\t\tbuf = u64_to_user_ptr(arg.buf_ptr);\n 197:\t\n 198:\t\tswitch (arg.metadata_type) {\n 199:\t\tcase FS_VERITY_METADATA_TYPE_MERKLE_TREE:\n 200:\t\t\treturn fsverity_read_merkle_tree(inode, vi, buf, arg.offset,\n 201:\t\t\t\t\t\t\t length);\n 202:\t\tcase FS_VERITY_METADATA_TYPE_DESCRIPTOR:\n 203:\t\t\treturn fsverity_read_descriptor(inode, buf, arg.offset, length);\n 204:\t\tcase FS_VERITY_METADATA_TYPE_SIGNATURE:\n 205:\t\t\treturn fsverity_read_signature(inode, buf, arg.offset, length);\n 206:\t\tdefault:\n 207:\t\t\treturn -EINVAL;\n 208:\t\t}\n 209:\t}\n"
}

29/3 2026/11/25 17:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34854
							output: 38
							thoughts: 10
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:

**Analyzing the `fsverity_read_descriptor` Function**

Alright, let's dive into this `fsverity_read_descriptor` function. I'm immediately focusing on the implications within a secure file system context. The core problem, as I see it, is how we're handling the descriptor read operation within the fs-verity framework. We need to ensure data integrity during file access, so that read operations don't undermine the guarantees provided by fs-verity.

My primary concern is the potential for vulnerabilities here. What are the edge cases? I'm wondering:

*   **Error Handling:** How robust is the error handling? Are we correctly checking return values from all the system calls involved? Specifically, are we gracefully handling errors during metadata validation? Are there any unchecked return values that could lead to information leaks or security bypasses?
*   **Race Conditions:** Are there any race conditions between the descriptor read and other concurrent operations? Concurrent reads or writes to related files? If the underlying data changes, how do we guarantee consistency? This could be a window of opportunity for attackers to inject malicious data.
*   **Data Integrity Verification:** Are we verifying the integrity of the descriptor itself? Are we hashing the descriptor data, comparing the hash, and if so, how? And where do the "keys" reside for that comparison?
*   **Descriptor Caching:** Is there any caching involved? If the descriptor is cached, how are cache invalidation and consistency handled? A stale descriptor could be used to present incorrect data.
*   **Security Contexts:** How does this function interact with security contexts (e.g., SELinux, AppArmor)? Are we appropriately restricting access to the descriptor based on the caller's security attributes?
*   **Performance:** I have to weigh the overhead associated with the descriptor read. Is the performance acceptable for a production environment? Are there any optimizations that can be applied without compromising security?

I'm keeping an eye out for potential attack vectors, specifically:

*   **Descriptor tampering:** Can an attacker modify the descriptor to point to malicious data?
*   **Resource exhaustion:** Is there a way to craft a malicious file system that triggers excessive descriptor reads, leading to a denial-of-service?

Ultimately, my goal here is to determine whether the `fsverity_read_descriptor` function is secure, and efficient. I need to be sure that this piece of code fulfills its security requirements within the larger fs-verity picture.



30/3 2026/11/25 17:00 tool read-file
0m Args:
{
  "File": "fs/verity/read_metadata.c",
  "FirstLine": 100,
  "LineCount": 40
}

Results:
{
  "Contents": " 100:\t\n 101:\t\tif (copy_to_user(dst, src, length))\n 102:\t\t\treturn -EFAULT;\n 103:\t\n 104:\t\treturn length;\n 105:\t}\n 106:\t\n 107:\tstatic int fsverity_read_descriptor(struct inode *inode,\n 108:\t\t\t\t\t    void __user *buf, u64 offset, int length)\n 109:\t{\n 110:\t\tstruct fsverity_descriptor *desc;\n 111:\t\tsize_t desc_size;\n 112:\t\tint res;\n 113:\t\n 114:\t\tres = fsverity_get_descriptor(inode, \u0026desc);\n 115:\t\tif (res)\n 116:\t\t\treturn res;\n 117:\t\n 118:\t\t/* don't include the builtin signature */\n 119:\t\tdesc_size = offsetof(struct fsverity_descriptor, signature);\n 120:\t\tdesc-\u003esig_size = 0;\n 121:\t\n 122:\t\tres = fsverity_read_buffer(buf, offset, length, desc, desc_size);\n 123:\t\n 124:\t\tkfree(desc);\n 125:\t\treturn res;\n 126:\t}\n 127:\t\n 128:\tstatic int fsverity_read_signature(struct inode *inode,\n 129:\t\t\t\t\t   void __user *buf, u64 offset, int length)\n 130:\t{\n 131:\t\tstruct fsverity_descriptor *desc;\n 132:\t\tint res;\n 133:\t\n 134:\t\tres = fsverity_get_descriptor(inode, \u0026desc);\n 135:\t\tif (res)\n 136:\t\t\treturn res;\n 137:\t\n 138:\t\tif (desc-\u003esig_size == 0) {\n 139:\t\t\tres = -ENODATA;\n"
}

31/3 2026/11/25 17:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35989
							output: 36
							thoughts: 27
						

Thoughts:
Okay, let's dive into this. Here's my understanding, presented as a personal thought process, as if I were considering this myself:

**Understanding `fsverity_get_descriptor`**

Alright, I'm thinking about how the `fsverity` system functions, and I need to solidify my understanding of a key component. The question that has sprung to mind is, precisely, what is the functionality of `fsverity_get_descriptor`? To properly grasp the architecture, I need to know the purpose of that specific call. Time to dig in and clarify its specific role in the larger picture.



32/3 2026/11/25 17:00 tool read-file
0m Args:
{
  "File": "fs/verity/open.c",
  "FirstLine": 305,
  "LineCount": 40
}

Results:
{
  "Contents": " 305:\t * signature) from the filesystem, and do basic validation of it.\n 306:\t */\n 307:\tint fsverity_get_descriptor(struct inode *inode,\n 308:\t\t\t\t    struct fsverity_descriptor **desc_ret)\n 309:\t{\n 310:\t\tint size, res;\n 311:\t\tstruct fsverity_descriptor *desc;\n 312:\t\n 313:\t\tsize = inode-\u003ei_sb-\u003es_vop-\u003eget_verity_descriptor(inode, NULL, 0);\n 314:\t\tif (size \u003c 0) {\n 315:\t\t\tfsverity_err(inode, \"Error %d getting verity descriptor size\",\n 316:\t\t\t\t     size);\n 317:\t\t\treturn size;\n 318:\t\t}\n 319:\t\tif (size \u003c sizeof(*desc) || size \u003e FS_VERITY_MAX_DESCRIPTOR_SIZE) {\n 320:\t\t\tfsverity_err(inode,\n 321:\t\t\t\t     \"Verity descriptor has invalid size (%d bytes)\",\n 322:\t\t\t\t     size);\n 323:\t\t\treturn -EMSGSIZE;\n 324:\t\t}\n 325:\t\tdesc = kmalloc(size, GFP_KERNEL);\n 326:\t\tif (!desc)\n 327:\t\t\treturn -ENOMEM;\n 328:\t\tres = inode-\u003ei_sb-\u003es_vop-\u003eget_verity_descriptor(inode, desc, size);\n 329:\t\tif (res \u003c 0) {\n 330:\t\t\tfsverity_err(inode, \"Error %d reading verity descriptor\", res);\n 331:\t\t\tkfree(desc);\n 332:\t\t\treturn res;\n 333:\t\t}\n 334:\t\tif (res != size) {\n 335:\t\t\tfsverity_err(inode, \"Verity descriptor size changed (%d =\u003e %d)\",\n 336:\t\t\t\t     size, res);\n 337:\t\t\tkfree(desc);\n 338:\t\t\treturn -EINVAL;\n 339:\t\t}\n 340:\t\tif (!validate_fsverity_descriptor(inode, desc, size)) {\n 341:\t\t\tkfree(desc);\n 342:\t\t\treturn -EINVAL;\n 343:\t\t}\n 344:\t\n"
}

33/3 2026/11/25 17:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36799
							output: 45
							thoughts: 307
						

Thoughts:
**Diving into the XFS Verity Descriptor Retrieval**

Okay, here we go. First, I see `kmalloc` allocating memory for the descriptor, followed by a call to `inode->i_sb->s_vop->get_verity_descriptor`. Right, and that's likely the XFS implementation, `xfs_fsverity_get_descriptor`. Let's take a closer look at what's happening in there.

So, `xfs_fsverity_get_descriptor` is calculating `desc_pos`, which is a rounded-down position based on `desc_size`, aiming to retrieve the descriptor from somewhere. A crucial check ensures `desc_pos` isn't less than the metadata offset, because, of course, that's where the descriptor has to be! If it *is*, we mark the inode as sick, and return `ERANGE`. Makes sense. Now, `fsverity_pagecache_read` comes into play, attempting to read `desc_size` bytes into the allocated buffer. The assumption is that `buf_size` *does* equal `desc_size` in the earlier allocation. Let's see how `fsverity_pagecache_read` works and how it retrieves the verity descriptor.



34/3 2026/11/25 17:00 tool grepper
0m Args:
{
  "Expression": "fsverity_pagecache_read",
  "PathPrefixes": [
    "fs/verity",
    "include/linux/fsverity.h"
  ]
}

Results:
{
  "Output": "fs/verity/pagecache.c=80=EXPORT_SYMBOL_GPL(fsverity_fill_zerohash);\n--\nfs/verity/pagecache.c-82-/**\nfs/verity/pagecache.c:83: * fsverity_pagecache_read() - read verity metadata via the pagecache\nfs/verity/pagecache.c-84- * @inode:\tcopy from this inode's address space\n--\nfs/verity/pagecache.c-91- */\nfs/verity/pagecache.c:92:int fsverity_pagecache_read(struct inode *inode, void *buf, size_t count,\nfs/verity/pagecache.c-93-\t\t\t  loff_t pos)\n--\nfs/verity/pagecache.c-112-}\nfs/verity/pagecache.c:113:EXPORT_SYMBOL_GPL(fsverity_pagecache_read);\n--\ninclude/linux/fsverity.h=331=void generic_readahead_merkle_tree(struct inode *inode, pgoff_t index,\ninclude/linux/fsverity.h-332-\t\t\t\t   unsigned long nr_pages);\ninclude/linux/fsverity.h:333:int fsverity_pagecache_read(struct inode *inode, void *buf, size_t count,\ninclude/linux/fsverity.h-334-\t\t\t    loff_t pos);\n"
}

35/3 2026/11/25 17:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37792
							output: 36
							thoughts: 15
						

Thoughts:
Okay, here's my interpretation of reading `fs/verity/pagecache.c`, summarized as though the thoughts are my own:

**Diving into the Verity Page Cache**

Alright, let's take a look at `fs/verity/pagecache.c`. This is where the rubber meets the road for verified data access, specifically concerning the page cache. I know this code is crucial for performance. It's the point where we optimize reads and writes against the verified data blocks. I'm immediately looking for the core structures and functions. What's the main entry point for requests? How do they handle the verified metadata association with the cached pages? I want to see how the verity implementation interacts with the standard page cache interfaces and mechanisms, like `address_space_operations`, read and write path, and how it handles potential errors during verification. I expect to find mechanisms for handling corrupt data within the page cache. I'm curious about the specific strategies employed for invalidating and re-validating the cache. Are they using checksums and Merkle trees efficiently? How do they ensure that any cached data remains trustworthy, especially in the face of ongoing background verification tasks? My goal is to understand how this code achieves integrity without sacrificing performance. I'm going to look for areas where there might be room for optimization, especially in terms of handling potentially frequent data modifications or verification failures. I'll focus on synchronization and concurrency aspects too, because those are likely key for safe and fast operations. I want to see how this design balances performance, security, and scalability.



36/3 2026/11/25 17:00 tool read-file
0m Args:
{
  "File": "fs/verity/pagecache.c",
  "FirstLine": 80,
  "LineCount": 40
}

Results:
{
  "Contents": "  80:\tEXPORT_SYMBOL_GPL(fsverity_fill_zerohash);\n  81:\t\n  82:\t/**\n  83:\t * fsverity_pagecache_read() - read verity metadata via the pagecache\n  84:\t * @inode:\tcopy from this inode's address space\n  85:\t * @buf:\tbuffer to copy to\n  86:\t * @count:\tnumber of bytes to copy\n  87:\t * @pos:\tbyte offset in the file to copy from\n  88:\t *\n  89:\t * Read some verity metadata from the inode.  __vfs_read() can't be used because\n  90:\t * we need to read beyond i_size.\n  91:\t */\n  92:\tint fsverity_pagecache_read(struct inode *inode, void *buf, size_t count,\n  93:\t\t\t\t  loff_t pos)\n  94:\t{\n  95:\t\twhile (count) {\n  96:\t\t\tstruct folio *folio;\n  97:\t\t\tsize_t n;\n  98:\t\n  99:\t\t\tfolio = read_mapping_folio(inode-\u003ei_mapping, pos \u003e\u003e PAGE_SHIFT,\n 100:\t\t\t\t\t\t NULL);\n 101:\t\t\tif (IS_ERR(folio))\n 102:\t\t\t\treturn PTR_ERR(folio);\n 103:\t\n 104:\t\t\tn = memcpy_from_file_folio(buf, folio, pos, count);\n 105:\t\t\tfolio_put(folio);\n 106:\t\n 107:\t\t\tbuf += n;\n 108:\t\t\tpos += n;\n 109:\t\t\tcount -= n;\n 110:\t\t}\n 111:\t\treturn 0;\n 112:\t}\n 113:\tEXPORT_SYMBOL_GPL(fsverity_pagecache_read);\n"
}

37/3 2026/11/25 17:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38661
							output: 38
							thoughts: 2256
						

Thoughts:
**XFS fsverity Descriptor Calculation Analysis**

Okay, let's break this down. My initial thought process is centered around the discrepancies in calculating descriptor positions and sizes between write and read operations within the XFS fs-verity implementation. Specifically, I'm diving into `xfs_fsverity_get_descriptor` and `xfs_fsverity_write_descriptor` to understand how `desc_pos` and `desc_size_pos` are derived, and if there are any subtle bugs here.

The core of the issue boils down to the placement of the descriptor and its size on disk, and then validating that in reading the descriptor, we can accurately find the relevant information.  In `xfs_fsverity_write_descriptor`, `desc_pos` is aligned, and `desc_size_pos` is calculated relative to that.  I've been looking to understand if the rounding and alignment introduce any vulnerabilities or potential for misinterpretation during the read operation.

The key equations are:
*   In write: `desc_pos` is aligned up, `desc_size_pos` is a block away from the descriptor's end
*   In read: `desc_pos` is calculated by down-rounding based on `desc_size_pos` and `desc_size`.

My first intuition is to verify these computations. The logic seems correct: calculating `desc_size_pos` relative to `desc_pos` and ensuring they line up based on block boundaries and the size of the descriptor itself.

I've traced through a specific example, assuming a blocksize of 4096 bytes and exploring the relationship between `desc_pos`, `desc_size`, `desc_end`, and `desc_size_pos`. By plugging in a few different values for `desc_size` (both within a block and spanning multiple blocks), I've confirmed that the calculations align as expected.

Furthermore, I have verified that the intermediate bytes between `desc_end` and `desc_size_pos` are not written during the write process. Therefore, `xfs_fsverity_get_descriptor` always reads from the data written by `iomap_fsverity_write`.

My next step has been to inspect the `xfs_fsverity_ioend` structure and the associated I/O completion path. I wanted to verify that the `ioend` structure used during read operations is properly initialized and if there are any issues arising from `ioend->io_vi`. It seems that the `fsv_ioend` is allocated and initialized correctly in `xfs_end_io_read`, and that the `io_vi` field is properly propagated from `xfs_ioend_submit_read` or related functions.  Therefore, I've confirmed that these aspects of the implementation are sound.

In summary, after tracing the key variables and equations, I feel confident that the descriptor placement and retrieval logic within XFS fs-verity is well-defined and secure.



38/3 2026/11/25 17:00 tool grepper
0m Args:
{
  "Expression": "read_ctx.*vi",
  "PathPrefixes": [
    "fs/xfs",
    "fs/iomap"
  ]
}

Results:
{
  "Output": "no matches"
}

39/3 2026/11/25 17:00 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 41614
							output: 22
							thoughts: 21
						

Thoughts:
Here's my thought process, as requested:

**Debugging This Context Structure**

Alright, I need to figure out how this `ctx` structure relates to `vi`. My first instinct is to use the tools at my disposal. I'll start with the most basic approach: I'm going to leverage `grep`. I want to search through the codebase for instances where either `ctx->vi` is used directly, or, critically, where the definition of the structure itself, where `ctx` is defined, includes `vi` as a member. That will give me a very focused view of how `ctx` and `vi` are linked, in code. This grep will quickly show me the most direct connections and allow me to zoom in further, very quickly, on the interesting parts of the structure.



40/3 2026/11/25 17:01 tool grepper
0m Args:
{
  "Expression": "struct fsverity_info.*vi"
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 334 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (18 files in total):\nfs/btrfs/extent_io.c:6\nfs/buffer.c:2\nfs/ext4/readpage.c:6\nfs/f2fs/data.c:9\nfs/f2fs/f2fs.h:2\nfs/verity/enable.c:1\nfs/verity/fsverity_private.h:5\nfs/verity/measure.c:3\nfs/verity/open.c:6\nfs/verity/pagecache.c:1\nfs/verity/read_metadata.c:2\nfs/verity/signature.c:1\nfs/verity/verify.c:9\nfs/xfs/xfs_ioend.c:1\nfs/xfs/xfs_ioend.h:1\ninclude/linux/fsverity.h:9\ninclude/linux/iomap.h:2\ninclude/trace/events/fsverity.h:1\n\nfs/btrfs/extent_io.c=489=void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end,\n--\nfs/btrfs/extent_io.c-499-\nfs/btrfs/extent_io.c:500:static bool btrfs_verify_folio(struct fsverity_info *vi, struct folio *folio,\nfs/btrfs/extent_io.c-501-\t\t\t       u64 start, u32 len)\n--\nfs/btrfs/extent_io.c-509-\nfs/btrfs/extent_io.c:510:static void end_folio_read(struct fsverity_info *vi, struct folio *folio,\nfs/btrfs/extent_io.c-511-\t\t\t   bool uptodate, u64 start, u32 len)\n--\nfs/btrfs/extent_io.c=586=static void end_bbio_data_read(struct btrfs_bio *bbio)\n--\nfs/btrfs/extent_io.c-590-\tstruct bio *bio = \u0026bbio-\u003ebio;\nfs/btrfs/extent_io.c:591:\tstruct fsverity_info *vi = NULL;\nfs/btrfs/extent_io.c-592-\tstruct folio_iter fi;\n--\nfs/btrfs/extent_io.c=1030=static int btrfs_do_readpage(struct folio *folio, struct extent_map **em_cached,\nfs/btrfs/extent_io.c-1031-\t\t\t     struct btrfs_bio_ctrl *bio_ctrl,\nfs/btrfs/extent_io.c:1032:\t\t\t     struct fsverity_info *vi)\nfs/btrfs/extent_io.c-1033-{\n--\nfs/btrfs/extent_io.c=1386=int btrfs_read_folio(struct file *file, struct folio *folio)\n--\nfs/btrfs/extent_io.c-1397-\tstruct extent_map *em_cached = NULL;\nfs/btrfs/extent_io.c:1398:\tstruct fsverity_info *vi = NULL;\nfs/btrfs/extent_io.c-1399-\tint ret;\n--\nfs/btrfs/extent_io.c=2972=void btrfs_readahead(struct readahead_control *rac)\n--\nfs/btrfs/extent_io.c-2985-\tstruct extent_map *em_cached = NULL;\nfs/btrfs/extent_io.c:2986:\tstruct fsverity_info *vi = NULL;\nfs/btrfs/extent_io.c-2987-\n--\nfs/buffer.c=338=struct verify_bh_ctx {\n--\nfs/buffer.c-340-\tstruct buffer_head *bh;\nfs/buffer.c:341:\tstruct fsverity_info *vi;\nfs/buffer.c-342-};\n--\nfs/buffer.c=361=static void bh_end_async_read(struct bio *bio)\n--\nfs/buffer.c-365-\tstruct inode *inode = bh-\u003eb_folio-\u003emapping-\u003ehost;\nfs/buffer.c:366:\tstruct fsverity_info *vi = NULL;\nfs/buffer.c-367-\n--\nfs/ext4/readpage.c=55=struct ext4_verity_work {\nfs/ext4/readpage.c-56-\tstruct bio *bio;\nfs/ext4/readpage.c:57:\tstruct fsverity_info *vi;\nfs/ext4/readpage.c-58-\tstruct work_struct work;\n--\nfs/ext4/readpage.c=72=static void verity_work(struct work_struct *work)\n--\nfs/ext4/readpage.c-76-\tstruct bio *bio = ctx-\u003ebio;\nfs/ext4/readpage.c:77:\tstruct fsverity_info *vi = ctx-\u003evi;\nfs/ext4/readpage.c-78-\n--\nfs/ext4/readpage.c=103=static void mpage_end_io(struct bio *bio)\n--\nfs/ext4/readpage.c-115-\nfs/ext4/readpage.c:116:static void ext4_set_verity_work(struct bio *bio, struct fsverity_info *vi)\nfs/ext4/readpage.c-117-{\n--\nfs/ext4/readpage.c=129=static inline loff_t ext4_readpage_limit(struct inode *inode)\n--\nfs/ext4/readpage.c-136-\nfs/ext4/readpage.c:137:static int ext4_mpage_readpages(struct inode *inode, struct fsverity_info *vi,\nfs/ext4/readpage.c-138-\t\tstruct readahead_control *rac, struct folio *folio)\n--\nfs/ext4/readpage.c=321=int ext4_read_folio(struct file *file, struct folio *folio)\n--\nfs/ext4/readpage.c-323-\tstruct inode *inode = folio-\u003emapping-\u003ehost;\nfs/ext4/readpage.c:324:\tstruct fsverity_info *vi = NULL;\nfs/ext4/readpage.c-325-\tint ret;\n--\nfs/ext4/readpage.c=342=void ext4_readahead(struct readahead_control *rac)\n--\nfs/ext4/readpage.c-344-\tstruct inode *inode = rac-\u003emapping-\u003ehost;\nfs/ext4/readpage.c:345:\tstruct fsverity_info *vi = NULL;\nfs/ext4/readpage.c-346-\n--\nfs/f2fs/data.c=87=struct bio_post_read_ctx {\n--\nfs/f2fs/data.c-89-\tstruct f2fs_sb_info *sbi;\nfs/f2fs/data.c:90:\tstruct fsverity_info *vi;\nfs/f2fs/data.c-91-\tstruct work_struct work;\n--\nfs/f2fs/data.c=157=static void f2fs_verify_bio(struct work_struct *work)\n--\nfs/f2fs/data.c-162-\tbool may_have_compressed_pages = (ctx-\u003eenabled_steps \u0026 STEP_DECOMPRESS);\nfs/f2fs/data.c:163:\tstruct fsverity_info *vi = ctx-\u003evi;\nfs/f2fs/data.c-164-\n--\nfs/f2fs/data.c=1364=static struct bio *f2fs_grab_read_bio(struct inode *inode,\nfs/f2fs/data.c:1365:\t\t\t\t      struct fsverity_info *vi, block_t blkaddr,\nfs/f2fs/data.c-1366-\t\t\t\t      unsigned nr_pages, blk_opf_t op_flag,\n--\nfs/f2fs/data.c-1409-/* This can handle encryption stuffs */\nfs/f2fs/data.c:1410:static void f2fs_submit_page_read(struct inode *inode, struct fsverity_info *vi,\nfs/f2fs/data.c-1411-\t\t\t\t  struct folio *folio, block_t blkaddr,\n--\nfs/f2fs/data.c=2442=static inline blk_opf_t f2fs_ra_op_flags(struct readahead_control *rac)\n--\nfs/f2fs/data.c-2446-\nfs/f2fs/data.c:2447:static int f2fs_read_single_page(struct inode *inode, struct fsverity_info *vi,\nfs/f2fs/data.c-2448-\t\t\t\t struct folio *folio, unsigned int nr_pages,\n--\nfs/f2fs/data.c=2752=static int f2fs_read_data_large_folio(struct inode *inode,\nfs/f2fs/data.c:2753:\t\tstruct fsverity_info *vi,\nfs/f2fs/data.c-2754-\t\tstruct readahead_control *rac, struct folio *folio)\n--\nfs/f2fs/data.c-2903- */\nfs/f2fs/data.c:2904:static int f2fs_mpage_readpages(struct inode *inode, struct fsverity_info *vi,\nfs/f2fs/data.c-2905-\t\tstruct readahead_control *rac, struct folio *folio)\n--\nfs/f2fs/data.c=3032=static int f2fs_read_data_folio(struct file *file, struct folio *folio)\n--\nfs/f2fs/data.c-3034-\tstruct inode *inode = folio-\u003emapping-\u003ehost;\nfs/f2fs/data.c:3035:\tstruct fsverity_info *vi = NULL;\nfs/f2fs/data.c-3036-\tint ret;\n--\nfs/f2fs/data.c=3058=static void f2fs_readahead(struct readahead_control *rac)\n--\nfs/f2fs/data.c-3060-\tstruct inode *inode = rac-\u003emapping-\u003ehost;\nfs/f2fs/data.c:3061:\tstruct fsverity_info *vi = NULL;\nfs/f2fs/data.c-3062-\n--\nfs/f2fs/f2fs.h=1664=struct compress_ctx {\n--\nfs/f2fs/f2fs.h-1679-\tvoid *private2;\t\t\t/* extra payload buffer */\nfs/f2fs/f2fs.h:1680:\tstruct fsverity_info *vi;\t/* verity info if needed */\nfs/f2fs/f2fs.h-1681-};\n--\nfs/f2fs/f2fs.h=1693=struct decompress_io_ctx {\n--\nfs/f2fs/f2fs.h-1735-\tbool failed;\t\t\t/* IO error occurred before decompression? */\nfs/f2fs/f2fs.h:1736:\tstruct fsverity_info *vi;\t/* fs-verity context if needed */\nfs/f2fs/f2fs.h-1737-\tunsigned char compress_algorithm;\t/* backup algorithm type */\n--\nfs/verity/enable.c=181=static int enable_verity(struct file *filp,\n--\nfs/verity/enable.c-188-\tsize_t desc_size = struct_size(desc, signature, arg-\u003esig_size);\nfs/verity/enable.c:189:\tstruct fsverity_info *vi;\nfs/verity/enable.c-190-\tint err;\n--\nfs/verity/fsverity_private.h=145=struct fsverity_info *fsverity_create_info(struct inode *inode,\n--\nfs/verity/fsverity_private.h-147-\nfs/verity/fsverity_private.h:148:int fsverity_set_info(struct fsverity_info *vi);\nfs/verity/fsverity_private.h:149:void fsverity_free_info(struct fsverity_info *vi);\nfs/verity/fsverity_private.h:150:void fsverity_remove_info(struct fsverity_info *vi);\nfs/verity/fsverity_private.h-151-\n--\nfs/verity/fsverity_private.h=160=extern int fsverity_require_signatures;\nfs/verity/fsverity_private.h:161:int fsverity_verify_signature(const struct fsverity_info *vi,\nfs/verity/fsverity_private.h-162-\t\t\t      const u8 *signature, size_t sig_size);\n--\nfs/verity/fsverity_private.h=168=static inline int\nfs/verity/fsverity_private.h:169:fsverity_verify_signature(const struct fsverity_info *vi,\nfs/verity/fsverity_private.h-170-\t\t\t  const u8 *signature, size_t sig_size)\n--\nfs/verity/measure.c=26=int fsverity_ioctl_measure(struct file *filp, void __user *_uarg)\n--\nfs/verity/measure.c-29-\tstruct fsverity_digest __user *uarg = _uarg;\nfs/verity/measure.c:30:\tconst struct fsverity_info *vi;\nfs/verity/measure.c-31-\tconst struct fsverity_hash_alg *hash_alg;\n--\nfs/verity/measure.c=96=int fsverity_get_digest(struct inode *inode,\n--\nfs/verity/measure.c-99-{\nfs/verity/measure.c:100:\tconst struct fsverity_info *vi;\nfs/verity/measure.c-101-\tconst struct fsverity_hash_alg *hash_alg;\n--\nfs/verity/measure.c=131=__bpf_kfunc int bpf_get_fsverity_digest(struct file *file, const struct bpf_dynptr *digest_p)\n--\nfs/verity/measure.c-136-\tstruct fsverity_digest *arg;\nfs/verity/measure.c:137:\tconst struct fsverity_info *vi;\nfs/verity/measure.c-138-\tconst struct fsverity_hash_alg *hash_alg;\n--\nfs/verity/open.c=189=struct fsverity_info *fsverity_create_info(struct inode *inode,\n--\nfs/verity/open.c-191-{\nfs/verity/open.c:192:\tstruct fsverity_info *vi;\nfs/verity/open.c-193-\tint err;\n--\nfs/verity/open.c-253-\nfs/verity/open.c:254:int fsverity_set_info(struct fsverity_info *vi)\nfs/verity/open.c-255-{\n--\nfs/verity/open.c=370=int fsverity_ensure_verity_info(struct inode *inode)\nfs/verity/open.c-371-{\nfs/verity/open.c:372:\tstruct fsverity_info *vi = fsverity_get_info(inode), *found;\nfs/verity/open.c-373-\tstruct fsverity_descriptor *desc;\n--\nfs/verity/open.c=423=EXPORT_SYMBOL_GPL(__fsverity_file_open);\nfs/verity/open.c-424-\nfs/verity/open.c:425:void fsverity_free_info(struct fsverity_info *vi)\nfs/verity/open.c-426-{\n--\nfs/verity/open.c=432=static void fsverity_free_info_rcu(struct rcu_head *head)\n--\n\n"
}

41/3 2026/11/25 17:01 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46054
							output: 36
							thoughts: 15
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:

**Diving into the I/O Mapping Landscape**

Right, let's get down to brass tacks. I'm thinking I need to refresh my memory on the kernel's I/O mapping mechanisms. Specifically, I should probably double check the definitions and structures involved in how the kernel handles I/O operations, particularly those that map device memory into the virtual address space. I'm going to jump into `include/linux/iomap.h`. I'm hoping I'll find a concise definition or high-level overview of the `iomap` subsystem, including any key structures like `struct iomap` itself or relevant macros and helper functions. I need to quickly ascertain the fundamental building blocks of how the kernel manages direct memory access and similar I/O methods. I want to refresh my understanding of where the abstractions begin and end.



42/3 2026/11/25 17:01 tool grepper
0m Args:
{
  "Expression": "struct fsverity_info",
  "PathPrefixes": [
    "include/linux/iomap.h"
  ]
}

Results:
{
  "Output": "include/linux/iomap.h=524=struct iomap_ioend {\n--\ninclude/linux/iomap.h-535-\tvoid\t\t\t*io_private;\t/* file system private data */\ninclude/linux/iomap.h:536:\tstruct fsverity_info\t*io_vi;\t\t/* fsverity info */\ninclude/linux/iomap.h-537-\tstruct bio\t\tio_bio;\t\t/* MUST BE LAST! */\n--\ninclude/linux/iomap.h=618=struct iomap_read_folio_ctx {\n--\ninclude/linux/iomap.h-623-\tloff_t\t\t\tread_ctx_file_offset;\ninclude/linux/iomap.h:624:\tstruct fsverity_info\t*vi;\ninclude/linux/iomap.h-625-};\n"
}

43/3 2026/11/25 17:01 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46544
							output: 29
							thoughts: 387
						

Thoughts:
**Analyzing the Initialization of `iomap_read_folio_ctx` in XFS's VM Operations**

Okay, let's break down how the `iomap_read_folio_ctx` struct is initialized within the XFS filesystem, specifically within the `xfs_vm_read_folio` and `xfs_vm_readahead` functions. Diving into `fs/xfs/xfs_aops.c`, I see that in `xfs_vm_read_folio`, a `struct iomap_read_folio_ctx ctx` is initialized with `{ .cur_folio = folio }`.  Similarly, `xfs_vm_readahead` initializes `ctx` with `{ .rac = rac }`. This immediately makes me think about what's *not* initialized. I know in C, using a designated initializer, any unspecified members get zero-initialized. So, `ctx.vi` is `NULL`, `ctx.read_ctx` is `NULL`, and so on.

The question then becomes: where are these other fields being populated? This is crucial because `iomap_read_folio_ctx` is obviously more than just a holder for the folio or readahead control. It's clearly a context object, and those other fields must have a role.  Since I see that `ctx.ops` is populated with the call `xfs_get_iomap_read_ops()`, which likely sets function pointers used for the I/O operations, now I need to trace *how* the other members like `ctx.vi` get set. Therefore, I need to check `iomap_read_folio` and `iomap_readahead` themselves to understand the complete initialization and usage of this context.



44/3 2026/11/25 17:01 tool grepper
0m Args:
{
  "Expression": "ctx-\u003evi",
  "PathPrefixes": [
    "fs/iomap"
  ]
}

Results:
{
  "Output": "fs/iomap/buffered-io.c=557=static int iomap_read_folio_iter(struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-600-\t\t *   2. This folio contains merkle tree blocks which need to be\nfs/iomap/buffered-io.c:601:\t\t *\tsynthesized. If we already have fsverity info (ctx-\u003evi)\nfs/iomap/buffered-io.c-602-\t\t *\tsynthesize these blocks.\n--\nfs/iomap/buffered-io.c-605-\t\t    iomap-\u003etype == IOMAP_HOLE) {\nfs/iomap/buffered-io.c:606:\t\t\tif (ctx-\u003evi)\nfs/iomap/buffered-io.c-607-\t\t\t\tfsverity_fill_zerohash(folio, poff, plen,\nfs/iomap/buffered-io.c:608:\t\t\t\t\t\t       ctx-\u003evi);\nfs/iomap/buffered-io.c-609-\t\t\tiomap_set_range_uptodate(folio, poff, plen);\n--\nfs/iomap/buffered-io.c-612-\t\t\tfolio_zero_range(folio, poff, plen);\nfs/iomap/buffered-io.c:613:\t\t\tif (ctx-\u003evi \u0026\u0026\nfs/iomap/buffered-io.c:614:\t\t\t    !fsverity_verify_blocks(ctx-\u003evi, folio, plen, poff))\nfs/iomap/buffered-io.c-615-\t\t\t\treturn -EIO;\n--\nfs/iomap/buffered-io.c=651=void iomap_read_folio(iomap_iter_next_fn next, struct iomap_read_folio_ctx *ctx,\n--\nfs/iomap/buffered-io.c-669-\t */\nfs/iomap/buffered-io.c:670:\tctx-\u003evi = fsverity_get_info(iter.inode);\nfs/iomap/buffered-io.c:671:\tif (ctx-\u003evi \u0026\u0026 iter.pos \u003c i_size_read(iter.inode))\nfs/iomap/buffered-io.c:672:\t\tfsverity_readahead(ctx-\u003evi, folio-\u003eindex,\nfs/iomap/buffered-io.c-673-\t\t\t\t   folio_nr_pages(folio));\n--\nfs/iomap/buffered-io.c=728=void iomap_readahead(iomap_iter_next_fn next, struct iomap_read_folio_ctx *ctx,\n--\nfs/iomap/buffered-io.c-745-\t */\nfs/iomap/buffered-io.c:746:\tctx-\u003evi = fsverity_get_info(iter.inode);\nfs/iomap/buffered-io.c:747:\tif (ctx-\u003evi \u0026\u0026 iter.pos \u003c i_size_read(iter.inode))\nfs/iomap/buffered-io.c:748:\t\tfsverity_readahead(ctx-\u003evi, readahead_index(rac),\nfs/iomap/buffered-io.c-749-\t\t\t\treadahead_count(rac));\n"
}

45/3 2026/11/25 17:01 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 48168
							output: 47
							thoughts: 593
						

Thoughts:
**Tracing the XFS fs-verity Metadata Handling in iomap**

Okay, so I'm digging into how XFS handles fs-verity metadata within the `iomap` framework, specifically after observing calls to `iomap_read_folio` and `iomap_readahead` setting `ctx->vi = fsverity_get_info(iter.inode)`.  The focus now is on how the offset is incorporated when mapping blocks.

My current concern centers around `xfs_bmbt_to_iomap`, which is clearly the critical function for translating block map entries into `iomap` structures. I need to understand where the `offset` parameter originates and how it influences the `iomap` process.

I see `xfs_bmbt_to_iomap` is called from `xfs_bmap.c`, `xfs_aops.c`, `xfs_pnfs.c` and `xfs_iomap.c`, which makes sense given the various contexts where block mapping occurs. The most relevant piece of the puzzle is inside of `xfs_bmbt_to_iomap` itself, where it checks `if (!(iomap_flags & IOMAP_F_XATTR) && xfs_iomap_is_fsverity_metadata(ip, offset))`.  This line is key. It's conditionally setting the `IOMAP_F_FSVERITY` flag on the `iomap` structure, but only if the operation *isn't* related to extended attributes and if the `offset` falls within the fs-verity metadata region, as determined by `xfs_iomap_is_fsverity_metadata`.

Looking into that function, `xfs_iomap_is_fsverity_metadata` then checks if the provided `offset` is greater than or equal to `xfs_fsverity_metadata_offset(ip)` and if either the fs-verity is building or active.  This confirms the offset comparison as the driver for this functionality.

Now I need to understand what `IOMAP_F_FSVERITY` actually *does*. I need to drill down into the `fs/iomap` code and see how that flag is used and how it interacts with fs-verity. That will give me the full picture on how this metadata is handled when read requests come in.



46/3 2026/11/25 17:02 tool grepper
0m Args:
{
  "Expression": "IOMAP_F_FSVERITY",
  "PathPrefixes": [
    "fs/iomap",
    "include/linux/iomap.h"
  ]
}

Results:
{
  "Output": "fs/iomap/buffered-io.c=382=static inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-402-\t */\nfs/iomap/buffered-io.c:403:\tif (srcmap-\u003eflags \u0026 IOMAP_F_FSVERITY)\nfs/iomap/buffered-io.c-404-\t\treturn false;\n--\nfs/iomap/buffered-io.c=557=static int iomap_read_folio_iter(struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-603-\t\t */\nfs/iomap/buffered-io.c:604:\t\tif ((iomap-\u003eflags \u0026 IOMAP_F_FSVERITY) \u0026\u0026\nfs/iomap/buffered-io.c-605-\t\t    iomap-\u003etype == IOMAP_HOLE) {\n--\nfs/iomap/buffered-io.c=1189=static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i,\n--\nfs/iomap/buffered-io.c-1259-\t\tif (pos + written \u003e old_size \u0026\u0026\nfs/iomap/buffered-io.c:1260:\t\t    !(iter-\u003eiomap.flags \u0026 IOMAP_F_FSVERITY)) {\nfs/iomap/buffered-io.c-1261-\t\t\ti_size_write(iter-\u003einode, pos + written);\n--\nfs/iomap/buffered-io.c-1265-\nfs/iomap/buffered-io.c:1266:\t\tif (old_size \u003c pos \u0026\u0026 !(iter-\u003eiomap.flags \u0026 IOMAP_F_FSVERITY))\nfs/iomap/buffered-io.c-1267-\t\t\tpagecache_isize_extended(iter-\u003einode, old_size, pos);\n--\nfs/iomap/buffered-io.c=1927=static bool iomap_writeback_handle_eof(struct folio *folio,\n--\nfs/iomap/buffered-io.c-1932-\nfs/iomap/buffered-io.c:1933:\tif (wpc-\u003eiomap.flags \u0026 IOMAP_F_FSVERITY) {\nfs/iomap/buffered-io.c-1934-\t\tWARN_ON_ONCE(folio_pos(folio) \u003c isize);\n--\nfs/iomap/trace.h=87=DEFINE_RANGE_EVENT(iomap_zero_iter);\n--\nfs/iomap/trace.h-121-\t{ IOMAP_F_STALE,\t\"STALE\" }, \\\nfs/iomap/trace.h:122:\t{ IOMAP_F_FSVERITY,\t\"FSVERITY\" }, \\\nfs/iomap/trace.h-123-\t{ IOMAP_F_ZERO_TAIL,\t\"ZERO TAIL\" }\n--\ninclude/linux/iomap.h=26=struct vm_fault;\n--\ninclude/linux/iomap.h-100- */\ninclude/linux/iomap.h:101:#define IOMAP_F_FSVERITY\t(1U \u003c\u003c 11)\ninclude/linux/iomap.h-102-\n"
}

47/3 2026/11/25 17:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 50210
							output: 39
							thoughts: 54
						

Thoughts:
Here's my analysis of the provided thought process:

**Diving into `iomap_block_needs_zeroing`**

Okay, let's drill down into `fs/iomap/buffered-io.c`, specifically around line 382, to understand `iomap_block_needs_zeroing`. This function is core to handling buffered I/O with iomap, so a thorough understanding is key. I'm immediately curious about the inclusion of `IOMAP_F_FSVERITY` in the checks. I understand its relationship with file integrity, but how is it impacting this particular zeroing function? I need to figure out why the verity flag is influencing the determination of whether a block needs to be zeroed or not. Is there a connection to securely writing data? Is it about ensuring that a verified read never encounters uninitialized data? It's time to dig deeper and figure out the exact logic here.



48/3 2026/11/25 17:02 tool read-file
0m Args:
{
  "File": "fs/iomap/buffered-io.c",
  "FirstLine": 380,
  "LineCount": 35
}

Results:
{
  "Contents": " 380:\t}\n 381:\t\n 382:\tstatic inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter,\n 383:\t\t\tloff_t pos)\n 384:\t{\n 385:\t\tconst struct iomap *srcmap = iomap_iter_srcmap(iter);\n 386:\t\n 387:\t\t/*\n 388:\t\t * If this block has not been written, there's nothing to read\n 389:\t\t */\n 390:\t\tif (srcmap-\u003etype != IOMAP_MAPPED)\n 391:\t\t\treturn true;\n 392:\t\n 393:\t\t/*\n 394:\t\t * Newly allocated blocks have not been written\n 395:\t\t */\n 396:\t\tif (srcmap-\u003eflags \u0026 IOMAP_F_NEW)\n 397:\t\t\treturn true;\n 398:\t\n 399:\t\t/*\n 400:\t\t * fsverity metadata is stored past i_size, we need to read it instead\n 401:\t\t * of zeroing\n 402:\t\t */\n 403:\t\tif (srcmap-\u003eflags \u0026 IOMAP_F_FSVERITY)\n 404:\t\t\treturn false;\n 405:\t\n 406:\t\treturn pos \u003e= i_size_read(iter-\u003einode);\n 407:\t}\n 408:\t\n 409:\t/**\n 410:\t * iomap_read_inline_data - copy inline data into the page cache\n 411:\t * @iter: iteration structure\n 412:\t * @folio: folio to copy to\n 413:\t *\n 414:\t * Copy the inline data in @iter into @folio and zero out the rest of the folio.\n"
}

49/3 2026/11/25 17:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 50989
							output: 28
							thoughts: 1352
						

Thoughts:
**XFS FSVerity Integration and Data Handling**

Alright, let's break this down. My initial thought was about `iomap_block_needs_zeroing`. The core of it is that, while regular files zero past `i_size`, the metadata for fsverity is stored beyond `i_size`. That means we shouldn't zero the existing block when reading it. That's a key distinction.

Now I'm diving into `scrub/inode.c`. The code explicitly addresses scenarios where fsverity descriptors can't be activated, typically during file repair. The logic is crystal clear: if we're going to repair a file and the fsverity descriptor is broken, we *must* drop the stale Merkle tree folios. The comment says it all: we have to clear the page cache to prevent this stale data from being exposed later through extending writes or truncates. It's a proactive measure to maintain data integrity.

Next, I'm verifying the supporting functions, `xchk_inode_verity_broken` and `xchk_inode_setup_verity`. The latter checks if fsverity is active. We have the `fsverity_ensure_verity_info` function. Following that is `xrep_inode_verity`. If the descriptor is broken, verity is disabled and the Merkle tree is freed beyond EOF, and the stale Merkle tree page cache was already cleared during the scrub setup. This `xfs_bunmapi_range` call is interesting, because it will call `xfs_bunmapi` with a range from 0 to `XFS_B_TO_FSB(mp, XFS_ISIZE(sc->ip))` and then up to `XFS_MAX_FILEOFF`. It seems this is where we're unmapping the extents to remove this information. We also see the core flags change and logging.

Checking the `xfs_bunmapi` changes, I see a crucial point. It explicitly only deletes unwritten extents if `XFS_BMAPI_UNWRITTEN` is passed. This seems like a filter ensuring we only touch unwritten extents.

The `xfs_ioctl.c` section is straightforward: The fsverity ioctls—`FS_IOC_ENABLE_VERITY`, `FS_IOC_MEASURE_VERITY`, and `FS_IOC_READ_VERITY_METADATA`—are all just wrappers that call existing fsverity core functions. Nothing special there.

Finally, I'm looking for any user-facing changes. The `struct xfs_bulkstat` definition, `XFS_BS_SICK_FSVERITY`, is there, along with the `ino_map[]` in `fs/xfs/xfs_health.c`. The question now is whether this is exposed to userspace via bulkstat ioctls. I need to trace how `ino_map` is used to confirm that.



50/3 2026/11/25 17:02 tool grepper
0m Args:
{
  "Expression": "ino_map",
  "PathPrefixes": [
    "fs/xfs"
  ]
}

Results:
{
  "Output": "fs/xfs/xfs_health.c=600=xfs_healthmon_rtgroup_mask(\n--\nfs/xfs/xfs_health.c-613-\nfs/xfs/xfs_health.c:614:static const struct ioctl_sick_map ino_map[] = {\nfs/xfs/xfs_health.c-615-\t{ XFS_SICK_INO_CORE,\tXFS_BS_SICK_INODE },\n--\nfs/xfs/xfs_health.c=633=xfs_bulkstat_health(\n--\nfs/xfs/xfs_health.c-644-\txfs_inode_measure_sickness(ip, \u0026sick, \u0026checked);\nfs/xfs/xfs_health.c:645:\tfor_each_sick_map(ino_map, m) {\nfs/xfs/xfs_health.c-646-\t\tif (checked \u0026 m-\u003esick_mask)\n--\nfs/xfs/xfs_health.c=655=xfs_healthmon_inode_mask(\n--\nfs/xfs/xfs_health.c-660-\nfs/xfs/xfs_health.c:661:\tfor_each_sick_map(ino_map, m) {\nfs/xfs/xfs_health.c-662-\t\tif (sick_mask \u0026 m-\u003esick_mask)\n"
}

51/3 2026/11/25 17:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 53377
							output: 39
							thoughts: 13
						

Thoughts:
Okay, here's my interpretation of "Let's see `xfs_bulkstat_health`," presented as a first-person thought process, keeping in mind the user is an expert.

**Analyzing `xfs_bulkstat_health`**

Alright, time to dig into this `xfs_bulkstat_health` functionality. I need to refresh my memory on what this tool actually does within the XFS ecosystem. More specifically, what's its purpose? Is it a quick diagnostic, a deeper performance analysis tool, or perhaps something that offers more extensive health checks? I should look at its output to understand how its results align with potential areas of investigation. I will evaluate what kind of information `xfs_bulkstat_health` provides, specifically focusing on the metrics and data presented. I'll mentally compare its behavior to other relevant utilities like `xfs_db` or even `xfs_growfs` in certain scenarios. Is it checking file system metadata consistency, looking for allocation issues, or something else entirely? A quick check of the man page, or better yet, a look at the code if I have it handy, will be a good starting point. I should be able to quickly determine how it integrates with XFS's core data structures and error handling mechanisms to get a solid grasp of its utility. Ultimately, I want to understand if this is something I can use effectively for quick triage, or if it requires a more in-depth analysis afterward. I need to assess its value as part of my toolbox.



52/3 2026/11/25 17:02 tool read-file
0m Args:
{
  "File": "fs/xfs/xfs_health.c",
  "FirstLine": 630,
  "LineCount": 30
}

Results:
{
  "Contents": " 630:\t\n 631:\t/* Fill out bulkstat health info. */\n 632:\tvoid\n 633:\txfs_bulkstat_health(\n 634:\t\tstruct xfs_inode\t\t*ip,\n 635:\t\tstruct xfs_bulkstat\t\t*bs)\n 636:\t{\n 637:\t\tconst struct ioctl_sick_map\t*m;\n 638:\t\tunsigned int\t\t\tsick;\n 639:\t\tunsigned int\t\t\tchecked;\n 640:\t\n 641:\t\tbs-\u003ebs_sick = 0;\n 642:\t\tbs-\u003ebs_checked = 0;\n 643:\t\n 644:\t\txfs_inode_measure_sickness(ip, \u0026sick, \u0026checked);\n 645:\t\tfor_each_sick_map(ino_map, m) {\n 646:\t\t\tif (checked \u0026 m-\u003esick_mask)\n 647:\t\t\t\tbs-\u003ebs_checked |= m-\u003eioctl_mask;\n 648:\t\t\tif (sick \u0026 m-\u003esick_mask)\n 649:\t\t\t\tbs-\u003ebs_sick |= m-\u003eioctl_mask;\n 650:\t\t}\n 651:\t}\n 652:\t\n 653:\t/* Translate XFS_SICK_INO_* into XFS_BS_SICK_*. */\n 654:\tunsigned int\n 655:\txfs_healthmon_inode_mask(\n 656:\t\tunsigned int\t\t\tsick_mask)\n 657:\t{\n 658:\t\tconst struct ioctl_sick_map\t*m;\n 659:\t\tunsigned int\t\t\tioctl_mask = 0;\n"
}

53/3 2026/11/25 17:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 54192
							output: 40
							thoughts: 185
						

Thoughts:
**XFS Verity Dive**

Okay, so I've checked `xfs_bulkstat_health` and I'm confident that the `bs_sick` and `bs_checked` fields are being handled correctly. No uninitialized memory issues there. And that `XFS_FSOP_GEOM_FLAGS_VERITY` flag... that's straightforward. If the mount point has verity enabled, we set the flag in the `geo` struct. `geo` is a `xfs_fsop_geom` which is either zeroed or initialized in `xfs_fs_geometry`. Nothing concerning stands out there.

Now, I really need to get granular with this verity stuff. Time to meticulously dissect `xfs_fsverity.c`. I'm going to go through it line by line. I need to be absolutely certain there are no sneaky memory allocations, any instances of uninitialized struct usage, or any potential buffer copying issues that I might have missed in a cursory review. This requires a deep dive into the code.



54/3 2026/11/25 17:02 tool read-file
0m Args:
{
  "File": "fs/xfs/xfs_fsverity.c",
  "FirstLine": 1,
  "LineCount": 100
}

Results:
{
  "Contents": "   1:\t// SPDX-License-Identifier: GPL-2.0\n   2:\t/*\n   3:\t * Copyright (C) 2026 Red Hat, Inc.\n   4:\t */\n   5:\t#include \"xfs_platform.h\"\n   6:\t#include \"xfs_fs.h\"\n   7:\t#include \"xfs_shared.h\"\n   8:\t#include \"xfs_format.h\"\n   9:\t#include \"xfs_trans_resv.h\"\n  10:\t#include \"xfs_mount.h\"\n  11:\t#include \"xfs_inode.h\"\n  12:\t#include \"xfs_log_format.h\"\n  13:\t#include \"xfs_trans.h\"\n  14:\t#include \"xfs_trace.h\"\n  15:\t#include \"xfs_quota.h\"\n  16:\t#include \"xfs_fsverity.h\"\n  17:\t#include \"xfs_iomap.h\"\n  18:\t#include \"xfs_error.h\"\n  19:\t#include \"xfs_health.h\"\n  20:\t#include \"xfs_bmap_util.h\"\n  21:\t#include \"xfs_icache.h\"\n  22:\t#include \u003clinux/fsverity.h\u003e\n  23:\t#include \u003clinux/iomap.h\u003e\n  24:\t#include \u003clinux/pagemap.h\u003e\n  25:\t\n  26:\tstruct kmem_cache *xfs_fsverity_ioend_cache;\n  27:\tmempool_t xfs_fsverity_ioend_pool;\n  28:\t\n  29:\t#define XFS_FSVERITY_IOEND_POOL_MIN\t128\n  30:\t\n  31:\t/*\n  32:\t * Back the fsverity ioend allocations with a mempool so that read I/O\n  33:\t * completion always makes forward progress and cannot deadlock\n  34:\t */\n  35:\tint\n  36:\txfs_fsverity_init(void)\n  37:\t{\n  38:\t\treturn mempool_init_slab_pool(\u0026xfs_fsverity_ioend_pool,\n  39:\t\t\t\tXFS_FSVERITY_IOEND_POOL_MIN, xfs_fsverity_ioend_cache);\n  40:\t}\n  41:\t\n  42:\tvoid\n  43:\txfs_fsverity_exit(void)\n  44:\t{\n  45:\t\tmempool_exit(\u0026xfs_fsverity_ioend_pool);\n  46:\t}\n  47:\t\n  48:\tbool\n  49:\txfs_fsverity_is_file_data(\n  50:\t\tconst struct xfs_inode\t*ip,\n  51:\t\tloff_t\t\t\toffset)\n  52:\t{\n  53:\t\treturn fsverity_active(VFS_IC(ip)) \u0026\u0026\n  54:\t\t\t\toffset \u003c xfs_fsverity_metadata_offset(ip);\n  55:\t}\n  56:\t\n  57:\t/*\n  58:\t * Retrieve the verity descriptor.\n  59:\t */\n  60:\tstatic int\n  61:\txfs_fsverity_get_descriptor(\n  62:\t\tstruct inode\t\t*inode,\n  63:\t\tvoid\t\t\t*buf,\n  64:\t\tsize_t\t\t\tbuf_size)\n  65:\t{\n  66:\t\tstruct xfs_inode\t*ip = XFS_I(inode);\n  67:\t\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n  68:\t\t__be32\t\t\td_desc_size;\n  69:\t\tu32\t\t\tdesc_size;\n  70:\t\tu64\t\t\tdesc_size_pos;\n  71:\t\tint\t\t\terror;\n  72:\t\tu64\t\t\tdesc_pos;\n  73:\t\tstruct xfs_bmbt_irec\trec;\n  74:\t\tint\t\t\tis_empty;\n  75:\t\tuint32_t\t\tblocksize = i_blocksize(VFS_I(ip));\n  76:\t\txfs_fileoff_t\t\tlast_block_offset;\n  77:\t\n  78:\t\t/*\n  79:\t\t * fs-verity cannot be used when the filesystem block size exceeds the\n  80:\t\t * page size, as the Merkle tree folios are compound and PG_checked is\n  81:\t\t * not supported on compound folios.  Reject such inodes so that they\n  82:\t\t * cannot be opened and read as verity files.\n  83:\t\t */\n  84:\t\tif (mp-\u003em_sb.sb_blocksize \u003e PAGE_SIZE)\n  85:\t\t\treturn -EOPNOTSUPP;\n  86:\t\n  87:\t\txfs_ilock(ip, XFS_ILOCK_EXCL);\n  88:\t\t/*\n  89:\t\t * Serialize reading of inode-\u003ei_flags with xfs_scrub clearing of this\n  90:\t\t * flag if inode is corrupted.\n  91:\t\t */\n  92:\t\tif (!(inode-\u003ei_flags \u0026 S_VERITY)) {\n  93:\t\t\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n  94:\t\t\treturn -ENODATA;\n  95:\t\t}\n  96:\t\terror = xfs_bmap_last_extent(NULL, ip, XFS_DATA_FORK, \u0026rec, \u0026is_empty);\n  97:\t\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n  98:\t\tif (error)\n  99:\t\t\treturn error;\n 100:\t\n"
}

55/3 2026/11/25 17:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 56121
							output: 42
							thoughts: 20
						

Thoughts:
Okay, here we go...

**Diving Back into `fs/xfs/xfs_fsverity.c`**

Alright, back to it. Time to dig deeper into the `xfs_fsverity.c` code. I'm already pretty familiar with the XFS file system internals, but I want to refresh my understanding of their implementation of FS-verity. I'm keen to examine the specifics of how they're handling integrity checks at the block level. I'm interested in the interplay between XFS's existing metadata structures and the demands of this verification feature. Specifically, I'll be looking for how they've integrated the integrity trees, where the digests are stored. I need to understand how efficiently they've implemented the read path to minimize the performance impact. Also how the write path is secured and how they prevent potential vulnerabilities within this context. I'll need to pay close attention to the error handling as well; it's critical to see how they manage corrupted data or issues during verification. Let's see how they've tackled this challenging problem.



56/3 2026/11/25 17:02 tool read-file
0m Args:
{
  "File": "fs/xfs/xfs_fsverity.c",
  "FirstLine": 101,
  "LineCount": 100
}

Results:
{
  "Contents": " 101:\t\tif (is_empty) {\n 102:\t\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n 103:\t\t\treturn -ENODATA;\n 104:\t\t}\n 105:\t\n 106:\t\t/*\n 107:\t\t * Make sure we can open large file on a 32-bit kernel\n 108:\t\t */\n 109:\t\tif (rec.br_startoff + rec.br_blockcount \u003e\n 110:\t\t\t\tXFS_B_TO_FSB(mp, inode-\u003ei_sb-\u003es_maxbytes))\n 111:\t\t\treturn -EFBIG;\n 112:\t\n 113:\t\tlast_block_offset =\n 114:\t\t\tXFS_FSB_TO_B(mp, rec.br_startoff + rec.br_blockcount);\n 115:\t\tif (last_block_offset \u003c= xfs_fsverity_metadata_offset(ip)) {\n 116:\t\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n 117:\t\t\treturn -ENODATA;\n 118:\t\t}\n 119:\t\n 120:\t\tdesc_size_pos = last_block_offset - sizeof(__be32);\n 121:\t\terror = fsverity_pagecache_read(inode, (char *)\u0026d_desc_size,\n 122:\t\t\t\tsizeof(d_desc_size), desc_size_pos);\n 123:\t\tif (error)\n 124:\t\t\treturn error;\n 125:\t\n 126:\t\tdesc_size = be32_to_cpu(d_desc_size);\n 127:\t\tif (XFS_IS_CORRUPT(mp, desc_size \u003e FS_VERITY_MAX_DESCRIPTOR_SIZE)) {\n 128:\t\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n 129:\t\t\treturn -ERANGE;\n 130:\t\t}\n 131:\t\n 132:\t\tif (XFS_IS_CORRUPT(mp, desc_size \u003e desc_size_pos)) {\n 133:\t\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n 134:\t\t\treturn -ERANGE;\n 135:\t\t}\n 136:\t\n 137:\t\tif (!buf_size)\n 138:\t\t\treturn desc_size;\n 139:\t\n 140:\t\tif (XFS_IS_CORRUPT(mp, desc_size \u003e buf_size)) {\n 141:\t\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n 142:\t\t\treturn -ERANGE;\n 143:\t\t}\n 144:\t\n 145:\t\tdesc_pos = round_down(desc_size_pos - desc_size, blocksize);\n 146:\t\tif (desc_pos \u003c xfs_fsverity_metadata_offset(ip)) {\n 147:\t\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n 148:\t\t\treturn -ERANGE;\n 149:\t\t}\n 150:\t\n 151:\t\terror = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);\n 152:\t\tif (error)\n 153:\t\t\treturn error;\n 154:\t\n 155:\t\treturn desc_size;\n 156:\t}\n 157:\t\n 158:\tstatic int\n 159:\txfs_fsverity_write_descriptor(\n 160:\t\tstruct file\t\t*file,\n 161:\t\tconst void\t\t*desc,\n 162:\t\tu32\t\t\tdesc_size,\n 163:\t\tu64\t\t\tmerkle_tree_size)\n 164:\t{\n 165:\t\tint\t\t\terror;\n 166:\t\tstruct inode\t\t*inode = file_inode(file);\n 167:\t\tstruct xfs_inode\t*ip = XFS_I(inode);\n 168:\t\tunsigned int\t\tblksize = ip-\u003ei_mount-\u003em_sb.sb_blocksize;\n 169:\t\tu64\t\t\ttree_last_block =\n 170:\t\t\t\txfs_fsverity_metadata_offset(ip) + merkle_tree_size;\n 171:\t\tu64\t\t\tdesc_pos =\n 172:\t\t\t\tround_up(tree_last_block, XFS_FSVERITY_START_ALIGN);\n 173:\t\tu64\t\t\tdesc_end = desc_pos + desc_size;\n 174:\t\t__be32\t\t\tdesc_size_disk = cpu_to_be32(desc_size);\n 175:\t\tu64\t\t\tdesc_size_pos =\n 176:\t\t\t\tround_up(desc_end + sizeof(desc_size_disk), blksize) -\n 177:\t\t\t\tsizeof(desc_size_disk);\n 178:\t\n 179:\t\tif (desc_size_pos + sizeof(desc_size_disk) \u003e inode-\u003ei_sb-\u003es_maxbytes)\n 180:\t\t\treturn -EFBIG;\n 181:\t\n 182:\t\terror = iomap_fsverity_write(file, desc_size_pos, sizeof(__be32),\n 183:\t\t\t\t(const void *)\u0026desc_size_disk,\n 184:\t\t\t\txfs_buffered_write_iomap_next,\n 185:\t\t\t\t\u0026xfs_iomap_write_ops);\n 186:\t\tif (error)\n 187:\t\t\treturn error;\n 188:\t\n 189:\t\treturn iomap_fsverity_write(file, desc_pos, desc_size, desc,\n 190:\t\t\t\txfs_buffered_write_iomap_next,\n 191:\t\t\t\t\u0026xfs_iomap_write_ops);\n 192:\t}\n 193:\t\n 194:\t/*\n 195:\t * Try to remove all the fsverity metadata after a failed enablement.\n 196:\t */\n 197:\tstatic int\n 198:\txfs_fsverity_delete_metadata(\n 199:\t\tstruct xfs_inode\t*ip)\n 200:\t{\n"
}

57/3 2026/11/25 17:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 58123
							output: 42
							thoughts: 30
						

Thoughts:
Okay, here's my take on those lines from `fs/xfs/xfs_fsverity.c`, summarized from my perspective:

**Diving into the XFS Verity Implementation**

Alright, I'm heading back into those core XFS verity functions, specifically lines 201 to 350. Let's see what's happening. My immediate assumption is that this section probably continues to flesh out the interaction between the filesystem verity implementation and the rest of the XFS structure. I expect to find some logic that interacts with how blocks are actually read and verified, particularly after the file data has been retrieved in some fashion. We're getting past the setup phase and into the nitty-gritty of verification itself, perhaps by adding some critical data or verification structures. I'm especially keen to see how they handle errors in this section. Does it get an immediate abort or some kind of retry mechanism? I need to check the exact function names to get a firm grasp on the action happening, but this portion of the file likely handles all the core pieces of verification, such as reading metadata from on-disk structures and comparing against the calculated hash. Let's keep a keen eye out for performance considerations, too. The XFS design is all about efficient storage and access, so I'm expecting some clever optimizations for the verity checks. It would be a nightmare to have it bog down disk IO. There will also likely be some safety checks in place to prevent attacks.



58/3 2026/11/25 17:02 tool read-file
0m Args:
{
  "File": "fs/xfs/xfs_fsverity.c",
  "FirstLine": 201,
  "LineCount": 100
}

Results:
{
  "Contents": " 201:\t\tstruct xfs_trans\t*tp;\n 202:\t\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n 203:\t\tint\t\t\terror;\n 204:\t\n 205:\t\txfs_ilock(ip, XFS_MMAPLOCK_EXCL);\n 206:\t\ttruncate_inode_pages(VFS_I(ip)-\u003ei_mapping, XFS_ISIZE(ip));\n 207:\t\n 208:\t\terror = xfs_trans_alloc(mp, \u0026M_RES(mp)-\u003etr_itruncate, 0, 0, 0, \u0026tp);\n 209:\t\tif (error) {\n 210:\t\t\txfs_iunlock(ip, XFS_MMAPLOCK_EXCL);\n 211:\t\t\treturn error;\n 212:\t\t}\n 213:\t\n 214:\t\txfs_ilock(ip, XFS_ILOCK_EXCL);\n 215:\t\txfs_trans_ijoin(tp, ip, 0);\n 216:\t\n 217:\t\t/*\n 218:\t\t * We remove post EOF data, no need to update i_size as fsverity\n 219:\t\t * didn't move i_size in the first place\n 220:\t\t */\n 221:\t\terror = xfs_itruncate_extents(\u0026tp, ip, XFS_DATA_FORK, XFS_ISIZE(ip));\n 222:\t\tif (error)\n 223:\t\t\tgoto err_cancel;\n 224:\t\n 225:\t\terror = xfs_trans_commit(tp);\n 226:\t\txfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);\n 227:\t\treturn error;\n 228:\terr_cancel:\n 229:\t\txfs_trans_cancel(tp);\n 230:\t\txfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);\n 231:\t\treturn error;\n 232:\t}\n 233:\t\n 234:\tstatic int\n 235:\txfs_fsverity_reset_inode(\n 236:\t\tstruct xfs_inode\t*ip)\n 237:\t{\n 238:\t\tint\t\t\terror;\n 239:\t\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n 240:\t\tstruct xfs_trans\t*tp;\n 241:\t\n 242:\t\terror = xfs_fsverity_delete_metadata(ip);\n 243:\t\tif (error)\n 244:\t\t\treturn error;\n 245:\t\n 246:\t\t/*\n 247:\t\t * First, let's clean in-memory fsverity flag and then reset it on the\n 248:\t\t * disk\n 249:\t\t */\n 250:\t\tinode_set_flags(VFS_I(ip), 0, S_VERITY);\n 251:\t\n 252:\t\t/*\n 253:\t\t * Set fsverity inode flag\n 254:\t\t */\n 255:\t\terror = xfs_trans_alloc_inode(ip, \u0026M_RES(mp)-\u003etr_ichange,\n 256:\t\t\t\t0, 0, false, \u0026tp);\n 257:\t\tif (error)\n 258:\t\t\treturn error;\n 259:\t\n 260:\t\tip-\u003ei_diflags2 \u0026= ~XFS_DIFLAG2_VERITY;\n 261:\t\n 262:\t\txfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);\n 263:\t\txfs_trans_set_sync(tp);\n 264:\t\n 265:\t\terror = xfs_trans_commit(tp);\n 266:\t\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n 267:\t\treturn error;\n 268:\t}\n 269:\t\n 270:\t/*\n 271:\t * Prepare to enable fsverity by clearing old metadata.\n 272:\t */\n 273:\tstatic int\n 274:\txfs_fsverity_begin_enable(\n 275:\t\tstruct file\t\t*filp)\n 276:\t{\n 277:\t\tstruct inode\t\t*inode = file_inode(filp);\n 278:\t\tstruct xfs_inode\t*ip = XFS_I(inode);\n 279:\t\tint\t\t\terror;\n 280:\t\n 281:\t\txfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);\n 282:\t\n 283:\t\tif (IS_DAX(inode) || ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_DAX)\n 284:\t\t\treturn -EINVAL;\n 285:\t\n 286:\t\t/*\n 287:\t\t * fs-verity tracks verified Merkle tree pages using PG_checked, which\n 288:\t\t * is only valid on single-page (non-compound) folios.  When the\n 289:\t\t * filesystem block size is larger than the page size, the page cache\n 290:\t\t * enforces a minimum folio order \u003e 0, so all Merkle tree folios are\n 291:\t\t * compound. fs-verity cannot be used on such filesystems.\n 292:\t\t */\n 293:\t\tif (ip-\u003ei_mount-\u003em_sb.sb_blocksize \u003e PAGE_SIZE)\n 294:\t\t\treturn -EOPNOTSUPP;\n 295:\t\n 296:\t\t/*\n 297:\t\t * fs-verity doesn't work on zoned\n 298:\t\t */\n 299:\t\tif (xfs_is_zoned_inode(ip))\n 300:\t\t\treturn -EOPNOTSUPP;\n"
}

59/3 2026/11/25 17:02 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 60071
							output: 42
							thoughts: 30
						

Thoughts:
Okay, let's dive into lines 301-450 of `fs/xfs/xfs_fsverity.c`. I need to get a clear picture of what's happening within this specific code segment related to XFS and FS-Verity. I'm assuming, given the range, we're likely in the weeds of either the implementation details, error handling, or perhaps a core function within that framework. My experience tells me these lines could be involved in setting up the verity metadata, calculating and checking hashes, or maybe even interacting with the underlying block device for these integrity checks. Given my understanding of XFS, I suspect we are probably looking at how `fsverity` is integrated.

**Diving Deep into xfs_fsverity.c: Lines 301-450**

Alright, I'm mentally parsing this now. The focus here *has* to be on the critical tasks for file integrity. I'll need to pay close attention to the following aspects:

*   **Data Structures:** What structures are they using to hold the hash trees, verity metadata, and file/block information? I need to understand how these elements are organized to maintain integrity.
*   **Hash Calculations and Verification:** What hashing algorithms are being employed (likely SHA-256 or something robust), and how are they implemented? I'll look for how they're handling block-by-block verification and, more importantly, how the verity roots are calculated and compared.
*   **Error Handling:** Given XFS's robustness, I expect very explicit error checks and handling. Are there specific checks for invalid metadata, corrupted hashes, or I/O errors? I'll be looking for robust error propagation strategies.
*   **Data Persistence:** How are these verification metadata and hash trees stored on disk? What is the approach to ensuring that these integrity checks can continue after a reboot or a system crash? Are there journals or atomic updates involved? Is there data redundancy?
*   **Performance Considerations:** Considering the overhead of hash calculations on a large file system, is there any optimization? Caching, parallelization, or other techniques to improve performance? This is a critical area. I'll be watching for any such details that might be revealed.
*   **Interaction with XFS:** The code segment will likely interact directly with XFS's block mapping and I/O mechanisms, so I'll be keeping an eye out for how this integration happens within this block.

Basically, I will be assessing how these lines handle all of the core components of the FS-Verity implementation for XFS.



60/3 2026/11/25 17:03 tool read-file
0m Args:
{
  "File": "fs/xfs/xfs_fsverity.c",
  "FirstLine": 301,
  "LineCount": 100
}

Results:
{
  "Contents": " 301:\t\n 302:\t\t/*\n 303:\t\t * fs-verity stores the Merkle tree past EOF in units of the filesystem\n 304:\t\t * block size, so it cannot support realtime files whose allocation unit\n 305:\t\t * (extent size) is larger than the block size.\n 306:\t\t */\n 307:\t\tif (xfs_inode_has_bigrtalloc(ip))\n 308:\t\t\treturn -EINVAL;\n 309:\t\n 310:\t\tif (XFS_B_TO_FSB(ip-\u003ei_mount, inode-\u003ei_size) \u003e\n 311:\t\t\t\tXFS_FSVERITY_LARGEST_FILE_FSB(ip-\u003ei_mount))\n 312:\t\t\treturn -EFBIG;\n 313:\t\n 314:\t\t/*\n 315:\t\t * Flush pagecache before building Merkle tree. Inode is locked and no\n 316:\t\t * further writes will happen to the file except fsverity metadata\n 317:\t\t */\n 318:\t\terror = filemap_write_and_wait(inode-\u003ei_mapping);\n 319:\t\tif (error)\n 320:\t\t\treturn error;\n 321:\t\n 322:\t\terror = xfs_qm_dqattach(ip);\n 323:\t\tif (error)\n 324:\t\t\treturn error;\n 325:\t\n 326:\t\treturn xfs_fsverity_delete_metadata(ip);\n 327:\t}\n 328:\t\n 329:\t/*\n 330:\t * Complete (or fail) the process of enabling fsverity.\n 331:\t */\n 332:\tstatic int\n 333:\txfs_fsverity_end_enable(\n 334:\t\tstruct file\t\t*file,\n 335:\t\tconst void\t\t*desc,\n 336:\t\tsize_t\t\t\tdesc_size,\n 337:\t\tu64\t\t\tmerkle_tree_size)\n 338:\t{\n 339:\t\tstruct inode\t\t*inode = file_inode(file);\n 340:\t\tstruct xfs_inode\t*ip = XFS_I(inode);\n 341:\t\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n 342:\t\tstruct xfs_trans\t*tp;\n 343:\t\tint\t\t\terror = 0;\n 344:\t\tint\t\t\terror2;\n 345:\t\tloff_t\t\t\trange_start = xfs_fsverity_metadata_offset(ip);\n 346:\t\n 347:\t\txfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);\n 348:\t\n 349:\t\t/* fs-verity failed, just cleanup */\n 350:\t\tif (desc == NULL)\n 351:\t\t\tgoto out;\n 352:\t\n 353:\t\terror = xfs_fsverity_write_descriptor(file, desc, desc_size,\n 354:\t\t\t\tmerkle_tree_size);\n 355:\t\tif (error)\n 356:\t\t\tgoto out;\n 357:\t\n 358:\t\t/*\n 359:\t\t * Wait for Merkle tree get written to disk before setting on-disk inode\n 360:\t\t * flag and clearing I_VERITY_BUILDING\n 361:\t\t */\n 362:\t\terror = filemap_write_and_wait_range(inode-\u003ei_mapping, range_start,\n 363:\t\t\t\tLLONG_MAX);\n 364:\t\tif (error)\n 365:\t\t\tgoto out;\n 366:\t\n 367:\t\t/*\n 368:\t\t * Proactively remove unwritten extents left by COW preallocations and\n 369:\t\t * write preallocation in the merkle tree holes and past descriptor,\n 370:\t\t * and any delayed preallocations\n 371:\t\t */\n 372:\t\terror = xfs_free_eofblocks(ip);\n 373:\t\tif (error)\n 374:\t\t\tgoto out;\n 375:\t\n 376:\t\t/*\n 377:\t\t * Set fsverity inode flag\n 378:\t\t */\n 379:\t\terror = xfs_trans_alloc_inode(ip, \u0026M_RES(mp)-\u003etr_ichange,\n 380:\t\t\t\t0, 0, false, \u0026tp);\n 381:\t\tif (error)\n 382:\t\t\tgoto out;\n 383:\t\n 384:\t\t/*\n 385:\t\t * Ensure that we've persisted the verity information before we enable\n 386:\t\t * it on the inode and tell the caller we have sealed the inode.\n 387:\t\t */\n 388:\t\tip-\u003ei_diflags2 |= XFS_DIFLAG2_VERITY;\n 389:\t\n 390:\t\txfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);\n 391:\t\txfs_trans_set_sync(tp);\n 392:\t\n 393:\t\terror = xfs_trans_commit(tp);\n 394:\t\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n 395:\t\tif (error)\n 396:\t\t\tgoto out;\n 397:\t\n 398:\t\tinode_set_flags(inode, S_VERITY, S_VERITY);\n 399:\t\treturn error;\n 400:\t\n"
}

61/3 2026/11/25 17:03 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 62146
							output: 42
							thoughts: 30
						

Thoughts:
Okay, here's my summary, taking on the persona you requested:

**Diving into the XFS Verity Implementation**

Alright, let's get back to it. I'm focusing on lines 401 through 509 of `fs/xfs/xfs_fsverity.c`. This is where the real nitty-gritty of the XFS filesystem verity implementation happens. I'm particularly interested in understanding how they're handling... well, everything, within this specific section. I need to get a clear picture of how they're managing the verification process, where the crucial data structures are defined and used, and of course, how they interact with the overall XFS architecture. I expect to see the meat of the data-integrity checks taking place here. I'm looking for where and how the Merkle trees are traversed, how block hashes are computed, and how those computations are validated against the stored metadata. I'm also anticipating some clever techniques to minimize overhead, given this is an XFS implementation; performance will be key. I'm also curious as to how this is all triggered, it's possible this section covers some of the ioctl calls or internal function calls from the kernel. Given my understanding of XFS, I can probably guess a few things that will happen, but it's important to look at the specifics of the actual code here. It's time to dig in.



62/3 2026/11/25 17:03 tool read-file
0m Args:
{
  "File": "fs/xfs/xfs_fsverity.c",
  "FirstLine": 401,
  "LineCount": 110
}

Results:
{
  "Contents": " 401:\tout:\n 402:\t\terror2 = xfs_fsverity_reset_inode(ip);\n 403:\t\tif (error2)\n 404:\t\t\txfs_alert(ip-\u003ei_mount,\n 405:\t\"ino 0x%llx failed to clean up new fsverity metadata, err %d\",\n 406:\t\t\t\t\tI_INO(ip), error2);\n 407:\t\n 408:\t\treturn error;\n 409:\t}\n 410:\t\n 411:\t/*\n 412:\t * Retrieve a merkle tree block.\n 413:\t */\n 414:\tstatic struct page *\n 415:\txfs_fsverity_read_merkle(\n 416:\t\tstruct inode\t\t*inode,\n 417:\t\tpgoff_t\t\t\tindex)\n 418:\t{\n 419:\t\tindex += xfs_fsverity_metadata_offset(XFS_I(inode)) \u003e\u003e PAGE_SHIFT;\n 420:\t\n 421:\t\treturn generic_read_merkle_tree_page(inode, index);\n 422:\t}\n 423:\t\n 424:\t/*\n 425:\t * Retrieve a merkle tree block.\n 426:\t */\n 427:\tstatic void\n 428:\txfs_fsverity_readahead_merkle_tree(\n 429:\t\tstruct inode\t\t*inode,\n 430:\t\tpgoff_t\t\t\tindex,\n 431:\t\tunsigned long\t\tnr_pages)\n 432:\t{\n 433:\t\tindex += xfs_fsverity_metadata_offset(XFS_I(inode)) \u003e\u003e PAGE_SHIFT;\n 434:\t\n 435:\t\tgeneric_readahead_merkle_tree(inode, index, nr_pages);\n 436:\t}\n 437:\t\n 438:\tstatic inline bool\n 439:\txfs_fsverity_is_hashes_of_zeroed_blocks(\n 440:\t\tstruct xfs_inode\t*ip,\n 441:\t\tconst void\t\t*buf,\n 442:\t\tunsigned int\t\tsize,\n 443:\t\tconst u8\t\t*zero_digest,\n 444:\t\tunsigned int\t\tdigest_size)\n 445:\t{\n 446:\t\t/*\n 447:\t\t * If this is a block full of hashes of zeroed blocks, don't bother\n 448:\t\t * storing the block. We can synthesize them later.\n 449:\t\t *\n 450:\t\t * However, do this only in case Merkle tree block == fs block size.\n 451:\t\t * Iomap synthesizes these blocks based on holes in the merkle tree. We\n 452:\t\t * won't be able to tell if something need to be synthesizes for the\n 453:\t\t * range in the fs block. For example, for 4k filesystem block\n 454:\t\t *\n 455:\t\t *\t[ 1k | zero hashes | zero hashes | 1k ]\n 456:\t\t *\n 457:\t\t * Iomap won't know about these empty blocks.\n 458:\t\t */\n 459:\t\tif (size != ip-\u003ei_mount-\u003em_sb.sb_blocksize)\n 460:\t\t\treturn false;\n 461:\t\t/*\n 462:\t\t * First digest is zero_digest\n 463:\t\t */\n 464:\t\tif (memcmp(buf, zero_digest, digest_size))\n 465:\t\t\treturn false;\n 466:\t\t/*\n 467:\t\t * Every digest is same as previous, thus all are\n 468:\t\t * zero_digest\n 469:\t\t */\n 470:\t\treturn memcmp(buf + digest_size, buf, size - digest_size) == 0;\n 471:\t}\n 472:\t\n 473:\t/*\n 474:\t * Write a merkle tree block.\n 475:\t */\n 476:\tstatic int\n 477:\txfs_fsverity_write_merkle(\n 478:\t\tstruct file\t\t*file,\n 479:\t\tconst void\t\t*buf,\n 480:\t\tu64\t\t\tpos,\n 481:\t\tunsigned int\t\tsize,\n 482:\t\tconst u8\t\t*zero_digest,\n 483:\t\tunsigned int\t\tdigest_size)\n 484:\t{\n 485:\t\tstruct inode\t\t*inode = file_inode(file);\n 486:\t\tstruct xfs_inode\t*ip = XFS_I(inode);\n 487:\t\tloff_t\t\t\tposition = pos +\n 488:\t\t\txfs_fsverity_metadata_offset(ip);\n 489:\t\n 490:\t\tif (position + size \u003e inode-\u003ei_sb-\u003es_maxbytes)\n 491:\t\t\treturn -EFBIG;\n 492:\t\n 493:\t\tif (xfs_fsverity_is_hashes_of_zeroed_blocks(ip, buf, size, zero_digest,\n 494:\t\t\t\t\t\t\t    digest_size))\n 495:\t\t\treturn 0;\n 496:\t\n 497:\t\treturn iomap_fsverity_write(file, position, size, buf,\n 498:\t\t\t\txfs_buffered_write_iomap_next,\n 499:\t\t\t\t\u0026xfs_iomap_write_ops);\n 500:\t}\n"
}

63/3 2026/11/25 17:03 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 63972
							output: 31
							thoughts: 989
						

Thoughts:
**Analyzing XFS fs-verity Implementation**

Okay, let's break this down systematically. My immediate focus is on the `xfs_fsverity_is_hashes_of_zeroed_blocks` function. I need to understand how it determines if a block's content is consistent with a "zeroed" state under fs-verity. I see that it takes the inode pointer (`ip`), the buffer (`buf`), the size of the buffer (`size`), the zero digest (`zero_digest`), and the digest size (`digest_size`) as arguments. It first performs a size check and, if it passes that, then it seems to be comparing digests. Specifically, it checks if the first digest in `buf` is equal to `zero_digest`. The critical part, though, is the subsequent `memcmp` call: `memcmp(buf + digest_size, buf, size - digest_size) == 0`. It looks like it's confirming that all subsequent digests are identical to the first.

I need to confirm the conditions for that `memcmp`. Could `size` ever be smaller than `digest_size`? I quickly realize that no, `size` is `params.block_size` (usually 4096), and `digest_size` is the hash size (e.g., 32 for SHA256). Also, a prior check ensures that `size` equals the superblock's block size. And the block size is at least 512, and the digest size is at most 64. So that corner case is covered.

Now, I'll switch gears and analyze `xfs_ioend.c`. I need to track the processing of I/O operations under fs-verity. The `xfs_end_fsverity_io_read` function is triggered after a read I/O completes. It obtains `struct xfs_fsverity_ioend` from a pool and calls `fsverity_verify_bio` if the I/O completed successfully. This makes sense. Let's trace it back. The `xfs_end_io_read` function checks if fs-verity is enabled, if there was no error, and if the current file data needs fs-verity validation, and enqueues a `xfs_end_fsverity_io_read` work. So, this is how I/O operations get enqueued for fs-verity verification. It looks fully initialized to me.

I also need to see how fs-verity interacts with the filesystem's geometry, so I will now analyze `xfs_fs_geometry` in `xfs_sb.c`. I see that the `XFS_FSOP_GEOM_FLAGS_VERITY` flag is set in the `geo->flags` if fs-verity is enabled on the mount. This confirms fs-verity is tracked at the filesystem level, and the information is available during filesystem operations.



64/3 2026/11/25 17:03 tool grepper
0m Args:
{
  "Expression": "xfs_fs_geometry",
  "PathPrefixes": [
    "fs/xfs"
  ]
}

Results:
{
  "Output": "fs/xfs/libxfs/xfs_sb.c=1464=void\nfs/xfs/libxfs/xfs_sb.c:1465:xfs_fs_geometry(\nfs/xfs/libxfs/xfs_sb.c-1466-\tstruct xfs_mount\t*mp,\n--\nfs/xfs/libxfs/xfs_sb.h=28=extern int\txfs_update_secondary_sbs(struct xfs_mount *mp);\n--\nfs/xfs/libxfs/xfs_sb.h-30-#define XFS_FS_GEOM_MAX_STRUCT_VER\t(5)\nfs/xfs/libxfs/xfs_sb.h:31:extern void\txfs_fs_geometry(struct xfs_mount *mp, struct xfs_fsop_geom *geo,\nfs/xfs/libxfs/xfs_sb.h-32-\t\t\t\tint struct_version);\n--\nfs/xfs/xfs_ioctl.c=359=xfs_ioc_fsgeometry(\n--\nfs/xfs/xfs_ioctl.c-366-\nfs/xfs/xfs_ioctl.c:367:\txfs_fs_geometry(mp, \u0026fsgeo, struct_version);\nfs/xfs/xfs_ioctl.c-368-\n--\nfs/xfs/xfs_ioctl32.c=34=xfs_compat_ioc_fsgeometry_v1(\n--\nfs/xfs/xfs_ioctl32.c-39-\nfs/xfs/xfs_ioctl32.c:40:\txfs_fs_geometry(mp, \u0026fsgeo, 3);\nfs/xfs/xfs_ioctl32.c-41-\t/* The 32-bit variant simply has some padding at the end */\n"
}

65/3 2026/11/25 17:03 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 66106
							output: 44
							thoughts: 14
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:

**XFS Filesystem Geometry – Diving In**

Alright, let's get down to brass tacks. I'm looking at `xfs_fs_geometry`. Time to figure out exactly how this thing initializes and presents the filesystem's physical layout to the rest of the kernel, and ultimately, to userspace. I'm expecting this to be where the block size, inode size, allocation group layout, and all those fundamental parameters that determine XFS's performance profile are defined. This is the bedrock; get this wrong, and the entire filesystem goes sideways. I'm keen to understand how this function is structured, what inputs it relies on, and what the ultimate outputs are. I'll be particularly interested in the interaction with the underlying block device and any heuristics it might use for optimal layout given different hardware characteristics. Let's see how well it's been engineered for various block device types, with a focus on NVMe devices and modern storage arrays. I'm looking for elegance, efficiency, and robustness, all in a single function!



66/3 2026/11/25 17:03 tool read-file
0m Args:
{
  "File": "fs/xfs/libxfs/xfs_sb.c",
  "FirstLine": 1465,
  "LineCount": 25
}

Results:
{
  "Contents": "1465:\txfs_fs_geometry(\n1466:\t\tstruct xfs_mount\t*mp,\n1467:\t\tstruct xfs_fsop_geom\t*geo,\n1468:\t\tint\t\t\tstruct_version)\n1469:\t{\n1470:\t\tstruct xfs_sb\t\t*sbp = \u0026mp-\u003em_sb;\n1471:\t\n1472:\t\tmemset(geo, 0, sizeof(struct xfs_fsop_geom));\n1473:\t\n1474:\t\tgeo-\u003eblocksize = sbp-\u003esb_blocksize;\n1475:\t\tgeo-\u003ertextsize = sbp-\u003esb_rextsize;\n1476:\t\tgeo-\u003eagblocks = sbp-\u003esb_agblocks;\n1477:\t\tgeo-\u003eagcount = sbp-\u003esb_agcount;\n1478:\t\tgeo-\u003elogblocks = sbp-\u003esb_logblocks;\n1479:\t\tgeo-\u003esectsize = sbp-\u003esb_sectsize;\n1480:\t\tgeo-\u003einodesize = sbp-\u003esb_inodesize;\n1481:\t\tgeo-\u003eimaxpct = sbp-\u003esb_imax_pct;\n1482:\t\tgeo-\u003edatablocks = sbp-\u003esb_dblocks;\n1483:\t\tgeo-\u003ertblocks = sbp-\u003esb_rblocks;\n1484:\t\tgeo-\u003ertextents = sbp-\u003esb_rextents;\n1485:\t\tgeo-\u003elogstart = sbp-\u003esb_logstart;\n1486:\t\tBUILD_BUG_ON(sizeof(geo-\u003euuid) != sizeof(sbp-\u003esb_uuid));\n1487:\t\tmemcpy(geo-\u003euuid, \u0026sbp-\u003esb_uuid, sizeof(sbp-\u003esb_uuid));\n1488:\t\n1489:\t\tif (struct_version \u003c 2)\n"
}

67/3 2026/11/25 17:03 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 66883
							output: 32
							thoughts: 420
						

Thoughts:
**My Analysis of Potential fsverity and Memory Issues**

Okay, so I'm digging into this code, looking for potential areas where fsverity might introduce vulnerabilities or unexpected behavior, especially around memory management and Direct I/O (DIO). First, the explicit `memset` call on `geo` in `struct xfs_fsop_geom` is good news. It confirms that any padding within the structure is zeroed out, which eliminates the possibility of uninitialized memory leaks there. That's a solid start.

Now, about `xrep_dinode_flags`. The conditional `if (!xfs_has_verity(mp) || !S_ISREG(mode))` simply clears the `XFS_DIFLAG2_VERITY` flag during repair operations, so that looks fine, it is not a leak.

The part I'm really focusing on now is `xfs_report_dioalign`. I see that when `fsverity_active(VFS_I(ip))` is true, the function returns early. This is good because `dio_mem_align` is not set which sets `STATX_DIOALIGN` to 0. 

A question. Is `stat` being zeroed by the caller *before* `getattr` is called? I need to verify that `stat` is properly initialized before this function runs. Let me check the call chain within `vfs_statx` / `statx` to make sure the values are initialized.



68/3 2026/11/25 17:03 tool grepper
0m Args:
{
  "Expression": "xfs_report_dioalign",
  "PathPrefixes": [
    "fs/xfs"
  ]
}

Results:
{
  "Output": "fs/xfs/xfs_iops.c=574=static void\nfs/xfs/xfs_iops.c:575:xfs_report_dioalign(\nfs/xfs/xfs_iops.c-576-\tstruct xfs_inode\t*ip,\n--\nfs/xfs/xfs_iops.c=712=xfs_vn_getattr(\n--\nfs/xfs/xfs_iops.c-772-\t\tif (request_mask \u0026 (STATX_DIOALIGN | STATX_DIO_READ_ALIGN))\nfs/xfs/xfs_iops.c:773:\t\t\txfs_report_dioalign(ip, stat);\nfs/xfs/xfs_iops.c-774-\t\tif (request_mask \u0026 STATX_WRITE_ATOMIC)\n"
}

69/3 2026/11/25 17:03 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 67873
							output: 29
							thoughts: 73
						

Thoughts:
Here's my summary, as though I'm thinking through this process:

**Investigating Potential Security Implications in Filesystem Stat Calls**

Okay, so I need to dig into how file stat information is handled. My initial thought is to examine the `vfs_statx` or potentially the `xfs_vn_getattr` functions. I want to see if there's any obvious initialization that could be relevant to security. Specifically, I'm expecting to find a `memset(stat, 0, sizeof(*stat));` call in `vfs_statx`. That's pretty standard practice in the VFS layer, right before the actual call to `vfs_getattr_nosec`, or whatever the non-secure get attribute function is. But, I need to confirm this. I don't want to make assumptions. Best to go straight to `fs/stat.c` to verify that initialization is happening as expected. Gotta be methodical about this.



70/3 2026/11/25 17:03 tool grepper
0m Args:
{
  "Expression": "memset.*stat",
  "PathPrefixes": [
    "fs/stat.c"
  ]
}

Results:
{
  "Output": "fs/stat.c=181=int vfs_getattr_nosec(const struct path *path, struct kstat *stat,\n--\nfs/stat.c-186-\nfs/stat.c:187:\tmemset(stat, 0, sizeof(*stat));\nfs/stat.c-188-\tstat-\u003eresult_mask |= STATX_BASIC_STATS;\n--\nfs/stat.c=387=static int cp_old_stat(struct kstat *stat, struct __old_kernel_stat __user * statbuf)\n--\nfs/stat.c-400-\nfs/stat.c:401:\tmemset(\u0026tmp, 0, sizeof(struct __old_kernel_stat));\nfs/stat.c-402-\ttmp.st_dev = old_encode_dev(stat-\u003edev);\n"
}

71/3 2026/11/25 17:03 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 68394
							output: 407
							thoughts: 1036
						

Thoughts:
**KMSAN Evaluation: No Need Here**

Okay, let's break this down. First thing's first, that `memset` call at the beginning of `vfs_getattr_nosec` is good practice, but not the focus. We're concerned about KMSAN (Kernel Memory Sanitizer) and whether it's *necessary* for this set of changes.

The core principle here is that KMSAN is a resource hog. If KASAN (Kernel Address Sanitizer), LOCKDEP, or any other standard bug detector can catch a potential bug, there's absolutely no point in running a KMSAN session. My upstream-apparmor-kasan.config already includes that comprehensive suite of debugging tools, so we should always evaluate whether those simpler options are sufficient first. KMSAN is for the *unique* problems KASAN doesn't solve: specifically, uninitialized memory reads (stack, heap, page allocations) and potential kernel-to-user memory leaks.

So, when do we *need* KMSAN? We only set `NeedsKMSAN=true` if the patch introduces or modifies:

1.  Kernel structures sent to userspace (like `copy_to_user`, `put_user`, netlink, ioctl, socket options, BPF buffers) where fields *might* be uninitialized.
2.  Conditional logic based on potentially uninitialized variables.
3.  Complex data structure allocations where uninitialized fields could be read later.
4.  Bounds checks that could lead to reading uninitialized bytes.

Conversely, we absolutely *don't* need KMSAN if:

*   The risks are out-of-bounds accesses, overflows, NULL pointer dereferences, deadlocks, or use-after-free bugs (KASAN and LOCKDEP are on the case).
*   All stack/heap structures are fully zeroed or initialized (`{0}`, `memset`, `kzalloc`) before any read or copy operation.
*   The patch doesn't introduce any risk of uninitialized memory usage or info-leaks.

Let's carefully consider whether any of the changes could introduce an opportunity for a memory read. I need to be sure.

Specifically, could interactions with the disk, like reading the Merkle tree or descriptor via `FS_IOC_READ_VERITY_METADATA`, expose uninitialized memory to user space?

Wait... the read path is well defined, authenticated against the Merkle tree. `fsverity_read_merkle_tree` pulls from pages that are written during verity enabling, or synthesized zero blocks. `fsverity_read_descriptor` allocates a buffer via `kmalloc` and then calls `get_verity_descriptor`, which reads disk into the buffer via `fsverity_pagecache_read`, completely filling the allocated size. No uninitialized memory is being created or copied in those cases. The buffers are completely filled.

What about memory allocations *within* XFS that might be introduced by this patch? I've got to cover all bases. The code creates a slab cache for `struct xfs_fsverity_ioend`. But when allocated via `mempool_alloc`, the `ioend` and `work` fields are initialized *before* being enqueued. The `struct iomap_read_folio_ctx` is also zero-initialized. Scrub structures are handled by existing scrub framework. There's no uninitialized stack or heap memory here. Locking problems (deadlocks and inversions) are for LOCKDEP. Buffer overflows, off-by-one errors and UAF are KASAN’s domain.

Therefore, after a thorough review, the patch does **not** introduce any uninitialized memory risks or kernel-to-user info-leaks. A standard KASAN + LOCKDEP build is entirely sufficient to catch any potential issues.

Time to call `set-results` with `NeedsKMSAN=false` and a clear, detailed explanation of this reasoning.



72/3 2026/11/25 17:03 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series adds fs-verity support to XFS, including filesystem format feature flags, fsverity operations (enable, descriptor read/write, Merkle tree read/write/readahead), ioctl routing (FS_IOC_ENABLE_VERITY, FS_IOC_MEASURE_VERITY, FS_IOC_READ_VERITY_METADATA), iomap integration, post-EOF Merkle tree management, and scrub/repair hooks.\n\nAnalysis of memory initialization and user-space exposure:\n1. All heap allocations (e.g., `struct xfs_fsverity_ioend` from the dedicated mempool) have all fields (`ioend`, `work`) immediately and fully initialized before use.\n2. User-facing data structures returned via ioctls (such as `xfs_fsop_geom` in `xfs_fs_geometry` and bulkstat structures) continue to be explicitly zeroed via `memset` before flags are populated.\n3. Reading of the fs-verity descriptor via `xfs_fsverity_get_descriptor()` reads exact byte counts (`desc_size`) from the page cache into the caller-provided buffer via `fsverity_pagecache_read()`, leaving no uninitialized buffer ranges.\n4. No uninitialized stack or heap variables are introduced, and no conditional logic branches on uninitialized memory.\n5. Potential bugs introduced by this patch primarily involve file offset/bounds calculations, extent manipulation, locking hierarchies (e.g. `IOLOCK`, `ILOCK`, `MMAPLOCK`), and refcounting, all of which are covered by standard KASAN and LOCKDEP configurations.\n\nBecause no uninitialized memory risks or kernel-to-user information leaks are introduced, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch series adds fs-verity support to XFS, including filesystem format feature flags, fsverity operations (enable, descriptor read/write, Merkle tree read/write/readahead), ioctl routing (FS_IOC_ENABLE_VERITY, FS_IOC_MEASURE_VERITY, FS_IOC_READ_VERITY_METADATA), iomap integration, post-EOF Merkle tree management, and scrub/repair hooks.\n\nAnalysis of memory initialization and user-space exposure:\n1. All heap allocations (e.g., `struct xfs_fsverity_ioend` from the dedicated mempool) have all fields (`ioend`, `work`) immediately and fully initialized before use.\n2. User-facing data structures returned via ioctls (such as `xfs_fsop_geom` in `xfs_fs_geometry` and bulkstat structures) continue to be explicitly zeroed via `memset` before flags are populated.\n3. Reading of the fs-verity descriptor via `xfs_fsverity_get_descriptor()` reads exact byte counts (`desc_size`) from the page cache into the caller-provided buffer via `fsverity_pagecache_read()`, leaving no uninitialized buffer ranges.\n4. No uninitialized stack or heap variables are introduced, and no conditional logic branches on uninitialized memory.\n5. Potential bugs introduced by this patch primarily involve file offset/bounds calculations, extent manipulation, locking hierarchies (e.g. `IOLOCK`, `ILOCK`, `MMAPLOCK`), and refcounting, all of which are covered by standard KASAN and LOCKDEP configurations.\n\nBecause no uninitialized memory risks or kernel-to-user information leaks are introduced, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)