From patchwork Fri Nov 25 04:36:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 25816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3775415wrr; Thu, 24 Nov 2022 21:09:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Efk2RByPn0+MPKN7Wt6GA/sfyj2E2/cpj2F+lRcR+c15LhvjIP/cpj1BAiP0IbTqZ/OKE X-Received: by 2002:a17:902:f78a:b0:186:5bbc:2ad9 with SMTP id q10-20020a170902f78a00b001865bbc2ad9mr29156199pln.157.1669352961891; Thu, 24 Nov 2022 21:09:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669352961; cv=none; d=google.com; s=arc-20160816; b=OCBQ1cI2b51OUcgTVWSpSKSulE/oCA8/CS4ct9e7p+AwEYrnsE3PnD5Fx6c8tTOron Bcoz9pz7H7s2H36N2VkoS/Hv0SNANWlpu2d+vhKjitW6KHQgrBWRXxmqsRbatr5CIgwa MdxfmBtTWs92BlSCENcFlcTaPbk02Xu6reN+QYhfPvKgVDTHUiH4KsLDkFUgHnmVw/D5 AWt/ukbSKemGLrWiYFxnJPuIRTYhoPyGL2w8rex70YX+m2SgTW64AAznyCKNWng/SnDh 5mlC6vPLl56gs6vwzQ/zM37CFuPNgS9nzuigcbdnUBDItV3IrceSN6cBJV2yZ04cMjtl tc2w== 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=Th1cT6A/G89MZ+4cqPqW93HER+ZSpOHYMUqPRjUvSg4=; b=cwQUkYQSfDqqikZAReccxQSh5XbYq9hSgFLcEROFmdk4U7rzQ5yRFAmEy87AZE1ANc yF6HiPd6214Ynf/p9VBUGK6rTiJfrmXRFfa5S0kn6yPHqJ0xZQbjX0svv1Hc/QWL8YfN 7TVxPL8gwGd33XyjgFRhl6ivsbFCOAVIxTnw7BJAvPbSY4djbvhkQU0lBIV2o2QWQ8nc JvBxt/5x/h1RK7ZyvuY3GzrMUrvSYDx2C9IEnoz1GnyxoVCpMKMHIlSq35cIAz840mmW DWnR2lZhJEVKWKhzWP8SyZbsD33Gh/Y5DvI0ioZN0++bjIjSUWrRA0mwRl+T3cNsOrVz 36Kg== 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 a127-20020a624d85000000b005721983cbe7si2555855pfb.318.2022.11.24.21.09.06; Thu, 24 Nov 2022 21:09:21 -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 S229764AbiKYEha (ORCPT + 99 others); Thu, 24 Nov 2022 23:37:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbiKYEhB (ORCPT ); Thu, 24 Nov 2022 23:37:01 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DF6E27934; Thu, 24 Nov 2022 20:36:56 -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 1oyQS5-000djv-CO; Fri, 25 Nov 2022 12:36:38 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Nov 2022 12:36:37 +0800 From: "Herbert Xu" Date: Fri, 25 Nov 2022 12:36:37 +0800 Subject: [v2 PATCH 5/9] crypto: skcipher - 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?1750443451505351044?= X-GMAIL-MSGID: =?utf-8?q?1750443451505351044?= This patch adds helpers to access the skcipher context structure and request context structure with an added alignment for DMA access. Signed-off-by: Herbert Xu --- include/crypto/internal/skcipher.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h index a2339f80a615..a05a55af5b2c 100644 --- a/include/crypto/internal/skcipher.h +++ b/include/crypto/internal/skcipher.h @@ -122,6 +122,13 @@ static inline void crypto_skcipher_set_reqsize( skcipher->reqsize = reqsize; } +static inline void crypto_skcipher_set_reqsize_dma( + struct crypto_skcipher *skcipher, unsigned int reqsize) +{ + reqsize += crypto_dma_align() & ~(crypto_tfm_ctx_alignment() - 1); + skcipher->reqsize = reqsize; +} + int crypto_register_skcipher(struct skcipher_alg *alg); void crypto_unregister_skcipher(struct skcipher_alg *alg); int crypto_register_skciphers(struct skcipher_alg *algs, int count); @@ -151,11 +158,26 @@ static inline void *crypto_skcipher_ctx(struct crypto_skcipher *tfm) return crypto_tfm_ctx(&tfm->base); } +static inline void *crypto_skcipher_ctx_dma(struct crypto_skcipher *tfm) +{ + return crypto_tfm_ctx_dma(&tfm->base); +} + static inline void *skcipher_request_ctx(struct skcipher_request *req) { return req->__ctx; } +static inline void *skcipher_request_ctx_dma(struct skcipher_request *req) +{ + unsigned int align = crypto_dma_align(); + + if (align <= crypto_tfm_ctx_alignment()) + align = 1; + + return PTR_ALIGN(skcipher_request_ctx(req), align); +} + static inline u32 skcipher_request_flags(struct skcipher_request *req) { return req->base.flags;