Skip to contentSkip to conversation

xen:arm: Populate arm64 image header

PATCH Superseded Amit Singh Tomar 3 participants 7 messages Aug 31, 2018 – Sep 1, 2018

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen:arm: Populate arm64 image header

While porting XEN on Amlogic SoC we found that in absence of image_size field of XEN image header, bootloader(U-BOOT) relocates[1] the XEN image to an address(not appropriate for Amlogic) derived from text_offset.

This unwanted situation can be fixed by updating image_size field along side kernel flags so that image wouldn't relocate from initial load address.

[1]:https://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/lib/image.c;h=699bf44e702f7a7084997406203fd7d2aaaf87fa;hb=HEAD#l50

These changes are derived from kernel v4.18 files

---
 xen/arch/arm/arm64/head.S                     |  5 ++-
 xen/arch/arm/arm64/lib/assembler.h            | 11 +++++
 xen/arch/arm/xen.lds.S                        |  3 ++
 xen/include/asm-arm/arm64/linux_header_vars.h | 62 +++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 2 deletions(-)
 create mode 100644 xen/include/asm-arm/arm64/linux_header_vars.h
xen/arch/arm/arm64/head.S +3 -2
index d63734f..ce72c95 100644
@@ -25,6 +25,7 @@
 #include <asm/early_printk.h>
 #include <efi/efierr.h>
 #include <asm/arm64/efibind.h>
+#include "lib/assembler.h"
 
 #define PT_PT     0xf7f /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=1 P=1 */
 #define PT_MEM    0xf7d /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=0 P=1 */
@@ -120,8 +121,8 @@ efi_head:
         add     x13, x18, #0x16
         b       real_start           /* branch to kernel start */
         .quad   0                    /* Image load offset from start of RAM */
-        .quad   0                    /* reserved */
-        .quad   0                    /* reserved */
+        le64sym _kernel_size_le      /* Effective size of kernel image, little-endian */
+        le64sym _kernel_flags_le     /* Informative flags, little-endian */
         .quad   0                    /* reserved */
         .quad   0                    /* reserved */
         .quad   0                    /* reserved */
xen/arch/arm/arm64/lib/assembler.h +11 -0
index 3f9c0dc..c0ef758 100644
@@ -9,4 +9,15 @@
 #define CPU_BE(x...)
 #define CPU_LE(x...) x
 
+    /*
+     * Emit a 64-bit absolute little endian symbol reference in a way that
+     * ensures that it will be resolved at build time, even when building a
+     * PIE binary. This requires cooperation from the linker script, which
+     * must emit the lo32/hi32 halves individually.
+     */
+    .macro  le64sym, sym
+    .long   \sym\()_lo32
+    .long   \sym\()_hi32
+    .endm
+
 #endif /* __ASM_ASSEMBLER_H__ */
xen/arch/arm/xen.lds.S +3 -0
index 245a0e0..0b9af9e 100644
@@ -5,6 +5,7 @@
 #include <xen/cache.h>
 #include <asm/page.h>
 #include <asm/percpu.h>
+#include <asm/arm64/linux_header_vars.h>
 #undef ENTRY
 #undef ALIGN
 
@@ -229,6 +230,8 @@ SECTIONS
   .stab.index 0 : { *(.stab.index) }
   .stab.indexstr 0 : { *(.stab.indexstr) }
   .comment 0 : { *(.comment) }
+
+  HEAD_SYMBOLS
 }
 
 /*
xen/include/asm-arm/arm64/linux_header_vars.h new file +62 -0

62 lines not on this page · raw message

Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

Hi,

Quoted 4 lines · Amit Singh Tomar

While porting XEN on Amlogic SoC we found that in absence of image_size field of XEN image header, bootloader(U-BOOT) relocates[1] the XEN image to an address(not appropriate for Amlogic) derived from text_offset.

IHMO, this is a bug in U-Boot rather than Xen. The current format, while old, is still valid.

In the case of U-Boot, you usually need to be really careful on the position of all the blobs (e.g Xen, DTB, Kernel, Initramfs) in the memory.

Quoted 4 lines

This unwanted situation can be fixed by updating image_size field along side kernel flags so that image wouldn't relocate from initial load address.

I think the first step is to fix your U-boot and rethink where you load your binaries.

Regarding the patch in itself, I think this is a good addition as it allow Xen to be loaded in more places. But please rewrite the commit message accordingly, this is an update to a new version.

Quoted 27 lines

[1]:https://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/lib/image.c;h=699bf44e702f7a7084997406203fd7d2aaaf87fa;hb=HEAD#l50

These changes are derived from kernel v4.18 files

---
  xen/arch/arm/arm64/head.S                     |  5 ++-
  xen/arch/arm/arm64/lib/assembler.h            | 11 +++++
  xen/arch/arm/xen.lds.S                        |  3 ++
  xen/include/asm-arm/arm64/linux_header_vars.h | 62 +++++++++++++++++++++++++++
  4 files changed, 79 insertions(+), 2 deletions(-)

create mode 100644 xen/include/asm-arm/arm64/linux_header_vars.h

xen/arch/arm/arm64/head.S +1 -0
index d63734f..ce72c95 100644
@@ -25,6 +25,7 @@
  #include <asm/early_printk.h>
  #include <efi/efierr.h>
  #include <asm/arm64/efibind.h>
+#include "lib/assembler.h"
 
  #define PT_PT     0xf7f /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=1 P=1 */
  #define PT_MEM    0xf7d /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=0 P=1 */

xen/arch/arm/arm64/head.S efi_head: · line 125

Quoted 7 lines
xen/arch/arm/arm64/head.S +2 -2
@@ -120,8 +121,8 @@ efi_head:
          add     x13, x18, #0x16
          b       real_start           /* branch to kernel start */
          .quad   0                    /* Image load offset from start of RAM */
-        .quad   0                    /* reserved */
-        .quad   0                    /* reserved */
+        le64sym _kernel_size_le      /* Effective size of kernel image, little-endian */
+        le64sym _kernel_flags_le     /* Informative flags, little-endian */

All the dance for to convert to little endian is not necessary on Xen. Please rework your series to avoid such code, this would also reduce quite significantly the series.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

On 08/31/2018 06:14 PM, Julien Grall wrote:

Hi,

Quoted 8 lines · Amit Singh Tomar
Quoted 4 lines

While porting XEN on Amlogic SoC we found that in absence of image_size field of XEN image header, bootloader(U-BOOT) relocates[1] the XEN image to an address(not appropriate for Amlogic) derived from text_offset.

IHMO, this is a bug in U-Boot rather than Xen. The current format, while old, is still valid.

As tempting at is it to blame the "other guy", I think it's really Xen not up to par here. The kernel doc [2] says: ...
"Where image_size is zero, text_offset can be assumed to be 0x80000."

This is what U-Boot implements.

So you load Xen, say, to 16MB into DRAM, and U-Boot moves it to 512 KB, again complying with the kernel doc:
"NOTE: versions prior to v4.6 cannot make use of memory below the physical offset of the Image so it is recommended that the Image be placed as close as possible to the start of system RAM." U-Boot derives this property from bit 3 of the flags being clear.

Quoted 2 lines

In the case of U-Boot, you usually need to be really careful on the position of all the blobs (e.g Xen, DTB, Kernel, Initramfs) in the memory.

Yes, and in fact it seems one can work around this by cleverly constructing the load addresses, but it's really time to bring Xen into the 21st century (or so) when it comes to the kernel image header ;-)

Quoted 6 lines
Quoted 3 lines

This unwanted situation can be fixed by updating image_size field along side kernel flags so that image wouldn't relocate from initial load address.

I think the first step is to fix your U-boot and rethink where you load your binaries.

I think U-Boot perfectly complies with the kernel document. Xen not so much. The kernel image format was deliberately updated to become more flexible with certain memory layout situations as we have here. There is for instance a problem if there is something precious at 512KB into DRAM (secure memory owned by firmware), as regardless of the load addresses the user chooses U-Boot will (rightfully!) revert to the original "512KB into DRAM" address to keep compatibility with older kernels - and it believes Xen is such a one because of the ancient header format.

But ...

Quoted 3 lines

Regarding the patch in itself, I think this is a good addition as it allow Xen to be loaded in more places. But please rewrite the commit message accordingly, this is an update to a new version.

I totally agree with that, the commit message should be reworded to stress that we want to comply with a newer version of the kernel image header (which is around for four years by now!), and just mention that it fixes problems with non-ancient U-Boots on certain platforms as an additional reason.

