xen: arm: Update arm64 image header
PATCH v3 1/1 xen: arm: Update arm64 image header
With the Linux kernel commits
the arm64 image header changed. While the size of the header isn't changed, some members have changed their usage.
Update Xen to this updated image header.
The main changes are that the first magic is gone and that there is an image size, now.
In case we read a size != 0, let's use this image size, now. This does allow us to check if the kernel Image is larger than the size given in the device tree, too.
Additionally, add an error message if the magic is not found. This might be the case with kernel's < 3.12 prior to
which introduced the second magic.
This is acceptable as the support of Xen for ARM64 in Linux has been added in Linux 3.11 and the number of boards supported by Linux 3.11 on ARM64 is very limited: ARM models and X-gene. And for the latter it was an early support with only the serial and timer upstreamed.
---
Changes in v3: Just update of the commit message regarding the support
for kernels < 3.12. No change to the patch itself.
xen/arch/arm/kernel.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-)
xen/arch/arm/kernel.c +26 -17
@@ -28,8 +28,7 @@#define ZIMAGE32_MAGIC 0x016f2818 -#define ZIMAGE64_MAGIC_V0 0x14000008 -#define ZIMAGE64_MAGIC_V1 0x644d5241/* "ARM\x64" */ +#define ZIMAGE64_MAGIC 0x644d5241/* "ARM\x64" */ struct minimal_dtb_header {uint32_t magic;
@@ -335,17 +334,17 @@ static int kernel_zimage64_probe(struct kernel_info *info, {/* linux/Documentation/arm64/booting.txt */ struct { -uint32_t magic0; -uint32_t res0; -uint64_t text_offset;/* Image load offset */ -uint64_t res1; -uint64_t res2; +uint32_t code0; +uint32_t code1; +uint64_t text_offset;/* Image load offset, little endian */ +uint64_t image_size;/* Effective Image size, little endian */ +uint64_t flags;/* zImage V1 only from here */ +uint64_t res2;uint64_t res3;uint64_t res4; -uint64_t res5; -uint32_t magic1; -uint32_t res6; +uint32_t magic;/* Magic number, little endian, "ARM\x64" */ +uint32_t res5; } zimage;uint64_t start, end;
@@ -354,20 +353,30 @@ static int kernel_zimage64_probe(struct kernel_info *info,copy_from_paddr (&zimage, addr,sizeof (zimage)); -if ( zimage.magic0 !=ZIMAGE64_MAGIC_V0 && - zimage.magic1 !=ZIMAGE64_MAGIC_V1 ) +if ( zimage.magic !=ZIMAGE64_MAGIC ) { +printk (XENLOG_ERR "No valid magic found in header! Kernel too old?\n" );return -EINVAL ; + } -/* Currently there is no length in the header, so just use the size */ start =0 ; - end = size;/* -* Given the above this check is a bit pointless, but leave it -* here in case someone adds a length field in the future. +* Where image_size is non-zero image_size is little-endian +* and must be respected. */ -if ( (end - start) > size ) +if ( zimage.image_size ) + end = zimage.image_size; +else + end = size; + +if ( (end - start) > size ) { +if ( zimage.image_size ) { +printk (XENLOG_ERR "Error: Kernel Image size: %lu bytes > bootmodule size: %lu bytes\n" , + zimage.image_size, (uint64_t )size); +printk (XENLOG_ERR "The field 'size' does not match the size of blob!\n" ); + }return -EINVAL ; + } info->zimage.kernel_addr = addr; info->zimage.len = end - start;
Signature · 7 lines
2.8.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Hi Dirk,
Quoted 59 lines · Dirk Behme
With the Linux kernel commits
the arm64 image header changed. While the size of the header isn't changed, some members have changed their usage.
Update Xen to this updated image header.
The main changes are that the first magic is gone and that there is an image size, now.
In case we read a size != 0, let's use this image size, now. This does allow us to check if the kernel Image is larger than the size given in the device tree, too.
Additionally, add an error message if the magic is not found. This might be the case with kernel's < 3.12 prior to
which introduced the second magic.
This is acceptable as the support of Xen for ARM64 in Linux has been added in Linux 3.11 and the number of boards supported by Linux 3.11 on ARM64 is very limited: ARM models and X-gene. And for the latter it was an early support with only the serial and timer upstreamed.
Signed-off-by Dirk Behme <[email protected]>---
Changes in v3: Just update of the commit message regarding the support
for kernels < 3.12. No change to the patch itself.xen/arch/arm/kernel.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-)xen/arch/arm/kernel.c +1
-3@@ -28,8 +28,7 @@#define ZIMAGE32_MAGIC 0x016f2818 -#define ZIMAGE64_MAGIC_V0 0x14000008 -#define ZIMAGE64_MAGIC_V1 0x644d5241/* "ARM\x64" */ +#define ZIMAGE64_MAGIC 0x644d5241/* "ARM\x64" */ struct minimal_dtb_header {uint32_t magic;@@ -335,17 +334,17 @@ static int kernel_zimage64_probe(struct kernel_info *info, {/* linux/Documentation/arm64/booting.txt */ struct { -uint32_t magic0;
xen/arch/arm/kernel.c static int kernel_zimage64_probe(struct kernel_info *info, · line 342
Quoted 10 lines
xen/arch/arm/kernel.c +5
-4-uint32_t res0; -uint64_t text_offset;/* Image load offset */ -uint64_t res1; -uint64_t res2; +uint32_t code0; +uint32_t code1; +uint64_t text_offset;/* Image load offset, little endian */ +uint64_t image_size;/* Effective Image size, little endian */ +uint64_t flags;/* zImage V1 only from here */
I think this comment is irrelevant now.
Quoted 12 lines
xen/arch/arm/kernel.c +3
-3+uint64_t res2;uint64_t res3;uint64_t res4; -uint64_t res5; -uint32_t magic1; -uint32_t res6; +uint32_t magic;/* Magic number, little endian, "ARM\x64" */ +uint32_t res5; } zimage;uint64_t start, end;
xen/arch/arm/kernel.c static int kernel_zimage64_probe(struct kernel_info *info, · line 357
Quoted 7 lines
xen/arch/arm/kernel.c +2
-2@@ -354,20 +353,30 @@ static int kernel_zimage64_probe(struct kernel_info *info,copy_from_paddr (&zimage, addr,sizeof (zimage)); -if ( zimage.magic0 !=ZIMAGE64_MAGIC_V0 && - zimage.magic1 !=ZIMAGE64_MAGIC_V1 ) +if ( zimage.magic !=ZIMAGE64_MAGIC ) { +printk (XENLOG_ERR "No valid magic found in header! Kernel too old?\n" );
I have found why there were no error messages here before. The function kernel_probe will try the different formats supported one by one.
So this message will be printed if the kernel is an ARM32 image, which will confuse the user. So I would print this message only when zimage.magic0 is equal to ZIMAGE64_MAGIC_V0.
Quoted 11 lines
xen/arch/arm/kernel.c +2
-4return -EINVAL ; + } -/* Currently there is no length in the header, so just use the size */ start =0 ; - end = size;/* -* Given the above this check is a bit pointless, but leave it -* here in case someone adds a length field in the future. +* Where image_size is non-zero image_size is little-endian
xen/arch/arm/kernel.c static int kernel_zimage64_probe(struct kernel_info *info, · line 373
Quoted 10 lines
xen/arch/arm/kernel.c +8
-1+* and must be respected. */ -if ( (end - start) > size ) +if ( zimage.image_size ) + end = zimage.image_size; +else + end = size; + +if ( (end - start) > size ) { +if ( zimage.image_size ) {
This check is not necessary. "(end - start) > size" will only succeed when zimage.image_size is different than 0.
xen/arch/arm/kernel.c static int kernel_zimage64_probe(struct kernel_info *info, · line 382
Quoted 10 lines
xen/arch/arm/kernel.c +5
-0+printk (XENLOG_ERR "Error: Kernel Image size: %lu bytes > bootmodule size: %lu bytes\n" , + zimage.image_size, (uint64_t )size); +printk (XENLOG_ERR "The field 'size' does not match the size of blob!\n" ); + }return -EINVAL ; + } info->zimage.kernel_addr = addr; info->zimage.len = end - start;
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Hi Julien,
Quoted 76 lines · Julien Grall
Hi Dirk,
Quoted 73 lines · Dirk Behme
With the Linux kernel commits
the arm64 image header changed. While the size of the header isn't changed,
some members have changed their usage.Update Xen to this updated image header.
The main changes are that the first magic is gone and that there is an image size, now.
In case we read a size != 0, let's use this image size, now. This does allow us to check if the kernel Image is larger than the size given in the device tree, too.
Additionally, add an error message if the magic is not found. This might
be the case with kernel's < 3.12 prior towhich introduced the second magic.
This is acceptable as the support of Xen for ARM64 in Linux has been added
in Linux 3.11 and the number of boards supported by Linux 3.11 on ARM64 is
very limited: ARM models and X-gene. And for the latter it was an early support with only the serial and timer upstreamed.Signed-off-by Dirk Behme <[email protected]>---
Changes in v3: Just update of the commit message regarding the support
for kernels < 3.12. No change to the patch itself.xen/arch/arm/kernel.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-)xen/arch/arm/kernel.c +2
-7@@ -28,8 +28,7 @@#define ZIMAGE32_MAGIC 0x016f2818 -#define ZIMAGE64_MAGIC_V0 0x14000008 -#define ZIMAGE64_MAGIC_V1 0x644d5241/* "ARM\x64" */ +#define ZIMAGE64_MAGIC 0x644d5241/* "ARM\x64" */ struct minimal_dtb_header {uint32_t magic;@@ -335,17 +334,17 @@ static int kernel_zimage64_probe(struct kernel_info *info, {/* linux/Documentation/arm64/booting.txt */ struct { -uint32_t magic0; -uint32_t res0; -uint64_t text_offset;/* Image load offset */ -uint64_t res1; -uint64_t res2; + uint32_t code0;
Quoted 8 lines
Quoted 6 lines
xen/arch/arm/kernel.c +3
-0+uint32_t code1; +uint64_t text_offset;/* Image load offset, little endian */ +uint64_t image_size;/* Effective Image size, little endian */
+ uint64_t flags; /* zImage V1 only from here */I think this comment is irrelevant now.
Yes :) I'll remove that.
Quoted 27 lines
Quoted 13 lines
xen/arch/arm/kernel.c +2
-3+uint64_t res2;uint64_t res3;uint64_t res4; -uint64_t res5; -uint32_t magic1; -uint32_t res6; +uint32_t magic;/* Magic number, little endian, "ARM\x64" */
xen/arch/arm/kernel.c +1
-0+uint32_t res5; } zimage;uint64_t start, end;xen/arch/arm/kernel.c static int kernel_zimage64_probe(struct · line 359
Quoted 9 lines
xen/arch/arm/kernel.c +2
-2@@ -354,20 +353,30 @@ static int kernel_zimage64_probe(structkernel_info *info, copy_from_paddr(&zimage, addr, sizeof(zimage)); -if ( zimage.magic0 !=ZIMAGE64_MAGIC_V0 && - zimage.magic1 !=ZIMAGE64_MAGIC_V1 ) + if ( zimage.magic != ZIMAGE64_MAGIC ) { + printk(XENLOG_ERR "No valid magic found in header! Kernel too old?\n");I have found why there were no error messages here before. The function
kernel_probewill try the different formats supported one by one.
Quoted 3 lines
So this message will be printed if the kernel is an ARM32 image, which will confuse the user. So I would print this message only when zimage.magic0 is equal to
ZIMAGE64_MAGIC_V0.
Which we don't have with the recent header format any more. This does mean I drop this message again, as it doesn't make sense if the magic is used for the format detection.
Quoted 23 lines
Quoted 12 lines
xen/arch/arm/kernel.c +1
-1return -EINVAL ; + } -/* Currently there is no length in the header, so just use the size */
start = 0;xen/arch/arm/kernel.c +1
-3- end = size;/* -* Given the above this check is a bit pointless, but leave it -* here in case someone adds a length field in the future. +* Where image_size is non-zero image_size is little-endian xen/arch/arm/kernel.c static int kernel_zimage64_probe(struct kernel_info *info, · line 373
Quoted 10 lines
xen/arch/arm/kernel.c +8
-1+* and must be respected. */ -if ( (end - start) > size ) +if ( zimage.image_size ) + end = zimage.image_size; +else + end = size; + +if ( (end - start) > size ) { +if ( zimage.image_size ) {
Quoted 2 lines
This check is not necessary. "(end - start) > size" will only succeed when zimage.image_size is different than 0.
Yes, indeed :) I'll remove that.
Quoted 11 lines
xen/arch/arm/kernel.c static int kernel_zimage64_probe(struct kernel_info *info, · line 382
Quoted 11 lines
+ printk(XENLOG_ERR "Error: Kernel Image size: %lu bytes
Quoted 1 line
bootmodule size: %lu bytes\n",
xen/arch/arm/kernel.c +2
-0+ zimage.image_size, (uint64_t)size); + printk(XENLOG_ERR "The field 'size' does not match thesize of blob!\n");
xen/arch/arm/kernel.c +2
-0+ }return -EINVAL ; + } info->zimage.kernel_addr = addr; info->zimage.len = end - start;
Best regards
Dirk
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Hello Dirk,
Quoted 29 lines · Dirk Behme
Quoted 28 lines · Julien Grall
Quoted 13 lines · Dirk Behme
xen/arch/arm/kernel.c +2
-3+uint64_t res2;uint64_t res3;uint64_t res4; -uint64_t res5; -uint32_t magic1; -uint32_t res6; +uint32_t magic;/* Magic number, little endian, "ARM\x64" */
xen/arch/arm/kernel.c +1
-0+uint32_t res5; } zimage;uint64_t start, end;xen/arch/arm/kernel.c static int kernel_zimage64_probe(struct · line 359
Quoted 9 lines
xen/arch/arm/kernel.c +2
-2@@ -354,20 +353,30 @@ static int kernel_zimage64_probe(structkernel_info *info, copy_from_paddr(&zimage, addr, sizeof(zimage)); -if ( zimage.magic0 !=ZIMAGE64_MAGIC_V0 && - zimage.magic1 !=ZIMAGE64_MAGIC_V1 ) + if ( zimage.magic != ZIMAGE64_MAGIC ) { + printk(XENLOG_ERR "No valid magic found in header! Kernel too old?\n");I have found why there were no error messages here before. The function
kernel_probewill try the different formats supported one by one.
Quoted 6 lines
Quoted 3 lines
So this message will be printed if the kernel is an ARM32 image, which will confuse the user. So I would print this message only when zimage.magic0 is equal to
ZIMAGE64_MAGIC_V0.Which we don't have with the recent header format any more.
Well, we control the structure in Xen. So we could re-introduce the field magic0 through an union.
Quoted 3 lines
This does
mean I drop this message again, as it doesn't make sense if the magic is used for the format detection.
I would still prefer to keep an error message when only MAGIC_V0 is present. This will avoid people to spend time understanding why it does not work anymore.
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Hi Julien,
Quoted 42 lines · Julien Grall
Hello Dirk,
Quoted 29 lines · Dirk Behme
Quoted 28 lines · Julien Grall
Quoted 13 lines · Dirk Behme
xen/arch/arm/kernel.c +2
-3+uint64_t res2;uint64_t res3;uint64_t res4; -uint64_t res5; -uint32_t magic1; -uint32_t res6; +uint32_t magic;/* Magic number, little endian, "ARM\x64" */
xen/arch/arm/kernel.c +1
-0+uint32_t res5; } zimage;uint64_t start, end;xen/arch/arm/kernel.c static int kernel_zimage64_probe(struct · line 359
Quoted 9 lines
xen/arch/arm/kernel.c +2
-2@@ -354,20 +353,30 @@ static int kernel_zimage64_probe(structkernel_info *info, copy_from_paddr(&zimage, addr, sizeof(zimage)); -if ( zimage.magic0 !=ZIMAGE64_MAGIC_V0 && - zimage.magic1 !=ZIMAGE64_MAGIC_V1 ) + if ( zimage.magic != ZIMAGE64_MAGIC ) { + printk(XENLOG_ERR "No valid magic found in header! Kernel too old?\n");I have found why there were no error messages here before. The function
kernel_probewill try the different formats supported one by one.Quoted 6 lines
Quoted 3 lines
So this message will be printed if the kernel is an ARM32 image, which will confuse the user. So I would print this message only when zimage.magic0 is equal to
ZIMAGE64_MAGIC_V0.Which we don't have with the recent header format any more.
Well, we control the structure in Xen. So we could re-introduce the field magic0 through an union.
Quoted 8 lines
Quoted 4 lines
This does
mean I drop this message again, as it doesn't make sense if the magic is
used for the format detection.I would still prefer to keep an error message when only
MAGIC_V0is present. This will avoid people to spend time understanding why it does not work anymore.
This way
if ( zimage.magic != ZIMAGE64_MAGIC ) {
if ( zimage.magic0 == ZIMAGE64_MAGIC_V0 )
printk(XENLOG_ERR "No valid magic found in header! Kernel
too old?\n");
return -EINVAL;
}with magic0 being a union with code0?
Best regards
Dirk
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 1 line · Dirk Behme
Hi Julien,
Hi Dirk,
Quoted 55 lines · Julien Grall
Quoted 42 lines
Hello Dirk,
Quoted 29 lines · Dirk Behme
Quoted 28 lines · Julien Grall
Quoted 13 lines · Dirk Behme
xen/arch/arm/kernel.c +2
-3+uint64_t res2;uint64_t res3;uint64_t res4; -uint64_t res5; -uint32_t magic1; -uint32_t res6; +uint32_t magic;/* Magic number, little endian, "ARM\x64" */
xen/arch/arm/kernel.c +1
-0+uint32_t res5; } zimage;uint64_t start, end;xen/arch/arm/kernel.c static int kernel_zimage64_probe(struct · line 359
Quoted 9 lines
xen/arch/arm/kernel.c +2
-2@@ -354,20 +353,30 @@ static int kernel_zimage64_probe(structkernel_info *info, copy_from_paddr(&zimage, addr, sizeof(zimage)); -if ( zimage.magic0 !=ZIMAGE64_MAGIC_V0 && - zimage.magic1 !=ZIMAGE64_MAGIC_V1 ) + if ( zimage.magic != ZIMAGE64_MAGIC ) { + printk(XENLOG_ERR "No valid magic found in header! Kernel too old?\n");I have found why there were no error messages here before. The function
kernel_probewill try the different formats supported one by one.Quoted 6 lines
Quoted 3 lines
So this message will be printed if the kernel is an ARM32 image, which will confuse the user. So I would print this message only when zimage.magic0 is equal to
ZIMAGE64_MAGIC_V0.Which we don't have with the recent header format any more.
Well, we control the structure in Xen. So we could re-introduce the field magic0 through an union.
Quoted 8 lines
Quoted 4 lines
This does
mean I drop this message again, as it doesn't make sense if the magic is
used for the format detection.I would still prefer to keep an error message when only
MAGIC_V0is present. This will avoid people to spend time understanding why it does not work anymore.This way
Quoted 8 lines
if ( zimage.magic !=
ZIMAGE64_MAGIC) {
if ( zimage.magic0 ==ZIMAGE64_MAGIC_V0)
printk(XENLOG_ERR "No valid magic found in header! Kerneltoo old?\n"); return -EINVAL; }with magic0 being a union with code0?
Yes, although I would drop the question marks at the end of the second sentence. We know that the kernel is too old.
Thank you for doing this.
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel