inode: free up more space
Subsystems (9)
Christian Brauner
maintainerRFC PATCH 1/1 inode: free up more space
struct inode is bloated as everyone is aware and we should try and shrink it as that's potentially a lot of memory savings. I've already freed up around 8 bytes but we can probably do better.
There's a bunch of stuff that got shoved into struct inode that I don't think deserves a spot in there. There are two members I'm currently particularly interested in:
(1) #ifdef CONFIG_FS_ENCRYPTION
struct fscrypt_inode_info *i_crypt_info;
#endif
ceph, ext4, f2fs, ubifs(2) #ifdef CONFIG_FS_VERITY
struct fsverity_info *i_verity_info;
#endif
btrfs, ext4, f2fsSo we have 4 users for fscrypt and 3 users for fsverity with both features having been around for a decent amount of time.
For all other filesystems the 16 bytes are just wasted bloating inodes for every pseudo filesystem and most other regular filesystems.
We should be able to move both of these out of struct inode by adding inode operations and making it the filesystem's responsibility to accommodate the information in their respective inodes.
Unless there are severe performance penalties for the extra pointer dereferences getting our hands on 16 bytes is a good reason to at least consider doing this.
I've drafted one way of doing this using ext4 as my victim^wexample. I'd like to hear some early feedback whether this is something we would want to pursue.
Build failures very much expected!
--- fs/crypto/bio.c | 2 +- fs/crypto/crypto.c | 8 ++++---- fs/crypto/fname.c | 8 ++++---- fs/crypto/fscrypt_private.h | 3 +-- fs/crypto/hooks.c | 2 +- fs/crypto/inline_crypt.c | 10 +++++----- fs/crypto/keysetup.c | 21 ++++---------------- fs/crypto/policy.c | 8 ++++---- fs/ext4/ext4.h | 9 +++++++++ fs/ext4/file.c | 4 ++++ fs/ext4/namei.c | 22 +++++++++++++++++++++ fs/ext4/super.c | 6 +++++- fs/ext4/symlink.c | 12 ++++++++++++ include/linux/fs.h | 9 +++++---- include/linux/fscrypt.h | 47 ++++++++++++++++++++++++++++++--------------- 15 files changed, 112 insertions(+), 59 deletions(-)
fs/crypto/bio.c +1 -1
@@ -111,7 +111,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,int fscrypt_zeroout_range (const struct inode *inode,pgoff_t lblk,sector_t pblk,unsigned int len) { -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits;const unsigned int du_per_page_bits =PAGE_SHIFT - du_bits;
fs/crypto/crypto.c +4 -4
@@ -181,7 +181,7 @@ struct page *fscrypt_encrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs, gfp_t gfp_flags) { const struct inode *inode = folio->mapping->host; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits;struct page *ciphertext_page;
@@ -241,7 +241,7 @@ int fscrypt_encrypt_block_inplace(const struct inode *inode, struct page *page, {if (WARN_ON_ONCE (inode->i_sb->s_cop->supports_subblock_data_units))return -EOPNOTSUPP ; -return fscrypt_crypt_data_unit (inode->i_crypt_info,FS_ENCRYPT , +return fscrypt_crypt_data_unit (inode->i_op->get_fscrypt (inode),FS_ENCRYPT , lblk_num, page, page, len, offs, gfp_flags); }
@@ -265,7 +265,7 @@ int fscrypt_decrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs) {const struct inode *inode = folio->mapping->host; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits; u64 index = ((u64)folio->index << (PAGE_SHIFT - du_bits)) +
@@ -316,7 +316,7 @@ int fscrypt_decrypt_block_inplace(const struct inode *inode, struct page *page, {if (WARN_ON_ONCE (inode->i_sb->s_cop->supports_subblock_data_units))return -EOPNOTSUPP ; -return fscrypt_crypt_data_unit (inode->i_crypt_info,FS_DECRYPT , +return fscrypt_crypt_data_unit (inode->i_op->get_fscrypt (inode),FS_DECRYPT , lblk_num, page, page, len, offs,GFP_NOFS ); }
fs/crypto/fname.c +4 -4
@@ -94,7 +94,7 @@ int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname, {struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait); -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;struct scatterlist sg;
@@ -151,7 +151,7 @@ static int fname_decrypt(const struct inode *inode,struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait);struct scatterlist src_sg, dst_sg; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;int res;
@@ -293,7 +293,7 @@ bool __fscrypt_fname_encrypted_size(const union fscrypt_policy *policy,bool fscrypt_fname_encrypted_size (const struct inode *inode,u32 orig_len,u32 max_len,u32 *encrypted_len_ret) { -return __fscrypt_fname_encrypted_size (&inode->i_crypt_info->ci_policy, +return __fscrypt_fname_encrypted_size (&inode->i_op->get_fscrypt (inode)->ci_policy, orig_len, max_len, encrypted_len_ret); }
@@ -562,7 +562,7 @@ EXPORT_SYMBOL_GPL(fscrypt_match_name);*/ u64 fscrypt_fname_siphash (const struct inode *dir,const struct qstr *name) { -const struct fscrypt_inode_info *ci = dir->i_crypt_info; +const struct fscrypt_inode_info *ci = dir->i_op->get_fscrypt (dir);WARN_ON_ONCE (!ci->ci_dirhash_key_initialized);
fs/crypto/fscrypt_private.h +1 -2
@@ -231,8 +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 -* inode is evicted. +* allocated and stored. Once created, it remains until the inode is evicted. */ struct fscrypt_inode_info {
fs/crypto/hooks.c +1 -1
@@ -197,7 +197,7 @@ int fscrypt_prepare_setflags(struct inode *inode, err =fscrypt_require_key (inode);if (err)return err; - ci = inode->i_crypt_info; + ci = inode->i_op->get_fscrypt (inode);if (ci->ci_policy.version !=FSCRYPT_POLICY_V2 )return -EINVAL ; mk = ci->ci_master_key;
fs/crypto/inline_crypt.c +5 -5
@@ -262,7 +262,7 @@ int fscrypt_derive_sw_secret(struct super_block *sb,bool __fscrypt_inode_uses_inline_crypto (const struct inode *inode) { -return inode->i_crypt_info->ci_inlinecrypt; +return inode->i_op->get_fscrypt (inode)->ci_inlinecrypt; }EXPORT_SYMBOL_GPL (__fscrypt_inode_uses_inline_crypto);
@@ -306,7 +306,7 @@ void fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,if (!fscrypt_inode_uses_inline_crypto (inode))return ; - ci = inode->i_crypt_info; + ci = inode->i_op->get_fscrypt (inode);fscrypt_generate_dun (ci, first_lblk, dun);bio_crypt_set_ctx (bio, ci->ci_enc_key.blk_key, dun, gfp_mask);
@@ -396,10 +396,10 @@ bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,* uses the same pointer. I.e., there's currently no need to support * merging requests where the keys are the same but the pointers differ. */ -if (bc->bc_key != inode->i_crypt_info->ci_enc_key.blk_key) +if (bc->bc_key != inode->i_op->get_fscrypt (inode)->ci_enc_key.blk_key)return false; -fscrypt_generate_dun (inode->i_crypt_info, next_lblk, next_dun); +fscrypt_generate_dun (inode->i_op->get_fscrypt (inode), next_lblk, next_dun);return bio_crypt_dun_is_contiguous (bc, bio->bi_iter.bi_size, next_dun); }EXPORT_SYMBOL_GPL (fscrypt_mergeable_bio);
@@ -501,7 +501,7 @@ u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk, u64 nr_blocks)if (nr_blocks <=1 )return nr_blocks; - ci = inode->i_crypt_info; + ci = inode->i_op->get_fscrypt (inode);if (!(fscrypt_policy_flags (&ci->ci_policy) &FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32 ))return nr_blocks;
fs/crypto/keysetup.c +4 -17
@@ -568,7 +568,7 @@ static int setup_file_encryption_key(struct fscrypt_inode_info *ci,return err; } -static void put_crypt_info (struct fscrypt_inode_info *ci) +void put_crypt_info (struct fscrypt_inode_info *ci) {struct fscrypt_master_key *mk;
@@ -597,6 +597,7 @@ static void put_crypt_info(struct fscrypt_inode_info *ci)memzero_explicit (ci,sizeof (*ci));kmem_cache_free (fscrypt_inode_info_cachep, ci); } +EXPORT_SYMBOL (put_crypt_info); static int fscrypt_setup_encryption_info(struct inode *inode,
@@ -644,7 +645,7 @@ fscrypt_setup_encryption_info(struct inode *inode,* fscrypt_get_inode_info(). I.e., here we publish ->i_crypt_info with * a RELEASE barrier so that other tasks can ACQUIRE it. */ -if (cmpxchg_release (&inode->i_crypt_info,NULL , crypt_info) ==NULL ) { +if (!inode->i_op->set_fscrypt (crypt_info, inode)) {/* * We won the race and set ->i_crypt_info to our crypt_info. * Now link it into the master key's inode list.
@@ -788,20 +789,6 @@ int fscrypt_prepare_new_inode(struct inode *dir, struct inode *inode, }EXPORT_SYMBOL_GPL (fscrypt_prepare_new_inode); -/** -* fscrypt_put_encryption_info() - free most of an inode's fscrypt data -* @inode: an inode being evicted -* -* Free the inode's fscrypt_inode_info. Filesystems must call this when the -* inode is being evicted. An RCU grace period need not have elapsed yet. -*/ -void fscrypt_put_encryption_info (struct inode *inode) -{ -put_crypt_info (inode->i_crypt_info); - inode->i_crypt_info =NULL ; -} -EXPORT_SYMBOL (fscrypt_put_encryption_info); -/** * fscrypt_free_inode() - free an inode's fscrypt data requiring RCU delay * @inode: an inode being freed
@@ -830,7 +817,7 @@ EXPORT_SYMBOL(fscrypt_free_inode);*/ int fscrypt_drop_inode (struct inode *inode) { -const struct fscrypt_inode_info *ci =fscrypt_get_inode_info (inode); +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);/* * If ci is NULL, then the inode doesn't have an encryption key set up
fs/crypto/policy.c +4 -4
@@ -436,7 +436,7 @@ static int fscrypt_get_policy(struct inode *inode, union fscrypt_policy *policy)union fscrypt_context ctx;int ret; - ci =fscrypt_get_inode_info (inode); + ci = inode->i_op->get_fscrypt (inode);if (ci) {/* key available, use the cached policy */ *policy = ci->ci_policy;
@@ -725,7 +725,7 @@ const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir) err =fscrypt_require_key (dir);if (err)return ERR_PTR (err); -return &dir->i_crypt_info->ci_policy; +return &dir->i_op->get_fscrypt (dir)->ci_policy; }return fscrypt_get_dummy_policy (dir->i_sb);
@@ -744,7 +744,7 @@ const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir)*/ int fscrypt_context_for_new_inode (void *ctx,struct inode *inode) { -struct fscrypt_inode_info *ci = inode->i_crypt_info; +struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);BUILD_BUG_ON (sizeof (union fscrypt_context ) !=FSCRYPT_SET_CONTEXT_MAX_SIZE );
@@ -769,7 +769,7 @@ EXPORT_SYMBOL_GPL(fscrypt_context_for_new_inode);*/ int fscrypt_set_context (struct inode *inode,void *fs_data) { -struct fscrypt_inode_info *ci = inode->i_crypt_info; +struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);union fscrypt_context ctx;int ctxsize;
fs/ext4/ext4.h +9 -0
@@ -1197,6 +1197,10 @@ struct ext4_inode_info {__u32 i_csum_seed;kprojid_t i_projid; + +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif };/*
@@ -3904,6 +3908,11 @@ static inline bool ext4_inode_can_atomic_write(struct inode *inode)extern int ext4_block_write_begin (handle_t *handle,struct folio *folio,loff_t pos,unsigned len,get_block_t *get_block); +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *ext4_get_fscrypt (const struct inode *inode); +int ext4_set_fscrypt (struct fscrypt_inode_info *fscrypt_info,struct inode *inode); +#endif +#endif /* __KERNEL__ */ #define EFSBADCRC EBADMSG/* Bad CRC detected */
fs/ext4/file.c +4 -0
@@ -989,5 +989,9 @@ const struct inode_operations ext4_file_inode_operations = { .fiemap = ext4_fiemap, .fileattr_get = ext4_fileattr_get, .fileattr_set = ext4_fileattr_set, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif };
fs/ext4/namei.c +22 -0
@@ -4203,6 +4203,20 @@ static int ext4_rename2(struct mnt_idmap *idmap,return ext4_rename (idmap, old_dir, old_dentry, new_dir, new_dentry, flags); } +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *ext4_get_fscrypt (const struct inode *inode) +{ +struct ext4_inode_info *ei =EXT4_I (inode); +return fscrypt_inode_info_get (&ei->i_fscrypt_info); +} + +int ext4_set_fscrypt (struct fscrypt_inode_info *fscrypt_info,struct inode *inode) +{ +struct ext4_inode_info *ei =EXT4_I (inode); +return fscrypt_inode_info_set (fscrypt_info, &ei->i_fscrypt_info); +} +#endif +/* * directories can handle most operations... */
@@ -4225,6 +4239,10 @@ const struct inode_operations ext4_dir_inode_operations = { .fiemap = ext4_fiemap, .fileattr_get = ext4_fileattr_get, .fileattr_set = ext4_fileattr_set, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif }; const struct inode_operations ext4_special_inode_operations = {
@@ -4233,4 +4251,8 @@ const struct inode_operations ext4_special_inode_operations = { .listxattr = ext4_listxattr, .get_inode_acl = ext4_get_acl, .set_acl = ext4_set_acl, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif };
fs/ext4/super.c +5 -1
@@ -1412,6 +1412,9 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)INIT_WORK (&ei->i_rsv_conversion_work, ext4_end_io_rsv_work);ext4_fc_init_inode (&ei->vfs_inode);spin_lock_init (&ei->i_fc_lock); +#ifdef CONFIG_FS_ENCRYPTION + ei->i_fscrypt_info =NULL ; +#endif return &ei->vfs_inode; }
@@ -1509,7 +1512,8 @@ void ext4_clear_inode(struct inode *inode)jbd2_free_inode (EXT4_I (inode)->jinode);EXT4_I (inode)->jinode =NULL ; } -fscrypt_put_encryption_info (inode); +put_crypt_info (EXT4_I (inode)->i_fscrypt_info); +EXT4_I (inode)->i_fscrypt_info =NULL ;fsverity_cleanup_inode (inode); }
fs/ext4/symlink.c +12 -0
@@ -119,6 +119,10 @@ const struct inode_operations ext4_encrypted_symlink_inode_operations = { .setattr = ext4_setattr, .getattr = ext4_encrypted_symlink_getattr, .listxattr = ext4_listxattr, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif }; const struct inode_operations ext4_symlink_inode_operations = {
@@ -126,6 +130,10 @@ const struct inode_operations ext4_symlink_inode_operations = { .setattr = ext4_setattr, .getattr = ext4_getattr, .listxattr = ext4_listxattr, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif }; const struct inode_operations ext4_fast_symlink_inode_operations = {
@@ -133,4 +141,8 @@ const struct inode_operations ext4_fast_symlink_inode_operations = { .setattr = ext4_setattr, .getattr = ext4_getattr, .listxattr = ext4_listxattr, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif };
include/linux/fs.h +5 -4
@@ -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
@@ -2257,6 +2253,11 @@ struct inode_operations { struct dentry *dentry, struct fileattr *fa);int (*fileattr_get)(struct dentry *dentry,struct fileattr *fa);struct offset_ctx *(*get_offset_ctx)(struct inode *inode); +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *(*get_fscrypt)(const struct inode *inode); +int (*set_fscrypt)(struct fscrypt_inode_info *fscrypt_info, +struct inode *inode); +#endif }____cacheline_aligned ;/* Did the driver provide valid mmap hook configuration? */
include/linux/fscrypt.h +31 -16
80 lines not on this page · raw message
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250715-work-inode-fscrypt-2b63b276e793
Quoted 586 lines · Christian Brauner
struct inode is bloated as everyone is aware and we should try and shrink it as that's potentially a lot of memory savings. I've already freed up around 8 bytes but we can probably do better.
There's a bunch of stuff that got shoved into struct inode that I don't think deserves a spot in there. There are two members I'm currently particularly interested in:
(1) #ifdef
CONFIG_FS_ENCRYPTIONstruct fscrypt_inode_info *i_crypt_info; #endif ceph, ext4, f2fs, ubifs(2) #ifdef
CONFIG_FS_VERITYstruct fsverity_info *i_verity_info; #endif btrfs, ext4, f2fsSo we have 4 users for fscrypt and 3 users for fsverity with both features having been around for a decent amount of time.
For all other filesystems the 16 bytes are just wasted bloating inodes for every pseudo filesystem and most other regular filesystems.
We should be able to move both of these out of struct inode by adding inode operations and making it the filesystem's responsibility to accommodate the information in their respective inodes.
Unless there are severe performance penalties for the extra pointer dereferences getting our hands on 16 bytes is a good reason to at least consider doing this.
I've drafted one way of doing this using ext4 as my victim^wexample. I'd like to hear some early feedback whether this is something we would want to pursue.
Build failures very much expected!
Not-Signed-off-by Christian Brauner <[email protected]>--- fs/crypto/bio.c | 2 +- fs/crypto/crypto.c | 8 ++++---- fs/crypto/fname.c | 8 ++++---- fs/crypto/fscrypt_private.h | 3 +-- fs/crypto/hooks.c | 2 +- fs/crypto/inline_crypt.c | 10 +++++----- fs/crypto/keysetup.c | 21 ++++---------------- fs/crypto/policy.c | 8 ++++---- fs/ext4/ext4.h | 9 +++++++++ fs/ext4/file.c | 4 ++++ fs/ext4/namei.c | 22 +++++++++++++++++++++ fs/ext4/super.c | 6 +++++- fs/ext4/symlink.c | 12 ++++++++++++ include/linux/fs.h | 9 +++++---- include/linux/fscrypt.h | 47 ++++++++++++++++++++++++++++++--------------- 15 files changed, 112 insertions(+), 59 deletions(-)fs/crypto/bio.c +1
-1@@ -111,7 +111,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,int fscrypt_zeroout_range (const struct inode *inode,pgoff_t lblk,sector_t pblk,unsigned int len) { -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits;const unsigned int du_per_page_bits =PAGE_SHIFT - du_bits;fs/crypto/crypto.c +4
-4@@ -181,7 +181,7 @@ struct page *fscrypt_encrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs, gfp_t gfp_flags) { const struct inode *inode = folio->mapping->host; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits;struct page *ciphertext_page;@@ -241,7 +241,7 @@ int fscrypt_encrypt_block_inplace(const struct inode *inode, struct page *page, {if (WARN_ON_ONCE (inode->i_sb->s_cop->supports_subblock_data_units))return -EOPNOTSUPP ; -return fscrypt_crypt_data_unit (inode->i_crypt_info,FS_ENCRYPT , +return fscrypt_crypt_data_unit (inode->i_op->get_fscrypt (inode),FS_ENCRYPT , lblk_num, page, page, len, offs, gfp_flags); }@@ -265,7 +265,7 @@ int fscrypt_decrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs) {const struct inode *inode = folio->mapping->host; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits; u64 index = ((u64)folio->index << (PAGE_SHIFT - du_bits)) +@@ -316,7 +316,7 @@ int fscrypt_decrypt_block_inplace(const struct inode *inode, struct page *page, {if (WARN_ON_ONCE (inode->i_sb->s_cop->supports_subblock_data_units))return -EOPNOTSUPP ; -return fscrypt_crypt_data_unit (inode->i_crypt_info,FS_DECRYPT , +return fscrypt_crypt_data_unit (inode->i_op->get_fscrypt (inode),FS_DECRYPT , lblk_num, page, page, len, offs,GFP_NOFS ); }fs/crypto/fname.c +4
-4@@ -94,7 +94,7 @@ int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname, {struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait); -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;struct scatterlist sg;@@ -151,7 +151,7 @@ static int fname_decrypt(const struct inode *inode,struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait);struct scatterlist src_sg, dst_sg; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;int res;@@ -293,7 +293,7 @@ bool __fscrypt_fname_encrypted_size(const union fscrypt_policy *policy,bool fscrypt_fname_encrypted_size (const struct inode *inode,u32 orig_len,u32 max_len,u32 *encrypted_len_ret) { -return __fscrypt_fname_encrypted_size (&inode->i_crypt_info->ci_policy, +return __fscrypt_fname_encrypted_size (&inode->i_op->get_fscrypt (inode)->ci_policy, orig_len, max_len, encrypted_len_ret); }@@ -562,7 +562,7 @@ EXPORT_SYMBOL_GPL(fscrypt_match_name);*/ u64 fscrypt_fname_siphash (const struct inode *dir,const struct qstr *name) { -const struct fscrypt_inode_info *ci = dir->i_crypt_info; +const struct fscrypt_inode_info *ci = dir->i_op->get_fscrypt (dir);WARN_ON_ONCE (!ci->ci_dirhash_key_initialized);fs/crypto/fscrypt_private.h +1
-2@@ -231,8 +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 -* inode is evicted. +* allocated and stored. Once created, it remains until the inode is evicted. */ struct fscrypt_inode_info {fs/crypto/hooks.c +1
-1@@ -197,7 +197,7 @@ int fscrypt_prepare_setflags(struct inode *inode, err =fscrypt_require_key (inode);if (err)return err; - ci = inode->i_crypt_info; + ci = inode->i_op->get_fscrypt (inode);if (ci->ci_policy.version !=FSCRYPT_POLICY_V2 )return -EINVAL ; mk = ci->ci_master_key;fs/crypto/inline_crypt.c +5
-5@@ -262,7 +262,7 @@ int fscrypt_derive_sw_secret(struct super_block *sb,bool __fscrypt_inode_uses_inline_crypto (const struct inode *inode) { -return inode->i_crypt_info->ci_inlinecrypt; +return inode->i_op->get_fscrypt (inode)->ci_inlinecrypt; }EXPORT_SYMBOL_GPL (__fscrypt_inode_uses_inline_crypto);@@ -306,7 +306,7 @@ void fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,if (!fscrypt_inode_uses_inline_crypto (inode))return ; - ci = inode->i_crypt_info; + ci = inode->i_op->get_fscrypt (inode);fscrypt_generate_dun (ci, first_lblk, dun);bio_crypt_set_ctx (bio, ci->ci_enc_key.blk_key, dun, gfp_mask);@@ -396,10 +396,10 @@ bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,* uses the same pointer. I.e., there's currently no need to support * merging requests where the keys are the same but the pointers differ. */ -if (bc->bc_key != inode->i_crypt_info->ci_enc_key.blk_key) +if (bc->bc_key != inode->i_op->get_fscrypt (inode)->ci_enc_key.blk_key)return false; -fscrypt_generate_dun (inode->i_crypt_info, next_lblk, next_dun); +fscrypt_generate_dun (inode->i_op->get_fscrypt (inode), next_lblk, next_dun);return bio_crypt_dun_is_contiguous (bc, bio->bi_iter.bi_size, next_dun); }EXPORT_SYMBOL_GPL (fscrypt_mergeable_bio);@@ -501,7 +501,7 @@ u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk, u64 nr_blocks)if (nr_blocks <=1 )return nr_blocks; - ci = inode->i_crypt_info; + ci = inode->i_op->get_fscrypt (inode);if (!(fscrypt_policy_flags (&ci->ci_policy) &FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32 ))return nr_blocks;fs/crypto/keysetup.c +4
-17@@ -568,7 +568,7 @@ static int setup_file_encryption_key(struct fscrypt_inode_info *ci,return err; } -static void put_crypt_info (struct fscrypt_inode_info *ci) +void put_crypt_info (struct fscrypt_inode_info *ci) {struct fscrypt_master_key *mk;@@ -597,6 +597,7 @@ static void put_crypt_info(struct fscrypt_inode_info *ci)memzero_explicit (ci,sizeof (*ci));kmem_cache_free (fscrypt_inode_info_cachep, ci); } +EXPORT_SYMBOL (put_crypt_info); static int fscrypt_setup_encryption_info(struct inode *inode,@@ -644,7 +645,7 @@ fscrypt_setup_encryption_info(struct inode *inode,* fscrypt_get_inode_info(). I.e., here we publish ->i_crypt_info with * a RELEASE barrier so that other tasks can ACQUIRE it. */ -if (cmpxchg_release (&inode->i_crypt_info,NULL , crypt_info) ==NULL ) { +if (!inode->i_op->set_fscrypt (crypt_info, inode)) {/* * We won the race and set ->i_crypt_info to our crypt_info. * Now link it into the master key's inode list. @@ -788,20 +789,6 @@ int fscrypt_prepare_new_inode(struct inode *dir, struct inode *inode, }EXPORT_SYMBOL_GPL (fscrypt_prepare_new_inode); -/** -* fscrypt_put_encryption_info() - free most of an inode's fscrypt data -* @inode: an inode being evicted -* -* Free the inode's fscrypt_inode_info. Filesystems must call this when the -* inode is being evicted. An RCU grace period need not have elapsed yet. -*/ -void fscrypt_put_encryption_info (struct inode *inode) -{ -put_crypt_info (inode->i_crypt_info); - inode->i_crypt_info =NULL ; -} -EXPORT_SYMBOL (fscrypt_put_encryption_info); -/** * fscrypt_free_inode() - free an inode's fscrypt data requiring RCU delay * @inode: an inode being freed @@ -830,7 +817,7 @@ EXPORT_SYMBOL(fscrypt_free_inode);*/ int fscrypt_drop_inode (struct inode *inode) { -const struct fscrypt_inode_info *ci =fscrypt_get_inode_info (inode); +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);/* * If ci is NULL, then the inode doesn't have an encryption key set up fs/crypto/policy.c +4
-4@@ -436,7 +436,7 @@ static int fscrypt_get_policy(struct inode *inode, union fscrypt_policy *policy)union fscrypt_context ctx;int ret; - ci =fscrypt_get_inode_info (inode); + ci = inode->i_op->get_fscrypt (inode);if (ci) {/* key available, use the cached policy */ *policy = ci->ci_policy;@@ -725,7 +725,7 @@ const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir) err =fscrypt_require_key (dir);if (err)return ERR_PTR (err); -return &dir->i_crypt_info->ci_policy; +return &dir->i_op->get_fscrypt (dir)->ci_policy; }return fscrypt_get_dummy_policy (dir->i_sb);@@ -744,7 +744,7 @@ const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir)*/ int fscrypt_context_for_new_inode (void *ctx,struct inode *inode) { -struct fscrypt_inode_info *ci = inode->i_crypt_info; +struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);BUILD_BUG_ON (sizeof (union fscrypt_context ) !=FSCRYPT_SET_CONTEXT_MAX_SIZE );@@ -769,7 +769,7 @@ EXPORT_SYMBOL_GPL(fscrypt_context_for_new_inode);*/ int fscrypt_set_context (struct inode *inode,void *fs_data) { -struct fscrypt_inode_info *ci = inode->i_crypt_info; +struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);union fscrypt_context ctx;int ctxsize;fs/ext4/ext4.h +9
-0@@ -1197,6 +1197,10 @@ struct ext4_inode_info {__u32 i_csum_seed;kprojid_t i_projid; + +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif };/* @@ -3904,6 +3908,11 @@ static inline bool ext4_inode_can_atomic_write(struct inode *inode)extern int ext4_block_write_begin (handle_t *handle,struct folio *folio,loff_t pos,unsigned len,get_block_t *get_block); +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *ext4_get_fscrypt (const struct inode *inode); +int ext4_set_fscrypt (struct fscrypt_inode_info *fscrypt_info,struct inode *inode); +#endif +#endif /* __KERNEL__ */ #define EFSBADCRC EBADMSG/* Bad CRC detected */ fs/ext4/file.c +4
-0@@ -989,5 +989,9 @@ const struct inode_operations ext4_file_inode_operations = { .fiemap = ext4_fiemap, .fileattr_get = ext4_fileattr_get, .fileattr_set = ext4_fileattr_set, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif };fs/ext4/namei.c +22
-0@@ -4203,6 +4203,20 @@ static int ext4_rename2(struct mnt_idmap *idmap,return ext4_rename (idmap, old_dir, old_dentry, new_dir, new_dentry, flags); } +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *ext4_get_fscrypt (const struct inode *inode) +{ +struct ext4_inode_info *ei =EXT4_I (inode); +return fscrypt_inode_info_get (&ei->i_fscrypt_info); +} + +int ext4_set_fscrypt (struct fscrypt_inode_info *fscrypt_info,struct inode *inode) +{ +struct ext4_inode_info *ei =EXT4_I (inode); +return fscrypt_inode_info_set (fscrypt_info, &ei->i_fscrypt_info); +} +#endif +/* * directories can handle most operations... */ @@ -4225,6 +4239,10 @@ const struct inode_operations ext4_dir_inode_operations = { .fiemap = ext4_fiemap, .fileattr_get = ext4_fileattr_get, .fileattr_set = ext4_fileattr_set, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif }; const struct inode_operations ext4_special_inode_operations = {@@ -4233,4 +4251,8 @@ const struct inode_operations ext4_special_inode_operations = { .listxattr = ext4_listxattr, .get_inode_acl = ext4_get_acl, .set_acl = ext4_set_acl, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif };fs/ext4/super.c +5
-1@@ -1412,6 +1412,9 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)INIT_WORK (&ei->i_rsv_conversion_work, ext4_end_io_rsv_work);ext4_fc_init_inode (&ei->vfs_inode);spin_lock_init (&ei->i_fc_lock); +#ifdef CONFIG_FS_ENCRYPTION + ei->i_fscrypt_info =NULL ; +#endif return &ei->vfs_inode; }@@ -1509,7 +1512,8 @@ void ext4_clear_inode(struct inode *inode)jbd2_free_inode (EXT4_I (inode)->jinode);EXT4_I (inode)->jinode =NULL ; } -fscrypt_put_encryption_info (inode); +put_crypt_info (EXT4_I (inode)->i_fscrypt_info); +EXT4_I (inode)->i_fscrypt_info =NULL ;fsverity_cleanup_inode (inode); }fs/ext4/symlink.c +12
-0@@ -119,6 +119,10 @@ const struct inode_operations ext4_encrypted_symlink_inode_operations = { .setattr = ext4_setattr, .getattr = ext4_encrypted_symlink_getattr, .listxattr = ext4_listxattr, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif }; const struct inode_operations ext4_symlink_inode_operations = {@@ -126,6 +130,10 @@ const struct inode_operations ext4_symlink_inode_operations = { .setattr = ext4_setattr, .getattr = ext4_getattr, .listxattr = ext4_listxattr, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif }; const struct inode_operations ext4_fast_symlink_inode_operations = {@@ -133,4 +141,8 @@ const struct inode_operations ext4_fast_symlink_inode_operations = { .setattr = ext4_setattr, .getattr = ext4_getattr, .listxattr = ext4_listxattr, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif };include/linux/fs.h +5
-4@@ -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 @@ -2257,6 +2253,11 @@ struct inode_operations { struct dentry *dentry, struct fileattr *fa);int (*fileattr_get)(struct dentry *dentry,struct fileattr *fa);struct offset_ctx *(*get_offset_ctx)(struct inode *inode); +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *(*get_fscrypt)(const struct inode *inode); +int (*set_fscrypt)(struct fscrypt_inode_info *fscrypt_info, +struct inode *inode); +#endif }____cacheline_aligned ;/* Did the driver provide valid mmap hook configuration? */ include/linux/fscrypt.h +31
-17@@ -195,18 +195,6 @@ struct fscrypt_operations {int fscrypt_d_revalidate (struct inode *dir,const struct qstr *name,struct dentry *dentry,unsigned int flags); -static inline struct fscrypt_inode_info * -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 -* a RELEASE barrier. We need to use smp_load_acquire() here to safely -* ACQUIRE the memory the other task published. -*/ -return smp_load_acquire (&inode->i_crypt_info); -} -/** * fscrypt_needs_contents_encryption() - check whether an inode needs * contents encryption @@ -385,7 +373,7 @@ int fscrypt_ioctl_get_key_status(struct file *filp, void __user *arg);/* keysetup.c */ int fscrypt_prepare_new_inode (struct inode *dir,struct inode *inode,bool *encrypt_ret); -void fscrypt_put_encryption_info (struct inode *inode); +void put_crypt_info (struct fscrypt_inode_info *ci);void fscrypt_free_inode (struct inode *inode);int fscrypt_drop_inode (struct inode *inode);@@ -446,10 +434,37 @@ static inline void fscrypt_set_ops(struct super_block *sb, { sb->s_cop = s_cop; } + +static inline int fscrypt_inode_info_set (struct fscrypt_inode_info *crypt_info, +struct fscrypt_inode_info **p) +{ +if (cmpxchg_release (p,NULL , crypt_info) !=NULL ) +return -EEXIST ; +return 0 ; +} + +static inline struct fscrypt_inode_info * +fscrypt_inode_info_get (struct fscrypt_inode_info **crypt_info) +{ +/* +* Pairs with the cmpxchg_release() in fscrypt_inode_info_set(). I.e., +* another task may publish crypt_info concurrently, executing a +* RELEASE barrier. We need to use smp_load_acquire() here to safely +* ACQUIRE the memory the other task published (could be a READ_ONCE() +* really). +*/ +return smp_load_acquire (crypt_info); +}#else /* !CONFIG_FS_ENCRYPTION */ +static inline int fscrypt_inode_info_set (struct fscrypt_inode_info *crypt_info, +struct fscrypt_inode_info **p) +{ +return 0 ; +} +static inline struct fscrypt_inode_info * -fscrypt_get_inode_info (const struct inode *inode) +fscrypt_inode_info_get (const struct fscrypt_inode_info **crypt_info) {return NULL ; }@@ -639,7 +654,7 @@ static inline int fscrypt_prepare_new_inode(struct inode *dir,return 0 ; } -static inline void fscrypt_put_encryption_info (struct inode *inode) +static inline void put_crypt_info (struct fscrypt_inode_info *ci) {return ; }@@ -930,7 +945,7 @@ static inline bool fscrypt_inode_uses_fs_layer_crypto(const struct inode *inode)*/ static inline bool fscrypt_has_encryption_key (const struct inode *inode) { -return fscrypt_get_inode_info (inode) !=NULL ; +return inode->i_op->get_fscrypt (inode) !=NULL ; }/** ---
Quoted 2 lines
base-commit:
19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250715-work-inode-fscrypt-2b63b276e793
I like the concept. Debloating struct inode is a great goal, IMO. Fields that are not generally useful should be in the fs-specific inodes.
I do wish it weren't quite so cumbersome with having to define _get/_set operations, but I think it's a reasonable tradeoff to get these fields out of struct inode.
Cheers!
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 3 lines · Christian Brauner
struct inode is bloated as everyone is aware and we should try and shrink it as that's potentially a lot of memory savings. I've already freed up around 8 bytes but we can probably do better.
OK, but let's make sure we're actually achieving memory savings. First, inodes are allocated from slabs. If we reduce a struct from, say, 596 to 592 bytes, we'll still get 27 of them in a 16KiB page (although we'd get 110 instead of 109 in a 64KiB page!) so we need to be crossing some important boundaries to actually make a difference.
For block/network filesystems, those slabs are fs-private with struct inode embedded into struct fs_inode. eg:
xfs_inode 584600 593856 1024 32 8 : tunables 0 0 0 : slabdata 18558 18558 0 ext4_inode_cache 756 756 1168 28 8 : tunables 0 0 0 : slabdata 27 27 0 proc_inode_cache 18316 19136 704 46 8 : tunables 0 0 0 : slabdata 416 416 0 inode_cache 8059 9325 632 25 4 : tunables 0 0 0 : slabdata 373 373 0
That's on a machine running 6.12 and pahole tells me struct inode is currently 624 bytes, so yes, you've saved 8 bytes (Debian config). And we've gone from 25 objects per 16KiB to 26, so yay! Getting to 27 will be harder, we have to get to 604 bytes. Although for my system if we could get xfs_inode down from 1024 bytes to 992, that'd save me much more memory ;-)
We could get rid of i_io_list by using an allocating xarray to store the inodes in each backing_dev. There's 16 bytes (would probably need to retain a 4 byte ID to allow for efficient deletion from the xarray, and there are multiple lists it might be on, so perhaps 3 bits to determine which list it's on).
That might work for i_sb_list, i_sb_list and i_lru too. That could get us 48 bytes.
We can also win in inode by shrinking address_space. nr_thps is one I want to kill. That'll get us 8 bytes back as soon as btrfs lets us drop CONFIG_READ_ONLY_THP_FOR_FS.
The i_private_* members in i_data can probably also go. Mostly they're used for buffer_heads. So more conversion to iomap will help with that.
I wonder if we can shift from having i_data embedded in struct inode to embedding it in struct foofs_inode. Then procfs and other pseudo filesystems wouldn't allocate 192 bytes worth of data ...
Christian Brauner
maintainerQuoted 39 lines · Matthew Wilcox
Quoted 3 lines · Christian Brauner
struct inode is bloated as everyone is aware and we should try and shrink it as that's potentially a lot of memory savings. I've already freed up around 8 bytes but we can probably do better.
OK, but let's make sure we're actually achieving memory savings. First, inodes are allocated from slabs. If we reduce a struct from, say, 596 to 592 bytes, we'll still get 27 of them in a 16KiB page (although we'd get 110 instead of 109 in a 64KiB page!) so we need to be crossing some important boundaries to actually make a difference.
For block/network filesystems, those slabs are fs-private with struct inode embedded into struct
fs_inode. eg:xfs_inode 584600 593856 1024 32 8 : tunables 0 0 0 : slabdata 18558 18558 0 ext4_inode_cache 756 756 1168 28 8 : tunables 0 0 0 : slabdata 27 27 0 proc_inode_cache 18316 19136 704 46 8 : tunables 0 0 0 : slabdata 416 416 0 inode_cache 8059 9325 632 25 4 : tunables 0 0 0 : slabdata 373 373 0That's on a machine running 6.12 and pahole tells me struct inode is currently 624 bytes, so yes, you've saved 8 bytes (Debian config). And we've gone from 25 objects per 16KiB to 26, so yay! Getting to 27 will be harder, we have to get to 604 bytes. Although for my system if we could get
xfs_inodedown from 1024 bytes to 992, that'd save me much more memory ;-)We could get rid of
i_io_listby using an allocating xarray to store the inodes in eachbacking_dev. There's 16 bytes (would probably need to retain a 4 byte ID to allow for efficient deletion from the xarray, and there are multiple lists it might be on, so perhaps 3 bits to determine which list it's on).That might work for
i_sb_list,i_sb_listandi_lrutoo. That could get us 48 bytes.We can also win in inode by shrinking
address_space.nr_thpsis one I want to kill. That'll get us 8 bytes back as soon as btrfs lets us dropCONFIG_READ_ONLY_THP_FOR_FS.
Quoted 7 lines
The i_private_* members in
i_datacan probably also go. Mostly they're used forbuffer_heads. So more conversion to iomap will help with that.I wonder if we can shift from having
i_dataembedded in struct inode to embedding it in structfoofs_inode. Then procfs and other pseudo filesystems wouldn't allocate 192 bytes worth of data ...
If you/or someone manages to do that work before LSFMM in May 2026 I'll bring the author a VFS T-Shirt with "I shrunk struct inode by $n bytes." LSFMM 2026 edition.
Quoted 3 lines · Matthew Wilcox
will be harder, we have to get to 604 bytes. Although for my system if we could get
xfs_inodedown from 1024 bytes to 992, that'd save me much more memory ;-)
There's some relatively low hanging fruit there.
One would be to make the VFS inode i_ino a u64 finally so that XFS and other modern files systems an stop having their own duplicate of it (which would also remove tons of code in various file systems).
i_mount could be replaced by going to the VFS inode i_sb, and from that to the xfs mount. That would be nicer if the sb was embeeded into the fs structure to reduce the pointer chasing, though.
і_pincount could move into the xfs_inode_log_item, as it is only needed for inodes that got logged.
i_ioend_lock and i_ioend_list (24 bytes) could be replaced with a llist_node (8 bytes). All the i_ioend fields are only used for inodes that are written to. We could move them into the inode log item, which would then also be allocated for inodes that are only purely overwritten and not actually logged.
Christian Brauner
maintainerQuoted 9 lines · Christoph Hellwig
Quoted 3 lines · Matthew Wilcox
will be harder, we have to get to 604 bytes. Although for my system if we could get
xfs_inodedown from 1024 bytes to 992, that'd save me much more memory ;-)There's some relatively low hanging fruit there.
One would be to make the VFS inode
i_inoa u64 finally so that XFS and other modern files systems an stop having their own duplicate of
That's already on my TODO since we discussed this with Jeff last year.
Quoted 6 lines · Christian Brauner
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Matthew Wilcox
will be harder, we have to get to 604 bytes. Although for my system if we could get
xfs_inodedown from 1024 bytes to 992, that'd save me much more memory ;-)
Quoted 6 lines
Quoted 4 lines
There's some relatively low hanging fruit there.
One would be to make the VFS inode
i_inoa u64 finally so that XFS and other modern files systems an stop having their own duplicate ofThat's already on my TODO since we discussed this with Jeff last year.
Cool!
Btw, I remember anothing I've been wanting to look at, which is killing the u/g/p quota pointers. If we used a rhashtable with proper sizing for them, doing a hash lookup instead of the caching should be efficient enough to be noise compared to the actual quota operations. That would free three pointers per inode, or in case of XFS six without the optimization in this thread. ---end quoted text---
Quoted 14 lines · Christoph Hellwig
Quoted 6 lines · Christian Brauner
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Matthew Wilcox
will be harder, we have to get to 604 bytes. Although for my system if we could get
xfs_inodedown from 1024 bytes to 992, that'd save me much more memory ;-)Quoted 6 lines
Quoted 4 lines
There's some relatively low hanging fruit there.
One would be to make the VFS inode
i_inoa u64 finally so that XFS and other modern files systems an stop having their own duplicate ofThat's already on my TODO since we discussed this with Jeff last year.
Quoted 8 lines
Cool!
Btw, I remember anothing I've been wanting to look at, which is killing the u/g/p quota pointers. If we used a rhashtable with proper sizing for them, doing a hash lookup instead of the caching should be efficient enough to be noise compared to the actual quota operations. That would free three pointers per inode, or in case of XFS six without the optimization in this thread.
That would be really nice. :)
--D
Jan Kara
reviewerQuoted 34 lines · Christian Brauner
struct inode is bloated as everyone is aware and we should try and shrink it as that's potentially a lot of memory savings. I've already freed up around 8 bytes but we can probably do better.
There's a bunch of stuff that got shoved into struct inode that I don't think deserves a spot in there. There are two members I'm currently particularly interested in:
(1) #ifdef
CONFIG_FS_ENCRYPTIONstruct fscrypt_inode_info *i_crypt_info; #endif ceph, ext4, f2fs, ubifs(2) #ifdef
CONFIG_FS_VERITYstruct fsverity_info *i_verity_info; #endif btrfs, ext4, f2fsSo we have 4 users for fscrypt and 3 users for fsverity with both features having been around for a decent amount of time.
For all other filesystems the 16 bytes are just wasted bloating inodes for every pseudo filesystem and most other regular filesystems.
We should be able to move both of these out of struct inode by adding inode operations and making it the filesystem's responsibility to accommodate the information in their respective inodes.
Unless there are severe performance penalties for the extra pointer dereferences getting our hands on 16 bytes is a good reason to at least consider doing this.
Quoted 7 lines
I've drafted one way of doing this using ext4 as my victim^wexample. I'd like to hear some early feedback whether this is something we would want to pursue.
Build failures very much expected!
Not-Signed-off-by Christian Brauner <[email protected]>
I like the concept. I went that way with quota info attached to the inode as well. Just for quota info I've put the .get_dquots hook into super_operations because in practice all inodes in a superblock have to have a common memory layout anyway. OTOH inode_operations are one deference closer so maybe they are a better fit? Anyway, all I wanted to say is that I think we should strive for a unified way of getting this extra inode info if possible so either I can switch quotas or you can switch fscrypt + fsverity.
Honza
Quoted 548 lines
--- fs/crypto/bio.c | 2 +- fs/crypto/crypto.c | 8 ++++---- fs/crypto/fname.c | 8 ++++---- fs/crypto/fscrypt_private.h | 3 +-- fs/crypto/hooks.c | 2 +- fs/crypto/inline_crypt.c | 10 +++++----- fs/crypto/keysetup.c | 21 ++++---------------- fs/crypto/policy.c | 8 ++++---- fs/ext4/ext4.h | 9 +++++++++ fs/ext4/file.c | 4 ++++ fs/ext4/namei.c | 22 +++++++++++++++++++++ fs/ext4/super.c | 6 +++++- fs/ext4/symlink.c | 12 ++++++++++++ include/linux/fs.h | 9 +++++---- include/linux/fscrypt.h | 47 ++++++++++++++++++++++++++++++--------------- 15 files changed, 112 insertions(+), 59 deletions(-)fs/crypto/bio.c +1
-1@@ -111,7 +111,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,int fscrypt_zeroout_range (const struct inode *inode,pgoff_t lblk,sector_t pblk,unsigned int len) { -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits;const unsigned int du_per_page_bits =PAGE_SHIFT - du_bits;fs/crypto/crypto.c +4
-4@@ -181,7 +181,7 @@ struct page *fscrypt_encrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs, gfp_t gfp_flags) { const struct inode *inode = folio->mapping->host; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits;struct page *ciphertext_page;@@ -241,7 +241,7 @@ int fscrypt_encrypt_block_inplace(const struct inode *inode, struct page *page, {if (WARN_ON_ONCE (inode->i_sb->s_cop->supports_subblock_data_units))return -EOPNOTSUPP ; -return fscrypt_crypt_data_unit (inode->i_crypt_info,FS_ENCRYPT , +return fscrypt_crypt_data_unit (inode->i_op->get_fscrypt (inode),FS_ENCRYPT , lblk_num, page, page, len, offs, gfp_flags); }@@ -265,7 +265,7 @@ int fscrypt_decrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs) {const struct inode *inode = folio->mapping->host; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits; u64 index = ((u64)folio->index << (PAGE_SHIFT - du_bits)) +@@ -316,7 +316,7 @@ int fscrypt_decrypt_block_inplace(const struct inode *inode, struct page *page, {if (WARN_ON_ONCE (inode->i_sb->s_cop->supports_subblock_data_units))return -EOPNOTSUPP ; -return fscrypt_crypt_data_unit (inode->i_crypt_info,FS_DECRYPT , +return fscrypt_crypt_data_unit (inode->i_op->get_fscrypt (inode),FS_DECRYPT , lblk_num, page, page, len, offs,GFP_NOFS ); }fs/crypto/fname.c +4
-4@@ -94,7 +94,7 @@ int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname, {struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait); -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;struct scatterlist sg;@@ -151,7 +151,7 @@ static int fname_decrypt(const struct inode *inode,struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait);struct scatterlist src_sg, dst_sg; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;int res;@@ -293,7 +293,7 @@ bool __fscrypt_fname_encrypted_size(const union fscrypt_policy *policy,bool fscrypt_fname_encrypted_size (const struct inode *inode,u32 orig_len,u32 max_len,u32 *encrypted_len_ret) { -return __fscrypt_fname_encrypted_size (&inode->i_crypt_info->ci_policy, +return __fscrypt_fname_encrypted_size (&inode->i_op->get_fscrypt (inode)->ci_policy, orig_len, max_len, encrypted_len_ret); }@@ -562,7 +562,7 @@ EXPORT_SYMBOL_GPL(fscrypt_match_name);*/ u64 fscrypt_fname_siphash (const struct inode *dir,const struct qstr *name) { -const struct fscrypt_inode_info *ci = dir->i_crypt_info; +const struct fscrypt_inode_info *ci = dir->i_op->get_fscrypt (dir);WARN_ON_ONCE (!ci->ci_dirhash_key_initialized);fs/crypto/fscrypt_private.h +1
-2@@ -231,8 +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 -* inode is evicted. +* allocated and stored. Once created, it remains until the inode is evicted. */ struct fscrypt_inode_info {fs/crypto/hooks.c +1
-1@@ -197,7 +197,7 @@ int fscrypt_prepare_setflags(struct inode *inode, err =fscrypt_require_key (inode);if (err)return err; - ci = inode->i_crypt_info; + ci = inode->i_op->get_fscrypt (inode);if (ci->ci_policy.version !=FSCRYPT_POLICY_V2 )return -EINVAL ; mk = ci->ci_master_key;fs/crypto/inline_crypt.c +5
-5@@ -262,7 +262,7 @@ int fscrypt_derive_sw_secret(struct super_block *sb,bool __fscrypt_inode_uses_inline_crypto (const struct inode *inode) { -return inode->i_crypt_info->ci_inlinecrypt; +return inode->i_op->get_fscrypt (inode)->ci_inlinecrypt; }EXPORT_SYMBOL_GPL (__fscrypt_inode_uses_inline_crypto);@@ -306,7 +306,7 @@ void fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,if (!fscrypt_inode_uses_inline_crypto (inode))return ; - ci = inode->i_crypt_info; + ci = inode->i_op->get_fscrypt (inode);fscrypt_generate_dun (ci, first_lblk, dun);bio_crypt_set_ctx (bio, ci->ci_enc_key.blk_key, dun, gfp_mask);@@ -396,10 +396,10 @@ bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,* uses the same pointer. I.e., there's currently no need to support * merging requests where the keys are the same but the pointers differ. */ -if (bc->bc_key != inode->i_crypt_info->ci_enc_key.blk_key) +if (bc->bc_key != inode->i_op->get_fscrypt (inode)->ci_enc_key.blk_key)return false; -fscrypt_generate_dun (inode->i_crypt_info, next_lblk, next_dun); +fscrypt_generate_dun (inode->i_op->get_fscrypt (inode), next_lblk, next_dun);return bio_crypt_dun_is_contiguous (bc, bio->bi_iter.bi_size, next_dun); }EXPORT_SYMBOL_GPL (fscrypt_mergeable_bio);@@ -501,7 +501,7 @@ u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk, u64 nr_blocks)if (nr_blocks <=1 )return nr_blocks; - ci = inode->i_crypt_info; + ci = inode->i_op->get_fscrypt (inode);if (!(fscrypt_policy_flags (&ci->ci_policy) &FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32 ))return nr_blocks;fs/crypto/keysetup.c +4
-17@@ -568,7 +568,7 @@ static int setup_file_encryption_key(struct fscrypt_inode_info *ci,return err; } -static void put_crypt_info (struct fscrypt_inode_info *ci) +void put_crypt_info (struct fscrypt_inode_info *ci) {struct fscrypt_master_key *mk;@@ -597,6 +597,7 @@ static void put_crypt_info(struct fscrypt_inode_info *ci)memzero_explicit (ci,sizeof (*ci));kmem_cache_free (fscrypt_inode_info_cachep, ci); } +EXPORT_SYMBOL (put_crypt_info); static int fscrypt_setup_encryption_info(struct inode *inode,@@ -644,7 +645,7 @@ fscrypt_setup_encryption_info(struct inode *inode,* fscrypt_get_inode_info(). I.e., here we publish ->i_crypt_info with * a RELEASE barrier so that other tasks can ACQUIRE it. */ -if (cmpxchg_release (&inode->i_crypt_info,NULL , crypt_info) ==NULL ) { +if (!inode->i_op->set_fscrypt (crypt_info, inode)) {/* * We won the race and set ->i_crypt_info to our crypt_info. * Now link it into the master key's inode list. @@ -788,20 +789,6 @@ int fscrypt_prepare_new_inode(struct inode *dir, struct inode *inode, }EXPORT_SYMBOL_GPL (fscrypt_prepare_new_inode); -/** -* fscrypt_put_encryption_info() - free most of an inode's fscrypt data -* @inode: an inode being evicted -* -* Free the inode's fscrypt_inode_info. Filesystems must call this when the -* inode is being evicted. An RCU grace period need not have elapsed yet. -*/ -void fscrypt_put_encryption_info (struct inode *inode) -{ -put_crypt_info (inode->i_crypt_info); - inode->i_crypt_info =NULL ; -} -EXPORT_SYMBOL (fscrypt_put_encryption_info); -/** * fscrypt_free_inode() - free an inode's fscrypt data requiring RCU delay * @inode: an inode being freed @@ -830,7 +817,7 @@ EXPORT_SYMBOL(fscrypt_free_inode);*/ int fscrypt_drop_inode (struct inode *inode) { -const struct fscrypt_inode_info *ci =fscrypt_get_inode_info (inode); +const struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);/* * If ci is NULL, then the inode doesn't have an encryption key set up fs/crypto/policy.c +4
-4@@ -436,7 +436,7 @@ static int fscrypt_get_policy(struct inode *inode, union fscrypt_policy *policy)union fscrypt_context ctx;int ret; - ci =fscrypt_get_inode_info (inode); + ci = inode->i_op->get_fscrypt (inode);if (ci) {/* key available, use the cached policy */ *policy = ci->ci_policy;@@ -725,7 +725,7 @@ const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir) err =fscrypt_require_key (dir);if (err)return ERR_PTR (err); -return &dir->i_crypt_info->ci_policy; +return &dir->i_op->get_fscrypt (dir)->ci_policy; }return fscrypt_get_dummy_policy (dir->i_sb);@@ -744,7 +744,7 @@ const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir)*/ int fscrypt_context_for_new_inode (void *ctx,struct inode *inode) { -struct fscrypt_inode_info *ci = inode->i_crypt_info; +struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);BUILD_BUG_ON (sizeof (union fscrypt_context ) !=FSCRYPT_SET_CONTEXT_MAX_SIZE );@@ -769,7 +769,7 @@ EXPORT_SYMBOL_GPL(fscrypt_context_for_new_inode);*/ int fscrypt_set_context (struct inode *inode,void *fs_data) { -struct fscrypt_inode_info *ci = inode->i_crypt_info; +struct fscrypt_inode_info *ci = inode->i_op->get_fscrypt (inode);union fscrypt_context ctx;int ctxsize;fs/ext4/ext4.h +9
-0@@ -1197,6 +1197,10 @@ struct ext4_inode_info {__u32 i_csum_seed;kprojid_t i_projid; + +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif };/* @@ -3904,6 +3908,11 @@ static inline bool ext4_inode_can_atomic_write(struct inode *inode)extern int ext4_block_write_begin (handle_t *handle,struct folio *folio,loff_t pos,unsigned len,get_block_t *get_block); +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *ext4_get_fscrypt (const struct inode *inode); +int ext4_set_fscrypt (struct fscrypt_inode_info *fscrypt_info,struct inode *inode); +#endif +#endif /* __KERNEL__ */ #define EFSBADCRC EBADMSG/* Bad CRC detected */ fs/ext4/file.c +4
-0@@ -989,5 +989,9 @@ const struct inode_operations ext4_file_inode_operations = { .fiemap = ext4_fiemap, .fileattr_get = ext4_fileattr_get, .fileattr_set = ext4_fileattr_set, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif };fs/ext4/namei.c +22
-0@@ -4203,6 +4203,20 @@ static int ext4_rename2(struct mnt_idmap *idmap,return ext4_rename (idmap, old_dir, old_dentry, new_dir, new_dentry, flags); } +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *ext4_get_fscrypt (const struct inode *inode) +{ +struct ext4_inode_info *ei =EXT4_I (inode); +return fscrypt_inode_info_get (&ei->i_fscrypt_info); +} + +int ext4_set_fscrypt (struct fscrypt_inode_info *fscrypt_info,struct inode *inode) +{ +struct ext4_inode_info *ei =EXT4_I (inode); +return fscrypt_inode_info_set (fscrypt_info, &ei->i_fscrypt_info); +} +#endif +/* * directories can handle most operations... */ @@ -4225,6 +4239,10 @@ const struct inode_operations ext4_dir_inode_operations = { .fiemap = ext4_fiemap, .fileattr_get = ext4_fileattr_get, .fileattr_set = ext4_fileattr_set, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif }; const struct inode_operations ext4_special_inode_operations = {@@ -4233,4 +4251,8 @@ const struct inode_operations ext4_special_inode_operations = { .listxattr = ext4_listxattr, .get_inode_acl = ext4_get_acl, .set_acl = ext4_set_acl, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif };fs/ext4/super.c +5
-1@@ -1412,6 +1412,9 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)INIT_WORK (&ei->i_rsv_conversion_work, ext4_end_io_rsv_work);ext4_fc_init_inode (&ei->vfs_inode);spin_lock_init (&ei->i_fc_lock); +#ifdef CONFIG_FS_ENCRYPTION + ei->i_fscrypt_info =NULL ; +#endif return &ei->vfs_inode; }@@ -1509,7 +1512,8 @@ void ext4_clear_inode(struct inode *inode)jbd2_free_inode (EXT4_I (inode)->jinode);EXT4_I (inode)->jinode =NULL ; } -fscrypt_put_encryption_info (inode); +put_crypt_info (EXT4_I (inode)->i_fscrypt_info); +EXT4_I (inode)->i_fscrypt_info =NULL ;fsverity_cleanup_inode (inode); }fs/ext4/symlink.c +12
-0@@ -119,6 +119,10 @@ const struct inode_operations ext4_encrypted_symlink_inode_operations = { .setattr = ext4_setattr, .getattr = ext4_encrypted_symlink_getattr, .listxattr = ext4_listxattr, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif }; const struct inode_operations ext4_symlink_inode_operations = {@@ -126,6 +130,10 @@ const struct inode_operations ext4_symlink_inode_operations = { .setattr = ext4_setattr, .getattr = ext4_getattr, .listxattr = ext4_listxattr, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif }; const struct inode_operations ext4_fast_symlink_inode_operations = {@@ -133,4 +141,8 @@ const struct inode_operations ext4_fast_symlink_inode_operations = { .setattr = ext4_setattr, .getattr = ext4_getattr, .listxattr = ext4_listxattr, +#ifdef CONFIG_FS_ENCRYPTION + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, +#endif };include/linux/fs.h +5
-4@@ -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 @@ -2257,6 +2253,11 @@ struct inode_operations { struct dentry *dentry, struct fileattr *fa);int (*fileattr_get)(struct dentry *dentry,struct fileattr *fa);struct offset_ctx *(*get_offset_ctx)(struct inode *inode); +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *(*get_fscrypt)(const struct inode *inode); +int (*set_fscrypt)(struct fscrypt_inode_info *fscrypt_info, +struct inode *inode); +#endif }____cacheline_aligned ;/* Did the driver provide valid mmap hook configuration? */ include/linux/fscrypt.h +31
-17@@ -195,18 +195,6 @@ struct fscrypt_operations {int fscrypt_d_revalidate (struct inode *dir,const struct qstr *name,struct dentry *dentry,unsigned int flags); -static inline struct fscrypt_inode_info * -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 -* a RELEASE barrier. We need to use smp_load_acquire() here to safely -* ACQUIRE the memory the other task published. -*/ -return smp_load_acquire (&inode->i_crypt_info); -} -/** * fscrypt_needs_contents_encryption() - check whether an inode needs * contents encryption @@ -385,7 +373,7 @@ int fscrypt_ioctl_get_key_status(struct file *filp, void __user *arg);/* keysetup.c */ int fscrypt_prepare_new_inode (struct inode *dir,struct inode *inode,bool *encrypt_ret); -void fscrypt_put_encryption_info (struct inode *inode); +void put_crypt_info (struct fscrypt_inode_info *ci);void fscrypt_free_inode (struct inode *inode);int fscrypt_drop_inode (struct inode *inode);@@ -446,10 +434,37 @@ static inline void fscrypt_set_ops(struct super_block *sb, { sb->s_cop = s_cop; } + +static inline int fscrypt_inode_info_set (struct fscrypt_inode_info *crypt_info, +struct fscrypt_inode_info **p) +{ +if (cmpxchg_release (p,NULL , crypt_info) !=NULL ) +return -EEXIST ; +return 0 ; +} + +static inline struct fscrypt_inode_info * +fscrypt_inode_info_get (struct fscrypt_inode_info **crypt_info) +{ +/* +* Pairs with the cmpxchg_release() in fscrypt_inode_info_set(). I.e., +* another task may publish crypt_info concurrently, executing a +* RELEASE barrier. We need to use smp_load_acquire() here to safely +* ACQUIRE the memory the other task published (could be a READ_ONCE() +* really). +*/ +return smp_load_acquire (crypt_info); +}#else /* !CONFIG_FS_ENCRYPTION */ +static inline int fscrypt_inode_info_set (struct fscrypt_inode_info *crypt_info, +struct fscrypt_inode_info **p) +{ +return 0 ; +} +static inline struct fscrypt_inode_info * -fscrypt_get_inode_info (const struct inode *inode) +fscrypt_inode_info_get (const struct fscrypt_inode_info **crypt_info) {return NULL ; }@@ -639,7 +654,7 @@ static inline int fscrypt_prepare_new_inode(struct inode *dir,return 0 ; } -static inline void fscrypt_put_encryption_info (struct inode *inode) +static inline void put_crypt_info (struct fscrypt_inode_info *ci) {return ; }@@ -930,7 +945,7 @@ static inline bool fscrypt_inode_uses_fs_layer_crypto(const struct inode *inode)*/ static inline bool fscrypt_has_encryption_key (const struct inode *inode) { -return fscrypt_get_inode_info (inode) !=NULL ; +return inode->i_op->get_fscrypt (inode) !=NULL ; }/** --- base-commit:
19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250715-work-inode-fscrypt-2b63b276e793
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerQuoted 41 lines · Jan Kara
Quoted 40 lines · Christian Brauner
struct inode is bloated as everyone is aware and we should try and shrink it as that's potentially a lot of memory savings. I've already freed up around 8 bytes but we can probably do better.
There's a bunch of stuff that got shoved into struct inode that I don't think deserves a spot in there. There are two members I'm currently particularly interested in:
(1) #ifdef
CONFIG_FS_ENCRYPTIONstruct fscrypt_inode_info *i_crypt_info; #endif ceph, ext4, f2fs, ubifs(2) #ifdef
CONFIG_FS_VERITYstruct fsverity_info *i_verity_info; #endif btrfs, ext4, f2fsSo we have 4 users for fscrypt and 3 users for fsverity with both features having been around for a decent amount of time.
For all other filesystems the 16 bytes are just wasted bloating inodes for every pseudo filesystem and most other regular filesystems.
We should be able to move both of these out of struct inode by adding inode operations and making it the filesystem's responsibility to accommodate the information in their respective inodes.
Unless there are severe performance penalties for the extra pointer dereferences getting our hands on 16 bytes is a good reason to at least consider doing this.
I've drafted one way of doing this using ext4 as my victim^wexample. I'd like to hear some early feedback whether this is something we would want to pursue.
Build failures very much expected!
Quoted 7 lines
Quoted 1 line
Not-Signed-off-by Christian Brauner <[email protected]>I like the concept. I went that way with quota info attached to the inode as well. Just for quota info I've put the .get_dquots hook into
super_operationsbecause in practice all inodes in a superblock have to have a common memory layout anyway. OTOHinode_operationsare one deference closer so maybe they are a better fit? Anyway, all I wanted to say is that
Imho, move it to inode operations. I think that's the better fit for quotas. It's easier to see what types of actual meaningful filesystem operations inodes actually support. I'm not to worried about having a lot of methods on i_op (yet). Thoughts?
Quoted 7 lines · Christian Brauner
Unless there are severe performance penalties for the extra pointer dereferences getting our hands on 16 bytes is a good reason to at least consider doing this.
I've drafted one way of doing this using ext4 as my victim^wexample. I'd like to hear some early feedback whether this is something we would want to pursue.
I like getting rid of the fields. But adding all these indirect calls is a bit nasty.
Given that all these fields should be in the file system specific inode that also embeddeds the vfs struct inode, what about just putting the relative offset into struct inode_operations.
e.g. something like
struct inode_operations {
...
ptrdiff_t i_crypto_offset;
}struct inode_operations foofs_iops {
...
.i_crypto_offset = offsetoff(struct foofs_inode), vfs_inode) -
offsetoff(struct foofs_inode, crypt_info);
}static inline struct fscrypt_inode_info CRYPT_I(struct inode *inode)
{
return ((void *)inode) - inode->i_op->i_cryto_offset;
}Christian Brauner
maintainerQuoted 30 lines · Christoph Hellwig
Quoted 7 lines · Christian Brauner
Unless there are severe performance penalties for the extra pointer dereferences getting our hands on 16 bytes is a good reason to at least consider doing this.
I've drafted one way of doing this using ext4 as my victim^wexample. I'd like to hear some early feedback whether this is something we would want to pursue.
I like getting rid of the fields. But adding all these indirect calls is a bit nasty.
Given that all these fields should be in the file system specific inode that also embeddeds the vfs struct inode, what about just putting the relative offset into struct
inode_operations.e.g. something like
struct inode_operations { ... ptrdiff_t i_crypto_offset; }struct inode_operations foofs_iops { ... .i_crypto_offset = offsetoff(struct foofs_inode), vfs_inode) - offsetoff(struct foofs_inode, crypt_info); }
Quoted 4 lines
static inline struct
fscrypt_inode_infoCRYPT_I(struct inode *inode){ return ((void *)inode) - inode->i_op->i_cryto_offset; }
Sheesh, ugly in a different way imho. I could live with it. I'll let @Jan be the tie-breaker.
I've started working on this so best tell me soon... :)
Quoted 36 lines · Christian Brauner
Quoted 30 lines · Christoph Hellwig
Quoted 7 lines · Christian Brauner
Unless there are severe performance penalties for the extra pointer dereferences getting our hands on 16 bytes is a good reason to at least consider doing this.
I've drafted one way of doing this using ext4 as my victim^wexample. I'd like to hear some early feedback whether this is something we would want to pursue.
I like getting rid of the fields. But adding all these indirect calls is a bit nasty.
Given that all these fields should be in the file system specific inode that also embeddeds the vfs struct inode, what about just putting the relative offset into struct
inode_operations.e.g. something like
struct inode_operations { ... ptrdiff_t i_crypto_offset; }struct inode_operations foofs_iops { ... .i_crypto_offset = offsetoff(struct foofs_inode), vfs_inode) - offsetoff(struct foofs_inode, crypt_info); }Quoted 4 lines
static inline struct
fscrypt_inode_infoCRYPT_I(struct inode *inode){ return ((void *)inode) - inode->i_op->i_cryto_offset; }
Quoted 4 lines
Sheesh, ugly in a different way imho. I could live with it. I'll let @Jan be the tie-breaker.
I've started working on this so best tell me soon... :)
I agree with HCH. Both of these methods are equally ugly, but we eliminate extra function call by just storing the offset.
It may also make things simpler for debugging with drgn and the like too. You can just do the pointer math with the info inside struct inode instead of having to track down an extra function call, etc.
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 40 lines · Jeff Layton
Quoted 39 lines · Christian Brauner
Quoted 30 lines · Christoph Hellwig
Quoted 7 lines · Christian Brauner
Unless there are severe performance penalties for the extra pointer dereferences getting our hands on 16 bytes is a good reason to at least consider doing this.
I've drafted one way of doing this using ext4 as my victim^wexample. I'd like to hear some early feedback whether this is something we would want to pursue.
I like getting rid of the fields. But adding all these indirect calls is a bit nasty.
Given that all these fields should be in the file system specific inode that also embeddeds the vfs struct inode, what about just putting the relative offset into struct
inode_operations.e.g. something like
struct inode_operations { ... ptrdiff_t i_crypto_offset; }struct inode_operations foofs_iops { ... .i_crypto_offset = offsetoff(struct foofs_inode), vfs_inode) - offsetoff(struct foofs_inode, crypt_info); }Quoted 4 lines
static inline struct
fscrypt_inode_infoCRYPT_I(struct inode *inode){ return ((void *)inode) - inode->i_op->i_cryto_offset; }Sheesh, ugly in a different way imho. I could live with it. I'll let @Jan be the tie-breaker.
Quoted 8 lines
Quoted 1 line
I've started working on this so best tell me soon... :)
I agree with HCH. Both of these methods are equally ugly, but we eliminate extra function call by just storing the offset.
It may also make things simpler for debugging with drgn and the like too. You can just do the pointer math with the info inside struct inode instead of having to track down an extra function call, etc.
struct inode {
...
};struct filemap_inode {
struct inode inode;
struct address_space i_mapping;
struct fscrypt_struct i_fscrypt;
struct fsverity_struct i_fsverity;
struct quota_struct i_quota;
};struct ext4_inode {
struct filemap_inode inode;
...
};saves any messing with i_ops and offsets.
Quoted 8 lines · Matthew Wilcox
struct filemap_inode {
struct inode inode;
struct address_space i_mapping;
struct fscrypt_struct i_fscrypt;
struct fsverity_struct i_fsverity;
struct quota_struct i_quota;
};Quoted 6 lines
struct ext4_inode { struct filemap_inode inode; ... };saves any messing with
i_opsand offsets.
I still wastest a lot of space for XFS which only needs inode and i_mapping of those. As would most ext4 file systems..
Christian Brauner
maintainerQuoted 14 lines · Christoph Hellwig
Quoted 13 lines · Matthew Wilcox
struct filemap_inode { struct inode inode; struct address_space i_mapping; struct fscrypt_struct i_fscrypt; struct fsverity_struct i_fsverity; struct quota_struct i_quota; };struct ext4_inode { struct filemap_inode inode; ... };
Quoted 4 lines
Quoted 1 line
saves any messing with
i_opsand offsets.I still wastest a lot of space for XFS which only needs inode and
i_mappingof those. As would most ext4 file systems..
We can do a hybrid approach:
fs/ext4/ext4.h +1 -3
@@ -1198,9 +1198,7 @@ struct ext4_inode_info {kprojid_t i_projid; -#ifdef CONFIG_FS_ENCRYPTION -struct fscrypt_inode_info *i_fscrypt_info; -#endif +struct vfs_inode_adjunct i_adjunct;/* Adjunct data for inode */ };/*
fs/ext4/file.c +12 -10
@@ -981,17 +981,19 @@ const struct file_operations ext4_file_operations = { };const struct inode_operations ext4_file_inode_operations = { - .setattr = ext4_setattr, - .getattr = ext4_file_getattr, - .listxattr = ext4_listxattr, - .get_inode_acl = ext4_get_acl, - .set_acl = ext4_set_acl, - .fiemap = ext4_fiemap, - .fileattr_get = ext4_fileattr_get, - .fileattr_set = ext4_fileattr_set, + .i_adjunct_offset = offsetof(struct ext4_inode_info , vfs_inode) - + offsetof(struct ext4_inode_info , i_adjunct), + .setattr = ext4_setattr, + .getattr = ext4_file_getattr, + .listxattr = ext4_listxattr, + .get_inode_acl = ext4_get_acl, + .set_acl = ext4_set_acl, + .fiemap = ext4_fiemap, + .fileattr_get = ext4_fileattr_get, + .fileattr_set = ext4_fileattr_set, #ifdef CONFIG_FS_ENCRYPTION - .get_fscrypt = ext4_get_fscrypt, - .set_fscrypt = ext4_set_fscrypt, + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, #endif };
include/linux/fs.h +7 -0
@@ -789,6 +789,12 @@ struct inode {void *i_private;/* fs or device private pointer */ } __randomize_layout; +struct vfs_inode_adjunct { +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif +}; +static inline void inode_set_cached_link (struct inode *inode,char *link,int linklen) {VFS_WARN_ON_INODE (strlen (link) != linklen, inode);
@@ -2217,6 +2223,7 @@ int wrap_directory_iterator(struct file *, struct dir_context *, {return wrap_directory_iterator (file, ctx, x); }struct inode_operations { +ptrdiff_t i_adjunct_offset;struct dentry * (*lookup) (struct inode *,struct dentry *,unsigned int );const char * (*get_link) (struct dentry *,struct inode *,struct delayed_call *);int (*permission) (struct mnt_idmap *,struct inode *,int );
include/linux/fscrypt.h +6 -0
@@ -195,6 +195,12 @@ struct fscrypt_operations {int fscrypt_d_revalidate (struct inode *dir,const struct qstr *name,struct dentry *dentry,unsigned int flags); +static inline struct fscrypt_inode_info *CRYPT_I (struct inode *inode) +{ +struct vfs_inode_adjunct *p = ((void *)inode) - inode->i_op->i_adjunct_offset; +return p->i_fscrypt_info; +} +static inline int vfs_fscrypt_inode_set (struct fscrypt_inode_info *crypt_info,struct fscrypt_inode_info **p) {
Jan Kara
reviewerQuoted 27 lines · Christian Brauner
Quoted 14 lines · Christoph Hellwig
Quoted 13 lines · Matthew Wilcox
struct filemap_inode { struct inode inode; struct address_space i_mapping; struct fscrypt_struct i_fscrypt; struct fsverity_struct i_fsverity; struct quota_struct i_quota; };struct ext4_inode { struct filemap_inode inode; ... };Quoted 4 lines
Quoted 1 line
saves any messing with
i_opsand offsets.I still wastest a lot of space for XFS which only needs inode and
i_mappingof those. As would most ext4 file systems..We can do a hybrid approach:
fs/ext4/ext4.h +0
-0
fs/ext4/ext4.h struct ext4_inode_info { · line 1202
Quoted 8 lines
fs/ext4/ext4.h +1
-3@@ -1198,9 +1198,7 @@ struct ext4_inode_info {kprojid_t i_projid; -#ifdef CONFIG_FS_ENCRYPTION -struct fscrypt_inode_info *i_fscrypt_info; -#endif +struct vfs_inode_adjunct i_adjunct;/* Adjunct data for inode */ };
Well, but if we moved also fsverity & quota & what not into vfs_inode_adjunct the benefit of such structure would be diminishing? Or am I misunderstanding the proposal? I think that the new method should strive for each filesystem inode to store only the info it needs and not waste space for things it isn't interested in.
Honza
Quoted 76 lines
fs/ext4/file.c +12
-10@@ -981,17 +981,19 @@ const struct file_operations ext4_file_operations = { };const struct inode_operations ext4_file_inode_operations = { - .setattr = ext4_setattr, - .getattr = ext4_file_getattr, - .listxattr = ext4_listxattr, - .get_inode_acl = ext4_get_acl, - .set_acl = ext4_set_acl, - .fiemap = ext4_fiemap, - .fileattr_get = ext4_fileattr_get, - .fileattr_set = ext4_fileattr_set, + .i_adjunct_offset = offsetof(struct ext4_inode_info , vfs_inode) - + offsetof(struct ext4_inode_info , i_adjunct), + .setattr = ext4_setattr, + .getattr = ext4_file_getattr, + .listxattr = ext4_listxattr, + .get_inode_acl = ext4_get_acl, + .set_acl = ext4_set_acl, + .fiemap = ext4_fiemap, + .fileattr_get = ext4_fileattr_get, + .fileattr_set = ext4_fileattr_set, #ifdef CONFIG_FS_ENCRYPTION - .get_fscrypt = ext4_get_fscrypt, - .set_fscrypt = ext4_set_fscrypt, + .get_fscrypt = ext4_get_fscrypt, + .set_fscrypt = ext4_set_fscrypt, #endif };include/linux/fs.h +7
-0@@ -789,6 +789,12 @@ struct inode {void *i_private;/* fs or device private pointer */ } __randomize_layout; +struct vfs_inode_adjunct { +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif +}; +static inline void inode_set_cached_link (struct inode *inode,char *link,int linklen) {VFS_WARN_ON_INODE (strlen (link) != linklen, inode);@@ -2217,6 +2223,7 @@ int wrap_directory_iterator(struct file *, struct dir_context *, {return wrap_directory_iterator (file, ctx, x); }struct inode_operations { +ptrdiff_t i_adjunct_offset;struct dentry * (*lookup) (struct inode *,struct dentry *,unsigned int );const char * (*get_link) (struct dentry *,struct inode *,struct delayed_call *);int (*permission) (struct mnt_idmap *,struct inode *,int );include/linux/fscrypt.h +6
-0@@ -195,6 +195,12 @@ struct fscrypt_operations {int fscrypt_d_revalidate (struct inode *dir,const struct qstr *name,struct dentry *dentry,unsigned int flags); +static inline struct fscrypt_inode_info *CRYPT_I (struct inode *inode) +{ +struct vfs_inode_adjunct *p = ((void *)inode) - inode->i_op->i_adjunct_offset; +return p->i_fscrypt_info; +} +static inline int vfs_fscrypt_inode_set (struct fscrypt_inode_info *crypt_info,struct fscrypt_inode_info **p) {
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerQuoted 31 lines · Jan Kara
Quoted 30 lines · Christian Brauner
Quoted 14 lines · Christoph Hellwig
Quoted 13 lines · Matthew Wilcox
struct filemap_inode { struct inode inode; struct address_space i_mapping; struct fscrypt_struct i_fscrypt; struct fsverity_struct i_fsverity; struct quota_struct i_quota; };struct ext4_inode { struct filemap_inode inode; ... };Quoted 4 lines
Quoted 1 line
saves any messing with
i_opsand offsets.I still wastest a lot of space for XFS which only needs inode and
i_mappingof those. As would most ext4 file systems..We can do a hybrid approach:
fs/ext4/ext4.h +0
-0@@ -1198,9 +1198,7 @@ struct ext4_inode_info {kprojid_t i_projid;
Quoted 11 lines
fs/ext4/ext4.h struct ext4_inode_info { · line 1202
Quoted 5 lines
fs/ext4/ext4.h +1
-3-#ifdef CONFIG_FS_ENCRYPTION -struct fscrypt_inode_info *i_fscrypt_info; -#endif +struct vfs_inode_adjunct i_adjunct;/* Adjunct data for inode */ };Well, but if we moved also fsverity & quota & what not into
vfs_inode_adjunctthe benefit of such structure would be diminishing? Or am I misunderstanding the proposal? I think that the new method should strive for each filesystem inode to store only the info it needs and not waste space for things it isn't interested in.
The benefit will still be there for any filesystem that doesn't care about any of it which is most of them. One could also just split this up into topics: fsverity & fscrypt, quota likely separately, and then other stuff. But we can also just do that later and start with splitting it individually.
Quoted 5 lines · Christian Brauner
The benefit will still be there for any filesystem that doesn't care about any of it which is most of them. One could also just split this up into topics: fsverity & fscrypt, quota likely separately, and then other stuff. But we can also just do that later and start with splitting it individually.
Having these arbitrary groups feels worse than just embedded structures with the offset in the inode ops. Because with more such semi-generic fields there will be combinatoric explosion.
In general the even better option would of course be to either eliminate the fields (which I think is doable for quotas), or restructure their users to be proper library code so the file systems directly pass the expected structures. But both of these are a lot more work and I'm not sure we'll get them done for all these.
Jan Kara
reviewerQuoted 31 lines · Christian Brauner
Quoted 30 lines · Christoph Hellwig
Quoted 7 lines · Christian Brauner
Unless there are severe performance penalties for the extra pointer dereferences getting our hands on 16 bytes is a good reason to at least consider doing this.
I've drafted one way of doing this using ext4 as my victim^wexample. I'd like to hear some early feedback whether this is something we would want to pursue.
I like getting rid of the fields. But adding all these indirect calls is a bit nasty.
Given that all these fields should be in the file system specific inode that also embeddeds the vfs struct inode, what about just putting the relative offset into struct
inode_operations.e.g. something like
struct inode_operations { ... ptrdiff_t i_crypto_offset; }struct inode_operations foofs_iops { ... .i_crypto_offset = offsetoff(struct foofs_inode), vfs_inode) - offsetoff(struct foofs_inode, crypt_info); }
Quoted 7 lines
Quoted 4 lines
static inline struct
fscrypt_inode_infoCRYPT_I(struct inode *inode){ return ((void *)inode) - inode->i_op->i_cryto_offset; }Sheesh, ugly in a different way imho. I could live with it. I'll let @Jan be the tie-breaker.
Heh, I feel biased because about 10 years ago I proposed something like this and it got shot down as being too ugly to be worth the memory. But times are changing :). I think hooks to return pointer are cleaner but this is clearly going to be faster. I think since this would be fully encapsulated in the few inline helpers the offset solution is (still) OK.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerQuoted 37 lines · Jan Kara
Quoted 36 lines · Christian Brauner
Quoted 34 lines · Christoph Hellwig
Quoted 7 lines · Christian Brauner
Unless there are severe performance penalties for the extra pointer dereferences getting our hands on 16 bytes is a good reason to at least consider doing this.
I've drafted one way of doing this using ext4 as my victim^wexample. I'd like to hear some early feedback whether this is something we would want to pursue.
I like getting rid of the fields. But adding all these indirect calls is a bit nasty.
Given that all these fields should be in the file system specific inode that also embeddeds the vfs struct inode, what about just putting the relative offset into struct
inode_operations.e.g. something like
struct inode_operations { ... ptrdiff_t i_crypto_offset; }struct inode_operations foofs_iops { ... .i_crypto_offset = offsetoff(struct foofs_inode), vfs_inode) - offsetoff(struct foofs_inode, crypt_info); }static inline struct
fscrypt_inode_infoCRYPT_I(struct inode *inode){ return ((void *)inode) - inode->i_op->i_cryto_offset; }
Quoted 6 lines
Quoted 2 lines
Sheesh, ugly in a different way imho. I could live with it. I'll let @Jan be the tie-breaker.
Heh, I feel biased because about 10 years ago I proposed something like this and it got shot down as being too ugly to be worth the memory. But times are changing :). I think hooks to return pointer are cleaner but this
We can't just keep accumulating more and more stuff in our core structures. The bpf people are breathing down our neck to put more things in struct inode and I'm sure the next thingamabob is already in the works and we need a way to push such stuff out of core struct inode.
It is simply not sustainable so I'd rather bite the bullet and have it look ugly rather than waste more and more memory or argue that we can't do something because it bloats a core structure for the sake of code purity. And it's not that bad tbh. We have uglier hacks (stealing pointer bits for struct fd comes to mind) for the sake of performance. I don't see why significant memory savings for most other kernel consumers of this struct should not be worth it.
Quoted 2 lines
is clearly going to be faster. I think since this would be fully encapsulated in the few inline helpers the offset solution is (still) OK.
Quoted 4 lines · Christian Brauner
We can't just keep accumulating more and more stuff in our core structures. The bpf people are breathing down our neck to put more things in struct inode and I'm sure the next thingamabob is already in the works and we need a way to push such stuff out of core struct inode.
Agreed. And as mentioned I'like to think even further and avoid having these optional bits in the fs inode unconditionally if there isn't a good reason for that. I mentioned quotas before, but an even more extreme case is fsverity. If I understand the fsverity use case correctly it is usually used for a very small number of files in the system only, and you'd usually do bulk reads from them. So instead of bloating the inode, be that the generic one or that of the file systems that use it, why not have a global rhastable index by the inode address to look it up? Compared to the actual hash generation and verification a lockless hashlookup is complete noise, but we'll save a lot of memory.
Christian Brauner
maintainerQuoted 6 lines · Christoph Hellwig
Quoted 4 lines · Christian Brauner
We can't just keep accumulating more and more stuff in our core structures. The bpf people are breathing down our neck to put more things in struct inode and I'm sure the next thingamabob is already in the works and we need a way to push such stuff out of core struct inode.
Quoted 11 lines
Agreed. And as mentioned I'like to think even further and avoid having these optional bits in the fs inode unconditionally if there isn't a good reason for that. I mentioned quotas before, but an even more extreme case is fsverity. If I understand the fsverity use case correctly it is usually used for a very small number of files in the system only, and you'd usually do bulk reads from them. So instead of bloating the inode, be that the generic one or that of the file systems that use it, why not have a global rhastable index by the inode address to look it up? Compared to the actual hash generation and verification a lockless hashlookup is complete noise, but we'll save a lot of memory.
My plan is to just push fsverity and fscrypt out via offsets. If someone wants to wade through the pain of then adding an rhashtable and getting rid of the offset, then fine by me. But I don't want the removal of verity and crypt to be gated on that. And I didn't understand you as wanting that either, I hope?
For anything new pushing for alternative lookup structures is fine.
Eric Biggers
maintainerQuoted 50 lines · Christian Brauner
struct inode is bloated as everyone is aware and we should try and shrink it as that's potentially a lot of memory savings. I've already freed up around 8 bytes but we can probably do better.
There's a bunch of stuff that got shoved into struct inode that I don't think deserves a spot in there. There are two members I'm currently particularly interested in:
(1) #ifdef
CONFIG_FS_ENCRYPTIONstruct fscrypt_inode_info *i_crypt_info; #endif ceph, ext4, f2fs, ubifs(2) #ifdef
CONFIG_FS_VERITYstruct fsverity_info *i_verity_info; #endif btrfs, ext4, f2fsSo we have 4 users for fscrypt and 3 users for fsverity with both features having been around for a decent amount of time.
For all other filesystems the 16 bytes are just wasted bloating inodes for every pseudo filesystem and most other regular filesystems.
We should be able to move both of these out of struct inode by adding inode operations and making it the filesystem's responsibility to accommodate the information in their respective inodes.
Unless there are severe performance penalties for the extra pointer dereferences getting our hands on 16 bytes is a good reason to at least consider doing this.
I've drafted one way of doing this using ext4 as my victim^wexample. I'd like to hear some early feedback whether this is something we would want to pursue.
Build failures very much expected!
Not-Signed-off-by Christian Brauner <[email protected]>--- fs/crypto/bio.c | 2 +- fs/crypto/crypto.c | 8 ++++---- fs/crypto/fname.c | 8 ++++---- fs/crypto/fscrypt_private.h | 3 +-- fs/crypto/hooks.c | 2 +- fs/crypto/inline_crypt.c | 10 +++++----- fs/crypto/keysetup.c | 21 ++++---------------- fs/crypto/policy.c | 8 ++++----
Quoted 8 lines
fs/ext4/ext4.h | 9 +++++++++ fs/ext4/file.c | 4 ++++ fs/ext4/namei.c | 22 +++++++++++++++++++++ fs/ext4/super.c | 6 +++++- fs/ext4/symlink.c | 12 ++++++++++++ include/linux/fs.h | 9 +++++---- include/linux/fscrypt.h | 47 ++++++++++++++++++++++++++++++--------------- 15 files changed, 112 insertions(+), 59 deletions(-)
This should have been Cc'ed to [email protected] and [email protected]. I almost missed this.
If done properly, fixing this would be great. I've tried to minimize the overhead of CONFIG_FS_ENCRYPTION and CONFIG_FS_VERITY when those features are not actually being used at runtime. The struct inode fields are the main case where we still don't do a good job at that.
However, as was mentioned elsewhere in the thread, unfortunately indirect calls are really expensive and would not be a great solution. I've been cleaning up indirect calls in other parts of the kernel, such as the crypto and crc subsystems, and getting some significant performance improvements from that. It would be unfortunate to add a large number of indirect calls for basically all operations done on encrypted and/or verity files.
Doing the dereferences to get an offset stored in the inode_operations (or fscrypt_operations or fsverity_operations, or maybe even super_block which would just need one dereference rather than two?), and then doing the pointer arithmetic, would be faster than an indirect call. It won't be all that great either, but it would do.
There are some cases where we could instead modify the functions in fs/crypto/ to have the filesystem pass in a pointer to the fscrypt_inode_info. But that won't work in all cases.
Just throwing another idea out there: there could also be an optimization for the case where only a single *filesystem type* is using fscrypt (or fsverity) at runtime, which is the usual case. This would look something like:
if (static_branch_likely(&fscrypt_single_fs_type))
ci = *(struct fscrypt_inode_info **)((void *)inode + fscrypt_crypt_info_offset);
else
ci = // get it in slower way. Maybe even just the indirect call.
In theory, the first case could even use a "runtime_const" for fscrypt_crypt_info_offset. In that case, the only difference between the fast code path (where fscrypt_single_fs_type==true) and the current inode->i_crypt_info would be the nop associated with the static branch.
But, that might be too fancy. For now we probably should go with a single code path that loads the offset from a per-filesystem-instance struct, like inode_operations or super_block.
- Eric
Eric Biggers
maintainerQuoted 5 lines · Eric Biggers
Doing the dereferences to get an offset stored in the
inode_operations(orfscrypt_operationsorfsverity_operations, or maybe evensuper_blockwhich would just need one dereference rather than two?), and then doing the pointer arithmetic, would be faster than an indirect call. It won't be all that great either, but it would do.
Correction: due to inode::i_op, it takes just one dereference to get from inode to inode_operations (as Jan pointed out elsewhere in the thread). So that would probably be best.
- Eric
Quoted 4 lines · Eric Biggers
If done properly, fixing this would be great. I've tried to minimize the overhead of
CONFIG_FS_ENCRYPTIONandCONFIG_FS_VERITYwhen those features are not actually being used at runtime. The struct inode fields are the main case where we still don't do a good job at that.
Can you take a look if my idea of not allocating the verity data for all inodes but just those where verity is enabled and then looking that up using a rhashtable makes any sense?
Eric Biggers
maintainerQuoted 10 lines · Christoph Hellwig
Quoted 4 lines · Eric Biggers
If done properly, fixing this would be great. I've tried to minimize the overhead of
CONFIG_FS_ENCRYPTIONandCONFIG_FS_VERITYwhen those features are not actually being used at runtime. The struct inode fields are the main case where we still don't do a good job at that.Can you take a look if my idea of not allocating the verity data for all inodes but just those where verity is enabled and then looking that up using a rhashtable makes any sense?
I wrote a prototype that puts the fsverity_info structs in an rhashtable, keyed by the ownening 'struct inode *'. It passes the 'verity' group of xfstests on ext4. However, I'm working on checking how bad the performance and code size overhead is, and whether my implementation is actually correct in all cases. Unfortunately, the rhashtable API and implementation is kind of a mess, and it seems it's often not as efficient as it should be.
I suppose an XArray would be the main alternative. But XArray needs 'unsigned long' indices, and it doesn't work efficiently when they are pointers. (And i_ino won't do, since i_ino isn't unique.)
- Eric
Quoted 7 lines · Eric Biggers
I wrote a prototype that puts the
fsverity_infostructs in an rhashtable, keyed by the ownening 'struct inode *'. It passes the 'verity' group of xfstests on ext4. However, I'm working on checking how bad the performance and code size overhead is, and whether my implementation is actually correct in all cases. Unfortunately, the rhashtable API and implementation is kind of a mess, and it seems it's often not as efficient as it should be.
While not exactly the prettiest API I think it isn't too bad if you stick to the simple parts. Having spent some time with it I'd be happy to look over your code.
Quoted 3 lines
I suppose an XArray would be the main alternative. But XArray needs 'unsigned long' indices, and it doesn't work efficiently when they are pointers. (And
i_inowon't do, sincei_inoisn't unique.)
I'm not sure an xarray is a good fit, as the xarray works best when the indices are clustered, which they probably won't be here. But the unsigned long should not be a problem, just hash the inode pointer instead of i_ino.
Jan Kara
reviewerQuoted 20 lines · Eric Biggers
Quoted 10 lines · Christoph Hellwig
Quoted 4 lines · Eric Biggers
If done properly, fixing this would be great. I've tried to minimize the overhead of
CONFIG_FS_ENCRYPTIONandCONFIG_FS_VERITYwhen those features are not actually being used at runtime. The struct inode fields are the main case where we still don't do a good job at that.Can you take a look if my idea of not allocating the verity data for all inodes but just those where verity is enabled and then looking that up using a rhashtable makes any sense?
I wrote a prototype that puts the
fsverity_infostructs in an rhashtable, keyed by the ownening 'struct inode *'. It passes the 'verity' group of xfstests on ext4. However, I'm working on checking how bad the performance and code size overhead is, and whether my implementation is actually correct in all cases. Unfortunately, the rhashtable API and implementation is kind of a mess, and it seems it's often not as efficient as it should be.
Quoted 3 lines
I suppose an XArray would be the main alternative. But XArray needs 'unsigned long' indices, and it doesn't work efficiently when they are pointers. (And
i_inowon't do, sincei_inoisn't unique.)
As Christoph wrote I don't think XArray is a good alternative. The memory overhead is big for sparsely populated key space and that also increases the lookup overhead which is O(log N) to start with. Rhashtable should have O(1) lookup which is what we are most interested in. So if xarray is faster than rhashtable, rhashtable is doing something seriously wrong.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerv2 cover Move fscrypt and fsverity out of struct inode
Hey,
This is a POC. We're still discussing alternatives and I want to provide some useful data on what I learned about using offsets to drop fscrypt and fsverity from struct inode.
As discussed, this moves the fscrypt and fsverity pointers out of struct inode shrinking it by 16 bytes. The pointers move into the individual filesystems that actually do make use of them.
In order to find the fscrypt and fsverity data pointers offsets from the embedded struct inode in the filesystem's private inode data are stored in struct inode_operations. This means we get fast access to the data pointers without having to rely on indirect calls.
Bugs & Issues
=============
* For fscrypt specifically the biggest issue is fscrypt_prepare_new_inode() is called in filesystem's inode allocation functions before inode->i_op is set. That means the offset isn't available at the time when we would need it. To fix this we can set dummy encrypted inode operations for the respective filesystem with an initialized offset.
* For both fscrypt & fsverity the biggest issue is that every codepath that currently calls make_bad_inode() after having initialized fscrypt or fsverity data will override inode->i_op with bad_inode_ops. At which point we're back to the previous problem: The offset isn't available anymore. So when inode->i_sb->s_op->evict_inode() is called fscrypt_put_encryption_info() doesn't have the offset available anymore and would corrupt the hell out of everything and also leak memory.
Obviously we could use a flag to detect a bad inodes instead of i_op and let the filesystem assign it's own bad inode operations including the correct offset. Is it worth it?
The other way I see we can fix this if we require fixed offsets in the filesystems inode so fscrypt and fsverity always now what offset to calculate. We could use two consecutive pointers at the beginning of the filesystem's inode. Does that always work and is it worth it?
Thanks!
Christian
Test results:
+ sudo ./check -g encrypt,verity
FSTYP -- ext4 PLATFORM -- Linux/x86_64 localhost 6.16.0-rc1-g15c8eb9cdbd3 #267 SMP PREEMPT_DYNAMIC Fri Jun 5 15:58:00 CEST 2015 MKFS_OPTIONS -- -F /dev/nvme3n1p6
MOUNT_OPTIONS -- -o acl,user_xattr /dev/nvme3n1p6 /mnt/scratch
ext4/024 3s ... 3s
generic/395 4s ... 4s generic/396 3s ... 3s generic/397 4s ... 3s generic/398 4s ... 4s
generic/399 39s ... 35s
generic/419 3s ... 4s
generic/421 4s ... 4s
generic/429 14s ... 14s
generic/435 23s ... 22s
generic/440 3s ... 4s
generic/548 10s ... 9s
generic/549 9s ... 9s
generic/550 [not run] encryption policy '-c 9 -n 9 -f 0' is unusable; probably missing kernel crypto API support
generic/572 6s generic/573 4s generic/574 28s generic/575 9s
generic/576 5s ... 4s
generic/577 4s
generic/579 24s
generic/580 4s ... 4s
generic/581 10s ... 11s
generic/582 10s ... 9s
generic/583 9s ... 9s
generic/584 [not run] encryption policy '-c 9 -n 9 -v 2 -f 0' is unusable; probably missing kernel crypto API support
generic/592 10s ... 10s
generic/593 4s ... 4s generic/595 7s ... 7s generic/602 9s ... 10s generic/613 20s ... 20s generic/621 9s ... 9s generic/624 3s generic/625 3s generic/692 5s
generic/693 [not run] encryption policy '-c 1 -n 10 -v 2 -f 0' is unusable; probably missing kernel crypto API support
generic/739 17s ... 18s
Ran: ext4/024 generic/395 generic/396 generic/397 generic/398 generic/399 generic/419 generic/421 generic/429 generic/435 generic/440 generic/548 generic/549 generic/550 generic/572 generic/573 generic/574 generic/575 generic/576 generic/577 generic/579 generic/580 generic/581 generic/582 generic/583 generic/584 generic/592 generic/593 generic/595 generic/602 generic/613 generic/621 generic/624 generic/625 generic/692 generic/693 generic/739 Not run: generic/550 generic/584 generic/693
Passed all 37 tests
---
Changes in v2:
- First full implementation.
- Link to v1: https://lore.kernel.org/[email protected]
---
Christian Brauner (13):
fs: add fscrypt offset
fs/crypto: use accessors
ext4: move fscrypt to filesystem inode
ubifs: move fscrypt to filesystem inode
f2fs: move fscrypt to filesystem inode
ceph: move fscrypt to filesystem inode
fs: drop i_crypt_info from struct inode
fs: add fsverity offset
fs/verity: use accessors
btrfs: move fsverity to filesystem inode
ext4: move fsverity to filesystem inode
f2fs: move fsverity to filesystem inode
fs: drop i_verity_info from struct inode
fs/btrfs/btrfs_inode.h | 3 +++ fs/btrfs/inode.c | 20 ++++++++++++++++- fs/ceph/dir.c | 8 +++++++ fs/ceph/inode.c | 21 ++++++++++++++++++ fs/crypto/bio.c | 2 +- fs/crypto/crypto.c | 8 +++---- fs/crypto/fname.c | 8 +++---- fs/crypto/fscrypt_private.h | 2 +- fs/crypto/hooks.c | 2 +- fs/crypto/inline_crypt.c | 10 ++++----- fs/crypto/keysetup.c | 27 +++++++++++++---------- fs/crypto/policy.c | 6 ++--- fs/ext4/ext4.h | 9 ++++++++ fs/ext4/file.c | 8 +++++++ fs/ext4/ialloc.c | 2 ++ fs/ext4/inode.c | 1 + fs/ext4/mballoc.c | 3 +++ fs/ext4/namei.c | 23 ++++++++++++++++++++ fs/ext4/super.c | 6 +++++ fs/ext4/symlink.c | 24 ++++++++++++++++++++ fs/f2fs/f2fs.h | 7 ++++++ fs/f2fs/file.c | 8 +++++++ fs/f2fs/inode.c | 1 + fs/f2fs/namei.c | 41 ++++++++++++++++++++++++++++++++++ fs/f2fs/super.c | 6 +++++ fs/ubifs/dir.c | 52 ++++++++++++++++++++++++-------------------- fs/ubifs/file.c | 8 +++++++ fs/ubifs/super.c | 8 +++++++ fs/ubifs/ubifs.h | 3 +++ fs/verity/enable.c | 2 +- fs/verity/fsverity_private.h | 2 +- fs/verity/open.c | 18 +++++++++------ fs/verity/verify.c | 2 +- include/linux/fs.h | 10 ++------- include/linux/fscrypt.h | 31 ++++++++++++++++++++++++-- include/linux/fsverity.h | 21 ++++++++++++------ include/linux/netfs.h | 6 +++++ 37 files changed, 337 insertions(+), 82 deletions(-)
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250715-work-inode-fscrypt-2b63b276e793
Christian Brauner
maintainerRFC PATCH v2 1/13 fs: add fscrypt offset
Store the offset of the fscrypt data pointer from struct inode in struct inode_operations. Both are embedded in the filesystem's private inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- include/linux/fs.h | 1 + 1 file changed, 1 insertion(+)
include/linux/fs.h +1 -0
@@ -2217,6 +2217,7 @@ int wrap_directory_iterator(struct file *, struct dir_context *, {return wrap_directory_iterator (file, ctx, x); }struct inode_operations { +ptrdiff_t i_fscrypt;struct dentry * (*lookup) (struct inode *,struct dentry *,unsigned int );const char * (*get_link) (struct dentry *,struct inode *,struct delayed_call *);int (*permission) (struct mnt_idmap *,struct inode *,int );
Signature · 1 line
2.47.2
Christian Brauner
maintainerRFC PATCH v2 2/13 fs/crypto: use accessors
In reply to Christian BraunerUse accessor to get and set the fscrypt info from the filesystem. They can be removed once all filesystems have been converted to make room for fscrypt info in their own inodes.
--- fs/crypto/bio.c | 2 +- fs/crypto/crypto.c | 8 ++++---- fs/crypto/fname.c | 8 ++++---- fs/crypto/hooks.c | 2 +- fs/crypto/inline_crypt.c | 10 +++++----- fs/crypto/keysetup.c | 12 +++++++++--- fs/crypto/policy.c | 6 +++--- include/linux/fscrypt.h | 36 ++++++++++++++++++++++++++++++++++++ 8 files changed, 63 insertions(+), 21 deletions(-)
fs/crypto/bio.c +1 -1
@@ -111,7 +111,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,int fscrypt_zeroout_range (const struct inode *inode,pgoff_t lblk,sector_t pblk,unsigned int len) { -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits;const unsigned int du_per_page_bits =PAGE_SHIFT - du_bits;
fs/crypto/crypto.c +4 -4
@@ -181,7 +181,7 @@ struct page *fscrypt_encrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs, gfp_t gfp_flags) { const struct inode *inode = folio->mapping->host; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits;struct page *ciphertext_page;
@@ -241,7 +241,7 @@ int fscrypt_encrypt_block_inplace(const struct inode *inode, struct page *page, {if (WARN_ON_ONCE (inode->i_sb->s_cop->supports_subblock_data_units))return -EOPNOTSUPP ; -return fscrypt_crypt_data_unit (inode->i_crypt_info,FS_ENCRYPT , +return fscrypt_crypt_data_unit (fscrypt_get_inode_info_raw (inode),FS_ENCRYPT , lblk_num, page, page, len, offs, gfp_flags); }
@@ -265,7 +265,7 @@ int fscrypt_decrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs) {const struct inode *inode = folio->mapping->host; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits; u64 index = ((u64)folio->index << (PAGE_SHIFT - du_bits)) +
@@ -316,7 +316,7 @@ int fscrypt_decrypt_block_inplace(const struct inode *inode, struct page *page, {if (WARN_ON_ONCE (inode->i_sb->s_cop->supports_subblock_data_units))return -EOPNOTSUPP ; -return fscrypt_crypt_data_unit (inode->i_crypt_info,FS_DECRYPT , +return fscrypt_crypt_data_unit (fscrypt_get_inode_info_raw (inode),FS_DECRYPT , lblk_num, page, page, len, offs,GFP_NOFS ); }
fs/crypto/fname.c +4 -4
@@ -94,7 +94,7 @@ int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname, {struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait); -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;struct scatterlist sg;
@@ -151,7 +151,7 @@ static int fname_decrypt(const struct inode *inode,struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait);struct scatterlist src_sg, dst_sg; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;int res;
@@ -293,7 +293,7 @@ bool __fscrypt_fname_encrypted_size(const union fscrypt_policy *policy,bool fscrypt_fname_encrypted_size (const struct inode *inode,u32 orig_len,u32 max_len,u32 *encrypted_len_ret) { -return __fscrypt_fname_encrypted_size (&inode->i_crypt_info->ci_policy, +return __fscrypt_fname_encrypted_size (&fscrypt_get_inode_info_raw (inode)->ci_policy, orig_len, max_len, encrypted_len_ret); }
@@ -562,7 +562,7 @@ EXPORT_SYMBOL_GPL(fscrypt_match_name);*/ u64 fscrypt_fname_siphash (const struct inode *dir,const struct qstr *name) { -const struct fscrypt_inode_info *ci = dir->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (dir);WARN_ON_ONCE (!ci->ci_dirhash_key_initialized);
fs/crypto/hooks.c +1 -1
@@ -197,7 +197,7 @@ int fscrypt_prepare_setflags(struct inode *inode, err =fscrypt_require_key (inode);if (err)return err; - ci = inode->i_crypt_info; + ci =fscrypt_get_inode_info_raw (inode);if (ci->ci_policy.version !=FSCRYPT_POLICY_V2 )return -EINVAL ; mk = ci->ci_master_key;
fs/crypto/inline_crypt.c +5 -5
@@ -262,7 +262,7 @@ int fscrypt_derive_sw_secret(struct super_block *sb,bool __fscrypt_inode_uses_inline_crypto (const struct inode *inode) { -return inode->i_crypt_info->ci_inlinecrypt; +return fscrypt_get_inode_info_raw (inode)->ci_inlinecrypt; }EXPORT_SYMBOL_GPL (__fscrypt_inode_uses_inline_crypto);
@@ -306,7 +306,7 @@ void fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,if (!fscrypt_inode_uses_inline_crypto (inode))return ; - ci = inode->i_crypt_info; + ci =fscrypt_get_inode_info_raw (inode);fscrypt_generate_dun (ci, first_lblk, dun);bio_crypt_set_ctx (bio, ci->ci_enc_key.blk_key, dun, gfp_mask);
@@ -396,10 +396,10 @@ bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,* uses the same pointer. I.e., there's currently no need to support * merging requests where the keys are the same but the pointers differ. */ -if (bc->bc_key != inode->i_crypt_info->ci_enc_key.blk_key) +if (bc->bc_key !=fscrypt_get_inode_info_raw (inode)->ci_enc_key.blk_key)return false; -fscrypt_generate_dun (inode->i_crypt_info, next_lblk, next_dun); +fscrypt_generate_dun (fscrypt_get_inode_info_raw (inode), next_lblk, next_dun);return bio_crypt_dun_is_contiguous (bc, bio->bi_iter.bi_size, next_dun); }EXPORT_SYMBOL_GPL (fscrypt_mergeable_bio);
@@ -501,7 +501,7 @@ u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk, u64 nr_blocks)if (nr_blocks <=1 )return nr_blocks; - ci = inode->i_crypt_info; + ci =fscrypt_get_inode_info_raw (inode);if (!(fscrypt_policy_flags (&ci->ci_policy) &FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32 ))return nr_blocks;
fs/crypto/keysetup.c +9 -3
@@ -644,7 +644,7 @@ fscrypt_setup_encryption_info(struct inode *inode,* fscrypt_get_inode_info(). I.e., here we publish ->i_crypt_info with * a RELEASE barrier so that other tasks can ACQUIRE it. */ -if (cmpxchg_release (&inode->i_crypt_info,NULL , crypt_info) ==NULL ) { +if (fscrypt_set_inode_info (inode, crypt_info)) {/* * We won the race and set ->i_crypt_info to our crypt_info. * Now link it into the master key's inode list.
@@ -797,8 +797,14 @@ EXPORT_SYMBOL_GPL(fscrypt_prepare_new_inode);*/ void fscrypt_put_encryption_info (struct inode *inode) { -put_crypt_info (inode->i_crypt_info); - inode->i_crypt_info =NULL ; +struct fscrypt_inode_info **crypt_info; + +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 ; }EXPORT_SYMBOL (fscrypt_put_encryption_info);
fs/crypto/policy.c +3 -3
@@ -725,7 +725,7 @@ const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir) err =fscrypt_require_key (dir);if (err)return ERR_PTR (err); -return &dir->i_crypt_info->ci_policy; +return &fscrypt_get_inode_info_raw (dir)->ci_policy; }return fscrypt_get_dummy_policy (dir->i_sb);
@@ -744,7 +744,7 @@ const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir)*/ int fscrypt_context_for_new_inode (void *ctx,struct inode *inode) { -struct fscrypt_inode_info *ci = inode->i_crypt_info; +struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);BUILD_BUG_ON (sizeof (union fscrypt_context ) !=FSCRYPT_SET_CONTEXT_MAX_SIZE );
@@ -769,7 +769,7 @@ EXPORT_SYMBOL_GPL(fscrypt_context_for_new_inode);*/ int fscrypt_set_context (struct inode *inode,void *fs_data) { -struct fscrypt_inode_info *ci = inode->i_crypt_info; +struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);union fscrypt_context ctx;int ctxsize;
include/linux/fscrypt.h +36 -0
@@ -195,6 +195,38 @@ struct fscrypt_operations {int fscrypt_d_revalidate (struct inode *dir,const struct qstr *name,struct dentry *dentry,unsigned int flags); +static inline struct fscrypt_inode_info **fscrypt_addr (const struct inode *inode) +{ +return ((void *)inode + inode->i_op->i_fscrypt); +} + +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. +* 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 +* 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 ; +} + +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; +} +static inline struct fscrypt_inode_info *fscrypt_get_inode_info (const struct inode *inode) {
@@ -204,6 +236,10 @@ fscrypt_get_inode_info(const struct inode *inode)* 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); }
Signature · 1 line
2.47.2
Christian Brauner
maintainerRFC PATCH v2 3/13 ext4: move fscrypt to filesystem inode
In reply to Christian BraunerMove fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/ext4/ext4.h | 5 +++++ fs/ext4/file.c | 4 ++++ fs/ext4/ialloc.c | 2 ++ fs/ext4/inode.c | 1 + fs/ext4/mballoc.c | 3 +++ fs/ext4/namei.c | 15 +++++++++++++++ fs/ext4/super.c | 3 +++ fs/ext4/symlink.c | 12 ++++++++++++ 8 files changed, 45 insertions(+)
fs/ext4/ext4.h +5 -0
@@ -1197,6 +1197,10 @@ struct ext4_inode_info {__u32 i_csum_seed;kprojid_t i_projid; + +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif };/*
@@ -3604,6 +3608,7 @@ int ext4_enable_quotas(struct super_block *sb);extern const struct file_operations ext4_dir_operations;/* file.c */ +extern const struct inode_operations ext4_encrypted_nop_operations;extern const struct inode_operations ext4_file_inode_operations;extern const struct file_operations ext4_file_operations;extern loff_t ext4_llseek (struct file *file,loff_t offset,int origin);
fs/ext4/file.c +4 -0
@@ -981,6 +981,10 @@ const struct file_operations ext4_file_operations = { };const struct inode_operations ext4_file_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ext4_inode_info , i_fscrypt_info) - + offsetof(struct ext4_inode_info , vfs_inode), +#endif .setattr = ext4_setattr, .getattr = ext4_file_getattr, .listxattr = ext4_listxattr,
fs/ext4/ialloc.c +2 -0
@@ -979,6 +979,8 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap, }else inode_init_owner (idmap, inode, dir, mode); + inode->i_op = &ext4_encrypted_nop_operations; +if (ext4_has_feature_project (sb) &&ext4_test_inode_flag (dir,EXT4_INODE_PROJINHERIT )) ei->i_projid =EXT4_I (dir)->i_projid;
fs/ext4/inode.c +1 -0
@@ -5163,6 +5163,7 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,return inode; } + inode->i_op = &ext4_encrypted_nop_operations; ei =EXT4_I (inode); iloc.bh =NULL ;
fs/ext4/mballoc.c +3 -0
@@ -3417,6 +3417,9 @@ static int ext4_mb_init_backend(struct super_block *sb)ext4_msg (sb,KERN_ERR ,"can't get new inode" ); goto err_freesgi; } + + sbi->s_buddy_cache->i_op = &ext4_encrypted_nop_operations; +/* To avoid potentially colliding with an valid on-disk inode number, * use EXT4_BAD_INO for the buddy cache inode number. This inode is * not in the inode hash, so it should never be found by iget(), but
fs/ext4/namei.c +15 -0
@@ -4206,7 +4206,18 @@ static int ext4_rename2(struct mnt_idmap *idmap,/* * directories can handle most operations... */ +const struct inode_operations ext4_encrypted_nop_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ext4_inode_info , i_fscrypt_info) - + offsetof(struct ext4_inode_info , vfs_inode), +#endif +}; +const struct inode_operations ext4_dir_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ext4_inode_info , i_fscrypt_info) - + offsetof(struct ext4_inode_info , vfs_inode), +#endif .create = ext4_create, .lookup = ext4_lookup, .link = ext4_link,
@@ -4228,6 +4239,10 @@ const struct inode_operations ext4_dir_inode_operations = { };const struct inode_operations ext4_special_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ext4_inode_info , i_fscrypt_info) - + offsetof(struct ext4_inode_info , vfs_inode), +#endif .setattr = ext4_setattr, .getattr = ext4_getattr, .listxattr = ext4_listxattr,
fs/ext4/super.c +3 -0
@@ -1412,6 +1412,9 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)INIT_WORK (&ei->i_rsv_conversion_work, ext4_end_io_rsv_work);ext4_fc_init_inode (&ei->vfs_inode);spin_lock_init (&ei->i_fc_lock); +#ifdef CONFIG_FS_ENCRYPTION + ei->i_fscrypt_info =NULL ; +#endif return &ei->vfs_inode; }
fs/ext4/symlink.c +12 -0
@@ -115,6 +115,10 @@ static const char *ext4_get_link(struct dentry *dentry, struct inode *inode, }const struct inode_operations ext4_encrypted_symlink_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ext4_inode_info , i_fscrypt_info) - + offsetof(struct ext4_inode_info , vfs_inode), +#endif .get_link = ext4_encrypted_get_link, .setattr = ext4_setattr, .getattr = ext4_encrypted_symlink_getattr,
@@ -122,6 +126,10 @@ const struct inode_operations ext4_encrypted_symlink_inode_operations = { };const struct inode_operations ext4_symlink_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ext4_inode_info , i_fscrypt_info) - + offsetof(struct ext4_inode_info , vfs_inode), +#endif .get_link = ext4_get_link, .setattr = ext4_setattr, .getattr = ext4_getattr,
@@ -129,6 +137,10 @@ const struct inode_operations ext4_symlink_inode_operations = { };const struct inode_operations ext4_fast_symlink_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ext4_inode_info , i_fscrypt_info) - + offsetof(struct ext4_inode_info , vfs_inode), +#endif .get_link = simple_get_link, .setattr = ext4_setattr, .getattr = ext4_getattr,
Signature · 1 line
2.47.2
Christian Brauner
maintainerRFC PATCH v2 4/13 ubifs: move fscrypt to filesystem inode
In reply to Christian BraunerMove fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/ubifs/dir.c | 52 ++++++++++++++++++++++++++++------------------------ fs/ubifs/file.c | 8 ++++++++ fs/ubifs/super.c | 8 ++++++++ fs/ubifs/ubifs.h | 3 +++ 4 files changed, 47 insertions(+), 24 deletions(-)
fs/ubifs/dir.c +28 -24
@@ -104,14 +104,6 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir,simple_inode_init_ts (inode); inode->i_mapping->nrpages =0 ; -if (!is_xattr) { - err =fscrypt_prepare_new_inode (dir, inode, &encrypted); -if (err) { -ubifs_err (c,"fscrypt_prepare_new_inode failed: %i" , err); - goto out_iput; - } - } -switch (mode &S_IFMT ) {case S_IFREG : inode->i_mapping->a_ops = &ubifs_file_address_operations;
@@ -136,6 +128,14 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir,BUG (); } +if (!is_xattr) { + err =fscrypt_prepare_new_inode (dir, inode, &encrypted); +if (err) { +ubifs_err (c,"fscrypt_prepare_new_inode failed: %i" , err); + goto out_iput; + } + } + ui->flags =inherit_flags (dir, mode);ubifs_set_inode_flags (inode);if (S_ISREG (mode))
@@ -1740,22 +1740,26 @@ static loff_t ubifs_dir_llseek(struct file *file, loff_t offset, int whence) }const struct inode_operations ubifs_dir_inode_operations = { - .lookup = ubifs_lookup, - .create = ubifs_create, - .link = ubifs_link, - .symlink = ubifs_symlink, - .unlink = ubifs_unlink, - .mkdir = ubifs_mkdir, - .rmdir = ubifs_rmdir, - .mknod = ubifs_mknod, - .rename = ubifs_rename, - .setattr = ubifs_setattr, - .getattr = ubifs_getattr, - .listxattr = ubifs_listxattr, - .update_time = ubifs_update_time, - .tmpfile = ubifs_tmpfile, - .fileattr_get = ubifs_fileattr_get, - .fileattr_set = ubifs_fileattr_set, +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ubifs_inode , i_fscrypt_info) - + offsetof(struct ubifs_inode , vfs_inode), +#endif + .lookup = ubifs_lookup, + .create = ubifs_create, + .link = ubifs_link, + .symlink = ubifs_symlink, + .unlink = ubifs_unlink, + .mkdir = ubifs_mkdir, + .rmdir = ubifs_rmdir, + .mknod = ubifs_mknod, + .rename = ubifs_rename, + .setattr = ubifs_setattr, + .getattr = ubifs_getattr, + .listxattr = ubifs_listxattr, + .update_time = ubifs_update_time, + .tmpfile = ubifs_tmpfile, + .fileattr_get = ubifs_fileattr_get, + .fileattr_set = ubifs_fileattr_set, };const struct file_operations ubifs_dir_operations = {
fs/ubifs/file.c +8 -0
@@ -1632,6 +1632,10 @@ const struct address_space_operations ubifs_file_address_operations = { };const struct inode_operations ubifs_file_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ubifs_inode , i_fscrypt_info) - + offsetof(struct ubifs_inode , vfs_inode), +#endif .setattr = ubifs_setattr, .getattr = ubifs_getattr, .listxattr = ubifs_listxattr,
@@ -1641,6 +1645,10 @@ const struct inode_operations ubifs_file_inode_operations = { };const struct inode_operations ubifs_symlink_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ubifs_inode , i_fscrypt_info) - + offsetof(struct ubifs_inode , vfs_inode), +#endif .get_link = ubifs_get_link, .setattr = ubifs_setattr, .getattr = ubifs_symlink_getattr,
fs/ubifs/super.c +8 -0
@@ -100,6 +100,13 @@ static int validate_inode(struct ubifs_info *c, const struct inode *inode)return err; } +static const struct inode_operations ubifs_encrypted_nop_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ubifs_inode , i_fscrypt_info) - + offsetof(struct ubifs_inode , vfs_inode), +#endif +}; +struct inode *ubifs_iget (struct super_block *sb,unsigned long inum) {int err;
@@ -118,6 +125,7 @@ struct inode *ubifs_iget(struct super_block *sb, unsigned long inum)return inode; ui =ubifs_inode (inode); + inode->i_op = &ubifs_encrypted_nop_inode_operations; ino =kmalloc (UBIFS_MAX_INO_NODE_SZ ,GFP_NOFS );if (!ino) { err = -ENOMEM ;
fs/ubifs/ubifs.h +3 -0
@@ -416,6 +416,9 @@ struct ubifs_inode {pgoff_t read_in_a_row;int data_len;void *data; +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif };/**
Signature · 1 line
2.47.2
Christian Brauner
maintainerRFC PATCH v2 5/13 f2fs: move fscrypt to filesystem inode
In reply to Christian BraunerMove fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/f2fs/f2fs.h | 4 ++++ fs/f2fs/file.c | 4 ++++ fs/f2fs/inode.c | 1 + fs/f2fs/namei.c | 25 +++++++++++++++++++++++++ fs/f2fs/super.c | 3 +++ 5 files changed, 37 insertions(+)
fs/f2fs/f2fs.h +4 -0
@@ -905,6 +905,9 @@ struct f2fs_inode_info {unsigned int atomic_write_cnt;loff_t original_i_size;/* original i_size before atomic write */ +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info;/* filesystem encryption info */ +#endif }; static inline void get_read_extent_info(struct extent_info *ext,
@@ -4297,6 +4300,7 @@ extern const struct inode_operations f2fs_dir_inode_operations;extern const struct inode_operations f2fs_symlink_inode_operations;extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;extern const struct inode_operations f2fs_special_inode_operations; +extern const struct inode_operations f2fs_encrypted_nop_inode_operations;extern struct kmem_cache *f2fs_inode_entry_slab;/*
fs/f2fs/file.c +4 -0
@@ -1150,6 +1150,10 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, }const struct inode_operations f2fs_file_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct f2fs_inode_info , i_fscrypt_info) - + offsetof(struct f2fs_inode_info , vfs_inode), +#endif .getattr = f2fs_getattr, .setattr = f2fs_setattr, .get_inode_acl = f2fs_get_acl,
fs/f2fs/inode.c +1 -0
@@ -583,6 +583,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)return inode; } + inode->i_op = &f2fs_encrypted_nop_inode_operations;if (is_meta_ino (sbi, ino)) goto make_now;
fs/f2fs/namei.c +25 -0
@@ -216,6 +216,13 @@ static void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *inode,file_set_hot (inode); } +const struct inode_operations f2fs_encrypted_nop_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct f2fs_inode_info , i_fscrypt_info) - + offsetof(struct f2fs_inode_info , vfs_inode), +#endif +}; +static struct inode *f2fs_new_inode (struct mnt_idmap *idmap,struct inode *dir,umode_t mode,const char *name)
@@ -249,6 +256,8 @@ static struct inode *f2fs_new_inode(struct mnt_idmap *idmap, fi->i_crtime =inode_get_mtime (inode); inode->i_generation =get_random_u32 (); + inode->i_op = &f2fs_encrypted_nop_inode_operations; +if (S_ISDIR (inode->i_mode)) fi->i_current_depth =1 ;
@@ -1325,6 +1334,10 @@ static int f2fs_encrypted_symlink_getattr(struct mnt_idmap *idmap, }const struct inode_operations f2fs_encrypted_symlink_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct f2fs_inode_info , i_fscrypt_info) - + offsetof(struct f2fs_inode_info , vfs_inode), +#endif .get_link = f2fs_encrypted_get_link, .getattr = f2fs_encrypted_symlink_getattr, .setattr = f2fs_setattr,
@@ -1332,6 +1345,10 @@ const struct inode_operations f2fs_encrypted_symlink_inode_operations = { };const struct inode_operations f2fs_dir_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct f2fs_inode_info , i_fscrypt_info) - + offsetof(struct f2fs_inode_info , vfs_inode), +#endif .create = f2fs_create, .lookup = f2fs_lookup, .link = f2fs_link,
@@ -1353,6 +1370,10 @@ const struct inode_operations f2fs_dir_inode_operations = { };const struct inode_operations f2fs_symlink_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct f2fs_inode_info , i_fscrypt_info) - + offsetof(struct f2fs_inode_info , vfs_inode), +#endif .get_link = f2fs_get_link, .getattr = f2fs_getattr, .setattr = f2fs_setattr,
@@ -1360,6 +1381,10 @@ const struct inode_operations f2fs_symlink_inode_operations = { };const struct inode_operations f2fs_special_inode_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct f2fs_inode_info , i_fscrypt_info) - + offsetof(struct f2fs_inode_info , vfs_inode), +#endif .getattr = f2fs_getattr, .setattr = f2fs_setattr, .get_inode_acl = f2fs_get_acl,
fs/f2fs/super.c +3 -0
@@ -1453,6 +1453,9 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)/* Will be used by directory only */ fi->i_dir_level =F2FS_SB (sb)->dir_level; +#ifdef CONFIG_FS_ENCRYPTION + fi->i_fscrypt_info =NULL ; +#endif return &fi->vfs_inode; }
Signature · 1 line
2.47.2
Christian Brauner
maintainerRFC PATCH v2 6/13 ceph: move fscrypt to filesystem inode
In reply to Christian BraunerMove fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/ceph/dir.c | 8 ++++++++ fs/ceph/inode.c | 21 +++++++++++++++++++++ include/linux/netfs.h | 6 ++++++ 3 files changed, 35 insertions(+)
fs/ceph/dir.c +8 -0
@@ -2229,6 +2229,10 @@ const struct file_operations ceph_snapdir_fops = { };const struct inode_operations ceph_dir_iops = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ceph_inode_info, netfs.i_fscrypt_info) - + offsetof(struct ceph_inode_info, netfs.inode), +#endif .lookup = ceph_lookup, .permission = ceph_permission, .getattr = ceph_getattr,
@@ -2248,6 +2252,10 @@ const struct inode_operations ceph_dir_iops = { };const struct inode_operations ceph_snapdir_iops = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ceph_inode_info, netfs.i_fscrypt_info) - + offsetof(struct ceph_inode_info, netfs.inode), +#endif .lookup = ceph_lookup, .permission = ceph_permission, .getattr = ceph_getattr,
fs/ceph/inode.c +21 -0
@@ -36,6 +36,12 @@static const struct inode_operations ceph_symlink_iops;static const struct inode_operations ceph_encrypted_symlink_iops; +static const struct inode_operations ceph_encrypted_nop_iops = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ceph_inode_info, netfs.i_fscrypt_info) - + offsetof(struct ceph_inode_info, netfs.inode), +#endif +};static void ceph_inode_work (struct work_struct *work);
@@ -49,6 +55,7 @@ static int ceph_set_ino_cb(struct inode *inode, void *data) ci->i_vino = *(struct ceph_vino *)data; inode->i_ino =ceph_vino_to_ino_t (ci->i_vino); + inode->i_op = &ceph_encrypted_nop_iops;inode_set_iversion_raw (inode,0 );percpu_counter_inc (&mdsc->metric.total_inodes);
@@ -89,6 +96,8 @@ struct inode *ceph_new_inode(struct inode *dir, struct dentry *dentry, inode->i_state =0 ; inode->i_mode = *mode; + inode->i_op = &ceph_encrypted_nop_iops; + err =ceph_security_init_secctx (dentry, *mode, as_ctx);if (err <0 ) goto out_err;
@@ -232,6 +241,10 @@ struct inode *ceph_get_snapdir(struct inode *parent) }const struct inode_operations ceph_file_iops = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ceph_inode_info, netfs.i_fscrypt_info) - + offsetof(struct ceph_inode_info, netfs.inode), +#endif .permission = ceph_permission, .setattr = ceph_setattr, .getattr = ceph_getattr,
@@ -2314,6 +2327,10 @@ static int ceph_encrypted_symlink_getattr(struct mnt_idmap *idmap,* symlinks */ static const struct inode_operations ceph_symlink_iops = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ceph_inode_info, netfs.i_fscrypt_info) - + offsetof(struct ceph_inode_info, netfs.inode), +#endif .get_link = simple_get_link, .setattr = ceph_setattr, .getattr = ceph_getattr,
@@ -2321,6 +2338,10 @@ static const struct inode_operations ceph_symlink_iops = { };static const struct inode_operations ceph_encrypted_symlink_iops = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ceph_inode_info, netfs.i_fscrypt_info) - + offsetof(struct ceph_inode_info, netfs.inode), +#endif .get_link = ceph_encrypted_get_link, .setattr = ceph_setattr, .getattr = ceph_encrypted_symlink_getattr,
include/linux/netfs.h +6 -0
@@ -57,6 +57,9 @@ typedef void (*netfs_io_terminated_t)(void *priv, ssize_t transferred_or_error);*/ struct netfs_inode {struct inode inode;/* The VFS inode */ +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif const struct netfs_request_ops *ops;#if IS_ENABLED (CONFIG_FSCACHE )struct fscache_cookie *cache;
@@ -503,6 +506,9 @@ static inline void netfs_inode_init(struct netfs_inode *ctx, ctx->zero_point = ctx->remote_i_size;mapping_set_release_always (ctx->inode.i_mapping); } +#ifdef CONFIG_FS_ENCRYPTION + ctx->i_fscrypt_info =NULL ; +#endif }/**
Signature · 1 line
2.47.2
Christian Brauner
maintainerRFC PATCH v2 7/13 fs: drop i_crypt_info from struct inode
In reply to Christian BraunerNow that all filesystems store the fscrypt data pointer in their private inode, drop the data pointer from struct inode itself freeing up 8 bytes.
--- 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(-)
fs/crypto/fscrypt_private.h +1 -1
@@ -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 {
fs/crypto/keysetup.c +12 -13
@@ -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);
include/linux/fs.h +0 -4
@@ -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
include/linux/fscrypt.h +6 -15
@@ -203,28 +203,20 @@ static inline struct fscrypt_inode_info **fscrypt_addr(const struct inode *inodestatic 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 ; }/**
Signature · 1 line
2.47.2
Christian Brauner
maintainerRFC PATCH v2 8/13 fs: add fsverity offset
In reply to Christian BraunerStore the offset of the fsverity data pointer from struct inode in struct inode_operations. Both are embedded in the filesystem's private inode.
This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
--- include/linux/fs.h | 1 + 1 file changed, 1 insertion(+)
include/linux/fs.h +1 -0
@@ -2214,6 +2214,7 @@ int wrap_directory_iterator(struct file *, struct dir_context *,struct inode_operations {ptrdiff_t i_fscrypt; +ptrdiff_t i_fsverity;struct dentry * (*lookup) (struct inode *,struct dentry *,unsigned int );const char * (*get_link) (struct dentry *,struct inode *,struct delayed_call *);int (*permission) (struct mnt_idmap *,struct inode *,int );
Signature · 1 line
2.47.2
Christian Brauner
maintainerRFC PATCH v2 9/13 fs/verity: use accessors
In reply to Christian BraunerUse accessor to get and set the verity info from the filesystem. They can be removed once all filesystems have been converted to make room for verity info in their own inodes.
--- fs/verity/open.c | 18 +++++++++++++++--- fs/verity/verify.c | 2 +- include/linux/fsverity.h | 9 ++++++++- 3 files changed, 24 insertions(+), 5 deletions(-)
fs/verity/open.c +15 -3
@@ -250,13 +250,20 @@ 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 (cmpxchg_release (&inode->i_verity_info,NULL , vi) !=NULL ) { + +if (inode->i_op->i_fsverity) + p =cmpxchg_release (fsverity_addr (inode),NULL , vi); +else + p =cmpxchg_release (&inode->i_verity_info,NULL , vi); +if (p !=NULL ) {/* Lost the race, so free the fsverity_info we allocated. */ fsverity_free_info (vi);/*
@@ -402,8 +409,13 @@ EXPORT_SYMBOL_GPL(__fsverity_prepare_setattr);void __fsverity_cleanup_inode (struct inode *inode) { -fsverity_free_info (inode->i_verity_info); - inode->i_verity_info =NULL ; +struct fsverity_info **vi; + + vi =fsverity_addr (inode); +if (!*vi) + vi = &inode->i_verity_info; +fsverity_free_info (*vi); + *vi =NULL ; }EXPORT_SYMBOL_GPL (__fsverity_cleanup_inode);
fs/verity/verify.c +1 -1
@@ -247,7 +247,7 @@ verify_data_blocks(struct folio *data_folio, size_t len, size_t offset, unsigned long max_ra_pages) {struct inode *inode = data_folio->mapping->host; -struct fsverity_info *vi = inode->i_verity_info; +struct fsverity_info *vi =fsverity_get_info (inode);const unsigned int block_size = vi->tree_params.block_size;u64 pos = (u64 )data_folio->index <<PAGE_SHIFT ;
include/linux/fsverity.h +8 -1
@@ -124,6 +124,11 @@ struct fsverity_operations {#ifdef CONFIG_FS_VERITY +static inline struct fsverity_info **fsverity_addr (const struct inode *inode) +{ +return ((void *)inode + inode->i_op->i_fsverity); +} +static inline struct fsverity_info *fsverity_get_info (const struct inode *inode) {/*
@@ -132,6 +137,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_op->i_fsverity) +return smp_load_acquire (fsverity_addr (inode));return smp_load_acquire (&inode->i_verity_info); }
@@ -160,7 +167,7 @@ void __fsverity_cleanup_inode(struct inode *inode);*/ static inline void fsverity_cleanup_inode (struct inode *inode) { -if (inode->i_verity_info) +if (inode->i_verity_info || inode->i_op->i_fsverity)__fsverity_cleanup_inode (inode); }
Signature · 1 line
2.47.2
Christian Brauner
maintainerRFC PATCH v2 10/13 btrfs: move fsverity to filesystem inode
In reply to Christian BraunerMove fsverity data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/btrfs/btrfs_inode.h | 3 +++ fs/btrfs/inode.c | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)
fs/btrfs/btrfs_inode.h +3 -0
@@ -339,6 +339,9 @@ struct btrfs_inode {struct rw_semaphore i_mmap_lock;struct inode vfs_inode; +#ifdef CONFIG_FS_VERITY +struct fsverity_info *i_fsverity_info; +#endif };static inline u64 btrfs_get_first_dir_index_to_log (const struct btrfs_inode *inode)
fs/btrfs/inode.c +19 -1
@@ -7873,7 +7873,9 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)INIT_LIST_HEAD (&ei->delalloc_inodes);INIT_LIST_HEAD (&ei->delayed_iput);init_rwsem (&ei->i_mmap_lock); - +#ifdef CONFIG_FS_VERITY + ei->i_fsverity_info =NULL ; +#endif return inode; }
@@ -10410,6 +10412,10 @@ struct btrfs_inode *btrfs_find_first_inode(struct btrfs_root *root, u64 min_ino) }static const struct inode_operations btrfs_dir_inode_operations = { +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct btrfs_inode , i_fsverity_info) - + offsetof(struct btrfs_inode , vfs_inode), +#endif .getattr = btrfs_getattr, .lookup = btrfs_lookup, .create = btrfs_create,
@@ -10471,6 +10477,10 @@ static const struct address_space_operations btrfs_aops = { };static const struct inode_operations btrfs_file_inode_operations = { +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct btrfs_inode , i_fsverity_info) - + offsetof(struct btrfs_inode , vfs_inode), +#endif .getattr = btrfs_getattr, .setattr = btrfs_setattr, .listxattr = btrfs_listxattr,
@@ -10483,6 +10493,10 @@ static const struct inode_operations btrfs_file_inode_operations = { .fileattr_set = btrfs_fileattr_set, };static const struct inode_operations btrfs_special_inode_operations = { +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct btrfs_inode , i_fsverity_info) - + offsetof(struct btrfs_inode , vfs_inode), +#endif .getattr = btrfs_getattr, .setattr = btrfs_setattr, .permission = btrfs_permission,
@@ -10492,6 +10506,10 @@ static const struct inode_operations btrfs_special_inode_operations = { .update_time = btrfs_update_time, };static const struct inode_operations btrfs_symlink_inode_operations = { +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct btrfs_inode , i_fsverity_info) - + offsetof(struct btrfs_inode , vfs_inode), +#endif .get_link = page_get_link, .getattr = btrfs_getattr, .setattr = btrfs_setattr,
Signature · 1 line
2.47.2
Christian Brauner
maintainerRFC PATCH v2 11/13 ext4: move fsverity to filesystem inode
In reply to Christian BraunerMove fsverity data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/ext4/ext4.h | 4 ++++ fs/ext4/file.c | 4 ++++ fs/ext4/namei.c | 8 ++++++++ fs/ext4/super.c | 3 +++ fs/ext4/symlink.c | 12 ++++++++++++ 5 files changed, 31 insertions(+)
fs/ext4/ext4.h +4 -0
@@ -1201,6 +1201,10 @@ struct ext4_inode_info {#ifdef CONFIG_FS_ENCRYPTION struct fscrypt_inode_info *i_fscrypt_info;#endif + +#ifdef CONFIG_FS_VERITY +struct fsverity_info *i_fsverity_info; +#endif };/*
fs/ext4/file.c +4 -0
@@ -984,6 +984,10 @@ const struct inode_operations ext4_file_inode_operations = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct ext4_inode_info, i_fscrypt_info) - offsetof(struct ext4_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct ext4_inode_info, i_fsverity_info) - + offsetof(struct ext4_inode_info, vfs_inode), #endif .setattr = ext4_setattr, .getattr = ext4_file_getattr,
fs/ext4/namei.c +8 -0
@@ -4217,6 +4217,10 @@ const struct inode_operations ext4_dir_inode_operations = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct ext4_inode_info, i_fscrypt_info) - offsetof(struct ext4_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct ext4_inode_info, i_fsverity_info) - + offsetof(struct ext4_inode_info, vfs_inode), #endif .create = ext4_create, .lookup = ext4_lookup,
@@ -4242,6 +4246,10 @@ const struct inode_operations ext4_special_inode_operations = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct ext4_inode_info, i_fscrypt_info) - offsetof(struct ext4_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct ext4_inode_info, i_fsverity_info) - + offsetof(struct ext4_inode_info, vfs_inode), #endif .setattr = ext4_setattr, .getattr = ext4_getattr,
fs/ext4/super.c +3 -0
@@ -1414,6 +1414,9 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)spin_lock_init (&ei->i_fc_lock);#ifdef CONFIG_FS_ENCRYPTION ei->i_fscrypt_info =NULL ; +#endif +#ifdef CONFIG_FS_VERITY + ei->i_fsverity_info =NULL ;#endif return &ei->vfs_inode; }
fs/ext4/symlink.c +12 -0
@@ -118,6 +118,10 @@ const struct inode_operations ext4_encrypted_symlink_inode_operations = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct ext4_inode_info, i_fscrypt_info) - offsetof(struct ext4_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct ext4_inode_info, i_fsverity_info) - + offsetof(struct ext4_inode_info, vfs_inode), #endif .get_link = ext4_encrypted_get_link, .setattr = ext4_setattr,
@@ -129,6 +133,10 @@ const struct inode_operations ext4_symlink_inode_operations = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct ext4_inode_info, i_fscrypt_info) - offsetof(struct ext4_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct ext4_inode_info, i_fsverity_info) - + offsetof(struct ext4_inode_info, vfs_inode), #endif .get_link = ext4_get_link, .setattr = ext4_setattr,
@@ -140,6 +148,10 @@ const struct inode_operations ext4_fast_symlink_inode_operations = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct ext4_inode_info, i_fscrypt_info) - offsetof(struct ext4_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct ext4_inode_info, i_fsverity_info) - + offsetof(struct ext4_inode_info, vfs_inode), #endif .get_link = simple_get_link, .setattr = ext4_setattr,
Signature · 1 line
2.47.2
Christian Brauner
maintainerRFC PATCH v2 12/13 f2fs: move fsverity to filesystem inode
In reply to Christian BraunerMove fsverity data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/file.c | 4 ++++ fs/f2fs/namei.c | 16 ++++++++++++++++ fs/f2fs/super.c | 3 +++ 4 files changed, 26 insertions(+)
fs/f2fs/f2fs.h +3 -0
@@ -908,6 +908,9 @@ struct f2fs_inode_info {#ifdef CONFIG_FS_ENCRYPTION struct fscrypt_inode_info *i_fscrypt_info;/* filesystem encryption info */ #endif +#ifdef CONFIG_FS_VERITY +struct fsverity_info *i_fsverity_info; +#endif }; static inline void get_read_extent_info(struct extent_info *ext,
fs/f2fs/file.c +4 -0
@@ -1153,6 +1153,10 @@ const struct inode_operations f2fs_file_inode_operations = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) - offsetof(struct f2fs_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct f2fs_inode_info, i_fsverity_info) - + offsetof(struct f2fs_inode_info, vfs_inode), #endif .getattr = f2fs_getattr, .setattr = f2fs_setattr,
fs/f2fs/namei.c +16 -0
@@ -1337,6 +1337,10 @@ const struct inode_operations f2fs_encrypted_symlink_inode_operations = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) - offsetof(struct f2fs_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct f2fs_inode_info, i_fsverity_info) - + offsetof(struct f2fs_inode_info, vfs_inode), #endif .get_link = f2fs_encrypted_get_link, .getattr = f2fs_encrypted_symlink_getattr,
@@ -1348,6 +1352,10 @@ const struct inode_operations f2fs_dir_inode_operations = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) - offsetof(struct f2fs_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct f2fs_inode_info, i_fsverity_info) - + offsetof(struct f2fs_inode_info, vfs_inode), #endif .create = f2fs_create, .lookup = f2fs_lookup,
@@ -1373,6 +1381,10 @@ const struct inode_operations f2fs_symlink_inode_operations = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) - offsetof(struct f2fs_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct f2fs_inode_info, i_fsverity_info) - + offsetof(struct f2fs_inode_info, vfs_inode), #endif .get_link = f2fs_get_link, .getattr = f2fs_getattr,
@@ -1384,6 +1396,10 @@ const struct inode_operations f2fs_special_inode_operations = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) - offsetof(struct f2fs_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct f2fs_inode_info, i_fsverity_info) - + offsetof(struct f2fs_inode_info, vfs_inode), #endif .getattr = f2fs_getattr, .setattr = f2fs_setattr,
fs/f2fs/super.c +3 -0
@@ -1456,6 +1456,9 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)#ifdef CONFIG_FS_ENCRYPTION fi->i_fscrypt_info =NULL ;#endif +#ifdef CONFIG_FS_VERITY + fi->i_fsverity_info =NULL ; +#endif return &fi->vfs_inode; }
Signature · 1 line
2.47.2
Christian Brauner
maintainerRFC PATCH v2 13/13 fs: drop i_verity_info from struct inode
In reply to Christian BraunerNow that all filesystems store the fsverity data pointer in their private inode, drop the data pointer from struct inode itself freeing up 8 bytes.
--- fs/verity/enable.c | 2 +- fs/verity/fsverity_private.h | 2 +- fs/verity/open.c | 18 +++++------------- include/linux/fs.h | 4 ---- include/linux/fsverity.h | 14 +++++++------- 5 files changed, 14 insertions(+), 26 deletions(-)
fs/verity/enable.c +1 -1
@@ -287,7 +287,7 @@ static int enable_verity(struct file *filp,/* Successfully enabled verity */ /* -* Readers can start using ->i_verity_info immediately, so it +* Readers can start using ->i_fsverity_info immediately, so it * can't be rolled back once set. So don't set it until just * after the filesystem has successfully enabled verity. */
fs/verity/fsverity_private.h +1 -1
@@ -58,7 +58,7 @@ struct merkle_tree_params {* fsverity_info - cached verity metadata for an inode * * When a verity file is first opened, an instance of this struct is allocated -* and stored in ->i_verity_info; it remains until the inode is evicted. It +* and stored in ->i_fsverity_info; it remains until the inode is evicted. It * caches information about the Merkle tree that's needed to efficiently verify * data read from the file. It also caches the file digest. The Merkle tree * pages themselves are not cached here, but the filesystem may cache them.
fs/verity/open.c +5 -13
@@ -250,24 +250,18 @@ 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 +* Multiple tasks may race to set ->i_fsverity_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 +* fsverity_get_info(). I.e., here we publish ->i_fsverity_info with a * RELEASE barrier so that other tasks can ACQUIRE it. */ -if (inode->i_op->i_fsverity) - p =cmpxchg_release (fsverity_addr (inode),NULL , vi); -else - p =cmpxchg_release (&inode->i_verity_info,NULL , vi); -if (p !=NULL ) { +if (cmpxchg_release (fsverity_addr (inode),NULL , vi) !=NULL ) {/* Lost the race, so free the fsverity_info we allocated. */ fsverity_free_info (vi);/* -* Afterwards, the caller may access ->i_verity_info directly, +* Afterwards, the caller may access ->i_fsverity_info directly, * so make sure to ACQUIRE the winning fsverity_info. */ (void )fsverity_get_info (inode);
@@ -364,7 +358,7 @@ int fsverity_get_descriptor(struct inode *inode,return 0 ; } -/* Ensure the inode has an ->i_verity_info */ +/* Ensure the inode has an ->i_fsverity_info */ static int ensure_verity_info (struct inode *inode) {struct fsverity_info *vi =fsverity_get_info (inode);
@@ -412,8 +406,6 @@ void __fsverity_cleanup_inode(struct inode *inode)struct fsverity_info **vi; vi =fsverity_addr (inode); -if (!*vi) - vi = &inode->i_verity_info;fsverity_free_info (*vi); *vi =NULL ; }
include/linux/fs.h +0 -4
@@ -778,10 +778,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;
include/linux/fsverity.h +7 -7
@@ -133,13 +133,13 @@ static inline struct fsverity_info *fsverity_get_info(const struct inode *inode) {/* * Pairs with the cmpxchg_release() in fsverity_set_info(). -* I.e., another task may publish ->i_verity_info concurrently, +* I.e., another task may publish ->i_fsverity_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_fsverity)return smp_load_acquire (fsverity_addr (inode)); -return smp_load_acquire (&inode->i_verity_info); +return NULL ; }/* enable.c */
@@ -163,11 +163,11 @@ void __fsverity_cleanup_inode(struct inode *inode);* fsverity_cleanup_inode() - free the inode's verity info, if present * @inode: an inode being evicted * -* Filesystems must call this on inode eviction to free ->i_verity_info. +* Filesystems must call this on inode eviction to free ->i_fsverity_info. */ static inline void fsverity_cleanup_inode (struct inode *inode) { -if (inode->i_verity_info || inode->i_op->i_fsverity) +if (inode->i_op->i_fsverity)__fsverity_cleanup_inode (inode); }
@@ -274,12 +274,12 @@ static inline bool fsverity_verify_page(struct page *page)* fsverity_active() - do reads from the inode need to go through fs-verity? * @inode: inode to check * -* This checks whether ->i_verity_info has been set. +* This checks whether ->i_fsverity_info has been set. * * Filesystems call this from ->readahead() to check whether the pages need to * be verified or not. Don't use IS_VERITY() for this purpose; it's subject to * a race condition where the file is being read concurrently with -* FS_IOC_ENABLE_VERITY completing. (S_VERITY is set before ->i_verity_info.) +* FS_IOC_ENABLE_VERITY completing. (S_VERITY is set before ->i_fsverity_info.) * * Return: true if reads need to go through fs-verity, otherwise false */
@@ -294,7 +294,7 @@ static inline bool fsverity_active(const struct inode *inode)* @filp: the struct file being set up * * When opening a verity file, deny the open if it is for writing. Otherwise, -* set up the inode's ->i_verity_info if not already done. +* set up the inode's ->i_fsverity_info if not already done. * * When combined with fscrypt, this must be called after fscrypt_file_open(). * Otherwise, we won't have the key set up to decrypt the verity metadata.
Signature · 1 line
2.47.2
Christian Brauner
maintainerRe: [PATCH RFC DRAFT v2 00/13] Move fscrypt and fsverity out of struct inode
In reply to Christian BraunerQuoted 34 lines · Christian Brauner
Hey,
This is a POC. We're still discussing alternatives and I want to provide some useful data on what I learned about using offsets to drop fscrypt and fsverity from struct inode.
As discussed, this moves the fscrypt and fsverity pointers out of struct inode shrinking it by 16 bytes. The pointers move into the individual filesystems that actually do make use of them.
In order to find the fscrypt and fsverity data pointers offsets from the embedded struct inode in the filesystem's private inode data are stored in struct
inode_operations. This means we get fast access to the data pointers without having to rely on indirect calls.Bugs & Issues
=============* For fscrypt specifically the biggest issue is
fscrypt_prepare_new_inode()is called in filesystem's inode allocation functions beforeinode->i_opis set. That means the offset isn't available at the time when we would need it. To fix this we can set dummy encrypted inode operations for the respective filesystem with an initialized offset.* For both fscrypt & fsverity the biggest issue is that every codepath that currently calls
make_bad_inode()after having initialized fscrypt or fsverity data will overrideinode->i_opwithbad_inode_ops. At which point we're back to the previous problem: The offset isn't available anymore. So wheninode->i_sb->s_op->evict_inode()is calledfscrypt_put_encryption_info()doesn't have the offset available anymore and would corrupt the hell out of everything and also leak memory.
Quoted 8 lines
Obviously we could use a flag to detect a bad inodes instead of
i_opand let the filesystem assign it's own bad inode operations including the correct offset. Is it worth it?The other way I see we can fix this if we require fixed offsets in the filesystems inode so fscrypt and fsverity always now what offset to calculate. We could use two consecutive pointers at the beginning of the filesystem's inode. Does that always work and is it worth it?
Another, way less idiotic but way more obvious solution is to move the offsets to struct super_operations. That will mean one additional pointer deref but it will have the big advantage that the patch will become really really simple. Thoughts? Otherwise I'd implement that.
Christian Brauner
maintainerv3 cover Move fscrypt and fsverity out of struct inode
Hey,
As discussed, this moves the fscrypt and fsverity pointers out of struct inode shrinking it by 16 bytes. The pointers move into the individual filesystems that actually do make use of them.
In order to find the fscrypt and fsverity data pointers offsets from the embedded struct inode in the filesystem's private inode data are stored in struct super_operations. This means we get fast access to the data pointers without having to rely on indirect calls.
Thanks!
Christian
Test results:
+ sudo ./check -g encrypt,verity
FSTYP -- ext4 PLATFORM -- Linux/x86_64 localhost 6.16.0-rc1-g9cfff4adb101 #268 SMP PREEMPT_DYNAMIC Fri Jun 5 15:58:00 CEST 2015 MKFS_OPTIONS -- -F /dev/nvme1n1p6
MOUNT_OPTIONS -- -o acl,user_xattr /dev/nvme1n1p6 /mnt/scratch
ext4/024 3s
generic/395 5s generic/396 3s generic/397 3s generic/398 4s generic/399 35s generic/419 3s generic/421 5s generic/429 13s generic/435 23s generic/440 4s generic/548 10s generic/549 9s generic/550 [not run] encryption policy '-c 9 -n 9 -f 0' is unusable; probably missing kernel crypto API support generic/572 6s generic/573 4s generic/574 36s generic/575 9s generic/576 5s generic/577 4s generic/579 24s generic/580 5s generic/581 11s generic/582 10s generic/583 9s generic/584 [not run] encryption policy '-c 9 -n 9 -v 2 -f 0' is unusable; probably missing kernel crypto API support generic/592 10s generic/593 4s generic/595 7s generic/602 9s generic/613 20s generic/621 8s generic/624 4s generic/625 4s generic/692 5s
generic/693 [not run] encryption policy '-c 1 -n 10 -v 2 -f 0' is unusable; probably missing kernel crypto API support
generic/739 18s
Ran: ext4/024 generic/395 generic/396 generic/397 generic/398 generic/399 generic/419 generic/421 generic/429 generic/435 generic/440 generic/548 generic/549 generic/550 generic/572 generic/573 generic/574 generic/575 generic/576 generic/577 generic/579 generic/580 generic/581 generic/582 generic/583 generic/584 generic/592 generic/593 generic/595 generic/602 generic/613 generic/621 generic/624 generic/625 generic/692 generic/693 generic/739 Not run: generic/550 generic/584 generic/693
Passed all 37 tests
+ sudo ./check -g encrypt,verity
FSTYP -- f2fs PLATFORM -- Linux/x86_64 localhost 6.16.0-rc1-g9cfff4adb101 #268 SMP PREEMPT_DYNAMIC Fri Jun 5 15:58:00 CEST 2015 MKFS_OPTIONS -- /dev/nvme1n1p6
MOUNT_OPTIONS -- -o acl,user_xattr /dev/nvme1n1p6 /mnt/scratch
f2fs/002 [not run] lz4 utility required, skipped this test
generic/395 5s ... 4s generic/396 3s ... 4s generic/397 3s ... 4s generic/398 4s ... 4s
generic/399 35s ... 20s
generic/419 3s ... 4s
generic/421 5s ... 5s
generic/429 13s ... 14s
generic/435 23s ... 32s
generic/440 4s ... 4s
generic/548 10s ... 12s
generic/549 9s ... 12s
generic/550 [not run] encryption policy '-c 9 -n 9 -f 0' is unusable; probably missing kernel crypto API support
generic/572 6s ... 6s
generic/573 4s ... 4s
generic/574 36s ... 27s
generic/575 9s ... 10s generic/576 5s ... 5s generic/577 4s ... 4s
generic/579 24s ... 26s
generic/580 5s ... 5s
generic/581 11s ... 12s
generic/582 10s ... 12s
generic/583 9s ... 12s
generic/584 [not run] encryption policy '-c 9 -n 9 -v 2 -f 0' is unusable; probably missing kernel crypto API support
generic/592 10s ... 13s
generic/593 4s ... 4s generic/595 7s ... 7s generic/602 9s ... 13s generic/613 20s ... 24s generic/621 8s ... 9s generic/624 4s ... 3s generic/625 4s ... 4s generic/692 5s ... 5s
generic/693 [not run] encryption policy '-c 1 -n 10 -v 2 -f 0' is unusable; probably missing kernel crypto API support
generic/739 18s ... 23s
Ran: f2fs/002 generic/395 generic/396 generic/397 generic/398 generic/399 generic/419 generic/421 generic/429 generic/435 generic/440 generic/548 generic/549 generic/550 generic/572 generic/573 generic/574 generic/575 generic/576 generic/577 generic/579 generic/580 generic/581 generic/582 generic/583 generic/584 generic/592 generic/593 generic/595 generic/602 generic/613 generic/621 generic/624 generic/625 generic/692 generic/693 generic/739 Not run: f2fs/002 generic/550 generic/584 generic/693
Passed all 37 tests
+ sudo ./check -g encrypt,verity
FSTYP -- btrfs PLATFORM -- Linux/x86_64 localhost 6.16.0-rc1-g9cfff4adb101 #268 SMP PREEMPT_DYNAMIC Fri Jun 5 15:58:00 CEST 2015 MKFS_OPTIONS -- /dev/nvme1n1p6
MOUNT_OPTIONS -- /dev/nvme1n1p6 /mnt/scratch
btrfs/277 [not run] kernel does not support send stream 3 btrfs/290 [not run] btrfs-corrupt-block utility required, skipped this test btrfs/291 [not run] This test requires a valid $LOGWRITES_DEV
generic/395 4s ... [not run] No encryption support for btrfs generic/396 4s ... [not run] No encryption support for btrfs generic/397 4s ... [not run] No encryption support for btrfs generic/398 4s ... [not run] No encryption support for btrfs generic/399 20s ... [not run] No encryption support for btrfs generic/419 4s ... [not run] No encryption support for btrfs generic/421 5s ... [not run] No encryption support for btrfs generic/429 14s ... [not run] No encryption support for btrfs generic/435 32s ... [not run] No encryption support for btrfs generic/440 4s ... [not run] No encryption support for btrfs generic/548 12s ... [not run] No encryption support for btrfs generic/549 12s ... [not run] No encryption support for btrfs
generic/550 [not run] No encryption support for btrfs
generic/572 6s ... 6s
generic/573 4s ... 3s
generic/574 27s ... [not run] btrfs-corrupt-block utility required, skipped this test generic/575 10s ... 8s
generic/576 5s ... [not run] No encryption support for btrfs generic/577 4s ... 5s
generic/579 26s ... 24s
generic/580 5s ... [not run] No encryption support for btrfs generic/581 12s ... [not run] No encryption support for btrfs generic/582 12s ... [not run] No encryption support for btrfs generic/583 12s ... [not run] No encryption support for btrfs
generic/584 [not run] No encryption support for btrfs
generic/592 13s ... [not run] No encryption support for btrfs generic/593 4s ... [not run] No encryption support for btrfs generic/595 7s ... [not run] No encryption support for btrfs generic/602 13s ... [not run] No encryption support for btrfs generic/613 24s ... [not run] No encryption support for btrfs generic/621 9s ... [not run] No encryption support for btrfs
generic/624 3s ... 2s generic/625 4s ... 2s generic/692 5s ... 3s
generic/693 [not run] No encryption support for btrfs
generic/739 23s ... [not run] No encryption support for btrfs
Ran: btrfs/277 btrfs/290 btrfs/291 generic/395 generic/396 generic/397 generic/398 generic/399 generic/419 generic/421 generic/429 generic/435 generic/440 generic/548 generic/549 generic/550 generic/572 generic/573 generic/574 generic/575 generic/576 generic/577 generic/579 generic/580 generic/581 generic/582 generic/583 generic/584 generic/592 generic/593 generic/595 generic/602 generic/613 generic/621 generic/624 generic/625 generic/692 generic/693 generic/739 Not run: btrfs/277 btrfs/290 btrfs/291 generic/395 generic/396 generic/397 generic/398 generic/399 generic/419 generic/421 generic/429 generic/435 generic/440 generic/548 generic/549 generic/550 generic/574 generic/576 generic/580 generic/581 generic/582 generic/583 generic/584 generic/592 generic/593 generic/595 generic/602 generic/613 generic/621 generic/693 generic/739
Passed all 39 tests
---
Changes in v3:
- Stash offsets in struct super_operations.
- Link to v2: https://lore.kernel.org/[email protected]
Changes in v2:
- First full implementation.
- Link to v1: https://lore.kernel.org/[email protected]
---
Christian Brauner (13):
fs: add fscrypt offset
fs/crypto: use accessors
ext4: move fscrypt to filesystem inode
ubifs: move fscrypt to filesystem inode
f2fs: move fscrypt to filesystem inode
ceph: move fscrypt to filesystem inode
fs: drop i_crypt_info from struct inode
fs: add fsverity offset
fs/verity: use accessors
btrfs: move fsverity to filesystem inode
ext4: move fsverity to filesystem inode
f2fs: move fsverity to filesystem inode
fs: drop i_verity_info from struct inode
fs/btrfs/btrfs_inode.h | 3 +++ fs/btrfs/inode.c | 3 +++ fs/btrfs/super.c | 4 ++++ fs/ceph/super.c | 4 ++++ fs/crypto/bio.c | 2 +- fs/crypto/crypto.c | 8 ++++---- fs/crypto/fname.c | 8 ++++---- fs/crypto/fscrypt_private.h | 2 +- fs/crypto/hooks.c | 2 +- fs/crypto/inline_crypt.c | 10 +++++----- fs/crypto/keysetup.c | 27 ++++++++++++++++----------- fs/crypto/policy.c | 6 +++--- fs/ext4/ext4.h | 8 ++++++++ fs/ext4/mballoc-test.c | 4 ++++ fs/ext4/super.c | 14 ++++++++++++++ fs/f2fs/f2fs.h | 6 ++++++ fs/f2fs/super.c | 14 ++++++++++++++ fs/ubifs/super.c | 4 ++++ fs/ubifs/ubifs.h | 3 +++ fs/verity/enable.c | 2 +- fs/verity/fsverity_private.h | 2 +- fs/verity/open.c | 17 ++++++++++------- fs/verity/verify.c | 2 +- include/linux/fs.h | 10 ++-------- include/linux/fscrypt.h | 31 +++++++++++++++++++++++++++++-- include/linux/fsverity.h | 21 ++++++++++++++------- include/linux/netfs.h | 6 ++++++ 27 files changed, 166 insertions(+), 57 deletions(-)
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250715-work-inode-fscrypt-2b63b276e793
Christian Brauner
maintainerPATCH v3 1/13 fs: add fscrypt offset
Store the offset of the fscrypt data pointer from struct inode in struct super_operations. Both are embedded in the filesystem's private inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- include/linux/fs.h | 1 + 1 file changed, 1 insertion(+)
include/linux/fs.h +1 -0
@@ -2332,6 +2332,7 @@ enum freeze_holder { };struct super_operations { +ptrdiff_t i_fscrypt;struct inode *(*alloc_inode)(struct super_block *sb);void (*destroy_inode)(struct inode *);void (*free_inode)(struct inode *);
Signature · 1 line
2.47.2
Eric Biggers
maintainerRe: [PATCH v3 01/13] fs: add fscrypt offset
Quoted 16 lines · Christian Brauner
Store the offset of the fscrypt data pointer from struct inode in struct
super_operations. Both are embedded in the filesystem's private inode.This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
Signed-off-by Christian Brauner <[email protected]>--- include/linux/fs.h | 1 + 1 file changed, 1 insertion(+)include/linux/fs.h +0
-0
include/linux/fs.h enum freeze_holder { · line 2338
Quoted 7 lines
include/linux/fs.h +1
-0@@ -2332,6 +2332,7 @@ enum freeze_holder { };struct super_operations { +ptrdiff_t i_fscrypt;struct inode *(*alloc_inode)(struct super_block *sb);void (*destroy_inode)(struct inode *);void (*free_inode)(struct inode *);
If using inode_operations was ruled out, so we have to go through the super_block to get to an operations struct anyway, wouldn't it make more sense to use fscrypt_operations and fsverity_operations? They are accessible as inode->i_sb->s_cop and inode->i_sb->s_vop. Same number of dereferences as getting to inode->i_sb->s_op.
For the naming, how about fscrypt_operations::inode_info_offs and fsverity_operations::inode_info_offs?
- Eric
Christian Brauner
maintainerRe: [PATCH v3 01/13] fs: add fscrypt offset
Quoted 19 lines · Eric Biggers
Quoted 18 lines · Christian Brauner
Store the offset of the fscrypt data pointer from struct inode in struct
super_operations. Both are embedded in the filesystem's private inode.This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
Signed-off-by Christian Brauner <[email protected]>--- include/linux/fs.h | 1 + 1 file changed, 1 insertion(+)include/linux/fs.h +0
-0@@ -2332,6 +2332,7 @@ enum freeze_holder { };
Quoted 9 lines
include/linux/fs.h enum freeze_holder { · line 2338
Quoted 5 lines
include/linux/fs.h +1
-0struct super_operations { +ptrdiff_t i_fscrypt;struct inode *(*alloc_inode)(struct super_block *sb);void (*destroy_inode)(struct inode *);void (*free_inode)(struct inode *);If using
inode_operationswas ruled out, so we have to go through thesuper_blockto get to an operations struct anyway, wouldn't it make more sense to usefscrypt_operationsandfsverity_operations? They are
Good idea.
Quoted 2 lines
accessible as
inode->i_sb->s_copandinode->i_sb->s_vop. Same number of dereferences as getting toinode->i_sb->s_op.
I also like Al's idea to move the offset directly into struct super_block.
Hm, but conceptually moving it into the respective operations would make a lot more sense...
I'll just sketch both and see what feels cleaner.
Al Viro
maintainerRe: [PATCH v3 01/13] fs: add fscrypt offset
In reply to Christian BraunerQuoted 16 lines · Christian Brauner
Store the offset of the fscrypt data pointer from struct inode in struct
super_operations. Both are embedded in the filesystem's private inode.This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
Signed-off-by Christian Brauner <[email protected]>--- include/linux/fs.h | 1 + 1 file changed, 1 insertion(+)include/linux/fs.h +0
-0
include/linux/fs.h enum freeze_holder { · line 2335
Quoted 4 lines
include/linux/fs.h +1
-0@@ -2332,6 +2332,7 @@ enum freeze_holder { };struct super_operations { +ptrdiff_t i_fscrypt;
Umm... Why not put that into super_block itself?
Christian Brauner
maintainerPATCH v3 2/13 fs/crypto: use accessors
In reply to Christian BraunerUse accessor to get and set the fscrypt info from the filesystem. They can be removed once all filesystems have been converted to make room for fscrypt info in their own inodes.
--- fs/crypto/bio.c | 2 +- fs/crypto/crypto.c | 8 ++++---- fs/crypto/fname.c | 8 ++++---- fs/crypto/hooks.c | 2 +- fs/crypto/inline_crypt.c | 10 +++++----- fs/crypto/keysetup.c | 12 +++++++++--- fs/crypto/policy.c | 6 +++--- include/linux/fscrypt.h | 36 ++++++++++++++++++++++++++++++++++++ 8 files changed, 63 insertions(+), 21 deletions(-)
fs/crypto/bio.c +1 -1
@@ -111,7 +111,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,int fscrypt_zeroout_range (const struct inode *inode,pgoff_t lblk,sector_t pblk,unsigned int len) { -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits;const unsigned int du_per_page_bits =PAGE_SHIFT - du_bits;
fs/crypto/crypto.c +4 -4
@@ -181,7 +181,7 @@ struct page *fscrypt_encrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs, gfp_t gfp_flags) { const struct inode *inode = folio->mapping->host; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits;struct page *ciphertext_page;
@@ -241,7 +241,7 @@ int fscrypt_encrypt_block_inplace(const struct inode *inode, struct page *page, {if (WARN_ON_ONCE (inode->i_sb->s_cop->supports_subblock_data_units))return -EOPNOTSUPP ; -return fscrypt_crypt_data_unit (inode->i_crypt_info,FS_ENCRYPT , +return fscrypt_crypt_data_unit (fscrypt_get_inode_info_raw (inode),FS_ENCRYPT , lblk_num, page, page, len, offs, gfp_flags); }
@@ -265,7 +265,7 @@ int fscrypt_decrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs) {const struct inode *inode = folio->mapping->host; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits; u64 index = ((u64)folio->index << (PAGE_SHIFT - du_bits)) +
@@ -316,7 +316,7 @@ int fscrypt_decrypt_block_inplace(const struct inode *inode, struct page *page, {if (WARN_ON_ONCE (inode->i_sb->s_cop->supports_subblock_data_units))return -EOPNOTSUPP ; -return fscrypt_crypt_data_unit (inode->i_crypt_info,FS_DECRYPT , +return fscrypt_crypt_data_unit (fscrypt_get_inode_info_raw (inode),FS_DECRYPT , lblk_num, page, page, len, offs,GFP_NOFS ); }
fs/crypto/fname.c +4 -4
@@ -94,7 +94,7 @@ int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname, {struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait); -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;struct scatterlist sg;
@@ -151,7 +151,7 @@ static int fname_decrypt(const struct inode *inode,struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait);struct scatterlist src_sg, dst_sg; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;int res;
@@ -293,7 +293,7 @@ bool __fscrypt_fname_encrypted_size(const union fscrypt_policy *policy,bool fscrypt_fname_encrypted_size (const struct inode *inode,u32 orig_len,u32 max_len,u32 *encrypted_len_ret) { -return __fscrypt_fname_encrypted_size (&inode->i_crypt_info->ci_policy, +return __fscrypt_fname_encrypted_size (&fscrypt_get_inode_info_raw (inode)->ci_policy, orig_len, max_len, encrypted_len_ret); }
@@ -562,7 +562,7 @@ EXPORT_SYMBOL_GPL(fscrypt_match_name);*/ u64 fscrypt_fname_siphash (const struct inode *dir,const struct qstr *name) { -const struct fscrypt_inode_info *ci = dir->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (dir);WARN_ON_ONCE (!ci->ci_dirhash_key_initialized);
fs/crypto/hooks.c +1 -1
@@ -197,7 +197,7 @@ int fscrypt_prepare_setflags(struct inode *inode, err =fscrypt_require_key (inode);if (err)return err; - ci = inode->i_crypt_info; + ci =fscrypt_get_inode_info_raw (inode);if (ci->ci_policy.version !=FSCRYPT_POLICY_V2 )return -EINVAL ; mk = ci->ci_master_key;
fs/crypto/inline_crypt.c +5 -5
@@ -262,7 +262,7 @@ int fscrypt_derive_sw_secret(struct super_block *sb,bool __fscrypt_inode_uses_inline_crypto (const struct inode *inode) { -return inode->i_crypt_info->ci_inlinecrypt; +return fscrypt_get_inode_info_raw (inode)->ci_inlinecrypt; }EXPORT_SYMBOL_GPL (__fscrypt_inode_uses_inline_crypto);
@@ -306,7 +306,7 @@ void fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,if (!fscrypt_inode_uses_inline_crypto (inode))return ; - ci = inode->i_crypt_info; + ci =fscrypt_get_inode_info_raw (inode);fscrypt_generate_dun (ci, first_lblk, dun);bio_crypt_set_ctx (bio, ci->ci_enc_key.blk_key, dun, gfp_mask);
@@ -396,10 +396,10 @@ bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,* uses the same pointer. I.e., there's currently no need to support * merging requests where the keys are the same but the pointers differ. */ -if (bc->bc_key != inode->i_crypt_info->ci_enc_key.blk_key) +if (bc->bc_key !=fscrypt_get_inode_info_raw (inode)->ci_enc_key.blk_key)return false; -fscrypt_generate_dun (inode->i_crypt_info, next_lblk, next_dun); +fscrypt_generate_dun (fscrypt_get_inode_info_raw (inode), next_lblk, next_dun);return bio_crypt_dun_is_contiguous (bc, bio->bi_iter.bi_size, next_dun); }EXPORT_SYMBOL_GPL (fscrypt_mergeable_bio);
@@ -501,7 +501,7 @@ u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk, u64 nr_blocks)if (nr_blocks <=1 )return nr_blocks; - ci = inode->i_crypt_info; + ci =fscrypt_get_inode_info_raw (inode);if (!(fscrypt_policy_flags (&ci->ci_policy) &FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32 ))return nr_blocks;
fs/crypto/keysetup.c +9 -3
@@ -644,7 +644,7 @@ fscrypt_setup_encryption_info(struct inode *inode,* fscrypt_get_inode_info(). I.e., here we publish ->i_crypt_info with * a RELEASE barrier so that other tasks can ACQUIRE it. */ -if (cmpxchg_release (&inode->i_crypt_info,NULL , crypt_info) ==NULL ) { +if (fscrypt_set_inode_info (inode, crypt_info)) {/* * We won the race and set ->i_crypt_info to our crypt_info. * Now link it into the master key's inode list.
@@ -797,8 +797,14 @@ EXPORT_SYMBOL_GPL(fscrypt_prepare_new_inode);*/ void fscrypt_put_encryption_info (struct inode *inode) { -put_crypt_info (inode->i_crypt_info); - inode->i_crypt_info =NULL ; +struct fscrypt_inode_info **crypt_info; + +if (inode->i_sb->s_op->i_fscrypt) + crypt_info =fscrypt_addr (inode); +else + crypt_info = &inode->i_crypt_info; +put_crypt_info (*crypt_info); + *crypt_info =NULL ; }EXPORT_SYMBOL (fscrypt_put_encryption_info);
fs/crypto/policy.c +3 -3
@@ -725,7 +725,7 @@ const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir) err =fscrypt_require_key (dir);if (err)return ERR_PTR (err); -return &dir->i_crypt_info->ci_policy; +return &fscrypt_get_inode_info_raw (dir)->ci_policy; }return fscrypt_get_dummy_policy (dir->i_sb);
@@ -744,7 +744,7 @@ const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir)*/ int fscrypt_context_for_new_inode (void *ctx,struct inode *inode) { -struct fscrypt_inode_info *ci = inode->i_crypt_info; +struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);BUILD_BUG_ON (sizeof (union fscrypt_context ) !=FSCRYPT_SET_CONTEXT_MAX_SIZE );
@@ -769,7 +769,7 @@ EXPORT_SYMBOL_GPL(fscrypt_context_for_new_inode);*/ int fscrypt_set_context (struct inode *inode,void *fs_data) { -struct fscrypt_inode_info *ci = inode->i_crypt_info; +struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);union fscrypt_context ctx;int ctxsize;
include/linux/fscrypt.h +36 -0
@@ -195,6 +195,38 @@ struct fscrypt_operations {int fscrypt_d_revalidate (struct inode *dir,const struct qstr *name,struct dentry *dentry,unsigned int flags); +static inline struct fscrypt_inode_info **fscrypt_addr (const struct inode *inode) +{ +return ((void *)inode + inode->i_sb->s_op->i_fscrypt); +} + +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. +* 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 +* a RELEASE barrier so that other tasks can ACQUIRE it. +*/ + +if (inode->i_sb->s_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 ; +} + +static inline struct fscrypt_inode_info * +fscrypt_get_inode_info_raw (const struct inode *inode) +{ +if (inode->i_sb->s_op->i_fscrypt) +return *fscrypt_addr (inode); +return inode->i_crypt_info; +} +static inline struct fscrypt_inode_info *fscrypt_get_inode_info (const struct inode *inode) {
@@ -204,6 +236,10 @@ fscrypt_get_inode_info(const struct inode *inode)* 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_op->i_fscrypt) +return smp_load_acquire (fscrypt_addr (inode)); +return smp_load_acquire (&inode->i_crypt_info); }
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v3 3/13 ext4: move fscrypt to filesystem inode
In reply to Christian BraunerMove fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/ext4/ext4.h | 4 ++++ fs/ext4/mballoc-test.c | 4 ++++ fs/ext4/super.c | 7 +++++++ 3 files changed, 15 insertions(+)
fs/ext4/ext4.h +4 -0
@@ -1197,6 +1197,10 @@ struct ext4_inode_info {__u32 i_csum_seed;kprojid_t i_projid; + +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif };/*
fs/ext4/mballoc-test.c +4 -0
@@ -53,6 +53,10 @@ static void mbt_free_inode(struct inode *inode) }static const struct super_operations mbt_sops = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ext4_inode_info , i_fscrypt_info) - + offsetof(struct ext4_inode_info , vfs_inode), +#endif .alloc_inode = mbt_alloc_inode, .free_inode = mbt_free_inode, };
fs/ext4/super.c +7 -0
@@ -1412,6 +1412,9 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)INIT_WORK (&ei->i_rsv_conversion_work, ext4_end_io_rsv_work);ext4_fc_init_inode (&ei->vfs_inode);spin_lock_init (&ei->i_fc_lock); +#ifdef CONFIG_FS_ENCRYPTION + ei->i_fscrypt_info =NULL ; +#endif return &ei->vfs_inode; }
@@ -1607,6 +1610,10 @@ static const struct quotactl_ops ext4_qctl_operations = {#endif static const struct super_operations ext4_sops = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ext4_inode_info , i_fscrypt_info) - + offsetof(struct ext4_inode_info , vfs_inode), +#endif .alloc_inode = ext4_alloc_inode, .free_inode = ext4_free_in_core_inode, .destroy_inode = ext4_destroy_inode,
Signature · 1 line
2.47.2
Eric Biggers
maintainerRe: [PATCH v3 03/13] ext4: move fscrypt to filesystem inode
fs/ext4/ext4.h struct ext4_inode_info { · line 1203
Quoted 12 lines · Christian Brauner
fs/ext4/ext4.h +4
-0@@ -1197,6 +1197,10 @@ struct ext4_inode_info {__u32 i_csum_seed;kprojid_t i_projid; + +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif
Did you consider keeping the name as i_crypt_info instead of changing it to i_fscrypt_info? The rationale for i_crypt_info in the first place is that it's filesystem code, so fs is implied.
I see you also had to replace i_crypt_info with i_fscrypt_info in a bunch of comments. It might make more sense to rephrase those to not refer to the exact field name. E.g. instead of "Set up ->i_fscrypt_info", we could write "Set up the inode's fscrypt info".
- Eric
Christian Brauner
maintainerRe: [PATCH v3 03/13] ext4: move fscrypt to filesystem inode
Quoted 8 lines · Eric Biggers
Quoted 7 lines · Christian Brauner
fs/ext4/ext4.h +0
-0@@ -1197,6 +1197,10 @@ struct ext4_inode_info {__u32 i_csum_seed;
Quoted 9 lines
fs/ext4/ext4.h struct ext4_inode_info { · line 1203
Quoted 5 lines
fs/ext4/ext4.h +4
-0kprojid_t i_projid; + +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif Did you consider keeping the name as
i_crypt_infoinstead of changing it toi_fscrypt_info? The rationale fori_crypt_infoin the first place is that it's filesystem code, so fs is implied.
Ok.
Quoted 5 lines
I see you also had to replace
i_crypt_infowithi_fscrypt_infoin a bunch of comments. It might make more sense to rephrase those to not refer to the exact field name. E.g. instead of "Set up ->i_fscrypt_info", we could write "Set up the inode's fscrypt info".
Ok, I'll do that.
Christian Brauner
maintainerPATCH v3 4/13 ubifs: move fscrypt to filesystem inode
In reply to Christian BraunerMove fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/ubifs/super.c | 4 ++++ fs/ubifs/ubifs.h | 3 +++ 2 files changed, 7 insertions(+)
fs/ubifs/super.c +4 -0
@@ -2003,6 +2003,10 @@ static int ubifs_reconfigure(struct fs_context *fc) }const struct super_operations ubifs_super_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ubifs_inode , i_fscrypt_info) - + offsetof(struct ubifs_inode , vfs_inode), +#endif .alloc_inode = ubifs_alloc_inode, .free_inode = ubifs_free_inode, .put_super = ubifs_put_super,
fs/ubifs/ubifs.h +3 -0
@@ -416,6 +416,9 @@ struct ubifs_inode {pgoff_t read_in_a_row;int data_len;void *data; +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif };/**
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v3 5/13 f2fs: move fscrypt to filesystem inode
In reply to Christian BraunerMove fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/super.c | 7 +++++++ 2 files changed, 10 insertions(+)
fs/f2fs/f2fs.h +3 -0
@@ -905,6 +905,9 @@ struct f2fs_inode_info {unsigned int atomic_write_cnt;loff_t original_i_size;/* original i_size before atomic write */ +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info;/* filesystem encryption info */ +#endif }; static inline void get_read_extent_info(struct extent_info *ext,
fs/f2fs/super.c +7 -0
@@ -1453,6 +1453,9 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)/* Will be used by directory only */ fi->i_dir_level =F2FS_SB (sb)->dir_level; +#ifdef CONFIG_FS_ENCRYPTION + fi->i_fscrypt_info =NULL ; +#endif return &fi->vfs_inode; }
@@ -3246,6 +3249,10 @@ void f2fs_quota_off_umount(struct super_block *sb)#endif static const struct super_operations f2fs_sops = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct f2fs_inode_info , i_fscrypt_info) - + offsetof(struct f2fs_inode_info , vfs_inode), +#endif .alloc_inode = f2fs_alloc_inode, .free_inode = f2fs_free_inode, .drop_inode = f2fs_drop_inode,
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v3 6/13 ceph: move fscrypt to filesystem inode
In reply to Christian BraunerMove fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/ceph/super.c | 4 ++++ include/linux/netfs.h | 6 ++++++ 2 files changed, 10 insertions(+)
fs/ceph/super.c +4 -0
@@ -1039,6 +1039,10 @@ void ceph_umount_begin(struct super_block *sb) }static const struct super_operations ceph_super_ops = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ceph_inode_info, netfs.i_fscrypt_info) - + offsetof(struct ceph_inode_info, netfs.inode), +#endif .alloc_inode = ceph_alloc_inode, .free_inode = ceph_free_inode, .write_inode = ceph_write_inode,
include/linux/netfs.h +6 -0
@@ -57,6 +57,9 @@ typedef void (*netfs_io_terminated_t)(void *priv, ssize_t transferred_or_error);*/ struct netfs_inode {struct inode inode;/* The VFS inode */ +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif const struct netfs_request_ops *ops;#if IS_ENABLED (CONFIG_FSCACHE )struct fscache_cookie *cache;
@@ -503,6 +506,9 @@ static inline void netfs_inode_init(struct netfs_inode *ctx, ctx->zero_point = ctx->remote_i_size;mapping_set_release_always (ctx->inode.i_mapping); } +#ifdef CONFIG_FS_ENCRYPTION + ctx->i_fscrypt_info =NULL ; +#endif }/**
Signature · 1 line
2.47.2
Eric Biggers
maintainerRe: [PATCH v3 06/13] ceph: move fscrypt to filesystem inode
Quoted 42 lines · Christian Brauner
Move fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
Signed-off-by Christian Brauner <[email protected]>--- fs/ceph/super.c | 4 ++++ include/linux/netfs.h | 6 ++++++ 2 files changed, 10 insertions(+)fs/ceph/super.c +4
-0@@ -1039,6 +1039,10 @@ void ceph_umount_begin(struct super_block *sb) }static const struct super_operations ceph_super_ops = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ceph_inode_info, netfs.i_fscrypt_info) - + offsetof(struct ceph_inode_info, netfs.inode), +#endif .alloc_inode = ceph_alloc_inode, .free_inode = ceph_free_inode, .write_inode = ceph_write_inode,include/linux/netfs.h +3
-0@@ -57,6 +57,9 @@ typedef void (*netfs_io_terminated_t)(void *priv, ssize_t transferred_or_error);*/ struct netfs_inode {struct inode inode;/* The VFS inode */ +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif const struct netfs_request_ops *ops;#if IS_ENABLED (CONFIG_FSCACHE )struct fscache_cookie *cache;
include/linux/netfs.h static inline void netfs_inode_init(struct netfs_inode *ctx, · line 511
Quoted 6 lines
include/linux/netfs.h +3
-0@@ -503,6 +506,9 @@ static inline void netfs_inode_init(struct netfs_inode *ctx, ctx->zero_point = ctx->remote_i_size;mapping_set_release_always (ctx->inode.i_mapping); } +#ifdef CONFIG_FS_ENCRYPTION + ctx->i_fscrypt_info =NULL ; +#endif
Why netfs_inode instead of ceph_inode_info?
- Eric
Christian Brauner
maintainerRe: [PATCH v3 06/13] ceph: move fscrypt to filesystem inode
Quoted 43 lines · Eric Biggers
Quoted 42 lines · Christian Brauner
Move fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
Signed-off-by Christian Brauner <[email protected]>--- fs/ceph/super.c | 4 ++++ include/linux/netfs.h | 6 ++++++ 2 files changed, 10 insertions(+)fs/ceph/super.c +4
-0@@ -1039,6 +1039,10 @@ void ceph_umount_begin(struct super_block *sb) }static const struct super_operations ceph_super_ops = { +#ifdef CONFIG_FS_ENCRYPTION + .i_fscrypt = offsetof(struct ceph_inode_info, netfs.i_fscrypt_info) - + offsetof(struct ceph_inode_info, netfs.inode), +#endif .alloc_inode = ceph_alloc_inode, .free_inode = ceph_free_inode, .write_inode = ceph_write_inode,include/linux/netfs.h +3
-0@@ -57,6 +57,9 @@ typedef void (*netfs_io_terminated_t)(void *priv, ssize_t transferred_or_error);*/ struct netfs_inode {struct inode inode;/* The VFS inode */ +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_fscrypt_info; +#endif const struct netfs_request_ops *ops;#if IS_ENABLED (CONFIG_FSCACHE )struct fscache_cookie *cache;@@ -503,6 +506,9 @@ static inline void netfs_inode_init(struct netfs_inode *ctx,
Quoted 8 lines
include/linux/netfs.h static inline void netfs_inode_init(struct netfs_inode *ctx, · line 511
Quoted 6 lines
include/linux/netfs.h +3
-0ctx->zero_point = ctx->remote_i_size;mapping_set_release_always (ctx->inode.i_mapping); } +#ifdef CONFIG_FS_ENCRYPTION + ctx->i_fscrypt_info =NULL ; +#endif Why
netfs_inodeinstead ofceph_inode_info?
If we add asserts that struct inode must be located at the beginning of struct netfs_inode then I would feel comfortable doing that. I'll do that.
Christian Brauner
maintainerPATCH v3 7/13 fs: drop i_crypt_info from struct inode
In reply to Christian BraunerNow that all filesystems store the fscrypt data pointer in their private inode, drop the data pointer from struct inode itself freeing up 8 bytes.
--- 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(-)
fs/crypto/fscrypt_private.h +1 -1
@@ -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 {
fs/crypto/keysetup.c +12 -13
@@ -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_sb->s_op->i_fscrypt) +if (inode->i_sb->s_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);
include/linux/fs.h +0 -4
@@ -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
include/linux/fscrypt.h +6 -15
@@ -203,28 +203,20 @@ static inline struct fscrypt_inode_info **fscrypt_addr(const struct inode *inodestatic 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_sb->s_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_sb->s_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_sb->s_op->i_fscrypt)return smp_load_acquire (fscrypt_addr (inode)); - -return smp_load_acquire (&inode->i_crypt_info); +return NULL ; }/**
Signature · 1 line
2.47.2
Eric Biggers
maintainerRe: [PATCH v3 07/13] fs: drop i_crypt_info from struct inode
Quoted 5 lines · Christian Brauner
fs/crypto/keysetup.c +0
-1@@ -799,12 +799,11 @@ void fscrypt_put_encryption_info(struct inode *inode) {struct fscrypt_inode_info **crypt_info; -if (inode->i_sb->s_op->i_fscrypt)
fs/crypto/keysetup.c void fscrypt_put_encryption_info(struct inode *inode) · line 807
Quoted 10 lines
fs/crypto/keysetup.c +4
-4+if (inode->i_sb->s_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 ; + } }
This could use an IS_ENCRYPTED(inode) check at the beginning, to minimize the overhead on unencrypted files. Before we just loaded inode:i_crypt_info, but now that accessing the fscrypt_inode_info will be more expensive it would be worthwhile to check IS_ENCRYPTED() first.
Quoted 6 lines
include/linux/fscrypt.h +0
-1static 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
include/linux/fscrypt.h fscrypt_get_inode_info(const struct inode *inode) · line 234
Quoted 10 lines
include/linux/fscrypt.h +2
-2+* 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_sb->s_op->i_fscrypt)return smp_load_acquire (fscrypt_addr (inode)); - -return smp_load_acquire (&inode->i_crypt_info); +return NULL ;
The conditional here shouldn't be needed, since this should be called only on filesystems that support encryption. Did you find a case where it isn't?
- Eric
Christian Brauner
maintainerRe: [PATCH v3 07/13] fs: drop i_crypt_info from struct inode
Quoted 5 lines · Eric Biggers
Quoted 4 lines · Christian Brauner
fs/crypto/keysetup.c +0
-0@@ -799,12 +799,11 @@ void fscrypt_put_encryption_info(struct inode *inode) {struct fscrypt_inode_info **crypt_info;
Quoted 16 lines
fs/crypto/keysetup.c void fscrypt_put_encryption_info(struct inode *inode) · line 807
Quoted 11 lines
fs/crypto/keysetup.c +4
-5-if (inode->i_sb->s_op->i_fscrypt) +if (inode->i_sb->s_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 ; + } }This could use an
IS_ENCRYPTED(inode)check at the beginning, to minimize the overhead on unencrypted files. Before we just loaded inode:i_crypt_info, but now that accessing thefscrypt_inode_infowill be more expensive it would be worthwhile to checkIS_ENCRYPTED()first.
Done.
Quoted 12 lines
Quoted 12 lines
include/linux/fscrypt.h +1
-1static 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. */
Quoted 9 lines
include/linux/fscrypt.h fscrypt_get_inode_info(const struct inode *inode) · line 234
Quoted 5 lines
include/linux/fscrypt.h +1
-2if (inode->i_sb->s_op->i_fscrypt)return smp_load_acquire (fscrypt_addr (inode)); - -return smp_load_acquire (&inode->i_crypt_info); +return NULL ;The conditional here shouldn't be needed, since this should be called only on filesystems that support encryption. Did you find a case where it isn't?
Ok, if that can't happen let's still place a VFS_WARN_ON_ONCE() here so we catch bugs when CONFIG_DEBUG_VFS is set.
Christian Brauner
maintainerPATCH v3 8/13 fs: add fsverity offset
In reply to Christian BraunerStore the offset of the fsverity data pointer from struct inode in struct super_operations. Both are embedded in the filesystem's private inode.
This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
--- include/linux/fs.h | 1 + 1 file changed, 1 insertion(+)
include/linux/fs.h +1 -0
@@ -2329,6 +2329,7 @@ enum freeze_holder {struct super_operations {ptrdiff_t i_fscrypt; +ptrdiff_t i_fsverity;struct inode *(*alloc_inode)(struct super_block *sb);void (*destroy_inode)(struct inode *);void (*free_inode)(struct inode *);
Signature · 1 line
2.47.2
Al Viro
maintainerRe: [PATCH v3 08/13] fs: add fsverity offset
Quoted 6 lines · Christian Brauner
Store the offset of the fsverity data pointer from struct inode in struct
super_operations. Both are embedded in the filesystem's private inode.This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
Same point re store in super_block itself.
Christian Brauner
maintainerPATCH v3 9/13 fs/verity: use accessors
In reply to Christian BraunerUse accessor to get and set the verity info from the filesystem. They can be removed once all filesystems have been converted to make room for verity info in their own inodes.
--- fs/verity/open.c | 18 +++++++++++++++--- fs/verity/verify.c | 2 +- include/linux/fsverity.h | 9 ++++++++- 3 files changed, 24 insertions(+), 5 deletions(-)
fs/verity/open.c +15 -3
@@ -250,13 +250,20 @@ 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 (cmpxchg_release (&inode->i_verity_info,NULL , vi) !=NULL ) { + +if (inode->i_sb->s_op->i_fsverity) + p =cmpxchg_release (fsverity_addr (inode),NULL , vi); +else + p =cmpxchg_release (&inode->i_verity_info,NULL , vi); +if (p !=NULL ) {/* Lost the race, so free the fsverity_info we allocated. */ fsverity_free_info (vi);/*
@@ -402,8 +409,13 @@ EXPORT_SYMBOL_GPL(__fsverity_prepare_setattr);void __fsverity_cleanup_inode (struct inode *inode) { -fsverity_free_info (inode->i_verity_info); - inode->i_verity_info =NULL ; +struct fsverity_info **vi; + + vi =fsverity_addr (inode); +if (!*vi) + vi = &inode->i_verity_info; +fsverity_free_info (*vi); + *vi =NULL ; }EXPORT_SYMBOL_GPL (__fsverity_cleanup_inode);
fs/verity/verify.c +1 -1
@@ -247,7 +247,7 @@ verify_data_blocks(struct folio *data_folio, size_t len, size_t offset, unsigned long max_ra_pages) {struct inode *inode = data_folio->mapping->host; -struct fsverity_info *vi = inode->i_verity_info; +struct fsverity_info *vi =fsverity_get_info (inode);const unsigned int block_size = vi->tree_params.block_size;u64 pos = (u64 )data_folio->index <<PAGE_SHIFT ;
include/linux/fsverity.h +8 -1
@@ -124,6 +124,11 @@ struct fsverity_operations {#ifdef CONFIG_FS_VERITY +static inline struct fsverity_info **fsverity_addr (const struct inode *inode) +{ +return ((void *)inode + inode->i_sb->s_op->i_fsverity); +} +static inline struct fsverity_info *fsverity_get_info (const struct inode *inode) {/*
@@ -132,6 +137,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_op->i_fsverity) +return smp_load_acquire (fsverity_addr (inode));return smp_load_acquire (&inode->i_verity_info); }
@@ -160,7 +167,7 @@ void __fsverity_cleanup_inode(struct inode *inode);*/ static inline void fsverity_cleanup_inode (struct inode *inode) { -if (inode->i_verity_info) +if (inode->i_verity_info || inode->i_sb->s_op->i_fsverity)__fsverity_cleanup_inode (inode); }
Signature · 1 line
2.47.2
Eric Biggers
maintainerRe: [PATCH v3 09/13] fs/verity: use accessors
include/linux/fsverity.h void __fsverity_cleanup_inode(struct inode *inode); · line 171
Quoted 5 lines · Christian Brauner
static inline void
fsverity_cleanup_inode(struct inode *inode){include/linux/fsverity.h +1
-1-if (inode->i_verity_info) +if (inode->i_verity_info || inode->i_sb->s_op->i_fsverity)__fsverity_cleanup_inode (inode);
Similarly to fscrypt_put_encryption_info(): I think this should look like:
if (IS_VERITY(inode))
__fsverity_cleanup_inode(inode);i_verity_info != NULL implies IS_VERITY(), so that would work and avoid adding extra dereferences to non-verity files.
The converse isn't necessarily true, but that's okay as long as __fsverity_cleanup_inode() handles i_verity_info == NULL.
- Eric
Christian Brauner
maintainerRe: [PATCH v3 09/13] fs/verity: use accessors
Quoted 10 lines · Eric Biggers
include/linux/fsverity.h void __fsverity_cleanup_inode(struct inode *inode); · line 171
Quoted 5 lines · Christian Brauner
static inline void
fsverity_cleanup_inode(struct inode *inode){include/linux/fsverity.h +1
-1-if (inode->i_verity_info) +if (inode->i_verity_info || inode->i_sb->s_op->i_fsverity)__fsverity_cleanup_inode (inode);Similarly to
fscrypt_put_encryption_info(): I think this should look like:
Quoted 8 lines
if (IS_VERITY(inode)) __fsverity_cleanup_inode(inode);
i_verity_info!= NULL impliesIS_VERITY(), so that would work and avoid adding extra dereferences to non-verity files.The converse isn't necessarily true, but that's okay as long as
__fsverity_cleanup_inode()handlesi_verity_info== NULL.
Done.
Christian Brauner
maintainerPATCH v3 10/13 btrfs: move fsverity to filesystem inode
In reply to Christian BraunerMove fsverity data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/btrfs/btrfs_inode.h | 3 +++ fs/btrfs/inode.c | 3 +++ fs/btrfs/super.c | 4 ++++ 3 files changed, 10 insertions(+)
fs/btrfs/btrfs_inode.h +3 -0
@@ -339,6 +339,9 @@ struct btrfs_inode {struct rw_semaphore i_mmap_lock;struct inode vfs_inode; +#ifdef CONFIG_FS_VERITY +struct fsverity_info *i_fsverity_info; +#endif };static inline u64 btrfs_get_first_dir_index_to_log (const struct btrfs_inode *inode)
fs/btrfs/inode.c +3 -0
@@ -7873,6 +7873,9 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)INIT_LIST_HEAD (&ei->delalloc_inodes);INIT_LIST_HEAD (&ei->delayed_iput);init_rwsem (&ei->i_mmap_lock); +#ifdef CONFIG_FS_VERITY + ei->i_fsverity_info =NULL ; +#endif return inode; }
fs/btrfs/super.c +4 -0
@@ -2395,6 +2395,10 @@ static long btrfs_free_cached_objects(struct super_block *sb, struct shrink_cont }static const struct super_operations btrfs_super_ops = { +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct btrfs_inode , i_fsverity_info) - + offsetof(struct btrfs_inode , vfs_inode), +#endif .drop_inode = btrfs_drop_inode, .evict_inode = btrfs_evict_inode, .put_super = btrfs_put_super,
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v3 11/13 ext4: move fsverity to filesystem inode
In reply to Christian BraunerMove fsverity data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/ext4/ext4.h | 4 ++++ fs/ext4/super.c | 7 +++++++ 2 files changed, 11 insertions(+)
fs/ext4/ext4.h +4 -0
@@ -1201,6 +1201,10 @@ struct ext4_inode_info {#ifdef CONFIG_FS_ENCRYPTION struct fscrypt_inode_info *i_fscrypt_info;#endif + +#ifdef CONFIG_FS_VERITY +struct fsverity_info *i_fsverity_info; +#endif };/*
fs/ext4/super.c +7 -0
@@ -1414,6 +1414,9 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)spin_lock_init (&ei->i_fc_lock);#ifdef CONFIG_FS_ENCRYPTION ei->i_fscrypt_info =NULL ; +#endif +#ifdef CONFIG_FS_VERITY + ei->i_fsverity_info =NULL ;#endif return &ei->vfs_inode; }
@@ -1613,6 +1616,10 @@ static const struct super_operations ext4_sops = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct ext4_inode_info, i_fscrypt_info) - offsetof(struct ext4_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct ext4_inode_info, i_fsverity_info) - + offsetof(struct ext4_inode_info, vfs_inode), #endif .alloc_inode = ext4_alloc_inode, .free_inode = ext4_free_in_core_inode,
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v3 12/13 f2fs: move fsverity to filesystem inode
In reply to Christian BraunerMove fsverity data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/super.c | 7 +++++++ 2 files changed, 10 insertions(+)
fs/f2fs/f2fs.h +3 -0
@@ -908,6 +908,9 @@ struct f2fs_inode_info {#ifdef CONFIG_FS_ENCRYPTION struct fscrypt_inode_info *i_fscrypt_info;/* filesystem encryption info */ #endif +#ifdef CONFIG_FS_VERITY +struct fsverity_info *i_fsverity_info; +#endif }; static inline void get_read_extent_info(struct extent_info *ext,
fs/f2fs/super.c +7 -0
@@ -1456,6 +1456,9 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)#ifdef CONFIG_FS_ENCRYPTION fi->i_fscrypt_info =NULL ;#endif +#ifdef CONFIG_FS_VERITY + fi->i_fsverity_info =NULL ; +#endif return &fi->vfs_inode; }
@@ -3252,6 +3255,10 @@ static const struct super_operations f2fs_sops = {#ifdef CONFIG_FS_ENCRYPTION .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) - offsetof(struct f2fs_inode_info, vfs_inode), +#endif +#ifdef CONFIG_FS_VERITY + .i_fsverity = offsetof(struct f2fs_inode_info, i_fsverity_info) - + offsetof(struct f2fs_inode_info, vfs_inode), #endif .alloc_inode = f2fs_alloc_inode, .free_inode = f2fs_free_inode,
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v3 13/13 fs: drop i_verity_info from struct inode
In reply to Christian BraunerNow that all filesystems store the fsverity data pointer in their private inode, drop the data pointer from struct inode itself freeing up 8 bytes.
--- fs/verity/enable.c | 2 +- fs/verity/fsverity_private.h | 2 +- fs/verity/open.c | 19 +++++-------------- include/linux/fs.h | 4 ---- include/linux/fsverity.h | 14 +++++++------- 5 files changed, 14 insertions(+), 27 deletions(-)
fs/verity/enable.c +1 -1
@@ -287,7 +287,7 @@ static int enable_verity(struct file *filp,/* Successfully enabled verity */ /* -* Readers can start using ->i_verity_info immediately, so it +* Readers can start using ->i_fsverity_info immediately, so it * can't be rolled back once set. So don't set it until just * after the filesystem has successfully enabled verity. */
fs/verity/fsverity_private.h +1 -1
@@ -58,7 +58,7 @@ struct merkle_tree_params {* fsverity_info - cached verity metadata for an inode * * When a verity file is first opened, an instance of this struct is allocated -* and stored in ->i_verity_info; it remains until the inode is evicted. It +* and stored in ->i_fsverity_info; it remains until the inode is evicted. It * caches information about the Merkle tree that's needed to efficiently verify * data read from the file. It also caches the file digest. The Merkle tree * pages themselves are not cached here, but the filesystem may cache them.
fs/verity/open.c +5 -14
@@ -250,24 +250,17 @@ 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 +* Multiple tasks may race to set ->i_fsverity_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 +* fsverity_get_info(). I.e., here we publish ->i_fsverity_info with a * RELEASE barrier so that other tasks can ACQUIRE it. */ - -if (inode->i_sb->s_op->i_fsverity) - p =cmpxchg_release (fsverity_addr (inode),NULL , vi); -else - p =cmpxchg_release (&inode->i_verity_info,NULL , vi); -if (p !=NULL ) { +if (cmpxchg_release (fsverity_addr (inode),NULL , vi) !=NULL ) {/* Lost the race, so free the fsverity_info we allocated. */ fsverity_free_info (vi);/* -* Afterwards, the caller may access ->i_verity_info directly, +* Afterwards, the caller may access ->i_fsverity_info directly, * so make sure to ACQUIRE the winning fsverity_info. */ (void )fsverity_get_info (inode);
@@ -364,7 +357,7 @@ int fsverity_get_descriptor(struct inode *inode,return 0 ; } -/* Ensure the inode has an ->i_verity_info */ +/* Ensure the inode has an ->i_fsverity_info */ static int ensure_verity_info (struct inode *inode) {struct fsverity_info *vi =fsverity_get_info (inode);
@@ -412,8 +405,6 @@ void __fsverity_cleanup_inode(struct inode *inode)struct fsverity_info **vi; vi =fsverity_addr (inode); -if (!*vi) - vi = &inode->i_verity_info;fsverity_free_info (*vi); *vi =NULL ; }
include/linux/fs.h +0 -4
@@ -778,10 +778,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;
include/linux/fsverity.h +7 -7
@@ -133,13 +133,13 @@ static inline struct fsverity_info *fsverity_get_info(const struct inode *inode) {/* * Pairs with the cmpxchg_release() in fsverity_set_info(). -* I.e., another task may publish ->i_verity_info concurrently, +* I.e., another task may publish ->i_fsverity_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_sb->s_op->i_fsverity)return smp_load_acquire (fsverity_addr (inode)); -return smp_load_acquire (&inode->i_verity_info); +return NULL ; }/* enable.c */
@@ -163,11 +163,11 @@ void __fsverity_cleanup_inode(struct inode *inode);* fsverity_cleanup_inode() - free the inode's verity info, if present * @inode: an inode being evicted * -* Filesystems must call this on inode eviction to free ->i_verity_info. +* Filesystems must call this on inode eviction to free ->i_fsverity_info. */ static inline void fsverity_cleanup_inode (struct inode *inode) { -if (inode->i_verity_info || inode->i_sb->s_op->i_fsverity) +if (inode->i_sb->s_op->i_fsverity)__fsverity_cleanup_inode (inode); }
@@ -274,12 +274,12 @@ static inline bool fsverity_verify_page(struct page *page)* fsverity_active() - do reads from the inode need to go through fs-verity? * @inode: inode to check * -* This checks whether ->i_verity_info has been set. +* This checks whether ->i_fsverity_info has been set. * * Filesystems call this from ->readahead() to check whether the pages need to * be verified or not. Don't use IS_VERITY() for this purpose; it's subject to * a race condition where the file is being read concurrently with -* FS_IOC_ENABLE_VERITY completing. (S_VERITY is set before ->i_verity_info.) +* FS_IOC_ENABLE_VERITY completing. (S_VERITY is set before ->i_fsverity_info.) * * Return: true if reads need to go through fs-verity, otherwise false */
@@ -294,7 +294,7 @@ static inline bool fsverity_active(const struct inode *inode)* @filp: the struct file being set up * * When opening a verity file, deny the open if it is for writing. Otherwise, -* set up the inode's ->i_verity_info if not already done. +* set up the inode's ->i_fsverity_info if not already done. * * When combined with fscrypt, this must be called after fscrypt_file_open(). * Otherwise, we won't have the key set up to decrypt the verity metadata.
Signature · 1 line
2.47.2
Christian Brauner
maintainerv4 cover Move fscrypt and fsverity out of struct inode
In reply to Christian BraunerHey,
As discussed, this moves the fscrypt and fsverity pointers out of struct inode shrinking it by 16 bytes. The pointers move into the individual filesystems that actually do make use of them.
In order to find the fscrypt and fsverity data pointers offsets from the embedded struct inode in the filesystem's private inode data are stored in struct fscrypt_operations and struct fsverity_operations respectively. This means we get fast access to the data pointers without having to rely on indirect calls.
Thanks to everyone for the very helpful reviews! The two obvious suggestions other than moving it into struct super_operations were moving it directly into struct super_block and moving it into struct fscrypt_operations and struct fsverity_operations. I chose the latter as I think that's just cleaner.
Thanks!
Christian
Test results:
+ sudo ./check -g encrypt,verity
FSTYP -- ext4 PLATFORM -- Linux/x86_64 localhost 6.16.0-rc1-gaa8ca50672ad #275 SMP PREEMPT_DYNAMIC Fri Jun 5 15:58:00 CEST 2015 MKFS_OPTIONS -- -F /dev/nvme0n1p6
MOUNT_OPTIONS -- -o acl,user_xattr /dev/nvme0n1p6 /mnt/scratch
ext4/024 3s
generic/395 4s generic/396 3s generic/397 4s generic/398 4s generic/399 35s generic/419 4s generic/421 4s generic/429 14s generic/435 23s generic/440 4s generic/548 9s generic/549 9s generic/550 [not run] encryption policy '-c 9 -n 9 -f 0' is unusable; probably missing kernel crypto API support generic/572 6s generic/573 3s generic/574 38s generic/575 10s generic/576 5s generic/577 4s generic/579 25s generic/580 4s generic/581 11s generic/582 10s generic/583 10s generic/584 [not run] encryption policy '-c 9 -n 9 -v 2 -f 0' is unusable; probably missing kernel crypto API support generic/592 10s generic/593 4s generic/595 8s generic/602 11s generic/613 21s generic/621 9s generic/624 4s generic/625 4s generic/692 5s
generic/693 [not run] encryption policy '-c 1 -n 10 -v 2 -f 0' is unusable; probably missing kernel crypto API support
generic/739 18s
Ran: ext4/024 generic/395 generic/396 generic/397 generic/398 generic/399 generic/419 generic/421 generic/429 generic/435 generic/440 generic/548 generic/549 generic/550 generic/572 generic/573 generic/574 generic/575 generic/576 generic/577 generic/579 generic/580 generic/581 generic/582 generic/583 generic/584 generic/592 generic/593 generic/595 generic/602 generic/613 generic/621 generic/624 generic/625 generic/692 generic/693 generic/739 Not run: generic/550 generic/584 generic/693
Passed all 37 tests
+ sudo ./check -g encrypt,verity
FSTYP -- btrfs PLATFORM -- Linux/x86_64 localhost 6.16.0-rc1-gaa8ca50672ad #275 SMP PREEMPT_DYNAMIC Fri Jun 5 15:58:00 CEST 2015 MKFS_OPTIONS -- /dev/nvme0n1p6
MOUNT_OPTIONS -- /dev/nvme0n1p6 /mnt/scratch
btrfs/277 [not run] kernel does not support send stream 3 btrfs/290 [not run] btrfs-corrupt-block utility required, skipped this test btrfs/291 [not run] This test requires a valid $LOGWRITES_DEV
generic/395 4s ... [not run] No encryption support for btrfs generic/396 3s ... [not run] No encryption support for btrfs generic/397 4s ... [not run] No encryption support for btrfs generic/398 5s ... [not run] No encryption support for btrfs generic/399 35s ... [not run] No encryption support for btrfs generic/419 4s ... [not run] No encryption support for btrfs generic/421 4s ... [not run] No encryption support for btrfs generic/429 14s ... [not run] No encryption support for btrfs generic/435 23s ... [not run] No encryption support for btrfs generic/440 4s ... [not run] No encryption support for btrfs generic/548 9s ... [not run] No encryption support for btrfs generic/549 9s ... [not run] No encryption support for btrfs
generic/550 [not run] No encryption support for btrfs
generic/572 6s ... 7s
generic/573 3s ... 3s
generic/574 38s ... [not run] btrfs-corrupt-block utility required, skipped this test generic/575 10s ... 9s
generic/576 5s ... [not run] No encryption support for btrfs generic/577 4s ... 4s
generic/579 25s ... 24s
generic/580 4s ... [not run] No encryption support for btrfs generic/581 11s ... [not run] No encryption support for btrfs generic/582 10s ... [not run] No encryption support for btrfs generic/583 10s ... [not run] No encryption support for btrfs
generic/584 [not run] No encryption support for btrfs
generic/592 10s ... [not run] No encryption support for btrfs generic/593 4s ... [not run] No encryption support for btrfs generic/595 8s ... [not run] No encryption support for btrfs generic/602 11s ... [not run] No encryption support for btrfs generic/613 21s ... [not run] No encryption support for btrfs generic/621 9s ... [not run] No encryption support for btrfs
generic/624 4s ... 4s generic/625 4s ... 3s generic/692 5s ... 5s
generic/693 [not run] No encryption support for btrfs
generic/739 18s ... [not run] No encryption support for btrfs
Ran: btrfs/277 btrfs/290 btrfs/291 generic/395 generic/396 generic/397 generic/398 generic/399 generic/419 generic/421 generic/429 generic/435 generic/440 generic/548 generic/549 generic/550 generic/572 generic/573 generic/574 generic/575 generic/576 generic/577 generic/579 generic/580 generic/581 generic/582 generic/583 generic/584 generic/592 generic/593 generic/595 generic/602 generic/613 generic/621 generic/624 generic/625 generic/692 generic/693 generic/739 Not run: btrfs/277 btrfs/290 btrfs/291 generic/395 generic/396 generic/397 generic/398 generic/399 generic/419 generic/421 generic/429 generic/435 generic/440 generic/548 generic/549 generic/550 generic/574 generic/576 generic/580 generic/581 generic/582 generic/583 generic/584 generic/592 generic/593 generic/595 generic/602 generic/613 generic/621 generic/693 generic/739
Passed all 39 tests
+ sudo ./check -g encrypt,verity
FSTYP -- f2fs PLATFORM -- Linux/x86_64 localhost 6.16.0-rc1-gaa8ca50672ad #275 SMP PREEMPT_DYNAMIC Fri Jun 5 15:58:00 CEST 2015 MKFS_OPTIONS -- /dev/nvme0n1p6
MOUNT_OPTIONS -- -o acl,user_xattr /dev/nvme0n1p6 /mnt/scratch
f2fs/002 22s
generic/395 4s ... 4s generic/396 3s ... 3s generic/397 4s ... 4s generic/398 5s ... 5s
generic/399 35s ... 19s
generic/419 4s ... 4s
generic/421 4s ... 5s
generic/429 14s ... 14s
generic/435 23s ... 34s
generic/440 4s ... 5s generic/548 9s ... 12s generic/549 9s ... 12s
generic/550 [not run] encryption policy '-c 9 -n 9 -f 0' is unusable; probably missing kernel crypto API support
generic/572 7s ... 7s
generic/573 3s ... 4s
generic/574 38s ... 29s
generic/575 9s ... 10s generic/576 5s ... 5s generic/577 4s ... 4s generic/579 24s ... 25s generic/580 4s ... 3s generic/581 11s ... 8s generic/582 10s ... 9s generic/583 10s ... 9s
generic/584 [not run] encryption policy '-c 9 -n 9 -v 2 -f 0' is unusable; probably missing kernel crypto API support
generic/592 10s ... 9s
generic/593 4s ... 3s
generic/595 8s ... 7s
generic/602 11s ... 9s
generic/613 21s ... 18s
generic/621 9s ... 8s generic/624 4s ... 2s generic/625 3s ... 3s generic/692 5s ... 3s
generic/693 [not run] encryption policy '-c 1 -n 10 -v 2 -f 0' is unusable; probably missing kernel crypto API support
generic/739 18s ... 17s
Ran: f2fs/002 generic/395 generic/396 generic/397 generic/398 generic/399 generic/419 generic/421 generic/429 generic/435 generic/440 generic/548 generic/549 generic/550 generic/572 generic/573 generic/574 generic/575 generic/576 generic/577 generic/579 generic/580 generic/581 generic/582 generic/583 generic/584 generic/592 generic/593 generic/595 generic/602 generic/613 generic/621 generic/624 generic/625 generic/692 generic/693 generic/739 Not run: generic/550 generic/584 generic/693
Passed all 37 tests
---
Changes in v4:
- Stash offsets in struct fscrypt_operations and struct
fsverity_operations.
- Link to v3: https://lore.kernel.org/[email protected]
Changes in v3:
- Stash offsets in struct super_operations.
- Link to v2: https://lore.kernel.org/[email protected]
Changes in v2:
- First full implementation.
- Link to v1: https://lore.kernel.org/[email protected]
---
Christian Brauner (15):
fs: add fscrypt offset
fs/crypto: use accessors
ext4: move fscrypt to filesystem inode
ubifs: move fscrypt to filesystem inode
f2fs: move fscrypt to filesystem inode
ceph: move fscrypt to filesystem inode
fs: drop i_crypt_info from struct inode
fscrypt: rephrase documentation and comments
fs: add fsverity offset
fs/verity: use accessors
btrfs: move fsverity to filesystem inode
ext4: move fsverity to filesystem inode
f2fs: move fsverity to filesystem inode
fs: drop i_verity_info from struct inode
fsverity: rephrase documentation and comments
fs/btrfs/btrfs_inode.h | 3 +++ fs/btrfs/inode.c | 3 +++ fs/btrfs/verity.c | 4 ++++ fs/ceph/crypto.c | 4 ++++ fs/ceph/inode.c | 1 + fs/ceph/super.h | 1 + fs/crypto/bio.c | 2 +- fs/crypto/crypto.c | 8 ++++---- fs/crypto/fname.c | 8 ++++---- fs/crypto/fscrypt_private.h | 4 ++-- fs/crypto/hooks.c | 2 +- fs/crypto/inline_crypt.c | 10 +++++----- fs/crypto/keysetup.c | 44 +++++++++++++++++++++++++++----------------- fs/crypto/policy.c | 6 +++--- fs/ext4/crypto.c | 4 ++++ fs/ext4/ext4.h | 8 ++++++++ fs/ext4/super.c | 6 ++++++ fs/ext4/verity.c | 4 ++++ fs/f2fs/f2fs.h | 6 ++++++ fs/f2fs/super.c | 10 ++++++++++ fs/f2fs/verity.c | 4 ++++ fs/ubifs/crypto.c | 4 ++++ fs/ubifs/ubifs.h | 3 +++ fs/verity/enable.c | 6 +++--- fs/verity/fsverity_private.h | 9 +++++---- fs/verity/open.c | 25 ++++++++++++++++--------- fs/verity/verify.c | 2 +- include/linux/fs.h | 10 ---------- include/linux/fscrypt.h | 42 ++++++++++++++++++++++++++++++++++++++---- include/linux/fsverity.h | 34 +++++++++++++++++++++++++++------- include/linux/netfs.h | 7 +++++++ 31 files changed, 209 insertions(+), 75 deletions(-)
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250715-work-inode-fscrypt-2b63b276e793
Christian Brauner
maintainerPATCH v4 1/15 fs: add fscrypt offset
Store the offset of the fscrypt data pointer from struct inode in struct fscrypt_operations. Both are embedded in the filesystem's private inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- include/linux/fscrypt.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/fscrypt.h +5 -0
@@ -61,6 +61,11 @@ struct fscrypt_name {/* Crypto operations for filesystems */ struct fscrypt_operations { +/** +* The offset of struct fscrypt_inode_info from struct inode embedded +* in the filesystem's inode. +*/ +ptrdiff_t inode_info_offs;/* * If set, then fs/crypto/ will allocate a global bounce page pool the
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v4 2/15 fs/crypto: use accessors
In reply to Christian BraunerUse accessor to get and set the fscrypt info from the filesystem. They can be removed once all filesystems have been converted to make room for fscrypt info in their own inodes.
--- fs/crypto/bio.c | 2 +- fs/crypto/crypto.c | 8 ++++---- fs/crypto/fname.c | 8 ++++---- fs/crypto/hooks.c | 2 +- fs/crypto/inline_crypt.c | 10 +++++----- fs/crypto/keysetup.c | 12 +++++++++--- fs/crypto/policy.c | 6 +++--- include/linux/fscrypt.h | 36 ++++++++++++++++++++++++++++++++++++ 8 files changed, 63 insertions(+), 21 deletions(-)
fs/crypto/bio.c +1 -1
@@ -111,7 +111,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,int fscrypt_zeroout_range (const struct inode *inode,pgoff_t lblk,sector_t pblk,unsigned int len) { -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits;const unsigned int du_per_page_bits =PAGE_SHIFT - du_bits;
fs/crypto/crypto.c +4 -4
@@ -181,7 +181,7 @@ struct page *fscrypt_encrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs, gfp_t gfp_flags) { const struct inode *inode = folio->mapping->host; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits;struct page *ciphertext_page;
@@ -241,7 +241,7 @@ int fscrypt_encrypt_block_inplace(const struct inode *inode, struct page *page, {if (WARN_ON_ONCE (inode->i_sb->s_cop->supports_subblock_data_units))return -EOPNOTSUPP ; -return fscrypt_crypt_data_unit (inode->i_crypt_info,FS_ENCRYPT , +return fscrypt_crypt_data_unit (fscrypt_get_inode_info_raw (inode),FS_ENCRYPT , lblk_num, page, page, len, offs, gfp_flags); }
@@ -265,7 +265,7 @@ int fscrypt_decrypt_pagecache_blocks(struct folio *folio, size_t len, size_t offs) {const struct inode *inode = folio->mapping->host; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);const unsigned int du_bits = ci->ci_data_unit_bits;const unsigned int du_size =1U << du_bits; u64 index = ((u64)folio->index << (PAGE_SHIFT - du_bits)) +
@@ -316,7 +316,7 @@ int fscrypt_decrypt_block_inplace(const struct inode *inode, struct page *page, {if (WARN_ON_ONCE (inode->i_sb->s_cop->supports_subblock_data_units))return -EOPNOTSUPP ; -return fscrypt_crypt_data_unit (inode->i_crypt_info,FS_DECRYPT , +return fscrypt_crypt_data_unit (fscrypt_get_inode_info_raw (inode),FS_DECRYPT , lblk_num, page, page, len, offs,GFP_NOFS ); }
fs/crypto/fname.c +4 -4
@@ -94,7 +94,7 @@ int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname, {struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait); -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;struct scatterlist sg;
@@ -151,7 +151,7 @@ static int fname_decrypt(const struct inode *inode,struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait);struct scatterlist src_sg, dst_sg; -const struct fscrypt_inode_info *ci = inode->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;int res;
@@ -293,7 +293,7 @@ bool __fscrypt_fname_encrypted_size(const union fscrypt_policy *policy,bool fscrypt_fname_encrypted_size (const struct inode *inode,u32 orig_len,u32 max_len,u32 *encrypted_len_ret) { -return __fscrypt_fname_encrypted_size (&inode->i_crypt_info->ci_policy, +return __fscrypt_fname_encrypted_size (&fscrypt_get_inode_info_raw (inode)->ci_policy, orig_len, max_len, encrypted_len_ret); }
@@ -562,7 +562,7 @@ EXPORT_SYMBOL_GPL(fscrypt_match_name);*/ u64 fscrypt_fname_siphash (const struct inode *dir,const struct qstr *name) { -const struct fscrypt_inode_info *ci = dir->i_crypt_info; +const struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (dir);WARN_ON_ONCE (!ci->ci_dirhash_key_initialized);
fs/crypto/hooks.c +1 -1
@@ -197,7 +197,7 @@ int fscrypt_prepare_setflags(struct inode *inode, err =fscrypt_require_key (inode);if (err)return err; - ci = inode->i_crypt_info; + ci =fscrypt_get_inode_info_raw (inode);if (ci->ci_policy.version !=FSCRYPT_POLICY_V2 )return -EINVAL ; mk = ci->ci_master_key;
fs/crypto/inline_crypt.c +5 -5
@@ -262,7 +262,7 @@ int fscrypt_derive_sw_secret(struct super_block *sb,bool __fscrypt_inode_uses_inline_crypto (const struct inode *inode) { -return inode->i_crypt_info->ci_inlinecrypt; +return fscrypt_get_inode_info_raw (inode)->ci_inlinecrypt; }EXPORT_SYMBOL_GPL (__fscrypt_inode_uses_inline_crypto);
@@ -306,7 +306,7 @@ void fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,if (!fscrypt_inode_uses_inline_crypto (inode))return ; - ci = inode->i_crypt_info; + ci =fscrypt_get_inode_info_raw (inode);fscrypt_generate_dun (ci, first_lblk, dun);bio_crypt_set_ctx (bio, ci->ci_enc_key.blk_key, dun, gfp_mask);
@@ -396,10 +396,10 @@ bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,* uses the same pointer. I.e., there's currently no need to support * merging requests where the keys are the same but the pointers differ. */ -if (bc->bc_key != inode->i_crypt_info->ci_enc_key.blk_key) +if (bc->bc_key !=fscrypt_get_inode_info_raw (inode)->ci_enc_key.blk_key)return false; -fscrypt_generate_dun (inode->i_crypt_info, next_lblk, next_dun); +fscrypt_generate_dun (fscrypt_get_inode_info_raw (inode), next_lblk, next_dun);return bio_crypt_dun_is_contiguous (bc, bio->bi_iter.bi_size, next_dun); }EXPORT_SYMBOL_GPL (fscrypt_mergeable_bio);
@@ -501,7 +501,7 @@ u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk, u64 nr_blocks)if (nr_blocks <=1 )return nr_blocks; - ci = inode->i_crypt_info; + ci =fscrypt_get_inode_info_raw (inode);if (!(fscrypt_policy_flags (&ci->ci_policy) &FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32 ))return nr_blocks;
fs/crypto/keysetup.c +9 -3
@@ -644,7 +644,7 @@ fscrypt_setup_encryption_info(struct inode *inode,* fscrypt_get_inode_info(). I.e., here we publish ->i_crypt_info with * a RELEASE barrier so that other tasks can ACQUIRE it. */ -if (cmpxchg_release (&inode->i_crypt_info,NULL , crypt_info) ==NULL ) { +if (fscrypt_set_inode_info (inode, crypt_info)) {/* * We won the race and set ->i_crypt_info to our crypt_info. * Now link it into the master key's inode list.
@@ -797,8 +797,14 @@ EXPORT_SYMBOL_GPL(fscrypt_prepare_new_inode);*/ void fscrypt_put_encryption_info (struct inode *inode) { -put_crypt_info (inode->i_crypt_info); - inode->i_crypt_info =NULL ; +struct fscrypt_inode_info **crypt_info; + +if (inode->i_sb->s_cop->inode_info_offs) + crypt_info =fscrypt_addr (inode); +else + crypt_info = &inode->i_crypt_info; +put_crypt_info (*crypt_info); + *crypt_info =NULL ; }EXPORT_SYMBOL (fscrypt_put_encryption_info);
fs/crypto/policy.c +3 -3
@@ -725,7 +725,7 @@ const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir) err =fscrypt_require_key (dir);if (err)return ERR_PTR (err); -return &dir->i_crypt_info->ci_policy; +return &fscrypt_get_inode_info_raw (dir)->ci_policy; }return fscrypt_get_dummy_policy (dir->i_sb);
@@ -744,7 +744,7 @@ const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir)*/ int fscrypt_context_for_new_inode (void *ctx,struct inode *inode) { -struct fscrypt_inode_info *ci = inode->i_crypt_info; +struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);BUILD_BUG_ON (sizeof (union fscrypt_context ) !=FSCRYPT_SET_CONTEXT_MAX_SIZE );
@@ -769,7 +769,7 @@ EXPORT_SYMBOL_GPL(fscrypt_context_for_new_inode);*/ int fscrypt_set_context (struct inode *inode,void *fs_data) { -struct fscrypt_inode_info *ci = inode->i_crypt_info; +struct fscrypt_inode_info *ci =fscrypt_get_inode_info_raw (inode);union fscrypt_context ctx;int ctxsize;
include/linux/fscrypt.h +36 -0
@@ -200,6 +200,38 @@ struct fscrypt_operations {int fscrypt_d_revalidate (struct inode *dir,const struct qstr *name,struct dentry *dentry,unsigned int flags); +static inline struct fscrypt_inode_info **fscrypt_addr (const struct inode *inode) +{ +return ((void *)inode + inode->i_sb->s_cop->inode_info_offs); +} + +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. +* 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 +* a RELEASE barrier so that other tasks can ACQUIRE it. +*/ + +if (inode->i_sb->s_cop->inode_info_offs) + p =cmpxchg_release (fscrypt_addr (inode),NULL , crypt_info); +else + p =cmpxchg_release (&inode->i_crypt_info,NULL , crypt_info); +return p ==NULL ; +} + +static inline struct fscrypt_inode_info * +fscrypt_get_inode_info_raw (const struct inode *inode) +{ +if (inode->i_sb->s_cop->inode_info_offs) +return *fscrypt_addr (inode); +return inode->i_crypt_info; +} +static inline struct fscrypt_inode_info *fscrypt_get_inode_info (const struct inode *inode) {
@@ -209,6 +241,10 @@ fscrypt_get_inode_info(const struct inode *inode)* 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_cop->inode_info_offs) +return smp_load_acquire (fscrypt_addr (inode)); +return smp_load_acquire (&inode->i_crypt_info); }
Signature · 1 line
2.47.2
Eric Biggers
maintainerRe: [PATCH v4 02/15] fs/crypto: use accessors
Quoted 1 line · Christian Brauner
fs/crypto: use accessors
fscrypt: use accessors to get/set inode info pointer
Quoted 5 lines
Use accessor to get and set the fscrypt info from the filesystem. They can be removed once all filesystems have been converted to make room for fscrypt info in their own inodes.
Signed-off-by Christian Brauner <[email protected]>
It would make more sense for this to be patch 1.
Patch 2 then would be "fscrypt: add support for inode_info_offs", adding the field and the support for it in the accessors.
- Eric
Eric Biggers
maintainerRe: [PATCH v4 02/15] fs/crypto: use accessors
In reply to Christian BraunerQuoted 2 lines · Christian Brauner
They can be removed once all filesystems have been converted to make room for fscrypt info in their own inodes.
Also note that the accessors still exist at the end of the series. I'm not sure what the above sentence is trying to say.
fs/crypto/inline_crypt.c bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode, · line 404
Quoted 12 lines
fs/crypto/inline_crypt.c +2
-2@@ -396,10 +396,10 @@ bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,* uses the same pointer. I.e., there's currently no need to support * merging requests where the keys are the same but the pointers differ. */ -if (bc->bc_key != inode->i_crypt_info->ci_enc_key.blk_key) +if (bc->bc_key !=fscrypt_get_inode_info_raw (inode)->ci_enc_key.blk_key)return false; -fscrypt_generate_dun (inode->i_crypt_info, next_lblk, next_dun); +fscrypt_generate_dun (fscrypt_get_inode_info_raw (inode), next_lblk, next_dun);return bio_crypt_dun_is_contiguous (bc, bio->bi_iter.bi_size, next_dun); }
This function could use a 'ci' local variable now. It's not clear that the second fscrypt_get_inode_info_raw() will get optimized out.
- Eric
Christian Brauner
maintainerPATCH v4 3/15 ext4: move fscrypt to filesystem inode
In reply to Christian BraunerMove fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/ext4/crypto.c | 4 ++++ fs/ext4/ext4.h | 4 ++++ fs/ext4/super.c | 3 +++ 3 files changed, 11 insertions(+)
fs/ext4/crypto.c +4 -0
@@ -227,6 +227,10 @@ static bool ext4_has_stable_inodes(struct super_block *sb) }const struct fscrypt_operations ext4_cryptops = { +#ifdef CONFIG_FS_ENCRYPTION + .inode_info_offs = offsetof(struct ext4_inode_info , i_crypt_info) - + offsetof(struct ext4_inode_info , vfs_inode), +#endif .needs_bounce_pages =1 , .has_32bit_inodes =1 , .supports_subblock_data_units =1 ,
fs/ext4/ext4.h +4 -0
@@ -1197,6 +1197,10 @@ struct ext4_inode_info {__u32 i_csum_seed;kprojid_t i_projid; + +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_crypt_info; +#endif };/*
fs/ext4/super.c +3 -0
@@ -1412,6 +1412,9 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)INIT_WORK (&ei->i_rsv_conversion_work, ext4_end_io_rsv_work);ext4_fc_init_inode (&ei->vfs_inode);spin_lock_init (&ei->i_fc_lock); +#ifdef CONFIG_FS_ENCRYPTION + ei->i_crypt_info =NULL ; +#endif return &ei->vfs_inode; }
Signature · 1 line
2.47.2
Eric Biggers
maintainerRe: [PATCH v4 03/15] ext4: move fscrypt to filesystem inode
Quoted 1 line · Christian Brauner
ext4: move fscrypt to filesystem inode
ext4: move fscrypt_inode_info pointer to ext4_inode_info
Similarly in other patches. Calling the pointer the "fscrypt" (or the "fsverity") is kind of an abuse of terminology.
fs/ext4/crypto.c static bool ext4_has_stable_inodes(struct super_block *sb) · line 236
Quoted 8 lines
const struct
fscrypt_operationsext4_cryptops= {fs/ext4/crypto.c +4
-0+#ifdef CONFIG_FS_ENCRYPTION + .inode_info_offs = offsetof(struct ext4_inode_info, i_crypt_info) - + offsetof(struct ext4_inode_info, vfs_inode), +#endif .needs_bounce_pages = 1, .has_32bit_inodes = 1, .supports_subblock_data_units = 1,
No need for #ifdef CONFIG_FS_ENCRYPTION in this file, since it is compiled only when CONFIG_FS_ENCRYPTION=y. Similarly in other patches.
- Eric
Christian Brauner
maintainerPATCH v4 4/15 ubifs: move fscrypt to filesystem inode
In reply to Christian BraunerMove fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/ubifs/crypto.c | 4 ++++ fs/ubifs/ubifs.h | 3 +++ 2 files changed, 7 insertions(+)
fs/ubifs/crypto.c +4 -0
@@ -88,6 +88,10 @@ int ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn, }const struct fscrypt_operations ubifs_crypt_operations = { +#ifdef CONFIG_FS_ENCRYPTION + .inode_info_offs = offsetof(struct ubifs_inode , i_crypt_info) - + offsetof(struct ubifs_inode , vfs_inode), +#endif .legacy_key_prefix ="ubifs:" , .get_context = ubifs_crypt_get_context, .set_context = ubifs_crypt_set_context,
fs/ubifs/ubifs.h +3 -0
@@ -416,6 +416,9 @@ struct ubifs_inode {pgoff_t read_in_a_row;int data_len;void *data; +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_crypt_info; +#endif };/**
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v4 5/15 f2fs: move fscrypt to filesystem inode
In reply to Christian BraunerMove fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/super.c | 7 +++++++ 2 files changed, 10 insertions(+)
fs/f2fs/f2fs.h +3 -0
@@ -905,6 +905,9 @@ struct f2fs_inode_info {unsigned int atomic_write_cnt;loff_t original_i_size;/* original i_size before atomic write */ +#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_crypt_info;/* filesystem encryption info */ +#endif }; static inline void get_read_extent_info(struct extent_info *ext,
fs/f2fs/super.c +7 -0
@@ -1453,6 +1453,9 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)/* Will be used by directory only */ fi->i_dir_level =F2FS_SB (sb)->dir_level; +#ifdef CONFIG_FS_ENCRYPTION + fi->i_crypt_info =NULL ; +#endif return &fi->vfs_inode; }
@@ -3326,6 +3329,10 @@ static struct block_device **f2fs_get_devices(struct super_block *sb, }static const struct fscrypt_operations f2fs_cryptops = { +#ifdef CONFIG_FS_ENCRYPTION + .inode_info_offs = offsetof(struct f2fs_inode_info , i_crypt_info) - + offsetof(struct f2fs_inode_info , vfs_inode), +#endif .needs_bounce_pages =1 , .has_32bit_inodes =1 , .supports_subblock_data_units =1 ,
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v4 6/15 ceph: move fscrypt to filesystem inode
In reply to Christian BraunerMove fscrypt data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fscrypt data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/ceph/crypto.c | 4 ++++ fs/ceph/inode.c | 1 + fs/ceph/super.h | 1 + include/linux/netfs.h | 7 +++++++ 4 files changed, 13 insertions(+)
fs/ceph/crypto.c +4 -0
@@ -133,6 +133,10 @@ static const union fscrypt_policy *ceph_get_dummy_policy(struct super_block *sb) }static struct fscrypt_operations ceph_fscrypt_ops = { +#ifdef CONFIG_FS_ENCRYPTION + .inode_info_offs = offsetof(struct ceph_inode_info , i_crypt_info) - + offsetof(struct ceph_inode_info , netfs), +#endif .needs_bounce_pages =1 , .get_context = ceph_crypt_get_context, .set_context = ceph_crypt_set_context,
fs/ceph/inode.c +1 -0
@@ -665,6 +665,7 @@ struct inode *ceph_alloc_inode(struct super_block *sb) ci->i_work_mask =0 ;memset (&ci->i_btime,'\0' ,sizeof (ci->i_btime));#ifdef CONFIG_FS_ENCRYPTION + ci->i_crypt_info =NULL ; ci->fscrypt_auth =NULL ; ci->fscrypt_auth_len =0 ;#endif
fs/ceph/super.h +1 -0
@@ -463,6 +463,7 @@ struct ceph_inode_info {unsigned long i_work_mask;#ifdef CONFIG_FS_ENCRYPTION +struct fscrypt_inode_info *i_crypt_info;u32 fscrypt_auth_len;u32 fscrypt_file_len;u8 *fscrypt_auth;
include/linux/netfs.h +7 -0
@@ -73,6 +73,13 @@ struct netfs_inode {#define NETFS_ICTX_SINGLE_NO_UPLOAD 4/* Monolithic payload, cache but no upload */ }; +/* +* struct inode must be the first member so we can easily calculate offsets for +* e.g., fscrypt or fsverity when embedded in filesystem specific inodes. +*/ +static_assert(__same_type(((struct netfs_inode *)NULL)->inode, struct inode)); +static_assert (offsetof(struct netfs_inode , inode) ==0 ); +/* * A netfs group - for instance a ceph snap. This is marked on dirty pages and * pages marked with a group must be flushed before they can be written under
Signature · 1 line
2.47.2
Eric Biggers
maintainerRe: [PATCH v4 06/15] ceph: move fscrypt to filesystem inode
fs/ceph/crypto.c static const union fscrypt_policy *ceph_get_dummy_policy(struct super_block *sb) · line 139
Quoted 4 lines · Christian Brauner
fs/ceph/crypto.c +4
-0+#ifdef CONFIG_FS_ENCRYPTION + .inode_info_offs = offsetof(struct ceph_inode_info, i_crypt_info) - + offsetof(struct ceph_inode_info, netfs), +#endif
This should use the offset to the VFS inode:
offsetof(struct ceph_inode_info, netfs.inode)
include/linux/netfs.h struct netfs_inode { · line 81
Quoted 6 lines
include/linux/netfs.h +6
-0+/* +* struct inode must be the first member so we can easily calculate offsets for +* e.g., fscrypt or fsverity when embedded in filesystem specific inodes. +*/ +static_assert(__same_type(((struct netfs_inode *)NULL)->inode, struct inode)); +static_assert (offsetof(struct netfs_inode , inode) ==0 );
Then no need for this.
- Eric
Christian Brauner
maintainerRe: [PATCH v4 06/15] ceph: move fscrypt to filesystem inode
Quoted 10 lines · Eric Biggers
fs/ceph/crypto.c static const union fscrypt_policy *ceph_get_dummy_policy(struct super_block *sb) · line 139
Quoted 4 lines · Christian Brauner
fs/ceph/crypto.c +4
-0+#ifdef CONFIG_FS_ENCRYPTION + .inode_info_offs = offsetof(struct ceph_inode_info, i_crypt_info) - + offsetof(struct ceph_inode_info, netfs), +#endif This should use the offset to the VFS inode:
offsetof(struct ceph_inode_info, netfs.inode)
Quoted 8 lines
include/linux/netfs.h struct netfs_inode { · line 81
Quoted 6 lines
include/linux/netfs.h +6
-0+/* +* struct inode must be the first member so we can easily calculate offsets for +* e.g., fscrypt or fsverity when embedded in filesystem specific inodes. +*/ +static_assert(__same_type(((struct netfs_inode *)NULL)->inode, struct inode)); +static_assert (offsetof(struct netfs_inode , inode) ==0 );Then no need for this.
Ok.
Christian Brauner
maintainerPATCH v4 7/15 fs: drop i_crypt_info from struct inode
In reply to Christian BraunerNow that all filesystems store the fscrypt data pointer in their private inode, drop the data pointer from struct inode itself freeing up 8 bytes.
--- fs/crypto/keysetup.c | 9 +++++---- include/linux/fs.h | 5 ----- include/linux/fscrypt.h | 23 +++++++---------------- 3 files changed, 12 insertions(+), 25 deletions(-)
fs/crypto/keysetup.c +5 -4
@@ -799,10 +799,11 @@ void fscrypt_put_encryption_info(struct inode *inode) {struct fscrypt_inode_info **crypt_info; -if (inode->i_sb->s_cop->inode_info_offs) - crypt_info =fscrypt_addr (inode); -else - crypt_info = &inode->i_crypt_info; +if (!IS_ENCRYPTED (inode)) +return ; +VFS_WARN_ON_ONCE (!inode->i_sb->s_cop); +VFS_WARN_ON_ONCE (!inode->i_sb->s_cop->inode_info_offs); + crypt_info =fscrypt_addr (inode);put_crypt_info (*crypt_info); *crypt_info =NULL ; }
include/linux/fs.h +0 -5
@@ -72,7 +72,6 @@ struct swap_info_struct;struct seq_file ;struct workqueue_struct ;struct iov_iter ; -struct fscrypt_inode_info ;struct fscrypt_operations ;struct fsverity_info ;struct fsverity_operations ;
@@ -778,10 +777,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
include/linux/fscrypt.h +7 -16
@@ -208,28 +208,21 @@ static inline struct fscrypt_inode_info **fscrypt_addr(const struct inode *inodestatic 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. * 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 * a RELEASE barrier so that other tasks can ACQUIRE it. */ - -if (inode->i_sb->s_cop->inode_info_offs) - 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_sb->s_cop->inode_info_offs) -return *fscrypt_addr (inode); -return inode->i_crypt_info; +VFS_WARN_ON_ONCE (!inode->i_sb->s_cop); +VFS_WARN_ON_ONCE (!inode->i_sb->s_cop->inode_info_offs); +return *fscrypt_addr (inode); } static inline struct fscrypt_inode_info *
@@ -241,11 +234,9 @@ fscrypt_get_inode_info(const struct inode *inode)* 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_cop->inode_info_offs) -return smp_load_acquire (fscrypt_addr (inode)); - -return smp_load_acquire (&inode->i_crypt_info); +VFS_WARN_ON_ONCE (!inode->i_sb->s_cop); +VFS_WARN_ON_ONCE (!inode->i_sb->s_cop->inode_info_offs); +return smp_load_acquire (fscrypt_addr (inode)); }/**
Signature · 1 line
2.47.2
Eric Biggers
maintainerRe: [PATCH v4 07/15] fs: drop i_crypt_info from struct inode
Review
Quoted 2 lines · Christian Brauner
(quoted diff) +2
-0+ VFS_WARN_ON_ONCE(!inode->i_sb->s_cop); + VFS_WARN_ON_ONCE(!inode->i_sb->s_cop->inode_info_offs);
These warnings seem odd. The first is redundant with the fact that there would be a NULL dereference anyway. The second should probably be located in fscrypt_addr() so that it applies everywhere inode_info_offs is used.
- Eric
Christian Brauner
maintainerPATCH v4 8/15 fscrypt: rephrase documentation and comments
In reply to Christian BraunerNow that we moved fscrypt out of struct inode update the comments to not imply that it's still located in there.
--- fs/crypto/fscrypt_private.h | 4 ++-- fs/crypto/keysetup.c | 31 +++++++++++++++++-------------- include/linux/fscrypt.h | 16 +++++++++------- 3 files changed, 28 insertions(+), 23 deletions(-)
fs/crypto/fscrypt_private.h +2 -2
@@ -231,8 +231,8 @@ 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 -* inode is evicted. +* allocated and stored in the inode's fscrypt info. Once created, it remains +* until the inode is evicted. */ struct fscrypt_inode_info {
fs/crypto/keysetup.c +17 -14
@@ -639,15 +639,16 @@ fscrypt_setup_encryption_info(struct inode *inode, goto out;/* -* For existing inodes, multiple tasks may race to set ->i_crypt_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 -* a RELEASE barrier so that other tasks can ACQUIRE it. +* For existing inodes, multiple tasks may race to set the inode's +* fscrypt info. So use cmpxchg_release(). This pairs with the +* smp_load_acquire() in fscrypt_get_inode_info(). I.e., here we +* publish the inode's 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. -* Now link it into the master key's inode list. +* We won the race and set the inode's fscrypt info to our +* crypt_info. Now link it into the master key's inode list. */ if (mk) { crypt_info->ci_master_key = mk;
@@ -678,14 +679,16 @@ 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 the inode's fscrypt info, if it hasn't already been done. * -* Note: unless ->i_crypt_info is already set, this isn't %GFP_NOFS-safe. So -* generally this shouldn't be called from within a filesystem transaction. +* Note: unless the inode's 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 -* encryption key is unavailable. (Use fscrypt_has_encryption_key() to -* distinguish these cases.) Also can return another -errno code. +* Return: 0 if the inode's 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. */ int fscrypt_get_encryption_info (struct inode *inode,bool allow_unsupported) {
@@ -738,9 +741,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 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 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
include/linux/fscrypt.h +9 -7
@@ -209,10 +209,11 @@ static inline bool fscrypt_set_inode_info(struct inode *inode, struct fscrypt_inode_info *crypt_info) {/* -* For existing inodes, multiple tasks may race to set ->i_crypt_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 -* a RELEASE barrier so that other tasks can ACQUIRE it. +* For existing inodes, multiple tasks may race to set up the inode's +* fscrypt info. So use cmpxchg_release(). This pairs with the +* smp_load_acquire() in fscrypt_get_inode_info(). I.e., here we +* publish the inode's fscrypt info with a RELEASE barrier so that +* other tasks can ACQUIRE it. */ return cmpxchg_release (fscrypt_addr (inode),NULL , crypt_info) ==NULL ; }
@@ -230,9 +231,10 @@ 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 -* a RELEASE barrier. We need to use smp_load_acquire() here to safely -* ACQUIRE the memory the other task published. +* I.e., another task may publish the inode's fscrypt info +* concurrently, executing a RELEASE barrier. We need to use +* smp_load_acquire() here to safely ACQUIRE the memory the other task +* published. */ VFS_WARN_ON_ONCE (!inode->i_sb->s_cop);VFS_WARN_ON_ONCE (!inode->i_sb->s_cop->inode_info_offs);
Signature · 1 line
2.47.2
Eric Biggers
maintainerRe: [PATCH v4 08/15] fscrypt: rephrase documentation and comments
include/linux/fscrypt.h fscrypt_get_inode_info(const struct inode *inode) · line 238
Quoted 10 lines · Christian Brauner
include/linux/fscrypt.h +4
-3/* * Pairs with the cmpxchg_release() in fscrypt_setup_encryption_info(). -* I.e., another task may publish ->i_crypt_info concurrently, executing -* a RELEASE barrier. We need to use smp_load_acquire() here to safely -* ACQUIRE the memory the other task published. +* I.e., another task may publish the inode's fscrypt info +* concurrently, executing a RELEASE barrier. We need to use +* smp_load_acquire() here to safely ACQUIRE the memory the other task +* published. */
Please make sure to wrap at 80 columns, not 79.
- Eric
Christian Brauner
maintainerPATCH v4 9/15 fs: add fsverity offset
In reply to Christian BraunerStore the offset of the fsverity data pointer from struct inode in struct super_operations. Both are embedded in the filesystem's private inode.
This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
--- include/linux/fsverity.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/fsverity.h +5 -0
@@ -28,6 +28,11 @@/* Verity operations for filesystems */ struct fsverity_operations { +/** +* The offset of struct fsverity_info from struct inode embedded in +* the filesystem's inode. +*/ +ptrdiff_t inode_info_offs;/** * Begin enabling verity on the given file.
Signature · 1 line
2.47.2
Eric Biggers
maintainerRe: [PATCH v4 09/15] fs: add fsverity offset
include/linux/fsverity.h line 35
Quoted 5 lines · Christian Brauner
include/linux/fsverity.h +5
-0+/** +* The offset of struct fsverity_info from struct inode embedded in +* the filesystem's inode. +*/ +ptrdiff_t inode_info_offs;
It's the offset to the pointer to the struct fsverity_info, not the offset to the struct fsverity_info itself.
Similarly for the fscrypt patch.
- Eric
Christian Brauner
maintainerPATCH v4 10/15 fs/verity: use accessors
In reply to Christian BraunerUse accessor to get and set the verity info from the filesystem. They can be removed once all filesystems have been converted to make room for verity info in their own inodes.
--- fs/verity/open.c | 19 ++++++++++++++++--- fs/verity/verify.c | 2 +- include/linux/fsverity.h | 12 +++++++++++- 3 files changed, 28 insertions(+), 5 deletions(-)
fs/verity/open.c +16 -3
@@ -250,13 +250,20 @@ 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 (cmpxchg_release (&inode->i_verity_info,NULL , vi) !=NULL ) { + +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 ) {/* Lost the race, so free the fsverity_info we allocated. */ fsverity_free_info (vi);/*
@@ -402,8 +409,14 @@ EXPORT_SYMBOL_GPL(__fsverity_prepare_setattr);void __fsverity_cleanup_inode (struct inode *inode) { -fsverity_free_info (inode->i_verity_info); - inode->i_verity_info =NULL ; +struct fsverity_info **vi; + +if (inode->i_sb->s_vop->inode_info_offs) + vi =fsverity_addr (inode); +else + vi = &inode->i_verity_info; +fsverity_free_info (*vi); + *vi =NULL ; }EXPORT_SYMBOL_GPL (__fsverity_cleanup_inode);
fs/verity/verify.c +1 -1
@@ -247,7 +247,7 @@ verify_data_blocks(struct folio *data_folio, size_t len, size_t offset, unsigned long max_ra_pages) {struct inode *inode = data_folio->mapping->host; -struct fsverity_info *vi = inode->i_verity_info; +struct fsverity_info *vi =fsverity_get_info (inode);const unsigned int block_size = vi->tree_params.block_size;u64 pos = (u64 )data_folio->index <<PAGE_SHIFT ;
include/linux/fsverity.h +11 -1
@@ -129,14 +129,24 @@ struct fsverity_operations {#ifdef CONFIG_FS_VERITY +static inline struct fsverity_info **fsverity_addr (const struct inode *inode) +{ +return ((void *)inode + inode->i_sb->s_vop->inode_info_offs); +} +static inline struct fsverity_info *fsverity_get_info (const struct inode *inode) { +if (!inode->i_sb->s_vop) +return NULL ; +/* * Pairs with the cmpxchg_release() in fsverity_set_info(). * I.e., another task may publish ->i_verity_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_sb->s_vop->inode_info_offs) +return smp_load_acquire (fsverity_addr (inode));return smp_load_acquire (&inode->i_verity_info); }
@@ -165,7 +175,7 @@ void __fsverity_cleanup_inode(struct inode *inode);*/ static inline void fsverity_cleanup_inode (struct inode *inode) { -if (inode->i_verity_info) +if (IS_VERITY (inode))__fsverity_cleanup_inode (inode); }
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v4 11/15 btrfs: move fsverity to filesystem inode
In reply to Christian BraunerMove fsverity data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/btrfs/btrfs_inode.h | 3 +++ fs/btrfs/inode.c | 3 +++ fs/btrfs/verity.c | 4 ++++ 3 files changed, 10 insertions(+)
fs/btrfs/btrfs_inode.h +3 -0
@@ -339,6 +339,9 @@ struct btrfs_inode {struct rw_semaphore i_mmap_lock;struct inode vfs_inode; +#ifdef CONFIG_FS_VERITY +struct fsverity_info *i_verity_info; +#endif };static inline u64 btrfs_get_first_dir_index_to_log (const struct btrfs_inode *inode)
fs/btrfs/inode.c +3 -0
@@ -7873,6 +7873,9 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)INIT_LIST_HEAD (&ei->delalloc_inodes);INIT_LIST_HEAD (&ei->delayed_iput);init_rwsem (&ei->i_mmap_lock); +#ifdef CONFIG_FS_VERITY + ei->i_verity_info =NULL ; +#endif return inode; }
fs/btrfs/verity.c +4 -0
@@ -802,6 +802,10 @@ static int btrfs_write_merkle_tree_block(struct inode *inode, const void *buf, }const struct fsverity_operations btrfs_verityops = { +#ifdef CONFIG_FS_VERITY + .inode_info_offs = offsetof(struct btrfs_inode , i_verity_info) - + offsetof(struct btrfs_inode , vfs_inode), +#endif .begin_enable_verity = btrfs_begin_enable_verity, .end_enable_verity = btrfs_end_enable_verity, .get_verity_descriptor = btrfs_get_verity_descriptor,
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v4 12/15 ext4: move fsverity to filesystem inode
In reply to Christian BraunerMove fsverity data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/ext4/ext4.h | 4 ++++ fs/ext4/super.c | 3 +++ fs/ext4/verity.c | 4 ++++ 3 files changed, 11 insertions(+)
fs/ext4/ext4.h +4 -0
@@ -1201,6 +1201,10 @@ struct ext4_inode_info {#ifdef CONFIG_FS_ENCRYPTION struct fscrypt_inode_info *i_crypt_info;#endif + +#ifdef CONFIG_FS_VERITY +struct fsverity_info *i_verity_info; +#endif };/*
fs/ext4/super.c +3 -0
@@ -1414,6 +1414,9 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)spin_lock_init (&ei->i_fc_lock);#ifdef CONFIG_FS_ENCRYPTION ei->i_crypt_info =NULL ; +#endif +#ifdef CONFIG_FS_VERITY + ei->i_verity_info =NULL ;#endif return &ei->vfs_inode; }
fs/ext4/verity.c +4 -0
@@ -389,6 +389,10 @@ static int ext4_write_merkle_tree_block(struct inode *inode, const void *buf, }const struct fsverity_operations ext4_verityops = { +#ifdef CONFIG_FS_VERITY + .inode_info_offs = offsetof(struct ext4_inode_info , i_verity_info) - + offsetof(struct ext4_inode_info , vfs_inode), +#endif .begin_enable_verity = ext4_begin_enable_verity, .end_enable_verity = ext4_end_enable_verity, .get_verity_descriptor = ext4_get_verity_descriptor,
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v4 13/15 f2fs: move fsverity to filesystem inode
In reply to Christian BraunerMove fsverity data pointer into the filesystem's private inode and record the offset from the embedded struct inode.
This will allow us to drop the fsverity data pointer from struct inode itself and move it into the filesystem's inode.
--- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/super.c | 3 +++ fs/f2fs/verity.c | 4 ++++ 3 files changed, 10 insertions(+)
fs/f2fs/f2fs.h +3 -0
@@ -908,6 +908,9 @@ struct f2fs_inode_info {#ifdef CONFIG_FS_ENCRYPTION struct fscrypt_inode_info *i_crypt_info;/* filesystem encryption info */ #endif +#ifdef CONFIG_FS_VERITY +struct fsverity_info *i_verity_info; +#endif }; static inline void get_read_extent_info(struct extent_info *ext,
fs/f2fs/super.c +3 -0
@@ -1456,6 +1456,9 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)#ifdef CONFIG_FS_ENCRYPTION fi->i_crypt_info =NULL ;#endif +#ifdef CONFIG_FS_VERITY + fi->i_verity_info =NULL ; +#endif return &fi->vfs_inode; }
fs/f2fs/verity.c +4 -0
@@ -287,6 +287,10 @@ static int f2fs_write_merkle_tree_block(struct inode *inode, const void *buf, }const struct fsverity_operations f2fs_verityops = { +#ifdef CONFIG_FS_VERITY + .inode_info_offs = offsetof(struct f2fs_inode_info , i_verity_info) - + offsetof(struct f2fs_inode_info , vfs_inode), +#endif .begin_enable_verity = f2fs_begin_enable_verity, .end_enable_verity = f2fs_end_enable_verity, .get_verity_descriptor = f2fs_get_verity_descriptor,
Signature · 1 line
2.47.2
Christian Brauner
maintainerPATCH v4 14/15 fs: drop i_verity_info from struct inode
In reply to Christian BraunerNow that all filesystems store the fsverity data pointer in their private inode, drop the data pointer from struct inode itself freeing up 8 bytes.
--- fs/verity/open.c | 18 ++++++------------ include/linux/fs.h | 5 ----- include/linux/fsverity.h | 11 +++++++---- 3 files changed, 13 insertions(+), 21 deletions(-)
fs/verity/open.c +6 -12
@@ -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 ; }
include/linux/fs.h +0 -5
@@ -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;
include/linux/fsverity.h +7 -4
@@ -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 */
Signature · 1 line
2.47.2
Eric Biggers
maintainerRe: [PATCH v4 14/15] fs: drop i_verity_info from struct inode
include/linux/fsverity.h static inline struct fsverity_info **fsverity_addr(const struct inode *inode) · line 144
Quoted 9 lines · Christian Brauner
static inline struct
fsverity_info*fsverity_get_info(const struct inode *inode) {include/linux/fsverity.h +5
-1-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 ;
!IS_VERITY().
Also the proposed comment is misleading, since fsverity_get_digest() and bpf_get_fsverity_digest() similarly can call this on arbitrary inodes.
- Eric
Christian Brauner
maintainerPATCH v4 15/15 fsverity: rephrase documentation and comments
In reply to Christian BraunerNow that we moved fsverity out of struct inode update the comments to not imply that it's still located in there.
--- fs/verity/enable.c | 6 +++--- fs/verity/fsverity_private.h | 9 +++++---- fs/verity/open.c | 12 ++++++------ include/linux/fsverity.h | 12 +++++++----- 4 files changed, 21 insertions(+), 18 deletions(-)
fs/verity/enable.c +3 -3
@@ -287,9 +287,9 @@ static int enable_verity(struct file *filp,/* Successfully enabled verity */ /* -* Readers can start using ->i_verity_info immediately, so it -* can't be rolled back once set. So don't set it until just -* after the filesystem has successfully enabled verity. +* Readers can start using the inode's verity info immediately, +* so it can't be rolled back once set. So don't set it until +* just after the filesystem has successfully enabled verity. */ fsverity_set_info (inode, vi); }
fs/verity/fsverity_private.h +5 -4
@@ -58,10 +58,11 @@ struct merkle_tree_params {* fsverity_info - cached verity metadata for an inode * * When a verity file is first opened, an instance of this struct is allocated -* and stored in ->i_verity_info; it remains until the inode is evicted. It -* caches information about the Merkle tree that's needed to efficiently verify -* data read from the file. It also caches the file digest. The Merkle tree -* pages themselves are not cached here, but the filesystem may cache them. +* and stored in inode's verity pointer; it remains until the inode is evicted. +* It caches information about the Merkle tree that's needed to efficiently +* verify data read from the file. It also caches the file digest. The Merkle +* tree pages themselves are not cached here, but the filesystem may cache +* them. */ struct fsverity_info {struct merkle_tree_params tree_params;
fs/verity/open.c +6 -6
@@ -251,10 +251,10 @@ struct fsverity_info *fsverity_create_info(const struct inode *inode,void fsverity_set_info (struct inode *inode,struct fsverity_info *vi) {/* -* Multiple tasks may race to set ->i_verity_info, so use +* Multiple tasks may race to set the inode's 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. +* fsverity_get_info(). I.e., here we publish the inode's verity info +* with a RELEASE barrier so that other tasks can ACQUIRE it. */ VFS_WARN_ON_ONCE (!inode->i_sb->s_vop);VFS_WARN_ON_ONCE (!inode->i_sb->s_vop->inode_info_offs);
@@ -262,8 +262,8 @@ void fsverity_set_info(struct inode *inode, struct fsverity_info *vi)/* Lost the race, so free the fsverity_info we allocated. */ fsverity_free_info (vi);/* -* Afterwards, the caller may access ->i_verity_info directly, -* so make sure to ACQUIRE the winning fsverity_info. +* Afterwards, the caller may access the inode's verity info +* directly, so make sure to ACQUIRE the winning fsverity_info. */ (void )fsverity_get_info (inode); }
@@ -359,7 +359,7 @@ int fsverity_get_descriptor(struct inode *inode,return 0 ; } -/* Ensure the inode has an ->i_verity_info */ +/* Ensure the inode has fsverity info set */ static int ensure_verity_info (struct inode *inode) {struct fsverity_info *vi =fsverity_get_info (inode);
include/linux/fsverity.h +7 -5
@@ -145,7 +145,7 @@ static inline struct fsverity_info *fsverity_get_info(const struct inode *inode)/* * Pairs with the cmpxchg_release() in fsverity_set_info(). -* I.e., another task may publish ->i_verity_info concurrently, +* I.e., another task may publish the inode's verity info concurrently, * executing a RELEASE barrier. We need to use smp_load_acquire() here * to safely ACQUIRE the memory the other task published. */
@@ -174,7 +174,8 @@ void __fsverity_cleanup_inode(struct inode *inode);* fsverity_cleanup_inode() - free the inode's verity info, if present * @inode: an inode being evicted * -* Filesystems must call this on inode eviction to free ->i_verity_info. +* Filesystems must call this on inode eviction to free -the inode's +* verity info. */ static inline void fsverity_cleanup_inode (struct inode *inode) {
@@ -285,12 +286,13 @@ static inline bool fsverity_verify_page(struct page *page)* fsverity_active() - do reads from the inode need to go through fs-verity? * @inode: inode to check * -* This checks whether ->i_verity_info has been set. +* This checks whether the inode's verity info has been set. * * Filesystems call this from ->readahead() to check whether the pages need to * be verified or not. Don't use IS_VERITY() for this purpose; it's subject to * a race condition where the file is being read concurrently with -* FS_IOC_ENABLE_VERITY completing. (S_VERITY is set before ->i_verity_info.) +* FS_IOC_ENABLE_VERITY completing. (S_VERITY is set before the inode's +* verity info.) * * Return: true if reads need to go through fs-verity, otherwise false */
@@ -305,7 +307,7 @@ static inline bool fsverity_active(const struct inode *inode)* @filp: the struct file being set up * * When opening a verity file, deny the open if it is for writing. Otherwise, -* set up the inode's ->i_verity_info if not already done. +* set up the inode's verity info if not already done. * * When combined with fscrypt, this must be called after fscrypt_file_open(). * Otherwise, we won't have the key set up to decrypt the verity metadata.
Signature · 1 line
2.47.2
Re: [PATCH RFC DRAFT v2 00/13] Move fscrypt and fsverity out of struct inode
In reply to Christian BraunerQuoted 34 lines · Christian Brauner
Hey,
This is a POC. We're still discussing alternatives and I want to provide some useful data on what I learned about using offsets to drop fscrypt and fsverity from struct inode.
As discussed, this moves the fscrypt and fsverity pointers out of struct inode shrinking it by 16 bytes. The pointers move into the individual filesystems that actually do make use of them.
In order to find the fscrypt and fsverity data pointers offsets from the embedded struct inode in the filesystem's private inode data are stored in struct
inode_operations. This means we get fast access to the data pointers without having to rely on indirect calls.Bugs & Issues
=============* For fscrypt specifically the biggest issue is
fscrypt_prepare_new_inode()is called in filesystem's inode allocation functions beforeinode->i_opis set. That means the offset isn't available at the time when we would need it. To fix this we can set dummy encrypted inode operations for the respective filesystem with an initialized offset.* For both fscrypt & fsverity the biggest issue is that every codepath that currently calls
make_bad_inode()after having initialized fscrypt or fsverity data will overrideinode->i_opwithbad_inode_ops. At which point we're back to the previous problem: The offset isn't available anymore. So wheninode->i_sb->s_op->evict_inode()is calledfscrypt_put_encryption_info()doesn't have the offset available anymore and would corrupt the hell out of everything and also leak memory.
Quoted 9 lines
Obviously we could use a flag to detect a bad inodes instead of
i_opand let the filesystem assign it's own bad inode operations including the correct offset. Is it worth it?The other way I see we can fix this if we require fixed offsets in the filesystems inode so fscrypt and fsverity always now what offset to calculate. We could use two consecutive pointers at the beginning of the filesystem's inode. Does that always work and is it worth it?
We could store the offsets in the superblock. It's an extra pointer chase to get to the offset in that case, but presumably it should be in cache in most cases.
We could even do both -- store it in i_ops and somehow allow falling back to looking in the superblock when i_ops isn't set or when make_bad_inode has been called.
Quoted 114 lines
Thanks!
ChristianTest results:
+ sudo ./check -g encrypt,verity
FSTYP -- ext4 PLATFORM -- Linux/x86_64 localhost 6.16.0-rc1-g15c8eb9cdbd3 #267 SMP PREEMPT_DYNAMIC Fri Jun 5 15:58:00 CEST 2015 MKFS_OPTIONS -- -F /dev/nvme3n1p6
MOUNT_OPTIONS-- -o acl,user_xattr/dev/nvme3n1p6/mnt/scratchext4/024 3s ... 3s
generic/395 4s ... 4s generic/396 3s ... 3s generic/397 4s ... 3s generic/398 4s ... 4sgeneric/399 39s ... 35s
generic/419 3s ... 4s
generic/421 4s ... 4s
generic/429 14s ... 14s
generic/435 23s ... 22s
generic/440 3s ... 4s
generic/548 10s ... 9s
generic/549 9s ... 9s
generic/550 [not run] encryption policy '-c 9 -n 9 -f 0' is unusable; probably missing kernel crypto API supportgeneric/572 6s generic/573 4s generic/574 28s generic/575 9sgeneric/576 5s ... 4s
generic/577 4s
generic/579 24s
generic/580 4s ... 4s
generic/581 10s ... 11s
generic/582 10s ... 9s
generic/583 9s ... 9s
generic/584 [not run] encryption policy '-c 9 -n 9 -v 2 -f 0' is unusable; probably missing kernel crypto API support
generic/592 10s ... 10sgeneric/593 4s ... 4s generic/595 7s ... 7s generic/602 9s ... 10s generic/613 20s ... 20s generic/621 9s ... 9s generic/624 3s generic/625 3s generic/692 5sgeneric/693 [not run] encryption policy '-c 1 -n 10 -v 2 -f 0' is unusable; probably missing kernel crypto API support
generic/739 17s ... 18s
Ran: ext4/024 generic/395 generic/396 generic/397 generic/398 generic/399 generic/419 generic/421 generic/429 generic/435 generic/440 generic/548 generic/549 generic/550 generic/572 generic/573 generic/574 generic/575 generic/576 generic/577 generic/579 generic/580 generic/581 generic/582 generic/583 generic/584 generic/592 generic/593 generic/595 generic/602 generic/613 generic/621 generic/624 generic/625 generic/692 generic/693 generic/739 Not run: generic/550 generic/584 generic/693
Passed all 37 tests---
Changes in v2:
- First full implementation.
- Link to v1: https://lore.kernel.org/[email protected]---
Christian Brauner (13):
fs: add fscrypt offset
fs/crypto: use accessors
ext4: move fscrypt to filesystem inode
ubifs: move fscrypt to filesystem inode
f2fs: move fscrypt to filesystem inode
ceph: move fscrypt to filesystem inode
fs: dropi_crypt_infofrom struct inode
fs: add fsverity offset
fs/verity: use accessors
btrfs: move fsverity to filesystem inode
ext4: move fsverity to filesystem inode
f2fs: move fsverity to filesystem inode
fs: dropi_verity_infofrom struct inodefs/btrfs/btrfs_inode.h | 3 +++ fs/btrfs/inode.c | 20 ++++++++++++++++- fs/ceph/dir.c | 8 +++++++ fs/ceph/inode.c | 21 ++++++++++++++++++ fs/crypto/bio.c | 2 +- fs/crypto/crypto.c | 8 +++---- fs/crypto/fname.c | 8 +++---- fs/crypto/fscrypt_private.h | 2 +- fs/crypto/hooks.c | 2 +- fs/crypto/inline_crypt.c | 10 ++++----- fs/crypto/keysetup.c | 27 +++++++++++++---------- fs/crypto/policy.c | 6 ++--- fs/ext4/ext4.h | 9 ++++++++ fs/ext4/file.c | 8 +++++++ fs/ext4/ialloc.c | 2 ++ fs/ext4/inode.c | 1 + fs/ext4/mballoc.c | 3 +++ fs/ext4/namei.c | 23 ++++++++++++++++++++ fs/ext4/super.c | 6 +++++ fs/ext4/symlink.c | 24 ++++++++++++++++++++ fs/f2fs/f2fs.h | 7 ++++++ fs/f2fs/file.c | 8 +++++++ fs/f2fs/inode.c | 1 + fs/f2fs/namei.c | 41 ++++++++++++++++++++++++++++++++++ fs/f2fs/super.c | 6 +++++ fs/ubifs/dir.c | 52 ++++++++++++++++++++++++-------------------- fs/ubifs/file.c | 8 +++++++ fs/ubifs/super.c | 8 +++++++ fs/ubifs/ubifs.h | 3 +++ fs/verity/enable.c | 2 +- fs/verity/fsverity_private.h | 2 +- fs/verity/open.c | 18 +++++++++------ fs/verity/verify.c | 2 +- include/linux/fs.h | 10 ++------- include/linux/fscrypt.h | 31 ++++++++++++++++++++++++-- include/linux/fsverity.h | 21 ++++++++++++------ include/linux/netfs.h | 6 +++++ 37 files changed, 337 insertions(+), 82 deletions(-)---
base-commit:19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250715-work-inode-fscrypt-2b63b276e793
Signature · 1 line
Jeff Layton <[email protected]>