[PATCH] PM / Hibernate: Remove unused parameter of enough_swap

2018-01-15 Thread Kyungsik Lee
Parameter flags is no longer used, remove it.

Signed-off-by: Kyungsik Lee 
---
 kernel/power/swap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 293ead5..a46be12 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -879,7 +879,7 @@ static int save_image_lzo(struct swap_map_handle *handle,
  * space avaiable from the resume partition.
  */
 
-static int enough_swap(unsigned int nr_pages, unsigned int flags)
+static int enough_swap(unsigned int nr_pages)
 {
unsigned int free_swap = count_swap_pages(root_swap, 1);
unsigned int required;
@@ -915,7 +915,7 @@ int swsusp_write(unsigned int flags)
return error;
}
if (flags & SF_NOCOMPRESS_MODE) {
-   if (!enough_swap(pages, flags)) {
+   if (!enough_swap(pages)) {
pr_err("Not enough free swap\n");
error = -ENOSPC;
goto out_finish;
-- 
1.9.1



Re: [PATCH] Fix flags for initramfs LZ4 compression

2014-02-18 Thread Kyungsik Lee
Hello,

On Tue, Feb 18, 2014 at 04:08:56PM -0800, Andrew Morton wrote:
> On Sat, 15 Feb 2014 18:14:57 -0500 "Daniel M. Weeks"  
> wrote:
> 
> > LZ4 as implemented in the kernel differs from the default method now
> > used by the reference implementation of LZ4. Until the in-kernel method
> > is updated to support the new default, passing the legacy flag (-l) to
> > the compressor is necessary. Without this flag the kernel-generated,
> > LZ4-compressed initramfs is junk.
> > 
> > ...
> >
> > --- a/scripts/gen_initramfs_list.sh
> > +++ b/scripts/gen_initramfs_list.sh
> > @@ -257,7 +257,7 @@ case "$arg" in
> >  && compr="lzop -9 -f"
> > echo "$output_file" | grep -q "\.lz4$" \
> >  && [ -x "`which lz4 2> /dev/null`" ] \
> > -&& compr="lz4 -9 -f"
> > +&& compr="lz4 -l -9 -f"
> > echo "$output_file" | grep -q "\.cpio$" && compr="cat"
> > shift
> > ;;
> 
> What happens is the user is running an old version of /bin/lz4?  A
> version which predates this switch to a new format?  Do those earlier
> versions accept -l, even though they don't need it?  Or will the kernel
> build fail?

It seems that lz4 supports legacy format with the same option as lz4c
does. Just looking at the first few bytes of lz4 compressed image, we
can see whether it is new format or not.

It shows new format magic number without this patch. New format magic
number is 0x184d2204.

$ hexdump -C ./initramfs_data.cpio.lz4 |more
  04 22 4d 18 64 70 b9 69 (Little Endian)
...

Currently Kernel supports legacy format only.

Acked-by: Kyungsik Lee 

Thanks,
Kyungsik

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] unlz4: always set an error return code on failures

2013-11-11 Thread Kyungsik Lee
On Mon, Nov 11, 2013 at 08:35:31AM +, Jan Beulich wrote:
> >>> On 11.11.13 at 03:49, Kyungsik Lee  wrote:
> > Hello Jan,
> > 
> > Thanks for the patch.
> > 
> > On Fri, Nov 08, 2013 at 09:27:09AM +, Jan Beulich wrote:
> >> "ret", being set to -1 early on, gets cleared by the first invocation
> >> of lz4_decompress()/lz4_decompress_unknownoutputsize(), and hence
> >> subsequent failures wouldn't be noticed by the caller without setting
> >> it back to -1 right after those calls.
> >> 
> >> Reported-by: Matthew Daley 
> >> Signed-off-by: Jan Beulich 
> >> Cc: Kyungsik Lee 
> >> Cc: Andrew Morton 
> >> 
> >> --- a/lib/decompress_unlz4.c
> >> +++ b/lib/decompress_unlz4.c
> >> @@ -141,6 +141,7 @@ STATIC inline int INIT unlz4(u8 *input, 
> >>goto exit_2;
> >>}
> >>  
> >> +  ret = -1;
> >>if (flush && flush(outp, dest_len) != dest_len)
> >>goto exit_2;
> >>if (output)
> >>
> > What do you think of adding "ret2" for keeping "ret" error status
> > which is set by lz4_decompress*() like below.
> 
> I'd be fine with that too, but preferred to submit the smallest
> possible (read: one line) patch in this case.
>
I think it looks neat avoiding "ret" being set to error status
in the loop. Can you please resend the patch with those changes?

Acked-by: Kyungsik Lee 

Thanks,
Kyungsik
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] unlz4: always set an error return code on failures

2013-11-10 Thread Kyungsik Lee
Hello Jan,

Thanks for the patch.

On Fri, Nov 08, 2013 at 09:27:09AM +, Jan Beulich wrote:
> "ret", being set to -1 early on, gets cleared by the first invocation
> of lz4_decompress()/lz4_decompress_unknownoutputsize(), and hence
> subsequent failures wouldn't be noticed by the caller without setting
> it back to -1 right after those calls.
> 
> Reported-by: Matthew Daley 
> Signed-off-by: Jan Beulich 
> Cc: Kyungsik Lee 
> Cc: Andrew Morton 
> 
> --- a/lib/decompress_unlz4.c
> +++ b/lib/decompress_unlz4.c
> @@ -141,6 +141,7 @@ STATIC inline int INIT unlz4(u8 *input, 
>   goto exit_2;
>   }
>  
> + ret = -1;
>   if (flush && flush(outp, dest_len) != dest_len)
>   goto exit_2;
>   if (output)
>
What do you think of adding "ret2" for keeping "ret" error status
which is set by lz4_decompress*() like below.

{
int ret2;

ret2 = lz4_decompress(inp, &chunksize, outp, dest_len);
if (ret2 < 0) {

}

Thanks,
Kyungsik

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Correct the LZ4 license

2013-08-16 Thread Kyungsik Lee
On Fri, Aug 16, 2013 at 04:45:29PM -0500, Richard Laager wrote:
> The LZ4 code is listed as using the "BSD 2-Clause License".
> 
> Signed-off-by: Richard Laager 
> ---
>  lib/lz4/lz4_compress.c   |4 ++--
>  lib/lz4/lz4_decompress.c |6 +++---
>  lib/lz4/lz4hc_compress.c |4 ++--
>  3 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/lz4/lz4_compress.c b/lib/lz4/lz4_compress.c
> index fd94058..28321d8 100644
> --- a/lib/lz4/lz4_compress.c
> +++ b/lib/lz4/lz4_compress.c
> @@ -437,7 +437,7 @@ int lz4_compress(const unsigned char *src, size_t src_len,
>  exit:
>   return ret;
>  }
> -EXPORT_SYMBOL_GPL(lz4_compress);
> +EXPORT_SYMBOL(lz4_compress);
>  
> -MODULE_LICENSE("GPL");
> +MODULE_LICENSE("Dual BSD/GPL");
>  MODULE_DESCRIPTION("LZ4 compressor");
> diff --git a/lib/lz4/lz4_decompress.c b/lib/lz4/lz4_decompress.c
> index d3414ea..411be80 100644
> --- a/lib/lz4/lz4_decompress.c
> +++ b/lib/lz4/lz4_decompress.c
> @@ -299,7 +299,7 @@ exit_0:
>   return ret;
>  }
>  #ifndef STATIC
> -EXPORT_SYMBOL_GPL(lz4_decompress);
> +EXPORT_SYMBOL(lz4_decompress);
>  #endif
>  
>  int lz4_decompress_unknownoutputsize(const char *src, size_t src_len,
> @@ -319,8 +319,8 @@ exit_0:
>   return ret;
>  }
>  #ifndef STATIC
> -EXPORT_SYMBOL_GPL(lz4_decompress_unknownoutputsize);
> +EXPORT_SYMBOL(lz4_decompress_unknownoutputsize);
>  
> -MODULE_LICENSE("GPL");
> +MODULE_LICENSE("Dual BSD/GPL");
>  MODULE_DESCRIPTION("LZ4 Decompressor");
>  #endif
> diff --git a/lib/lz4/lz4hc_compress.c b/lib/lz4/lz4hc_compress.c
> index eb1a74f..f344f76 100644
> --- a/lib/lz4/lz4hc_compress.c
> +++ b/lib/lz4/lz4hc_compress.c
> @@ -533,7 +533,7 @@ int lz4hc_compress(const unsigned char *src, size_t 
> src_len,
>  exit:
>   return ret;
>  }
> -EXPORT_SYMBOL_GPL(lz4hc_compress);
> +EXPORT_SYMBOL(lz4hc_compress);
>  
> -MODULE_LICENSE("GPL");
> +MODULE_LICENSE("Dual BSD/GPL");
>  MODULE_DESCRIPTION("LZ4HC compressor");

Acked-by: Kyungsik Lee 

Thanks,
Kyungsik
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] LZ4: compression/decompression signedness mismatch

2013-07-19 Thread Kyungsik Lee
On Thu, Jul 18, 2013 at 11:29:57PM +0200, Geert Uytterhoeven wrote:
> On Thu, Jul 18, 2013 at 11:18 PM, Sergey Senozhatsky
>  wrote:
> > On (07/12/13 12:48), Sergey Senozhatsky wrote:
> >> On (07/12/13 11:28), Yann Collet wrote:
> >> >The reference implementation, hosted at :�
> >> >[1]https://code.google.com/p/lz4/
> >> >only proposes char* (signed) types as part of the interface contract.
> >> >I would recommend to keep it that way, to remain consistent.
> >> >Regards
> >>
> >> Crypto lz4 accepts u8 * for both compression and decompression:
> >>
> >>  lz4_compress_crypto(struct crypto_tfm *tfm, const u8 *src,
> >> unsigned int slen, u8 *dst, unsigned int *dlen)
> >>
> >>  lz4_decompress_crypto(struct crypto_tfm *tfm, const u8 *src,
> >>unsigned int slen, u8 *dst, unsigned int *dlen)
> >>
> >>
> >> Internally LZ4 may cast unsigned char* to signed char*, the same way you
> >> already do with compression:
> >>
> >>   int lz4_compress(const unsigned char *src, size_t src_len,
> >>   unsigned char *dst, size_t *dst_len, void *wrkmem)
> >>
> >>   calls:
> >>   lz4_compressctx(void *ctx,
> >>   const char *source, char *dest,
> >>   int isize, int maxoutputsize)
> >>
> >
> >
> > + lib/decompress_unlz4.c
> >  STATIC int INIT decompress(unsigned char *buf, int in_len,
> > int(*fill)(void*, unsigned int),
> > int(*flush)(void*, unsigned int),
> > unsigned char *output,
> > int *posp,
> > void(*error)(char *x)
> >
> >>
> >> At the moment API is a bit misaligned: unsiged char* for compression and 
> >> signed char* for
> >> decompression.
> >>
> >>
> >> My 'real word' use case is, suppose:
> >>
> >>   struct foo {
> >>   [..]
> >>   int (*compress)(const unsigned char *src, size_t src_len,
> >>   unsigned char *dst, size_t *dst_len, void 
> >> *wrkmem);
> >>   int (*decompress)(const unsigned char *src, size_t src_len,
> >>   unsigned char *dst, size_t *dst_len);
> >>   };
> >>
> >>
> >> and (for example) module also provides sysfs attribute, so user can switch 
> >> select
> >> LZO or LZ4 compressions depending of his needs:
> >>
> >>   ->compress = lzo1x_1_compress;
> >>   ->decompress = lzo1x_decompress_safe;
> >>
> >> to
> >>   ->compress = lz4_compress;
> >>   ->decompress = lz4_decompress_unknownoutputsize;
> >>
> >>
> >> the last one produces unneccessary compilation warning.
> >>
> >
> > did you guys have a chance to review the patch? it does not change
> > implementation/internals, just decompression exported symbols.
> 
> IMHO, all these memory buffers should be of type "(const) void *", cfr.
> e.g. read(2) and memcpy(3).
> 
> This avoids casts in the callers.

How about using "const unsigned char *" for the exported symbols in the
patch?
It is OK unless the patch changes the internal implementation.

Thanks,
Kyungsik
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH -next 2/2] kbuild: fix for updated LZ4 tool with the new streaming format

2013-07-10 Thread Kyungsik Lee
> 
> BTW speaking of introductory-level patches, what about the following
> one:
> 
> Now that lz4 kernel compression is available, add *.lz4 to .gitignore
> 
> diff --git a/.gitignore b/.gitignore
> index 3b8b9b3..7e9932e 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -29,6 +29,7 @@ modules.builtin
>  *.bz2
>  *.lzma
>  *.xz
> +*.lz4
>  *.lzo
>  *.patch
>  *.gcno
> 
Acked-by: Kyungsik Lee 

Thanks,
Kyungsik

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH -next 2/2] kbuild: fix for updated LZ4 tool with the new streaming format

2013-05-06 Thread Kyungsik Lee
LZ4 has been updated with LZ4 Streaming Format specification(v1.3).
lz4demo is replaced by lz4c. lz4c supports both the new streaming and
legacy format with -l option.

This patch makes use of lz4c to support legacy format which is
used for LZ4 De/compression in the linux kernel.

Link: https://code.google.com/p/lz4/source/checkout
Signed-off-by: Kyungsik Lee 
Cc: "H. Peter Anvin" 
Cc: Ingo Molnar 
Cc: Thomas Gleixner 
Cc: Russell King 
Cc: Borislav Petkov 
Cc: Florian Fainelli 
Cc: Yann Collet 
Cc: Chanho Min 
---
 scripts/Makefile.lib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index a0ab6d7..c9bfbb0 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -313,7 +313,7 @@ cmd_lzo = (cat $(filter-out FORCE,$^) | \
 
 quiet_cmd_lz4 = LZ4 $@
 cmd_lz4 = (cat $(filter-out FORCE,$^) | \
-   lz4demo -c1 stdin stdout && $(call size_append, $(filter-out 
FORCE,$^))) > $@ || \
+   lz4c -l -c1 stdin stdout && $(call size_append, $(filter-out 
FORCE,$^))) > $@ || \
(rm -f $@ ; false)
 
 # U-Boot mkimage
-- 
1.8.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH -next 1/2] arm: Remove enforced Os flag for LZ4 decompressor

2013-05-06 Thread Kyungsik Lee
-Os is enforced here, based on the test result of decompression time
below, slightly faster than -O2.

But further tests with UA show that using -O2 will be the right choice
especially in the case of the unaligned access enabled and the gap,
few counts in the normal decompression mode is small enough to remove -Os.

Decompression Time(counts)
 NormalUA enabled
-Os  6717  3447
-O2  6720  2728

Note: ARM v7, Kernel 3.4
  counter freq. = 32768 HZ
  UA(Unaligned Access)
  gcc version 4.6.2