Quoted 35 lines
Quoted 35 lines

[1]:https://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/lib/image.c;h=699bf44e702f7a7084997406203fd7d2aaaf87fa;hb=HEAD#l50

These changes are derived from kernel v4.18 files

---
  xen/arch/arm/arm64/head.S                     |  5 ++- xen/arch/arm/arm64/lib/assembler.h            | 11 +++++ xen/arch/arm/xen.lds.S                        |  3 ++ xen/include/asm-arm/arm64/linux_header_vars.h | 62
+++++++++++++++++++++++++++

  4 files changed, 79 insertions(+), 2 deletions(-)

  create mode 100644 xen/include/asm-arm/arm64/linux_header_vars.h

xen/arch/arm/arm64/head.S +1 -0
index d63734f..ce72c95 100644
@@ -25,6 +25,7 @@
   #include <asm/early_printk.h>
   #include <efi/efierr.h>
   #include <asm/arm64/efibind.h>
+#include "lib/assembler.h"
     #define PT_PT     0xf7f /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=1

P=1 */
  #define PT_MEM    0xf7d /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=0 P=1 */

xen/arch/arm/arm64/head.S +0 -0
@@ -120,8 +121,8 @@ efi_head:

          add     x13, x18, #0x16
          b       real_start           /* branch to kernel start */ .quad   0                    /* Image load offset from start of RAM */
-        .quad   0                    /* reserved */
-        .quad   0                    /* reserved */

Quoted 8 lines
Quoted 4 lines

+        le64sym _kernel_size_le      /* Effective size of kernel image, little-endian */
+        le64sym _kernel_flags_le     /* Informative flags, little-endian */

All the dance for to convert to little endian is not necessary on Xen. Please rework your series to avoid such code, this would also reduce quite significantly the series.

Indeed!

Cheers,
Andre.

[2]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/arm64/booting.txt#n98

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 3 lines · André Przywara

On 08/31/2018 06:14 PM, Julien Grall wrote:

Hi,

Hi,

Quoted 6 lines
Quoted 6 lines · Amit Singh Tomar
Quoted 4 lines

While porting XEN on Amlogic SoC we found that in absence of image_size field of XEN image header, bootloader(U-BOOT) relocates[1] the XEN image to an address(not appropriate for Amlogic) derived from text_offset.

Quoted 8 lines
Quoted 2 lines

IHMO, this is a bug in U-Boot rather than Xen. The current format, while old, is still valid.

As tempting at is it to blame the "other guy", I think it's really Xen not up to par here. The kernel doc [2] says: ...
"Where image_size is zero, text_offset can be assumed to be 0x80000."

This is what U-Boot implements.

And Xen comply to that... Xen is actually able to boot at any address that is 4KB aligned.

Quoted 6 lines

So you load Xen, say, to 16MB into DRAM, and U-Boot moves it to 512 KB, again complying with the kernel doc:
"NOTE: versions prior to v4.6 cannot make use of memory below the physical offset of the Image so it is recommended that the Image be placed as close as possible to the start of system RAM." U-Boot derives this property from bit 3 of the flags being clear.

What's wrong with clearing bit 3? This is a valid things to do per the new format.

So that does not explain why the bug lie in Xen...

Quoted 7 lines
Quoted 3 lines

In the case of U-Boot, you usually need to be really careful on the position of all the blobs (e.g Xen, DTB, Kernel, Initramfs) in the memory.

Yes, and in fact it seems one can work around this by cleverly constructing the load addresses, but it's really time to bring Xen into the 21st century (or so) when it comes to the kernel image header ;-)

Even with the new format, you will have to cleverly construct the load addresses because nothing prevents U-boot to move the binaries around...

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

This unwanted situation can be fixed by updating image_size field along side kernel flags so that image wouldn't relocate from initial load address.

I think the first step is to fix your U-boot and rethink where you load your binaries.

Quoted 9 lines

I think U-Boot perfectly complies with the kernel document. Xen not so much. The kernel image format was deliberately updated to become more flexible with certain memory layout situations as we have here. There is for instance a problem if there is something precious at 512KB into DRAM (secure memory owned by firmware), as regardless of the load addresses the user chooses U-Boot will (rightfully!) revert to the original "512KB into DRAM" address to keep compatibility with older kernels - and it believes Xen is such a one because of the ancient header format.

You could construct the same behavior with the new format (text-offset = 0x80000 and flag 3 cleared). So how come this does not work?

This is why the spec says: "As close as possible to start of System RAM" not "At the start of System RAM". U-boot is probably too pedantic here.

Quoted 7 lines

But ...

Quoted 3 lines

Regarding the patch in itself, I think this is a good addition as it allow Xen to be loaded in more places. But please rewrite the commit message accordingly, this is an update to a new version.

Quoted 5 lines

I totally agree with that, the commit message should be reworded to stress that we want to comply with a newer version of the kernel image header (which is around for four years by now!), and just mention that it fixes problems with non-ancient U-Boots on certain platforms as an additional reason.

Either you or Amit needs to explain what is the real problem because at the moment, it still feels this is just a workaround for a bug in the firmware.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

PATCH 1/1 xen:arm: Populate arm64 image header

On 08/31/2018 09:39 PM, Julien Grall wrote:

Hi,

tl;dr: I think we don't disagree on the usefulness of this change in general, so let's just change the commit towards something like:

Update the Xen image header to match the newest Linux kernel definition. This allows to specify some relaxed properties of Xen and allows a bootloader to place the Xen kernel more flexibly.
This fixes the boot on some systems which have other data or code close to the beginning of DRAM.

More explanation why I don't think this is a U-Boot bug:

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines · Amit Singh Tomar
Quoted 4 lines

While porting XEN on Amlogic SoC we found that in absence of image_size field of XEN image header, bootloader(U-BOOT) relocates[1] the XEN image to an address(not appropriate for Amlogic) derived from text_offset.

IHMO, this is a bug in U-Boot rather than Xen. The current format, while old, is still valid.

Quoted 8 lines
Quoted 5 lines

As tempting at is it to blame the "other guy", I think it's really Xen not up to par here. The kernel doc [2] says: ...
"Where image_size is zero, text_offset can be assumed to be 0x80000."

This is what U-Boot implements.

And Xen comply to that... Xen is actually able to boot at any address that is 4KB aligned.

Yes, Xen is much more relaxed then even the newest kernel (ignoring TEXT_OFFSET), but it doesn't tell the boot loader. So that assumes the worst. Fair enough, works mostly, but not in every case, like this one here. The kernel image header got improved to cope with those cases, and Xen should just be updated to do as well. There is no regression expected, it's just improving the situation in some cases. Actually regardless of that we could just update the image header.

Quoted 11 lines
Quoted 6 lines

So you load Xen, say, to 16MB into DRAM, and U-Boot moves it to 512 KB, again complying with the kernel doc:
"NOTE: versions prior to v4.6 cannot make use of memory below the physical offset of the Image so it is recommended that the Image be placed as close as possible to the start of system RAM." U-Boot derives this property from bit 3 of the flags being clear.

What's wrong with clearing bit 3? This is a valid things to do per the new format.

So that does not explain why the bug lie in Xen...

There is no bug in Xen, it's just not very precise in advertising its needs and properties and this bites us in corner cases like this one.

Quoted 10 lines
Quoted 7 lines
Quoted 3 lines

In the case of U-Boot, you usually need to be really careful on the position of all the blobs (e.g Xen, DTB, Kernel, Initramfs) in the memory.

Yes, and in fact it seems one can work around this by cleverly constructing the load addresses, but it's really time to bring Xen into the 21st century (or so) when it comes to the kernel image header ;-)

Even with the new format, you will have to cleverly construct the load addresses because nothing prevents U-boot to move the binaries around...

U-Boot will *try* to not move the image around, to avoid overwriting other images (Dom0, DT, ramdisk, firmware...). But if the information it gets from the kernel image give it no choice, it goes the extra mile to make the kernel happy (as early as possible, 512KB offset). Xen doesn't need all that, so we should tell that to the bootloader.

Quoted 17 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

This unwanted situation can be fixed by updating image_size field along side kernel flags so that image wouldn't relocate from initial load address.

I think the first step is to fix your U-boot and rethink where you load your binaries.

Quoted 9 lines

I think U-Boot perfectly complies with the kernel document. Xen not so much. The kernel image format was deliberately updated to become more flexible with certain memory layout situations as we have here. There is for instance a problem if there is something precious at 512KB into DRAM (secure memory owned by firmware), as regardless of the load addresses the user chooses U-Boot will (rightfully!) revert to the original "512KB into DRAM" address to keep compatibility with older kernels - and it believes Xen is such a one because of the ancient header format.

Quoted 2 lines

You could construct the same behavior with the new format (text-offset = 0x80000 and flag 3 cleared). So how come this does not work?

The old kernel had some requirements, which got relaxed over time. The image format now reflects this. You might run into similar issues with an old kernel, but people don't care so much.
So at the moment it works somehow and mostly, but is unnecessarily complicated. You load Xen to address X, but then have to know that U-Boot relocates Xen (and just Xen!) to some other address and adjust your load addresses accordingly. Not very user friendly.

Quoted 2 lines

This is why the spec says: "As close as possible to start of System RAM" not "At the start of System RAM". U-boot is probably too pedantic here.

As a human I tend to agree, but what should U-Boot do? "As close as possible" means 0, unless you have other information (which we don't).

Quoted 12 lines
Quoted 11 lines

But ...

Quoted 3 lines

Regarding the patch in itself, I think this is a good addition as it allow Xen to be loaded in more places. But please rewrite the commit message accordingly, this is an update to a new version.

I totally agree with that, the commit message should be reworded to stress that we want to comply with a newer version of the kernel image header (which is around for four years by now!), and just mention that it fixes problems with non-ancient U-Boots on certain platforms as an additional reason.

Quoted 3 lines

Either you or Amit needs to explain what is the real problem because at the moment, it still feels this is just a workaround for a bug in the firmware.

Let me try it another way: Xen decided to piggy back on a "foreign" image format, which is good (and I like it!). But Xen doesn't control it's definition, so it should keep up with any changes done there. So far this wasn't a problem (although I remember some awkward workarounds in the past for other boards due to TEXT_OFFSET 0), but now we have a good reason to update it.

Actually: even if I would agree with you that the problem is in U-Boot, I wouldn't know how to fix it without making the situation worse for Linux kernels. The U-Boot implementation seems perfectly fine for both older and newer Linux kernels according to the spec. So shall we add a hack to U-Boot just because of Xen? Especially if the Xen fix proposed is easy, backwards compatible and would have been done anyway?

People would probably run into similar problems with pre v3.17 kernels, but then we could just ask to update the kernel. I would like to give the same advice to Xen users.

Frankly, let's stop bikeshedding about this simple thing. Since I saw a similar patch in one of your branches, I think we don't disagree about the usefulness ;-)

Cheers,
Andre.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#5 lore raw
In reply to André Przywara

Hello,

Quoted 2 lines

Yes, and in fact it seems one can work around this by cleverly constructing the load addresses,

But we are really dealing a corner case here. No matter where we load the image, it would be relocated to 0x80000( since dram starts at 0x0000...) and unfortunately first 16MiB is reserved for ROM Firmware.

Quoted 73 lines
Quoted 6 lines
Quoted 3 lines

This unwanted situation can be fixed by updating image_size field along side kernel flags so that image wouldn't relocate from initial load address.

I think the first step is to fix your U-boot and rethink where you load your binaries.

I think U-Boot perfectly complies with the kernel document. Xen not so much. The kernel image format was deliberately updated to become more flexible with certain memory layout situations as we have here. There is for instance a problem if there is something precious at 512KB into DRAM (secure memory owned by firmware), as regardless of the load addresses the user chooses U-Boot will (rightfully!) revert to the original "512KB into DRAM" address to keep compatibility with older kernels - and it believes Xen is such a one because of the ancient header format.

But ...

Quoted 3 lines

Regarding the patch in itself, I think this is a good addition as it allow Xen to be loaded in more places. But please rewrite the commit message accordingly, this is an update to a new version.

I totally agree with that, the commit message should be reworded to stress that we want to comply with a newer version of the kernel image header (which is around for four years by now!), and just mention that it fixes problems with non-ancient U-Boots on certain platforms as an additional reason.

Quoted 35 lines
Quoted 35 lines

[1]:https://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/lib/image.c;h=699bf44e702f7a7084997406203fd7d2aaaf87fa;hb=HEAD#l50

These changes are derived from kernel v4.18 files

