x86: multiboot2 protocol support
v15 cover x86: multiboot2 protocol support
Hi,
I am sending fifteenth version of multiboot2 protocol support for legacy BIOS and EFI platforms. This patch series release contains fixes for all known/confirmed issues.
The final goal is xen.efi binary file which could be loaded by EFI loader, multiboot (v1) protocol (only on legacy BIOS platforms) and multiboot2 protocol. This way we will have:
- smaller Xen code base,
- one code base for xen.gz and xen.efi,
- one build method for xen.gz and xen.efi;
xen.efi will be extracted from xen(-syms)
file using objcopy or special custom tool,
- xen.efi build will not so strongly depend
on a given GCC and binutils version.
Here is short list of changes since v14:
- new patch: 1,
- changed patch: 5.
If you are not interested in this patch series at all please drop me a line and I will remove you from distribution list.
Daniel
xen/arch/x86/Makefile | 4 +- xen/arch/x86/Rules.mk | 3 + xen/arch/x86/boot/Makefile | 3 +- xen/arch/x86/boot/head.S | 578 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- xen/arch/x86/boot/reloc.c | 154 +++++++++++++++++++++- xen/arch/x86/boot/trampoline.S | 7 +- xen/arch/x86/boot/wakeup.S | 4 +- xen/arch/x86/boot/x86_64.S | 46 +++---- xen/arch/x86/efi/Makefile | 14 +- xen/arch/x86/efi/efi-boot.h | 60 +++++++-- xen/arch/x86/efi/stub.c | 39 ++++++ xen/arch/x86/setup.c | 24 ++-- xen/arch/x86/x86_64/asm-offsets.c | 15 +++ xen/arch/x86/xen.lds.S | 13 +- xen/common/efi/boot.c | 64 +++++++++ xen/common/efi/runtime.c | 9 ++ xen/include/asm-x86/config.h | 5 + xen/include/asm-x86/page.h | 2 +- xen/include/xen/config.h | 1 + xen/include/xen/multiboot2.h | 182 ++++++++++++++++++++++++++ 20 files changed, 1103 insertions(+), 124 deletions(-)
Daniel Kiper (10):
x86: add "w" flag to .init.data section definition
x86: add multiboot2 protocol support
efi: build xen.gz with EFI code
efi: create new early memory allocator
x86: add multiboot2 protocol support for EFI platforms
x86: change default load address from 1 MiB to 2 MiB x86/setup: use XEN_IMG_OFFSET instead of...
x86: make Xen early boot code relocatable x86/boot: rename sym_phys() to sym_offs()
x86: add multiboot2 protocol support for relocatable images
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v15 1/10 x86: add "w" flag to .init.data section definition
init.data section is clearly writable, so, add "w" flag to its definition in xen/arch/x86/boot/x86_64.S.
--- xen/arch/x86/boot/x86_64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/boot/x86_64.S +1 -1
@@ -186,7 +186,7 @@ GLOBAL(idle_pg_table) GLOBAL(__page_tables_end) /* Init pagetables. Enough page directories to map into the bottom 1GB. */ - .section .init.data, "a", @progbits + .section .init.data, "aw", @progbits .align PAGE_SIZE, 0 GLOBAL(l2_bootmap)
Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v15 01/10] x86: add "w" flag to .init.data section definition
Quoted 4 lines · Daniel Kiper
init.data section is clearly writable, so, add "w" flag to its definition in
xen/arch/x86/boot/x86_64.S.Signed-off-by Daniel Kiper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v15 2/10 x86: add multiboot2 protocol support
In reply to Daniel KiperAdd multiboot2 protocol support. Alter min memory limit handling as we now may not find it from either multiboot (v1) or multiboot2.
This way we are laying the foundation for EFI + GRUB2 + Xen development.
---
v13 - suggestions/fixes:
- add Emacs file-local variables
(suggested by Andrew Cooper).
v12 - suggestions/fixes:
- replace TABs with spaces in xen/include/xen/multiboot2.h (suggested by Doug Goldstein).
v9 - suggestions/fixes:
- use .L label instead of numeric one in multiboot2 data scanning loop; I hope that this change does not invalidate Jan's Reviewed-by (suggested by Jan Beulich).
v8 - suggestions/fixes:
- use sizeof(<var>/<expr>) instead of sizeof(<type>) if it is possible
(suggested by Jan Beulich).
v7 - suggestions/fixes:
- rename mbi_mbi/mbi2_mbi to mbi_reloc/mbi2_reloc respectively (suggested by Jan Beulich),
- initialize mbi_out->flags using "|=" instead of "=" (suggested by Jan Beulich),
- use sizeof(*mmap_dst) instead of sizeof(memory_map_t) if it makes sense
(suggested by Jan Beulich).
v6 - suggestions/fixes:
- properly index multiboot2_tag_mmap_t.entries[] (suggested by Jan Beulich),
- do not index mbi_out_mods[] beyond its end (suggested by Andrew Cooper),
- reduce number of casts
(suggested by Andrew Cooper and Jan Beulich),
- add braces to increase code readability (suggested by Andrew Cooper).
v5 - suggestions/fixes:
- check multiboot2_tag_mmap_t.entry_size before multiboot2_tag_mmap_t.entries[] use (suggested by Jan Beulich),
- properly index multiboot2_tag_mmap_t.entries[] (suggested by Jan Beulich),
- use "type name[]" instad of "type name[0]" in xen/include/xen/multiboot2.h (suggested by Jan Beulich),
- remove unneeded comment
(suggested by Jan Beulich).
v4 - suggestions/fixes:
- avoid assembly usage in xen/arch/x86/boot/reloc.c,
- fix boundary check issue and optimize
for() loops in mbi2_mbi(),
- move to stdcall calling convention,
- remove unneeded typeof() from ALIGN_UP() macro (suggested by Jan Beulich),
- add and use NULL definition in xen/arch/x86/boot/reloc.c (suggested by Jan Beulich),
- do not read data beyond the end of multiboot2 information in xen/arch/x86/boot/head.S (suggested by Jan Beulich),
- add :req to some .macro arguments
(suggested by Jan Beulich),
- use cmovcc if possible,
- add .L to multiboot2_header_end label (suggested by Jan Beulich),
- add .L to multiboot2_proto label
(suggested by Jan Beulich),
- improve label names
(suggested by Jan Beulich).
v3 - suggestions/fixes:
- reorder reloc() arguments
(suggested by Jan Beulich),
- remove .L from multiboot2 header labels
(suggested by Andrew Cooper, Jan Beulich and Konrad Rzeszutek Wilk),
- take into account alignment when skipping multiboot2 fixed part (suggested by Konrad Rzeszutek Wilk),
- create modules data if modules count != 0
(suggested by Jan Beulich),
- improve macros
(suggested by Jan Beulich),
- reduce number of casts
(suggested by Jan Beulich),
- use const if possible
(suggested by Jan Beulich),
- drop static and __used__ attribute from reloc() (suggested by Jan Beulich),
- remove isolated/stray __packed attribute from multiboot2_memory_map_t type definition
(suggested by Jan Beulich),
- reformat xen/include/xen/multiboot2.h
(suggested by Konrad Rzeszutek Wilk),
- improve comments
(suggested by Konrad Rzeszutek Wilk),
- remove hard tabs
(suggested by Jan Beulich and Konrad Rzeszutek Wilk).
v2 - suggestions/fixes:
- generate multiboot2 header using macros (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- simplify assembly in xen/arch/x86/boot/head.S (suggested by Jan Beulich),
- do not include include/xen/compiler.h
in xen/arch/x86/boot/reloc.c
(suggested by Jan Beulich),
- do not read data beyond the end of multiboot2 information (suggested by Jan Beulich).
v2 - not fixed yet:
- dynamic dependency generation for xen/arch/x86/boot/reloc.S; this requires more work; I am not sure that it pays because potential patch requires more changes than addition of just multiboot2.h to Makefile
(suggested by Jan Beulich),
- isolated/stray __packed attribute usage for multiboot2_memory_map_t (suggested by Jan Beulich).
--- xen/arch/x86/boot/Makefile | 3 +- xen/arch/x86/boot/head.S | 107 ++++++++++++++++++++++- xen/arch/x86/boot/reloc.c | 154 +++++++++++++++++++++++++++++++-- xen/arch/x86/x86_64/asm-offsets.c | 9 ++ xen/include/xen/multiboot2.h | 169 +++++++++++++++++++++++++++++++++++++ 5 files changed, 432 insertions(+), 10 deletions(-) create mode 100644 xen/include/xen/multiboot2.h
xen/arch/x86/boot/Makefile +2 -1
@@ -4,7 +4,8 @@ DEFS_H_DEPS = defs.h $(BASEDIR)/include/xen/stdbool.h CMDLINE_DEPS = $(DEFS_H_DEPS) video.h -RELOC_DEPS = $(DEFS_H_DEPS) $(BASEDIR)/include/xen/multiboot.h +RELOC_DEPS = $(DEFS_H_DEPS) $(BASEDIR)/include/xen/multiboot.h \ + $(BASEDIR)/include/xen/multiboot2.h head.o: cmdline.S reloc.S
xen/arch/x86/boot/head.S +103 -4
145 lines not on this page · raw message
xen/arch/x86/boot/reloc.c +149 -5
192 lines not on this page · raw message
xen/arch/x86/x86_64/asm-offsets.c +9 -0
@@ -13,6 +13,7 @@#include <asm/fixmap.h> #include <asm/hardirq.h> #include <xen/multiboot.h> +#include <xen/multiboot2.h> #define DEFINE(_sym, _val) \ asm volatile ("\n.ascii\"==>#define " #_sym " %0 /* " #_val " */<==\"" \
@@ -167,6 +168,14 @@ void __dummy__(void)OFFSET (MB_flags, multiboot_info_t, flags);OFFSET (MB_cmdline, multiboot_info_t, cmdline);OFFSET (MB_mem_lower, multiboot_info_t, mem_lower); +BLANK (); + +DEFINE (MB2_fixed_sizeof,sizeof (multiboot2_fixed_t)); +OFFSET (MB2_fixed_total_size, multiboot2_fixed_t, total_size); +OFFSET (MB2_tag_type, multiboot2_tag_t, type); +OFFSET (MB2_tag_size, multiboot2_tag_t, size); +OFFSET (MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower); +BLANK (); OFFSET(DOMAIN_vm_assist, struct domain, vm_assist); }
xen/include/xen/multiboot2.h new file +169 -0
169 lines not on this page · raw message
Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v15 3/10 efi: build xen.gz with EFI code
In reply to Daniel KiperBuild xen.gz with EFI code. We need this to support multiboot2 protocol on EFI platforms.
If we wish to load non-ELF file using multiboot (v1) or multiboot2 then it must contain "linear" (or "flat") representation of code and data. This is requirement of both boot protocols. Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). From EFI point of view everything is OK and works. However, this file layout cannot be properly interpreted by multiboot protocols family. In theory there is a chance that we could build proper PE file (from multiboot protocols POV) using current build system. However, it means that xen.efi further diverge from Xen ELF file (in terms of contents and build method). On the other hand ELF has all needed properties. So, it means that this is good starting point for further development. Additionally, I think that this is also good starting point for further xen.efi code and build optimizations. It looks that there is a chance that finally we can generate xen.efi directly from Xen ELF using just simple objcopy or other tool. This way we will have one Xen binary which can be loaded by three boot protocols: EFI native loader, multiboot (v1) and multiboot2.
---
v14 - suggestions/fixes:
- at least GNU Make 4.1 does not build efi/buildid.o if nothing depends on it; so, add "boot.init.o: buildid.o" dependency to force efi/buildid.o on some versions of make; I hope that this small change does not invalidate Acked-by/Reviewed-by; however, I am dropping Tested-by
(discovered by Konrad Rzeszutek Wilk and Marcos Matsunaga).
v6 - suggestions/fixes:
- improve efi_enabled() checks in efi_runtime_call() (suggested by Jan Beulich).
v5 - suggestions/fixes:
- properly calculate efi symbol address in
xen/arch/x86/xen.lds.S (I hope that this
change does not invalidate Jan's ACK).
v4 - suggestions/fixes:
- functions should return -ENOSYS instead
of -EOPNOTSUPP if EFI runtime services
are not available
(suggested by Jan Beulich),
- remove stale bits from xen/arch/x86/Makefile
(suggested by Jan Beulich).
v3 - suggestions/fixes:
- check for EFI platform in EFI code
(suggested by Jan Beulich),
- fix Makefiles
(suggested by Jan Beulich),
- improve commit message
(suggested by Jan Beulich).
v2 - suggestions/fixes:
- build EFI code only if it is supported in a given build environment (suggested by Jan Beulich).
--- xen/arch/x86/Makefile | 2 +- xen/arch/x86/efi/Makefile | 14 ++++++-------- xen/arch/x86/xen.lds.S | 4 ++-- xen/common/efi/boot.c | 3 +++ xen/common/efi/runtime.c | 9 +++++++++ 5 files changed, 21 insertions(+), 11 deletions(-)
xen/arch/x86/Makefile +1 -1
@@ -219,6 +219,6 @@ efi/mkreloc: efi/mkreloc.c 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 $(BASEDIR)/.xen.efi.[0-9]* efi/*.efi efi/disabled efi/mkreloc rm -f boot/cmdline.S boot/reloc.S boot/*.lnk boot/*.bin rm -f note.o
xen/arch/x86/efi/Makefile +6 -8
@@ -1,18 +1,16 @@ CFLAGS += -fshort-wchar -obj-y += stub.o - -create = test -e $(1) || touch -t 199901010000 $(1) - efi := y$(shell rm -f disabled) efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y)) efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y)) -efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o))) - -extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o buildid.o +efi := $(if $(efi),$(shell rm disabled)y) %.o: %.ihex $(OBJCOPY) -I ihex -O binary $< $@ -stub.o: $(extra-y) +boot.init.o: buildid.o + +obj-y := stub.o +obj-$(efi) := boot.init.o compat.o relocs-dummy.o runtime.o +extra-$(efi) += buildid.o nogcov-$(efi) += stub.o
xen/arch/x86/xen.lds.S +2 -2
@@ -270,10 +270,10 @@ SECTIONS .pad : { . = ALIGN(MB(16)); } :text -#else - efi = .; #endif + efi = DEFINED(efi) ? efi : .; + /* Sections to be discarded */ /DISCARD/ : { *(.exit.text)
xen/common/efi/boot.c +3 -0
@@ -1251,6 +1251,9 @@ void __init efi_init_memory(void) } *extra, *extra_head = NULL;#endif +if ( !efi_enabled (EFI_BOOT ) ) +return ; +printk (XENLOG_INFO "EFI memory map:%s\n" , map_bs ?" (mapping BootServices)" :"" );for ( i =0 ; i < efi_memmap_size; i += efi_mdesc_size )
xen/common/efi/runtime.c +9 -0
@@ -196,6 +196,9 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info) {unsigned int i, n; +if ( !efi_enabled (EFI_BOOT ) ) +return -ENOSYS ; +switch ( idx ) {case XEN_FW_EFI_VERSION :
@@ -331,6 +334,12 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)EFI_STATUS status =EFI_NOT_STARTED ;int rc =0 ; +if ( !efi_enabled (EFI_BOOT ) ) +return -ENOSYS ; + +if ( !efi_enabled (EFI_RS ) ) +return -EOPNOTSUPP ; +switch ( op->function ) {case XEN_EFI_get_time:
Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v15 4/10 efi: create new early memory allocator
In reply to Daniel KiperThere is a problem with place_string() which is used as early memory allocator. It gets memory chunks starting from start symbol and goes down. Sadly this does not work when Xen is loaded using multiboot2 protocol because then the start lives on 1 MiB address and we should not allocate a memory from below of it. So, I tried to use mem_lower address calculated by GRUB2. However, this solution works only on some machines. There are machines in the wild (e.g. Dell PowerEdge R820) which uses first ~640 KiB for boot services code or data... :-((( Hence, we need new memory allocator for Xen EFI boot code which is quite simple and generic and could be used by place_string() and efi_arch_allocate_mmap_buffer(). I think about following solutions:
1) We could use native EFI allocation functions (e.g. AllocatePool() or AllocatePages()) to get memory chunk. However, later (somewhere in __start_xen()) we must copy its contents to safe place or reserve it in e820 memory map and map it in Xen virtual address space. This means that the code referring to Xen command line, loaded modules and EFI memory map, mostly in __start_xen(), will be further complicated and diverge from legacy BIOS cases. Additionally, both former things have to be placed below 4 GiB because their addresses are stored in multiboot_info_t structure which has 32-bit relevant members.
2) We may allocate memory area statically somewhere in Xen code which could be used as memory pool for early dynamic allocations. Looks quite simple. Additionally, it would not depend on EFI at all and could be used on legacy BIOS platforms if we need it. However, we must carefully choose size of this pool. We do not want increase Xen binary size too much and waste too much memory but also we must fit at least memory map on x86 EFI platforms. As I saw on small machine, e.g. IBM System x3550 M2 with 8 GiB RAM, memory map may contain more than 200 entries. Every entry on x86-64 platform is 40 bytes in size. So, it means that we need more than 8 KiB for EFI memory map only. Additionally, if we use this memory pool for Xen and modules command line storage (it would be used when xen.efi is executed as EFI application) then we should add, I think, about 1 KiB. In this case, to be on safe side, we should assume at least 64 KiB pool for early memory allocations. Which is about 4 times of our earlier calculations. However, during discussion on Xen-devel Jan Beulich suggested that just in case we should use 1 MiB memory pool like it is in original place_string() implementation. So, let's use 1 MiB as it was proposed. If we think that we should not waste unallocated memory in the pool on running system then we can mark this region as __initdata and move all required data to dynamically allocated places somewhere in __start_xen().
2a) We could put memory pool into .bss.page_aligned section. Then allocate
memory chunks starting from the lowest address. After init phase we can free unused portion of the memory pool as in case of .init.text or .init.data sections. This way we do not need to allocate any space in image file and freeing of unused area in the memory pool is very simple.
Now #2a solution is implemented because it is quite simple and requires limited number of changes, especially in __start_xen().
New allocator is quite generic and can be used on ARM platforms too. Though it is not enabled on ARM yet due to lack of some prereq. List of them is placed before ebmalloc code.
---
v11 - suggestions/fixes:
- #ifdef only EBMALLOC_SIZE from ebmalloc machinery (suggested by Jan Beulich).
v10 - suggestions/fixes:
- remove unneeded ARM free_ebmalloc_unused_mem() stub.
v9 - suggestions/fixes:
- call free_ebmalloc_unused_mem() from efi_init_memory() instead of xen/arch/arm/setup.c:init_done() (suggested by Jan Beulich),
- improve comments.
v8 - suggestions/fixes:
- disable whole ebmalloc machinery on ARM platforms,
- add comment saying what should be done before enabling ebmalloc on ARM,
(suggested by Julien Grall),
- move ebmalloc code before efi-boot.h inclusion and remove unneeded forward declaration (suggested by Jan Beulich),
- remove free_ebmalloc_unused_mem() call from xen/arch/arm/setup.c:init_done() (suggested by Julien Grall),
- improve commit message.
v7 - suggestions/fixes:
- enable most of ebmalloc machinery on ARM platforms (suggested by Jan Beulich),
- remove unneeded cast
(suggested by Jan Beulich),
- wrap long line
(suggested by Jan Beulich),
- improve commit message.
v6 - suggestions/fixes:
- optimize ebmalloc allocator,
- move ebmalloc machinery to xen/common/efi/boot.c (suggested by Jan Beulich),
- enforce PAGE_SIZE ebmalloc_mem alignment (suggested by Jan Beulich),
- ebmalloc() must allocate properly aligned memory regions
(suggested by Jan Beulich),
- printk() should use XENLOG_INFO (suggested by Jan Beulich).
v4 - suggestions/fixes:
- move from #2 solution to #2a solution,
- improve commit message.
--- xen/arch/x86/efi/efi-boot.h | 11 +++------- xen/arch/x86/setup.c | 3 +-- xen/common/efi/boot.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 10 deletions(-)
xen/arch/x86/efi/efi-boot.h +3 -8
@@ -114,7 +114,7 @@ static void __init relocate_trampoline(unsigned long phys)static void __init place_string (u32 *addr,const char *s) { -static char *__initdata alloc = start; +char *alloc =NULL ;if ( s && *s ) {
@@ -122,7 +122,7 @@ static void __init place_string(u32 *addr, const char *s)const char *old = (char *)(long )*addr;size_t len2 = *addr ?strlen (old) +1 :0 ; - alloc -= len1 + len2; + alloc =ebmalloc (len1 + len2);/* * Insert new string before already existing one. This is needed * for options passed on the command line to override options from
@@ -205,12 +205,7 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,static void *__init efi_arch_allocate_mmap_buffer (UINTN map_size) { -place_string (&mbi.mem_upper,NULL ); - mbi.mem_upper -= map_size; - mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR ); -if ( mbi.mem_upper < xen_phys_start ) -return NULL ; -return (void *)(long )mbi.mem_upper; +return ebmalloc (map_size); }static void __init efi_arch_pre_exit_boot (void )
xen/arch/x86/setup.c +1 -2
@@ -1124,8 +1124,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( !xen_phys_start )panic ("Not enough memory to relocate Xen." ); -reserve_e820_ram (&boot_e820,efi_enabled (EFI_LOADER ) ? mbi->mem_upper :__pa (&_start), -__pa (&_end)); +reserve_e820_ram (&boot_e820,__pa (&_start),__pa (&_end));/* Late kexec reservation (dynamic start address). */ kexec_reserve_area (&boot_e820);
xen/common/efi/boot.c +50 -0
62 lines not on this page · raw message
Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v15 5/10 x86: add multiboot2 protocol support for EFI platforms
In reply to Daniel KiperThis way Xen can be loaded on EFI platforms using GRUB2 and other boot loaders which support multiboot2 protocol.
---
v15 - suggestions/fixes:
- rearrange inline assembly arguments in
xen/arch/x86/efi/stub.c:efi_multiboot2()
(suggested by Jan Beulich),
- improve comments in error handling in
legacy BIOS Multiboot2 scanning loop
(suggested by Jan Beulich).
v14 - suggestions/fixes:
- mark .init.data section as writable; by the way we must change similar definition in xen/arch/x86/boot/x86_64.S because otherwise compiler complains about section types conflicts
(suggested by Jan Beulich),
- use %r15 instead of %r15d
(suggested by Jan Beulich),
- remove redundant add from UEFI stack alignment
(suggested by Jan Beulich),
- use "mov (%rsp),%rdi" instead of "pop %rdi/push %rdi"
(suggested by Jan Beulich),
- return void instead of paddr_t from efi_multiboot2()
and then simplify a bit trampoline setup assembly
(suggested by Jan Beulich),
- remove "(XEN)" from efi_multiboot2() stub error messages
(suggested by Jan Beulich),
- move err from inline assembly OutputOperands to InputOperands in stub.c:efi_multiboot2(); this way we avoid following compile time error:
stub.c: In function ‘efi_multiboot2’:
stub.c:36:5: error: read-only variable ‘err’ used as ‘asm’ output
asm volatile(
^~~
issue was introduced by changing err type to "static const CHAR16 __initconst"; potentially we can revert this change but move to InputOperands looks better IMO; even if we are not able to specify %rdx in Clobbers; simply we do not care because next instruction after call is hlt
(discovered by Konrad Rzeszutek Wilk and Marcos Matsunaga),
- take into account MBI_SPACE_MIN in ASSERT((trampoline_end - trampoline_start) < ...) (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich).
v13 - suggestions/fixes:
- move vga_text_buffer and efi_platform to .init.data section (suggested by Jan Beulich),
- reduce number of error branches in EFI code in xen/arch/x86/boot/head.S (suggested by Jan Beulich),
- rename run_bs label to .Lrun_bs
(suggested by Jan Beulich),
- align the stack as UEFI spec requires
(suggested by Jan Beulich),
- change trampoline region memory layout
(suggested by Jan Beulich),
- revert changes in efi_arch_pre_exit_boot()
(suggested by Jan Beulich),
- relocate_trampoline() must set trampoline_phys for all bootloaders; otherwise fallback allocator is always used if Xen was loaded with Multiboot2 protocol,
- change err type in efi_multiboot2() to "static const CHAR16 __initconst" (suggested by Jan Beulich),
- change asm "g" constraint to "rm" in efi_multiboot2() (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich and Doug Goldstein).
v12 - suggestions/fixes:
- rename __efi64_start to __efi64_mb2_start (suggested by Andrew Cooper),
- use efi_arch_memory_setup() machinery as trampoline et consortes main memory allocator
(suggested by Doug Goldstein),
- allocate space for mbi struct in efi_arch_memory_setup() too; this thing was not taken into account in earlier releases,
- revert trampoline et consortes fallback memory allocator code in efi_arch_process_memory_map() to current upstream state (suggested by Doug Goldstein),
- further simplify efi_arch_pre_exit_boot() code,
- call efi_arch_memory_setup() from efi_multiboot2() (suggested by Doug Goldstein),
- fix asembly call argument in xen/arch/x86/efi/stub.c (suggested by Andrew Cooper),
- add ASSERT() for trampoline size
(suggested by Doug Goldstein),
- add KB() macro
(suggested by Doug Goldstein),
- improve comments
(suggested by Andrew Cooper and Doug Goldstein).
v10 - suggestions/fixes:
- replace ljmpl with lretq
(suggested by Andrew Cooper),
- introduce efi_platform to increase code readability (suggested by Andrew Cooper).
v9 - suggestions/fixes:
- use .L labels instead of numeric ones in multiboot2 data scanning loops (suggested by Jan Beulich).
v8 - suggestions/fixes:
- use __bss_start(%rip)/__bss_end(%rip) instead of of .startof.(.bss)(%rip)/$.sizeof.(.bss) because latter is not tested extensively in different built environments yet
(suggested by Andrew Cooper),
- fix multiboot2 data scanning loop in x86_32 code (suggested by Jan Beulich),
- add check for extra mem for mbi data if Xen is loaded via multiboot2 protocol on EFI platform (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich).
v7 - suggestions/fixes:
- do not allocate twice memory for trampoline if we were loaded via multiboot2 protocol on EFI platform,
- wrap long line
(suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich).
v6 - suggestions/fixes:
- improve label names in assembly
error printing code
(suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- various minor cleanups and fixes
(suggested by Jan Beulich).
v4 - suggestions/fixes:
- remove redundant BSS alignment,
- update BSS alignment check,
- use __set_bit() instead of set_bit() if possible (suggested by Jan Beulich),
- call efi_arch_cpu() from efi_multiboot2() even if the same work is done later in other place right now
(suggested by Jan Beulich),
- xen/arch/x86/efi/stub.c:efi_multiboot2() fail properly on EFI platforms,
- do not read data beyond the end of multiboot2 information in xen/arch/x86/boot/head.S (suggested by Jan Beulich),
- use 32-bit registers in x86_64 code if possible (suggested by Jan Beulich),
- multiboot2 information address is 64-bit in x86_64 code, so, treat it is as is (suggested by Jan Beulich),
- use cmovcc if possible,
- leave only one space between rep and stosq (suggested by Jan Beulich),
- improve error handling,
- improve early error messages,
(suggested by Jan Beulich),
- improve early error messages printing code,
- improve label names
(suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- various minor cleanups.
v3 - suggestions/fixes:
- take into account alignment when skipping multiboot2 fixed part (suggested by Konrad Rzeszutek Wilk),
- improve segment registers initialization
(suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich and Konrad Rzeszutek Wilk),
- improve commit message
(suggested by Jan Beulich).
v2 - suggestions/fixes:
- generate multiboot2 header using macros
(suggested by Jan Beulich),
- switch CPU to x86_32 mode before
jumping to 32-bit code
(suggested by Andrew Cooper),
- reduce code changes to increase patch readability (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- ignore MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag on EFI platform and find on my own multiboot2.mem_lower value,
- stop execution if EFI platform is detected
in legacy BIOS path.
--- xen/arch/x86/boot/head.S | 305 ++++++++++++++++++++++++++++++++++--- xen/arch/x86/boot/reloc.c | 2 +- xen/arch/x86/efi/efi-boot.h | 49 +++++- xen/arch/x86/efi/stub.c | 39 +++++ xen/arch/x86/x86_64/asm-offsets.c | 2 + xen/arch/x86/xen.lds.S | 7 +- xen/common/efi/boot.c | 11 ++ xen/include/asm-x86/config.h | 5 + xen/include/xen/config.h | 1 + 9 files changed, 399 insertions(+), 22 deletions(-)
xen/arch/x86/boot/head.S +287 -18
@@ -89,6 +89,13 @@ multiboot2_header_start: 0, /* Number of the lines - no preference. */ \ 0 /* Number of bits per pixel - no preference. */ + /* Request that ExitBootServices() not be called. */ + mb2ht_init MB2_HT(EFI_BS), MB2_HT(OPTIONAL) + + /* EFI64 Multiboot2 entry point. */ + mb2ht_init MB2_HT(ENTRY_ADDRESS_EFI64), MB2_HT(OPTIONAL), \ + sym_phys(__efi64_mb2_start) + /* Multiboot2 header end tag. */ mb2ht_init MB2_HT(END), MB2_HT(REQUIRED) .Lmultiboot2_header_end:
@@ -100,20 +107,50 @@ multiboot2_header_start: gdt_boot_descr: .word 6*8-1 .long sym_phys(trampoline_gdt) + .long 0 /* Needed for 64-bit lgdt */ .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!" .Lbad_ldr_msg: .asciz "ERR: Not a Multiboot bootloader!" +.Lbad_ldr_nbs: .asciz "ERR: Bootloader shutdown EFI x64 boot services!" +.Lbad_ldr_nst: .asciz "ERR: EFI SystemTable is not provided by bootloader!" +.Lbad_ldr_nih: .asciz "ERR: EFI ImageHandle is not provided by bootloader!" +.Lbad_efi_msg: .asciz "ERR: EFI IA-32 platforms are not supported!" + + .section .init.data, "aw", @progbits + .align 4 + +vga_text_buffer: + .long 0xb8000 + +efi_platform: + .byte 0 .section .init.text, "ax", @progbits bad_cpu: mov $(sym_phys(.Lbad_cpu_msg)),%esi # Error message - jmp print_err + jmp .Lget_vtb not_multiboot: mov $(sym_phys(.Lbad_ldr_msg)),%esi # Error message -print_err: - mov $0xB8000,%edi # VGA framebuffer -1: mov (%esi),%bl + jmp .Lget_vtb +.Lmb2_no_st: + mov $(sym_phys(.Lbad_ldr_nst)),%esi # Error message + jmp .Lget_vtb +.Lmb2_no_ih: + mov $(sym_phys(.Lbad_ldr_nih)),%esi # Error message + jmp .Lget_vtb +.Lmb2_no_bs: + mov $(sym_phys(.Lbad_ldr_nbs)),%esi # Error message + xor %edi,%edi # No VGA text buffer + jmp .Lsend_chr +.Lmb2_efi_ia_32: + mov $(sym_phys(.Lbad_efi_msg)),%esi # Error message + xor %edi,%edi # No VGA text buffer + jmp .Lsend_chr +.Lget_vtb: + mov sym_phys(vga_text_buffer),%edi +.Lsend_chr: + mov (%esi),%bl test %bl,%bl # Terminate on '\0' sentinel je .Lhalt mov $0x3f8+5,%dx # UART Line Status Register
@@ -123,13 +160,192 @@ print_err: mov $0x3f8+0,%dx # UART Transmit Holding Register mov %bl,%al out %al,%dx # Send a character over the serial line - movsb # Write a character to the VGA framebuffer + test %edi,%edi # Is the VGA text buffer available? + jz .Lsend_chr + movsb # Write a character to the VGA text buffer mov $7,%al - stosb # Write an attribute to the VGA framebuffer - jmp 1b + stosb # Write an attribute to the VGA text buffer + jmp .Lsend_chr .Lhalt: hlt jmp .Lhalt + .code64 + +__efi64_mb2_start: + /* + * Multiboot2 spec says that here CPU is in 64-bit mode. However, + * there is also guarantee that all code and data is always put + * by the bootloader below 4 GiB. Hence, we can safely truncate + * addresses to 32-bits in most cases below. + */ + + cld + + /* VGA is not available on EFI platforms. */ + movl $0,vga_text_buffer(%rip) + + /* Check for Multiboot2 bootloader. */ + cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax + je .Lefi_multiboot2_proto + + /* Jump to not_multiboot after switching CPU to x86_32 mode. */ + lea not_multiboot(%rip),%r15 + jmp x86_32_switch + +.Lefi_multiboot2_proto: + /* Zero EFI SystemTable and EFI ImageHandle addresses. */ + xor %esi,%esi + xor %edi,%edi + + /* Skip Multiboot2 information fixed part. */ + lea (MB2_fixed_sizeof+MULTIBOOT2_TAG_ALIGN-1)(%rbx),%ecx + and $~(MULTIBOOT2_TAG_ALIGN-1),%ecx + +.Lefi_mb2_tsize: + /* Check Multiboot2 information total size. */ + mov %ecx,%r8d + sub %ebx,%r8d + cmp %r8d,MB2_fixed_total_size(%rbx) + jbe .Lrun_bs + + /* Are EFI boot services available? */ + cmpl $MULTIBOOT2_TAG_TYPE_EFI_BS,MB2_tag_type(%rcx) + jne .Lefi_mb2_st + + /* We are on EFI platform and EFI boot services are available. */ + incb efi_platform(%rip) + + /* + * Disable real mode and other legacy stuff which should not + * be run on EFI platforms. + */ + incb skip_realmode(%rip) + jmp .Lefi_mb2_next_tag + +.Lefi_mb2_st: + /* Get EFI SystemTable address from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%rcx) + cmove MB2_efi64_st(%rcx),%rsi + je .Lefi_mb2_next_tag + + /* Get EFI ImageHandle address from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_EFI64_IH,MB2_tag_type(%rcx) + cmove MB2_efi64_ih(%rcx),%rdi + je .Lefi_mb2_next_tag + + /* Is it the end of Multiboot2 information? */ + cmpl $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx) + je .Lrun_bs + +.Lefi_mb2_next_tag: + /* Go to next Multiboot2 information tag. */ + add MB2_tag_size(%rcx),%ecx + add $(MULTIBOOT2_TAG_ALIGN-1),%ecx + and $~(MULTIBOOT2_TAG_ALIGN-1),%ecx + jmp .Lefi_mb2_tsize + +.Lrun_bs: + /* Are EFI boot services available? */ + cmpb $0,efi_platform(%rip) + + /* Jump to .Lmb2_no_bs after switching CPU to x86_32 mode. */ + lea .Lmb2_no_bs(%rip),%r15 + jz x86_32_switch + + /* Is EFI SystemTable address provided by boot loader? */ + test %rsi,%rsi + + /* Jump to .Lmb2_no_st after switching CPU to x86_32 mode. */ + lea .Lmb2_no_st(%rip),%r15 + jz x86_32_switch + + /* Is EFI ImageHandle address provided by boot loader? */ + test %rdi,%rdi + + /* Jump to .Lmb2_no_ih after switching CPU to x86_32 mode. */ + lea .Lmb2_no_ih(%rip),%r15 + jz x86_32_switch + + /* + * Align the stack as UEFI spec requires. Keep it aligned + * before efi_multiboot2() call by pushing/popping even + * numbers of items on it. + */ + and $~15,%rsp + + /* Save Multiboot2 magic on the stack. */ + push %rax + + /* Save EFI ImageHandle on the stack. */ + push %rdi + + /* + * Initialize BSS (no nasty surprises!). + * It must be done earlier than in BIOS case + * because efi_multiboot2() touches it. + */ + lea __bss_start(%rip),%edi + lea __bss_end(%rip),%ecx + sub %edi,%ecx + shr $3,%ecx + xor %eax,%eax + rep stosq + + /* Keep the stack aligned. Do not pop a single item off it. */ + mov (%rsp),%rdi + + /* + * efi_multiboot2() is called according to System V AMD64 ABI: + * - IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable. + */ + call efi_multiboot2 + + /* Just pop an item from the stack. */ + pop %rax + + /* Restore Multiboot2 magic. */ + pop %rax + + /* Jump to trampoline_setup after switching CPU to x86_32 mode. */ + lea trampoline_setup(%rip),%r15 + +x86_32_switch: + mov %r15,%rdi + + cli + + /* Initialize GDTR. */ + lgdt gdt_boot_descr(%rip) + + /* Reload code selector. */ + pushq $BOOT_CS32 + lea cs32_switch(%rip),%edx + push %rdx + lretq + + .code32 + +cs32_switch: + /* Initialize basic data segments. */ + mov $BOOT_DS,%edx + mov %edx,%ds + mov %edx,%es + mov %edx,%ss + /* %esp is initialized later. */ + + /* Load null descriptor to unused segment registers. */ + xor %edx,%edx + mov %edx,%fs + mov %edx,%gs + + /* Disable paging. */ + mov %cr0,%edx + and $(~X86_CR0_PG),%edx + mov %edx,%cr0 + + /* Jump to earlier loaded address. */ + jmp *%edi + __start: cld cli
@@ -157,7 +373,7 @@ __start: /* Not available? BDA value will be fine. */ cmovnz MB_mem_lower(%ebx),%edx - jmp trampoline_setup + jmp trampoline_bios_setup .Lmultiboot2_proto: /* Skip Multiboot2 information fixed part. */
@@ -169,24 +385,41 @@ __start: mov %ecx,%edi sub %ebx,%edi cmp %edi,MB2_fixed_total_size(%ebx) - jbe trampoline_setup + jbe trampoline_bios_setup /* Get mem_lower from Multiboot2 information. */ cmpl $MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO,MB2_tag_type(%ecx) cmove MB2_mem_lower(%ecx),%edx - je trampoline_setup + je .Lmb2_next_tag + + /* EFI IA-32 platforms are not supported. */ + cmpl $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ + je .Lmb2_efi_ia_32 + + /* Bootloader shutdown EFI x64 boot services. */ + cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ + je .Lmb2_no_bs /* Is it the end of Multiboot2 information? */ cmpl $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%ecx) - je trampoline_setup + je trampoline_bios_setup +.Lmb2_next_tag: /* Go to next Multiboot2 information tag. */ add MB2_tag_size(%ecx),%ecx add $(MULTIBOOT2_TAG_ALIGN-1),%ecx and $~(MULTIBOOT2_TAG_ALIGN-1),%ecx jmp .Lmb2_tsize -trampoline_setup: +trampoline_bios_setup: /* Set up trampoline segment 64k below EBDA */ movzwl 0x40e,%ecx /* EBDA segment */ cmp $0xa000,%ecx /* sanity check (high) */
@@ -207,23 +440,54 @@ trampoline_setup: cmp %ecx,%edx /* compare with BDA value */ cmovb %edx,%ecx /* and use the smaller */ -2: /* Reserve 64kb for the trampoline */ - sub $0x1000,%ecx +2: + /* Reserve memory for the trampoline and the low-memory stack. */ + sub $((TRAMPOLINE_SPACE+TRAMPOLINE_STACK_SPACE)>>4),%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) +trampoline_setup: + mov sym_phys(trampoline_phys),%ecx + + /* Get bottom-most low-memory stack address. */ + add $TRAMPOLINE_SPACE,%ecx + /* Save the Multiboot info struct (after relocation) for later use. */ mov $sym_phys(cpu0_stack)+1024,%esp - push %ecx /* Boot trampoline address. */ + push %ecx /* Bottom-most low-memory stack address. */ push %ebx /* Multiboot information address. */ push %eax /* Multiboot magic. */ call reloc mov %eax,sym_phys(multiboot_ptr) - /* Initialize BSS (no nasty surprises!) */ + /* + * Now trampoline_phys points to the following structure (lowest address + * is at the bottom): + * + * +------------------------+ + * | TRAMPOLINE_STACK_SPACE | + * +------------------------+ + * | mbi data | + * +- - - - - - - - - - - - + + * | TRAMPOLINE_SPACE | + * +------------------------+ + * + * mbi data grows downwards from the highest address of TRAMPOLINE_SPACE + * region to the end of the trampoline. The rest of TRAMPOLINE_SPACE is + * reserved for trampoline code and data. + */ + + /* + * Do not zero BSS on EFI platform here. + * It was initialized earlier. + */ + cmpb $0,sym_phys(efi_platform) + jnz 1f + + /* Initialize BSS (no nasty surprises!). */ mov $sym_phys(__bss_start),%edi mov $sym_phys(__bss_end),%ecx sub %edi,%ecx
@@ -231,6 +495,7 @@ trampoline_setup: shr $2,%ecx rep stosl +1: /* Interrogate CPU extended features via CPUID. */ mov $0x80000000,%eax cpuid
@@ -282,6 +547,10 @@ trampoline_setup: cmp $sym_phys(__trampoline_seg_stop),%edi jb 1b + /* Do not parse command line on EFI platform here. */ + cmpb $0,sym_phys(efi_platform) + jnz 1f + /* Bail if there is no command line to parse. */ mov sym_phys(multiboot_ptr),%ebx testl $MBI_CMDLINE,MB_flags(%ebx)
@@ -292,9 +561,9 @@ trampoline_setup: call cmdline_parse_early 1: - /* Switch to low-memory stack. */ + /* Switch to low-memory stack which lives at the end of trampoline region. */ mov sym_phys(trampoline_phys),%edi - lea 0x10000(%edi),%esp + lea TRAMPOLINE_SPACE+TRAMPOLINE_STACK_SPACE(%edi),%esp lea trampoline_boot_cpu_entry-trampoline_start(%edi),%eax pushl $BOOT_CS32 push %eax
xen/arch/x86/boot/reloc.c +1 -1
@@ -16,7 +16,7 @@* This entry point is entered from xen/arch/x86/boot/head.S with: * - 0x4(%esp) = MULTIBOOT_MAGIC, * - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS, -* - 0xc(%esp) = BOOT_TRAMPOLINE_ADDRESS. +* - 0xc(%esp) = TOPMOST_LOW_MEMORY_STACK_ADDRESS. */ asm ( " .text \n"
xen/arch/x86/efi/efi-boot.h +48 -1
73 lines not on this page · raw message
xen/arch/x86/efi/stub.c +39 -0
@@ -3,6 +3,45 @@#include <xen/init.h> #include <xen/lib.h> #include <asm/page.h> +#include <asm/efibind.h> +#include <efi/efidef.h> +#include <efi/eficapsule.h> +#include <efi/eficon.h> +#include <efi/efidevp.h> +#include <efi/efiapi.h> + +/* +* Here we are in EFI stub. EFI calls are not supported due to lack +* of relevant functionality in compiler and/or linker. +* +* efi_multiboot2() is an exception. Please look below for more details. +*/ + +void __init noreturnefi_multiboot2 (EFI_HANDLE ImageHandle, +EFI_SYSTEM_TABLE *SystemTable) +{ +static const CHAR16 __initconst err[] = +L"Xen does not have EFI code build in!\r\nSystem halted!\r\n" ; +SIMPLE_TEXT_OUTPUT_INTERFACE *StdErr; + + StdErr = SystemTable->StdErr ? SystemTable->StdErr : SystemTable->ConOut; + +/* +* Print error message and halt the system. +* +* We have to open code MS x64 calling convention +* in assembly because here this convention may +* not be directly supported by C compiler. +*/ + asmvolatile ( +" call *%3 \n" +"0: hlt \n" +" jmp 0b \n" + :"+c" (StdErr),"=d" (StdErr) :"1" (err),"rm" (StdErr->OutputString) + :"rax" ,"r8" ,"r9" ,"r10" ,"r11" ,"memory" ); + +unreachable (); +}bool efi_enabled (unsigned int feature) {
xen/arch/x86/x86_64/asm-offsets.c +2 -0
@@ -175,6 +175,8 @@ void __dummy__(void)OFFSET (MB2_tag_type, multiboot2_tag_t, type);OFFSET (MB2_tag_size, multiboot2_tag_t, size);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);BLANK (); OFFSET(DOMAIN_vm_assist, struct domain, vm_assist);
xen/arch/x86/xen.lds.S +5 -2
@@ -331,5 +331,8 @@ ASSERT(IS_ALIGNED(__init_end, PAGE_SIZE), "__init_end misaligned") ASSERT(IS_ALIGNED(trampoline_start, 4), "trampoline_start misaligned") ASSERT(IS_ALIGNED(trampoline_end, 4), "trampoline_end misaligned") -ASSERT(IS_ALIGNED(__bss_start, 4), "__bss_start misaligned") -ASSERT(IS_ALIGNED(__bss_end, 4), "__bss_end misaligned") +ASSERT(IS_ALIGNED(__bss_start, 8), "__bss_start misaligned") +ASSERT(IS_ALIGNED(__bss_end, 8), "__bss_end misaligned") + +ASSERT((trampoline_end - trampoline_start) < TRAMPOLINE_SPACE - MBI_SPACE_MIN, + "not enough room for trampoline and mbi data")
xen/common/efi/boot.c +11 -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); +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); +static const EFI_BOOT_SERVICES *__initdata efi_bs;static UINT32 __initdata efi_bs_revision;static EFI_HANDLE __initdata efi_ih;
xen/include/asm-x86/config.h +5 -0
@@ -73,6 +73,11 @@#define STACK_ORDER 3#define STACK_SIZE (PAGE_SIZE << STACK_ORDER) +#define TRAMPOLINE_STACK_SPACE PAGE_SIZE +#define TRAMPOLINE_SPACE (KB(64) - TRAMPOLINE_STACK_SPACE) + +#define MBI_SPACE_MIN (2 * PAGE_SIZE) +/* Primary stack is restricted to 8kB by guard pages. */ #define PRIMARY_STACK_SIZE 8192
xen/include/xen/config.h +1 -0
@@ -70,6 +70,7 @@#define __force#define __bitwise +#define KB (_kb) (_AC(_kb, ULL) << 10)#define MB (_mb) (_AC(_mb, ULL) << 20)#define GB (_gb) (_AC(_gb, ULL) << 30)
Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v15 05/10] x86: add multiboot2 protocol support for EFI platforms
Quoted 4 lines · Daniel Kiper
This way Xen can be loaded on EFI platforms using GRUB2 and other boot loaders which support multiboot2 protocol.
Signed-off-by Daniel Kiper <[email protected]>
I am posting diff between v14 and v15 for your convenience.
xen/arch/x86/boot/head.S +8 -0
@@ -394,10 +394,18 @@ __start: /* EFI IA-32 platforms are not supported. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_efi_ia_32 /* Bootloader shutdown EFI x64 boot services. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_no_bs /* Is it the end of Multiboot2 information? */
xen/arch/x86/efi/stub.c +2 -2
@@ -34,10 +34,10 @@ void __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle,* not be directly supported by C compiler. */ asmvolatile ( -" call *%2 \n" +" call *%3 \n" "0: hlt \n" " jmp 0b \n" - :"+c" (StdErr) :"d" (err),"rm" (StdErr->OutputString) + :"+c" (StdErr),"=d" (StdErr) :"1" (err),"rm" (StdErr->OutputString) :"rax" ,"r8" ,"r9" ,"r10" ,"r11" ,"memory" );unreachable ();
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v15 05/10] x86: add multiboot2 protocol support for EFI platforms
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 14.02.17 at 19:38, <[email protected]> wrote:
xen/arch/x86/boot/head.S +3
-0@@ -394,10 +394,18 @@ __start: /* EFI IA-32 platforms are not supported. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later.
xen/arch/x86/boot/head.S __start: · line 409
Quoted 10 lines
xen/arch/x86/boot/head.S +5
-0+ */ je .Lmb2_efi_ia_32 /* Bootloader shutdown EFI x64 boot services. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_no_bs
I'm afraid I don't view these comments as helpful in understanding the whole situation. That's partly because I don't follow both the "simpler" and "more reliable" parts (using just the information here, i.e. leaving aside what you've given as explanation earlier, albeit I don't think that was fully clarifying things either), and partly because I continue to think that the explanation should go where the labels are (which is what I had meant to suggest with my comment placement in reply to v14). Nor does the adjustment above help (me) understand the correctness of the dual use of .Lmb2_no_bs.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v15 05/10] x86: add multiboot2 protocol support for EFI platforms
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 14.02.17 at 19:38, <[email protected]> wrote:
xen/arch/x86/boot/head.S +4
-0@@ -394,10 +394,18 @@ __start: /* EFI IA-32 platforms are not supported. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_efi_ia_32
Quoted 11 lines
xen/arch/x86/boot/head.S __start: · line 409
Quoted 7 lines
xen/arch/x86/boot/head.S +4
-0/* Bootloader shutdown EFI x64 boot services. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_no_bsI'm afraid I don't view these comments as helpful in understanding the whole situation. That's partly because I don't follow both the "simpler" and "more reliable" parts (using just the information here,
OK, I will clarify it.
Quoted 5 lines
i.e. leaving aside what you've given as explanation earlier, albeit I don't think that was fully clarifying things either), and partly because I continue to think that the explanation should go where the labels are (which is what I had meant to suggest with my comment placement in reply to v14). Nor does the adjustment
OK.
Quoted 2 lines
above help (me) understand the correctness of the dual use of .Lmb2_no_bs.
What do you mean by "dual use of .Lmb2_no_bs."? I would like to be sure.
By the way, what about second half of the patch series? Does it make sense or a little or is it total crap? Could you say something? You have not commented it for a few releases, so, there is a chance that it is OK. However, opposite is also possible. So, if you wish to fix something please say it now than later. Then I will have more time to do the work.
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v15 05/10] x86: add multiboot2 protocol support for EFI platforms
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 22:53, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 14.02.17 at 19:38, <[email protected]> wrote:
xen/arch/x86/boot/head.S +4
-0@@ -394,10 +394,18 @@ __start: /* EFI IA-32 platforms are not supported. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_efi_ia_32Quoted 11 lines
xen/arch/x86/boot/head.S __start: · line 409
Quoted 7 lines
xen/arch/x86/boot/head.S +4
-0/* Bootloader shutdown EFI x64 boot services. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_no_bsI'm afraid I don't view these comments as helpful in understanding the whole situation. That's partly because I don't follow both the "simpler" and "more reliable" parts (using just the information here,
OK, I will clarify it.
Quoted 5 lines
i.e. leaving aside what you've given as explanation earlier, albeit I don't think that was fully clarifying things either), and partly because I continue to think that the explanation should go where the labels are (which is what I had meant to suggest with my comment placement in reply to v14). Nor does the adjustment
Quoted 6 lines
OK.
Quoted 2 lines
above help (me) understand the correctness of the dual use of .Lmb2_no_bs.
What do you mean by "dual use of .Lmb2_no_bs."? I would like to be sure.
As said in v14 review, it's being jumped to from two rather different places, and hence the VGA aspect isn't obviously the same for both.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v15 05/10] x86: add multiboot2 protocol support for EFI platforms
Quoted 37 lines · Jan Beulich
Quoted 37 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 22:53, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 14.02.17 at 19:38, <[email protected]> wrote:
xen/arch/x86/boot/head.S +4
-0@@ -394,10 +394,18 @@ __start: /* EFI IA-32 platforms are not supported. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_efi_ia_32Quoted 11 lines
xen/arch/x86/boot/head.S __start: · line 409
Quoted 7 lines
xen/arch/x86/boot/head.S +4
-0/* Bootloader shutdown EFI x64 boot services. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_no_bsI'm afraid I don't view these comments as helpful in understanding the whole situation. That's partly because I don't follow both the "simpler" and "more reliable" parts (using just the information here,
OK, I will clarify it.
Quoted 5 lines
i.e. leaving aside what you've given as explanation earlier, albeit I don't think that was fully clarifying things either), and partly because I continue to think that the explanation should go where the labels are (which is what I had meant to suggest with my comment placement in reply to v14). Nor does the adjustment
OK.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
above help (me) understand the correctness of the dual use of .Lmb2_no_bs.
What do you mean by "dual use of .Lmb2_no_bs."? I would like to be sure.
As said in v14 review, it's being jumped to from two rather different places, and hence the VGA aspect isn't obviously the same for both.
OK, I will try to clarify. If a bootloader called us using __efi64_mb2_start we are sure that we are running on EFI platform and there is no VGA there. It means that we can safely zap vga_text_buffer unconditionally in first steps (we do that in second instruction). Then we do not need to take care about that in case of error. And one of these errors is lack of MULTIBOOT2_TAG_TYPE_EFI_BS tag. It means that EFI boot services are shutdown. So, we are in black hole. We have to inform user about that and halt the system. And that is why we jump to .Lmb2_no_bs here.
On the other hand if the bootloader called us using start label then in most cases we are running on legacy BIOS platforms. However, if the bootloader also provided MULTIBOOT2_TAG_TYPE_EFI64 tag here then we are sure that we are running on EFI platform and EFI boot services are shutdown. This happens when we are loaded by old boot loader which does not understand MULTIBOOT2_HEADER_TAG_EFI_BS and MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI64 tags. So, as above we can jump to .Lmb2_no_bs here too.
I hope that helps.
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v15 05/10] x86: add multiboot2 protocol support for EFI platforms
Quoted 46 lines · Daniel Kiper
Quoted 37 lines · Jan Beulich
Quoted 37 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 22:53, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 14.02.17 at 19:38, <[email protected]> wrote:
xen/arch/x86/boot/head.S +4
-0@@ -394,10 +394,18 @@ __start: /* EFI IA-32 platforms are not supported. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_efi_ia_32Quoted 11 lines
xen/arch/x86/boot/head.S __start: · line 409
Quoted 7 lines
xen/arch/x86/boot/head.S +4
-0/* Bootloader shutdown EFI x64 boot services. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_no_bsI'm afraid I don't view these comments as helpful in understanding the whole situation. That's partly because I don't follow both the "simpler" and "more reliable" parts (using just the information here,
OK, I will clarify it.
Quoted 5 lines
i.e. leaving aside what you've given as explanation earlier, albeit I don't think that was fully clarifying things either), and partly because I continue to think that the explanation should go where the labels are (which is what I had meant to suggest with my comment placement in reply to v14). Nor does the adjustment
OK.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
above help (me) understand the correctness of the dual use of .Lmb2_no_bs.
What do you mean by "dual use of .Lmb2_no_bs."? I would like to be sure.
As said in v14 review, it's being jumped to from two rather different places, and hence the VGA aspect isn't obviously the same for both.
Quoted 7 lines
OK, I will try to clarify. If a bootloader called us using
__efi64_mb2_startwe are sure that we are running on EFI platform and there is no VGA there. It means that we can safely zapvga_text_bufferunconditionally in first steps (we do that in second instruction). Then we do not need to take care about that in case of error. And one of these errors is lack ofMULTIBOOT2_TAG_TYPE_EFI_BStag. It means that EFI boot services are shutdown. So, we are in black hole. We have to inform user about that and halt the system. And that is why we
Not looking at the code but the words here. If ExitBootServices() has been called we should be able to still boot if the memory map was passed along. Are we deferring that use case to a follow on?
Signature · 1 line
Doug Goldstein
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v15 05/10] x86: add multiboot2 protocol support for EFI platforms
Quoted 55 lines · Doug Goldstein
Quoted 46 lines · Daniel Kiper
Quoted 37 lines · Jan Beulich
Quoted 37 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 22:53, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 14.02.17 at 19:38, <[email protected]> wrote:
xen/arch/x86/boot/head.S +4
-0@@ -394,10 +394,18 @@ __start: /* EFI IA-32 platforms are not supported. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_efi_ia_32Quoted 11 lines
xen/arch/x86/boot/head.S __start: · line 409
Quoted 7 lines
xen/arch/x86/boot/head.S +4
-0/* Bootloader shutdown EFI x64 boot services. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_no_bsI'm afraid I don't view these comments as helpful in understanding the whole situation. That's partly because I don't follow both the "simpler" and "more reliable" parts (using just the information here,
OK, I will clarify it.
Quoted 5 lines
i.e. leaving aside what you've given as explanation earlier, albeit I don't think that was fully clarifying things either), and partly because I continue to think that the explanation should go where the labels are (which is what I had meant to suggest with my comment placement in reply to v14). Nor does the adjustment
OK.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
above help (me) understand the correctness of the dual use of .Lmb2_no_bs.
What do you mean by "dual use of .Lmb2_no_bs."? I would like to be sure.
As said in v14 review, it's being jumped to from two rather different places, and hence the VGA aspect isn't obviously the same for both.
Quoted 7 lines
OK, I will try to clarify. If a bootloader called us using
__efi64_mb2_startwe are sure that we are running on EFI platform and there is no VGA there. It means that we can safely zapvga_text_bufferunconditionally in first steps (we do that in second instruction). Then we do not need to take care about that in case of error. And one of these errors is lack ofMULTIBOOT2_TAG_TYPE_EFI_BStag. It means that EFI boot services are shutdown. So, we are in black hole. We have to inform user about that and halt the system. And that is why we
Quoted 3 lines
Not looking at the code but the words here. If
ExitBootServices()has been called we should be able to still boot if the memory map was passed along. Are we deferring that use case to a follow on?
In theory yes but, IIRC, we have to significantly refactor Xen EFI boot code then due to lack of EFI boot services. I tried to do that once but quickly realized that it does not pays.
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v15 05/10] x86: add multiboot2 protocol support for EFI platforms
In reply to Daniel KiperQuoted 47 lines
Quoted 1 line
Quoted 1 line · On 16.02.17 at 22:49, <[email protected]> wrote:
Quoted 37 lines · Jan Beulich
Quoted 37 lines
Quoted 1 line
Quoted 1 line · On 15.02.17 at 22:53, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 14.02.17 at 19:38, <[email protected]> wrote:
xen/arch/x86/boot/head.S +4
-0@@ -394,10 +394,18 @@ __start: /* EFI IA-32 platforms are not supported. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_efi_ia_32Quoted 11 lines
xen/arch/x86/boot/head.S __start: · line 409
Quoted 7 lines
xen/arch/x86/boot/head.S +4
-0/* Bootloader shutdown EFI x64 boot services. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx) + /* + * Here we should zap vga_text_buffer. However, we can disable + * VGA updates in simpler and more reliable way later. + */ je .Lmb2_no_bsI'm afraid I don't view these comments as helpful in understanding the whole situation. That's partly because I don't follow both the "simpler" and "more reliable" parts (using just the information here,
OK, I will clarify it.
Quoted 5 lines
i.e. leaving aside what you've given as explanation earlier, albeit I don't think that was fully clarifying things either), and partly because I continue to think that the explanation should go where the labels are (which is what I had meant to suggest with my comment placement in reply to v14). Nor does the adjustment
OK.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
above help (me) understand the correctness of the dual use of .Lmb2_no_bs.
What do you mean by "dual use of .Lmb2_no_bs."? I would like to be sure.
As said in v14 review, it's being jumped to from two rather different places, and hence the VGA aspect isn't obviously the same for both.
Quoted 6 lines
OK, I will try to clarify. If a bootloader called us using
__efi64_mb2_startwe are sure that we are running on EFI platform and there is no VGA there. It means that we can safely zapvga_text_bufferunconditionally in first steps (we do that in second instruction). Then we do not need to take care about that in case of error. And one of these errors is lack ofMULTIBOOT2_TAG_TYPE_EFI_BStag. It means that EFI boot services are shutdown. So, we are in black hole.
Well, see - this is one of my problems with the overall approach here. Running on EFI in no way means there _is_ no VGA there, it only means there _may not be_ any VGA. With boot services shut down and without serial console you have no way of informing the user, so making an attempt at writing something to VGA may still be helpful. In the worst case the memory writes go no-where, to RAM, or to an unrelated device (both of the latter rather unlikely on x86). Granted there's the second problem of you perhaps not knowing the video mode, and hence having a hard time producing output that's also readable.
Quoted 10 lines
We have to inform user about that and halt the system. And that is why we jump to .Lmb2_no_bs here.
On the other hand if the bootloader called us using start label then in most cases we are running on legacy BIOS platforms. However, if the bootloader also provided
MULTIBOOT2_TAG_TYPE_EFI64tag here then we are sure that we are running on EFI platform and EFI boot services are shutdown. This happens when we are loaded by old boot loader which does not understandMULTIBOOT2_HEADER_TAG_EFI_BSandMULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI64tags. So, as above we can jump to .Lmb2_no_bs here too.
However, when the boot loader invoked our start label, can't we be sure there is VGA (at least as much or as little as there would be on non-EFI platforms, where headless systems certainly also exist)? I don't think the boot loader can reasonably invoke our legacy entry point with the system in a state that's not legacy compatible (which, among other things, means if there is VGA, then it would be in traditional 80x25 text mode). Hence this second use of the label ought to avoid suppressing the VGA output attempt in any case.
Quoted 1 line
I hope that helps.
The above aside, yes, it does. An abbreviated variant of this is what I would hope to have attached as comment to the error handling labels, to namely help readers understand why some of them inhibit VGA output while others don't.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v15 6/10 x86: change default load address from 1 MiB to 2 MiB
In reply to Daniel KiperSubsequent patches introducing relocatable early boot code play with page tables using 2 MiB huge pages. If load address is not aligned at 2 MiB then code touching such page tables must have special cases for start and end of Xen image memory region. So, let's make life easier and move default load address from 1 MiB to 2 MiB. This way page table code will be nice and easy. Hence, there is a chance that it will be less error prone too... :-)))
Additionally, drop first 2 MiB mapping from Xen image mapping. It is no longer needed.
---
v8 - suggestions/fixes:
- drop first 2 MiB mapping from Xen image mapping (suggested by Jan Beulich),
- improve commit message.
v7 - suggestions/fixes:
- minor cleanups
(suggested by Jan Beulich).
--- xen/arch/x86/Makefile | 2 +- xen/arch/x86/Rules.mk | 3 +++ xen/arch/x86/boot/head.S | 8 -------- xen/arch/x86/boot/x86_64.S | 5 +++-- xen/arch/x86/setup.c | 3 ++- xen/arch/x86/xen.lds.S | 2 +- 6 files changed, 10 insertions(+), 13 deletions(-)
xen/arch/x86/Makefile +1 -1
@@ -90,7 +90,7 @@ all_symbols = endif $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32 - ./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) 0x100000 \ + ./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) $(XEN_IMG_OFFSET) \ `$(NM) $(TARGET)-syms | sed -ne 's/^\([^ ]*\) . __2M_rwdata_end$$/0x\1/p'` ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
xen/arch/x86/Rules.mk +3 -0
@@ -1,9 +1,12 @@ ######################################## # x86-specific definitions +XEN_IMG_OFFSET := 0x200000 + CFLAGS += -I$(BASEDIR)/include CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-generic CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-default +CFLAGS += -DXEN_IMG_OFFSET=$(XEN_IMG_OFFSET) CFLAGS += '-D__OBJECT_LABEL__=$(subst /,$$,$(subst -,_,$(subst $(BASEDIR)/,,$(CURDIR))/$@))' # Prevent floating-point variables from creeping into Xen.
xen/arch/x86/boot/head.S +0 -8
@@ -519,14 +519,6 @@ trampoline_setup: mov %eax,sym_phys(boot_tsc_stamp) mov %edx,sym_phys(boot_tsc_stamp+4) - /* - * During boot, hook 4kB mappings of first 2MB of memory into L2. - * This avoids mixing cachability for the legacy VGA region, and is - * corrected when Xen relocates itself. - */ - mov $sym_phys(l1_identmap)+__PAGE_HYPERVISOR,%edi - mov %edi,sym_phys(l2_xenmap) - /* Apply relocations to bootstrap trampoline. */ mov sym_phys(trampoline_phys),%edx mov $sym_phys(__trampoline_rel_start),%edi
xen/arch/x86/boot/x86_64.S +3 -2
@@ -121,8 +121,9 @@ GLOBAL(l2_identmap) * page. */ GLOBAL(l2_xenmap) - idx = 0 - .rept 8 + .quad 0 + idx = 1 + .rept 7 .quad sym_phys(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE) idx = idx + 1 .endr
xen/arch/x86/setup.c +2 -1
@@ -999,7 +999,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)* Undo the temporary-hooking of the l1_identmap. __2M_text_start * is contained in this PTE. */ -BUG_ON (l2_table_offset ((unsigned long )_erodata) == +BUG_ON (using_2M_mapping () && +l2_table_offset ((unsigned long )_erodata) ==l2_table_offset ((unsigned long )_stext)); *pl2e++ =l2e_from_pfn (xen_phys_start >>PAGE_SHIFT ,PAGE_HYPERVISOR_RX | _PAGE_PSE);
xen/arch/x86/xen.lds.S +1 -1
@@ -55,7 +55,7 @@ SECTIONS __2M_text_start = .; /* Start of 2M superpages, mapped RX. */ #endif - . = __XEN_VIRT_START + MB(1); + . = __XEN_VIRT_START + XEN_IMG_OFFSET; _start = .; .text : { _stext = .; /* Text and read-only data */
Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v15 7/10 x86/setup: use XEN_IMG_OFFSET instead of...
In reply to Daniel Kiper..calculating its value during runtime.
--- xen/arch/x86/setup.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
xen/arch/x86/setup.c +1 -3
@@ -943,7 +943,6 @@ void __init noreturn __start_xen(unsigned long mbi_p)l4_pgentry_t *pl4e;l3_pgentry_t *pl3e;l2_pgentry_t *pl2e; -uint64_t load_start;int i, j, k;/* Select relocation address. */
@@ -957,9 +956,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)* with a barrier(). After this we must *not* modify static/global * data until after we have switched to the relocated pagetables! */ - load_start = (unsigned long )_start -XEN_VIRT_START ;barrier (); -move_memory (e + load_start, load_start, _end - _start,1 ); +move_memory (e +XEN_IMG_OFFSET ,XEN_IMG_OFFSET , _end - _start,1 );/* Walk initial pagetables, relocating page directory entries. */ pl4e =__va (__pa (idle_pg_table));
Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v15 8/10 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 2 MiB and ends at ~5 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 and help boot loader to relocate image in proper way by suggesting, not requesting specific load addresses as it is right now, allowed address ranges. This patch does former. It does not add multiboot2 protocol interface which is done in "x86: add multiboot2 protocol support for relocatable images" patch.
This patch changes following things:
- %esi register is used as a storage for Xen image load base address; it is mostly unused in early boot code and preserved during C functions calls in 32-bit mode,
- %fs is used as base for Xen data relative addressing in 32-bit code if it is possible; %esi is used for that thing during error printing because it is not always possible to properly and efficiently initialize %fs.
---
v13 - suggestions/fixes:
- move gdt_boot_descr to .init.data section
(suggested by Jan Beulich).
v12 - suggestions/fixes:
- store Xen image load base address directly into %esi,
- store Xen image load base address after x86_32_switch (suggested by Doug Goldstein),
- improve commit message.
v8 - suggestions/fixes:
- use shld instead of mov and shr in BOOT_FS segment descriptor base address initialization (suggested by Jan Beulich),
- simplify code updating frame addresses in page tables (suggested by Jan Beulich),
- print Xen image base addresses using "%#lx" format (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich).
v6 - suggestions/fixes:
- leave static mapping of first
16 MiB in l2_identmap as is
(suggested by Jan Beulich),
- use xen_phys_start instead of xen_img_load_base_addr (suggested by Daniel Kiper and Jan Beulich),
- simplify BOOT_FS segment descriptor
base address initialization
(suggested by Jan Beulich),
- fix BOOT_FS segment limit
(suggested by Jan Beulich),
- do not rename sym_phys in this patch (suggested by Jan Beulich),
- rename esi_offset/fs_offset to sym_esi/sym_fs respectively
(suggested by Jan Beulich),
- use add instead of lea in assembly
error printing code
(suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- improve commit message
(suggested by Jan Beulich),
- various minor cleanups and fixes
(suggested by Jan Beulich).
v4 - suggestions/fixes:
- do not relocate Xen image if boot loader did work for us (suggested by Andrew Cooper and Jan Beulich),
- initialize xen_img_load_base_addr in EFI boot code too,
- properly initialize trampoline_xen_phys_start,
- calculate Xen image load base address in
x86_64 code ourselves,
(suggested by Jan Beulich),
- change how and when Xen image base address is printed,
- use %fs instead of %esi for relative addressing (suggested by Andrew Cooper and Jan Beulich),
- create esi_offset and fs_offset() macros in assembly,
- calculate <final-exec-addr> mkelf32 argument automatically,
- optimize and cleanup code,
- improve comments,
- improve commit message.
v3 - suggestions/fixes:
- improve segment registers initialization (suggested by Jan Beulich),
- simplify Xen image load base address calculation (suggested by Jan Beulich),
- use %esi and %r15d instead of %ebp to store Xen image load base address,
- use %esi instead of %fs for relative addressing; this way we get shorter and simpler code,
- rename some variables and constants (suggested by Jan Beulich),
- improve comments
(suggested by Konrad Rzeszutek Wilk),
- improve commit message
(suggested by Jan Beulich).
--- xen/arch/x86/boot/head.S | 170 ++++++++++++++++++++++++++++--------- xen/arch/x86/boot/trampoline.S | 5 ++ xen/arch/x86/boot/x86_64.S | 21 +++-- xen/arch/x86/setup.c | 14 +-- xen/arch/x86/x86_64/asm-offsets.c | 3 + xen/include/asm-x86/page.h | 2 +- 6 files changed, 158 insertions(+), 57 deletions(-)
xen/arch/x86/boot/head.S +131 -39
@@ -13,12 +13,15 @@ .code32 #define sym_phys(sym) ((sym) - __XEN_VIRT_START) +#define sym_esi(sym) sym_phys(sym)(%esi) +#define sym_fs(sym) %fs:sym_phys(sym) #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)
@@ -101,13 +104,6 @@ multiboot2_header_start: .Lmultiboot2_header_end: .section .init.rodata, "a", @progbits - .align 4 - - .word 0 -gdt_boot_descr: - .word 6*8-1 - .long sym_phys(trampoline_gdt) - .long 0 /* Needed for 64-bit lgdt */ .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!" .Lbad_ldr_msg: .asciz "ERR: Not a Multiboot bootloader!"
@@ -119,6 +115,13 @@ gdt_boot_descr: .section .init.data, "aw", @progbits .align 4 + .word 0 +gdt_boot_descr: + .word 7*8-1 +gdt_boot_base: + .long sym_phys(trampoline_gdt) + .long 0 /* Needed for 64-bit lgdt */ + vga_text_buffer: .long 0xb8000
@@ -128,27 +131,27 @@ efi_platform: .section .init.text, "ax", @progbits bad_cpu: - mov $(sym_phys(.Lbad_cpu_msg)),%esi # Error message + add $sym_phys(.Lbad_cpu_msg),%esi # Error message jmp .Lget_vtb not_multiboot: - mov $(sym_phys(.Lbad_ldr_msg)),%esi # Error message + add $sym_phys(.Lbad_ldr_msg),%esi # Error message jmp .Lget_vtb .Lmb2_no_st: - mov $(sym_phys(.Lbad_ldr_nst)),%esi # Error message + add $sym_phys(.Lbad_ldr_nst),%esi # Error message jmp .Lget_vtb .Lmb2_no_ih: - mov $(sym_phys(.Lbad_ldr_nih)),%esi # Error message + add $sym_phys(.Lbad_ldr_nih),%esi # Error message jmp .Lget_vtb .Lmb2_no_bs: - mov $(sym_phys(.Lbad_ldr_nbs)),%esi # Error message + add $sym_phys(.Lbad_ldr_nbs),%esi # Error message xor %edi,%edi # No VGA text buffer jmp .Lsend_chr .Lmb2_efi_ia_32: - mov $(sym_phys(.Lbad_efi_msg)),%esi # Error message + add $sym_phys(.Lbad_efi_msg),%esi # Error message xor %edi,%edi # No VGA text buffer jmp .Lsend_chr .Lget_vtb: - mov sym_phys(vga_text_buffer),%edi + mov sym_esi(vga_text_buffer),%edi .Lsend_chr: mov (%esi),%bl test %bl,%bl # Terminate on '\0' sentinel
@@ -312,9 +315,13 @@ __efi64_mb2_start: x86_32_switch: mov %r15,%rdi + /* Store Xen image load base address in place accessible for 32-bit code. */ + lea __image_base__(%rip),%esi + cli /* Initialize GDTR. */ + add %esi,gdt_boot_base(%rip) lgdt gdt_boot_descr(%rip) /* Reload code selector. */
@@ -350,12 +357,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 load base address. */ + mov $sym_phys(__image_base__),%esi /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value. */ xor %edx,%edx
@@ -420,6 +423,25 @@ __start: jmp .Lmb2_tsize trampoline_bios_setup: + /* + * Called on legacy BIOS platforms only. + * + * Initialize GDTR and basic data segments. + */ + add %esi,sym_esi(gdt_boot_base) + lgdt sym_esi(gdt_boot_descr) + + mov $BOOT_DS,%ecx + mov %ecx,%ds + mov %ecx,%es + mov %ecx,%ss + /* %esp is initialized later. */ + + /* Load null descriptor to unused segment registers. */ + xor %ecx,%ecx + mov %ecx,%fs + mov %ecx,%gs + /* Set up trampoline segment 64k below EBDA */ movzwl 0x40e,%ecx /* EBDA segment */ cmp $0xa000,%ecx /* sanity check (high) */
@@ -447,21 +469,49 @@ trampoline_bios_setup: /* 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,sym_esi(trampoline_phys) trampoline_setup: - mov sym_phys(trampoline_phys),%ecx + /* + * Called on legacy BIOS and EFI platforms. + * + * Initialize 0-15 bits of BOOT_FS segment descriptor base address. + */ + mov %si,BOOT_FS+2+sym_esi(trampoline_gdt) + + /* Initialize 16-23 bits of BOOT_FS segment descriptor base address. */ + shld $16,%esi,%edx + mov %dl,BOOT_FS+4+sym_esi(trampoline_gdt) + + /* Initialize 24-31 bits of BOOT_FS segment descriptor base address. */ + mov %dh,BOOT_FS+7+sym_esi(trampoline_gdt) + + /* + * Initialize %fs and later use it to access Xen data if possible. + * According to Intel 64 and IA-32 Architectures Software Developer's + * Manual it is safe to do that without reloading GDTR before. + */ + mov $BOOT_FS,%edx + mov %edx,%fs + + /* Save Xen image load base address for later use. */ + mov %esi,sym_fs(xen_phys_start) + mov %esi,sym_fs(trampoline_xen_phys_start) + + /* Setup stack. %ss was initialized earlier. */ + lea 1024+sym_esi(cpu0_stack),%esp + + mov sym_fs(trampoline_phys),%ecx /* Get bottom-most low-memory stack address. */ add $TRAMPOLINE_SPACE,%ecx /* Save the Multiboot info struct (after relocation) for later use. */ - mov $sym_phys(cpu0_stack)+1024,%esp push %ecx /* Bottom-most low-memory stack address. */ push %ebx /* Multiboot information address. */ push %eax /* Multiboot magic. */ call reloc - mov %eax,sym_phys(multiboot_ptr) + mov %eax,sym_fs(multiboot_ptr) /* * Now trampoline_phys points to the following structure (lowest address
@@ -484,16 +534,20 @@ trampoline_setup: * Do not zero BSS on EFI platform here. * It was initialized earlier. */ - cmpb $0,sym_phys(efi_platform) + cmpb $0,sym_fs(efi_platform) jnz 1f /* Initialize BSS (no nasty surprises!). */ mov $sym_phys(__bss_start),%edi mov $sym_phys(__bss_end),%ecx + push %fs + pop %es sub %edi,%ecx xor %eax,%eax shr $2,%ecx rep stosl + push %ds + pop %es 1: /* Interrogate CPU extended features via CPUID. */
@@ -507,8 +561,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,sym_fs(cpuid_ext_features) + mov %edx,sym_fs(boot_cpu_data)+CPUINFO_FEATURE_OFFSET(X86_FEATURE_LM) /* Check for availability of long mode. */ bt $cpufeat_bit(X86_FEATURE_LM),%edx
@@ -516,15 +570,52 @@ 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,sym_fs(boot_tsc_stamp) + mov %edx,sym_fs(boot_tsc_stamp)+4 + + /* + * Update frame addresses in page tables excluding l2_identmap + * without its first entry which points to l1_identmap. + */ + mov $((__page_tables_end-__page_tables_start)/8),%ecx + mov $(((l2_identmap-__page_tables_start)/8)+1),%edx +1: cmp $((l2_identmap+l2_identmap_sizeof-__page_tables_start)/8),%ecx + cmove %edx,%ecx + testl $_PAGE_PRESENT,sym_fs(__page_tables_start)-8(,%ecx,8) + jz 2f + add %esi,sym_fs(__page_tables_start)-8(,%ecx,8) +2: loop 1b + + /* Initialize L2 boot-map/direct map page table entries (16MB). */ + lea sym_esi(start),%ebx + lea (1<<L2_PAGETABLE_SHIFT)*7+(PAGE_HYPERVISOR|_PAGE_PSE)(%ebx),%eax + shr $(L2_PAGETABLE_SHIFT-3),%ebx + mov $8,%ecx +1: mov %eax,sym_fs(l2_bootmap)-8(%ebx,%ecx,8) + mov %eax,sym_fs(l2_identmap)-8(%ebx,%ecx,8) + sub $(1<<L2_PAGETABLE_SHIFT),%eax + loop 1b + + /* Initialize L3 boot-map page directory entry. */ + lea __PAGE_HYPERVISOR+(L2_PAGETABLE_ENTRIES*8)*3+sym_esi(l2_bootmap),%eax + mov $4,%ecx +1: mov %eax,sym_fs(l3_bootmap)-8(,%ecx,8) + sub $(L2_PAGETABLE_ENTRIES*8),%eax + loop 1b + + /* + * During boot, hook 4kB mappings of first 2MB of memory into L2. + * This avoids mixing cachability for the legacy VGA region. + */ + lea __PAGE_HYPERVISOR+sym_esi(l1_identmap),%edi + mov %edi,sym_fs(l2_bootmap) /* Apply relocations to bootstrap trampoline. */ - mov sym_phys(trampoline_phys),%edx + mov sym_fs(trampoline_phys),%edx mov $sym_phys(__trampoline_rel_start),%edi 1: - mov (%edi),%eax - add %edx,(%edi,%eax) + mov %fs:(%edi),%eax + add %edx,%fs:(%edi,%eax) add $4,%edi cmp $sym_phys(__trampoline_rel_stop),%edi jb 1b
@@ -533,28 +624,29 @@ trampoline_setup: shr $4,%edx mov $sym_phys(__trampoline_seg_start),%edi 1: - mov (%edi),%eax - mov %dx,(%edi,%eax) + mov %fs:(%edi),%eax + mov %dx,%fs:(%edi,%eax) add $4,%edi cmp $sym_phys(__trampoline_seg_stop),%edi jb 1b /* Do not parse command line on EFI platform here. */ - cmpb $0,sym_phys(efi_platform) + cmpb $0,sym_fs(efi_platform) jnz 1f /* Bail if there is no command line to parse. */ - mov sym_phys(multiboot_ptr),%ebx + mov sym_fs(multiboot_ptr),%ebx testl $MBI_CMDLINE,MB_flags(%ebx) jz 1f - pushl $sym_phys(early_boot_opts) + lea sym_esi(early_boot_opts),%eax + push %eax pushl MB_cmdline(%ebx) call cmdline_parse_early 1: /* Switch to low-memory stack which lives at the end of trampoline region. */ - mov sym_phys(trampoline_phys),%edi + mov sym_fs(trampoline_phys),%edi lea TRAMPOLINE_SPACE+TRAMPOLINE_STACK_SPACE(%edi),%esp lea trampoline_boot_cpu_entry-trampoline_start(%edi),%eax pushl $BOOT_CS32
@@ -563,7 +655,7 @@ trampoline_setup: /* Copy bootstrap trampoline to low memory, below 1MB. */ mov $sym_phys(trampoline_start),%esi mov $((trampoline_end - trampoline_start) / 4),%ecx - rep movsl + rep movsl %fs:(%esi),%es:(%edi) /* Jump into the relocated trampoline. */ lret
xen/arch/x86/boot/trampoline.S +5 -0
@@ -54,6 +54,11 @@ trampoline_gdt: /* 0x0028: real-mode data @ BOOT_TRAMPOLINE */ .long 0x0000ffff .long 0x00009200 + /* + * 0x0030: ring 0 Xen data, 16 MiB size, base + * address is computed during runtime. + */ + .quad 0x00c0920000000fff .pushsection .trampoline_rel, "a" .long trampoline_gdt + BOOT_PSEUDORM_CS + 2 - .
xen/arch/x86/boot/x86_64.S +10 -11
@@ -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
@@ -102,6 +101,13 @@ l1_identmap: .size l1_identmap, . - l1_identmap /* + * __page_tables_start does not cover l1_identmap because it (l1_identmap) + * contains 1-1 mappings. This means that frame addresses of these mappings + * are static and should not be updated during runtime. + */ +GLOBAL(__page_tables_start) + +/* * Space for mapping the first 4GB of memory, with the first 16 megabytes * actualy mapped (mostly using superpages). Uses 4x 4k pages. */
@@ -186,21 +192,14 @@ GLOBAL(idle_pg_table) GLOBAL(__page_tables_end) -/* Init pagetables. Enough page directories to map into the bottom 1GB. */ +/* Init pagetables. Enough page directories to map into 4GB. */ .section .init.data, "aw", @progbits .align PAGE_SIZE, 0 GLOBAL(l2_bootmap) - .quad sym_phys(l1_identmap) + __PAGE_HYPERVISOR - idx = 1 - .rept 7 - .quad (idx << L2_PAGETABLE_SHIFT) | __PAGE_HYPERVISOR | _PAGE_PSE - idx = idx + 1 - .endr - .fill L2_PAGETABLE_ENTRIES - 8, 8, 0 + .fill 4 * L2_PAGETABLE_ENTRIES, 8, 0 .size l2_bootmap, . - l2_bootmap GLOBAL(l3_bootmap) - .quad sym_phys(l2_bootmap) + __PAGE_HYPERVISOR - .fill L3_PAGETABLE_ENTRIES - 1, 8, 0 + .fill L3_PAGETABLE_ENTRIES, 8, 0 .size l3_bootmap, . - l3_bootmap
xen/arch/x86/setup.c +8 -6
@@ -330,9 +330,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;
@@ -716,6 +713,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)printk ("Command line: %s\n" , cmdline); +printk ("Xen image load base address: %#lx\n" , xen_phys_start); +printk ("Video information:\n" );/* Print VGA display mode information. */
@@ -973,7 +972,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)/* 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);
@@ -983,7 +982,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)/* 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);
@@ -1006,7 +1005,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) {unsigned int flags; -if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) ) +if ( !(l2e_get_flags (*pl2e) & _PAGE_PRESENT) || + (l2e_get_pfn (*pl2e) >PFN_DOWN (xen_phys_start)) )continue ;if ( !using_2M_mapping () )
@@ -1060,6 +1060,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) : "memory" );bootstrap_map (NULL ); + +printk ("New Xen image base address: %#lx\n" , xen_phys_start); }/* Is the region suitable for relocating the multiboot modules? */
xen/arch/x86/x86_64/asm-offsets.c +3 -0
@@ -179,5 +179,8 @@ void __dummy__(void)OFFSET (MB2_efi64_ih, multiboot2_tag_efi64_ih_t, pointer);BLANK (); +DEFINE (l2_identmap_sizeof,sizeof (l2_identmap)); +BLANK (); + OFFSET(DOMAIN_vm_assist, struct domain, vm_assist); }
xen/include/asm-x86/page.h +1 -1
@@ -288,7 +288,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_fixmap[L1_PAGETABLE_ENTRIES ];
Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v15 9/10 x86/boot: rename sym_phys() to sym_offs()
In reply to Daniel KiperThis way macro name better describes its function. Currently it is used to calculate symbol offset in relation to the beginning of Xen image mapping. However, value returned by sym_offs() for a given symbol is not always equal its physical address.
There is no functional change.
---
v8 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).
--- xen/arch/x86/boot/head.S | 38 +++++++++++++++++++------------------- xen/arch/x86/boot/trampoline.S | 2 +- xen/arch/x86/boot/wakeup.S | 4 ++-- xen/arch/x86/boot/x86_64.S | 18 +++++++++--------- 4 files changed, 31 insertions(+), 31 deletions(-)
xen/arch/x86/boot/head.S +19 -19
@@ -12,9 +12,9 @@ .text .code32 -#define sym_phys(sym) ((sym) - __XEN_VIRT_START) -#define sym_esi(sym) sym_phys(sym)(%esi) -#define sym_fs(sym) %fs:sym_phys(sym) +#define sym_offs(sym) ((sym) - __XEN_VIRT_START) +#define sym_esi(sym) sym_offs(sym)(%esi) +#define sym_fs(sym) %fs:sym_offs(sym) #define BOOT_CS32 0x0008 #define BOOT_CS64 0x0010
@@ -97,7 +97,7 @@ multiboot2_header_start: /* EFI64 Multiboot2 entry point. */ mb2ht_init MB2_HT(ENTRY_ADDRESS_EFI64), MB2_HT(OPTIONAL), \ - sym_phys(__efi64_mb2_start) + sym_offs(__efi64_mb2_start) /* Multiboot2 header end tag. */ mb2ht_init MB2_HT(END), MB2_HT(REQUIRED)
@@ -119,7 +119,7 @@ multiboot2_header_start: gdt_boot_descr: .word 7*8-1 gdt_boot_base: - .long sym_phys(trampoline_gdt) + .long sym_offs(trampoline_gdt) .long 0 /* Needed for 64-bit lgdt */ vga_text_buffer:
@@ -131,23 +131,23 @@ efi_platform: .section .init.text, "ax", @progbits bad_cpu: - add $sym_phys(.Lbad_cpu_msg),%esi # Error message + add $sym_offs(.Lbad_cpu_msg),%esi # Error message jmp .Lget_vtb not_multiboot: - add $sym_phys(.Lbad_ldr_msg),%esi # Error message + add $sym_offs(.Lbad_ldr_msg),%esi # Error message jmp .Lget_vtb .Lmb2_no_st: - add $sym_phys(.Lbad_ldr_nst),%esi # Error message + add $sym_offs(.Lbad_ldr_nst),%esi # Error message jmp .Lget_vtb .Lmb2_no_ih: - add $sym_phys(.Lbad_ldr_nih),%esi # Error message + add $sym_offs(.Lbad_ldr_nih),%esi # Error message jmp .Lget_vtb .Lmb2_no_bs: - add $sym_phys(.Lbad_ldr_nbs),%esi # Error message + add $sym_offs(.Lbad_ldr_nbs),%esi # Error message xor %edi,%edi # No VGA text buffer jmp .Lsend_chr .Lmb2_efi_ia_32: - add $sym_phys(.Lbad_efi_msg),%esi # Error message + add $sym_offs(.Lbad_efi_msg),%esi # Error message xor %edi,%edi # No VGA text buffer jmp .Lsend_chr .Lget_vtb:
@@ -358,7 +358,7 @@ __start: cli /* Load default Xen image load base address. */ - mov $sym_phys(__image_base__),%esi + mov $sym_offs(__image_base__),%esi /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value. */ xor %edx,%edx
@@ -538,8 +538,8 @@ trampoline_setup: jnz 1f /* Initialize BSS (no nasty surprises!). */ - mov $sym_phys(__bss_start),%edi - mov $sym_phys(__bss_end),%ecx + mov $sym_offs(__bss_start),%edi + mov $sym_offs(__bss_end),%ecx push %fs pop %es sub %edi,%ecx
@@ -612,22 +612,22 @@ trampoline_setup: /* Apply relocations to bootstrap trampoline. */ mov sym_fs(trampoline_phys),%edx - mov $sym_phys(__trampoline_rel_start),%edi + mov $sym_offs(__trampoline_rel_start),%edi 1: mov %fs:(%edi),%eax add %edx,%fs:(%edi,%eax) add $4,%edi - cmp $sym_phys(__trampoline_rel_stop),%edi + cmp $sym_offs(__trampoline_rel_stop),%edi jb 1b /* Patch in the trampoline segment. */ shr $4,%edx - mov $sym_phys(__trampoline_seg_start),%edi + mov $sym_offs(__trampoline_seg_start),%edi 1: mov %fs:(%edi),%eax mov %dx,%fs:(%edi,%eax) add $4,%edi - cmp $sym_phys(__trampoline_seg_stop),%edi + cmp $sym_offs(__trampoline_seg_stop),%edi jb 1b /* Do not parse command line on EFI platform here. */
@@ -653,7 +653,7 @@ trampoline_setup: push %eax /* Copy bootstrap trampoline to low memory, below 1MB. */ - mov $sym_phys(trampoline_start),%esi + mov $sym_offs(trampoline_start),%esi mov $((trampoline_end - trampoline_start) / 4),%ecx rep movsl %fs:(%esi),%es:(%edi)
xen/arch/x86/boot/trampoline.S +1 -1
@@ -92,7 +92,7 @@ trampoline_protmode_entry: mov %ecx,%cr4 /* Load pagetable base register. */ - mov $sym_phys(idle_pg_table),%eax + mov $sym_offs(idle_pg_table),%eax add bootsym_rel(trampoline_xen_phys_start,4,%eax) mov %eax,%cr3
xen/arch/x86/boot/wakeup.S +2 -2
@@ -120,7 +120,7 @@ wakeup_32: mov $bootsym_rel(wakeup_stack, 4, %esp) # check saved magic again - mov $sym_phys(saved_magic), %eax + mov $sym_offs(saved_magic),%eax add bootsym_rel(trampoline_xen_phys_start, 4, %eax) mov (%eax), %eax cmp $0x9abcdef0, %eax
@@ -133,7 +133,7 @@ wakeup_32: mov %ecx, %cr4 /* Load pagetable base register */ - mov $sym_phys(idle_pg_table),%eax + mov $sym_offs(idle_pg_table),%eax add bootsym_rel(trampoline_xen_phys_start,4,%eax) mov %eax,%cr3
xen/arch/x86/boot/x86_64.S +9 -9
@@ -112,7 +112,7 @@ GLOBAL(__page_tables_start) * actualy mapped (mostly using superpages). Uses 4x 4k pages. */ GLOBAL(l2_identmap) - .quad sym_phys(l1_identmap) + __PAGE_HYPERVISOR + .quad sym_offs(l1_identmap) + __PAGE_HYPERVISOR idx = 1 .rept 7 .quad (idx << L2_PAGETABLE_SHIFT) | PAGE_HYPERVISOR | _PAGE_PSE
@@ -130,7 +130,7 @@ GLOBAL(l2_xenmap) .quad 0 idx = 1 .rept 7 - .quad sym_phys(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE) + .quad sym_offs(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE) idx = idx + 1 .endr .fill L2_PAGETABLE_ENTRIES - 8, 8, 0
@@ -141,7 +141,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_offs(l1_fixmap) + __PAGE_HYPERVISOR .else .quad 0 .endif
@@ -153,7 +153,7 @@ l2_fixmap: l3_identmap: idx = 0 .rept 4 - .quad sym_phys(l2_identmap) + (idx << PAGE_SHIFT) + __PAGE_HYPERVISOR + .quad sym_offs(l2_identmap) + (idx << PAGE_SHIFT) + __PAGE_HYPERVISOR idx = idx + 1 .endr .fill L3_PAGETABLE_ENTRIES - 4, 8, 0
@@ -164,9 +164,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_offs(l2_xenmap) + __PAGE_HYPERVISOR .elseif idx == l3_table_offset(FIXADDR_TOP - 1) - .quad sym_phys(l2_fixmap) + __PAGE_HYPERVISOR + .quad sym_offs(l2_fixmap) + __PAGE_HYPERVISOR .else .quad 0 .endif
@@ -176,13 +176,13 @@ l3_xenmap: /* Top-level master (and idle-domain) page directory. */ GLOBAL(idle_pg_table) - .quad sym_phys(l3_bootmap) + __PAGE_HYPERVISOR + .quad sym_offs(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_offs(l3_identmap) + __PAGE_HYPERVISOR .elseif idx == l4_table_offset(XEN_VIRT_START) - .quad sym_phys(l3_xenmap) + __PAGE_HYPERVISOR + .quad sym_offs(l3_xenmap) + __PAGE_HYPERVISOR .else .quad 0 .endif
Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v15 10/10 x86: add multiboot2 protocol support for relocatable images
In reply to Daniel KiperAdd multiboot2 protocol support for relocatable images. Only GRUB2 with "multiboot2: Add support for relocatable images" patch understands that feature. Older multiboot protocol (regardless of version) compatible loaders ignore it and everything works as usual.
---
v12 - suggestions/fixes:
- replace TABs with spaces in xen/include/xen/multiboot2.h (suggested by Doug Goldstein).
v9 - suggestions/fixes:
- use .L labels instead of numeric ones in multiboot2 data scanning loop (suggested by Jan Beulich).
v4 - suggestions/fixes:
- do not get Xen image load base address from
multiboot2 information in x86_64 code
(suggested by Jan Beulich),
- improve label names
(suggested by Jan Beulich),
- improve comments,
(suggested by Jan Beulich).
v3 - suggestions/fixes:
- use %esi and %r15d instead of %ebp to store
Xen image load base address,
- rename some types and constants,
- reformat xen/include/xen/multiboot2.h
(suggested by Konrad Rzeszutek Wilk),
- improve comments,
- improve commit message
(suggested by Konrad Rzeszutek Wilk).
--- xen/arch/x86/boot/head.S | 16 ++++++++++++++++ xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/include/xen/multiboot2.h | 13 +++++++++++++ 3 files changed, 30 insertions(+)
xen/arch/x86/boot/head.S +16 -0
@@ -82,6 +82,13 @@ multiboot2_header_start: /* 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_offs(start), /* Min load address. */ \ + 0xffffffff, /* The end of image 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
@@ -390,6 +397,15 @@ __start: cmp %edi,MB2_fixed_total_size(%ebx) jbe trampoline_bios_setup + /* Get Xen image load base address from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_LOAD_BASE_ADDR,MB2_tag_type(%ecx) + jne .Lmb2_mem_lower + + mov MB2_load_base_addr(%ecx),%esi + sub $XEN_IMG_OFFSET,%esi + jmp .Lmb2_next_tag + +.Lmb2_mem_lower: /* Get mem_lower from Multiboot2 information. */ cmpl $MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO,MB2_tag_type(%ecx) cmove MB2_mem_lower(%ecx),%edx
xen/arch/x86/x86_64/asm-offsets.c +1 -0
@@ -174,6 +174,7 @@ void __dummy__(void)OFFSET (MB2_fixed_total_size, multiboot2_fixed_t, total_size);OFFSET (MB2_tag_type, multiboot2_tag_t, type);OFFSET (MB2_tag_size, multiboot2_tag_t, size); +OFFSET (MB2_load_base_addr, multiboot2_tag_load_base_addr_t, load_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_LOAD_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 load_base_addr; +}multiboot2_tag_load_base_addr_t ; + +typedef struct { +u32 type; +u32 size;char string[]; }multiboot2_tag_string_t ;
Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel