[PATCH v2 4/5] x86: Compensate relocation in case of EFI

Frediano Ziglio posted 5 patches 3 months, 1 week ago
[PATCH v2 4/5] x86: Compensate relocation in case of EFI
Posted by Frediano Ziglio 3 months, 1 week ago
If code is loaded by EFI the loader will relocate the image
under 4GB. This causes offsets in x86 code generated by
sym_offs(SYMBOL) to be relocated too (basically they won't be
offsets from image base). In order to get wanted address
when using sym_offs an sym_esi compensate the difference
in %esi.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
---
 xen/arch/x86/boot/head.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
---
Changes since v1:
- Completely different way to cope with the issue, much more easier.

diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
index 666e341bc5..86805389f9 100644
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -380,7 +380,8 @@ x86_32_switch:
         lgdt    gdt_boot_descr(%rip)
 
         /* Store Xen image load base address in place accessible for 32-bit code. */
-        lea     __image_base__(%rip),%esi
+        lea     __image_base__(%rip), %esi
+        sub     $sym_offs(__image_base__), %esi
 
         /* Reload code selector. */
         pushq   $BOOT_CS32
-- 
2.45.2
Re: [PATCH v2 4/5] x86: Compensate relocation in case of EFI
Posted by Jan Beulich 3 months ago
On 14.08.2024 10:34, Frediano Ziglio wrote:
> If code is loaded by EFI the loader will relocate the image
> under 4GB. This causes offsets in x86 code generated by
> sym_offs(SYMBOL) to be relocated too (basically they won't be
> offsets from image base).

In turn meaning that ...

> --- a/xen/arch/x86/boot/head.S
> +++ b/xen/arch/x86/boot/head.S
> @@ -380,7 +380,8 @@ x86_32_switch:
>          lgdt    gdt_boot_descr(%rip)
>  
>          /* Store Xen image load base address in place accessible for 32-bit code. */
> -        lea     __image_base__(%rip),%esi
> +        lea     __image_base__(%rip), %esi
> +        sub     $sym_offs(__image_base__), %esi

... the comment needs updating too then, as %esi won't necessarily hold
the load base address any longer (if I understand correctly what's going
on here).

Jan