From patchwork Fri Nov 25 04:36:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 25811 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3764928wrr; Thu, 24 Nov 2022 20:37:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf5JShvcdyhZ6RD+Pxq0EJudHQZWEFqV2CdNiZ2Fy/xmatNR09LEKYxwp96jMmIjQQ3SuVm6 X-Received: by 2002:a05:6402:5517:b0:461:c563:defa with SMTP id fi23-20020a056402551700b00461c563defamr32751771edb.72.1669351074654; Thu, 24 Nov 2022 20:37:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669351074; cv=none; d=google.com; s=arc-20160816; b=QDHXpcq8Q0DGuruf+p5ygGE8TzuD8+PuCkdRnwJ+IuOcBxj4dXtgLQBEqrW1moFgdT BoCOIzt/jsZ/pxYIWHUtIXhnUybuxM4FRD0y5rhh2GUEOgWfFU7knWE4d5jBFUwMO+rV +veyPU4930bzoMt4xGtwgDdzr+fFHGX5iukEWE4dDSx84gI/wueqpNOgE3Gdt9qoExB+ UD5/2pTkiYGZsFzwHBaQGDU78onlifNht2LAb5RVcUTAIdyrSg+BFQC4ea1TNTXAOupC LxJeh9mI8HPv/h8w1NM/QBPQkyuNIzvCeRo9ofJ0ZdamYgfD1kGZK0KkNo8BCF+LEZ+c 8CiQ== 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=5EdxE9V/cohDWAWiwYzWscGUjdaz62prbBWA3c9Oy90=; b=ZAJi2iAKdz8dxldJwGNGdUXpU3Sk78t3PkWuLYvs1omFJWrQhkAwgrdBEHH9wlx3Zx wgVsfTrW/lizZejGS7G+qGkQuqkFZqPRw/bdVz/7iPVGGxSUQxEkgRhf5xazWwDVPk5A TfBhKAW5o0zS1V8uvHI5Tb81BKymsOonRnJSJftiC27dKbgQZLhtvGttQ+ZNyWrs2+Lz 4j5YeYwITsD96hlWgnJl7lSYel8EkelgmERR0Ns0qNpSYukG+4skOoFPnG1++jZr6bIh Nzc1WKTMlmgJiQUOH89A+JPtGr9HzBwartZOzwXGz72j0H80lR7bfCvg0AXReDsrGjSU LXuA== 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 d18-20020aa7d692000000b004619e210510si2069284edr.150.2022.11.24.20.37.31; Thu, 24 Nov 2022 20:37:54 -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 S229669AbiKYEg6 (ORCPT + 99 others); Thu, 24 Nov 2022 23:36:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbiKYEgr (ORCPT ); Thu, 24 Nov 2022 23:36:47 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19A192338F; 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 1oyQS1-000djS-65; Fri, 25 Nov 2022 12:36:34 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 12:36:33 +0800 From: "Herbert Xu" Date: Fri, 25 Nov 2022 12:36:33 +0800 Subject: [v2 PATCH 3/9] crypto: aead - 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?1750441472230951836?= X-GMAIL-MSGID: =?utf-8?q?1750441472230951836?= This patch adds helpers to access the aead context structure and request context structure with an added alignment for DMA access. Signed-off-by: Herbert Xu --- include/crypto/internal/aead.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/crypto/internal/aead.h b/include/crypto/internal/aead.h index d482017f3e20..cd8cb1e921b7 100644 --- a/include/crypto/internal/aead.h +++ b/include/crypto/internal/aead.h @@ -39,6 +39,11 @@ static inline void *crypto_aead_ctx(struct crypto_aead *tfm) return crypto_tfm_ctx(&tfm->base); } +static inline void *crypto_aead_ctx_dma(struct crypto_aead *tfm) +{ + return crypto_tfm_ctx_dma(&tfm->base); +} + static inline struct crypto_instance *aead_crypto_instance( struct aead_instance *inst) { @@ -65,6 +70,16 @@ static inline void *aead_request_ctx(struct aead_request *req) return req->__ctx; } +static inline void *aead_request_ctx_dma(struct aead_request *req) +{ + unsigned int align = crypto_dma_align(); + + if (align <= crypto_tfm_ctx_alignment()) + align = 1; + + return PTR_ALIGN(aead_request_ctx(req), align); +} + static inline void aead_request_complete(struct aead_request *req, int err) { req->base.complete(&req->base, err); @@ -108,6 +123,13 @@ static inline void crypto_aead_set_reqsize(struct crypto_aead *aead, aead->reqsize = reqsize; } +static inline void crypto_aead_set_reqsize_dma(struct crypto_aead *aead, + unsigned int reqsize) +{ + reqsize += crypto_dma_align() & ~(crypto_tfm_ctx_alignment() - 1); + aead->reqsize = reqsize; +} + static inline void aead_init_queue(struct aead_queue *queue, unsigned int max_qlen) {