Lines Matching refs:ctx

67 void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx)  in ext4_release_crypto_ctx()  argument
71 if (ctx->bounce_page) { in ext4_release_crypto_ctx()
72 if (ctx->flags & EXT4_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL) in ext4_release_crypto_ctx()
73 __free_page(ctx->bounce_page); in ext4_release_crypto_ctx()
75 mempool_free(ctx->bounce_page, ext4_bounce_page_pool); in ext4_release_crypto_ctx()
76 ctx->bounce_page = NULL; in ext4_release_crypto_ctx()
78 ctx->control_page = NULL; in ext4_release_crypto_ctx()
79 if (ctx->flags & EXT4_CTX_REQUIRES_FREE_ENCRYPT_FL) { in ext4_release_crypto_ctx()
80 if (ctx->tfm) in ext4_release_crypto_ctx()
81 crypto_free_tfm(ctx->tfm); in ext4_release_crypto_ctx()
82 kfree(ctx); in ext4_release_crypto_ctx()
85 list_add(&ctx->free_list, &ext4_free_crypto_ctxs); in ext4_release_crypto_ctx()
99 struct ext4_crypto_ctx *ctx = kzalloc(sizeof(struct ext4_crypto_ctx), in ext4_alloc_and_init_crypto_ctx() local
102 if (!ctx) in ext4_alloc_and_init_crypto_ctx()
104 return ctx; in ext4_alloc_and_init_crypto_ctx()
118 struct ext4_crypto_ctx *ctx = NULL; in ext4_get_crypto_ctx() local
137 ctx = list_first_entry_or_null(&ext4_free_crypto_ctxs, in ext4_get_crypto_ctx()
139 if (ctx) in ext4_get_crypto_ctx()
140 list_del(&ctx->free_list); in ext4_get_crypto_ctx()
142 if (!ctx) { in ext4_get_crypto_ctx()
143 ctx = ext4_alloc_and_init_crypto_ctx(GFP_NOFS); in ext4_get_crypto_ctx()
144 if (IS_ERR(ctx)) { in ext4_get_crypto_ctx()
145 res = PTR_ERR(ctx); in ext4_get_crypto_ctx()
148 ctx->flags |= EXT4_CTX_REQUIRES_FREE_ENCRYPT_FL; in ext4_get_crypto_ctx()
150 ctx->flags &= ~EXT4_CTX_REQUIRES_FREE_ENCRYPT_FL; in ext4_get_crypto_ctx()
156 if (ctx->tfm && (ctx->mode != key->mode)) { in ext4_get_crypto_ctx()
157 crypto_free_tfm(ctx->tfm); in ext4_get_crypto_ctx()
158 ctx->tfm = NULL; in ext4_get_crypto_ctx()
159 ctx->mode = EXT4_ENCRYPTION_MODE_INVALID; in ext4_get_crypto_ctx()
161 if (!ctx->tfm) { in ext4_get_crypto_ctx()
164 ctx->tfm = crypto_ablkcipher_tfm( in ext4_get_crypto_ctx()
170 ctx->tfm = ERR_PTR(-ENOTSUPP); in ext4_get_crypto_ctx()
175 if (IS_ERR_OR_NULL(ctx->tfm)) { in ext4_get_crypto_ctx()
176 res = PTR_ERR(ctx->tfm); in ext4_get_crypto_ctx()
177 ctx->tfm = NULL; in ext4_get_crypto_ctx()
180 ctx->mode = key->mode; in ext4_get_crypto_ctx()
186 BUG_ON(ctx->bounce_page); in ext4_get_crypto_ctx()
190 if (!IS_ERR_OR_NULL(ctx)) in ext4_get_crypto_ctx()
191 ext4_release_crypto_ctx(ctx); in ext4_get_crypto_ctx()
192 ctx = ERR_PTR(res); in ext4_get_crypto_ctx()
194 return ctx; in ext4_get_crypto_ctx()
252 struct ext4_crypto_ctx *ctx; in ext4_init_crypto() local
254 ctx = ext4_alloc_and_init_crypto_ctx(GFP_KERNEL); in ext4_init_crypto()
255 if (IS_ERR(ctx)) { in ext4_init_crypto()
256 res = PTR_ERR(ctx); in ext4_init_crypto()
259 list_add(&ctx->free_list, &ext4_free_crypto_ctxs); in ext4_init_crypto()
279 struct ext4_crypto_ctx *ctx = in ext4_restore_control_page() local
285 ext4_release_crypto_ctx(ctx); in ext4_restore_control_page()
308 static int ext4_page_crypto(struct ext4_crypto_ctx *ctx, in ext4_page_crypto() argument
321 struct crypto_ablkcipher *atfm = __crypto_ablkcipher_cast(ctx->tfm); in ext4_page_crypto()
324 BUG_ON(!ctx->tfm); in ext4_page_crypto()
325 BUG_ON(ctx->mode != ei->i_encryption_key.mode); in ext4_page_crypto()
327 if (ctx->mode != EXT4_ENCRYPTION_MODE_AES_256_XTS) { in ext4_page_crypto()
330 __func__, ctx->mode); in ext4_page_crypto()
335 crypto_tfm_set_flags(ctx->tfm, CRYPTO_TFM_REQ_WEAK_KEY); in ext4_page_crypto()
405 struct ext4_crypto_ctx *ctx; in ext4_encrypt() local
411 ctx = ext4_get_crypto_ctx(inode); in ext4_encrypt()
412 if (IS_ERR(ctx)) in ext4_encrypt()
413 return (struct page *) ctx; in ext4_encrypt()
426 ctx->flags &= ~EXT4_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL; in ext4_encrypt()
428 ctx->flags |= EXT4_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL; in ext4_encrypt()
430 ctx->bounce_page = ciphertext_page; in ext4_encrypt()
431 ctx->control_page = plaintext_page; in ext4_encrypt()
432 err = ext4_page_crypto(ctx, inode, EXT4_ENCRYPT, plaintext_page->index, in ext4_encrypt()
435 ext4_release_crypto_ctx(ctx); in ext4_encrypt()
439 set_page_private(ciphertext_page, (unsigned long)ctx); in ext4_encrypt()
455 int ext4_decrypt(struct ext4_crypto_ctx *ctx, struct page *page) in ext4_decrypt() argument
459 return ext4_page_crypto(ctx, page->mapping->host, in ext4_decrypt()
471 struct ext4_crypto_ctx *ctx = ext4_get_crypto_ctx(inode); in ext4_decrypt_one() local
473 if (!ctx) in ext4_decrypt_one()
475 ret = ext4_decrypt(ctx, page); in ext4_decrypt_one()
476 ext4_release_crypto_ctx(ctx); in ext4_decrypt_one()
482 struct ext4_crypto_ctx *ctx; in ext4_encrypted_zeroout() local
492 ctx = ext4_get_crypto_ctx(inode); in ext4_encrypted_zeroout()
493 if (IS_ERR(ctx)) in ext4_encrypted_zeroout()
494 return PTR_ERR(ctx); in ext4_encrypted_zeroout()
506 ctx->flags &= ~EXT4_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL; in ext4_encrypted_zeroout()
508 ctx->flags |= EXT4_BOUNCE_PAGE_REQUIRES_FREE_ENCRYPT_FL; in ext4_encrypted_zeroout()
510 ctx->bounce_page = ciphertext_page; in ext4_encrypted_zeroout()
513 err = ext4_page_crypto(ctx, inode, EXT4_ENCRYPT, lblk, in ext4_encrypted_zeroout()
537 ext4_release_crypto_ctx(ctx); in ext4_encrypted_zeroout()