crypto: Add EIP-93 crypto engine support
Subsystems (5)
Christian Marangi
maintainerv8 cover crypto: Add EIP-93 crypto engine support
This small series add support for the Inside Secure EIP-93. This is a predecessor of the current supported EIP197. It doesn't require a firmware but instead it's embedded in the SoC.
First patch extend guard for spinlock_bh.
The other actually implement Documentation and Driver.
The Driver pass all the normal selft test for the supported algo and also pass the EXTRA test with fuzz_iterations set to 10000.
Changes v8:
- Rework export and update to not sleep on exporting state (consume pending packet in update and return -EINPROGRESS)
Changes v7:
- Fix copypaste error in __eip93_hash_init
- Rework import/export to actually export the partial hash (we actually unmap DMA on export)
- Rename no_finalize variable to better partial_hash
- Rename 3rd commit title and drop Mediatek from title.
- Add Cover Letter
- Add Reviewed-by to DT commit
(cumulative changes from old series that had changelog in each patch) Changes v6:
- Add SoC specific compatible
- Add now supported entry for compatible with no user Changes v5:
- Add Ack tag to guard patch
- Comment out compatible with no current user
- Fix smatch warning (reported by Dan Carpenter)
Changes v4:
- Out of RFC
- Add missing bitfield.h
- Drop useless header
Changes v3:
- Mute warning from Clang about C23
- Fix not inizialized err
- Drop unused variable
- Add SoC compatible with generic one
Changes v2:
- Rename all variables from mtk to eip93
- Move to inside-secure directory
- Check DMA map errors
- Use guard API for spinlock
- Minor improvements to code
- Add guard patch
- Change to better compatible
- Add description for EIP93 models
Christian Marangi (3):
spinlock: extend guard with spinlock_bh variants
dt-bindings: crypto: Add Inside Secure SafeXcel EIP-93 crypto engine
crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
.../crypto/inside-secure,safexcel-eip93.yaml | 67 ++ MAINTAINERS | 7 + drivers/crypto/Kconfig | 1 + drivers/crypto/Makefile | 1 + drivers/crypto/inside-secure/eip93/Kconfig | 20 + drivers/crypto/inside-secure/eip93/Makefile | 5 + .../crypto/inside-secure/eip93/eip93-aead.c | 710 +++++++++++++ .../crypto/inside-secure/eip93/eip93-aead.h | 38 + .../crypto/inside-secure/eip93/eip93-aes.h | 16 + .../crypto/inside-secure/eip93/eip93-cipher.c | 413 ++++++++ .../crypto/inside-secure/eip93/eip93-cipher.h | 60 ++ .../crypto/inside-secure/eip93/eip93-common.c | 822 +++++++++++++++ .../crypto/inside-secure/eip93/eip93-common.h | 23 + .../crypto/inside-secure/eip93/eip93-des.h | 16 + .../crypto/inside-secure/eip93/eip93-hash.c | 987 ++++++++++++++++++ .../crypto/inside-secure/eip93/eip93-hash.h | 77 ++ .../crypto/inside-secure/eip93/eip93-main.c | 502 +++++++++ .../crypto/inside-secure/eip93/eip93-main.h | 152 +++ .../crypto/inside-secure/eip93/eip93-regs.h | 335 ++++++ include/linux/spinlock.h | 13 + 20 files changed, 4265 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip93.yaml create mode 100644 drivers/crypto/inside-secure/eip93/Kconfig create mode 100644 drivers/crypto/inside-secure/eip93/Makefile create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aead.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aead.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aes.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-cipher.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-cipher.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-common.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-common.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-des.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-hash.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-hash.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-main.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-main.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-regs.h
Signature · 1 line
2.45.2
Christian Marangi
maintainerPATCH v8 1/3 spinlock: extend guard with spinlock_bh variants
Extend guard APIs with missing raw/spinlock_bh variants.
--- include/linux/spinlock.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/linux/spinlock.h +13 -0
@@ -548,6 +548,12 @@ DEFINE_LOCK_GUARD_1(raw_spinlock_irq, raw_spinlock_t, DEFINE_LOCK_GUARD_1_COND(raw_spinlock_irq, _try, raw_spin_trylock_irq(_T->lock)) +DEFINE_LOCK_GUARD_1 (raw_spinlock_bh, raw_spinlock_t, +raw_spin_lock_bh (_T->lock), + raw_spin_unlock_bh(_T->lock)) + +DEFINE_LOCK_GUARD_1_COND(raw_spinlock_bh, _try, raw_spin_trylock_bh(_T->lock)) + DEFINE_LOCK_GUARD_1(raw_spinlock_irqsave, raw_spinlock_t, raw_spin_lock_irqsave(_T->lock, _T->flags), raw_spin_unlock_irqrestore(_T->lock, _T->flags),
@@ -569,6 +575,13 @@ DEFINE_LOCK_GUARD_1(spinlock_irq, spinlock_t,DEFINE_LOCK_GUARD_1_COND (spinlock_irq, _try, spin_trylock_irq(_T->lock)) +DEFINE_LOCK_GUARD_1 (spinlock_bh, spinlock_t, +spin_lock_bh (_T->lock), + spin_unlock_bh(_T->lock)) + +DEFINE_LOCK_GUARD_1_COND (spinlock_bh, _try, + spin_trylock_bh(_T->lock)) + DEFINE_LOCK_GUARD_1(spinlock_irqsave, spinlock_t, spin_lock_irqsave(_T->lock, _T->flags), spin_unlock_irqrestore(_T->lock, _T->flags),
Signature · 1 line
2.45.2
Christian Marangi
maintainerPATCH v8 2/3 dt-bindings: crypto: Add Inside Secure SafeXcel EIP-93 crypto engine
In reply to Christian MarangiAdd bindings for the Inside Secure SafeXcel EIP-93 crypto engine.
The IP is present on Airoha SoC and on various Mediatek devices and other SoC under different names like mtk-eip93 or PKTE.
All the compatible that currently doesn't have any user are defined but rejected waiting for an actual device that makes use of them.
--- .../crypto/inside-secure,safexcel-eip93.yaml | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip93.yaml
Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip93.yaml new file +67 -0
@@ -0,0 +1,67 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/crypto/inside-secure,safexcel-eip93.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Inside Secure SafeXcel EIP-93 cryptographic engine + +maintainers: + - Christian Marangi <[email protected]> + +description: | + The Inside Secure SafeXcel EIP-93 is a cryptographic engine IP block + integrated in varios devices with very different and generic name from + PKTE to simply vendor+EIP93. The real IP under the hood is actually + developed by Inside Secure and given to license to vendors. + + The IP block is sold with different model based on what feature are + needed and are identified with the final letter. Each letter correspond + to a specific set of feature and multiple letter reflect the sum of the + feature set. + + EIP-93 models: + - EIP-93i: (basic) DES/Triple DES, AES, PRNG, IPsec ESP, SRTP, SHA1 + - EIP-93ie: i + SHA224/256, AES-192/256 + - EIP-93is: i + SSL/DTLS/DTLS, MD5, ARC4 + - EIP-93ies: i + e + s + - EIP-93iw: i + AES-XCB-MAC, AES-CCM + +properties: + compatible: + oneOf: + - items: + - const: airoha,en7581-eip93 + - const: inside-secure,safexcel-eip93ies + - items: + - not: {} + description: Need a SoC specific compatible + - enum: + - inside-secure,safexcel-eip93i + - inside-secure,safexcel-eip93ie + - inside-secure,safexcel-eip93is + - inside-secure,safexcel-eip93iw + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + crypto@1e004000 { + compatible = "airoha,en7581-eip93", "inside-secure,safexcel-eip93ies"; + reg = <0x1fb70000 0x1000>; + + interrupts = <GIC_SPI 44 IRQ_TYPE_LEVEL_HIGH>; + };
Signature · 1 line
2.45.2
Christian Marangi
maintainerPATCH v8 3/3 crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
In reply to Christian MarangiAdd support for the Inside Secure SafeXcel EIP-93 Crypto Engine used on Mediatek MT7621 SoC and new Airoha SoC.
EIP-93 IP supports AES/DES/3DES ciphers in ECB/CBC and CTR modes as well as authenc(HMAC(x), cipher(y)) using HMAC MD5, SHA1, SHA224 and SHA256.
EIP-93 provide regs to signal support for specific chipers and the driver dynamically register only the supported one by the chip.
--- MAINTAINERS | 7 + drivers/crypto/Kconfig | 1 + drivers/crypto/Makefile | 1 + drivers/crypto/inside-secure/eip93/Kconfig | 20 + drivers/crypto/inside-secure/eip93/Makefile | 5 + .../crypto/inside-secure/eip93/eip93-aead.c | 710 +++++++++++++ .../crypto/inside-secure/eip93/eip93-aead.h | 38 + .../crypto/inside-secure/eip93/eip93-aes.h | 16 + .../crypto/inside-secure/eip93/eip93-cipher.c | 413 ++++++++ .../crypto/inside-secure/eip93/eip93-cipher.h | 60 ++ .../crypto/inside-secure/eip93/eip93-common.c | 822 +++++++++++++++ .../crypto/inside-secure/eip93/eip93-common.h | 23 + .../crypto/inside-secure/eip93/eip93-des.h | 16 + .../crypto/inside-secure/eip93/eip93-hash.c | 987 ++++++++++++++++++ .../crypto/inside-secure/eip93/eip93-hash.h | 77 ++ .../crypto/inside-secure/eip93/eip93-main.c | 502 +++++++++ .../crypto/inside-secure/eip93/eip93-main.h | 152 +++ .../crypto/inside-secure/eip93/eip93-regs.h | 335 ++++++ 18 files changed, 4185 insertions(+) create mode 100644 drivers/crypto/inside-secure/eip93/Kconfig create mode 100644 drivers/crypto/inside-secure/eip93/Makefile create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aead.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aead.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aes.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-cipher.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-cipher.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-common.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-common.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-des.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-hash.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-hash.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-main.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-main.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-regs.h
MAINTAINERS +7 -0
@@ -11322,6 +11322,13 @@ L: [email protected] S: Maintained F: drivers/crypto/inside-secure/ +INSIDE SECURE EIP93 CRYPTO DRIVER +M: Christian Marangi <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip93.yaml +F: drivers/crypto/inside-secure/eip93/ + INTEGRITY MEASUREMENT ARCHITECTURE (IMA) M: Mimi Zohar <[email protected]> M: Roberto Sassu <[email protected]>
drivers/crypto/Kconfig +1 -0
@@ -851,5 +851,6 @@ config CRYPTO_DEV_SA2UL source "drivers/crypto/aspeed/Kconfig" source "drivers/crypto/starfive/Kconfig" +source "drivers/crypto/inside-secure/eip93/Kconfig" endif # CRYPTO_HW
drivers/crypto/Makefile +1 -0
@@ -52,3 +52,4 @@ obj-y += hisilicon/ obj-$(CONFIG_CRYPTO_DEV_AMLOGIC_GXL) += amlogic/ obj-y += intel/ obj-y += starfive/ +obj-y += inside-secure/eip93/
drivers/crypto/inside-secure/eip93/Kconfig new file +20 -0
@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0 +config CRYPTO_DEV_EIP93 + tristate "Support for EIP93 crypto HW accelerators" + depends on SOC_MT7621 || ARCH_AIROHA ||COMPILE_TEST + select CRYPTO_LIB_AES + select CRYPTO_LIB_DES + select CRYPTO_SKCIPHER + select CRYPTO_AEAD + select CRYPTO_AUTHENC + select CRYPTO_MD5 + select CRYPTO_SHA1 + select CRYPTO_SHA256 + help + EIP93 have various crypto HW accelerators. Select this if + you want to use the EIP93 modules for any of the crypto algorithms. + + If the IP supports it, this provide offload for AES - ECB, CBC and + CTR crypto. Also provide DES and 3DES ECB and CBC. + + Also provide AEAD authenc(hmac(x), cipher(y)) for supported algo.
drivers/crypto/inside-secure/eip93/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +obj-$(CONFIG_CRYPTO_DEV_EIP93) += crypto-hw-eip93.o + +crypto-hw-eip93-y += eip93-main.o eip93-common.o +crypto-hw-eip93-y += eip93-cipher.o eip93-aead.o +crypto-hw-eip93-y += eip93-hash.o
drivers/crypto/inside-secure/eip93/eip93-aead.c new file +710 -0
710 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-aead.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2019 - 2021 +* +* Richard van Schagen <[email protected]> +* Christian Marangi <[email protected] +*/ +#ifndef _EIP93_AEAD_H_ +#define _EIP93_AEAD_H_ + +extern struct eip93_alg_template eip93_alg_authenc_hmac_md5_cbc_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha1_cbc_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha224_cbc_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha256_cbc_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_md5_ctr_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha1_ctr_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha224_ctr_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha256_ctr_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_md5_rfc3686_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha1_rfc3686_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha224_rfc3686_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha256_rfc3686_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_md5_cbc_des; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha1_cbc_des; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha224_cbc_des; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha256_cbc_des; +extern struct eip93_alg_template eip93_alg_authenc_hmac_md5_cbc_des3_ede; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha1_cbc_des3_ede; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha224_cbc_des3_ede; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha256_cbc_des3_ede; +extern struct eip93_alg_template eip93_alg_authenc_hmac_md5_ecb_null; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha1_ecb_null; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha224_ecb_null; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha256_ecb_null; + +void eip93_aead_handle_result (struct crypto_async_request *async,int err); + +#endif /* _EIP93_AEAD_H_ */
drivers/crypto/inside-secure/eip93/eip93-aes.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2019 - 2021 +* +* Richard van Schagen <[email protected]> +* Christian Marangi <[email protected] +*/ +#ifndef _EIP93_AES_H_ +#define _EIP93_AES_H_ + +extern struct eip93_alg_template eip93_alg_ecb_aes; +extern struct eip93_alg_template eip93_alg_cbc_aes; +extern struct eip93_alg_template eip93_alg_ctr_aes; +extern struct eip93_alg_template eip93_alg_rfc3686_aes; + +#endif /* _EIP93_AES_H_ */
drivers/crypto/inside-secure/eip93/eip93-cipher.c new file +413 -0
413 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-cipher.h new file +60 -0
60 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-common.c new file +822 -0
822 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-common.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2019 - 2021 +* +* Richard van Schagen <[email protected]> +* Christian Marangi <[email protected] +*/ + +#ifndef _EIP93_COMMON_H_ +#define _EIP93_COMMON_H_ + +void *eip93_get_descriptor (struct eip93_device *mtk); +int eip93_put_descriptor (struct eip93_device *mtk,struct eip93_descriptor *desc); + +void eip93_set_sa_record (struct sa_record *sa_record,const unsigned int keylen, +const u32 flags); + +int eip93_parse_ctrl_stat_err (struct eip93_device *mtk,int err); + +int eip93_authenc_setkey (struct crypto_aead *aead,struct sa_record *sa, +const u8 *authkey,unsigned int authkeylen); + +#endif /* _EIP93_COMMON_H_ */
drivers/crypto/inside-secure/eip93/eip93-des.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2019 - 2021 +* +* Richard van Schagen <[email protected]> +* Christian Marangi <[email protected] +*/ +#ifndef _EIP93_DES_H_ +#define _EIP93_DES_H_ + +extern struct eip93_alg_template eip93_alg_ecb_des; +extern struct eip93_alg_template eip93_alg_cbc_des; +extern struct eip93_alg_template eip93_alg_ecb_des3_ede; +extern struct eip93_alg_template eip93_alg_cbc_des3_ede; + +#endif /* _EIP93_DES_H_ */
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +987 -0
854 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-hash.h new file +77 -0
77 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-main.c new file +502 -0
502 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-main.h new file +152 -0
152 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-regs.h new file +335 -0
335 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.45.2
Part of the diff is not shown here. View the raw message.
Herbert Xu
maintainerRe: [PATCH v8 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
drivers/crypto/inside-secure/eip93/eip93-hash.c line 400
Quoted 12 lines · Christian Marangi
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +11
-0+/* +* Consume remaining data. +* 1. Loop until we consume all the data in block of 64bytes +* 2. Send full block of 64bytes +* 3. Skip sending last block for future update() or for final() to +* enable HASH_FINALIZE bit. +*/ +while (to_consume >0 ) { +int to_read =min (to_consume,SHA256_BLOCK_SIZE ); + + block =kzalloc (sizeof (*block),GFP_KERNEL );
You should avoid allocating memory. If you really must do it, then it needs to be GFP_ATOMIC, and your algorithm needs to set CRYPTO_ALG_ALLOCATES_MEMORY which means that it won't be used by the storage layer as memory allocations may lead to dead-lock.
The preferred way to access extra memory is through the request context structure.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerRe: [PATCH v8 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
In reply to Christian MarangiQuoted 13 lines · Christian Marangi
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +12
-0+static int eip93_hash_export (struct ahash_request *req,void *out) +{ +struct eip93_hash_reqctx *rctx =ahash_request_ctx (req); +struct eip93_hash_export_state *state = out; + +/* Save the first block in state data */ +if (rctx->len) { +struct mkt_hash_block *block; + + block =list_first_entry (&rctx->blocks, + struct mkt_hash_block, + list);
drivers/crypto/inside-secure/eip93/eip93-hash.c line 740
Quoted 10 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +10
-0+ +memcpy (state->data, block->data, +SHA256_BLOCK_SIZE - rctx->left_last); + } + +eip93_hash_export_sa_state (req, state); + +eip93_hash_free_data_blocks (req); +eip93_hash_free_sa_state (req); +eip93_hash_free_sa_record (req);
The export function should be idempotent so it shouldn't be freeing anything.
In fact this indicates a bigger problem with how DMA is being used in the driver. You shouldn't be leaving DMA memory mapped after the init (or update) function completes. It is perfectly legal for a user to call init and then abandon the request by freeing it directly without ever calling final. In that case you will be leaking the DMA mappings.
So make sure that DMA is mapped only when needed, and freed before you call the user callback.
The import/export functions should only be touching kernel memory, not DMA.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Christian Marangi
maintainerRe: [PATCH v8 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
In reply to Herbert XuQuoted 19 lines · Herbert Xu
drivers/crypto/inside-secure/eip93/eip93-hash.c line 400
Quoted 12 lines · Christian Marangi
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +11
-0+/* +* Consume remaining data. +* 1. Loop until we consume all the data in block of 64bytes +* 2. Send full block of 64bytes +* 3. Skip sending last block for future update() or for final() to +* enable HASH_FINALIZE bit. +*/ +while (to_consume >0 ) { +int to_read =min (to_consume,SHA256_BLOCK_SIZE ); + + block =kzalloc (sizeof (*block),GFP_KERNEL );You should avoid allocating memory. If you really must do it, then it needs to be
GFP_ATOMIC, and your algorithm needs to setCRYPTO_ALG_ALLOCATES_MEMORYwhich means that it won't be used by the storage layer as memory allocations may lead to dead-lock.
It's problematic for the ring consumption logic to free the block as they get consumed hence memory allocation is needed.
Quoted 3 lines
The preferred way to access extra memory is through the request context structure.
Do you have quick example for this?
Signature · 1 line
Ansuel
Christian Marangi
maintainerRe: [PATCH v8 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
In reply to Herbert XuQuoted 35 lines · Herbert Xu
Quoted 13 lines · Christian Marangi
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +12
-0+static int eip93_hash_export (struct ahash_request *req,void *out) +{ +struct eip93_hash_reqctx *rctx =ahash_request_ctx (req); +struct eip93_hash_export_state *state = out; + +/* Save the first block in state data */ +if (rctx->len) { +struct mkt_hash_block *block; + + block =list_first_entry (&rctx->blocks, + struct mkt_hash_block, + list);drivers/crypto/inside-secure/eip93/eip93-hash.c line 740
Quoted 10 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +10
-0+ +memcpy (state->data, block->data, +SHA256_BLOCK_SIZE - rctx->left_last); + } + +eip93_hash_export_sa_state (req, state); + +eip93_hash_free_data_blocks (req); +eip93_hash_free_sa_state (req); +eip93_hash_free_sa_record (req);The export function should be idempotent so it shouldn't be freeing anything.
In fact this indicates a bigger problem with how DMA is being used in the driver. You shouldn't be leaving DMA memory mapped after the init (or update) function completes. It is perfectly legal for a user to call init and then abandon the request by freeing it directly without ever calling final. In that case you will be leaking the DMA mappings.
Quoted 6 lines
So make sure that DMA is mapped only when needed, and freed before you call the user callback.
The import/export functions should only be touching kernel memory, not DMA.
Just to make sure, this is only limited to DMA or it's also problematic to the block list? Aka NO FREE should be done in export or NO DMA FREE should be done in export?
Signature · 1 line
Ansuel
Herbert Xu
maintainerRe: [PATCH v8 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
Quoted 4 lines · Christian Marangi
Just to make sure, this is only limited to DMA or it's also problematic to the block list? Aka NO FREE should be done in export or NO DMA FREE should be done in export?
It's all resources.
The user does not have to call export, final or finup. The request object can be freed directly at any time after a call. So you can never hold any resources in the request object between calls.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerRe: [PATCH v8 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
In reply to Christian MarangiQuoted 2 lines · Christian Marangi
Do you have quick example for this?
Just search for crypto_ahash_set_reqsize in drivers/crypto and see how they use the reqctx to store temporary data. For each request, you're guaranteed to have exclusive ownership of the reqctx.
If you wish to DMA into the reqctx, search for ahash_request_ctx_dma to see how you should set it up.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Christian Marangi
maintainerRe: [PATCH v8 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
Quoted 11 lines · Herbert Xu
Quoted 2 lines · Christian Marangi
Do you have quick example for this?
Just search for
crypto_ahash_set_reqsizeindrivers/cryptoand see how they use the reqctx to store temporary data. For each request, you're guaranteed to have exclusive ownership of the reqctx.If you wish to DMA into the reqctx, search for
ahash_request_ctx_dmato see how you should set it up.
Oh ok I didn't understood you were referring to the request_ctx API thanks.
I just pushed v9 with the requested changes done. Now we map DMA only when needed and use local struct instead of kmalloc. kmalloc is only used for blocks. For that GFP_ATOMIC is used. The ALLOCATES_MEMORY was already set in the algo flags.
Hope I'm making good progress on this.
Signature · 1 line
Ansuel