From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8A1DC4345F for ; Wed, 1 May 2024 21:46:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A8BD6B0088; Wed, 1 May 2024 17:46:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00A756B008A; Wed, 1 May 2024 17:46:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D54FA6B0092; Wed, 1 May 2024 17:46:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B1F336B0088 for ; Wed, 1 May 2024 17:46:39 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 232C140C35 for ; Wed, 1 May 2024 21:46:37 +0000 (UTC) X-FDA: 82071161634.09.95303B6 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) by imf15.hostedemail.com (Postfix) with ESMTP id 2D543A0027 for ; Wed, 1 May 2024 21:46:34 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=hqfbHcwE; spf=none (imf15.hostedemail.com: domain of andre.glover@linux.intel.com has no SPF policy when checking 198.175.65.15) smtp.mailfrom=andre.glover@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714599995; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CC1Zmh52me0lGP9xiPGKRUOqGW9skqwABMh3F3izXw8=; b=zisuYnIGaXvN6IjqKRWBhv16TPE4hzJBr/QMLn1IwZXmILAXw3FlMp6IStqQv8U8iM1Uki jc3iTMQmdCmmXYS/VFODVo9fFNxqKrSOkr0LOmstCtx5fn2gNip6EebWvGbaYqzh9Afsnq EUyOBaJEIwkR3xm75sWK5mlzAxKrxwk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714599995; a=rsa-sha256; cv=none; b=3r+kgrT93dIY1hU+lJOgJk2EBg5SuPCihj9zx6MXC1YBK9McPxYDKYU1bEgKM6P5q8txPz ILxfpuKZQdsIG356OT0jxHwj5teSSdev2OaNCH3Sn0NdT4Co/Zh/Ynw/GAHvTCkN6HB37Q MHHlA7CopMBjd2NjDagY0HrTK1AJ6t4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=hqfbHcwE; spf=none (imf15.hostedemail.com: domain of andre.glover@linux.intel.com has no SPF policy when checking 198.175.65.15) smtp.mailfrom=andre.glover@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714599996; x=1746135996; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2f5vPdonutO4FVTDMf62pMfW1qZlAhqJA03iBuAYN+0=; b=hqfbHcwE6Cixqc3s+oO35I67YPPwRbvNl5pWFGESdtCmeWRI1+DCABCX /ZxQQVunmIMH9HzWBt3sABbP3gbYUw9vY5+WilBEZzzMjFRtghFUyxptK Pl0953OvphBFt2ghfe0xwHNUfmJ8TxmzYc24l2kbTZqg323AE7qjUd+9n P8QtK4HB6D2yYdakFE1v5h4VRlTBQnBsGlZIB4KZ0h+62CDa0HgdJENsl LNaASy67ZHEpjZWYYOceUxPtnp/EdnYbnldTPMjg6pJmE+mnaMfJD73NH BWMIjwh95Oz1xWaxn/qPgG1x1uCXxUzWiUOvsQKKoJzI9mcjK13VoN+0W w==; X-CSE-ConnectionGUID: GIpaphxtQGqiDVBW4v4Ljg== X-CSE-MsgGUID: D7STCQDSTzKCxfkINVS2kw== X-IronPort-AV: E=McAfee;i="6600,9927,11061"; a="14130149" X-IronPort-AV: E=Sophos;i="6.07,246,1708416000"; d="scan'208";a="14130149" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 May 2024 14:46:34 -0700 X-CSE-ConnectionGUID: vvcWl59ZSqq0x/bFRbB61g== X-CSE-MsgGUID: GO8/KGW5RUelpqqTZehRTg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,246,1708416000"; d="scan'208";a="31726379" Received: from jf5300-b11a264t.jf.intel.com ([10.242.51.89]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 May 2024 14:46:33 -0700 From: Andre Glover To: tom.zanussi@linux.intel.com, minchan@kernel.org, senozhatsky@chromium.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, fenghua.yu@intel.com, dave.jiang@intel.com Cc: wajdi.k.feghali@intel.com, james.guilford@intel.com, vinodh.gopal@intel.com, bala.seshasayee@intel.com, heath.caldwell@intel.com, kanchana.p.sridhar@intel.com, andre.glover@linux.intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, 21cnbao@gmail.com, ryan.roberts@arm.com, linux-crypto@vger.kernel.org, dmaengine@vger.kernel.org Subject: [RFC PATCH 1/3] crypto: Add pre_alloc and post_free callbacks for acomp algorithms Date: Wed, 1 May 2024 14:46:27 -0700 Message-Id: <4f6ebdb42f3a999cc77e81dc1ceeb4ea46f615df.1714581792.git.andre.glover@linux.intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Stat-Signature: 1xn4znfapfutkjgq49f4csoke5tqwbdz X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 2D543A0027 X-HE-Tag: 1714599994-876494 X-HE-Meta: U2FsdGVkX1+wZ5pN20ZmFO5gxBfOgbBvg6TNGyCax38eX6uXMWwsSRgcJ23D2y5H1O+A6OZD+BSeJ88ONTn9nEV9it42U8MLdPsOEDG/IyR22TbgjUqTyAnxEeVAiQCAQtw1LECAfV1/NvuZU5AIWuSYsOUN35b/S1Xj/QEzFhvXqGN79nk3wAU+tWEBwI8I02UN0MXVI10fNvGetfyEoQ8hSQPH48g3xWDtAg3bbuzzB0p7csubt6qnb7mITpPVF7T8ijuxEH9aBycjEkVq5zE3j9mQmYuc3wvqQngnJEufizGPG4IpY9hTS8CpwJHVkeqpKaVDjqw1XYovrxkpJdBkyGEU9GMDawAqa8XQRqwFSumw/hgAZ+cgMCd+DslHAHNkEWKXiqOAUWDjEvTOwe4t38ZKLGDN3DCtRJx15ku5YoaaR1vVZ1VSUkDMNaBzJrmpA94lBJhWf7Ji3kLZgGPjzEEijdBzaaZioAGC88rkBuuMH6JvGUp1jasn3GcsDhC9iTd65m9Hfc+bhrZjMnfERyCLWnabtoqlYSLmJ2rR0uLxh0TnmTn3ckH4tYqPF8eNBZDssjV2r1knt0ho/CIwzfFctayQr5waxyh+9TCMclu9rXJQ9n4Z2MDWqcIrnIJ/+sViBMJQQotAFlh5nJXj3PXGLbjtyzl8GGZgknwcBST4uSH5I6TulkpQdYL5T5n7ZV2QT8NO99I3yfwNyZ86qRjGNOcc8rfJMJInPZ0CGBYSI/UsPEFLueaCawFx596rZZlkQEL4/nf5DCZ/OgFeVr69gO5k6PDigZRd2X/hzq6zotbLapiStLRiCB78vnlz4XDMhr0biIYetfhyqIk9xB9C4KYF8tp6AQ6EGMlC82LIEQddtxpqQ2jcalXqWzPbIU9LqX7DNDoSgoQzduMGlLJyq/YP X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add callbacks to acomp crypto algorithms that facilitate the allocation and subsequent freeing of resources required by an acomp_req before and after a series of compress and/or decompress operations. Signed-off-by: Andre Glover --- crypto/acompress.c | 13 +++++++++++++ include/crypto/acompress.h | 2 ++ include/crypto/internal/acompress.h | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/crypto/acompress.c b/crypto/acompress.c index 6fdf0ff9f3c0..873918be75cc 100644 --- a/crypto/acompress.c +++ b/crypto/acompress.c @@ -71,9 +71,13 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm) acomp->compress = alg->compress; acomp->decompress = alg->decompress; + acomp->dst_free = alg->dst_free; acomp->reqsize = alg->reqsize; + acomp->pre_alloc = alg->pre_alloc; + acomp->post_free = alg->post_free; + if (alg->exit) acomp->base.exit = crypto_acomp_exit_tfm; @@ -129,6 +133,12 @@ struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp) struct acomp_req *req; req = __acomp_request_alloc(acomp); + + if (req && (acomp->pre_alloc && acomp->pre_alloc(req))) { + __acomp_request_free(req); + return NULL; + } + if (req && (tfm->__crt_alg->cra_type != &crypto_acomp_type)) return crypto_acomp_scomp_alloc_ctx(req); @@ -144,6 +154,9 @@ void acomp_request_free(struct acomp_req *req) if (tfm->__crt_alg->cra_type != &crypto_acomp_type) crypto_acomp_scomp_free_ctx(req); + if (acomp->post_free) + acomp->post_free(req); + if (req->flags & CRYPTO_ACOMP_ALLOC_OUTPUT) { acomp->dst_free(req->dst); req->dst = NULL; diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index 54937b615239..2b73cef2f430 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -51,6 +51,8 @@ struct acomp_req { struct crypto_acomp { int (*compress)(struct acomp_req *req); int (*decompress)(struct acomp_req *req); + int (*pre_alloc)(struct acomp_req *req); + void (*post_free)(struct acomp_req *req); void (*dst_free)(struct scatterlist *dst); unsigned int reqsize; struct crypto_tfm base; diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h index d00392d1988e..081e1cf5235f 100644 --- a/include/crypto/internal/acompress.h +++ b/include/crypto/internal/acompress.h @@ -29,6 +29,10 @@ * @exit: Deinitialize the cryptographic transformation object. This is a * counterpart to @init, used to remove various changes set in * @init. + * @pre_alloc: Function that performs any pre-allocation and setup that an + * algorithm may require on a per req basis. + * @post_free: Function that performs any post freeing that an algorithm + * may require on a per req basis. * * @reqsize: Context size for (de)compression requests * @base: Common crypto API algorithm data structure @@ -40,6 +44,8 @@ struct acomp_alg { void (*dst_free)(struct scatterlist *dst); int (*init)(struct crypto_acomp *tfm); void (*exit)(struct crypto_acomp *tfm); + int (*pre_alloc)(struct acomp_req *req); + void (*post_free)(struct acomp_req *req); unsigned int reqsize; -- 2.27.0