Signed-off-by: Kyungsik Lee 
Cc: Thomas Gleixner 
Cc: Russell King 
Cc: Borislav Petkov 
Cc: Florian Fainelli 
Cc: Yann Collet 
---
 arch/arm/boot/compressed/Makefile | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/arm/boot/compressed/Makefile 
b/arch/arm/boot/compressed/Makefile
index 001a13a..198a4ad 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -27,9 +27,6 @@ OBJS  += misc.o decompress.o
 ifeq ($(CONFIG_DEBUG_UNCOMPRESS),y)
 OBJS   += debug.o
 endif
-ifeq ($(CONFIG_KERNEL_LZ4),y)
-CFLAGS_decompress.o := -Os
-endif
 FONTC  = $(srctree)/drivers/video/console/font_acorn_8x8.c
 
 # string library code (-Os is enforced to keep it much smaller)
-- 
1.8.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 -next 3/5] arm: Add support for LZ4-compressed kernel

2013-05-03 Thread Kyungsik Lee
On Tue, Apr 30, 2013 at 01:56:02PM -0700, Andrew Morton wrote:
> On Tue,  5 Mar 2013 20:47:34 +0900 Kyungsik Lee  wrote:
> 
> > This patch integrates the LZ4 decompression code to the arm pre-boot code.
> > And it depends on two patchs below
> > 
> > lib: Add support for LZ4-compressed kernel
> > decompressor: Add LZ4 decompressor module
> > 
> > ...
> >
> > - Apply CFLAGS, -Os to decompress.o to improve decompress
> >   performance during boot-up process
> >
> > ...
> >
> > --- a/arch/arm/boot/compressed/Makefile
> > +++ b/arch/arm/boot/compressed/Makefile
> > @@ -24,6 +24,9 @@ endif
> >  AFLAGS_head.o += -DTEXT_OFFSET=$(TEXT_OFFSET)
> >  HEAD   = head.o
> >  OBJS   += misc.o decompress.o
> > +ifeq ($(CONFIG_KERNEL_LZ4),y)
> > +CFLAGS_decompress.o := -Os
> > +endif
> 
> Surprised.  You found that -Os produces faster code than -O2?  Details,
> please?
-Os is enforced here, based on the test result of decompression time
below, slightly faster than -O2.
But further tests with UA show that using -O2 will be the right choice
especially in the case of the unaligned access enabled.

Decompression Time(counts)
 UA
-Os  67173447
-O2  67202728

Note: ARM v7, Kernel 3.4
  counter freq. = 32768 HZ
  UA(Unaligned Access)
  gcc version 4.6.2 (Ubuntu/Linaro 4.6.2-14ubuntu2~ppa1)

Thanks,
Kyungsik
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH -next] x86, doc: Add LZ4 magic number for the new compression

2013-04-25 Thread Kyungsik Lee
Documentation/x86/boot.txt is updated to list the LZ4 magic number.
This LZ4 magic number is used for the new compression format.

Signed-off-by: Kyungsik Lee 
Cc: "H. Peter Anvin" 
Cc: Ingo Molnar 
Cc: Thomas Gleixner 
Cc: Russell King 
Cc: Borislav Petkov 
Cc: Florian Fainelli 
Cc: Yann Collet 
---
 Documentation/x86/boot.txt | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/x86/boot.txt b/Documentation/x86/boot.txt
index 3840b6f..fc66d42 100644
--- a/Documentation/x86/boot.txt
+++ b/Documentation/x86/boot.txt
@@ -657,9 +657,10 @@ Protocol:  2.08+
   uncompressed data should be determined using the standard magic
   numbers.  The currently supported compression formats are gzip
   (magic numbers 1F 8B or 1F 9E), bzip2 (magic number 42 5A), LZMA
-  (magic number 5D 00), and XZ (magic number FD 37).  The uncompressed
-  payload is currently always ELF (magic number 7F 45 4C 46).
-  
+  (magic number 5D 00), XZ (magic number FD 37), and LZ4 (magic number
+  02 21).  The uncompressed payload is currently always ELF (magic
+  number 7F 45 4C 46).
+
 Field name:payload_length
 Type:  read
 Offset/size:   0x24c/4
-- 
1.8.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 -next 0/5] Add support for LZ4-compressed kernel

2013-03-07 Thread Kyungsik Lee
Hello,

On Tue, Mar 05, 2013 at 03:06:16PM -0800, Andrew Morton wrote:
> On Tue,  5 Mar 2013 20:47:31 +0900 Kyungsik Lee  wrote:
> 
> > This is the third version. In this version, Some codes are fixed
> > and more description and note are added. I would like to thank David Sterba
> > for his review.
> > 
> > The Last patch[5/5] of the patch set is for making x86 and arm default to
> > LZ4-compressed for testing the LZ4 code in the linux-next.
> > It was requested by Andrew Morton in the patch set v2.
> > 
> > Currently, A preliminary version of LZ4 de/compression tool is supported.
> > However, It is expected that we will have a tool with more features
> > once its format is finished.
> 
> What happened to the changelog?  The earlier version at least had some
> rudimentary benchmarking results, but now we don't even have that. 
> 
> Someone should prepare the information explaining why we added this to
> Linux, and I'd prefer that person be you rather than me!  Certainly it
> should include performance measurements - both speed and space.  Also
> it should capture our thinking regarding all the other decompressors,
> explaining why we view it as acceptable to add yet another one.
> 
> Please, put yourself in the position of someone reading these commits
> in 2017 wondering "why did they merge this".  We should tell them.

Sorry for the inconvenience regarding changelog. Another patch(v4)
is not required so this is the information you mentioned.
I'm not sure that I captured what we had discussed regarding all the other
decompressors properly.


Benchmark Results(PATCH v3)
Compiler: Linaro ARM gcc 4.6.2

1. ARMv7, 1.5GHz based board
   Kernel: linux 3.4
   Uncompressed Kernel Size: 14MB
Compressed Size  Decompression Speed
   LZO  6.7MB20.1MB/s, 25.2MB/s(UA)
   LZ4  7.3MB29.1MB/s, 45.6MB/s(UA)

2. ARMv7, 1.7GHz based board
   Kernel: linux 3.7
   Uncompressed Kernel Size: 14MB
Compressed Size  Decompression Speed
   LZO  6.0MB34.1MB/s, 52.2MB/s(UA)
   LZ4  6.5MB86.7MB/s
- UA: Unaligned memory Access support
- Latest patch set for LZO applied


This patch set is for adding support for LZ4-compressed Kernel.
LZ4 is a very fast lossless compression algorithm and it also features
an extremely fast decoder [1].

But we have five of decompressors already and one question which does arise,
however, is that of where do we stop adding new ones? This issue had been
discussed and came to the conclusion [2].
Russell King said that
we should have:
- one decompressor which is the fastest
- one decompressor for the highest compression ratio
- one popular decompressor (eg conventional gzip)
If we have a replacement one for one of these, then it should do exactly that:
replace it.

The benchmark shows that an 8% increase in image size vs a 66% increase
in decompression speed compared to LZO(which has been known as the fastest
decompressor in the Kernel). Therefore the "fast but may not be small"
compression title has clearly been taken by LZ4 [3].

[1] http://code.google.com/p/lz4/
[2] http://thread.gmane.org/gmane.linux.kbuild.devel/9157
[3] http://thread.gmane.org/gmane.linux.kbuild.devel/9347


Thanks,
Kyungsik
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 -next 4/5] x86: Add support for LZ4-compressed kernel

2013-03-05 Thread Kyungsik Lee
On Tue, Mar 05, 2013 at 08:13:38AM -0800, H. Peter Anvin wrote:
> Please add the new magic to Documentation/x86/boot.txt as well.

Ok, I will update it as soon as the patch set is stabilized.

Thanks,
Kyungsik

> >This patch integrates the LZ4 decompression code to the x86 pre-boot
> >code.
> >And it depends on two patchs below
> >
> >lib: Add support for LZ4-compressed kernel
> >decompressor: Add LZ4 decompressor module
> >
> >Signed-off-by: Kyungsik Lee 
> >---
> > arch/x86/Kconfig  | 1 +
> > arch/x86/boot/compressed/Makefile | 5 -
> > arch/x86/boot/compressed/misc.c   | 4 
> > 3 files changed, 9 insertions(+), 1 deletion(-)
> >
> >diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> >index 225543b..ab916fd 100644
> >--- a/arch/x86/Kconfig
> >+++ b/arch/x86/Kconfig
> >@@ -63,6 +63,7 @@ config X86
> > select HAVE_KERNEL_LZMA
> > select HAVE_KERNEL_XZ
> > select HAVE_KERNEL_LZO
> >+select HAVE_KERNEL_LZ4
> > select HAVE_HW_BREAKPOINT
> > select HAVE_MIXED_BREAKPOINTS_REGS
> > select PERF_EVENTS
> >diff --git a/arch/x86/boot/compressed/Makefile
> >b/arch/x86/boot/compressed/Makefile
> >index 8a84501..c275db5 100644
> >--- a/arch/x86/boot/compressed/Makefile
> >+++ b/arch/x86/boot/compressed/Makefile
> >@@ -4,7 +4,7 @@
> > # create a compressed vmlinux image from the original vmlinux
> > #
> > 
> >-targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz
> >vmlinux.bin.bz2 vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo
> >head_$(BITS).o misc.o string.o cmdline.o early_serial_console.o piggy.o
> >+targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz
> >vmlinux.bin.bz2 vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo
> >vmlinux.bin.lz4 head_$(BITS).o misc.o string.o cmdline.o
> >early_serial_console.o piggy.o
> > 
> > KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2
> > KBUILD_CFLAGS += -fno-strict-aliasing -fPIC
> >@@ -64,12 +64,15 @@ $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
> > $(call if_changed,xzkern)
> > $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
> > $(call if_changed,lzo)
> >+$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
> >+$(call if_changed,lz4)
> > 
> > suffix-$(CONFIG_KERNEL_GZIP):= gz
> > suffix-$(CONFIG_KERNEL_BZIP2)   := bz2
> > suffix-$(CONFIG_KERNEL_LZMA):= lzma
> > suffix-$(CONFIG_KERNEL_XZ)  := xz
> > suffix-$(CONFIG_KERNEL_LZO) := lzo
> >+suffix-$(CONFIG_KERNEL_LZ4) := lz4
> > 
> > quiet_cmd_mkpiggy = MKPIGGY $@
> >   cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false )
> >diff --git a/arch/x86/boot/compressed/misc.c
> >b/arch/x86/boot/compressed/misc.c
> >index 88f7ff6..166a0a8 100644
> >--- a/arch/x86/boot/compressed/misc.c
> >+++ b/arch/x86/boot/compressed/misc.c
> >@@ -145,6 +145,10 @@ static int lines, cols;
> > #include "../../../../lib/decompress_unlzo.c"
> > #endif
> > 
> >+#ifdef CONFIG_KERNEL_LZ4
> >+#include "../../../../lib/decompress_unlz4.c"
> >+#endif
> >+
> > static void scroll(void)
> > {
> > int i;
> 
> -- 
> Sent from my mobile phone. Please excuse brevity and lack of formatting.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 -next 0/5] Add support for LZ4-compressed kernel

2013-03-05 Thread Kyungsik Lee
On Tue, Mar 05, 2013 at 03:06:16PM -0800, Andrew Morton wrote:
> On Tue,  5 Mar 2013 20:47:31 +0900 Kyungsik Lee  wrote:
> 
> > This is the third version. In this version, Some codes are fixed
> > and more description and note are added. I would like to thank David Sterba
> > for his review.
> > 
> > The Last patch[5/5] of the patch set is for making x86 and arm default to
> > LZ4-compressed for testing the LZ4 code in the linux-next.
> > It was requested by Andrew Morton in the patch set v2.
> > 
> > Currently, A preliminary version of LZ4 de/compression tool is supported.
> > However, It is expected that we will have a tool with more features
> > once its format is finished.
> 
> What happened to the changelog?  The earlier version at least had some
> rudimentary benchmarking results, but now we don't even have that. 
> 
> Someone should prepare the information explaining why we added this to
> Linux, and I'd prefer that person be you rather than me!  Certainly it
> should include performance measurements - both speed and space.  Also
> it should capture our thinking regarding all the other decompressors,
> explaining why we view it as acceptable to add yet another one.
Sorry, It will have all the information you mentioned. I can reply to
this thread if you want.

Or I might need another patch(v4). I have one thing to be confirmed
regarding LZ4 format. One of the patch set needs to be fixed
if there is a change. After that I can include the information
in the changelog.

> Please, put yourself in the position of someone reading these commits
> in 2017 wondering "why did they merge this".  We should tell them.

Thanks,
Kyungsik
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 -next 0/5] Add support for LZ4-compressed kernel

2013-03-05 Thread Kyungsik Lee
Hi,

This is the third version. In this version, Some codes are fixed
and more description and note are added. I would like to thank David Sterba
for his review.

The Last patch[5/5] of the patch set is for making x86 and arm default to
LZ4-compressed for testing the LZ4 code in the linux-next.
It was requested by Andrew Morton in the patch set v2.

Currently, A preliminary version of LZ4 de/compression tool is supported.
However, It is expected that we will have a tool with more features
once its format is finished.

LZ4 compression tool is available at
http://code.google.com/p/lz4/source/checkout.

Thanks,
Kyungsik


Change log: v2
- Clean up code
- Enable unaligned access for ARM v6 and above with
  CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
- Add lz4_decompress() for faster decompression with
  uncompressed output size
- Use lz4_decompress() for LZ4-compressed kernel during
  boot-process
- Apply -Os to decompress.o to improve decompress
  performance during boot-up process
Change log: v3
- Prevent double evaluation by using an inline function
- Add LZ4 description and note for uncompressed chunk size issue
- Fix indentation error


Kyungsik Lee (5):
  decompressor: Add LZ4 decompressor module
  lib: Add support for LZ4-compressed kernel
  arm: Add support for LZ4-compressed kernel
  x86: Add support for LZ4-compressed kernel
  Kconfig: Make x86 and arm kernels default to the LZ4-compressed

 arch/arm/Kconfig  |   1 +
 arch/arm/boot/compressed/.gitignore   |   1 +
 arch/arm/boot/compressed/Makefile |   6 +-
 arch/arm/boot/compressed/decompress.c |   4 +
 arch/arm/boot/compressed/piggy.lz4.S  |   6 +
 arch/x86/Kconfig  |   1 +
 arch/x86/boot/compressed/Makefile |   5 +-
 arch/x86/boot/compressed/misc.c   |   4 +
 include/linux/decompress/unlz4.h  |  10 ++
 include/linux/lz4.h   |  51 ++
 init/Kconfig  |  19 +-
 lib/Kconfig   |   7 +
 lib/Makefile  |   2 +
 lib/decompress.c  |   5 +
 lib/decompress_unlz4.c| 187 +++
 lib/lz4/Makefile  |   1 +
 lib/lz4/lz4_decompress.c  | 326 ++
 lib/lz4/lz4defs.h |  94 ++
 scripts/Makefile.lib  |   5 +
 usr/Kconfig   |   9 +
 20 files changed, 740 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/boot/compressed/piggy.lz4.S
 create mode 100644 include/linux/decompress/unlz4.h
 create mode 100644 include/linux/lz4.h
 create mode 100644 lib/decompress_unlz4.c
 create mode 100644 lib/lz4/Makefile
 create mode 100644 lib/lz4/lz4_decompress.c
 create mode 100644 lib/lz4/lz4defs.h

-- 
1.8.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 -next 5/5] Kconfig: Make x86 and arm kernels default to the LZ4-compressed

2013-03-05 Thread Kyungsik Lee
This patch makes x86 and arm kernels default to the LZ4-compressed
to test new LZ4 code in the linux-next. This is requested by
Andrew Morton.

Signed-off-by: Kyungsik Lee 
---
 init/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/init/Kconfig b/init/Kconfig
index fc8eb1f..de3cb00 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -138,7 +138,7 @@ config HAVE_KERNEL_LZ4
 
 choice
prompt "Kernel compression mode"
-   default KERNEL_GZIP
+   default KERNEL_LZ4
depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || 
HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4
help
  The linux kernel is a kind of self-extracting executable.
-- 
1.8.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 -next 2/5] lib: Add support for LZ4-compressed kernel

2013-03-05 Thread Kyungsik Lee
This patch adds support for extracting LZ4-compressed kernel images,
as well as LZ4-compressed ramdisk images in the kernel boot process.

This depends on the patch below
decompressor: Add LZ4 decompressor module

Signed-off-by: Kyungsik Lee 

v2:
- Clean up code
- Use lz4_decompress() for LZ4-compressed kernel during boot-process
v3:
- Use an inline function instead of macro to prevent double evaluation
- Add LZ4 description and note for uncompressed chunk size
---
 include/linux/decompress/unlz4.h |  10 +++
 init/Kconfig |  17 +++-
 lib/Kconfig  |   7 ++
 lib/Makefile |   2 +
 lib/decompress.c |   5 ++
 lib/decompress_unlz4.c   | 187 +++
 lib/lz4/Makefile |   1 +
 lib/lz4/lz4_decompress.c |   2 +-
 scripts/Makefile.lib |   5 ++
 usr/Kconfig  |   9 ++
 10 files changed, 243 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/decompress/unlz4.h
 create mode 100644 lib/decompress_unlz4.c
 create mode 100644 lib/lz4/Makefile

diff --git a/include/linux/decompress/unlz4.h b/include/linux/decompress/unlz4.h
new file mode 100644
index 000..d5b68bf
--- /dev/null
+++ b/include/linux/decompress/unlz4.h
@@ -0,0 +1,10 @@
+#ifndef DECOMPRESS_UNLZ4_H
+#define DECOMPRESS_UNLZ4_H
+
+int unlz4(unsigned char *inbuf, int len,
+   int(*fill)(void*, unsigned int),
+   int(*flush)(void*, unsigned int),
+   unsigned char *output,
+   int *pos,
+   void(*error)(char *x));
+#endif
diff --git a/init/Kconfig b/init/Kconfig
index be8b7f5..fc8eb1f 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -133,10 +133,13 @@ config HAVE_KERNEL_XZ
 config HAVE_KERNEL_LZO
bool
 
+config HAVE_KERNEL_LZ4
+   bool
+
 choice
prompt "Kernel compression mode"
default KERNEL_GZIP
-   depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || 
HAVE_KERNEL_XZ || HAVE_KERNEL_LZO
+   depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || 
HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4
help
  The linux kernel is a kind of self-extracting executable.
  Several compression algorithms are available, which differ
@@ -203,6 +206,18 @@ config KERNEL_LZO
  size is about 10% bigger than gzip; however its speed
  (both compression and decompression) is the fastest.
 
+config KERNEL_LZ4
+   bool "LZ4"
+   depends on HAVE_KERNEL_LZ4
+   help
+ LZ4 is an LZ77-type compressor with a fixed, byte-oriented encoding.
+ A preliminary version of LZ4 de/compression tool is available at
+ <https://code.google.com/p/lz4/>.
+
+ Its compression ratio is worse than LZO. The size of the kernel
+ is about 8% bigger than LZO. But the decompression speed is
+ faster than LZO.
+
 endchoice
 
 config DEFAULT_HOSTNAME
diff --git a/lib/Kconfig b/lib/Kconfig
index 75cdb77..b108047 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -189,6 +189,9 @@ config LZO_COMPRESS
 config LZO_DECOMPRESS
tristate
 
+config LZ4_DECOMPRESS
+   tristate
+
 source "lib/xz/Kconfig"
 
 #
@@ -213,6 +216,10 @@ config DECOMPRESS_LZO
select LZO_DECOMPRESS
tristate
 
+config DECOMPRESS_LZ4
+   select LZ4_DECOMPRESS
+   tristate
+
 #
 # Generic allocator support is selected if needed
 #
diff --git a/lib/Makefile b/lib/Makefile
index 02ed6c0..c2073bf 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_REED_SOLOMON) += reed_solomon/
 obj-$(CONFIG_BCH) += bch.o
 obj-$(CONFIG_LZO_COMPRESS) += lzo/
 obj-$(CONFIG_LZO_DECOMPRESS) += lzo/
+obj-$(CONFIG_LZ4_DECOMPRESS) += lz4/
 obj-$(CONFIG_XZ_DEC) += xz/
 obj-$(CONFIG_RAID6_PQ) += raid6/
 
@@ -80,6 +81,7 @@ lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o
 lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o
 lib-$(CONFIG_DECOMPRESS_XZ) += decompress_unxz.o
 lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o
+lib-$(CONFIG_DECOMPRESS_LZ4) += decompress_unlz4.o
 
 obj-$(CONFIG_TEXTSEARCH) += textsearch.o
 obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o
diff --git a/lib/decompress.c b/lib/decompress.c
index 31a8042..c70810e 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -31,6 +32,9 @@
 #ifndef CONFIG_DECOMPRESS_LZO
 # define unlzo NULL
 #endif
+#ifndef CONFIG_DECOMPRESS_LZ4
+# define unlz4 NULL
+#endif
 
 struct compress_format {
unsigned char magic[2];
@@ -45,6 +49,7 @@ static const struct compress_format compressed_formats[] 
__initdata = {
{ {0x5d, 0x00}, "lzma", unlzma },
{ {0xfd, 0x37}, "xz", unxz },
{ {0x89, 0x4c}, "lzo", unlzo },
+   { {0x02, 0x21}, "lz4", unlz4 },
{ {0, 0}, NULL, NULL }
 };
 
diff --git a/lib/decompress_unlz4.c b

[PATCH v3 -next 4/5] x86: Add support for LZ4-compressed kernel

2013-03-05 Thread Kyungsik Lee
This patch integrates the LZ4 decompression code to the x86 pre-boot code.
And it depends on two patchs below

lib: Add support for LZ4-compressed kernel
decompressor: Add LZ4 decompressor module

Signed-off-by: Kyungsik Lee 
---
 arch/x86/Kconfig  | 1 +
 arch/x86/boot/compressed/Makefile | 5 -
 arch/x86/boot/compressed/misc.c   | 4 
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 225543b..ab916fd 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -63,6 +63,7 @@ config X86
select HAVE_KERNEL_LZMA
select HAVE_KERNEL_XZ
select HAVE_KERNEL_LZO
+   select HAVE_KERNEL_LZ4
select HAVE_HW_BREAKPOINT
select HAVE_MIXED_BREAKPOINTS_REGS
select PERF_EVENTS
diff --git a/arch/x86/boot/compressed/Makefile 
b/arch/x86/boot/compressed/Makefile
index 8a84501..c275db5 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -4,7 +4,7 @@
 # create a compressed vmlinux image from the original vmlinux
 #
 
-targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 
vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo head_$(BITS).o misc.o string.o 
cmdline.o early_serial_console.o piggy.o
+targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 
vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 head_$(BITS).o 
misc.o string.o cmdline.o early_serial_console.o piggy.o
 
 KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2
 KBUILD_CFLAGS += -fno-strict-aliasing -fPIC
@@ -64,12 +64,15 @@ $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
$(call if_changed,xzkern)
 $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
$(call if_changed,lzo)
+$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
+   $(call if_changed,lz4)
 
 suffix-$(CONFIG_KERNEL_GZIP)   := gz
 suffix-$(CONFIG_KERNEL_BZIP2)  := bz2
 suffix-$(CONFIG_KERNEL_LZMA)   := lzma
 suffix-$(CONFIG_KERNEL_XZ) := xz
 suffix-$(CONFIG_KERNEL_LZO):= lzo
+suffix-$(CONFIG_KERNEL_LZ4):= lz4
 
 quiet_cmd_mkpiggy = MKPIGGY $@
   cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false )
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 88f7ff6..166a0a8 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -145,6 +145,10 @@ static int lines, cols;
 #include "../../../../lib/decompress_unlzo.c"
 #endif
 
+#ifdef CONFIG_KERNEL_LZ4
+#include "../../../../lib/decompress_unlz4.c"
+#endif
+
 static void scroll(void)
 {
int i;
-- 
1.8.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 -next 3/5] arm: Add support for LZ4-compressed kernel

2013-03-05 Thread Kyungsik Lee
This patch integrates the LZ4 decompression code to the arm pre-boot code.
And it depends on two patchs below

lib: Add support for LZ4-compressed kernel
decompressor: Add LZ4 decompressor module

Signed-off-by: Kyungsik Lee 

v2:
- Apply CFLAGS, -Os to decompress.o to improve decompress
  performance during boot-up process
---
 arch/arm/Kconfig  | 1 +
 arch/arm/boot/compressed/.gitignore   | 1 +
 arch/arm/boot/compressed/Makefile | 6 +-
 arch/arm/boot/compressed/decompress.c | 4 
 arch/arm/boot/compressed/piggy.lz4.S  | 6 ++
 5 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/boot/compressed/piggy.lz4.S

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 67874b8..0f9b363 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -38,6 +38,7 @@ config ARM
select HAVE_IDE if PCI || ISA || PCMCIA
select HAVE_IRQ_WORK
select HAVE_KERNEL_GZIP
+   select HAVE_KERNEL_LZ4
select HAVE_KERNEL_LZMA
select HAVE_KERNEL_LZO
select HAVE_KERNEL_XZ
diff --git a/arch/arm/boot/compressed/.gitignore 
b/arch/arm/boot/compressed/.gitignore
index f79a08e..47279aa 100644
--- a/arch/arm/boot/compressed/.gitignore
+++ b/arch/arm/boot/compressed/.gitignore
@@ -6,6 +6,7 @@ piggy.gzip
 piggy.lzo
 piggy.lzma
 piggy.xzkern
+piggy.lz4
 vmlinux
 vmlinux.lds
 
diff --git a/arch/arm/boot/compressed/Makefile 
b/arch/arm/boot/compressed/Makefile
index 5cad8a6..2249d52 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -24,6 +24,9 @@ endif
 AFLAGS_head.o += -DTEXT_OFFSET=$(TEXT_OFFSET)
 HEAD   = head.o
 OBJS   += misc.o decompress.o
+ifeq ($(CONFIG_KERNEL_LZ4),y)
+CFLAGS_decompress.o := -Os
+endif
 FONTC  = $(srctree)/drivers/video/console/font_acorn_8x8.c
 
 # string library code (-Os is enforced to keep it much smaller)
@@ -88,6 +91,7 @@ suffix_$(CONFIG_KERNEL_GZIP) = gzip
 suffix_$(CONFIG_KERNEL_LZO)  = lzo
 suffix_$(CONFIG_KERNEL_LZMA) = lzma
 suffix_$(CONFIG_KERNEL_XZ)   = xzkern
+suffix_$(CONFIG_KERNEL_LZ4)  = lz4
 
 # Borrowed libfdt files for the ATAG compatibility mode
 
@@ -112,7 +116,7 @@ targets   := vmlinux vmlinux.lds \
 font.o font.c head.o misc.o $(OBJS)
 
 # Make sure files are removed during clean
-extra-y   += piggy.gzip piggy.lzo piggy.lzma piggy.xzkern \
+extra-y   += piggy.gzip piggy.lzo piggy.lzma piggy.xzkern piggy.lz4 \
 lib1funcs.S ashldi3.S $(libfdt) $(libfdt_hdrs)
 
 ifeq ($(CONFIG_FUNCTION_TRACER),y)
diff --git a/arch/arm/boot/compressed/decompress.c 
b/arch/arm/boot/compressed/decompress.c
index 9deb56a..a95f071 100644
--- a/arch/arm/boot/compressed/decompress.c
+++ b/arch/arm/boot/compressed/decompress.c
@@ -53,6 +53,10 @@ extern char * strstr(const char * s1, const char *s2);
 #include "../../../../lib/decompress_unxz.c"
 #endif
 
+#ifdef CONFIG_KERNEL_LZ4
+#include "../../../../lib/decompress_unlz4.c"
+#endif
+
 int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x))
 {
return decompress(input, len, NULL, NULL, output, NULL, error);
diff --git a/arch/arm/boot/compressed/piggy.lz4.S 
b/arch/arm/boot/compressed/piggy.lz4.S
new file mode 100644
index 000..3d9a575
--- /dev/null
+++ b/arch/arm/boot/compressed/piggy.lz4.S
@@ -0,0 +1,6 @@
+   .section .piggydata,#alloc
+   .globl  input_data
+input_data:
+   .incbin "arch/arm/boot/compressed/piggy.lz4"
+   .globl  input_data_end
+input_data_end:
-- 
1.8.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 -next 1/5] decompressor: Add LZ4 decompressor module

2013-03-05 Thread Kyungsik Lee
This patch adds support for LZ4 decompression in the Linux Kernel.
LZ4 Decompression APIs for kernel are based on LZ4 implementation
by Yann Collet.

LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
LZ4 source repository : http://code.google.com/p/lz4/

Signed-off-by: Kyungsik Lee 

v2:
- Clean up code
- Enable unaligned access for ARM v6 and above with
  CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
- Add lz4_decompress() for faster decompression with
  uncompressed output size
v3:
- Fix indent errors
- Prevent double evaluation by using an inline function
---
 include/linux/lz4.h  |  51 
 lib/lz4/lz4_decompress.c | 326 +++
 lib/lz4/lz4defs.h|  94 ++
 3 files changed, 471 insertions(+)
 create mode 100644 include/linux/lz4.h
 create mode 100644 lib/lz4/lz4_decompress.c
 create mode 100644 lib/lz4/lz4defs.h

diff --git a/include/linux/lz4.h b/include/linux/lz4.h
new file mode 100644
index 000..7f6c75a
--- /dev/null
+++ b/include/linux/lz4.h
@@ -0,0 +1,51 @@
+#ifndef __LZ4_H__
+#define __LZ4_H__
+/*
+ * LZ4 Kernel Interface
+ *
+ * Copyright (C) 2013, LG Electronics, Kyungsik Lee 
+ *
+ * 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.
+ */
+
+/*
+ * lz4_compressbound()
+ * Provides the maximum size that LZ4 may output in a "worst case" scenario
+ * (input data not compressible)
+ */
+static inline size_t lz4_compressbound(size_t isize)
+{
+   return isize + (isize / 255) + 16;
+}
+
+/*
+ * lz4_decompress()
+ * src : source address of the compressed data
+ * src_len : is the input size, whcih is returned after decompress done
+ * dest: output buffer address of the decompressed data
+ * actual_dest_len: is the size of uncompressed data, supposing it's known
+ * return  : Success if return 0
+ *   Error if return (< 0)
+ * note :  Destination buffer must be already allocated.
+ * slightly faster than lz4_decompress_unknownoutputsize()
+ */
+int lz4_decompress(const char *src, size_t *src_len, char *dest,
+   size_t actual_dest_len);
+
+/*
+ * lz4_decompress_unknownoutputsize()
+ * src : source address of the compressed data
+ * src_len : is the input size, therefore the compressed size
+ * dest: output buffer address of the decompressed data
+ * dest_len: is the max size of the destination buffer, which is
+ * returned with actual size of decompressed data after
+ * decompress done
+ * return  : Success if return 0
+ *   Error if return (< 0)
+ * note :  Destination buffer must be already allocated.
+ */
+int lz4_decompress_unknownoutputsize(const char *src, size_t src_len,
+   char *dest, size_t *dest_len);
+#endif
diff --git a/lib/lz4/lz4_decompress.c b/lib/lz4/lz4_decompress.c
new file mode 100644
index 000..dcc8975
--- /dev/null
+++ b/lib/lz4/lz4_decompress.c
@@ -0,0 +1,326 @@
+/*
+ * LZ4 Decompressor for Linux kernel
+ *
+ * Copyright (C) 2013 LG Electronics Co., Ltd. (http://www.lge.com/)
+ *
+ * Based on LZ4 implementation by Yann Collet.
+ *
+ * LZ4 - Fast LZ compression algorithm
+ * Copyright (C) 2011-2012, Yann Collet.
+ * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *  You can contact the author at :
+ *  - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
+ *  - LZ4 source repository : http://code.google.com/p/lz4/
+

Re: [RFC PATCH v2 2/4] lib: Add support for LZ4-compressed kernel

2013-02-27 Thread Kyungsik Lee
On Tue, Feb 26, 2013 at 03:00:51PM +0100, David Sterba wrote:
> On Tue, Feb 26, 2013 at 03:24:28PM +0900, Kyungsik Lee wrote:
> > +config KERNEL_LZ4
> > +   bool "LZ4"
> > +   depends on HAVE_KERNEL_LZ4
> > +   help
> > + Its compression ratio is worse than LZO. The size of the kernel
> > + is about 8% bigger than LZO. But the decompression speed is
> > + faster than LZO.
> > +
> 
> Can you please add a sentence what lz4 actually is before you start
> comparing it with the current competitor(s)?
Yes, I will update it.

> > --- /dev/null
> > +++ b/lib/decompress_unlz4.c
> > @@ -0,0 +1,190 @@
> > +#define LZ4_CHUNK_SIZE (8<<20)
> 
> Please use a less cryptic way of representing a value of 8 MB. Also,
> this is a hardcoded value that must be used on the compressor side. It's
> an upper limit, so anything below 8MB does not break decompresssion, but
> this must be somehow checked or saved along in the binary stream. You
> seem to use the lz4demo.c on the userspace side for compression, but
> this is not a standard tool nor the output format is well-defined or
> stabilized.
Yes, It will be easy to parse and extract the meta information required
for the kernel decompressor if output format is well-defined and
standardized.

> For proper use I would like to see a commandline tool similar to
> gzip/bzip2/lzop that can be packaged and shipped by distros, and the
> output format defintion.
> 
> Yann has some ideas for the format
> http://fastcompression.blogspot.cz/2012/04/file-container-format-for-lz4.html
Actually, I would like to use a packaged tool by distros too.
lz4demo is what I use for compressing the kernel so far.
I name it lz4 in the patch.

> For kernel, the minimum of meta information is total compressed length,
> total uncompressed length and chunk size. I don't know if the first two
> aren't stored elsewhere in the generic kernel image headers, but chunk
> size must be specified.
Right, Currently the chunk size used in the kernel decompressor is the same
as defined in lz4demo but it should have been provided as meta
information.

Thanks,
Kyungsik
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH v2 0/4] Add support for LZ4-compressed kernel

2013-02-27 Thread Kyungsik Lee
On Wed, Feb 27, 2013 at 09:51:39AM +, Russell King - ARM Linux wrote:
> On Wed, Feb 27, 2013 at 04:36:47PM +0900, Kyungsik Lee wrote:
> > Compiler: Linaro ARM gcc 4.6.2
> > 2. ARMv7, 1.7GHz based board
> >Kernel: linux 3.7
> >Uncompressed Kernel Size: 14MB
> >  Compressed Size  Decompression Speed
> > LZO  6.0MB34.1MB/sOld
> >  
> >  6.0MB34.7MB/sNew
> >  6.0MB52.2MB/s(UA)
> > =
> > LZ4  6.5MB86.7MB/s
> > UA: Unaligned memory Access support
> 
> That is pretty conclusive - it shows an 8% increase in image size vs a
> 66% increase in decompression speed.  It will take a _lot_ to offset
> that increase in decompression speed.
> 
> So, what I think is that yes, we should accept LZ4 and drop LZO from
> the kernel - the "fast but may not be small" compression title has
> clearly been taken by LZ4.

I have read the comments regarding how many compressors the kernel
should support and understand that it can not support all the
compressors available.

However, I don't think that LZO can be replaced by LZ4 in all the
cases. The benchmark above shows only about improved decompression
speed.

Thanks,
Kyungsik

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH v2 0/4] Add support for LZ4-compressed kernel

2013-02-26 Thread Kyungsik Lee
On Tue, Feb 26, 2013 at 09:33:22PM +0100, Markus F.X.J. Oberhumer wrote:
> On 2013-02-26 07:24, Kyungsik Lee wrote:
> > Hi,
> > 
> > [...]
> > 
> > Through the benchmark, it was found that -Os Compiler flag for
> > decompress.o brought better decompression performance in most of cases
> > (ex, different compiler and hardware spec.) in ARM architecture.
> > 
> > Lastly, CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is not always the best
> > option even though it is supported. The decompression speed can be
> > slightly slower in some cases.
> > 
> > This patchset is based on 3.8.
> > 
> > Any comments are appreciated.
> 
> Did you actually *try* the new LZO version and the patch (which is attached
> once again) as explained in https://lkml.org/lkml/2013/2/3/367 ?
> 
> Because the new LZO version is faster than LZ4 in my testing, at least
> when comparing apples with apples and enabling unaligned access in
> BOTH versions:
> 
> armv7 (Cortex-A9), Linaro gcc-4.6 -O3, Silesia test corpus, 256 kB block-size:
> 
>compression speed   decompression speed
> 
>   LZO-2012:  44 MB/sec  117 MB/sec no unaligned access
>   LZO-2013-UA :  47 MB/sec  167 MB/sec Unaligned Access
>   LZ4 r88  UA :  46 MB/sec  154 MB/sec Unaligned Access
>

I agree that the new LZO version provided shows better decompression
speed than 3.7 based. It is much improved especially for UA.

Compiler: Linaro ARM gcc 4.6.2
2. ARMv7, 1.7GHz based board
   Kernel: linux 3.7
   Uncompressed Kernel Size: 14MB
 Compressed Size  Decompression Speed
LZO  6.0MB34.1MB/sOld
 
 6.0MB34.7MB/sNew
 6.0MB52.2MB/s(UA)
=
LZ4  6.5MB86.7MB/s
UA: Unaligned memory Access support

One thing I can say that the code you may have used, guessing
"lz4demo" is not the same code provided in this patch.
It has been ported for the kernel and uses different function
not like the "lz4demo". 

Thanks,
Kyungsik

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC PATCH v2 1/4] decompressor: Add LZ4 decompressor module

2013-02-26 Thread Kyungsik Lee
On Tue, Feb 26, 2013 at 02:12:06PM +0100, David Sterba wrote:
> On Tue, Feb 26, 2013 at 03:24:27PM +0900, Kyungsik Lee wrote:
> > This patch adds support for LZ4 decompression in the Linux Kernel.
> > LZ4 Decompression APIs for kernel are based on LZ4 implementation
> > by Yann Collet.
> > 
> > LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
> > LZ4 source repository : http://code.google.com/p/lz4/
> 
> What SVN version did you use?
It's based on r88.

> > +/*
> > + * LZ4_COMPRESSBOUND()
> > + * Provides the maximum size that LZ4 may output in a "worst case" scenario
> > + * (input data not compressible)
> > + */
> > +#define LZ4_COMPRESSBOUND(isize) (isize + ((isize)/255) + 16)
> 
> For safety reasons I suggest to add a temporary variable to avoid double
> evaluation of isize.
Yes, Good point.
> > --- /dev/null
> > +++ b/lib/lz4/lz4_decompress.c
> > +   }
> > +   cpy = op + length - (STEPSIZE - 4);
> > +   if (cpy > oend - COPYLENGTH) {
> > +
> > +   /* Error: request to write beyond destination buffer */
> > +   if (cpy > oend)
> > +   goto _output_error;
> > +   LZ4_SECURECOPY(ref, op, (oend - COPYLENGTH));
> > +   while (op < cpy)
> > +   *op++ = *ref++;
> > +   op = cpy;
> > +   /*
> > +* Check EOF (should never happen, since last 5 bytes
> > +* are supposed to be literals)
> > +*/
> > +   if (op == oend)
> > +   goto _output_error;
> > +   continue;
> > +   }
> > +   LZ4_SECURECOPY(ref, op, cpy);
> > +   op = cpy; /* correction */
> > +   }
> 
> Does this compile? The } is an extra one, and does not match the
> original sources.
>
It's about indent errors. The } is a pair of braces regarding
"while (1) {". However it compiled. It will be fixed.
 
> > +#define LZ4_COPYPACKET(s, d)   \
> > +   do {\
> > +   LZ4_COPYSTEP(s, d); \
> > +   LZ4_COPYSTEP(s, d); \
> > +   } while (0)
> > +
> > +#define LZ4_SECURECOPY LZ4_WILDCOPY
> > +#endif
> > +
> > +#define LZ4_READ_LITTLEENDIAN_16(d, s, p) \
> > +   (d = s - get_unaligned_le16(p))
> > +#define LZ4_WILDCOPY(s, d, e)  \
> > +   do {\
> > +   LZ4_COPYPACKET(s, d);   \
> > +   } while (d < e)
> 
> All the \ at the ends of lines would look better aligned in one column.
>
Yes, right. It looks better if it's aligned.

Thanks,
Kyungsik
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v2 3/4] arm: Add support for LZ4-compressed kernel

2013-02-25 Thread Kyungsik Lee
This patch integrates the LZ4 decompression code to the arm pre-boot code.
And it depends on two patchs below

lib: Add support for LZ4-compressed kernel
decompressor: Add LZ4 decompressor module

Signed-off-by: Kyungsik Lee 

v2:
- Apply CFLAGS, -Os to decompress.o to improve decompress
  performance during boot-up process
---
 arch/arm/Kconfig  | 1 +
 arch/arm/boot/compressed/.gitignore   | 1 +
 arch/arm/boot/compressed/Makefile | 6 +-
 arch/arm/boot/compressed/decompress.c | 4 
 arch/arm/boot/compressed/piggy.lz4.S  | 6 ++
 5 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/boot/compressed/piggy.lz4.S

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 67874b8..0f9b363 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -38,6 +38,7 @@ config ARM
select HAVE_IDE if PCI || ISA || PCMCIA
select HAVE_IRQ_WORK
select HAVE_KERNEL_GZIP
+   select HAVE_KERNEL_LZ4
select HAVE_KERNEL_LZMA
select HAVE_KERNEL_LZO
select HAVE_KERNEL_XZ
diff --git a/arch/arm/boot/compressed/.gitignore 
b/arch/arm/boot/compressed/.gitignore
index f79a08e..47279aa 100644
--- a/arch/arm/boot/compressed/.gitignore
+++ b/arch/arm/boot/compressed/.gitignore
@@ -6,6 +6,7 @@ piggy.gzip
 piggy.lzo
 piggy.lzma
 piggy.xzkern
+piggy.lz4
 vmlinux
 vmlinux.lds
 
diff --git a/arch/arm/boot/compressed/Makefile 
b/arch/arm/boot/compressed/Makefile
index 5cad8a6..2249d52 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -24,6 +24,9 @@ endif
 AFLAGS_head.o += -DTEXT_OFFSET=$(TEXT_OFFSET)
 HEAD   = head.o
 OBJS   += misc.o decompress.o
+ifeq ($(CONFIG_KERNEL_LZ4),y)
+CFLAGS_decompress.o := -Os
+endif
 FONTC  = $(srctree)/drivers/video/console/font_acorn_8x8.c
 
 # string library code (-Os is enforced to keep it much smaller)
@@ -88,6 +91,7 @@ suffix_$(CONFIG_KERNEL_GZIP) = gzip
 suffix_$(CONFIG_KERNEL_LZO)  = lzo
 suffix_$(CONFIG_KERNEL_LZMA) = lzma
 suffix_$(CONFIG_KERNEL_XZ)   = xzkern
+suffix_$(CONFIG_KERNEL_LZ4)  = lz4
 
 # Borrowed libfdt files for the ATAG compatibility mode
 
@@ -112,7 +116,7 @@ targets   := vmlinux vmlinux.lds \
 font.o font.c head.o misc.o $(OBJS)
 
 # Make sure files are removed during clean
-extra-y   += piggy.gzip piggy.lzo piggy.lzma piggy.xzkern \
+extra-y   += piggy.gzip piggy.lzo piggy.lzma piggy.xzkern piggy.lz4 \
 lib1funcs.S ashldi3.S $(libfdt) $(libfdt_hdrs)
 
 ifeq ($(CONFIG_FUNCTION_TRACER),y)
diff --git a/arch/arm/boot/compressed/decompress.c 
b/arch/arm/boot/compressed/decompress.c
index 9deb56a..a95f071 100644
--- a/arch/arm/boot/compressed/decompress.c
+++ b/arch/arm/boot/compressed/decompress.c
@@ -53,6 +53,10 @@ extern char * strstr(const char * s1, const char *s2);
 #include "../../../../lib/decompress_unxz.c"
 #endif
 
