Re: [PATCH 7/8] lib/lzo: separate lzo-rle from lzo
On Fri, Nov 30, 2018 at 02:26:30PM +, Dave Rodgman wrote: > To prevent any issues with persistent data, separate lzo-rle > from lzo so that it is treated as a separate algorithm, and > lzo is still available. > > Link: http://lkml.kernel.org/r/20181127161913.23863-8-dave.rodg...@arm.com > Signed-off-by: Dave Rodgman > Cc: David S. Miller > Cc: Greg Kroah-Hartman > Cc: Herbert Xu > Cc: Markus F.X.J. Oberhumer > Cc: Matt Sealey > Cc: Minchan Kim > Cc: Nitin Gupta > Cc: Richard Purdie > Cc: Sergey Senozhatsky > Cc: Sonny Rao > Signed-off-by: Andrew Morton > Signed-off-by: Stephen Rothwell > Signed-off-by: Dave Rodgman > --- > Documentation/lzo.txt | 12 ++- > crypto/Makefile| 2 +- > crypto/lzo-rle.c | 175 + > crypto/tcrypt.c| 4 +- > drivers/block/zram/zcomp.c | 1 + > include/linux/lzo.h| 4 + > lib/lzo/lzo1x_compress.c | 42 +++-- > lib/lzo/lzodefs.h | 3 +- > 8 files changed, 226 insertions(+), 17 deletions(-) > create mode 100644 crypto/lzo-rle.c Acked-by: Herbert Xu Thanks, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
[PATCH 7/8] lib/lzo: separate lzo-rle from lzo
To prevent any issues with persistent data, separate lzo-rle from lzo so that it is treated as a separate algorithm, and lzo is still available. Link: http://lkml.kernel.org/r/20181127161913.23863-8-dave.rodg...@arm.com Signed-off-by: Dave Rodgman Cc: David S. Miller Cc: Greg Kroah-Hartman Cc: Herbert Xu Cc: Markus F.X.J. Oberhumer Cc: Matt Sealey Cc: Minchan Kim Cc: Nitin Gupta Cc: Richard Purdie Cc: Sergey Senozhatsky Cc: Sonny Rao Signed-off-by: Andrew Morton Signed-off-by: Stephen Rothwell Signed-off-by: Dave Rodgman --- Documentation/lzo.txt | 12 ++- crypto/Makefile| 2 +- crypto/lzo-rle.c | 175 + crypto/tcrypt.c| 4 +- drivers/block/zram/zcomp.c | 1 + include/linux/lzo.h| 4 + lib/lzo/lzo1x_compress.c | 42 +++-- lib/lzo/lzodefs.h | 3 +- 8 files changed, 226 insertions(+), 17 deletions(-) create mode 100644 crypto/lzo-rle.c diff --git a/Documentation/lzo.txt b/Documentation/lzo.txt index 306c60344ca7..f79934225d8d 100644 --- a/Documentation/lzo.txt +++ b/Documentation/lzo.txt @@ -88,6 +88,10 @@ length encoding. This improves speed for data with many zeros, which is a common case for zram. This modifies the bitstream in a backwards compatible way (v1 can correctly decompress v0 compressed data, but v0 cannot read v1 data). +For maximum compatibility, both versions are available under different names +(lzo and lzo-rle). Differences in the encoding are noted in this document with +e.g.: version 1 only. + Byte sequences == @@ -99,8 +103,8 @@ Byte sequences invalid at this place. 17 : bitstream version. If the first byte is 17, the next byte -gives the bitstream version. If the first byte is not 17, -the bitstream version is 0. +gives the bitstream version (version 1 only). If the first byte +is not 17, the bitstream version is 0. 18..21 : copy 0..3 literals state = (byte - 17) = 0..3 [ copy literals ] @@ -154,8 +158,8 @@ Byte sequences state = S (copy S literals after this block) End of stream is reached if distance == 16384 -In version 1, this instruction is also used to encode a run of zeros if -distance = 0xbfff, i.e. H = 1 and the D bits are all 1. +In version 1 only, this instruction is also used to encode a run of +zeros if distance = 0xbfff, i.e. H = 1 and the D bits are all 1. In this case, it is followed by a fourth byte, X. run length = ((X << 3) | (0 0 0 0 0 L L L)) + 4. diff --git a/crypto/Makefile b/crypto/Makefile index 5e789dc2d4fd..23491b70e601 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -127,7 +127,7 @@ obj-$(CONFIG_CRYPTO_CRC32C) += crc32c_generic.o obj-$(CONFIG_CRYPTO_CRC32) += crc32_generic.o obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif_common.o crct10dif_generic.o obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o -obj-$(CONFIG_CRYPTO_LZO) += lzo.o +obj-$(CONFIG_CRYPTO_LZO) += lzo.o lzo-rle.o obj-$(CONFIG_CRYPTO_LZ4) += lz4.o obj-$(CONFIG_CRYPTO_LZ4HC) += lz4hc.o obj-$(CONFIG_CRYPTO_842) += 842.o diff --git a/crypto/lzo-rle.c b/crypto/lzo-rle.c new file mode 100644 index ..ea9c75b1db49 --- /dev/null +++ b/crypto/lzo-rle.c @@ -0,0 +1,175 @@ +/* + * Cryptographic API. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include + +struct lzorle_ctx { + void *lzorle_comp_mem; +}; + +static void *lzorle_alloc_ctx(struct crypto_scomp *tfm) +{ + void *ctx; + + ctx = kvmalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); + if (!ctx) + return ERR_PTR(-ENOMEM); + + return ctx; +} + +static int lzorle_init(struct crypto_tfm *tfm) +{ + struct lzorle_ctx *ctx = crypto_tfm_ctx(tfm); + + ctx->lzorle_comp_mem = lzorle_alloc_ctx(NULL); + if (IS_ERR(ctx->lzorle_comp_mem)) + return -ENOMEM; + + return 0; +} + +static void lzorle_free_ctx(struct crypto_scomp *tfm, void *ctx) +{ + kvfree(ctx); +} + +static void lzorle_exit(struct crypto_tfm *tfm) +{ + struct lzorle_ctx *ctx = crypto_tfm_ctx(tfm); + + lzorle_free_ctx(NULL, ctx->lzorle_comp_mem); +} + +static
[PATCH 7/8] lib/lzo: separate lzo-rle from lzo
To prevent any issues with persistent data, separate lzo-rle from lzo so that it is treated as a separate algorithm, and lzo is still available. Link: http://lkml.kernel.org/r/20181127161913.23863-8-dave.rodg...@arm.com Signed-off-by: Dave Rodgman Cc: David S. Miller Cc: Greg Kroah-Hartman Cc: Herbert Xu Cc: Markus F.X.J. Oberhumer Cc: Matt Sealey Cc: Minchan Kim Cc: Nitin Gupta Cc: Richard Purdie Cc: Sergey Senozhatsky Cc: Sonny Rao Signed-off-by: Andrew Morton Signed-off-by: Stephen Rothwell Signed-off-by: Dave Rodgman --- Documentation/lzo.txt | 12 ++- crypto/Makefile| 2 +- crypto/lzo-rle.c | 175 + crypto/tcrypt.c| 4 +- drivers/block/zram/zcomp.c | 1 + include/linux/lzo.h| 4 + lib/lzo/lzo1x_compress.c | 42 +++-- lib/lzo/lzodefs.h | 3 +- 8 files changed, 226 insertions(+), 17 deletions(-) create mode 100644 crypto/lzo-rle.c diff --git a/Documentation/lzo.txt b/Documentation/lzo.txt index 306c60344ca7..f79934225d8d 100644 --- a/Documentation/lzo.txt +++ b/Documentation/lzo.txt @@ -88,6 +88,10 @@ length encoding. This improves speed for data with many zeros, which is a common case for zram. This modifies the bitstream in a backwards compatible way (v1 can correctly decompress v0 compressed data, but v0 cannot read v1 data). +For maximum compatibility, both versions are available under different names +(lzo and lzo-rle). Differences in the encoding are noted in this document with +e.g.: version 1 only. + Byte sequences == @@ -99,8 +103,8 @@ Byte sequences invalid at this place. 17 : bitstream version. If the first byte is 17, the next byte -gives the bitstream version. If the first byte is not 17, -the bitstream version is 0. +gives the bitstream version (version 1 only). If the first byte +is not 17, the bitstream version is 0. 18..21 : copy 0..3 literals state = (byte - 17) = 0..3 [ copy literals ] @@ -154,8 +158,8 @@ Byte sequences state = S (copy S literals after this block) End of stream is reached if distance == 16384 -In version 1, this instruction is also used to encode a run of zeros if -distance = 0xbfff, i.e. H = 1 and the D bits are all 1. +In version 1 only, this instruction is also used to encode a run of +zeros if distance = 0xbfff, i.e. H = 1 and the D bits are all 1. In this case, it is followed by a fourth byte, X. run length = ((X << 3) | (0 0 0 0 0 L L L)) + 4. diff --git a/crypto/Makefile b/crypto/Makefile index 5e789dc2d4fd..23491b70e601 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -127,7 +127,7 @@ obj-$(CONFIG_CRYPTO_CRC32C) += crc32c_generic.o obj-$(CONFIG_CRYPTO_CRC32) += crc32_generic.o obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif_common.o crct10dif_generic.o obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o -obj-$(CONFIG_CRYPTO_LZO) += lzo.o +obj-$(CONFIG_CRYPTO_LZO) += lzo.o lzo-rle.o obj-$(CONFIG_CRYPTO_LZ4) += lz4.o obj-$(CONFIG_CRYPTO_LZ4HC) += lz4hc.o obj-$(CONFIG_CRYPTO_842) += 842.o diff --git a/crypto/lzo-rle.c b/crypto/lzo-rle.c new file mode 100644 index ..ea9c75b1db49 --- /dev/null +++ b/crypto/lzo-rle.c @@ -0,0 +1,175 @@ +/* + * Cryptographic API. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include + +struct lzorle_ctx { + void *lzorle_comp_mem; +}; + +static void *lzorle_alloc_ctx(struct crypto_scomp *tfm) +{ + void *ctx; + + ctx = kvmalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); + if (!ctx) + return ERR_PTR(-ENOMEM); + + return ctx; +} + +static int lzorle_init(struct crypto_tfm *tfm) +{ + struct lzorle_ctx *ctx = crypto_tfm_ctx(tfm); + + ctx->lzorle_comp_mem = lzorle_alloc_ctx(NULL); + if (IS_ERR(ctx->lzorle_comp_mem)) + return -ENOMEM; + + return 0; +} + +static void lzorle_free_ctx(struct crypto_scomp *tfm, void *ctx) +{ + kvfree(ctx); +} + +static void lzorle_exit(struct crypto_tfm *tfm) +{ + struct lzorle_ctx *ctx = crypto_tfm_ctx(tfm); + + lzorle_free_ctx(NULL, ctx->lzorle_comp_mem); +} + +static