diff mbox series

[PATCH-next,2/3] crypto: api - Provide gfp mask for tfm allocation

Message ID 20230614174643.3836590-3-dima@arista.com
State New
Headers show
Series crypto: cmac - clone fixes | expand

Commit Message

Dmitry Safonov June 14, 2023, 5:46 p.m. UTC
Use it straight away in crypto_clone_cipher(), as that is not meant to
sleep.

Signed-off-by: Dmitry Safonov <dima@arista.com>
---
 crypto/algapi.c   | 2 +-
 crypto/api.c      | 6 +++---
 crypto/cipher.c   | 2 +-
 crypto/internal.h | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

Comments

Eric Biggers June 15, 2023, 11:38 p.m. UTC | #1
On Wed, Jun 14, 2023 at 06:46:42PM +0100, Dmitry Safonov wrote:
> diff --git a/crypto/cipher.c b/crypto/cipher.c
> index d39ef5f72ab8..184188339a4a 100644
> --- a/crypto/cipher.c
> +++ b/crypto/cipher.c
> @@ -102,7 +102,7 @@ struct crypto_cipher *crypto_clone_cipher(struct crypto_cipher *cipher)
>  		return ERR_PTR(-ENOSYS);
>  
>  	ntfm = __crypto_alloc_tfm(alg, CRYPTO_ALG_TYPE_CIPHER,
> -				  CRYPTO_ALG_TYPE_MASK);
> +				  CRYPTO_ALG_TYPE_MASK, GFP_ATOMIC);
>  	if (IS_ERR(ntfm))
>  		return ERR_CAST(ntfm);
>  

Should crypto_clone_cipher() not have a gfp_t argument itself?

I'm wondering if any users of the crypto_clone_*() functions will need anything
other than GFP_ATOMIC, such as GFP_NOFS or GFP_NOIO.

FWIW, btrfs's support for fscrypt is planned to use per-extent keys.  It's
challenging to implement.  I've been thinking it might need a
crypto_clone_skcipher() function that it can use during filesystem I/O.  That
use case would want GFP_NOFS, I think.

- Eric
Herbert Xu June 16, 2023, 12:25 a.m. UTC | #2
On Thu, Jun 15, 2023 at 04:38:49PM -0700, Eric Biggers wrote:
>
> Should crypto_clone_cipher() not have a gfp_t argument itself?
> 
> I'm wondering if any users of the crypto_clone_*() functions will need anything
> other than GFP_ATOMIC, such as GFP_NOFS or GFP_NOIO.
> 
> FWIW, btrfs's support for fscrypt is planned to use per-extent keys.  It's
> challenging to implement.  I've been thinking it might need a
> crypto_clone_skcipher() function that it can use during filesystem I/O.  That
> use case would want GFP_NOFS, I think.

This is usually a small allocation (< 1 page).  But if you do
need it then we should add it to the generic cloning interface
crypto_clone_tfm.

Thanks,
diff mbox series

Patch

diff --git a/crypto/algapi.c b/crypto/algapi.c
index 5e7cd603d489..8d7d9cc008ff 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -798,7 +798,7 @@  struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
 	if (unlikely((alg->cra_flags ^ type) & mask))
 		goto out_put_alg;
 
-	tfm = __crypto_alloc_tfm(alg, type, mask);
+	tfm = __crypto_alloc_tfm(alg, type, mask, GFP_KERNEL);
 	if (IS_ERR(tfm))
 		goto out_put_alg;
 
diff --git a/crypto/api.c b/crypto/api.c
index a94bd0695719..54bf7c71b482 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -387,14 +387,14 @@  void crypto_shoot_alg(struct crypto_alg *alg)
 EXPORT_SYMBOL_GPL(crypto_shoot_alg);
 
 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
-				      u32 mask)
+				      u32 mask, gfp_t gfp)
 {
 	struct crypto_tfm *tfm = NULL;
 	unsigned int tfm_size;
 	int err = -ENOMEM;
 
 	tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask);
-	tfm = kzalloc(tfm_size, GFP_KERNEL);
+	tfm = kzalloc(tfm_size, gfp);
 	if (tfm == NULL)
 		goto out_err;
 
@@ -454,7 +454,7 @@  struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask)
 			goto err;
 		}
 
-		tfm = __crypto_alloc_tfm(alg, type, mask);
+		tfm = __crypto_alloc_tfm(alg, type, mask, GFP_KERNEL);
 		if (!IS_ERR(tfm))
 			return tfm;
 
diff --git a/crypto/cipher.c b/crypto/cipher.c
index d39ef5f72ab8..184188339a4a 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -102,7 +102,7 @@  struct crypto_cipher *crypto_clone_cipher(struct crypto_cipher *cipher)
 		return ERR_PTR(-ENOSYS);
 
 	ntfm = __crypto_alloc_tfm(alg, CRYPTO_ALG_TYPE_CIPHER,
-				  CRYPTO_ALG_TYPE_MASK);
+				  CRYPTO_ALG_TYPE_MASK, GFP_ATOMIC);
 	if (IS_ERR(ntfm))
 		return ERR_CAST(ntfm);
 
diff --git a/crypto/internal.h b/crypto/internal.h
index 8dd746b1130b..eba723a57689 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -103,7 +103,7 @@  void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
 void crypto_remove_final(struct list_head *list);
 void crypto_shoot_alg(struct crypto_alg *alg);
 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
-				      u32 mask);
+				      u32 mask, gfp_t gfp);
 void *crypto_create_tfm_node(struct crypto_alg *alg,
 			const struct crypto_type *frontend, int node);
 void *crypto_clone_tfm(const struct crypto_type *frontend,