diff mbox series

[v2,2/5] x86: Set xen_phys_start and trampoline_xen_phys_start earlier

Message ID 20240814083428.3012-3-frediano.ziglio@cloud.com (mailing list archive)
State New
Headers show
Series Support EFI multiboot loading using PE binary | expand

Commit Message

Frediano Ziglio Aug. 14, 2024, 8:34 a.m. UTC
No reason to wait, if Xen image is loaded by EFI (not multiboot
EFI path) these are set in efi_arch_load_addr_check, but
not in the multiboot EFI code path.
This change makes the 2 EFI code paths more similar and allows
the usage of these variables if needed.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
---
 xen/arch/x86/boot/head.S | 5 +++++
 1 file changed, 5 insertions(+)
---
Changes since v1:
- Do not remove other hunk, used for BIOS;
- Slightly improved commit message.

Comments

Jan Beulich Aug. 20, 2024, 8:02 a.m. UTC | #1
On 14.08.2024 10:34, Frediano Ziglio wrote:
> No reason to wait, if Xen image is loaded by EFI (not multiboot
> EFI path) these are set in efi_arch_load_addr_check, but
> not in the multiboot EFI code path.
> This change makes the 2 EFI code paths more similar and allows
> the usage of these variables if needed.

It still remains a just-in-case change this way. It's init-only code,
so the code size increase doesn't really matter, yet having such
redundant code without a good explanation is at risk of being
confusing down the road. Therefore - if this change is needed in a
later patch in this series, please mention the intended use case
here, or perhaps simply fold both patches.

> Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
> ---
>  xen/arch/x86/boot/head.S | 5 +++++
>  1 file changed, 5 insertions(+)
> ---
> Changes since v1:
> - Do not remove other hunk, used for BIOS;

As indicated on the v1 thread: The writes simply write 0 in the BIOS
case. It's the PVH case which needs them. With that I see two options:
Move the existing code to ahead of __pvh_start's jump to
trampoline_setup (my preference), or at least make sure that in the
MB2 case we don't write the two variables a 2nd time (else raising
the question of whether the same value is written, or why the value is
okay to change.)

> --- a/xen/arch/x86/boot/head.S
> +++ b/xen/arch/x86/boot/head.S
> @@ -240,6 +240,11 @@ __efi64_mb2_start:
>          jmp     x86_32_switch
>  
>  .Lefi_multiboot2_proto:
> +        /* Save Xen image load base address for later use. */
> +        lea     __image_base__(%rip), %esi
> +        mov     %rsi, xen_phys_start(%rip)
> +        mov     %esi, trampoline_xen_phys_start(%rip)

As iirc also indicated in reply to v1 already: The existing code you
clone uses two 32-bit writes. What's the point of using a mix here?
If the address was really above 4G, we'd have an issue anyway, wouldn't
we? (Leaving aside that the LEA already truncates the value anyway.)

Finally I'd like to recommend to avoid the use of %esi here. It gives
the wrong impression of sym_esi() becoming usable, when in fact %esi is
zeroed ...

>          /* Zero EFI SystemTable, EFI ImageHandle addresses and cmdline. */
>          xor     %esi,%esi

... immediately afterwards.

Jan
diff mbox series

Patch

diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
index 16830f636f..af598a60bf 100644
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -240,6 +240,11 @@  __efi64_mb2_start:
         jmp     x86_32_switch
 
 .Lefi_multiboot2_proto:
+        /* Save Xen image load base address for later use. */
+        lea     __image_base__(%rip), %esi
+        mov     %rsi, xen_phys_start(%rip)
+        mov     %esi, trampoline_xen_phys_start(%rip)
+
         /* Zero EFI SystemTable, EFI ImageHandle addresses and cmdline. */
         xor     %esi,%esi
         xor     %edi,%edi