Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp9861089rwb; Thu, 24 Nov 2022 20:37:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf7bRwfJzG9kgfPFdI3sV5HePbu86vFpdLt3vhe/6eiXZhdmk8S4BqcV7UAtQY8H5ePhSp1e X-Received: by 2002:a17:906:328c:b0:78d:cc87:b1d7 with SMTP id 12-20020a170906328c00b0078dcc87b1d7mr30714882ejw.543.1669351058912; Thu, 24 Nov 2022 20:37:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669351058; cv=none; d=google.com; s=arc-20160816; b=YQwndeOopQxlf/CHabdogRoT+A2wD2SLJa6jWPr7vpAX6dwYNkxLNufDMpmuTfun3L RK5APGDcTAHbk+xAlBwKbbjBBNO8UlaDIbIo7BmhkrnlagaUrJRN4odxf4j0XWEGn61c s6hGORo6bBP3c1OTr75DkiaM40HYxx+NhF+4cMwIMnM4Uhn1/1Zgwcw1RI1rxM0rjq5w nVwK8bRw4jLZMsVvS/9MG63w8fQ8/jQ6ijZKWj255tjEmX3q4P0VObFkBz0nQLiZb3gv 6wgVij1ePNUhfzuOzGucvs6Wsw2tyhaG+MqndznqW21aI4AMUPEJiD4qvIHEGHSgHNoW 968A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:to:references:subject:date:from; bh=D8c/nhAmGNSO5KXyFuLlJgqpW9/DrrZcwHG20Y7sHqM=; b=gi3m8KB+S0bQ5PRFReL6smzhO3FnzIJZmAz8TOX6Q84HG+6Kbu1OJjXDxFLWOtXMTT SMGNiMtHClWrpdl0NwnHobFoTGrL7ieUZ6wbxWc6pusLL+9mT4lq2x1ey7yQPvaTKSMw L/PNZri0O8BSG+nELKrmY/O10I2qD454fjb6V0/7JPQaj12dJx9iqSxcU9TQ7J9o1zkJ SL6iGJKVqRJ8jsdAvNRKJLaKDj/BomU2Ec8GAcHDzp5tgg+gMmhV1CpcpMgf3+vqz23i 3IF9t+m+GmxPVnYHn3v3SHFKnIru6cd2DJ2FNjybXjgvOVX+WDidG+Mj7FUi8Y0paV2f Yreg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u26-20020aa7d89a000000b0046883aeffd8si1823198edq.278.2022.11.24.20.37.15; Thu, 24 Nov 2022 20:37:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229504AbiKYEgq (ORCPT + 99 others); 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: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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 +#include #include #include #include @@ -25,6 +26,14 @@ #define MAX_CIPHER_BLOCKSIZE 16 #define MAX_CIPHER_ALIGNMASK 15 +#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, } } +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 <= crypto_tfm_ctx_alignment()) + align = 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()); } 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 crypto_tfm *tfm, u32 flags) tfm->crt_flags &= ~flags; } -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;