crypto: Add new compression modes for zlib and IAA
Subsystems (6)
cover crypto: Add new compression modes for zlib and IAA
This patch series adds 'canned' compression for Intel IAA and zlib. It also adds 'dynamic' compression for Intel IAA which is compatible with zlib deflate algorithms.
The original IAA crypto submissions [1] included a 'canned' compression mode, but support for 'canned' compression was removed during the review because it didn't have an equivalent software implementation available [2].
Deflate compression can be done in a variety of modes. The dynamic mode uses Huffman tables that are generated/optimized for that particular input. This gives the best compression ratio but has the longest latency. The fixed mode uses Huffman tables that are defined by the Deflate standard. It generally gives the best latency but with a lower compression ratio. The 'canned' compression mode implements a compression scheme that uses a statically defined set of Huffman tables, but where the Deflate Block Header is implied rather than stored with the compressed data.
The 'canned' mode results in lower compression/decompression latencies compared to using the dynamic mode, but it results in a better compression ratio than using the fixed mode.
Below is a table showing the latency improvements with zlib, between zlib dynamic and zlib canned modes, and the compression ratio for each mode while using a set of 4300 4KB pages sampled from SPEC CPU17 workloads:
_________________________________________________________
| Zlib Level | Canned Latency Gain | Comp Ratio | |------------|-----------------------|------------------| | | compress | decompress | dynamic | canned | |____________|__________|____________|_________|________| | 1 | 49% | 29% | 3.16 | 2.92 | |------------|----------|------------|---------|--------| | 6 | 27% | 28% | 3.35 | 3.09 | |------------|----------|------------|---------|--------| | 9 | 12% | 29% | 3.36 | 3.11 | |____________|__________|____________|_________|________|
Using the same data set as for the above table, IAA fixed-mode compression results in a compression ratio of 2.69. Using IAA canned-mode compression results in a ratio of 2.88, which is a 7% improvement. This data shows that the canned mode results in better latencies than the dynamic mode, but a better ratio than the fixed mode. Thus, the canned mode would be preferred when compression and decompression latencies are valued more than the compression ratio.
'Dynamic' mode IAA compression is a HW accelerated dynamic Deflate that is fully compatible with software decompress implementations, including zlib. 'Dynamic' IAA compression allows users to perform hardware-accelerated compression that achieves a higher compression ratio than both 'canned' and 'fixed' compression modes. Thus, Dynamic IAA compression should be used when the goal is to produce the best compression ratio while minimizing latencies by using IAA hardware acceleration. IAA decompression is fully compatible with software compress implementations, when the uncompressed size is no more than 4KB.
Below is a table showing the compression ratio seen when compressing a data set of 4300 4KB pages sampled from SPEC CPU17 workloads via various IAA compression modes:
|---------------------------------------| | Intel IAA | |---------------------------------------| | compression mode | compression ratio | |---------------------------------------| | fixed | 2.69 | |---------------------------------------| | canned | 2.88 | |---------------------------------------| | dynamic | 3.14 | |---------------------------------------|
Patch 1/4 adds a software implementation of “canned’ mode to the existing zlib software library and exposes it as “deflate-canned”. This was done instead of creating a new canned-mode library to avoid a lot of code duplication. Testing shows that this change has no performance impact to the existing zlib algorithms.
Patch 2/4 adds IAA 'canned' support which is based on the original implementation [1] and will be exposed as 'deflate-iaa-canned'
Patch 3/4 adds 'dynamic' mode IAA compression support and will be exposed as 'deflate-iaa-dynamic'.
Patch 4/4 adds software compression stats to the optional debugfs statistics support for IAA.
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/ZIw%[email protected]/
Andre Glover (4):
crypto: Add 'canned' compression mode for zlib
crypto: iaa - Add deflate-canned compression algorithm
crypto: iaa - Add deflate-iaa-dynamic compression algorithm
crypto: iaa - Add Software Compression stats to IAA Compression
Accelerator stats
.../driver-api/crypto/iaa/iaa-crypto.rst | 36 +- crypto/deflate.c | 72 +++- crypto/testmgr.c | 30 ++ crypto/testmgr.h | 220 +++++++++++ drivers/crypto/intel/iaa/Kconfig | 1 + drivers/crypto/intel/iaa/Makefile | 2 +- drivers/crypto/intel/iaa/iaa_crypto.h | 44 ++- .../crypto/intel/iaa/iaa_crypto_comp_canned.c | 116 ++++++ .../intel/iaa/iaa_crypto_comp_dynamic.c | 22 ++ .../crypto/intel/iaa/iaa_crypto_comp_fixed.c | 1 + drivers/crypto/intel/iaa/iaa_crypto_main.c | 361 ++++++++++++++++-- drivers/crypto/intel/iaa/iaa_crypto_stats.c | 8 + drivers/crypto/intel/iaa/iaa_crypto_stats.h | 2 + include/linux/zlib.h | 10 + lib/Kconfig | 9 + lib/zlib_deflate/defcanned.h | 118 ++++++ lib/zlib_deflate/deflate.c | 8 +- lib/zlib_deflate/deftree.c | 15 +- lib/zlib_inflate/infcanned.h | 191 +++++++++ lib/zlib_inflate/inflate.c | 15 +- lib/zlib_inflate/inflate.h | 5 +- lib/zlib_inflate/infutil.h | 16 + 22 files changed, 1255 insertions(+), 47 deletions(-) create mode 100644 drivers/crypto/intel/iaa/iaa_crypto_comp_canned.c create mode 100644 drivers/crypto/intel/iaa/iaa_crypto_comp_dynamic.c create mode 100644 lib/zlib_deflate/defcanned.h create mode 100644 lib/zlib_inflate/infcanned.h
Signature · 1 line
2.27.0
PATCH 1/4 crypto: Add 'canned' compression mode for zlib
The 'canned' compression mode implements a compression scheme that uses statically defined Huffman tables. Since the Deflate block header is a constant, it is not stored with the compressed data. The Huffman tables used were generated from statistics derived from swapped 4KB pages of SPEC CPU17 workloads. We believe that these tables should be generally applicable to page compression.
Canned mode provides lower compression and decompression latencies than dynamic compression with slightly lower compression ratio.
Below is a table showing the latency improvements of zlib, between dynamic and canned modes, and the compression ratio for each mode while using a set of 4300 4KB pages sampled from SPEC CPU17 workloads:
_________________________________________________________
| Zlib Level | Canned Latency Gain | Comp Ratio | |------------|-----------------------|------------------| | | compress | decompress | dynamic | canned | |____________|__________|____________|_________|________| | 1 | 49% | 29% | 3.16 | 2.92 | |------------|----------|------------|---------|--------| | 6 | 27% | 28% | 3.35 | 3.09 | |------------|----------|------------|---------|--------| | 9 | 12% | 29% | 3.36 | 3.11 | |____________|__________|____________|_________|________|
Canned mode is exposed by the 'deflate-canned' crypto algorithm in the zlib crypto driver. The set of static canned-mode deflate and inflate tables were generated and are used in the same manner as the pre-existing zlib fixed tables. We have insured that the 'canned' mode additions do not impact existing zlib performance or functionality.
--- crypto/deflate.c | 72 +++++++++++-- crypto/testmgr.c | 10 ++ crypto/testmgr.h | 74 ++++++++++++++ include/linux/zlib.h | 10 ++ lib/Kconfig | 9 ++ lib/zlib_deflate/defcanned.h | 118 ++++++++++++++++++++++ lib/zlib_deflate/deflate.c | 8 +- lib/zlib_deflate/deftree.c | 15 ++- lib/zlib_inflate/infcanned.h | 191 +++++++++++++++++++++++++++++++++++ lib/zlib_inflate/inflate.c | 15 ++- lib/zlib_inflate/inflate.h | 5 +- lib/zlib_inflate/infutil.h | 16 +++ 12 files changed, 529 insertions(+), 14 deletions(-) create mode 100644 lib/zlib_deflate/defcanned.h create mode 100644 lib/zlib_inflate/infcanned.h
crypto/deflate.c +64 -8
@@ -37,6 +37,7 @@struct deflate_ctx {struct z_stream_s comp_stream;struct z_stream_s decomp_stream; +bool canned; };static int deflate_comp_init (struct deflate_ctx *ctx)
@@ -50,9 +51,16 @@ static int deflate_comp_init(struct deflate_ctx *ctx) ret = -ENOMEM ; goto out; } - ret =zlib_deflateInit2 (stream,DEFLATE_DEF_LEVEL ,Z_DEFLATED , - -DEFLATE_DEF_WINBITS ,DEFLATE_DEF_MEMLEVEL , -Z_DEFAULT_STRATEGY ); + +if (IS_ENABLED (CONFIG_ZLIB_CANNED ) && ctx->canned) + ret =zlib_deflateInit2 (stream,DEFLATE_DEF_LEVEL ,Z_DEFLATED , +DEFLATE_DEF_CANNED_WINBITS , +DEFLATE_DEF_MEMLEVEL , +Z_CANNED ); +else + ret =zlib_deflateInit2 (stream,DEFLATE_DEF_LEVEL ,Z_DEFLATED , + -DEFLATE_DEF_WINBITS ,DEFLATE_DEF_MEMLEVEL , +Z_DEFAULT_STRATEGY );if (ret !=Z_OK ) { ret = -EINVAL ; goto out_free;
@@ -74,7 +82,16 @@ static int deflate_decomp_init(struct deflate_ctx *ctx) ret = -ENOMEM ; goto out; } - ret =zlib_inflateInit2 (stream, -DEFLATE_DEF_WINBITS ); + +/* +* The wrap is embedded in bits 31:4 of the windowBits argument and is incremented +* by 1 during extraction. +*/ +if (IS_ENABLED (CONFIG_ZLIB_CANNED ) && ctx->canned) + ret =zlib_inflateInit2 (stream, (((ZLIB_CANNED_WRAP -1 ) <<4 ) | + (DEFLATE_DEF_CANNED_WINBITS ))); +else + ret =zlib_inflateInit2 (stream, -DEFLATE_DEF_WINBITS );if (ret !=Z_OK ) { ret = -EINVAL ; goto out_free;
@@ -130,6 +147,25 @@ static void *deflate_alloc_ctx(struct crypto_scomp *tfm)return ctx; } +static __maybe_unused void *deflate_canned_alloc_ctx (struct crypto_scomp *tfm) +{ +struct deflate_ctx *ctx; +int ret; + + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) +return ERR_PTR (-ENOMEM ); + + ctx->canned = true; + ret =__deflate_init (ctx); +if (ret) { +kfree (ctx); +return ERR_PTR (ret); + } + +return ctx; +} +static int deflate_init (struct crypto_tfm *tfm) {struct deflate_ctx *ctx =crypto_tfm_ctx (tfm);
@@ -219,6 +255,11 @@ static int __deflate_decompress(const u8 *src, unsigned int slen, stream->next_out = (u8 *)dst; stream->avail_out = *dlen; +if (IS_ENABLED (CONFIG_ZLIB_CANNED ) && dctx->canned) { + ret =zlib_inflate (stream,Z_FINISH ); + goto inflate_done; + } + ret =zlib_inflate (stream,Z_SYNC_FLUSH );/* * Work around a bug in zlib, which sometimes wants to taste an extra
@@ -231,6 +272,8 @@ static int __deflate_decompress(const u8 *src, unsigned int slen, stream->avail_in =1 ; ret =zlib_inflate (stream,Z_FINISH ); } + +inflate_done:if (ret !=Z_STREAM_END ) { ret = -EINVAL ; goto out;
@@ -269,7 +312,8 @@ static struct crypto_alg alg = { .coa_decompress = deflate_decompress } } }; -static struct scomp_alg scomp = { +static struct scomp_alg scomp[] = { +{ .alloc_ctx = deflate_alloc_ctx, .free_ctx = deflate_free_ctx, .compress = deflate_scompress,
@@ -279,7 +323,19 @@ static struct scomp_alg scomp = { .cra_driver_name = "deflate-scomp", .cra_module = THIS_MODULE, } -}; +#ifdef CONFIG_ZLIB_CANNED +}, { + .alloc_ctx = deflate_canned_alloc_ctx, + .free_ctx = deflate_free_ctx, + .compress = deflate_scompress, + .decompress = deflate_sdecompress, + .base = { + .cra_name = "deflate-canned", + .cra_driver_name = "deflate-scomp-canned", + .cra_module = THIS_MODULE, + } +#endif +} };static int __init deflate_mod_init (void ) {
@@ -289,7 +345,7 @@ static int __init deflate_mod_init(void)if (ret)return ret; - ret =crypto_register_scomp (&scomp); + ret =crypto_register_scomps (scomp,ARRAY_SIZE (scomp));if (ret) {crypto_unregister_alg (&alg);return ret;
@@ -301,7 +357,7 @@ static int __init deflate_mod_init(void) static void __exit deflate_mod_fini(void) {crypto_unregister_alg (&alg); -crypto_unregister_scomp (&scomp); +crypto_unregister_scomps (scomp,ARRAY_SIZE (scomp)); }subsys_initcall (deflate_mod_init);
crypto/testmgr.c +10 -0
@@ -4806,6 +4806,16 @@ static const struct alg_test_desc alg_test_descs[] = { .decomp = __VECS(deflate_decomp_tv_template) } } + }, { + .alg = "deflate-scomp-canned", + .test = alg_test_comp, + .fips_allowed = 1, + .suite = { + .comp = { + .comp = __VECS(deflate_scomp_canned_comp_tv_template), + .decomp = __VECS(deflate_scomp_canned_decomp_tv_template) + } + } }, { .alg = "dh", .test = alg_test_kpp,
crypto/testmgr.h +74 -0
80 lines not on this page · raw message
include/linux/zlib.h +10 -0
@@ -166,7 +166,14 @@ typedef z_stream *z_streamp;#define Z_FILTERED 1#define Z_HUFFMAN_ONLY 2 +#define Z_CANNED 3#define Z_DEFAULT_STRATEGY 0 + +#ifdef CONFIG_ZLIB_CANNED +#define Z_STRATEGY_MAX Z_CANNED +#else +#define Z_STRATEGY_MAX Z_HUFFMAN_ONLY +#endif /* compression strategy; see deflateInit2() below for details */ #define Z_BINARY 0
@@ -177,6 +184,9 @@ typedef z_stream *z_streamp;#define Z_DEFLATED 8/* The deflate compression method (the only one supported in this version) */ +#define DEFLATE_DEF_CANNED_WINBITS 12 +#define ZLIB_CANNED_WRAP 4 +/* basic functions */ extern int zlib_deflate_workspacesize (int windowBits,int memLevel);
lib/Kconfig +9 -0
@@ -320,6 +320,15 @@ config ZLIB_DEFLATE tristate select BITREVERSE +config ZLIB_CANNED + bool + depends on ZLIB_INFLATE && ZLIB_DEFLATE + prompt "Enable canned compression mode support for kernel zlib" + help + Enable canned compression mode support for zlib in the kernel. + The 'canned' compression mode implements a compression scheme that + uses statically defined Huffman tables. + config ZLIB_DFLTCC def_bool y depends on S390
lib/zlib_deflate/defcanned.h new file +118 -0
118 lines not on this page · raw message
lib/zlib_deflate/deflate.c +7 -1
@@ -218,10 +218,16 @@ int zlib_deflateInit2( }if (memLevel <1 || memLevel >MAX_MEM_LEVEL || method !=Z_DEFLATED || windowBits <9 || windowBits >15 || level <0 || level >9 || - strategy <0 || strategy >Z_HUFFMAN_ONLY ) { + strategy <0 || strategy >Z_STRATEGY_MAX ) {return Z_STREAM_ERROR ; } +if (IS_ENABLED (CONFIG_ZLIB_CANNED ) && strategy ==Z_CANNED ) { +if (windowBits >DEFLATE_DEF_CANNED_WINBITS ) +return Z_STREAM_ERROR ; + noheader =1 ;/* suppress zlib header for canned compression */ + } +/* * Direct the workspace's pointers to the chunks that were allocated * along with the deflate_workspace struct.
lib/zlib_deflate/deftree.c +12 -3
@@ -124,6 +124,13 @@ static static_tree_desc static_d_desc =static static_tree_desc static_bl_desc = {(const ct_data *)0 , extra_blbits,0 ,BL_CODES ,MAX_BL_BITS }; +#ifdef CONFIG_ZLIB_CANNED +#include "defcanned.h" +#else +#define canned_ltree NULL +#define canned_dtree NULL +#endif +/* =========================================================================== * Local (static) routines in this file. */
@@ -810,7 +817,7 @@ ulg zlib_tr_flush_block(int max_blindex =0 ;/* index of last bit length code of non zero freq */ /* Build the Huffman trees unless a stored block is forced */ -if (s->level >0 ) { +if (s->level >0 && !(IS_ENABLED (CONFIG_ZLIB_CANNED ) && s->strategy ==Z_CANNED )) {/* Check if the file is ascii or binary */ if (s->data_type ==Z_UNKNOWN )set_data_type (s);
@@ -866,10 +873,12 @@ ulg zlib_tr_flush_block( } else#endif /* STORED_FILE_OK */ +if (IS_ENABLED (CONFIG_ZLIB_CANNED ) && s->strategy ==Z_CANNED ) { +compress_block (s, (ct_data *)canned_ltree, (ct_data *)canned_dtree); #ifdef FORCE_STORED -if (buf != (char *)0 ) {/* force stored block */ + }else if (buf != (char *)0 ) {/* force stored block */ #else -if (stored_len+4 <= opt_lenb && buf != (char *)0 ) { + }else if (stored_len +4 <= opt_lenb && buf != (char *)0 ) {/* 4: two words for the lengths */ #endif /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
lib/zlib_inflate/infcanned.h new file +191 -0
191 lines not on this page · raw message
lib/zlib_inflate/inflate.c +14 -1
@@ -72,6 +72,11 @@ int zlib_inflateInit2(z_streamp strm, int windowBits) }else { state->wrap = (windowBits >>4 ) +1 ; +if (IS_ENABLED (CONFIG_ZLIB_CANNED ) && state->wrap ==ZLIB_CANNED_WRAP ) { + windowBits &=15 ; +if (windowBits >DEFLATE_DEF_CANNED_WINBITS ) +return Z_STREAM_ERROR ; + } }if (windowBits <8 || windowBits >15 ) {return Z_STREAM_ERROR ;
@@ -363,6 +368,13 @@ int zlib_inflate(z_streamp strm, int flush)for (;;)switch (state->mode) {case HEAD : +if (IS_ENABLED (CONFIG_ZLIB_CANNED ) && state->wrap ==ZLIB_CANNED_WRAP ) { +zlib_cannedtables (state); + state->mode =LEN ; + state->last =1 ; +PULLBYTE (); +break ; + }if (state->wrap ==0 ) { state->mode =TYPEDO ;break ;
@@ -702,7 +714,8 @@ int zlib_inflate(z_streamp strm, int flush) state->mode =LEN ;break ;case CHECK : -if (state->wrap) { +if (state->wrap && !(IS_ENABLED (CONFIG_ZLIB_CANNED ) && + state->wrap ==ZLIB_CANNED_WRAP )) {NEEDBITS (32 ); out -= left; strm->total_out += out;
lib/zlib_inflate/inflate.h +4 -1
@@ -74,7 +74,10 @@ typedef enum {struct inflate_state {inflate_mode mode;/* current inflate mode */ int last;/* true if processing last block */ -int wrap;/* bit 0 true for zlib, bit 1 true for gzip */ +int wrap;/* +* bit 0 true for zlib, bit 1 true for gzip, +* bit 2 true for canned mode +*/ int havedict;/* true if dictionary provided */ int flags;/* gzip header method and flags (0 if zlib) */ unsigned dmax;/* zlib header max distance (INFLATE_STRICT) */
lib/zlib_inflate/infutil.h +16 -0
@@ -36,4 +36,20 @@ static_assert(offsetof(struct inflate_workspace, dfltcc_state) % 8 == 0);#define WS (strm) ((struct inflate_workspace *)(strm->workspace)) +/* +* Return state with length and distance decoding tables and index sizes set to +* canned code decoding. This returns canned tables from infcanned.h if +* CONFIG_ZLIB_CANNED is set, otherwise it will get removed during +* compliation. +*/ +static inline void zlib_cannedtables (struct inflate_state *state) +{ +#ifdef CONFIG_ZLIB_CANNED +#include "infcanned.h" + state->lencode = lencan; + state->lenbits =9 ; + state->distcode = distcan; + state->distbits =9 ; +#endif +}#endif
Signature · 1 line
2.27.0
PATCH 2/4 crypto: iaa - Add deflate-canned compression algorithm
In reply to Andre GloverThe 'canned' compression mode implements a compression scheme that uses statically-defined customized Huffman tables. Since the Deflate block header is a constant, it is not stored with the compressed data. The Huffman tables used were generated from statistics derived from swapped 4KB pages of SPEC CPU17 workloads. Canned mode provides better compression than using the Deflate standard's (RFC-1951) "fixed" tables and better latencies than dynamic compression.
Compressing a data set of 4300 4KB pages sampled from SPEC CPU17 workloads produces a compression ratio of 2.88 for IAA canned compression and 2.69 for IAA fixed compression, which is a 7% improvement.
Either 'fixed' or 'canned' modes can be chosen as the mode to be used by crypto facilities by selecting the corresponding algorithm. For example, to use IAA fixed mode in zswap:
echo deflate-iaa > /sys/module/zswap/parameters/compressor
To choose 'canned' mode:
echo deflate-iaa-canned > /sys/module/zswap/parameters/compressor
[ Based on work originally by George Powley, Jing Lin and Kyung Min Park ]
--- .../driver-api/crypto/iaa/iaa-crypto.rst | 15 +- crypto/testmgr.c | 10 + crypto/testmgr.h | 72 +++++ drivers/crypto/intel/iaa/Kconfig | 1 + drivers/crypto/intel/iaa/Makefile | 2 +- drivers/crypto/intel/iaa/iaa_crypto.h | 38 +++ .../crypto/intel/iaa/iaa_crypto_comp_canned.c | 116 ++++++++ .../crypto/intel/iaa/iaa_crypto_comp_fixed.c | 1 + drivers/crypto/intel/iaa/iaa_crypto_main.c | 271 ++++++++++++++++-- 9 files changed, 500 insertions(+), 26 deletions(-) create mode 100644 drivers/crypto/intel/iaa/iaa_crypto_comp_canned.c
Documentation/driver-api/crypto/iaa/iaa-crypto.rst +13 -2
@@ -30,8 +30,8 @@ algorithm:: This will tell zswap to use the IAA 'fixed' compression mode for all compresses and decompresses. -Currently, there is only one compression modes available, 'fixed' -mode. +Currently, two compression modes are available to all IAA hardware, +'canned' and 'fixed' modes. The 'fixed' compression mode implements the compression scheme specified by RFC 1951 and is given the crypto algorithm name
@@ -42,6 +42,17 @@ which allows for a window of up to 32k. Because of this limitation, the IAA fixed mode deflate algorithm is given its own algorithm name rather than simply 'deflate'). +The 'canned' compression mode implements a good general-purpose +compression scheme whose tables were generated from statistics derived +from a wide variety of SPEC17 workloads. It provides much better +overall characteristics than the existing deflate-1951 tables +implemented by 'fixed'. 'Canned' mode is implemented by the +'deflate-iaa-canned' crypto algorithm.:: + +A zswap device can select the IAA 'canned' mode represented by +selecting the 'deflate-iaa-canned' crypto compression algorithm:: + + # echo deflate-iaa-canned > /sys/module/zswap/parameters/compressor Config options and other setup ==============================
crypto/testmgr.c +10 -0
@@ -4806,6 +4806,16 @@ static const struct alg_test_desc alg_test_descs[] = { .decomp = __VECS(deflate_decomp_tv_template) } } + }, { + .alg = "deflate-iaa-canned", + .test = alg_test_comp, + .fips_allowed = 1, + .suite = { + .comp = { + .comp = __VECS(deflate_iaa_canned_comp_tv_template), + .decomp = __VECS(deflate_iaa_canned_decomp_tv_template) + } + } }, { .alg = "deflate-scomp-canned", .test = alg_test_comp,
crypto/testmgr.h +72 -0
78 lines not on this page · raw message
drivers/crypto/intel/iaa/Kconfig +1 -0
@@ -2,6 +2,7 @@ config CRYPTO_DEV_IAA_CRYPTO tristate "Support for Intel(R) IAA Compression Accelerator" depends on CRYPTO_DEFLATE depends on INTEL_IDXD + select ZLIB_CANNED default n help This driver supports acceleration for compression and
drivers/crypto/intel/iaa/Makefile +1 -1
@@ -7,6 +7,6 @@ ccflags-y += -I $(srctree)/drivers/dma/idxd -DDEFAULT_SYMBOL_NAMESPACE=IDXD obj-$(CONFIG_CRYPTO_DEV_IAA_CRYPTO) := iaa_crypto.o -iaa_crypto-y := iaa_crypto_main.o iaa_crypto_comp_fixed.o +iaa_crypto-y := iaa_crypto_main.o iaa_crypto_comp_fixed.o iaa_crypto_comp_canned.o iaa_crypto-$(CONFIG_CRYPTO_DEV_IAA_CRYPTO_STATS) += iaa_crypto_stats.o
drivers/crypto/intel/iaa/iaa_crypto.h +38 -0
@@ -39,6 +39,15 @@ IAA_DECOMP_CHECK_FOR_EOB | \ IAA_DECOMP_STOP_ON_EOB) +/* +* iaa_cap.dec_aecs_format_ver == 1 means the decompress internal state in +* the AECS is Format 2, which requires a different length from Format 1. +* See Intel® In-Memory Analytics Accelerator Architecture Specification +* Sections 6.4.1.1 and 7.2.2 for details. +*/ +#define DECOMP_INT_STATE_FMT1_LEN 1088 +#define DECOMP_INT_STATE_FMT2_LEN 1248 +/* Representation of IAA workqueue */ struct iaa_wq {struct list_head list;
@@ -59,8 +68,10 @@ struct iaa_device_compression_mode {const char *name;struct aecs_comp_table_record *aecs_comp_table; +struct aecs_decomp_table_record *aecs_decomp_table;dma_addr_t aecs_comp_table_dma_addr; +dma_addr_t aecs_decomp_table_dma_addr; };/* Representation of IAA device with wqs, populated by probe */
@@ -77,6 +88,7 @@ struct iaa_device {atomic64_t comp_bytes;atomic64_t decomp_calls;atomic64_t decomp_bytes; +u32 src2_size; };struct wq_table_entry {
@@ -105,8 +117,27 @@ struct aecs_comp_table_record {u32 reserved_padding[2 ]; } __packed; +/* AECS for decompress */ +struct aecs_decomp_table_record { +u32 crc; +u32 xor_checksum; +u32 low_filter_param; +u32 high_filter_param; +u32 output_mod_idx; +u32 drop_init_decomp_out_bytes; +u32 reserved[36 ]; +u32 output_accum_data[2 ]; +u32 out_bits_valid; +u32 bit_off_indexing; +u32 input_accum_data[64 ]; +u8 size_qw[32 ]; +u32 decomp_state[1220 ]; +} __packed; +int iaa_aecs_init_fixed (void );void iaa_aecs_cleanup_fixed (void ); +int iaa_aecs_init_canned (void ); +void iaa_aecs_cleanup_canned (void );typedef int (*iaa_dev_comp_init_fn_t ) (struct iaa_device_compression_mode *mode);typedef int (*iaa_dev_comp_free_fn_t ) (struct iaa_device_compression_mode *mode);
@@ -117,6 +148,9 @@ struct iaa_compression_mode {int ll_table_size;u32 *d_table;int d_table_size; +u8 *header_table; +int header_table_size; +u16 gen_decomp_table_flags;iaa_dev_comp_init_fn_t init;iaa_dev_comp_free_fn_t free; };
@@ -126,6 +160,9 @@ int add_iaa_compression_mode(const char *name,int ll_table_size, const u32 *d_table, int d_table_size, + const u8 *header_table, + int header_table_size, + u16 gen_decomp_table_flags, iaa_dev_comp_init_fn_t init, iaa_dev_comp_free_fn_t free);
@@ -133,6 +170,7 @@ void remove_iaa_compression_mode(const char *name);enum iaa_mode {IAA_MODE_FIXED , +IAA_MODE_CANNED , };struct iaa_compression_ctx {
drivers/crypto/intel/iaa/iaa_crypto_comp_canned.c new file +116 -0
116 lines not on this page · raw message
drivers/crypto/intel/iaa/iaa_crypto_comp_fixed.c +1 -0
@@ -78,6 +78,7 @@ int iaa_aecs_init_fixed(void)sizeof (fixed_ll_sym), fixed_d_sym,sizeof (fixed_d_sym), +NULL ,0 ,0 , init_fixed_mode, NULL);if (!ret)pr_debug ("IAA fixed compression mode initialized\n" );
drivers/crypto/intel/iaa/iaa_crypto_main.c +248 -23
449 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH 3/4 crypto: iaa - Add deflate-iaa-dynamic compression algorithm
In reply to Andre GloverSome versions of Intel IAA support dynamic compression where the hardware dynamically computes the Huffman tables and generates a Deflate header if the input size is no larger than 4KB. This patch will use IAA for dynamic compression if an appropriate IAA is present and the input size is not too big. If an IAA is not present, the algorithm will not be available. Otherwise, if the size of the input is too big, zlib is used to do the compression. If the algorithm is selected, IAA will be used for decompression. If the compressed stream contains a reference whose distance is greater than 4KB, hardware decompression will fail, and the decompression will be done with zlib.
Intel IAA dynamic compression results in a compression ratio that is better than or equal to the currently supported "canned" and/or "fixed" compression modes on the same data set. Compressing a data set of 4300 4KB pages sampled from SPEC CPU17 workloads produces a compression ratio of 3.14 for IAA dynamic compression, 2.88 for IAA canned compression and 2.69 for IAA fixed compression.
If an appropriate IAA exists, ‘dynamic’ mode can be chosen as the mode to be used by crypto facilities by selecting the corresponding algorithm. For example, to use IAA dynamic mode in zswap:
echo deflate-iaa-dynamic > /sys/module/zswap/parameters/compressor
--- .../driver-api/crypto/iaa/iaa-crypto.rst | 21 +++++ crypto/testmgr.c | 10 +++ crypto/testmgr.h | 74 ++++++++++++++++ drivers/crypto/intel/iaa/Makefile | 2 +- drivers/crypto/intel/iaa/iaa_crypto.h | 6 +- .../intel/iaa/iaa_crypto_comp_dynamic.c | 22 +++++ drivers/crypto/intel/iaa/iaa_crypto_main.c | 88 +++++++++++++++++-- 7 files changed, 215 insertions(+), 8 deletions(-) create mode 100644 drivers/crypto/intel/iaa/iaa_crypto_comp_dynamic.c
Documentation/driver-api/crypto/iaa/iaa-crypto.rst +21 -0
@@ -33,6 +33,8 @@ compresses and decompresses. Currently, two compression modes are available to all IAA hardware, 'canned' and 'fixed' modes. +'dynamic' mode is available on certain generations of IAA hardware. + The 'fixed' compression mode implements the compression scheme specified by RFC 1951 and is given the crypto algorithm name 'deflate-iaa'. (Because the IAA hardware has a 4k history-window
@@ -54,6 +56,25 @@ selecting the 'deflate-iaa-canned' crypto compression algorithm:: # echo deflate-iaa-canned > /sys/module/zswap/parameters/compressor +The 'dynamic' compression mode implements a compression scheme where +the IAA hardware will internally do one pass through the data, compute the +Huffman tables and generate a Deflate header, then automatically do a +second pass through the data, generating the final compressed output. IAA +dynamic compression can be used if an appropriate IAA is present and the +input size is not too big. If an appropriate IAA is not present, the +algorithm will not be available. Otherwise, if the size of the input is too +big, zlib is used to do the compression. If the algorithm is selected, +IAA will be used for decompression. If the compressed stream contains a +reference whose distance is greater than 4KB, hardware decompression will +fail, and the decompression will be done with zlib. If an appropriate IAA +exists, 'dynamic' compression, it is implemented by the +'deflate-iaa-dynamic' crypto algorithm. + +A zswap device can select the IAA 'dynamic' mode represented by +selecting the 'deflate-iaa-dynamic' crypto compression algorithm:: + + # echo deflate-iaa-dynamic> /sys/module/zswap/parameters/compressor + Config options and other setup ==============================
crypto/testmgr.c +10 -0
@@ -4816,6 +4816,16 @@ static const struct alg_test_desc alg_test_descs[] = { .decomp = __VECS(deflate_iaa_canned_decomp_tv_template) } } + }, { + .alg = "deflate-iaa-dynamic", + .test = alg_test_comp, + .fips_allowed = 1, + .suite = { + .comp = { + .comp = __VECS(deflate_iaa_dynamic_comp_tv_template), + .decomp = __VECS(deflate_iaa_dynamic_decomp_tv_template) + } + } }, { .alg = "deflate-scomp-canned", .test = alg_test_comp,
crypto/testmgr.h +74 -0
80 lines not on this page · raw message
drivers/crypto/intel/iaa/Makefile +1 -1
@@ -7,6 +7,6 @@ ccflags-y += -I $(srctree)/drivers/dma/idxd -DDEFAULT_SYMBOL_NAMESPACE=IDXD obj-$(CONFIG_CRYPTO_DEV_IAA_CRYPTO) := iaa_crypto.o -iaa_crypto-y := iaa_crypto_main.o iaa_crypto_comp_fixed.o iaa_crypto_comp_canned.o +iaa_crypto-y := iaa_crypto_main.o iaa_crypto_comp_fixed.o iaa_crypto_comp_canned.o iaa_crypto_comp_dynamic.o iaa_crypto-$(CONFIG_CRYPTO_DEV_IAA_CRYPTO_STATS) += iaa_crypto_stats.o
drivers/crypto/intel/iaa/iaa_crypto.h +5 -1
@@ -18,6 +18,7 @@#define IAA_COMP_FLUSH_OUTPUT BIT(1)#define IAA_COMP_APPEND_EOB BIT(2) +#define IAA_COMP_GEN_HDR_1_PASS (BIT(12) | BIT(13))#define IAA_COMPLETION_TIMEOUT 1000000
@@ -26,7 +27,7 @@#define IAA_ERROR_COMP_BUF_OVERFLOW 0x19#define IAA_ERROR_WATCHDOG_EXPIRED 0x24 -#define IAA_COMP_MODES_MAX 2 +#define IAA_COMP_MODES_MAX 3#define FIXED_HDR 0x2#define FIXED_HDR_SIZE 3
@@ -138,6 +139,8 @@ int iaa_aecs_init_fixed(void);void iaa_aecs_cleanup_fixed (void );int iaa_aecs_init_canned (void );void iaa_aecs_cleanup_canned (void ); +int iaa_aecs_init_dynamic (void ); +void iaa_aecs_cleanup_dynamic (void );typedef int (*iaa_dev_comp_init_fn_t ) (struct iaa_device_compression_mode *mode);typedef int (*iaa_dev_comp_free_fn_t ) (struct iaa_device_compression_mode *mode);
@@ -171,6 +174,7 @@ void remove_iaa_compression_mode(const char *name);enum iaa_mode {IAA_MODE_FIXED ,IAA_MODE_CANNED , +IAA_MODE_DYNAMIC , };struct iaa_compression_ctx {
drivers/crypto/intel/iaa/iaa_crypto_comp_dynamic.c new file +22 -0
@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2023 Intel Corporation. All rights rsvd. */ + +#include "idxd.h" +#include "iaa_crypto.h" + +int iaa_aecs_init_dynamic (void ) +{ +int ret; + + ret =add_iaa_compression_mode ("dynamic" ,NULL ,0 ,NULL ,0 ,NULL ,0 ,0 ,NULL ,NULL ); + +if (!ret) +pr_debug ("IAA dynamic compression mode initialized\n" ); + +return ret; +} + +void iaa_aecs_cleanup_dynamic (void ) +{ +remove_iaa_compression_mode ("dynamic" ); +}
drivers/crypto/intel/iaa/iaa_crypto_main.c +82 -6
162 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH 4/4 crypto: iaa - Add Software Compression stats to IAA Compression Accelerator stats
In reply to Andre GloverUpdate optional debugfs statistics support for IAA with additional software compression statistics. The software compression statistics will track instances where iaa falls back to software deflate (e.g. when the source data input length is greater than 4KB).
--- drivers/crypto/intel/iaa/iaa_crypto_main.c | 2 ++ drivers/crypto/intel/iaa/iaa_crypto_stats.c | 8 ++++++++ drivers/crypto/intel/iaa/iaa_crypto_stats.h | 2 ++ 3 files changed, 12 insertions(+)
drivers/crypto/intel/iaa/iaa_crypto_main.c +2 -0
@@ -1152,6 +1152,8 @@ static int deflate_generic_compress(struct acomp_req *req)kunmap_local (src);kunmap_local (dst); +update_total_sw_comp_calls (); +return ret; }
drivers/crypto/intel/iaa/iaa_crypto_stats.c +8 -0
@@ -19,6 +19,7 @@static atomic64_t total_comp_calls;static atomic64_t total_decomp_calls; +static atomic64_t total_sw_comp_calls;static atomic64_t total_sw_decomp_calls;static atomic64_t total_comp_bytes_out;static atomic64_t total_decomp_bytes_in;
@@ -43,6 +44,11 @@ void update_total_decomp_calls(void)atomic64_inc (&total_decomp_calls); } +void update_total_sw_comp_calls (void ) +{ +atomic64_inc (&total_sw_comp_calls); +} +void update_total_sw_decomp_calls (void ) {atomic64_inc (&total_sw_decomp_calls);
@@ -174,6 +180,8 @@ static int global_stats_show(struct seq_file *m, void *v) atomic64_read(&total_comp_calls));seq_printf (m," total_decomp_calls: %llu\n" ,atomic64_read (&total_decomp_calls)); +seq_printf (m," total_sw_comp_calls: %llu\n" , +atomic64_read (&total_sw_comp_calls));seq_printf (m," total_sw_decomp_calls: %llu\n" ,atomic64_read (&total_sw_decomp_calls)); seq_printf(m, " total_comp_bytes_out: %llu\n",
drivers/crypto/intel/iaa/iaa_crypto_stats.h +2 -0
@@ -11,6 +11,7 @@ void iaa_crypto_debugfs_cleanup(void);void update_total_comp_calls (void );void update_total_comp_bytes_out (int n);void update_total_decomp_calls (void ); +void update_total_sw_comp_calls (void );void update_total_sw_decomp_calls (void );void update_total_decomp_bytes_in (int n);void update_completion_einval_errs (void );
@@ -29,6 +30,7 @@ static inline void iaa_crypto_debugfs_cleanup(void) {}static inline void update_total_comp_calls (void ) {}static inline void update_total_comp_bytes_out (int n) {}static inline void update_total_decomp_calls (void ) {} +static inline void update_total_sw_comp_calls (void ) {}static inline void update_total_sw_decomp_calls (void ) {}static inline void update_total_decomp_bytes_in (int n) {}static inline void update_completion_einval_errs (void ) {}
Signature · 1 line
2.27.0
Quoted 3 lines · Andre Glover
The 'canned' compression mode implements a compression scheme that uses a statically defined set of Huffman tables, but where the Deflate Block Header is implied rather than stored with the compressed data.
This already exists in standard DEFLATE; it's called fixed mode. See section 3.2.6 of RFC1951 (https://datatracker.ietf.org/doc/html/rfc1951#page-12).
I think that what's going on is that you've implemented a custom variant of DEFLATE where you set the fixed Huffman codes to something different from the ones defined in the standard.
Is that correct, or are there other differences?
Actually, looking at your zlib_tr_flush_block(), it looks instead of using the reserved block type value (3) or redefining the meaning of the fixed block type value (1), you actually deleted the BTYPE and BFINAL fields from the data stream entirely. So the stream no longer stores the type of block or the flag that indicates whether the block is the final one or not.
That has the property that there cannot be any standard blocks, even uncompressed blocks, included in the data stream anymore. Is that intentional?
Maybe this is why you're using the name "canned", instead of going with something more consistent with the existing "fixed" name, like "custom-fixed"?
I wonder what the plan is for when the next hardware vendor tries to do this and chooses their own Huffman codes, different from yours. Or what if Intel decides the Huffman codes they chose aren't the best ones anymore and releases new hardware that uses different codes. Will we perhaps be getting a tinned mode too?
Is your customization described in any sort of publicly available document that could hint at some way to name it properly?
- Eric
Hi Eric,
Thank you for reviewing the patch. Please see responses to your questions inline below.
Quoted 12 lines · Eric Biggers
Quoted 5 lines · Andre Glover
The 'canned' compression mode implements a compression scheme that uses a statically defined set of Huffman tables, but where the Deflate
Block Header is implied rather than stored with the compressed data.This already exists in standard DEFLATE; it's called fixed mode. See section
3.2.6 of RFC1951
(https://datatracker.ietf.org/doc/html/rfc1951#page-12).
Quoted 8 lines
I think that what's going on is that you've implemented a custom variant of
DEFLATE where you set the fixed Huffman codes to something different from the
ones defined in the standard.Is that correct, or are there other differences?
We view it as a variant of dynamic block Deflate as opposed to a variant of fixed. In particular, it is compressing the input with static Huffman tables (i.e. ones that do not vary with the input), and where the Deflate block header (which is a constant) is not stored with the compressed data. If the missing block header were to be prepended to the compressed data, the result would be a valid dynamic compressed block.
One might think of this as vaguely similar to dictionary compression. In that case, the dictionary is not stored with the compressed data but is agreed to by the compressor and decompression. In the case of canned compression, the header is not stored with the compressed data but is agreed to by both entities.
Quoted 10 lines
Actually, looking at your
zlib_tr_flush_block(), it looks instead of using the
reserved block type value (3) or redefining the meaning of the fixed block type
value (1), you actually deleted the BTYPE and BFINAL fields from the data stream
entirely. So the stream no longer stores the type of block or the flag that
indicates whether the block is the final one or not.
Quoted 4 lines
That has the property that there cannot be any standard blocks, even uncompressed blocks, included in the data stream anymore. Is that intentional?
Conceptually, there is a valid dynamic block header associated with the compressed data, it is just not stored with the data in order to save space (since it is effectively an unchanging constant). In this usage, it is envisioned that the output would consist of a single Deflate block (i.e. the implied header is marked as BFINAL). In theory, one could have the implied block header not marked as BFINAL, and so the compressed data would need to contain at least two blocks (i.e. the body of the initial block, an EOB, and a normal block with header), but this would be counterproductive to the intended usage.
Quoted 5 lines
Maybe this is why you're using the name "canned", instead of going with
something more consistent with the existing "fixed" name, like "custom-fixed"?
Again, we view this as a variant of dynamic compression rather than as a variant of fixed compression. We use the term "static" to describe compression with a dynamic block where the tables are unchanging (i.e. not dependent on the input data) . This can allow the compression to be done in one pass rather than two. The "canned" compression uses a static table, but is different in that the header is implied rather than stored.
Quoted 10 lines
I wonder what the plan is for when the next hardware vendor tries to do this and
chooses their own Huffman codes, different from yours. Or what if Intel decides
the Huffman codes they chose aren't the best ones anymore and releases new
hardware that uses different codes. Will we perhaps be getting a tinned mode
too?
The Huffman tables are not built into the hardware. The Huffman tables/block header is in this case built into the software. The same tables are embedded in the zlib portion of the patch for software compression/decompression and in the hardware driver portion of the patch for IAA compression/decompression. The hardware itself can work with any desired set of tables.
Thanks,
Andre
Herbert Xu
maintainerQuoted 6 lines · Andre Glover
Below is a table showing the latency improvements with zlib, between zlib dynamic and zlib canned modes, and the compression ratio for each mode while using a set of 4300 4KB pages sampled from SPEC CPU17 workloads:
_________________________________________________________
Quoted 10 lines
| Zlib Level | Canned Latency Gain | Comp Ratio | |------------|-----------------------|------------------| | | compress | decompress | dynamic | canned | |____________|__________|____________|_________|________| | 1 | 49% | 29% | 3.16 | 2.92 | |------------|----------|------------|---------|--------| | 6 | 27% | 28% | 3.35 | 3.09 | |------------|----------|------------|---------|--------| | 9 | 12% | 29% | 3.36 | 3.11 | |____________|__________|____________|_________|________|
So which kernel user (zswap I presume) is clamouring for this feature? We don't add new algorithms that have no in-kernel users. So we need to be sure that the kernel user actually want this.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH 2/4] crypto: iaa - Add deflate-canned compression algorithm
In reply to Andre GloverHi Andre,
Some comments inline below...
Quoted 59 lines · Andre Glover
The 'canned' compression mode implements a compression scheme that uses statically-defined customized Huffman tables. Since the Deflate block header is a constant, it is not stored with the compressed data. The Huffman tables used were generated from statistics derived from swapped 4KB pages of SPEC CPU17 workloads. Canned mode provides better compression than using the Deflate standard's (RFC-1951) "fixed" tables and better latencies than dynamic compression.
Compressing a data set of 4300 4KB pages sampled from SPEC CPU17 workloads produces a compression ratio of 2.88 for IAA canned compression and 2.69 for IAA fixed compression, which is a 7% improvement.
Either 'fixed' or 'canned' modes can be chosen as the mode to be used by crypto facilities by selecting the corresponding algorithm. For example, to use IAA fixed mode in zswap:
echo deflate-iaa >
/sys/module/zswap/parameters/compressorTo choose 'canned' mode:
echo deflate-iaa-canned >
/sys/module/zswap/parameters/compressor[ Based on work originally by George Powley, Jing Lin and Kyung Min Park ]
Signed-off-by Tom Zanussi <[email protected]>Signed-off-by Andre Glover <[email protected]>---
.../driver-api/crypto/iaa/iaa-crypto.rst | 15 +- crypto/testmgr.c | 10 + crypto/testmgr.h | 72 +++++ drivers/crypto/intel/iaa/Kconfig | 1 + drivers/crypto/intel/iaa/Makefile | 2 +- drivers/crypto/intel/iaa/iaa_crypto.h | 38 +++.../crypto/intel/iaa/iaa_crypto_comp_canned.c| 116 ++++++++ .../crypto/intel/iaa/iaa_crypto_comp_fixed.c | 1 + drivers/crypto/intel/iaa/iaa_crypto_main.c | 271 ++++++++++++++++--9 files changed, 500 insertions(+), 26 deletions(-)create mode 100644
drivers/crypto/intel/iaa/iaa_crypto_comp_canned.cDocumentation/driver-api/crypto/iaa/iaa-crypto.rst +0
-0@@ -30,8 +30,8 @@ algorithm::This will tell zswap to use the IAA 'fixed' compression mode for all compresses and decompresses.
Documentation/driver-api/crypto/iaa/iaa-crypto.rst +2
-2-Currently, there is only one compression modes available, 'fixed' -mode. +Currently, two compression modes are available to all IAA hardware, +'canned' and 'fixed' modes.
The 'fixed' compression mode implements the compression scheme specified by RFC 1951 and is given the crypto algorithm nameDocumentation/driver-api/crypto/iaa/iaa-crypto.rst +0
-0@@ -42,6 +42,17 @@ which allows for a window of up to 32k. Because of this limitation,the IAA fixed mode deflate algorithm is given its own algorithm name rather than simply 'deflate').
Documentation/driver-api/crypto/iaa/iaa-crypto.rst which allows for a window of up to 32k. Because of this limitation, · line 50
Quoted 6 lines
Documentation/driver-api/crypto/iaa/iaa-crypto.rst +6
-0+The 'canned' compression mode implements a good general-purpose +compression scheme whose tables were generated from statistics derived +from a wide variety of SPEC17 workloads. It provides much better +overall characteristics than the existing deflate-1951 tables +implemented by 'fixed'. 'Canned' mode is implemented by the +'deflate-iaa-canned' crypto algorithm.::
The double colon here isn't necessary.
Quoted 168 lines
Documentation/driver-api/crypto/iaa/iaa-crypto.rst +5
-0+ +A zswap device can select the IAA 'canned' mode represented by +selecting the 'deflate-iaa-canned' crypto compression algorithm:: + + # echo deflate-iaa-canned > /sys/module/zswap/parameters/compressor
Config options and other setup
==============================crypto/testmgr.c +10
-0@@ -4806,6 +4806,16 @@ static const struct alg_test_desc alg_test_descs[] = { .decomp = __VECS(deflate_decomp_tv_template) } } + }, { + .alg = "deflate-iaa-canned", + .test = alg_test_comp, + .fips_allowed = 1, + .suite = { + .comp = { + .comp = __VECS(deflate_iaa_canned_comp_tv_template), + .decomp = __VECS(deflate_iaa_canned_decomp_tv_template) + } + } }, { .alg = "deflate-scomp-canned", .test = alg_test_comp,crypto/testmgr.h +0
-0@@ -34526,6 +34526,78 @@ static const struct comp_testvec deflate_decomp_tv_template[] = { }, };crypto/testmgr.h +72
-0+static const struct comp_testvec deflate_iaa_canned_comp_tv_template[] = { + { + .inlen = 70, + .outlen = 37, + .input = "Join us now and share the software " + "Join us now and share the software ", + .output = "\x6d\x23\x43\x23\xa4\x71\x31\xd2" + "\x88\xc8\x61\x52\x75\x84\x56\x1a" + "\x13\xa2\x8e\xd6\x49\x63\x43\x74" + "\xd2\x98\xc8\xe0\xd8\x61\x58\x69" + "\xcb\x71\x01\xe5\x3f", + }, { + .inlen = 191, + .outlen = 128, + .input = "This document describes a compression method based on the DEFLATE" + "compression algorithm. This document defines the application of " + "the DEFLATE algorithm to the IP Payload Compression Protocol.", + .output = "\xdd\x42\x42\x63\xa4\xda\x48\x4d" + "\x5c\xb8\x2e\x22\x56\xaa\xd5\xc5" + "\x68\xa2\x43\x83\x74\x31\x52\xb5" + "\x54\x13\x19\x1e\x15\xad\x8b\x89" + "\x09\x8d\x8c\x90\x86\xeb\x62\x43" + "\x22\xb5\xd2\x20\x75\x8c\x4e\x2b" + "\x05\x3d\x36\x44\x27\xf5\x69\xe5" + "\xdb\xde\xbb\x5b\x2b\x7d\x37\x75" + "\xd8\xc0\xc8\xe8\xd0\xd8\x90\x70" + "\x7b\xa9\x54\x1c\x38\x38\x34\x02" + "\xc2\xe2\x8e\xea\xa8\xa8\xb0\x50" + "\x8d\x3a\x16\xf7\x88\x0c\xd6\x8f" + "\x95\x1f\x40\x1a\x1b\x29\x34\xb4" + "\xf1\x97\xfa\xab\x87\x87\x45\xaa" + "\xb5\xd2\x96\x7a\x03\xf9\x47\x47" + "\xc6\x46\x6a\x22\xc3\xec\xff\x03", + }, +}; + +static const struct comp_testvec deflate_iaa_canned_decomp_tv_template[] = { + { + .inlen = 128, + .outlen = 191, + .input = "\xdd\x42\x42\x63\xa4\xda\x48\x4d" + "\x5c\xb8\x2e\x22\x56\xaa\xd5\xc5" + "\x68\xa2\x43\x83\x74\x31\x52\xb5" + "\x54\x13\x19\x1e\x15\xad\x8b\x89" + "\x09\x8d\x8c\x90\x86\xeb\x62\x43" + "\x22\xb5\xd2\x20\x75\x8c\x4e\x2b" + "\x05\x3d\x36\x44\x27\xf5\x69\xe5" + "\xdb\xde\xbb\x5b\x2b\x7d\x37\x75" + "\xd8\xc0\xc8\xe8\xd0\xd8\x90\x70" + "\x7b\xa9\x54\x1c\x38\x38\x34\x02" + "\xc2\xe2\x8e\xea\xa8\xa8\xb0\x50" + "\x8d\x3a\x16\xf7\x88\x0c\xd6\x8f" + "\x95\x1f\x40\x1a\x1b\x29\x34\xb4" + "\xf1\x97\xfa\xab\x87\x87\x45\xaa" + "\xb5\xd2\x96\x7a\x03\xf9\x47\x47" + "\xc6\x46\x6a\x22\xc3\xec\xff\x03", + .output = "This document describes a compression method based on the DEFLATE" + "compression algorithm. This document defines the application of " + "the DEFLATE algorithm to the IP Payload Compression Protocol.", + }, { + .inlen = 37, + .outlen = 70, + .input = "\x6d\x23\x43\x23\xa4\x71\x31\xd2" + "\x88\xc8\x61\x52\x75\x84\x56\x1a" + "\x13\xa2\x8e\xd6\x49\x63\x43\x74" + "\xd2\x98\xc8\xe0\xd8\x61\x58\x69" + "\xcb\x71\x01\xe5\x3f", + .output = "Join us now and share the software " + "Join us now and share the software ", + }, +}; +static const struct
comp_testvecdeflate_scomp_canned_comp_tv_template[] = { {
.inlen = 70,drivers/crypto/intel/iaa/Kconfig +0
-0@@ -2,6 +2,7 @@ config CRYPTO_DEV_IAA_CRYPTOtristate "Support for Intel(R) IAA Compression Accelerator" depends on
CRYPTO_DEFLATE
depends onINTEL_IDXD
+ selectZLIB_CANNED
default n
help
This driver supports acceleration for compression anddrivers/crypto/intel/iaa/Makefile +0
-0@@ -7,6 +7,6 @@ ccflags-y += -I $(srctree)/drivers/dma/idxd -DDEFAULT_SYMBOL_NAMESPACE=IDXD
obj-$(CONFIG_CRYPTO_DEV_IAA_CRYPTO) := iaa_crypto.odrivers/crypto/intel/iaa/Makefile +1
-1-iaa_crypto-y := iaa_crypto_main.o iaa_crypto_comp_fixed.o +iaa_crypto-y := iaa_crypto_main.o iaa_crypto_comp_fixed.o iaa_crypto_comp_canned.o
iaa_crypto-$(CONFIG_CRYPTO_DEV_IAA_CRYPTO_STATS) += iaa_crypto_stats.odrivers/crypto/intel/iaa/iaa_crypto.h +0
-0@@ -39,6 +39,15 @@ IAA_DECOMP_CHECK_FOR_EOB | \ IAA_DECOMP_STOP_ON_EOB)drivers/crypto/intel/iaa/iaa_crypto.h +9
-0+/* +* iaa_cap.dec_aecs_format_ver == 1 means the decompress internal state in +* the AECS is Format 2, which requires a different length from Format 1. +* See Intel® In-Memory Analytics Accelerator Architecture Specification +* Sections 6.4.1.1 and 7.2.2 for details. +*/ +#define DECOMP_INT_STATE_FMT1_LEN 1088 +#define DECOMP_INT_STATE_FMT2_LEN 1248 +/* Representation of IAA workqueue */
structiaa_wq{
struct list_head list;drivers/crypto/intel/iaa/iaa_crypto.h +0
-0@@ -59,8 +68,10 @@ struct iaa_device_compression_mode { const char *name;
struct aecs_comp_table_record *aecs_comp_table; + struct aecs_decomp_table_record *aecs_decomp_table;
dma_addr_t aecs_comp_table_dma_addr; + dma_addr_t aecs_decomp_table_dma_addr; };
/* Representation of IAA device with wqs, populated by probe */
drivers/crypto/intel/iaa/iaa_crypto.h struct iaa_device { · line 90
Quoted 3 lines
drivers/crypto/intel/iaa/iaa_crypto.h +0
-0@@ -77,6 +88,7 @@ struct iaa_device { atomic64_t comp_bytes; atomic64_t decomp_calls; atomic64_t decomp_bytes;
Could you add a space here, to visually separate the stats fields from the unrelated field below?
Quoted 301 lines
drivers/crypto/intel/iaa/iaa_crypto.h +1
-0+ u32 src2_size; };
structwq_table_entry{drivers/crypto/intel/iaa/iaa_crypto.h +0
-0@@ -105,8 +117,27 @@ struct aecs_comp_table_record { u32 reserved_padding[2]; } __packed;drivers/crypto/intel/iaa/iaa_crypto.h +17
-0+/* AECS for decompress */ +struct aecs_decomp_table_record { + u32 crc; + u32 xor_checksum; + u32 low_filter_param; + u32 high_filter_param; + u32 output_mod_idx; + u32 drop_init_decomp_out_bytes; + u32 reserved[36]; + u32 output_accum_data[2]; + u32 out_bits_valid; + u32 bit_off_indexing; + u32 input_accum_data[64]; + u8 size_qw[32]; + u32 decomp_state[1220]; +} __packed; +int
iaa_aecs_init_fixed(void);
voidiaa_aecs_cleanup_fixed(void);drivers/crypto/intel/iaa/iaa_crypto.h +2
-0+int iaa_aecs_init_canned (void ); +void iaa_aecs_cleanup_canned (void );
typedef int (*iaa_dev_comp_init_fn_t) (structiaa_device_compression_mode*mode); typedef int (*iaa_dev_comp_free_fn_t) (structiaa_device_compression_mode*mode);drivers/crypto/intel/iaa/iaa_crypto.h +6
-0@@ -117,6 +148,9 @@ struct iaa_compression_mode { int ll_table_size; u32 *d_table; int d_table_size; + u8 *header_table; + int header_table_size; + u16 gen_decomp_table_flags; iaa_dev_comp_init_fn_t init; iaa_dev_comp_free_fn_t free; };@@ -126,6 +160,9 @@ int add_iaa_compression_mode(const char *name, int ll_table_size, const u32 *d_table, int d_table_size, + const u8 *header_table, + int header_table_size, + u16 gen_decomp_table_flags, iaa_dev_comp_init_fn_t init, iaa_dev_comp_free_fn_t free);drivers/crypto/intel/iaa/iaa_crypto.h +0
-0@@ -133,6 +170,7 @@ void remove_iaa_compression_mode(const char *name);
enumiaa_mode{
IAA_MODE_FIXED,
+ IAA_MODE_CANNED,
};
structiaa_compression_ctx{drivers/crypto/intel/iaa/iaa_crypto_comp_canned.c new file +116
-0@@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2021 Intel Corporation. All rights rsvd. */ + +#include "iaa_crypto.h" +#include "idxd.h" + +#define IAA_AECS_ALIGN 32 + +/* +* These tables were generated from statistics derived from a wide +* variety of SPEC17 workloads and implement a good general-purpose +* compression scheme called simply 'canned'. +*/ + +static const u32 canned_ll_iaa[286 ] = { +0x28002, 0x38024, 0x40066, 0x40067, 0x40068, 0x48144, 0x40069, 0x48145, +0x4006a, 0x48146, 0x4006b, 0x48147, 0x48148, 0x48149, 0x4814a, 0x4814b, +0x4006c, 0x4814c, 0x4814d, 0x4814e, 0x4814f, 0x48150, 0x48151, 0x48152, +0x4006d, 0x48153, 0x48154, 0x48155, 0x48156, 0x48157, 0x48158, 0x48159, +0x38025, 0x4815a, 0x4815b, 0x4815c, 0x4815d, 0x4815e, 0x4815f, 0x48160, +0x4006e, 0x48161, 0x48162, 0x48163, 0x48164, 0x48165, 0x4006f, 0x48166, +0x38026, 0x38027, 0x40070, 0x40071, 0x40072, 0x40073, 0x40074, 0x40075, +0x38028, 0x40076, 0x40077, 0x48167, 0x40078, 0x40079, 0x4007a, 0x38029, +0x3802a, 0x4007b, 0x48168, 0x48169, 0x4007c, 0x4816a, 0x4007d, 0x4816b, +0x4007e, 0x4816c, 0x4816d, 0x4816e, 0x4816f, 0x48170, 0x48171, 0x48172, +0x4007f, 0x48173, 0x48174, 0x48175, 0x48176, 0x48177, 0x48178, 0x48179, +0x40080, 0x4817a, 0x4817b, 0x4817c, 0x4817d, 0x4817e, 0x4817f, 0x48180, +0x40081, 0x3802b, 0x40082, 0x3802c, 0x3802d, 0x3802e, 0x40083, 0x48181, +0x40084, 0x40085, 0x48182, 0x48183, 0x40086, 0x40087, 0x40088, 0x40089, +0x4008a, 0x48184, 0x4008b, 0x4008c, 0x4008d, 0x4008e, 0x48185, 0x48186, +0x4008f, 0x48187, 0x48188, 0x48189, 0x4818a, 0x4818b, 0x4818c, 0x4818d, +0x40090, 0x4818e, 0x4818f, 0x48190, 0x48191, 0x48192, 0x48193, 0x48194, +0x40091, 0x48195, 0x48196, 0x48197, 0x48198, 0x48199, 0x4819a, 0x4819b, +0x40092, 0x4819c, 0x4819d, 0x4819e, 0x4819f, 0x481a0, 0x481a1, 0x481a2, +0x40093, 0x481a3, 0x481a4, 0x481a5, 0x481a6, 0x481a7, 0x481a8, 0x481a9, +0x40094, 0x481aa, 0x481ab, 0x481ac, 0x481ad, 0x481ae, 0x481af, 0x481b0, +0x481b1, 0x481b2, 0x481b3, 0x481b4, 0x481b5, 0x481b6, 0x481b7, 0x481b8, +0x40095, 0x481b9, 0x481ba, 0x481bb, 0x481bc, 0x481bd, 0x481be, 0x481bf, +0x40096, 0x481c0, 0x481c1, 0x481c2, 0x481c3, 0x481c4, 0x481c5, 0x40097, +0x40098, 0x481c6, 0x481c7, 0x481c8, 0x481c9, 0x481ca, 0x481cb, 0x481cc, +0x40099, 0x481cd, 0x481ce, 0x481cf, 0x481d0, 0x481d1, 0x481d2, 0x481d3, +0x4009a, 0x481d4, 0x481d5, 0x481d6, 0x481d7, 0x481d8, 0x481d9, 0x481da, +0x481db, 0x481dc, 0x481dd, 0x481de, 0x481df, 0x481e0, 0x481e1, 0x481e2, +0x4009b, 0x481e3, 0x481e4, 0x481e5, 0x481e6, 0x481e7, 0x481e8, 0x481e9, +0x481ea, 0x481eb, 0x481ec, 0x481ed, 0x481ee, 0x481ef, 0x481f0, 0x481f1, +0x4009c, 0x481f2, 0x481f3, 0x481f4, 0x481f5, 0x481f6, 0x481f7, 0x481f8, +0x481f9, 0x481fa, 0x481fb, 0x587fe, 0x481fc, 0x481fd, 0x481fe, 0x4009d, +0x503fe, 0x20000, 0x28003, 0x30010, 0x28004, 0x28005, 0x28006, 0x4009e, +0x4009f, 0x3802f, 0x38030, 0x30011, 0x400a0, 0x38031, 0x38032, 0x400a1, +0x28007, 0x73ff8, 0x73ff9, 0x7fff6, 0x7fff7, 0x7fff8, 0x7fff9, 0x7fffa, +0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, 0x7ffff, 0x73ffa, +}; + +static const u32 canned_d_iaa[30 ] = { +0x3807e, 0x20004, 0x481fe, 0x18000, 0x400fe, 0x18001, 0x3003c, 0x20005, +0x20006, 0x28016, 0x20007, 0x28017, 0x20008, 0x28018, 0x28019, 0x20009, +0x2000a, 0x2801a, 0x2801b, 0x2801c, 0x2801d, 0x3003d, 0x3003e, 0x481ff, +0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +}; + +#define HEADER_SIZE_IN_BITS 656 +static const u8 canned_header[] = { +0xed ,0xfd ,0x05 ,0x5c ,0x54 ,0xcf ,0x17 ,0x06 , +0x8c ,0xcf ,0x02 ,0x22 ,0x62 ,0x61 ,0x63 ,0xaf , +0x8d ,0x85 ,0xbb ,0xe4 ,0x82 ,0xc0 ,0x2e ,0x8a , +0x88 ,0x8d ,0x8d ,0xcd ,0xb2 ,0xbb ,0x08 ,0x4a , +0x49 ,0x28 ,0x36 ,0x36 ,0x36 ,0x36 ,0x36 ,0x76 , +0x2b ,0x36 ,0x26 ,0xd8 ,0xd8 ,0xd8 ,0xad ,0xd8 , +0xad ,0xd8 ,0xf1 ,0x53 ,0xf9 ,0x9e ,0xb9 ,0x33 , +0x03 ,0xbb ,0x97 ,0x5d ,0xe6 ,0x7d ,0xff ,0x1d , +0xef ,0x1e ,0x1f ,0x9e ,0x7b ,0xce ,0x9c ,0x39 , +0x33 ,0xe7 ,0x4c ,0xdc ,0xeb ,0xe7 ,0xf3 ,0xf9 , +0x7c ,0x3e , +}; + +#define CEIL (a, b) (((a) + ((b) - 1)) / (b)) + +int iaa_aecs_init_canned (void ) +{ + u16 gen_decomp_table_flags; + unsigned int slen; + int ret; + + slen = CEIL(HEADER_SIZE_IN_BITS, 8); + + gen_decomp_table_flags = 0x1; /* enable decompression */ + gen_decomp_table_flags |= 1 << 9; /* suppress output */ + + /* + * Bits 8:6 specify the number of bits to ignore at the end of the + * compressed input stream. + * See Intel® In-Memory Analytics Accelerator Architecture Specification + * Sections 6.3.3.1 for details. + */ + gen_decomp_table_flags |= (((slen * 8) - HEADER_SIZE_IN_BITS) << 6); + + ret = add_iaa_compression_mode("canned", + canned_ll_iaa, + sizeof(canned_ll_iaa), + canned_d_iaa, + sizeof(canned_d_iaa), + canned_header, + sizeof(canned_header), + gen_decomp_table_flags, + NULL, NULL); + + if (!ret) + pr_debug("IAA canned compression mode initialized\n"); + + return ret; +} + +void iaa_aecs_cleanup_canned (void ) +{ + remove_iaa_compression_mode("canned"); +}drivers/crypto/intel/iaa/iaa_crypto_comp_fixed.c +1
-0@@ -78,6 +78,7 @@ int iaa_aecs_init_fixed(void) sizeof(fixed_ll_sym), fixed_d_sym, sizeof(fixed_d_sym), + NULL, 0, 0, init_fixed_mode, NULL); if (!ret) pr_debug("IAA fixed compression mode initialized\n");drivers/crypto/intel/iaa/iaa_crypto_main.c +0
-0@@ -34,6 +34,7 @@ static unsigned int nr_cpus_per_node; static unsigned int cpus_per_iaa;
static structcrypto_comp*deflate_generic_tfm;
+static structcrypto_acomp*deflate_canned_tfm;
/* Per-cpu lookup table for balanced wqs */
static structwq_table_entry__percpu*wq_table;drivers/crypto/intel/iaa/iaa_crypto_main.c +0
-0@@ -91,7 +92,8 @@ DEFINE_MUTEX(iaa_devices_lock);
/* If enabled, IAA hw crypto algos are registered, unavailable otherwise */ static booliaa_crypto_enabled;drivers/crypto/intel/iaa/iaa_crypto_main.c +2
-1-static bool iaa_crypto_registered; +static bool iaa_crypto_fixed_registered; +static bool iaa_crypto_canned_registered;
/* Verify results of IAA compress or not */
static booliaa_verify_compress= true;drivers/crypto/intel/iaa/iaa_crypto_main.c +1
-0@@ -258,14 +260,16 @@ static void free_iaa_compression_mode(struct iaa_compression_mode *mode) kfree(mode->name); kfree(mode->ll_table); kfree(mode->d_table); + kfree(mode->header_table);
kfree(mode);
}
/*
- * IAA Compression modes are defined by anll_tableand ad_table.
- * These tables are typically generated and captured using statistics
- * collected from running actual compress/decompress workloads.
+ * IAA Compression modes are defined by anll_table, ad_table, and an
+ * optionalheader_table. These tables are typically generated and
+ * captured using statistics collected from running actual
+ * compress/decompress workloads.
*
* A module or other kernel code can add and remove compression modes
* with a given name using the exported @add_iaa_compression_mode()drivers/crypto/intel/iaa/iaa_crypto_main.c +6
-0@@ -313,6 +317,9 @@ EXPORT_SYMBOL_GPL(remove_iaa_compression_mode); * @ll_table_size: The ll table size in bytes * @d_table: The d table * @d_table_size: The d table size in bytes + * @header_table: Optional header table + * @header_table_size: Optional header table size in bytes + * @gen_decomp_table_flags: Otional flags used to generate the decomp table * @init: Optional callback function to init the compression mode data * @free: Optional callback function to free the compression mode data *@@ -325,6 +332,9 @@ int add_iaa_compression_mode(const char *name, int ll_table_size, const u32 *d_table, int d_table_size, + const u8 *header_table, + int header_table_size, + u16 gen_decomp_table_flags, iaa_dev_comp_init_fn_t init, iaa_dev_comp_free_fn_t free) {@@ -362,6 +372,16 @@ int add_iaa_compression_mode(const char *name, mode->d_table_size = d_table_size; }
+ if (header_table) {
+ mode->header_table =kzalloc(header_table_size, GFP_KERNEL); + if (!mode->header_table)
+ goto free;
+ memcpy(mode->header_table,header_table,header_table_size); + mode->header_table_size =header_table_size;
+ }drivers/crypto/intel/iaa/iaa_crypto_main.c +3
-0+ + mode->gen_decomp_table_flags = gen_decomp_table_flags; +mode->init = init;
mode->free = free;drivers/crypto/intel/iaa/iaa_crypto_main.c +2
-1@@ -394,14 +414,19 @@ get_iaa_device_compression_mode(struct iaa_device *iaa_device, int idx) static void free_device_compression_mode(struct iaa_device *iaa_device, struct iaa_device_compression_mode *device_mode) { - size_t size = sizeof(struct aecs_comp_table_record) + IAA_AECS_ALIGN; + size_t c_size = sizeof(struct aecs_comp_table_record) + IAA_AECS_ALIGN; + size_t d_size = sizeof(struct aecs_decomp_table_record) + IAA_AECS_ALIGN; struct device *dev = &iaa_device->idxd->pdev->dev;
kfree(device_mode->name);
if (device_mode->aecs_comp_table)
- dma_free_coherent(dev, size,device_mode->aecs_comp_table, + dma_free_coherent(dev,c_size,device_mode->aecs_comp_table,device_mode->aecs_comp_table_dma_addr); + if (device_mode->aecs_decomp_table)
+ dma_free_coherent(dev,d_size,device_mode->aecs_decomp_table, +device_mode->aecs_decomp_table_dma_addr); +
kfree(device_mode);
}drivers/crypto/intel/iaa/iaa_crypto_main.c +0
-0@@ -418,11 +443,79 @@ static int check_completion(struct device *dev, bool compress, bool only_once);drivers/crypto/intel/iaa/iaa_crypto_main.c +2
-0+static int decompress_header(struct iaa_device_compression_mode *device_mode, + struct iaa_compression_mode *mode,
drivers/crypto/intel/iaa/iaa_crypto_main.c static int check_completion(struct device *dev, · line 457
Quoted 10 lines
drivers/crypto/intel/iaa/iaa_crypto_main.c +10
-0+ struct idxd_wq *wq) +{ + dma_addr_t src_addr, src2_addr; + struct idxd_desc *idxd_desc; + struct iax_hw_desc *desc; + struct device *dev; + struct iaa_wq *iaa_wq; + struct iaa_device *iaa_device; + int ret = 0; +
Just a small style thing - when possible, it's good to use 'reverse Christmas tree' order for locals so e.g. instead of the above it would look like this:
+ dma_addr_t src_addr, src2_addr; + struct iaa_device *iaa_device; + struct idxd_desc *idxd_desc; + struct iax_hw_desc *desc; + struct iaa_wq *iaa_wq; + struct device *dev; + int ret = 0;
So, the longest at the top, followed by the next longest, etc.
Quoted 114 lines
+ idxd_desc =
idxd_alloc_desc(wq, IDXD_OP_BLOCK); + if (IS_ERR(idxd_desc))
+ returnPTR_ERR(idxd_desc);drivers/crypto/intel/iaa/iaa_crypto_main.c +52
-0+ + desc = idxd_desc->iax_hw; + + iaa_wq = idxd_wq_get_private(wq); + iaa_device = iaa_wq->iaa_device; + dev = &wq->idxd->pdev->dev; + + src_addr = dma_map_single(dev, (void *)mode->header_table, + mode->header_table_size, DMA_TO_DEVICE); + dev_dbg(dev, "%s: mode->name %s, src_addr %llx, dev %p, src %p, slen %d\n", + __func__, mode->name, src_addr, dev, + mode->header_table, mode->header_table_size); + if (unlikely(dma_mapping_error(dev, src_addr))) { + dev_dbg(dev, "dma_map_single err, exiting\n"); + ret = -ENOMEM; + return ret; + } + src2_addr = device_mode->aecs_decomp_table_dma_addr; + + desc->flags = IAX_AECS_GEN_FLAG; + desc->opcode = IAX_OPCODE_DECOMPRESS; + desc->decompr_flags = mode->gen_decomp_table_flags; + desc->priv = 0; + + desc->src1_addr = (u64)src_addr; + desc->src1_size = mode->header_table_size; + desc->src2_addr = (u64)src2_addr; + desc->src2_size = iaa_device->src2_size; + dev_dbg(dev, "%s: mode->name %s, src2_addr %llx, dev %p, src2_size %d\n", + __func__, mode->name, desc->src2_addr, dev, desc->src2_size); + desc->max_dst_size = 0; // suppressed output + desc->completion_addr = idxd_desc->compl_dma; + + ret = idxd_submit_desc(wq, idxd_desc); + if (ret) { + pr_err("%s: submit_desc failed ret=0x%x\n", __func__, ret); + goto out; + } + + ret = check_completion(dev, idxd_desc->iax_completion, false, false); + if (ret) + dev_dbg(dev, "%s: mode->name %s check_completion failed ret=%d\n", + __func__, mode->name, ret); + else + dev_dbg(dev, "%s: mode->name %s succeeded\n", __func__, + mode->name); +out: + dma_unmap_single(dev, src_addr, desc->src2_size, DMA_TO_DEVICE); + + return ret; +} +static int
init_device_compression_mode(struct iaa_device *iaa_device, struct iaa_compression_mode *mode, int idx, struct idxd_wq *wq){
- size_t size =sizeof(struct aecs_comp_table_record)+IAA_AECS_ALIGN; + size_tc_size=sizeof(struct aecs_comp_table_record)+IAA_AECS_ALIGN; + size_td_size=sizeof(struct aecs_decomp_table_record)+IAA_AECS_ALIGN; struct device *dev =&iaa_device->idxd->pdev->dev;
structiaa_device_compression_mode*device_mode;
int ret =-ENOMEM;drivers/crypto/intel/iaa/iaa_crypto_main.c +0
-0@@ -435,16 +528,29 @@ static int init_device_compression_mode(struct iaa_device *iaa_device, if (!device_mode->name) goto free;
- device_mode->aecs_comp_table = dma_alloc_coherent(dev, size,
+ device_mode->aecs_comp_table =dma_alloc_coherent(dev, c_size, &device_mode->aecs_comp_table_dma_addr, GFP_KERNEL); if (!device_mode->aecs_comp_table)
goto free;
+ device_mode->aecs_decomp_table = dma_alloc_coherent(dev,d_size,
+&device_mode->aecs_decomp_table_dma_addr,GFP_KERNEL); + if (!device_mode->aecs_decomp_table)
+ goto free;
+
/* Add Huffman table to aecs */
memset(device_mode->aecs_comp_table, 0,sizeof(*device_mode->aecs_comp_table));memcpy(device_mode->aecs_comp_table->ll_sym, mode->ll_table, mode->ll_table_size);memcpy(device_mode->aecs_comp_table->d_sym, mode->d_table, mode->d_table_size);
+ if (mode->header_table) {
+ ret =decompress_header(device_mode, mode, wq);
+ if (ret) {
+ pr_debug("iaa header decompression failed: ret=%d\n", ret);
+ goto free;
+ }
+ }
+
if (mode->init) {
ret =mode->init(device_mode);
if (ret)drivers/crypto/intel/iaa/iaa_crypto_main.c +0
-0@@ -786,6 +892,13 @@ static int save_iaa_wq(struct idxd_wq *wq) goto out; }
+ idxd =new_device->idxd;
+ /* Set IAA device src2 size based on AECS Format Version */ + if (idxd->hw.iaa_cap.dec_aecs_format_ver)
+ new_device->src2_size =DECOMP_INT_STATE_FMT2_LEN; + else
+ new_device->src2_size =DECOMP_INT_STATE_FMT1_LEN; +
ret =add_iaa_wq(new_device, wq, &new_wq);
if (ret) {
del_iaa_device(new_device);drivers/crypto/intel/iaa/iaa_crypto_main.c +0
-0@@ -1006,6 +1119,24 @@ static int deflate_generic_decompress(struct acomp_req *req) return ret; }
drivers/crypto/intel/iaa/iaa_crypto_main.c static int deflate_generic_decompress(struct acomp_req *req) · line 1126
Quoted 5 lines
drivers/crypto/intel/iaa/iaa_crypto_main.c +5
-0+static int deflate_canned_decompress (struct acomp_req *req) +{ + int ret; + struct acomp_req *sw_req; +
Reverse Christmas tree here too (I won't go through them all, please just check this in any new/changed functions throughout).
Thanks,
Tom
Hi Herbert,
Quoted 19 lines · Herbert Xu
Quoted 17 lines · Andre Glover
Below is a table showing the latency improvements with zlib, between
zlib dynamic and zlib canned modes, and the compression ratio for each mode while using a set of 4300 4KB pages sampled from SPEC CPU17 workloads:
_________________________________________________________Quoted 10 lines
Zlib Level | Canned Latency Gain | Comp Ratio |
------------|-----------------------|------------------| | compress | decompress | dynamic | canned | ____________|__________|____________|_________|________| 1 | 49% | 29% | 3.16 | 2.92 | ------------|----------|------------|---------|--------| 6 | 27% | 28% | 3.35 | 3.09 | ------------|----------|------------|---------|--------| 9 | 12% | 29% | 3.36 | 3.11 | ____________|__________|____________|_________|________|
Quoted 6 lines
So which kernel user (zswap I presume) is clamouring for this feature? We don't add new algorithms that have no in-kernel users. So we need to be sure that the kernel user actually want this.
Thanks,
Hi Herbert,
We have recently submitted an RFC to zswap and zram maintainers and users for by_n compression with Intel IAA [1] feedback. This work is in support of efforts to swap in/out large and multi-sized folios. With by_n compression, we have created a scheme that allows parallel IAA compression and decompression operations on a single folio resulting in performance gains. Currently the by_n scheme uses the canned mode compression algorithm to perform the compression and decompression operations. Using canned mode compression results in reduced compression latency because the deflate header doesnt need to be created dynamically, while also producing better ratio than Deflate Fixed mode. We would appreciate your feedback on this scheme.
Here is data from the RFC showing a performance comparison for 64KB folio swap in/out
with zram on Sapphire Rapids, whose core frequency is fixed at 2500MHz:
+------------+-------------+---------+-------------+----------+-------+ | | Compression | Decomp | Compression | zram | zram | | Algorithm | latency | latency | ratio | write | read | +------------+-------------+---------+-------------+----------+-------+ | | Median (ns) | | Median (ns) | +------------+-------------+---------+-------------+----------+-------+ | | | | | | | | IAA by_1 | 34,493 | 20,038 | 2.93 | 40,130 | 24,478| | IAA by_2 | 18,830 | 11,888 | 2.93 | 24,149 | 15,536| | IAA by_4 | 11,364 | 8,146 | 2.90 | 16,735 | 11,469| | IAA by_8 | 8,344 | 6,342 | 2.77 | 13,527 | 9,177| | IAA by_16 | 8,837 | 6,549 | 2.33 | 15,309 | 9,547| | IAA by_32 | 11,153 | 9,641 | 2.19 | 16,457 | 14,086| | IAA by_64 | 18,272 | 16,696 | 1.96 | 24,294 | 20,048| | | | | | | | | lz4 | 139,190 | 33,687 | 2.40 | 144,940 | 37,312| | | | | | | | | lzo-rle | 138,235 | 61,055 | 2.52 | 143,666 | 64,321| | | | | | | | | zstd | 251,820 | 90,878 | 3.40 | 256,384 | 94,328| +------------+-------------+---------+-------------+----------+-------+
[1]https://lore.kernel.org/all/cover.1714581792.git.andre.glover@linux. intel.com/