[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201125211311.2179-2-iuliana.prodan@oss.nxp.com>
Date: Wed, 25 Nov 2020 23:13:08 +0200
From: "Iuliana Prodan (OSS)" <iuliana.prodan@....nxp.com>
To: Herbert Xu <herbert@...dor.apana.org.au>,
Ard Biesheuvel <ard.biesheuvel@...aro.org>,
"David S. Miller" <davem@...emloft.net>,
Horia Geanta <horia.geanta@....com>
Cc: Aymen Sghaier <aymen.sghaier@....com>,
Silvano Di Ninno <silvano.dininno@....com>,
Franck Lenormand <franck.lenormand@....com>,
linux-crypto@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-imx <linux-imx@....com>,
Iuliana Prodan <iuliana.prodan@....com>
Subject: [RFC PATCH 1/4] crypto: add CRYPTO_TFM_REQ_DMA flag
From: Iuliana Prodan <iuliana.prodan@....com>
The CRYPTO_TFM_REQ_DMA flag can be used by backend implementations to
indicate to crypto API the need to allocate GFP_DMA memory
for private contexts of the crypto requests.
For public key encryption add the needed functions to
set/get/clear flags.
Signed-off-by: Horia Geanta <horia.geanta@....com>
Signed-off-by: Iuliana Prodan <iuliana.prodan@....com>
---
include/crypto/aead.h | 4 ++++
include/crypto/akcipher.h | 21 +++++++++++++++++++++
include/crypto/hash.h | 4 ++++
include/crypto/skcipher.h | 4 ++++
include/linux/crypto.h | 1 +
5 files changed, 34 insertions(+)
diff --git a/include/crypto/aead.h b/include/crypto/aead.h
index fcc12c593ef8..ae2ef87cfb0d 100644
--- a/include/crypto/aead.h
+++ b/include/crypto/aead.h
@@ -416,6 +416,10 @@ static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm,
{
struct aead_request *req;
+ if (crypto_aead_reqsize(tfm) &&
+ (crypto_aead_get_flags(tfm) & CRYPTO_TFM_REQ_DMA))
+ gfp |= GFP_DMA;
+
req = kmalloc(sizeof(*req) + crypto_aead_reqsize(tfm), gfp);
if (likely(req))
diff --git a/include/crypto/akcipher.h b/include/crypto/akcipher.h
index 1d3aa252caba..c06c140d1b7a 100644
--- a/include/crypto/akcipher.h
+++ b/include/crypto/akcipher.h
@@ -158,6 +158,23 @@ static inline unsigned int crypto_akcipher_reqsize(struct crypto_akcipher *tfm)
return crypto_akcipher_alg(tfm)->reqsize;
}
+static inline u32 crypto_akcipher_get_flags(struct crypto_akcipher *tfm)
+{
+ return crypto_tfm_get_flags(crypto_akcipher_tfm(tfm));
+}
+
+static inline void crypto_akcipher_set_flags(struct crypto_akcipher *tfm,
+ u32 flags)
+{
+ crypto_tfm_set_flags(crypto_akcipher_tfm(tfm), flags);
+}
+
+static inline void crypto_akcipher_clear_flags(struct crypto_akcipher *tfm,
+ u32 flags)
+{
+ crypto_tfm_clear_flags(crypto_akcipher_tfm(tfm), flags);
+}
+
static inline void akcipher_request_set_tfm(struct akcipher_request *req,
struct crypto_akcipher *tfm)
{
@@ -193,6 +210,10 @@ static inline struct akcipher_request *akcipher_request_alloc(
{
struct akcipher_request *req;
+ if (crypto_akcipher_reqsize(tfm) &&
+ (crypto_akcipher_get_flags(tfm) & CRYPTO_TFM_REQ_DMA))
+ gfp |= GFP_DMA;
+
req = kmalloc(sizeof(*req) + crypto_akcipher_reqsize(tfm), gfp);
if (likely(req))
akcipher_request_set_tfm(req, tfm);
diff --git a/include/crypto/hash.h b/include/crypto/hash.h
index af2ff31ff619..cb28be54569a 100644
--- a/include/crypto/hash.h
+++ b/include/crypto/hash.h
@@ -599,6 +599,10 @@ static inline struct ahash_request *ahash_request_alloc(
{
struct ahash_request *req;
+ if (crypto_ahash_reqsize(tfm) &&
+ (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_REQ_DMA))
+ gfp |= GFP_DMA;
+
req = kmalloc(sizeof(struct ahash_request) +
crypto_ahash_reqsize(tfm), gfp);
diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h
index 6a733b171a5d..3c598b56628b 100644
--- a/include/crypto/skcipher.h
+++ b/include/crypto/skcipher.h
@@ -493,6 +493,10 @@ static inline struct skcipher_request *skcipher_request_alloc(
{
struct skcipher_request *req;
+ if (crypto_skcipher_reqsize(tfm) &&
+ (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_REQ_DMA))
+ gfp |= GFP_DMA;
+
req = kmalloc(sizeof(struct skcipher_request) +
crypto_skcipher_reqsize(tfm), gfp);
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index ef90e07c9635..87d7f0563c13 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -141,6 +141,7 @@
#define CRYPTO_TFM_REQ_FORBID_WEAK_KEYS 0x00000100
#define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200
#define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400
+#define CRYPTO_TFM_REQ_DMA 0x00000800
/*
* Miscellaneous stuff.
--
2.17.1
Powered by blists - more mailing lists