Support EFI multiboot loading using PE binary
PATCH v2 1/5 x86: Put trampoline in .init.data section
In reply to Frediano ZiglioThis change allows to put the trampoline in a separate, not executable section. The trampoline contains a mix of code and data (data which is modified from C code during early start so must be writable). This is in preparation for W^X patch in order to satisfy UEFI CA memory mitigation requirements.
At the moment .init.text and .init.data in EFI mode are put together so they will be in the same final section as before this patch.
--- xen/arch/x86/boot/head.S | 2 ++ 1 file changed, 2 insertions(+)
xen/arch/x86/boot/head.S +2 -0
@@ -870,6 +870,8 @@ cmdline_parse_early: reloc: .incbin "reloc.bin" + .section .init.data, "aw", @progbits + ENTRY(trampoline_start) #include "trampoline.S" ENTRY(trampoline_end)
Signature · 1 line
2.45.2
v2 cover Support EFI multiboot loading using PE binary
Testing this feature in preparation for UEFI CA memory mitigation requirements I found some issues causing the loading to fail and other minor issues.
Details in series commit messages.
This is adding an additional way to boot Xen, using GrUB2+EFI (xen.efi:__efi64_mb2_start).
Changes since v1:
- Changed title, apparently this is a kind of new mode;
- address lot of comments (see "Changes" in other messages).
Frediano Ziglio (5):
x86: Put trampoline in .init.data section
x86: Set xen_phys_start and trampoline_xen_phys_start earlier
x86: Force proper gdt_boot_base setting
x86: Compensate relocation in case of EFI
x86: Rollback relocation in case of EFI multiboot
xen/arch/x86/boot/Makefile | 2 +- xen/arch/x86/boot/efi-reloc-image.c | 40 ++++++++++++++ xen/arch/x86/boot/efi-reloc-image.h | 85 +++++++++++++++++++++++++++++ xen/arch/x86/boot/head.S | 72 ++++++++++++++++++------ xen/arch/x86/efi/efi-boot.h | 64 ++-------------------- 5 files changed, 187 insertions(+), 76 deletions(-) create mode 100644 xen/arch/x86/boot/efi-reloc-image.c create mode 100644 xen/arch/x86/boot/efi-reloc-image.h
Signature · 1 line
2.45.2
PATCH v2 2/5 x86: Set xen_phys_start and trampoline_xen_phys_start earlier
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.
--- 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.
xen/arch/x86/boot/head.S +5 -0
@@ -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
Signature · 1 line
2.45.2
PATCH v2 3/5 x86: Force proper gdt_boot_base setting
In reply to Frediano ZiglioInstead of relocate the value at that position compute it entirely and write it.
During EFI boots sym_offs(SYMBOL) are potentially relocated causing the values to be corrupted.
For PVH and BIOS the change won't be necessary but keep the code consistent.
--- xen/arch/x86/boot/head.S | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
xen/arch/x86/boot/head.S +10 -8
@@ -132,8 +132,7 @@ multiboot2_header: gdt_boot_descr: .word .Ltrampoline_gdt_end - trampoline_gdt - 1 gdt_boot_base: - .long sym_offs(trampoline_gdt) - .long 0 /* Needed for 64-bit lgdt */ + .quad 0 /* Needed for 64-bit lgdt */ vga_text_buffer: .long 0xb8000
@@ -373,15 +372,16 @@ __efi64_mb2_start: x86_32_switch: mov %r15,%rdi - /* Store Xen image load base address in place accessible for 32-bit code. */ - lea __image_base__(%rip),%esi - cli /* Initialize GDTR. */ - add %esi,gdt_boot_base(%rip) + lea trampoline_gdt(%rip), %esi + mov %esi, gdt_boot_base(%rip) lgdt gdt_boot_descr(%rip) + /* Store Xen image load base address in place accessible for 32-bit code. */ + lea __image_base__(%rip),%esi + /* Reload code selector. */ pushq $BOOT_CS32 lea cs32_switch(%rip),%edx
@@ -439,7 +439,8 @@ __pvh_start: movb $-1, sym_esi(opt_console_xen) /* Prepare gdt and segments */ - add %esi, sym_esi(gdt_boot_base) + lea sym_esi(trampoline_gdt), %ecx + mov %ecx, sym_esi(gdt_boot_base) lgdt sym_esi(gdt_boot_descr) mov $BOOT_DS, %ecx
@@ -543,7 +544,8 @@ trampoline_bios_setup: * * Initialize GDTR and basic data segments. */ - add %esi,sym_esi(gdt_boot_base) + lea sym_esi(trampoline_gdt), %ecx + mov %ecx, sym_esi(gdt_boot_base) lgdt sym_esi(gdt_boot_descr) mov $BOOT_DS,%ecx
Signature · 1 line
2.45.2
PATCH v2 4/5 x86: Compensate relocation in case of EFI
In reply to Frediano ZiglioIf 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.
--- 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.
xen/arch/x86/boot/head.S +2 -1
@@ -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
Signature · 1 line
2.45.2
PATCH v2 5/5 x86: Rollback relocation in case of EFI multiboot
In reply to Frediano ZiglioIn case EFI not multiboot rolling back relocation is done in efi_arch_post_exit_boot, called by efi_start however this is not done in multiboot code path.
Do it also for this path to make it work correctly.
--- xen/arch/x86/boot/Makefile | 2 +- xen/arch/x86/boot/efi-reloc-image.c | 40 ++++++++++++++ xen/arch/x86/boot/efi-reloc-image.h | 85 +++++++++++++++++++++++++++++ xen/arch/x86/boot/head.S | 44 ++++++++++++--- xen/arch/x86/efi/efi-boot.h | 64 ++-------------------- 5 files changed, 168 insertions(+), 67 deletions(-) create mode 100644 xen/arch/x86/boot/efi-reloc-image.c create mode 100644 xen/arch/x86/boot/efi-reloc-image.h
---
Changes since v1:
- many style updates;
- split file for 32 bit relocation;
- reuse code from header avoiding duplication;
- add some more comment to assembly code;
xen/arch/x86/boot/Makefile +1 -1
@@ -1,6 +1,6 @@ obj-bin-y += head.o -head-bin-objs := cmdline.o reloc.o +head-bin-objs := cmdline.o reloc.o efi-reloc-image.o nocov-y += $(head-bin-objs) noubsan-y += $(head-bin-objs)
xen/arch/x86/boot/efi-reloc-image.c new file +40 -0
@@ -0,0 +1,40 @@ +/* +* efi-reloc-image.c +* +* 32-bit flat memory-map routines for relocating back PE executable. +* This is done with paging disabled to avoid permission issues. +* +* Copyright (c) 2024, Citrix Systems, Inc. +*/ + +/* +* This entry point is entered from xen/arch/x86/boot/head.S with: +* - 0x04(%esp) = __XEN_VIRT_START - xen_phys_start +* - 0x0c(%esp) = xen_phys_start +* - 0x10(%esp) = __base_relocs_start +* - 0x14(%esp) = __base_relocs_end +*/ +asm ( +" .text \n" +" .globl _start \n" +"_start: \n" +" jmp reloc_pe_back \n" + ); + +#include "defs.h" + +/* Do not patch page tables. */ +#define in_page_tables (v) false + +#define EFI_RELOC_IMAGE_EARLY 1 +#include "efi-reloc-image.h" + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/x86/boot/efi-reloc-image.h new file +85 -0
85 lines not on this page · raw message
xen/arch/x86/boot/head.S +37 -7
75 lines not on this page · raw message
xen/arch/x86/efi/efi-boot.h +5 -59
74 lines not on this page · raw message
Signature · 1 line
2.45.2
Quoted 11 lines · Frediano Ziglio
Testing this feature in preparation for UEFI CA memory mitigation requirements I found some issues causing the loading to fail and other minor issues.
Details in series commit messages.
This is adding an additional way to boot Xen, using GrUB2+EFI (xen.efi:__efi64_mb2_start).Changes since v1:
- Changed title, apparently this is a kind of new mode;
- address lot of comments (see "Changes" in other messages).
Quoted 6 lines
Frediano Ziglio (5):
x86: Put trampoline in .init.data section
x86: Setxen_phys_startandtrampoline_xen_phys_startearlier
x86: Force propergdt_boot_basesetting
x86: Compensate relocation in case of EFI
x86: Rollback relocation in case of EFI multiboot
Patch 1 is one part of supporting NX_COMPAT in the PE header, which is a requirement from Microsoft in order to be signed.
It has nothing to do with the rest of the series, which is about making the EFI+MB2 entry point work.
It would have helped a lot to not have mixed these together in a series claiming to only be about the latter.
Now, as indicated in our documentation (yes - this is one of the very few I have managed to get committed),
https://xenbits.xen.org/docs/latest/hypervisor-guide/x86/how-xen-boots.html#xen-efi
The MB2 tags existing in xen.efi is a known thing but came as a surprise to some. It exists because xen.efi is a strict superset of xen.gz, including head.S which contains the MB1/MB2 tags.
Nevertheless, if we want to make EFI+MB2 work, that's fine, but the final patch in the series needs to be one updating the docs to reflect the new behaviour of Xen.
~Andrew
Quoted 29 lines · Andrew Cooper
Quoted 11 lines · Frediano Ziglio
Testing this feature in preparation for UEFI CA memory mitigation requirements I found some issues causing the loading to fail and other minor issues.
Details in series commit messages.
This is adding an additional way to boot Xen, using GrUB2+EFI (xen.efi:__efi64_mb2_start).Changes since v1:
- Changed title, apparently this is a kind of new mode;
- address lot of comments (see "Changes" in other messages).Quoted 6 lines
Frediano Ziglio (5):
x86: Put trampoline in .init.data section
x86: Setxen_phys_startandtrampoline_xen_phys_startearlier
x86: Force propergdt_boot_basesetting
x86: Compensate relocation in case of EFI
x86: Rollback relocation in case of EFI multibootPatch 1 is one part of supporting
NX_COMPATin the PE header, which is a requirement from Microsoft in order to be signed.It has nothing to do with the rest of the series, which is about making the EFI+MB2 entry point work.
It would have helped a lot to not have mixed these together in a series claiming to only be about the latter.
Quoted 7 lines
Now, as indicated in our documentation (yes - this is one of the very few I have managed to get committed),
https://xenbits.xen.org/docs/latest/hypervisor-guide/x86/how-xen-boots.html#xen-efiThe MB2 tags existing in xen.efi is a known thing but came as a surprise to some. It exists because xen.efi is a strict superset of xen.gz, including
head.Swhich contains the MB1/MB2 tags.
Which in turn so far was just to keep build machinery as uniform as possible. IOW I'd rather call the tags being there a side effect, not something that was intentional. And for MB1 I don't think that's going to change with the effort made now.
Jan
Re: [PATCH v2 2/5] x86: Set xen_phys_start and trampoline_xen_phys_start earlier
In reply to Frediano ZiglioQuoted 5 lines · Frediano Ziglio
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.
Quoted 7 lines
Signed-off-by Frediano Ziglio <[email protected]>--- 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.)
xen/arch/x86/boot/head.S __efi64_mb2_start: · line 246
Quoted 10 lines
xen/arch/x86/boot/head.S +4
-0@@ -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 ...
xen/arch/x86/boot/head.S __efi64_mb2_start: · line 249
Quoted 2 lines
xen/arch/x86/boot/head.S +0
-0/* Zero EFI SystemTable, EFI ImageHandle addresses and cmdline. */ xor %esi,%esi
... immediately afterwards.
Jan
Re: [PATCH v2 3/5] x86: Force proper gdt_boot_base setting
In reply to Frediano ZiglioQuoted 4 lines · Frediano Ziglio
Instead of relocate the value at that position compute it entirely and write it.
During EFI bootssym_offs(SYMBOL)are potentially relocated causing the values to be corrupted.
This requires quite a bit more explanation, also to understand why a lone specific sym_offs() is being dealt with here, leaving others untouched. I'm specifically puzzled by the two in the MB2 header: If the GDT one is a problem, why would those not be? Of course similarly for others, in particular those used to pre-fill page tables. I think an adjustment here needs to come with the addition of a comment next to the #define, to clarify where the use is appropriate and where it needs to be avoided.
xen/arch/x86/boot/head.S multiboot2_header: · line 135
Quoted 9 lines
xen/arch/x86/boot/head.S +1
-2@@ -132,8 +132,7 @@ multiboot2_header: gdt_boot_descr: .word .Ltrampoline_gdt_end - trampoline_gdt - 1 gdt_boot_base: - .long sym_offs(trampoline_gdt) - .long 0 /* Needed for 64-bit lgdt */ + .quad 0 /* Needed for 64-bit lgdt */
The comment is now somewhat odd: It's no longer the entire line that's there just because we want to use LGDT from 64-bit code, but just half of what the .quad produces. Therefore perhaps either keep as two longs (maybe with a different brief comment put on the former), or adjust the comment wording.
Quoted 7 lines
xen/arch/x86/boot/head.S +0
-3@@ -373,15 +372,16 @@ __efi64_mb2_start: x86_32_switch: mov %r15,%rdi - /* Store Xen image load base address in place accessible for 32-bit code. */ - lea __image_base__(%rip),%esi -
xen/arch/x86/boot/head.S __efi64_mb2_start: · line 383
Quoted 10 lines
xen/arch/x86/boot/head.S +4
-1cli /* Initialize GDTR. */ - add %esi,gdt_boot_base(%rip) + lea trampoline_gdt(%rip), %esi + mov %esi, gdt_boot_base(%rip) lgdt gdt_boot_descr(%rip) + /* Store Xen image load base address in place accessible for 32-bit code. */ + lea __image_base__(%rip),%esi
What's the point in moving this code? Surely you could use another register for the LEA/MOV pair above? In any event - _if_ you move the code, please also add the blank missing after the comma.
Quoted 11 lines
xen/arch/x86/boot/head.S +2
-1@@ -439,7 +439,8 @@ __pvh_start: movb $-1, sym_esi(opt_console_xen) /* Prepare gdt and segments */ - add %esi, sym_esi(gdt_boot_base) + lea sym_esi(trampoline_gdt), %ecx + mov %ecx, sym_esi(gdt_boot_base) lgdt sym_esi(gdt_boot_descr) mov $BOOT_DS, %ecx
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 551
Quoted 9 lines
xen/arch/x86/boot/head.S +2
-1@@ -543,7 +544,8 @@ trampoline_bios_setup: * * Initialize GDTR and basic data segments. */ - add %esi,sym_esi(gdt_boot_base) + lea sym_esi(trampoline_gdt), %ecx + mov %ecx, sym_esi(gdt_boot_base) lgdt sym_esi(gdt_boot_descr) mov $BOOT_DS,%ecx
While you mention that you make these changes for consistency, I'm afraid I don't really see the point. The paths are all different anyway - there's nothing wrong with leaving everything except x86_32_switch untouched. Far less code churn then. All it would take is extending the comment there a little to mention why the value is fully overwritten rather than merely adjusted.
Jan
Re: [PATCH v2 4/5] x86: Compensate relocation in case of EFI
In reply to Frediano ZiglioQuoted 4 lines · Frediano Ziglio
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 ...
xen/arch/x86/boot/head.S x86_32_switch: · line 384
Quoted 9 lines
xen/arch/x86/boot/head.S +2
-1@@ -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
Re: [PATCH v2 5/5] x86: Rollback relocation in case of EFI multiboot
In reply to Frediano ZiglioQuoted 6 lines · Frediano Ziglio
In case EFI not multiboot rolling back relocation is done in
efi_arch_post_exit_boot, called byefi_starthowever this is not done in multiboot code path.
Do it also for this path to make it work correctly.Signed-off-by Frediano Ziglio <[email protected]>
Quoted 9 lines
--- xen/arch/x86/boot/Makefile | 2 +- xen/arch/x86/boot/efi-reloc-image.c | 40 ++++++++++++++ xen/arch/x86/boot/efi-reloc-image.h | 85 +++++++++++++++++++++++++++++ xen/arch/x86/boot/head.S | 44 ++++++++++++--- xen/arch/x86/efi/efi-boot.h | 64 ++-------------------- 5 files changed, 168 insertions(+), 67 deletions(-) create mode 100644 xen/arch/x86/boot/efi-reloc-image.c create mode 100644 xen/arch/x86/boot/efi-reloc-image.h
Would there be anything wrong with using just efi-reloc.[ch]? I'm sorry, but I'm a little averse to long names when shorter ones are as unambiguous.
xen/arch/x86/boot/efi-reloc-image.c line 8
Quoted 11 lines
xen/arch/x86/boot/efi-reloc-image.c new file +8
-0@@ -0,0 +1,40 @@ +/* +* efi-reloc-image.c +* +* 32-bit flat memory-map routines for relocating back PE executable. +* This is done with paging disabled to avoid permission issues. +* +* Copyright (c) 2024, Citrix Systems, Inc. +*/
Just curious: Is "Citrix" still the right name to use in places like this one?
xen/arch/x86/boot/efi-reloc-image.c line 12
Quoted 3 lines
xen/arch/x86/boot/efi-reloc-image.c new file +3
-0+/* +* This entry point is entered from xen/arch/x86/boot/head.S with: +* - 0x04(%esp) = __XEN_VIRT_START - xen_phys_start
This could to with adding "(two slots)" or "(64 bits)".
Quoted 5 lines
xen/arch/x86/boot/efi-reloc-image.c new file +5
-0+* - 0x0c(%esp) = xen_phys_start +* - 0x10(%esp) = __base_relocs_start +* - 0x14(%esp) = __base_relocs_end +*/ +asm (
xen/arch/x86/boot/efi-reloc-image.c line 27
Quoted 10 lines
xen/arch/x86/boot/efi-reloc-image.c new file +10
-0+" .text \n" +" .globl _start \n" +"_start: \n" +" jmp reloc_pe_back \n" + ); + +#include "defs.h" + +/* Do not patch page tables. */ +#define in_page_tables (v) false
If you want what the comment says, this can't yield "false" for every possible input. Didn't you even have page table related logic in v1?
Quoted 5 lines
xen/arch/x86/boot/efi-reloc-image.h new file +2
-0@@ -0,0 +1,85 @@ +/* +* efi-reloc-image.h
xen/arch/x86/boot/efi-reloc-image.h line 12
Quoted 10 lines
xen/arch/x86/boot/efi-reloc-image.h new file +10
-0+* +* Code for relocating back PE executable. +* This code is common between 64 bit and 32 bit. +* +* Copyright (c) 2024, Citrix Systems, Inc. +*/ + +#if EFI_RELOC_IMAGE_EARLY !=0 &&EFI_RELOC_IMAGE_EARLY !=1 +#error EFI_RELOC_IMAGE_EARLY must be defined either 0 or 1 +#endif
Depending on compiler type and version, EFI_RELOC_IMAGE_EARLY simply not being defined may or may not raise a warning, but would otherwise satisfy EFI_RELOC_IMAGE_EARLY == 0. I think you want to also guard against un-defined-ness.
Quoted 47 lines
xen/arch/x86/boot/efi-reloc-image.h new file +47
-0+typedef struct pe_base_relocs { +uint32_t rva; +uint32_t size; +uint16_t entries[]; +}pe_base_relocs ; + +#define PE_BASE_RELOC_ABS 0 +#define PE_BASE_RELOC_HIGHLOW 3 +#define PE_BASE_RELOC_DIR64 10 + +#if EFI_RELOC_IMAGE_EARLY +bool __stdcall +#else +static bool +#endif +reloc_pe_back (long long delta, +unsigned long xen_phys_start, +const pe_base_relocs *__base_relocs_start, +const pe_base_relocs *__base_relocs_end) +{ +const struct pe_base_relocs *base_relocs; + +for ( base_relocs = __base_relocs_start; base_relocs < __base_relocs_end; ) + { +unsigned int i =0 , n; + + n = (base_relocs->size -sizeof (*base_relocs)) / +sizeof (*base_relocs->entries); + +for ( ; i < n; ++i ) + { +unsigned long addr = xen_phys_start + base_relocs->rva + + (base_relocs->entries[i] &0xfff ); + +switch ( base_relocs->entries[i] >>12 ) + { +case PE_BASE_RELOC_ABS : +break ; +case PE_BASE_RELOC_HIGHLOW : +if ( delta ) + { + *(uint32_t *)addr += delta; +if (in_page_tables (addr) ) + *(uint32_t *)addr += xen_phys_start; + } +break ; +case PE_BASE_RELOC_DIR64 :
xen/arch/x86/boot/efi-reloc-image.h line 70
Quoted 10 lines
xen/arch/x86/boot/efi-reloc-image.h new file +10
-0+if ( delta ) + { + *(uint64_t *)addr += delta; +if (in_page_tables (addr) ) + *(uint64_t *)addr += xen_phys_start; + } +break ; +default : +return false; + }
As you're moving this code, please put blank lines between case blocks.
xen/arch/x86/boot/efi-reloc-image.h line 75
Quoted 5 lines
xen/arch/x86/boot/efi-reloc-image.h new file +5
-0+ } + base_relocs = (const void *)(base_relocs->entries + i + (i &1 )); + } +return true; +}
Nit: Blank line please ahead of a function's main "return".
xen/arch/x86/boot/head.S __efi64_mb2_start: · line 337
Quoted 10 lines
xen/arch/x86/boot/head.S +2
-1@@ -332,7 +332,8 @@ __efi64_mb2_start: */ and $~15,%rsp - /* Save Multiboot2 magic on the stack. */ + /* Save Multiboot2 magic on the stack for a later 32bit call */ + shl $32, %rax push %rax
I see you're now extending the comment here. However, ...
xen/arch/x86/boot/head.S __efi64_mb2_start: · line 366
Quoted 5 lines
xen/arch/x86/boot/head.S +0
-1@@ -363,11 +364,25 @@ __efi64_mb2_start: /* Just pop an item from the stack. */ pop %rax - /* Restore Multiboot2 magic. */
... this comment shouldn't be lost (wants to move down), and ...
xen/arch/x86/boot/head.S __efi64_mb2_start: · line 375
Quoted 10 lines
xen/arch/x86/boot/head.S +9
-1- pop %rax + /* + * Prepare stack for relocation call. + * Note that we are in 64bit mode but we are going to call a + * function in 32bit mode so the stack is not written with + * push instructions. + */ + sub $16, %rsp + lea __base_relocs_end(%rip), %ecx + mov %ecx, 16(%rsp)
... the re-using of half a 64-bit slot here still isn't present in commentary (in fact the comment is slightly wrong as is, because that re-used half slot _is_ written by a PUSH, just higher up).
Quoted 8 lines
xen/arch/x86/efi/efi-boot.h +0
-2@@ -36,69 +36,15 @@ extern const intpte_t __page_tables_start[], __page_tables_end[];#define in_page_tables (v) ((intpte_t *)(v) >= __page_tables_start && \ (intpte_t *)(v) < __page_tables_end) -#define PE_BASE_RELOC_ABS 0 -#define PE_BASE_RELOC_HIGHLOW 3
xen/arch/x86/efi/efi-boot.h extern const intpte_t __page_tables_start[], __page_tables_end[]; · line 42
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +3
-6-#define PE_BASE_RELOC_DIR64 10 +#define EFI_RELOC_IMAGE_EARLY 0 +#include "../boot/efi-reloc-image.h" -extern const struct pe_base_relocs { -u32 rva; -u32 size; -u16 entries[]; -} __base_relocs_start[], __base_relocs_end[]; +extern pe_base_relocs __base_relocs_start[], __base_relocs_end[];
You've lost the const.
Quoted 11 lines
xen/arch/x86/efi/efi-boot.h +0
-9static void __init efi_arch_relocate_image (unsigned long delta) { -const struct pe_base_relocs *base_relocs; - -for ( base_relocs = __base_relocs_start; base_relocs < __base_relocs_end; ) - { -unsigned int i =0 , n; - - n = (base_relocs->size -sizeof (*base_relocs)) / -sizeof (*base_relocs->entries); -
xen/arch/x86/efi/efi-boot.h extern const intpte_t __page_tables_start[], __page_tables_end[]; · line 69
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +0
-10-/* -* Relevant l{2,3}_bootmap entries get initialized explicitly in -* efi_arch_memory_setup(), so we must not apply relocations there. -* l2_directmap's first slot, otoh, should be handled normally, as -* efi_arch_memory_setup() won't touch it (xen_phys_start should -* never be zero). -*/ -if ( xen_phys_start + base_relocs->rva == (unsigned long )l3_bootmap || - xen_phys_start + base_relocs->rva == (unsigned long )l2_bootmap ) - i = n;
I can't spot the replacement for this code.
Quoted 22 lines
xen/arch/x86/efi/efi-boot.h +0
-22-for ( ; i < n; ++i ) - { -unsigned long addr = xen_phys_start + base_relocs->rva + - (base_relocs->entries[i] &0xfff ); - -switch ( base_relocs->entries[i] >>12 ) - { -case PE_BASE_RELOC_ABS : -break ; -case PE_BASE_RELOC_HIGHLOW : -if ( delta ) - { - *(u32 *)addr += delta; -if (in_page_tables (addr) ) - *(u32 *)addr += xen_phys_start; - } -break ; -case PE_BASE_RELOC_DIR64 : -if ( delta ) - { - *(u64 *)addr += delta; -if (in_page_tables (addr) )
xen/arch/x86/efi/efi-boot.h extern const intpte_t __page_tables_start[], __page_tables_end[]; · line 46
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +1
-9- *(u64 *)addr += xen_phys_start; - } -break ; -default : -blexit (L"Unsupported relocation type" ); - } - } - base_relocs = (const void *)(base_relocs->entries + i + (i &1 )); - } +if (!reloc_pe_back (delta, xen_phys_start, __base_relocs_start, __base_relocs_end))
Nit: Style.
Quoted 4 lines
xen/arch/x86/efi/efi-boot.h +1
-0+blexit (L"Unsupported relocation type" ); }extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[];
Quoted 11 lines · Frediano Ziglio
Testing this feature in preparation for UEFI CA memory mitigation requirements I found some issues causing the loading to fail and other minor issues.
Details in series commit messages.
This is adding an additional way to boot Xen, using GrUB2+EFI (xen.efi:__efi64_mb2_start).Changes since v1:
- Changed title, apparently this is a kind of new mode;
- address lot of comments (see "Changes" in other messages).
Quoted 6 lines
Frediano Ziglio (5):
x86: Put trampoline in .init.data section
x86: Setxen_phys_startandtrampoline_xen_phys_startearlier
x86: Force propergdt_boot_basesetting
x86: Compensate relocation in case of EFI
x86: Rollback relocation in case of EFI multiboot
What I'm missing throughout the series (maybe with patch 1 excluded, which
- as Andrew clarified - is really dealing with an independent aspect) is discussion / clarification of the individual changes not affecting any of the existing boot modes, first and foremost the EFI+MB2 one using xen.gz.
Jan