support gzipped kernels on arm
v2 cover support gzipped kernels on arm
Hi all,
this patch series introduces support for gzipped kernels, such as the standard Image.gz format used by Linux on arm64 by default, in Xen on arm. Without it, Xen cannot load the default kernel shipped by distros, such as CentOS 7.
Stefano Stabellini (2):
xen: move perform_gunzip to common
xen/arm: support gzip compressed kernels
xen/arch/arm/kernel.c | 48 +++++++++++++++ xen/arch/arm/setup.c | 2 +- xen/arch/x86/bzimage.c | 134 +---------------------------------------- xen/common/Makefile | 1 + xen/common/gunzip.c | 138 +++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/setup.h | 2 + xen/include/xen/gunzip.h | 7 +++ 7 files changed, 198 insertions(+), 134 deletions(-) create mode 100644 xen/common/gunzip.c create mode 100644 xen/include/xen/gunzip.h
Cheers,
Stefano
PATCH v2 1/2 xen: move perform_gunzip to common
The current gunzip code to decompress the Dom0 kernel is implemented in inflate.c which is included by bzimage.c.
I am looking to doing the same on ARM64 but there is quite a bit of boilerplate definitions that I would need to import in order for inflate.c to work correctly.
Instead of copying/pasting the code from x86/bzimage.c, move those definitions to a new common file, gunzip.c. Export only perform_gunzip and gzip_check. Leave output_length where it is.
---
Changes in v2:
- the patch has been reworked from scratch
--- xen/arch/x86/bzimage.c | 134 +------------------------------------------- xen/common/Makefile | 1 + xen/common/gunzip.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/gunzip.h | 7 +++ 4 files changed, 147 insertions(+), 133 deletions(-) create mode 100644 xen/common/gunzip.c create mode 100644 xen/include/xen/gunzip.h
xen/arch/x86/bzimage.c +1 -133
@@ -4,148 +4,16 @@#include <xen/mm.h> #include <xen/string.h> #include <xen/types.h> +#include <xen/gunzip.h> #include <xen/decompress.h> #include <xen/libelf.h> #include <asm/bzimage.h> -#define HEAPORDER 3 - -static unsigned char *__initdata window; -#define memptr long -static memptr __initdata free_mem_ptr; -static memptr __initdata free_mem_end_ptr; - -#define WSIZE 0x80000000 - -static unsigned char *__initdata inbuf; -static unsigned __initdata insize; - -/* Index of next byte to be processed in inbuf: */ -static unsigned __initdata inptr; - -/* Bytes in output buffer: */ -static unsigned __initdata outcnt; - -#define OF (args) args -#define STATIC static - -#define memzero (s, n) memset((s), 0, (n)) - -typedef unsigned char uch ; -typedef unsigned short ush ; -typedef unsigned long ulg ; - -#define INIT __init -#define INITDATA __initdata - -#define get_byte () (inptr < insize ? inbuf[inptr++] : fill_inbuf()) - -/* Diagnostic functions */ -#ifdef DEBUG -# define Assert (cond, msg) do { if (!(cond)) error(msg); } while (0) -# define Trace (x) do { fprintf x; } while (0) -# define Tracev (x) do { if (verbose) fprintf x ; } while (0) -# define Tracevv (x) do { if (verbose > 1) fprintf x ; } while (0) -# define Tracec (c, x) do { if (verbose && (c)) fprintf x ; } while (0) -# define Tracecv (c, x) do { if (verbose > 1 && (c)) fprintf x ; } while (0) -#else -# define Assert (cond, msg) -# define Trace (x) -# define Tracev (x) -# define Tracevv (x) -# define Tracec (c, x) -# define Tracecv (c, x) -#endif - -static long __initdata bytes_out; -static void flush_window (void ); - -static __init void error (char *x) -{ -panic ("%s" , x); -} - -static __init int fill_inbuf (void ) -{ -error ("ran out of input data" ); -return 0 ; -} - - -#include "../../common/inflate.c" - -static __init void flush_window (void ) -{ -/* -* The window is equal to the output buffer therefore only need to -* compute the crc. -*/ -unsigned long c = crc; -unsigned n; -unsigned char *in, ch; - - in = window; -for ( n =0 ; n < outcnt; n++ ) - { - ch = *in++; - c = crc_32_tab[((int )c ^ ch) &0xff ] ^ (c >>8 ); - } - crc = c; - - bytes_out += (unsigned long )outcnt; - outcnt =0 ; -} -static __init unsigned long output_length (char *image,unsigned long image_len) {return *(uint32_t *)&image[image_len -4 ]; } -static __init int gzip_check (char *image,unsigned long image_len) -{ -unsigned char magic0, magic1; - -if ( image_len <2 ) -return 0 ; - - magic0 = (unsigned char )image[0 ]; - magic1 = (unsigned char )image[1 ]; - -return (magic0 ==0x1f ) && ((magic1 ==0x8b ) || (magic1 ==0x9e )); -} - -static __init int perform_gunzip (char *output,char *image,unsigned long image_len) -{ -int rc; - -if ( !gzip_check (image, image_len) ) -return 1 ; - - window = (unsigned char *)output; - - free_mem_ptr = (unsigned long )alloc_xenheap_pages (HEAPORDER ,0 ); - free_mem_end_ptr = free_mem_ptr + (PAGE_SIZE <<HEAPORDER ); - - inbuf = (unsigned char *)image; - insize = image_len; - inptr =0 ; - -makecrc (); - -if (gunzip () <0 ) - { - rc = -EINVAL ; - } -else - { - rc =0 ; - } - -free_xenheap_pages ((void *)free_mem_ptr,HEAPORDER ); - -return rc; -} -struct __packed setup_header {uint8_t _pad0[0x1f1 ];/* skip uninteresting stuff */ uint8_t setup_sects;
xen/common/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-y += vmap.o obj-y += vsprintf.o obj-y += wait.o obj-y += xmalloc_tlsf.o +obj-y += gunzip.o obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma unlzo unlz4 earlycpio,$(n).init.o)
xen/common/gunzip.c new file +138 -0
138 lines not on this page · raw message
xen/include/xen/gunzip.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __XEN_GUNZIP_H +#define __XEN_GUNZIP_H + +__init int gzip_check (char *image,unsigned long image_len); +__init int perform_gunzip (char *output,char *image,unsigned long image_len); + +#endif
Signature · 1 line
1.7.10.4
Re: [PATCH v2 1/2] xen: move perform_gunzip to common
xen/common/Makefile obj-y += vmap.o · line 60
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.08.15 at 13:21, <[email protected]> wrote:
xen/common/Makefile +1
-0@@ -55,6 +55,7 @@ obj-y += vmap.o obj-y += vsprintf.o obj-y += wait.o obj-y += xmalloc_tlsf.o +obj-y += gunzip.o obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma unlzo unlz4 earlycpio,$(n).init.o)
Isn't the code you add in gunzip.c all __init / __initdata (or could at least be)? If so, this should become obj-bin-y += gunzip.o just like is being done for all the other decompressors.
xen/common/gunzip.c line 1
Quoted 4 lines
xen/common/gunzip.c new file +1
-0@@ -0,0 +1,138 @@ +#include <xen/config.h>
This should no be included explicitly in new code.
Quoted 17 lines
xen/common/gunzip.c new file +17
-0+#include <xen/errno.h> +#include <xen/init.h> +#include <xen/lib.h> +#include <xen/mm.h> + +#define HEAPORDER 3 + +static unsigned char *__initdata window; +#define memptr long +static memptr __initdata free_mem_ptr; +static memptr __initdata free_mem_end_ptr; + +#define WSIZE 0x80000000 + +static unsigned char *__initdata inbuf; +static unsigned __initdata insize; +
xen/common/gunzip.c line 28
Quoted 10 lines
xen/common/gunzip.c new file +10
-0+/* Index of next byte to be processed in inbuf: */ +static unsigned __initdata inptr; + +/* Bytes in output buffer: */ +static unsigned __initdata outcnt; + +#define OF (args) args +#define STATIC static + +#define memzero (s, n) memset((s), 0, (n))
I understand that you're mostly moving code, but I'd appreciate if you did some formatting adjustments along the way (like removing the superfluous parentheses here...
Quoted 28 lines
xen/common/gunzip.c new file +28
-0+typedef unsigned char uch ; +typedef unsigned short ush ; +typedef unsigned long ulg ; + +#define INIT __init +#define INITDATA __initdata + +#define get_byte () (inptr < insize ? inbuf[inptr++] : fill_inbuf()) + +/* Diagnostic functions */ +#ifdef DEBUG +# define Assert (cond, msg) do { if (!(cond)) error(msg); } while (0) +# define Trace (x) do { fprintf x; } while (0) +# define Tracev (x) do { if (verbose) fprintf x ; } while (0) +# define Tracevv (x) do { if (verbose > 1) fprintf x ; } while (0) +# define Tracec (c, x) do { if (verbose && (c)) fprintf x ; } while (0) +# define Tracecv (c, x) do { if (verbose > 1 && (c)) fprintf x ; } while (0) +#else +# define Assert (cond, msg) +# define Trace (x) +# define Tracev (x) +# define Tracevv (x) +# define Tracec (c, x) +# define Tracecv (c, x) +#endif + +static long __initdata bytes_out; +static void flush_window (void );
xen/common/gunzip.c line 67
Quoted 10 lines
xen/common/gunzip.c new file +10
-0+ +static __init void error (char *x) +{ +panic ("%s" , x); +} + +static __init int fill_inbuf (void ) +{ +error ("ran out of input data" ); +return 0 ;
... or indentation here).
xen/common/gunzip.c line 69
Quoted 3 lines
xen/common/gunzip.c new file +3
-0+} + +
Just one blank line please.
xen/common/gunzip.c line 73
Quoted 3 lines
xen/common/gunzip.c new file +3
-0+#include "inflate.c" + +static __init void flush_window (void )
Any reason this can't be placed ahead of the #include, avoiding the extra declaration earlier on?
xen/common/gunzip.c line 95
Quoted 1 line
xen/common/gunzip.c new file +1
-0+__init int gzip_check (char *image,unsigned long image_len)
int __init gzip_check(...
xen/common/gunzip.c line 103
Quoted 8 lines
xen/common/gunzip.c new file +8
-0+{ +unsigned char magic0, magic1; + +if ( image_len <2 ) +return 0 ; + + magic0 = (unsigned char )image[0 ]; + magic1 = (unsigned char )image[1 ];
Pointless casts?
xen/common/gunzip.c line 115
Quoted 8 lines
xen/common/gunzip.c new file +8
-0+__init int perform_gunzip (char *output,char *image,unsigned long image_len) +{ +int rc; + +if ( !gzip_check (image, image_len) ) +return 1 ; + + window = (unsigned char *)output;
Any reason output and image can't be declared "unsigned char *" right away, avoiding such bogus casts? (Same then for gzip_check().)
Quoted 8 lines
xen/common/gunzip.c new file +8
-0+ + free_mem_ptr = (unsigned long )alloc_xenheap_pages (HEAPORDER ,0 ); + free_mem_end_ptr = free_mem_ptr + (PAGE_SIZE <<HEAPORDER ); + + inbuf = (unsigned char *)image; + insize = image_len; + inptr =0 ; +
xen/common/gunzip.c line 133
Quoted 10 lines
xen/common/gunzip.c new file +10
-0+makecrc (); + +if (gunzip () <0 ) + { + rc = -EINVAL ; + } +else + { + rc =0 ; + }
Many pointless braces.
xen/include/xen/gunzip.h line 5
Quoted 8 lines
xen/include/xen/gunzip.h new file +5
-0@@ -0,0 +1,7 @@ +#ifndef __XEN_GUNZIP_H +#define __XEN_GUNZIP_H + +__init int gzip_check (char *image,unsigned long image_len); +__init int perform_gunzip (char *output,char *image,unsigned long image_len);
No __init on declarations please.
Jan
Re: [PATCH v2 1/2] xen: move perform_gunzip to common
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.08.15 at 13:21, <[email protected]> wrote:
xen/common/Makefile +1
-0@@ -55,6 +55,7 @@ obj-y += vmap.o obj-y += vsprintf.o obj-y += wait.o obj-y += xmalloc_tlsf.o +obj-y += gunzip.o
Quoted 5 lines
xen/common/Makefile obj-y += vmap.o · line 60
Quoted 1 line
xen/common/Makefile +0
-0obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma unlzo unlz4 earlycpio,$(n).init.o)Isn't the code you add in
gunzip.call__init/__initdata(or could at least be)? If so, this should become obj-bin-y += gunzip.o just like is being done for all the other decompressors.
OK, I'll make the change
Quoted 6 lines
xen/common/gunzip.c line 1
Quoted 4 lines
xen/common/gunzip.c new file +1
-0@@ -0,0 +1,138 @@ +#include <xen/config.h> This should no be included explicitly in new code.
OK
Quoted 23 lines
Quoted 23 lines
xen/common/gunzip.c new file +23
-0+#include <xen/errno.h> +#include <xen/init.h> +#include <xen/lib.h> +#include <xen/mm.h> + +#define HEAPORDER 3 + +static unsigned char *__initdata window; +#define memptr long +static memptr __initdata free_mem_ptr; +static memptr __initdata free_mem_end_ptr; + +#define WSIZE 0x80000000 + +static unsigned char *__initdata inbuf; +static unsigned __initdata insize; + +/* Index of next byte to be processed in inbuf: */ +static unsigned __initdata inptr; + +/* Bytes in output buffer: */ +static unsigned __initdata outcnt; +
Quoted 8 lines
xen/common/gunzip.c line 28
Quoted 4 lines
xen/common/gunzip.c new file +4
-0+#define OF (args) args +#define STATIC static + +#define memzero (s, n) memset((s), 0, (n))I understand that you're mostly moving code, but I'd appreciate if you did some formatting adjustments along the way (like removing the superfluous parentheses here...
I prefer to keep code movement as code movement -- much easier to bisect or spot regressions. If you have any changes that you really require on top of the movement, I could carry them on a separate patch on top of this.
Quoted 69 lines
Quoted 28 lines
xen/common/gunzip.c new file +28
-0+typedef unsigned char uch ; +typedef unsigned short ush ; +typedef unsigned long ulg ; + +#define INIT __init +#define INITDATA __initdata + +#define get_byte () (inptr < insize ? inbuf[inptr++] : fill_inbuf()) + +/* Diagnostic functions */ +#ifdef DEBUG +# define Assert (cond, msg) do { if (!(cond)) error(msg); } while (0) +# define Trace (x) do { fprintf x; } while (0) +# define Tracev (x) do { if (verbose) fprintf x ; } while (0) +# define Tracevv (x) do { if (verbose > 1) fprintf x ; } while (0) +# define Tracec (c, x) do { if (verbose && (c)) fprintf x ; } while (0) +# define Tracecv (c, x) do { if (verbose > 1 && (c)) fprintf x ; } while (0) +#else +# define Assert (cond, msg) +# define Trace (x) +# define Tracev (x) +# define Tracevv (x) +# define Tracec (c, x) +# define Tracecv (c, x) +#endif + +static long __initdata bytes_out; +static void flush_window (void );xen/common/gunzip.c line 67
Quoted 10 lines
xen/common/gunzip.c new file +10
-0+ +static __init void error (char *x) +{ +panic ("%s" , x); +} + +static __init int fill_inbuf (void ) +{ +error ("ran out of input data" ); +return 0 ;... or indentation here).
xen/common/gunzip.c line 69
Quoted 3 lines
xen/common/gunzip.c new file +3
-0+} + +Just one blank line please.
xen/common/gunzip.c line 73
Quoted 3 lines
xen/common/gunzip.c new file +3
-0+#include "inflate.c" + +static __init void flush_window (void )Any reason this can't be placed ahead of the #include, avoiding the extra declaration earlier on?
xen/common/gunzip.c line 95
Quoted 1 line
xen/common/gunzip.c new file +1
-0+__init int gzip_check (char *image,unsigned long image_len)int
__initgzip_check(...xen/common/gunzip.c line 103
Quoted 8 lines
xen/common/gunzip.c new file +8
-0+{ +unsigned char magic0, magic1; + +if ( image_len <2 ) +return 0 ; + + magic0 = (unsigned char )image[0 ]; + magic1 = (unsigned char )image[1 ];Pointless casts?
Quoted 12 lines
xen/common/gunzip.c line 115
Quoted 8 lines
xen/common/gunzip.c new file +8
-0+__init int perform_gunzip (char *output,char *image,unsigned long image_len) +{ +int rc; + +if ( !gzip_check (image, image_len) ) +return 1 ; + + window = (unsigned char *)output;Any reason output and image can't be declared "unsigned char *" right away, avoiding such bogus casts? (Same then for
gzip_check().)
all this code was left untouched by the movement, but FYI simply changing output and image to unsigned char * would break the compilation of bzimage.c
Quoted 21 lines
Quoted 8 lines
xen/common/gunzip.c new file +8
-0+ + free_mem_ptr = (unsigned long )alloc_xenheap_pages (HEAPORDER ,0 ); + free_mem_end_ptr = free_mem_ptr + (PAGE_SIZE <<HEAPORDER ); + + inbuf = (unsigned char *)image; + insize = image_len; + inptr =0 ; +xen/common/gunzip.c line 133
Quoted 10 lines
xen/common/gunzip.c new file +10
-0+makecrc (); + +if (gunzip () <0 ) + { + rc = -EINVAL ; + } +else + { + rc =0 ; + }Many pointless braces.
Quoted 10 lines
xen/include/xen/gunzip.h line 5
Quoted 8 lines
xen/include/xen/gunzip.h new file +5
-0@@ -0,0 +1,7 @@ +#ifndef __XEN_GUNZIP_H +#define __XEN_GUNZIP_H + +__init int gzip_check (char *image,unsigned long image_len); +__init int perform_gunzip (char *output,char *image,unsigned long image_len);No
__initon declarations please.
OK
Re: [PATCH v2 1/2] xen: move perform_gunzip to common
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 01.09.15 at 15:56, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.08.15 at 13:21, <[email protected]> wrote:
xen/common/Makefile +1
-0@@ -55,6 +55,7 @@ obj-y += vmap.o obj-y += vsprintf.o obj-y += wait.o obj-y += xmalloc_tlsf.o +obj-y += gunzip.o
Quoted 7 lines
Quoted 5 lines
xen/common/Makefile obj-y += vmap.o · line 60
Quoted 1 line
xen/common/Makefile +0
-0obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma unlzo unlz4 earlycpio,$(n).init.o)Isn't the code you add in
gunzip.call__init/__initdata(or could at least be)? If so, this should become obj-bin-y += gunzip.o just like is being done for all the other decompressors.OK, I'll make the change
Just for the avoidance of doubt or future confusion: I didn't spell this out correctly, it ought to be "obj-bin-y += gunzip.init.o".
Quoted 10 lines
Quoted 5 lines
xen/common/Makefile obj-y += vmap.o · line 61
Quoted 1 line
xen/common/Makefile +1
-0+#define memzero(s, n) memset((s), 0, (n))I understand that you're mostly moving code, but I'd appreciate if you did some formatting adjustments along the way (like removing the superfluous parentheses here...
I prefer to keep code movement as code movement -- much easier to bisect or spot regressions. If you have any changes that you really require on top of the movement, I could carry them on a separate patch on top of this.
Well, okay then (albeit I'm not really happy about the code that way remaining as crappy as it used to be).
Jan
PATCH v2 2/2 xen/arm: support gzip compressed kernels
In reply to Stefano StabelliniFree the memory used for the compressed kernel and update the relative mod->start and mod->size parameters with the uncompressed ones.
---
Changes in v2:
- use gzip_check
- avoid useless casts
- free original kernel image and update the mod with the new address and size
- remove changes to common Makefile
- remove CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
--- xen/arch/arm/kernel.c | 48 +++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 2 +- xen/include/asm-arm/setup.h | 2 ++ 3 files changed, 51 insertions(+), 1 deletion(-)
xen/arch/arm/kernel.c +48 -0
@@ -13,6 +13,8 @@#include <asm/byteorder.h> #include <asm/setup.h> #include <xen/libfdt/libfdt.h> +#include <xen/gunzip.h> +#include <xen/vmap.h> #include "kernel.h"
@@ -257,6 +259,43 @@ static int kernel_uimage_probe(struct kernel_info *info,return 0 ; } +static __init unsigned long output_length (char *image,unsigned long image_len) +{ +return *(uint32_t *)&image[image_len -4 ]; +} + +static int kernel_decompress (struct kernel_info *info, +paddr_t *addr,paddr_t *size) +{ +char *output, *input; +char magic[2 ]; +int rc; +unsigned kernel_order_in; +unsigned kernel_order_out; +paddr_t output_size; + +copy_from_paddr (magic, *addr,sizeof (magic)); + +/* only gzip is supported */ +if (!gzip_check (magic, *size)) +return 0 ; + + kernel_order_in =get_order_from_bytes (*size); + input =ioremap_cache (*addr, *size); + + output_size =output_length (input, *size); + kernel_order_out =get_order_from_bytes (output_size); + output =alloc_xenheap_pages (kernel_order_out,0 ); + + rc =perform_gunzip (output, input, *size); +clean_dcache_va_range (output, output_size); +iounmap (input); + + *addr =virt_to_maddr (output); + *size = output_size; +return 1 ; +} +#ifdef CONFIG_ARM_64 /* * Check if the image is a 64-bit Image.
@@ -463,6 +502,15 @@ int kernel_probe(struct kernel_info *info)printk ("Loading ramdisk from boot module @ %" PRIpaddr"\n" , info->initrd_bootmodule->start); +if (kernel_decompress (info, &start, &size) >0 ) + { +/* Free the original kernel, update the pointers to the +* decompressed kernel */ +dt_unreserved_regions (mod->start, mod->start + mod->size, + init_domheap_pages,0 ); + mod->start = start; + mod->size = size; + }#ifdef CONFIG_ARM_64 rc =kernel_zimage64_probe (info, start, size);if (rc <0 )
xen/arch/arm/setup.c +1 -1
@@ -165,7 +165,7 @@ static void __init processor_id(void)processor_setup (); } -static void dt_unreserved_regions (paddr_t s,paddr_t e, +void dt_unreserved_regions (paddr_t s,paddr_t e,void (*cb)(paddr_t ,paddr_t ),int first) {int i, nr =fdt_num_mem_rsv (device_tree_flattened);
xen/include/asm-arm/setup.h +2 -0
@@ -54,6 +54,8 @@ void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len);int construct_dom0 (struct domain *d);void discard_initial_modules (void ); +void dt_unreserved_regions (paddr_t s,paddr_t e, +void (*cb)(paddr_t ,paddr_t ),int first);size_t __init boot_fdt_info (const void *fdt,paddr_t paddr);const char __init *boot_fdt_cmdline (const void *fdt);
Signature · 1 line
1.7.10.4
Re: [PATCH v2 2/2] xen/arm: support gzip compressed kernels
Hi Stefano,
xen/arch/arm/kernel.c static int kernel_uimage_probe(struct kernel_info *info, · line 276
Quoted 10 lines · Stefano Stabellini
xen/arch/arm/kernel.c +10
-0+static int kernel_decompress (struct kernel_info *info, +paddr_t *addr,paddr_t *size) +{ +char *output, *input; +char magic[2 ]; +int rc; +unsigned kernel_order_in; +unsigned kernel_order_out; +paddr_t output_size; +
Please check that the binary is not too small before reading the magic.
xen/arch/arm/kernel.c static int kernel_uimage_probe(struct kernel_info *info, · line 284
Quoted 8 lines
xen/arch/arm/kernel.c +8
-0+copy_from_paddr (magic, *addr,sizeof (magic)); + +/* only gzip is supported */ +if (!gzip_check (magic, *size)) +return 0 ; + + kernel_order_in =get_order_from_bytes (*size); + input =ioremap_cache (*addr, *size);
The return of ioremap_cache should be check.
xen/arch/arm/kernel.c static int kernel_uimage_probe(struct kernel_info *info, · line 288
Quoted 4 lines
xen/arch/arm/kernel.c +4
-0+ + output_size =output_length (input, *size); + kernel_order_out =get_order_from_bytes (output_size); + output =alloc_xenheap_pages (kernel_order_out,0 );
Ditto.
Quoted 15 lines
xen/arch/arm/kernel.c +10
-0+ + rc =perform_gunzip (output, input, *size); +clean_dcache_va_range (output, output_size); +iounmap (input); + + *addr =virt_to_maddr (output); + *size = output_size; +return 1 ; +} +#ifdef CONFIG_ARM_64 /* * Check if the image is a 64-bit Image. @@ -463,6 +502,15 @@ int kernel_probe(struct kernel_info *info) printk("Loading ramdisk from boot module @ %"PRIpaddr"\n",
xen/arch/arm/kernel.c int kernel_probe(struct kernel_info *info) · line 512
Quoted 10 lines
xen/arch/arm/kernel.c +8
-0info->initrd_bootmodule->start); +if (kernel_decompress (info, &start, &size) >0 ) + { +/* Free the original kernel, update the pointers to the +* decompressed kernel */ +dt_unreserved_regions (mod->start, mod->start + mod->size, + init_domheap_pages,0 ); + mod->start = start; + mod->size = size;
I'm not sure to see how this would work. Any call to alloc_xenheap_pages should be follow by a called to free_xenheap_pages.
But when freeing the modules, we are using init_heap_pages. I don't think they are similar.
Furthermore, you may allocate more memory than necessary because you are using an order but you never update the size. So we would have memory loose forever.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v2 2/2] xen/arm: support gzip compressed kernels
Quoted 27 lines · Julien Grall
Hi Stefano,
xen/arch/arm/kernel.c static int kernel_uimage_probe(struct kernel_info *info, · line 276
Quoted 10 lines · Stefano Stabellini
xen/arch/arm/kernel.c +10
-0+static int kernel_decompress (struct kernel_info *info, +paddr_t *addr,paddr_t *size) +{ +char *output, *input; +char magic[2 ]; +int rc; +unsigned kernel_order_in; +unsigned kernel_order_out; +paddr_t output_size; +Please check that the binary is not too small before reading the magic.
xen/arch/arm/kernel.c static int kernel_uimage_probe(struct kernel_info *info, · line 284
Quoted 8 lines
xen/arch/arm/kernel.c +8
-0+copy_from_paddr (magic, *addr,sizeof (magic)); + +/* only gzip is supported */ +if (!gzip_check (magic, *size)) +return 0 ; + + kernel_order_in =get_order_from_bytes (*size); + input =ioremap_cache (*addr, *size);The return of
ioremap_cacheshould be check.
Quoted 6 lines
xen/arch/arm/kernel.c static int kernel_uimage_probe(struct kernel_info *info, · line 288
Quoted 4 lines
xen/arch/arm/kernel.c +4
-0+ + output_size =output_length (input, *size); + kernel_order_out =get_order_from_bytes (output_size); + output =alloc_xenheap_pages (kernel_order_out,0 );Ditto.
I'll make these changes
Quoted 17 lines
Quoted 17 lines
xen/arch/arm/kernel.c +10
-0+ + rc =perform_gunzip (output, input, *size); +clean_dcache_va_range (output, output_size); +iounmap (input); + + *addr =virt_to_maddr (output); + *size = output_size; +return 1 ; +} +#ifdef CONFIG_ARM_64 /* * Check if the image is a 64-bit Image. @@ -463,6 +502,15 @@ int kernel_probe(struct kernel_info *info)printk ("Loading ramdisk from boot module @ %" PRIpaddr"\n" , info->initrd_bootmodule->start);
Quoted 13 lines
xen/arch/arm/kernel.c int kernel_probe(struct kernel_info *info) · line 512
Quoted 8 lines
xen/arch/arm/kernel.c +8
-0+if (kernel_decompress (info, &start, &size) >0 ) + { +/* Free the original kernel, update the pointers to the +* decompressed kernel */ +dt_unreserved_regions (mod->start, mod->start + mod->size, + init_domheap_pages,0 ); + mod->start = start; + mod->size = size;I'm not sure to see how this would work. Any call to
alloc_xenheap_pagesshould be follow by a called tofree_xenheap_pages.
But when freeing the modules, we are usinginit_heap_pages. I don't think they are similar.
Actually init_heap_pages is just a wrapper around free_heap_pages, like free_xenheap_pages. I think it is safe to call init_heap_pages, on memory allocated by alloc_xenheap_pages.
Quoted 3 lines
Furthermore, you may allocate more memory than necessary because you are using an order but you never update the size. So we would have memory loose forever.
That is a good point. I am going to write a simple loop to free the remaining pages.
Re: [PATCH v2 2/2] xen/arm: support gzip compressed kernels
Quoted 10 lines · Stefano Stabellini
Quoted 6 lines
I'm not sure to see how this would work. Any call to
alloc_xenheap_pages
should be follow by a called tofree_xenheap_pages. But when freeing the modules, we are usinginit_heap_pages. I don't think they are similar.Actually
init_heap_pagesis just a wrapper aroundfree_heap_pages, likefree_xenheap_pages. I think it is safe to callinit_heap_pages, on memory allocated byalloc_xenheap_pages.
That probably depends on lots of things, in particular the setting of CONFIG_SEPARATE_XENHEAP and in any case I think it should be avoided as a matter of principal.
Also, modules are freed to the domheap not the xenheap.
Maybe it would be best if this memory was allocated from there?
Ian.
Re: [PATCH v2 2/2] xen/arm: support gzip compressed kernels
Quoted 12 lines · Ian Campbell
Quoted 10 lines · Stefano Stabellini
Quoted 6 lines
I'm not sure to see how this would work. Any call to
alloc_xenheap_pages
should be follow by a called tofree_xenheap_pages. But when freeing the modules, we are usinginit_heap_pages. I don't think they are similar.Actually
init_heap_pagesis just a wrapper aroundfree_heap_pages, likefree_xenheap_pages. I think it is safe to callinit_heap_pages, on memory allocated byalloc_xenheap_pages.
Quoted 7 lines
That probably depends on lots of things, in particular the setting of
CONFIG_SEPARATE_XENHEAPand in any case I think it should be avoided as a matter of principal.Also, modules are freed to the domheap not the xenheap.
Maybe it would be best if this memory was allocated from there?
Yes, you are right, it would definitely be better.