ext4 crypto: use per-inode tfm structure

As suggested by Herbert Xu, we shouldn't allocate a new tfm each time
we read or write a page.  Instead we can use a single tfm hanging off
the inode's crypt_info structure for all of our encryption needs for
that inode, since the tfm can be used by multiple crypto requests in
parallel.

Also use cmpxchg() to avoid races that could result in crypt_info
structure getting doubly allocated or doubly freed.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
Theodore Ts'o
2015-05-31 13:34:22 -04:00
parent 71dea01ea2
commit c936e1ec28
9 changed files with 96 additions and 156 deletions

View File

@@ -74,13 +74,11 @@ struct ext4_encryption_key {
} __attribute__((__packed__));
struct ext4_crypt_info {
unsigned char ci_size;
char ci_data_mode;
char ci_filename_mode;
char ci_flags;
struct crypto_ablkcipher *ci_ctfm;
struct key *ci_keyring_key;
char ci_raw[EXT4_MAX_KEY_SIZE];
char ci_master_key[EXT4_KEY_DESCRIPTOR_SIZE];
};
@@ -89,7 +87,6 @@ struct ext4_crypt_info {
#define EXT4_WRITE_PATH_FL 0x00000004
struct ext4_crypto_ctx {
struct crypto_tfm *tfm; /* Crypto API context */
union {
struct {
struct page *bounce_page; /* Ciphertext page */