diff options
-rw-r--r-- | drivers/md/dm-crypt.c | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 2da9b9536afb..79316580c780 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c | |||
@@ -80,10 +80,11 @@ struct crypt_config { | |||
80 | sector_t start; | 80 | sector_t start; |
81 | 81 | ||
82 | /* | 82 | /* |
83 | * pool for per bio private data and | 83 | * pool for per bio private data, crypto requests and |
84 | * for encryption buffer pages | 84 | * encryption requeusts/buffer pages |
85 | */ | 85 | */ |
86 | mempool_t *io_pool; | 86 | mempool_t *io_pool; |
87 | mempool_t *req_pool; | ||
87 | mempool_t *page_pool; | 88 | mempool_t *page_pool; |
88 | struct bio_set *bs; | 89 | struct bio_set *bs; |
89 | 90 | ||
@@ -101,6 +102,22 @@ struct crypt_config { | |||
101 | sector_t iv_offset; | 102 | sector_t iv_offset; |
102 | unsigned int iv_size; | 103 | unsigned int iv_size; |
103 | 104 | ||
105 | /* | ||
106 | * Layout of each crypto request: | ||
107 | * | ||
108 | * struct ablkcipher_request | ||
109 | * context | ||
110 | * padding | ||
111 | * struct dm_crypt_request | ||
112 | * padding | ||
113 | * IV | ||
114 | * | ||
115 | * The padding is added so that dm_crypt_request and the IV are | ||
116 | * correctly aligned. | ||
117 | */ | ||
118 | unsigned int dmreq_start; | ||
119 | struct ablkcipher_request *req; | ||
120 | |||
104 | char cipher[CRYPTO_MAX_ALG_NAME]; | 121 | char cipher[CRYPTO_MAX_ALG_NAME]; |
105 | char chainmode[CRYPTO_MAX_ALG_NAME]; | 122 | char chainmode[CRYPTO_MAX_ALG_NAME]; |
106 | struct crypto_blkcipher *tfm; | 123 | struct crypto_blkcipher *tfm; |
@@ -377,6 +394,13 @@ static int crypt_convert_block(struct crypt_config *cc, | |||
377 | ctx->sector); | 394 | ctx->sector); |
378 | } | 395 | } |
379 | 396 | ||
397 | static void crypt_alloc_req(struct crypt_config *cc, | ||
398 | struct convert_context *ctx) | ||
399 | { | ||
400 | if (!cc->req) | ||
401 | cc->req = mempool_alloc(cc->req_pool, GFP_NOIO); | ||
402 | } | ||
403 | |||
380 | /* | 404 | /* |
381 | * Encrypt / decrypt data from one bio to another one (can be the same one) | 405 | * Encrypt / decrypt data from one bio to another one (can be the same one) |
382 | */ | 406 | */ |
@@ -882,6 +906,17 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
882 | goto bad_slab_pool; | 906 | goto bad_slab_pool; |
883 | } | 907 | } |
884 | 908 | ||
909 | cc->dmreq_start = sizeof(struct ablkcipher_request); | ||
910 | cc->dmreq_start = ALIGN(cc->dmreq_start, crypto_tfm_ctx_alignment()); | ||
911 | |||
912 | cc->req_pool = mempool_create_kmalloc_pool(MIN_IOS, cc->dmreq_start + | ||
913 | sizeof(struct dm_crypt_request) + cc->iv_size); | ||
914 | if (!cc->req_pool) { | ||
915 | ti->error = "Cannot allocate crypt request mempool"; | ||
916 | goto bad_req_pool; | ||
917 | } | ||
918 | cc->req = NULL; | ||
919 | |||
885 | cc->page_pool = mempool_create_page_pool(MIN_POOL_PAGES, 0); | 920 | cc->page_pool = mempool_create_page_pool(MIN_POOL_PAGES, 0); |
886 | if (!cc->page_pool) { | 921 | if (!cc->page_pool) { |
887 | ti->error = "Cannot allocate page mempool"; | 922 | ti->error = "Cannot allocate page mempool"; |
@@ -955,6 +990,8 @@ bad_device: | |||
955 | bad_bs: | 990 | bad_bs: |
956 | mempool_destroy(cc->page_pool); | 991 | mempool_destroy(cc->page_pool); |
957 | bad_page_pool: | 992 | bad_page_pool: |
993 | mempool_destroy(cc->req_pool); | ||
994 | bad_req_pool: | ||
958 | mempool_destroy(cc->io_pool); | 995 | mempool_destroy(cc->io_pool); |
959 | bad_slab_pool: | 996 | bad_slab_pool: |
960 | if (cc->iv_gen_ops && cc->iv_gen_ops->dtr) | 997 | if (cc->iv_gen_ops && cc->iv_gen_ops->dtr) |
@@ -975,8 +1012,12 @@ static void crypt_dtr(struct dm_target *ti) | |||
975 | destroy_workqueue(cc->io_queue); | 1012 | destroy_workqueue(cc->io_queue); |
976 | destroy_workqueue(cc->crypt_queue); | 1013 | destroy_workqueue(cc->crypt_queue); |
977 | 1014 | ||
1015 | if (cc->req) | ||
1016 | mempool_free(cc->req, cc->req_pool); | ||
1017 | |||
978 | bioset_free(cc->bs); | 1018 | bioset_free(cc->bs); |
979 | mempool_destroy(cc->page_pool); | 1019 | mempool_destroy(cc->page_pool); |
1020 | mempool_destroy(cc->req_pool); | ||
980 | mempool_destroy(cc->io_pool); | 1021 | mempool_destroy(cc->io_pool); |
981 | 1022 | ||
982 | kfree(cc->iv_mode); | 1023 | kfree(cc->iv_mode); |