public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Andrey Albershteyn <aalbersh@kernel.org>, b@magnolia.djwong.org
Cc: linux-xfs@vger.kernel.org, fsverity@lists.linux.dev,
	linux-fsdevel@vger.kernel.org, ebiggers@kernel.org, hch@lst.de
Subject: Re: [PATCH v3 27/35] xfs: use different on-disk and pagecache offset for fsverity
Date: Thu, 19 Feb 2026 11:30:16 -0800	[thread overview]
Message-ID: <20260219193016.GO6490@frogsfrogsfrogs> (raw)
In-Reply-To: <20260217231937.1183679-28-aalbersh@kernel.org>

On Wed, Feb 18, 2026 at 12:19:27AM +0100, Andrey Albershteyn wrote:
> Convert between pagecache and on-disk offset while reading/writing
> fsverity metadata through iomap.
> 
> We can not use on-disk (1ULL << 53) offset for pagecache as it doesn't

nit: 'cannot', not 'can not'.

(English is a weird language, the two don't quite mean the same thing)

> fit into 32-bit address space and the page radix tree is going to be
> quite high on 64-bit. To prevent this we use lower offset, right after
> EOF. The fsverity_metadata_offset() sets it to be next largest folio
> after EOF.

I'd say "fsverity_metadata_offset() sets the pagecache offset so that
file data and fsverity metadata cannot be cached by the same folio."

> We can not use this pagecache offset for on-disk file offset though, as
> this is folio size dependent. Therefore, for on-disk we use offset far
> beyond EOF which allows to use largest file size supported by fsverity.
> 
> Also don't convert offset if IOMAP_REPORT is set as we need to see real
> extents for fiemap.
> 
> Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
> ---
>  fs/xfs/libxfs/xfs_bmap.c | 12 ++++++++++--
>  fs/xfs/xfs_aops.c        | 13 ++++++++++---
>  fs/xfs/xfs_iomap.c       | 33 ++++++++++++++++++++++++++-------
>  3 files changed, 46 insertions(+), 12 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index 99a3ff2ee928..05fddd34c697 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -41,6 +41,8 @@
>  #include "xfs_inode_util.h"
>  #include "xfs_rtgroup.h"
>  #include "xfs_zone_alloc.h"
> +#include "xfs_fsverity.h"
> +#include <linux/fsverity.h>
>  
>  struct kmem_cache		*xfs_bmap_intent_cache;
>  
> @@ -4451,7 +4453,9 @@ xfs_bmapi_convert_one_delalloc(
>  	XFS_STATS_ADD(mp, xs_xstrat_bytes, XFS_FSB_TO_B(mp, bma.length));
>  	XFS_STATS_INC(mp, xs_xstrat_quick);
>  
> -	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
> +	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION) &&
> +	    XFS_FSB_TO_B(mp, bma.got.br_startoff) >=
> +		    fsverity_metadata_offset(VFS_I(ip)))
>  		flags |= IOMAP_F_FSVERITY;

Hrmmm.  I wonder, why not create a set of fsverity-specific iomap ops
that wrap xfs_read_iomap_begin and/or xfs_buffered_write_iomap_begin?
The wrappers could then do the offset translation prior to calling the
real _iomap_begin function, and then undo that translation on the output
mapping and set IOMAP_F_FSVERITY?  Then we don't clutter up the regular
paths with the translation stuff.

<shrug> Thoughts?  This way seems to work as well.

--D

