From: Herbert Xu <herbert@gondor.apana.org.au>
To: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>
Cc: linux-mm@kvack.org, Yosry Ahmed <yosry.ahmed@linux.dev>
Subject: [PATCH 5/7] crypto: scomp - Remove support for non-trivial SG lists
Date: Thu, 27 Feb 2025 18:15:04 +0800 [thread overview]
Message-ID: <30f87ea9a3738c57287f9099a9e638781fa212c5.1740651138.git.herbert@gondor.apana.org.au> (raw)
In-Reply-To: <cover.1740651138.git.herbert@gondor.apana.org.au>
As the only user of scomp uses a trivial single-page SG list,
remove support for everything else in preprataion for a shift
to virtual addresses.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
crypto/acompress.c | 6 --
crypto/scompress.c | 139 +++++-----------------------
include/crypto/acompress.h | 12 +--
include/crypto/internal/scompress.h | 2 -
4 files changed, 27 insertions(+), 132 deletions(-)
diff --git a/crypto/acompress.c b/crypto/acompress.c
index d2103d4e42cc..8914d0c4cc75 100644
--- a/crypto/acompress.c
+++ b/crypto/acompress.c
@@ -73,7 +73,6 @@ 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;
if (alg->exit)
@@ -146,11 +145,6 @@ void acomp_request_free(struct acomp_req *req)
if (tfm->__crt_alg->cra_type != &crypto_acomp_type)
crypto_acomp_scomp_free_ctx(req);
- if (req->base.flags & CRYPTO_ACOMP_ALLOC_OUTPUT) {
- acomp->dst_free(req->dst);
- req->dst = NULL;
- }
-
__acomp_request_free(req);
}
EXPORT_SYMBOL_GPL(acomp_request_free);
diff --git a/crypto/scompress.c b/crypto/scompress.c
index 1cef6bb06a81..ffc8e7f4862c 100644
--- a/crypto/scompress.c
+++ b/crypto/scompress.c
@@ -18,24 +18,11 @@
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/string.h>
-#include <linux/vmalloc.h>
#include <net/netlink.h>
#include "compress.h"
-struct scomp_scratch {
- spinlock_t lock;
- void *src;
- void *dst;
-};
-
-static DEFINE_PER_CPU(struct scomp_scratch, scomp_scratch) = {
- .lock = __SPIN_LOCK_UNLOCKED(scomp_scratch.lock),
-};
-
static const struct crypto_type crypto_scomp_type;
-static int scomp_scratch_users;
-static DEFINE_MUTEX(scomp_lock);
static int __maybe_unused crypto_scomp_report(
struct sk_buff *skb, struct crypto_alg *alg)
@@ -58,127 +45,57 @@ static void crypto_scomp_show(struct seq_file *m, struct crypto_alg *alg)
seq_puts(m, "type : scomp\n");
}
-static void crypto_scomp_free_scratches(void)
-{
- struct scomp_scratch *scratch;
- int i;
-
- for_each_possible_cpu(i) {
- scratch = per_cpu_ptr(&scomp_scratch, i);
-
- vfree(scratch->src);
- vfree(scratch->dst);
- scratch->src = NULL;
- scratch->dst = NULL;
- }
-}
-
-static int crypto_scomp_alloc_scratches(void)
-{
- struct scomp_scratch *scratch;
- int i;
-
- for_each_possible_cpu(i) {
- void *mem;
-
- scratch = per_cpu_ptr(&scomp_scratch, i);
-
- mem = vmalloc_node(SCOMP_SCRATCH_SIZE, cpu_to_node(i));
- if (!mem)
- goto error;
- scratch->src = mem;
- mem = vmalloc_node(SCOMP_SCRATCH_SIZE, cpu_to_node(i));
- if (!mem)
- goto error;
- scratch->dst = mem;
- }
- return 0;
-error:
- crypto_scomp_free_scratches();
- return -ENOMEM;
-}
-
static int crypto_scomp_init_tfm(struct crypto_tfm *tfm)
{
- int ret = 0;
-
- mutex_lock(&scomp_lock);
- if (!scomp_scratch_users++)
- ret = crypto_scomp_alloc_scratches();
- mutex_unlock(&scomp_lock);
-
- return ret;
+ return 0;
}
static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
{
struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
- void **tfm_ctx = acomp_tfm_ctx(tfm);
+ struct crypto_scomp **tfm_ctx = acomp_tfm_ctx(tfm);
struct crypto_scomp *scomp = *tfm_ctx;
void **ctx = acomp_request_ctx(req);
- struct scomp_scratch *scratch;
+ unsigned int slen = req->slen;
+ unsigned int dlen = req->dlen;
void *src, *dst;
- unsigned int dlen;
int ret;
- if (!req->src || !req->slen || req->slen > SCOMP_SCRATCH_SIZE)
+ if (!req->src || !slen)
return -EINVAL;
- if (req->dst && !req->dlen)
+ if (req->dst && !dlen)
return -EINVAL;
- if (!req->dlen || req->dlen > SCOMP_SCRATCH_SIZE)
- req->dlen = SCOMP_SCRATCH_SIZE;
+ if (!req->dst || !dlen)
+ return -ENOSYS;
- dlen = req->dlen;
+ if (sg_nents(req->src) > 1 || req->src->offset + slen > PAGE_SIZE)
+ return -ENOSYS;
- scratch = raw_cpu_ptr(&scomp_scratch);
- spin_lock(&scratch->lock);
+ if (sg_nents(req->dst) > 1)
+ return -ENOSYS;
- if (sg_nents(req->src) == 1 && !PageHighMem(sg_page(req->src))) {
- src = page_to_virt(sg_page(req->src)) + req->src->offset;
- } else {
- scatterwalk_map_and_copy(scratch->src, req->src, 0,
- req->slen, 0);
- src = scratch->src;
- }
+ if (req->dst->offset >= PAGE_SIZE)
+ return -ENOSYS;
- if (req->dst && sg_nents(req->dst) == 1 && !PageHighMem(sg_page(req->dst)))
- dst = page_to_virt(sg_page(req->dst)) + req->dst->offset;
- else
- dst = scratch->dst;
+ if (req->dst->offset + dlen > PAGE_SIZE)
+ dlen = PAGE_SIZE - req->dst->offset;
+
+ src = kmap_local_page(sg_page(req->src)) + req->src->offset;
+ dst = kmap_local_page(sg_page(req->dst)) + req->dst->offset;
if (dir)
- ret = crypto_scomp_compress(scomp, src, req->slen,
+ ret = crypto_scomp_compress(scomp, src, slen,
dst, &req->dlen, *ctx);
else
- ret = crypto_scomp_decompress(scomp, src, req->slen,
+ ret = crypto_scomp_decompress(scomp, src, slen,
dst, &req->dlen, *ctx);
- if (!ret) {
- if (!req->dst) {
- req->dst = sgl_alloc(req->dlen, GFP_ATOMIC, NULL);
- if (!req->dst) {
- ret = -ENOMEM;
- goto out;
- }
- } else if (req->dlen > dlen) {
- ret = -ENOSPC;
- goto out;
- }
- if (dst == scratch->dst) {
- scatterwalk_map_and_copy(scratch->dst, req->dst, 0,
- req->dlen, 1);
- } else {
- int nr_pages = DIV_ROUND_UP(req->dst->offset + req->dlen, PAGE_SIZE);
- int i;
- struct page *dst_page = sg_page(req->dst);
- for (i = 0; i < nr_pages; i++)
- flush_dcache_page(dst_page + i);
- }
- }
-out:
- spin_unlock(&scratch->lock);
+ kunmap_local(src);
+ kunmap_local(dst);
+ flush_dcache_page(sg_page(req->dst));
+
return ret;
}
@@ -197,11 +114,6 @@ static void crypto_exit_scomp_ops_async(struct crypto_tfm *tfm)
struct crypto_scomp **ctx = crypto_tfm_ctx(tfm);
crypto_free_scomp(*ctx);
-
- mutex_lock(&scomp_lock);
- if (!--scomp_scratch_users)
- crypto_scomp_free_scratches();
- mutex_unlock(&scomp_lock);
}
int crypto_init_scomp_ops_async(struct crypto_tfm *tfm)
@@ -225,7 +137,6 @@ int crypto_init_scomp_ops_async(struct crypto_tfm *tfm)
crt->compress = scomp_acomp_compress;
crt->decompress = scomp_acomp_decompress;
- crt->dst_free = sgl_free;
crt->reqsize = sizeof(void *);
return 0;
diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h
index 15bb13e47f8b..25e193b0b8b4 100644
--- a/include/crypto/acompress.h
+++ b/include/crypto/acompress.h
@@ -15,8 +15,6 @@
#include <linux/scatterlist.h>
#include <linux/types.h>
-#define CRYPTO_ACOMP_ALLOC_OUTPUT 0x00000001
-
/* Set this bit for virtual address instead of SG list. */
#define CRYPTO_ACOMP_REQ_VIRT 0x00000002
@@ -75,15 +73,12 @@ struct acomp_req {
*
* @compress: Function performs a compress operation
* @decompress: Function performs a de-compress operation
- * @dst_free: Frees destination buffer if allocated inside the
- * algorithm
* @reqsize: Context size for (de)compression requests
* @base: Common crypto API algorithm data structure
*/
struct crypto_acomp {
int (*compress)(struct acomp_req *req);
int (*decompress)(struct acomp_req *req);
- void (*dst_free)(struct scatterlist *dst);
unsigned int reqsize;
struct crypto_tfm base;
};
@@ -234,7 +229,7 @@ static inline void acomp_request_set_callback(struct acomp_req *req,
crypto_completion_t cmpl,
void *data)
{
- u32 keep = CRYPTO_ACOMP_ALLOC_OUTPUT | CRYPTO_ACOMP_REQ_VIRT;
+ u32 keep = CRYPTO_ACOMP_REQ_VIRT;
req->base.complete = cmpl;
req->base.data = data;
@@ -268,9 +263,7 @@ static inline void acomp_request_set_params(struct acomp_req *req,
req->slen = slen;
req->dlen = dlen;
- req->base.flags &= ~(CRYPTO_ACOMP_ALLOC_OUTPUT | CRYPTO_ACOMP_REQ_VIRT);
- if (!req->dst)
- req->base.flags |= CRYPTO_ACOMP_ALLOC_OUTPUT;
+ req->base.flags &= ~CRYPTO_ACOMP_REQ_VIRT;
}
/**
@@ -294,7 +287,6 @@ static inline void acomp_request_set_virt(struct acomp_req *req,
req->slen = slen;
req->dlen = dlen;
- req->base.flags &= ~CRYPTO_ACOMP_ALLOC_OUTPUT;
req->base.flags |= CRYPTO_ACOMP_REQ_VIRT;
}
diff --git a/include/crypto/internal/scompress.h b/include/crypto/internal/scompress.h
index 07a10fd2d321..25c5f8126618 100644
--- a/include/crypto/internal/scompress.h
+++ b/include/crypto/internal/scompress.h
@@ -12,8 +12,6 @@
#include <crypto/acompress.h>
#include <crypto/algapi.h>
-#define SCOMP_SCRATCH_SIZE 131072
-
struct acomp_req;
struct crypto_scomp {
--
2.39.5
next prev parent reply other threads:[~2025-02-27 10:15 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 10:14 [PATCH 0/7] crypto: acomp - Add request chaining and virtual address support Herbert Xu
2025-02-27 10:14 ` [PATCH 1/7] crypto: iaa - Test the correct request flag Herbert Xu
2025-02-27 10:14 ` [PATCH 2/7] crypto: acomp - Remove acomp request flags Herbert Xu
2025-02-27 10:15 ` [PATCH 3/7] crypto: acomp - Add request chaining and virtual addresses Herbert Xu
2025-02-27 18:33 ` Eric Biggers
2025-02-27 10:15 ` [PATCH 4/7] crypto: testmgr - Remove NULL dst acomp tests Herbert Xu
2025-02-27 10:15 ` Herbert Xu [this message]
2025-02-27 10:15 ` [PATCH 6/7] crypto: scomp - Add chaining and virtual address support Herbert Xu
2025-02-27 10:15 ` [RFC PATCH 7/7] mm: zswap: Use acomp virtual address interface Herbert Xu
2025-02-27 18:11 ` Yosry Ahmed
2025-02-27 18:38 ` Eric Biggers
2025-02-27 21:43 ` Yosry Ahmed
2025-02-28 8:13 ` Herbert Xu
2025-02-28 9:54 ` Herbert Xu
2025-02-28 15:56 ` Yosry Ahmed
2025-03-01 6:36 ` Herbert Xu
2025-03-01 7:03 ` Herbert Xu
2025-03-03 20:17 ` Yosry Ahmed
2025-03-04 3:29 ` Herbert Xu
2025-03-04 4:30 ` Yosry Ahmed
2025-03-04 6:10 ` Herbert Xu
2025-03-04 8:33 ` Sergey Senozhatsky
2025-03-04 8:42 ` Herbert Xu
2025-03-04 8:45 ` Sergey Senozhatsky
2025-03-04 13:19 ` Sergey Senozhatsky
2025-03-04 20:47 ` Yosry Ahmed
2025-03-05 3:45 ` Herbert Xu
[not found] ` <Z8fssWOSw0kfggsM@google.com>
2025-03-05 7:41 ` Herbert Xu
2025-03-05 17:07 ` Nhat Pham
2025-03-06 2:48 ` Sergey Senozhatsky
2025-03-05 3:40 ` Herbert Xu
[not found] ` <Z8fsXZNgEbVkZrJP@google.com>
2025-03-05 7:46 ` Herbert Xu
2025-03-05 14:10 ` Herbert Xu
2025-03-05 16:25 ` Yosry Ahmed
2025-03-06 0:40 ` Herbert Xu
2025-03-06 16:58 ` Yosry Ahmed
2025-03-01 7:34 ` Herbert Xu
2025-03-01 7:38 ` Herbert Xu
2025-02-27 18:11 ` [PATCH 0/7] crypto: acomp - Add request chaining and virtual address support Yosry Ahmed
2025-02-28 9:02 ` Herbert Xu
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=30f87ea9a3738c57287f9099a9e638781fa212c5.1740651138.git.herbert@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=yosry.ahmed@linux.dev \
/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