x86: multiboot2 protocol support
Re: [PATCH v2 20/23] x86: add multiboot2 protocol support for EFI platforms
In reply to Daniel Kiperxen/arch/x86/boot/head.S print_err: · line 213
Quoted 11 lines
xen/arch/x86/boot/head.S +11
-0+run_bs: + push %rax + push %rdi + + /* Initialize BSS (no nasty surprises!). */ + lea __bss_start(%rip),%rdi + lea __bss_end(%rip),%rcx + sub %rdi,%rcx + shr $3,%rcx + xor %eax,%eax + rep stosq
This means we are using the %es segment. The multiboot1 is pretty clear that it should cover up to 4GB.
Would it be worth adding a comment about that?
xen/arch/x86/boot/head.S print_err: · line 223
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ + pop %rdi + + /* + * IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable. + * OUT: %rax - multiboot2.mem_lower. Do not get this value from + * MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag. It could be bogus on + * EFI platforms. + */ + call efi_multiboot2
However the function prototype for efi_multiboot2 is 'void', not 'int' - so it would not return anything!
Review
Quoted 2 lines
(quoted diff) +2
-0+ + /* Convert multiboot2.mem_lower to bytes/16. */
Should we check to make sure it is valid? With those weird machines you seem to have run into I am not actually sure what a valid value is :-(
.. snip..
xen/arch/x86/efi/stub.c struct efi __read_mostly efi = { · line 16
Quoted 9 lines
xen/arch/x86/efi/stub.c +1
-0@@ -13,6 +13,11 @@ struct efi __read_mostly efi = { .smbios3 = EFI_INVALID_TABLE_ADDR }; +void __init efi_multiboot2 (void )
unsigned int __init ..
xen/arch/x86/efi/stub.c struct efi __read_mostly efi = { · line 18
Quoted 2 lines
xen/arch/x86/efi/stub.c +2
-0+{ +/* TODO: Fail if entered! */
And maybe just 'return 0'; ?
Quoted 1 line
xen/arch/x86/efi/stub.c +1
-0+}
Re: [PATCH v2 20/23] x86: add multiboot2 protocol support for EFI platforms
In reply to Daniel KiperQuoted 2 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
Signed-off-by Daniel Kiper <[email protected]>
For a patch of this size, no description at all seems rather problematic.
xen/arch/x86/boot/head.S multiboot1_header_end: · line 97
Quoted 12 lines
xen/arch/x86/boot/head.S +6
-0@@ -89,6 +89,13 @@ multiboot1_header_end: 0, /* Number of the lines - no preference. */ \ 0 /* Number of bits per pixel - no preference. */ + /* Do not disable EFI boot services. */ + mb2ht_init MB2_HT(EFI_BS), MB2_HT(OPTIONAL) + + /* EFI64 entry point. */ + mb2ht_init MB2_HT(ENTRY_ADDRESS_EFI64), MB2_HT(OPTIONAL), \ + sym_phys(__efi64_start)
Iirc at least one of those two is what upstream doesn't have yet, or not all earlier grub2 versions might have. If so - what happens if the resulting Xen gets booted on an incapable grub? Silent death (with black screen)? Or at least some note to the user that the grub2 version is not suitable?
Quoted 8 lines
xen/arch/x86/boot/head.S +4
-0@@ -130,6 +146,119 @@ print_err: .Lhalt: hlt jmp .Lhalt + .code64 + +__efi64_start: + cld
xen/arch/x86/boot/head.S print_err: · line 162
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ + /* Check for Multiboot2 bootloader. */ + cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax + je efi_multiboot2_proto + + /* Jump to not_multiboot after switching CPU to x86_32 mode. */ + lea not_multiboot(%rip),%rdi + jmp x86_32_switch + +efi_multiboot2_proto:
.L
xen/arch/x86/boot/head.S print_err: · line 203
Quoted 1 line
xen/arch/x86/boot/head.S +1
-0+run_bs:
Again.
Quoted 9 lines
xen/arch/x86/boot/head.S +9
-0+x86_32_switch: + cli + + /* Initialise GDT. */ + lgdt gdt_boot_descr(%rip) + + /* Reload code selector. */ + ljmpl *cs32_switch_addr(%rip) +
xen/arch/x86/boot/head.S print_err: · line 252
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ .code32 + +cs32_switch: + /* Initialise basic data segments. */ + mov $BOOT_DS,%edx + mov %edx,%ds + mov %edx,%es + mov %edx,%fs + mov %edx,%gs + mov %edx,%ss
I see no point in loading %fs and %gs with other than nul selectors. I also think %ss should be loaded first. Which reminds me - what about %rsp? Is it guaranteed to have its upper 32 bits clear, so you can re-use the stack in 32-bit mode? (If it is, saying so in a comment would be very desirable.)
xen/arch/x86/boot/head.S multiboot2_proto: · line 321
Quoted 6 lines
xen/arch/x86/boot/head.S +1
-1@@ -182,7 +318,7 @@ multiboot2_proto: and $~(MULTIBOOT2_TAG_ALIGN-1),%ecx jmp 0b -trampoline_setup: +trampoline_bios_setup:
Another .L candidate.
Quoted 6 lines
xen/arch/x86/boot/head.S +0
-0/* Set up trampoline segment 64k below EBDA */ movzwl 0x40e,%ecx /* EBDA segment */ cmp $0xa000,%ecx /* sanity check (high) */@@ -198,12 +334,13 @@ trampoline_setup: * multiboot structure (if available) and use the smallest. */
xen/arch/x86/boot/head.S trampoline_setup: · line 343
Quoted 10 lines
xen/arch/x86/boot/head.S +3
-2cmp $0x100,%edx /* is the multiboot value too small? */ - jb 2f /* if so, do not use it */ + jb trampoline_setup /* if so, do not use it */ shl $10-4,%edx cmp %ecx,%edx /* compare with BDA value */ cmovb %edx,%ecx /* and use the smaller */ -2: /* Reserve 64kb for the trampoline */ +trampoline_setup: + /* Reserve 64kb for the trampoline. */
And one more.
xen/arch/x86/boot/head.S trampoline_setup: · line 365
Quoted 10 lines
xen/arch/x86/boot/head.S +6
-0@@ -220,6 +357,13 @@ trampoline_setup: add $12,%esp /* Remove reloc() args from stack. */ mov %eax,sym_phys(multiboot_ptr) + /* + * Do not zero BSS on EFI platform here. + * It was initialized earlier. + */ + cmpb $1,sym_phys(skip_realmode) + je 1f
So why can't this be done uniformly here? I didn't see you write any variable in .bss by now. And if there was any, moving it to .data would avoid zeroing .bss in two different places. Or wait - I see, it's the C code in efi_multiboot2() that you need to take care of. Well, probably okay then this way, but please extend the comment at the new zeroing site to say _why_ it needs to be done differently/earlier.
Quoted 15 lines
xen/arch/x86/boot/head.S +15
-0+paddr_t __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) +{ + EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; + UINTN cols, gop_mode = ~0, rows; + + set_bit(EFI_PLATFORM, &efi.flags); + + efi_init(ImageHandle, SystemTable); + + efi_console_set_mode(); + + if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode, + &cols, &rows) == EFI_SUCCESS ) + efi_arch_console_init(cols, rows); +
xen/arch/x86/boot/head.S trampoline_setup:
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ gop = efi_get_gop(); + gop_mode = efi_find_gop_mode(gop, 0, 0, 0); + efi_arch_edd(); + efi_tables(); + setup_efi_pci(); + efi_variables(); + efi_set_gop_mode(gop, gop_mode); + efi_exit_boot(ImageHandle, SystemTable); + + return cfg.addr;
With all the refactoring in the earlier patches it is now almost impossible to know what cfg.addr holds at this point - it looks to me as if this is entirely unrelated to the mem_lower value the caller wants to derive from this. Please at least add a brief comment.
xen/arch/x86/efi/stub.c struct efi __read_mostly efi = { · line 18
Quoted 9 lines
xen/arch/x86/efi/stub.c +3
-0@@ -13,6 +13,11 @@ struct efi __read_mostly efi = { .smbios3 = EFI_INVALID_TABLE_ADDR }; +void __init efi_multiboot2 (void ) +{ +/* TODO: Fail if entered! */
No "TODO" or alike please in non-RFC patch submissions (unless there are exceptional circumstances). Here - BUG() (or panic() if there was a remote chance of this being reached).
xen/arch/x86/efi/stub.c void __init noreturn __start_xen(unsigned long mbi_p) · line 711
Quoted 6 lines
xen/arch/x86/efi/stub.c +1
-1@@ -708,7 +708,11 @@ void __init noreturn __start_xen(unsigned long mbi_p) l3_bootmap[l3_table_offset (BOOTSTRAP_MAP_BASE )] =l3e_from_paddr (__pa (l2_bootmap), __PAGE_HYPERVISOR); - memmap_type = loader; + memmap_type ="EFI" ;
What's wrong with keeping this line as is?
xen/arch/x86/efi/stub.c void __init noreturn __start_xen(unsigned long mbi_p) · line 716
Quoted 5 lines
xen/arch/x86/efi/stub.c +4
-0+ } +else if (efi_enabled (EFI_PLATFORM ) ) + { + memmap_type ="EFI" ; }
The braces are now pointless here.
Quoted 6 lines
xen/common/efi/boot.c +0
-0@@ -79,6 +79,17 @@ static size_t wstrlen(const CHAR16 * s);static int set_color (u32 mask,int bpp,u8 *pos,u8 *sz);static bool_t match_guid (const EFI_GUID *guid1,const EFI_GUID *guid2);
xen/common/efi/boot.c static size_t wstrlen(const CHAR16 * s); · line 91
Quoted 10 lines
xen/common/efi/boot.c +10
-0+static void efi_init (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable); +static void efi_console_set_mode (void ); +static EFI_GRAPHICS_OUTPUT_PROTOCOL *efi_get_gop (void ); +static UINTN efi_find_gop_mode (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, +UINTN cols,UINTN rows,UINTN depth); +static void efi_tables (void ); +static void setup_efi_pci (void ); +static void efi_variables (void ); +static void efi_set_gop_mode (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,UINTN gop_mode); +static void efi_exit_boot (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable);
This is ugly; I'm sure there is a way to avoid these declarations.
Jan
Re: [PATCH v2 20/23] x86: add multiboot2 protocol support for EFI platforms
In reply to Daniel KiperQuoted 2 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
Signed-off-by Daniel Kiper <[email protected]>
For a patch of this size, no description at all seems rather problematic.
xen/arch/x86/boot/head.S multiboot1_header_end: · line 97
Quoted 12 lines
xen/arch/x86/boot/head.S +6
-0@@ -89,6 +89,13 @@ multiboot1_header_end: 0, /* Number of the lines - no preference. */ \ 0 /* Number of bits per pixel - no preference. */ + /* Do not disable EFI boot services. */ + mb2ht_init MB2_HT(EFI_BS), MB2_HT(OPTIONAL) + + /* EFI64 entry point. */ + mb2ht_init MB2_HT(ENTRY_ADDRESS_EFI64), MB2_HT(OPTIONAL), \ + sym_phys(__efi64_start)
Iirc at least one of those two is what upstream doesn't have yet, or not all earlier grub2 versions might have. If so - what happens if the resulting Xen gets booted on an incapable grub? Silent death (with black screen)? Or at least some note to the user that the grub2 version is not suitable?
Quoted 8 lines
xen/arch/x86/boot/head.S +4
-0@@ -130,6 +146,119 @@ print_err: .Lhalt: hlt jmp .Lhalt + .code64 + +__efi64_start: + cld
xen/arch/x86/boot/head.S print_err: · line 162
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ + /* Check for Multiboot2 bootloader. */ + cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax + je efi_multiboot2_proto + + /* Jump to not_multiboot after switching CPU to x86_32 mode. */ + lea not_multiboot(%rip),%rdi + jmp x86_32_switch + +efi_multiboot2_proto:
.L
xen/arch/x86/boot/head.S print_err: · line 203
Quoted 1 line
xen/arch/x86/boot/head.S +1
-0+run_bs:
Again.
Quoted 9 lines
xen/arch/x86/boot/head.S +9
-0+x86_32_switch: + cli + + /* Initialise GDT. */ + lgdt gdt_boot_descr(%rip) + + /* Reload code selector. */ + ljmpl *cs32_switch_addr(%rip) +
xen/arch/x86/boot/head.S print_err: · line 252
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ .code32 + +cs32_switch: + /* Initialise basic data segments. */ + mov $BOOT_DS,%edx + mov %edx,%ds + mov %edx,%es + mov %edx,%fs + mov %edx,%gs + mov %edx,%ss
I see no point in loading %fs and %gs with other than nul selectors. I also think %ss should be loaded first. Which reminds me - what about %rsp? Is it guaranteed to have its upper 32 bits clear, so you can re-use the stack in 32-bit mode? (If it is, saying so in a comment would be very desirable.)
xen/arch/x86/boot/head.S multiboot2_proto: · line 321
Quoted 6 lines
xen/arch/x86/boot/head.S +1
-1@@ -182,7 +318,7 @@ multiboot2_proto: and $~(MULTIBOOT2_TAG_ALIGN-1),%ecx jmp 0b -trampoline_setup: +trampoline_bios_setup:
Another .L candidate.
Quoted 6 lines
xen/arch/x86/boot/head.S +0
-0/* Set up trampoline segment 64k below EBDA */ movzwl 0x40e,%ecx /* EBDA segment */ cmp $0xa000,%ecx /* sanity check (high) */@@ -198,12 +334,13 @@ trampoline_setup: * multiboot structure (if available) and use the smallest. */
xen/arch/x86/boot/head.S trampoline_setup: · line 343
Quoted 10 lines
xen/arch/x86/boot/head.S +3
-2cmp $0x100,%edx /* is the multiboot value too small? */ - jb 2f /* if so, do not use it */ + jb trampoline_setup /* if so, do not use it */ shl $10-4,%edx cmp %ecx,%edx /* compare with BDA value */ cmovb %edx,%ecx /* and use the smaller */ -2: /* Reserve 64kb for the trampoline */ +trampoline_setup: + /* Reserve 64kb for the trampoline. */
And one more.
xen/arch/x86/boot/head.S trampoline_setup: · line 365
Quoted 10 lines
xen/arch/x86/boot/head.S +6
-0@@ -220,6 +357,13 @@ trampoline_setup: add $12,%esp /* Remove reloc() args from stack. */ mov %eax,sym_phys(multiboot_ptr) + /* + * Do not zero BSS on EFI platform here. + * It was initialized earlier. + */ + cmpb $1,sym_phys(skip_realmode) + je 1f
So why can't this be done uniformly here? I didn't see you write any variable in .bss by now. And if there was any, moving it to .data would avoid zeroing .bss in two different places. Or wait - I see, it's the C code in efi_multiboot2() that you need to take care of. Well, probably okay then this way, but please extend the comment at the new zeroing site to say _why_ it needs to be done differently/earlier.
Quoted 15 lines
xen/arch/x86/boot/head.S +15
-0+paddr_t __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) +{ + EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; + UINTN cols, gop_mode = ~0, rows; + + set_bit(EFI_PLATFORM, &efi.flags); + + efi_init(ImageHandle, SystemTable); + + efi_console_set_mode(); + + if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode, + &cols, &rows) == EFI_SUCCESS ) + efi_arch_console_init(cols, rows); +
xen/arch/x86/boot/head.S trampoline_setup:
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ gop = efi_get_gop(); + gop_mode = efi_find_gop_mode(gop, 0, 0, 0); + efi_arch_edd(); + efi_tables(); + setup_efi_pci(); + efi_variables(); + efi_set_gop_mode(gop, gop_mode); + efi_exit_boot(ImageHandle, SystemTable); + + return cfg.addr;
With all the refactoring in the earlier patches it is now almost impossible to know what cfg.addr holds at this point - it looks to me as if this is entirely unrelated to the mem_lower value the caller wants to derive from this. Please at least add a brief comment.
xen/arch/x86/efi/stub.c struct efi __read_mostly efi = { · line 18
Quoted 9 lines
xen/arch/x86/efi/stub.c +3
-0@@ -13,6 +13,11 @@ struct efi __read_mostly efi = { .smbios3 = EFI_INVALID_TABLE_ADDR }; +void __init efi_multiboot2 (void ) +{ +/* TODO: Fail if entered! */
No "TODO" or alike please in non-RFC patch submissions (unless there are exceptional circumstances). Here - BUG() (or panic() if there was a remote chance of this being reached).
xen/arch/x86/efi/stub.c void __init noreturn __start_xen(unsigned long mbi_p) · line 711
Quoted 6 lines
xen/arch/x86/efi/stub.c +1
-1@@ -708,7 +708,11 @@ void __init noreturn __start_xen(unsigned long mbi_p) l3_bootmap[l3_table_offset (BOOTSTRAP_MAP_BASE )] =l3e_from_paddr (__pa (l2_bootmap), __PAGE_HYPERVISOR); - memmap_type = loader; + memmap_type ="EFI" ;
What's wrong with keeping this line as is?
xen/arch/x86/efi/stub.c void __init noreturn __start_xen(unsigned long mbi_p) · line 716
Quoted 5 lines
xen/arch/x86/efi/stub.c +4
-0+ } +else if (efi_enabled (EFI_PLATFORM ) ) + { + memmap_type ="EFI" ; }
The braces are now pointless here.
Quoted 6 lines
xen/common/efi/boot.c +0
-0@@ -79,6 +79,17 @@ static size_t wstrlen(const CHAR16 * s);static int set_color (u32 mask,int bpp,u8 *pos,u8 *sz);static bool_t match_guid (const EFI_GUID *guid1,const EFI_GUID *guid2);
xen/common/efi/boot.c static size_t wstrlen(const CHAR16 * s); · line 91
Quoted 10 lines
xen/common/efi/boot.c +10
-0+static void efi_init (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable); +static void efi_console_set_mode (void ); +static EFI_GRAPHICS_OUTPUT_PROTOCOL *efi_get_gop (void ); +static UINTN efi_find_gop_mode (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, +UINTN cols,UINTN rows,UINTN depth); +static void efi_tables (void ); +static void setup_efi_pci (void ); +static void efi_variables (void ); +static void efi_set_gop_mode (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,UINTN gop_mode); +static void efi_exit_boot (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable);
This is ugly; I'm sure there is a way to avoid these declarations.
Jan
Re: [PATCH v2 20/23] x86: add multiboot2 protocol support for EFI platforms
Quoted 12 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
Signed-off-by Daniel Kiper <[email protected]>For a patch of this size, no description at all seems rather problematic.
Quoted 6 lines
xen/arch/x86/boot/head.S +0
-0@@ -89,6 +89,13 @@ multiboot1_header_end: 0, /* Number of the lines - no preference. */ \ 0 /* Number of bits per pixel - no preference. */
Quoted 12 lines
xen/arch/x86/boot/head.S multiboot1_header_end: · line 97
Quoted 6 lines
xen/arch/x86/boot/head.S +6
-0+ /* Do not disable EFI boot services. */ + mb2ht_init MB2_HT(EFI_BS), MB2_HT(OPTIONAL) + + /* EFI64 entry point. */ + mb2ht_init MB2_HT(ENTRY_ADDRESS_EFI64), MB2_HT(OPTIONAL), \ + sym_phys(__efi64_start)Iirc at least one of those two is what upstream doesn't have yet, or not all earlier grub2 versions might have. If so - what happens if the resulting Xen gets booted on an incapable grub? Silent death (with black screen)? Or at least some note to the user that the grub2 version is not suitable?
There is the code below which sends relevant message to COM1 and... ...well, VGA which of course does not make sense and should be fixed.
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/boot/head.S +0
-0@@ -130,6 +146,119 @@ print_err: .Lhalt: hlt jmp .Lhalt
Quoted 16 lines
Quoted 4 lines
xen/arch/x86/boot/head.S +4
-0+ .code64 + +__efi64_start: + cldxen/arch/x86/boot/head.S print_err: · line 162
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ + /* Check for Multiboot2 bootloader. */ + cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax + je efi_multiboot2_proto + + /* Jump to not_multiboot after switching CPU to x86_32 mode. */ + lea not_multiboot(%rip),%rdi + jmp x86_32_switch + +efi_multiboot2_proto:.L
Why do you want to hide labels which could be useful during debugging?
Quoted 3 lines
xen/arch/x86/boot/head.S print_err: · line 203
Quoted 1 line
xen/arch/x86/boot/head.S +1
-0+run_bs:Again.
Ditto.
Quoted 17 lines
Quoted 17 lines
xen/arch/x86/boot/head.S +17
-0+x86_32_switch: + cli + + /* Initialise GDT. */ + lgdt gdt_boot_descr(%rip) + + /* Reload code selector. */ + ljmpl *cs32_switch_addr(%rip) + + .code32 + +cs32_switch: + /* Initialise basic data segments. */ + mov $BOOT_DS,%edx + mov %edx,%ds + mov %edx,%es + mov %edx,%fs
Quoted 8 lines
xen/arch/x86/boot/head.S print_err: · line 252
Quoted 2 lines
xen/arch/x86/boot/head.S +2
-0+ mov %edx,%gs + mov %edx,%ssI see no point in loading %fs and %gs with other than nul selectors. I also think %ss should be loaded first. Which reminds me - what about %rsp? Is it guaranteed to have its upper 32 bits clear, so you can re-use the stack in 32-bit mode? (If it is, saying so in a comment would be very desirable.)
I am not reusing %rsp value. %esp is initialized later in 32-bit code. Stack is not used until %esp is not initialized.
[...]
Quoted 6 lines
Quoted 6 lines
xen/common/efi/boot.c +0
-0@@ -79,6 +79,17 @@ static size_t wstrlen(const CHAR16 * s);static int set_color (u32 mask,int bpp,u8 *pos,u8 *sz);static bool_t match_guid (const EFI_GUID *guid1,const EFI_GUID *guid2);
Quoted 12 lines
xen/common/efi/boot.c static size_t wstrlen(const CHAR16 * s); · line 91
Quoted 10 lines
xen/common/efi/boot.c +10
-0+static void efi_init (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable); +static void efi_console_set_mode (void ); +static EFI_GRAPHICS_OUTPUT_PROTOCOL *efi_get_gop (void ); +static UINTN efi_find_gop_mode (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, +UINTN cols,UINTN rows,UINTN depth); +static void efi_tables (void ); +static void setup_efi_pci (void ); +static void efi_variables (void ); +static void efi_set_gop_mode (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,UINTN gop_mode); +static void efi_exit_boot (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable);This is ugly; I'm sure there is a way to avoid these declarations.
This probably requires play with '#include "efi-boot.h"' and move somewhere before efi_start(). Maybe something else. If it is not a problem for you I can do that.
Daniel
Re: [PATCH v2 20/23] x86: add multiboot2 protocol support for EFI platforms
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 22.09.15 at 17:21, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
xen/arch/x86/boot/head.S +0
-0@@ -130,6 +146,119 @@ print_err: .Lhalt: hlt jmp .LhaltQuoted 16 lines
Quoted 4 lines
xen/arch/x86/boot/head.S +4
-0+ .code64 + +__efi64_start: + cldxen/arch/x86/boot/head.S print_err: · line 162
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ + /* Check for Multiboot2 bootloader. */ + cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax + je efi_multiboot2_proto + + /* Jump to not_multiboot after switching CPU to x86_32 mode. */ + lea not_multiboot(%rip),%rdi + jmp x86_32_switch + +efi_multiboot2_proto:.L
Quoted 1 line
Why do you want to hide labels which could be useful during debugging?
With a few exceptions, assembly code should follow C and other high level languages: Symbol table entries only at function boundaries (or whatever their suitable counterparts in assembly are).
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
xen/arch/x86/boot/head.S +17
-0+x86_32_switch: + cli + + /* Initialise GDT. */ + lgdt gdt_boot_descr(%rip) + + /* Reload code selector. */ + ljmpl *cs32_switch_addr(%rip) + + .code32 + +cs32_switch: + /* Initialise basic data segments. */ + mov $BOOT_DS,%edx + mov %edx,%ds + mov %edx,%es + mov %edx,%fsQuoted 8 lines
xen/arch/x86/boot/head.S print_err: · line 252
Quoted 2 lines
xen/arch/x86/boot/head.S +2
-0+ mov %edx,%gs + mov %edx,%ssI see no point in loading %fs and %gs with other than nul selectors. I also think %ss should be loaded first. Which reminds me - what about %rsp? Is it guaranteed to have its upper 32 bits clear, so you can re-use the stack in 32-bit mode? (If it is, saying so in a comment would be very desirable.)
Quoted 2 lines
I am not reusing %rsp value. %esp is initialized later in 32-bit code. Stack is not used until %esp is not initialized.
If you load %ss without loading the stack pointer, you should imo at least add a comment saying when/where the other half will be done.
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
xen/common/efi/boot.c +0
-0@@ -79,6 +79,17 @@ static size_t wstrlen(const CHAR16 * s);static int set_color (u32 mask,int bpp,u8 *pos,u8 *sz);static bool_t match_guid (const EFI_GUID *guid1,const EFI_GUID *guid2);Quoted 12 lines
xen/common/efi/boot.c static size_t wstrlen(const CHAR16 * s); · line 91
Quoted 10 lines
xen/common/efi/boot.c +10
-0+static void efi_init (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable); +static void efi_console_set_mode (void ); +static EFI_GRAPHICS_OUTPUT_PROTOCOL *efi_get_gop (void ); +static UINTN efi_find_gop_mode (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, +UINTN cols,UINTN rows,UINTN depth); +static void efi_tables (void ); +static void setup_efi_pci (void ); +static void efi_variables (void ); +static void efi_set_gop_mode (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,UINTN gop_mode); +static void efi_exit_boot (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable);This is ugly; I'm sure there is a way to avoid these declarations.
Quoted 3 lines
This probably requires play with '#include "
efi-boot.h"' and move somewhere beforeefi_start(). Maybe something else. If it is not a problem for you I can do that.
Indeed moving an #include would seem far better than adding almost a dozen declarations (any of which will need to get touched if the respective definition changes, i.e. arranging for future churn).
Jan
Re: [PATCH v2 20/23] x86: add multiboot2 protocol support for EFI platforms
In reply to Daniel KiperQuoted 24 lines
Quoted 1 line
Quoted 1 line · On 22.09.15 at 17:21, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
xen/arch/x86/boot/head.S +0
-0@@ -130,6 +146,119 @@ print_err: .Lhalt: hlt jmp .LhaltQuoted 16 lines
Quoted 4 lines
xen/arch/x86/boot/head.S +4
-0+ .code64 + +__efi64_start: + cldxen/arch/x86/boot/head.S print_err: · line 162
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ + /* Check for Multiboot2 bootloader. */ + cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax + je efi_multiboot2_proto + + /* Jump to not_multiboot after switching CPU to x86_32 mode. */ + lea not_multiboot(%rip),%rdi + jmp x86_32_switch + +efi_multiboot2_proto:.L
Quoted 1 line
Why do you want to hide labels which could be useful during debugging?
With a few exceptions, assembly code should follow C and other high level languages: Symbol table entries only at function boundaries (or whatever their suitable counterparts in assembly are).
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
xen/arch/x86/boot/head.S +17
-0+x86_32_switch: + cli + + /* Initialise GDT. */ + lgdt gdt_boot_descr(%rip) + + /* Reload code selector. */ + ljmpl *cs32_switch_addr(%rip) + + .code32 + +cs32_switch: + /* Initialise basic data segments. */ + mov $BOOT_DS,%edx + mov %edx,%ds + mov %edx,%es + mov %edx,%fsQuoted 8 lines
xen/arch/x86/boot/head.S print_err: · line 252
Quoted 2 lines
xen/arch/x86/boot/head.S +2
-0+ mov %edx,%gs + mov %edx,%ssI see no point in loading %fs and %gs with other than nul selectors. I also think %ss should be loaded first. Which reminds me - what about %rsp? Is it guaranteed to have its upper 32 bits clear, so you can re-use the stack in 32-bit mode? (If it is, saying so in a comment would be very desirable.)
Quoted 2 lines
I am not reusing %rsp value. %esp is initialized later in 32-bit code. Stack is not used until %esp is not initialized.
If you load %ss without loading the stack pointer, you should imo at least add a comment saying when/where the other half will be done.
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
xen/common/efi/boot.c +0
-0@@ -79,6 +79,17 @@ static size_t wstrlen(const CHAR16 * s);static int set_color (u32 mask,int bpp,u8 *pos,u8 *sz);static bool_t match_guid (const EFI_GUID *guid1,const EFI_GUID *guid2);Quoted 12 lines
xen/common/efi/boot.c static size_t wstrlen(const CHAR16 * s); · line 91
Quoted 10 lines
xen/common/efi/boot.c +10
-0+static void efi_init (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable); +static void efi_console_set_mode (void ); +static EFI_GRAPHICS_OUTPUT_PROTOCOL *efi_get_gop (void ); +static UINTN efi_find_gop_mode (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, +UINTN cols,UINTN rows,UINTN depth); +static void efi_tables (void ); +static void setup_efi_pci (void ); +static void efi_variables (void ); +static void efi_set_gop_mode (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,UINTN gop_mode); +static void efi_exit_boot (EFI_HANDLE ImageHandle,EFI_SYSTEM_TABLE *SystemTable);This is ugly; I'm sure there is a way to avoid these declarations.
Quoted 3 lines
This probably requires play with '#include "
efi-boot.h"' and move somewhere beforeefi_start(). Maybe something else. If it is not a problem for you I can do that.
Indeed moving an #include would seem far better than adding almost a dozen declarations (any of which will need to get touched if the respective definition changes, i.e. arranging for future churn).
Jan
PATCH v2 21/23 x86/boot: implement early command line parser in C
In reply to Daniel KiperCurrent early command line parser implementation in assembler is very difficult to change to relocatable stuff using segment registers. This requires a lot of changes in very weird and fragile code. So, reimplement this functionality in C. This way code will be relocatable out of the box and much easier to maintain.
--- .gitignore | 5 +- xen/arch/x86/Makefile | 2 +- xen/arch/x86/boot/Makefile | 7 +- xen/arch/x86/boot/build32.mk | 2 + xen/arch/x86/boot/cmdline.S | 367 ------------------------------------- xen/arch/x86/boot/cmdline.c | 396 ++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/boot/edd.S | 3 - xen/arch/x86/boot/head.S | 17 ++ xen/arch/x86/boot/trampoline.S | 14 ++ xen/arch/x86/boot/video.S | 6 - 10 files changed, 439 insertions(+), 380 deletions(-) delete mode 100644 xen/arch/x86/boot/cmdline.S create mode 100644 xen/arch/x86/boot/cmdline.c
.gitignore +3 -2
@@ -223,9 +223,10 @@ xen/arch/arm/xen.lds xen/arch/x86/asm-offsets.s xen/arch/x86/boot/mkelf32 xen/arch/x86/xen.lds +xen/arch/x86/boot/cmdline.S xen/arch/x86/boot/reloc.S -xen/arch/x86/boot/reloc.bin -xen/arch/x86/boot/reloc.lnk +xen/arch/x86/boot/*.bin +xen/arch/x86/boot/*.lnk xen/arch/x86/efi.lds xen/arch/x86/efi/check.efi xen/arch/x86/efi/disabled
xen/arch/x86/Makefile +1 -1
@@ -170,4 +170,4 @@ clean:: rm -f asm-offsets.s *.lds boot/*.o boot/*~ boot/core boot/mkelf32 rm -f $(BASEDIR)/.xen-syms.[0-9]* boot/.*.d rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.o efi/.*.d efi/*.efi efi/disabled efi/mkreloc - rm -f boot/reloc.S boot/reloc.lnk boot/reloc.bin + rm -f boot/cmdline.S boot/reloc.S boot/*.lnk boot/*.bin
xen/arch/x86/boot/Makefile +6 -1
@@ -1,9 +1,14 @@ obj-bin-y += head.o +CMDLINE_DEPS = video.h + RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h \ $(BASEDIR)/include/xen/multiboot2.h -head.o: reloc.S +head.o: cmdline.S reloc.S + +cmdline.S: cmdline.c $(CMDLINE_DEPS) + $(MAKE) -f build32.mk $@ CMDLINE_DEPS="$(CMDLINE_DEPS)" reloc.S: reloc.c $(RELOC_DEPS) $(MAKE) -f build32.mk $@ RELOC_DEPS="$(RELOC_DEPS)"
xen/arch/x86/boot/build32.mk +2 -0
@@ -30,6 +30,8 @@ CFLAGS := $(filter-out -flto,$(CFLAGS)) esac; \ done +cmdline.o: cmdline.c $(CMDLINE_DEPS) + reloc.o: reloc.c $(RELOC_DEPS) .PRECIOUS: %.bin %.lnk
xen/arch/x86/boot/cmdline.S deleted +0 -367
367 lines not on this page · raw message
xen/arch/x86/boot/cmdline.c new file +396 -0
396 lines not on this page · raw message
xen/arch/x86/boot/edd.S +0 -3
@@ -142,9 +142,6 @@ edd_next: edd_done: ret -opt_edd: - .byte 0 # edd=on/off/skipmbr - GLOBAL(boot_edd_info_nr) .byte 0 GLOBAL(boot_mbr_signature_nr)
xen/arch/x86/boot/head.S +17 -0
@@ -429,8 +429,24 @@ trampoline_setup: cmp $sym_phys(__trampoline_seg_stop),%edi jb 1b + /* Do not parse command line on EFI platform here. */ + cmpb $1,sym_phys(skip_realmode) + je 1f + + /* Bail if there is no command line to parse. */ + mov sym_phys(multiboot_ptr),%ebx + testl $MBI_CMDLINE,MB_flags(%ebx) + jz 1f + + cmpl $0,MB_cmdline(%ebx) + jz 1f + + pushl $sym_phys(early_boot_opts) + pushl MB_cmdline(%ebx) call cmdline_parse_early + add $8,%esp /* Remove cmdline_parse_early() args from stack. */ +1: /* Switch to low-memory stack. */ mov sym_phys(trampoline_phys),%edi lea 0x10000(%edi),%esp
@@ -446,6 +462,7 @@ trampoline_setup: /* Jump into the relocated trampoline. */ lret +cmdline_parse_early: #include "cmdline.S" reloc:
xen/arch/x86/boot/trampoline.S +14 -0
@@ -1,3 +1,5 @@ +#include "video.h" + .code16 /* NB. bootsym() is only usable in real mode, or via BOOT_PSEUDORM_DS. */
@@ -201,8 +203,20 @@ trampoline_boot_cpu_entry: /* Jump to the common bootstrap entry point. */ jmp trampoline_protmode_entry +/* + * Keep in sync with cmdline.c:early_boot_opts_t type! + */ +early_boot_opts: skip_realmode: .byte 0 +opt_edd: + .byte 0 /* edd=on/off/skipmbr */ +opt_edid: + .byte 0 /* EDID parsing option (force/no/default). */ +GLOBAL(boot_vid_mode) + .word VIDEO_80x25 /* If we don't run at all, assume basic video mode 3 at 80x25. */ +vesa_size: + .word 0,0,0 /* width x depth x height */ GLOBAL(kbd_shift_flags) .byte 0
xen/arch/x86/boot/video.S +0 -6
@@ -945,7 +945,6 @@ store_edid: #endif ret -opt_edid: .byte 0 # EDID parsing option (force/no/default) mt_end: .word 0 # End of video mode table if built edit_buf: .space 6 # Line editor buffer card_name: .word 0 # Pointer to adapter name
@@ -991,11 +990,6 @@ name_bann: .asciz "Video adapter: " force_size: .word 0 # Use this size instead of the one in BIOS vars -vesa_size: .word 0,0,0 # width x depth x height - -/* If we don't run at all, assume basic video mode 3 at 80x25. */ -GLOBAL(boot_vid_mode) - .word VIDEO_80x25 GLOBAL(boot_vid_info) .byte 0, 0 /* orig_x, orig_y */ .byte 3 /* text mode 3 */
Signature · 1 line
1.7.10.4
PATCH v2 21/23 x86/boot: implement early command line parser in C
In reply to Daniel KiperCurrent early command line parser implementation in assembler is very difficult to change to relocatable stuff using segment registers. This requires a lot of changes in very weird and fragile code. So, reimplement this functionality in C. This way code will be relocatable out of the box and much easier to maintain.
--- .gitignore | 5 +- xen/arch/x86/Makefile | 2 +- xen/arch/x86/boot/Makefile | 7 +- xen/arch/x86/boot/build32.mk | 2 + xen/arch/x86/boot/cmdline.S | 367 ------------------------------------- xen/arch/x86/boot/cmdline.c | 396 ++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/boot/edd.S | 3 - xen/arch/x86/boot/head.S | 17 ++ xen/arch/x86/boot/trampoline.S | 14 ++ xen/arch/x86/boot/video.S | 6 - 10 files changed, 439 insertions(+), 380 deletions(-) delete mode 100644 xen/arch/x86/boot/cmdline.S create mode 100644 xen/arch/x86/boot/cmdline.c
.gitignore +3 -2
@@ -223,9 +223,10 @@ xen/arch/arm/xen.lds xen/arch/x86/asm-offsets.s xen/arch/x86/boot/mkelf32 xen/arch/x86/xen.lds +xen/arch/x86/boot/cmdline.S xen/arch/x86/boot/reloc.S -xen/arch/x86/boot/reloc.bin -xen/arch/x86/boot/reloc.lnk +xen/arch/x86/boot/*.bin +xen/arch/x86/boot/*.lnk xen/arch/x86/efi.lds xen/arch/x86/efi/check.efi xen/arch/x86/efi/disabled
xen/arch/x86/Makefile +1 -1
@@ -170,4 +170,4 @@ clean:: rm -f asm-offsets.s *.lds boot/*.o boot/*~ boot/core boot/mkelf32 rm -f $(BASEDIR)/.xen-syms.[0-9]* boot/.*.d rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.o efi/.*.d efi/*.efi efi/disabled efi/mkreloc - rm -f boot/reloc.S boot/reloc.lnk boot/reloc.bin + rm -f boot/cmdline.S boot/reloc.S boot/*.lnk boot/*.bin
xen/arch/x86/boot/Makefile +6 -1
@@ -1,9 +1,14 @@ obj-bin-y += head.o +CMDLINE_DEPS = video.h + RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h \ $(BASEDIR)/include/xen/multiboot2.h -head.o: reloc.S +head.o: cmdline.S reloc.S + +cmdline.S: cmdline.c $(CMDLINE_DEPS) + $(MAKE) -f build32.mk $@ CMDLINE_DEPS="$(CMDLINE_DEPS)" reloc.S: reloc.c $(RELOC_DEPS) $(MAKE) -f build32.mk $@ RELOC_DEPS="$(RELOC_DEPS)"
xen/arch/x86/boot/build32.mk +2 -0
@@ -30,6 +30,8 @@ CFLAGS := $(filter-out -flto,$(CFLAGS)) esac; \ done +cmdline.o: cmdline.c $(CMDLINE_DEPS) + reloc.o: reloc.c $(RELOC_DEPS) .PRECIOUS: %.bin %.lnk
xen/arch/x86/boot/cmdline.S deleted +0 -367
367 lines not on this page · raw message
xen/arch/x86/boot/cmdline.c new file +396 -0
396 lines not on this page · raw message
xen/arch/x86/boot/edd.S +0 -3
@@ -142,9 +142,6 @@ edd_next: edd_done: ret -opt_edd: - .byte 0 # edd=on/off/skipmbr - GLOBAL(boot_edd_info_nr) .byte 0 GLOBAL(boot_mbr_signature_nr)
xen/arch/x86/boot/head.S +17 -0
@@ -429,8 +429,24 @@ trampoline_setup: cmp $sym_phys(__trampoline_seg_stop),%edi jb 1b + /* Do not parse command line on EFI platform here. */ + cmpb $1,sym_phys(skip_realmode) + je 1f + + /* Bail if there is no command line to parse. */ + mov sym_phys(multiboot_ptr),%ebx + testl $MBI_CMDLINE,MB_flags(%ebx) + jz 1f + + cmpl $0,MB_cmdline(%ebx) + jz 1f + + pushl $sym_phys(early_boot_opts) + pushl MB_cmdline(%ebx) call cmdline_parse_early + add $8,%esp /* Remove cmdline_parse_early() args from stack. */ +1: /* Switch to low-memory stack. */ mov sym_phys(trampoline_phys),%edi lea 0x10000(%edi),%esp
@@ -446,6 +462,7 @@ trampoline_setup: /* Jump into the relocated trampoline. */ lret +cmdline_parse_early: #include "cmdline.S" reloc:
xen/arch/x86/boot/trampoline.S +14 -0
@@ -1,3 +1,5 @@ +#include "video.h" + .code16 /* NB. bootsym() is only usable in real mode, or via BOOT_PSEUDORM_DS. */
@@ -201,8 +203,20 @@ trampoline_boot_cpu_entry: /* Jump to the common bootstrap entry point. */ jmp trampoline_protmode_entry +/* + * Keep in sync with cmdline.c:early_boot_opts_t type! + */ +early_boot_opts: skip_realmode: .byte 0 +opt_edd: + .byte 0 /* edd=on/off/skipmbr */ +opt_edid: + .byte 0 /* EDID parsing option (force/no/default). */ +GLOBAL(boot_vid_mode) + .word VIDEO_80x25 /* If we don't run at all, assume basic video mode 3 at 80x25. */ +vesa_size: + .word 0,0,0 /* width x depth x height */ GLOBAL(kbd_shift_flags) .byte 0
xen/arch/x86/boot/video.S +0 -6
@@ -945,7 +945,6 @@ store_edid: #endif ret -opt_edid: .byte 0 # EDID parsing option (force/no/default) mt_end: .word 0 # End of video mode table if built edit_buf: .space 6 # Line editor buffer card_name: .word 0 # Pointer to adapter name
@@ -991,11 +990,6 @@ name_bann: .asciz "Video adapter: " force_size: .word 0 # Use this size instead of the one in BIOS vars -vesa_size: .word 0,0,0 # width x depth x height - -/* If we don't run at all, assume basic video mode 3 at 80x25. */ -GLOBAL(boot_vid_mode) - .word VIDEO_80x25 GLOBAL(boot_vid_info) .byte 0, 0 /* orig_x, orig_y */ .byte 3 /* text mode 3 */
Signature · 1 line
1.7.10.4
Re: [Xen-devel] [PATCH v2 21/23] x86/boot: implement early command line parser in C
Quoted 9 lines · Daniel Kiper
Current early command line parser implementation in assembler is very difficult to change to relocatable stuff using segment registers. This requires a lot of changes in very weird and fragile code. So, reimplement this functionality in C. This way code will be relocatable out of the box and much easier to maintain.
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Daniel Kiper <[email protected]>
I did not look at the str* functions that were added in but just at how the parameters parsing was done. Also at the assembler code and with that
.. snip..
xen/arch/x86/boot/cmdline.c line 2
Quoted 8 lines
xen/arch/x86/boot/cmdline.c new file +2
-0@@ -0,0 +1,396 @@ +/* +* Copyright (c) 2015 Oracle Co.
Oracle Corporation.
Re: [PATCH v2 21/23] x86/boot: implement early command line parser in C
In reply to Daniel KiperQuoted 9 lines · Daniel Kiper
Current early command line parser implementation in assembler is very difficult to change to relocatable stuff using segment registers. This requires a lot of changes in very weird and fragile code. So, reimplement this functionality in C. This way code will be relocatable out of the box and much easier to maintain.
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Daniel Kiper <[email protected]>
I did not look at the str* functions that were added in but just at how the parameters parsing was done. Also at the assembler code and with that
.. snip..
xen/arch/x86/boot/cmdline.c line 2
Quoted 8 lines
xen/arch/x86/boot/cmdline.c new file +2
-0@@ -0,0 +1,396 @@ +/* +* Copyright (c) 2015 Oracle Co.
Oracle Corporation.
Re: [PATCH v2 21/23] x86/boot: implement early command line parser in C
In reply to Daniel KiperQuoted 30 lines
xen/arch/x86/boot/cmdline.c new file +30
-0+static void vga_parse (const char *cmdline,early_boot_opts_t *ebo) +{ +const char *c; +int tmp; +size_t la; + static const char empty_chars_comma[] __text = " \n\r\t,"; + static const char x[] __text = "x"; + static const char vga[] __text = "vga="; + static const char vga_current[] __text = "current"; + static const char vga_gfx[] __text = "gfx-"; + static const char vga_mode[] __text = "mode-"; + static const char vga_text_80x[] __text = "text-80x"; + + c =find_opt (cmdline, vga,1 ); + +if ( !c ) +return ; + + ebo->boot_vid_mode =ASK_VGA ; + + c +=strlen_static (vga); + la =strcspn (c, empty_chars_comma); + +if ( !strncmp (c, vga_current,max (la,strlen_static (vga_current))) ) + ebo->boot_vid_mode =VIDEO_CURRENT_MODE ; +else if ( !strncmp (c, vga_text_80x,strlen_static (vga_text_80x)) ) + { + c +=strlen_static (vga_text_80x); + ebo->boot_vid_mode =rows2vmode (strtoi (c, empty_chars_comma,NULL )); + }
xen/arch/x86/boot/cmdline.c line 363
Quoted 10 lines
xen/arch/x86/boot/cmdline.c new file +10
-0+else if ( !strncmp (c, vga_gfx,strlen_static (vga_gfx)) ) + { + tmp =strtoi (c +strlen_static (vga_gfx), x, &c); + +if ( tmp <0 || tmp >U16_MAX ) +return ; + + ebo->vesa_size[VESA_WIDTH ] = tmp; + + tmp =strtoi (++c, x, &c);
My ancient OL5 installation:
Choked on that with:
gcc -O1 -fno-omit-frame-pointer -m32 -march=i686 -g -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -fno-stack-protector -fno-exceptions -Werror -fno-builtin -msoft-float -c -fpic cmdline.c -o cmdline.o
cc1: warnings being treated as errorscmdline.c: In function ‘vga_parse’:
cmdline.c:363: warning: operation on ‘c’ may be undefined
Moving the ++c before the tmp assigment make the compiler happy.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH v2 21/23] x86/boot: implement early command line parser in C
In reply to Daniel KiperQuoted 30 lines
xen/arch/x86/boot/cmdline.c new file +30
-0+static void vga_parse (const char *cmdline,early_boot_opts_t *ebo) +{ +const char *c; +int tmp; +size_t la; + static const char empty_chars_comma[] __text = " \n\r\t,"; + static const char x[] __text = "x"; + static const char vga[] __text = "vga="; + static const char vga_current[] __text = "current"; + static const char vga_gfx[] __text = "gfx-"; + static const char vga_mode[] __text = "mode-"; + static const char vga_text_80x[] __text = "text-80x"; + + c =find_opt (cmdline, vga,1 ); + +if ( !c ) +return ; + + ebo->boot_vid_mode =ASK_VGA ; + + c +=strlen_static (vga); + la =strcspn (c, empty_chars_comma); + +if ( !strncmp (c, vga_current,max (la,strlen_static (vga_current))) ) + ebo->boot_vid_mode =VIDEO_CURRENT_MODE ; +else if ( !strncmp (c, vga_text_80x,strlen_static (vga_text_80x)) ) + { + c +=strlen_static (vga_text_80x); + ebo->boot_vid_mode =rows2vmode (strtoi (c, empty_chars_comma,NULL )); + }
xen/arch/x86/boot/cmdline.c line 363
Quoted 10 lines
xen/arch/x86/boot/cmdline.c new file +10
-0+else if ( !strncmp (c, vga_gfx,strlen_static (vga_gfx)) ) + { + tmp =strtoi (c +strlen_static (vga_gfx), x, &c); + +if ( tmp <0 || tmp >U16_MAX ) +return ; + + ebo->vesa_size[VESA_WIDTH ] = tmp; + + tmp =strtoi (++c, x, &c);
My ancient OL5 installation:
Choked on that with:
gcc -O1 -fno-omit-frame-pointer -m32 -march=i686 -g -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -fno-stack-protector -fno-exceptions -Werror -fno-builtin -msoft-float -c -fpic cmdline.c -o cmdline.o
cc1: warnings being treated as errorscmdline.c: In function ‘vga_parse’:
cmdline.c:363: warning: operation on ‘c’ may be undefined
Moving the ++c before the tmp assigment make the compiler happy.
Re: [PATCH v2 21/23] x86/boot: implement early command line parser in C
In reply to Daniel KiperQuoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
Current early command line parser implementation in assembler is very difficult to change to relocatable stuff using segment registers. This requires a lot of changes in very weird and fragile code. So, reimplement this functionality in C. This way code will be relocatable out of the box and much easier to maintain.
All appreciated and nice, but the goal of making the code relocatable by playing with segment registers sounds fragile:
This breaks assumptions the compiler may validly make.
Quoted 2 lines
xen/arch/x86/boot/cmdline.S | 367 ------------------------------------- xen/arch/x86/boot/cmdline.c | 396 ++++++++++++++++++++++++++++++++++++++++
A fundamental expectation I would have had is for the C file to be noticeably smaller than the assembly file.
xen/arch/x86/boot/cmdline.c line 43
Quoted 8 lines
xen/arch/x86/boot/cmdline.c new file +5
-0+#define VESA_WIDTH 0 +#define VESA_HEIGHT 1 +#define VESA_DEPTH 2 + +#define VESA_SIZE 3
These should go away in favor of using individual (sub)structure fields.
Quoted 1 line
+#define
__cdecl__attribute__((__cdecl__))
???
xen/arch/x86/boot/cmdline.c line 50
Quoted 3 lines
xen/arch/x86/boot/cmdline.c new file +3
-0+#define __packed __attribute__((__packed__)) +#define __text __attribute__((__section__(".text"))) +#define __used __attribute__((__used__))
Likely better to include compiler.h instead.
xen/arch/x86/boot/cmdline.c line 56
Quoted 5 lines
xen/arch/x86/boot/cmdline.c new file +5
-0+#define max (x,y) ({ \ + const typeof(x) _x = (x); \ + const typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x > _y ? _x : _y; })
I also wonder whether -imacros .../xen/kernel.h wouldn't be a better approach here. Please really think hard on how to avoid duplications like these.
Quoted 1 line
+#define
strlen_static(s)(sizeof(s) - 1)
What is this good for? A decent compiler should be able to deal with strlen("..."). Plus your macro is longer that what it tries to "abbreviate".
Quoted 1 line
+static const char empty_chars[]
__text= " \n\r\t";
What is empty about them? DYM blank or (white) space or separator or delimiter? I also wonder whether \n and \r are actually usefully here, as they should (if at all) only end the line.
xen/arch/x86/boot/cmdline.c line 85
Quoted 5 lines
xen/arch/x86/boot/cmdline.c new file +5
-0+/** +* strlen - Find the length of a string +* @s: The string to be sized +*/ +static size_t strlen (const char *s)
Comments are certainly nice, but in this special case I'd rather suggest against bloating the code by commenting standard library functions.
Quoted 28 lines
xen/arch/x86/boot/cmdline.c new file +28
-0+static int strtoi (const char *s,const char *stop,const char **next) +{ +int base =10 , i, ores =0 , res =0 ; + +if ( *s =='0' ) + base = (tolower (*++s) =='x' ) ? (++s,16 ) :8 ; + +for ( ; *s !='\0' ; ++s ) + { +for ( i =0 ; stop && stop[i] !='\0' ; ++i ) +if ( *s == stop[i] ) + goto out; + +if ( *s <'0' || (*s >'7' && base ==8 ) ) + { + res =-1 ; + goto out; + } + +if ( *s >'9' && (base !=16 ||tolower (*s) <'a' ||tolower (*s) >'f' ) ) + { + res =-1 ; + goto out; + } + + res *= base; + res += (tolower (*s) >='a' ) ? (tolower (*s) -'a' +10 ) : (*s -'0' ); +
xen/arch/x86/boot/cmdline.c line 202
Quoted 10 lines
xen/arch/x86/boot/cmdline.c new file +10
-0+if ( ores > res ) + { + res =-1 ; + goto out; + } + + ores = res; + } + +out:
C labels intended by at least one space please.
xen/arch/x86/boot/cmdline.c line 212
Quoted 4 lines
xen/arch/x86/boot/cmdline.c new file +4
-0+static const char *find_opt (const char *cmdline,const char *opt,int arg) +{ +size_t lc, lo; + static const char mm[] __text = "--";
I'd be surprised if there weren't compiler/assembler versions complaining about a section type conflict here. I can see why you want everything in one section, but I'd rather suggest achieving this at the linking step (which I would suppose to already be taking care of this).
xen/arch/x86/boot/cmdline.c line 243
Quoted 9 lines
xen/arch/x86/boot/cmdline.c new file +9
-0+static u8 skip_realmode (const char *cmdline) +{ + static const char nrm[] __text = "no-real-mode"; + static const char tboot[] __text = "tboot="; + +if (find_opt (cmdline, nrm,0 ) ||find_opt (cmdline, tboot,1 ) ) +return 1 ; + +return 0 ;
return find_opt(cmdline, nrm, 0) || find_opt(cmdline, tboot, 1);
Quoted 9 lines
xen/arch/x86/boot/cmdline.c new file +9
-0+static u8 edd_parse (const char *cmdline) +{ +const char *c; +size_t la; + static const char edd[] __text = "edd="; + static const char edd_off[] __text = "off"; + static const char edd_skipmbr[] __text = "skipmbr"; + + c =find_opt (cmdline, edd,1 );
xen/arch/x86/boot/cmdline.c line 264
Quoted 10 lines
xen/arch/x86/boot/cmdline.c new file +10
-0+ +if ( !c ) +return 0 ; + + c +=strlen_static (edd); + la =strcspn (c, empty_chars); + +if ( !strncmp (c, edd_off,max (la,strlen_static (edd_off))) ) +return 2 ; +else if ( !strncmp (c, edd_skipmbr,max (la,strlen_static (edd_skipmbr))) )
Pointless else.
xen/arch/x86/boot/cmdline.c line 243
Quoted 3 lines
xen/arch/x86/boot/cmdline.c new file +3
-0+return 1 ; + +return 0 ;
And the last two returns can be folded again anyway.
Quoted 1 line
+static void
__cdecl__usedcmdline_parse_early(const char *cmdline, early_boot_opts_t *ebo)
I don't see the point of the __cdecl, and (as said before) dislike the static __used pair.
xen/arch/x86/boot/head.S trampoline_setup: · line 433
Quoted 8 lines
xen/arch/x86/boot/head.S +2
-0@@ -429,8 +429,24 @@ trampoline_setup: cmp $sym_phys(__trampoline_seg_stop),%edi jb 1b + /* Do not parse command line on EFI platform here. */ + cmpb $1,sym_phys(skip_realmode)
Is there a reason you can't look at efi.flags instead here (and in the other case you abuse skip_realmode as meaning EFI)?
xen/arch/x86/boot/trampoline.S line 1
Quoted 4 lines
xen/arch/x86/boot/trampoline.S +1
-0@@ -1,3 +1,5 @@ +#include "video.h"
Please move this farther down, making invisible all its definitions to code not supposed to use them.
Jan
Re: [PATCH v2 21/23] x86/boot: implement early command line parser in C
In reply to Daniel KiperQuoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
Current early command line parser implementation in assembler is very difficult to change to relocatable stuff using segment registers. This requires a lot of changes in very weird and fragile code. So, reimplement this functionality in C. This way code will be relocatable out of the box and much easier to maintain.
All appreciated and nice, but the goal of making the code relocatable by playing with segment registers sounds fragile:
This breaks assumptions the compiler may validly make.
Quoted 2 lines
xen/arch/x86/boot/cmdline.S | 367 ------------------------------------- xen/arch/x86/boot/cmdline.c | 396 ++++++++++++++++++++++++++++++++++++++++
A fundamental expectation I would have had is for the C file to be noticeably smaller than the assembly file.
xen/arch/x86/boot/cmdline.c line 43
Quoted 8 lines
xen/arch/x86/boot/cmdline.c new file +5
-0+#define VESA_WIDTH 0 +#define VESA_HEIGHT 1 +#define VESA_DEPTH 2 + +#define VESA_SIZE 3
These should go away in favor of using individual (sub)structure fields.
Quoted 1 line
+#define
__cdecl__attribute__((__cdecl__))
???
xen/arch/x86/boot/cmdline.c line 50
Quoted 3 lines
xen/arch/x86/boot/cmdline.c new file +3
-0+#define __packed __attribute__((__packed__)) +#define __text __attribute__((__section__(".text"))) +#define __used __attribute__((__used__))
Likely better to include compiler.h instead.
xen/arch/x86/boot/cmdline.c line 56
Quoted 5 lines
xen/arch/x86/boot/cmdline.c new file +5
-0+#define max (x,y) ({ \ + const typeof(x) _x = (x); \ + const typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x > _y ? _x : _y; })
I also wonder whether -imacros .../xen/kernel.h wouldn't be a better approach here. Please really think hard on how to avoid duplications like these.
Quoted 1 line
+#define
strlen_static(s)(sizeof(s) - 1)
What is this good for? A decent compiler should be able to deal with strlen("..."). Plus your macro is longer that what it tries to "abbreviate".
Quoted 1 line
+static const char empty_chars[]
__text= " \n\r\t";
What is empty about them? DYM blank or (white) space or separator or delimiter? I also wonder whether \n and \r are actually usefully here, as they should (if at all) only end the line.
xen/arch/x86/boot/cmdline.c line 85
Quoted 5 lines
xen/arch/x86/boot/cmdline.c new file +5
-0+/** +* strlen - Find the length of a string +* @s: The string to be sized +*/ +static size_t strlen (const char *s)
Comments are certainly nice, but in this special case I'd rather suggest against bloating the code by commenting standard library functions.
Quoted 28 lines
xen/arch/x86/boot/cmdline.c new file +28
-0+static int strtoi (const char *s,const char *stop,const char **next) +{ +int base =10 , i, ores =0 , res =0 ; + +if ( *s =='0' ) + base = (tolower (*++s) =='x' ) ? (++s,16 ) :8 ; + +for ( ; *s !='\0' ; ++s ) + { +for ( i =0 ; stop && stop[i] !='\0' ; ++i ) +if ( *s == stop[i] ) + goto out; + +if ( *s <'0' || (*s >'7' && base ==8 ) ) + { + res =-1 ; + goto out; + } + +if ( *s >'9' && (base !=16 ||tolower (*s) <'a' ||tolower (*s) >'f' ) ) + { + res =-1 ; + goto out; + } + + res *= base; + res += (tolower (*s) >='a' ) ? (tolower (*s) -'a' +10 ) : (*s -'0' ); +
xen/arch/x86/boot/cmdline.c line 202
Quoted 10 lines
xen/arch/x86/boot/cmdline.c new file +10
-0+if ( ores > res ) + { + res =-1 ; + goto out; + } + + ores = res; + } + +out:
C labels intended by at least one space please.
xen/arch/x86/boot/cmdline.c line 212
Quoted 4 lines
xen/arch/x86/boot/cmdline.c new file +4
-0+static const char *find_opt (const char *cmdline,const char *opt,int arg) +{ +size_t lc, lo; + static const char mm[] __text = "--";
I'd be surprised if there weren't compiler/assembler versions complaining about a section type conflict here. I can see why you want everything in one section, but I'd rather suggest achieving this at the linking step (which I would suppose to already be taking care of this).
xen/arch/x86/boot/cmdline.c line 243
Quoted 9 lines
xen/arch/x86/boot/cmdline.c new file +9
-0+static u8 skip_realmode (const char *cmdline) +{ + static const char nrm[] __text = "no-real-mode"; + static const char tboot[] __text = "tboot="; + +if (find_opt (cmdline, nrm,0 ) ||find_opt (cmdline, tboot,1 ) ) +return 1 ; + +return 0 ;
return find_opt(cmdline, nrm, 0) || find_opt(cmdline, tboot, 1);
Quoted 9 lines
xen/arch/x86/boot/cmdline.c new file +9
-0+static u8 edd_parse (const char *cmdline) +{ +const char *c; +size_t la; + static const char edd[] __text = "edd="; + static const char edd_off[] __text = "off"; + static const char edd_skipmbr[] __text = "skipmbr"; + + c =find_opt (cmdline, edd,1 );
xen/arch/x86/boot/cmdline.c line 264
Quoted 10 lines
xen/arch/x86/boot/cmdline.c new file +10
-0+ +if ( !c ) +return 0 ; + + c +=strlen_static (edd); + la =strcspn (c, empty_chars); + +if ( !strncmp (c, edd_off,max (la,strlen_static (edd_off))) ) +return 2 ; +else if ( !strncmp (c, edd_skipmbr,max (la,strlen_static (edd_skipmbr))) )
Pointless else.
xen/arch/x86/boot/cmdline.c line 243
Quoted 3 lines
xen/arch/x86/boot/cmdline.c new file +3
-0+return 1 ; + +return 0 ;
And the last two returns can be folded again anyway.
Quoted 1 line
+static void
__cdecl__usedcmdline_parse_early(const char *cmdline, early_boot_opts_t *ebo)
I don't see the point of the __cdecl, and (as said before) dislike the static __used pair.
xen/arch/x86/boot/head.S trampoline_setup: · line 433
Quoted 8 lines
xen/arch/x86/boot/head.S +2
-0@@ -429,8 +429,24 @@ trampoline_setup: cmp $sym_phys(__trampoline_seg_stop),%edi jb 1b + /* Do not parse command line on EFI platform here. */ + cmpb $1,sym_phys(skip_realmode)
Is there a reason you can't look at efi.flags instead here (and in the other case you abuse skip_realmode as meaning EFI)?
xen/arch/x86/boot/trampoline.S line 1
Quoted 4 lines
xen/arch/x86/boot/trampoline.S +1
-0@@ -1,3 +1,5 @@ +#include "video.h"
Please move this farther down, making invisible all its definitions to code not supposed to use them.
Jan
Re: [PATCH v2 21/23] x86/boot: implement early command line parser in C
Quoted 11 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
Current early command line parser implementation in assembler is very difficult to change to relocatable stuff using segment registers. This requires a lot of changes in very weird and fragile code. So, reimplement this functionality in C. This way code will be relocatable out of the box and much easier to maintain.
All appreciated and nice, but the goal of making the code relocatable by playing with segment registers sounds fragile:
This breaks assumptions the compiler may validly make.
Well, it looks that this sentence is not precise. I should fix this. Anyway, I am not playing with segment registers in C code because it is not needed and as you pointed out it is dangerous.
Quoted 17 lines
Quoted 2 lines
xen/arch/x86/boot/cmdline.S | 367 ------------------------------------- xen/arch/x86/boot/cmdline.c | 396 ++++++++++++++++++++++++++++++++++++++++A fundamental expectation I would have had is for the C file to be noticeably smaller than the assembly file.
xen/arch/x86/boot/cmdline.c line 43
Quoted 8 lines
xen/arch/x86/boot/cmdline.c new file +5
-0+#define VESA_WIDTH 0 +#define VESA_HEIGHT 1 +#define VESA_DEPTH 2 + +#define VESA_SIZE 3These should go away in favor of using individual (sub)structure fields.
Quoted 3 lines
Quoted 1 line
+#define
__cdecl__attribute__((__cdecl__))???
Please look below.
Quoted 5 lines
xen/arch/x86/boot/cmdline.c line 50
Quoted 3 lines
xen/arch/x86/boot/cmdline.c new file +3
-0+#define __packed __attribute__((__packed__)) +#define __text __attribute__((__section__(".text"))) +#define __used __attribute__((__used__))Likely better to include
compiler.hinstead.
As I know you do not like to include such headers in early C files because it makes code fragile and it looks strange. I agree with you to some extent. So, I decided to define needed constants ourselves. Whatever we do we should be consistent. Hence, if we include compiler.h here we should do the same in reloc.c too if it is required.
Quoted 9 lines
xen/arch/x86/boot/cmdline.c line 56
Quoted 5 lines
xen/arch/x86/boot/cmdline.c new file +5
-0+#define max (x,y) ({ \ + const typeof(x) _x = (x); \ + const typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x > _y ? _x : _y; })I also wonder whether -imacros
.../xen/kernel.hwouldn't be a better approach here. Please really think hard on how to avoid duplications like these.
Ditto. So, what is your decision? Include or define? If include then we should think how to generate relevant dependencies automatically.
Quoted 4 lines
Quoted 1 line
+#define
strlen_static(s)(sizeof(s) - 1)What is this good for? A decent compiler should be able to deal with
strlen("..."). Plus your macro is longer that what it tries to "abbreviate".
I thought that it is true but it is not. Sadly, without this binary is bigger... :-((( However, you are right that the name could be better.
Quoted 4 lines
Quoted 1 line
+static const char empty_chars[]
__text= " \n\r\t";What is empty about them? DYM blank or (white) space or separator or delimiter? I also wonder whether \n and \r are actually usefully here,
Yep, delimiter or something like that looks better.
Quoted 1 line
as they should (if at all) only end the line.
Yes, I included them just in case and they should not appear in command line.
Quoted 10 lines
xen/arch/x86/boot/cmdline.c line 212
Quoted 4 lines
xen/arch/x86/boot/cmdline.c new file +4
-0+static const char *find_opt (const char *cmdline,const char *opt,int arg) +{ +size_t lc, lo; + static const char mm[] __text = "--";I'd be surprised if there weren't compiler/assembler versions complaining about a section type conflict here. I can see why you want everything in one section, but I'd rather suggest achieving this at the linking step (which I would suppose to already be taking care of this).
Nope, it does not work in that way. However, I discovered that newer GCC versions generate .rodata for switch/case. So, anyway we must cope with at least two different sections and link them properly.
Quoted 38 lines
xen/arch/x86/boot/cmdline.c line 243
Quoted 9 lines
xen/arch/x86/boot/cmdline.c new file +9
-0+static u8 skip_realmode (const char *cmdline) +{ + static const char nrm[] __text = "no-real-mode"; + static const char tboot[] __text = "tboot="; + +if (find_opt (cmdline, nrm,0 ) ||find_opt (cmdline, tboot,1 ) ) +return 1 ; + +return 0 ;return
find_opt(cmdline, nrm, 0)||find_opt(cmdline, tboot, 1);Quoted 9 lines
xen/arch/x86/boot/cmdline.c new file +9
-0+static u8 edd_parse (const char *cmdline) +{ +const char *c; +size_t la; + static const char edd[] __text = "edd="; + static const char edd_off[] __text = "off"; + static const char edd_skipmbr[] __text = "skipmbr"; + + c =find_opt (cmdline, edd,1 );xen/arch/x86/boot/cmdline.c line 264
Quoted 10 lines
xen/arch/x86/boot/cmdline.c new file +10
-0+ +if ( !c ) +return 0 ; + + c +=strlen_static (edd); + la =strcspn (c, empty_chars); + +if ( !strncmp (c, edd_off,max (la,strlen_static (edd_off))) ) +return 2 ; +else if ( !strncmp (c, edd_skipmbr,max (la,strlen_static (edd_skipmbr))) )Pointless else.
xen/arch/x86/boot/cmdline.c line 243
Quoted 3 lines
xen/arch/x86/boot/cmdline.c new file +3
-0+return 1 ; + +return 0 ;
Quoted 6 lines
And the last two returns can be folded again anyway.
Quoted 1 line
+static void
__cdecl__usedcmdline_parse_early(const char *cmdline, early_boot_opts_t *ebo)I don't see the point of the
__cdecl, and (as said before) dislike the static__usedpair.
Are you sure that without __cdecl compiler will not try to optimize cmdline_parse_early() call and try to pass arguments using registers or anything else not conforming to cdecl calling convention? Right now I am not sure about that. However, I suppose that if we remove static then there is a chance that function will be always called according to cdecl (I must check this). Anyway, I think that we should retain (even add in case of reloc.c:reloc(), others?) __cdecl before 32-bit functions which are called from assembly. Just in case.
Daniel
Re: [PATCH v2 21/23] x86/boot: implement early command line parser in C
In reply to Jan BeulichQuoted 11 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
Current early command line parser implementation in assembler is very difficult to change to relocatable stuff using segment registers. This requires a lot of changes in very weird and fragile code. So, reimplement this functionality in C. This way code will be relocatable out of the box and much easier to maintain.
All appreciated and nice, but the goal of making the code relocatable by playing with segment registers sounds fragile:
This breaks assumptions the compiler may validly make.
Well, it looks that this sentence is not precise. I should fix this. Anyway, I am not playing with segment registers in C code because it is not needed and as you pointed out it is dangerous.
Quoted 17 lines
Quoted 2 lines
xen/arch/x86/boot/cmdline.S | 367 ------------------------------------- xen/arch/x86/boot/cmdline.c | 396 ++++++++++++++++++++++++++++++++++++++++A fundamental expectation I would have had is for the C file to be noticeably smaller than the assembly file.
xen/arch/x86/boot/cmdline.c line 43
Quoted 8 lines
xen/arch/x86/boot/cmdline.c new file +5
-0+#define VESA_WIDTH 0 +#define VESA_HEIGHT 1 +#define VESA_DEPTH 2 + +#define VESA_SIZE 3These should go away in favor of using individual (sub)structure fields.
Quoted 3 lines
Quoted 1 line
+#define
__cdecl__attribute__((__cdecl__))???
Please look below.
Quoted 5 lines
xen/arch/x86/boot/cmdline.c line 50
Quoted 3 lines
xen/arch/x86/boot/cmdline.c new file +3
-0+#define __packed __attribute__((__packed__)) +#define __text __attribute__((__section__(".text"))) +#define __used __attribute__((__used__))Likely better to include
compiler.hinstead.
As I know you do not like to include such headers in early C files because it makes code fragile and it looks strange. I agree with you to some extent. So, I decided to define needed constants ourselves. Whatever we do we should be consistent. Hence, if we include compiler.h here we should do the same in reloc.c too if it is required.
Quoted 9 lines
xen/arch/x86/boot/cmdline.c line 56
Quoted 5 lines
xen/arch/x86/boot/cmdline.c new file +5
-0+#define max (x,y) ({ \ + const typeof(x) _x = (x); \ + const typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x > _y ? _x : _y; })I also wonder whether -imacros
.../xen/kernel.hwouldn't be a better approach here. Please really think hard on how to avoid duplications like these.
Ditto. So, what is your decision? Include or define? If include then we should think how to generate relevant dependencies automatically.
Quoted 4 lines
Quoted 1 line
+#define
strlen_static(s)(sizeof(s) - 1)What is this good for? A decent compiler should be able to deal with
strlen("..."). Plus your macro is longer that what it tries to "abbreviate".
I thought that it is true but it is not. Sadly, without this binary is bigger... :-((( However, you are right that the name could be better.
Quoted 4 lines
Quoted 1 line
+static const char empty_chars[]
__text= " \n\r\t";What is empty about them? DYM blank or (white) space or separator or delimiter? I also wonder whether \n and \r are actually usefully here,
Yep, delimiter or something like that looks better.
Quoted 1 line
as they should (if at all) only end the line.
Yes, I included them just in case and they should not appear in command line.
Quoted 10 lines
xen/arch/x86/boot/cmdline.c line 212
Quoted 4 lines
xen/arch/x86/boot/cmdline.c new file +4
-0+static const char *find_opt (const char *cmdline,const char *opt,int arg) +{ +size_t lc, lo; + static const char mm[] __text = "--";I'd be surprised if there weren't compiler/assembler versions complaining about a section type conflict here. I can see why you want everything in one section, but I'd rather suggest achieving this at the linking step (which I would suppose to already be taking care of this).
Nope, it does not work in that way. However, I discovered that newer GCC versions generate .rodata for switch/case. So, anyway we must cope with at least two different sections and link them properly.
Quoted 38 lines
xen/arch/x86/boot/cmdline.c line 243
Quoted 9 lines
xen/arch/x86/boot/cmdline.c new file +9
-0+static u8 skip_realmode (const char *cmdline) +{ + static const char nrm[] __text = "no-real-mode"; + static const char tboot[] __text = "tboot="; + +if (find_opt (cmdline, nrm,0 ) ||find_opt (cmdline, tboot,1 ) ) +return 1 ; + +return 0 ;return
find_opt(cmdline, nrm, 0)||find_opt(cmdline, tboot, 1);Quoted 9 lines
xen/arch/x86/boot/cmdline.c new file +9
-0+static u8 edd_parse (const char *cmdline) +{ +const char *c; +size_t la; + static const char edd[] __text = "edd="; + static const char edd_off[] __text = "off"; + static const char edd_skipmbr[] __text = "skipmbr"; + + c =find_opt (cmdline, edd,1 );xen/arch/x86/boot/cmdline.c line 264
Quoted 10 lines
xen/arch/x86/boot/cmdline.c new file +10
-0+ +if ( !c ) +return 0 ; + + c +=strlen_static (edd); + la =strcspn (c, empty_chars); + +if ( !strncmp (c, edd_off,max (la,strlen_static (edd_off))) ) +return 2 ; +else if ( !strncmp (c, edd_skipmbr,max (la,strlen_static (edd_skipmbr))) )Pointless else.
xen/arch/x86/boot/cmdline.c line 243
Quoted 3 lines
xen/arch/x86/boot/cmdline.c new file +3
-0+return 1 ; + +return 0 ;
Quoted 6 lines
And the last two returns can be folded again anyway.
Quoted 1 line
+static void
__cdecl__usedcmdline_parse_early(const char *cmdline, early_boot_opts_t *ebo)I don't see the point of the
__cdecl, and (as said before) dislike the static__usedpair.
Are you sure that without __cdecl compiler will not try to optimize cmdline_parse_early() call and try to pass arguments using registers or anything else not conforming to cdecl calling convention? Right now I am not sure about that. However, I suppose that if we remove static then there is a chance that function will be always called according to cdecl (I must check this). Anyway, I think that we should retain (even add in case of reloc.c:reloc(), others?) __cdecl before 32-bit functions which are called from assembly. Just in case.
Daniel
Re: [PATCH v2 21/23] x86/boot: implement early command line parser in C
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 22.09.15 at 19:03, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
xen/arch/x86/boot/cmdline.c line 50
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
xen/arch/x86/boot/cmdline.c new file +3
-0+#define __packed __attribute__((__packed__)) +#define __text __attribute__((__section__(".text"))) +#define __used __attribute__((__used__))Likely better to include
compiler.hinstead.
Quoted 5 lines
As I know you do not like to include such headers in early C files because it makes code fragile and it looks strange. I agree with you to some extent. So, I decided to define needed constants ourselves. Whatever we do we should be consistent. Hence, if we include
compiler.hhere we should do the same inreloc.ctoo if it is required.
I disagree - reloc.c serves a completely different purpose, and hence may have different considerations applied when it comes to what to (not) include.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
xen/arch/x86/boot/cmdline.c new file +5
-0+#define max (x,y) ({ \ + const typeof(x) _x = (x); \ + const typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x > _y ? _x : _y; })
Quoted 6 lines
Quoted 3 lines
I also wonder whether -imacros
.../xen/kernel.hwouldn't be a better approach here. Please really think hard on how to avoid duplications like these.Ditto. So, what is your decision? Include or define? If include then we should think how to generate relevant dependencies automatically.
I think the question should rather be whether we can't make cmdline.c build the normal way, not the reloc.c one.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+#define
strlen_static(s)(sizeof(s) - 1)What is this good for? A decent compiler should be able to deal with
strlen("..."). Plus your macro is longer that what it tries to "abbreviate".I thought that it is true but it is not. Sadly, without this binary is bigger... :-(((
Perhaps as a result of some (missing) option(s)?
Quoted 1 line
However, you are right that the name could be better.
Or just drop the macro.
Quoted 11 lines
Quoted 4 lines
Quoted 1 line
+static const char empty_chars[]
__text= " \n\r\t";What is empty about them? DYM blank or (white) space or separator or delimiter? I also wonder whether \n and \r are actually usefully here,
Yep, delimiter or something like that looks better.
Quoted 1 line
as they should (if at all) only end the line.
Yes, I included them just in case and they should not appear in command line.
If you mean to retain characters in that array that aren't obviously needed, please explain such in a comment so people won't have to guess whether to delete them, or will know it is (relatively) safe to delete them in case their presence causes problems. But even better would be to just have the obvious blank characters (space and tab) there.
Quoted 9 lines
Quoted 1 line
Quoted 1 line
+static void
__cdecl__usedcmdline_parse_early(const char *cmdline,
early_boot_opts_t*ebo)Quoted 3 lines
I don't see the point of the
__cdecl, and (as said before) dislike the static__usedpair.Are you sure that without
__cdeclcompiler will not try to optimizecmdline_parse_early()call and try to pass arguments using registers or anything else not conforming to cdecl calling convention?
Yes, I am - the moment you drop the "static". At that point the compiler has no choice, unless it is being told on the command line to use a different calling convention
Jan
Re: [PATCH v2 21/23] x86/boot: implement early command line parser in C
In reply to Daniel KiperQuoted 9 lines
Quoted 1 line
Quoted 1 line · On 22.09.15 at 19:03, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
xen/arch/x86/boot/cmdline.c line 50
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
xen/arch/x86/boot/cmdline.c new file +3
-0+#define __packed __attribute__((__packed__)) +#define __text __attribute__((__section__(".text"))) +#define __used __attribute__((__used__))Likely better to include
compiler.hinstead.
Quoted 5 lines
As I know you do not like to include such headers in early C files because it makes code fragile and it looks strange. I agree with you to some extent. So, I decided to define needed constants ourselves. Whatever we do we should be consistent. Hence, if we include
compiler.hhere we should do the same inreloc.ctoo if it is required.
I disagree - reloc.c serves a completely different purpose, and hence may have different considerations applied when it comes to what to (not) include.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
xen/arch/x86/boot/cmdline.c new file +5
-0+#define max (x,y) ({ \ + const typeof(x) _x = (x); \ + const typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x > _y ? _x : _y; })
Quoted 6 lines
Quoted 3 lines
I also wonder whether -imacros
.../xen/kernel.hwouldn't be a better approach here. Please really think hard on how to avoid duplications like these.Ditto. So, what is your decision? Include or define? If include then we should think how to generate relevant dependencies automatically.
I think the question should rather be whether we can't make cmdline.c build the normal way, not the reloc.c one.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+#define
strlen_static(s)(sizeof(s) - 1)What is this good for? A decent compiler should be able to deal with
strlen("..."). Plus your macro is longer that what it tries to "abbreviate".I thought that it is true but it is not. Sadly, without this binary is bigger... :-(((
Perhaps as a result of some (missing) option(s)?
Quoted 1 line
However, you are right that the name could be better.
Or just drop the macro.
Quoted 11 lines
Quoted 4 lines
Quoted 1 line
+static const char empty_chars[]
__text= " \n\r\t";What is empty about them? DYM blank or (white) space or separator or delimiter? I also wonder whether \n and \r are actually usefully here,
Yep, delimiter or something like that looks better.
Quoted 1 line
as they should (if at all) only end the line.
Yes, I included them just in case and they should not appear in command line.
If you mean to retain characters in that array that aren't obviously needed, please explain such in a comment so people won't have to guess whether to delete them, or will know it is (relatively) safe to delete them in case their presence causes problems. But even better would be to just have the obvious blank characters (space and tab) there.
Quoted 9 lines
Quoted 1 line
Quoted 1 line
+static void
__cdecl__usedcmdline_parse_early(const char *cmdline,
early_boot_opts_t*ebo)Quoted 3 lines
I don't see the point of the
__cdecl, and (as said before) dislike the static__usedpair.Are you sure that without
__cdeclcompiler will not try to optimizecmdline_parse_early()call and try to pass arguments using registers or anything else not conforming to cdecl calling convention?
Yes, I am - the moment you drop the "static". At that point the compiler has no choice, unless it is being told on the command line to use a different calling convention
Jan
PATCH v2 22/23 x86: make Xen early boot code relocatable
In reply to Daniel KiperEvery multiboot protocol (regardless of version) compatible image must specify its load address (in ELF or multiboot header). Multiboot protocol compatible loader have to load image at specified address. However, there is no guarantee that the requested memory region (in case of Xen it starts at 1 MiB and ends at 17 MiB) where image should be loaded initially is a RAM and it is free (legacy BIOS platforms are merciful for Xen but I found at least one EFI platform on which Xen load address conflicts with EFI boot services; it is Dell PowerEdge R820 with latest firmware). To cope with that problem we must make Xen early boot code relocatable. This patch does that. However, it does not add multiboot2 protocol interface which is done in next patch.
This patch changes following things:
- default load address is changed from 1 MiB to 2 MiB; I did that because initial page tables are using 2 MiB huge pages and this way required updates for them are quite easy; it means that e.g. we avoid spacial cases for beginning and end of required memory region if it live at address not aligned to 2 MiB,
- %ebp register is used as a storage for Xen image base address; this way we can get this value very quickly if it is needed; however, %ebp register is not used directly to access a given memory region,
- %fs register is filled with segment descriptor which describes memory region with Xen image (it could be relocated or not); it is used to access some of Xen data in early boot code; potentially we can use above mentioned segment descriptor to access data using %ds:%esi and/or %es:%esi (e.g. movs*); however, I think that it could unnecessarily obfuscate code (e.g. we need at least to operations to reload a given segment descriptor) and current solution looks quite optimal.
--- xen/arch/x86/Makefile | 6 +- xen/arch/x86/Rules.mk | 4 + xen/arch/x86/boot/head.S | 165 ++++++++++++++++++++++++++++++---------- xen/arch/x86/boot/trampoline.S | 11 ++- xen/arch/x86/boot/wakeup.S | 6 +- xen/arch/x86/boot/x86_64.S | 34 ++++----- xen/arch/x86/setup.c | 33 ++++---- xen/arch/x86/x86_64/mm.c | 2 +- xen/arch/x86/xen.lds.S | 2 +- xen/include/asm-x86/config.h | 3 + xen/include/asm-x86/page.h | 2 +- 11 files changed, 182 insertions(+), 86 deletions(-)
xen/arch/x86/Makefile +4 -2
@@ -72,8 +72,10 @@ efi-$(x86_64) := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ echo '$(TARGET).efi'; fi) $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32 - ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ - `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` +# THIS IS UGLY HACK! PLEASE DO NOT COMPLAIN. I WILL FIX IT IN NEXT RELEASE. + ./boot/mkelf32 $(TARGET)-syms $(TARGET) $(XEN_IMG_PHYS_START) 0xffff82d081000000 +# ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ +# `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
xen/arch/x86/Rules.mk +4 -0
@@ -15,6 +15,10 @@ HAS_GDBSX := y HAS_PDX := y xenoprof := y +XEN_IMG_PHYS_START = 0x200000 + +CFLAGS += -DXEN_IMG_PHYS_START=$(XEN_IMG_PHYS_START) + CFLAGS += -I$(BASEDIR)/include CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-generic CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-default
xen/arch/x86/boot/head.S +123 -42
307 lines not on this page · raw message
xen/arch/x86/boot/trampoline.S +10 -1
@@ -52,12 +52,20 @@ trampoline_gdt: /* 0x0028: real-mode data @ BOOT_TRAMPOLINE */ .long 0x0000ffff .long 0x00009200 + /* + * 0x0030: ring 0 Xen data, 16 MiB size, base + * address is initialized during runtime. + */ + .quad 0x00c0920000001000 .pushsection .trampoline_rel, "a" .long trampoline_gdt + BOOT_PSEUDORM_CS + 2 - . .long trampoline_gdt + BOOT_PSEUDORM_DS + 2 - . .popsection +GLOBAL(xen_img_base_phys_addr) + .long 0 + GLOBAL(cpuid_ext_features) .long 0
@@ -82,7 +90,8 @@ trampoline_protmode_entry: mov %ecx,%cr4 /* Load pagetable base register. */ - mov $sym_phys(idle_pg_table),%eax + mov bootsym_rel(xen_img_base_phys_addr,4,%eax) + lea sym_offset(idle_pg_table)(%eax),%eax add bootsym_rel(trampoline_xen_phys_start,4,%eax) mov %eax,%cr3
xen/arch/x86/boot/wakeup.S +4 -2
@@ -119,8 +119,10 @@ wakeup_32: mov %eax, %ss mov $bootsym_rel(wakeup_stack, 4, %esp) + mov bootsym_rel(xen_img_base_phys_addr, 4, %ebx) + # check saved magic again - mov $sym_phys(saved_magic), %eax + lea sym_offset(saved_magic)(%ebx), %eax add bootsym_rel(trampoline_xen_phys_start, 4, %eax) mov (%eax), %eax cmp $0x9abcdef0, %eax
@@ -133,7 +135,7 @@ wakeup_32: mov %ecx, %cr4 /* Load pagetable base register */ - mov $sym_phys(idle_pg_table),%eax + lea sym_offset(idle_pg_table)(%ebx),%eax add bootsym_rel(trampoline_xen_phys_start,4,%eax) mov %eax,%cr3
xen/arch/x86/boot/x86_64.S +15 -19
@@ -81,7 +81,6 @@ GLOBAL(boot_cpu_compat_gdt_table) .quad 0x0000910000000000 /* per-CPU entry (limit == cpu) */ .align PAGE_SIZE, 0 -GLOBAL(__page_tables_start) /* * Mapping of first 2 megabytes of memory. This is mapped with 4kB mappings * to avoid type conflicts with fixed-range MTRRs covering the lowest megabyte
@@ -101,21 +100,18 @@ GLOBAL(l1_identmap) .endr .size l1_identmap, . - l1_identmap -/* Mapping of first 16 megabytes of memory. */ +GLOBAL(__page_tables_start) + GLOBAL(l2_identmap) - .quad sym_phys(l1_identmap) + __PAGE_HYPERVISOR - pfn = 0 - .rept 7 - pfn = pfn + (1 << PAGETABLE_ORDER) - .quad (pfn << PAGE_SHIFT) | PAGE_HYPERVISOR | _PAGE_PSE - .endr - .fill 4 * L2_PAGETABLE_ENTRIES - 8, 8, 0 + .quad sym_offset(l1_identmap) + __PAGE_HYPERVISOR + .fill 4 * L2_PAGETABLE_ENTRIES - 1, 8, 0 .size l2_identmap, . - l2_identmap GLOBAL(l2_xenmap) - idx = 0 - .rept 8 - .quad sym_phys(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE) + .quad 0 + idx = 1 + .rept 7 + .quad sym_offset(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE) idx = idx + 1 .endr .fill L2_PAGETABLE_ENTRIES - 8, 8, 0
@@ -125,7 +121,7 @@ l2_fixmap: idx = 0 .rept L2_PAGETABLE_ENTRIES .if idx == l2_table_offset(FIXADDR_TOP - 1) - .quad sym_phys(l1_fixmap) + __PAGE_HYPERVISOR + .quad sym_offset(l1_fixmap) + __PAGE_HYPERVISOR .else .quad 0 .endif
@@ -136,7 +132,7 @@ l2_fixmap: GLOBAL(l3_identmap) idx = 0 .rept 4 - .quad sym_phys(l2_identmap) + (idx << PAGE_SHIFT) + __PAGE_HYPERVISOR + .quad sym_offset(l2_identmap) + (idx << PAGE_SHIFT) + __PAGE_HYPERVISOR idx = idx + 1 .endr .fill L3_PAGETABLE_ENTRIES - 4, 8, 0
@@ -146,9 +142,9 @@ l3_xenmap: idx = 0 .rept L3_PAGETABLE_ENTRIES .if idx == l3_table_offset(XEN_VIRT_START) - .quad sym_phys(l2_xenmap) + __PAGE_HYPERVISOR + .quad sym_offset(l2_xenmap) + __PAGE_HYPERVISOR .elseif idx == l3_table_offset(FIXADDR_TOP - 1) - .quad sym_phys(l2_fixmap) + __PAGE_HYPERVISOR + .quad sym_offset(l2_fixmap) + __PAGE_HYPERVISOR .else .quad 0 .endif
@@ -158,13 +154,13 @@ l3_xenmap: /* Top-level master (and idle-domain) page directory. */ GLOBAL(idle_pg_table) - .quad sym_phys(l3_bootmap) + __PAGE_HYPERVISOR + .quad sym_offset(l3_bootmap) + __PAGE_HYPERVISOR idx = 1 .rept L4_PAGETABLE_ENTRIES - 1 .if idx == l4_table_offset(DIRECTMAP_VIRT_START) - .quad sym_phys(l3_identmap) + __PAGE_HYPERVISOR + .quad sym_offset(l3_identmap) + __PAGE_HYPERVISOR .elseif idx == l4_table_offset(XEN_VIRT_START) - .quad sym_phys(l3_xenmap) + __PAGE_HYPERVISOR + .quad sym_offset(l3_xenmap) + __PAGE_HYPERVISOR .else .quad 0 .endif
xen/arch/x86/setup.c +16 -17
@@ -291,9 +291,6 @@ static void *__init bootstrap_map(const module_t *mod)if ( start >= end )return NULL ; -if ( end <=BOOTSTRAP_MAP_BASE ) -return (void *)(unsigned long )start; - ret = (void *)(map_cur + (unsigned long )(start & mask)); start &= ~mask; end = (end + mask) & ~mask;
@@ -641,6 +638,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)printk ("Command line: %s\n" , cmdline); +printk ("Xen image base address: 0x%08lx\n" , + xen_phys_start ? xen_phys_start : (unsigned long )xen_img_base_phys_addr); +printk ("Video information:\n" );/* Print VGA display mode information. */
@@ -835,10 +835,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)uint64_t s, e, mask = (1UL <<L2_PAGETABLE_SHIFT ) -1 ;uint64_t end, limit =ARRAY_SIZE (l2_identmap) <<L2_PAGETABLE_SHIFT ; -/* Superpage-aligned chunks from BOOTSTRAP_MAP_BASE. */ s = (boot_e820.map[i].addr + mask) & ~mask; e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask; - s =max_t (uint64_t, s,BOOTSTRAP_MAP_BASE );if ( (boot_e820.map[i].type !=E820_RAM ) || (s >= e) )continue ;
@@ -876,7 +874,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)/* Select relocation address. */ e = end - reloc_size; xen_phys_start = e; -bootsym (trampoline_xen_phys_start) = e; +bootsym (trampoline_xen_phys_start) = e - xen_img_base_phys_addr;/* * Perform relocation to new physical address.
@@ -886,7 +884,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)*/ load_start = (unsigned long )_start -XEN_VIRT_START ;barrier (); -move_memory (e + load_start, load_start, _end - _start,1 ); +move_memory (e + load_start, load_start + xen_img_base_phys_addr, _end - _start,1 );/* Walk initial pagetables, relocating page directory entries. */ pl4e =__va (__pa (idle_pg_table));
@@ -895,27 +893,27 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( !(l4e_get_flags (*pl4e) & _PAGE_PRESENT) )continue ; *pl4e =l4e_from_intpte (l4e_get_intpte (*pl4e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); pl3e =l4e_to_l3e (*pl4e);for ( j =0 ; j <L3_PAGETABLE_ENTRIES ; j++, pl3e++ ) {/* Not present, 1GB mapping, or already relocated? */ if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) || (l3e_get_flags (*pl3e) & _PAGE_PSE) || - (l3e_get_pfn (*pl3e) >0x1000 ) ) + (l3e_get_pfn (*pl3e) >PFN_DOWN (xen_phys_start)) )continue ; *pl3e =l3e_from_intpte (l3e_get_intpte (*pl3e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); pl2e =l3e_to_l2e (*pl3e);for ( k =0 ; k <L2_PAGETABLE_ENTRIES ; k++, pl2e++ ) {/* Not present, PSE, or already relocated? */ if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) || (l2e_get_flags (*pl2e) & _PAGE_PSE) || - (l2e_get_pfn (*pl2e) >0x1000 ) ) + (l2e_get_pfn (*pl2e) >PFN_DOWN (xen_phys_start)) )continue ; *pl2e =l2e_from_intpte (l2e_get_intpte (*pl2e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); } } }
@@ -926,10 +924,10 @@ void __init noreturn __start_xen(unsigned long mbi_p) PAGE_HYPERVISOR_RWX | _PAGE_PSE);for ( i =1 ; i <L2_PAGETABLE_ENTRIES ; i++, pl2e++ ) { -if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) +if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) || (l2e_get_pfn (*pl2e) >PFN_DOWN (xen_phys_start)))continue ; *pl2e =l2e_from_intpte (l2e_get_intpte (*pl2e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); }/* Re-sync the stack and then switch to relocated pagetables. */
@@ -998,6 +996,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( !xen_phys_start )panic ("Not enough memory to relocate Xen." ); + +printk ("New Xen image base address: 0x%08lx\n" , xen_phys_start); +reserve_e820_ram (&boot_e820,__pa (&_start),__pa (&_end));/* Late kexec reservation (dynamic start address). */
@@ -1070,14 +1071,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)set_pdx_range (s >>PAGE_SHIFT , e >>PAGE_SHIFT ); -/* Need to create mappings above BOOTSTRAP_MAP_BASE. */ - map_s =max_t (uint64_t, s,BOOTSTRAP_MAP_BASE ); + map_s = s; map_e =min_t (uint64_t, e,ARRAY_SIZE (l2_identmap) <<L2_PAGETABLE_SHIFT );/* Pass mapped memory to allocator /before/ creating new mappings. */ init_boot_pages (s,min (map_s, e)); - s = map_s;if ( s < map_e ) {uint64_t mask = (1UL <<L2_PAGETABLE_SHIFT ) -1 ;
xen/arch/x86/x86_64/mm.c +1 -1
@@ -44,7 +44,7 @@ unsigned int __read_mostly m2p_compat_vstart = __HYPERVISOR_COMPAT_VIRT_START;/* Enough page directories to map into the bottom 1GB. */ l3_pgentry_t __section(".bss.page_aligned") l3_bootmap[L3_PAGETABLE_ENTRIES]; -l2_pgentry_t __section(".bss.page_aligned") l2_bootmap[L2_PAGETABLE_ENTRIES]; +l2_pgentry_t __section(".bss.page_aligned") l2_bootmap[4 * L2_PAGETABLE_ENTRIES];l2_pgentry_t *compat_idle_pg_table_l2;
xen/arch/x86/xen.lds.S +1 -1
@@ -38,7 +38,7 @@ SECTIONS . = __XEN_VIRT_START; __image_base__ = .; #endif - . = __XEN_VIRT_START + MB(1); + . = __XEN_VIRT_START + XEN_IMG_OFFSET; _start = .; .text : { _stext = .; /* Text and read-only data */
xen/include/asm-x86/config.h +3 -0
@@ -114,6 +114,7 @@ extern unsigned long trampoline_phys; trampoline_phys-__pa(trampoline_start)))extern char trampoline_start[], trampoline_end[];extern char trampoline_realmode_entry[]; +extern unsigned int xen_img_base_phys_addr;extern unsigned int trampoline_xen_phys_start;extern unsigned char trampoline_cpu_started;extern char wakeup_start[];
@@ -280,6 +281,8 @@ extern unsigned char boot_edid_info[128];#endif #define DIRECTMAP_VIRT_END (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE) +#define XEN_IMG_OFFSET 0x200000 +#ifndef __ASSEMBLY__/* This is not a fixed value, just a lower limit. */
xen/include/asm-x86/page.h +1 -1
@@ -283,7 +283,7 @@ extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES];extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];extern l3_pgentry_t l3_bootmap[L3_PAGETABLE_ENTRIES ];extern l2_pgentry_t l2_identmap[4 *L2_PAGETABLE_ENTRIES ]; extern l1_pgentry_t l1_identmap[L1_PAGETABLE_ENTRIES],
Signature · 1 line
1.7.10.4
PATCH v2 22/23 x86: make Xen early boot code relocatable
In reply to Daniel KiperEvery multiboot protocol (regardless of version) compatible image must specify its load address (in ELF or multiboot header). Multiboot protocol compatible loader have to load image at specified address. However, there is no guarantee that the requested memory region (in case of Xen it starts at 1 MiB and ends at 17 MiB) where image should be loaded initially is a RAM and it is free (legacy BIOS platforms are merciful for Xen but I found at least one EFI platform on which Xen load address conflicts with EFI boot services; it is Dell PowerEdge R820 with latest firmware). To cope with that problem we must make Xen early boot code relocatable. This patch does that. However, it does not add multiboot2 protocol interface which is done in next patch.
This patch changes following things:
- default load address is changed from 1 MiB to 2 MiB; I did that because initial page tables are using 2 MiB huge pages and this way required updates for them are quite easy; it means that e.g. we avoid spacial cases for beginning and end of required memory region if it live at address not aligned to 2 MiB,
- %ebp register is used as a storage for Xen image base address; this way we can get this value very quickly if it is needed; however, %ebp register is not used directly to access a given memory region,
- %fs register is filled with segment descriptor which describes memory region with Xen image (it could be relocated or not); it is used to access some of Xen data in early boot code; potentially we can use above mentioned segment descriptor to access data using %ds:%esi and/or %es:%esi (e.g. movs*); however, I think that it could unnecessarily obfuscate code (e.g. we need at least to operations to reload a given segment descriptor) and current solution looks quite optimal.
--- xen/arch/x86/Makefile | 6 +- xen/arch/x86/Rules.mk | 4 + xen/arch/x86/boot/head.S | 165 ++++++++++++++++++++++++++++++---------- xen/arch/x86/boot/trampoline.S | 11 ++- xen/arch/x86/boot/wakeup.S | 6 +- xen/arch/x86/boot/x86_64.S | 34 ++++----- xen/arch/x86/setup.c | 33 ++++---- xen/arch/x86/x86_64/mm.c | 2 +- xen/arch/x86/xen.lds.S | 2 +- xen/include/asm-x86/config.h | 3 + xen/include/asm-x86/page.h | 2 +- 11 files changed, 182 insertions(+), 86 deletions(-)
xen/arch/x86/Makefile +4 -2
@@ -72,8 +72,10 @@ efi-$(x86_64) := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ echo '$(TARGET).efi'; fi) $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32 - ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ - `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` +# THIS IS UGLY HACK! PLEASE DO NOT COMPLAIN. I WILL FIX IT IN NEXT RELEASE. + ./boot/mkelf32 $(TARGET)-syms $(TARGET) $(XEN_IMG_PHYS_START) 0xffff82d081000000 +# ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ +# `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
xen/arch/x86/Rules.mk +4 -0
@@ -15,6 +15,10 @@ HAS_GDBSX := y HAS_PDX := y xenoprof := y +XEN_IMG_PHYS_START = 0x200000 + +CFLAGS += -DXEN_IMG_PHYS_START=$(XEN_IMG_PHYS_START) + CFLAGS += -I$(BASEDIR)/include CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-generic CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-default
xen/arch/x86/boot/head.S +123 -42
307 lines not on this page · raw message
xen/arch/x86/boot/trampoline.S +10 -1
@@ -52,12 +52,20 @@ trampoline_gdt: /* 0x0028: real-mode data @ BOOT_TRAMPOLINE */ .long 0x0000ffff .long 0x00009200 + /* + * 0x0030: ring 0 Xen data, 16 MiB size, base + * address is initialized during runtime. + */ + .quad 0x00c0920000001000 .pushsection .trampoline_rel, "a" .long trampoline_gdt + BOOT_PSEUDORM_CS + 2 - . .long trampoline_gdt + BOOT_PSEUDORM_DS + 2 - . .popsection +GLOBAL(xen_img_base_phys_addr) + .long 0 + GLOBAL(cpuid_ext_features) .long 0
@@ -82,7 +90,8 @@ trampoline_protmode_entry: mov %ecx,%cr4 /* Load pagetable base register. */ - mov $sym_phys(idle_pg_table),%eax + mov bootsym_rel(xen_img_base_phys_addr,4,%eax) + lea sym_offset(idle_pg_table)(%eax),%eax add bootsym_rel(trampoline_xen_phys_start,4,%eax) mov %eax,%cr3
xen/arch/x86/boot/wakeup.S +4 -2
@@ -119,8 +119,10 @@ wakeup_32: mov %eax, %ss mov $bootsym_rel(wakeup_stack, 4, %esp) + mov bootsym_rel(xen_img_base_phys_addr, 4, %ebx) + # check saved magic again - mov $sym_phys(saved_magic), %eax + lea sym_offset(saved_magic)(%ebx), %eax add bootsym_rel(trampoline_xen_phys_start, 4, %eax) mov (%eax), %eax cmp $0x9abcdef0, %eax
@@ -133,7 +135,7 @@ wakeup_32: mov %ecx, %cr4 /* Load pagetable base register */ - mov $sym_phys(idle_pg_table),%eax + lea sym_offset(idle_pg_table)(%ebx),%eax add bootsym_rel(trampoline_xen_phys_start,4,%eax) mov %eax,%cr3
xen/arch/x86/boot/x86_64.S +15 -19
@@ -81,7 +81,6 @@ GLOBAL(boot_cpu_compat_gdt_table) .quad 0x0000910000000000 /* per-CPU entry (limit == cpu) */ .align PAGE_SIZE, 0 -GLOBAL(__page_tables_start) /* * Mapping of first 2 megabytes of memory. This is mapped with 4kB mappings * to avoid type conflicts with fixed-range MTRRs covering the lowest megabyte
@@ -101,21 +100,18 @@ GLOBAL(l1_identmap) .endr .size l1_identmap, . - l1_identmap -/* Mapping of first 16 megabytes of memory. */ +GLOBAL(__page_tables_start) + GLOBAL(l2_identmap) - .quad sym_phys(l1_identmap) + __PAGE_HYPERVISOR - pfn = 0 - .rept 7 - pfn = pfn + (1 << PAGETABLE_ORDER) - .quad (pfn << PAGE_SHIFT) | PAGE_HYPERVISOR | _PAGE_PSE - .endr - .fill 4 * L2_PAGETABLE_ENTRIES - 8, 8, 0 + .quad sym_offset(l1_identmap) + __PAGE_HYPERVISOR + .fill 4 * L2_PAGETABLE_ENTRIES - 1, 8, 0 .size l2_identmap, . - l2_identmap GLOBAL(l2_xenmap) - idx = 0 - .rept 8 - .quad sym_phys(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE) + .quad 0 + idx = 1 + .rept 7 + .quad sym_offset(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE) idx = idx + 1 .endr .fill L2_PAGETABLE_ENTRIES - 8, 8, 0
@@ -125,7 +121,7 @@ l2_fixmap: idx = 0 .rept L2_PAGETABLE_ENTRIES .if idx == l2_table_offset(FIXADDR_TOP - 1) - .quad sym_phys(l1_fixmap) + __PAGE_HYPERVISOR + .quad sym_offset(l1_fixmap) + __PAGE_HYPERVISOR .else .quad 0 .endif
@@ -136,7 +132,7 @@ l2_fixmap: GLOBAL(l3_identmap) idx = 0 .rept 4 - .quad sym_phys(l2_identmap) + (idx << PAGE_SHIFT) + __PAGE_HYPERVISOR + .quad sym_offset(l2_identmap) + (idx << PAGE_SHIFT) + __PAGE_HYPERVISOR idx = idx + 1 .endr .fill L3_PAGETABLE_ENTRIES - 4, 8, 0
@@ -146,9 +142,9 @@ l3_xenmap: idx = 0 .rept L3_PAGETABLE_ENTRIES .if idx == l3_table_offset(XEN_VIRT_START) - .quad sym_phys(l2_xenmap) + __PAGE_HYPERVISOR + .quad sym_offset(l2_xenmap) + __PAGE_HYPERVISOR .elseif idx == l3_table_offset(FIXADDR_TOP - 1) - .quad sym_phys(l2_fixmap) + __PAGE_HYPERVISOR + .quad sym_offset(l2_fixmap) + __PAGE_HYPERVISOR .else .quad 0 .endif
@@ -158,13 +154,13 @@ l3_xenmap: /* Top-level master (and idle-domain) page directory. */ GLOBAL(idle_pg_table) - .quad sym_phys(l3_bootmap) + __PAGE_HYPERVISOR + .quad sym_offset(l3_bootmap) + __PAGE_HYPERVISOR idx = 1 .rept L4_PAGETABLE_ENTRIES - 1 .if idx == l4_table_offset(DIRECTMAP_VIRT_START) - .quad sym_phys(l3_identmap) + __PAGE_HYPERVISOR + .quad sym_offset(l3_identmap) + __PAGE_HYPERVISOR .elseif idx == l4_table_offset(XEN_VIRT_START) - .quad sym_phys(l3_xenmap) + __PAGE_HYPERVISOR + .quad sym_offset(l3_xenmap) + __PAGE_HYPERVISOR .else .quad 0 .endif
xen/arch/x86/setup.c +16 -17
@@ -291,9 +291,6 @@ static void *__init bootstrap_map(const module_t *mod)if ( start >= end )return NULL ; -if ( end <=BOOTSTRAP_MAP_BASE ) -return (void *)(unsigned long )start; - ret = (void *)(map_cur + (unsigned long )(start & mask)); start &= ~mask; end = (end + mask) & ~mask;
@@ -641,6 +638,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)printk ("Command line: %s\n" , cmdline); +printk ("Xen image base address: 0x%08lx\n" , + xen_phys_start ? xen_phys_start : (unsigned long )xen_img_base_phys_addr); +printk ("Video information:\n" );/* Print VGA display mode information. */
@@ -835,10 +835,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)uint64_t s, e, mask = (1UL <<L2_PAGETABLE_SHIFT ) -1 ;uint64_t end, limit =ARRAY_SIZE (l2_identmap) <<L2_PAGETABLE_SHIFT ; -/* Superpage-aligned chunks from BOOTSTRAP_MAP_BASE. */ s = (boot_e820.map[i].addr + mask) & ~mask; e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask; - s =max_t (uint64_t, s,BOOTSTRAP_MAP_BASE );if ( (boot_e820.map[i].type !=E820_RAM ) || (s >= e) )continue ;
@@ -876,7 +874,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)/* Select relocation address. */ e = end - reloc_size; xen_phys_start = e; -bootsym (trampoline_xen_phys_start) = e; +bootsym (trampoline_xen_phys_start) = e - xen_img_base_phys_addr;/* * Perform relocation to new physical address.
@@ -886,7 +884,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)*/ load_start = (unsigned long )_start -XEN_VIRT_START ;barrier (); -move_memory (e + load_start, load_start, _end - _start,1 ); +move_memory (e + load_start, load_start + xen_img_base_phys_addr, _end - _start,1 );/* Walk initial pagetables, relocating page directory entries. */ pl4e =__va (__pa (idle_pg_table));
@@ -895,27 +893,27 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( !(l4e_get_flags (*pl4e) & _PAGE_PRESENT) )continue ; *pl4e =l4e_from_intpte (l4e_get_intpte (*pl4e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); pl3e =l4e_to_l3e (*pl4e);for ( j =0 ; j <L3_PAGETABLE_ENTRIES ; j++, pl3e++ ) {/* Not present, 1GB mapping, or already relocated? */ if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) || (l3e_get_flags (*pl3e) & _PAGE_PSE) || - (l3e_get_pfn (*pl3e) >0x1000 ) ) + (l3e_get_pfn (*pl3e) >PFN_DOWN (xen_phys_start)) )continue ; *pl3e =l3e_from_intpte (l3e_get_intpte (*pl3e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); pl2e =l3e_to_l2e (*pl3e);for ( k =0 ; k <L2_PAGETABLE_ENTRIES ; k++, pl2e++ ) {/* Not present, PSE, or already relocated? */ if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) || (l2e_get_flags (*pl2e) & _PAGE_PSE) || - (l2e_get_pfn (*pl2e) >0x1000 ) ) + (l2e_get_pfn (*pl2e) >PFN_DOWN (xen_phys_start)) )continue ; *pl2e =l2e_from_intpte (l2e_get_intpte (*pl2e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); } } }
@@ -926,10 +924,10 @@ void __init noreturn __start_xen(unsigned long mbi_p) PAGE_HYPERVISOR_RWX | _PAGE_PSE);for ( i =1 ; i <L2_PAGETABLE_ENTRIES ; i++, pl2e++ ) { -if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) +if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) || (l2e_get_pfn (*pl2e) >PFN_DOWN (xen_phys_start)))continue ; *pl2e =l2e_from_intpte (l2e_get_intpte (*pl2e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); }/* Re-sync the stack and then switch to relocated pagetables. */
@@ -998,6 +996,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( !xen_phys_start )panic ("Not enough memory to relocate Xen." ); + +printk ("New Xen image base address: 0x%08lx\n" , xen_phys_start); +reserve_e820_ram (&boot_e820,__pa (&_start),__pa (&_end));/* Late kexec reservation (dynamic start address). */
@@ -1070,14 +1071,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)set_pdx_range (s >>PAGE_SHIFT , e >>PAGE_SHIFT ); -/* Need to create mappings above BOOTSTRAP_MAP_BASE. */ - map_s =max_t (uint64_t, s,BOOTSTRAP_MAP_BASE ); + map_s = s; map_e =min_t (uint64_t, e,ARRAY_SIZE (l2_identmap) <<L2_PAGETABLE_SHIFT );/* Pass mapped memory to allocator /before/ creating new mappings. */ init_boot_pages (s,min (map_s, e)); - s = map_s;if ( s < map_e ) {uint64_t mask = (1UL <<L2_PAGETABLE_SHIFT ) -1 ;
xen/arch/x86/x86_64/mm.c +1 -1
@@ -44,7 +44,7 @@ unsigned int __read_mostly m2p_compat_vstart = __HYPERVISOR_COMPAT_VIRT_START;/* Enough page directories to map into the bottom 1GB. */ l3_pgentry_t __section(".bss.page_aligned") l3_bootmap[L3_PAGETABLE_ENTRIES]; -l2_pgentry_t __section(".bss.page_aligned") l2_bootmap[L2_PAGETABLE_ENTRIES]; +l2_pgentry_t __section(".bss.page_aligned") l2_bootmap[4 * L2_PAGETABLE_ENTRIES];l2_pgentry_t *compat_idle_pg_table_l2;
xen/arch/x86/xen.lds.S +1 -1
@@ -38,7 +38,7 @@ SECTIONS . = __XEN_VIRT_START; __image_base__ = .; #endif - . = __XEN_VIRT_START + MB(1); + . = __XEN_VIRT_START + XEN_IMG_OFFSET; _start = .; .text : { _stext = .; /* Text and read-only data */
xen/include/asm-x86/config.h +3 -0
@@ -114,6 +114,7 @@ extern unsigned long trampoline_phys; trampoline_phys-__pa(trampoline_start)))extern char trampoline_start[], trampoline_end[];extern char trampoline_realmode_entry[]; +extern unsigned int xen_img_base_phys_addr;extern unsigned int trampoline_xen_phys_start;extern unsigned char trampoline_cpu_started;extern char wakeup_start[];
@@ -280,6 +281,8 @@ extern unsigned char boot_edid_info[128];#endif #define DIRECTMAP_VIRT_END (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE) +#define XEN_IMG_OFFSET 0x200000 +#ifndef __ASSEMBLY__/* This is not a fixed value, just a lower limit. */
xen/include/asm-x86/page.h +1 -1
@@ -283,7 +283,7 @@ extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES];extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];extern l3_pgentry_t l3_bootmap[L3_PAGETABLE_ENTRIES ];extern l2_pgentry_t l2_identmap[4 *L2_PAGETABLE_ENTRIES ]; extern l1_pgentry_t l1_identmap[L1_PAGETABLE_ENTRIES],
Signature · 1 line
1.7.10.4
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 11 lines · Daniel Kiper
Every multiboot protocol (regardless of version) compatible image must specify its load address (in ELF or multiboot header). Multiboot protocol compatible loader have to load image at specified address. However, there is no guarantee that the requested memory region (in case of Xen it starts at 1 MiB and ends at 17 MiB) where image should be loaded initially is a RAM and it is free (legacy BIOS platforms are merciful for Xen but I found at least one EFI platform on which Xen load address conflicts with EFI boot services; it is Dell PowerEdge R820 with latest firmware). To cope with that problem we must make Xen early boot code relocatable. This patch does that. However, it does not add multiboot2 protocol interface which is done in next patch.
s/next patch/"x86: add multiboot2 protocol support for relocatable image."
Quoted 12 lines
This patch changes following things:
- default load address is changed from 1 MiB to 2 MiB; I did that because initial page tables are using 2 MiB huge pages and this way required updates for them are quite easy; it means that e.g. we avoid spacial cases for beginning and end of required memory region if it live at address not aligned to 2 MiB,
- %ebp register is used as a storage for Xen image base address; this way we can get this value very quickly if it is needed; however, %ebp register is not used directly to access a given memory region,
- %fs register is filled with segment descriptor which describes memory region with Xen image (it could be relocated or not); it is used to access some of
'memory region with Xen image' ? Not sure I follow?
Perhaps:
segment descriptor which starts (0) at Xen image base (_start).
Quoted 4 lines
Xen data in early boot code; potentially we can use above mentioned segment descriptor to access data using %ds:%esi and/or %es:%esi (e.g. movs*); however, I think that it could unnecessarily obfuscate code (e.g. we need at least to operations to reload a given segment descriptor) and current solution
s/to/two/ ?
Quoted 22 lines
looks quite optimal.
Signed-off-by Daniel Kiper <[email protected]>--- xen/arch/x86/Makefile | 6 +- xen/arch/x86/Rules.mk | 4 + xen/arch/x86/boot/head.S | 165 ++++++++++++++++++++++++++++++---------- xen/arch/x86/boot/trampoline.S | 11 ++- xen/arch/x86/boot/wakeup.S | 6 +- xen/arch/x86/boot/x86_64.S | 34 ++++----- xen/arch/x86/setup.c | 33 ++++---- xen/arch/x86/x86_64/mm.c | 2 +- xen/arch/x86/xen.lds.S | 2 +- xen/include/asm-x86/config.h | 3 + xen/include/asm-x86/page.h | 2 +- 11 files changed, 182 insertions(+), 86 deletions(-)xen/arch/x86/Makefile +0
-0
xen/arch/x86/Makefile efi-$(x86_64) := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ · line 75
Quoted 6 lines
xen/arch/x86/Makefile +1
-2@@ -72,8 +72,10 @@ efi-$(x86_64) := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ echo '$(TARGET).efi'; fi) $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32 - ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ - `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` +# THIS IS UGLY HACK! PLEASE DO NOT COMPLAIN. I WILL FIX IT IN NEXT RELEASE.
OK :-)
Quoted 120 lines
xen/arch/x86/Makefile +3
-0+ ./boot/mkelf32 $(TARGET)-syms $(TARGET) $(XEN_IMG_PHYS_START) 0xffff82d081000000 +# ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ +# `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)xen/arch/x86/Rules.mk +4
-0@@ -15,6 +15,10 @@ HAS_GDBSX := y HAS_PDX := y xenoprof := y +XEN_IMG_PHYS_START = 0x200000 + +CFLAGS += -DXEN_IMG_PHYS_START=$(XEN_IMG_PHYS_START) + CFLAGS += -I$(BASEDIR)/include CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-generic CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-defaultxen/arch/x86/boot/head.S +20
-13@@ -12,13 +12,15 @@ .text .code32 -#define sym_phys(sym) ((sym) - __XEN_VIRT_START) +#define sym_phys(sym) ((sym) - __XEN_VIRT_START + XEN_IMG_PHYS_START - XEN_IMG_OFFSET) +#define sym_offset(sym) ((sym) - __XEN_VIRT_START) #define BOOT_CS32 0x0008 #define BOOT_CS64 0x0010 #define BOOT_DS 0x0018 #define BOOT_PSEUDORM_CS 0x0020 #define BOOT_PSEUDORM_DS 0x0028 +#define BOOT_FS 0x0030 #define MB2_HT(name) (MULTIBOOT2_HEADER_TAG_##name) #define MB2_TT(name) (MULTIBOOT2_TAG_TYPE_##name)@@ -105,12 +107,13 @@ multiboot1_header_end: .word 0 gdt_boot_descr: - .word 6*8-1 - .long sym_phys(trampoline_gdt) + .word 7*8-1 +gdt_boot_descr_addr: + .long sym_offset(trampoline_gdt) .long 0 /* Needed for 64-bit lgdt */ cs32_switch_addr: - .long sym_phys(cs32_switch) + .long sym_offset(cs32_switch) .word BOOT_CS32 .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!"@@ -120,13 +123,13 @@ cs32_switch_addr: .section .init.text, "ax", @progbits bad_cpu: - mov $(sym_phys(.Lbad_cpu_msg)),%esi # Error message + lea sym_offset(.Lbad_cpu_msg)(%ebp),%esi # Error message jmp print_err not_multiboot: - mov $(sym_phys(.Lbad_ldr_msg)),%esi # Error message + lea sym_offset(.Lbad_ldr_msg)(%ebp),%esi # Error message jmp print_err mb2_too_old: - mov $(sym_phys(.Lbad_mb2_ldr)),%esi # Error message + lea sym_offset(.Lbad_mb2_ldr)(%ebp),%esi # Error message print_err: mov $0xB8000,%edi # VGA framebuffer 1: mov (%esi),%bl@@ -151,6 +154,9 @@ print_err: __efi64_start: cld + /* Load default Xen image base address. */ + mov $sym_phys(__image_base__),%ebp + /* Check for Multiboot2 bootloader. */ cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax je efi_multiboot2_proto@@ -235,9 +241,11 @@ x86_32_switch: cli /* Initialise GDT. */ + add %ebp,gdt_boot_descr_addr(%rip) lgdt gdt_boot_descr(%rip) /* Reload code selector. */ + add %ebp,cs32_switch_addr(%rip) ljmpl *cs32_switch_addr(%rip) .code32@@ -263,12 +271,8 @@ __start: cld cli - /* Initialise GDT and basic data segments. */ - lgdt %cs:sym_phys(gdt_boot_descr) - mov $BOOT_DS,%ecx - mov %ecx,%ds - mov %ecx,%es - mov %ecx,%ss + /* Load default Xen image base address. */ + mov $sym_phys(__image_base__),%ebp /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value. */ xor %edx,%edx@@ -319,6 +323,19 @@ multiboot2_proto: jmp 0b trampoline_bios_setup: + mov %ebp,%esi + + /* Initialise GDT and basic data segments. */
xen/arch/x86/boot/head.S multiboot2_proto: · line 338
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ add %ebp,sym_offset(gdt_boot_descr_addr)(%esi) + lgdt sym_offset(gdt_boot_descr)(%esi) + + mov $BOOT_DS,%ecx + mov %ecx,%ds + mov %ecx,%es + mov %ecx,%fs + mov %ecx,%gs + mov %ecx,%ss +
The non-EFI boot path is now:
start
\- __start
\- multiboot2_proto
| jmp trampoline_bios_setup
|
\-and if not MB2: jmp trampoline_bios_setup.
In here you tweak the GDT and reload the %ds - but during this call chain we do touch the %ds - via:
__start+27>: testb $0x1,(%rbx)
__start+30>: cmovne 0x4(%rbx),%edx
which is OK (as MB1 says that the %ds has to cover up to 4GB). But I wonder why the __start code had the segments reloaded so early? Was the bootloader not setting the proper segments?
Let me double-check what SYSLINUX's mboot.c32 does. Perhaps it had done something odd in the past.
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 359
Quoted 7 lines
xen/arch/x86/boot/head.S +0
-0/* Set up trampoline segment 64k below EBDA */ movzwl 0x40e,%ecx /* EBDA segment */ cmp $0xa000,%ecx /* sanity check (high) */@@ -340,33 +357,58 @@ trampoline_bios_setup: cmovb %edx,%ecx /* and use the smaller */ trampoline_setup:
Would it make sense to add:
/* Gets called from EFI (from x86_32_switch) and legacy (see above) boot loaders. */
Quoted 12 lines
xen/arch/x86/boot/head.S +12
-0+ mov %ebp,%esi + + /* Initialize 0-15 bits of BOOT_FS segment descriptor base address. */ + mov %ebp,%edx + shl $16,%edx + or %edx,(sym_offset(trampoline_gdt)+BOOT_FS)(%esi) + + /* Initialize 16-23 bits of BOOT_FS segment descriptor base address. */ + mov %ebp,%edx + shr $16,%edx + and $0x000000ff,%edx + or %edx,(sym_offset(trampoline_gdt)+BOOT_FS+4)(%esi)
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 381
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ + /* Initialize 24-31 bits of BOOT_FS segment descriptor base address. */ + mov %ebp,%edx + and $0xff000000,%edx + or %edx,(sym_offset(trampoline_gdt)+BOOT_FS+4)(%esi) + + /* Initialize %fs and later use it to access Xen data if possible. */ + mov $BOOT_FS,%edx + mov %edx,%fs +
We just modified the GDT. Should we reload it (lgdt?)?
Quoted 109 lines
xen/arch/x86/boot/head.S +52
-16/* Reserve 64kb for the trampoline. */ sub $0x1000,%ecx /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */ xor %cl, %cl shl $4, %ecx - mov %ecx,sym_phys(trampoline_phys) + mov %ecx,%fs:sym_offset(trampoline_phys) + + /* Save Xen image base address for later use. */ + mov %ebp,%fs:sym_offset(xen_img_base_phys_addr) /* Save the Multiboot info struct (after relocation) for later use. */ - mov $sym_phys(cpu0_stack)+1024,%esp + lea (sym_offset(cpu0_stack)+1024)(%ebp),%esp push %eax /* Multiboot magic. */ push %ebx /* Multiboot information address. */ push %ecx /* Boot trampoline address. */ call reloc add $12,%esp /* Remove reloc() args from stack. */ - mov %eax,sym_phys(multiboot_ptr) + mov %eax,%fs:sym_offset(multiboot_ptr) /* * Do not zero BSS on EFI platform here. * It was initialized earlier. */ - cmpb $1,sym_phys(skip_realmode) + cmpb $1,%fs:sym_offset(skip_realmode) je 1f /* Initialize BSS (no nasty surprises!). */ - mov $sym_phys(__bss_start),%edi - mov $sym_phys(__bss_end),%ecx + lea sym_offset(__bss_start)(%ebp),%edi + lea sym_offset(__bss_end)(%ebp),%ecx sub %edi,%ecx shr $2,%ecx xor %eax,%eax@@ -381,8 +423,8 @@ trampoline_setup: jbe 1f mov $0x80000001,%eax cpuid -1: mov %edx,sym_phys(cpuid_ext_features) - mov %edx,sym_phys(boot_cpu_data)+CPUINFO_FEATURE_OFFSET(X86_FEATURE_LM) +1: mov %edx,%fs:sym_offset(cpuid_ext_features) + mov %edx,%fs:(sym_offset(boot_cpu_data)+CPUINFO_FEATURE_OFFSET(X86_FEATURE_LM)) /* Check for availability of long mode. */ bt $X86_FEATURE_LM & 0x1f,%edx@@ -390,72 +432,111 @@ trampoline_setup: /* Stash TSC to calculate a good approximation of time-since-boot */ rdtsc - mov %eax,sym_phys(boot_tsc_stamp) - mov %edx,sym_phys(boot_tsc_stamp+4) + mov %eax,%fs:sym_offset(boot_tsc_stamp) + mov %edx,%fs:sym_offset(boot_tsc_stamp+4) - /* Initialise L2 boot-map page table entries (16MB). */ - mov $sym_phys(l2_bootmap),%edx - mov $PAGE_HYPERVISOR|_PAGE_PSE,%eax - mov $8,%ecx + /* Update frame addreses in page tables. */ + lea sym_offset(__page_tables_start)(%ebp),%edx + mov $((__page_tables_end-__page_tables_start)/8),%ecx +1: testl $_PAGE_PRESENT,(%edx) + jz 2f + add %ebp,(%edx) +2: add $8,%edx + loop 1b + + /* Initialise L2 boot-map page table entries (14MB). */ + lea sym_offset(l2_bootmap)(%ebp),%edx + lea sym_offset(start)(%ebp),%eax + and $~((1<<L2_PAGETABLE_SHIFT)-1),%eax + mov %eax,%ebx + shr $(L2_PAGETABLE_SHIFT-3),%ebx + and $(L2_PAGETABLE_ENTRIES*4*8-1),%ebx + add %ebx,%edx + add $(PAGE_HYPERVISOR|_PAGE_PSE),%eax + mov $7,%ecx 1: mov %eax,(%edx) add $8,%edx add $(1<<L2_PAGETABLE_SHIFT),%eax loop 1b + /* Initialise L3 boot-map page directory entry. */ - mov $sym_phys(l2_bootmap)+__PAGE_HYPERVISOR,%eax - mov %eax,sym_phys(l3_bootmap) + 0*8 + lea (sym_offset(l2_bootmap)+__PAGE_HYPERVISOR)(%ebp),%eax + lea sym_offset(l3_bootmap)(%ebp),%ebx + mov $4,%ecx +1: mov %eax,(%ebx) + add $8,%ebx + add $(L2_PAGETABLE_ENTRIES*8),%eax + loop 1b + + /* Initialise L2 direct map page table entries (14MB). */ + lea sym_offset(l2_identmap)(%ebp),%edx + lea sym_offset(start)(%ebp),%eax + and $~((1<<L2_PAGETABLE_SHIFT)-1),%eax + mov %eax,%ebx + shr $(L2_PAGETABLE_SHIFT-3),%ebx + and $(L2_PAGETABLE_ENTRIES*4*8-1),%ebx + add %ebx,%edx + add $(PAGE_HYPERVISOR|_PAGE_PSE),%eax + mov $7,%ecx +1: mov %eax,(%edx)
xen/arch/x86/boot/head.S trampoline_setup: · line 488
Quoted 10 lines
xen/arch/x86/boot/head.S +6
-3+ add $8,%edx + add $(1<<L2_PAGETABLE_SHIFT),%eax + loop 1b + /* Hook 4kB mappings of first 2MB of memory into L2. */ - mov $sym_phys(l1_identmap)+__PAGE_HYPERVISOR,%edi - mov %edi,sym_phys(l2_xenmap) - mov %edi,sym_phys(l2_bootmap) + lea (sym_offset(l1_identmap)+__PAGE_HYPERVISOR)(%ebp),%edi + mov %edi,%fs:sym_offset(l2_bootmap)
But not to l2_xenmap?
Quoted 69 lines
xen/arch/x86/boot/head.S +13
-10/* Apply relocations to bootstrap trampoline. */ - mov sym_phys(trampoline_phys),%edx - mov $sym_phys(__trampoline_rel_start),%edi + mov %fs:sym_offset(trampoline_phys),%edx + lea sym_offset(__trampoline_rel_start)(%ebp),%edi + lea sym_offset(__trampoline_rel_stop)(%ebp),%esi 1: mov (%edi),%eax add %edx,(%edi,%eax) add $4,%edi - cmp $sym_phys(__trampoline_rel_stop),%edi + cmp %esi,%edi jb 1b /* Patch in the trampoline segment. */ shr $4,%edx - mov $sym_phys(__trampoline_seg_start),%edi + lea sym_offset(__trampoline_seg_start)(%ebp),%edi + lea sym_offset(__trampoline_seg_stop)(%ebp),%esi 1: mov (%edi),%eax mov %dx,(%edi,%eax) add $4,%edi - cmp $sym_phys(__trampoline_seg_stop),%edi + cmp %esi,%edi jb 1b /* Do not parse command line on EFI platform here. */ - cmpb $1,sym_phys(skip_realmode) + cmpb $1,%fs:sym_offset(skip_realmode) je 1f /* Bail if there is no command line to parse. */ - mov sym_phys(multiboot_ptr),%ebx + mov %fs:sym_offset(multiboot_ptr),%ebx testl $MBI_CMDLINE,MB_flags(%ebx) jz 1f cmpl $0,MB_cmdline(%ebx) jz 1f - pushl $sym_phys(early_boot_opts) + lea sym_offset(early_boot_opts)(%ebp),%eax + push %eax pushl MB_cmdline(%ebx) call cmdline_parse_early add $8,%esp /* Remove cmdline_parse_early() args from stack. */ 1: /* Switch to low-memory stack. */ - mov sym_phys(trampoline_phys),%edi + mov %fs:sym_offset(trampoline_phys),%edi lea 0x10000(%edi),%esp lea trampoline_boot_cpu_entry-trampoline_start(%edi),%eax pushl $BOOT_CS32 push %eax /* Copy bootstrap trampoline to low memory, below 1MB. */ - mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsbxen/arch/x86/boot/trampoline.S +0
-0
xen/arch/x86/boot/trampoline.S trampoline_gdt: · line 57
Quoted 6 lines
xen/arch/x86/boot/trampoline.S +3
-0@@ -52,12 +52,20 @@ trampoline_gdt: /* 0x0028: real-mode data @ BOOT_TRAMPOLINE */ .long 0x0000ffff .long 0x00009200 + /* + * 0x0030: ring 0 Xen data, 16 MiB size, base + * address is initialized during runtime.
s/initialized/computed/
Quoted 62 lines
xen/arch/x86/boot/trampoline.S +7
-1+ */ + .quad 0x00c0920000001000 .pushsection .trampoline_rel, "a" .long trampoline_gdt + BOOT_PSEUDORM_CS + 2 - . .long trampoline_gdt + BOOT_PSEUDORM_DS + 2 - . .popsection +GLOBAL(xen_img_base_phys_addr) + .long 0 + GLOBAL(cpuid_ext_features) .long 0@@ -82,7 +90,8 @@ trampoline_protmode_entry: mov %ecx,%cr4 /* Load pagetable base register. */ - mov $sym_phys(idle_pg_table),%eax + mov bootsym_rel(xen_img_base_phys_addr,4,%eax) + lea sym_offset(idle_pg_table)(%eax),%eax add bootsym_rel(trampoline_xen_phys_start,4,%eax) mov %eax,%cr3xen/arch/x86/boot/wakeup.S +4
-2@@ -119,8 +119,10 @@ wakeup_32: mov %eax, %ss mov $bootsym_rel(wakeup_stack, 4, %esp) + mov bootsym_rel(xen_img_base_phys_addr, 4, %ebx) + # check saved magic again - mov $sym_phys(saved_magic), %eax + lea sym_offset(saved_magic)(%ebx), %eax add bootsym_rel(trampoline_xen_phys_start, 4, %eax) mov (%eax), %eax cmp $0x9abcdef0, %eax@@ -133,7 +135,7 @@ wakeup_32: mov %ecx, %cr4 /* Load pagetable base register */ - mov $sym_phys(idle_pg_table),%eax + lea sym_offset(idle_pg_table)(%ebx),%eax add bootsym_rel(trampoline_xen_phys_start,4,%eax) mov %eax,%cr3xen/arch/x86/boot/x86_64.S +0
-1@@ -81,7 +81,6 @@ GLOBAL(boot_cpu_compat_gdt_table) .quad 0x0000910000000000 /* per-CPU entry (limit == cpu) */ .align PAGE_SIZE, 0 -GLOBAL(__page_tables_start) /* * Mapping of first 2 megabytes of memory. This is mapped with 4kB mappings * to avoid type conflicts with fixed-range MTRRs covering the lowest megabyte
xen/arch/x86/boot/x86_64.S GLOBAL(l1_identmap) · line 104
Quoted 4 lines
xen/arch/x86/boot/x86_64.S +0
-1@@ -101,21 +100,18 @@ GLOBAL(l1_identmap) .endr .size l1_identmap, . - l1_identmap -/* Mapping of first 16 megabytes of memory. */
Don't want to just update the comment?
xen/arch/x86/boot/x86_64.S GLOBAL(l1_identmap) · line 105
Quoted 3 lines
xen/arch/x86/boot/x86_64.S +2
-0+GLOBAL(__page_tables_start) + GLOBAL(l2_identmap)
And perhaps explain how this page is being updated at runtime?
Quoted 157 lines
xen/arch/x86/boot/x86_64.S +13
-17- .quad sym_phys(l1_identmap) + __PAGE_HYPERVISOR - pfn = 0 - .rept 7 - pfn = pfn + (1 << PAGETABLE_ORDER) - .quad (pfn << PAGE_SHIFT) | PAGE_HYPERVISOR | _PAGE_PSE - .endr - .fill 4 * L2_PAGETABLE_ENTRIES - 8, 8, 0 + .quad sym_offset(l1_identmap) + __PAGE_HYPERVISOR + .fill 4 * L2_PAGETABLE_ENTRIES - 1, 8, 0 .size l2_identmap, . - l2_identmap GLOBAL(l2_xenmap) - idx = 0 - .rept 8 - .quad sym_phys(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE) + .quad 0 + idx = 1 + .rept 7 + .quad sym_offset(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE) idx = idx + 1 .endr .fill L2_PAGETABLE_ENTRIES - 8, 8, 0@@ -125,7 +121,7 @@ l2_fixmap: idx = 0 .rept L2_PAGETABLE_ENTRIES .if idx == l2_table_offset(FIXADDR_TOP - 1) - .quad sym_phys(l1_fixmap) + __PAGE_HYPERVISOR + .quad sym_offset(l1_fixmap) + __PAGE_HYPERVISOR .else .quad 0 .endif@@ -136,7 +132,7 @@ l2_fixmap: GLOBAL(l3_identmap) idx = 0 .rept 4 - .quad sym_phys(l2_identmap) + (idx << PAGE_SHIFT) + __PAGE_HYPERVISOR + .quad sym_offset(l2_identmap) + (idx << PAGE_SHIFT) + __PAGE_HYPERVISOR idx = idx + 1 .endr .fill L3_PAGETABLE_ENTRIES - 4, 8, 0@@ -146,9 +142,9 @@ l3_xenmap: idx = 0 .rept L3_PAGETABLE_ENTRIES .if idx == l3_table_offset(XEN_VIRT_START) - .quad sym_phys(l2_xenmap) + __PAGE_HYPERVISOR + .quad sym_offset(l2_xenmap) + __PAGE_HYPERVISOR .elseif idx == l3_table_offset(FIXADDR_TOP - 1) - .quad sym_phys(l2_fixmap) + __PAGE_HYPERVISOR + .quad sym_offset(l2_fixmap) + __PAGE_HYPERVISOR .else .quad 0 .endif@@ -158,13 +154,13 @@ l3_xenmap: /* Top-level master (and idle-domain) page directory. */ GLOBAL(idle_pg_table) - .quad sym_phys(l3_bootmap) + __PAGE_HYPERVISOR + .quad sym_offset(l3_bootmap) + __PAGE_HYPERVISOR idx = 1 .rept L4_PAGETABLE_ENTRIES - 1 .if idx == l4_table_offset(DIRECTMAP_VIRT_START) - .quad sym_phys(l3_identmap) + __PAGE_HYPERVISOR + .quad sym_offset(l3_identmap) + __PAGE_HYPERVISOR .elseif idx == l4_table_offset(XEN_VIRT_START) - .quad sym_phys(l3_xenmap) + __PAGE_HYPERVISOR + .quad sym_offset(l3_xenmap) + __PAGE_HYPERVISOR .else .quad 0 .endifxen/arch/x86/setup.c +10
-12@@ -291,9 +291,6 @@ static void *__init bootstrap_map(const module_t *mod)if ( start >= end )return NULL ; -if ( end <=BOOTSTRAP_MAP_BASE ) -return (void *)(unsigned long )start; - ret = (void *)(map_cur + (unsigned long )(start & mask)); start &= ~mask; end = (end + mask) & ~mask;@@ -641,6 +638,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)printk ("Command line: %s\n" , cmdline); +printk ("Xen image base address: 0x%08lx\n" , + xen_phys_start ? xen_phys_start : (unsigned long )xen_img_base_phys_addr); +printk ("Video information:\n" );/* Print VGA display mode information. */ @@ -835,10 +835,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)uint64_t s, e, mask = (1UL <<L2_PAGETABLE_SHIFT ) -1 ;uint64_t end, limit =ARRAY_SIZE (l2_identmap) <<L2_PAGETABLE_SHIFT ; -/* Superpage-aligned chunks from BOOTSTRAP_MAP_BASE. */ s = (boot_e820.map[i].addr + mask) & ~mask; e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask; - s =max_t (uint64_t, s,BOOTSTRAP_MAP_BASE );if ( (boot_e820.map[i].type !=E820_RAM ) || (s >= e) )continue ;@@ -876,7 +874,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)/* Select relocation address. */ e = end - reloc_size; xen_phys_start = e; -bootsym (trampoline_xen_phys_start) = e; +bootsym (trampoline_xen_phys_start) = e - xen_img_base_phys_addr;/* * Perform relocation to new physical address. @@ -886,7 +884,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)*/ load_start = (unsigned long )_start -XEN_VIRT_START ;barrier (); -move_memory (e + load_start, load_start, _end - _start,1 ); +move_memory (e + load_start, load_start + xen_img_base_phys_addr, _end - _start,1 );/* Walk initial pagetables, relocating page directory entries. */ pl4e =__va (__pa (idle_pg_table));@@ -895,27 +893,27 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( !(l4e_get_flags (*pl4e) & _PAGE_PRESENT) )continue ; *pl4e =l4e_from_intpte (l4e_get_intpte (*pl4e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); pl3e =l4e_to_l3e (*pl4e);for ( j =0 ; j <L3_PAGETABLE_ENTRIES ; j++, pl3e++ ) {/* Not present, 1GB mapping, or already relocated? */ if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) || (l3e_get_flags (*pl3e) & _PAGE_PSE) || - (l3e_get_pfn (*pl3e) >0x1000 ) ) + (l3e_get_pfn (*pl3e) >PFN_DOWN (xen_phys_start)) )continue ; *pl3e =l3e_from_intpte (l3e_get_intpte (*pl3e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); pl2e =l3e_to_l2e (*pl3e);for ( k =0 ; k <L2_PAGETABLE_ENTRIES ; k++, pl2e++ ) {/* Not present, PSE, or already relocated? */ if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) || (l2e_get_flags (*pl2e) & _PAGE_PSE) || - (l2e_get_pfn (*pl2e) >0x1000 ) ) + (l2e_get_pfn (*pl2e) >PFN_DOWN (xen_phys_start)) )continue ; *pl2e =l2e_from_intpte (l2e_get_intpte (*pl2e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); } } }
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 927
Quoted 5 lines
xen/arch/x86/setup.c +1
-1@@ -926,10 +924,10 @@ void __init noreturn __start_xen(unsigned long mbi_p) PAGE_HYPERVISOR_RWX | _PAGE_PSE);for ( i =1 ; i <L2_PAGETABLE_ENTRIES ; i++, pl2e++ ) { -if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) +if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) || (l2e_get_pfn (*pl2e) >PFN_DOWN (xen_phys_start)))
Could this be split in two lines?
Quoted 38 lines
xen/arch/x86/setup.c +5
-4continue ; *pl2e =l2e_from_intpte (l2e_get_intpte (*pl2e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); }/* Re-sync the stack and then switch to relocated pagetables. */ @@ -998,6 +996,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( !xen_phys_start )panic ("Not enough memory to relocate Xen." ); + +printk ("New Xen image base address: 0x%08lx\n" , xen_phys_start); +reserve_e820_ram (&boot_e820,__pa (&_start),__pa (&_end));/* Late kexec reservation (dynamic start address). */ @@ -1070,14 +1071,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)set_pdx_range (s >>PAGE_SHIFT , e >>PAGE_SHIFT ); -/* Need to create mappings above BOOTSTRAP_MAP_BASE. */ - map_s =max_t (uint64_t, s,BOOTSTRAP_MAP_BASE ); + map_s = s; map_e =min_t (uint64_t, e,ARRAY_SIZE (l2_identmap) <<L2_PAGETABLE_SHIFT );/* Pass mapped memory to allocator /before/ creating new mappings. */ init_boot_pages (s,min (map_s, e)); - s = map_s;if ( s < map_e ) {uint64_t mask = (1UL <<L2_PAGETABLE_SHIFT ) -1 ;xen/arch/x86/x86_64/mm.c +0
-0
xen/arch/x86/x86_64/mm.c unsigned int __read_mostly m2p_compat_vstart = __HYPERVISOR_COMPAT_VIRT_START; · line 48
Quoted 6 lines
xen/arch/x86/x86_64/mm.c +1
-1@@ -44,7 +44,7 @@ unsigned int __read_mostly m2p_compat_vstart = __HYPERVISOR_COMPAT_VIRT_START;/* Enough page directories to map into the bottom 1GB. */ l3_pgentry_t __section(".bss.page_aligned") l3_bootmap[L3_PAGETABLE_ENTRIES]; -l2_pgentry_t __section(".bss.page_aligned") l2_bootmap[L2_PAGETABLE_ENTRIES]; +l2_pgentry_t __section(".bss.page_aligned") l2_bootmap[4 * L2_PAGETABLE_ENTRIES];
16KB?
? Confused.
Quoted 42 lines
xen/arch/x86/x86_64/mm.c +0
-0l2_pgentry_t *compat_idle_pg_table_l2;xen/arch/x86/xen.lds.S +1
-1@@ -38,7 +38,7 @@ SECTIONS . = __XEN_VIRT_START; __image_base__ = .; #endif - . = __XEN_VIRT_START + MB(1); + . = __XEN_VIRT_START + XEN_IMG_OFFSET; _start = .; .text : { _stext = .; /* Text and read-only data */xen/include/asm-x86/config.h +3
-0@@ -114,6 +114,7 @@ extern unsigned long trampoline_phys; trampoline_phys-__pa(trampoline_start)))extern char trampoline_start[], trampoline_end[];extern char trampoline_realmode_entry[]; +extern unsigned int xen_img_base_phys_addr;extern unsigned int trampoline_xen_phys_start;extern unsigned char trampoline_cpu_started;extern char wakeup_start[];@@ -280,6 +281,8 @@ extern unsigned char boot_edid_info[128];#endif #define DIRECTMAP_VIRT_END (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE) +#define XEN_IMG_OFFSET 0x200000 +#ifndef __ASSEMBLY__/* This is not a fixed value, just a lower limit. */ xen/include/asm-x86/page.h +0
-0
xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 286
Quoted 5 lines
xen/include/asm-x86/page.h +1
-1@@ -283,7 +283,7 @@ extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES];extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];
? Why do we need to expand this to be 16kB?
Quoted 11 lines
xen/include/asm-x86/page.h +0
-0extern l3_pgentry_t l3_bootmap[L3_PAGETABLE_ENTRIES ];extern l2_pgentry_t l2_identmap[4 *L2_PAGETABLE_ENTRIES ]; extern l1_pgentry_t l1_identmap[L1_PAGETABLE_ENTRIES],Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Daniel KiperQuoted 11 lines · Daniel Kiper
Every multiboot protocol (regardless of version) compatible image must specify its load address (in ELF or multiboot header). Multiboot protocol compatible loader have to load image at specified address. However, there is no guarantee that the requested memory region (in case of Xen it starts at 1 MiB and ends at 17 MiB) where image should be loaded initially is a RAM and it is free (legacy BIOS platforms are merciful for Xen but I found at least one EFI platform on which Xen load address conflicts with EFI boot services; it is Dell PowerEdge R820 with latest firmware). To cope with that problem we must make Xen early boot code relocatable. This patch does that. However, it does not add multiboot2 protocol interface which is done in next patch.
s/next patch/"x86: add multiboot2 protocol support for relocatable image."
Quoted 12 lines
This patch changes following things:
- default load address is changed from 1 MiB to 2 MiB; I did that because initial page tables are using 2 MiB huge pages and this way required updates for them are quite easy; it means that e.g. we avoid spacial cases for beginning and end of required memory region if it live at address not aligned to 2 MiB,
- %ebp register is used as a storage for Xen image base address; this way we can get this value very quickly if it is needed; however, %ebp register is not used directly to access a given memory region,
- %fs register is filled with segment descriptor which describes memory region with Xen image (it could be relocated or not); it is used to access some of
'memory region with Xen image' ? Not sure I follow?
Perhaps:
segment descriptor which starts (0) at Xen image base (_start).
Quoted 4 lines
Xen data in early boot code; potentially we can use above mentioned segment descriptor to access data using %ds:%esi and/or %es:%esi (e.g. movs*); however, I think that it could unnecessarily obfuscate code (e.g. we need at least to operations to reload a given segment descriptor) and current solution
s/to/two/ ?
Quoted 22 lines
looks quite optimal.
Signed-off-by Daniel Kiper <[email protected]>--- xen/arch/x86/Makefile | 6 +- xen/arch/x86/Rules.mk | 4 + xen/arch/x86/boot/head.S | 165 ++++++++++++++++++++++++++++++---------- xen/arch/x86/boot/trampoline.S | 11 ++- xen/arch/x86/boot/wakeup.S | 6 +- xen/arch/x86/boot/x86_64.S | 34 ++++----- xen/arch/x86/setup.c | 33 ++++---- xen/arch/x86/x86_64/mm.c | 2 +- xen/arch/x86/xen.lds.S | 2 +- xen/include/asm-x86/config.h | 3 + xen/include/asm-x86/page.h | 2 +- 11 files changed, 182 insertions(+), 86 deletions(-)xen/arch/x86/Makefile +0
-0
xen/arch/x86/Makefile efi-$(x86_64) := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ · line 75
Quoted 6 lines
xen/arch/x86/Makefile +1
-2@@ -72,8 +72,10 @@ efi-$(x86_64) := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ echo '$(TARGET).efi'; fi) $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32 - ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ - `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` +# THIS IS UGLY HACK! PLEASE DO NOT COMPLAIN. I WILL FIX IT IN NEXT RELEASE.
OK :-)
Quoted 120 lines
xen/arch/x86/Makefile +3
-0+ ./boot/mkelf32 $(TARGET)-syms $(TARGET) $(XEN_IMG_PHYS_START) 0xffff82d081000000 +# ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ +# `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)xen/arch/x86/Rules.mk +4
-0@@ -15,6 +15,10 @@ HAS_GDBSX := y HAS_PDX := y xenoprof := y +XEN_IMG_PHYS_START = 0x200000 + +CFLAGS += -DXEN_IMG_PHYS_START=$(XEN_IMG_PHYS_START) + CFLAGS += -I$(BASEDIR)/include CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-generic CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-defaultxen/arch/x86/boot/head.S +20
-13@@ -12,13 +12,15 @@ .text .code32 -#define sym_phys(sym) ((sym) - __XEN_VIRT_START) +#define sym_phys(sym) ((sym) - __XEN_VIRT_START + XEN_IMG_PHYS_START - XEN_IMG_OFFSET) +#define sym_offset(sym) ((sym) - __XEN_VIRT_START) #define BOOT_CS32 0x0008 #define BOOT_CS64 0x0010 #define BOOT_DS 0x0018 #define BOOT_PSEUDORM_CS 0x0020 #define BOOT_PSEUDORM_DS 0x0028 +#define BOOT_FS 0x0030 #define MB2_HT(name) (MULTIBOOT2_HEADER_TAG_##name) #define MB2_TT(name) (MULTIBOOT2_TAG_TYPE_##name)@@ -105,12 +107,13 @@ multiboot1_header_end: .word 0 gdt_boot_descr: - .word 6*8-1 - .long sym_phys(trampoline_gdt) + .word 7*8-1 +gdt_boot_descr_addr: + .long sym_offset(trampoline_gdt) .long 0 /* Needed for 64-bit lgdt */ cs32_switch_addr: - .long sym_phys(cs32_switch) + .long sym_offset(cs32_switch) .word BOOT_CS32 .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!"@@ -120,13 +123,13 @@ cs32_switch_addr: .section .init.text, "ax", @progbits bad_cpu: - mov $(sym_phys(.Lbad_cpu_msg)),%esi # Error message + lea sym_offset(.Lbad_cpu_msg)(%ebp),%esi # Error message jmp print_err not_multiboot: - mov $(sym_phys(.Lbad_ldr_msg)),%esi # Error message + lea sym_offset(.Lbad_ldr_msg)(%ebp),%esi # Error message jmp print_err mb2_too_old: - mov $(sym_phys(.Lbad_mb2_ldr)),%esi # Error message + lea sym_offset(.Lbad_mb2_ldr)(%ebp),%esi # Error message print_err: mov $0xB8000,%edi # VGA framebuffer 1: mov (%esi),%bl@@ -151,6 +154,9 @@ print_err: __efi64_start: cld + /* Load default Xen image base address. */ + mov $sym_phys(__image_base__),%ebp + /* Check for Multiboot2 bootloader. */ cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax je efi_multiboot2_proto@@ -235,9 +241,11 @@ x86_32_switch: cli /* Initialise GDT. */ + add %ebp,gdt_boot_descr_addr(%rip) lgdt gdt_boot_descr(%rip) /* Reload code selector. */ + add %ebp,cs32_switch_addr(%rip) ljmpl *cs32_switch_addr(%rip) .code32@@ -263,12 +271,8 @@ __start: cld cli - /* Initialise GDT and basic data segments. */ - lgdt %cs:sym_phys(gdt_boot_descr) - mov $BOOT_DS,%ecx - mov %ecx,%ds - mov %ecx,%es - mov %ecx,%ss + /* Load default Xen image base address. */ + mov $sym_phys(__image_base__),%ebp /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value. */ xor %edx,%edx@@ -319,6 +323,19 @@ multiboot2_proto: jmp 0b trampoline_bios_setup: + mov %ebp,%esi + + /* Initialise GDT and basic data segments. */
xen/arch/x86/boot/head.S multiboot2_proto: · line 338
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ add %ebp,sym_offset(gdt_boot_descr_addr)(%esi) + lgdt sym_offset(gdt_boot_descr)(%esi) + + mov $BOOT_DS,%ecx + mov %ecx,%ds + mov %ecx,%es + mov %ecx,%fs + mov %ecx,%gs + mov %ecx,%ss +
The non-EFI boot path is now:
start
\- __start
\- multiboot2_proto
| jmp trampoline_bios_setup
|
\-and if not MB2: jmp trampoline_bios_setup.
In here you tweak the GDT and reload the %ds - but during this call chain we do touch the %ds - via:
__start+27>: testb $0x1,(%rbx)
__start+30>: cmovne 0x4(%rbx),%edx
which is OK (as MB1 says that the %ds has to cover up to 4GB). But I wonder why the __start code had the segments reloaded so early? Was the bootloader not setting the proper segments?
Let me double-check what SYSLINUX's mboot.c32 does. Perhaps it had done something odd in the past.
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 359
Quoted 7 lines
xen/arch/x86/boot/head.S +0
-0/* Set up trampoline segment 64k below EBDA */ movzwl 0x40e,%ecx /* EBDA segment */ cmp $0xa000,%ecx /* sanity check (high) */@@ -340,33 +357,58 @@ trampoline_bios_setup: cmovb %edx,%ecx /* and use the smaller */ trampoline_setup:
Would it make sense to add:
/* Gets called from EFI (from x86_32_switch) and legacy (see above) boot loaders. */
Quoted 12 lines
xen/arch/x86/boot/head.S +12
-0+ mov %ebp,%esi + + /* Initialize 0-15 bits of BOOT_FS segment descriptor base address. */ + mov %ebp,%edx + shl $16,%edx + or %edx,(sym_offset(trampoline_gdt)+BOOT_FS)(%esi) + + /* Initialize 16-23 bits of BOOT_FS segment descriptor base address. */ + mov %ebp,%edx + shr $16,%edx + and $0x000000ff,%edx + or %edx,(sym_offset(trampoline_gdt)+BOOT_FS+4)(%esi)
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 381
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ + /* Initialize 24-31 bits of BOOT_FS segment descriptor base address. */ + mov %ebp,%edx + and $0xff000000,%edx + or %edx,(sym_offset(trampoline_gdt)+BOOT_FS+4)(%esi) + + /* Initialize %fs and later use it to access Xen data if possible. */ + mov $BOOT_FS,%edx + mov %edx,%fs +
We just modified the GDT. Should we reload it (lgdt?)?
Quoted 109 lines
xen/arch/x86/boot/head.S +52
-16/* Reserve 64kb for the trampoline. */ sub $0x1000,%ecx /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */ xor %cl, %cl shl $4, %ecx - mov %ecx,sym_phys(trampoline_phys) + mov %ecx,%fs:sym_offset(trampoline_phys) + + /* Save Xen image base address for later use. */ + mov %ebp,%fs:sym_offset(xen_img_base_phys_addr) /* Save the Multiboot info struct (after relocation) for later use. */ - mov $sym_phys(cpu0_stack)+1024,%esp + lea (sym_offset(cpu0_stack)+1024)(%ebp),%esp push %eax /* Multiboot magic. */ push %ebx /* Multiboot information address. */ push %ecx /* Boot trampoline address. */ call reloc add $12,%esp /* Remove reloc() args from stack. */ - mov %eax,sym_phys(multiboot_ptr) + mov %eax,%fs:sym_offset(multiboot_ptr) /* * Do not zero BSS on EFI platform here. * It was initialized earlier. */ - cmpb $1,sym_phys(skip_realmode) + cmpb $1,%fs:sym_offset(skip_realmode) je 1f /* Initialize BSS (no nasty surprises!). */ - mov $sym_phys(__bss_start),%edi - mov $sym_phys(__bss_end),%ecx + lea sym_offset(__bss_start)(%ebp),%edi + lea sym_offset(__bss_end)(%ebp),%ecx sub %edi,%ecx shr $2,%ecx xor %eax,%eax@@ -381,8 +423,8 @@ trampoline_setup: jbe 1f mov $0x80000001,%eax cpuid -1: mov %edx,sym_phys(cpuid_ext_features) - mov %edx,sym_phys(boot_cpu_data)+CPUINFO_FEATURE_OFFSET(X86_FEATURE_LM) +1: mov %edx,%fs:sym_offset(cpuid_ext_features) + mov %edx,%fs:(sym_offset(boot_cpu_data)+CPUINFO_FEATURE_OFFSET(X86_FEATURE_LM)) /* Check for availability of long mode. */ bt $X86_FEATURE_LM & 0x1f,%edx@@ -390,72 +432,111 @@ trampoline_setup: /* Stash TSC to calculate a good approximation of time-since-boot */ rdtsc - mov %eax,sym_phys(boot_tsc_stamp) - mov %edx,sym_phys(boot_tsc_stamp+4) + mov %eax,%fs:sym_offset(boot_tsc_stamp) + mov %edx,%fs:sym_offset(boot_tsc_stamp+4) - /* Initialise L2 boot-map page table entries (16MB). */ - mov $sym_phys(l2_bootmap),%edx - mov $PAGE_HYPERVISOR|_PAGE_PSE,%eax - mov $8,%ecx + /* Update frame addreses in page tables. */ + lea sym_offset(__page_tables_start)(%ebp),%edx + mov $((__page_tables_end-__page_tables_start)/8),%ecx +1: testl $_PAGE_PRESENT,(%edx) + jz 2f + add %ebp,(%edx) +2: add $8,%edx + loop 1b + + /* Initialise L2 boot-map page table entries (14MB). */ + lea sym_offset(l2_bootmap)(%ebp),%edx + lea sym_offset(start)(%ebp),%eax + and $~((1<<L2_PAGETABLE_SHIFT)-1),%eax + mov %eax,%ebx + shr $(L2_PAGETABLE_SHIFT-3),%ebx + and $(L2_PAGETABLE_ENTRIES*4*8-1),%ebx + add %ebx,%edx + add $(PAGE_HYPERVISOR|_PAGE_PSE),%eax + mov $7,%ecx 1: mov %eax,(%edx) add $8,%edx add $(1<<L2_PAGETABLE_SHIFT),%eax loop 1b + /* Initialise L3 boot-map page directory entry. */ - mov $sym_phys(l2_bootmap)+__PAGE_HYPERVISOR,%eax - mov %eax,sym_phys(l3_bootmap) + 0*8 + lea (sym_offset(l2_bootmap)+__PAGE_HYPERVISOR)(%ebp),%eax + lea sym_offset(l3_bootmap)(%ebp),%ebx + mov $4,%ecx +1: mov %eax,(%ebx) + add $8,%ebx + add $(L2_PAGETABLE_ENTRIES*8),%eax + loop 1b + + /* Initialise L2 direct map page table entries (14MB). */ + lea sym_offset(l2_identmap)(%ebp),%edx + lea sym_offset(start)(%ebp),%eax + and $~((1<<L2_PAGETABLE_SHIFT)-1),%eax + mov %eax,%ebx + shr $(L2_PAGETABLE_SHIFT-3),%ebx + and $(L2_PAGETABLE_ENTRIES*4*8-1),%ebx + add %ebx,%edx + add $(PAGE_HYPERVISOR|_PAGE_PSE),%eax + mov $7,%ecx +1: mov %eax,(%edx)
xen/arch/x86/boot/head.S trampoline_setup: · line 488
Quoted 10 lines
xen/arch/x86/boot/head.S +6
-3+ add $8,%edx + add $(1<<L2_PAGETABLE_SHIFT),%eax + loop 1b + /* Hook 4kB mappings of first 2MB of memory into L2. */ - mov $sym_phys(l1_identmap)+__PAGE_HYPERVISOR,%edi - mov %edi,sym_phys(l2_xenmap) - mov %edi,sym_phys(l2_bootmap) + lea (sym_offset(l1_identmap)+__PAGE_HYPERVISOR)(%ebp),%edi + mov %edi,%fs:sym_offset(l2_bootmap)
But not to l2_xenmap?
Quoted 69 lines
xen/arch/x86/boot/head.S +13
-10/* Apply relocations to bootstrap trampoline. */ - mov sym_phys(trampoline_phys),%edx - mov $sym_phys(__trampoline_rel_start),%edi + mov %fs:sym_offset(trampoline_phys),%edx + lea sym_offset(__trampoline_rel_start)(%ebp),%edi + lea sym_offset(__trampoline_rel_stop)(%ebp),%esi 1: mov (%edi),%eax add %edx,(%edi,%eax) add $4,%edi - cmp $sym_phys(__trampoline_rel_stop),%edi + cmp %esi,%edi jb 1b /* Patch in the trampoline segment. */ shr $4,%edx - mov $sym_phys(__trampoline_seg_start),%edi + lea sym_offset(__trampoline_seg_start)(%ebp),%edi + lea sym_offset(__trampoline_seg_stop)(%ebp),%esi 1: mov (%edi),%eax mov %dx,(%edi,%eax) add $4,%edi - cmp $sym_phys(__trampoline_seg_stop),%edi + cmp %esi,%edi jb 1b /* Do not parse command line on EFI platform here. */ - cmpb $1,sym_phys(skip_realmode) + cmpb $1,%fs:sym_offset(skip_realmode) je 1f /* Bail if there is no command line to parse. */ - mov sym_phys(multiboot_ptr),%ebx + mov %fs:sym_offset(multiboot_ptr),%ebx testl $MBI_CMDLINE,MB_flags(%ebx) jz 1f cmpl $0,MB_cmdline(%ebx) jz 1f - pushl $sym_phys(early_boot_opts) + lea sym_offset(early_boot_opts)(%ebp),%eax + push %eax pushl MB_cmdline(%ebx) call cmdline_parse_early add $8,%esp /* Remove cmdline_parse_early() args from stack. */ 1: /* Switch to low-memory stack. */ - mov sym_phys(trampoline_phys),%edi + mov %fs:sym_offset(trampoline_phys),%edi lea 0x10000(%edi),%esp lea trampoline_boot_cpu_entry-trampoline_start(%edi),%eax pushl $BOOT_CS32 push %eax /* Copy bootstrap trampoline to low memory, below 1MB. */ - mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsbxen/arch/x86/boot/trampoline.S +0
-0
xen/arch/x86/boot/trampoline.S trampoline_gdt: · line 57
Quoted 6 lines
xen/arch/x86/boot/trampoline.S +3
-0@@ -52,12 +52,20 @@ trampoline_gdt: /* 0x0028: real-mode data @ BOOT_TRAMPOLINE */ .long 0x0000ffff .long 0x00009200 + /* + * 0x0030: ring 0 Xen data, 16 MiB size, base + * address is initialized during runtime.
s/initialized/computed/
Quoted 62 lines
xen/arch/x86/boot/trampoline.S +7
-1+ */ + .quad 0x00c0920000001000 .pushsection .trampoline_rel, "a" .long trampoline_gdt + BOOT_PSEUDORM_CS + 2 - . .long trampoline_gdt + BOOT_PSEUDORM_DS + 2 - . .popsection +GLOBAL(xen_img_base_phys_addr) + .long 0 + GLOBAL(cpuid_ext_features) .long 0@@ -82,7 +90,8 @@ trampoline_protmode_entry: mov %ecx,%cr4 /* Load pagetable base register. */ - mov $sym_phys(idle_pg_table),%eax + mov bootsym_rel(xen_img_base_phys_addr,4,%eax) + lea sym_offset(idle_pg_table)(%eax),%eax add bootsym_rel(trampoline_xen_phys_start,4,%eax) mov %eax,%cr3xen/arch/x86/boot/wakeup.S +4
-2@@ -119,8 +119,10 @@ wakeup_32: mov %eax, %ss mov $bootsym_rel(wakeup_stack, 4, %esp) + mov bootsym_rel(xen_img_base_phys_addr, 4, %ebx) + # check saved magic again - mov $sym_phys(saved_magic), %eax + lea sym_offset(saved_magic)(%ebx), %eax add bootsym_rel(trampoline_xen_phys_start, 4, %eax) mov (%eax), %eax cmp $0x9abcdef0, %eax@@ -133,7 +135,7 @@ wakeup_32: mov %ecx, %cr4 /* Load pagetable base register */ - mov $sym_phys(idle_pg_table),%eax + lea sym_offset(idle_pg_table)(%ebx),%eax add bootsym_rel(trampoline_xen_phys_start,4,%eax) mov %eax,%cr3xen/arch/x86/boot/x86_64.S +0
-1@@ -81,7 +81,6 @@ GLOBAL(boot_cpu_compat_gdt_table) .quad 0x0000910000000000 /* per-CPU entry (limit == cpu) */ .align PAGE_SIZE, 0 -GLOBAL(__page_tables_start) /* * Mapping of first 2 megabytes of memory. This is mapped with 4kB mappings * to avoid type conflicts with fixed-range MTRRs covering the lowest megabyte
xen/arch/x86/boot/x86_64.S GLOBAL(l1_identmap) · line 104
Quoted 4 lines
xen/arch/x86/boot/x86_64.S +0
-1@@ -101,21 +100,18 @@ GLOBAL(l1_identmap) .endr .size l1_identmap, . - l1_identmap -/* Mapping of first 16 megabytes of memory. */
Don't want to just update the comment?
xen/arch/x86/boot/x86_64.S GLOBAL(l1_identmap) · line 105
Quoted 3 lines
xen/arch/x86/boot/x86_64.S +2
-0+GLOBAL(__page_tables_start) + GLOBAL(l2_identmap)
And perhaps explain how this page is being updated at runtime?
Quoted 157 lines
xen/arch/x86/boot/x86_64.S +13
-17- .quad sym_phys(l1_identmap) + __PAGE_HYPERVISOR - pfn = 0 - .rept 7 - pfn = pfn + (1 << PAGETABLE_ORDER) - .quad (pfn << PAGE_SHIFT) | PAGE_HYPERVISOR | _PAGE_PSE - .endr - .fill 4 * L2_PAGETABLE_ENTRIES - 8, 8, 0 + .quad sym_offset(l1_identmap) + __PAGE_HYPERVISOR + .fill 4 * L2_PAGETABLE_ENTRIES - 1, 8, 0 .size l2_identmap, . - l2_identmap GLOBAL(l2_xenmap) - idx = 0 - .rept 8 - .quad sym_phys(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE) + .quad 0 + idx = 1 + .rept 7 + .quad sym_offset(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE) idx = idx + 1 .endr .fill L2_PAGETABLE_ENTRIES - 8, 8, 0@@ -125,7 +121,7 @@ l2_fixmap: idx = 0 .rept L2_PAGETABLE_ENTRIES .if idx == l2_table_offset(FIXADDR_TOP - 1) - .quad sym_phys(l1_fixmap) + __PAGE_HYPERVISOR + .quad sym_offset(l1_fixmap) + __PAGE_HYPERVISOR .else .quad 0 .endif@@ -136,7 +132,7 @@ l2_fixmap: GLOBAL(l3_identmap) idx = 0 .rept 4 - .quad sym_phys(l2_identmap) + (idx << PAGE_SHIFT) + __PAGE_HYPERVISOR + .quad sym_offset(l2_identmap) + (idx << PAGE_SHIFT) + __PAGE_HYPERVISOR idx = idx + 1 .endr .fill L3_PAGETABLE_ENTRIES - 4, 8, 0@@ -146,9 +142,9 @@ l3_xenmap: idx = 0 .rept L3_PAGETABLE_ENTRIES .if idx == l3_table_offset(XEN_VIRT_START) - .quad sym_phys(l2_xenmap) + __PAGE_HYPERVISOR + .quad sym_offset(l2_xenmap) + __PAGE_HYPERVISOR .elseif idx == l3_table_offset(FIXADDR_TOP - 1) - .quad sym_phys(l2_fixmap) + __PAGE_HYPERVISOR + .quad sym_offset(l2_fixmap) + __PAGE_HYPERVISOR .else .quad 0 .endif@@ -158,13 +154,13 @@ l3_xenmap: /* Top-level master (and idle-domain) page directory. */ GLOBAL(idle_pg_table) - .quad sym_phys(l3_bootmap) + __PAGE_HYPERVISOR + .quad sym_offset(l3_bootmap) + __PAGE_HYPERVISOR idx = 1 .rept L4_PAGETABLE_ENTRIES - 1 .if idx == l4_table_offset(DIRECTMAP_VIRT_START) - .quad sym_phys(l3_identmap) + __PAGE_HYPERVISOR + .quad sym_offset(l3_identmap) + __PAGE_HYPERVISOR .elseif idx == l4_table_offset(XEN_VIRT_START) - .quad sym_phys(l3_xenmap) + __PAGE_HYPERVISOR + .quad sym_offset(l3_xenmap) + __PAGE_HYPERVISOR .else .quad 0 .endifxen/arch/x86/setup.c +10
-12@@ -291,9 +291,6 @@ static void *__init bootstrap_map(const module_t *mod)if ( start >= end )return NULL ; -if ( end <=BOOTSTRAP_MAP_BASE ) -return (void *)(unsigned long )start; - ret = (void *)(map_cur + (unsigned long )(start & mask)); start &= ~mask; end = (end + mask) & ~mask;@@ -641,6 +638,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)printk ("Command line: %s\n" , cmdline); +printk ("Xen image base address: 0x%08lx\n" , + xen_phys_start ? xen_phys_start : (unsigned long )xen_img_base_phys_addr); +printk ("Video information:\n" );/* Print VGA display mode information. */ @@ -835,10 +835,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)uint64_t s, e, mask = (1UL <<L2_PAGETABLE_SHIFT ) -1 ;uint64_t end, limit =ARRAY_SIZE (l2_identmap) <<L2_PAGETABLE_SHIFT ; -/* Superpage-aligned chunks from BOOTSTRAP_MAP_BASE. */ s = (boot_e820.map[i].addr + mask) & ~mask; e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask; - s =max_t (uint64_t, s,BOOTSTRAP_MAP_BASE );if ( (boot_e820.map[i].type !=E820_RAM ) || (s >= e) )continue ;@@ -876,7 +874,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)/* Select relocation address. */ e = end - reloc_size; xen_phys_start = e; -bootsym (trampoline_xen_phys_start) = e; +bootsym (trampoline_xen_phys_start) = e - xen_img_base_phys_addr;/* * Perform relocation to new physical address. @@ -886,7 +884,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)*/ load_start = (unsigned long )_start -XEN_VIRT_START ;barrier (); -move_memory (e + load_start, load_start, _end - _start,1 ); +move_memory (e + load_start, load_start + xen_img_base_phys_addr, _end - _start,1 );/* Walk initial pagetables, relocating page directory entries. */ pl4e =__va (__pa (idle_pg_table));@@ -895,27 +893,27 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( !(l4e_get_flags (*pl4e) & _PAGE_PRESENT) )continue ; *pl4e =l4e_from_intpte (l4e_get_intpte (*pl4e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); pl3e =l4e_to_l3e (*pl4e);for ( j =0 ; j <L3_PAGETABLE_ENTRIES ; j++, pl3e++ ) {/* Not present, 1GB mapping, or already relocated? */ if ( !(l3e_get_flags (*pl3e) & _PAGE_PRESENT) || (l3e_get_flags (*pl3e) & _PAGE_PSE) || - (l3e_get_pfn (*pl3e) >0x1000 ) ) + (l3e_get_pfn (*pl3e) >PFN_DOWN (xen_phys_start)) )continue ; *pl3e =l3e_from_intpte (l3e_get_intpte (*pl3e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); pl2e =l3e_to_l2e (*pl3e);for ( k =0 ; k <L2_PAGETABLE_ENTRIES ; k++, pl2e++ ) {/* Not present, PSE, or already relocated? */ if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) || (l2e_get_flags (*pl2e) & _PAGE_PSE) || - (l2e_get_pfn (*pl2e) >0x1000 ) ) + (l2e_get_pfn (*pl2e) >PFN_DOWN (xen_phys_start)) )continue ; *pl2e =l2e_from_intpte (l2e_get_intpte (*pl2e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); } } }
xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 927
Quoted 5 lines
xen/arch/x86/setup.c +1
-1@@ -926,10 +924,10 @@ void __init noreturn __start_xen(unsigned long mbi_p) PAGE_HYPERVISOR_RWX | _PAGE_PSE);for ( i =1 ; i <L2_PAGETABLE_ENTRIES ; i++, pl2e++ ) { -if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) +if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) || (l2e_get_pfn (*pl2e) >PFN_DOWN (xen_phys_start)))
Could this be split in two lines?
Quoted 38 lines
xen/arch/x86/setup.c +5
-4continue ; *pl2e =l2e_from_intpte (l2e_get_intpte (*pl2e) + - xen_phys_start); + xen_phys_start - xen_img_base_phys_addr); }/* Re-sync the stack and then switch to relocated pagetables. */ @@ -998,6 +996,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( !xen_phys_start )panic ("Not enough memory to relocate Xen." ); + +printk ("New Xen image base address: 0x%08lx\n" , xen_phys_start); +reserve_e820_ram (&boot_e820,__pa (&_start),__pa (&_end));/* Late kexec reservation (dynamic start address). */ @@ -1070,14 +1071,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)set_pdx_range (s >>PAGE_SHIFT , e >>PAGE_SHIFT ); -/* Need to create mappings above BOOTSTRAP_MAP_BASE. */ - map_s =max_t (uint64_t, s,BOOTSTRAP_MAP_BASE ); + map_s = s; map_e =min_t (uint64_t, e,ARRAY_SIZE (l2_identmap) <<L2_PAGETABLE_SHIFT );/* Pass mapped memory to allocator /before/ creating new mappings. */ init_boot_pages (s,min (map_s, e)); - s = map_s;if ( s < map_e ) {uint64_t mask = (1UL <<L2_PAGETABLE_SHIFT ) -1 ;xen/arch/x86/x86_64/mm.c +0
-0
xen/arch/x86/x86_64/mm.c unsigned int __read_mostly m2p_compat_vstart = __HYPERVISOR_COMPAT_VIRT_START; · line 48
Quoted 6 lines
xen/arch/x86/x86_64/mm.c +1
-1@@ -44,7 +44,7 @@ unsigned int __read_mostly m2p_compat_vstart = __HYPERVISOR_COMPAT_VIRT_START;/* Enough page directories to map into the bottom 1GB. */ l3_pgentry_t __section(".bss.page_aligned") l3_bootmap[L3_PAGETABLE_ENTRIES]; -l2_pgentry_t __section(".bss.page_aligned") l2_bootmap[L2_PAGETABLE_ENTRIES]; +l2_pgentry_t __section(".bss.page_aligned") l2_bootmap[4 * L2_PAGETABLE_ENTRIES];
16KB?
? Confused.
Quoted 42 lines
xen/arch/x86/x86_64/mm.c +0
-0l2_pgentry_t *compat_idle_pg_table_l2;xen/arch/x86/xen.lds.S +1
-1@@ -38,7 +38,7 @@ SECTIONS . = __XEN_VIRT_START; __image_base__ = .; #endif - . = __XEN_VIRT_START + MB(1); + . = __XEN_VIRT_START + XEN_IMG_OFFSET; _start = .; .text : { _stext = .; /* Text and read-only data */xen/include/asm-x86/config.h +3
-0@@ -114,6 +114,7 @@ extern unsigned long trampoline_phys; trampoline_phys-__pa(trampoline_start)))extern char trampoline_start[], trampoline_end[];extern char trampoline_realmode_entry[]; +extern unsigned int xen_img_base_phys_addr;extern unsigned int trampoline_xen_phys_start;extern unsigned char trampoline_cpu_started;extern char wakeup_start[];@@ -280,6 +281,8 @@ extern unsigned char boot_edid_info[128];#endif #define DIRECTMAP_VIRT_END (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE) +#define XEN_IMG_OFFSET 0x200000 +#ifndef __ASSEMBLY__/* This is not a fixed value, just a lower limit. */ xen/include/asm-x86/page.h +0
-0
xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 286
Quoted 5 lines
xen/include/asm-x86/page.h +1
-1@@ -283,7 +283,7 @@ extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES];extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];
? Why do we need to expand this to be 16kB?
Quoted 11 lines
xen/include/asm-x86/page.h +0
-0extern l3_pgentry_t l3_bootmap[L3_PAGETABLE_ENTRIES ];extern l2_pgentry_t l2_identmap[4 *L2_PAGETABLE_ENTRIES ]; extern l1_pgentry_t l1_identmap[L1_PAGETABLE_ENTRIES],Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 42 lines · Konrad Rzeszutek Wilk
Quoted 11 lines · Daniel Kiper
Every multiboot protocol (regardless of version) compatible image must specify its load address (in ELF or multiboot header). Multiboot protocol compatible loader have to load image at specified address. However, there is no guarantee that the requested memory region (in case of Xen it starts at 1 MiB and ends at 17 MiB) where image should be loaded initially is a RAM and it is free (legacy BIOS platforms are merciful for Xen but I found at least one EFI platform on which Xen load address conflicts with EFI boot services; it is Dell PowerEdge R820 with latest firmware). To cope with that problem we must make Xen early boot code relocatable. This patch does that. However, it does not add multiboot2 protocol interface which is done in next patch.
s/next patch/"x86: add multiboot2 protocol support for relocatable image."
Quoted 12 lines
This patch changes following things:
- default load address is changed from 1 MiB to 2 MiB; I did that because initial page tables are using 2 MiB huge pages and this way required updates for them are quite easy; it means that e.g. we avoid spacial cases for beginning and end of required memory region if it live at address not aligned to 2 MiB,
- %ebp register is used as a storage for Xen image base address; this way we can get this value very quickly if it is needed; however, %ebp register is not used directly to access a given memory region,
- %fs register is filled with segment descriptor which describes memory region with Xen image (it could be relocated or not); it is used to access some of'memory region with Xen image' ? Not sure I follow?
Perhaps:
segment descriptor which starts (0) at Xen image base (_start).Quoted 4 lines
Xen data in early boot code; potentially we can use above mentioned segment descriptor to access data using %ds:%esi and/or %es:%esi (e.g. movs*); however, I think that it could unnecessarily obfuscate code (e.g. we need at least to operations to reload a given segment descriptor) and current solution
s/to/two/ ?
Quoted 3 lines
looks quite optimal.
Signed-off-by Daniel Kiper <[email protected]>
[...]
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/boot/head.S +0
-0
[...]
Quoted 29 lines
Quoted 4 lines
trampoline_bios_setup:xen/arch/x86/boot/head.S +3
-0+ mov %ebp,%esi + + /* Initialise GDT and basic data segments. */xen/arch/x86/boot/head.S multiboot2_proto: · line 338
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ add %ebp,sym_offset(gdt_boot_descr_addr)(%esi) + lgdt sym_offset(gdt_boot_descr)(%esi) + + mov $BOOT_DS,%ecx + mov %ecx,%ds + mov %ecx,%es + mov %ecx,%fs + mov %ecx,%gs + mov %ecx,%ss +The non-EFI boot path is now:
start
\-__start
\-multiboot2_proto
| jmptrampoline_bios_setup
|
\-and if not MB2: jmptrampoline_bios_setup.In here you tweak the GDT and reload the %ds - but during this call chain we do touch the %ds - via:
Quoted 6 lines
__start+27>: testb $0x1,(%rbx)
__start+30>: cmovne 0x4(%rbx),%edxwhich is OK (as MB1 says that the %ds has to cover up to 4GB). But I wonder why the
__startcode had the segments reloaded so early? Was the bootloader not setting the proper segments?
This is very good question. I was asking myself about that thing at least once. Sadly, I cannot find real explanation.
Quoted 2 lines
Let me double-check what SYSLINUX's mboot.c32 does. Perhaps it had done something odd in the past.
Good idea!
Quoted 28 lines
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 359
Quoted 7 lines
/* Set up trampoline segment 64k below EBDA */ movzwl 0x40e,%ecx /* EBDA segment */ cmp $0xa000,%ecx /* sanity check (high) */xen/arch/x86/boot/head.S +0
-0@@ -340,33 +357,58 @@ trampoline_bios_setup: cmovb %edx,%ecx /* and use the smaller */ trampoline_setup:Would it make sense to add:
/* Gets called from EFI (from
x86_32_switch) and legacy (see above) boot loaders. */Quoted 16 lines
xen/arch/x86/boot/head.S +16
-0+ mov %ebp,%esi + + /* Initialize 0-15 bits of BOOT_FS segment descriptor base address. */ + mov %ebp,%edx + shl $16,%edx + or %edx,(sym_offset(trampoline_gdt)+BOOT_FS)(%esi) + + /* Initialize 16-23 bits of BOOT_FS segment descriptor base address. */ + mov %ebp,%edx + shr $16,%edx + and $0x000000ff,%edx + or %edx,(sym_offset(trampoline_gdt)+BOOT_FS+4)(%esi) + + /* Initialize 24-31 bits of BOOT_FS segment descriptor base address. */ + mov %ebp,%edx + and $0xff000000,%edx
Quoted 8 lines
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 381
Quoted 6 lines
xen/arch/x86/boot/head.S +6
-0+ or %edx,(sym_offset(trampoline_gdt)+BOOT_FS+4)(%esi) + + /* Initialize %fs and later use it to access Xen data if possible. */ + mov $BOOT_FS,%edx + mov %edx,%fs +We just modified the GDT. Should we reload it (lgdt?)?
I do not think it is needed.
Intel 64 and IA-32 Architectures Software Developer’s Manual, Volume 2 (2A, 2B & 2C): Instruction Set Reference, A-Z says:
LGDT ... Loads the values in the source operand into the global descriptor table register (GDTR)...
...and ...
MOV ... If the destination operand is a segment register (DS, ES, FS, GS, or SS), the source operand must be a valid segment selector. In protected mode, moving a segment selector into a segment register automatically causes the segment descriptor information associated with that segment selector to be loaded into the hidden (shadow) part of the segment register. While loading this information, the segment selector and segment descriptor information is validated (see the "Operation" algorithm below). The segment descriptor data is obtained from the GDT or LDT entry for the specified segment selector.
Additionally, Intel 64 and IA-32 Architectures Software Developer’s Manual Volume 3 (3A, 3B & 3C): System Programming Guide, section 3.4.3, Segment Registers says:
Every segment register has a "visible" part and a "hidden" part. (The hidden part is sometimes referred to as a "descriptor cache" or a "shadow register.") When a segment selector is loaded into the visible part of a segment register, the processor also loads the hidden part of the segment register with the base address, segment limit, and access control information from the segment descriptor pointed to by the segment selector. The information cached in the segment register (visible and hidden) allows the processor to translate addresses without taking extra bus cycles to read the base address and limit from the segment descriptor. In systems in which multiple processors have access to the same descriptor tables, it is the responsibility of software to reload the segment registers when the descriptor tables are modified (side note:
GDTR reload is not required! probably the same applies to UP systems and if CPU update own active GDT). If this is not done, an old segment descriptor cached in a segment register might be used after its memory-resident version has been modified.
AIUI, only GDT address and limit are loaded into GDTR when lgdt is executed. Segment descriptor is loaded directly from memory into segment register (hiden part) only when relevant load instruction is used (e.g. mov %edx,%fs). Though GDT content probably could be stored in CPU cache but nothing suggest that CPU caching interfere in one way or another with segment descriptor load. So, it looks that every change in active GDT is immediately available for relevant segment descriptor load instruction.
I was not able to find anything which invalidates above. So, everything suggest that we do not need an extra lgdt.
Quoted 2 lines
Quoted 2 lines
xen/arch/x86/boot/head.S +0
-0/* Reserve 64kb for the trampoline. */ sub $0x1000,%ecx
[...]
Quoted 8 lines
xen/arch/x86/boot/head.S trampoline_setup: · line 488
Quoted 6 lines
/* Hook 4kB mappings of first 2MB of memory into L2. */xen/arch/x86/boot/head.S +2
-3- mov $sym_phys(l1_identmap)+__PAGE_HYPERVISOR,%edi - mov %edi,sym_phys(l2_xenmap) - mov %edi,sym_phys(l2_bootmap) + lea (sym_offset(l1_identmap)+__PAGE_HYPERVISOR)(%ebp),%edi + mov %edi,%fs:sym_offset(l2_bootmap)But not to
l2_xenmap?
No, l?_xenmap maps Xen code and data only.
Quoted 6 lines
Quoted 6 lines
/* Apply relocations to bootstrap trampoline. */xen/arch/x86/boot/head.S +3
-2- mov sym_phys(trampoline_phys),%edx - mov $sym_phys(__trampoline_rel_start),%edi + mov %fs:sym_offset(trampoline_phys),%edx + lea sym_offset(__trampoline_rel_start)(%ebp),%edi + lea sym_offset(__trampoline_rel_stop)(%ebp),%esi
[...]
Quoted 4 lines
Quoted 4 lines
xen/include/asm-x86/page.h +0
-0
Quoted 8 lines
xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 286
Quoted 6 lines
xen/include/asm-x86/page.h +1
-1@@ -283,7 +283,7 @@ extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES];extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];? Why do we need to expand this to be 16kB?
TBH, we need 8 KiB in the worst case. The worst case is when next GiB starts (e.g. 1 GiB ends and 2 GiB starts) in the middle of Xen image. In this situation we must hook up lower l2_bootmap table with lower l3_bootmap entry, higher l2_bootmap table with higher l3_bootmap entry and finally fill l2_bootmap relevant tables in proper way. Sadly, this method requires more calculations. To avoid that I have added 3 l2_bootmap tables and simply hook up one after another with relevant l3_bootmap entries. However, if you wish we can reduce number of l2_bootmap tables to two. This way code will be more complicated but we will save about 8 KiB.
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Konrad Rzeszutek WilkQuoted 42 lines · Konrad Rzeszutek Wilk
Quoted 11 lines · Daniel Kiper
Every multiboot protocol (regardless of version) compatible image must specify its load address (in ELF or multiboot header). Multiboot protocol compatible loader have to load image at specified address. However, there is no guarantee that the requested memory region (in case of Xen it starts at 1 MiB and ends at 17 MiB) where image should be loaded initially is a RAM and it is free (legacy BIOS platforms are merciful for Xen but I found at least one EFI platform on which Xen load address conflicts with EFI boot services; it is Dell PowerEdge R820 with latest firmware). To cope with that problem we must make Xen early boot code relocatable. This patch does that. However, it does not add multiboot2 protocol interface which is done in next patch.
s/next patch/"x86: add multiboot2 protocol support for relocatable image."
Quoted 12 lines
This patch changes following things:
- default load address is changed from 1 MiB to 2 MiB; I did that because initial page tables are using 2 MiB huge pages and this way required updates for them are quite easy; it means that e.g. we avoid spacial cases for beginning and end of required memory region if it live at address not aligned to 2 MiB,
- %ebp register is used as a storage for Xen image base address; this way we can get this value very quickly if it is needed; however, %ebp register is not used directly to access a given memory region,
- %fs register is filled with segment descriptor which describes memory region with Xen image (it could be relocated or not); it is used to access some of'memory region with Xen image' ? Not sure I follow?
Perhaps:
segment descriptor which starts (0) at Xen image base (_start).Quoted 4 lines
Xen data in early boot code; potentially we can use above mentioned segment descriptor to access data using %ds:%esi and/or %es:%esi (e.g. movs*); however, I think that it could unnecessarily obfuscate code (e.g. we need at least to operations to reload a given segment descriptor) and current solution
s/to/two/ ?
Quoted 3 lines
looks quite optimal.
Signed-off-by Daniel Kiper <[email protected]>
[...]
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/boot/head.S +0
-0
[...]
Quoted 29 lines
Quoted 4 lines
trampoline_bios_setup:xen/arch/x86/boot/head.S +3
-0+ mov %ebp,%esi + + /* Initialise GDT and basic data segments. */xen/arch/x86/boot/head.S multiboot2_proto: · line 338
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ add %ebp,sym_offset(gdt_boot_descr_addr)(%esi) + lgdt sym_offset(gdt_boot_descr)(%esi) + + mov $BOOT_DS,%ecx + mov %ecx,%ds + mov %ecx,%es + mov %ecx,%fs + mov %ecx,%gs + mov %ecx,%ss +The non-EFI boot path is now:
start
\-__start
\-multiboot2_proto
| jmptrampoline_bios_setup
|
\-and if not MB2: jmptrampoline_bios_setup.In here you tweak the GDT and reload the %ds - but during this call chain we do touch the %ds - via:
Quoted 6 lines
__start+27>: testb $0x1,(%rbx)
__start+30>: cmovne 0x4(%rbx),%edxwhich is OK (as MB1 says that the %ds has to cover up to 4GB). But I wonder why the
__startcode had the segments reloaded so early? Was the bootloader not setting the proper segments?
This is very good question. I was asking myself about that thing at least once. Sadly, I cannot find real explanation.
Quoted 2 lines
Let me double-check what SYSLINUX's mboot.c32 does. Perhaps it had done something odd in the past.
Good idea!
Quoted 28 lines
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 359
Quoted 7 lines
/* Set up trampoline segment 64k below EBDA */ movzwl 0x40e,%ecx /* EBDA segment */ cmp $0xa000,%ecx /* sanity check (high) */xen/arch/x86/boot/head.S +0
-0@@ -340,33 +357,58 @@ trampoline_bios_setup: cmovb %edx,%ecx /* and use the smaller */ trampoline_setup:Would it make sense to add:
/* Gets called from EFI (from
x86_32_switch) and legacy (see above) boot loaders. */Quoted 16 lines
xen/arch/x86/boot/head.S +16
-0+ mov %ebp,%esi + + /* Initialize 0-15 bits of BOOT_FS segment descriptor base address. */ + mov %ebp,%edx + shl $16,%edx + or %edx,(sym_offset(trampoline_gdt)+BOOT_FS)(%esi) + + /* Initialize 16-23 bits of BOOT_FS segment descriptor base address. */ + mov %ebp,%edx + shr $16,%edx + and $0x000000ff,%edx + or %edx,(sym_offset(trampoline_gdt)+BOOT_FS+4)(%esi) + + /* Initialize 24-31 bits of BOOT_FS segment descriptor base address. */ + mov %ebp,%edx + and $0xff000000,%edx
Quoted 8 lines
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 381
Quoted 6 lines
xen/arch/x86/boot/head.S +6
-0+ or %edx,(sym_offset(trampoline_gdt)+BOOT_FS+4)(%esi) + + /* Initialize %fs and later use it to access Xen data if possible. */ + mov $BOOT_FS,%edx + mov %edx,%fs +We just modified the GDT. Should we reload it (lgdt?)?
I do not think it is needed.
Intel 64 and IA-32 Architectures Software Developer’s Manual, Volume 2 (2A, 2B & 2C): Instruction Set Reference, A-Z says:
LGDT ... Loads the values in the source operand into the global descriptor table register (GDTR)...
...and ...
MOV ... If the destination operand is a segment register (DS, ES, FS, GS, or SS), the source operand must be a valid segment selector. In protected mode, moving a segment selector into a segment register automatically causes the segment descriptor information associated with that segment selector to be loaded into the hidden (shadow) part of the segment register. While loading this information, the segment selector and segment descriptor information is validated (see the "Operation" algorithm below). The segment descriptor data is obtained from the GDT or LDT entry for the specified segment selector.
Additionally, Intel 64 and IA-32 Architectures Software Developer’s Manual Volume 3 (3A, 3B & 3C): System Programming Guide, section 3.4.3, Segment Registers says:
Every segment register has a "visible" part and a "hidden" part. (The hidden part is sometimes referred to as a "descriptor cache" or a "shadow register.") When a segment selector is loaded into the visible part of a segment register, the processor also loads the hidden part of the segment register with the base address, segment limit, and access control information from the segment descriptor pointed to by the segment selector. The information cached in the segment register (visible and hidden) allows the processor to translate addresses without taking extra bus cycles to read the base address and limit from the segment descriptor. In systems in which multiple processors have access to the same descriptor tables, it is the responsibility of software to reload the segment registers when the descriptor tables are modified (side note:
GDTR reload is not required! probably the same applies to UP systems and if CPU update own active GDT). If this is not done, an old segment descriptor cached in a segment register might be used after its memory-resident version has been modified.
AIUI, only GDT address and limit are loaded into GDTR when lgdt is executed. Segment descriptor is loaded directly from memory into segment register (hiden part) only when relevant load instruction is used (e.g. mov %edx,%fs). Though GDT content probably could be stored in CPU cache but nothing suggest that CPU caching interfere in one way or another with segment descriptor load. So, it looks that every change in active GDT is immediately available for relevant segment descriptor load instruction.
I was not able to find anything which invalidates above. So, everything suggest that we do not need an extra lgdt.
Quoted 2 lines
Quoted 2 lines
xen/arch/x86/boot/head.S +0
-0/* Reserve 64kb for the trampoline. */ sub $0x1000,%ecx
[...]
Quoted 8 lines
xen/arch/x86/boot/head.S trampoline_setup: · line 488
Quoted 6 lines
/* Hook 4kB mappings of first 2MB of memory into L2. */xen/arch/x86/boot/head.S +2
-3- mov $sym_phys(l1_identmap)+__PAGE_HYPERVISOR,%edi - mov %edi,sym_phys(l2_xenmap) - mov %edi,sym_phys(l2_bootmap) + lea (sym_offset(l1_identmap)+__PAGE_HYPERVISOR)(%ebp),%edi + mov %edi,%fs:sym_offset(l2_bootmap)But not to
l2_xenmap?
No, l?_xenmap maps Xen code and data only.
Quoted 6 lines
Quoted 6 lines
/* Apply relocations to bootstrap trampoline. */xen/arch/x86/boot/head.S +3
-2- mov sym_phys(trampoline_phys),%edx - mov $sym_phys(__trampoline_rel_start),%edi + mov %fs:sym_offset(trampoline_phys),%edx + lea sym_offset(__trampoline_rel_start)(%ebp),%edi + lea sym_offset(__trampoline_rel_stop)(%ebp),%esi
[...]
Quoted 4 lines
Quoted 4 lines
xen/include/asm-x86/page.h +0
-0
Quoted 8 lines
xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 286
Quoted 6 lines
xen/include/asm-x86/page.h +1
-1@@ -283,7 +283,7 @@ extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES];extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];? Why do we need to expand this to be 16kB?
TBH, we need 8 KiB in the worst case. The worst case is when next GiB starts (e.g. 1 GiB ends and 2 GiB starts) in the middle of Xen image. In this situation we must hook up lower l2_bootmap table with lower l3_bootmap entry, higher l2_bootmap table with higher l3_bootmap entry and finally fill l2_bootmap relevant tables in proper way. Sadly, this method requires more calculations. To avoid that I have added 3 l2_bootmap tables and simply hook up one after another with relevant l3_bootmap entries. However, if you wish we can reduce number of l2_bootmap tables to two. This way code will be more complicated but we will save about 8 KiB.
Daniel
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 13:52, <[email protected]> wrote:
Quoted 13 lines · Konrad Rzeszutek Wilk
xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 286
Quoted 10 lines · Daniel Kiper
xen/include/asm-x86/page.h +1
-1@@ -283,7 +283,7 @@ extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES];extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];? Why do we need to expand this to be 16kB?
Quoted 10 lines
TBH, we need 8 KiB in the worst case. The worst case is when next GiB starts (e.g. 1 GiB ends and 2 GiB starts) in the middle of Xen image. In this situation we must hook up lower
l2_bootmaptable with lowerl3_bootmapentry, higherl2_bootmaptable with higherl3_bootmapentry and finally filll2_bootmaprelevant tables in proper way. Sadly, this method requires more calculations. To avoid that I have added 3l2_bootmaptables and simply hook up one after another with relevantl3_bootmapentries. However, if you wish we can reduce number ofl2_bootmaptables to two. This way code will be more complicated but we will save about 8 KiB.
Wouldn't it be better (simpler) to enforce, say, 16Mb alignment in the PE32+ header (which the EFI loader would then honor)?
Jan
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Daniel KiperQuoted 16 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 13:52, <[email protected]> wrote:
Quoted 13 lines · Konrad Rzeszutek Wilk
xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 286
Quoted 10 lines · Daniel Kiper
xen/include/asm-x86/page.h +1
-1@@ -283,7 +283,7 @@ extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES];extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];? Why do we need to expand this to be 16kB?
Quoted 10 lines
TBH, we need 8 KiB in the worst case. The worst case is when next GiB starts (e.g. 1 GiB ends and 2 GiB starts) in the middle of Xen image. In this situation we must hook up lower
l2_bootmaptable with lowerl3_bootmapentry, higherl2_bootmaptable with higherl3_bootmapentry and finally filll2_bootmaprelevant tables in proper way. Sadly, this method requires more calculations. To avoid that I have added 3l2_bootmaptables and simply hook up one after another with relevantl3_bootmapentries. However, if you wish we can reduce number ofl2_bootmaptables to two. This way code will be more complicated but we will save about 8 KiB.
Wouldn't it be better (simpler) to enforce, say, 16Mb alignment in the PE32+ header (which the EFI loader would then honor)?
Jan
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 27 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 13:52, <[email protected]> wrote:
Quoted 13 lines · Konrad Rzeszutek Wilk
xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 286
Quoted 10 lines · Daniel Kiper
xen/include/asm-x86/page.h +1
-1@@ -283,7 +283,7 @@ extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES];extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];? Why do we need to expand this to be 16kB?
Quoted 10 lines
TBH, we need 8 KiB in the worst case. The worst case is when next GiB starts (e.g. 1 GiB ends and 2 GiB starts) in the middle of Xen image. In this situation we must hook up lower
l2_bootmaptable with lowerl3_bootmapentry, higherl2_bootmaptable with higherl3_bootmapentry and finally filll2_bootmaprelevant tables in proper way. Sadly, this method requires more calculations. To avoid that I have added 3l2_bootmaptables and simply hook up one after another with relevantl3_bootmapentries. However, if you wish we can reduce number ofl2_bootmaptables to two. This way code will be more complicated but we will save about 8 KiB.
Quoted 2 lines
Wouldn't it be better (simpler) to enforce, say, 16Mb alignment in the PE32+ header (which the EFI loader would then honor)?
Good idea but then we must enforce this for multiboot protocol (v1 and v2) too. multiboot2 with my patches supports that solution. However, multiboot (v1) could be a bit problematic because it means that we must set load address to 16 MiB. Are we sure that this region is available on all machines like region starting at 1 MiB?
Daniel
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 15:59, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 13:52, <[email protected]> wrote:
Quoted 6 lines · Konrad Rzeszutek Wilk
xen/include/asm-x86/page.h extern root_pgentry_t
Quoted 5 lines · Daniel Kiper
xen/include/asm-x86/page.h +0
-0@@ -283,7 +283,7 @@ extern root_pgentry_tidle_pg_table[ROOT_PAGETABLE_ENTRIES];
Quoted 19 lines
Quoted 8 lines
Quoted 7 lines
xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 286
Quoted 5 lines
xen/include/asm-x86/page.h +1
-1extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];? Why do we need to expand this to be 16kB?
Quoted 10 lines
TBH, we need 8 KiB in the worst case. The worst case is when next GiB starts (e.g. 1 GiB ends and 2 GiB starts) in the middle of Xen image. In this situation we must hook up lower
l2_bootmaptable with lowerl3_bootmapentry, higherl2_bootmaptable with higherl3_bootmapentry and finally filll2_bootmaprelevant tables in proper way. Sadly, this method requires more calculations. To avoid that I have added 3l2_bootmaptables and simply hook up one after another with relevantl3_bootmapentries. However, if you wish we can reduce number ofl2_bootmaptables to two. This way code will be more complicated but we will save about 8 KiB.Quoted 2 lines
Wouldn't it be better (simpler) to enforce, say, 16Mb alignment in the PE32+ header (which the EFI loader would then honor)?
Quoted 9 lines
Good idea but then we must enforce this for multiboot protocol (v1 and v2) too.
multiboot2 with my patches supports that solution. However, multiboot (v1) could
be a bit problematic because it means that we must set load address to 16 MiB.
Are we sure that this region is available on all machines like region starting
at 1 MiB?
"This region" being which one?
Jan
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Daniel KiperQuoted 33 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 15:59, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 13:52, <[email protected]> wrote:
Quoted 6 lines · Konrad Rzeszutek Wilk
xen/include/asm-x86/page.h extern root_pgentry_t
Quoted 5 lines · Daniel Kiper
xen/include/asm-x86/page.h +0
-0@@ -283,7 +283,7 @@ extern root_pgentry_tidle_pg_table[ROOT_PAGETABLE_ENTRIES];
Quoted 19 lines
Quoted 8 lines
Quoted 7 lines
xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 286
Quoted 5 lines
xen/include/asm-x86/page.h +1
-1extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];? Why do we need to expand this to be 16kB?
Quoted 10 lines
TBH, we need 8 KiB in the worst case. The worst case is when next GiB starts (e.g. 1 GiB ends and 2 GiB starts) in the middle of Xen image. In this situation we must hook up lower
l2_bootmaptable with lowerl3_bootmapentry, higherl2_bootmaptable with higherl3_bootmapentry and finally filll2_bootmaprelevant tables in proper way. Sadly, this method requires more calculations. To avoid that I have added 3l2_bootmaptables and simply hook up one after another with relevantl3_bootmapentries. However, if you wish we can reduce number ofl2_bootmaptables to two. This way code will be more complicated but we will save about 8 KiB.Quoted 2 lines
Wouldn't it be better (simpler) to enforce, say, 16Mb alignment in the PE32+ header (which the EFI loader would then honor)?
Quoted 9 lines
Good idea but then we must enforce this for multiboot protocol (v1 and v2) too.
multiboot2 with my patches supports that solution. However, multiboot (v1) could
be a bit problematic because it means that we must set load address to 16 MiB.
Are we sure that this region is available on all machines like region starting
at 1 MiB?
"This region" being which one?
Jan
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 43 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 15:59, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 13:52, <[email protected]> wrote:
Quoted 6 lines · Konrad Rzeszutek Wilk
xen/include/asm-x86/page.h extern root_pgentry_t
Quoted 5 lines · Daniel Kiper
xen/include/asm-x86/page.h +0
-0@@ -283,7 +283,7 @@ extern root_pgentry_tidle_pg_table[ROOT_PAGETABLE_ENTRIES];
Quoted 19 lines
Quoted 8 lines
Quoted 7 lines
xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 286
Quoted 5 lines
xen/include/asm-x86/page.h +1
-1extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];? Why do we need to expand this to be 16kB?
Quoted 10 lines
TBH, we need 8 KiB in the worst case. The worst case is when next GiB starts (e.g. 1 GiB ends and 2 GiB starts) in the middle of Xen image. In this situation we must hook up lower
l2_bootmaptable with lowerl3_bootmapentry, higherl2_bootmaptable with higherl3_bootmapentry and finally filll2_bootmaprelevant tables in proper way. Sadly, this method requires more calculations. To avoid that I have added 3l2_bootmaptables and simply hook up one after another with relevantl3_bootmapentries. However, if you wish we can reduce number ofl2_bootmaptables to two. This way code will be more complicated but we will save about 8 KiB.Quoted 2 lines
Wouldn't it be better (simpler) to enforce, say, 16Mb alignment in the PE32+ header (which the EFI loader would then honor)?
Quoted 9 lines
Good idea but then we must enforce this for multiboot protocol (v1 and v2) too.
multiboot2 with my patches supports that solution. However, multiboot (v1) could
be a bit problematic because it means that we must set load address to 16 MiB.
Are we sure that this region is available on all machines like region starting
at 1 MiB?
Quoted 1 line
"This region" being which one?
16 MiB - 32 MiB.
Daniel
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 45 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 16:37, <[email protected]> wrote:
Quoted 43 lines · Jan Beulich
Quoted 42 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 15:59, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 13:52, <[email protected]> wrote:
Quoted 6 lines · Konrad Rzeszutek Wilk
xen/include/asm-x86/page.h extern root_pgentry_t
Quoted 5 lines · Daniel Kiper
xen/include/asm-x86/page.h +0
-0@@ -283,7 +283,7 @@ extern root_pgentry_tidle_pg_table[ROOT_PAGETABLE_ENTRIES];
Quoted 19 lines
Quoted 8 lines
Quoted 7 lines
xen/include/asm-x86/page.h extern root_pgentry_t · line 286
Quoted 5 lines
xen/include/asm-x86/page.h +1
-1extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];? Why do we need to expand this to be 16kB?
Quoted 10 lines
TBH, we need 8 KiB in the worst case. The worst case is when next GiB starts (e.g. 1 GiB ends and 2 GiB starts) in the middle of Xen image. In this situation we must hook up lower
l2_bootmaptable with lowerl3_bootmapentry, higherl2_bootmaptable with higherl3_bootmapentry and finally filll2_bootmaprelevant tables in proper way. Sadly, this method requires more calculations. To avoid that I have added 3l2_bootmaptables and simply hook up one after another with relevantl3_bootmapentries. However, if you wish we can reduce number ofl2_bootmaptables to two. This way code will be more complicated but we will save about 8 KiB.Quoted 2 lines
Wouldn't it be better (simpler) to enforce, say, 16Mb alignment in the PE32+ header (which the EFI loader would then honor)?
Good idea but then we must enforce this for multiboot protocol (v1 and v2) too.
multiboot2 with my patches supports that solution. However, multiboot (v1) could
be a bit problematic because it means that we must set load address to 16 MiB.
Are we sure that this region is available on all machines like region starting
at 1 MiB?
Quoted 3 lines
Quoted 1 line
"This region" being which one?
16 MiB - 32 MiB.
While I think all systems where Xen can reasonably run on would have memory in that range, I'd really prefer not to touch the MB1 case (i.e. find a way for it to continue to load at 1Mb). Perhaps the 16Mb alignment could be specified only in the PE32+ header, but not enforced in the ELF one?
Jan
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Jan BeulichQuoted 43 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 15:59, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 13:52, <[email protected]> wrote:
Quoted 6 lines · Konrad Rzeszutek Wilk
xen/include/asm-x86/page.h extern root_pgentry_t
Quoted 5 lines · Daniel Kiper
xen/include/asm-x86/page.h +0
-0@@ -283,7 +283,7 @@ extern root_pgentry_tidle_pg_table[ROOT_PAGETABLE_ENTRIES];
Quoted 19 lines
Quoted 8 lines
Quoted 7 lines
xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 286
Quoted 5 lines
xen/include/asm-x86/page.h +1
-1extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];? Why do we need to expand this to be 16kB?
Quoted 10 lines
TBH, we need 8 KiB in the worst case. The worst case is when next GiB starts (e.g. 1 GiB ends and 2 GiB starts) in the middle of Xen image. In this situation we must hook up lower
l2_bootmaptable with lowerl3_bootmapentry, higherl2_bootmaptable with higherl3_bootmapentry and finally filll2_bootmaprelevant tables in proper way. Sadly, this method requires more calculations. To avoid that I have added 3l2_bootmaptables and simply hook up one after another with relevantl3_bootmapentries. However, if you wish we can reduce number ofl2_bootmaptables to two. This way code will be more complicated but we will save about 8 KiB.Quoted 2 lines
Wouldn't it be better (simpler) to enforce, say, 16Mb alignment in the PE32+ header (which the EFI loader would then honor)?
Quoted 9 lines
Good idea but then we must enforce this for multiboot protocol (v1 and v2) too.
multiboot2 with my patches supports that solution. However, multiboot (v1) could
be a bit problematic because it means that we must set load address to 16 MiB.
Are we sure that this region is available on all machines like region starting
at 1 MiB?
Quoted 1 line
"This region" being which one?
16 MiB - 32 MiB.
Daniel
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Jan BeulichQuoted 27 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 13:52, <[email protected]> wrote:
Quoted 13 lines · Konrad Rzeszutek Wilk
xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 286
Quoted 10 lines · Daniel Kiper
xen/include/asm-x86/page.h +1
-1@@ -283,7 +283,7 @@ extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES];extern l2_pgentry_t *compat_idle_pg_table_l2;extern unsigned int m2p_compat_vstart;extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES ], - l2_bootmap[L2_PAGETABLE_ENTRIES ]; + l2_bootmap[4 *L2_PAGETABLE_ENTRIES ];? Why do we need to expand this to be 16kB?
Quoted 10 lines
TBH, we need 8 KiB in the worst case. The worst case is when next GiB starts (e.g. 1 GiB ends and 2 GiB starts) in the middle of Xen image. In this situation we must hook up lower
l2_bootmaptable with lowerl3_bootmapentry, higherl2_bootmaptable with higherl3_bootmapentry and finally filll2_bootmaprelevant tables in proper way. Sadly, this method requires more calculations. To avoid that I have added 3l2_bootmaptables and simply hook up one after another with relevantl3_bootmapentries. However, if you wish we can reduce number ofl2_bootmaptables to two. This way code will be more complicated but we will save about 8 KiB.
Quoted 2 lines
Wouldn't it be better (simpler) to enforce, say, 16Mb alignment in the PE32+ header (which the EFI loader would then honor)?
Good idea but then we must enforce this for multiboot protocol (v1 and v2) too. multiboot2 with my patches supports that solution. However, multiboot (v1) could be a bit problematic because it means that we must set load address to 16 MiB. Are we sure that this region is available on all machines like region starting at 1 MiB?
Daniel
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Daniel KiperQuoted 36 lines
Quoted 29 lines
Quoted 4 lines
trampoline_bios_setup:xen/arch/x86/boot/head.S +3
-0+ mov %ebp,%esi + + /* Initialise GDT and basic data segments. */xen/arch/x86/boot/head.S multiboot2_proto: · line 338
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ add %ebp,sym_offset(gdt_boot_descr_addr)(%esi) + lgdt sym_offset(gdt_boot_descr)(%esi) + + mov $BOOT_DS,%ecx + mov %ecx,%ds + mov %ecx,%es + mov %ecx,%fs + mov %ecx,%gs + mov %ecx,%ss +The non-EFI boot path is now:
start
\-__start
\-multiboot2_proto
| jmptrampoline_bios_setup
|
\-and if not MB2: jmptrampoline_bios_setup.In here you tweak the GDT and reload the %ds - but during this call chain we do touch the %ds - via:
Quoted 6 lines
__start+27>: testb $0x1,(%rbx)
__start+30>: cmovne 0x4(%rbx),%edxwhich is OK (as MB1 says that the %ds has to cover up to 4GB). But I wonder why the
__startcode had the segments reloaded so early? Was the bootloader not setting the proper segments?
Quoted 7 lines
This is very good question. I was asking myself about that thing at least once. Sadly, I cannot find real explanation.
Quoted 2 lines
Let me double-check what SYSLINUX's mboot.c32 does. Perhaps it had done something odd in the past.
Good idea!
Nope, the mboot.c32 COMBOOT images are booted with:
%ds,%es,%fs,%gs : 32-bit data segment with zero base and 4GB limit
So that is OK. Perhaps this code used to be shared with trampoline startup and got copied over.
Anyhow not worried about it.
.. snip..
Quoted 23 lines
Quoted 6 lines
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 381
Quoted 4 lines
xen/arch/x86/boot/head.S +4
-0+ /* Initialize %fs and later use it to access Xen data if possible. */ + mov $BOOT_FS,%edx + mov %edx,%fs +We just modified the GDT. Should we reload it (lgdt?)?
I do not think it is needed.
Intel 64 and IA-32 Architectures Software Developer’s Manual, Volume 2 (2A, 2B & 2C): Instruction Set Reference, A-Z says:
LGDT ... Loads the values in the source operand into the global descriptor table register (GDTR)...
...and ...
MOV ... If the destination operand is a segment register (DS, ES, FS, GS, or SS), the source operand must be a valid segment selector. In protected mode, moving a segment selector into a segment register automatically causes the segment descriptor information associated with that segment selector to be loaded into the hidden (shadow) part of the segment register. While loading this information, the segment
.. snip..
Quoted 5 lines
"shadow register.") When a segment selector is loaded into the visible part of a segment register, the processor also loads the hidden part of the segment register with the base address, segment limit, and access control information from the segment descriptor pointed to by the segment selector. The information cached in the segment register (visible and
Excellent!
Quoted 10 lines
hidden) allows the processor to translate addresses without taking extra bus cycles to read the base address and limit from the segment descriptor. In systems in which multiple processors have access to the same descriptor tables, it is the responsibility of software to reload the segment registers when the descriptor tables are modified (side note:
GDTR reload is not required! probably the same applies to UP systems and if CPU update own active GDT). If this is not done, an old segment descriptor cached in a segment register might be used after its memory-resident version has been modified.
Quoted 3 lines
AIUI, only GDT address and limit are loaded into GDTR when lgdt is executed. Segment descriptor is loaded directly from memory into segment register (hiden part) only when relevant load instruction is used (e.g. mov %edx,%fs).
Yeey!
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Daniel KiperQuoted 36 lines
Quoted 29 lines
Quoted 4 lines
trampoline_bios_setup:xen/arch/x86/boot/head.S +3
-0+ mov %ebp,%esi + + /* Initialise GDT and basic data segments. */xen/arch/x86/boot/head.S multiboot2_proto: · line 338
Quoted 10 lines
xen/arch/x86/boot/head.S +10
-0+ add %ebp,sym_offset(gdt_boot_descr_addr)(%esi) + lgdt sym_offset(gdt_boot_descr)(%esi) + + mov $BOOT_DS,%ecx + mov %ecx,%ds + mov %ecx,%es + mov %ecx,%fs + mov %ecx,%gs + mov %ecx,%ss +The non-EFI boot path is now:
start
\-__start
\-multiboot2_proto
| jmptrampoline_bios_setup
|
\-and if not MB2: jmptrampoline_bios_setup.In here you tweak the GDT and reload the %ds - but during this call chain we do touch the %ds - via:
Quoted 6 lines
__start+27>: testb $0x1,(%rbx)
__start+30>: cmovne 0x4(%rbx),%edxwhich is OK (as MB1 says that the %ds has to cover up to 4GB). But I wonder why the
__startcode had the segments reloaded so early? Was the bootloader not setting the proper segments?
Quoted 7 lines
This is very good question. I was asking myself about that thing at least once. Sadly, I cannot find real explanation.
Quoted 2 lines
Let me double-check what SYSLINUX's mboot.c32 does. Perhaps it had done something odd in the past.
Good idea!
Nope, the mboot.c32 COMBOOT images are booted with:
%ds,%es,%fs,%gs : 32-bit data segment with zero base and 4GB limit
So that is OK. Perhaps this code used to be shared with trampoline startup and got copied over.
Anyhow not worried about it.
.. snip..
Quoted 23 lines
Quoted 6 lines
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 381
Quoted 4 lines
xen/arch/x86/boot/head.S +4
-0+ /* Initialize %fs and later use it to access Xen data if possible. */ + mov $BOOT_FS,%edx + mov %edx,%fs +We just modified the GDT. Should we reload it (lgdt?)?
I do not think it is needed.
Intel 64 and IA-32 Architectures Software Developer’s Manual, Volume 2 (2A, 2B & 2C): Instruction Set Reference, A-Z says:
LGDT ... Loads the values in the source operand into the global descriptor table register (GDTR)...
...and ...
MOV ... If the destination operand is a segment register (DS, ES, FS, GS, or SS), the source operand must be a valid segment selector. In protected mode, moving a segment selector into a segment register automatically causes the segment descriptor information associated with that segment selector to be loaded into the hidden (shadow) part of the segment register. While loading this information, the segment
.. snip..
Quoted 5 lines
"shadow register.") When a segment selector is loaded into the visible part of a segment register, the processor also loads the hidden part of the segment register with the base address, segment limit, and access control information from the segment descriptor pointed to by the segment selector. The information cached in the segment register (visible and
Excellent!
Quoted 10 lines
hidden) allows the processor to translate addresses without taking extra bus cycles to read the base address and limit from the segment descriptor. In systems in which multiple processors have access to the same descriptor tables, it is the responsibility of software to reload the segment registers when the descriptor tables are modified (side note:
GDTR reload is not required! probably the same applies to UP systems and if CPU update own active GDT). If this is not done, an old segment descriptor cached in a segment register might be used after its memory-resident version has been modified.
Quoted 3 lines
AIUI, only GDT address and limit are loaded into GDTR when lgdt is executed. Segment descriptor is loaded directly from memory into segment register (hiden part) only when relevant load instruction is used (e.g. mov %edx,%fs).
Yeey!
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Daniel KiperQuoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
- %fs register is filled with segment descriptor which describes memory region
with Xen image (it could be relocated or not);
This is too fuzzy. Please be very precise which region it is that %fs is supposed to point to (so that reviewers have a chance to validate uses).
xen/arch/x86/Makefile efi-$(x86_64) := $(shell if [ ! -r · line 79
Quoted 13 lines
xen/arch/x86/Makefile +4
-2@@ -72,8 +72,10 @@ efi-$(x86_64) := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ echo '$(TARGET).efi'; fi) $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32 - ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ - `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` +# THIS IS UGLY HACK! PLEASE DO NOT COMPLAIN. I WILL FIX IT IN NEXT RELEASE. + ./boot/mkelf32 $(TARGET)-syms $(TARGET) $(XEN_IMG_PHYS_START) 0xffff82d081000000 +# ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ +# `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'`
I do complain nevertheless: Such a patch should be tagged RFC. And with such a hack in place I'm not even sure it's worth reviewing.
xen/arch/x86/boot/head.S line 16
Quoted 9 lines
xen/arch/x86/boot/head.S +2
-1@@ -12,13 +12,15 @@ .text .code32 -#define sym_phys(sym) ((sym) - __XEN_VIRT_START) +#define sym_phys(sym) ((sym) - __XEN_VIRT_START + XEN_IMG_PHYS_START - XEN_IMG_OFFSET) +#define sym_offset(sym) ((sym) - __XEN_VIRT_START)
With XEN_IMG_PHYS_START == XEN_IMG_OFFSET - what's the point? (If there is a point, then there's obviously a comment missing here explaining things, including when to use which.)
xen/arch/x86/boot/head.S multiboot1_header_end: · line 111
Quoted 8 lines
xen/arch/x86/boot/head.S +2
-2@@ -105,12 +107,13 @@ multiboot1_header_end: .word 0 gdt_boot_descr: - .word 6*8-1 - .long sym_phys(trampoline_gdt) + .word 7*8-1 +gdt_boot_descr_addr:
gdt_boot_base would seem a better name; with C in mind what you use currently could be easily mistaken for a variable holding &gdt_boot_descr.
xen/arch/x86/boot/head.S __start: · line 275
Quoted 12 lines
xen/arch/x86/boot/head.S +2
-6@@ -263,12 +271,8 @@ __start: cld cli - /* Initialise GDT and basic data segments. */ - lgdt %cs:sym_phys(gdt_boot_descr) - mov $BOOT_DS,%ecx - mov %ecx,%ds - mov %ecx,%es - mov %ecx,%ss + /* Load default Xen image base address. */ + mov $sym_phys(__image_base__),%ebp
Isn't this always zero? I.e. wouldn't you better use "xor %ebp,%ebp"?
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 394
Quoted 3 lines
xen/arch/x86/boot/head.S +1
-1/* Save the Multiboot info struct (after relocation) for later use. */ - mov $sym_phys(cpu0_stack)+1024,%esp + lea (sym_offset(cpu0_stack)+1024)(%ebp),%esp
Please avoid obfuscating the code by adding pointless parentheses.
Quoted 123 lines
xen/arch/x86/boot/head.S +59
-20@@ -390,72 +432,111 @@ trampoline_setup: /* Stash TSC to calculate a good approximation of time-since-boot */ rdtsc - mov %eax,sym_phys(boot_tsc_stamp) - mov %edx,sym_phys(boot_tsc_stamp+4) + mov %eax,%fs:sym_offset(boot_tsc_stamp) + mov %edx,%fs:sym_offset(boot_tsc_stamp+4) - /* Initialise L2 boot-map page table entries (16MB). */ - mov $sym_phys(l2_bootmap),%edx - mov $PAGE_HYPERVISOR|_PAGE_PSE,%eax - mov $8,%ecx + /* Update frame addreses in page tables. */ + lea sym_offset(__page_tables_start)(%ebp),%edx + mov $((__page_tables_end-__page_tables_start)/8),%ecx +1: testl $_PAGE_PRESENT,(%edx) + jz 2f + add %ebp,(%edx) +2: add $8,%edx + loop 1b + + /* Initialise L2 boot-map page table entries (14MB). */ + lea sym_offset(l2_bootmap)(%ebp),%edx + lea sym_offset(start)(%ebp),%eax + and $~((1<<L2_PAGETABLE_SHIFT)-1),%eax + mov %eax,%ebx + shr $(L2_PAGETABLE_SHIFT-3),%ebx + and $(L2_PAGETABLE_ENTRIES*4*8-1),%ebx + add %ebx,%edx + add $(PAGE_HYPERVISOR|_PAGE_PSE),%eax + mov $7,%ecx 1: mov %eax,(%edx) add $8,%edx add $(1<<L2_PAGETABLE_SHIFT),%eax loop 1b + /* Initialise L3 boot-map page directory entry. */ - mov $sym_phys(l2_bootmap)+__PAGE_HYPERVISOR,%eax - mov %eax,sym_phys(l3_bootmap) + 0*8 + lea (sym_offset(l2_bootmap)+__PAGE_HYPERVISOR)(%ebp),%eax + lea sym_offset(l3_bootmap)(%ebp),%ebx + mov $4,%ecx +1: mov %eax,(%ebx) + add $8,%ebx + add $(L2_PAGETABLE_ENTRIES*8),%eax + loop 1b + + /* Initialise L2 direct map page table entries (14MB). */ + lea sym_offset(l2_identmap)(%ebp),%edx + lea sym_offset(start)(%ebp),%eax + and $~((1<<L2_PAGETABLE_SHIFT)-1),%eax + mov %eax,%ebx + shr $(L2_PAGETABLE_SHIFT-3),%ebx + and $(L2_PAGETABLE_ENTRIES*4*8-1),%ebx + add %ebx,%edx + add $(PAGE_HYPERVISOR|_PAGE_PSE),%eax + mov $7,%ecx +1: mov %eax,(%edx) + add $8,%edx + add $(1<<L2_PAGETABLE_SHIFT),%eax + loop 1b + /* Hook 4kB mappings of first 2MB of memory into L2. */ - mov $sym_phys(l1_identmap)+__PAGE_HYPERVISOR,%edi - mov %edi,sym_phys(l2_xenmap) - mov %edi,sym_phys(l2_bootmap) + lea (sym_offset(l1_identmap)+__PAGE_HYPERVISOR)(%ebp),%edi + mov %edi,%fs:sym_offset(l2_bootmap) /* Apply relocations to bootstrap trampoline. */ - mov sym_phys(trampoline_phys),%edx - mov $sym_phys(__trampoline_rel_start),%edi + mov %fs:sym_offset(trampoline_phys),%edx + lea sym_offset(__trampoline_rel_start)(%ebp),%edi + lea sym_offset(__trampoline_rel_stop)(%ebp),%esi 1: mov (%edi),%eax add %edx,(%edi,%eax) add $4,%edi - cmp $sym_phys(__trampoline_rel_stop),%edi + cmp %esi,%edi jb 1b /* Patch in the trampoline segment. */ shr $4,%edx - mov $sym_phys(__trampoline_seg_start),%edi + lea sym_offset(__trampoline_seg_start)(%ebp),%edi + lea sym_offset(__trampoline_seg_stop)(%ebp),%esi 1: mov (%edi),%eax mov %dx,(%edi,%eax) add $4,%edi - cmp $sym_phys(__trampoline_seg_stop),%edi + cmp %esi,%edi jb 1b /* Do not parse command line on EFI platform here. */ - cmpb $1,sym_phys(skip_realmode) + cmpb $1,%fs:sym_offset(skip_realmode) je 1f /* Bail if there is no command line to parse. */ - mov sym_phys(multiboot_ptr),%ebx + mov %fs:sym_offset(multiboot_ptr),%ebx testl $MBI_CMDLINE,MB_flags(%ebx) jz 1f cmpl $0,MB_cmdline(%ebx) jz 1f - pushl $sym_phys(early_boot_opts) + lea sym_offset(early_boot_opts)(%ebp),%eax + push %eax pushl MB_cmdline(%ebx) call cmdline_parse_early add $8,%esp /* Remove cmdline_parse_early() args from stack. */ 1: /* Switch to low-memory stack. */ - mov sym_phys(trampoline_phys),%edi + mov %fs:sym_offset(trampoline_phys),%edi lea 0x10000(%edi),%esp
xen/arch/x86/boot/head.S trampoline_setup: · line 542
Quoted 10 lines
xen/arch/x86/boot/head.S +1
-1lea trampoline_boot_cpu_entry-trampoline_start(%edi),%eax pushl $BOOT_CS32 push %eax /* Copy bootstrap trampoline to low memory, below 1MB. */ - mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsb
The latest at this final hunk I'm getting tired (and upset). I'd much rather not touch all this code in these fragile ways, and instead require Xen to be booted without grub2 on badly written firmware like the one on the machine you quote in the description.
Jan
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Daniel KiperQuoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
- %fs register is filled with segment descriptor which describes memory region
with Xen image (it could be relocated or not);
This is too fuzzy. Please be very precise which region it is that %fs is supposed to point to (so that reviewers have a chance to validate uses).
xen/arch/x86/Makefile efi-$(x86_64) := $(shell if [ ! -r · line 79
Quoted 13 lines
xen/arch/x86/Makefile +4
-2@@ -72,8 +72,10 @@ efi-$(x86_64) := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ echo '$(TARGET).efi'; fi) $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32 - ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ - `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` +# THIS IS UGLY HACK! PLEASE DO NOT COMPLAIN. I WILL FIX IT IN NEXT RELEASE. + ./boot/mkelf32 $(TARGET)-syms $(TARGET) $(XEN_IMG_PHYS_START) 0xffff82d081000000 +# ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \ +# `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'`
I do complain nevertheless: Such a patch should be tagged RFC. And with such a hack in place I'm not even sure it's worth reviewing.
xen/arch/x86/boot/head.S line 16
Quoted 9 lines
xen/arch/x86/boot/head.S +2
-1@@ -12,13 +12,15 @@ .text .code32 -#define sym_phys(sym) ((sym) - __XEN_VIRT_START) +#define sym_phys(sym) ((sym) - __XEN_VIRT_START + XEN_IMG_PHYS_START - XEN_IMG_OFFSET) +#define sym_offset(sym) ((sym) - __XEN_VIRT_START)
With XEN_IMG_PHYS_START == XEN_IMG_OFFSET - what's the point? (If there is a point, then there's obviously a comment missing here explaining things, including when to use which.)
xen/arch/x86/boot/head.S multiboot1_header_end: · line 111
Quoted 8 lines
xen/arch/x86/boot/head.S +2
-2@@ -105,12 +107,13 @@ multiboot1_header_end: .word 0 gdt_boot_descr: - .word 6*8-1 - .long sym_phys(trampoline_gdt) + .word 7*8-1 +gdt_boot_descr_addr:
gdt_boot_base would seem a better name; with C in mind what you use currently could be easily mistaken for a variable holding &gdt_boot_descr.
xen/arch/x86/boot/head.S __start: · line 275
Quoted 12 lines
xen/arch/x86/boot/head.S +2
-6@@ -263,12 +271,8 @@ __start: cld cli - /* Initialise GDT and basic data segments. */ - lgdt %cs:sym_phys(gdt_boot_descr) - mov $BOOT_DS,%ecx - mov %ecx,%ds - mov %ecx,%es - mov %ecx,%ss + /* Load default Xen image base address. */ + mov $sym_phys(__image_base__),%ebp
Isn't this always zero? I.e. wouldn't you better use "xor %ebp,%ebp"?
xen/arch/x86/boot/head.S trampoline_bios_setup: · line 394
Quoted 3 lines
xen/arch/x86/boot/head.S +1
-1/* Save the Multiboot info struct (after relocation) for later use. */ - mov $sym_phys(cpu0_stack)+1024,%esp + lea (sym_offset(cpu0_stack)+1024)(%ebp),%esp
Please avoid obfuscating the code by adding pointless parentheses.
Quoted 123 lines
xen/arch/x86/boot/head.S +59
-20@@ -390,72 +432,111 @@ trampoline_setup: /* Stash TSC to calculate a good approximation of time-since-boot */ rdtsc - mov %eax,sym_phys(boot_tsc_stamp) - mov %edx,sym_phys(boot_tsc_stamp+4) + mov %eax,%fs:sym_offset(boot_tsc_stamp) + mov %edx,%fs:sym_offset(boot_tsc_stamp+4) - /* Initialise L2 boot-map page table entries (16MB). */ - mov $sym_phys(l2_bootmap),%edx - mov $PAGE_HYPERVISOR|_PAGE_PSE,%eax - mov $8,%ecx + /* Update frame addreses in page tables. */ + lea sym_offset(__page_tables_start)(%ebp),%edx + mov $((__page_tables_end-__page_tables_start)/8),%ecx +1: testl $_PAGE_PRESENT,(%edx) + jz 2f + add %ebp,(%edx) +2: add $8,%edx + loop 1b + + /* Initialise L2 boot-map page table entries (14MB). */ + lea sym_offset(l2_bootmap)(%ebp),%edx + lea sym_offset(start)(%ebp),%eax + and $~((1<<L2_PAGETABLE_SHIFT)-1),%eax + mov %eax,%ebx + shr $(L2_PAGETABLE_SHIFT-3),%ebx + and $(L2_PAGETABLE_ENTRIES*4*8-1),%ebx + add %ebx,%edx + add $(PAGE_HYPERVISOR|_PAGE_PSE),%eax + mov $7,%ecx 1: mov %eax,(%edx) add $8,%edx add $(1<<L2_PAGETABLE_SHIFT),%eax loop 1b + /* Initialise L3 boot-map page directory entry. */ - mov $sym_phys(l2_bootmap)+__PAGE_HYPERVISOR,%eax - mov %eax,sym_phys(l3_bootmap) + 0*8 + lea (sym_offset(l2_bootmap)+__PAGE_HYPERVISOR)(%ebp),%eax + lea sym_offset(l3_bootmap)(%ebp),%ebx + mov $4,%ecx +1: mov %eax,(%ebx) + add $8,%ebx + add $(L2_PAGETABLE_ENTRIES*8),%eax + loop 1b + + /* Initialise L2 direct map page table entries (14MB). */ + lea sym_offset(l2_identmap)(%ebp),%edx + lea sym_offset(start)(%ebp),%eax + and $~((1<<L2_PAGETABLE_SHIFT)-1),%eax + mov %eax,%ebx + shr $(L2_PAGETABLE_SHIFT-3),%ebx + and $(L2_PAGETABLE_ENTRIES*4*8-1),%ebx + add %ebx,%edx + add $(PAGE_HYPERVISOR|_PAGE_PSE),%eax + mov $7,%ecx +1: mov %eax,(%edx) + add $8,%edx + add $(1<<L2_PAGETABLE_SHIFT),%eax + loop 1b + /* Hook 4kB mappings of first 2MB of memory into L2. */ - mov $sym_phys(l1_identmap)+__PAGE_HYPERVISOR,%edi - mov %edi,sym_phys(l2_xenmap) - mov %edi,sym_phys(l2_bootmap) + lea (sym_offset(l1_identmap)+__PAGE_HYPERVISOR)(%ebp),%edi + mov %edi,%fs:sym_offset(l2_bootmap) /* Apply relocations to bootstrap trampoline. */ - mov sym_phys(trampoline_phys),%edx - mov $sym_phys(__trampoline_rel_start),%edi + mov %fs:sym_offset(trampoline_phys),%edx + lea sym_offset(__trampoline_rel_start)(%ebp),%edi + lea sym_offset(__trampoline_rel_stop)(%ebp),%esi 1: mov (%edi),%eax add %edx,(%edi,%eax) add $4,%edi - cmp $sym_phys(__trampoline_rel_stop),%edi + cmp %esi,%edi jb 1b /* Patch in the trampoline segment. */ shr $4,%edx - mov $sym_phys(__trampoline_seg_start),%edi + lea sym_offset(__trampoline_seg_start)(%ebp),%edi + lea sym_offset(__trampoline_seg_stop)(%ebp),%esi 1: mov (%edi),%eax mov %dx,(%edi,%eax) add $4,%edi - cmp $sym_phys(__trampoline_seg_stop),%edi + cmp %esi,%edi jb 1b /* Do not parse command line on EFI platform here. */ - cmpb $1,sym_phys(skip_realmode) + cmpb $1,%fs:sym_offset(skip_realmode) je 1f /* Bail if there is no command line to parse. */ - mov sym_phys(multiboot_ptr),%ebx + mov %fs:sym_offset(multiboot_ptr),%ebx testl $MBI_CMDLINE,MB_flags(%ebx) jz 1f cmpl $0,MB_cmdline(%ebx) jz 1f - pushl $sym_phys(early_boot_opts) + lea sym_offset(early_boot_opts)(%ebp),%eax + push %eax pushl MB_cmdline(%ebx) call cmdline_parse_early add $8,%esp /* Remove cmdline_parse_early() args from stack. */ 1: /* Switch to low-memory stack. */ - mov sym_phys(trampoline_phys),%edi + mov %fs:sym_offset(trampoline_phys),%edi lea 0x10000(%edi),%esp
xen/arch/x86/boot/head.S trampoline_setup: · line 542
Quoted 10 lines
xen/arch/x86/boot/head.S +1
-1lea trampoline_boot_cpu_entry-trampoline_start(%edi),%eax pushl $BOOT_CS32 push %eax /* Copy bootstrap trampoline to low memory, below 1MB. */ - mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsb
The latest at this final hunk I'm getting tired (and upset). I'd much rather not touch all this code in these fragile ways, and instead require Xen to be booted without grub2 on badly written firmware like the one on the machine you quote in the description.
Jan
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
[...]
Quoted 11 lines
xen/arch/x86/boot/head.S trampoline_setup: · line 541
Quoted 6 lines
/* Copy bootstrap trampoline to low memory, below 1MB. */xen/arch/x86/boot/head.S +1
-1- mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsbThe latest at this final hunk I'm getting tired (and upset). I'd much rather not touch all this code in these fragile ways, and instead require Xen to be booted without grub2 on badly written firmware like the one on the machine you quote in the description.
Let's start discussion from here. My further work on this patch series is pointless until we do not agree details in this case.
So, I agree that any software (including firmware) should not use precious resources (i.e. low memory in that case) if it is not strictly required. And I do not think so that latest UEFI implementations
on new hardware really need this low memory to survive (at least page tables could be put anywhere above low memory). However, in case of UEFI it is a wish of smart people not requirement set by spec. I was checking UEFI docs a few times but I was not able to find anything which says that e.g. "...developer MUST allocate memory outside of low memory ...". Even I have not found any suggestion about that. However, I must admit that I do not know whole UEFI spec, so, if you know something which is similar to above please tell me where it is (title, revision, page, paragraph, etc.). Hence, if there is not strict requirement in regards to memory allocation in specs we are lost. Of course we can encourage people to not do nasty things but I do not believe that many will listen. So, sadly, I suppose that we will see more and more machines in the wild which are "broken" (well, let's say do not align to good practices).
On the other hand I think that we should not assume that a given memory region (in our case starting at 1 MiB) is (or will be) available in every machine. I have not seen anything which says that it is true. We should stop doing that even if it works right now. I think that it works by chance and there is a chance that it will stop working one day because somebody will discover that he or she can put there e.g. device or hole.
Last but not least. I suppose that Xen users and especially distros will complain when they are not able to use GRUB2 with Xen on every platform just because somebody (i.e. platform designers, developers, or whatever) do not accept our beliefs or we require that platform must obey rules (i.e. memory map requirements) which are specified nowhere.
So, I think that early Xen boot code should be relocatable. However, I agree that there is a chance that may solution is not perfect. So, I suppose, taking into account above, we should discuss how to improve it instead of discussing whether we should do it.
Daniel
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Jan BeulichQuoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
[...]
Quoted 11 lines
xen/arch/x86/boot/head.S trampoline_setup: · line 541
Quoted 6 lines
/* Copy bootstrap trampoline to low memory, below 1MB. */xen/arch/x86/boot/head.S +1
-1- mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsbThe latest at this final hunk I'm getting tired (and upset). I'd much rather not touch all this code in these fragile ways, and instead require Xen to be booted without grub2 on badly written firmware like the one on the machine you quote in the description.
Let's start discussion from here. My further work on this patch series is pointless until we do not agree details in this case.
So, I agree that any software (including firmware) should not use precious resources (i.e. low memory in that case) if it is not strictly required. And I do not think so that latest UEFI implementations
on new hardware really need this low memory to survive (at least page tables could be put anywhere above low memory). However, in case of UEFI it is a wish of smart people not requirement set by spec. I was checking UEFI docs a few times but I was not able to find anything which says that e.g. "...developer MUST allocate memory outside of low memory ...". Even I have not found any suggestion about that. However, I must admit that I do not know whole UEFI spec, so, if you know something which is similar to above please tell me where it is (title, revision, page, paragraph, etc.). Hence, if there is not strict requirement in regards to memory allocation in specs we are lost. Of course we can encourage people to not do nasty things but I do not believe that many will listen. So, sadly, I suppose that we will see more and more machines in the wild which are "broken" (well, let's say do not align to good practices).
On the other hand I think that we should not assume that a given memory region (in our case starting at 1 MiB) is (or will be) available in every machine. I have not seen anything which says that it is true. We should stop doing that even if it works right now. I think that it works by chance and there is a chance that it will stop working one day because somebody will discover that he or she can put there e.g. device or hole.
Last but not least. I suppose that Xen users and especially distros will complain when they are not able to use GRUB2 with Xen on every platform just because somebody (i.e. platform designers, developers, or whatever) do not accept our beliefs or we require that platform must obey rules (i.e. memory map requirements) which are specified nowhere.
So, I think that early Xen boot code should be relocatable. However, I agree that there is a chance that may solution is not perfect. So, I suppose, taking into account above, we should discuss how to improve it instead of discussing whether we should do it.
Daniel
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 43 lines
Quoted 1 line
Quoted 1 line · On 27.08.15 at 17:10, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
xen/arch/x86/boot/head.S trampoline_setup: · line 541
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
/* Copy bootstrap trampoline to low memory, below 1MB. */xen/arch/x86/boot/head.S +1
-1- mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsbQuoted 4 lines
The latest at this final hunk I'm getting tired (and upset). I'd much rather not touch all this code in these fragile ways, and instead require Xen to be booted without grub2 on badly written firmware like the one on the machine you quote in the description.
Let's start discussion from here. My further work on this patch series is pointless until we do not agree details in this case.
So, I agree that any software (including firmware) should not use precious resources (i.e. low memory in that case) if it is not strictly required. And I do not think so that latest UEFI implementations on new hardware really need this low memory to survive (at least page tables could be put anywhere above low memory). However, in case of UEFI it is a wish of smart people not requirement set by spec. I was checking UEFI docs a few times but I was not able to find anything which says that e.g. "...developer MUST allocate memory outside of low memory ...". Even I have not found any suggestion about that. However, I must admit that I do not know whole UEFI spec, so, if you know something which is similar to above please tell me where it is (title, revision, page, paragraph, etc.). Hence, if there is not strict requirement in regards to memory allocation in specs we are lost. Of course we can encourage people to not do nasty things but I do not believe that many will listen. So, sadly, I suppose that we will see more and more machines in the wild which are "broken" (well, let's say do not align to good practices).
On the other hand I think that we should not assume that a given memory region (in our case starting at 1 MiB) is (or will be) available in every machine. I have not seen anything which says that it is true. We should stop doing that even if it works right now. I think that it works by chance and there is a chance that it will stop working one day because somebody will discover that he or she can put there e.g. device or hole.
Quoted 5 lines
Last but not least. I suppose that Xen users and especially distros will complain when they are not able to use GRUB2 with Xen on every platform just because somebody (i.e. platform designers, developers, or whatever) do not accept our beliefs or we require that platform must obey rules (i.e. memory map requirements) which are specified nowhere.
You're right, there's no such requirement on memory use in the spec. But you're missing the point. Supporting grub2 on UEFI is already a hack (ignoring all intentions EFI had from its first days). And now you've found an environment where that hack needs another hack (in Xen) to actually work. That's too much hackery for my taste, the more that things on this system can (afaict) work quite okay (without grub2, or with using its chainloader mechanism).
So no, I'm still not convinced of the need for this patch.
Jan
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Daniel KiperQuoted 43 lines
Quoted 1 line
Quoted 1 line · On 27.08.15 at 17:10, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
xen/arch/x86/boot/head.S trampoline_setup: · line 541
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
/* Copy bootstrap trampoline to low memory, below 1MB. */xen/arch/x86/boot/head.S +1
-1- mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsbQuoted 4 lines
The latest at this final hunk I'm getting tired (and upset). I'd much rather not touch all this code in these fragile ways, and instead require Xen to be booted without grub2 on badly written firmware like the one on the machine you quote in the description.
Let's start discussion from here. My further work on this patch series is pointless until we do not agree details in this case.
So, I agree that any software (including firmware) should not use precious resources (i.e. low memory in that case) if it is not strictly required. And I do not think so that latest UEFI implementations on new hardware really need this low memory to survive (at least page tables could be put anywhere above low memory). However, in case of UEFI it is a wish of smart people not requirement set by spec. I was checking UEFI docs a few times but I was not able to find anything which says that e.g. "...developer MUST allocate memory outside of low memory ...". Even I have not found any suggestion about that. However, I must admit that I do not know whole UEFI spec, so, if you know something which is similar to above please tell me where it is (title, revision, page, paragraph, etc.). Hence, if there is not strict requirement in regards to memory allocation in specs we are lost. Of course we can encourage people to not do nasty things but I do not believe that many will listen. So, sadly, I suppose that we will see more and more machines in the wild which are "broken" (well, let's say do not align to good practices).
On the other hand I think that we should not assume that a given memory region (in our case starting at 1 MiB) is (or will be) available in every machine. I have not seen anything which says that it is true. We should stop doing that even if it works right now. I think that it works by chance and there is a chance that it will stop working one day because somebody will discover that he or she can put there e.g. device or hole.
Quoted 5 lines
Last but not least. I suppose that Xen users and especially distros will complain when they are not able to use GRUB2 with Xen on every platform just because somebody (i.e. platform designers, developers, or whatever) do not accept our beliefs or we require that platform must obey rules (i.e. memory map requirements) which are specified nowhere.
You're right, there's no such requirement on memory use in the spec. But you're missing the point. Supporting grub2 on UEFI is already a hack (ignoring all intentions EFI had from its first days). And now you've found an environment where that hack needs another hack (in Xen) to actually work. That's too much hackery for my taste, the more that things on this system can (afaict) work quite okay (without grub2, or with using its chainloader mechanism).
So no, I'm still not convinced of the need for this patch.
Jan
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 58 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 27.08.15 at 17:10, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
xen/arch/x86/boot/head.S trampoline_setup: · line 541
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
/* Copy bootstrap trampoline to low memory, below 1MB. */xen/arch/x86/boot/head.S +1
-1- mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsbQuoted 4 lines
The latest at this final hunk I'm getting tired (and upset). I'd much rather not touch all this code in these fragile ways, and instead require Xen to be booted without grub2 on badly written firmware like the one on the machine you quote in the description.
Let's start discussion from here. My further work on this patch series is pointless until we do not agree details in this case.
Quoted 10 lines
So, I agree that any software (including firmware) should not use precious resources (i.e. low memory in that case) if it is not strictly required. And I do not think so that latest UEFI implementations on new hardware really need this low memory to survive (at least page tables could be put anywhere above low memory). However, in case of UEFI it is a wish of smart people not requirement set by spec. I was checking UEFI docs a few times but I was not able to find anything which says that e.g. "...developer MUST allocate memory outside of low memory ...". Even I have not found any suggestion about that. However, I must admit that I do not know whole UEFI spec, so, if you know
something
Quoted 15 lines
which is similar to above please tell me where it is (title, revision, page, paragraph, etc.). Hence, if there is not strict requirement in regards to memory allocation in specs we are lost. Of course we can encourage people to not do nasty things but I do not believe that many will listen. So, sadly, I suppose that we will see more and more machines in the wild which are "broken" (well, let's say do not align to good practices).
On the other hand I think that we should not assume that a given memory region (in our case starting at 1 MiB) is (or will be) available in every machine. I have not seen anything which says that it is true. We should stop doing that even if it works right now. I think that it works by chance and there is a chance that it will stop working one day because somebody will discover that he or she can put there e.g. device or hole.
Quoted 5 lines
Last but not least. I suppose that Xen users and especially distros will complain when they are not able to use GRUB2 with Xen on every platform just because somebody (i.e. platform designers, developers, or whatever) do not accept our beliefs or we require that platform must obey rules (i.e. memory map requirements) which are specified nowhere.
You're right, there's no such requirement on memory use in the spec. But you're missing the point. Supporting grub2 on UEFI is already a hack (ignoring all intentions EFI had from its first days). And now you've found an environment where that hack needs another hack (in Xen) to actually work. That's too much hackery for my taste, the more that things on this system can (afaict) work quite okay (without grub2, or with using its chainloader mechanism).
Quoted 1 line
If you advocate direct booting ( no boot loader) on production machines I
wont argue much, as long as there is good recovery tools to deal with failed boots (grub does this very well, I am not aware of anything comparable that is pure efi). however the other use case which care more about is dual booting. I am a novice when it comes to Xen, although otherwise competent. The test machines I have for playing with Xen are also used for other tests, some of which require raw hardware support, so I want the ability to use a boot menu. I am aware of refit, but it does not have serial support which makes automating testing more difficult. and I have not yet got ipxe to successfully boot Xen (although this is purely because I have not yet devoted enough time to that project and I am not yet familiar with how Xen boots).
So no, I'm still not convinced of the need for this patch.
Quoted 1 line
I am at a loss for alternatives. Yes grub on efi violates the spirit of efi. Propose a better way forward rather than deriding those who have found a successful, portable way around the limitations of efi implementations.
Quoted 9 lines
Jan
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
-- Ben Hildred Automation Support Services 303 815 6721
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 9 lines
Quoted 2 lines
Quoted 1 line · On 27.08.15 at 19:56, <[email protected]> wrote:
If you advocate direct booting ( no boot loader) on production machines I
wont argue much, as long as there is good recovery tools to deal with failed boots (grub does this very well, I am not aware of anything comparable that is pure efi). however the other use case which care more about is dual booting. I am a novice when it comes to Xen, although otherwise competent. The test machines I have for playing with Xen are also used for other tests, some of which require raw hardware support, so I want the ability to use a boot menu.
All EFI systems that I've seen so far have a boot manager. Are you saying there are vendors who remove that?
Jan
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Ben HildredQuoted 9 lines
Quoted 2 lines
Quoted 1 line · On 27.08.15 at 19:56, <[email protected]> wrote:
If you advocate direct booting ( no boot loader) on production machines I
wont argue much, as long as there is good recovery tools to deal with failed boots (grub does this very well, I am not aware of anything comparable that is pure efi). however the other use case which care more about is dual booting. I am a novice when it comes to Xen, although otherwise competent. The test machines I have for playing with Xen are also used for other tests, some of which require raw hardware support, so I want the ability to use a boot menu.
All EFI systems that I've seen so far have a boot manager. Are you saying there are vendors who remove that?
Jan
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 10 lines · Jan Beulich
Quoted 9 lines
Quoted 2 lines
Quoted 1 line · On 27.08.15 at 19:56, <[email protected]> wrote:
If you advocate direct booting ( no boot loader) on production machines I
wont argue much, as long as there is good recovery tools to deal with failed boots (grub does this very well, I am not aware of anything comparable that is pure efi). however the other use case which care more about is dual booting. I am a novice when it comes to Xen, although otherwise competent. The test machines I have for playing with Xen are also used for other tests, some of which require raw hardware support, so I want the ability to use a boot menu.
Quoted 2 lines
All EFI systems that I've seen so far have a boot manager. Are you saying there are vendors who remove that?
Worst. There are some where the boot managers <cough>certain families of AMI based BIOSes</cough> which delete all but the last boot entry to only have _one_ boot entry per ESP. No DualBoot for you!
The 'boot manager' in question is an boot entry (F8 or F12), which does not allow any changes (change the parameters, etc) - just select the entry.
Furthermore my recollection is Microsoft has a 'boot configuration manager' after EFI boots - you hit F8 and you can select which options you want to boot Windows with.
We need that functionality and we can't depend on EFI getting it right - hence need GRUB. It would be fantastic if everybody fixed their EFI firmware but since some of these for SMI have 'O.E.M vendor should
put information here' (or whatever it says) - it makes me think they don't care the sligthest after the product has been released.
And I am not comfortable to say 'GRUB2+Xen cannot run on this hardware because your firmware vendor is not following the EFI spec in spirit.'
Now that said - do you have suggestions on how to make this work with GRUB in the picture?
Thank you.
Quoted 7 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Jan BeulichQuoted 10 lines · Jan Beulich
Quoted 9 lines
Quoted 2 lines
Quoted 1 line · On 27.08.15 at 19:56, <[email protected]> wrote:
If you advocate direct booting ( no boot loader) on production machines I
wont argue much, as long as there is good recovery tools to deal with failed boots (grub does this very well, I am not aware of anything comparable that is pure efi). however the other use case which care more about is dual booting. I am a novice when it comes to Xen, although otherwise competent. The test machines I have for playing with Xen are also used for other tests, some of which require raw hardware support, so I want the ability to use a boot menu.
Quoted 2 lines
All EFI systems that I've seen so far have a boot manager. Are you saying there are vendors who remove that?
Worst. There are some where the boot managers <cough>certain families of AMI based BIOSes</cough> which delete all but the last boot entry to only have _one_ boot entry per ESP. No DualBoot for you!
The 'boot manager' in question is an boot entry (F8 or F12), which does not allow any changes (change the parameters, etc) - just select the entry.
Furthermore my recollection is Microsoft has a 'boot configuration manager' after EFI boots - you hit F8 and you can select which options you want to boot Windows with.
We need that functionality and we can't depend on EFI getting it right - hence need GRUB. It would be fantastic if everybody fixed their EFI firmware but since some of these for SMI have 'O.E.M vendor should
put information here' (or whatever it says) - it makes me think they don't care the sligthest after the product has been released.
And I am not comfortable to say 'GRUB2+Xen cannot run on this hardware because your firmware vendor is not following the EFI spec in spirit.'
Now that said - do you have suggestions on how to make this work with GRUB in the picture?
Thank you.
Quoted 7 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 28.08.15 at 15:42, <[email protected]> wrote:
And I am not comfortable to say 'GRUB2+Xen cannot run on this hardware because your firmware vendor is not following the EFI spec in spirit.'
Well, not the least since I don't really agree with this (albeit I can see where you're coming from) ...
Quoted 2 lines
Now that said - do you have suggestions on how to make this work with GRUB in the picture?
... I don't think I'm the one to make suggestions on how to make things work with grub in the picture when I continue to be of the opinion that it shouldn't have been brought into the picture in the first place.
But for the purely technical (patch) aspect: Anything (e.g. macroization such that at least some sym_phys() uses can remain untouched) allowing to limit the impact of said patch on the source code (thus helping review and perhaps also long term maintainability) would be a step towards talking me into withdrawing my objection.
Jan
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 28.08.15 at 15:42, <[email protected]> wrote:
And I am not comfortable to say 'GRUB2+Xen cannot run on this hardware because your firmware vendor is not following the EFI spec in spirit.'
Well, not the least since I don't really agree with this (albeit I can see where you're coming from) ...
Quoted 7 lines
Quoted 2 lines
Now that said - do you have suggestions on how to make this work with GRUB in the picture?
... I don't think I'm the one to make suggestions on how to make things work with grub in the picture when I continue to be of the opinion that it shouldn't have been brought into the picture in the first place.
Could you be more specific what is wrong with this patch or at least last hunk which you reviewed? What is real technical reason that it could not be accepted? If idea is wrong in general please tell me where and why. Otherwise I am not able to work out other better solution.
By the way, once I have put 3 (IIRC) proposals for this problem on the table. Even we discussed this issue in Shanghai. You and Andrew approved more or less this one. So, I am a bit disappointed that you withdraw your approval (yes, partial but still the approval) at this stage with just vague explanations. Though I am not trying to argue that this patch is fully correct. For sure it could be improved but I do not think that this invalidates idea as whole.
Quoted 6 lines
But for the purely technical (patch) aspect: Anything (e.g. macroization such that at least some
sym_phys()uses can remain untouched) allowing to limit the impact of said patch on the source code (thus helping review and perhaps also long term maintainability) would be a step towards talking me into withdrawing my objection.
Ditto. This is too vague. So, I will be very grateful if you review this patch until the end or at least tell me what (if you add why it will be nice) exactly should be fixed.
Daniel
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Jan BeulichQuoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 28.08.15 at 15:42, <[email protected]> wrote:
And I am not comfortable to say 'GRUB2+Xen cannot run on this hardware because your firmware vendor is not following the EFI spec in spirit.'
Well, not the least since I don't really agree with this (albeit I can see where you're coming from) ...
Quoted 7 lines
Quoted 2 lines
Now that said - do you have suggestions on how to make this work with GRUB in the picture?
... I don't think I'm the one to make suggestions on how to make things work with grub in the picture when I continue to be of the opinion that it shouldn't have been brought into the picture in the first place.
Could you be more specific what is wrong with this patch or at least last hunk which you reviewed? What is real technical reason that it could not be accepted? If idea is wrong in general please tell me where and why. Otherwise I am not able to work out other better solution.
By the way, once I have put 3 (IIRC) proposals for this problem on the table. Even we discussed this issue in Shanghai. You and Andrew approved more or less this one. So, I am a bit disappointed that you withdraw your approval (yes, partial but still the approval) at this stage with just vague explanations. Though I am not trying to argue that this patch is fully correct. For sure it could be improved but I do not think that this invalidates idea as whole.
Quoted 6 lines
But for the purely technical (patch) aspect: Anything (e.g. macroization such that at least some
sym_phys()uses can remain untouched) allowing to limit the impact of said patch on the source code (thus helping review and perhaps also long term maintainability) would be a step towards talking me into withdrawing my objection.
Ditto. This is too vague. So, I will be very grateful if you review this patch until the end or at least tell me what (if you add why it will be nice) exactly should be fixed.
Daniel
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 31.08.15 at 21:49, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 28.08.15 at 15:42, <[email protected]> wrote:
Now that said - do you have suggestions on how to make this work with GRUB in the picture?
... I don't think I'm the one to make suggestions on how to make things work with grub in the picture when I continue to be of the opinion that it shouldn't have been brought into the picture in the first place.
Quoted 4 lines
Could you be more specific what is wrong with this patch or at least last hunk which you reviewed? What is real technical reason that it could not be accepted? If idea is wrong in general please tell me where and why. Otherwise I am not able to work out other better solution.
The patch may not be wrong technically (and I never said so), it is just that the way you carry things out is too intrusive for my taste. Since Andrew is happy with the change in principle, I think I wouldn't veto it going in with his R-b.
Quoted 6 lines
By the way, once I have put 3 (IIRC) proposals for this problem on the table.
Even we discussed this issue in Shanghai. You and Andrew approved more or less this one. So, I am a bit disappointed that you withdraw your approval (yes, partial but still the approval) at this stage with just vague explanations.
I've never approved of anything here. At the hackathon we've only hashed out possible options.
Quoted 10 lines
Quoted 6 lines
But for the purely technical (patch) aspect: Anything (e.g. macroization such that at least some
sym_phys()uses can remain untouched) allowing to limit the impact of said patch on the source code (thus helping review and perhaps also long term maintainability) would be a step towards talking me into withdrawing my objection.Ditto. This is too vague. So, I will be very grateful if you review this patch until the end or at least tell me what (if you add why it will be nice) exactly should be fixed.
How is this to vague? I gave a possible direction (macroization) as well as the criteria (less impact on existing code; to be slightly more precise I'd specifically like to see most of the open coded %fs: uses gone).
Again - if Andrew thinks this is the right thing to do, I'll defer to him for reviewing these final few patches of the series, since as said before to me this is a workaround for a misguided design, and as such I'm not willing to accept as intrusive a patch as this one is. (And no, I don't really buy his argument of Xen boot code needing to be relocatable anyway - the legacy boot path doesn't really need to fear there not being free memory right above 1Mb. At least I have seen no proof of there being any system [supporting legacy boot] where Xen can't boot that way. And even if there was, it would still need to be determined whether this is legitimately so, or again due to poorly written firmware.)
Jan
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Daniel KiperQuoted 11 lines
Quoted 1 line
Quoted 1 line · On 31.08.15 at 21:49, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 28.08.15 at 15:42, <[email protected]> wrote:
Now that said - do you have suggestions on how to make this work with GRUB in the picture?
... I don't think I'm the one to make suggestions on how to make things work with grub in the picture when I continue to be of the opinion that it shouldn't have been brought into the picture in the first place.
Quoted 4 lines
Could you be more specific what is wrong with this patch or at least last hunk which you reviewed? What is real technical reason that it could not be accepted? If idea is wrong in general please tell me where and why. Otherwise I am not able to work out other better solution.
The patch may not be wrong technically (and I never said so), it is just that the way you carry things out is too intrusive for my taste. Since Andrew is happy with the change in principle, I think I wouldn't veto it going in with his R-b.
Quoted 6 lines
By the way, once I have put 3 (IIRC) proposals for this problem on the table.
Even we discussed this issue in Shanghai. You and Andrew approved more or less this one. So, I am a bit disappointed that you withdraw your approval (yes, partial but still the approval) at this stage with just vague explanations.
I've never approved of anything here. At the hackathon we've only hashed out possible options.
Quoted 10 lines
Quoted 6 lines
But for the purely technical (patch) aspect: Anything (e.g. macroization such that at least some
sym_phys()uses can remain untouched) allowing to limit the impact of said patch on the source code (thus helping review and perhaps also long term maintainability) would be a step towards talking me into withdrawing my objection.Ditto. This is too vague. So, I will be very grateful if you review this patch until the end or at least tell me what (if you add why it will be nice) exactly should be fixed.
How is this to vague? I gave a possible direction (macroization) as well as the criteria (less impact on existing code; to be slightly more precise I'd specifically like to see most of the open coded %fs: uses gone).
Again - if Andrew thinks this is the right thing to do, I'll defer to him for reviewing these final few patches of the series, since as said before to me this is a workaround for a misguided design, and as such I'm not willing to accept as intrusive a patch as this one is. (And no, I don't really buy his argument of Xen boot code needing to be relocatable anyway - the legacy boot path doesn't really need to fear there not being free memory right above 1Mb. At least I have seen no proof of there being any system [supporting legacy boot] where Xen can't boot that way. And even if there was, it would still need to be determined whether this is legitimately so, or again due to poorly written firmware.)
Jan
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Jan BeulichQuoted 58 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 27.08.15 at 17:10, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
xen/arch/x86/boot/head.S trampoline_setup: · line 541
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
/* Copy bootstrap trampoline to low memory, below 1MB. */xen/arch/x86/boot/head.S +1
-1- mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsbQuoted 4 lines
The latest at this final hunk I'm getting tired (and upset). I'd much rather not touch all this code in these fragile ways, and instead require Xen to be booted without grub2 on badly written firmware like the one on the machine you quote in the description.
Let's start discussion from here. My further work on this patch series is pointless until we do not agree details in this case.
Quoted 10 lines
So, I agree that any software (including firmware) should not use precious resources (i.e. low memory in that case) if it is not strictly required. And I do not think so that latest UEFI implementations on new hardware really need this low memory to survive (at least page tables could be put anywhere above low memory). However, in case of UEFI it is a wish of smart people not requirement set by spec. I was checking UEFI docs a few times but I was not able to find anything which says that e.g. "...developer MUST allocate memory outside of low memory ...". Even I have not found any suggestion about that. However, I must admit that I do not know whole UEFI spec, so, if you know
something
Quoted 15 lines
which is similar to above please tell me where it is (title, revision, page, paragraph, etc.). Hence, if there is not strict requirement in regards to memory allocation in specs we are lost. Of course we can encourage people to not do nasty things but I do not believe that many will listen. So, sadly, I suppose that we will see more and more machines in the wild which are "broken" (well, let's say do not align to good practices).
On the other hand I think that we should not assume that a given memory region (in our case starting at 1 MiB) is (or will be) available in every machine. I have not seen anything which says that it is true. We should stop doing that even if it works right now. I think that it works by chance and there is a chance that it will stop working one day because somebody will discover that he or she can put there e.g. device or hole.
Quoted 5 lines
Last but not least. I suppose that Xen users and especially distros will complain when they are not able to use GRUB2 with Xen on every platform just because somebody (i.e. platform designers, developers, or whatever) do not accept our beliefs or we require that platform must obey rules (i.e. memory map requirements) which are specified nowhere.
You're right, there's no such requirement on memory use in the spec. But you're missing the point. Supporting grub2 on UEFI is already a hack (ignoring all intentions EFI had from its first days). And now you've found an environment where that hack needs another hack (in Xen) to actually work. That's too much hackery for my taste, the more that things on this system can (afaict) work quite okay (without grub2, or with using its chainloader mechanism).
Quoted 1 line
If you advocate direct booting ( no boot loader) on production machines I
wont argue much, as long as there is good recovery tools to deal with failed boots (grub does this very well, I am not aware of anything comparable that is pure efi). however the other use case which care more about is dual booting. I am a novice when it comes to Xen, although otherwise competent. The test machines I have for playing with Xen are also used for other tests, some of which require raw hardware support, so I want the ability to use a boot menu. I am aware of refit, but it does not have serial support which makes automating testing more difficult. and I have not yet got ipxe to successfully boot Xen (although this is purely because I have not yet devoted enough time to that project and I am not yet familiar with how Xen boots).
So no, I'm still not convinced of the need for this patch.
Quoted 1 line
I am at a loss for alternatives. Yes grub on efi violates the spirit of efi. Propose a better way forward rather than deriding those who have found a successful, portable way around the limitations of efi implementations.
Quoted 9 lines
Jan
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
-- Ben Hildred Automation Support Services 303 815 6721
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Jan BeulichQuoted 54 lines · Jan Beulich
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 27.08.15 at 17:10, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
xen/arch/x86/boot/head.S trampoline_setup: · line 541
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
/* Copy bootstrap trampoline to low memory, below 1MB. */xen/arch/x86/boot/head.S +1
-1- mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsbThe latest at this final hunk I'm getting tired (and upset). I'd much rather not touch all this code in these fragile ways, and instead require Xen to be booted without grub2 on badly written firmware like the one on the machine you quote in the description.
Let's start discussion from here. My further work on this patch series is pointless until we do not agree details in this case.
So, I agree that any software (including firmware) should not use precious resources (i.e. low memory in that case) if it is not strictly required. And I do not think so that latest UEFI implementations on new hardware really need this low memory to survive (at least page tables could be put anywhere above low memory). However, in case of UEFI it is a wish of smart people not requirement set by spec. I was checking UEFI docs a few times but I was not able to find anything which says that e.g. "...developer MUST allocate memory outside of low memory ...". Even I have not found any suggestion about that. However, I must admit that I do not know whole UEFI spec, so, if you know something which is similar to above please tell me where it is (title, revision, page, paragraph, etc.). Hence, if there is not strict requirement in regards to memory allocation in specs we are lost. Of course we can encourage people to not do nasty things but I do not believe that many will listen. So, sadly, I suppose that we will see more and more machines in the wild which are "broken" (well, let's say do not align to good practices).
On the other hand I think that we should not assume that a given memory region (in our case starting at 1 MiB) is (or will be) available in every machine. I have not seen anything which says that it is true. We should stop doing that even if it works right now. I think that it works by chance and there is a chance that it will stop working one day because somebody will discover that he or she can put there e.g. device or hole.
Quoted 5 lines
Last but not least. I suppose that Xen users and especially distros will complain when they are not able to use GRUB2 with Xen on every platform just because somebody (i.e. platform designers, developers, or whatever) do not accept our beliefs or we require that platform must obey rules (i.e. memory map requirements) which are specified nowhere.
You're right, there's no such requirement on memory use in the spec. But you're missing the point. Supporting grub2 on UEFI is already a hack (ignoring all intentions EFI had from its first days). And now you've found an environment where that hack needs another hack (in Xen) to actually work. That's too much hackery for my taste, the more that things on this system can (afaict) work quite okay (without grub2, or with using its chainloader mechanism).
Quoted 1 line
So no, I'm still not convinced of the need for this patch.
I disagree. There are many things a grub environment gives us which plain EFI doesn't, most notably a familiar booting environment and recovery facilities for users (which vastly trumps how EFI expects to run things).
Furthermore, it offers common management of /boot in the dom0 filesystem between legacy and EFI boots.
Therefore I am very much +1 get grub working.
~Andrew
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Jan BeulichQuoted 54 lines · Jan Beulich
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 27.08.15 at 17:10, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
xen/arch/x86/boot/head.S trampoline_setup: · line 541
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
/* Copy bootstrap trampoline to low memory, below 1MB. */xen/arch/x86/boot/head.S +1
-1- mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsbThe latest at this final hunk I'm getting tired (and upset). I'd much rather not touch all this code in these fragile ways, and instead require Xen to be booted without grub2 on badly written firmware like the one on the machine you quote in the description.
Let's start discussion from here. My further work on this patch series is pointless until we do not agree details in this case.
So, I agree that any software (including firmware) should not use precious resources (i.e. low memory in that case) if it is not strictly required. And I do not think so that latest UEFI implementations on new hardware really need this low memory to survive (at least page tables could be put anywhere above low memory). However, in case of UEFI it is a wish of smart people not requirement set by spec. I was checking UEFI docs a few times but I was not able to find anything which says that e.g. "...developer MUST allocate memory outside of low memory ...". Even I have not found any suggestion about that. However, I must admit that I do not know whole UEFI spec, so, if you know something which is similar to above please tell me where it is (title, revision, page, paragraph, etc.). Hence, if there is not strict requirement in regards to memory allocation in specs we are lost. Of course we can encourage people to not do nasty things but I do not believe that many will listen. So, sadly, I suppose that we will see more and more machines in the wild which are "broken" (well, let's say do not align to good practices).
On the other hand I think that we should not assume that a given memory region (in our case starting at 1 MiB) is (or will be) available in every machine. I have not seen anything which says that it is true. We should stop doing that even if it works right now. I think that it works by chance and there is a chance that it will stop working one day because somebody will discover that he or she can put there e.g. device or hole.
Quoted 5 lines
Last but not least. I suppose that Xen users and especially distros will complain when they are not able to use GRUB2 with Xen on every platform just because somebody (i.e. platform designers, developers, or whatever) do not accept our beliefs or we require that platform must obey rules (i.e. memory map requirements) which are specified nowhere.
You're right, there's no such requirement on memory use in the spec. But you're missing the point. Supporting grub2 on UEFI is already a hack (ignoring all intentions EFI had from its first days). And now you've found an environment where that hack needs another hack (in Xen) to actually work. That's too much hackery for my taste, the more that things on this system can (afaict) work quite okay (without grub2, or with using its chainloader mechanism).
Quoted 1 line
So no, I'm still not convinced of the need for this patch.
I disagree. There are many things a grub environment gives us which plain EFI doesn't, most notably a familiar booting environment and recovery facilities for users (which vastly trumps how EFI expects to run things).
Furthermore, it offers common management of /boot in the dom0 filesystem between legacy and EFI boots.
Therefore I am very much +1 get grub working.
~Andrew
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 56 lines
Quoted 1 line
Quoted 1 line · On 27.08.15 at 20:04, <[email protected]> wrote:
Quoted 54 lines · Jan Beulich
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 27.08.15 at 17:10, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
xen/arch/x86/boot/head.S trampoline_setup: · line 541
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
/* Copy bootstrap trampoline to low memory, below 1MB. */xen/arch/x86/boot/head.S +1
-1- mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsbThe latest at this final hunk I'm getting tired (and upset). I'd much rather not touch all this code in these fragile ways, and instead require Xen to be booted without grub2 on badly written firmware like the one on the machine you quote in the description.
Let's start discussion from here. My further work on this patch series is pointless until we do not agree details in this case.
So, I agree that any software (including firmware) should not use precious resources (i.e. low memory in that case) if it is not strictly required. And I do not think so that latest UEFI implementations on new hardware really need this low memory to survive (at least page tables could be put anywhere above low memory). However, in case of UEFI it is a wish of smart people not requirement set by spec. I was checking UEFI docs a few times but I was not able to find anything which says that e.g. "...developer MUST allocate memory outside of low memory ...". Even I have not found any suggestion about that. However, I must admit that I do not know whole UEFI spec, so, if you know something which is similar to above please tell me where it is (title, revision, page, paragraph, etc.). Hence, if there is not strict requirement in regards to memory allocation in specs we are lost. Of course we can encourage people to not do nasty things but I do not believe that many will listen. So, sadly, I suppose that we will see more and more machines in the wild which are "broken" (well, let's say do not align to good practices).
On the other hand I think that we should not assume that a given memory region (in our case starting at 1 MiB) is (or will be) available in every machine. I have not seen anything which says that it is true. We should stop doing that even if it works right now. I think that it works by chance and there is a chance that it will stop working one day because somebody will discover that he or she can put there e.g. device or hole.
Quoted 5 lines
Last but not least. I suppose that Xen users and especially distros will complain when they are not able to use GRUB2 with Xen on every platform just because somebody (i.e. platform designers, developers, or whatever) do not accept our beliefs or we require that platform must obey rules (i.e. memory map requirements) which are specified nowhere.
You're right, there's no such requirement on memory use in the spec. But you're missing the point. Supporting grub2 on UEFI is already a hack (ignoring all intentions EFI had from its first days). And now you've found an environment where that hack needs another hack (in Xen) to actually work. That's too much hackery for my taste, the more that things on this system can (afaict) work quite okay (without grub2, or with using its chainloader mechanism).
Quoted 6 lines
Quoted 1 line
So no, I'm still not convinced of the need for this patch.
I disagree. There are many things a grub environment gives us which plain EFI doesn't, most notably a familiar booting environment and recovery facilities for users (which vastly trumps how EFI expects to run things).
"Familiar booting environment"? I knew of EFI's much earlier than I saw grub for the first time, so to me EFI's is more familiar if you so will.
Quoted 2 lines
Furthermore, it offers common management of /boot in the dom0 filesystem between legacy and EFI boots.
Which is an argument for porting suitable file system drivers to EFI, not an argument to layer multiple boot loaders. Plus booting _is_ (naturally) different between platforms. Plus if EFI was ported to architectures of interest (see ARM), the difference between platforms would decrease too (which btw was one of the original goals of EFI). Are you btw saying that ARM should use grub2 too? I didn't hear that mentioned as a goal anywhere so far...
Quoted 1 line
Therefore I am very much +1 get grub working.
Then you kind of misunderstood: I'm not against getting grub2 working (i.e. patches prior to this one are fine in principle). What I'm against is hacking around firmware+grub2 combinations not suitable for Xen's purposes (where one could argue which of the three is really at fault, and I'm far from convinced it's Xen).
Jan
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Andrew CooperQuoted 56 lines
Quoted 1 line
Quoted 1 line · On 27.08.15 at 20:04, <[email protected]> wrote:
Quoted 54 lines · Jan Beulich
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 27.08.15 at 17:10, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
xen/arch/x86/boot/head.S trampoline_setup: · line 541
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
/* Copy bootstrap trampoline to low memory, below 1MB. */xen/arch/x86/boot/head.S +1
-1- mov $sym_phys(trampoline_start),%esi + lea sym_offset(trampoline_start)(%ebp),%esi mov $trampoline_end - trampoline_start,%ecx rep movsbThe latest at this final hunk I'm getting tired (and upset). I'd much rather not touch all this code in these fragile ways, and instead require Xen to be booted without grub2 on badly written firmware like the one on the machine you quote in the description.
Let's start discussion from here. My further work on this patch series is pointless until we do not agree details in this case.
So, I agree that any software (including firmware) should not use precious resources (i.e. low memory in that case) if it is not strictly required. And I do not think so that latest UEFI implementations on new hardware really need this low memory to survive (at least page tables could be put anywhere above low memory). However, in case of UEFI it is a wish of smart people not requirement set by spec. I was checking UEFI docs a few times but I was not able to find anything which says that e.g. "...developer MUST allocate memory outside of low memory ...". Even I have not found any suggestion about that. However, I must admit that I do not know whole UEFI spec, so, if you know something which is similar to above please tell me where it is (title, revision, page, paragraph, etc.). Hence, if there is not strict requirement in regards to memory allocation in specs we are lost. Of course we can encourage people to not do nasty things but I do not believe that many will listen. So, sadly, I suppose that we will see more and more machines in the wild which are "broken" (well, let's say do not align to good practices).
On the other hand I think that we should not assume that a given memory region (in our case starting at 1 MiB) is (or will be) available in every machine. I have not seen anything which says that it is true. We should stop doing that even if it works right now. I think that it works by chance and there is a chance that it will stop working one day because somebody will discover that he or she can put there e.g. device or hole.
Quoted 5 lines
Last but not least. I suppose that Xen users and especially distros will complain when they are not able to use GRUB2 with Xen on every platform just because somebody (i.e. platform designers, developers, or whatever) do not accept our beliefs or we require that platform must obey rules (i.e. memory map requirements) which are specified nowhere.
You're right, there's no such requirement on memory use in the spec. But you're missing the point. Supporting grub2 on UEFI is already a hack (ignoring all intentions EFI had from its first days). And now you've found an environment where that hack needs another hack (in Xen) to actually work. That's too much hackery for my taste, the more that things on this system can (afaict) work quite okay (without grub2, or with using its chainloader mechanism).
Quoted 6 lines
Quoted 1 line
So no, I'm still not convinced of the need for this patch.
I disagree. There are many things a grub environment gives us which plain EFI doesn't, most notably a familiar booting environment and recovery facilities for users (which vastly trumps how EFI expects to run things).
"Familiar booting environment"? I knew of EFI's much earlier than I saw grub for the first time, so to me EFI's is more familiar if you so will.
Quoted 2 lines
Furthermore, it offers common management of /boot in the dom0 filesystem between legacy and EFI boots.
Which is an argument for porting suitable file system drivers to EFI, not an argument to layer multiple boot loaders. Plus booting _is_ (naturally) different between platforms. Plus if EFI was ported to architectures of interest (see ARM), the difference between platforms would decrease too (which btw was one of the original goals of EFI). Are you btw saying that ARM should use grub2 too? I didn't hear that mentioned as a goal anywhere so far...
Quoted 1 line
Therefore I am very much +1 get grub working.
Then you kind of misunderstood: I'm not against getting grub2 working (i.e. patches prior to this one are fine in principle). What I'm against is hacking around firmware+grub2 combinations not suitable for Xen's purposes (where one could argue which of the three is really at fault, and I'm far from convinced it's Xen).
Jan
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
Quoted 7 lines · Jan Beulich
Quoted 2 lines
Therefore I am very much +1 get grub working.
Then you kind of misunderstood: I'm not against getting grub2 working (i.e. patches prior to this one are fine in principle). What I'm against is hacking around firmware+grub2 combinations not suitable for Xen's purposes (where one could argue which of the three is really at fault, and I'm far from convinced it's Xen).
Irrespective of the EFI angle, there are other good reasons for making Xens boot code position-independent and able to be located elsewhere.
The region of memory between 0x10000 and 0x10fffe is at increased risk of clobbering from buggy firmwares. I have submitted bugfixes to Xen before, and there are further investigations which didn't result in anything upstream.
Moving the Xen text section out of this high risk region would make even legacy boot more reliable. Currently IMO it is a Xen bug that it strictly must be placed at the 1MB boundary to boot.
~Andrew
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Jan BeulichQuoted 7 lines · Jan Beulich
Quoted 2 lines
Therefore I am very much +1 get grub working.
Then you kind of misunderstood: I'm not against getting grub2 working (i.e. patches prior to this one are fine in principle). What I'm against is hacking around firmware+grub2 combinations not suitable for Xen's purposes (where one could argue which of the three is really at fault, and I'm far from convinced it's Xen).
Irrespective of the EFI angle, there are other good reasons for making Xens boot code position-independent and able to be located elsewhere.
The region of memory between 0x10000 and 0x10fffe is at increased risk of clobbering from buggy firmwares. I have submitted bugfixes to Xen before, and there are further investigations which didn't result in anything upstream.
Moving the Xen text section out of this high risk region would make even legacy boot more reliable. Currently IMO it is a Xen bug that it strictly must be placed at the 1MB boundary to boot.
~Andrew
Re: [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Jan BeulichQuoted 8 lines
Quoted 1 line
Quoted 1 line · On 27.08.15 at 17:29, <[email protected]> wrote:
You're right, there's no such requirement on memory use in the spec. But you're missing the point. Supporting grub2 on UEFI is already a hack (ignoring all intentions EFI had from its first days). And now you've found an environment where that hack needs another hack (in Xen) to actually work. That's too much hackery for my taste, the more that things on this system can (afaict) work quite okay (without grub2, or with using its chainloader mechanism).
It has been brought to my attention that the use of the work "hack" above could have been understood as an offense. It certainly wasn't meant so, and I'd like to apologize if it came over that way. I simply used it not finding a better term while writing; perhaps I could have used "misguided" and "workaround" respectively, but I'm not sure that would have been received much better.
In any event - I didn't mean to insult you or anyone else.
Jan
Re: [Xen-devel] [PATCH v2 22/23] x86: make Xen early boot code relocatable
In reply to Jan BeulichQuoted 8 lines
Quoted 1 line
Quoted 1 line · On 27.08.15 at 17:29, <[email protected]> wrote:
You're right, there's no such requirement on memory use in the spec. But you're missing the point. Supporting grub2 on UEFI is already a hack (ignoring all intentions EFI had from its first days). And now you've found an environment where that hack needs another hack (in Xen) to actually work. That's too much hackery for my taste, the more that things on this system can (afaict) work quite okay (without grub2, or with using its chainloader mechanism).
It has been brought to my attention that the use of the work "hack" above could have been understood as an offense. It certainly wasn't meant so, and I'd like to apologize if it came over that way. I simply used it not finding a better term while writing; perhaps I could have used "misguided" and "workaround" respectively, but I'm not sure that would have been received much better.
In any event - I didn't mean to insult you or anyone else.
Jan
PATCH v2 23/23 x86: add multiboot2 protocol support for relocatable images
In reply to Daniel KiperAdd multiboot2 protocol support for relocatable images. Only GRUB2 with relevant patches understands that feature. Older multiboot protocol (regardless of version) compatible loaders ignore it and everything works as usual.
--- xen/arch/x86/boot/head.S | 46 +++++++++++++++++++++++++++++-------- xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/include/xen/multiboot2.h | 13 +++++++++++ 3 files changed, 50 insertions(+), 10 deletions(-)
xen/arch/x86/boot/head.S +36 -10
@@ -81,6 +81,13 @@ multiboot1_header_end: /* Align modules at page boundry. */ mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED) + /* Load address preference. */ + mb2ht_init MB2_HT(RELOCATABLE), MB2_HT(OPTIONAL), \ + sym_phys(start), /* Min load address. */ \ + 0xffffffff, /* Max load address (4 GiB - 1). */ \ + 0x200000, /* Load address alignment (2 MiB). */ \ + MULTIBOOT2_LOAD_PREFERENCE_HIGH + /* Console flags tag. */ mb2ht_init MB2_HT(CONSOLE_FLAGS), MB2_HT(OPTIONAL), \ MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED
@@ -176,30 +183,39 @@ efi_multiboot2_proto: lea MB2_fixed_sizeof(%rbx),%rcx 0: + /* Get Xen image base address from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_BASE_ADDR,MB2_tag_type(%rcx) + jne 1f + + mov MB2_base_addr(%rcx),%ebp + sub $XEN_IMG_OFFSET,%rbp + jmp 4f + +1: /* Get EFI SystemTable address from Multiboot2 information. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%rcx) - jne 1f + jne 2f mov MB2_efi64_st(%rcx),%rsi /* Do not go into real mode on EFI platform. */ movb $1,skip_realmode(%rip) - jmp 3f + jmp 4f -1: +2: /* Get EFI ImageHandle address from Multiboot2 information. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64_IH,MB2_tag_type(%rcx) - jne 2f + jne 3f mov MB2_efi64_ih(%rcx),%rdi - jmp 3f + jmp 4f -2: +3: /* Is it the end of Multiboot2 information? */ cmpl $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx) je run_bs -3: +4: /* Go to next Multiboot2 information tag. */ add MB2_tag_size(%rcx),%ecx add $(MULTIBOOT2_TAG_ALIGN-1),%rcx
@@ -297,14 +313,23 @@ multiboot2_proto: lea MB2_fixed_sizeof(%ebx),%ecx 0: + /* Get Xen image base address from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_BASE_ADDR,MB2_tag_type(%ecx) + jne 1f + + mov MB2_base_addr(%ecx),%ebp + sub $XEN_IMG_OFFSET,%ebp + jmp 3f + +1: /* Get mem_lower from Multiboot2 information. */ cmpl $MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO,MB2_tag_type(%ecx) - jne 1f + jne 2f mov MB2_mem_lower(%ecx),%edx - jmp trampoline_bios_setup + jmp 3f -1: +2: /* EFI mode is not supported via legacy BIOS path. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx) je mb2_too_old
@@ -316,6 +341,7 @@ multiboot2_proto: cmpl $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%ecx) je trampoline_bios_setup +3: /* Go to next Multiboot2 information tag. */ add MB2_tag_size(%ecx),%ecx add $(MULTIBOOT2_TAG_ALIGN-1),%ecx
xen/arch/x86/x86_64/asm-offsets.c +1 -0
@@ -172,6 +172,7 @@ void __dummy__(void)DEFINE (MB2_fixed_sizeof,sizeof (multiboot2_fixed_t));OFFSET (MB2_tag_type, multiboot2_tag_t, type);OFFSET (MB2_tag_size, multiboot2_tag_t, size); +OFFSET (MB2_base_addr, multiboot2_tag_base_addr_t, base_addr);OFFSET (MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);OFFSET (MB2_efi64_st, multiboot2_tag_efi64_t, pointer);OFFSET (MB2_efi64_ih, multiboot2_tag_efi64_ih_t, pointer);
xen/include/xen/multiboot2.h +13 -0
@@ -59,11 +59,17 @@#define MULTIBOOT2_HEADER_TAG_EFI_BS 7#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI32 8#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 +#define MULTIBOOT2_HEADER_TAG_RELOCATABLE 10/* Header tag flags. */ #define MULTIBOOT2_HEADER_TAG_REQUIRED 0#define MULTIBOOT2_HEADER_TAG_OPTIONAL 1 +/* Where image should be loaded (suggestion not requirement). */ +#define MULTIBOOT2_LOAD_PREFERENCE_NONE 0 +#define MULTIBOOT2_LOAD_PREFERENCE_LOW 1 +#define MULTIBOOT2_LOAD_PREFERENCE_HIGH 2 +/* Header console tag console_flags. */ #define MULTIBOOT2_CONSOLE_FLAGS_CONSOLE_REQUIRED 1#define MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
@@ -90,6 +96,7 @@#define MULTIBOOT2_TAG_TYPE_EFI_BS 18#define MULTIBOOT2_TAG_TYPE_EFI32_IH 19#define MULTIBOOT2_TAG_TYPE_EFI64_IH 20 +#define MULTIBOOT2_TAG_TYPE_BASE_ADDR 21/* Multiboot 2 tag alignment. */ #define MULTIBOOT2_TAG_ALIGN 8
@@ -120,6 +127,12 @@ typedef struct {typedef struct {u32 type;u32 size; +u32 base_addr; +}multiboot2_tag_base_addr_t ; + +typedef struct { +u32 type; +u32 size;char string[0 ]; }multiboot2_tag_string_t ;
Signature · 1 line
1.7.10.4
Re: [PATCH v2 23/23] x86: add multiboot2 protocol support for relocatable images
Quoted 2 lines · Daniel Kiper
Add multiboot2 protocol support for relocatable images. Only GRUB2 with relevant patches understands that feature. Older multiboot
You may want to enumerate what those 'relevant' patches are.
Quoted 15 lines
protocol (regardless of version) compatible loaders ignore it and everything works as usual.
Signed-off-by Daniel Kiper <[email protected]>--- xen/arch/x86/boot/head.S | 46 +++++++++++++++++++++++++++++-------- xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/include/xen/multiboot2.h | 13 +++++++++++ 3 files changed, 50 insertions(+), 10 deletions(-)xen/arch/x86/boot/head.S +0
-0
xen/arch/x86/boot/head.S multiboot1_header_end: · line 86
Quoted 6 lines
xen/arch/x86/boot/head.S +3
-0@@ -81,6 +81,13 @@ multiboot1_header_end: /* Align modules at page boundry. */ mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED) + /* Load address preference. */ + mb2ht_init MB2_HT(RELOCATABLE), MB2_HT(OPTIONAL), \ + sym_phys(start), /* Min load address. */ \
We could go straight to __start?
Quoted 109 lines
xen/arch/x86/boot/head.S +33
-10+ 0xffffffff, /* Max load address (4 GiB - 1). */ \ + 0x200000, /* Load address alignment (2 MiB). */ \ + MULTIBOOT2_LOAD_PREFERENCE_HIGH + /* Console flags tag. */ mb2ht_init MB2_HT(CONSOLE_FLAGS), MB2_HT(OPTIONAL), \ MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED@@ -176,30 +183,39 @@ efi_multiboot2_proto: lea MB2_fixed_sizeof(%rbx),%rcx 0: + /* Get Xen image base address from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_BASE_ADDR,MB2_tag_type(%rcx) + jne 1f + + mov MB2_base_addr(%rcx),%ebp + sub $XEN_IMG_OFFSET,%rbp + jmp 4f + +1: /* Get EFI SystemTable address from Multiboot2 information. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%rcx) - jne 1f + jne 2f mov MB2_efi64_st(%rcx),%rsi /* Do not go into real mode on EFI platform. */ movb $1,skip_realmode(%rip) - jmp 3f + jmp 4f -1: +2: /* Get EFI ImageHandle address from Multiboot2 information. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64_IH,MB2_tag_type(%rcx) - jne 2f + jne 3f mov MB2_efi64_ih(%rcx),%rdi - jmp 3f + jmp 4f -2: +3: /* Is it the end of Multiboot2 information? */ cmpl $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx) je run_bs -3: +4: /* Go to next Multiboot2 information tag. */ add MB2_tag_size(%rcx),%ecx add $(MULTIBOOT2_TAG_ALIGN-1),%rcx@@ -297,14 +313,23 @@ multiboot2_proto: lea MB2_fixed_sizeof(%ebx),%ecx 0: + /* Get Xen image base address from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_BASE_ADDR,MB2_tag_type(%ecx) + jne 1f + + mov MB2_base_addr(%ecx),%ebp + sub $XEN_IMG_OFFSET,%ebp + jmp 3f + +1: /* Get mem_lower from Multiboot2 information. */ cmpl $MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO,MB2_tag_type(%ecx) - jne 1f + jne 2f mov MB2_mem_lower(%ecx),%edx - jmp trampoline_bios_setup + jmp 3f -1: +2: /* EFI mode is not supported via legacy BIOS path. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx) je mb2_too_old@@ -316,6 +341,7 @@ multiboot2_proto: cmpl $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%ecx) je trampoline_bios_setup +3: /* Go to next Multiboot2 information tag. */ add MB2_tag_size(%ecx),%ecx add $(MULTIBOOT2_TAG_ALIGN-1),%ecxxen/arch/x86/x86_64/asm-offsets.c +1
-0@@ -172,6 +172,7 @@ void __dummy__(void)DEFINE (MB2_fixed_sizeof,sizeof (multiboot2_fixed_t));OFFSET (MB2_tag_type, multiboot2_tag_t, type);OFFSET (MB2_tag_size, multiboot2_tag_t, size); +OFFSET (MB2_base_addr, multiboot2_tag_base_addr_t, base_addr);OFFSET (MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);OFFSET (MB2_efi64_st, multiboot2_tag_efi64_t, pointer);OFFSET (MB2_efi64_ih, multiboot2_tag_efi64_ih_t, pointer);xen/include/xen/multiboot2.h +0
-0@@ -59,11 +59,17 @@#define MULTIBOOT2_HEADER_TAG_EFI_BS 7#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI32 8#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI64 9
xen/include/xen/multiboot2.h line 71
Quoted 10 lines
xen/include/xen/multiboot2.h +5
-0+#define MULTIBOOT2_HEADER_TAG_RELOCATABLE 10/* Header tag flags. */ #define MULTIBOOT2_HEADER_TAG_REQUIRED 0#define MULTIBOOT2_HEADER_TAG_OPTIONAL 1 +/* Where image should be loaded (suggestion not requirement). */ +#define MULTIBOOT2_LOAD_PREFERENCE_NONE 0 +#define MULTIBOOT2_LOAD_PREFERENCE_LOW 1 +#define MULTIBOOT2_LOAD_PREFERENCE_HIGH 2
Would be good for all of this (with the other MULTIBOOT2..) to be aligned on the same column-ish.
Quoted 28 lines
xen/include/xen/multiboot2.h +8
-0+/* Header console tag console_flags. */ #define MULTIBOOT2_CONSOLE_FLAGS_CONSOLE_REQUIRED 1#define MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2@@ -90,6 +96,7 @@#define MULTIBOOT2_TAG_TYPE_EFI_BS 18#define MULTIBOOT2_TAG_TYPE_EFI32_IH 19#define MULTIBOOT2_TAG_TYPE_EFI64_IH 20 +#define MULTIBOOT2_TAG_TYPE_BASE_ADDR 21/* Multiboot 2 tag alignment. */ #define MULTIBOOT2_TAG_ALIGN 8@@ -120,6 +127,12 @@ typedef struct {typedef struct {u32 type;u32 size; +u32 base_addr; +}multiboot2_tag_base_addr_t ; + +typedef struct { +u32 type; +u32 size;char string[0 ]; }multiboot2_tag_string_t ;Signature · 1 line
1.7.10.4
Otherwise, Reviewed-by: Konrad Rzeszutek Wilk <[email protected]>
Re: [PATCH v2 23/23] x86: add multiboot2 protocol support for relocatable images
In reply to Daniel KiperQuoted 2 lines · Daniel Kiper
Add multiboot2 protocol support for relocatable images. Only GRUB2 with relevant patches understands that feature. Older multiboot
You may want to enumerate what those 'relevant' patches are.
Quoted 15 lines
protocol (regardless of version) compatible loaders ignore it and everything works as usual.
Signed-off-by Daniel Kiper <[email protected]>--- xen/arch/x86/boot/head.S | 46 +++++++++++++++++++++++++++++-------- xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/include/xen/multiboot2.h | 13 +++++++++++ 3 files changed, 50 insertions(+), 10 deletions(-)xen/arch/x86/boot/head.S +0
-0
xen/arch/x86/boot/head.S multiboot1_header_end: · line 86
Quoted 6 lines
xen/arch/x86/boot/head.S +3
-0@@ -81,6 +81,13 @@ multiboot1_header_end: /* Align modules at page boundry. */ mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED) + /* Load address preference. */ + mb2ht_init MB2_HT(RELOCATABLE), MB2_HT(OPTIONAL), \ + sym_phys(start), /* Min load address. */ \
We could go straight to __start?
Quoted 109 lines
xen/arch/x86/boot/head.S +33
-10+ 0xffffffff, /* Max load address (4 GiB - 1). */ \ + 0x200000, /* Load address alignment (2 MiB). */ \ + MULTIBOOT2_LOAD_PREFERENCE_HIGH + /* Console flags tag. */ mb2ht_init MB2_HT(CONSOLE_FLAGS), MB2_HT(OPTIONAL), \ MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED@@ -176,30 +183,39 @@ efi_multiboot2_proto: lea MB2_fixed_sizeof(%rbx),%rcx 0: + /* Get Xen image base address from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_BASE_ADDR,MB2_tag_type(%rcx) + jne 1f + + mov MB2_base_addr(%rcx),%ebp + sub $XEN_IMG_OFFSET,%rbp + jmp 4f + +1: /* Get EFI SystemTable address from Multiboot2 information. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%rcx) - jne 1f + jne 2f mov MB2_efi64_st(%rcx),%rsi /* Do not go into real mode on EFI platform. */ movb $1,skip_realmode(%rip) - jmp 3f + jmp 4f -1: +2: /* Get EFI ImageHandle address from Multiboot2 information. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64_IH,MB2_tag_type(%rcx) - jne 2f + jne 3f mov MB2_efi64_ih(%rcx),%rdi - jmp 3f + jmp 4f -2: +3: /* Is it the end of Multiboot2 information? */ cmpl $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx) je run_bs -3: +4: /* Go to next Multiboot2 information tag. */ add MB2_tag_size(%rcx),%ecx add $(MULTIBOOT2_TAG_ALIGN-1),%rcx@@ -297,14 +313,23 @@ multiboot2_proto: lea MB2_fixed_sizeof(%ebx),%ecx 0: + /* Get Xen image base address from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_BASE_ADDR,MB2_tag_type(%ecx) + jne 1f + + mov MB2_base_addr(%ecx),%ebp + sub $XEN_IMG_OFFSET,%ebp + jmp 3f + +1: /* Get mem_lower from Multiboot2 information. */ cmpl $MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO,MB2_tag_type(%ecx) - jne 1f + jne 2f mov MB2_mem_lower(%ecx),%edx - jmp trampoline_bios_setup + jmp 3f -1: +2: /* EFI mode is not supported via legacy BIOS path. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx) je mb2_too_old@@ -316,6 +341,7 @@ multiboot2_proto: cmpl $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%ecx) je trampoline_bios_setup +3: /* Go to next Multiboot2 information tag. */ add MB2_tag_size(%ecx),%ecx add $(MULTIBOOT2_TAG_ALIGN-1),%ecxxen/arch/x86/x86_64/asm-offsets.c +1
-0@@ -172,6 +172,7 @@ void __dummy__(void)DEFINE (MB2_fixed_sizeof,sizeof (multiboot2_fixed_t));OFFSET (MB2_tag_type, multiboot2_tag_t, type);OFFSET (MB2_tag_size, multiboot2_tag_t, size); +OFFSET (MB2_base_addr, multiboot2_tag_base_addr_t, base_addr);OFFSET (MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);OFFSET (MB2_efi64_st, multiboot2_tag_efi64_t, pointer);OFFSET (MB2_efi64_ih, multiboot2_tag_efi64_ih_t, pointer);xen/include/xen/multiboot2.h +0
-0@@ -59,11 +59,17 @@#define MULTIBOOT2_HEADER_TAG_EFI_BS 7#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI32 8#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI64 9
xen/include/xen/multiboot2.h line 71
Quoted 10 lines
xen/include/xen/multiboot2.h +5
-0+#define MULTIBOOT2_HEADER_TAG_RELOCATABLE 10/* Header tag flags. */ #define MULTIBOOT2_HEADER_TAG_REQUIRED 0#define MULTIBOOT2_HEADER_TAG_OPTIONAL 1 +/* Where image should be loaded (suggestion not requirement). */ +#define MULTIBOOT2_LOAD_PREFERENCE_NONE 0 +#define MULTIBOOT2_LOAD_PREFERENCE_LOW 1 +#define MULTIBOOT2_LOAD_PREFERENCE_HIGH 2
Would be good for all of this (with the other MULTIBOOT2..) to be aligned on the same column-ish.
Quoted 28 lines
xen/include/xen/multiboot2.h +8
-0+/* Header console tag console_flags. */ #define MULTIBOOT2_CONSOLE_FLAGS_CONSOLE_REQUIRED 1#define MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2@@ -90,6 +96,7 @@#define MULTIBOOT2_TAG_TYPE_EFI_BS 18#define MULTIBOOT2_TAG_TYPE_EFI32_IH 19#define MULTIBOOT2_TAG_TYPE_EFI64_IH 20 +#define MULTIBOOT2_TAG_TYPE_BASE_ADDR 21/* Multiboot 2 tag alignment. */ #define MULTIBOOT2_TAG_ALIGN 8@@ -120,6 +127,12 @@ typedef struct {typedef struct {u32 type;u32 size; +u32 base_addr; +}multiboot2_tag_base_addr_t ; + +typedef struct { +u32 type; +u32 size;char string[0 ]; }multiboot2_tag_string_t ;Signature · 1 line
1.7.10.4
Otherwise, Reviewed-by: Konrad Rzeszutek Wilk <[email protected]>
Re: [PATCH v2 23/23] x86: add multiboot2 protocol support for relocatable images
Quoted 24 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Daniel Kiper
Add multiboot2 protocol support for relocatable images. Only GRUB2 with relevant patches understands that feature. Older multiboot
You may want to enumerate what those 'relevant' patches are.
Quoted 18 lines
protocol (regardless of version) compatible loaders ignore it and everything works as usual.
Signed-off-by Daniel Kiper <[email protected]>--- xen/arch/x86/boot/head.S | 46 +++++++++++++++++++++++++++++-------- xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/include/xen/multiboot2.h | 13 +++++++++++ 3 files changed, 50 insertions(+), 10 deletions(-)xen/arch/x86/boot/head.S +0
-0@@ -81,6 +81,13 @@ multiboot1_header_end: /* Align modules at page boundry. */ mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED)
Quoted 5 lines
xen/arch/x86/boot/head.S multiboot1_header_end: · line 86
Quoted 3 lines
xen/arch/x86/boot/head.S +3
-0+ /* Load address preference. */ + mb2ht_init MB2_HT(RELOCATABLE), MB2_HT(OPTIONAL), \ + sym_phys(start), /* Min load address. */ \We could go straight to
__start?
This specifies lowest load address not entry point.
Daniel
Re: [PATCH v2 23/23] x86: add multiboot2 protocol support for relocatable images
In reply to Konrad Rzeszutek WilkQuoted 24 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Daniel Kiper
Add multiboot2 protocol support for relocatable images. Only GRUB2 with relevant patches understands that feature. Older multiboot
You may want to enumerate what those 'relevant' patches are.
Quoted 18 lines
protocol (regardless of version) compatible loaders ignore it and everything works as usual.
Signed-off-by Daniel Kiper <[email protected]>--- xen/arch/x86/boot/head.S | 46 +++++++++++++++++++++++++++++-------- xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/include/xen/multiboot2.h | 13 +++++++++++ 3 files changed, 50 insertions(+), 10 deletions(-)xen/arch/x86/boot/head.S +0
-0@@ -81,6 +81,13 @@ multiboot1_header_end: /* Align modules at page boundry. */ mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED)
Quoted 5 lines
xen/arch/x86/boot/head.S multiboot1_header_end: · line 86
Quoted 3 lines
xen/arch/x86/boot/head.S +3
-0+ /* Load address preference. */ + mb2ht_init MB2_HT(RELOCATABLE), MB2_HT(OPTIONAL), \ + sym_phys(start), /* Min load address. */ \We could go straight to
__start?
This specifies lowest load address not entry point.
Daniel
Re: [PATCH v2 23/23] x86: add multiboot2 protocol support for relocatable images
Quoted 25 lines · Daniel Kiper
Quoted 24 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Daniel Kiper
Add multiboot2 protocol support for relocatable images. Only GRUB2 with relevant patches understands that feature. Older multiboot
You may want to enumerate what those 'relevant' patches are.
Quoted 18 lines
protocol (regardless of version) compatible loaders ignore it and everything works as usual.
Signed-off-by Daniel Kiper <[email protected]>--- xen/arch/x86/boot/head.S | 46 +++++++++++++++++++++++++++++-------- xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/include/xen/multiboot2.h | 13 +++++++++++ 3 files changed, 50 insertions(+), 10 deletions(-)xen/arch/x86/boot/head.S +0
-0@@ -81,6 +81,13 @@ multiboot1_header_end: /* Align modules at page boundry. */ mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED)
Quoted 7 lines
Quoted 5 lines
xen/arch/x86/boot/head.S multiboot1_header_end: · line 86
Quoted 3 lines
xen/arch/x86/boot/head.S +3
-0+ /* Load address preference. */ + mb2ht_init MB2_HT(RELOCATABLE), MB2_HT(OPTIONAL), \ + sym_phys(start), /* Min load address. */ \We could go straight to
__start?This specifies lowest load address not entry point.
Ah right. And the __start can be moved somewhere inside the .text code, while 'start' is always at offset 0. Thank you!
Quoted 2 lines
Daniel
Re: [PATCH v2 23/23] x86: add multiboot2 protocol support for relocatable images
In reply to Daniel KiperQuoted 25 lines · Daniel Kiper
Quoted 24 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Daniel Kiper
Add multiboot2 protocol support for relocatable images. Only GRUB2 with relevant patches understands that feature. Older multiboot
You may want to enumerate what those 'relevant' patches are.
Quoted 18 lines
protocol (regardless of version) compatible loaders ignore it and everything works as usual.
Signed-off-by Daniel Kiper <[email protected]>--- xen/arch/x86/boot/head.S | 46 +++++++++++++++++++++++++++++-------- xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/include/xen/multiboot2.h | 13 +++++++++++ 3 files changed, 50 insertions(+), 10 deletions(-)xen/arch/x86/boot/head.S +0
-0@@ -81,6 +81,13 @@ multiboot1_header_end: /* Align modules at page boundry. */ mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED)
Quoted 7 lines
Quoted 5 lines
xen/arch/x86/boot/head.S multiboot1_header_end: · line 86
Quoted 3 lines
xen/arch/x86/boot/head.S +3
-0+ /* Load address preference. */ + mb2ht_init MB2_HT(RELOCATABLE), MB2_HT(OPTIONAL), \ + sym_phys(start), /* Min load address. */ \We could go straight to
__start?This specifies lowest load address not entry point.
Ah right. And the __start can be moved somewhere inside the .text code, while 'start' is always at offset 0. Thank you!
Quoted 2 lines
Daniel
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:28, <[email protected]> wrote:
This series, in general, is not targeted to Xen 4.6. However, there are some fixes at the beginning of it which are worth considering, I think.
I looked at the first few, and didn't spot any fixes. If you meant just cleanup or other cosmetic adjustments, then I don't view them as candidates for going in now. If I overlooked some aspect, then please be more precise.
Jan
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:28, <[email protected]> wrote:
This series, in general, is not targeted to Xen 4.6. However, there are some fixes at the beginning of it which are worth considering, I think.
I looked at the first few, and didn't spot any fixes. If you meant just cleanup or other cosmetic adjustments, then I don't view them as candidates for going in now. If I overlooked some aspect, then please be more precise.
Jan