From nobody Fri Sep 19 10:37:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A655C433FE for ; Fri, 25 Nov 2022 04:36:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229619AbiKYEgu (ORCPT ); Thu, 24 Nov 2022 23:36:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbiKYEgp (ORCPT ); Thu, 24 Nov 2022 23:36:45 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E43D2338D; Thu, 24 Nov 2022 20:36:44 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1oyQRw-000dj8-W3; Fri, 25 Nov 2022 12:36:30 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 12:36:28 +0800 From: "Herbert Xu" Date: Fri, 25 Nov 2022 12:36:28 +0800 Subject: [v2 PATCH 1/9] crypto: Prepare to move crypto_tfm_ctx References: To: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , Linux Crypto Mailing List Message-Id: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The helper crypto_tfm_ctx is only used by the Crypto API algorithm code and should really be in algapi.h. However, for historical reasons many files relied on it to be in crypto.h. This patch changes those files to use algapi.h instead in prepartion for a move. Signed-off-by: Herbert Xu --- arch/arm/crypto/aes-cipher-glue.c | 2 +- arch/arm64/crypto/aes-ce-glue.c | 2 +- arch/arm64/crypto/aes-cipher-glue.c | 2 +- arch/arm64/crypto/sm4-ce-cipher-glue.c | 2 +- arch/x86/crypto/twofish_glue.c | 2 +- crypto/aes_generic.c | 2 +- crypto/aes_ti.c | 2 +- crypto/anubis.c | 2 +- crypto/blowfish_common.c | 3 ++- crypto/blowfish_generic.c | 3 ++- crypto/camellia_generic.c | 2 +- crypto/cast5_generic.c | 2 +- crypto/cast6_generic.c | 2 +- crypto/des_generic.c | 2 +- crypto/fcrypt.c | 2 +- crypto/khazad.c | 2 +- crypto/seed.c | 2 +- crypto/serpent_generic.c | 2 +- crypto/sm4_generic.c | 2 +- crypto/tea.c | 2 +- crypto/twofish_common.c | 2 +- crypto/twofish_generic.c | 2 +- drivers/crypto/nx/nx-842.h | 2 +- include/crypto/aria.h | 2 +- include/crypto/internal/acompress.h | 2 ++ include/crypto/internal/scompress.h | 3 ++- 26 files changed, 30 insertions(+), 25 deletions(-) diff --git a/arch/arm/crypto/aes-cipher-glue.c b/arch/arm/crypto/aes-cipher= -glue.c index 8cd00f56800e..6dfaef2d8f91 100644 --- a/arch/arm/crypto/aes-cipher-glue.c +++ b/arch/arm/crypto/aes-cipher-glue.c @@ -7,7 +7,7 @@ */ =20 #include -#include +#include #include =20 asmlinkage void __aes_arm_encrypt(u32 *rk, int rounds, const u8 *in, u8 *o= ut); diff --git a/arch/arm64/crypto/aes-ce-glue.c b/arch/arm64/crypto/aes-ce-glu= e.c index 56a5f6f0b0c1..e921823ca103 100644 --- a/arch/arm64/crypto/aes-ce-glue.c +++ b/arch/arm64/crypto/aes-ce-glue.c @@ -9,9 +9,9 @@ #include #include #include +#include #include #include -#include #include =20 #include "aes-ce-setkey.h" diff --git a/arch/arm64/crypto/aes-cipher-glue.c b/arch/arm64/crypto/aes-ci= pher-glue.c index 8caf6dfefce8..4ec55e568941 100644 --- a/arch/arm64/crypto/aes-cipher-glue.c +++ b/arch/arm64/crypto/aes-cipher-glue.c @@ -6,7 +6,7 @@ */ =20 #include -#include +#include #include =20 asmlinkage void __aes_arm64_encrypt(u32 *rk, u8 *out, const u8 *in, int ro= unds); diff --git a/arch/arm64/crypto/sm4-ce-cipher-glue.c b/arch/arm64/crypto/sm4= -ce-cipher-glue.c index 76a34ef4abbb..c31d76fb5a17 100644 --- a/arch/arm64/crypto/sm4-ce-cipher-glue.c +++ b/arch/arm64/crypto/sm4-ce-cipher-glue.c @@ -2,11 +2,11 @@ =20 #include #include +#include #include #include #include #include -#include #include =20 MODULE_ALIAS_CRYPTO("sm4"); diff --git a/arch/x86/crypto/twofish_glue.c b/arch/x86/crypto/twofish_glue.c index f9c4adc27404..0614beece279 100644 --- a/arch/x86/crypto/twofish_glue.c +++ b/arch/x86/crypto/twofish_glue.c @@ -38,8 +38,8 @@ * Third Edition. */ =20 +#include #include -#include #include #include #include diff --git a/crypto/aes_generic.c b/crypto/aes_generic.c index 27ab27931813..666474b81c6a 100644 --- a/crypto/aes_generic.c +++ b/crypto/aes_generic.c @@ -48,11 +48,11 @@ */ =20 #include +#include #include #include #include #include -#include #include #include =20 diff --git a/crypto/aes_ti.c b/crypto/aes_ti.c index 205c2c257d49..a3b342f92fab 100644 --- a/crypto/aes_ti.c +++ b/crypto/aes_ti.c @@ -6,7 +6,7 @@ */ =20 #include -#include +#include #include =20 static int aesti_set_key(struct crypto_tfm *tfm, const u8 *in_key, diff --git a/crypto/anubis.c b/crypto/anubis.c index 5da0241ef453..9f0cf61bbc6e 100644 --- a/crypto/anubis.c +++ b/crypto/anubis.c @@ -29,11 +29,11 @@ * */ =20 +#include #include #include #include #include -#include #include =20 #define ANUBIS_MIN_KEY_SIZE 16 diff --git a/crypto/blowfish_common.c b/crypto/blowfish_common.c index 1c072012baff..c0208ce269a3 100644 --- a/crypto/blowfish_common.c +++ b/crypto/blowfish_common.c @@ -14,11 +14,12 @@ * Copyright (c) Kyle McMartin * Copyright (c) 2002 James Morris */ + +#include #include #include #include #include -#include #include #include =20 diff --git a/crypto/blowfish_generic.c b/crypto/blowfish_generic.c index 003b52c6880e..0e74c7242e77 100644 --- a/crypto/blowfish_generic.c +++ b/crypto/blowfish_generic.c @@ -11,11 +11,12 @@ * Copyright (c) Kyle McMartin * Copyright (c) 2002 James Morris */ + +#include #include #include #include #include -#include #include #include =20 diff --git a/crypto/camellia_generic.c b/crypto/camellia_generic.c index fd1a88af9e77..c04670cf51ac 100644 --- a/crypto/camellia_generic.c +++ b/crypto/camellia_generic.c @@ -9,7 +9,7 @@ * https://info.isl.ntt.co.jp/crypt/eng/camellia/specifications.html */ =20 -#include +#include #include #include #include diff --git a/crypto/cast5_generic.c b/crypto/cast5_generic.c index 0257c14cefc2..085a1eedae03 100644 --- a/crypto/cast5_generic.c +++ b/crypto/cast5_generic.c @@ -14,8 +14,8 @@ =20 =20 #include +#include #include -#include #include #include #include diff --git a/crypto/cast6_generic.c b/crypto/cast6_generic.c index 75346380aa0b..34f1ab53e3a7 100644 --- a/crypto/cast6_generic.c +++ b/crypto/cast6_generic.c @@ -11,8 +11,8 @@ =20 =20 #include +#include #include -#include #include #include #include diff --git a/crypto/des_generic.c b/crypto/des_generic.c index c85354a5e94c..1274e18d3eb9 100644 --- a/crypto/des_generic.c +++ b/crypto/des_generic.c @@ -8,11 +8,11 @@ */ =20 #include +#include #include #include #include #include -#include =20 #include =20 diff --git a/crypto/fcrypt.c b/crypto/fcrypt.c index 76a04d000c0d..95a16e88899b 100644 --- a/crypto/fcrypt.c +++ b/crypto/fcrypt.c @@ -43,10 +43,10 @@ */ =20 #include +#include #include #include #include -#include =20 #define ROUNDS 16 =20 diff --git a/crypto/khazad.c b/crypto/khazad.c index f19339954c89..70cafe73f974 100644 --- a/crypto/khazad.c +++ b/crypto/khazad.c @@ -19,11 +19,11 @@ * */ =20 +#include #include #include #include #include -#include #include =20 #define KHAZAD_KEY_SIZE 16 diff --git a/crypto/seed.c b/crypto/seed.c index 27720140820e..d0506ade2a5f 100644 --- a/crypto/seed.c +++ b/crypto/seed.c @@ -8,11 +8,11 @@ * Copyright (C) 2007 Korea Information Security Agency (KISA). */ =20 +#include #include #include #include #include -#include #include =20 #define SEED_NUM_KCONSTANTS 16 diff --git a/crypto/serpent_generic.c b/crypto/serpent_generic.c index 45f98b750053..c6bca47931e2 100644 --- a/crypto/serpent_generic.c +++ b/crypto/serpent_generic.c @@ -7,11 +7,11 @@ * Copyright (C) 2002 Dag Arne Osvik */ =20 +#include #include #include #include #include -#include #include #include =20 diff --git a/crypto/sm4_generic.c b/crypto/sm4_generic.c index 4a6480a27fee..560eba37dc55 100644 --- a/crypto/sm4_generic.c +++ b/crypto/sm4_generic.c @@ -7,12 +7,12 @@ * All rights reserved. */ =20 +#include #include #include #include #include #include -#include #include #include =20 diff --git a/crypto/tea.c b/crypto/tea.c index 02efc5d81690..896f863f3067 100644 --- a/crypto/tea.c +++ b/crypto/tea.c @@ -14,11 +14,11 @@ * Copyright (c) 2004 Aaron Grothe ajgrothe@yahoo.com */ =20 +#include #include #include #include #include -#include #include =20 #define TEA_KEY_SIZE 16 diff --git a/crypto/twofish_common.c b/crypto/twofish_common.c index f921f30334f4..bf4f28742f77 100644 --- a/crypto/twofish_common.c +++ b/crypto/twofish_common.c @@ -25,9 +25,9 @@ * Third Edition. */ =20 +#include #include #include -#include #include #include #include diff --git a/crypto/twofish_generic.c b/crypto/twofish_generic.c index 86b2f067a416..557915e4062d 100644 --- a/crypto/twofish_generic.c +++ b/crypto/twofish_generic.c @@ -25,12 +25,12 @@ */ =20 #include +#include #include #include #include #include #include -#include #include =20 /* Macros to compute the g() function in the encryption and decryption diff --git a/drivers/crypto/nx/nx-842.h b/drivers/crypto/nx/nx-842.h index b66f19ac600f..7590bfb24d79 100644 --- a/drivers/crypto/nx/nx-842.h +++ b/drivers/crypto/nx/nx-842.h @@ -3,10 +3,10 @@ #ifndef __NX_842_H__ #define __NX_842_H__ =20 +#include #include #include #include -#include #include #include #include diff --git a/include/crypto/aria.h b/include/crypto/aria.h index 254da46cc385..73295146be11 100644 --- a/include/crypto/aria.h +++ b/include/crypto/aria.h @@ -18,11 +18,11 @@ #ifndef _CRYPTO_ARIA_H #define _CRYPTO_ARIA_H =20 +#include #include #include #include #include -#include #include =20 #define ARIA_MIN_KEY_SIZE 16 diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/= acompress.h index cfc47e18820f..49339003bd2c 100644 --- a/include/crypto/internal/acompress.h +++ b/include/crypto/internal/acompress.h @@ -8,7 +8,9 @@ */ #ifndef _CRYPTO_ACOMP_INT_H #define _CRYPTO_ACOMP_INT_H + #include +#include =20 /* * Transform internal helpers. diff --git a/include/crypto/internal/scompress.h b/include/crypto/internal/= scompress.h index f834274c2493..252cc949d4ee 100644 --- a/include/crypto/internal/scompress.h +++ b/include/crypto/internal/scompress.h @@ -8,7 +8,8 @@ */ #ifndef _CRYPTO_SCOMP_INT_H #define _CRYPTO_SCOMP_INT_H -#include + +#include =20 #define SCOMP_SCRATCH_SIZE 131072 From nobody Fri Sep 19 10:37:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3310C4321E for ; Fri, 25 Nov 2022 04:36:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229580AbiKYEgq (ORCPT ); Thu, 24 Nov 2022 23:36:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbiKYEgp (ORCPT ); Thu, 24 Nov 2022 23:36:45 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B548C2338F; Thu, 24 Nov 2022 20:36:44 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1oyQRz-000djH-3a; Fri, 25 Nov 2022 12:36:32 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 12:36:31 +0800 From: "Herbert Xu" Date: Fri, 25 Nov 2022 12:36:31 +0800 Subject: [v2 PATCH 2/9] crypto: api - Add crypto_tfm_ctx_dma References: To: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , Linux Crypto Mailing List Message-Id: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds the helpers crypto_tfm_ctx_aligned and crypto_tfm_ctx_dma. The first aligns the tfm context to the value cra_alignmask. The second sets the alignment according to dma_cache_get_alignment(); This patch also moves crypto_tfm_ctx into algapi.h. Signed-off-by: Herbert Xu --- include/crypto/algapi.h | 41 +++++++++++++++++++++++++++++++++++++++-- include/linux/crypto.h | 5 ----- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index f50c5d1725da..4c99eb66e654 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -7,6 +7,7 @@ #ifndef _CRYPTO_ALGAPI_H #define _CRYPTO_ALGAPI_H =20 +#include #include #include #include @@ -25,6 +26,14 @@ #define MAX_CIPHER_BLOCKSIZE 16 #define MAX_CIPHER_ALIGNMASK 15 =20 +#ifdef ARCH_DMA_MINALIGN +#define CRYPTO_DMA_ALIGN ARCH_DMA_MINALIGN +#else +#define CRYPTO_DMA_ALIGN CRYPTO_MINALIGN +#endif + +#define CRYPTO_DMA_PADDING ((CRYPTO_DMA_ALIGN - 1) & ~(CRYPTO_MINALIGN - 1= )) + struct crypto_aead; struct crypto_instance; struct module; @@ -189,10 +198,38 @@ static inline void crypto_xor_cpy(u8 *dst, const u8 *= src1, const u8 *src2, } } =20 +static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm) +{ + return tfm->__crt_ctx; +} + +static inline void *crypto_tfm_ctx_align(struct crypto_tfm *tfm, + unsigned int align) +{ + if (align <=3D crypto_tfm_ctx_alignment()) + align =3D 1; + + return PTR_ALIGN(crypto_tfm_ctx(tfm), align); +} + static inline void *crypto_tfm_ctx_aligned(struct crypto_tfm *tfm) { - return PTR_ALIGN(crypto_tfm_ctx(tfm), - crypto_tfm_alg_alignmask(tfm) + 1); + return crypto_tfm_ctx_align(tfm, crypto_tfm_alg_alignmask(tfm) + 1); +} + +static inline unsigned int crypto_dma_align(void) +{ + return CRYPTO_DMA_ALIGN; +} + +static inline unsigned int crypto_dma_padding(void) +{ + return (crypto_dma_align() - 1) & ~(crypto_tfm_ctx_alignment() - 1); +} + +static inline void *crypto_tfm_ctx_dma(struct crypto_tfm *tfm) +{ + return crypto_tfm_ctx_align(tfm, crypto_dma_align()); } =20 static inline struct crypto_instance *crypto_tfm_alg_instance( diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 2324ab6f1846..5d1e961f810e 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -714,11 +714,6 @@ static inline void crypto_tfm_clear_flags(struct crypt= o_tfm *tfm, u32 flags) tfm->crt_flags &=3D ~flags; } =20 -static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm) -{ - return tfm->__crt_ctx; -} - static inline unsigned int crypto_tfm_ctx_alignment(void) { struct crypto_tfm *tfm; From nobody Fri Sep 19 10:37:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6B6FC4167B for ; Fri, 25 Nov 2022 04:37:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbiKYEg7 (ORCPT ); Thu, 24 Nov 2022 23:36:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbiKYEgr (ORCPT ); Thu, 24 Nov 2022 23:36:47 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19A192338F; Thu, 24 Nov 2022 20:36:47 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1oyQS1-000djS-65; Fri, 25 Nov 2022 12:36:34 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 12:36:33 +0800 From: "Herbert Xu" Date: Fri, 25 Nov 2022 12:36:33 +0800 Subject: [v2 PATCH 3/9] crypto: aead - Add ctx helpers with DMA alignment References: To: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , Linux Crypto Mailing List Message-Id: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds helpers to access the aead context structure and request context structure with an added alignment for DMA access. Signed-off-by: Herbert Xu --- include/crypto/internal/aead.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/crypto/internal/aead.h b/include/crypto/internal/aead.h index d482017f3e20..cd8cb1e921b7 100644 --- a/include/crypto/internal/aead.h +++ b/include/crypto/internal/aead.h @@ -39,6 +39,11 @@ static inline void *crypto_aead_ctx(struct crypto_aead *= tfm) return crypto_tfm_ctx(&tfm->base); } =20 +static inline void *crypto_aead_ctx_dma(struct crypto_aead *tfm) +{ + return crypto_tfm_ctx_dma(&tfm->base); +} + static inline struct crypto_instance *aead_crypto_instance( struct aead_instance *inst) { @@ -65,6 +70,16 @@ static inline void *aead_request_ctx(struct aead_request= *req) return req->__ctx; } =20 +static inline void *aead_request_ctx_dma(struct aead_request *req) +{ + unsigned int align =3D crypto_dma_align(); + + if (align <=3D crypto_tfm_ctx_alignment()) + align =3D 1; + + return PTR_ALIGN(aead_request_ctx(req), align); +} + static inline void aead_request_complete(struct aead_request *req, int err) { req->base.complete(&req->base, err); @@ -108,6 +123,13 @@ static inline void crypto_aead_set_reqsize(struct cryp= to_aead *aead, aead->reqsize =3D reqsize; } =20 +static inline void crypto_aead_set_reqsize_dma(struct crypto_aead *aead, + unsigned int reqsize) +{ + reqsize +=3D crypto_dma_align() & ~(crypto_tfm_ctx_alignment() - 1); + aead->reqsize =3D reqsize; +} + static inline void aead_init_queue(struct aead_queue *queue, unsigned int max_qlen) { From nobody Fri Sep 19 10:37:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1BDBC433FE for ; Fri, 25 Nov 2022 04:37:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229681AbiKYEhF (ORCPT ); Thu, 24 Nov 2022 23:37:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbiKYEgs (ORCPT ); Thu, 24 Nov 2022 23:36:48 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82E8023391; Thu, 24 Nov 2022 20:36:47 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1oyQS3-000djf-AS; Fri, 25 Nov 2022 12:36:36 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 12:36:35 +0800 From: "Herbert Xu" Date: Fri, 25 Nov 2022 12:36:35 +0800 Subject: [v2 PATCH 4/9] crypto: hash - Add ctx helpers with DMA alignment References: To: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , Linux Crypto Mailing List Message-Id: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds helpers to access the ahash context structure and request context structure with an added alignment for DMA access. Signed-off-by: Herbert Xu --- include/crypto/internal/hash.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index 25806141db59..a871b46a24da 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h @@ -134,6 +134,11 @@ static inline void *crypto_ahash_ctx(struct crypto_aha= sh *tfm) return crypto_tfm_ctx(crypto_ahash_tfm(tfm)); } =20 +static inline void *crypto_ahash_ctx_dma(struct crypto_ahash *tfm) +{ + return crypto_tfm_ctx_dma(crypto_ahash_tfm(tfm)); +} + static inline struct ahash_alg *__crypto_ahash_alg(struct crypto_alg *alg) { return container_of(__crypto_hash_alg_common(alg), struct ahash_alg, @@ -146,6 +151,13 @@ static inline void crypto_ahash_set_reqsize(struct cry= pto_ahash *tfm, tfm->reqsize =3D reqsize; } =20 +static inline void crypto_ahash_set_reqsize_dma(struct crypto_ahash *ahash, + unsigned int reqsize) +{ + reqsize +=3D crypto_dma_align() & ~(crypto_tfm_ctx_alignment() - 1); + ahash->reqsize =3D reqsize; +} + static inline struct crypto_instance *ahash_crypto_instance( struct ahash_instance *inst) { @@ -169,6 +181,16 @@ static inline void *ahash_instance_ctx(struct ahash_in= stance *inst) return crypto_instance_ctx(ahash_crypto_instance(inst)); } =20 +static inline void *ahash_request_ctx_dma(struct ahash_request *req) +{ + unsigned int align =3D crypto_dma_align(); + + if (align <=3D crypto_tfm_ctx_alignment()) + align =3D 1; + + return PTR_ALIGN(ahash_request_ctx(req), align); +} + static inline void ahash_request_complete(struct ahash_request *req, int e= rr) { req->base.complete(&req->base, err); From nobody Fri Sep 19 10:37:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1410C433FE for ; Fri, 25 Nov 2022 04:37:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229767AbiKYEhb (ORCPT ); Thu, 24 Nov 2022 23:37:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbiKYEhB (ORCPT ); Thu, 24 Nov 2022 23:37:01 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DF6E27934; Thu, 24 Nov 2022 20:36:56 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1oyQS5-000djv-CO; Fri, 25 Nov 2022 12:36:38 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 12:36:37 +0800 From: "Herbert Xu" Date: Fri, 25 Nov 2022 12:36:37 +0800 Subject: [v2 PATCH 5/9] crypto: skcipher - Add ctx helpers with DMA alignment References: To: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , Linux Crypto Mailing List Message-Id: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds helpers to access the skcipher context structure and request context structure with an added alignment for DMA access. Signed-off-by: Herbert Xu --- include/crypto/internal/skcipher.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/s= kcipher.h index a2339f80a615..a05a55af5b2c 100644 --- a/include/crypto/internal/skcipher.h +++ b/include/crypto/internal/skcipher.h @@ -122,6 +122,13 @@ static inline void crypto_skcipher_set_reqsize( skcipher->reqsize =3D reqsize; } =20 +static inline void crypto_skcipher_set_reqsize_dma( + struct crypto_skcipher *skcipher, unsigned int reqsize) +{ + reqsize +=3D crypto_dma_align() & ~(crypto_tfm_ctx_alignment() - 1); + skcipher->reqsize =3D reqsize; +} + int crypto_register_skcipher(struct skcipher_alg *alg); void crypto_unregister_skcipher(struct skcipher_alg *alg); int crypto_register_skciphers(struct skcipher_alg *algs, int count); @@ -151,11 +158,26 @@ static inline void *crypto_skcipher_ctx(struct crypto= _skcipher *tfm) return crypto_tfm_ctx(&tfm->base); } =20 +static inline void *crypto_skcipher_ctx_dma(struct crypto_skcipher *tfm) +{ + return crypto_tfm_ctx_dma(&tfm->base); +} + static inline void *skcipher_request_ctx(struct skcipher_request *req) { return req->__ctx; } =20 +static inline void *skcipher_request_ctx_dma(struct skcipher_request *req) +{ + unsigned int align =3D crypto_dma_align(); + + if (align <=3D crypto_tfm_ctx_alignment()) + align =3D 1; + + return PTR_ALIGN(skcipher_request_ctx(req), align); +} + static inline u32 skcipher_request_flags(struct skcipher_request *req) { return req->base.flags; From nobody Fri Sep 19 10:37:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E430C4332F for ; Fri, 25 Nov 2022 04:37:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229690AbiKYEhL (ORCPT ); Thu, 24 Nov 2022 23:37:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbiKYEg5 (ORCPT ); Thu, 24 Nov 2022 23:36:57 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4ABA825C74; Thu, 24 Nov 2022 20:36:52 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1oyQS7-000dkB-Ec; Fri, 25 Nov 2022 12:36:40 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 12:36:39 +0800 From: "Herbert Xu" Date: Fri, 25 Nov 2022 12:36:39 +0800 Subject: [v2 PATCH 6/9] crypto: api - Increase MAX_ALGAPI_ALIGNMASK to 127 References: To: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , Linux Crypto Mailing List Message-Id: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Previously we limited the maximum alignment mask to 63. This is mostly due to stack usage for shash. This patch introduces a separate limit for shash algorithms and increases the general limit to 127 which is the value that we need for DMA allocations on arm64. Signed-off-by: Herbert Xu --- crypto/shash.c | 9 +++++++-- include/crypto/algapi.h | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crypto/shash.c b/crypto/shash.c index 4c88e63b3350..22c744389586 100644 --- a/crypto/shash.c +++ b/crypto/shash.c @@ -18,6 +18,8 @@ =20 #include "internal.h" =20 +#define MAX_SHASH_ALIGNMASK 63 + static const struct crypto_type crypto_shash_type; =20 static int shash_no_setkey(struct crypto_shash *tfm, const u8 *key, @@ -100,7 +102,7 @@ static int shash_update_unaligned(struct shash_desc *de= sc, const u8 *data, * We cannot count on __aligned() working for large values: * https://patchwork.kernel.org/patch/9507697/ */ - u8 ubuf[MAX_ALGAPI_ALIGNMASK * 2]; + u8 ubuf[MAX_SHASH_ALIGNMASK * 2]; u8 *buf =3D PTR_ALIGN(&ubuf[0], alignmask + 1); int err; =20 @@ -142,7 +144,7 @@ static int shash_final_unaligned(struct shash_desc *des= c, u8 *out) * We cannot count on __aligned() working for large values: * https://patchwork.kernel.org/patch/9507697/ */ - u8 ubuf[MAX_ALGAPI_ALIGNMASK + HASH_MAX_DIGESTSIZE]; + u8 ubuf[MAX_SHASH_ALIGNMASK + HASH_MAX_DIGESTSIZE]; u8 *buf =3D PTR_ALIGN(&ubuf[0], alignmask + 1); int err; =20 @@ -536,6 +538,9 @@ static int shash_prepare_alg(struct shash_alg *alg) alg->statesize > HASH_MAX_STATESIZE) return -EINVAL; =20 + if (base->cra_alignmask > MAX_SHASH_ALIGNMASK) + return -EINVAL; + if ((alg->export && !alg->import) || (alg->import && !alg->export)) return -EINVAL; =20 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 4c99eb66e654..8722fd67f40a 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -22,7 +22,7 @@ * algs and architectures. Ciphers have a lower maximum size. */ #define MAX_ALGAPI_BLOCKSIZE 160 -#define MAX_ALGAPI_ALIGNMASK 63 +#define MAX_ALGAPI_ALIGNMASK 127 #define MAX_CIPHER_BLOCKSIZE 16 #define MAX_CIPHER_ALIGNMASK 15 From nobody Fri Sep 19 10:37:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FAC0C433FE for ; Fri, 25 Nov 2022 04:37:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229586AbiKYEhZ (ORCPT ); Thu, 24 Nov 2022 23:37:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229706AbiKYEg6 (ORCPT ); Thu, 24 Nov 2022 23:36:58 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EC022613C; Thu, 24 Nov 2022 20:36:54 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1oyQS9-000dkR-IC; Fri, 25 Nov 2022 12:36:42 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 12:36:41 +0800 From: "Herbert Xu" Date: Fri, 25 Nov 2022 12:36:41 +0800 Subject: [v2 PATCH 7/9] crypto: akcipher - Add ctx helpers with DMA alignment References: To: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , Linux Crypto Mailing List Message-Id: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds helpers to access the akcipher context structure and request context structure with an added alignment for DMA access. Signed-off-by: Herbert Xu --- include/crypto/internal/akcipher.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/include/crypto/internal/akcipher.h b/include/crypto/internal/a= kcipher.h index 1474a2d890fc..aaf1092b93b8 100644 --- a/include/crypto/internal/akcipher.h +++ b/include/crypto/internal/akcipher.h @@ -33,15 +33,37 @@ static inline void *akcipher_request_ctx(struct akciphe= r_request *req) return req->__ctx; } =20 +static inline void *akcipher_request_ctx_dma(struct akcipher_request *req) +{ + unsigned int align =3D crypto_dma_align(); + + if (align <=3D crypto_tfm_ctx_alignment()) + align =3D 1; + + return PTR_ALIGN(akcipher_request_ctx(req), align); +} + static inline void akcipher_set_reqsize(struct crypto_akcipher *akcipher, unsigned int reqsize) { akcipher->reqsize =3D reqsize; } =20 +static inline void akcipher_set_reqsize_dma(struct crypto_akcipher *akciph= er, + unsigned int reqsize) +{ + reqsize +=3D crypto_dma_align() & ~(crypto_tfm_ctx_alignment() - 1); + akcipher->reqsize =3D reqsize; +} + static inline void *akcipher_tfm_ctx(struct crypto_akcipher *tfm) { - return tfm->base.__crt_ctx; + return crypto_tfm_ctx(&tfm->base); +} + +static inline void *akcipher_tfm_ctx_dma(struct crypto_akcipher *tfm) +{ + return crypto_tfm_ctx_dma(&tfm->base); } =20 static inline void akcipher_request_complete(struct akcipher_request *req, From nobody Fri Sep 19 10:37:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3703C4332F for ; Fri, 25 Nov 2022 04:37:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbiKYEhu (ORCPT ); Thu, 24 Nov 2022 23:37:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbiKYEhB (ORCPT ); Thu, 24 Nov 2022 23:37:01 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1760927B00; Thu, 24 Nov 2022 20:36:56 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1oyQSB-000dkk-LW; Fri, 25 Nov 2022 12:36:44 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 12:36:43 +0800 From: "Herbert Xu" Date: Fri, 25 Nov 2022 12:36:43 +0800 Subject: [v2 PATCH 8/9] crypto: kpp - Add ctx helpers with DMA alignment References: To: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , Linux Crypto Mailing List Message-Id: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds helpers to access the kpp context structure and request context structure with an added alignment for DMA access. Signed-off-by: Herbert Xu --- include/crypto/internal/kpp.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/include/crypto/internal/kpp.h b/include/crypto/internal/kpp.h index 167662407e36..3c9726e89f53 100644 --- a/include/crypto/internal/kpp.h +++ b/include/crypto/internal/kpp.h @@ -50,15 +50,37 @@ static inline void *kpp_request_ctx(struct kpp_request = *req) return req->__ctx; } =20 +static inline void *kpp_request_ctx_dma(struct kpp_request *req) +{ + unsigned int align =3D crypto_dma_align(); + + if (align <=3D crypto_tfm_ctx_alignment()) + align =3D 1; + + return PTR_ALIGN(kpp_request_ctx(req), align); +} + static inline void kpp_set_reqsize(struct crypto_kpp *kpp, unsigned int reqsize) { kpp->reqsize =3D reqsize; } =20 +static inline void kpp_set_reqsize_dma(struct crypto_kpp *kpp, + unsigned int reqsize) +{ + reqsize +=3D crypto_dma_align() & ~(crypto_tfm_ctx_alignment() - 1); + kpp->reqsize =3D reqsize; +} + static inline void *kpp_tfm_ctx(struct crypto_kpp *tfm) { - return tfm->base.__crt_ctx; + return crypto_tfm_ctx(&tfm->base); +} + +static inline void *kpp_tfm_ctx_dma(struct crypto_kpp *tfm) +{ + return crypto_tfm_ctx_dma(&tfm->base); } =20 static inline void kpp_request_complete(struct kpp_request *req, int err) From nobody Fri Sep 19 10:37:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0760C4332F for ; Fri, 25 Nov 2022 04:38:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229795AbiKYEiN (ORCPT ); Thu, 24 Nov 2022 23:38:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbiKYEhw (ORCPT ); Thu, 24 Nov 2022 23:37:52 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9543D2A41B; Thu, 24 Nov 2022 20:37:01 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1oyQSD-000dl0-Oh; Fri, 25 Nov 2022 12:36:46 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 12:36:45 +0800 From: "Herbert Xu" Date: Fri, 25 Nov 2022 12:36:45 +0800 Subject: [v2 PATCH 9/9] crypto: caam - Set DMA alignment explicitly References: To: Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , Linux Crypto Mailing List Message-Id: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This driver has been implicitly relying on kmalloc alignment to be sufficient for DMA. This may no longer be the case with upcoming arm64 changes. This patch changes it to explicitly request DMA alignment from the Crypto API. Signed-off-by: Herbert Xu --- drivers/crypto/caam/caamalg.c | 72 +++++++-------- drivers/crypto/caam/caamalg_qi.c | 52 +++++------ drivers/crypto/caam/caamalg_qi2.c | 173 +++++++++++++++++++--------------= ----- drivers/crypto/caam/caamhash.c | 87 +++++++++---------- drivers/crypto/caam/caampkc.c | 47 +++++----- 5 files changed, 216 insertions(+), 215 deletions(-) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index d3d8bb0a6990..ecc15bc521db 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -131,7 +131,7 @@ struct caam_aead_req_ctx { =20 static int aead_null_set_sh_desc(struct crypto_aead *aead) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; struct caam_drv_private *ctrlpriv =3D dev_get_drvdata(jrdev->parent); u32 *desc; @@ -184,7 +184,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead) struct caam_aead_alg *alg =3D container_of(crypto_aead_alg(aead), struct caam_aead_alg, aead); unsigned int ivsize =3D crypto_aead_ivsize(aead); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; struct caam_drv_private *ctrlpriv =3D dev_get_drvdata(jrdev->parent); u32 ctx1_iv_off =3D 0; @@ -312,7 +312,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead) static int aead_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { - struct caam_ctx *ctx =3D crypto_aead_ctx(authenc); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(authenc); =20 ctx->authsize =3D authsize; aead_set_sh_desc(authenc); @@ -322,7 +322,7 @@ static int aead_setauthsize(struct crypto_aead *authenc, =20 static int gcm_set_sh_desc(struct crypto_aead *aead) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; unsigned int ivsize =3D crypto_aead_ivsize(aead); u32 *desc; @@ -372,7 +372,7 @@ static int gcm_set_sh_desc(struct crypto_aead *aead) =20 static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int auths= ize) { - struct caam_ctx *ctx =3D crypto_aead_ctx(authenc); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(authenc); int err; =20 err =3D crypto_gcm_check_authsize(authsize); @@ -387,7 +387,7 @@ static int gcm_setauthsize(struct crypto_aead *authenc,= unsigned int authsize) =20 static int rfc4106_set_sh_desc(struct crypto_aead *aead) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; unsigned int ivsize =3D crypto_aead_ivsize(aead); u32 *desc; @@ -440,7 +440,7 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead) static int rfc4106_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { - struct caam_ctx *ctx =3D crypto_aead_ctx(authenc); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(authenc); int err; =20 err =3D crypto_rfc4106_check_authsize(authsize); @@ -455,7 +455,7 @@ static int rfc4106_setauthsize(struct crypto_aead *auth= enc, =20 static int rfc4543_set_sh_desc(struct crypto_aead *aead) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; unsigned int ivsize =3D crypto_aead_ivsize(aead); u32 *desc; @@ -508,7 +508,7 @@ static int rfc4543_set_sh_desc(struct crypto_aead *aead) static int rfc4543_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { - struct caam_ctx *ctx =3D crypto_aead_ctx(authenc); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(authenc); =20 if (authsize !=3D 16) return -EINVAL; @@ -521,7 +521,7 @@ static int rfc4543_setauthsize(struct crypto_aead *auth= enc, =20 static int chachapoly_set_sh_desc(struct crypto_aead *aead) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; unsigned int ivsize =3D crypto_aead_ivsize(aead); u32 *desc; @@ -547,7 +547,7 @@ static int chachapoly_set_sh_desc(struct crypto_aead *a= ead) static int chachapoly_setauthsize(struct crypto_aead *aead, unsigned int authsize) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); =20 if (authsize !=3D POLY1305_DIGEST_SIZE) return -EINVAL; @@ -559,7 +559,7 @@ static int chachapoly_setauthsize(struct crypto_aead *a= ead, static int chachapoly_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); unsigned int ivsize =3D crypto_aead_ivsize(aead); unsigned int saltlen =3D CHACHAPOLY_IV_SIZE - ivsize; =20 @@ -575,7 +575,7 @@ static int chachapoly_setkey(struct crypto_aead *aead, = const u8 *key, static int aead_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; struct caam_drv_private *ctrlpriv =3D dev_get_drvdata(jrdev->parent); struct crypto_authenc_keys keys; @@ -656,7 +656,7 @@ static int des3_aead_setkey(struct crypto_aead *aead, c= onst u8 *key, static int gcm_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; int err; =20 @@ -677,7 +677,7 @@ static int gcm_setkey(struct crypto_aead *aead, static int rfc4106_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; int err; =20 @@ -703,7 +703,7 @@ static int rfc4106_setkey(struct crypto_aead *aead, static int rfc4543_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; int err; =20 @@ -729,7 +729,7 @@ static int rfc4543_setkey(struct crypto_aead *aead, static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, unsigned int keylen, const u32 ctx1_iv_off) { - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct caam_skcipher_alg *alg =3D container_of(crypto_skcipher_alg(skcipher), typeof(*alg), skcipher); @@ -832,7 +832,7 @@ static int des3_skcipher_setkey(struct crypto_skcipher = *skcipher, static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 = *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct device *jrdev =3D ctx->jrdev; struct caam_drv_private *ctrlpriv =3D dev_get_drvdata(jrdev->parent); u32 *desc; @@ -1057,7 +1057,7 @@ static void init_aead_job(struct aead_request *req, bool all_contig, bool encrypt) { struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); int authsize =3D ctx->authsize; u32 *desc =3D edesc->hw_desc; u32 out_options, in_options; @@ -1118,7 +1118,7 @@ static void init_gcm_job(struct aead_request *req, bool all_contig, bool encrypt) { struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); unsigned int ivsize =3D crypto_aead_ivsize(aead); u32 *desc =3D edesc->hw_desc; bool generic_gcm =3D (ivsize =3D=3D GCM_AES_IV_SIZE); @@ -1185,7 +1185,7 @@ static void init_authenc_job(struct aead_request *req, struct caam_aead_alg *alg =3D container_of(crypto_aead_alg(aead), struct caam_aead_alg, aead); unsigned int ivsize =3D crypto_aead_ivsize(aead); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct caam_drv_private *ctrlpriv =3D dev_get_drvdata(ctx->jrdev->parent); const bool ctr_mode =3D ((ctx->cdata.algtype & OP_ALG_AAI_MASK) =3D=3D OP_ALG_AAI_CTR_MOD128); @@ -1234,7 +1234,7 @@ static void init_skcipher_job(struct skcipher_request= *req, const bool encrypt) { struct crypto_skcipher *skcipher =3D crypto_skcipher_reqtfm(req); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct device *jrdev =3D ctx->jrdev; int ivsize =3D crypto_skcipher_ivsize(skcipher); u32 *desc =3D edesc->hw_desc; @@ -1290,7 +1290,7 @@ static struct aead_edesc *aead_edesc_alloc(struct aea= d_request *req, bool encrypt) { struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; struct caam_aead_req_ctx *rctx =3D aead_request_ctx(req); gfp_t flags =3D (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? @@ -1457,7 +1457,7 @@ static inline int chachapoly_crypt(struct aead_reques= t *req, bool encrypt) { struct aead_edesc *edesc; struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; bool all_contig; u32 *desc; @@ -1491,7 +1491,7 @@ static inline int aead_crypt(struct aead_request *req= , bool encrypt) { struct aead_edesc *edesc; struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; bool all_contig; =20 @@ -1524,7 +1524,7 @@ static int aead_decrypt(struct aead_request *req) static int aead_do_one_req(struct crypto_engine *engine, void *areq) { struct aead_request *req =3D aead_request_cast(areq); - struct caam_ctx *ctx =3D crypto_aead_ctx(crypto_aead_reqtfm(req)); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(crypto_aead_reqtfm(req)); struct caam_aead_req_ctx *rctx =3D aead_request_ctx(req); u32 *desc =3D rctx->edesc->hw_desc; int ret; @@ -1550,7 +1550,7 @@ static inline int gcm_crypt(struct aead_request *req,= bool encrypt) { struct aead_edesc *edesc; struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; bool all_contig; =20 @@ -1597,7 +1597,7 @@ static struct skcipher_edesc *skcipher_edesc_alloc(st= ruct skcipher_request *req, int desc_bytes) { struct crypto_skcipher *skcipher =3D crypto_skcipher_reqtfm(req); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct caam_skcipher_req_ctx *rctx =3D skcipher_request_ctx(req); struct device *jrdev =3D ctx->jrdev; gfp_t flags =3D (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? @@ -1756,7 +1756,7 @@ static struct skcipher_edesc *skcipher_edesc_alloc(st= ruct skcipher_request *req, static int skcipher_do_one_req(struct crypto_engine *engine, void *areq) { struct skcipher_request *req =3D skcipher_request_cast(areq); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(crypto_skcipher_reqtfm(req)); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(crypto_skcipher_reqtfm(r= eq)); struct caam_skcipher_req_ctx *rctx =3D skcipher_request_ctx(req); u32 *desc =3D rctx->edesc->hw_desc; int ret; @@ -1790,7 +1790,7 @@ static inline int skcipher_crypt(struct skcipher_requ= est *req, bool encrypt) { struct skcipher_edesc *edesc; struct crypto_skcipher *skcipher =3D crypto_skcipher_reqtfm(req); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct device *jrdev =3D ctx->jrdev; struct caam_drv_private_jr *jrpriv =3D dev_get_drvdata(jrdev); struct caam_drv_private *ctrlpriv =3D dev_get_drvdata(jrdev->parent); @@ -3397,7 +3397,7 @@ static int caam_cra_init(struct crypto_skcipher *tfm) struct skcipher_alg *alg =3D crypto_skcipher_alg(tfm); struct caam_skcipher_alg *caam_alg =3D container_of(alg, typeof(*caam_alg), skcipher); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(tfm); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(tfm); u32 alg_aai =3D caam_alg->caam.class1_alg_type & OP_ALG_AAI_MASK; int ret =3D 0; =20 @@ -3434,7 +3434,7 @@ static int caam_aead_init(struct crypto_aead *tfm) struct aead_alg *alg =3D crypto_aead_alg(tfm); struct caam_aead_alg *caam_alg =3D container_of(alg, struct caam_aead_alg, aead); - struct caam_ctx *ctx =3D crypto_aead_ctx(tfm); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(tfm); =20 crypto_aead_set_reqsize(tfm, sizeof(struct caam_aead_req_ctx)); =20 @@ -3454,7 +3454,7 @@ static void caam_exit_common(struct caam_ctx *ctx) =20 static void caam_cra_exit(struct crypto_skcipher *tfm) { - struct caam_ctx *ctx =3D crypto_skcipher_ctx(tfm); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(tfm); =20 if (ctx->fallback) crypto_free_skcipher(ctx->fallback); @@ -3463,7 +3463,7 @@ static void caam_cra_exit(struct crypto_skcipher *tfm) =20 static void caam_aead_exit(struct crypto_aead *tfm) { - caam_exit_common(crypto_aead_ctx(tfm)); + caam_exit_common(crypto_aead_ctx_dma(tfm)); } =20 void caam_algapi_exit(void) @@ -3491,7 +3491,7 @@ static void caam_skcipher_alg_init(struct caam_skciph= er_alg *t_alg) =20 alg->base.cra_module =3D THIS_MODULE; alg->base.cra_priority =3D CAAM_CRA_PRIORITY; - alg->base.cra_ctxsize =3D sizeof(struct caam_ctx); + alg->base.cra_ctxsize =3D sizeof(struct caam_ctx) + crypto_dma_padding(); alg->base.cra_flags |=3D (CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | CRYPTO_ALG_KERN_DRIVER_ONLY); =20 @@ -3505,7 +3505,7 @@ static void caam_aead_alg_init(struct caam_aead_alg *= t_alg) =20 alg->base.cra_module =3D THIS_MODULE; alg->base.cra_priority =3D CAAM_CRA_PRIORITY; - alg->base.cra_ctxsize =3D sizeof(struct caam_ctx); + alg->base.cra_ctxsize =3D sizeof(struct caam_ctx) + crypto_dma_padding(); alg->base.cra_flags =3D CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | CRYPTO_ALG_KERN_DRIVER_ONLY; =20 diff --git a/drivers/crypto/caam/caamalg_qi.c b/drivers/crypto/caam/caamalg= _qi.c index 189a7438b29c..c37b67be0492 100644 --- a/drivers/crypto/caam/caamalg_qi.c +++ b/drivers/crypto/caam/caamalg_qi.c @@ -81,7 +81,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead) { struct caam_aead_alg *alg =3D container_of(crypto_aead_alg(aead), typeof(*alg), aead); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); unsigned int ivsize =3D crypto_aead_ivsize(aead); u32 ctx1_iv_off =3D 0; u32 *nonce =3D NULL; @@ -184,7 +184,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead) =20 static int aead_setauthsize(struct crypto_aead *authenc, unsigned int auth= size) { - struct caam_ctx *ctx =3D crypto_aead_ctx(authenc); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(authenc); =20 ctx->authsize =3D authsize; aead_set_sh_desc(authenc); @@ -195,7 +195,7 @@ static int aead_setauthsize(struct crypto_aead *authenc= , unsigned int authsize) static int aead_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; struct caam_drv_private *ctrlpriv =3D dev_get_drvdata(jrdev->parent); struct crypto_authenc_keys keys; @@ -299,7 +299,7 @@ static int des3_aead_setkey(struct crypto_aead *aead, c= onst u8 *key, =20 static int gcm_set_sh_desc(struct crypto_aead *aead) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); unsigned int ivsize =3D crypto_aead_ivsize(aead); int rem_bytes =3D CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN - ctx->cdata.keylen; @@ -342,7 +342,7 @@ static int gcm_set_sh_desc(struct crypto_aead *aead) =20 static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int auths= ize) { - struct caam_ctx *ctx =3D crypto_aead_ctx(authenc); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(authenc); int err; =20 err =3D crypto_gcm_check_authsize(authsize); @@ -358,7 +358,7 @@ static int gcm_setauthsize(struct crypto_aead *authenc,= unsigned int authsize) static int gcm_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; int ret; =20 @@ -402,7 +402,7 @@ static int gcm_setkey(struct crypto_aead *aead, =20 static int rfc4106_set_sh_desc(struct crypto_aead *aead) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); unsigned int ivsize =3D crypto_aead_ivsize(aead); int rem_bytes =3D CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN - ctx->cdata.keylen; @@ -446,7 +446,7 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead) static int rfc4106_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { - struct caam_ctx *ctx =3D crypto_aead_ctx(authenc); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(authenc); int err; =20 err =3D crypto_rfc4106_check_authsize(authsize); @@ -462,7 +462,7 @@ static int rfc4106_setauthsize(struct crypto_aead *auth= enc, static int rfc4106_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; int ret; =20 @@ -510,7 +510,7 @@ static int rfc4106_setkey(struct crypto_aead *aead, =20 static int rfc4543_set_sh_desc(struct crypto_aead *aead) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); unsigned int ivsize =3D crypto_aead_ivsize(aead); int rem_bytes =3D CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN - ctx->cdata.keylen; @@ -554,7 +554,7 @@ static int rfc4543_set_sh_desc(struct crypto_aead *aead) static int rfc4543_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { - struct caam_ctx *ctx =3D crypto_aead_ctx(authenc); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(authenc); =20 if (authsize !=3D 16) return -EINVAL; @@ -568,7 +568,7 @@ static int rfc4543_setauthsize(struct crypto_aead *auth= enc, static int rfc4543_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *jrdev =3D ctx->jrdev; int ret; =20 @@ -617,7 +617,7 @@ static int rfc4543_setkey(struct crypto_aead *aead, static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, unsigned int keylen, const u32 ctx1_iv_off) { - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct caam_skcipher_alg *alg =3D container_of(crypto_skcipher_alg(skcipher), typeof(*alg), skcipher); @@ -731,7 +731,7 @@ static int des_skcipher_setkey(struct crypto_skcipher *= skcipher, static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 = *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct device *jrdev =3D ctx->jrdev; struct caam_drv_private *ctrlpriv =3D dev_get_drvdata(jrdev->parent); int ret =3D 0; @@ -915,7 +915,7 @@ static void aead_done(struct caam_drv_req *drv_req, u32= status) struct aead_edesc *edesc; struct aead_request *aead_req =3D drv_req->app_ctx; struct crypto_aead *aead =3D crypto_aead_reqtfm(aead_req); - struct caam_ctx *caam_ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *caam_ctx =3D crypto_aead_ctx_dma(aead); int ecode =3D 0; =20 qidev =3D caam_ctx->qidev; @@ -937,7 +937,7 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_= request *req, bool encrypt) { struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct caam_aead_alg *alg =3D container_of(crypto_aead_alg(aead), typeof(*alg), aead); struct device *qidev =3D ctx->qidev; @@ -1157,7 +1157,7 @@ static inline int aead_crypt(struct aead_request *req= , bool encrypt) { struct aead_edesc *edesc; struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); int ret; =20 if (unlikely(caam_congested)) @@ -1207,7 +1207,7 @@ static void skcipher_done(struct caam_drv_req *drv_re= q, u32 status) struct skcipher_edesc *edesc; struct skcipher_request *req =3D drv_req->app_ctx; struct crypto_skcipher *skcipher =3D crypto_skcipher_reqtfm(req); - struct caam_ctx *caam_ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *caam_ctx =3D crypto_skcipher_ctx_dma(skcipher); struct device *qidev =3D caam_ctx->qidev; int ivsize =3D crypto_skcipher_ivsize(skcipher); int ecode =3D 0; @@ -1245,7 +1245,7 @@ static struct skcipher_edesc *skcipher_edesc_alloc(st= ruct skcipher_request *req, bool encrypt) { struct crypto_skcipher *skcipher =3D crypto_skcipher_reqtfm(req); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct device *qidev =3D ctx->qidev; gfp_t flags =3D (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? GFP_KERNEL : GFP_ATOMIC; @@ -1405,7 +1405,7 @@ static inline int skcipher_crypt(struct skcipher_requ= est *req, bool encrypt) { struct skcipher_edesc *edesc; struct crypto_skcipher *skcipher =3D crypto_skcipher_reqtfm(req); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct caam_drv_private *ctrlpriv =3D dev_get_drvdata(ctx->jrdev->parent); int ret; =20 @@ -2491,7 +2491,7 @@ static int caam_cra_init(struct crypto_skcipher *tfm) struct skcipher_alg *alg =3D crypto_skcipher_alg(tfm); struct caam_skcipher_alg *caam_alg =3D container_of(alg, typeof(*caam_alg), skcipher); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(tfm); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(tfm); u32 alg_aai =3D caam_alg->caam.class1_alg_type & OP_ALG_AAI_MASK; int ret =3D 0; =20 @@ -2524,7 +2524,7 @@ static int caam_aead_init(struct crypto_aead *tfm) struct aead_alg *alg =3D crypto_aead_alg(tfm); struct caam_aead_alg *caam_alg =3D container_of(alg, typeof(*caam_alg), aead); - struct caam_ctx *ctx =3D crypto_aead_ctx(tfm); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(tfm); =20 return caam_init_common(ctx, &caam_alg->caam, !caam_alg->caam.nodkp); } @@ -2542,7 +2542,7 @@ static void caam_exit_common(struct caam_ctx *ctx) =20 static void caam_cra_exit(struct crypto_skcipher *tfm) { - struct caam_ctx *ctx =3D crypto_skcipher_ctx(tfm); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(tfm); =20 if (ctx->fallback) crypto_free_skcipher(ctx->fallback); @@ -2551,7 +2551,7 @@ static void caam_cra_exit(struct crypto_skcipher *tfm) =20 static void caam_aead_exit(struct crypto_aead *tfm) { - caam_exit_common(crypto_aead_ctx(tfm)); + caam_exit_common(crypto_aead_ctx_dma(tfm)); } =20 void caam_qi_algapi_exit(void) @@ -2579,7 +2579,7 @@ static void caam_skcipher_alg_init(struct caam_skciph= er_alg *t_alg) =20 alg->base.cra_module =3D THIS_MODULE; alg->base.cra_priority =3D CAAM_CRA_PRIORITY; - alg->base.cra_ctxsize =3D sizeof(struct caam_ctx); + alg->base.cra_ctxsize =3D sizeof(struct caam_ctx) + crypto_dma_padding(); alg->base.cra_flags |=3D (CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | CRYPTO_ALG_KERN_DRIVER_ONLY); =20 @@ -2593,7 +2593,7 @@ static void caam_aead_alg_init(struct caam_aead_alg *= t_alg) =20 alg->base.cra_module =3D THIS_MODULE; alg->base.cra_priority =3D CAAM_CRA_PRIORITY; - alg->base.cra_ctxsize =3D sizeof(struct caam_ctx); + alg->base.cra_ctxsize =3D sizeof(struct caam_ctx) + crypto_dma_padding(); alg->base.cra_flags =3D CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | CRYPTO_ALG_KERN_DRIVER_ONLY; =20 diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamal= g_qi2.c index 4482cb145d05..1b0dd742c53f 100644 --- a/drivers/crypto/caam/caamalg_qi2.c +++ b/drivers/crypto/caam/caamalg_qi2.c @@ -134,12 +134,12 @@ static struct caam_request *to_caam_req(struct crypto= _async_request *areq) { switch (crypto_tfm_alg_type(areq->tfm)) { case CRYPTO_ALG_TYPE_SKCIPHER: - return skcipher_request_ctx(skcipher_request_cast(areq)); + return skcipher_request_ctx_dma(skcipher_request_cast(areq)); case CRYPTO_ALG_TYPE_AEAD: - return aead_request_ctx(container_of(areq, struct aead_request, - base)); + return aead_request_ctx_dma( + container_of(areq, struct aead_request, base)); case CRYPTO_ALG_TYPE_AHASH: - return ahash_request_ctx(ahash_request_cast(areq)); + return ahash_request_ctx_dma(ahash_request_cast(areq)); default: return ERR_PTR(-EINVAL); } @@ -171,7 +171,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead) { struct caam_aead_alg *alg =3D container_of(crypto_aead_alg(aead), typeof(*alg), aead); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); unsigned int ivsize =3D crypto_aead_ivsize(aead); struct device *dev =3D ctx->dev; struct dpaa2_caam_priv *priv =3D dev_get_drvdata(dev); @@ -276,7 +276,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead) =20 static int aead_setauthsize(struct crypto_aead *authenc, unsigned int auth= size) { - struct caam_ctx *ctx =3D crypto_aead_ctx(authenc); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(authenc); =20 ctx->authsize =3D authsize; aead_set_sh_desc(authenc); @@ -287,7 +287,7 @@ static int aead_setauthsize(struct crypto_aead *authenc= , unsigned int authsize) static int aead_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *dev =3D ctx->dev; struct crypto_authenc_keys keys; =20 @@ -350,10 +350,10 @@ static struct aead_edesc *aead_edesc_alloc(struct aea= d_request *req, bool encrypt) { struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_request *req_ctx =3D aead_request_ctx(req); + struct caam_request *req_ctx =3D aead_request_ctx_dma(req); struct dpaa2_fl_entry *in_fle =3D &req_ctx->fd_flt[1]; struct dpaa2_fl_entry *out_fle =3D &req_ctx->fd_flt[0]; - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct caam_aead_alg *alg =3D container_of(crypto_aead_alg(aead), typeof(*alg), aead); struct device *dev =3D ctx->dev; @@ -587,7 +587,7 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_= request *req, =20 static int chachapoly_set_sh_desc(struct crypto_aead *aead) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); unsigned int ivsize =3D crypto_aead_ivsize(aead); struct device *dev =3D ctx->dev; struct caam_flc *flc; @@ -620,7 +620,7 @@ static int chachapoly_set_sh_desc(struct crypto_aead *a= ead) static int chachapoly_setauthsize(struct crypto_aead *aead, unsigned int authsize) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); =20 if (authsize !=3D POLY1305_DIGEST_SIZE) return -EINVAL; @@ -632,7 +632,7 @@ static int chachapoly_setauthsize(struct crypto_aead *a= ead, static int chachapoly_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); unsigned int ivsize =3D crypto_aead_ivsize(aead); unsigned int saltlen =3D CHACHAPOLY_IV_SIZE - ivsize; =20 @@ -647,7 +647,7 @@ static int chachapoly_setkey(struct crypto_aead *aead, = const u8 *key, =20 static int gcm_set_sh_desc(struct crypto_aead *aead) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *dev =3D ctx->dev; unsigned int ivsize =3D crypto_aead_ivsize(aead); struct caam_flc *flc; @@ -704,7 +704,7 @@ static int gcm_set_sh_desc(struct crypto_aead *aead) =20 static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int auths= ize) { - struct caam_ctx *ctx =3D crypto_aead_ctx(authenc); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(authenc); int err; =20 err =3D crypto_gcm_check_authsize(authsize); @@ -720,7 +720,7 @@ static int gcm_setauthsize(struct crypto_aead *authenc,= unsigned int authsize) static int gcm_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *dev =3D ctx->dev; int ret; =20 @@ -739,7 +739,7 @@ static int gcm_setkey(struct crypto_aead *aead, =20 static int rfc4106_set_sh_desc(struct crypto_aead *aead) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *dev =3D ctx->dev; unsigned int ivsize =3D crypto_aead_ivsize(aead); struct caam_flc *flc; @@ -799,7 +799,7 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead) static int rfc4106_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { - struct caam_ctx *ctx =3D crypto_aead_ctx(authenc); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(authenc); int err; =20 err =3D crypto_rfc4106_check_authsize(authsize); @@ -815,7 +815,7 @@ static int rfc4106_setauthsize(struct crypto_aead *auth= enc, static int rfc4106_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *dev =3D ctx->dev; int ret; =20 @@ -840,7 +840,7 @@ static int rfc4106_setkey(struct crypto_aead *aead, =20 static int rfc4543_set_sh_desc(struct crypto_aead *aead) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *dev =3D ctx->dev; unsigned int ivsize =3D crypto_aead_ivsize(aead); struct caam_flc *flc; @@ -900,7 +900,7 @@ static int rfc4543_set_sh_desc(struct crypto_aead *aead) static int rfc4543_setauthsize(struct crypto_aead *authenc, unsigned int authsize) { - struct caam_ctx *ctx =3D crypto_aead_ctx(authenc); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(authenc); =20 if (authsize !=3D 16) return -EINVAL; @@ -914,7 +914,7 @@ static int rfc4543_setauthsize(struct crypto_aead *auth= enc, static int rfc4543_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); struct device *dev =3D ctx->dev; int ret; =20 @@ -940,7 +940,7 @@ static int rfc4543_setkey(struct crypto_aead *aead, static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, unsigned int keylen, const u32 ctx1_iv_off) { - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct caam_skcipher_alg *alg =3D container_of(crypto_skcipher_alg(skcipher), struct caam_skcipher_alg, skcipher); @@ -1059,7 +1059,7 @@ static int des3_skcipher_setkey(struct crypto_skciphe= r *skcipher, static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 = *key, unsigned int keylen) { - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct device *dev =3D ctx->dev; struct dpaa2_caam_priv *priv =3D dev_get_drvdata(dev); struct caam_flc *flc; @@ -1109,10 +1109,10 @@ static int xts_skcipher_setkey(struct crypto_skciph= er *skcipher, const u8 *key, static struct skcipher_edesc *skcipher_edesc_alloc(struct skcipher_request= *req) { struct crypto_skcipher *skcipher =3D crypto_skcipher_reqtfm(req); - struct caam_request *req_ctx =3D skcipher_request_ctx(req); + struct caam_request *req_ctx =3D skcipher_request_ctx_dma(req); struct dpaa2_fl_entry *in_fle =3D &req_ctx->fd_flt[1]; struct dpaa2_fl_entry *out_fle =3D &req_ctx->fd_flt[0]; - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct device *dev =3D ctx->dev; gfp_t flags =3D (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? GFP_KERNEL : GFP_ATOMIC; @@ -1286,7 +1286,7 @@ static void aead_encrypt_done(void *cbk_ctx, u32 stat= us) struct caam_request *req_ctx =3D to_caam_req(areq); struct aead_edesc *edesc =3D req_ctx->edesc; struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); int ecode =3D 0; =20 dev_dbg(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status); @@ -1307,7 +1307,7 @@ static void aead_decrypt_done(void *cbk_ctx, u32 stat= us) struct caam_request *req_ctx =3D to_caam_req(areq); struct aead_edesc *edesc =3D req_ctx->edesc; struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); int ecode =3D 0; =20 dev_dbg(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status); @@ -1324,8 +1324,8 @@ static int aead_encrypt(struct aead_request *req) { struct aead_edesc *edesc; struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); - struct caam_request *caam_req =3D aead_request_ctx(req); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); + struct caam_request *caam_req =3D aead_request_ctx_dma(req); int ret; =20 /* allocate extended descriptor */ @@ -1352,8 +1352,8 @@ static int aead_decrypt(struct aead_request *req) { struct aead_edesc *edesc; struct crypto_aead *aead =3D crypto_aead_reqtfm(req); - struct caam_ctx *ctx =3D crypto_aead_ctx(aead); - struct caam_request *caam_req =3D aead_request_ctx(req); + struct caam_ctx *ctx =3D crypto_aead_ctx_dma(aead); + struct caam_request *caam_req =3D aead_request_ctx_dma(req); int ret; =20 /* allocate extended descriptor */ @@ -1392,7 +1392,7 @@ static void skcipher_encrypt_done(void *cbk_ctx, u32 = status) struct skcipher_request *req =3D skcipher_request_cast(areq); struct caam_request *req_ctx =3D to_caam_req(areq); struct crypto_skcipher *skcipher =3D crypto_skcipher_reqtfm(req); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct skcipher_edesc *edesc =3D req_ctx->edesc; int ecode =3D 0; int ivsize =3D crypto_skcipher_ivsize(skcipher); @@ -1430,7 +1430,7 @@ static void skcipher_decrypt_done(void *cbk_ctx, u32 = status) struct skcipher_request *req =3D skcipher_request_cast(areq); struct caam_request *req_ctx =3D to_caam_req(areq); struct crypto_skcipher *skcipher =3D crypto_skcipher_reqtfm(req); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); struct skcipher_edesc *edesc =3D req_ctx->edesc; int ecode =3D 0; int ivsize =3D crypto_skcipher_ivsize(skcipher); @@ -1474,8 +1474,8 @@ static int skcipher_encrypt(struct skcipher_request *= req) { struct skcipher_edesc *edesc; struct crypto_skcipher *skcipher =3D crypto_skcipher_reqtfm(req); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); - struct caam_request *caam_req =3D skcipher_request_ctx(req); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); + struct caam_request *caam_req =3D skcipher_request_ctx_dma(req); struct dpaa2_caam_priv *priv =3D dev_get_drvdata(ctx->dev); int ret; =20 @@ -1524,8 +1524,8 @@ static int skcipher_decrypt(struct skcipher_request *= req) { struct skcipher_edesc *edesc; struct crypto_skcipher *skcipher =3D crypto_skcipher_reqtfm(req); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(skcipher); - struct caam_request *caam_req =3D skcipher_request_ctx(req); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(skcipher); + struct caam_request *caam_req =3D skcipher_request_ctx_dma(req); struct dpaa2_caam_priv *priv =3D dev_get_drvdata(ctx->dev); int ret; =20 @@ -1603,7 +1603,7 @@ static int caam_cra_init_skcipher(struct crypto_skcip= her *tfm) struct skcipher_alg *alg =3D crypto_skcipher_alg(tfm); struct caam_skcipher_alg *caam_alg =3D container_of(alg, typeof(*caam_alg), skcipher); - struct caam_ctx *ctx =3D crypto_skcipher_ctx(tfm); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(tfm); u32 alg_aai =3D caam_alg->caam.class1_alg_type & OP_ALG_AAI_MASK; int ret =3D 0; =20 @@ -1621,10 +1621,12 @@ static int caam_cra_init_skcipher(struct crypto_skc= ipher *tfm) } =20 ctx->fallback =3D fallback; - crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_request) + - crypto_skcipher_reqsize(fallback)); + crypto_skcipher_set_reqsize_dma( + tfm, sizeof(struct caam_request) + + crypto_skcipher_reqsize(fallback)); } else { - crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_request)); + crypto_skcipher_set_reqsize_dma(tfm, + sizeof(struct caam_request)); } =20 ret =3D caam_cra_init(ctx, &caam_alg->caam, false); @@ -1640,8 +1642,8 @@ static int caam_cra_init_aead(struct crypto_aead *tfm) struct caam_aead_alg *caam_alg =3D container_of(alg, typeof(*caam_alg), aead); =20 - crypto_aead_set_reqsize(tfm, sizeof(struct caam_request)); - return caam_cra_init(crypto_aead_ctx(tfm), &caam_alg->caam, + crypto_aead_set_reqsize_dma(tfm, sizeof(struct caam_request)); + return caam_cra_init(crypto_aead_ctx_dma(tfm), &caam_alg->caam, !caam_alg->caam.nodkp); } =20 @@ -1654,7 +1656,7 @@ static void caam_exit_common(struct caam_ctx *ctx) =20 static void caam_cra_exit(struct crypto_skcipher *tfm) { - struct caam_ctx *ctx =3D crypto_skcipher_ctx(tfm); + struct caam_ctx *ctx =3D crypto_skcipher_ctx_dma(tfm); =20 if (ctx->fallback) crypto_free_skcipher(ctx->fallback); @@ -1663,7 +1665,7 @@ static void caam_cra_exit(struct crypto_skcipher *tfm) =20 static void caam_cra_exit_aead(struct crypto_aead *tfm) { - caam_exit_common(crypto_aead_ctx(tfm)); + caam_exit_common(crypto_aead_ctx_dma(tfm)); } =20 static struct caam_skcipher_alg driver_algs[] =3D { @@ -3008,7 +3010,7 @@ static void caam_skcipher_alg_init(struct caam_skciph= er_alg *t_alg) =20 alg->base.cra_module =3D THIS_MODULE; alg->base.cra_priority =3D CAAM_CRA_PRIORITY; - alg->base.cra_ctxsize =3D sizeof(struct caam_ctx); + alg->base.cra_ctxsize =3D sizeof(struct caam_ctx) + crypto_dma_padding(); alg->base.cra_flags |=3D (CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | CRYPTO_ALG_KERN_DRIVER_ONLY); =20 @@ -3022,7 +3024,7 @@ static void caam_aead_alg_init(struct caam_aead_alg *= t_alg) =20 alg->base.cra_module =3D THIS_MODULE; alg->base.cra_priority =3D CAAM_CRA_PRIORITY; - alg->base.cra_ctxsize =3D sizeof(struct caam_ctx); + alg->base.cra_ctxsize =3D sizeof(struct caam_ctx) + crypto_dma_padding(); alg->base.cra_flags =3D CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | CRYPTO_ALG_KERN_DRIVER_ONLY; =20 @@ -3132,7 +3134,7 @@ static inline int ctx_map_to_qm_sg(struct device *dev, =20 static int ahash_set_sh_desc(struct crypto_ahash *ahash) { - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); int digestsize =3D crypto_ahash_digestsize(ahash); struct dpaa2_caam_priv *priv =3D dev_get_drvdata(ctx->dev); struct caam_flc *flc; @@ -3305,7 +3307,7 @@ static int hash_digest_key(struct caam_hash_ctx *ctx,= u32 *keylen, u8 *key, static int ahash_setkey(struct crypto_ahash *ahash, const u8 *key, unsigned int keylen) { - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); unsigned int blocksize =3D crypto_tfm_alg_blocksize(&ahash->base); unsigned int digestsize =3D crypto_ahash_digestsize(ahash); int ret; @@ -3356,7 +3358,7 @@ static int ahash_setkey(struct crypto_ahash *ahash, c= onst u8 *key, static inline void ahash_unmap(struct device *dev, struct ahash_edesc *ede= sc, struct ahash_request *req) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); =20 if (edesc->src_nents) dma_unmap_sg(dev, req->src, edesc->src_nents, DMA_TO_DEVICE); @@ -3376,7 +3378,7 @@ static inline void ahash_unmap_ctx(struct device *dev, struct ahash_edesc *edesc, struct ahash_request *req, u32 flag) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); =20 if (state->ctx_dma) { dma_unmap_single(dev, state->ctx_dma, state->ctx_dma_len, flag); @@ -3390,9 +3392,9 @@ static void ahash_done(void *cbk_ctx, u32 status) struct crypto_async_request *areq =3D cbk_ctx; struct ahash_request *req =3D ahash_request_cast(areq); struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct ahash_edesc *edesc =3D state->caam_req.edesc; - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); int digestsize =3D crypto_ahash_digestsize(ahash); int ecode =3D 0; =20 @@ -3417,9 +3419,9 @@ static void ahash_done_bi(void *cbk_ctx, u32 status) struct crypto_async_request *areq =3D cbk_ctx; struct ahash_request *req =3D ahash_request_cast(areq); struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct ahash_edesc *edesc =3D state->caam_req.edesc; - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); int ecode =3D 0; =20 dev_dbg(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status); @@ -3455,9 +3457,9 @@ static void ahash_done_ctx_src(void *cbk_ctx, u32 sta= tus) struct crypto_async_request *areq =3D cbk_ctx; struct ahash_request *req =3D ahash_request_cast(areq); struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct ahash_edesc *edesc =3D state->caam_req.edesc; - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); int digestsize =3D crypto_ahash_digestsize(ahash); int ecode =3D 0; =20 @@ -3482,9 +3484,9 @@ static void ahash_done_ctx_dst(void *cbk_ctx, u32 sta= tus) struct crypto_async_request *areq =3D cbk_ctx; struct ahash_request *req =3D ahash_request_cast(areq); struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct ahash_edesc *edesc =3D state->caam_req.edesc; - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); int ecode =3D 0; =20 dev_dbg(ctx->dev, "%s %d: err 0x%x\n", __func__, __LINE__, status); @@ -3518,8 +3520,8 @@ static void ahash_done_ctx_dst(void *cbk_ctx, u32 sta= tus) static int ahash_update_ctx(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct caam_request *req_ctx =3D &state->caam_req; struct dpaa2_fl_entry *in_fle =3D &req_ctx->fd_flt[1]; struct dpaa2_fl_entry *out_fle =3D &req_ctx->fd_flt[0]; @@ -3637,8 +3639,8 @@ static int ahash_update_ctx(struct ahash_request *req) static int ahash_final_ctx(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct caam_request *req_ctx =3D &state->caam_req; struct dpaa2_fl_entry *in_fle =3D &req_ctx->fd_flt[1]; struct dpaa2_fl_entry *out_fle =3D &req_ctx->fd_flt[0]; @@ -3708,8 +3710,8 @@ static int ahash_final_ctx(struct ahash_request *req) static int ahash_finup_ctx(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct caam_request *req_ctx =3D &state->caam_req; struct dpaa2_fl_entry *in_fle =3D &req_ctx->fd_flt[1]; struct dpaa2_fl_entry *out_fle =3D &req_ctx->fd_flt[0]; @@ -3802,8 +3804,8 @@ static int ahash_finup_ctx(struct ahash_request *req) static int ahash_digest(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct caam_request *req_ctx =3D &state->caam_req; struct dpaa2_fl_entry *in_fle =3D &req_ctx->fd_flt[1]; struct dpaa2_fl_entry *out_fle =3D &req_ctx->fd_flt[0]; @@ -3897,8 +3899,8 @@ static int ahash_digest(struct ahash_request *req) static int ahash_final_no_ctx(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct caam_request *req_ctx =3D &state->caam_req; struct dpaa2_fl_entry *in_fle =3D &req_ctx->fd_flt[1]; struct dpaa2_fl_entry *out_fle =3D &req_ctx->fd_flt[0]; @@ -3970,8 +3972,8 @@ static int ahash_final_no_ctx(struct ahash_request *r= eq) static int ahash_update_no_ctx(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct caam_request *req_ctx =3D &state->caam_req; struct dpaa2_fl_entry *in_fle =3D &req_ctx->fd_flt[1]; struct dpaa2_fl_entry *out_fle =3D &req_ctx->fd_flt[0]; @@ -4091,8 +4093,8 @@ static int ahash_update_no_ctx(struct ahash_request *= req) static int ahash_finup_no_ctx(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct caam_request *req_ctx =3D &state->caam_req; struct dpaa2_fl_entry *in_fle =3D &req_ctx->fd_flt[1]; struct dpaa2_fl_entry *out_fle =3D &req_ctx->fd_flt[0]; @@ -4187,8 +4189,8 @@ static int ahash_finup_no_ctx(struct ahash_request *r= eq) static int ahash_update_first(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct caam_request *req_ctx =3D &state->caam_req; struct dpaa2_fl_entry *in_fle =3D &req_ctx->fd_flt[1]; struct dpaa2_fl_entry *out_fle =3D &req_ctx->fd_flt[0]; @@ -4320,7 +4322,7 @@ static int ahash_finup_first(struct ahash_request *re= q) =20 static int ahash_init(struct ahash_request *req) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); =20 state->update =3D ahash_update_first; state->finup =3D ahash_finup_first; @@ -4337,28 +4339,28 @@ static int ahash_init(struct ahash_request *req) =20 static int ahash_update(struct ahash_request *req) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); =20 return state->update(req); } =20 static int ahash_finup(struct ahash_request *req) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); =20 return state->finup(req); } =20 static int ahash_final(struct ahash_request *req) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); =20 return state->final(req); } =20 static int ahash_export(struct ahash_request *req, void *out) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct caam_export_state *export =3D out; u8 *buf =3D state->buf; int len =3D state->buflen; @@ -4375,7 +4377,7 @@ static int ahash_export(struct ahash_request *req, vo= id *out) =20 static int ahash_import(struct ahash_request *req, const void *in) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); const struct caam_export_state *export =3D in; =20 memset(state, 0, sizeof(*state)); @@ -4547,7 +4549,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm) container_of(halg, struct ahash_alg, halg); struct caam_hash_alg *caam_hash =3D container_of(alg, struct caam_hash_alg, ahash_alg); - struct caam_hash_ctx *ctx =3D crypto_tfm_ctx(tfm); + struct caam_hash_ctx *ctx =3D crypto_tfm_ctx_dma(tfm); /* Sizes for MDHA running digests: MD5, SHA1, 224, 256, 384, 512 */ static const u8 runninglen[] =3D { HASH_MSG_LEN + MD5_DIGEST_SIZE, HASH_MSG_LEN + SHA1_DIGEST_SIZE, @@ -4594,8 +4596,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm) OP_ALG_ALGSEL_SUBMASK) >> OP_ALG_ALGSEL_SHIFT]; =20 - crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), - sizeof(struct caam_hash_state)); + crypto_ahash_set_reqsize_dma(ahash, sizeof(struct caam_hash_state)); =20 /* * For keyed hash algorithms shared descriptors @@ -4606,7 +4607,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm) =20 static void caam_hash_cra_exit(struct crypto_tfm *tfm) { - struct caam_hash_ctx *ctx =3D crypto_tfm_ctx(tfm); + struct caam_hash_ctx *ctx =3D crypto_tfm_ctx_dma(tfm); =20 dma_unmap_single_attrs(ctx->dev, ctx->flc_dma[0], sizeof(ctx->flc), DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC); @@ -4646,7 +4647,7 @@ static struct caam_hash_alg *caam_hash_alloc(struct d= evice *dev, alg->cra_module =3D THIS_MODULE; alg->cra_init =3D caam_hash_cra_init; alg->cra_exit =3D caam_hash_cra_exit; - alg->cra_ctxsize =3D sizeof(struct caam_hash_ctx); + alg->cra_ctxsize =3D sizeof(struct caam_hash_ctx) + crypto_dma_padding(); alg->cra_priority =3D CAAM_CRA_PRIORITY; alg->cra_blocksize =3D template->blocksize; alg->cra_alignmask =3D 0; diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index 36ef738e4a18..1050e965a438 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -199,7 +199,7 @@ static inline int ctx_map_to_sec4_sg(struct device *jrd= ev, =20 static int ahash_set_sh_desc(struct crypto_ahash *ahash) { - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); int digestsize =3D crypto_ahash_digestsize(ahash); struct device *jrdev =3D ctx->jrdev; struct caam_drv_private *ctrlpriv =3D dev_get_drvdata(jrdev->parent); @@ -255,7 +255,7 @@ static int ahash_set_sh_desc(struct crypto_ahash *ahash) =20 static int axcbc_set_sh_desc(struct crypto_ahash *ahash) { - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); int digestsize =3D crypto_ahash_digestsize(ahash); struct device *jrdev =3D ctx->jrdev; u32 *desc; @@ -307,7 +307,7 @@ static int axcbc_set_sh_desc(struct crypto_ahash *ahash) =20 static int acmac_set_sh_desc(struct crypto_ahash *ahash) { - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); int digestsize =3D crypto_ahash_digestsize(ahash); struct device *jrdev =3D ctx->jrdev; u32 *desc; @@ -421,7 +421,7 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, u= 32 *keylen, u8 *key, static int ahash_setkey(struct crypto_ahash *ahash, const u8 *key, unsigned int keylen) { - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); struct device *jrdev =3D ctx->jrdev; int blocksize =3D crypto_tfm_alg_blocksize(&ahash->base); int digestsize =3D crypto_ahash_digestsize(ahash); @@ -484,7 +484,7 @@ static int ahash_setkey(struct crypto_ahash *ahash, static int axcbc_setkey(struct crypto_ahash *ahash, const u8 *key, unsigned int keylen) { - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); struct device *jrdev =3D ctx->jrdev; =20 if (keylen !=3D AES_KEYSIZE_128) @@ -504,7 +504,7 @@ static int axcbc_setkey(struct crypto_ahash *ahash, con= st u8 *key, static int acmac_setkey(struct crypto_ahash *ahash, const u8 *key, unsigned int keylen) { - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); int err; =20 err =3D aes_check_keylen(keylen); @@ -543,7 +543,7 @@ static inline void ahash_unmap(struct device *dev, struct ahash_edesc *edesc, struct ahash_request *req, int dst_len) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); =20 if (edesc->src_nents) dma_unmap_sg(dev, req->src, edesc->src_nents, DMA_TO_DEVICE); @@ -563,7 +563,7 @@ static inline void ahash_unmap_ctx(struct device *dev, struct ahash_edesc *edesc, struct ahash_request *req, int dst_len, u32 flag) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); =20 if (state->ctx_dma) { dma_unmap_single(dev, state->ctx_dma, state->ctx_dma_len, flag); @@ -580,8 +580,8 @@ static inline void ahash_done_cpy(struct device *jrdev,= u32 *desc, u32 err, struct ahash_edesc *edesc; struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); int digestsize =3D crypto_ahash_digestsize(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); int ecode =3D 0; bool has_bklog; =20 @@ -630,8 +630,8 @@ static inline void ahash_done_switch(struct device *jrd= ev, u32 *desc, u32 err, struct caam_drv_private_jr *jrp =3D dev_get_drvdata(jrdev); struct ahash_edesc *edesc; struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); int digestsize =3D crypto_ahash_digestsize(ahash); int ecode =3D 0; bool has_bklog; @@ -695,8 +695,8 @@ static struct ahash_edesc *ahash_edesc_alloc(struct aha= sh_request *req, dma_addr_t sh_desc_dma) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); gfp_t flags =3D (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? GFP_KERNEL : GFP_ATOMIC; struct ahash_edesc *edesc; @@ -755,8 +755,8 @@ static int ahash_edesc_add_src(struct caam_hash_ctx *ct= x, static int ahash_do_one_req(struct crypto_engine *engine, void *areq) { struct ahash_request *req =3D ahash_request_cast(areq); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(crypto_ahash_reqtfm(req)); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(crypto_ahash_reqtfm(re= q)); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct device *jrdev =3D ctx->jrdev; u32 *desc =3D state->edesc->hw_desc; int ret; @@ -785,7 +785,7 @@ static int ahash_enqueue_req(struct device *jrdev, int dst_len, enum dma_data_direction dir) { struct caam_drv_private_jr *jrpriv =3D dev_get_drvdata(jrdev); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct ahash_edesc *edesc =3D state->edesc; u32 *desc =3D edesc->hw_desc; int ret; @@ -815,8 +815,8 @@ static int ahash_enqueue_req(struct device *jrdev, static int ahash_update_ctx(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct device *jrdev =3D ctx->jrdev; u8 *buf =3D state->buf; int *buflen =3D &state->buflen; @@ -940,8 +940,8 @@ static int ahash_update_ctx(struct ahash_request *req) static int ahash_final_ctx(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct device *jrdev =3D ctx->jrdev; int buflen =3D state->buflen; u32 *desc; @@ -1001,8 +1001,8 @@ static int ahash_final_ctx(struct ahash_request *req) static int ahash_finup_ctx(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct device *jrdev =3D ctx->jrdev; int buflen =3D state->buflen; u32 *desc; @@ -1075,8 +1075,8 @@ static int ahash_finup_ctx(struct ahash_request *req) static int ahash_digest(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct device *jrdev =3D ctx->jrdev; u32 *desc; int digestsize =3D crypto_ahash_digestsize(ahash); @@ -1142,8 +1142,8 @@ static int ahash_digest(struct ahash_request *req) static int ahash_final_no_ctx(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct device *jrdev =3D ctx->jrdev; u8 *buf =3D state->buf; int buflen =3D state->buflen; @@ -1191,8 +1191,8 @@ static int ahash_final_no_ctx(struct ahash_request *r= eq) static int ahash_update_no_ctx(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct device *jrdev =3D ctx->jrdev; u8 *buf =3D state->buf; int *buflen =3D &state->buflen; @@ -1312,8 +1312,8 @@ static int ahash_update_no_ctx(struct ahash_request *= req) static int ahash_finup_no_ctx(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct device *jrdev =3D ctx->jrdev; int buflen =3D state->buflen; u32 *desc; @@ -1388,8 +1388,8 @@ static int ahash_finup_no_ctx(struct ahash_request *r= eq) static int ahash_update_first(struct ahash_request *req) { struct crypto_ahash *ahash =3D crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx =3D crypto_ahash_ctx(ahash); - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct device *jrdev =3D ctx->jrdev; u8 *buf =3D state->buf; int *buflen =3D &state->buflen; @@ -1498,7 +1498,7 @@ static int ahash_finup_first(struct ahash_request *re= q) =20 static int ahash_init(struct ahash_request *req) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); =20 state->update =3D ahash_update_first; state->finup =3D ahash_finup_first; @@ -1515,28 +1515,28 @@ static int ahash_init(struct ahash_request *req) =20 static int ahash_update(struct ahash_request *req) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); =20 return state->update(req); } =20 static int ahash_finup(struct ahash_request *req) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); =20 return state->finup(req); } =20 static int ahash_final(struct ahash_request *req) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); =20 return state->final(req); } =20 static int ahash_export(struct ahash_request *req, void *out) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); struct caam_export_state *export =3D out; u8 *buf =3D state->buf; int len =3D state->buflen; @@ -1553,7 +1553,7 @@ static int ahash_export(struct ahash_request *req, vo= id *out) =20 static int ahash_import(struct ahash_request *req, const void *in) { - struct caam_hash_state *state =3D ahash_request_ctx(req); + struct caam_hash_state *state =3D ahash_request_ctx_dma(req); const struct caam_export_state *export =3D in; =20 memset(state, 0, sizeof(*state)); @@ -1762,7 +1762,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm) container_of(halg, struct ahash_alg, halg); struct caam_hash_alg *caam_hash =3D container_of(alg, struct caam_hash_alg, ahash_alg); - struct caam_hash_ctx *ctx =3D crypto_tfm_ctx(tfm); + struct caam_hash_ctx *ctx =3D crypto_ahash_ctx_dma(ahash); /* Sizes for MDHA running digests: MD5, SHA1, 224, 256, 384, 512 */ static const u8 runninglen[] =3D { HASH_MSG_LEN + MD5_DIGEST_SIZE, HASH_MSG_LEN + SHA1_DIGEST_SIZE, @@ -1854,8 +1854,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm) =20 ctx->enginectx.op.do_one_request =3D ahash_do_one_req; =20 - crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), - sizeof(struct caam_hash_state)); + crypto_ahash_set_reqsize_dma(ahash, sizeof(struct caam_hash_state)); =20 /* * For keyed hash algorithms shared descriptors @@ -1866,7 +1865,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm) =20 static void caam_hash_cra_exit(struct crypto_tfm *tfm) { - struct caam_hash_ctx *ctx =3D crypto_tfm_ctx(tfm); + struct caam_hash_ctx *ctx =3D crypto_tfm_ctx_dma(tfm); =20 dma_unmap_single_attrs(ctx->jrdev, ctx->sh_desc_update_dma, offsetof(struct caam_hash_ctx, key) - @@ -1926,7 +1925,7 @@ caam_hash_alloc(struct caam_hash_template *template, alg->cra_module =3D THIS_MODULE; alg->cra_init =3D caam_hash_cra_init; alg->cra_exit =3D caam_hash_cra_exit; - alg->cra_ctxsize =3D sizeof(struct caam_hash_ctx); + alg->cra_ctxsize =3D sizeof(struct caam_hash_ctx) + crypto_dma_padding(); alg->cra_priority =3D CAAM_CRA_PRIORITY; alg->cra_blocksize =3D template->blocksize; alg->cra_alignmask =3D 0; diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c index 642846693d7c..aef031946f33 100644 --- a/drivers/crypto/caam/caampkc.c +++ b/drivers/crypto/caam/caampkc.c @@ -57,7 +57,7 @@ static void rsa_pub_unmap(struct device *dev, struct rsa_= edesc *edesc, struct akcipher_request *req) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; struct rsa_pub_pdb *pdb =3D &edesc->pdb.pub; =20 @@ -69,7 +69,7 @@ static void rsa_priv_f1_unmap(struct device *dev, struct = rsa_edesc *edesc, struct akcipher_request *req) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; struct rsa_priv_f1_pdb *pdb =3D &edesc->pdb.priv_f1; =20 @@ -81,7 +81,7 @@ static void rsa_priv_f2_unmap(struct device *dev, struct = rsa_edesc *edesc, struct akcipher_request *req) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; struct rsa_priv_f2_pdb *pdb =3D &edesc->pdb.priv_f2; size_t p_sz =3D key->p_sz; @@ -98,7 +98,7 @@ static void rsa_priv_f3_unmap(struct device *dev, struct = rsa_edesc *edesc, struct akcipher_request *req) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; struct rsa_priv_f3_pdb *pdb =3D &edesc->pdb.priv_f3; size_t p_sz =3D key->p_sz; @@ -149,7 +149,7 @@ static void rsa_priv_f_done(struct device *dev, u32 *de= sc, u32 err, struct akcipher_request *req =3D context; struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); struct caam_drv_private_jr *jrp =3D dev_get_drvdata(dev); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; struct caam_rsa_req_ctx *req_ctx =3D akcipher_request_ctx(req); struct rsa_edesc *edesc; @@ -242,7 +242,7 @@ static struct rsa_edesc *rsa_edesc_alloc(struct akciphe= r_request *req, size_t desclen) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct device *dev =3D ctx->dev; struct caam_rsa_req_ctx *req_ctx =3D akcipher_request_ctx(req); struct caam_rsa_key *key =3D &ctx->key; @@ -371,7 +371,7 @@ static int akcipher_do_one_req(struct crypto_engine *en= gine, void *areq) base); struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); struct caam_rsa_req_ctx *req_ctx =3D akcipher_request_ctx(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct device *jrdev =3D ctx->dev; u32 *desc =3D req_ctx->edesc->hw_desc; int ret; @@ -399,7 +399,7 @@ static int set_rsa_pub_pdb(struct akcipher_request *req, { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); struct caam_rsa_req_ctx *req_ctx =3D akcipher_request_ctx(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; struct device *dev =3D ctx->dev; struct rsa_pub_pdb *pdb =3D &edesc->pdb.pub; @@ -444,7 +444,7 @@ static int set_rsa_priv_f1_pdb(struct akcipher_request = *req, struct rsa_edesc *edesc) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; struct device *dev =3D ctx->dev; struct rsa_priv_f1_pdb *pdb =3D &edesc->pdb.priv_f1; @@ -491,7 +491,7 @@ static int set_rsa_priv_f2_pdb(struct akcipher_request = *req, struct rsa_edesc *edesc) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; struct device *dev =3D ctx->dev; struct rsa_priv_f2_pdb *pdb =3D &edesc->pdb.priv_f2; @@ -568,7 +568,7 @@ static int set_rsa_priv_f3_pdb(struct akcipher_request = *req, struct rsa_edesc *edesc) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; struct device *dev =3D ctx->dev; struct rsa_priv_f3_pdb *pdb =3D &edesc->pdb.priv_f3; @@ -664,7 +664,7 @@ static int akcipher_enqueue_req(struct device *jrdev, { struct caam_drv_private_jr *jrpriv =3D dev_get_drvdata(jrdev); struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; struct caam_rsa_req_ctx *req_ctx =3D akcipher_request_ctx(req); struct rsa_edesc *edesc =3D req_ctx->edesc; @@ -707,7 +707,7 @@ static int akcipher_enqueue_req(struct device *jrdev, static int caam_rsa_enc(struct akcipher_request *req) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; struct device *jrdev =3D ctx->dev; struct rsa_edesc *edesc; @@ -746,7 +746,7 @@ static int caam_rsa_enc(struct akcipher_request *req) static int caam_rsa_dec_priv_f1(struct akcipher_request *req) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct device *jrdev =3D ctx->dev; struct rsa_edesc *edesc; int ret; @@ -775,7 +775,7 @@ static int caam_rsa_dec_priv_f1(struct akcipher_request= *req) static int caam_rsa_dec_priv_f2(struct akcipher_request *req) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct device *jrdev =3D ctx->dev; struct rsa_edesc *edesc; int ret; @@ -804,7 +804,7 @@ static int caam_rsa_dec_priv_f2(struct akcipher_request= *req) static int caam_rsa_dec_priv_f3(struct akcipher_request *req) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct device *jrdev =3D ctx->dev; struct rsa_edesc *edesc; int ret; @@ -833,7 +833,7 @@ static int caam_rsa_dec_priv_f3(struct akcipher_request= *req) static int caam_rsa_dec(struct akcipher_request *req) { struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; int ret; =20 @@ -936,7 +936,7 @@ static int caam_rsa_check_key_length(unsigned int len) static int caam_rsa_set_pub_key(struct crypto_akcipher *tfm, const void *k= ey, unsigned int keylen) { - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct rsa_key raw_key =3D {NULL}; struct caam_rsa_key *rsa_key =3D &ctx->key; int ret; @@ -1038,7 +1038,7 @@ static void caam_rsa_set_priv_key_form(struct caam_rs= a_ctx *ctx, static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *= key, unsigned int keylen) { - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct rsa_key raw_key =3D {NULL}; struct caam_rsa_key *rsa_key =3D &ctx->key; int ret; @@ -1089,7 +1089,7 @@ static int caam_rsa_set_priv_key(struct crypto_akciph= er *tfm, const void *key, =20 static unsigned int caam_rsa_max_size(struct crypto_akcipher *tfm) { - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); =20 return ctx->key.n_sz; } @@ -1097,7 +1097,7 @@ static unsigned int caam_rsa_max_size(struct crypto_a= kcipher *tfm) /* Per session pkc's driver context creation function */ static int caam_rsa_init_tfm(struct crypto_akcipher *tfm) { - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); =20 akcipher_set_reqsize(tfm, sizeof(struct caam_rsa_req_ctx)); =20 @@ -1125,7 +1125,7 @@ static int caam_rsa_init_tfm(struct crypto_akcipher *= tfm) /* Per session pkc's driver context cleanup function */ static void caam_rsa_exit_tfm(struct crypto_akcipher *tfm) { - struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct caam_rsa_ctx *ctx =3D akcipher_tfm_ctx_dma(tfm); struct caam_rsa_key *key =3D &ctx->key; =20 dma_unmap_single(ctx->dev, ctx->padding_dma, CAAM_RSA_MAX_INPUT_SIZE - @@ -1148,7 +1148,8 @@ static struct caam_akcipher_alg caam_rsa =3D { .cra_driver_name =3D "rsa-caam", .cra_priority =3D 3000, .cra_module =3D THIS_MODULE, - .cra_ctxsize =3D sizeof(struct caam_rsa_ctx), + .cra_ctxsize =3D sizeof(struct caam_rsa_ctx) + + CRYPTO_DMA_PADDING, }, } };