+#ifdef CONFIG_KERNEL_LZ4
+#include "../../../../lib/decompress_unlz4.c"
+#endif
+
 int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x))
 {
return decompress(input, len, NULL, NULL, output, NULL, error);
diff --git a/arch/arm/boot/compressed/piggy.lz4.S 
b/arch/arm/boot/compressed/piggy.lz4.S
new file mode 100644
index 000..3d9a575
--- /dev/null
+++ b/arch/arm/boot/compressed/piggy.lz4.S
@@ -0,0 +1,6 @@
+   .section .piggydata,#alloc
+   .globl  input_data
+input_data:
+   .incbin "arch/arm/boot/compressed/piggy.lz4"
+   .globl  input_data_end
+input_data_end:
-- 
1.8.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v2 4/4] x86: Add support for LZ4-compressed kernel

2013-02-25 Thread Kyungsik Lee
This patch integrates the LZ4 decompression code to the x86 pre-boot code.
And it depends on two patchs below

lib: Add support for LZ4-compressed kernel
decompressor: Add LZ4 decompressor module

Signed-off-by: Kyungsik Lee 
---
 arch/x86/Kconfig  | 1 +
 arch/x86/boot/compressed/Makefile | 5 -
 arch/x86/boot/compressed/misc.c   | 4 
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 225543b..ab916fd 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -63,6 +63,7 @@ config X86
select HAVE_KERNEL_LZMA
select HAVE_KERNEL_XZ
select HAVE_KERNEL_LZO
+   select HAVE_KERNEL_LZ4
select HAVE_HW_BREAKPOINT
select HAVE_MIXED_BREAKPOINTS_REGS
select PERF_EVENTS
diff --git a/arch/x86/boot/compressed/Makefile 
b/arch/x86/boot/compressed/Makefile
index 8a84501..c275db5 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -4,7 +4,7 @@
 # create a compressed vmlinux image from the original vmlinux
 #
 
-targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 
vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo head_$(BITS).o misc.o string.o 
cmdline.o early_serial_console.o piggy.o
+targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 
vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 head_$(BITS).o 
misc.o string.o cmdline.o early_serial_console.o piggy.o
 
 KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2
 KBUILD_CFLAGS += -fno-strict-aliasing -fPIC
@@ -64,12 +64,15 @@ $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
$(call if_changed,xzkern)
 $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
$(call if_changed,lzo)
+$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
+   $(call if_changed,lz4)
 
 suffix-$(CONFIG_KERNEL_GZIP)   := gz
 suffix-$(CONFIG_KERNEL_BZIP2)  := bz2
 suffix-$(CONFIG_KERNEL_LZMA)   := lzma
 suffix-$(CONFIG_KERNEL_XZ) := xz
 suffix-$(CONFIG_KERNEL_LZO):= lzo
+suffix-$(CONFIG_KERNEL_LZ4):= lz4
 
 quiet_cmd_mkpiggy = MKPIGGY $@
   cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false )
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 88f7ff6..166a0a8 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -145,6 +145,10 @@ static int lines, cols;
 #include "../../../../lib/decompress_unlzo.c"
 #endif
 
+#ifdef CONFIG_KERNEL_LZ4
+#include "../../../../lib/decompress_unlz4.c"
+#endif
+
 static void scroll(void)
 {
int i;
-- 
1.8.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v2 2/4] lib: Add support for LZ4-compressed kernel

2013-02-25 Thread Kyungsik Lee
This patch adds support for extracting LZ4-compressed kernel images,
as well as LZ4-compressed ramdisk images in the kernel boot process.

This depends on the patch below
decompressor: Add LZ4 decompressor module

Signed-off-by: Kyungsik Lee 

v2:
- Clean up code
- Use lz4_decompress() for LZ4-compressed kernel during boot-process
---
 include/linux/decompress/unlz4.h |  10 +++
 init/Kconfig |  13 ++-
 lib/Kconfig  |   7 ++
 lib/Makefile |   2 +
 lib/decompress.c |   5 ++
 lib/decompress_unlz4.c   | 190 +++
 lib/lz4/Makefile |   1 +
 lib/lz4/lz4_decompress.c |   2 +-
 scripts/Makefile.lib |   5 ++
 usr/Kconfig  |   9 ++
 10 files changed, 242 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/decompress/unlz4.h
 create mode 100644 lib/decompress_unlz4.c
 create mode 100644 lib/lz4/Makefile

diff --git a/include/linux/decompress/unlz4.h b/include/linux/decompress/unlz4.h
new file mode 100644
index 000..d5b68bf
--- /dev/null
+++ b/include/linux/decompress/unlz4.h
@@ -0,0 +1,10 @@
+#ifndef DECOMPRESS_UNLZ4_H
+#define DECOMPRESS_UNLZ4_H
+
+int unlz4(unsigned char *inbuf, int len,
+   int(*fill)(void*, unsigned int),
+   int(*flush)(void*, unsigned int),
+   unsigned char *output,
+   int *pos,
+   void(*error)(char *x));
+#endif
diff --git a/init/Kconfig b/init/Kconfig
index be8b7f5..86dc67c 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -133,10 +133,13 @@ config HAVE_KERNEL_XZ
 config HAVE_KERNEL_LZO
bool
 
+config HAVE_KERNEL_LZ4
+   bool
+
 choice
prompt "Kernel compression mode"
default KERNEL_GZIP
-   depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || 
HAVE_KERNEL_XZ || HAVE_KERNEL_LZO
+   depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || 
HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4
help
  The linux kernel is a kind of self-extracting executable.
  Several compression algorithms are available, which differ
@@ -203,6 +206,14 @@ config KERNEL_LZO
  size is about 10% bigger than gzip; however its speed
  (both compression and decompression) is the fastest.
 
+config KERNEL_LZ4
+   bool "LZ4"
+   depends on HAVE_KERNEL_LZ4
+   help
+ Its compression ratio is worse than LZO. The size of the kernel
+ is about 8% bigger than LZO. But the decompression speed is
+ faster than LZO.
+
 endchoice
 
 config DEFAULT_HOSTNAME
diff --git a/lib/Kconfig b/lib/Kconfig
index 75cdb77..b108047 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -189,6 +189,9 @@ config LZO_COMPRESS
 config LZO_DECOMPRESS
tristate
 
+config LZ4_DECOMPRESS
+   tristate
+
 source "lib/xz/Kconfig"
 
 #
@@ -213,6 +216,10 @@ config DECOMPRESS_LZO
select LZO_DECOMPRESS
tristate
 
+config DECOMPRESS_LZ4
+   select LZ4_DECOMPRESS
+   tristate
+
 #
 # Generic allocator support is selected if needed
 #
diff --git a/lib/Makefile b/lib/Makefile
index 02ed6c0..c2073bf 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_REED_SOLOMON) += reed_solomon/
 obj-$(CONFIG_BCH) += bch.o
 obj-$(CONFIG_LZO_COMPRESS) += lzo/
 obj-$(CONFIG_LZO_DECOMPRESS) += lzo/
+obj-$(CONFIG_LZ4_DECOMPRESS) += lz4/
 obj-$(CONFIG_XZ_DEC) += xz/
 obj-$(CONFIG_RAID6_PQ) += raid6/
 
@@ -80,6 +81,7 @@ lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o
 lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o
 lib-$(CONFIG_DECOMPRESS_XZ) += decompress_unxz.o
 lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o
+lib-$(CONFIG_DECOMPRESS_LZ4) += decompress_unlz4.o
 
 obj-$(CONFIG_TEXTSEARCH) += textsearch.o
 obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o
diff --git a/lib/decompress.c b/lib/decompress.c
index 31a8042..c70810e 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -31,6 +32,9 @@
 #ifndef CONFIG_DECOMPRESS_LZO
 # define unlzo NULL
 #endif
+#ifndef CONFIG_DECOMPRESS_LZ4
+# define unlz4 NULL
+#endif
 
 struct compress_format {
unsigned char magic[2];
@@ -45,6 +49,7 @@ static const struct compress_format compressed_formats[] 
__initdata = {
{ {0x5d, 0x00}, "lzma", unlzma },
{ {0xfd, 0x37}, "xz", unxz },
{ {0x89, 0x4c}, "lzo", unlzo },
+   { {0x02, 0x21}, "lz4", unlz4 },
{ {0, 0}, NULL, NULL }
 };
 
diff --git a/lib/decompress_unlz4.c b/lib/decompress_unlz4.c
new file mode 100644
index 000..84346c4
--- /dev/null
+++ b/lib/decompress_unlz4.c
@@ -0,0 +1,190 @@
+/*
+ * Wrapper for decompressing LZ4-compressed kernel, initramfs, and initrd
+ *
+ * Copyright (C) 2013, LG Electronics, Kyungsik Lee 
+ *
+ * This program is free software; you can redistribute it and/or

[RFC PATCH v2 1/4] decompressor: Add LZ4 decompressor module

2013-02-25 Thread Kyungsik Lee
This patch adds support for LZ4 decompression in the Linux Kernel.
LZ4 Decompression APIs for kernel are based on LZ4 implementation
by Yann Collet.

LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
LZ4 source repository : http://code.google.com/p/lz4/

Signed-off-by: Kyungsik Lee 

v2:
- Clean up code
- Enable unaligned access for ARM v6 and above with
  CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
- Add lz4_decompress() for faster decompression with
  uncompressed output size
---
 include/linux/lz4.h  |  48 +++
 lib/lz4/lz4_decompress.c | 331 +++
 lib/lz4/lz4defs.h|  93 +
 3 files changed, 472 insertions(+)
 create mode 100644 include/linux/lz4.h
 create mode 100644 lib/lz4/lz4_decompress.c
 create mode 100644 lib/lz4/lz4defs.h

diff --git a/include/linux/lz4.h b/include/linux/lz4.h
new file mode 100644
index 000..66b504c
--- /dev/null
+++ b/include/linux/lz4.h
@@ -0,0 +1,48 @@
+#ifndef __LZ4_H__
+#define __LZ4_H__
+/*
+ * LZ4 Kernel Interface
+ *
+ * Copyright (C) 2013, LG Electronics, Kyungsik Lee 
+ *
+ * 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.
+ */
+
+/*
+ * LZ4_COMPRESSBOUND()
+ * Provides the maximum size that LZ4 may output in a "worst case" scenario
+ * (input data not compressible)
+ */
+#define LZ4_COMPRESSBOUND(isize) (isize + ((isize)/255) + 16)
+
+/*
+ * lz4_decompress()
+ * src : source address of the compressed data
+ * src_len : is the input size, whcih is returned after decompress done
+ * dest: output buffer address of the decompressed data
+ * actual_dest_len: is the size of uncompressed data, supposing it's known
+ * return  : Success if return 0
+ *   Error if return (< 0)
+ * note :  Destination buffer must be already allocated.
+ * a bit faster than lz4_decompress_unknownoutputsize()
+ */
+int lz4_decompress(const char *src, size_t *src_len, char *dest,
+   size_t actual_dest_len);
+
+/*
+ * lz4_decompress_unknownoutputsize()
+ * src : source address of the compressed data
+ * src_len : is the input size, therefore the compressed size
+ * dest: output buffer address of the decompressed data
+ * dest_len: is the max size of the destination buffer, which is
+ * returned with actual size of decompressed data after
+ * decompress done
+ * return  : Success if return 0
+ *   Error if return (< 0)
+ * note :  Destination buffer must be already allocated.
+ */
+int lz4_decompress_unknownoutputsize(const char *src, size_t src_len,
+   char *dest, size_t *dest_len);
+#endif
diff --git a/lib/lz4/lz4_decompress.c b/lib/lz4/lz4_decompress.c
new file mode 100644
index 000..1998d7a
--- /dev/null
+++ b/lib/lz4/lz4_decompress.c
@@ -0,0 +1,331 @@
+/*
+ * LZ4 Decompressor for Linux kernel
+ *
+ * Copyright (C) 2013 LG Electronics Co., Ltd. (http://www.lge.com/)
+ *
+ * Based on LZ4 implementation by Yann Collet.
+ *
+ * LZ4 - Fast LZ compression algorithm
+ * Copyright (C) 2011-2012, Yann Collet.
+ * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *  You can contact the author at :
+ *  - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
+ *  - LZ4 source repository : http://code.google.com/p/lz4/
+ */
+
+#ifndef STATIC
+#include 
+#include 
+#endif
+#include 
+
+#include 
+
+#include "lz4defs.h"
+
+static int lz4_uncom

[RFC PATCH v2 0/4] Add support for LZ4-compressed kernel

2013-02-25 Thread Kyungsik Lee
Hi,

First of all, Thank you for the comments and emails from the community.

Here is the second version of support for LZ4-compressed kernel.
In this version, lz4_decompress() has been added. In case of knowing
the uncompressed data size, this function can be used to decompress
more faster.

Through the benchmark, it was found that -Os Compiler flag for
decompress.o brought better decompression performance in most of cases
(ex, different compiler and hardware spec.) in ARM architecture.

Lastly, CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is not always the best
option even though it is supported. The decompression speed can be
slightly slower in some cases.

This patchset is based on 3.8.

Any comments are appreciated.

Thanks,
Kyungsik


Benchmark Results(PATCH v2)
Compiler: Linaro ARM gcc 4.6.2
1. ARMv7, 1.5GHz based board
   Kernel: linux 3.4
   Uncompressed Kernel Size: 14MB
Compressed Size  Decompression Speed
   LZO  6.7MB21.1MB/s
   LZ4  7.3MB29.1MB/s, 45.6MB/s(UA)
2. ARMv7, 1.7GHz based board
   Kernel: linux 3.7
   Uncompressed Kernel Size: 14MB
Compressed Size  Decompression Speed
   LZO  6.0MB34.1MB/s
   LZ4  6.5MB86.7MB/s
UA: Unaligned memory Access support


Change log: v2
- Clean up code
- Enable unaligned access for ARM v6 and above with
  CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
- Add lz4_decompress() for faster decompression with
  uncompressed output size
- Use lz4_decompress() for LZ4-compressed kernel during
  boot-process
- Apply -Os to decompress.o to improve decompress
  performance during boot-up process


Kyungsik Lee (4):
  decompressor: Add LZ4 decompressor module
  lib: Add support for LZ4-compressed kernel
  arm: Add support for LZ4-compressed kernel
  x86: Add support for LZ4-compressed kernel

 arch/arm/Kconfig  |   1 +
 arch/arm/boot/compressed/.gitignore   |   1 +
 arch/arm/boot/compressed/Makefile |   6 +-
 arch/arm/boot/compressed/decompress.c |   4 +
 arch/arm/boot/compressed/piggy.lz4.S  |   6 +
 arch/x86/Kconfig  |   1 +
 arch/x86/boot/compressed/Makefile |   5 +-
 arch/x86/boot/compressed/misc.c   |   4 +
 include/linux/decompress/unlz4.h  |  10 +
 include/linux/lz4.h   |  48 +
 init/Kconfig  |  13 +-
 lib/Kconfig   |   7 +
 lib/Makefile  |   2 +
 lib/decompress.c  |   5 +
 lib/decompress_unlz4.c| 190 +++
 lib/lz4/Makefile  |   1 +
 lib/lz4/lz4_decompress.c  | 331 ++
 lib/lz4/lz4defs.h |  93 ++
 scripts/Makefile.lib  |   5 +
 usr/Kconfig   |   9 +
 20 files changed, 739 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/boot/compressed/piggy.lz4.S
 create mode 100644 include/linux/decompress/unlz4.h
 create mode 100644 include/linux/lz4.h
 create mode 100644 lib/decompress_unlz4.c
 create mode 100644 lib/lz4/Makefile
 create mode 100644 lib/lz4/lz4_decompress.c
 create mode 100644 lib/lz4/lz4defs.h

-- 
1.8.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] btrfs: use kmalloc for lzo de/compress buffer

2013-02-22 Thread Kyungsik Lee
On Thu, Feb 21, 2013 at 02:41:53PM +0100, David Sterba wrote:
> On Mon, Feb 18, 2013 at 04:56:04PM +0900, Kyungsik Lee wrote:
> > @@ -55,8 +55,9 @@ static struct list_head *lzo_alloc_workspace(void)
> > return ERR_PTR(-ENOMEM);
> >  
> > workspace->mem = vmalloc(LZO1X_MEM_COMPRESS);
> > -   workspace->buf = vmalloc(PAGE_CACHE_SIZE);
> > -   workspace->cbuf = vmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE));
> > +   workspace->buf = kmalloc(PAGE_CACHE_SIZE, GFP_NOFS);
> > +   workspace->cbuf = kmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE),
> 
> This is still larger than usual page size and allocator may issue a
> warning, so if we want to use kmalloc (it's ~4.4k in size and likely to
> be available, but not always due to possible page fragmentation), the
> __GFP_NOWARN should be supplied and if the allocation fails fall back to
> vmalloc.
Right, there shoud be another fixed verson for this.

Thanks,
Kyungsik
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] btrfs: use kmalloc for lzo de/compress buffer

2013-02-17 Thread Kyungsik Lee
The size of de/compress buffer is small enough to use kmalloc.
Allocating it with kmalloc rather than vmalloc is preferred.

This patch depends on my previous patch, “btrfs: fix decompress buffer size”.

v2: Using vmalloc for "workspace->mem" due to the size limit.

Signed-off-by: Kyungsik Lee 
Cc: David Sterba 
---
 fs/btrfs/lzo.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index 223893a..b2e 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -40,8 +40,8 @@ static void lzo_free_workspace(struct list_head *ws)
 {
struct workspace *workspace = list_entry(ws, struct workspace, list);
 
-   vfree(workspace->buf);
-   vfree(workspace->cbuf);
+   kfree(workspace->buf);
+   kfree(workspace->cbuf);
vfree(workspace->mem);
kfree(workspace);
 }
@@ -55,8 +55,9 @@ static struct list_head *lzo_alloc_workspace(void)
return ERR_PTR(-ENOMEM);
 
workspace->mem = vmalloc(LZO1X_MEM_COMPRESS);
-   workspace->buf = vmalloc(PAGE_CACHE_SIZE);
-   workspace->cbuf = vmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE));
+   workspace->buf = kmalloc(PAGE_CACHE_SIZE, GFP_NOFS);
+   workspace->cbuf = kmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE),
+   GFP_NOFS);
if (!workspace->mem || !workspace->buf || !workspace->cbuf)
goto fail;
 
-- 
1.8.0.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] btrfs: use kmalloc for lzo de/compress buffer

2013-02-15 Thread Kyungsik Lee
The size of de/compress buffer and LZO1X_MEM_COMPRESS is small enough.
Allocating it with kmalloc rather than vmalloc is preferred.

This patch depends on my previous patch, “btrfs: fix decompress buffer size”.

Signed-off-by: Kyungsik Lee 
Cc: David Sterba 
---
 fs/btrfs/lzo.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index 223893a..f223742 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -18,7 +18,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -40,9 +39,9 @@ static void lzo_free_workspace(struct list_head *ws)
 {
struct workspace *workspace = list_entry(ws, struct workspace, list);
 
-   vfree(workspace->buf);
-   vfree(workspace->cbuf);
-   vfree(workspace->mem);
+   kfree(workspace->buf);
+   kfree(workspace->cbuf);
+   kfree(workspace->mem);
kfree(workspace);
 }
 
@@ -54,9 +53,10 @@ static struct list_head *lzo_alloc_workspace(void)
if (!workspace)
return ERR_PTR(-ENOMEM);
 
-   workspace->mem = vmalloc(LZO1X_MEM_COMPRESS);
-   workspace->buf = vmalloc(PAGE_CACHE_SIZE);
-   workspace->cbuf = vmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE));
+   workspace->mem = kmalloc(LZO1X_MEM_COMPRESS, GFP_NOFS);
+   workspace->buf = kmalloc(PAGE_CACHE_SIZE, GFP_NOFS);
+   workspace->cbuf = kmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE),
+   GFP_NOFS);
if (!workspace->mem || !workspace->buf || !workspace->cbuf)
goto fail;
 
-- 
1.8.0.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] btrfs: fix decompress buffer size

2013-02-14 Thread Kyungsik Lee
lzo1x_1_compress() is unnecessarily used for allocating decompress buffer.

Signed-off-by: Kyungsik Lee 
---
 fs/btrfs/lzo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index 743b86f..223893a 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -55,7 +55,7 @@ static struct list_head *lzo_alloc_workspace(void)
return ERR_PTR(-ENOMEM);
 
workspace->mem = vmalloc(LZO1X_MEM_COMPRESS);
-   workspace->buf = vmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE));
+   workspace->buf = vmalloc(PAGE_CACHE_SIZE);
workspace->cbuf = vmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE));
if (!workspace->mem || !workspace->buf || !workspace->cbuf)
goto fail;
@@ -349,7 +349,7 @@ cont:
}
}
 
-   out_len = lzo1x_worst_compress(PAGE_CACHE_SIZE);
+   out_len = PAGE_CACHE_SIZE;
ret = lzo1x_decompress_safe(buf, in_len, workspace->buf,
&out_len);
if (need_unmap)
-- 
1.8.0.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH 2/4] lib: add support for LZ4-compressed kernels

2013-01-25 Thread Kyungsik Lee
This patch adds support for extracting LZ4-compressed kernel images,
as well as LZ4-compressed ramdisk images in the kernel boot process.

This depends on the patch below
decompressors: add lz4 decompressor module

Signed-off-by: Kyungsik Lee 
---
 include/linux/decompress/unlz4.h |  10 ++
 init/Kconfig |  13 ++-
 lib/Kconfig  |   7 ++
 lib/Makefile |   2 +
 lib/decompress.c |   5 +
 lib/decompress_unlz4.c   | 199 +++
 lib/lz4/Makefile |   1 +
 lib/lz4/lz4_decompress.c |   2 +-
 scripts/Makefile.lib |   5 +
 usr/Kconfig  |   9 ++
 10 files changed, 251 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/decompress/unlz4.h
 create mode 100644 lib/decompress_unlz4.c
 create mode 100644 lib/lz4/Makefile

diff --git a/include/linux/decompress/unlz4.h b/include/linux/decompress/unlz4.h
new file mode 100644
index 000..d5b68bf
--- /dev/null
+++ b/include/linux/decompress/unlz4.h
@@ -0,0 +1,10 @@
+#ifndef DECOMPRESS_UNLZ4_H
+#define DECOMPRESS_UNLZ4_H
+
+int unlz4(unsigned char *inbuf, int len,
+   int(*fill)(void*, unsigned int),
+   int(*flush)(void*, unsigned int),
+   unsigned char *output,
+   int *pos,
+   void(*error)(char *x));
+#endif
diff --git a/init/Kconfig b/init/Kconfig
index 1aefe1a..be3753e 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -102,10 +102,13 @@ config HAVE_KERNEL_XZ
 config HAVE_KERNEL_LZO
bool
 
+config HAVE_KERNEL_LZ4
+   bool
+
 choice
prompt "Kernel compression mode"
default KERNEL_GZIP
-   depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || 
HAVE_KERNEL_XZ || HAVE_KERNEL_LZO
+   depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || 
HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4
help
  The linux kernel is a kind of self-extracting executable.
  Several compression algorithms are available, which differ
@@ -172,6 +175,14 @@ config KERNEL_LZO
  size is about 10% bigger than gzip; however its speed
  (both compression and decompression) is the fastest.
 
+config KERNEL_LZ4
+   bool "LZ4"
+   depends on HAVE_KERNEL_LZ4
+   help
+ Its compression ratio is worse than LZO. The size of the kernel
+ is about 5% bigger than LZO. But the decompression speed is
+ faster than LZO.
+
 endchoice
 
 config DEFAULT_HOSTNAME
diff --git a/lib/Kconfig b/lib/Kconfig
index 75cdb77..b108047 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -189,6 +189,9 @@ config LZO_COMPRESS
 config LZO_DECOMPRESS
tristate
 
+config LZ4_DECOMPRESS
+   tristate
+
 source "lib/xz/Kconfig"
 
 #
@@ -213,6 +216,10 @@ config DECOMPRESS_LZO
select LZO_DECOMPRESS
tristate
 
+config DECOMPRESS_LZ4
+   select LZ4_DECOMPRESS
+   tristate
+
 #
 # Generic allocator support is selected if needed
 #
diff --git a/lib/Makefile b/lib/Makefile
index 02ed6c0..c2073bf 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_REED_SOLOMON) += reed_solomon/
 obj-$(CONFIG_BCH) += bch.o
 obj-$(CONFIG_LZO_COMPRESS) += lzo/
 obj-$(CONFIG_LZO_DECOMPRESS) += lzo/
+obj-$(CONFIG_LZ4_DECOMPRESS) += lz4/
 obj-$(CONFIG_XZ_DEC) += xz/
 obj-$(CONFIG_RAID6_PQ) += raid6/
 
@@ -80,6 +81,7 @@ lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o
 lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o
 lib-$(CONFIG_DECOMPRESS_XZ) += decompress_unxz.o
 lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o
+lib-$(CONFIG_DECOMPRESS_LZ4) += decompress_unlz4.o
 
 obj-$(CONFIG_TEXTSEARCH) += textsearch.o
 obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o
diff --git a/lib/decompress.c b/lib/decompress.c
index 31a8042..c70810e 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -31,6 +32,9 @@
 #ifndef CONFIG_DECOMPRESS_LZO
 # define unlzo NULL
 #endif
+#ifndef CONFIG_DECOMPRESS_LZ4
+# define unlz4 NULL
+#endif
 
 struct compress_format {
unsigned char magic[2];
@@ -45,6 +49,7 @@ static const struct compress_format compressed_formats[] 
__initdata = {
{ {0x5d, 0x00}, "lzma", unlzma },
{ {0xfd, 0x37}, "xz", unxz },
{ {0x89, 0x4c}, "lzo", unlzo },
+   { {0x02, 0x21}, "lz4", unlz4 },
{ {0, 0}, NULL, NULL }
 };
 
diff --git a/lib/decompress_unlz4.c b/lib/decompress_unlz4.c
new file mode 100644
index 000..6b6a8d0
--- /dev/null
+++ b/lib/decompress_unlz4.c
@@ -0,0 +1,199 @@
+/*
+ * LZ4 decompressor for the Linux kernel.
+ *
+ * Linux kernel adaptation:
+ * Copyright (C) 2013, LG Electronics, Kyungsik Lee 
+ *
+ * Based on LZ4 implementation by Yann Collet.
+ *
+ * LZ4 - Fast LZ compression algorithm
+ * Copyright (C) 2011-2012, Yann Collet.
+ * BSD 2-Clause License (http

[RFC PATCH 3/4] arm: add support for LZ4-compressed kernels

2013-01-25 Thread Kyungsik Lee
This patch integrates the LZ4 decompression code to the arm pre-boot code.
And it depends on two patchs below

lib: add support for LZ4-compressed kernels
decompressors: add lz4 decompressor module

Signed-off-by: Kyungsik Lee 
---
 arch/arm/Kconfig  | 1 +
 arch/arm/boot/compressed/.gitignore   | 1 +
 arch/arm/boot/compressed/Makefile | 3 ++-
 arch/arm/boot/compressed/decompress.c | 4 
 arch/arm/boot/compressed/piggy.lz4.S  | 6 ++
 5 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/boot/compressed/piggy.lz4.S

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 91f8d78..1b3621d 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -37,6 +37,7 @@ config ARM
select HAVE_HW_BREAKPOINT if (PERF_EVENTS && (CPU_V6 || CPU_V6K || 
CPU_V7))
select HAVE_IDE if PCI || ISA || PCMCIA
select HAVE_KERNEL_GZIP
+   select HAVE_KERNEL_LZ4
select HAVE_KERNEL_LZMA
select HAVE_KERNEL_LZO
select HAVE_KERNEL_XZ
diff --git a/arch/arm/boot/compressed/.gitignore 
b/arch/arm/boot/compressed/.gitignore
index f79a08e..47279aa 100644
--- a/arch/arm/boot/compressed/.gitignore
+++ b/arch/arm/boot/compressed/.gitignore
@@ -6,6 +6,7 @@ piggy.gzip
 piggy.lzo
 piggy.lzma
 piggy.xzkern
+piggy.lz4
 vmlinux
 vmlinux.lds
 
diff --git a/arch/arm/boot/compressed/Makefile 
b/arch/arm/boot/compressed/Makefile
index 5cad8a6..8b5c79a 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -88,6 +88,7 @@ suffix_$(CONFIG_KERNEL_GZIP) = gzip
 suffix_$(CONFIG_KERNEL_LZO)  = lzo
 suffix_$(CONFIG_KERNEL_LZMA) = lzma
 suffix_$(CONFIG_KERNEL_XZ)   = xzkern
+suffix_$(CONFIG_KERNEL_LZ4)  = lz4
 
 # Borrowed libfdt files for the ATAG compatibility mode
 
@@ -112,7 +113,7 @@ targets   := vmlinux vmlinux.lds \
 font.o font.c head.o misc.o $(OBJS)
 
 # Make sure files are removed during clean
-extra-y   += piggy.gzip piggy.lzo piggy.lzma piggy.xzkern \
+extra-y   += piggy.gzip piggy.lzo piggy.lzma piggy.xzkern piggy.lz4 \
 lib1funcs.S ashldi3.S $(libfdt) $(libfdt_hdrs)
 
 ifeq ($(CONFIG_FUNCTION_TRACER),y)
diff --git a/arch/arm/boot/compressed/decompress.c 
b/arch/arm/boot/compressed/decompress.c
index 9deb56a..a95f071 100644
--- a/arch/arm/boot/compressed/decompress.c
+++ b/arch/arm/boot/compressed/decompress.c
@@ -53,6 +53,10 @@ extern char * strstr(const char * s1, const char *s2);
 #include "../../../../lib/decompress_unxz.c"
 #endif
 
+#ifdef CONFIG_KERNEL_LZ4
+#include "../../../../lib/decompress_unlz4.c"
+#endif
+
 int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x))
 {
return decompress(input, len, NULL, NULL, output, NULL, error);
diff --git a/arch/arm/boot/compressed/piggy.lz4.S 
b/arch/arm/boot/compressed/piggy.lz4.S
new file mode 100644
index 000..3d9a575
--- /dev/null
+++ b/arch/arm/boot/compressed/piggy.lz4.S
@@ -0,0 +1,6 @@
+   .section .piggydata,#alloc
+   .globl  input_data
+input_data:
+   .incbin "arch/arm/boot/compressed/piggy.lz4"
+   .globl  input_data_end
+input_data_end:
-- 
1.8.0.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH 1/4] decompressors: add lz4 decompressor module

2013-01-25 Thread Kyungsik Lee
This patch adds support for LZ4 decompression in the kernel.
LZ4 Decompression APIs for kernel are based on LZ4 implementation
by Yann Collet.

LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
LZ4 source repository : http://code.google.com/p/lz4/

Signed-off-by: Kyungsik Lee 
---
 include/linux/lz4.h  |  62 +++
 lib/lz4/lz4_decompress.c | 199 +++
 lib/lz4/lz4defs.h| 129 ++
 3 files changed, 390 insertions(+)
 create mode 100644 include/linux/lz4.h
 create mode 100644 lib/lz4/lz4_decompress.c
 create mode 100644 lib/lz4/lz4defs.h

diff --git a/include/linux/lz4.h b/include/linux/lz4.h
new file mode 100644
index 000..df03dd8
--- /dev/null
+++ b/include/linux/lz4.h
@@ -0,0 +1,62 @@
+#ifndef __LZ4_H__
+#define __LZ4_H__
+/*
+ * LZ4 Decompressor Kernel Interface
+ *
+ * Copyright (C) 2013, LG Electronics, Kyungsik Lee 
+ * Based on LZ4 implementation by Yann Collet.
+ *
+ * LZ4 - Fast LZ compression algorithm
+ * Copyright (C) 2011-2012, Yann Collet.
+ * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You can contact the author at :
+ * - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
+ * - LZ4 source repository : http://code.google.com/p/lz4/
+ */
+
+
+/*
+ * LZ4_COMPRESSBOUND()
+ * Provides the maximum size that LZ4 may output in a "worst case" scenario
+ * (input data not compressible)
+ */
+#define LZ4_COMPRESSBOUND(isize) (isize + ((isize)/255) + 16)
+
+/*
+ * lz4_decompress()
+ * src : source address of the compressed data
+ * src_len : is the input size, therefore the compressed size
+ * dest: output buffer address of the decompressed data
+ * dest_len: is the size of the destination buffer
+ * (which must be already allocated)
+ * return  : Success if return 0
+ *   Error if return (< 0)
+ * note :  Destination buffer must be already allocated.
+ */
+int lz4_decompress(const char *src, size_t src_len, char *dest,
+   size_t *dest_len);
+#endif
diff --git a/lib/lz4/lz4_decompress.c b/lib/lz4/lz4_decompress.c
new file mode 100644
index 000..e8beb6b
--- /dev/null
+++ b/lib/lz4/lz4_decompress.c
@@ -0,0 +1,199 @@
+/*
+ * LZ4 Decompressor for Linux kernel
+ *
+ * Copyright (C) 2013 LG Electronics Co., Ltd. (http://www.lge.com/)
+ *
+ * Based on LZ4 implementation by Yann Collet.
+ *
+ * LZ4 - Fast LZ compression algorithm
+ * Copyright (C) 2011-2012, Yann Collet.
+ * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS O

[RFC PATCH 4/4] x86: add support for LZ4-compressed kernels

2013-01-25 Thread Kyungsik Lee
This patch integrates the LZ4 decompression code to the x86 pre-boot code.
And it depends on two patchs below

lib: add support for LZ4-compressed kernels
decompressors: add lz4 decompressor module

Signed-off-by: Kyungsik Lee 
---
 arch/x86/Kconfig  | 1 +
 arch/x86/boot/compressed/Makefile | 5 -
 arch/x86/boot/compressed/misc.c   | 4 
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 8c185d0..7142bef 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -62,6 +62,7 @@ config X86
select HAVE_KERNEL_LZMA
select HAVE_KERNEL_XZ
select HAVE_KERNEL_LZO
+   select HAVE_KERNEL_LZ4
select HAVE_HW_BREAKPOINT
select HAVE_MIXED_BREAKPOINTS_REGS
select PERF_EVENTS
diff --git a/arch/x86/boot/compressed/Makefile 
b/arch/x86/boot/compressed/Makefile
index 8a84501..c275db5 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -4,7 +4,7 @@
 # create a compressed vmlinux image from the original vmlinux
 #
 
-targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 
vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo head_$(BITS).o misc.o string.o 
cmdline.o early_serial_console.o piggy.o
+targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 
vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 head_$(BITS).o 
misc.o string.o cmdline.o early_serial_console.o piggy.o
 
 KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2
 KBUILD_CFLAGS += -fno-strict-aliasing -fPIC
@@ -64,12 +64,15 @@ $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
$(call if_changed,xzkern)
 $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
$(call if_changed,lzo)
+$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
+   $(call if_changed,lz4)
 
 suffix-$(CONFIG_KERNEL_GZIP)   := gz
 suffix-$(CONFIG_KERNEL_BZIP2)  := bz2
 suffix-$(CONFIG_KERNEL_LZMA)   := lzma
 suffix-$(CONFIG_KERNEL_XZ) := xz
 suffix-$(CONFIG_KERNEL_LZO):= lzo
+suffix-$(CONFIG_KERNEL_LZ4):= lz4
 
 quiet_cmd_mkpiggy = MKPIGGY $@
   cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false )
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 88f7ff6..166a0a8 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -145,6 +145,10 @@ static int lines, cols;
 #include "../../../../lib/decompress_unlzo.c"
 #endif
 
+#ifdef CONFIG_KERNEL_LZ4
+#include "../../../../lib/decompress_unlz4.c"
+#endif
+
 static void scroll(void)
 {
int i;
-- 
1.8.0.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] mmc: debugfs: Fix incorrect size of string allocation

2012-12-04 Thread Kyungsik Lee
It is usually accepted that code should explain itself.
The max size of string is 1025(512*2 + 1) bytes so there is
no point to add one more byte for string allocation.

This patch is intended to fix incorrect size for string allocation
and make code more readable.

Signed-off-by: Kyungsik Lee 
---
 drivers/mmc/core/debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
index 35c2f85..5008149 100644
--- a/drivers/mmc/core/debugfs.c
+++ b/drivers/mmc/core/debugfs.c
@@ -281,7 +281,7 @@ static int mmc_ext_csd_open(struct inode *inode, struct 
file *filp)
u8 *ext_csd;
int err, i;
 
-   buf = kmalloc(EXT_CSD_STR_LEN + 1, GFP_KERNEL);
+   buf = kmalloc(EXT_CSD_STR_LEN, GFP_KERNEL);
if (!buf)
return -ENOMEM;
 
-- 
1.8.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RESEND v6] mmc: core: Remove bounce buffer in mmc_send_cxd_data()

2012-08-02 Thread Kyungsik Lee
It is expected that Extended CSD register(the size of this register
is larger than CID/CSD) will be referenced more frequently as more
fields have been added to Extended CSD and it seems that it is not
a good option to double the memory used.

This patch is intended to avoid the use of bounce buffer for reading
Extended CSD register in mmc_send_cxd_data(). It will provide a better
performance gain by removing memcpy() overhead for a half KiB and
a redundant bounce buffer allocated repeatedly at the cost of providing
DMA-capable buffer from upper caller(but on-stack buffer is allowed
with no performance gain).

Signed-off-by: Kyungsik Lee 
Reviewed-by: Venkatraman S 
---
Changes in v2:
- Handling on-stack buffer if it's used in caller.

Changes in v3:
- Remove unnecesary code.

Changes in v4:
- Modify codes based-on S, Venkatraman's comments.

Changes in v5:
- Modify commit log and add NOTE description.

Changes in v6:
- Modify commit log.
---
 drivers/mmc/core/mmc_ops.c |   58 +++
 1 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 0ed2cc5..acf578d 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -230,6 +230,10 @@ mmc_send_cxd_native(struct mmc_host *host, u32 arg, u32 
*cxd, int opcode)
return 0;
 }
 
+/*
+ * NOTE: void *buf, Caller for the buf is required to use DMA-capable
+ * buffer or on-stack buffer(with some overhead in callee).
+ */
 static int
 mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
u32 opcode, void *buf, unsigned len)
@@ -239,13 +243,19 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
struct mmc_data data = {0};
struct scatterlist sg;
void *data_buf;
+   int is_on_stack;
 
-   /* dma onto stack is unsafe/nonportable, but callers to this
-* routine normally provide temporary on-stack buffers ...
-*/
-   data_buf = kmalloc(len, GFP_KERNEL);
-   if (data_buf == NULL)
-   return -ENOMEM;
+   is_on_stack = object_is_on_stack(buf);
+   if (is_on_stack) {
+
+   /* dma onto stack is unsafe/nonportable, but callers to this
+* routine normally provide temporary on-stack buffers ...
+*/
+   data_buf = kmalloc(len, GFP_KERNEL);
+   if (data_buf == NULL)
+   return -ENOMEM;
+   } else
+   data_buf = buf;
 
mrq.cmd = &cmd;
mrq.data = &data;
@@ -280,8 +290,10 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
 
mmc_wait_for_req(host, &mrq);
 
-   memcpy(buf, data_buf, len);
-   kfree(data_buf);
+   if (is_on_stack) {
+   memcpy(buf, data_buf, len);
+   kfree(data_buf);
+   }
 
if (cmd.error)
return cmd.error;
@@ -294,24 +306,32 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
 int mmc_send_csd(struct mmc_card *card, u32 *csd)
 {
int ret, i;
+   u32 *csd_tmp;
 
if (!mmc_host_is_spi(card->host))
return mmc_send_cxd_native(card->host, card->rca << 16,
csd, MMC_SEND_CSD);
 
-   ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16);
+   csd_tmp = kmalloc(16, GFP_KERNEL);
+   if (!csd_tmp)
+   return -ENOMEM;
+
+   ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd_tmp, 16);
if (ret)
-   return ret;
+   goto err;
 
for (i = 0;i < 4;i++)
-   csd[i] = be32_to_cpu(csd[i]);
+   csd[i] = be32_to_cpu(csd_tmp[i]);
 
-   return 0;
+err:
+   kfree(csd_tmp);
+   return ret;
 }
 
 int mmc_send_cid(struct mmc_host *host, u32 *cid)
 {
int ret, i;
+   u32 *cid_tmp;
 
if (!mmc_host_is_spi(host)) {
if (!host->card)
@@ -320,14 +340,20 @@ int mmc_send_cid(struct mmc_host *host, u32 *cid)
cid, MMC_SEND_CID);
}
 
-   ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16);
+   cid_tmp = kmalloc(16, GFP_KERNEL);
+   if (!cid_tmp)
+   return -ENOMEM;
+
+   ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid_tmp, 16);
if (ret)
-   return ret;
+   goto err;
 
for (i = 0;i < 4;i++)
-   cid[i] = be32_to_cpu(cid[i]);
+   cid[i] = be32_to_cpu(cid_tmp[i]);
 
-   return 0;
+err:
+   kfree(cid_tmp);
+   return ret;
 }
 
 int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RESEND v5] mmc: core: Remove bounce buffer in mmc_send_cxd_data()

2012-08-02 Thread Kyungsik Lee
It is expected that Extended CSD register(the size of this register
is larger than CID/CSD) will be referenced more frequently as more
fields have been added to Extended CSD and it seems that it is not
a good option to double the memory used.

This patch is intended to avoid the use of bounce buffer for reading
Extended CSD register in mmc_send_cxd_data(). It will provide a better
performance gain by removing memcpy() overhead for a half KiB and
a redundant bounce buffer allocated repeatedly at the cost of providing
DMA-capable buffer from upper caller(but on-stack buffer is allowed
with no performance gain).

Signed-off-by: Kyungsik Lee 
Signed-off-by: S, Venkatraman 
---
Changes in v2:
- Handling on-stack buffer if it's used in caller.

Changes in v3:
- Remove unnecesary code.

Changes in v4:
- Modify codes based-on S, Venkatraman's comments.

Changes in v5:
- Modify commit log and add NOTE description.
---
 drivers/mmc/core/mmc_ops.c |   58 +++
 1 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 0ed2cc5..acf578d 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -230,6 +230,10 @@ mmc_send_cxd_native(struct mmc_host *host, u32 arg, u32 
*cxd, int opcode)
return 0;
 }
 
+/*
+ * NOTE: void *buf, Caller for the buf is required to use DMA-capable
+ * buffer or on-stack buffer(with some overhead in callee).
+ */
 static int
 mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
u32 opcode, void *buf, unsigned len)
@@ -239,13 +243,19 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
struct mmc_data data = {0};
struct scatterlist sg;
void *data_buf;
+   int is_on_stack;
 
-   /* dma onto stack is unsafe/nonportable, but callers to this
-* routine normally provide temporary on-stack buffers ...
-*/
-   data_buf = kmalloc(len, GFP_KERNEL);
-   if (data_buf == NULL)
-   return -ENOMEM;
+   is_on_stack = object_is_on_stack(buf);
+   if (is_on_stack) {
+
+   /* dma onto stack is unsafe/nonportable, but callers to this
+* routine normally provide temporary on-stack buffers ...
+*/
+   data_buf = kmalloc(len, GFP_KERNEL);
+   if (data_buf == NULL)
+   return -ENOMEM;
+   } else
+   data_buf = buf;
 
mrq.cmd = &cmd;
mrq.data = &data;
@@ -280,8 +290,10 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
 
mmc_wait_for_req(host, &mrq);
 
-   memcpy(buf, data_buf, len);
-   kfree(data_buf);
+   if (is_on_stack) {
+   memcpy(buf, data_buf, len);
+   kfree(data_buf);
+   }
 
if (cmd.error)
return cmd.error;
@@ -294,24 +306,32 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
 int mmc_send_csd(struct mmc_card *card, u32 *csd)
 {
int ret, i;
+   u32 *csd_tmp;
 
if (!mmc_host_is_spi(card->host))
return mmc_send_cxd_native(card->host, card->rca << 16,
csd, MMC_SEND_CSD);
 
-   ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16);
+   csd_tmp = kmalloc(16, GFP_KERNEL);
+   if (!csd_tmp)
+   return -ENOMEM;
+
+   ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd_tmp, 16);
if (ret)
-   return ret;
+   goto err;
 
for (i = 0;i < 4;i++)
-   csd[i] = be32_to_cpu(csd[i]);
+   csd[i] = be32_to_cpu(csd_tmp[i]);
 
