]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/kvm/x86: Enable relocation for `Firecracker` `PIE` builds
authorSergiu Moga <sergiu@unikraft.io>
Sun, 13 Aug 2023 12:06:12 +0000 (15:06 +0300)
committerUnikraft <monkey@unikraft.io>
Mon, 14 Aug 2023 11:01:56 +0000 (11:01 +0000)
Previously, `PIE` builds for `Firecracker VMM` would fail at runtime
due to the fact that the static boot page tables would not be
relocated.

Therefore, enable `Firecracker` builds to run as `PIE` by employing
the early self relocator from `libukreloc`. Since an early bootstack
is also required to backup `rsi` holding the Linux Boot Protocol
structure as well as to provide room to `do_uk_reloc`'s local variables,
use the already existing `lcpu_bootstack` since it does not matter
whether it ends up being tainted or not.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1045

plat/kvm/x86/lxboot.S

index 41e71063948996c33ec05a7e3525c59d7c626e1c..0ebe18a55c3b04a0565d7f1b1f55c6b0f2a52b36 100644 (file)
@@ -35,6 +35,23 @@ ENTRY(_lxboot_entry)
        cmpl    $LXBOOT_HDR_HEADER_MAGIC, LXBOOT_HDR_HEADER_OFFSET(%rsi)
        jne     no_lxboot
 
+#if CONFIG_LIBUKRELOC
+       /* We are going to taint the early lcpu_bootstack but we do not care.
+        * Since it's a stack, it does not need to not be tainted anyway.
+        */
+       leaq    lcpu_bootstack(%rip), %rsp
+       /* Make sure it is aligned */
+       andq    $~0xf, %rsp
+       pushq   %rsi
+       xorl    %esi, %esi
+       xorl    %edi, %edi
+       call    do_uk_reloc
+       popq    %rsi
+       /* We do not restore the previous %rsp. At this time it does not seem to
+        * be needed.
+        */
+#endif /* CONFIG_LIBUKRELOC */
+
        /* startup args for boot CPU */
        leaq    lcpu_boot_startup_args(%rip), %rdi
        leaq    lxboot_entry(%rip), %rax
@@ -44,7 +61,6 @@ ENTRY(_lxboot_entry)
 
        leaq    x86_bpt_pml4(%rip), %rax
        movq    %rax, %cr3
-
        jmp     lcpu_start64
 
 no_lxboot: