ext4 crypto: initialize crypto memory in early stage
PATCH 2/3 ext4 crypto: initialize crypto memory in early stage
Previously, crypto initialization was done at the first readpage time. It'd need to avoid large memory allocation at run time.
--- fs/ext4/crypto.c | 2 +- fs/ext4/crypto_key.c | 6 ------ fs/ext4/ext4.h | 4 ++-- fs/ext4/super.c | 8 ++++++++ 4 files changed, 11 insertions(+), 9 deletions(-)
fs/ext4/crypto.c +1 -1
@@ -256,7 +256,7 @@ void ext4_exit_crypto(void)* * Return: Zero on success, non-zero otherwise. */ -int ext4_init_crypto (void ) +int __init ext4_init_crypto (void ) {int i, res = -ENOMEM ;
fs/ext4/crypto_key.c +0 -6
@@ -113,12 +113,6 @@ int _ext4_get_encryption_info(struct inode *inode)struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb);int res; -if (!ext4_read_workqueue) { - res =ext4_init_crypto (); -if (res) -return res; - } -if (ei->i_crypt_info) {if (!ei->i_crypt_info->ci_keyring_key ||key_validate (ei->i_crypt_info->ci_keyring_key) ==0 )
fs/ext4/ext4.h +2 -2
@@ -2073,14 +2073,14 @@ int ext4_decrypt_one(struct inode *inode, struct page *page);int ext4_encrypted_zeroout (struct inode *inode,struct ext4_extent *ex);#ifdef CONFIG_EXT4_FS_ENCRYPTION -int ext4_init_crypto (void ); +int __init ext4_init_crypto (void );void ext4_exit_crypto (void );static inline int ext4_sb_has_crypto (struct super_block *sb) {return EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_ENCRYPT ); }#else -static inline int ext4_init_crypto (void ) {return 0 ; } +static inline int __init ext4_init_crypto (void ) {return 0 ; }static inline void ext4_exit_crypto (void ) { }static inline int ext4_sb_has_crypto (struct super_block *sb) {
fs/ext4/super.c +8 -0
@@ -5611,6 +5611,11 @@ static int __init ext4_init_fs(void) err =init_inodecache ();if (err) goto out1; + + err =ext4_init_crypto (); +if (err) + goto out0; +register_as_ext3 ();register_as_ext2 (); err =register_filesystem (&ext4_fs_type);
@@ -5621,6 +5626,8 @@ static int __init ext4_init_fs(void) out:unregister_as_ext2 ();unregister_as_ext3 (); +ext4_exit_crypto (); +out0:destroy_inodecache (); out1: ext4_mballoc_ready =0 ;
@@ -5646,6 +5653,7 @@ static void __exit ext4_exit_fs(void)ext4_destroy_lazyinit_thread ();unregister_as_ext2 ();unregister_as_ext3 (); +ext4_exit_crypto ();unregister_filesystem (&ext4_fs_type);destroy_inodecache ();ext4_exit_mballoc ();
Signature · 1 line
2.1.1
PATCH 3/3 ext4 crypto: use inode number for xts_tweak
This patch was from:
"f2fs crypto: use inode number for xts_tweak
Previoulsy when making xts_tweak, page->index was used.
But, when it supports fcollapse, the block address was moved, so that we can lose the original page->index, which causes decryption failure.
In order to avoid that, let's use the inode->i_ino for xfs_tweak hint."
--- fs/ext4/crypto.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
fs/ext4/crypto.c +7 -8
@@ -337,7 +337,6 @@ typedef enum {static int ext4_page_crypto (struct ext4_crypto_ctx *ctx,struct inode *inode,ext4_direction_t rw, -pgoff_t index,struct page *src_page,struct page *dest_page)
@@ -382,10 +381,10 @@ static int ext4_page_crypto(struct ext4_crypto_ctx *ctx, req,CRYPTO_TFM_REQ_MAY_BACKLOG |CRYPTO_TFM_REQ_MAY_SLEEP , ext4_crypt_complete, &ecr); -BUILD_BUG_ON (EXT4_XTS_TWEAK_SIZE <sizeof (index)); -memcpy (xts_tweak, &index,sizeof (index)); -memset (&xts_tweak[sizeof (index)],0 , -EXT4_XTS_TWEAK_SIZE -sizeof (index)); +BUILD_BUG_ON (EXT4_XTS_TWEAK_SIZE <sizeof (inode->i_ino)); +memcpy (xts_tweak, &inode->i_ino,sizeof (inode->i_ino)); +memset (&xts_tweak[sizeof (inode->i_ino)],0 , +EXT4_XTS_TWEAK_SIZE -sizeof (inode->i_ino));sg_init_table (&dst,1 );sg_set_page (&dst, dest_page,PAGE_CACHE_SIZE ,0 );
@@ -459,7 +458,7 @@ struct page *ext4_encrypt(struct inode *inode, ctx->flags |=EXT4_WRITE_PATH_FL ; ctx->w.bounce_page = ciphertext_page; ctx->w.control_page = plaintext_page; - err =ext4_page_crypto (ctx, inode,EXT4_ENCRYPT , plaintext_page->index, + err =ext4_page_crypto (ctx, inode,EXT4_ENCRYPT , plaintext_page, ciphertext_page);if (err) {ext4_release_crypto_ctx (ctx);
@@ -487,7 +486,7 @@ int ext4_decrypt(struct ext4_crypto_ctx *ctx, struct page *page)BUG_ON (!PageLocked (page));return ext4_page_crypto (ctx, page->mapping->host, -EXT4_DECRYPT , page->index, page, page); +EXT4_DECRYPT , page, page); }/*
@@ -541,7 +540,7 @@ int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex)while (len--) { err =ext4_page_crypto (ctx, inode,EXT4_ENCRYPT , lblk, -ZERO_PAGE (0 ), ciphertext_page); + ciphertext_page);if (err) goto errout;
Signature · 1 line
2.1.1
Re: [PATCH 3/3 v2] ext4 crypto: use inode number for xts_tweak
Sorry for the noise.
Chnage log from v1:
- fix wrong code changes.
-- >8 --
Quoted 1 line
From
2c5474450be7811d9553b3920fb0ed0681f9fdddMon Sep 17 00:00:00 2001
From: Jaegeuk Kim <[email protected]>
Date: Tue, 12 May 2015 14:14:49 -0700
Subject: [PATCH] ext4 crypto: use inode number for xts_tweak
This patch was from:
"f2fs crypto: use inode number for xts_tweak
Previoulsy when making xts_tweak, page->index was used.
But, when it supports fcollapse, the block address was moved, so that we can lose the original page->index, which causes decryption failure.
In order to avoid that, let's use the inode->i_ino for xfs_tweak hint."
--- fs/ext4/crypto.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
fs/ext4/crypto.c +7 -9
@@ -337,7 +337,6 @@ typedef enum {static int ext4_page_crypto (struct ext4_crypto_ctx *ctx,struct inode *inode,ext4_direction_t rw, -pgoff_t index,struct page *src_page,struct page *dest_page)
@@ -382,10 +381,10 @@ static int ext4_page_crypto(struct ext4_crypto_ctx *ctx, req,CRYPTO_TFM_REQ_MAY_BACKLOG |CRYPTO_TFM_REQ_MAY_SLEEP , ext4_crypt_complete, &ecr); -BUILD_BUG_ON (EXT4_XTS_TWEAK_SIZE <sizeof (index)); -memcpy (xts_tweak, &index,sizeof (index)); -memset (&xts_tweak[sizeof (index)],0 , -EXT4_XTS_TWEAK_SIZE -sizeof (index)); +BUILD_BUG_ON (EXT4_XTS_TWEAK_SIZE <sizeof (inode->i_ino)); +memcpy (xts_tweak, &inode->i_ino,sizeof (inode->i_ino)); +memset (&xts_tweak[sizeof (inode->i_ino)],0 , +EXT4_XTS_TWEAK_SIZE -sizeof (inode->i_ino));sg_init_table (&dst,1 );sg_set_page (&dst, dest_page,PAGE_CACHE_SIZE ,0 );
@@ -459,7 +458,7 @@ struct page *ext4_encrypt(struct inode *inode, ctx->flags |=EXT4_WRITE_PATH_FL ; ctx->w.bounce_page = ciphertext_page; ctx->w.control_page = plaintext_page; - err =ext4_page_crypto (ctx, inode,EXT4_ENCRYPT , plaintext_page->index, + err =ext4_page_crypto (ctx, inode,EXT4_ENCRYPT , plaintext_page, ciphertext_page);if (err) {ext4_release_crypto_ctx (ctx);
@@ -487,7 +486,7 @@ int ext4_decrypt(struct ext4_crypto_ctx *ctx, struct page *page)BUG_ON (!PageLocked (page));return ext4_page_crypto (ctx, page->mapping->host, -EXT4_DECRYPT , page->index, page, page); +EXT4_DECRYPT , page, page); }/*
@@ -512,7 +511,6 @@ int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex)struct ext4_crypto_ctx *ctx;struct page *ciphertext_page =NULL ;struct bio *bio; -ext4_lblk_t lblk = ex->ee_block;ext4_fsblk_t pblk =ext4_ext_pblock (ex);unsigned int len =ext4_ext_get_actual_len (ex);int err =0 ;
@@ -540,7 +538,7 @@ int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex) ctx->w.bounce_page = ciphertext_page;while (len--) { - err =ext4_page_crypto (ctx, inode,EXT4_ENCRYPT , lblk, + err =ext4_page_crypto (ctx, inode,EXT4_ENCRYPT ,ZERO_PAGE (0 ), ciphertext_page);if (err) goto errout;
Signature · 1 line
2.1.1