>  
>  	ASSERT(!isnullstartblock(bma.got.br_startblock));
> @@ -4495,6 +4499,10 @@ xfs_bmapi_convert_delalloc(
>  	unsigned int		*seq)
>  {
>  	int			error;
> +	loff_t			iomap_offset = offset;
> +
> +	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
> +		iomap_offset = xfs_fsverity_offset_from_disk(ip, offset);
>  
>  	/*
>  	 * Attempt to allocate whatever delalloc extent currently backs offset
> @@ -4507,7 +4515,7 @@ xfs_bmapi_convert_delalloc(
>  					iomap, seq);
>  		if (error)
>  			return error;
> -	} while (iomap->offset + iomap->length <= offset);
> +	} while (iomap->offset + iomap->length <= iomap_offset);
>  
>  	return 0;
>  }
> diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
> index 9d4fc3322ec7..53aeea5e9ebd 100644
> --- a/fs/xfs/xfs_aops.c
> +++ b/fs/xfs/xfs_aops.c
> @@ -335,8 +335,8 @@ xfs_map_blocks(
>  	struct xfs_inode	*ip = XFS_I(wpc->inode);
>  	struct xfs_mount	*mp = ip->i_mount;
>  	ssize_t			count = i_blocksize(wpc->inode);
> -	xfs_fileoff_t		offset_fsb = XFS_B_TO_FSBT(mp, offset);
> -	xfs_fileoff_t		end_fsb = XFS_B_TO_FSB(mp, offset + count);
> +	xfs_fileoff_t		offset_fsb;
> +	xfs_fileoff_t		end_fsb;
>  	xfs_fileoff_t		cow_fsb;
>  	int			whichfork;
>  	struct xfs_bmbt_irec	imap;
> @@ -351,8 +351,12 @@ xfs_map_blocks(
>  
>  	XFS_ERRORTAG_DELAY(mp, XFS_ERRTAG_WB_DELAY_MS);
>  
> -	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
> +	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION)) {
>  		iomap_flags |= IOMAP_F_FSVERITY;
> +		offset = xfs_fsverity_offset_to_disk(ip, offset);
> +	}
> +	offset_fsb = XFS_B_TO_FSBT(mp, offset);
> +	end_fsb = XFS_B_TO_FSB(mp, offset + count);
>  
>  	/*
>  	 * COW fork blocks can overlap data fork blocks even if the blocks
> @@ -484,6 +488,9 @@ xfs_map_blocks(
>  			wpc->iomap.length = cow_offset - wpc->iomap.offset;
>  	}
>  
> +	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
> +		offset = xfs_fsverity_offset_from_disk(ip, offset);
> +
>  	ASSERT(wpc->iomap.offset <= offset);
>  	ASSERT(wpc->iomap.offset + wpc->iomap.length > offset);
>  	trace_xfs_map_blocks_alloc(ip, offset, count, whichfork, &imap);
> diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
> index 6b14221ecee2..a04361cf0e99 100644
> --- a/fs/xfs/xfs_iomap.c
> +++ b/fs/xfs/xfs_iomap.c
> @@ -32,6 +32,7 @@
>  #include "xfs_rtbitmap.h"
>  #include "xfs_icache.h"
>  #include "xfs_zone_alloc.h"
> +#include "xfs_fsverity.h"
>  #include <linux/fsverity.h>
>  
>  #define XFS_ALLOC_ALIGN(mp, off) \
> @@ -142,7 +143,11 @@ xfs_bmbt_to_iomap(
>  		    xfs_rtbno_is_group_start(mp, imap->br_startblock))
>  			iomap->flags |= IOMAP_F_BOUNDARY;
>  	}
> -	iomap->offset = XFS_FSB_TO_B(mp, imap->br_startoff);
> +	if (xfs_fsverity_need_convert_offset(ip, imap, mapping_flags))
> +		iomap->offset = xfs_fsverity_offset_from_disk(
> +			ip, XFS_FSB_TO_B(mp, imap->br_startoff));
> +	else
> +		iomap->offset = XFS_FSB_TO_B(mp, imap->br_startoff);
>  	iomap->length = XFS_FSB_TO_B(mp, imap->br_blockcount);
>  	iomap->flags = iomap_flags;
>  	if (mapping_flags & IOMAP_DAX) {
> @@ -629,6 +634,8 @@ xfs_iomap_write_unwritten(
>  	uint		resblks;
>  	int		error;
>  
> +	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
> +		offset = xfs_fsverity_offset_to_disk(ip, offset);
>  	trace_xfs_unwritten_convert(ip, offset, count);
>  
>  	offset_fsb = XFS_B_TO_FSBT(mp, offset);
> @@ -1766,8 +1773,8 @@ xfs_buffered_write_iomap_begin(
>  						     iomap);
>  	struct xfs_inode	*ip = XFS_I(inode);
>  	struct xfs_mount	*mp = ip->i_mount;
> -	xfs_fileoff_t		offset_fsb = XFS_B_TO_FSBT(mp, offset);
> -	xfs_fileoff_t		end_fsb = xfs_iomap_end_fsb(mp, offset, count);
> +	xfs_fileoff_t		offset_fsb;
> +	xfs_fileoff_t		end_fsb;
>  	struct xfs_bmbt_irec	imap, cmap;
>  	struct xfs_iext_cursor	icur, ccur;
>  	xfs_fsblock_t		prealloc_blocks = 0;
> @@ -1790,8 +1797,12 @@ xfs_buffered_write_iomap_begin(
>  		return xfs_direct_write_iomap_begin(inode, offset, count,
>  				flags, iomap, srcmap);
>  
> -	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
> +	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION)) {
>  		iomap_flags |= IOMAP_F_FSVERITY;
> +		offset = xfs_fsverity_offset_to_disk(ip, offset);
> +	}
> +	offset_fsb = XFS_B_TO_FSBT(mp, offset);
> +	end_fsb = xfs_iomap_end_fsb(mp, offset, count);
>  
>  	error = xfs_qm_dqattach(ip);
>  	if (error)
> @@ -2112,8 +2123,8 @@ xfs_read_iomap_begin(
>  	struct xfs_inode	*ip = XFS_I(inode);
>  	struct xfs_mount	*mp = ip->i_mount;
>  	struct xfs_bmbt_irec	imap;
> -	xfs_fileoff_t		offset_fsb = XFS_B_TO_FSBT(mp, offset);
> -	xfs_fileoff_t		end_fsb = xfs_iomap_end_fsb(mp, offset, length);
> +	xfs_fileoff_t		offset_fsb;
> +	xfs_fileoff_t		end_fsb;
>  	int			nimaps = 1, error = 0;
>  	bool			shared = false;
>  	unsigned int		lockmode = XFS_ILOCK_SHARED;
> @@ -2125,8 +2136,15 @@ xfs_read_iomap_begin(
>  	if (xfs_is_shutdown(mp))
>  		return -EIO;
>  
> -	if (fsverity_active(inode) && offset >= XFS_FSVERITY_REGION_START)
> +	if (fsverity_active(inode) &&
> +	    (offset >= fsverity_metadata_offset(inode)) &&
> +	    !(flags & IOMAP_REPORT)) {
>  		iomap_flags |= IOMAP_F_FSVERITY;
> +		offset = xfs_fsverity_offset_to_disk(ip, offset);
> +	}
> +
> +	offset_fsb = XFS_B_TO_FSBT(mp, offset);
> +	end_fsb = xfs_iomap_end_fsb(mp, offset, length);
>  
>  	error = xfs_ilock_for_iomap(ip, flags, &lockmode);
>  	if (error)
> @@ -2142,6 +2160,7 @@ xfs_read_iomap_begin(
>  		return error;
>  	trace_xfs_iomap_found(ip, offset, length, XFS_DATA_FORK, &imap);
>  	iomap_flags |= shared ? IOMAP_F_SHARED : 0;
> +
>  	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, iomap_flags, seq);
>  }
>  
> -- 
> 2.51.2
> 
> 

  reply	other threads:[~2026-02-19 19:30 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-17 23:19 [PATCH v3 00/35] fs-verity support for XFS with post EOF merkle tree Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 01/35] fsverity: report validation errors back to the filesystem Andrey Albershteyn
2026-02-18 21:40   ` Darrick J. Wong
2026-02-17 23:19 ` [PATCH v3 02/35] fsverity: expose ensure_fsverity_info() Andrey Albershteyn
2026-02-18 21:41   ` Darrick J. Wong
2026-02-17 23:19 ` [PATCH v3 03/35] fsverity: add consolidated pagecache offset for metadata Andrey Albershteyn
2026-02-18  6:17   ` Christoph Hellwig
2026-02-18 21:57     ` Darrick J. Wong
2026-02-19 13:09       ` Andrey Albershteyn
2026-02-19 17:16         ` Darrick J. Wong
2026-02-17 23:19 ` [PATCH v3 04/35] fsverity: generate and store zero-block hash Andrey Albershteyn
2026-02-18 22:04   ` Darrick J. Wong
2026-02-19 13:00     ` Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 05/35] fsverity: introduce fsverity_folio_zero_hash() Andrey Albershteyn
2026-02-18 22:53   ` Darrick J. Wong
2026-02-19 12:45     ` Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 06/35] fsverity: pass digest size and hash of the empty block to ->write Andrey Albershteyn
2026-02-18  6:18   ` Christoph Hellwig
2026-02-18 12:17     ` Andrey Albershteyn
2026-02-19  5:58       ` Christoph Hellwig
2026-02-19  6:30         ` Eric Biggers
2026-02-23 13:23           ` Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 07/35] iomap: introduce IOMAP_F_FSVERITY Andrey Albershteyn
2026-02-18 23:03   ` Darrick J. Wong
2026-02-19  6:00     ` Christoph Hellwig
2026-02-19  6:04       ` Darrick J. Wong
2026-02-17 23:19 ` [PATCH v3 08/35] iomap: don't limit fsverity metadata by EOF in writeback Andrey Albershteyn
2026-02-18 23:05   ` Darrick J. Wong
2026-02-19 12:27     ` Andrey Albershteyn
2026-02-20 16:42   ` Matthew Wilcox
2026-02-20 16:44     ` Christoph Hellwig
2026-02-17 23:19 ` [PATCH v3 09/35] iomap: obtain fsverity info for read path Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 10/35] iomap: issue readahead for fsverity merkle tree Andrey Albershteyn
2026-02-18 23:06   ` Darrick J. Wong
2026-02-17 23:19 ` [PATCH v3 11/35] iomap: allow filesystem to read fsverity metadata beyound EOF Andrey Albershteyn
2026-02-18  6:36   ` Christoph Hellwig
2026-02-18  9:41     ` Andrey Albershteyn
2026-02-19  6:04       ` Christoph Hellwig
2026-02-19 11:11         ` Andrey Albershteyn
2026-02-19 13:38           ` Christoph Hellwig
2026-02-19 14:23             ` Andrey Albershteyn
2026-02-20 15:31               ` Christoph Hellwig
2026-02-23 15:10                 ` Andrey Albershteyn
2026-02-24 14:42                   ` Christoph Hellwig
2026-02-17 23:19 ` [PATCH v3 12/35] iomap: let fsverity verify holes Andrey Albershteyn
2026-02-18 23:09   ` Darrick J. Wong
2026-02-17 23:19 ` [PATCH v3 13/35] xfs: use folio host instead of file struct Andrey Albershteyn
2026-02-18  6:32   ` Christoph Hellwig
2026-02-18  9:42     ` Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 14/35] xfs: add fs-verity ro-compat flag Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 15/35] xfs: add inode on-disk VERITY flag Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 16/35] xfs: initialize fs-verity on file open Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 17/35] xfs: don't allow to enable DAX on fs-verity sealed inode Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 18/35] xfs: disable direct read path for fs-verity files Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 19/35] xfs: introduce XFS_FSVERITY_CONSTRUCTION inode flag Andrey Albershteyn
2026-02-18 23:10   ` Darrick J. Wong
2026-02-17 23:19 ` [PATCH v3 20/35] xfs: introduce XFS_FSVERITY_REGION_START constant Andrey Albershteyn
2026-02-18  6:33   ` Christoph Hellwig
2026-02-18 23:11   ` Darrick J. Wong
2026-02-17 23:19 ` [PATCH v3 21/35] xfs: disable preallocations for fsverity Merkle tree writes Andrey Albershteyn
2026-02-18 23:12   ` Darrick J. Wong
2026-02-17 23:19 ` [PATCH v3 22/35] xfs: add iomap write/writeback and reading of Merkle tree pages Andrey Albershteyn
2026-02-18  6:35   ` Christoph Hellwig
2026-02-18 10:18     ` Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 23/35] xfs: add helper to check that inode data need fsverity verification Andrey Albershteyn
2026-02-18  6:38   ` Christoph Hellwig
2026-02-18  9:46     ` Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 24/35] xfs: use read ioend for fsverity data verification Andrey Albershteyn
2026-02-18  6:39   ` Christoph Hellwig
2026-02-17 23:19 ` [PATCH v3 25/35] xfs: add helpers to convert between pagecache and on-disk offset Andrey Albershteyn
2026-02-18 23:20   ` Darrick J. Wong
2026-02-17 23:19 ` [PATCH v3 26/35] xfs: add a helper to decide if bmbt record needs offset conversion Andrey Albershteyn
2026-02-19 17:41   ` Darrick J. Wong
2026-02-17 23:19 ` [PATCH v3 27/35] xfs: use different on-disk and pagecache offset for fsverity Andrey Albershteyn
2026-02-19 19:30   ` Darrick J. Wong [this message]
2026-02-17 23:19 ` [PATCH v3 28/35] xfs: add fs-verity support Andrey Albershteyn
2026-02-18  6:44   ` Christoph Hellwig
2026-02-18  9:57     ` Andrey Albershteyn
2026-02-19  6:11       ` Christoph Hellwig
2026-02-19  9:51         ` Andrey Albershteyn
2026-02-19 13:41           ` Christoph Hellwig
2026-02-19 14:38             ` Andrey Albershteyn
2026-02-19 17:29               ` Darrick J. Wong
2026-02-17 23:19 ` [PATCH v3 29/35] xfs: add fs-verity ioctls Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 30/35] xfs: advertise fs-verity being available on filesystem Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 31/35] xfs: check and repair the verity inode flag state Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 32/35] xfs: report verity failures through the health system Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 33/35] xfs: introduce health state for corrupted fsverity metadata Andrey Albershteyn
2026-02-19 17:34   ` Darrick J. Wong
2026-02-23 18:19     ` Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 34/35] xfs: add fsverity traces Andrey Albershteyn
2026-02-19 17:36   ` Darrick J. Wong
2026-02-23 18:12     ` Andrey Albershteyn
2026-02-17 23:19 ` [PATCH v3 35/35] xfs: enable ro-compat fs-verity flag Andrey Albershteyn

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=20260219193016.GO6490@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=aalbersh@kernel.org \
    --cc=b@magnolia.djwong.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox