From 239b716199d9aff0d09444b0086e23aacd6bd445 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Tue, 13 Feb 2018 14:40:39 +0800 Subject: [PATCH 1/6] pstore: Add lz4hc and 842 compression support Currently, pstore has supported three compression algorithms: zlib, lzo and lz4. This patch added two more compression algorithms: lz4hc and 842. Signed-off-by: Geliang Tang [kees: tweaked Kconfig help text slightly] Signed-off-by: Kees Cook --- fs/pstore/Kconfig | 20 ++++++ fs/pstore/platform.c | 155 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 153 insertions(+), 22 deletions(-) diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig index b42e5bd6d8ff..898abafea7a5 100644 --- a/fs/pstore/Kconfig +++ b/fs/pstore/Kconfig @@ -19,6 +19,11 @@ choice help This option chooses compression algorithm. + Currently, pstore has support for 5 compression algorithms: + zlib, lzo, lz4, lz4hc and 842. + + The default compression algorithm is zlib. + config PSTORE_ZLIB_COMPRESS bool "ZLIB" select ZLIB_DEFLATE @@ -39,6 +44,21 @@ config PSTORE_LZ4_COMPRESS select LZ4_DECOMPRESS help This option enables LZ4 compression algorithm support. + +config PSTORE_LZ4HC_COMPRESS + bool "LZ4HC" + select LZ4HC_COMPRESS + select LZ4_DECOMPRESS + help + This option enables LZ4HC (high compression) mode algorithm. + +config PSTORE_842_COMPRESS + bool "842" + select 842_COMPRESS + select 842_DECOMPRESS + help + This option enables 842 compression algorithm support. + endchoice config PSTORE_CONSOLE diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index c3129b131e4d..19aaefeb052f 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -34,9 +34,12 @@ #ifdef CONFIG_PSTORE_LZO_COMPRESS #include #endif -#ifdef CONFIG_PSTORE_LZ4_COMPRESS +#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || defined(CONFIG_PSTORE_LZ4HC_COMPRESS) #include #endif +#ifdef CONFIG_PSTORE_842_COMPRESS +#include +#endif #include #include #include @@ -336,20 +339,7 @@ static const struct pstore_zbackend backend_lzo = { }; #endif -#ifdef CONFIG_PSTORE_LZ4_COMPRESS -static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen) -{ - int ret; - - ret = LZ4_compress_default(in, out, inlen, outlen, workspace); - if (!ret) { - pr_err("LZ4_compress_default error; compression failed!\n"); - return -EIO; - } - - return ret; -} - +#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || defined(CONFIG_PSTORE_LZ4HC_COMPRESS) static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen) { int ret; @@ -367,6 +357,29 @@ static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen) return ret; } +static void free_lz4(void) +{ + kfree(workspace); + kfree(big_oops_buf); + big_oops_buf = NULL; + big_oops_buf_sz = 0; +} +#endif + +#ifdef CONFIG_PSTORE_LZ4_COMPRESS +static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen) +{ + int ret; + + ret = LZ4_compress_default(in, out, inlen, outlen, workspace); + if (!ret) { + pr_err("LZ4_compress_default error; compression failed!\n"); + return -EIO; + } + + return ret; +} + static void allocate_lz4(void) { big_oops_buf_sz = LZ4_compressBound(psinfo->bufsize); @@ -384,7 +397,101 @@ static void allocate_lz4(void) } } -static void free_lz4(void) +static const struct pstore_zbackend backend_lz4 = { + .compress = compress_lz4, + .decompress = decompress_lz4, + .allocate = allocate_lz4, + .free = free_lz4, + .name = "lz4", +}; +#endif + +#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS +static int compress_lz4hc(const void *in, void *out, + size_t inlen, size_t outlen) +{ + int ret; + + ret = LZ4_compress_HC(in, out, inlen, outlen, + LZ4HC_DEFAULT_CLEVEL, workspace); + if (!ret) { + pr_err("LZ4_compress_HC error; compression failed!\n"); + return -EIO; + } + + return ret; +} + +static void allocate_lz4hc(void) +{ + big_oops_buf_sz = LZ4_compressBound(psinfo->bufsize); + big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); + if (big_oops_buf) { + workspace = kmalloc(LZ4HC_MEM_COMPRESS, GFP_KERNEL); + if (!workspace) { + pr_err("No memory for compression workspace; skipping compression\n"); + kfree(big_oops_buf); + big_oops_buf = NULL; + } + } else { + pr_err("No memory for uncompressed data; skipping compression\n"); + workspace = NULL; + } +} + +static const struct pstore_zbackend backend_lz4hc = { + .compress = compress_lz4hc, + .decompress = decompress_lz4, + .allocate = allocate_lz4hc, + .free = free_lz4, + .name = "lz4hc", +}; +#endif + +#ifdef CONFIG_PSTORE_842_COMPRESS +static int compress_842(const void *in, void *out, size_t inlen, size_t outlen) +{ + int ret; + + ret = sw842_compress(in, inlen, out, (unsigned int *)&outlen, workspace); + if (ret) { + pr_err("sw842_compress error; compression failed!\n"); + return ret; + } + + return outlen; +} + +static int decompress_842(void *in, void *out, size_t inlen, size_t outlen) +{ + int ret; + + ret = sw842_decompress(in, inlen, out, (unsigned int *)&outlen); + if (ret) { + pr_err("sw842_decompress error, ret = %d!\n", ret); + return ret; + } + + return outlen; +} + +static void allocate_842(void) +{ + big_oops_buf_sz = psinfo->bufsize; + big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); + if (big_oops_buf) { + workspace = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL); + if (!workspace) { + kfree(big_oops_buf); + big_oops_buf = NULL; + } + } else { + pr_err("No memory for uncompressed data; skipping compression\n"); + workspace = NULL; + } +} + +static void free_842(void) { kfree(workspace); kfree(big_oops_buf); @@ -392,12 +499,12 @@ static void free_lz4(void) big_oops_buf_sz = 0; } -static const struct pstore_zbackend backend_lz4 = { - .compress = compress_lz4, - .decompress = decompress_lz4, - .allocate = allocate_lz4, - .free = free_lz4, - .name = "lz4", +static const struct pstore_zbackend backend_842 = { + .compress = compress_842, + .decompress = decompress_842, + .allocate = allocate_842, + .free = free_842, + .name = "842", }; #endif @@ -408,6 +515,10 @@ static const struct pstore_zbackend *zbackend = &backend_lzo; #elif defined(CONFIG_PSTORE_LZ4_COMPRESS) &backend_lz4; +#elif defined(CONFIG_PSTORE_LZ4HC_COMPRESS) + &backend_lz4hc; +#elif defined(CONFIG_PSTORE_842_COMPRESS) + &backend_842; #else NULL; #endif From 555974068ee533e8e0c6093ec7ca1682057aa4c1 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Tue, 6 Mar 2018 15:15:24 -0800 Subject: [PATCH 2/6] pstore: Avoid size casts for 842 compression Instead of casting, make sure we don't end up with giant values and just perform regular assignments with unsigned int instead of re-cast size_t. Signed-off-by: Kees Cook --- fs/pstore/platform.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 19aaefeb052f..df54dd87598a 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -452,27 +452,37 @@ static const struct pstore_zbackend backend_lz4hc = { static int compress_842(const void *in, void *out, size_t inlen, size_t outlen) { int ret; + unsigned int size; - ret = sw842_compress(in, inlen, out, (unsigned int *)&outlen, workspace); + if (outlen > UINT_MAX) + return -EIO; + size = outlen; + + ret = sw842_compress(in, inlen, out, &size, workspace); if (ret) { pr_err("sw842_compress error; compression failed!\n"); return ret; } - return outlen; + return size; } static int decompress_842(void *in, void *out, size_t inlen, size_t outlen) { int ret; + unsigned int size; - ret = sw842_decompress(in, inlen, out, (unsigned int *)&outlen); + if (outlen > UINT_MAX) + return -EIO; + size = outlen; + + ret = sw842_decompress(in, inlen, out, &size); if (ret) { pr_err("sw842_decompress error, ret = %d!\n", ret); return ret; } - return outlen; + return size; } static void allocate_842(void) From fe1d475888eecf1319458ee916e642e3e5e41c28 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Tue, 6 Mar 2018 15:57:38 -0800 Subject: [PATCH 3/6] pstore: Select compression at runtime To allow for easier build test coverage and run-time testing, this allows multiple compression algorithms to be built into pstore. Still only one is supported to operate at a time (which can be selected at build time or at boot time, similar to how LSMs are selected). Signed-off-by: Kees Cook --- fs/pstore/Kconfig | 96 +++++++++++++++++++++--------- fs/pstore/inode.c | 2 + fs/pstore/internal.h | 3 + fs/pstore/platform.c | 136 +++++++++++++++++++++++++------------------ 4 files changed, 152 insertions(+), 85 deletions(-) diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig index 898abafea7a5..e4e22026c7a1 100644 --- a/fs/pstore/Kconfig +++ b/fs/pstore/Kconfig @@ -12,55 +12,93 @@ config PSTORE If you don't have a platform persistent store driver, say N. -choice - prompt "Choose compression algorithm" - depends on PSTORE - default PSTORE_ZLIB_COMPRESS - help - This option chooses compression algorithm. - - Currently, pstore has support for 5 compression algorithms: - zlib, lzo, lz4, lz4hc and 842. - - The default compression algorithm is zlib. - config PSTORE_ZLIB_COMPRESS - bool "ZLIB" - select ZLIB_DEFLATE - select ZLIB_INFLATE - help - This option enables ZLIB compression algorithm support. + bool "ZLIB compression" + default y + depends on PSTORE + select ZLIB_DEFLATE + select ZLIB_INFLATE + help + This option enables ZLIB compression algorithm support. config PSTORE_LZO_COMPRESS - bool "LZO" - select LZO_COMPRESS - select LZO_DECOMPRESS - help - This option enables LZO compression algorithm support. + bool "LZO compression" + depends on PSTORE + select LZO_COMPRESS + select LZO_DECOMPRESS + help + This option enables LZO compression algorithm support. config PSTORE_LZ4_COMPRESS - bool "LZ4" - select LZ4_COMPRESS - select LZ4_DECOMPRESS - help - This option enables LZ4 compression algorithm support. + bool "LZ4 compression" + depends on PSTORE + select LZ4_COMPRESS + select LZ4_DECOMPRESS + help + This option enables LZ4 compression algorithm support. config PSTORE_LZ4HC_COMPRESS - bool "LZ4HC" + bool "LZ4HC compression" + depends on PSTORE select LZ4HC_COMPRESS select LZ4_DECOMPRESS help This option enables LZ4HC (high compression) mode algorithm. config PSTORE_842_COMPRESS - bool "842" + bool "842 compression" + depends on PSTORE select 842_COMPRESS select 842_DECOMPRESS help This option enables 842 compression algorithm support. +config PSTORE_COMPRESS + def_bool y + depends on PSTORE + depends on PSTORE_ZLIB_COMPRESS || PSTORE_LZO_COMPRESS || \ + PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS || \ + PSTORE_842_COMPRESS + +choice + prompt "Default pstore compression algorithm" + depends on PSTORE_COMPRESS + help + This option chooses the default active compression algorithm. + This change be changed at boot with "pstore.compress=..." on + the kernel command line. + + Currently, pstore has support for 5 compression algorithms: + zlib, lzo, lz4, lz4hc and 842. + + The default compression algorithm is zlib. + + config PSTORE_ZLIB_COMPRESS_DEFAULT + bool "zlib" if PSTORE_ZLIB_COMPRESS=y + + config PSTORE_LZO_COMPRESS_DEFAULT + bool "lzo" if PSTORE_LZO_COMPRESS=y + + config PSTORE_LZ4_COMPRESS_DEFAULT + bool "lz4" if PSTORE_LZ4_COMPRESS=y + + config PSTORE_LZ4HC_COMPRESS_DEFAULT + bool "lz4hc" if PSTORE_LZ4HC_COMPRESS=y + + config PSTORE_842_COMPRESS_DEFAULT + bool "842" if PSTORE_842_COMPRESS=y + endchoice +config PSTORE_COMPRESS_DEFAULT + string + depends on PSTORE_COMPRESS + default "zlib" if PSTORE_ZLIB_COMPRESS_DEFAULT + default "lzo" if PSTORE_LZO_COMPRESS_DEFAULT + default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT + default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT + default "842" if PSTORE_842_COMPRESS_DEFAULT + config PSTORE_CONSOLE bool "Log kernel console messages" depends on PSTORE diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index d814723fb27d..5fcb845b9fec 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -486,6 +486,8 @@ static int __init init_pstore_fs(void) { int err; + pstore_choose_compression(); + /* Create a convenient mount point for people to access pstore */ err = sysfs_create_mount_point(fs_kobj, "pstore"); if (err) diff --git a/fs/pstore/internal.h b/fs/pstore/internal.h index c029314478fa..fb767e28aeb2 100644 --- a/fs/pstore/internal.h +++ b/fs/pstore/internal.h @@ -37,4 +37,7 @@ extern bool pstore_is_mounted(void); extern void pstore_record_init(struct pstore_record *record, struct pstore_info *psi); +/* Called during module_init() */ +extern void __init pstore_choose_compression(void); + #endif diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index df54dd87598a..06e3b280c3a5 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -77,6 +77,12 @@ static DEFINE_SPINLOCK(pstore_lock); struct pstore_info *psinfo; static char *backend; +static char *compress = +#ifdef CONFIG_PSTORE_COMPRESS_DEFAULT + CONFIG_PSTORE_COMPRESS_DEFAULT; +#else + NULL; +#endif /* Compression parameters */ #ifdef CONFIG_PSTORE_ZLIB_COMPRESS @@ -84,7 +90,11 @@ static char *backend; #define WINDOW_BITS 12 #define MEM_LEVEL 4 static struct z_stream_s stream; -#else +#endif +#if defined(CONFIG_PSTORE_LZO_COMPRESS) || \ + defined(CONFIG_PSTORE_LZ4_COMPRESS) || \ + defined(CONFIG_PSTORE_LZ4HC_COMPRESS) || \ + defined(CONFIG_PSTORE_842_COMPRESS) static unsigned char *workspace; #endif @@ -268,14 +278,6 @@ static void free_zlib(void) big_oops_buf = NULL; big_oops_buf_sz = 0; } - -static const struct pstore_zbackend backend_zlib = { - .compress = compress_zlib, - .decompress = decompress_zlib, - .allocate = allocate_zlib, - .free = free_zlib, - .name = "zlib", -}; #endif #ifdef CONFIG_PSTORE_LZO_COMPRESS @@ -329,14 +331,6 @@ static void free_lzo(void) big_oops_buf = NULL; big_oops_buf_sz = 0; } - -static const struct pstore_zbackend backend_lzo = { - .compress = compress_lzo, - .decompress = decompress_lzo, - .allocate = allocate_lzo, - .free = free_lzo, - .name = "lzo", -}; #endif #if defined(CONFIG_PSTORE_LZ4_COMPRESS) || defined(CONFIG_PSTORE_LZ4HC_COMPRESS) @@ -396,14 +390,6 @@ static void allocate_lz4(void) workspace = NULL; } } - -static const struct pstore_zbackend backend_lz4 = { - .compress = compress_lz4, - .decompress = decompress_lz4, - .allocate = allocate_lz4, - .free = free_lz4, - .name = "lz4", -}; #endif #ifdef CONFIG_PSTORE_LZ4HC_COMPRESS @@ -438,14 +424,6 @@ static void allocate_lz4hc(void) workspace = NULL; } } - -static const struct pstore_zbackend backend_lz4hc = { - .compress = compress_lz4hc, - .decompress = decompress_lz4, - .allocate = allocate_lz4hc, - .free = free_lz4, - .name = "lz4hc", -}; #endif #ifdef CONFIG_PSTORE_842_COMPRESS @@ -508,30 +486,58 @@ static void free_842(void) big_oops_buf = NULL; big_oops_buf_sz = 0; } +#endif -static const struct pstore_zbackend backend_842 = { - .compress = compress_842, - .decompress = decompress_842, - .allocate = allocate_842, - .free = free_842, - .name = "842", +static const struct pstore_zbackend *zbackend __ro_after_init; + +static const struct pstore_zbackend zbackends[] = { +#ifdef CONFIG_PSTORE_ZLIB_COMPRESS + { + .compress = compress_zlib, + .decompress = decompress_zlib, + .allocate = allocate_zlib, + .free = free_zlib, + .name = "zlib", + }, +#endif +#ifdef CONFIG_PSTORE_LZO_COMPRESS + { + .compress = compress_lzo, + .decompress = decompress_lzo, + .allocate = allocate_lzo, + .free = free_lzo, + .name = "lzo", + }, +#endif +#ifdef CONFIG_PSTORE_LZ4_COMPRESS + { + .compress = compress_lz4, + .decompress = decompress_lz4, + .allocate = allocate_lz4, + .free = free_lz4, + .name = "lz4", + }, +#endif +#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS + { + .compress = compress_lz4hc, + .decompress = decompress_lz4, + .allocate = allocate_lz4hc, + .free = free_lz4, + .name = "lz4hc", + }, +#endif +#ifdef CONFIG_PSTORE_842_COMPRESS + { + .compress = compress_842, + .decompress = decompress_842, + .allocate = allocate_842, + .free = free_842, + .name = "842", + }, +#endif + { } }; -#endif - -static const struct pstore_zbackend *zbackend = -#if defined(CONFIG_PSTORE_ZLIB_COMPRESS) - &backend_zlib; -#elif defined(CONFIG_PSTORE_LZO_COMPRESS) - &backend_lzo; -#elif defined(CONFIG_PSTORE_LZ4_COMPRESS) - &backend_lz4; -#elif defined(CONFIG_PSTORE_LZ4HC_COMPRESS) - &backend_lz4hc; -#elif defined(CONFIG_PSTORE_842_COMPRESS) - &backend_842; -#else - NULL; -#endif static int pstore_compress(const void *in, void *out, size_t inlen, size_t outlen) @@ -553,7 +559,6 @@ static int pstore_decompress(void *in, void *out, size_t inlen, size_t outlen) static void allocate_buf_for_compression(void) { if (zbackend) { - pr_info("using %s compression\n", zbackend->name); zbackend->allocate(); } else { pr_err("allocate compression buffer error!\n"); @@ -1022,5 +1027,24 @@ static void pstore_timefunc(struct timer_list *unused) jiffies + msecs_to_jiffies(pstore_update_ms)); } +void __init pstore_choose_compression(void) +{ + const struct pstore_zbackend *step; + + if (!compress) + return; + + for (step = zbackends; step->name; step++) { + if (!strcmp(compress, step->name)) { + zbackend = step; + pr_info("using %s compression\n", zbackend->name); + return; + } + } +} + +module_param(compress, charp, 0444); +MODULE_PARM_DESC(compress, "Pstore compression to use"); + module_param(backend, charp, 0444); MODULE_PARM_DESC(backend, "Pstore backend to use"); From f2531f1976d98a7a4328da7f3cbf31b7c1927738 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Wed, 7 Mar 2018 12:18:33 -0800 Subject: [PATCH 4/6] pstore/ram: Do not use stack VLA for parity workspace Instead of using a stack VLA for the parity workspace, preallocate a memory region. The preallocation is done to keep from needing to perform allocations during crash dump writing, etc. This also fixes a missed release of librs on free. Signed-off-by: Kees Cook --- fs/pstore/ram_core.c | 29 ++++++++++++++++++++++------- include/linux/pstore_ram.h | 1 + 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index e11672aa4575..951a14edcf51 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -98,24 +98,23 @@ static void notrace persistent_ram_encode_rs8(struct persistent_ram_zone *prz, uint8_t *data, size_t len, uint8_t *ecc) { int i; - uint16_t par[prz->ecc_info.ecc_size]; /* Initialize the parity buffer */ - memset(par, 0, sizeof(par)); - encode_rs8(prz->rs_decoder, data, len, par, 0); + memset(prz->ecc_info.par, 0, + prz->ecc_info.ecc_size * sizeof(prz->ecc_info.par[0])); + encode_rs8(prz->rs_decoder, data, len, prz->ecc_info.par, 0); for (i = 0; i < prz->ecc_info.ecc_size; i++) - ecc[i] = par[i]; + ecc[i] = prz->ecc_info.par[i]; } static int persistent_ram_decode_rs8(struct persistent_ram_zone *prz, void *data, size_t len, uint8_t *ecc) { int i; - uint16_t par[prz->ecc_info.ecc_size]; for (i = 0; i < prz->ecc_info.ecc_size; i++) - par[i] = ecc[i]; - return decode_rs8(prz->rs_decoder, data, par, len, + prz->ecc_info.par[i] = ecc[i]; + return decode_rs8(prz->rs_decoder, data, prz->ecc_info.par, len, NULL, 0, NULL, 0, NULL); } @@ -228,6 +227,15 @@ static int persistent_ram_init_ecc(struct persistent_ram_zone *prz, return -EINVAL; } + /* allocate workspace instead of using stack VLA */ + prz->ecc_info.par = kmalloc_array(prz->ecc_info.ecc_size, + sizeof(*prz->ecc_info.par), + GFP_KERNEL); + if (!prz->ecc_info.par) { + pr_err("cannot allocate ECC parity workspace\n"); + return -ENOMEM; + } + prz->corrected_bytes = 0; prz->bad_blocks = 0; @@ -514,6 +522,13 @@ void persistent_ram_free(struct persistent_ram_zone *prz) } prz->vaddr = NULL; } + if (prz->rs_decoder) { + free_rs(prz->rs_decoder); + prz->rs_decoder = NULL; + } + kfree(prz->ecc_info.par); + prz->ecc_info.par = NULL; + persistent_ram_free_old(prz); kfree(prz); } diff --git a/include/linux/pstore_ram.h b/include/linux/pstore_ram.h index 9395f06e8372..e6d226464838 100644 --- a/include/linux/pstore_ram.h +++ b/include/linux/pstore_ram.h @@ -39,6 +39,7 @@ struct persistent_ram_ecc_info { int ecc_size; int symsize; int poly; + uint16_t *par; }; struct persistent_ram_zone { From cb3bee0369bc9316e47f4ad95a3c33f4e0d50a06 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Fri, 9 Mar 2018 18:51:07 +0800 Subject: [PATCH 5/6] pstore: Use crypto compress API In the pstore compression part, we use zlib/lzo/lz4/lz4hc/842 compression algorithm API to implement pstore compression backends. But there are many repeat codes in these implementations. This patch uses crypto compress API to simplify these codes. 1) rewrite allocate_buf_for_compression, free_buf_for_compression, pstore_compress, pstore_decompress functions using crypto compress API. 2) drop compress, decompress, allocate, free functions in pstore_zbackend, and add zbufsize function to get each different compress buffer size. 3) use late_initcall to call ramoops_init later, to make sure the crypto subsystem has already initialized. 4) use 'unsigned int' type instead of 'size_t' in pstore_compress, pstore_decompress functions' length arguments. 5) rename 'zlib' to 'deflate' to follow the crypto API's name convention. Signed-off-by: Geliang Tang [kees: tweaked error messages on allocation failures and Kconfig help] Signed-off-by: Kees Cook --- fs/pstore/Kconfig | 34 ++-- fs/pstore/platform.c | 415 +++++++------------------------------------ fs/pstore/ram.c | 2 +- 3 files changed, 84 insertions(+), 367 deletions(-) diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig index e4e22026c7a1..49b407eab846 100644 --- a/fs/pstore/Kconfig +++ b/fs/pstore/Kconfig @@ -12,51 +12,47 @@ config PSTORE If you don't have a platform persistent store driver, say N. -config PSTORE_ZLIB_COMPRESS - bool "ZLIB compression" +config PSTORE_DEFLATE_COMPRESS + bool "DEFLATE (ZLIB) compression" default y depends on PSTORE - select ZLIB_DEFLATE - select ZLIB_INFLATE + select CRYPTO_DEFLATE help - This option enables ZLIB compression algorithm support. + This option enables DEFLATE (also known as ZLIB) compression + algorithm support. config PSTORE_LZO_COMPRESS bool "LZO compression" depends on PSTORE - select LZO_COMPRESS - select LZO_DECOMPRESS + select CRYPTO_LZO help This option enables LZO compression algorithm support. config PSTORE_LZ4_COMPRESS bool "LZ4 compression" depends on PSTORE - select LZ4_COMPRESS - select LZ4_DECOMPRESS + select CRYPTO_LZ4 help This option enables LZ4 compression algorithm support. config PSTORE_LZ4HC_COMPRESS bool "LZ4HC compression" depends on PSTORE - select LZ4HC_COMPRESS - select LZ4_DECOMPRESS + select CRYPTO_LZ4HC help This option enables LZ4HC (high compression) mode algorithm. config PSTORE_842_COMPRESS bool "842 compression" depends on PSTORE - select 842_COMPRESS - select 842_DECOMPRESS + select CRYPTO_842 help This option enables 842 compression algorithm support. config PSTORE_COMPRESS def_bool y depends on PSTORE - depends on PSTORE_ZLIB_COMPRESS || PSTORE_LZO_COMPRESS || \ + depends on PSTORE_DEFLATE_COMPRESS || PSTORE_LZO_COMPRESS || \ PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS || \ PSTORE_842_COMPRESS @@ -69,12 +65,12 @@ choice the kernel command line. Currently, pstore has support for 5 compression algorithms: - zlib, lzo, lz4, lz4hc and 842. + deflate, lzo, lz4, lz4hc and 842. - The default compression algorithm is zlib. + The default compression algorithm is deflate. - config PSTORE_ZLIB_COMPRESS_DEFAULT - bool "zlib" if PSTORE_ZLIB_COMPRESS=y + config PSTORE_DEFLATE_COMPRESS_DEFAULT + bool "deflate" if PSTORE_DEFLATE_COMPRESS=y config PSTORE_LZO_COMPRESS_DEFAULT bool "lzo" if PSTORE_LZO_COMPRESS=y @@ -93,7 +89,7 @@ endchoice config PSTORE_COMPRESS_DEFAULT string depends on PSTORE_COMPRESS - default "zlib" if PSTORE_ZLIB_COMPRESS_DEFAULT + default "deflate" if PSTORE_DEFLATE_COMPRESS_DEFAULT default "lzo" if PSTORE_LZO_COMPRESS_DEFAULT default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 06e3b280c3a5..42e111b3bd0c 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -28,18 +28,13 @@ #include #include #include -#ifdef CONFIG_PSTORE_ZLIB_COMPRESS -#include -#endif #ifdef CONFIG_PSTORE_LZO_COMPRESS #include #endif #if defined(CONFIG_PSTORE_LZ4_COMPRESS) || defined(CONFIG_PSTORE_LZ4HC_COMPRESS) #include #endif -#ifdef CONFIG_PSTORE_842_COMPRESS -#include -#endif +#include #include #include #include @@ -85,25 +80,10 @@ static char *compress = #endif /* Compression parameters */ -#ifdef CONFIG_PSTORE_ZLIB_COMPRESS -#define COMPR_LEVEL 6 -#define WINDOW_BITS 12 -#define MEM_LEVEL 4 -static struct z_stream_s stream; -#endif -#if defined(CONFIG_PSTORE_LZO_COMPRESS) || \ - defined(CONFIG_PSTORE_LZ4_COMPRESS) || \ - defined(CONFIG_PSTORE_LZ4HC_COMPRESS) || \ - defined(CONFIG_PSTORE_842_COMPRESS) -static unsigned char *workspace; -#endif +static struct crypto_comp *tfm; struct pstore_zbackend { - int (*compress)(const void *in, void *out, size_t inlen, size_t outlen); - int (*decompress)(void *in, void *out, size_t inlen, size_t outlen); - void (*allocate)(void); - void (*free)(void); - + int (*zbufsize)(size_t size); const char *name; }; @@ -162,77 +142,12 @@ bool pstore_cannot_block_path(enum kmsg_dump_reason reason) } EXPORT_SYMBOL_GPL(pstore_cannot_block_path); -#ifdef CONFIG_PSTORE_ZLIB_COMPRESS -/* Derived from logfs_compress() */ -static int compress_zlib(const void *in, void *out, size_t inlen, size_t outlen) +#ifdef CONFIG_PSTORE_DEFLATE_COMPRESS +static int zbufsize_deflate(size_t size) { - int err, ret; - - ret = -EIO; - err = zlib_deflateInit2(&stream, COMPR_LEVEL, Z_DEFLATED, WINDOW_BITS, - MEM_LEVEL, Z_DEFAULT_STRATEGY); - if (err != Z_OK) - goto error; - - stream.next_in = in; - stream.avail_in = inlen; - stream.total_in = 0; - stream.next_out = out; - stream.avail_out = outlen; - stream.total_out = 0; - - err = zlib_deflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) - goto error; - - err = zlib_deflateEnd(&stream); - if (err != Z_OK) - goto error; - - if (stream.total_out >= stream.total_in) - goto error; - - ret = stream.total_out; -error: - return ret; -} - -/* Derived from logfs_uncompress */ -static int decompress_zlib(void *in, void *out, size_t inlen, size_t outlen) -{ - int err, ret; - - ret = -EIO; - err = zlib_inflateInit2(&stream, WINDOW_BITS); - if (err != Z_OK) - goto error; - - stream.next_in = in; - stream.avail_in = inlen; - stream.total_in = 0; - stream.next_out = out; - stream.avail_out = outlen; - stream.total_out = 0; - - err = zlib_inflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) - goto error; - - err = zlib_inflateEnd(&stream); - if (err != Z_OK) - goto error; - - ret = stream.total_out; -error: - return ret; -} - -static void allocate_zlib(void) -{ - size_t size; size_t cmpr; - switch (psinfo->bufsize) { + switch (size) { /* buffer range for efivars */ case 1000 ... 2000: cmpr = 56; @@ -252,287 +167,61 @@ static void allocate_zlib(void) break; } - big_oops_buf_sz = (psinfo->bufsize * 100) / cmpr; - big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); - if (big_oops_buf) { - size = max(zlib_deflate_workspacesize(WINDOW_BITS, MEM_LEVEL), - zlib_inflate_workspacesize()); - stream.workspace = kmalloc(size, GFP_KERNEL); - if (!stream.workspace) { - pr_err("No memory for compression workspace; skipping compression\n"); - kfree(big_oops_buf); - big_oops_buf = NULL; - } - } else { - pr_err("No memory for uncompressed data; skipping compression\n"); - stream.workspace = NULL; - } - -} - -static void free_zlib(void) -{ - kfree(stream.workspace); - stream.workspace = NULL; - kfree(big_oops_buf); - big_oops_buf = NULL; - big_oops_buf_sz = 0; + return (size * 100) / cmpr; } #endif #ifdef CONFIG_PSTORE_LZO_COMPRESS -static int compress_lzo(const void *in, void *out, size_t inlen, size_t outlen) +static int zbufsize_lzo(size_t size) { - int ret; - - ret = lzo1x_1_compress(in, inlen, out, &outlen, workspace); - if (ret != LZO_E_OK) { - pr_err("lzo_compress error, ret = %d!\n", ret); - return -EIO; - } - - return outlen; -} - -static int decompress_lzo(void *in, void *out, size_t inlen, size_t outlen) -{ - int ret; - - ret = lzo1x_decompress_safe(in, inlen, out, &outlen); - if (ret != LZO_E_OK) { - pr_err("lzo_decompress error, ret = %d!\n", ret); - return -EIO; - } - - return outlen; -} - -static void allocate_lzo(void) -{ - big_oops_buf_sz = lzo1x_worst_compress(psinfo->bufsize); - big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); - if (big_oops_buf) { - workspace = kmalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); - if (!workspace) { - pr_err("No memory for compression workspace; skipping compression\n"); - kfree(big_oops_buf); - big_oops_buf = NULL; - } - } else { - pr_err("No memory for uncompressed data; skipping compression\n"); - workspace = NULL; - } -} - -static void free_lzo(void) -{ - kfree(workspace); - kfree(big_oops_buf); - big_oops_buf = NULL; - big_oops_buf_sz = 0; + return lzo1x_worst_compress(size); } #endif #if defined(CONFIG_PSTORE_LZ4_COMPRESS) || defined(CONFIG_PSTORE_LZ4HC_COMPRESS) -static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen) +static int zbufsize_lz4(size_t size) { - int ret; - - ret = LZ4_decompress_safe(in, out, inlen, outlen); - if (ret < 0) { - /* - * LZ4_decompress_safe will return an error code - * (< 0) if decompression failed - */ - pr_err("LZ4_decompress_safe error, ret = %d!\n", ret); - return -EIO; - } - - return ret; -} - -static void free_lz4(void) -{ - kfree(workspace); - kfree(big_oops_buf); - big_oops_buf = NULL; - big_oops_buf_sz = 0; -} -#endif - -#ifdef CONFIG_PSTORE_LZ4_COMPRESS -static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen) -{ - int ret; - - ret = LZ4_compress_default(in, out, inlen, outlen, workspace); - if (!ret) { - pr_err("LZ4_compress_default error; compression failed!\n"); - return -EIO; - } - - return ret; -} - -static void allocate_lz4(void) -{ - big_oops_buf_sz = LZ4_compressBound(psinfo->bufsize); - big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); - if (big_oops_buf) { - workspace = kmalloc(LZ4_MEM_COMPRESS, GFP_KERNEL); - if (!workspace) { - pr_err("No memory for compression workspace; skipping compression\n"); - kfree(big_oops_buf); - big_oops_buf = NULL; - } - } else { - pr_err("No memory for uncompressed data; skipping compression\n"); - workspace = NULL; - } -} -#endif - -#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS -static int compress_lz4hc(const void *in, void *out, - size_t inlen, size_t outlen) -{ - int ret; - - ret = LZ4_compress_HC(in, out, inlen, outlen, - LZ4HC_DEFAULT_CLEVEL, workspace); - if (!ret) { - pr_err("LZ4_compress_HC error; compression failed!\n"); - return -EIO; - } - - return ret; -} - -static void allocate_lz4hc(void) -{ - big_oops_buf_sz = LZ4_compressBound(psinfo->bufsize); - big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); - if (big_oops_buf) { - workspace = kmalloc(LZ4HC_MEM_COMPRESS, GFP_KERNEL); - if (!workspace) { - pr_err("No memory for compression workspace; skipping compression\n"); - kfree(big_oops_buf); - big_oops_buf = NULL; - } - } else { - pr_err("No memory for uncompressed data; skipping compression\n"); - workspace = NULL; - } + return LZ4_compressBound(size); } #endif #ifdef CONFIG_PSTORE_842_COMPRESS -static int compress_842(const void *in, void *out, size_t inlen, size_t outlen) +static int zbufsize_842(size_t size) { - int ret; - unsigned int size; - - if (outlen > UINT_MAX) - return -EIO; - size = outlen; - - ret = sw842_compress(in, inlen, out, &size, workspace); - if (ret) { - pr_err("sw842_compress error; compression failed!\n"); - return ret; - } - return size; } - -static int decompress_842(void *in, void *out, size_t inlen, size_t outlen) -{ - int ret; - unsigned int size; - - if (outlen > UINT_MAX) - return -EIO; - size = outlen; - - ret = sw842_decompress(in, inlen, out, &size); - if (ret) { - pr_err("sw842_decompress error, ret = %d!\n", ret); - return ret; - } - - return size; -} - -static void allocate_842(void) -{ - big_oops_buf_sz = psinfo->bufsize; - big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); - if (big_oops_buf) { - workspace = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL); - if (!workspace) { - kfree(big_oops_buf); - big_oops_buf = NULL; - } - } else { - pr_err("No memory for uncompressed data; skipping compression\n"); - workspace = NULL; - } -} - -static void free_842(void) -{ - kfree(workspace); - kfree(big_oops_buf); - big_oops_buf = NULL; - big_oops_buf_sz = 0; -} #endif static const struct pstore_zbackend *zbackend __ro_after_init; static const struct pstore_zbackend zbackends[] = { -#ifdef CONFIG_PSTORE_ZLIB_COMPRESS +#ifdef CONFIG_PSTORE_DEFLATE_COMPRESS { - .compress = compress_zlib, - .decompress = decompress_zlib, - .allocate = allocate_zlib, - .free = free_zlib, - .name = "zlib", + .zbufsize = zbufsize_deflate, + .name = "deflate", }, #endif #ifdef CONFIG_PSTORE_LZO_COMPRESS { - .compress = compress_lzo, - .decompress = decompress_lzo, - .allocate = allocate_lzo, - .free = free_lzo, + .zbufsize = zbufsize_lzo, .name = "lzo", }, #endif #ifdef CONFIG_PSTORE_LZ4_COMPRESS { - .compress = compress_lz4, - .decompress = decompress_lz4, - .allocate = allocate_lz4, - .free = free_lz4, + .zbufsize = zbufsize_lz4, .name = "lz4", }, #endif #ifdef CONFIG_PSTORE_LZ4HC_COMPRESS { - .compress = compress_lz4hc, - .decompress = decompress_lz4, - .allocate = allocate_lz4hc, - .free = free_lz4, + .zbufsize = zbufsize_lz4, .name = "lz4hc", }, #endif #ifdef CONFIG_PSTORE_842_COMPRESS { - .compress = compress_842, - .decompress = decompress_842, - .allocate = allocate_842, - .free = free_842, + .zbufsize = zbufsize_842, .name = "842", }, #endif @@ -540,37 +229,69 @@ static const struct pstore_zbackend zbackends[] = { }; static int pstore_compress(const void *in, void *out, - size_t inlen, size_t outlen) + unsigned int inlen, unsigned int outlen) { - if (zbackend) - return zbackend->compress(in, out, inlen, outlen); - else - return -EIO; + int ret; + + ret = crypto_comp_compress(tfm, in, inlen, out, &outlen); + if (ret) { + pr_err("crypto_comp_compress failed, ret = %d!\n", ret); + return ret; + } + + return outlen; } -static int pstore_decompress(void *in, void *out, size_t inlen, size_t outlen) +static int pstore_decompress(void *in, void *out, + unsigned int inlen, unsigned int outlen) { - if (zbackend) - return zbackend->decompress(in, out, inlen, outlen); - else - return -EIO; + int ret; + + ret = crypto_comp_decompress(tfm, in, inlen, out, &outlen); + if (ret) { + pr_err("crypto_comp_decompress failed, ret = %d!\n", ret); + return ret; + } + + return outlen; } static void allocate_buf_for_compression(void) { - if (zbackend) { - zbackend->allocate(); - } else { + if (!zbackend) + return; + + if (!crypto_has_comp(zbackend->name, 0, 0)) { + pr_err("No %s compression\n", zbackend->name); + return; + } + + big_oops_buf_sz = zbackend->zbufsize(psinfo->bufsize); + if (big_oops_buf_sz <= 0) + return; + + big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); + if (!big_oops_buf) { pr_err("allocate compression buffer error!\n"); + return; + } + + tfm = crypto_alloc_comp(zbackend->name, 0, 0); + if (IS_ERR_OR_NULL(tfm)) { + kfree(big_oops_buf); + big_oops_buf = NULL; + pr_err("crypto_alloc_comp() failed!\n"); + return; } } static void free_buf_for_compression(void) { - if (zbackend) - zbackend->free(); - else - pr_err("free compression buffer error!\n"); + if (!IS_ERR_OR_NULL(tfm)) + crypto_free_comp(tfm); + kfree(big_oops_buf); + big_oops_buf = NULL; + big_oops_buf_sz = 0; } /* diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 7125b398d312..49b2bc114868 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -938,7 +938,7 @@ static int __init ramoops_init(void) ramoops_register_dummy(); return platform_driver_register(&ramoops_driver); } -postcore_initcall(ramoops_init); +late_initcall(ramoops_init); static void __exit ramoops_exit(void) { From 58eb5b6707477ff458db3ee522aac317da719e2a Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Thu, 15 Mar 2018 16:34:08 +0100 Subject: [PATCH 6/6] pstore: fix crypto dependencies The new crypto API use causes some problems with Kconfig dependencies, including this link error: fs/pstore/platform.o: In function `pstore_register': platform.c:(.text+0x248): undefined reference to `crypto_has_alg' platform.c:(.text+0x2a0): undefined reference to `crypto_alloc_base' fs/pstore/platform.o: In function `pstore_unregister': platform.c:(.text+0x498): undefined reference to `crypto_destroy_tfm' crypto/lz4hc.o: In function `lz4hc_sdecompress': lz4hc.c:(.text+0x1a): undefined reference to `LZ4_decompress_safe' crypto/lz4hc.o: In function `lz4hc_decompress_crypto': lz4hc.c:(.text+0x5a): undefined reference to `LZ4_decompress_safe' crypto/lz4hc.o: In function `lz4hc_scompress': lz4hc.c:(.text+0xaa): undefined reference to `LZ4_compress_HC' crypto/lz4hc.o: In function `lz4hc_mod_init': lz4hc.c:(.init.text+0xf): undefined reference to `crypto_register_alg' lz4hc.c:(.init.text+0x1f): undefined reference to `crypto_register_scomp' lz4hc.c:(.init.text+0x2f): undefined reference to `crypto_unregister_alg' The problem is that with CONFIG_CRYPTO=m, we must not 'select CRYPTO_LZ4' from a bool symbol, or call crypto API functions from a built-in module. This turns the sub-options into 'tristate' ones so the dependencies are honored, and makes the pstore itself select the crypto core if necessary. Fixes: cb3bee0369bc ("pstore: Use crypto compress API") Signed-off-by: Arnd Bergmann Signed-off-by: Kees Cook --- fs/pstore/Kconfig | 19 ++++++++++--------- fs/pstore/platform.c | 22 +++++++++++----------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig index 49b407eab846..09c19ef91526 100644 --- a/fs/pstore/Kconfig +++ b/fs/pstore/Kconfig @@ -1,5 +1,6 @@ config PSTORE tristate "Persistent store support" + select CRYPTO if PSTORE_COMPRESS default n help This option enables generic access to platform level @@ -13,7 +14,7 @@ config PSTORE say N. config PSTORE_DEFLATE_COMPRESS - bool "DEFLATE (ZLIB) compression" + tristate "DEFLATE (ZLIB) compression" default y depends on PSTORE select CRYPTO_DEFLATE @@ -22,21 +23,21 @@ config PSTORE_DEFLATE_COMPRESS algorithm support. config PSTORE_LZO_COMPRESS - bool "LZO compression" + tristate "LZO compression" depends on PSTORE select CRYPTO_LZO help This option enables LZO compression algorithm support. config PSTORE_LZ4_COMPRESS - bool "LZ4 compression" + tristate "LZ4 compression" depends on PSTORE select CRYPTO_LZ4 help This option enables LZ4 compression algorithm support. config PSTORE_LZ4HC_COMPRESS - bool "LZ4HC compression" + tristate "LZ4HC compression" depends on PSTORE select CRYPTO_LZ4HC help @@ -70,19 +71,19 @@ choice The default compression algorithm is deflate. config PSTORE_DEFLATE_COMPRESS_DEFAULT - bool "deflate" if PSTORE_DEFLATE_COMPRESS=y + bool "deflate" if PSTORE_DEFLATE_COMPRESS config PSTORE_LZO_COMPRESS_DEFAULT - bool "lzo" if PSTORE_LZO_COMPRESS=y + bool "lzo" if PSTORE_LZO_COMPRESS config PSTORE_LZ4_COMPRESS_DEFAULT - bool "lz4" if PSTORE_LZ4_COMPRESS=y + bool "lz4" if PSTORE_LZ4_COMPRESS config PSTORE_LZ4HC_COMPRESS_DEFAULT - bool "lz4hc" if PSTORE_LZ4HC_COMPRESS=y + bool "lz4hc" if PSTORE_LZ4HC_COMPRESS config PSTORE_842_COMPRESS_DEFAULT - bool "842" if PSTORE_842_COMPRESS=y + bool "842" if PSTORE_842_COMPRESS endchoice diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 42e111b3bd0c..1143ef351c58 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -28,10 +28,10 @@ #include #include #include -#ifdef CONFIG_PSTORE_LZO_COMPRESS +#if IS_ENABLED(CONFIG_PSTORE_LZO_COMPRESS) #include #endif -#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || defined(CONFIG_PSTORE_LZ4HC_COMPRESS) +#if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS) #include #endif #include @@ -142,7 +142,7 @@ bool pstore_cannot_block_path(enum kmsg_dump_reason reason) } EXPORT_SYMBOL_GPL(pstore_cannot_block_path); -#ifdef CONFIG_PSTORE_DEFLATE_COMPRESS +#if IS_ENABLED(CONFIG_PSTORE_DEFLATE_COMPRESS) static int zbufsize_deflate(size_t size) { size_t cmpr; @@ -171,21 +171,21 @@ static int zbufsize_deflate(size_t size) } #endif -#ifdef CONFIG_PSTORE_LZO_COMPRESS +#if IS_ENABLED(CONFIG_PSTORE_LZO_COMPRESS) static int zbufsize_lzo(size_t size) { return lzo1x_worst_compress(size); } #endif -#if defined(CONFIG_PSTORE_LZ4_COMPRESS) || defined(CONFIG_PSTORE_LZ4HC_COMPRESS) +#if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS) static int zbufsize_lz4(size_t size) { return LZ4_compressBound(size); } #endif -#ifdef CONFIG_PSTORE_842_COMPRESS +#if IS_ENABLED(CONFIG_PSTORE_842_COMPRESS) static int zbufsize_842(size_t size) { return size; @@ -195,31 +195,31 @@ static int zbufsize_842(size_t size) static const struct pstore_zbackend *zbackend __ro_after_init; static const struct pstore_zbackend zbackends[] = { -#ifdef CONFIG_PSTORE_DEFLATE_COMPRESS +#if IS_ENABLED(CONFIG_PSTORE_DEFLATE_COMPRESS) { .zbufsize = zbufsize_deflate, .name = "deflate", }, #endif -#ifdef CONFIG_PSTORE_LZO_COMPRESS +#if IS_ENABLED(CONFIG_PSTORE_LZO_COMPRESS) { .zbufsize = zbufsize_lzo, .name = "lzo", }, #endif -#ifdef CONFIG_PSTORE_LZ4_COMPRESS +#if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) { .zbufsize = zbufsize_lz4, .name = "lz4", }, #endif -#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS +#if IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS) { .zbufsize = zbufsize_lz4, .name = "lz4hc", }, #endif -#ifdef CONFIG_PSTORE_842_COMPRESS +#if IS_ENABLED(CONFIG_PSTORE_842_COMPRESS) { .zbufsize = zbufsize_842, .name = "842",