---
  xen/arch/arm/arm64/head.S                     |  5 ++-
  xen/arch/arm/arm64/lib/assembler.h            | 11 +++++
  xen/arch/arm/xen.lds.S                        |  3 ++
  xen/include/asm-arm/arm64/linux_header_vars.h | 62
+++++++++++++++++++++++++++
  4 files changed, 79 insertions(+), 2 deletions(-)

create mode 100644 xen/include/asm-arm/arm64/linux_header_vars.h

xen/arch/arm/arm64/head.S +1 -0
index d63734f..ce72c95 100644
@@ -25,6 +25,7 @@
  #include <asm/early_printk.h>
  #include <efi/efierr.h>
  #include <asm/arm64/efibind.h>
+#include "lib/assembler.h"
    #define PT_PT     0xf7f /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=1

P=1 */
#define PT_MEM 0xf7d /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=0
P=1 */

xen/arch/arm/arm64/head.S +0 -0
@@ -120,8 +121,8 @@ efi_head:
          add     x13, x18, #0x16
          b       real_start           /* branch to kernel start */
          .quad   0                    /* Image load offset from start

of RAM */

xen/arch/arm/arm64/head.S +0 -2
-        .quad   0                    /* reserved */
-        .quad   0                    /* reserved */
Quoted 8 lines
Quoted 4 lines

+ le64sym _kernel_size_le /* Effective size of kernel
image, little-endian */
+ le64sym _kernel_flags_le /* Informative flags,
little-endian */

All the dance for to convert to little endian is not necessary on Xen. Please rework your series to avoid such code, this would also reduce quite significantly the series.

Quoted 1 line

Indeed!

How about this change?

index ce72c95..ec29e01 100644

xen/arch/arm/arm64/head.S +0 -1
@@ -121,8 +121,8 @@ efi_head:
         add     x13, x18, #0x16
         b       real_start           /* branch to kernel start */
         .quad   0                    /* Image load offset from start of RAM */
-        le64sym _kernel_size_le      /* Effective size of kernel

image, little-endian */
- le64sym _kernel_flags_le /* Informative flags, little-endian */
+ .quad _end - start /* Effective size of kernel image,
little-endian */

+        .quad   __HEAD_FLAGS     /* Informative flags, little-endian */
         .quad   0                    /* reserved */
         .quad   0                    /* reserved */
         .quad   0                    /* reserved */
(quoted diff) +0 -0

b/xen/arch/arm/arm64/lib/assembler.h
index c0ef758..05861b8 100644

xen/arch/arm/arm64/lib/assembler.h +5 -10
@@ -9,15 +9,11 @@
 #define CPU_BE(x...)
 #define CPU_LE(x...) x
 
-    /*
-     * Emit a 64-bit absolute little endian symbol reference in a way that
-     * ensures that it will be resolved at build time, even when building a
-     * PIE binary. This requires cooperation from the linker script, which
-     * must emit the lo32/hi32 halves individually.
-     */
-    .macro  le64sym, sym
-    .long   \sym\()_lo32
-    .long   \sym\()_hi32
-    .endm
+#define __HEAD_FLAG_PAGE_SIZE  1 /* 4K hard-coded */
+
+#define __HEAD_FLAG_PHYS_BASE  1
+
+#define __HEAD_FLAGS    ((__HEAD_FLAG_PAGE_SIZE << 1) |  \
 

Thanks
-Amit

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw
Quoted 83 lines · Amit Tomer

Hello,

Quoted 2 lines

Yes, and in fact it seems one can work around this by cleverly constructing the load addresses,

But we are really dealing a corner case here. No matter where we load the image, it would be relocated to 0x80000( since dram starts at 0x0000...) and unfortunately first 16MiB is reserved for ROM Firmware.

Quoted 73 lines
Quoted 6 lines
Quoted 3 lines

This unwanted situation can be fixed by updating image_size field along side kernel flags so that image wouldn't relocate from initial load address.

I think the first step is to fix your U-boot and rethink where you load your binaries.

I think U-Boot perfectly complies with the kernel document. Xen not so much. The kernel image format was deliberately updated to become more flexible with certain memory layout situations as we have here. There is for instance a problem if there is something precious at 512KB into DRAM (secure memory owned by firmware), as regardless of the load addresses the user chooses U-Boot will (rightfully!) revert to the original "512KB into DRAM" address to keep compatibility with older kernels - and it believes Xen is such a one because of the ancient header format.

