Skip to contentSkip to conversation

crypto: Remove cavium zip and drop scomp dst buffer

PATCH In review Herbert Xu 2 participants 5 messages Mar 19, 2025 – Mar 20, 2025 Crypto API

lore
Share & tools
lore

Herbert Xu

author maintainer
#0 lore raw

cover crypto: Remove cavium zip and drop scomp dst buffer

This series removes the cavium zip driver and the dst scratch buffer from scomp. The latter could use up to 64K of memory per CPU.

Herbert Xu (3):
crypto: cavium - Move cpt and nitrox rules into cavium Makefile
crypto: cavium/zip - Remove driver
crypto: scomp - Drop the dst scratch buffer

 crypto/scompress.c                      |   98 +-
 drivers/crypto/Kconfig                  |    7 -
 drivers/crypto/Makefile                 |    4 +-
 drivers/crypto/cavium/Makefile          |    3 +-
 drivers/crypto/cavium/zip/Makefile      |   12 -
 drivers/crypto/cavium/zip/common.h      |  222 ----
 drivers/crypto/cavium/zip/zip_crypto.c  |  261 -----
 drivers/crypto/cavium/zip/zip_crypto.h  |   68 --
 drivers/crypto/cavium/zip/zip_deflate.c |  200 ----
 drivers/crypto/cavium/zip/zip_deflate.h |   62 --
 drivers/crypto/cavium/zip/zip_device.c  |  202 ----
 drivers/crypto/cavium/zip/zip_device.h  |  108 --
 drivers/crypto/cavium/zip/zip_inflate.c |  223 ----
 drivers/crypto/cavium/zip/zip_inflate.h |   62 --
 drivers/crypto/cavium/zip/zip_main.c    |  603 ----------
 drivers/crypto/cavium/zip/zip_main.h    |  120 --
 drivers/crypto/cavium/zip/zip_mem.c     |  114 --
 drivers/crypto/cavium/zip/zip_mem.h     |   78 --
 drivers/crypto/cavium/zip/zip_regs.h    | 1347 -----------------------
 19 files changed, 47 insertions(+), 3747 deletions(-)
 delete mode 100644 drivers/crypto/cavium/zip/Makefile
 delete mode 100644 drivers/crypto/cavium/zip/common.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_crypto.c
 delete mode 100644 drivers/crypto/cavium/zip/zip_crypto.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_deflate.c
 delete mode 100644 drivers/crypto/cavium/zip/zip_deflate.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_device.c
 delete mode 100644 drivers/crypto/cavium/zip/zip_device.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_inflate.c
 delete mode 100644 drivers/crypto/cavium/zip/zip_inflate.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_main.c
 delete mode 100644 drivers/crypto/cavium/zip/zip_main.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_mem.c
 delete mode 100644 drivers/crypto/cavium/zip/zip_mem.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_regs.h
Signature · 1 line
2.39.5
author maintainer
#1 lore raw

PATCH 1/3 crypto: cavium - Move cpt and nitrox rules into cavium Makefile

Move the cpt and nitrox rules into the cavium Makefile.

---
 drivers/crypto/Makefile        | 4 +---
 drivers/crypto/cavium/Makefile | 2 ++
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/Makefile +1 -3
index c97f0ebc55ec..22eadcc8f4a2 100644
@@ -8,12 +8,9 @@ obj-$(CONFIG_CRYPTO_DEV_ATMEL_TDES) += atmel-tdes.o
 obj-$(CONFIG_CRYPTO_DEV_ATMEL_I2C) += atmel-i2c.o
 obj-$(CONFIG_CRYPTO_DEV_ATMEL_ECC) += atmel-ecc.o
 obj-$(CONFIG_CRYPTO_DEV_ATMEL_SHA204A) += atmel-sha204a.o
-obj-$(CONFIG_CRYPTO_DEV_CAVIUM_ZIP) += cavium/
 obj-$(CONFIG_CRYPTO_DEV_CCP) += ccp/
 obj-$(CONFIG_CRYPTO_DEV_CCREE) += ccree/
 obj-$(CONFIG_CRYPTO_DEV_CHELSIO) += chelsio/
-obj-$(CONFIG_CRYPTO_DEV_CPT) += cavium/cpt/
-obj-$(CONFIG_CRYPTO_DEV_NITROX) += cavium/nitrox/
 obj-$(CONFIG_CRYPTO_DEV_EXYNOS_RNG) += exynos-rng.o
 obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_COMMON) += caam/
 obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o
