linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andre Glover <andre.glover@linux.intel.com>
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	[thread overview]
Message-ID: <4f6ebdb42f3a999cc77e81dc1ceeb4ea46f615df.1714581792.git.andre.glover@linux.intel.com> (raw)
In-Reply-To: <cover.1714581792.git.andre.glover@linux.intel.com>

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 <andre.glover@linux.intel.com>
---
 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



  reply	other threads:[~2024-05-01 21:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-01 21:46 [RFC PATCH 0/3] by_n compression and decompression with Intel IAA Andre Glover
2024-05-01 21:46 ` Andre Glover [this message]
2024-05-01 21:46 ` [RFC PATCH 2/3] crypto: add by_n attribute to acomp_req Andre Glover
2024-09-16  6:16   ` Barry Song
2024-09-27 16:03     ` bala.seshasayee
2024-05-01 21:46 ` [RFC PATCH 3/3] crypto: Add deflate-canned-byN algorithm to IAA Andre Glover

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4f6ebdb42f3a999cc77e81dc1ceeb4ea46f615df.1714581792.git.andre.glover@linux.intel.com \
    --to=andre.glover@linux.intel.com \
    --cc=21cnbao@gmail.com \
    --cc=bala.seshasayee@intel.com \
    --cc=chengming.zhou@linux.dev \
    --cc=dave.jiang@intel.com \
    --cc=davem@davemloft.net \
    --cc=dmaengine@vger.kernel.org \
    --cc=fenghua.yu@intel.com \
    --cc=hannes@cmpxchg.org \
    --cc=heath.caldwell@intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=james.guilford@intel.com \
    --cc=kanchana.p.sridhar@intel.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=nphamcs@gmail.com \
    --cc=ryan.roberts@arm.com \
    --cc=senozhatsky@chromium.org \
    --cc=tom.zanussi@linux.intel.com \
    --cc=vinodh.gopal@intel.com \
    --cc=wajdi.k.feghali@intel.com \
    --cc=yosryahmed@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox