ext4 refuses encryption when the block size is larger than the page size, both at mount time and on a mounted filesystem, and refuses to load an existing encrypted inode. The checks exist because such a block size needs folios that cover a whole block, while file contents were encrypted page by page in the fs-layer path, which cannot handle a folio that covers several data units. Since commit 5acc6f649a68 ("fscrypt: Always use blk-crypto for contents on block-based filesystems") file contents are always encrypted through blk-crypto, and after the adaptations in the preceding patches, both inline encryption hardware and blk-crypto-fallback support data units larger than a page, so the checks can be removed. Encrypted filesystems still keep their folio order at s_min_folio_order; allowing large folios needs additional work and will be enabled later. Performance: Hardware: 96-core machine, 3.84T NVMe, 512G memory Filesystem: ext4, encryption on the fallback path Buffered sequential 1M writes and reads (1G, fsync) in MiB/s; medians of 3 runs. job 4k plain 4k enc 32k plain 32k enc 4k->32k --------- -------- -------- --------- ------- ------- seqwrite 1981 1044 2062 1399 +34% seqread 1139 931 1791 1793 +93% Signed-off-by: Baokun Li --- fs/ext4/crypto.c | 9 --------- fs/ext4/inode.c | 6 ------ fs/ext4/super.c | 25 +++---------------------- 3 files changed, 3 insertions(+), 37 deletions(-) diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c index 318b2eaea741..1a0fccb084ef 100644 --- a/fs/ext4/crypto.c +++ b/fs/ext4/crypto.c @@ -156,15 +156,6 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, if (ext4_test_inode_flag(inode, EXT4_INODE_DAX)) return -EOPNOTSUPP; - /* - * Encryption is not supported when the block size is larger - * than the page size. This is rejected at mount time by - * ext4_check_large_folio(), and this check here is for the case - * when the 'encrypt' feature is enabled on a mounted filesystem. - */ - if (inode->i_sb->s_blocksize > PAGE_SIZE) - return -EOPNOTSUPP; - res = ext4_convert_inline_data(inode); if (res) return res; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 31248fef8bce..26f0f9714f03 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5671,12 +5671,6 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, ret = -EFSCORRUPTED; goto bad_inode; } - if (IS_ENCRYPTED(inode) && sb->s_blocksize > PAGE_SIZE) { - ext4_error_inode(inode, function, line, 0, - "encrypted inode with block size larger than page size"); - ret = -EFSCORRUPTED; - goto bad_inode; - } ext4_set_inode_mapping_order(inode); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index bca0dc87d0b7..9cd5b7445a27 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5116,30 +5116,13 @@ static void ext4_set_max_mapping_order(struct super_block *sb) { struct ext4_sb_info *sbi = EXT4_SB(sb); - if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) + if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA || + ext4_has_feature_encrypt(sb)) sbi->s_max_folio_order = sbi->s_min_folio_order; else sbi->s_max_folio_order = EXT4_MAX_PAGECACHE_ORDER(sb); } -static int ext4_check_large_folio(struct super_block *sb) -{ - const char *err_str = NULL; - - if (ext4_has_feature_encrypt(sb)) - err_str = "encrypt"; - - if (!err_str) { - ext4_set_max_mapping_order(sb); - } else if (sb->s_blocksize > PAGE_SIZE) { - ext4_msg(sb, KERN_ERR, "bs(%lu) > ps(%lu) unsupported for %s", - sb->s_blocksize, PAGE_SIZE, err_str); - return -EINVAL; - } - - return 0; -} - static int ext4_load_super(struct super_block *sb, ext4_fsblk_t *lsb, int silent) { @@ -5418,9 +5401,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) ext4_apply_options(fc, sb); - err = ext4_check_large_folio(sb); - if (err < 0) - goto failed_mount; + ext4_set_max_mapping_order(sb); err = ext4_encoding_init(sb, es); if (err) -- 2.43.7