-   return 0;
+err:
+   kfree(csd_tmp);
+   return ret;
 }
 
 int mmc_send_cid(struct mmc_host *host, u32 *cid)
 {
int ret, i;
+   u32 *cid_tmp;
 
if (!mmc_host_is_spi(host)) {
if (!host->card)
@@ -320,14 +340,20 @@ int mmc_send_cid(struct mmc_host *host, u32 *cid)
cid, MMC_SEND_CID);
}
 
-   ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16);
+   cid_tmp = kmalloc(16, GFP_KERNEL);
+   if (!cid_tmp)
+   return -ENOMEM;
+
+   ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid_tmp, 16);
if (ret)
-   return ret;
+   goto err;
 
for (i = 0;i < 4;i++)
-   cid[i] = be32_to_cpu(cid[i]);
+   cid[i] = be32_to_cpu(cid_tmp[i]);
 
-   return 0;
+err:
+   kfree(cid_tmp);
+   return ret;
 }
 
 int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RESEND v4] mmc: core: Remove bounce buffer in mmc_send_cxd_data()

2012-07-31 Thread Kyungsik Lee
It is expected that Extended CSD register(the size of this register
is larger than CID/CSD) will be referenced more frequently as more
fields have been added to Extended CSD and it seems that it is not
a good option to double the memory used.

This patch is intended to avoid the use of bounce buffer for reading
Extended CSD register in mmc_send_cxd_data().

Signed-off-by: Kyungsik Lee 
Signed-off-by: S, Venkatraman 
---
Changes in v2:
- Handling on-stack buffer if it's used in caller.

Changes in v3:
- Remove unnecesary code.

Changes in v4:
- Modify codes based-on S, Venkatraman's comments.
---
 drivers/mmc/core/mmc_ops.c |   54 +++-
 1 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 0ed2cc5..920a017 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -239,13 +239,19 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
struct mmc_data data = {0};
struct scatterlist sg;
void *data_buf;
+   int is_on_stack;
 
-   /* dma onto stack is unsafe/nonportable, but callers to this
-* routine normally provide temporary on-stack buffers ...
-*/
-   data_buf = kmalloc(len, GFP_KERNEL);
-   if (data_buf == NULL)
-   return -ENOMEM;
+   is_on_stack = object_is_on_stack(buf);
+   if (is_on_stack) {
+
+   /* dma onto stack is unsafe/nonportable, but callers to this
+* routine normally provide temporary on-stack buffers ...
+*/
+   data_buf = kmalloc(len, GFP_KERNEL);
+   if (data_buf == NULL)
+   return -ENOMEM;
+   } else
+   data_buf = buf;
 
mrq.cmd = &cmd;
mrq.data = &data;
@@ -280,8 +286,10 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
 
mmc_wait_for_req(host, &mrq);
 
-   memcpy(buf, data_buf, len);
-   kfree(data_buf);
+   if (is_on_stack) {
+   memcpy(buf, data_buf, len);
+   kfree(data_buf);
+   }
 
if (cmd.error)
return cmd.error;
@@ -294,24 +302,32 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
 int mmc_send_csd(struct mmc_card *card, u32 *csd)
 {
int ret, i;
+   u32 *csd_tmp;
 
if (!mmc_host_is_spi(card->host))
return mmc_send_cxd_native(card->host, card->rca << 16,
csd, MMC_SEND_CSD);
 
-   ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16);
+   csd_tmp = kmalloc(16, GFP_KERNEL);
+   if (!csd_tmp)
+   return -ENOMEM;
+
+   ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd_tmp, 16);
if (ret)
-   return ret;
+   goto err;
 
for (i = 0;i < 4;i++)
-   csd[i] = be32_to_cpu(csd[i]);
+   csd[i] = be32_to_cpu(csd_tmp[i]);
 
-   return 0;
+err:
+   kfree(csd_tmp);
+   return ret;
 }
 
 int mmc_send_cid(struct mmc_host *host, u32 *cid)
 {
int ret, i;
+   u32 *cid_tmp;
 
if (!mmc_host_is_spi(host)) {
if (!host->card)
@@ -320,14 +336,20 @@ int mmc_send_cid(struct mmc_host *host, u32 *cid)
cid, MMC_SEND_CID);
}
 
-   ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16);
+   cid_tmp = kmalloc(16, GFP_KERNEL);
+   if (!cid_tmp)
+   return -ENOMEM;
+
+   ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid_tmp, 16);
if (ret)
-   return ret;
+   goto err;
 
for (i = 0;i < 4;i++)
-   cid[i] = be32_to_cpu(cid[i]);
+   cid[i] = be32_to_cpu(cid_tmp[i]);
 
-   return 0;
+err:
+   kfree(cid_tmp);
+   return ret;
 }
 
 int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RESEND v3] mmc: core: Remove bounce buffer in mmc_send_cxd_data()

2012-07-30 Thread Kyungsik Lee
It is expected that Extended CSD register(the size of this register
is larger than CID/CSD) will be referenced more frequently as more
fields have been added to Extended CSD and it seems that it is not
a good option to double the memory used.

This patch is intended to avoid the use of bounce buffer for reading
Extended CSD register in mmc_send_cxd_data().

Signed-off-by: Kyungsik Lee 
---
Changes in v2:
- Handling on-stack buffer if it's used in caller.

Changes in v3:
- Remove unnecesary code.
---
 drivers/mmc/core/mmc_ops.c |   54 ---
 1 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 0ed2cc5..036e6d5 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -239,13 +239,19 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
struct mmc_data data = {0};
struct scatterlist sg;
void *data_buf;
+   int is_on_stack;
 
-   /* dma onto stack is unsafe/nonportable, but callers to this
-* routine normally provide temporary on-stack buffers ...
-*/
-   data_buf = kmalloc(len, GFP_KERNEL);
-   if (data_buf == NULL)
-   return -ENOMEM;
+   is_on_stack = object_is_on_stack(buf);
+   if (is_on_stack) {
+
+   /* dma onto stack is unsafe/nonportable, but callers to this
+* routine normally provide temporary on-stack buffers ...
+*/
+   data_buf = kmalloc(len, GFP_KERNEL);
+   if (data_buf == NULL)
+   return -ENOMEM;
+   } else
+   data_buf = buf;
 
mrq.cmd = &cmd;
mrq.data = &data;
@@ -280,8 +286,10 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
 
mmc_wait_for_req(host, &mrq);
 
-   memcpy(buf, data_buf, len);
-   kfree(data_buf);
+   if (is_on_stack) {
+   memcpy(buf, data_buf, len);
+   kfree(data_buf);
+   }
 
if (cmd.error)
return cmd.error;
@@ -294,24 +302,34 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
 int mmc_send_csd(struct mmc_card *card, u32 *csd)
 {
int ret, i;
+   u32 *csd_tmp;
 
if (!mmc_host_is_spi(card->host))
return mmc_send_cxd_native(card->host, card->rca << 16,
csd, MMC_SEND_CSD);
 
-   ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16);
+   csd_tmp = kmalloc(16, GFP_KERNEL);
+   if (!csd_tmp)
+   return -ENOMEM;
+
+   ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd_tmp, 16);
if (ret)
-   return ret;
+   goto err;
+
+   memcpy(csd, csd_tmp, 16);
 
for (i = 0;i < 4;i++)
csd[i] = be32_to_cpu(csd[i]);
 
-   return 0;
+err:
+   kfree(csd_tmp);
+   return ret;
 }
 
 int mmc_send_cid(struct mmc_host *host, u32 *cid)
 {
int ret, i;
+   u32 *cid_tmp;
 
if (!mmc_host_is_spi(host)) {
if (!host->card)
@@ -320,14 +338,22 @@ int mmc_send_cid(struct mmc_host *host, u32 *cid)
cid, MMC_SEND_CID);
}
 
-   ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16);
+   cid_tmp = kmalloc(16, GFP_KERNEL);
+   if (!cid_tmp)
+   return -ENOMEM;
+
+   ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid_tmp, 16);
if (ret)
-   return ret;
+   goto err;
+
+   memcpy(cid, cid_tmp, 16);
 
for (i = 0;i < 4;i++)
cid[i] = be32_to_cpu(cid[i]);
 
-   return 0;
+err:
+   kfree(cid_tmp);
+   return ret;
 }
 
 int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RESEND v2] mmc: core: Remove bounce buffer in mmc_send_cxd_data()

2012-07-29 Thread Kyungsik Lee
It is expected that Extended CSD register(the size of this register
is larger than CID/CSD) will be referenced more frequently as more
fields have been added to Extended CSD and it seems that it is not
a good option to double the memory used.

This patch is intended to avoid the use of bounce buffer for reading
Extended CSD register in mmc_send_cxd_data().

Signed-off-by: Kyungsik Lee 
---
Changes in v2:
- Handling on-stack buffer if it's used in caller.
---
 drivers/mmc/core/mmc_ops.c |   56 ++-
 1 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 0ed2cc5..dae5492 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -239,13 +239,19 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
struct mmc_data data = {0};
struct scatterlist sg;
void *data_buf;
+   int is_on_stack;
 
-   /* dma onto stack is unsafe/nonportable, but callers to this
-* routine normally provide temporary on-stack buffers ...
-*/
-   data_buf = kmalloc(len, GFP_KERNEL);
-   if (data_buf == NULL)
-   return -ENOMEM;
+   is_on_stack = object_is_on_stack(buf);
+   if (is_on_stack) {
+
+   /* dma onto stack is unsafe/nonportable, but callers to this
+* routine normally provide temporary on-stack buffers ...
+*/
+   data_buf = kmalloc(len, GFP_KERNEL);
+   if (data_buf == NULL)
+   return -ENOMEM;
+   } else
+   data_buf = buf;
 
mrq.cmd = &cmd;
mrq.data = &data;
@@ -280,8 +286,10 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
 
mmc_wait_for_req(host, &mrq);
 
-   memcpy(buf, data_buf, len);
-   kfree(data_buf);
+   if (is_on_stack) {
+   memcpy(buf, data_buf, len);
+   kfree(data_buf);
+   }
 
if (cmd.error)
return cmd.error;
@@ -294,24 +302,37 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
 int mmc_send_csd(struct mmc_card *card, u32 *csd)
 {
int ret, i;
+   u32 *csd_tmp;
 
if (!mmc_host_is_spi(card->host))
return mmc_send_cxd_native(card->host, card->rca << 16,
csd, MMC_SEND_CSD);
 
-   ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16);
+   csd_tmp = kmalloc(16, GFP_KERNEL);
+   if (!csd_tmp)
+   return -ENOMEM;
+
+   ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd_tmp, 16);
if (ret)
-   return ret;
+   goto err;
+
+   memcpy(csd, csd_tmp, 16);
 
for (i = 0;i < 4;i++)
csd[i] = be32_to_cpu(csd[i]);
 
+   kfree(csd_tmp);
return 0;
+
+err:
+   kfree(csd_tmp);
+   return ret;
 }
 
 int mmc_send_cid(struct mmc_host *host, u32 *cid)
 {
int ret, i;
+   u32 *cid_tmp;
 
if (!mmc_host_is_spi(host)) {
if (!host->card)
@@ -320,14 +341,25 @@ int mmc_send_cid(struct mmc_host *host, u32 *cid)
cid, MMC_SEND_CID);
}
 
-   ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16);
+   cid_tmp = kmalloc(16, GFP_KERNEL);
+   if (!cid_tmp)
+   return -ENOMEM;
+
+   ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid_tmp, 16);
if (ret)
-   return ret;
+   goto err;
+
+   memcpy(cid, cid_tmp, 16);
 
for (i = 0;i < 4;i++)
cid[i] = be32_to_cpu(cid[i]);
 
+   kfree(cid_tmp);
return 0;
+
+err:
+   kfree(cid_tmp);
+   return ret;
 }
 
 int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RESEND] mmc: core: Remove bounce buffer in mmc_send_cxd_data()

2012-07-25 Thread Kyungsik Lee
It is expected that Extended CSD register(the size of this register
is larger than CID/CSD) will be referenced more frequently as more
fields have been added to Extended CSD and it seems that it is not
a good option to double the memory used.

This patch is intended to avoid the use of bounce buffer for reading
Extended CSD register in mmc_send_cxd_data().

Signed-off-by: Kyungsik Lee 
---
 drivers/mmc/core/mmc_ops.c |   45 ---
 1 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 0ed2cc5..95d94a0 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -238,14 +238,6 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
struct mmc_command cmd = {0};
struct mmc_data data = {0};
struct scatterlist sg;
-   void *data_buf;
-
-   /* dma onto stack is unsafe/nonportable, but callers to this
-* routine normally provide temporary on-stack buffers ...
-*/
-   data_buf = kmalloc(len, GFP_KERNEL);
-   if (data_buf == NULL)
-   return -ENOMEM;
 
mrq.cmd = &cmd;
mrq.data = &data;
@@ -266,7 +258,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
data.sg = &sg;
data.sg_len = 1;
 
-   sg_init_one(&sg, data_buf, len);
+   sg_init_one(&sg, buf, len);
 
if (opcode == MMC_SEND_CSD || opcode == MMC_SEND_CID) {
/*
@@ -280,9 +272,6 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
 
mmc_wait_for_req(host, &mrq);
 
-   memcpy(buf, data_buf, len);
-   kfree(data_buf);
-
if (cmd.error)
return cmd.error;
if (data.error)
@@ -294,24 +283,37 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host 
*host,
 int mmc_send_csd(struct mmc_card *card, u32 *csd)
 {
int ret, i;
+   u32 *csd_tmp;
 
if (!mmc_host_is_spi(card->host))
return mmc_send_cxd_native(card->host, card->rca << 16,
csd, MMC_SEND_CSD);
 
-   ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16);
+   csd_tmp = kmalloc(16, GFP_KERNEL);
+   if (!csd_tmp)
+   return -ENOMEM;
+
+   ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd_tmp, 16);
if (ret)
-   return ret;
+   goto err;
+
+   memcpy(csd, csd_tmp, 16);
 
for (i = 0;i < 4;i++)
csd[i] = be32_to_cpu(csd[i]);
 
+   kfree(csd_tmp);
return 0;
+
+err:
+   kfree(csd_tmp);
+   return ret;
 }
 
 int mmc_send_cid(struct mmc_host *host, u32 *cid)
 {
int ret, i;
+   u32 *cid_tmp;
 
if (!mmc_host_is_spi(host)) {
if (!host->card)
@@ -320,14 +322,25 @@ int mmc_send_cid(struct mmc_host *host, u32 *cid)
cid, MMC_SEND_CID);
}
 
-   ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16);
+   cid_tmp = kmalloc(16, GFP_KERNEL);
+   if (!cid_tmp)
+   return -ENOMEM;
+
+   ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid_tmp, 16);
if (ret)
-   return ret;
+   goto err;
+
+   memcpy(cid, cid_tmp, 16);
 
for (i = 0;i < 4;i++)
cid[i] = be32_to_cpu(cid[i]);
 
+   kfree(cid_tmp);
return 0;
+
+err:
+   kfree(cid_tmp);
+   return ret;
 }
 
 int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/