@@ -50,3 +47,4 @@ obj-y += hisilicon/
 obj-$(CONFIG_CRYPTO_DEV_AMLOGIC_GXL) += amlogic/
 obj-y += intel/
 obj-y += starfive/
+obj-y += cavium/
drivers/crypto/cavium/Makefile +2 -0
index 4679c06b611f..6c1297426376 100644
@@ -2,4 +2,6 @@
 #
 # Makefile for Cavium crypto device drivers
 #
+obj-$(CONFIG_CRYPTO_DEV_CPT) += cpt/
+obj-$(CONFIG_CRYPTO_DEV_NITROX) += nitrox/
 obj-$(CONFIG_CRYPTO_DEV_CAVIUM_ZIP) += zip/
Signature · 1 line
2.39.5
author maintainer
#2 lore raw

PATCH 2/3 crypto: cavium/zip - Remove driver

In reply to Herbert Xu

Remove cavium/zip as it is obsolete and stands in the way of acomp API work. If this is ever resurrected, please turn it into an acomp driver.

---
 drivers/crypto/Kconfig                  |    7 -
 drivers/crypto/cavium/Makefile          |    1 -
 drivers/crypto/cavium/zip/Makefile      |   12 -
 drivers/crypto/cavium/zip/common.h      |  222 ----
 drivers/crypto/cavium/zip/zip_crypto.c  |  261 -----
 drivers/crypto/cavium/zip/zip_crypto.h  |   68 --
 drivers/crypto/cavium/zip/zip_deflate.c |  200 ----
 drivers/crypto/cavium/zip/zip_deflate.h |   62 --
 drivers/crypto/cavium/zip/zip_device.c  |  202 ----
 drivers/crypto/cavium/zip/zip_device.h  |  108 --
 drivers/crypto/cavium/zip/zip_inflate.c |  223 ----
 drivers/crypto/cavium/zip/zip_inflate.h |   62 --
 drivers/crypto/cavium/zip/zip_main.c    |  603 ----------
 drivers/crypto/cavium/zip/zip_main.h    |  120 --
 drivers/crypto/cavium/zip/zip_mem.c     |  114 --
 drivers/crypto/cavium/zip/zip_mem.h     |   78 --
 drivers/crypto/cavium/zip/zip_regs.h    | 1347 -----------------------
 17 files changed, 3690 deletions(-)
 delete mode 100644 drivers/crypto/cavium/zip/Makefile
 delete mode 100644 drivers/crypto/cavium/zip/common.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_crypto.c
 delete mode 100644 drivers/crypto/cavium/zip/zip_crypto.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_deflate.c
 delete mode 100644 drivers/crypto/cavium/zip/zip_deflate.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_device.c
 delete mode 100644 drivers/crypto/cavium/zip/zip_device.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_inflate.c
 delete mode 100644 drivers/crypto/cavium/zip/zip_inflate.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_main.c
 delete mode 100644 drivers/crypto/cavium/zip/zip_main.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_mem.c
 delete mode 100644 drivers/crypto/cavium/zip/zip_mem.h
 delete mode 100644 drivers/crypto/cavium/zip/zip_regs.h
drivers/crypto/Kconfig +0 -7
index 47082782008a..5686369779be 100644
@@ -530,13 +530,6 @@ source "drivers/crypto/cavium/nitrox/Kconfig"
 source "drivers/crypto/marvell/Kconfig"
 source "drivers/crypto/intel/Kconfig"
 
-config CRYPTO_DEV_CAVIUM_ZIP
-	tristate "Cavium ZIP driver"
-	depends on PCI && 64BIT && (ARM64 || COMPILE_TEST)
-	help
-	  Select this option if you want to enable compression/decompression
-	  acceleration on Cavium's ARM based SoCs
-
 config CRYPTO_DEV_QCE
 	tristate "Qualcomm crypto engine accelerator"
 	depends on ARCH_QCOM || COMPILE_TEST
drivers/crypto/cavium/Makefile +0 -1
index 6c1297426376..75227c587ed0 100644
@@ -4,4 +4,3 @@
 #
 obj-$(CONFIG_CRYPTO_DEV_CPT) += cpt/
 obj-$(CONFIG_CRYPTO_DEV_NITROX) += nitrox/
