[PATCH RFC DRAFT v2 07/13] fs: drop i_crypt_info from struct inode

Christian Brauner
2025-07-22T12:58:07Z

Now that all filesystems store the fscrypt 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/crypto/fscrypt_private.h | 2 +-
fs/crypto/keysetup.c | 25 ++++++++++++-------------
include/linux/fs.h | 4 ----
include/linux/fscrypt.h | 21 ++++++---------------
4 files changed, 19 insertions(+), 33 deletions(-)

diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h
index c1d92074b65c..53a72dc909d9 100644
--- a/fs/crypto/fscrypt_private.h
+++ b/fs/crypto/fscrypt_private.h
@@ -231,7 +231,7 @@ struct fscrypt_prepared_key {
* fscrypt_inode_info - the "encryption key" for an inode
*
* When an encrypted file's key is made available, an instance of this struct is
- * allocated and stored in ->i_crypt_info. Once created, it remains until the
+ * allocated and stored in ->i_fscrypt_info. Once created, it remains until the
* inode is evicted.
*/
struct fscrypt_inode_info {
diff --git a/fs/crypto/keysetup.c b/fs/crypto/keysetup.c
index 76a5c7aafd89..e520712431f6 100644
--- a/fs/crypto/keysetup.c
+++ b/fs/crypto/keysetup.c
@@ -639,14 +639,14 @@ fscrypt_setup_encryption_info(struct inode *inode,
goto out;

/*
- * For existing inodes, multiple tasks may race to set ->i_crypt_info.
+ * For existing inodes, multiple tasks may race to set ->i_fscrypt_info.
* So use cmpxchg_release(). This pairs with the smp_load_acquire() in
- * fscrypt_get_inode_info(). I.e., here we publish ->i_crypt_info with
+ * fscrypt_get_inode_info(). I.e., here we publish ->i_fscrypt_info with
* a RELEASE barrier so that other tasks can ACQUIRE it.
*/
if (fscrypt_set_inode_info(inode, crypt_info)) {
/*
- * We won the race and set ->i_crypt_info to our crypt_info.
+ * We won the race and set ->i_fscrypt_info to our crypt_info.
* Now link it into the master key's inode list.
*/
if (mk) {
@@ -678,12 +678,12 @@ fscrypt_setup_encryption_info(struct inode *inode,
* %false unless the operation being performed is needed in
* order for files (or directories) to be deleted.
*
- * Set up ->i_crypt_info, if it hasn't already been done.
+ * Set up ->i_fscrypt_info, if it hasn't already been done.
*
- * Note: unless ->i_crypt_info is already set, this isn't %GFP_NOFS-safe. So
+ * Note: unless ->i_fscrypt_info is already set, this isn't %GFP_NOFS-safe. So
* generally this shouldn't be called from within a filesystem transaction.
*
- * Return: 0 if ->i_crypt_info was set or was already set, *or* if the
+ * Return: 0 if ->i_fscrypt_info was set or was already set, *or* if the
* encryption key is unavailable. (Use fscrypt_has_encryption_key() to
* distinguish these cases.) Also can return another -errno code.
*/
@@ -738,9 +738,9 @@ int fscrypt_get_encryption_info(struct inode *inode, bool allow_unsupported)
* ->i_ino doesn't need to be set yet.
* @encrypt_ret: (output) set to %true if the new inode will be encrypted
*
- * If the directory is encrypted, set up its ->i_crypt_info in preparation for
+ * If the directory is encrypted, set up its ->i_fscrypt_info in preparation for
* encrypting the name of the new file. Also, if the new inode will be
- * encrypted, set up its ->i_crypt_info and set *encrypt_ret=true.
+ * encrypted, set up its ->i_fscrypt_info and set *encrypt_ret=true.
*
* This isn't %GFP_NOFS-safe, and therefore it should be called before starting
* any filesystem transaction to create the inode. For this reason, ->i_ino
@@ -799,12 +799,11 @@ void fscrypt_put_encryption_info(struct inode *inode)
{
struct fscrypt_inode_info **crypt_info;

- if (inode->i_op->i_fscrypt)
+ if (inode->i_op->i_fscrypt) {
crypt_info = fscrypt_addr(inode);
- else
- crypt_info = &inode->i_crypt_info;
- put_crypt_info(*crypt_info);
- *crypt_info = NULL;
+ put_crypt_info(*crypt_info);
+ *crypt_info = NULL;
+ }
}
EXPORT_SYMBOL(fscrypt_put_encryption_info);

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 82678b523720..ea5d3d3356c9 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -778,10 +778,6 @@ struct inode {
struct fsnotify_mark_connector __rcu *i_fsnotify_marks;
#endif

-#ifdef CONFIG_FS_ENCRYPTION
- struct fscrypt_inode_info *i_crypt_info;
-#endif
-
#ifdef CONFIG_FS_VERITY
struct fsverity_info *i_verity_info;
#endif
diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h
index fe48dfe171e4..fb9c8da4420f 100644
--- a/include/linux/fscrypt.h
+++ b/include/linux/fscrypt.h
@@ -203,28 +203,20 @@ static inline struct fscrypt_inode_info **fscrypt_addr(const struct inode *inode
static inline bool fscrypt_set_inode_info(struct inode *inode,
struct fscrypt_inode_info *crypt_info)
{
- void *p;
-
/*
- * For existing inodes, multiple tasks may race to set ->i_crypt_info.
+ * For existing inodes, multiple tasks may race to set ->i_fscrypt_info.
* So use cmpxchg_release(). This pairs with the smp_load_acquire() in
- * fscrypt_get_inode_info(). I.e., here we publish ->i_crypt_info with
+ * fscrypt_get_inode_info(). I.e., here we publish ->i_fscrypt_info with
* a RELEASE barrier so that other tasks can ACQUIRE it.
*/

- if (inode->i_op->i_fscrypt)
- p = cmpxchg_release(fscrypt_addr(inode), NULL, crypt_info);
- else
- p = cmpxchg_release(&inode->i_crypt_info, NULL, crypt_info);
- return p == NULL;
+ return cmpxchg_release(fscrypt_addr(inode), NULL, crypt_info) == NULL;
}

static inline struct fscrypt_inode_info *
fscrypt_get_inode_info_raw(const struct inode *inode)
{
- if (inode->i_op->i_fscrypt)
- return *fscrypt_addr(inode);
- return inode->i_crypt_info;
+ return *fscrypt_addr(inode);
}

static inline struct fscrypt_inode_info *
@@ -232,15 +224,14 @@ fscrypt_get_inode_info(const struct inode *inode)
{
/*
* Pairs with the cmpxchg_release() in fscrypt_setup_encryption_info().
- * I.e., another task may publish ->i_crypt_info concurrently, executing
+ * I.e., another task may publish ->i_fscrypt_info concurrently, executing
* a RELEASE barrier. We need to use smp_load_acquire() here to safely
* ACQUIRE the memory the other task published.
*/

if (inode->i_op->i_fscrypt)
return smp_load_acquire(fscrypt_addr(inode));
-
- return smp_load_acquire(&inode->i_crypt_info);
+ return NULL;
}

/**

--
2.47.2