But ...

Quoted 3 lines

Regarding the patch in itself, I think this is a good addition as it allow Xen to be loaded in more places. But please rewrite the commit message accordingly, this is an update to a new version.

I totally agree with that, the commit message should be reworded to stress that we want to comply with a newer version of the kernel image header (which is around for four years by now!), and just mention that it fixes problems with non-ancient U-Boots on certain platforms as an additional reason.

Quoted 43 lines
Quoted 36 lines

[1]:https://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/lib/image.c;h=699bf44e702f7a7084997406203fd7d2aaaf87fa;hb=HEAD#l50

These changes are derived from kernel v4.18 files

---
  xen/arch/arm/arm64/head.S                     |  5 ++-
  xen/arch/arm/arm64/lib/assembler.h            | 11 +++++
  xen/arch/arm/xen.lds.S                        |  3 ++
  xen/include/asm-arm/arm64/linux_header_vars.h | 62
+++++++++++++++++++++++++++
  4 files changed, 79 insertions(+), 2 deletions(-)

create mode 100644 xen/include/asm-arm/arm64/linux_header_vars.h

xen/arch/arm/arm64/head.S +1 -0
index d63734f..ce72c95 100644
@@ -25,6 +25,7 @@
  #include <asm/early_printk.h>
  #include <efi/efierr.h>
  #include <asm/arm64/efibind.h>
+#include "lib/assembler.h"
    #define PT_PT     0xf7f /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=1

P=1 */
#define PT_MEM 0xf7d /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=0
P=1 */

xen/arch/arm/arm64/head.S +0 -0
@@ -120,8 +121,8 @@ efi_head:
          add     x13, x18, #0x16
          b       real_start           /* branch to kernel start */
          .quad   0                    /* Image load offset from start

of RAM */

xen/arch/arm/arm64/head.S +1 -2
-        .quad   0                    /* reserved */
-        .quad   0                    /* reserved */
+        le64sym _kernel_size_le      /* Effective size of kernel
Quoted 3 lines

image, little-endian */
+ le64sym _kernel_flags_le /* Informative flags,
little-endian */

All the dance for to convert to little endian is not necessary on Xen. Please rework your series to avoid such code, this would also reduce quite significantly the series.

Quoted 3 lines
Quoted 1 line

Indeed!

How about this change?

The diff below doesn't make sense. Please just send a new version without *any* endianess code and with the changed commit message - focusing on the overdue image format update as the main rationale and just mentioning the platform as an example.

Cheers,
Andre.

Quoted 42 lines

index ce72c95..ec29e01 100644

xen/arch/arm/arm64/head.S +0 -1
@@ -121,8 +121,8 @@ efi_head:
         add     x13, x18, #0x16
         b       real_start           /* branch to kernel start */
         .quad   0                    /* Image load offset from start of RAM */
-        le64sym _kernel_size_le      /* Effective size of kernel

image, little-endian */

xen/arch/arm/arm64/head.S +1 -1
-        le64sym _kernel_flags_le     /* Informative flags, little-endian */
+        .quad   _end - start      /* Effective size of kernel image,

little-endian */

xen/arch/arm/arm64/head.S +1 -0
+        .quad   __HEAD_FLAGS     /* Informative flags, little-endian */
         .quad   0                    /* reserved */
         .quad   0                    /* reserved */
         .quad   0                    /* reserved */
xen/arch/arm/arm64/lib/assembler.h +5 -10
index c0ef758..05861b8 100644
@@ -9,15 +9,11 @@
 #define CPU_BE(x...)
 #define CPU_LE(x...) x
 
-    /*
-     * Emit a 64-bit absolute little endian symbol reference in a way that
-     * ensures that it will be resolved at build time, even when building a
-     * PIE binary. This requires cooperation from the linker script, which
-     * must emit the lo32/hi32 halves individually.
-     */
-    .macro  le64sym, sym
-    .long   \sym\()_lo32
-    .long   \sym\()_hi32
-    .endm
+#define __HEAD_FLAG_PAGE_SIZE  1 /* 4K hard-coded */
+
+#define __HEAD_FLAG_PHYS_BASE  1
+
+#define __HEAD_FLAGS    ((__HEAD_FLAG_PAGE_SIZE << 1) |  \
 
Quoted 3 lines

Thanks
-Amit

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel