From patchwork Fri Nov 25 04:36:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 25814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3765534wrr; Thu, 24 Nov 2022 20:40:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf63VuQlbso36VU3z27flghL+vvSWpj4IUwqYD6ksQ6kP7NNCPN2IqOMvRERZIocWQXXzZL1 X-Received: by 2002:a17:906:375a:b0:7a9:a59c:4be with SMTP id e26-20020a170906375a00b007a9a59c04bemr30263868ejc.556.1669351224963; Thu, 24 Nov 2022 20:40:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669351224; cv=none; d=google.com; s=arc-20160816; b=iTFs5ZMhkP9OEluWiW8kgNYLRa9l0ImOOS8xvogWxlZtLB5BCRcYI8xDFab79dgm9t W0R+4uTO0BYg2IEubwpv0OnMY99CaBMlp7Kwd8rx0lTyLTHfzQK4ua8At56wCxbTvMYs 7dU26v1Ni6DQ0Y7UmSFP78OICA/fAW/fUuX2hp7jjqaIEbIpgcouuHmEARJZ6uZRkEE6 ScepbQVBkW5bCgWMt1Mu1P5F1ptfbySq141nV0al3rDRDLaSiBKo5fmg4hEAf98AQ1WZ BTXQVIfdEJnmTlJh5zIjQsp78LUor0mWziwGo32zmV+r08tynKWhMbJpwbYu8Efj75+P XwVQ== 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=wemd1EtwVOaKHj5YUWAHzksMxNrnzyltHoWdEJe2khA=; b=zRXbtzuvJyMI18UMZaTIER20bqi5j2EOObsdPZFKisW/jQka7AIgQgPEgo4W197l8R fAtCNtzMb2JZlF6dOyvMVu9rYLG2LddEu9RsdW1lnJbniuNKlqUNcVAv7m5B14Y+RUJ5 1XnzMagX1etid9RVHqh0Di9vBdBB6OvncyIf9MgnQ6gcS6BJpYhXiyDFEOY+6kCBtfA5 RuKNNBEgiLqGWT0TaQAamUf2b+9t9Xs0JTxPAOPEwkbjSLH+Jw/JhIn/Kifbbb8oYL9e 5Y7Y5sMQlD+D5uMJw+o3qKzLdu9DZzKHsQRU3jgA3M0PMqj61CmAZXYUl6w9r2QfUraL fDjA== 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 xc1-20020a170907074100b0077945c44b7fsi2579811ejb.856.2022.11.24.20.40.01; Thu, 24 Nov 2022 20:40:24 -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 S229569AbiKYEhW (ORCPT + 99 others); Thu, 24 Nov 2022 23:37:22 -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: 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?1750441630186078978?= X-GMAIL-MSGID: =?utf-8?q?1750441630186078978?= 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/akcipher.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 akcipher_request *req) return req->__ctx; } +static inline void *akcipher_request_ctx_dma(struct akcipher_request *req) +{ + unsigned int align = crypto_dma_align(); + + if (align <= crypto_tfm_ctx_alignment()) + align = 1; + + return PTR_ALIGN(akcipher_request_ctx(req), align); +} + static inline void akcipher_set_reqsize(struct crypto_akcipher *akcipher, unsigned int reqsize) { akcipher->reqsize = reqsize; } +static inline void akcipher_set_reqsize_dma(struct crypto_akcipher *akcipher, + unsigned int reqsize) +{ + reqsize += crypto_dma_align() & ~(crypto_tfm_ctx_alignment() - 1); + akcipher->reqsize = 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); } static inline void akcipher_request_complete(struct akcipher_request *req,