-obj-$(CONFIG_CRYPTO_DEV_CAVIUM_ZIP) += zip/
drivers/crypto/cavium/zip/Makefile deleted +0 -12
deleted file mode 100644
index 020d189d793d..000000000000
@@ -1,12 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-#
-# Makefile for Cavium's ZIP Driver.
-#
-
-obj-$(CONFIG_CRYPTO_DEV_CAVIUM_ZIP) += thunderx_zip.o
-thunderx_zip-y := zip_main.o    \
-                  zip_device.o  \
-                  zip_crypto.o  \
-                  zip_mem.o     \
-                  zip_deflate.o \
-                  zip_inflate.o
drivers/crypto/cavium/zip/common.h deleted +0 -222

222 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_crypto.c deleted +0 -261

261 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_crypto.h deleted +0 -68

68 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_deflate.c deleted +0 -200

200 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_deflate.h deleted +0 -62

62 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_device.c deleted +0 -202

202 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_device.h deleted +0 -108

108 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_inflate.c deleted +0 -223

223 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_inflate.h deleted +0 -62

62 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_main.c deleted +0 -603

603 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_main.h deleted +0 -120

120 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_mem.c deleted +0 -114

114 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_mem.h deleted +0 -78

78 lines not on this page · raw message

drivers/crypto/cavium/zip/zip_regs.h deleted +0 -1347

648 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.39.5

Part of the diff is not shown here. View the raw message.

author maintainer
#3 lore raw

PATCH 3/3 crypto: scomp - Drop the dst scratch buffer

In reply to Herbert Xu

As deflate has been converted over to acomp, and cavium zip has been removed, there are no longer any scomp algorithms that can be used by IPsec.

Since IPsec was the only user of the dst scratch buffer, remove it.

---
 crypto/scompress.c | 98 +++++++++++++++++++++-------------------------
 1 file changed, 44 insertions(+), 54 deletions(-)
crypto/scompress.c +44 -54
index 5a40605570f5..4a2b3933aa95 100644
@@ -25,15 +25,12 @@
 
 #include "compress.h"
 
-#define SCOMP_SCRATCH_SIZE 65400
-
 struct scomp_scratch {
 	spinlock_t	lock;
 	union {
 		void	*src;
 		unsigned long saddr;
 	};
-	void		*dst;
 };
 
 static DEFINE_PER_CPU(struct scomp_scratch, scomp_scratch) = {
@@ -78,9 +75,7 @@ static void crypto_scomp_free_scratches(void)
 		scratch = per_cpu_ptr(&scomp_scratch, i);
 
 		free_page(scratch->saddr);
-		kvfree(scratch->dst);
 		scratch->src = NULL;
-		scratch->dst = NULL;
 	}
 }
 
@@ -88,19 +83,12 @@ static int scomp_alloc_scratch(struct scomp_scratch *scratch, int cpu)
 {
 	int node = cpu_to_node(cpu);
 	struct page *page;
-	void *mem;
 
-	mem = kvmalloc_node(SCOMP_SCRATCH_SIZE, GFP_KERNEL, node);
-	if (!mem)
-		return -ENOMEM;
 	page = alloc_pages_node(node, GFP_KERNEL, 0);
-	if (!page) {
-		kvfree(mem);
+	if (!page)
 		return -ENOMEM;
-	}
 	spin_lock_bh(&scratch->lock);
 	scratch->src = page_address(page);
-	scratch->dst = mem;
 	spin_unlock_bh(&scratch->lock);
 	return 0;
 }
