[PATCH v4 14/15] fs: drop i_verity_info from struct inode

Christian Brauner
2025-07-23T10:58:47Z

Now that all filesystems store the fsverity data pointer in their
private inode, drop the data pointer from struct inode itself freeing up
8 bytes.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/verity/open.c | 18 ++++++------------
include/linux/fs.h | 5 -----
include/linux/fsverity.h | 11 +++++++----
3 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/fs/verity/open.c b/fs/verity/open.c
index a4d7388e2f71..0dcd33f00361 100644
--- a/fs/verity/open.c
+++ b/fs/verity/open.c
@@ -250,20 +250,15 @@ struct fsverity_info *fsverity_create_info(const struct inode *inode,

void fsverity_set_info(struct inode *inode, struct fsverity_info *vi)
{
- void *p;
-
/*
* Multiple tasks may race to set ->i_verity_info, so use
* cmpxchg_release(). This pairs with the smp_load_acquire() in
* fsverity_get_info(). I.e., here we publish ->i_verity_info with a
* RELEASE barrier so that other tasks can ACQUIRE it.
*/
-
- if (inode->i_sb->s_vop->inode_info_offs)
- p = cmpxchg_release(fsverity_addr(inode), NULL, vi);
- else
- p = cmpxchg_release(&inode->i_verity_info, NULL, vi);
- if (p != NULL) {
+ VFS_WARN_ON_ONCE(!inode->i_sb->s_vop);
+ VFS_WARN_ON_ONCE(!inode->i_sb->s_vop->inode_info_offs);
+ if (cmpxchg_release(fsverity_addr(inode), NULL, vi) != NULL) {
/* Lost the race, so free the fsverity_info we allocated. */
fsverity_free_info(vi);
/*
@@ -411,10 +406,9 @@ void __fsverity_cleanup_inode(struct inode *inode)
{
struct fsverity_info **vi;

- if (inode->i_sb->s_vop->inode_info_offs)
- vi = fsverity_addr(inode);
- else
- vi = &inode->i_verity_info;
+ VFS_WARN_ON_ONCE(!inode->i_sb->s_vop);
+ VFS_WARN_ON_ONCE(!inode->i_sb->s_vop->inode_info_offs);
+ vi = fsverity_addr(inode);
fsverity_free_info(*vi);
*vi = NULL;
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b76a10fc765b..cb249b6646f3 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -73,7 +73,6 @@ struct seq_file;
struct workqueue_struct;
struct iov_iter;
struct fscrypt_operations;
-struct fsverity_info;
struct fsverity_operations;
struct fsnotify_mark_connector;
struct fsnotify_sb_info;
@@ -777,10 +776,6 @@ struct inode {
struct fsnotify_mark_connector __rcu *i_fsnotify_marks;
#endif

-#ifdef CONFIG_FS_VERITY
- struct fsverity_info *i_verity_info;
-#endif
-
void *i_private; /* fs or device private pointer */
} __randomize_layout;

diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h
index 75ff6c9c50ef..0ee5b2fea389 100644
--- a/include/linux/fsverity.h
+++ b/include/linux/fsverity.h
@@ -136,7 +136,11 @@ static inline struct fsverity_info **fsverity_addr(const struct inode *inode)

static inline struct fsverity_info *fsverity_get_info(const struct inode *inode)
{
- if (!inode->i_sb->s_vop)
+ /*
+ * We're called from fsverity_active() which might be called on
+ * inodes from filesystems that don't support fsverity at all.
+ */
+ if (likely(!inode->i_sb->s_vop))
return NULL;

/*
@@ -145,9 +149,8 @@ static inline struct fsverity_info *fsverity_get_info(const struct inode *inode)
* executing a RELEASE barrier. We need to use smp_load_acquire() here
* to safely ACQUIRE the memory the other task published.
*/
- if (inode->i_sb->s_vop->inode_info_offs)
- return smp_load_acquire(fsverity_addr(inode));
- return smp_load_acquire(&inode->i_verity_info);
+ VFS_WARN_ON_ONCE(!inode->i_sb->s_vop->inode_info_offs);
+ return smp_load_acquire(fsverity_addr(inode));
}

/* enable.c */

--
2.47.2