# \[PATCH\] crypto: allow to assign gfp\_t for \_\_crypto\_alloc\_tfm

- From: Jaegeuk Kim \<jaegeuk@kernel.org\>
- Date: 2015-05-19 06:58:19 
- List: linux-arm-kernel
- Page: https://ratatoskr.run/linux-arm-kernel/2015/05/4496643
- Thread: https://ratatoskr.run/linux-crypto/2015/05/4496563/t.md

```text
On Tue, May 19, 2015 at 02:32:11PM +0800, Herbert Xu wrote:
> On Mon, May 18, 2015 at 11:24:30PM -0700, Jaegeuk Kim wrote:
> >
> > The call path in fs/ext4/crypto.c is:
> >  - writepage
> >   - ext4_encrypt
> >    - ext4_get_crypto_ctx
> >     - crypto_alloc_ablkcipher
> > 
> > AFAIK, this way can achieve to reduce memory footprint gracefully.
> > Just before submitting bios, fs allocates the required memory, and then end_io
> > will free them in pair.
> 
> So where does the key get generated? The crypto tfm should be
> allocated when you generate the key.

In fs/ext4/crypto.c,

 - writepage
   - ext4_encrypt
     - ext4_get_crypto_ctx
       - crypto_alloc_ablkcipher
     - ext4_page_crypto
       - crypto_ablkcipher_setkey
       - ablkcipher_request_alloc(GFP_NOFS)
       - ablkcipher_request_set_crypt(PAGE_CACHE_SIZE)
       - crypto_ablkcipher_encrypt

 - end_io
   - crypto_free_tfm

Thanks,

> 
> Cheers,
> -- 
> Email: Herbert Xu [ref]
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
```
