From patchwork Fri Nov 25 04:36:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 25809 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3764890wrr; Thu, 24 Nov 2022 20:37:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf5EG35GTJUAH+DT0aghtywkeqHZwLK2kuln3N7lIcsU8csBvcQuhGa8DMKvhXx51sqUXvi3 X-Received: by 2002:aa7:cc8a:0:b0:464:1296:d5d4 with SMTP id p10-20020aa7cc8a000000b004641296d5d4mr32328282edt.83.1669351064562; Thu, 24 Nov 2022 20:37:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669351064; cv=none; d=google.com; s=arc-20160816; b=qoLjHg4OdCGMV7dWmSopyNRLBxNr07M9Cyj4qq3lVJzBRYEoWSVopBxh2SC4s5cnFc N+VvPYz634MViljjeYBLxJe8Zzy0wc9dIRZkI/PIz8mn9HCZ4ghYQWwFSOd0RFZ7tknB itT+TR8VZkas4O+1LXvoTQLXXyyYXpjUpj9oYyiKc8/tsdiOTbkzg6Z0jZmPtO7+3CYk pjGoKmVKODh+efUL0Wj2aURRDvYUWI2n/B66wH7NhEbGLC/RIlmkdkz7vbvtEUYWzprs +ZuY6+QPw9+NkUsqHKew7CJj2cXeT1ynLUk5JCZdo9HssOITZvtL44/EY6xroVgT+uyB IBxQ== 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=cRpzK80WL1AKwEwiQMVLz6jCATFf1tXhIZTx8ADwl7ctbAymmXSy/8TP51VITiGd/w 0YT5y1+l3tDLYb/W/pk94E6VLOhNuuROThWyen7M/1czHW0yBdxlqkpWfGilQxZLkAfV U/ov8zzzRxXYAABR3KWalcsLlMnypZYRHN7nAo0++cNICo1PG6KvSP83J0LAg55BdVei hTHTpfSiv0buFc1t2+lDNDA/GsLCYAmGCmGM5Mt7dzjGaOq1H9qx67SPvHpTe0NlmiKs JfyXzrWh6Rm0hX8sLVcNX1EI+b0ziVhU+6PdagrvN/TsqMnAYQExkfOrYwQZ8N3ETBYG ZNcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id vj23-20020a170907131700b0078db1258ae9si1648054ejb.555.2022.11.24.20.37.21; Thu, 24 Nov 2022 20:37:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229539AbiKYEgq (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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750441461404829082?= X-GMAIL-MSGID: =?utf-8?q?1750441461404829082?= 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;