[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] xen:arm: Populate arm64 image header


  • To: Julien Grall <julien.grall@xxxxxxx>, Amit Singh Tomar <amittomer25@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: André Przywara <andre.przywara@xxxxxxx>
  • Date: Fri, 31 Aug 2018 19:04:05 +0100
  • Autocrypt: addr=andre.przywara@xxxxxxx; prefer-encrypt=mutual; keydata= xsFNBFNPCKMBEAC+6GVcuP9ri8r+gg2fHZDedOmFRZPtcrMMF2Cx6KrTUT0YEISsqPoJTKld tPfEG0KnRL9CWvftyHseWTnU2Gi7hKNwhRkC0oBL5Er2hhNpoi8x4VcsxQ6bHG5/dA7ctvL6 kYvKAZw4X2Y3GTbAZIOLf+leNPiF9175S8pvqMPi0qu67RWZD5H/uT/TfLpvmmOlRzNiXMBm kGvewkBpL3R2clHquv7pB6KLoY3uvjFhZfEedqSqTwBVu/JVZZO7tvYCJPfyY5JG9+BjPmr+ REe2gS6w/4DJ4D8oMWKoY3r6ZpHx3YS2hWZFUYiCYovPxfj5+bOr78sg3JleEd0OB0yYtzTT esiNlQpCo0oOevwHR+jUiaZevM4xCyt23L2G+euzdRsUZcK/M6qYf41Dy6Afqa+PxgMEiDto ITEH3Dv+zfzwdeqCuNU0VOGrQZs/vrKOUmU/QDlYL7G8OIg5Ekheq4N+Ay+3EYCROXkstQnf YYxRn5F1oeVeqoh1LgGH7YN9H9LeIajwBD8OgiZDVsmb67DdF6EQtklH0ycBcVodG1zTCfqM AavYMfhldNMBg4vaLh0cJ/3ZXZNIyDlV372GmxSJJiidxDm7E1PkgdfCnHk+pD8YeITmSNyb 7qeU08Hqqh4ui8SSeUp7+yie9zBhJB5vVBJoO5D0MikZAODIDwARAQABzS1BbmRyZSBQcnp5 d2FyYSAoQVJNKSA8YW5kcmUucHJ6eXdhcmFAYXJtLmNvbT7CwXsEEwECACUCGwMGCwkIBwMC BhUIAgkKCw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BaUbiUZf i4aIXCH3Wv6K
  • Cc: sstabellini@xxxxxxxxxx
  • Delivery-date: Fri, 31 Aug 2018 18:05:48 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Openpgp: preference=signencrypt

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

Hi,

> On 08/31/2018 06:01 PM, Amit Singh Tomar wrote:
>> 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.

> 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 ;-)

>> 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 ...

> 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.

>> [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
>>
>> Signed-off-by: Amit Singh Tomar <amittomer25@xxxxxxxxx>
>> ---
>>   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
>>
>> diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S
>> index d63734f..ce72c95 100644
>> --- a/xen/arch/arm/arm64/head.S
>> +++ b/xen/arch/arm/arm64/head.S
>> @@ -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 */
> 
> 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
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.