Commit 239b7161 authored by Geliang Tang's avatar Geliang Tang Committed by Kees Cook

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: default avatarGeliang Tang <geliangtang@gmail.com>
[kees: tweaked Kconfig help text slightly]
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent 91ab883e
...@@ -19,6 +19,11 @@ choice ...@@ -19,6 +19,11 @@ choice
help help
This option chooses compression algorithm. 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 config PSTORE_ZLIB_COMPRESS
bool "ZLIB" bool "ZLIB"
select ZLIB_DEFLATE select ZLIB_DEFLATE
...@@ -39,6 +44,21 @@ config PSTORE_LZ4_COMPRESS ...@@ -39,6 +44,21 @@ config PSTORE_LZ4_COMPRESS
select LZ4_DECOMPRESS select LZ4_DECOMPRESS
help help
This option enables LZ4 compression algorithm support. 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 endchoice
config PSTORE_CONSOLE config PSTORE_CONSOLE
......
...@@ -34,9 +34,12 @@ ...@@ -34,9 +34,12 @@
#ifdef CONFIG_PSTORE_LZO_COMPRESS #ifdef CONFIG_PSTORE_LZO_COMPRESS
#include <linux/lzo.h> #include <linux/lzo.h>
#endif #endif
#ifdef CONFIG_PSTORE_LZ4_COMPRESS #if defined(CONFIG_PSTORE_LZ4_COMPRESS) || defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
#include <linux/lz4.h> #include <linux/lz4.h>
#endif #endif
#ifdef CONFIG_PSTORE_842_COMPRESS
#include <linux/sw842.h>
#endif
#include <linux/string.h> #include <linux/string.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -336,6 +339,33 @@ static const struct pstore_zbackend backend_lzo = { ...@@ -336,6 +339,33 @@ static const struct pstore_zbackend backend_lzo = {
}; };
#endif #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)
{
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 #ifdef CONFIG_PSTORE_LZ4_COMPRESS
static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen) static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen)
{ {
...@@ -350,29 +380,54 @@ static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen) ...@@ -350,29 +380,54 @@ static int compress_lz4(const void *in, void *out, size_t inlen, size_t outlen)
return ret; return ret;
} }
static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen) 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;
}
}
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; int ret;
ret = LZ4_decompress_safe(in, out, inlen, outlen); ret = LZ4_compress_HC(in, out, inlen, outlen,
if (ret < 0) { LZ4HC_DEFAULT_CLEVEL, workspace);
/* if (!ret) {
* LZ4_decompress_safe will return an error code pr_err("LZ4_compress_HC error; compression failed!\n");
* (< 0) if decompression failed
*/
pr_err("LZ4_decompress_safe error, ret = %d!\n", ret);
return -EIO; return -EIO;
} }
return ret; return ret;
} }
static void allocate_lz4(void) static void allocate_lz4hc(void)
{ {
big_oops_buf_sz = LZ4_compressBound(psinfo->bufsize); big_oops_buf_sz = LZ4_compressBound(psinfo->bufsize);
big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL);
if (big_oops_buf) { if (big_oops_buf) {
workspace = kmalloc(LZ4_MEM_COMPRESS, GFP_KERNEL); workspace = kmalloc(LZ4HC_MEM_COMPRESS, GFP_KERNEL);
if (!workspace) { if (!workspace) {
pr_err("No memory for compression workspace; skipping compression\n"); pr_err("No memory for compression workspace; skipping compression\n");
kfree(big_oops_buf); kfree(big_oops_buf);
...@@ -384,7 +439,59 @@ static void allocate_lz4(void) ...@@ -384,7 +439,59 @@ static void allocate_lz4(void)
} }
} }
static void free_lz4(void) 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(workspace);
kfree(big_oops_buf); kfree(big_oops_buf);
...@@ -392,12 +499,12 @@ static void free_lz4(void) ...@@ -392,12 +499,12 @@ static void free_lz4(void)
big_oops_buf_sz = 0; big_oops_buf_sz = 0;
} }
static const struct pstore_zbackend backend_lz4 = { static const struct pstore_zbackend backend_842 = {
.compress = compress_lz4, .compress = compress_842,
.decompress = decompress_lz4, .decompress = decompress_842,
.allocate = allocate_lz4, .allocate = allocate_842,
.free = free_lz4, .free = free_842,
.name = "lz4", .name = "842",
}; };
#endif #endif
...@@ -408,6 +515,10 @@ static const struct pstore_zbackend *zbackend = ...@@ -408,6 +515,10 @@ static const struct pstore_zbackend *zbackend =
&backend_lzo; &backend_lzo;
#elif defined(CONFIG_PSTORE_LZ4_COMPRESS) #elif defined(CONFIG_PSTORE_LZ4_COMPRESS)
&backend_lz4; &backend_lz4;
#elif defined(CONFIG_PSTORE_LZ4HC_COMPRESS)
&backend_lz4hc;
#elif defined(CONFIG_PSTORE_842_COMPRESS)
&backend_842;
#else #else
NULL; NULL;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment