From: Andrey Albershteyn <aalbersh@kernel.org>
To: "Eric Biggers" <ebiggers@kernel.org>,
"Christoph Hellwig" <hch@lst.de>,
"Carlos Maiolino" <cem@kernel.org>,
"fsverity" <fsverity@lists.linux.dev>,
"linux-xfs" <linux-xfs@vger.kernel.org>
Cc: Andrey Albershteyn <aalbersh@kernel.org>,
"fsdevel" <linux-fsdevel@vger.kernel.org>,
david@fromorbit.com
Subject: [PATCH v19 05/15] xfs: handle fsverity I/O in write/read path
Date: Fri, 20 Nov 2026 16:57:39 +0100 [thread overview]
Message-ID: <20261120155752.192025-6-aalbersh@kernel.org> (raw)
In-Reply-To: <20261120155752.192025-1-aalbersh@kernel.org>
For write/writeback set IOMAP_F_FSVERITY flag telling iomap to not
update inode size and to not skip folios beyond EOF.
Initiate fsverity writeback with IOMAP_F_FSVERITY set to tell iomap
should not skip folio that is dirty beyond EOF.
In read path let iomap know that we are reading fsverity metadata. So,
treat holes in the tree as request to synthesize tree blocks and hole
after descriptor as end of the fsverity region.
Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
---
fs/xfs/Makefile | 1 +
fs/xfs/libxfs/xfs_bmap.c | 4 +--
fs/xfs/libxfs/xfs_verity.c | 20 +++++++++++++
fs/xfs/libxfs/xfs_verity.h | 13 ++++++++
fs/xfs/xfs_aops.c | 6 ++--
fs/xfs/xfs_iomap.c | 61 ++++++++++++++++++++++++++++----------
fs/xfs/xfs_iomap.h | 5 ++--
fs/xfs/xfs_pnfs.c | 2 +-
8 files changed, 89 insertions(+), 23 deletions(-)
create mode 100644 fs/xfs/libxfs/xfs_verity.c
create mode 100644 fs/xfs/libxfs/xfs_verity.h
diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index 399a207f2d0e..cb7f71457ee9 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/, \
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 050522c58b16..f74411312901 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);
diff --git a/fs/xfs/libxfs/xfs_verity.c b/fs/xfs/libxfs/xfs_verity.c
new file mode 100644
index 000000000000..c1731b89a5a1
--- /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 000000000000..da90f798faa8
--- /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/xfs_aops.c b/fs/xfs/xfs_aops.c
index 1db6f3640c53..b9728997f944 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -23,6 +23,7 @@
#include "xfs_ioend.h"
#include "xfs_zone_alloc.h"
#include "xfs_rtgroup.h"
+#include "xfs_verity.h"
struct xfs_writepage_ctx {
struct iomap_writepage_ctx ctx;
@@ -265,7 +266,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 +443,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);
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 50eae7ff6145..5117704530f6 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 071fff666507..c9bd6de1bfda 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_pnfs.c b/fs/xfs/xfs_pnfs.c
index 065875c8b7da..ff097400d064 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:
--
2.54.0
next prev parent reply other threads:[~2026-11-20 15:58 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 15:57 [PATCH v19 00/15] fs-verity support for XFS with post EOF merkle tree Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 01/15] xfs: introduce fsverity on-disk changes Andrey Albershteyn
2026-11-20 16:26 ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 02/15] xfs: don't allow to enable DAX on fs-verity sealed inode Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 03/15] xfs: disable direct read path for fs-verity files Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 04/15] xfs: don't report dio_mem_align and dio_offset_align for fsverity files Andrey Albershteyn
2026-11-20 15:57 ` Andrey Albershteyn [this message]
2026-11-20 16:27 ` [PATCH v19 05/15] xfs: handle fsverity I/O in write/read path sashiko-bot
2026-11-20 15:57 ` [PATCH v19 06/15] xfs: use read ioend for fsverity data verification Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 07/15] xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi() Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 08/15] xfs: don't remove written extents past EOF on fsverity inodes Andrey Albershteyn
2026-11-20 16:21 ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 09/15] xfs: add fs-verity support Andrey Albershteyn
2026-11-20 16:51 ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 10/15] xfs: initialize fs-verity on file open Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 11/15] xfs: add fs-verity ioctls Andrey Albershteyn
2026-11-20 16:19 ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 12/15] xfs: advertise fs-verity being available on filesystem Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 13/15] xfs: check and repair the verity inode flag state Andrey Albershteyn
2026-11-20 16:28 ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 14/15] xfs: introduce health state for corrupted fsverity metadata Andrey Albershteyn
2026-11-20 16:36 ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 15/15] xfs: enable ro-compat fs-verity flag Andrey Albershteyn
2026-11-20 16:38 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120155752.192025-6-aalbersh@kernel.org \
--to=aalbersh@kernel.org \
--cc=cem@kernel.org \
--cc=david@fromorbit.com \
--cc=ebiggers@kernel.org \
--cc=fsverity@lists.linux.dev \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.