@@ -181,6 +169,8 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
 {
 	struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
 	struct crypto_scomp **tfm_ctx = acomp_tfm_ctx(tfm);
+	bool src_isvirt = acomp_request_src_isvirt(req);
+	bool dst_isvirt = acomp_request_dst_isvirt(req);
 	struct crypto_scomp *scomp = *tfm_ctx;
 	struct crypto_acomp_stream *stream;
 	struct scomp_scratch *scratch;
@@ -200,13 +190,33 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
 	if (!req->dst || !dlen)
 		return -EINVAL;
 
-	stream = crypto_acomp_lock_stream_bh(&crypto_scomp_alg(scomp)->streams);
-	scratch = scomp_lock_scratch();
+	if (dst_isvirt)
+		dst = req->dvirt;
+	else {
+		if (acomp_request_dst_isfolio(req)) {
+			dpage = folio_page(req->dfolio, 0);
+			doff = req->doff;
+		} else if (dlen <= req->dst->length) {
+			dpage = sg_page(req->dst);
+			doff = req->dst->offset;
+		} else
+			return -ENOSYS;
 
-	if (acomp_request_src_isvirt(req))
+		dpage = nth_page(dpage, doff / PAGE_SIZE);
+		doff = offset_in_page(doff);
+
+		n = dlen / PAGE_SIZE;
+		n += (offset_in_page(dlen) + doff - 1) / PAGE_SIZE;
+		if (PageHighMem(dpage + n) &&
+		    size_add(doff, dlen) > PAGE_SIZE)
+			return -ENOSYS;
+		dst = kmap_local_page(dpage) + doff;
+	}
+
+	if (src_isvirt)
 		src = req->svirt;
 	else {
-		src = scratch->src;
+		src = NULL;
 		do {
 			if (acomp_request_src_isfolio(req)) {
 				spage = folio_page(req->sfolio, 0);
@@ -227,57 +237,39 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
 				break;
 			src = kmap_local_page(spage) + soff;
 		} while (0);
-
-		if (src == scratch->src)
-			memcpy_from_sglist(scratch->src, req->src, 0, slen);
 	}
 
-	if (acomp_request_dst_isvirt(req))
-		dst = req->dvirt;
-	else {
-		unsigned int max = SCOMP_SCRATCH_SIZE;
+	stream = crypto_acomp_lock_stream_bh(&crypto_scomp_alg(scomp)->streams);
 
-		dst = scratch->dst;
-		do {
-			if (acomp_request_dst_isfolio(req)) {
-				dpage = folio_page(req->dfolio, 0);
-				doff = req->doff;
-			} else if (dlen <= req->dst->length) {
-				dpage = sg_page(req->dst);
-				doff = req->dst->offset;
-			} else
-				break;
+	if (!src_isvirt && !src) {
+		const u8 *src;
 
-			dpage = nth_page(dpage, doff / PAGE_SIZE);
-			doff = offset_in_page(doff);
+		scratch = scomp_lock_scratch();
+		src = scratch->src;
+		memcpy_from_sglist(scratch->src, req->src, 0, slen);
 
-			n = dlen / PAGE_SIZE;
-			n += (offset_in_page(dlen) + doff - 1) / PAGE_SIZE;
-			if (PageHighMem(dpage + n) &&
-			    size_add(doff, dlen) > PAGE_SIZE)
-				break;
-			dst = kmap_local_page(dpage) + doff;
-			max = dlen;
-		} while (0);
-		dlen = min(dlen, max);
-	}
+		if (dir)
+			ret = crypto_scomp_compress(scomp, src, slen,
+						    dst, &dlen, stream->ctx);
+		else
+			ret = crypto_scomp_decompress(scomp, src, slen,
+						      dst, &dlen, stream->ctx);
 
-	if (dir)
+		scomp_unlock_scratch(scratch);
+	} else if (dir)
 		ret = crypto_scomp_compress(scomp, src, slen,
 					    dst, &dlen, stream->ctx);
 	else
 		ret = crypto_scomp_decompress(scomp, src, slen,
 					      dst, &dlen, stream->ctx);
 
-	if (dst == scratch->dst)
-		memcpy_to_sglist(req->dst, 0, dst, dlen);
-
-	scomp_unlock_scratch(scratch);
 	crypto_acomp_unlock_stream_bh(stream);
 
 	req->dlen = dlen;
 
-	if (!acomp_request_dst_isvirt(req) && dst != scratch->dst) {
+	if (!src_isvirt && src)
+		kunmap_local(src);
+	if (!dst_isvirt) {
 		kunmap_local(dst);
 		dlen += doff;
 		for (;;) {
@@ -288,8 +280,6 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
 			dpage = nth_page(dpage, 1);
 		}
 	}
-	if (!acomp_request_src_isvirt(req) && src != scratch->src)
-		kunmap_local(src);
 
 	return ret;
 }
Signature · 1 line
2.39.5
Acked-by on the v1 series
#4 lore raw
In reply to Herbert Xu
Quoted 9 lines · Herbert Xu

This series removes the cavium zip driver and the dst scratch buffer from scomp. The latter could use up to 64K of memory per CPU.

Herbert Xu (3):
crypto: cavium - Move cpt and nitrox rules into cavium Makefile
crypto: cavium/zip - Remove driver
crypto: scomp - Drop the dst scratch buffer

I haven't followed the acomp changes in detail, but this series seems like a welcome cleanup, so