Skip to contentSkip to conversation

xen:arm: Populate arm64 image header

PATCH Stewart Hildebrand 4 participants 4 messages Oct 5, 2018 – Oct 9, 2018

lore
Share & tools
lore
#0 lore raw
Quoted 5 lines · Amit Singh Tomar
xen/arch/arm/arm64/head.S +0 -0
index d63734f..ef87b5c 100644

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

Quoted 10 lines
xen/arch/arm/arm64/head.S +2 -2
@@ -120,8 +127,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 */
+        .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 */

Since 17bd254a xen:arm: Populate arm64 image header, qemu-system-aarch64 has not been too happy about booting Xen.

Trying to launch qemu-system-aarch64 gives the following error:
rom: requested regions overlap (rom bootloader. free=0x00000000400d0150, addr=0x0000000040000000)
qemu-system-aarch64: rom check and register reset failed

Reverting 17bd254a allowed it to boot again. Alternatively, setting the image offset to some value allowed it to boot again.

xen/arch/arm/arm64/head.S +1 -1
index ef87b5c..8879c77 100644
@@ -126,7 +126,7 @@ efi_head:
          */
         add     x13, x18, #0x16
         b       real_start           /* branch to kernel start */
-        .quad   0                    /* Image load offset from start of RAM */
+        .quad   0x00080000           /* Image load offset from start of RAM */
         .quad   _end - start         /* Effective size of kernel image, little-endian */
         .quad   __HEAD_FLAGS         /* Informative flags, little-endian */
         .quad   0                    /* reserved */

I'm not sure if this is a fault of qemu, or if Xen should put some value in the image load offset field?

For reference, I'm using the following script to build and launch qemu+Xen https://gist.github.com/stewdk/110f43e0cc1d905fc6ed4c7e10d8d35e
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#1 lore raw

Xen boot failure on QEMU (WAS: Re: [PATCH v3] xen:arm: Populate arm64 image header)

(+ Peter Maydell and Stefano)

Hi Steward,

Thank you for the bug report.

Quoted 39 lines · Stewart Hildebrand
Quoted 5 lines · Amit Singh Tomar
xen/arch/arm/arm64/head.S +0 -0
index d63734f..ef87b5c 100644

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

Quoted 10 lines
xen/arch/arm/arm64/head.S +2 -2
@@ -120,8 +127,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 */
+        .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 */

Since 17bd254a xen:arm: Populate arm64 image header, qemu-system-aarch64 has not been too happy about booting Xen.

Trying to launch qemu-system-aarch64 gives the following error:
rom: requested regions overlap (rom bootloader. free=0x00000000400d0150, addr=0x0000000040000000)
qemu-system-aarch64: rom check and register reset failed

Reverting 17bd254a allowed it to boot again. Alternatively, setting the image offset to some value allowed it to boot again.

xen/arch/arm/arm64/head.S +1 -1
index ef87b5c..8879c77 100644
@@ -126,7 +126,7 @@ efi_head:
           */
          add     x13, x18, #0x16
          b       real_start           /* branch to kernel start */
-        .quad   0                    /* Image load offset from start of RAM */
+        .quad   0x00080000           /* Image load offset from start of RAM */
          .quad   _end - start         /* Effective size of kernel image, little-endian */
          .quad   __HEAD_FLAGS         /* Informative flags, little-endian */
          .quad   0                    /* reserved */
Quoted 1 line

I'm not sure if this is a fault of qemu, or if Xen should put some value in the image load offset field?

Per the Linux arm64 booting protocol [1], the load offset can definitely be 0. The bootloader (here QEMU) should not assume a specific text offset, Linux actually provides an option to randomize the text offset in order to test that assumption (see ARM64_RANDOMIZE_TEXT_OFFSET).

I have CCed Stefano and Peter who could give more details on how QEMU is handling the Image protocol.

Quoted 3 lines

For reference, I'm using the following script to build and launch qemu+Xen https://gist.github.com/stewdk/110f43e0cc1d905fc6ed4c7e10d8d35e

Cheers,

[1] https://www.kernel.org/doc/Documentation/arm64/booting.txt

Signature · 6 lines
Julien Grall

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

Re: Xen boot failure on QEMU (WAS: Re: [PATCH v3] xen:arm: Populate arm64 image header)

Quoted 7 lines · Julien Grall

Per the Linux arm64 booting protocol [1], the load offset can definitely be
0. The bootloader (here QEMU) should not assume a specific text offset, Linux actually provides an option to randomize the text offset in order to test that assumption (see ARM64_RANDOMIZE_TEXT_OFFSET).

I have CCed Stefano and Peter who could give more details on how QEMU is handling the Image protocol.

QEMU's code to handle this is in hw/arm/boot.c/load_aarch64_image(). We do have code to handle reading the text offset from the Image header. The error message
rom: requested regions overlap (rom bootloader. free=0x00000000400d0150, addr=0x0000000040000000)

suggests that we have correctly pulled the text offset from the Image file, but it overlaps with something else. Specifically, for the virt board we write our startup "bootloader" (about a dozen insns of assembly that do the job of jumping to the kernel) at the very bottom of RAM, so you can't use that bit of RAM for the image. In theory boot.c could notice that the image is where it would by default put the bootloader code and move that somewhere else (it is IIRC position-independent), but that would be quite complicated code for a corner case, and it doesn't help you with existing deployed versions of QEMU anyway.

thanks
-- PMM

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

#3 lore raw

Re: Xen boot failure on QEMU (WAS: Re: [PATCH v3] xen:arm: Populate arm64 image header)

On Tue, 9 Oct 2018 09:58:14 +0100
Peter Maydell <[email protected]> wrote:

Hi,

Quoted 16 lines · Julien Grall
Quoted 8 lines

Per the Linux arm64 booting protocol [1], the load offset can definitely be 0. The bootloader (here QEMU) should not assume a specific text offset, Linux actually provides an option to randomize the text offset in order to test that assumption (see ARM64_RANDOMIZE_TEXT_OFFSET).

I have CCed Stefano and Peter who could give more details on how QEMU is handling the Image protocol.

QEMU's code to handle this is in hw/arm/boot.c/load_aarch64_image(). We do have code to handle reading the text offset from the Image header. The error message
rom: requested regions overlap (rom bootloader. free=0x00000000400d0150, addr=0x0000000040000000)

Quoted 10 lines

suggests that we have correctly pulled the text offset from the Image file, but it overlaps with something else. Specifically, for the virt board we write our startup "bootloader" (about a dozen insns of assembly that do the job of jumping to the kernel) at the very bottom of RAM, so you can't use that bit of RAM for the image. In theory boot.c could notice that the image is where it would by default put the bootloader code and move that somewhere else (it is IIRC position-independent), but that would be quite complicated code for a corner case, and it doesn't help you with existing deployed versions of QEMU anyway.

While the latter is true, QEMU still violates the kernel arm64 booting protocol:
"The Image must be placed text_offset bytes from a 2MB aligned base address anywhere in usable system RAM and called there."

I tried some values yesterday, just from those experiments it seems like any 4K aligned values would work for Xen. So what about the following:
- We use a 4K text_offset for Xen, to work with existing QEMUs.
- QEMU switches the kernel image load address to
DRAM + 2MB + text_offset, when it sees that text_offset is smaller than the "startup bootloader" size.
That way people can upgrade either of Xen or QEMU to fix the problem, and QEMU becomes more kernel boot protocol compliant.

Happy to provide the trivial Xen patch ;-)

Cheers,
Andre.

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