]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
fsverity: use a hashtable to find the fsverity_info
authorChristoph Hellwig <hch@lst.de>
Mon, 2 Feb 2026 06:06:40 +0000 (07:06 +0100)
committerEric Biggers <ebiggers@kernel.org>
Wed, 4 Feb 2026 19:31:54 +0000 (11:31 -0800)
commitf77f281b61183a5c0b87e6a4d101c70bd32c1c79
treebdca555b35133f7d898fd43472eb815d960d5e51
parentb0160e4501bb3572d9ef6e4f8edf758193ee37aa
fsverity: use a hashtable to find the fsverity_info

Use the kernel's resizable hash table (rhashtable) to find the
fsverity_info.  This way file systems that want to support fsverity don't
have to bloat every inode in the system with an extra pointer.  The
trade-off is that looking up the fsverity_info is a bit more expensive
now, but the main operations are still dominated by I/O and hashing
overhead.

The rhashtable implementations requires no external synchronization, and
the _fast versions of the APIs provide the RCU critical sections required
by the implementation.  Because struct fsverity_info is only removed on
inode eviction and does not contain a reference count, there is no need
for an extended critical section to grab a reference or validate the
object state.  The file open path uses rhashtable_lookup_get_insert_fast,
which can either find an existing object for the hash key or insert a
new one in a single atomic operation, so that concurrent opens never
instantiate duplicate fsverity_info structure.  FS_IOC_ENABLE_VERITY must
already be synchronized by a combination of i_rwsem and file system flags
and uses rhashtable_lookup_insert_fast, which errors out on an existing
object for the hash key as an additional safety check.

Because insertion into the hash table now happens before S_VERITY is set,
fsverity just becomes a barrier and a flag check and doesn't have to look
up the fsverity_info at all, so there is only a single lookup per
->read_folio or ->readahead invocation.  For btrfs there is an additional
one for each bio completion, while for ext4 and f2fs the fsverity_info
is stored in the per-I/O context and reused for the completion workqueue.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Link: https://lore.kernel.org/r/20260202060754.270269-12-hch@lst.de
[EB: folded in fix for missing fsverity_free_info()]
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
13 files changed:
fs/btrfs/btrfs_inode.h
fs/btrfs/inode.c
fs/btrfs/verity.c
fs/ext4/ext4.h
fs/ext4/super.c
fs/ext4/verity.c
fs/f2fs/f2fs.h
fs/f2fs/super.c
fs/f2fs/verity.c
fs/verity/enable.c
fs/verity/fsverity_private.h
fs/verity/open.c
include/linux/fsverity.h