* [PATCH v1 0/3] zram: introduce crypto-backend api
@ 2024-11-19 12:27 Alexey Romanov
2024-11-19 12:27 ` [PATCH v1 1/3] zram: pass zcomp instead of zcomp_params to create_context method Alexey Romanov
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Alexey Romanov @ 2024-11-19 12:27 UTC (permalink / raw)
To: minchan, senozhatsky, axboe, terrelln
Cc: linux-kernel, linux-block, kernel, Alexey Romanov
Since we use custom backend implementation, we remove the ability
for users to use algorithms from crypto backend. This breaks
backward compatibility, user doesn't necessarily use one of the
algorithms from "custom" backends defined in zram folder.
For example, he can use some driver with hardware compression support.
This patchset adds an option that allows user to enable Crypto API
backend support. Crypto API backend is also implemented in a separate
file backend_crypto_api like the other custom backends.
Alexey Romanov (3):
zram: pass zcomp instead of zcomp_params to create_context method
zram: store crypto backends in list instead of array
zram: introduce crypto-api backend
drivers/block/zram/Kconfig | 10 ++
drivers/block/zram/Makefile | 1 +
drivers/block/zram/backend_842.c | 14 +-
drivers/block/zram/backend_842.h | 2 +-
drivers/block/zram/backend_crypto_api.c | 117 +++++++++++++++
drivers/block/zram/backend_crypto_api.h | 10 ++
drivers/block/zram/backend_deflate.c | 15 +-
drivers/block/zram/backend_deflate.h | 2 +-
drivers/block/zram/backend_lz4.c | 15 +-
drivers/block/zram/backend_lz4.h | 2 +-
drivers/block/zram/backend_lz4hc.c | 15 +-
drivers/block/zram/backend_lz4hc.h | 2 +-
drivers/block/zram/backend_lzo.c | 14 +-
drivers/block/zram/backend_lzo.h | 2 +-
drivers/block/zram/backend_lzorle.c | 14 +-
drivers/block/zram/backend_lzorle.h | 2 +-
drivers/block/zram/backend_zstd.c | 15 +-
drivers/block/zram/backend_zstd.h | 2 +-
drivers/block/zram/zcomp.c | 183 ++++++++++++++++++------
drivers/block/zram/zcomp.h | 11 +-
drivers/block/zram/zram_drv.c | 7 +
21 files changed, 390 insertions(+), 65 deletions(-)
create mode 100644 drivers/block/zram/backend_crypto_api.c
create mode 100644 drivers/block/zram/backend_crypto_api.h
--
2.34.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v1 1/3] zram: pass zcomp instead of zcomp_params to create_context method
2024-11-19 12:27 [PATCH v1 0/3] zram: introduce crypto-backend api Alexey Romanov
@ 2024-11-19 12:27 ` Alexey Romanov
2024-11-19 12:27 ` [PATCH v1 2/3] zram: store crypto backends in list instead of array Alexey Romanov
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Alexey Romanov @ 2024-11-19 12:27 UTC (permalink / raw)
To: minchan, senozhatsky, axboe, terrelln
Cc: linux-kernel, linux-block, kernel, Alexey Romanov
This is a more general approach: for some backends, some of the
data needed to create a context can be stored in zcomp structure.
And we also can get zcomp_params structure from zcomp.
Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
---
drivers/block/zram/backend_842.c | 2 +-
drivers/block/zram/backend_deflate.c | 3 ++-
drivers/block/zram/backend_lz4.c | 3 ++-
drivers/block/zram/backend_lz4hc.c | 3 ++-
drivers/block/zram/backend_lzo.c | 2 +-
drivers/block/zram/backend_lzorle.c | 2 +-
drivers/block/zram/backend_zstd.c | 3 ++-
drivers/block/zram/zcomp.c | 2 +-
drivers/block/zram/zcomp.h | 4 +++-
9 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/drivers/block/zram/backend_842.c b/drivers/block/zram/backend_842.c
index 10d9d5c60f53..9147feb1e994 100644
--- a/drivers/block/zram/backend_842.c
+++ b/drivers/block/zram/backend_842.c
@@ -21,7 +21,7 @@ static void destroy_842(struct zcomp_ctx *ctx)
kfree(ctx->context);
}
-static int create_842(struct zcomp_params *params, struct zcomp_ctx *ctx)
+static int create_842(struct zcomp *zcomp, struct zcomp_ctx *ctx)
{
ctx->context = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL);
if (!ctx->context)
diff --git a/drivers/block/zram/backend_deflate.c b/drivers/block/zram/backend_deflate.c
index 0f7f252c12f4..10fde82dc5e7 100644
--- a/drivers/block/zram/backend_deflate.c
+++ b/drivers/block/zram/backend_deflate.c
@@ -46,8 +46,9 @@ static void deflate_destroy(struct zcomp_ctx *ctx)
kfree(zctx);
}
-static int deflate_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
+static int deflate_create(struct zcomp *zcomp, struct zcomp_ctx *ctx)
{
+ struct zcomp_params *params = zcomp->params;
struct deflate_ctx *zctx;
size_t sz;
int ret;
diff --git a/drivers/block/zram/backend_lz4.c b/drivers/block/zram/backend_lz4.c
index 847f3334eb38..8f7c8f16b6ce 100644
--- a/drivers/block/zram/backend_lz4.c
+++ b/drivers/block/zram/backend_lz4.c
@@ -37,8 +37,9 @@ static void lz4_destroy(struct zcomp_ctx *ctx)
kfree(zctx);
}
-static int lz4_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
+static int lz4_create(struct zcomp *zcomp, struct zcomp_ctx *ctx)
{
+ struct zcomp_params *params = zcomp->params;
struct lz4_ctx *zctx;
zctx = kzalloc(sizeof(*zctx), GFP_KERNEL);
diff --git a/drivers/block/zram/backend_lz4hc.c b/drivers/block/zram/backend_lz4hc.c
index 5f37d5abcaeb..b0302b8027ab 100644
--- a/drivers/block/zram/backend_lz4hc.c
+++ b/drivers/block/zram/backend_lz4hc.c
@@ -37,8 +37,9 @@ static void lz4hc_destroy(struct zcomp_ctx *ctx)
kfree(zctx);
}
-static int lz4hc_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
+static int lz4hc_create(struct zcomp *zcomp, struct zcomp_ctx *ctx)
{
+ struct zcomp_params *params = zcomp->params;
struct lz4hc_ctx *zctx;
zctx = kzalloc(sizeof(*zctx), GFP_KERNEL);
diff --git a/drivers/block/zram/backend_lzo.c b/drivers/block/zram/backend_lzo.c
index 4c906beaae6b..78e611ea841e 100644
--- a/drivers/block/zram/backend_lzo.c
+++ b/drivers/block/zram/backend_lzo.c
@@ -15,7 +15,7 @@ static int lzo_setup_params(struct zcomp_params *params)
return 0;
}
-static int lzo_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
+static int lzo_create(struct zcomp *params, struct zcomp_ctx *ctx)
{
ctx->context = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
if (!ctx->context)
diff --git a/drivers/block/zram/backend_lzorle.c b/drivers/block/zram/backend_lzorle.c
index 10640c96cbfc..b0ff72468ea8 100644
--- a/drivers/block/zram/backend_lzorle.c
+++ b/drivers/block/zram/backend_lzorle.c
@@ -15,7 +15,7 @@ static int lzorle_setup_params(struct zcomp_params *params)
return 0;
}
-static int lzorle_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
+static int lzorle_create(struct zcomp *zcomp, struct zcomp_ctx *ctx)
{
ctx->context = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
if (!ctx->context)
diff --git a/drivers/block/zram/backend_zstd.c b/drivers/block/zram/backend_zstd.c
index 1184c0036f44..b73b975599f4 100644
--- a/drivers/block/zram/backend_zstd.c
+++ b/drivers/block/zram/backend_zstd.c
@@ -125,8 +125,9 @@ static void zstd_destroy(struct zcomp_ctx *ctx)
kfree(zctx);
}
-static int zstd_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
+static int zstd_create(struct zcomp *zcomp, struct zcomp_ctx *ctx)
{
+ struct zcomp_params *params = zcomp->params;
struct zstd_ctx *zctx;
zstd_parameters prm;
size_t sz;
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index bb514403e305..be3a31f09344 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -54,7 +54,7 @@ static int zcomp_strm_init(struct zcomp *comp, struct zcomp_strm *zstrm)
{
int ret;
- ret = comp->ops->create_ctx(comp->params, &zstrm->ctx);
+ ret = comp->ops->create_ctx(comp, &zstrm->ctx);
if (ret)
return ret;
diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h
index ad5762813842..89d32bb13f8c 100644
--- a/drivers/block/zram/zcomp.h
+++ b/drivers/block/zram/zcomp.h
@@ -45,13 +45,15 @@ struct zcomp_req {
size_t dst_len;
};
+struct zcomp;
+
struct zcomp_ops {
int (*compress)(struct zcomp_params *params, struct zcomp_ctx *ctx,
struct zcomp_req *req);
int (*decompress)(struct zcomp_params *params, struct zcomp_ctx *ctx,
struct zcomp_req *req);
- int (*create_ctx)(struct zcomp_params *params, struct zcomp_ctx *ctx);
+ int (*create_ctx)(struct zcomp *zcomp, struct zcomp_ctx *ctx);
void (*destroy_ctx)(struct zcomp_ctx *ctx);
int (*setup_params)(struct zcomp_params *params);
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v1 2/3] zram: store crypto backends in list instead of array
2024-11-19 12:27 [PATCH v1 0/3] zram: introduce crypto-backend api Alexey Romanov
2024-11-19 12:27 ` [PATCH v1 1/3] zram: pass zcomp instead of zcomp_params to create_context method Alexey Romanov
@ 2024-11-19 12:27 ` Alexey Romanov
2024-11-19 12:27 ` [PATCH v1 3/3] zram: introduce crypto-api backend Alexey Romanov
2024-11-20 3:15 ` [PATCH v1 0/3] zram: introduce crypto-backend api Sergey Senozhatsky
3 siblings, 0 replies; 11+ messages in thread
From: Alexey Romanov @ 2024-11-19 12:27 UTC (permalink / raw)
To: minchan, senozhatsky, axboe, terrelln
Cc: linux-kernel, linux-block, kernel, Alexey Romanov
This approach allows us to add backends in runtime.
We will use this in next patches.
Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
---
drivers/block/zram/backend_842.c | 12 ++-
drivers/block/zram/backend_842.h | 2 +-
drivers/block/zram/backend_deflate.c | 12 ++-
drivers/block/zram/backend_deflate.h | 2 +-
drivers/block/zram/backend_lz4.c | 12 ++-
drivers/block/zram/backend_lz4.h | 2 +-
drivers/block/zram/backend_lz4hc.c | 12 ++-
drivers/block/zram/backend_lz4hc.h | 2 +-
drivers/block/zram/backend_lzo.c | 12 ++-
drivers/block/zram/backend_lzo.h | 2 +-
drivers/block/zram/backend_lzorle.c | 12 ++-
drivers/block/zram/backend_lzorle.h | 2 +-
drivers/block/zram/backend_zstd.c | 12 ++-
drivers/block/zram/backend_zstd.h | 2 +-
drivers/block/zram/zcomp.c | 124 ++++++++++++++++++---------
drivers/block/zram/zcomp.h | 7 ++
drivers/block/zram/zram_drv.c | 7 ++
17 files changed, 180 insertions(+), 56 deletions(-)
diff --git a/drivers/block/zram/backend_842.c b/drivers/block/zram/backend_842.c
index 9147feb1e994..3b91b43888af 100644
--- a/drivers/block/zram/backend_842.c
+++ b/drivers/block/zram/backend_842.c
@@ -50,12 +50,22 @@ static int decompress_842(struct zcomp_params *params, struct zcomp_ctx *ctx,
return sw842_decompress(req->src, req->src_len, req->dst, &dlen);
}
-const struct zcomp_ops backend_842 = {
+static void destroy_ops_842(struct zcomp_ops *backend_842)
+{
+}
+
+struct zcomp_ops backend_842 = {
.compress = compress_842,
.decompress = decompress_842,
.create_ctx = create_842,
.destroy_ctx = destroy_842,
.setup_params = setup_params_842,
.release_params = release_params_842,
+ .destroy = destroy_ops_842,
.name = "842",
};
+
+struct zcomp_ops *get_backend_842(void)
+{
+ return &backend_842;
+}
diff --git a/drivers/block/zram/backend_842.h b/drivers/block/zram/backend_842.h
index 4dc85c188799..9cdc59b0faa9 100644
--- a/drivers/block/zram/backend_842.h
+++ b/drivers/block/zram/backend_842.h
@@ -5,6 +5,6 @@
#include "zcomp.h"
-extern const struct zcomp_ops backend_842;
+struct zcomp_ops *get_backend_842(void);
#endif /* __BACKEND_842_H__ */
diff --git a/drivers/block/zram/backend_deflate.c b/drivers/block/zram/backend_deflate.c
index 10fde82dc5e7..c1460ab04b24 100644
--- a/drivers/block/zram/backend_deflate.c
+++ b/drivers/block/zram/backend_deflate.c
@@ -136,12 +136,22 @@ static int deflate_decompress(struct zcomp_params *params,
return 0;
}
-const struct zcomp_ops backend_deflate = {
+static void deflate_destroy_ops(struct zcomp_ops *backend_delfate)
+{
+}
+
+struct zcomp_ops backend_deflate = {
.compress = deflate_compress,
.decompress = deflate_decompress,
.create_ctx = deflate_create,
.destroy_ctx = deflate_destroy,
.setup_params = deflate_setup_params,
.release_params = deflate_release_params,
+ .destroy = deflate_destroy_ops,
.name = "deflate",
};
+
+struct zcomp_ops *get_backend_deflate(void)
+{
+ return &backend_deflate;
+}
diff --git a/drivers/block/zram/backend_deflate.h b/drivers/block/zram/backend_deflate.h
index a39ac12b114c..c15b18012aeb 100644
--- a/drivers/block/zram/backend_deflate.h
+++ b/drivers/block/zram/backend_deflate.h
@@ -5,6 +5,6 @@
#include "zcomp.h"
-extern const struct zcomp_ops backend_deflate;
+struct zcomp_ops *get_backend_deflate(void);
#endif /* __BACKEND_DEFLATE_H__ */
diff --git a/drivers/block/zram/backend_lz4.c b/drivers/block/zram/backend_lz4.c
index 8f7c8f16b6ce..5638eefa657a 100644
--- a/drivers/block/zram/backend_lz4.c
+++ b/drivers/block/zram/backend_lz4.c
@@ -117,12 +117,22 @@ static int lz4_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx,
return 0;
}
-const struct zcomp_ops backend_lz4 = {
+static void lz4_destroy_ops(struct zcomp_ops *backend_lz4)
+{
+}
+
+struct zcomp_ops backend_lz4 = {
.compress = lz4_compress,
.decompress = lz4_decompress,
.create_ctx = lz4_create,
.destroy_ctx = lz4_destroy,
.setup_params = lz4_setup_params,
.release_params = lz4_release_params,
+ .destroy = lz4_destroy_ops,
.name = "lz4",
};
+
+struct zcomp_ops *get_backend_lz4(void)
+{
+ return &backend_lz4;
+}
diff --git a/drivers/block/zram/backend_lz4.h b/drivers/block/zram/backend_lz4.h
index c11fa602a703..439f96222ee5 100644
--- a/drivers/block/zram/backend_lz4.h
+++ b/drivers/block/zram/backend_lz4.h
@@ -5,6 +5,6 @@
#include "zcomp.h"
-extern const struct zcomp_ops backend_lz4;
+struct zcomp_ops *get_backend_lz4(void);
#endif /* __BACKEND_LZ4_H__ */
diff --git a/drivers/block/zram/backend_lz4hc.c b/drivers/block/zram/backend_lz4hc.c
index b0302b8027ab..c502b6afd571 100644
--- a/drivers/block/zram/backend_lz4hc.c
+++ b/drivers/block/zram/backend_lz4hc.c
@@ -118,12 +118,22 @@ static int lz4hc_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx,
return 0;
}
-const struct zcomp_ops backend_lz4hc = {
+static void lz4hc_destroy_ops(struct zcomp_ops *backend_lz4hc)
+{
+}
+
+struct zcomp_ops backend_lz4hc = {
.compress = lz4hc_compress,
.decompress = lz4hc_decompress,
.create_ctx = lz4hc_create,
.destroy_ctx = lz4hc_destroy,
.setup_params = lz4hc_setup_params,
.release_params = lz4hc_release_params,
+ .destroy = lz4hc_destroy_ops,
.name = "lz4hc",
};
+
+struct zcomp_ops *get_backend_lz4hc(void)
+{
+ return &backend_lz4hc;
+}
diff --git a/drivers/block/zram/backend_lz4hc.h b/drivers/block/zram/backend_lz4hc.h
index 6de03551ed4d..1334519082bb 100644
--- a/drivers/block/zram/backend_lz4hc.h
+++ b/drivers/block/zram/backend_lz4hc.h
@@ -5,6 +5,6 @@
#include "zcomp.h"
-extern const struct zcomp_ops backend_lz4hc;
+struct zcomp_ops *get_backend_lz4hc(void);
#endif /* __BACKEND_LZ4HC_H__ */
diff --git a/drivers/block/zram/backend_lzo.c b/drivers/block/zram/backend_lzo.c
index 78e611ea841e..88eab940f723 100644
--- a/drivers/block/zram/backend_lzo.c
+++ b/drivers/block/zram/backend_lzo.c
@@ -48,12 +48,22 @@ static int lzo_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx,
return ret == LZO_E_OK ? 0 : ret;
}
-const struct zcomp_ops backend_lzo = {
+static void lzo_destroy_ops(struct zcomp_ops *backend_lzo)
+{
+}
+
+struct zcomp_ops backend_lzo = {
.compress = lzo_compress,
.decompress = lzo_decompress,
.create_ctx = lzo_create,
.destroy_ctx = lzo_destroy,
.setup_params = lzo_setup_params,
.release_params = lzo_release_params,
+ .destroy = lzo_destroy_ops,
.name = "lzo",
};
+
+struct zcomp_ops *get_backend_lzo(void)
+{
+ return &backend_lzo;
+}
diff --git a/drivers/block/zram/backend_lzo.h b/drivers/block/zram/backend_lzo.h
index 93d54749e63c..21493591dec3 100644
--- a/drivers/block/zram/backend_lzo.h
+++ b/drivers/block/zram/backend_lzo.h
@@ -5,6 +5,6 @@
#include "zcomp.h"
-extern const struct zcomp_ops backend_lzo;
+struct zcomp_ops *get_backend_lzo(void);
#endif /* __BACKEND_LZO_H__ */
diff --git a/drivers/block/zram/backend_lzorle.c b/drivers/block/zram/backend_lzorle.c
index b0ff72468ea8..28837acd205c 100644
--- a/drivers/block/zram/backend_lzorle.c
+++ b/drivers/block/zram/backend_lzorle.c
@@ -48,12 +48,22 @@ static int lzorle_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx,
return ret == LZO_E_OK ? 0 : ret;
}
-const struct zcomp_ops backend_lzorle = {
+static void lzorle_destroy_ops(struct zcomp_ops *backend_lzorle)
+{
+}
+
+struct zcomp_ops backend_lzorle = {
.compress = lzorle_compress,
.decompress = lzorle_decompress,
.create_ctx = lzorle_create,
.destroy_ctx = lzorle_destroy,
.setup_params = lzorle_setup_params,
.release_params = lzorle_release_params,
+ .destroy = lzorle_destroy_ops,
.name = "lzo-rle",
};
+
+struct zcomp_ops *get_backend_lzorle(void)
+{
+ return &backend_lzorle;
+}
diff --git a/drivers/block/zram/backend_lzorle.h b/drivers/block/zram/backend_lzorle.h
index 6ecb163b09f1..7871f44b73a3 100644
--- a/drivers/block/zram/backend_lzorle.h
+++ b/drivers/block/zram/backend_lzorle.h
@@ -5,6 +5,6 @@
#include "zcomp.h"
-extern const struct zcomp_ops backend_lzorle;
+struct zcomp_ops *get_backend_lzorle(void);
#endif /* __BACKEND_LZORLE_H__ */
diff --git a/drivers/block/zram/backend_zstd.c b/drivers/block/zram/backend_zstd.c
index b73b975599f4..0762bea90296 100644
--- a/drivers/block/zram/backend_zstd.c
+++ b/drivers/block/zram/backend_zstd.c
@@ -216,12 +216,22 @@ static int zstd_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx,
return 0;
}
-const struct zcomp_ops backend_zstd = {
+static void zstd_destroy_ops(struct zcomp_ops *backend_zstd)
+{
+}
+
+struct zcomp_ops backend_zstd = {
.compress = zstd_compress,
.decompress = zstd_decompress,
.create_ctx = zstd_create,
.destroy_ctx = zstd_destroy,
.setup_params = zstd_setup_params,
.release_params = zstd_release_params,
+ .destroy = zstd_destroy_ops,
.name = "zstd",
};
+
+struct zcomp_ops *get_backend_zstd(void)
+{
+ return &backend_zstd;
+}
diff --git a/drivers/block/zram/backend_zstd.h b/drivers/block/zram/backend_zstd.h
index 10fdfff1ec1c..f737fbdfa57a 100644
--- a/drivers/block/zram/backend_zstd.h
+++ b/drivers/block/zram/backend_zstd.h
@@ -5,6 +5,6 @@
#include "zcomp.h"
-extern const struct zcomp_ops backend_zstd;
+struct zcomp_ops *get_backend_zstd(void);
#endif /* __BACKEND_ZSTD_H__ */
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index be3a31f09344..40b5ab4c598b 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -9,6 +9,7 @@
#include <linux/cpu.h>
#include <linux/crypto.h>
#include <linux/vmalloc.h>
+#include <linux/list.h>
#include "zcomp.h"
@@ -20,28 +21,7 @@
#include "backend_deflate.h"
#include "backend_842.h"
-static const struct zcomp_ops *backends[] = {
-#if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZO)
- &backend_lzorle,
- &backend_lzo,
-#endif
-#if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZ4)
- &backend_lz4,
-#endif
-#if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZ4HC)
- &backend_lz4hc,
-#endif
-#if IS_ENABLED(CONFIG_ZRAM_BACKEND_ZSTD)
- &backend_zstd,
-#endif
-#if IS_ENABLED(CONFIG_ZRAM_BACKEND_DEFLATE)
- &backend_deflate,
-#endif
-#if IS_ENABLED(CONFIG_ZRAM_BACKEND_842)
- &backend_842,
-#endif
- NULL
-};
+static LIST_HEAD(backends);
static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *zstrm)
{
@@ -72,14 +52,13 @@ static int zcomp_strm_init(struct zcomp *comp, struct zcomp_strm *zstrm)
static const struct zcomp_ops *lookup_backend_ops(const char *comp)
{
- int i = 0;
+ struct zcomp_ops *backend;
- while (backends[i]) {
- if (sysfs_streq(comp, backends[i]->name))
- break;
- i++;
- }
- return backends[i];
+ list_for_each_entry(backend, &backends, list)
+ if (sysfs_streq(comp, backend->name))
+ return backend;
+
+ return NULL;
}
bool zcomp_available_algorithm(const char *comp)
@@ -91,15 +70,15 @@ bool zcomp_available_algorithm(const char *comp)
ssize_t zcomp_available_show(const char *comp, char *buf)
{
ssize_t sz = 0;
- int i;
+ struct zcomp_ops *backend;
- for (i = 0; i < ARRAY_SIZE(backends) - 1; i++) {
- if (!strcmp(comp, backends[i]->name)) {
+ list_for_each_entry(backend, &backends, list) {
+ if (!strcmp(comp, backend->name)) {
sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2,
- "[%s] ", backends[i]->name);
+ "[%s] ", backend->name);
} else {
sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2,
- "%s ", backends[i]->name);
+ "%s ", backend->name);
}
}
@@ -211,14 +190,6 @@ struct zcomp *zcomp_create(const char *alg, struct zcomp_params *params)
struct zcomp *comp;
int error;
- /*
- * The backends array has a sentinel NULL value, so the minimum
- * size is 1. In order to be valid the array, apart from the
- * sentinel NULL element, should have at least one compression
- * backend selected.
- */
- BUILD_BUG_ON(ARRAY_SIZE(backends) <= 1);
-
comp = kzalloc(sizeof(struct zcomp), GFP_KERNEL);
if (!comp)
return ERR_PTR(-ENOMEM);
@@ -236,3 +207,72 @@ struct zcomp *zcomp_create(const char *alg, struct zcomp_params *params)
}
return comp;
}
+
+void clean_zcomp_backends(void)
+{
+ struct zcomp_ops *backend;
+
+ list_for_each_entry(backend, &backends, list)
+ backend->destroy(backend);
+}
+
+int init_zcomp_backends(void)
+{
+ struct zcomp_ops *ops;
+
+#if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZO)
+ ops = get_backend_lzorle();
+ if (IS_ERR_OR_NULL(ops))
+ goto err;
+
+ list_add(&ops->list, &backends);
+
+ ops = get_backend_lzo();
+ if (IS_ERR_OR_NULL(ops))
+ goto err;
+
+ list_add(&ops->list, &backends);
+#endif
+#if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZ4)
+ ops = get_backend_lz4();
+ if (IS_ERR_OR_NULL(ops))
+ goto err;
+
+ list_add(&ops->list, &backends);
+#endif
+#if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZ4HC)
+ ops = get_backend_lz4hc();
+ if (IS_ERR_OR_NULL(ops))
+ goto err;
+
+ list_add(&ops->list, &backends);
+#endif
+#if IS_ENABLED(CONFIG_ZRAM_BACKEND_ZSTD)
+ ops = get_backend_zstd();
+ if (IS_ERR_OR_NULL(ops))
+ goto err;
+
+ list_add(&ops->list, &backends);
+#endif
+#if IS_ENABLED(CONFIG_ZRAM_BACKEND_DEFLATE)
+ ops = get_backend_deflate();
+ if (IS_ERR_OR_NULL(ops))
+ goto err;
+
+ list_add(&ops->list, &backends);
+#endif
+#if IS_ENABLED(CONFIG_ZRAM_BACKEND_842)
+ ops = get_backend_842();
+ if (IS_ERR_OR_NULL(ops))
+ goto err;
+
+ list_add(&ops->list, &backends);
+#endif
+
+ return 0;
+
+err:
+ clean_zcomp_backends();
+
+ return PTR_ERR(ops);
+}
diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h
index 89d32bb13f8c..12d82acd0d39 100644
--- a/drivers/block/zram/zcomp.h
+++ b/drivers/block/zram/zcomp.h
@@ -59,7 +59,11 @@ struct zcomp_ops {
int (*setup_params)(struct zcomp_params *params);
void (*release_params)(struct zcomp_params *params);
+ void (*destroy)(struct zcomp_ops *ops);
+
const char *name;
+
+ struct list_head list;
};
/* dynamic per-device compression frontend */
@@ -86,4 +90,7 @@ int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm,
int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm,
const void *src, unsigned int src_len, void *dst);
+void clean_zcomp_backends(void);
+int init_zcomp_backends(void);
+
#endif /* _ZCOMP_H_ */
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index cee49bb0126d..29df68e0e450 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -2726,6 +2726,7 @@ static void destroy_devices(void)
idr_destroy(&zram_index_idr);
unregister_blkdev(zram_major, "zram");
cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE);
+ clean_zcomp_backends();
}
static int __init zram_init(void)
@@ -2765,6 +2766,12 @@ static int __init zram_init(void)
num_devices--;
}
+ ret = init_zcomp_backends();
+ if (ret) {
+ pr_err("Unable to create zcomp devices\n");
+ goto out_error;
+ }
+
return 0;
out_error:
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v1 3/3] zram: introduce crypto-api backend
2024-11-19 12:27 [PATCH v1 0/3] zram: introduce crypto-backend api Alexey Romanov
2024-11-19 12:27 ` [PATCH v1 1/3] zram: pass zcomp instead of zcomp_params to create_context method Alexey Romanov
2024-11-19 12:27 ` [PATCH v1 2/3] zram: store crypto backends in list instead of array Alexey Romanov
@ 2024-11-19 12:27 ` Alexey Romanov
2024-11-19 12:34 ` Christoph Hellwig
2024-11-22 14:59 ` kernel test robot
2024-11-20 3:15 ` [PATCH v1 0/3] zram: introduce crypto-backend api Sergey Senozhatsky
3 siblings, 2 replies; 11+ messages in thread
From: Alexey Romanov @ 2024-11-19 12:27 UTC (permalink / raw)
To: minchan, senozhatsky, axboe, terrelln
Cc: linux-kernel, linux-block, kernel, Alexey Romanov
Since we use custom backend implementation, we remove the ability
for users to use algorithms from crypto backend. This breaks
backward compatibility, user doesn't necessarily use one of the
algorithms from "custom" backends defined in zram folder.
For example, he can use some driver with hardware compression support.
This patch adds opinion to enable Crypto API: add ZRAM_BACKEND_CRYPTO_API.
Option is enabled by default, because in previously version of ZRAM
it was possible to choose any alogirthm using Crypto API. This is
also done for backward compatibility purposes.
Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
---
drivers/block/zram/Kconfig | 10 ++
drivers/block/zram/Makefile | 1 +
drivers/block/zram/backend_crypto_api.c | 117 ++++++++++++++++++++++++
drivers/block/zram/backend_crypto_api.h | 10 ++
drivers/block/zram/zcomp.c | 73 +++++++++++++--
5 files changed, 203 insertions(+), 8 deletions(-)
create mode 100644 drivers/block/zram/backend_crypto_api.c
create mode 100644 drivers/block/zram/backend_crypto_api.h
diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig
index 6aea609b795c..672578040912 100644
--- a/drivers/block/zram/Kconfig
+++ b/drivers/block/zram/Kconfig
@@ -57,6 +57,16 @@ config ZRAM_BACKEND_LZO
select LZO_COMPRESS
select LZO_DECOMPRESS
+config ZRAM_BACKEND_CRYPTO_API
+ bool "Enable support for compression algorithms available in Crypto API"
+ depends on ZRAM
+ default y
+ select CRYPTO
+ help
+ If you still want to use Crypto API as a backend, enable this option.
+ All compression algorithms enabled on your system will be available in ZRAM.
+ This option is useful if you are using hardware compression using any driver.
+
choice
prompt "Default zram compressor"
default ZRAM_DEF_COMP_LZORLE
diff --git a/drivers/block/zram/Makefile b/drivers/block/zram/Makefile
index 0fdefd576691..d12d03a01f35 100644
--- a/drivers/block/zram/Makefile
+++ b/drivers/block/zram/Makefile
@@ -8,5 +8,6 @@ zram-$(CONFIG_ZRAM_BACKEND_LZ4HC) += backend_lz4hc.o
zram-$(CONFIG_ZRAM_BACKEND_ZSTD) += backend_zstd.o
zram-$(CONFIG_ZRAM_BACKEND_DEFLATE) += backend_deflate.o
zram-$(CONFIG_ZRAM_BACKEND_842) += backend_842.o
+zram-$(CONFIG_ZRAM_BACKEND_CRYPTO_API) += backend_crypto_api.o
obj-$(CONFIG_ZRAM) += zram.o
diff --git a/drivers/block/zram/backend_crypto_api.c b/drivers/block/zram/backend_crypto_api.c
new file mode 100644
index 000000000000..1cd792b77aac
--- /dev/null
+++ b/drivers/block/zram/backend_crypto_api.c
@@ -0,0 +1,117 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/crypto.h>
+
+#include "backend_crypto_api.h"
+
+struct crypto_api_ctx {
+ struct crypto_comp *tfm;
+};
+
+extern struct list_head crypto_alg_list;
+
+static void crypto_api_release_params(struct zcomp_params *params)
+{
+}
+
+static int crypto_api_setup_params(struct zcomp_params *params)
+{
+ return 0;
+}
+
+static int crypto_api_create(struct zcomp *zcomp, struct zcomp_ctx *ctx)
+{
+ struct crypto_api_ctx *crypto_ctx;
+ const char *algname = zcomp->ops->name;
+
+ crypto_ctx = kzalloc(sizeof(*crypto_ctx), GFP_KERNEL);
+ if (!crypto_ctx)
+ return -ENOMEM;
+
+ crypto_ctx->tfm = crypto_alloc_comp(algname, 0, 0);
+ if (IS_ERR_OR_NULL(crypto_ctx->tfm)) {
+ kfree(crypto_ctx);
+ return -ENOMEM;
+ }
+
+ ctx->context = crypto_ctx;
+
+ return 0;
+}
+
+static void crypto_api_destroy(struct zcomp_ctx *ctx)
+{
+ struct crypto_api_ctx *crypto_ctx = ctx->context;
+
+ if (!IS_ERR_OR_NULL(crypto_ctx->tfm))
+ crypto_free_comp(crypto_ctx->tfm);
+
+ kfree(crypto_ctx);
+}
+
+static int crypto_api_compress(struct zcomp_params *params, struct zcomp_ctx *ctx,
+ struct zcomp_req *req)
+{
+ struct crypto_api_ctx *crypto_ctx = ctx->context;
+ unsigned int dst_len = req->dst_len;
+ int ret;
+
+ ret = crypto_comp_compress(crypto_ctx->tfm,
+ req->src, req->src_len,
+ req->dst, &dst_len);
+
+ req->dst_len = dst_len;
+
+ return ret;
+}
+
+static int crypto_api_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx,
+ struct zcomp_req *req)
+{
+ struct crypto_api_ctx *crypto_ctx = ctx->context;
+ unsigned int dst_len = req->dst_len;
+ int ret;
+
+ ret = crypto_comp_decompress(crypto_ctx->tfm,
+ req->src, req->src_len,
+ req->dst, &dst_len);
+
+ req->dst_len = dst_len;
+
+ return ret;
+}
+
+static void crypto_api_destroy_ops(struct zcomp_ops *ops)
+{
+ kfree(ops->name);
+ kfree(ops);
+}
+
+struct zcomp_ops *get_backend_crypto_api(const char *name)
+{
+ struct zcomp_ops *ops;
+ char *algname;
+
+ ops = kmalloc(sizeof(*ops), GFP_KERNEL);
+ if (!ops)
+ return ERR_PTR(-ENOMEM);
+
+ algname = kstrdup(name, GFP_KERNEL);
+ if (!algname) {
+ kfree(ops);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ ops->compress = crypto_api_compress;
+ ops->decompress = crypto_api_decompress,
+ ops->create_ctx = crypto_api_create,
+ ops->destroy_ctx = crypto_api_destroy,
+ ops->setup_params = crypto_api_setup_params,
+ ops->release_params = crypto_api_release_params,
+ ops->destroy = crypto_api_destroy_ops,
+ ops->name = algname;
+
+ return ops;
+}
diff --git a/drivers/block/zram/backend_crypto_api.h b/drivers/block/zram/backend_crypto_api.h
new file mode 100644
index 000000000000..5ff8f75efdb4
--- /dev/null
+++ b/drivers/block/zram/backend_crypto_api.h
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#ifndef __BACKEND_CRYPTO_API_H__
+#define __BACKEND_CRYPTO_API_H__
+
+#include "zcomp.h"
+
+struct zcomp_ops *get_backend_crypto_api(const char *name);
+
+#endif /* __BACKEND_CRYPTO_API_H__ */
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index 40b5ab4c598b..da4b370c31c1 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -20,6 +20,9 @@
#include "backend_zstd.h"
#include "backend_deflate.h"
#include "backend_842.h"
+#include "backend_crypto_api.h"
+
+extern struct list_head crypto_alg_list;
static LIST_HEAD(backends);
@@ -216,63 +219,117 @@ void clean_zcomp_backends(void)
backend->destroy(backend);
}
+static bool backend_enabled(const char *name)
+{
+ struct zcomp_ops *backend;
+
+ list_for_each_entry(backend, &backends, list)
+ if (!strcmp(backend->name, name))
+ return true;
+
+ return false;
+}
+
+static int init_crypto_api_backends(void)
+{
+ struct crypto_alg *alg;
+ struct zcomp_ops *ops;
+
+ list_for_each_entry(alg, &crypto_alg_list, cra_list) {
+ if (!crypto_has_comp(alg->cra_name, 0, 0))
+ continue;
+
+ if (backend_enabled(alg->cra_name))
+ continue;
+
+ ops = get_backend_crypto_api(alg->cra_name);
+ if (IS_ERR_OR_NULL(ops))
+ return PTR_ERR(ops);
+
+ list_add(&ops->list, &backends);
+ }
+
+ return 0;
+}
+
int init_zcomp_backends(void)
{
struct zcomp_ops *ops;
+ int ret;
#if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZO)
ops = get_backend_lzorle();
- if (IS_ERR_OR_NULL(ops))
+ if (IS_ERR_OR_NULL(ops)) {
+ ret = PTR_ERR(ops);
goto err;
+ }
list_add(&ops->list, &backends);
ops = get_backend_lzo();
- if (IS_ERR_OR_NULL(ops))
+ if (IS_ERR_OR_NULL(ops)) {
+ ret = PTR_ERR(ops);
goto err;
+ }
list_add(&ops->list, &backends);
#endif
#if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZ4)
ops = get_backend_lz4();
- if (IS_ERR_OR_NULL(ops))
+ if (IS_ERR_OR_NULL(ops)) {
+ ret = PTR_ERR(ops);
goto err;
+ }
list_add(&ops->list, &backends);
#endif
#if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZ4HC)
ops = get_backend_lz4hc();
- if (IS_ERR_OR_NULL(ops))
+ if (IS_ERR_OR_NULL(ops)) {
+ ret = PTR_ERR(ops);
goto err;
+ }
list_add(&ops->list, &backends);
#endif
#if IS_ENABLED(CONFIG_ZRAM_BACKEND_ZSTD)
ops = get_backend_zstd();
- if (IS_ERR_OR_NULL(ops))
+ if (IS_ERR_OR_NULL(ops)) {
+ ret = PTR_ERR(ops);
goto err;
+ }
list_add(&ops->list, &backends);
#endif
#if IS_ENABLED(CONFIG_ZRAM_BACKEND_DEFLATE)
ops = get_backend_deflate();
- if (IS_ERR_OR_NULL(ops))
+ if (IS_ERR_OR_NULL(ops)) {
+ ret = PTR_ERR(ops);
goto err;
+ }
list_add(&ops->list, &backends);
#endif
#if IS_ENABLED(CONFIG_ZRAM_BACKEND_842)
ops = get_backend_842();
- if (IS_ERR_OR_NULL(ops))
+ if (IS_ERR_OR_NULL(ops)) {
+ ret = PTR_ERR(ops);
goto err;
+ }
list_add(&ops->list, &backends);
#endif
+#if IS_ENABLED(CONFIG_ZRAM_BACKEND_CRYPTO_API)
+ ret = init_crypto_api_backends();
+ if (ret)
+ goto err;
+#endif
+
return 0;
err:
clean_zcomp_backends();
- return PTR_ERR(ops);
+ return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v1 3/3] zram: introduce crypto-api backend
2024-11-19 12:27 ` [PATCH v1 3/3] zram: introduce crypto-api backend Alexey Romanov
@ 2024-11-19 12:34 ` Christoph Hellwig
2024-11-19 13:04 ` Alexey Romanov
2024-11-22 14:59 ` kernel test robot
1 sibling, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2024-11-19 12:34 UTC (permalink / raw)
To: Alexey Romanov
Cc: minchan, senozhatsky, axboe, terrelln, linux-kernel, linux-block,
kernel
On Tue, Nov 19, 2024 at 03:27:13PM +0300, Alexey Romanov wrote:
> Since we use custom backend implementation, we remove the ability
> for users to use algorithms from crypto backend. This breaks
> backward compatibility, user doesn't necessarily use one of the
> algorithms from "custom" backends defined in zram folder.
> For example, he can use some driver with hardware compression support.
>
> This patch adds opinion to enable Crypto API: add ZRAM_BACKEND_CRYPTO_API.
> Option is enabled by default, because in previously version of ZRAM
> it was possible to choose any alogirthm using Crypto API. This is
> also done for backward compatibility purposes.
Which crypto API algorithm do you care about? You should probably
just add a backend for that instead of a double indirection.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v1 3/3] zram: introduce crypto-api backend
2024-11-19 12:34 ` Christoph Hellwig
@ 2024-11-19 13:04 ` Alexey Romanov
2024-11-19 13:08 ` Christoph Hellwig
0 siblings, 1 reply; 11+ messages in thread
From: Alexey Romanov @ 2024-11-19 13:04 UTC (permalink / raw)
To: Christoph Hellwig
Cc: minchan@kernel.org, senozhatsky@chromium.org, axboe@kernel.dk,
terrelln@fb.com, linux-kernel@vger.kernel.org,
linux-block@vger.kernel.org, kernel
Hi Christoph,
On Tue, Nov 19, 2024 at 04:34:52AM -0800, Christoph Hellwig wrote:
> On Tue, Nov 19, 2024 at 03:27:13PM +0300, Alexey Romanov wrote:
> > Since we use custom backend implementation, we remove the ability
> > for users to use algorithms from crypto backend. This breaks
> > backward compatibility, user doesn't necessarily use one of the
> > algorithms from "custom" backends defined in zram folder.
> > For example, he can use some driver with hardware compression support.
> >
> > This patch adds opinion to enable Crypto API: add ZRAM_BACKEND_CRYPTO_API.
> > Option is enabled by default, because in previously version of ZRAM
> > it was possible to choose any alogirthm using Crypto API. This is
> > also done for backward compatibility purposes.
>
> Which crypto API algorithm do you care about? You should probably
> just add a backend for that instead of a double indirection.
>
Should I create backend_*.c file for every compression algo driver?
Okay, there aren't many of them now. But what will do, for example,
when there will be 250 such compression drivers?
And also your approach doesn't allow working with loadable modules.
For example, we may have only binary module (without sources) from
vendor SDK that provieds a driver for data compression.
This is an even bigger problem.
--
Thank you,
Alexey
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v1 3/3] zram: introduce crypto-api backend
2024-11-19 13:04 ` Alexey Romanov
@ 2024-11-19 13:08 ` Christoph Hellwig
0 siblings, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2024-11-19 13:08 UTC (permalink / raw)
To: Alexey Romanov
Cc: Christoph Hellwig, minchan@kernel.org, senozhatsky@chromium.org,
axboe@kernel.dk, terrelln@fb.com, linux-kernel@vger.kernel.org,
linux-block@vger.kernel.org, kernel
On Tue, Nov 19, 2024 at 01:04:44PM +0000, Alexey Romanov wrote:
> Should I create backend_*.c file for every compression algo driver?
No.
> Okay, there aren't many of them now. But what will do, for example,
> when there will be 250 such compression drivers?
Why would there?
>
> And also your approach doesn't allow working with loadable modules.
> For example, we may have only binary module (without sources) from
> vendor SDK that provieds a driver for data compression.
Well, maybe just piss off instead of sneaking in hooks for your
illegal binary modules.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v1 0/3] zram: introduce crypto-backend api
2024-11-19 12:27 [PATCH v1 0/3] zram: introduce crypto-backend api Alexey Romanov
` (2 preceding siblings ...)
2024-11-19 12:27 ` [PATCH v1 3/3] zram: introduce crypto-api backend Alexey Romanov
@ 2024-11-20 3:15 ` Sergey Senozhatsky
2024-11-21 12:11 ` Alexey Romanov
3 siblings, 1 reply; 11+ messages in thread
From: Sergey Senozhatsky @ 2024-11-20 3:15 UTC (permalink / raw)
To: Alexey Romanov
Cc: minchan, senozhatsky, axboe, terrelln, linux-kernel, linux-block,
kernel
On (24/11/19 15:27), Alexey Romanov wrote:
> Since we use custom backend implementation, we remove the ability
> for users to use algorithms from crypto backend. This breaks
> backward compatibility, user doesn't necessarily use one of the
> algorithms from "custom" backends defined in zram folder.
Sorry, no, we are not adding this for a hypothetical scenario.
> For example, he can use some driver with hardware compression support.
Such as? Pretty much all H/W compression modules (I'm aware of)
that people use with zram are out-of-tree.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v1 0/3] zram: introduce crypto-backend api
2024-11-20 3:15 ` [PATCH v1 0/3] zram: introduce crypto-backend api Sergey Senozhatsky
@ 2024-11-21 12:11 ` Alexey Romanov
2024-11-21 15:53 ` Sergey Senozhatsky
0 siblings, 1 reply; 11+ messages in thread
From: Alexey Romanov @ 2024-11-21 12:11 UTC (permalink / raw)
To: Sergey Senozhatsky
Cc: minchan@kernel.org, axboe@kernel.dk, terrelln@fb.com,
linux-kernel@vger.kernel.org, linux-block@vger.kernel.org
Hi Sergey,
On Wed, Nov 20, 2024 at 12:15:29PM +0900, Sergey Senozhatsky wrote:
> On (24/11/19 15:27), Alexey Romanov wrote:
> > Since we use custom backend implementation, we remove the ability
> > for users to use algorithms from crypto backend. This breaks
> > backward compatibility, user doesn't necessarily use one of the
> > algorithms from "custom" backends defined in zram folder.
>
> Sorry, no, we are not adding this for a hypothetical scenario.
>
> > For example, he can use some driver with hardware compression support.
>
> Such as? Pretty much all H/W compression modules (I'm aware of)
> that people use with zram are out-of-tree.
At least we have this:
drivers/crypto/nx/nx-common-powernv.c:1043: .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
drivers/crypto/nx/nx-common-pseries.c:1020: .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
drivers/crypto/cavium/zip/zip_main.c:377: .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
drivers/crypto/cavium/zip/zip_main.c:392: .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
Anyway, if we want to completely abandon Crypto API, these modules
still need to be supported in zram.
--
Thank you,
Alexey
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v1 0/3] zram: introduce crypto-backend api
2024-11-21 12:11 ` Alexey Romanov
@ 2024-11-21 15:53 ` Sergey Senozhatsky
0 siblings, 0 replies; 11+ messages in thread
From: Sergey Senozhatsky @ 2024-11-21 15:53 UTC (permalink / raw)
To: Alexey Romanov
Cc: Sergey Senozhatsky, minchan@kernel.org, axboe@kernel.dk,
terrelln@fb.com, linux-kernel@vger.kernel.org,
linux-block@vger.kernel.org
On (24/11/21 12:11), Alexey Romanov wrote:
> > Sorry, no, we are not adding this for a hypothetical scenario.
> >
> > > For example, he can use some driver with hardware compression support.
> >
> > Such as? Pretty much all H/W compression modules (I'm aware of)
> > that people use with zram are out-of-tree.
>
> At least we have this:
>
> drivers/crypto/nx/nx-common-powernv.c:1043: .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
> drivers/crypto/nx/nx-common-pseries.c:1020: .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
> drivers/crypto/cavium/zip/zip_main.c:377: .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
> drivers/crypto/cavium/zip/zip_main.c:392: .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
>
> Anyway, if we want to completely abandon Crypto API
It's more complicated than that.
> these modules still need to be supported in zram.
We support what we have always claimed we supported, namely
what is listed in drivers/block/zram/Kconfig. That's how one
enables a particular algorithm in zram - during zram configuration.
If those algos are not in zram's Kconfig after so many years,
then it's most likely because people don't use them with zram.
If we ever need backends for those H/W algos, then I really would
prefer a patch from folks that have a corresponding hardware to
run and test it on. The thing is, zram, in its current form and
shape, imposes strict requirements on comp implementation.
So we should not add algos just because they are there (especially
H/W algos) that's how we added 842, lz4hc many years ago and now
have to carry them around. We are not doing that again.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v1 3/3] zram: introduce crypto-api backend
2024-11-19 12:27 ` [PATCH v1 3/3] zram: introduce crypto-api backend Alexey Romanov
2024-11-19 12:34 ` Christoph Hellwig
@ 2024-11-22 14:59 ` kernel test robot
1 sibling, 0 replies; 11+ messages in thread
From: kernel test robot @ 2024-11-22 14:59 UTC (permalink / raw)
To: Alexey Romanov, minchan, senozhatsky, axboe, terrelln
Cc: oe-kbuild-all, linux-kernel, linux-block, kernel, Alexey Romanov
Hi Alexey,
kernel test robot noticed the following build warnings:
[auto build test WARNING on axboe-block/for-next]
[also build test WARNING on linus/master v6.12 next-20241122]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Alexey-Romanov/zram-pass-zcomp-instead-of-zcomp_params-to-create_context-method/20241121-135511
base: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
patch link: https://lore.kernel.org/r/20241119122713.3294173-4-avromanov%40salutedevices.com
patch subject: [PATCH v1 3/3] zram: introduce crypto-api backend
config: x86_64-randconfig-012-20241122 (https://download.01.org/0day-ci/archive/20241122/202411222217.SkVD8y1f-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241122/202411222217.SkVD8y1f-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411222217.SkVD8y1f-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> drivers/block/zram/zcomp.c:233:12: warning: 'init_crypto_api_backends' defined but not used [-Wunused-function]
233 | static int init_crypto_api_backends(void)
| ^~~~~~~~~~~~~~~~~~~~~~~~
vim +/init_crypto_api_backends +233 drivers/block/zram/zcomp.c
232
> 233 static int init_crypto_api_backends(void)
234 {
235 struct crypto_alg *alg;
236 struct zcomp_ops *ops;
237
238 list_for_each_entry(alg, &crypto_alg_list, cra_list) {
239 if (!crypto_has_comp(alg->cra_name, 0, 0))
240 continue;
241
242 if (backend_enabled(alg->cra_name))
243 continue;
244
245 ops = get_backend_crypto_api(alg->cra_name);
246 if (IS_ERR_OR_NULL(ops))
247 return PTR_ERR(ops);
248
249 list_add(&ops->list, &backends);
250 }
251
252 return 0;
253 }
254
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-11-22 14:59 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-19 12:27 [PATCH v1 0/3] zram: introduce crypto-backend api Alexey Romanov
2024-11-19 12:27 ` [PATCH v1 1/3] zram: pass zcomp instead of zcomp_params to create_context method Alexey Romanov
2024-11-19 12:27 ` [PATCH v1 2/3] zram: store crypto backends in list instead of array Alexey Romanov
2024-11-19 12:27 ` [PATCH v1 3/3] zram: introduce crypto-api backend Alexey Romanov
2024-11-19 12:34 ` Christoph Hellwig
2024-11-19 13:04 ` Alexey Romanov
2024-11-19 13:08 ` Christoph Hellwig
2024-11-22 14:59 ` kernel test robot
2024-11-20 3:15 ` [PATCH v1 0/3] zram: introduce crypto-backend api Sergey Senozhatsky
2024-11-21 12:11 ` Alexey Romanov
2024-11-21 15:53 ` Sergey Senozhatsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).