From patchwork Tue May 10 11:07:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 12844855 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E7B4C433EF for ; Tue, 10 May 2022 11:07:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06C018D0003; Tue, 10 May 2022 07:07:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C93B48D0002; Tue, 10 May 2022 07:07:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7EF18D0005; Tue, 10 May 2022 07:07:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A37168D0002 for ; Tue, 10 May 2022 07:07:26 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8A226618E7 for ; Tue, 10 May 2022 11:07:26 +0000 (UTC) X-FDA: 79449557292.10.B80C8D2 Received: from fornost.hmeau.com (helcar.hmeau.com [216.24.177.18]) by imf23.hostedemail.com (Postfix) with ESMTP id 4148114009A for ; Tue, 10 May 2022 11:07:13 +0000 (UTC) Received: from gwarestrin.arnor.me.apana.org.au ([192.168.103.7]) by fornost.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1noNhy-00BzVR-Si; Tue, 10 May 2022 21:07:16 +1000 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Tue, 10 May 2022 19:07:15 +0800 From: "Herbert Xu" Date: Tue, 10 May 2022 19:07:15 +0800 Subject: [RFC PATCH 4/7] crypto: hash - Add ctx helpers with DMA alignment References: To: Catalin Marinas , 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: X-Rspamd-Queue-Id: 4148114009A X-Stat-Signature: wue69m7sdx61jfgoefjzyodu3d8raft3 X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of herbert@gondor.apana.org.au designates 216.24.177.18 as permitted sender) smtp.mailfrom=herbert@gondor.apana.org.au X-Rspamd-Server: rspam09 X-HE-Tag: 1652180833-410539 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index 25806141db591..f635a61fd1a0e 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_ahash *tfm) return crypto_tfm_ctx(crypto_ahash_tfm(tfm)); } +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,15 @@ static inline void crypto_ahash_set_reqsize(struct crypto_ahash *tfm, tfm->reqsize = reqsize; } +static inline void crypto_ahash_set_reqsize_dma(struct crypto_ahash *ahash, + unsigned int reqsize) +{ +#ifdef ARCH_DMA_MINALIGN + reqsize += ARCH_DMA_MINALIGN & ~(crypto_tfm_ctx_alignment() - 1); +#endif + ahash->reqsize = reqsize; +} + static inline struct crypto_instance *ahash_crypto_instance( struct ahash_instance *inst) { @@ -169,6 +183,20 @@ static inline void *ahash_instance_ctx(struct ahash_instance *inst) return crypto_instance_ctx(ahash_crypto_instance(inst)); } +static inline void *ahash_request_ctx_dma(struct ahash_request *req) +{ + unsigned int align = 1; + +#ifdef ARCH_DMA_MINALIGN + align = ARCH_DMA_MINALIGN; +#endif + + if (align <= crypto_tfm_ctx_alignment()) + align = 1; + + return PTR_ALIGN(ahash_request_ctx(req), align); +} + static inline void ahash_request_complete(struct ahash_request *req, int err) { req->base.complete(&req->base, err);