From patchwork Fri Nov 25 04:36:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 25812 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3764993wrr; Thu, 24 Nov 2022 20:38:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf5m3/df0FKkNbV8g+zY2DSqJEA2vI/UXk/ZC3sEjjirq+yMqtqVsUVW3CNGpNgkDHyh5bm1 X-Received: by 2002:a17:906:850d:b0:7ae:21bc:89f0 with SMTP id i13-20020a170906850d00b007ae21bc89f0mr30058740ejx.132.1669351094360; Thu, 24 Nov 2022 20:38:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669351094; cv=none; d=google.com; s=arc-20160816; b=V5ihMWs3ysiXuh+EM4Yh41xDoMKLQSmkIC+FnozG0WdYUzU5LZFKs5+//ckeWDOB3d 01Vh0bThugH/7B3hSHe0BjxY9/tyw8kV86M82tETBSaaAEnEEo2FMQRDQI8h5JsVK4RQ vBY9i+JmBEN+dnna41vouTspES0nhQNqd3+BEgQA6nyKEOGDqWP4RtEdEwFNCrtATjZ+ xOfNu0WdmuYI6b54bCPhFIo6CVeyc5SswyJvbFHDZt1oD/ElIQ0BT3OUX/Rc8BAQHEPS 4FG4Ok+PHT19qrWeHVBqnzVsDBrpSwaiuVZkyg5RFAKpkvGf4FHwXKQE+Uf3F3gWFsSb ApzA== 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=YAEKWnEWNYozD+cMbEn+XeUNTrN5wp9mIMIHTJBHBk8=; b=hWMOWU1u3U4AX2D2ySHC22qI1P/SW7/6Y1ES01cmDjuTY32Qv3sQAZrUtN+jN0XdNo tZoRCjgEoe7KnfHGt8rsfevs2qmfomIqGPynvsvUMXAoSok0pat6z0xUWuY+kJxMhqv2 wMqRHyDstt5fY3sFuE76lqSVwuoOAfhHv0czoFleyhJ78PiZZ2Lq4KMRE/RaGijWWJC9 K2p4F2eBpiHJefzJ0C/xKIiltqixN2AKqqXyro3TruBmj6LByvbckRgwVmINHqGw/ZPh fbT8wN/YfcIO/GXpEt94Ve5v9IXV9slZENN7GuCOKJvIQpvlpjjmFbUmtIJxHUbVMAo/ Taiw== 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 d26-20020a056402517a00b00468dba126a8si1187758ede.580.2022.11.24.20.37.50; Thu, 24 Nov 2022 20:38:14 -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 S229677AbiKYEhC (ORCPT + 99 others); Thu, 24 Nov 2022 23:37:02 -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: 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?1750441493158568921?= X-GMAIL-MSGID: =?utf-8?q?1750441493158568921?= 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_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,13 @@ 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) +{ + reqsize += crypto_dma_align() & ~(crypto_tfm_ctx_alignment() - 1); + ahash->reqsize = 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_instance *inst) return crypto_instance_ctx(ahash_crypto_instance(inst)); } +static inline void *ahash_request_ctx_dma(struct ahash_request *req) +{ + unsigned int align = crypto_dma_align(); + + 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);