mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Usama Arif <usama.arif@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	chengming.zhou@linux.dev, dsterba@suse.com, hannes@cmpxchg.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	nphamcs@gmail.com, terrelln@fb.com, yosry@kernel.org,
	riel@surriel.com, shakeel.butt@linux.dev, alex@ghiti.fr,
	senozhatsky@chromium.org, davem@davemloft.net,
	linux-crypto@vger.kernel.org, kernel-team@meta.com
Subject: [PATCH] crypto: acomp - Enforce MAX_SYNC_COMP_REQSIZE in init_tfm
Date: Tue, 13 Oct 2026 20:44:39 +1100	[thread overview]
Message-ID: <as39h_dFzL-Al1-r@gondor.apana.org.au> (raw)
In-Reply-To: <20261009163146.83112-3-usama.arif@linux.dev>

On Fri, Oct 09, 2026 at 09:30:31AM -0700, Usama Arif wrote:
>
> diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h
> index 5d5358dfab734..12c1ce1f6243b 100644
> --- a/include/crypto/acompress.h
> +++ b/include/crypto/acompress.h
> @@ -203,6 +203,19 @@ static inline bool acomp_is_async(struct crypto_acomp *tfm)
>  	       CRYPTO_ALG_ASYNC;
>  }
>  
> +/**
> + * acomp_can_use_stack_req() - check whether a transform can use stack requests
> + * @tfm: ACOMPRESS transform
> + *
> + * Return: true if @tfm completes synchronously and its request context fits
> + * in the storage reserved by ACOMP_REQUEST_ON_STACK(), false otherwise.
> + */
> +static inline bool acomp_can_use_stack_req(struct crypto_acomp *tfm)
> +{
> +	return !acomp_is_async(tfm) &&
> +	       crypto_acomp_reqsize(tfm) <= MAX_SYNC_COMP_REQSIZE;

I think we should enforce MAX_SYNC_COMP_REQSIZE in the Crypto API
and then you can simply test against acomp_is_async(tfm).

Feel free to include this patch in your series:

---8<---
Enforce the limit MAX_SYNC_COMP_REQSIZE when an acomp tfm is
initialised.  All existing algorithms obey this limit.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/crypto/acompress.c b/crypto/acompress.c
index 4de1a2ad577f..c8b4b8589769 100644
--- a/crypto/acompress.c
+++ b/crypto/acompress.c
@@ -92,10 +92,6 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm)
 		if (IS_ERR(fb))
 			return PTR_ERR(fb);
 
-		err = -EINVAL;
-		if (crypto_acomp_reqsize(fb) > MAX_SYNC_COMP_REQSIZE)
-			goto out_free_fb;
-
 		tfm->fb = crypto_acomp_tfm(fb);
 	}
 
@@ -105,15 +101,19 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm)
 
 	acomp->base.exit = crypto_acomp_exit_tfm;
 
-	if (!alg->init)
-		return 0;
-
-	err = alg->init(acomp);
-	if (err)
+	if (alg->init && ((err = alg->init(acomp))))
 		goto out_free_fb;
 
+	err = -EINVAL;
+	if (!acomp_is_async(acomp) &&
+	    crypto_acomp_reqsize(acomp) > MAX_SYNC_COMP_REQSIZE)
+		goto out_exit_tfm;
+
 	return 0;
 
+out_exit_tfm:
+	if (alg->exit)
+		alg->exit(acomp);
 out_free_fb:
 	crypto_free_acomp(fb);
 	return err;
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

      reply	other threads:[~2026-10-13  9:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09 16:30 [PATCH v2 0/2] mm: zswap: reduce request contention on loads Usama Arif
2026-10-09 16:30 ` [PATCH v2 1/2] mm: zswap: use separate compression and decompression requests Usama Arif
2026-10-10 10:14   ` Nhat Pham
2026-10-13  0:21   ` Kanchana P. Sridhar
2026-11-03 14:25     ` Usama Arif
2026-11-03 22:05       ` Kanchana P. Sridhar
2026-11-04 11:53         ` Usama Arif
2026-10-13  9:28   ` Herbert Xu
2026-10-09 16:30 ` [PATCH v2 2/2] mm: zswap: use stack requests for synchronous decompression Usama Arif
2026-10-13  9:44   ` Herbert Xu [this message]

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=as39h_dFzL-Al1-r@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=chengming.zhou@linux.dev \
    --cc=davem@davemloft.net \
    --cc=dsterba@suse.com \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@meta.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=riel@surriel.com \
    --cc=senozhatsky@chromium.org \
    --cc=shakeel.butt@linux.dev \
    --cc=terrelln@fb.com \
    --cc=usama.arif@linux.dev \
    --cc=yosry@kernel.org \
    /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

all inboxes | Powered by JetHome®