Skip to contentSkip to conversation

x86: multiboot2 protocol support

PATCH Superseded Daniel Kiper 4 participants 70 messages Aug 19, 2016 – Sep 8, 2016

v5 of 16 Superseded Latest is v16 →

lore
Share & tools
lore
#0 lore raw

v5 cover x86: multiboot2 protocol support

Hi,

I am sending fifth version of multiboot2 protocol support for legacy BIOS and EFI platforms. This patch series release contains fixes for all known issues (many of them were found by Jan Beulich; thanks a lot!).

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 v4:
- changed patches: 01, 03, 04, 05, 09, 10, 11.

Patches 12-16 were reviewed by nobody last time.

This patch series was build with following tools:
- gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

    and binutils 2.17-3+etch1,
  - gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
    and binutils 2.23.2-2.el6,
  - gcc version 4.7.2 (Debian 4.7.2-5)
    and binutils 2.22-8,
  - gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)
    and binutils 2.25-9.fc22.

I hope that features provided by this patch series will be included in Xen 4.8 release in one way or another.

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

PS FYI, I will be on vacation next week. It will be nice if
you review my patches during that time.

 .gitignore                        |    5 +-
 xen/arch/x86/Makefile             |    8 +-
 xen/arch/x86/Rules.mk             |    4 +
 xen/arch/x86/boot/Makefile        |   10 +-
 xen/arch/x86/boot/build32.lds     |   52 ++++++++
 xen/arch/x86/boot/build32.mk      |   18 ++-
 xen/arch/x86/boot/cmdline.S       |  367 -----------------------------------------------------
 xen/arch/x86/boot/cmdline.c       |  376 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/boot/edd.S           |    3 -
 xen/arch/x86/boot/head.S          |  568 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
 xen/arch/x86/boot/reloc.c         |  249 ++++++++++++++++++++++++++++--------
 xen/arch/x86/boot/trampoline.S    |   22 +++-
 xen/arch/x86/boot/video.S         |    7 -
 xen/arch/x86/boot/wakeup.S        |    4 +-
 xen/arch/x86/boot/x86_64.S        |   51 +++-----
 xen/arch/x86/dmi_scan.c           |    4 +-
 xen/arch/x86/domain_page.c        |    2 +-
 xen/arch/x86/efi/Makefile         |   11 +-
 xen/arch/x86/efi/efi-boot.h       |  108 ++++++++++++++--
 xen/arch/x86/efi/stub.c           |   33 ++++-
 xen/arch/x86/mpparse.c            |    4 +-
 xen/arch/x86/setup.c              |   48 +++----
 xen/arch/x86/shutdown.c           |    5 +-
 xen/arch/x86/time.c               |    2 +-
 xen/arch/x86/x86_64/asm-offsets.c |   12 ++
 xen/arch/x86/xen.lds.S            |   16 ++-
 xen/common/efi/boot.c             |   31 ++++-
 xen/common/efi/runtime.c          |   21 ++-
 xen/drivers/acpi/osl.c            |    2 +-
 xen/include/asm-x86/config.h      |    1 +
 xen/include/asm-x86/page.h        |    2 +-
 xen/include/xen/efi.h             |   10 +-
 xen/include/xen/multiboot2.h      |  182 ++++++++++++++++++++++++++
 33 files changed, 1624 insertions(+), 614 deletions(-)

Daniel Kiper (16):
x86: allow EFI reboot method neither on EFI platforms... x86/boot: remove multiboot1_header_end from symbol table x86/boot: create *.lnk files with linker script x86/boot/reloc: reduce assembly usage as much as possible x86/boot: call reloc() using stdcall calling convention x86/boot/reloc: create generic alloc and copy functions x86/boot: use %ecx instead of %eax
x86/boot/reloc: rename some variables and rearrange code a bit
x86: add multiboot2 protocol support
efi: create efi_enabled()
efi: build xen.gz with EFI code
x86/efi: create new early memory allocator
x86: add multiboot2 protocol support for EFI platforms x86/boot: implement early command line parser in C
x86: make Xen early boot code relocatable
x86: add multiboot2 protocol support for relocatable images

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw

PATCH v5 1/16 x86: allow EFI reboot method neither on EFI platforms...

..nor EFI platforms with runtime services enabled.

---
v5 - suggestions/fixes:
- fix build error
(suggested by Jan Beulich),
- improve commit message.

---
 xen/arch/x86/shutdown.c |    3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/shutdown.c +3 -0
index 0e1499d..972e20b 100644
@@ -80,6 +80,9 @@ static void __init set_reboot_type(char *str)
             break;
         str++;
     }
+
+    if ( reboot_type == BOOT_EFI && !efi_enabled )
+        reboot_type = BOOT_INVALID;
 }
 custom_param("reboot", set_reboot_type);
 
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw

PATCH v5 2/16 x86/boot: remove multiboot1_header_end from symbol table

In reply to Daniel Kiper

Its visibility is not needed and just pollute symbol table.

---
 xen/arch/x86/boot/head.S |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/boot/head.S +1 -1
index 85770e8..e34351c 100644
@@ -32,7 +32,7 @@ multiboot1_header_start:       /*** MULTIBOOT1 HEADER ****/
         .long   MULTIBOOT_HEADER_FLAGS
         /* Checksum: must be the negated sum of the first two fields. */
         .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
-multiboot1_header_end:
+.Lmultiboot1_header_end:
 
         .section .init.rodata, "a", @progbits
         .align 4
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#7 lore raw

PATCH v5 3/16 x86/boot: create *.lnk files with linker script

In reply to Daniel Kiper

Newer GCC (e.g. gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)) does some code optimizations by creating data sections (e.g. jump addresses for C switch/case are calculated using data in .rodata section). This thing is not accepted by *.lnk build recipe which requires that only .text section lives in output. Potentially we can inhibit this GCC behavior by using special options, e.g. -fno-tree-switch-conversion. However, this does not guarantee that in the future new similar optimizations or anything else which creates not accepted sections will not break our build recipes again. I do not mention that probably this is not good idea to just disable random optimizations. So, take over full control on *.lnk linking process by using linker script and merge all text and data sections into one .text section.

Additionally, remove .got.plt section which is not used in our final code.

---
v5 - suggestions/fixes:
- merge __ALL__ text and data sections into one .text section (suggested by Jan Beulich),
- check that .got.plt size is correct
(suggested by Jan Beulich),
- reformat comments
(suggested by Jan Beulich),
- improve commit message.

v4 - suggestions/fixes:
- remove my name from copyright (Oracle requirement) (suggested by Konrad Rzeszutek Wilk),
- improve comments,
(suggested by Jan Beulich),
- improve commit message
(suggested by Jan Beulich).

---
 xen/arch/x86/boot/build32.lds |   52 +++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/boot/build32.mk  |   16 +++++++------
 2 files changed, 61 insertions(+), 7 deletions(-)
 create mode 100644 xen/arch/x86/boot/build32.lds
xen/arch/x86/boot/build32.lds new file +52 -0
new file mode 100644
index 0000000..da35aee
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+ENTRY(_start)
+
+SECTIONS
+{
+  /* Merge code and data into one section. */
+  .text : {
+        *(.text)
+        *(.text.*)
+        *(.data)
+        *(.data.*)
+        *(.rodata)
+        *(.rodata.*)
+        *(.bss)
+        *(.bss.*)
+  }
+
+  /DISCARD/ : {
+        /*
+         * PIC/PIE executable contains .got.plt section even if it is not linked
+         * with dynamic libraries. In such case it is just placeholder for
+         * _GLOBAL_OFFSET_TABLE_ symbol and .PLT0. .PLT0 is filled by dynamic
+         * linker and our code is not supposed to be loaded by dynamic linker.
+         * So, from our point of view .PLT0 is unused. This means that there is
+         * pretty good chance that we can safely drop .got.plt as a whole here.
+         * Sadly this is not true. _GLOBAL_OFFSET_TABLE_ is used as a reference
+         * for relative addressing (and only for that thing) and ld complains if
+         * we remove .got.plt section here because it cannot find required symbol.
+         * However, _GLOBAL_OFFSET_TABLE_ is no longer needed in final output.
+         * So, drop .got.plt section during conversion to plain binary format.
+         *
+         * Please check build32.mk for more details.
+         */
+        /* *(.got.plt) */
+  }
+}
xen/arch/x86/boot/build32.mk +9 -7
index 4a7d388..39e6453 100644
@@ -12,20 +12,22 @@ CFLAGS := $(filter-out -flto,$(CFLAGS))
 	(od -v -t x $< | tr -s ' ' | awk 'NR > 1 {print s} {s=$$0}' | \
 	sed 's/ /,0x/g' | sed 's/,0x$$//' | sed 's/^[0-9]*,/ .long /') >$@
 
+# Drop .got.plt during conversion to plain binary format.
+# Please check build32.lds for more details.
 %.bin: %.lnk
-	$(OBJCOPY) -O binary $< $@
-
-%.lnk: %.o
-	$(OBJDUMP) -h $< | sed -n '/[0-9]/{s,00*,0,g;p;}' |\
+	$(OBJDUMP) -h $< | sed -n '/[0-9]/{s,00*,0,g;p;}' | \
 		while read idx name sz rest; do \
 			case "$$name" in \
-			.data|.data.*|.rodata|.rodata.*|.bss|.bss.*) \
-				test $$sz != 0 || continue; \
+			.got.plt) \
+				test $$sz != 0c || continue; \
 				echo "Error: non-empty $$name: 0x$$sz" >&2; \
 				exit $$(expr $$idx + 1);; \
 			esac; \
 		done
-	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0 -o $@ $<
+	$(OBJCOPY) -O binary -R .got.plt $< $@
+
+%.lnk: %.o
+	$(LD) $(LDFLAGS_DIRECT) -N -T build32.lds -o $@ $<
 
 %.o: %.c
 	$(CC) $(CFLAGS) -c -fpic $< -o $@
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#9 lore raw

PATCH v5 4/16 x86/boot/reloc: reduce assembly usage as much as possible

In reply to Daniel Kiper

..to increase code readability and ease its maintenance.

---
v5 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/arch/x86/boot/reloc.c |   52 ++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 27 deletions(-)
xen/arch/x86/boot/reloc.c +25 -27
index 63045c0..9ae42e2 100644
@@ -15,39 +15,33 @@ asm (
     "    .text                         \n"
     "    .globl _start                 \n"
     "_start:                           \n"
-    "    call 1f                       \n"
-    "1:  pop  %ebx                     \n"
-    "    mov  %eax,alloc-1b(%ebx)      \n"
-    "    jmp  reloc                    \n"
-    );
-
-/*
- * This is our data. Because the code must be relocatable, no BSS is
- * allowed. All data is accessed PC-relative with inline assembly.
- */
-asm (
-    "alloc:                            \n"
-    "    .long 0                       \n"
+    "    push %eax                     \n"
+    "    push 0x8(%esp)                \n"
+    "    call reloc                    \n"
+    "    ret  $0x4                     \n"
     );
 
 typedef unsigned int u32;
 #include "../../../include/xen/multiboot.h"
 
+#define __stdcall	__attribute__((__stdcall__))
+
+#define ALIGN_UP(arg, align) \
+                (((arg) + (align) - 1) & ~((typeof(arg))(align) - 1))
+
+static u32 alloc;
+
 static void *reloc_mbi_struct(void *old, unsigned int bytes)
 {
     void *new;
-    asm(
-    "    call 1f                      \n"
-    "1:  pop  %%edx                   \n"
-    "    mov  alloc-1b(%%edx),%0      \n"
-    "    sub  %1,%0                   \n"
-    "    and  $~15,%0                 \n"
-    "    mov  %0,alloc-1b(%%edx)      \n"
-    "    mov  %0,%%edi                \n"
-    "    rep  movsb                   \n"
-       : "=&r" (new), "+c" (bytes), "+S" (old)
-	: : "edx", "edi", "memory");
-    return new;
+
+    alloc -= ALIGN_UP(bytes, 16);
+    new = (void *)alloc;
+
+    while ( bytes-- )
+        *(char *)new++ = *(char *)old++;
+
+    return (void *)alloc;
 }
 
 static char *reloc_mbi_string(char *old)
@@ -58,11 +52,15 @@ static char *reloc_mbi_string(char *old)
     return reloc_mbi_struct(old, p - old + 1);
 }
 
-multiboot_info_t *reloc(multiboot_info_t *mbi_old)
+multiboot_info_t __stdcall *reloc(multiboot_info_t *mbi_old, u32 trampoline)
 {
-    multiboot_info_t *mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi));
+    multiboot_info_t *mbi;
     int i;
 
+    alloc = trampoline;
+
+    mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi));
+
     if ( mbi->flags & MBI_CMDLINE )
         mbi->cmdline = (u32)reloc_mbi_string((char *)mbi->cmdline);
 
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#11 lore raw

PATCH v5 5/16 x86/boot: call reloc() using stdcall calling convention

In reply to Daniel Kiper

Current reloc() call method makes confusion and does not scale well for more arguments. And subsequent patch adding multiboot2 protocol support have to pass 3 arguments instead of 2. Hence, move reloc() call to stdcall calling convention. One may argue that we should use standard cdecl calling convention. However, stdcall is better here than cdecl because we do not need to remove "manually" arguments from stack in xen/arch/x86/boot/head.S assembly file.

---
v5 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

v4 - suggestions/fixes:
- move to stdcall calling convention
(suggested by Jan Beulich).

v3 - suggestions/fixes:
- simplify assembly in xen/arch/x86/boot/reloc.c file (suggested by Jan Beulich),
- reorder arguments for reloc() call from xen/arch/x86/boot/head.S (suggested by Jan Beulich),
- improve commit message
(suggested by Jan Beulich).

---
 xen/arch/x86/boot/head.S  |    3 ++-
 xen/arch/x86/boot/reloc.c |   11 ++++++-----
 2 files changed, 8 insertions(+), 6 deletions(-)
xen/arch/x86/boot/head.S +2 -1
index e34351c..7e5ae12 100644
@@ -119,7 +119,8 @@ __start:
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
-        push    %ebx
+        push    %eax                /* Boot trampoline address. */
+        push    %ebx                /* Multiboot information address. */
         call    reloc
         mov     %eax,sym_phys(multiboot_ptr)
 
xen/arch/x86/boot/reloc.c +6 -5
index 9ae42e2..28c6cea 100644
@@ -10,15 +10,16 @@
  *    Keir Fraser <[email protected]>
  */
 
-/* entered with %eax = BOOT_TRAMPOLINE */
+/*
+ * This entry point is entered from xen/arch/x86/boot/head.S with:
+ *   - 0x4(%esp) = MULTIBOOT_INFORMATION_ADDRESS,
+ *   - 0x8(%esp) = BOOT_TRAMPOLINE_ADDRESS.
+ */
 asm (
     "    .text                         \n"
     "    .globl _start                 \n"
     "_start:                           \n"
-    "    push %eax                     \n"
-    "    push 0x8(%esp)                \n"
-    "    call reloc                    \n"
-    "    ret  $0x4                     \n"
+    "    jmp  reloc                    \n"
     );
 
 typedef unsigned int u32;
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#12 lore raw

PATCH v5 6/16 x86/boot/reloc: create generic alloc and copy functions

In reply to Daniel Kiper

Create generic alloc and copy functions. We need
separate tools for memory allocation and copy to
provide multiboot2 protocol support.

---
v4 - suggestions/fixes:
- avoid assembly usage.

v3 - suggestions/fixes:
- use "g" constraint instead of "r" for alloc_mem() bytes argument (suggested by Jan Beulich).

v2 - suggestions/fixes:
- generalize new functions names
(suggested by Jan Beulich),
- reduce number of casts
(suggested by Jan Beulich).

---
 xen/arch/x86/boot/reloc.c |   51 ++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 21 deletions(-)
xen/arch/x86/boot/reloc.c +30 -21
index 28c6cea..21b1f32 100644
@@ -32,60 +32,69 @@ typedef unsigned int u32;
 
 static u32 alloc;
 
-static void *reloc_mbi_struct(void *old, unsigned int bytes)
+static u32 alloc_mem(u32 bytes)
 {
-    void *new;
+    return alloc -= ALIGN_UP(bytes, 16);
+}
 
-    alloc -= ALIGN_UP(bytes, 16);
-    new = (void *)alloc;
+static u32 copy_mem(u32 src, u32 bytes)
+{
+    u32 dst, dst_ret;
+
+    dst = alloc_mem(bytes);
+    dst_ret = dst;
 
     while ( bytes-- )
-        *(char *)new++ = *(char *)old++;
+        *(char *)dst++ = *(char *)src++;
 
-    return (void *)alloc;
+    return dst_ret;
 }
 
-static char *reloc_mbi_string(char *old)
+static u32 copy_string(u32 src)
 {
-    char *p;
-    for ( p = old; *p != '\0'; p++ )
+    u32 p;
+
+    if ( src == 0 )
+        return 0;
+
+    for ( p = src; *(char *)p != '\0'; p++ )
         continue;
-    return reloc_mbi_struct(old, p - old + 1);
+
+    return copy_mem(src, p - src + 1);
 }
 
-multiboot_info_t __stdcall *reloc(multiboot_info_t *mbi_old, u32 trampoline)
+multiboot_info_t __stdcall *reloc(u32 mbi_old, u32 trampoline)
 {
     multiboot_info_t *mbi;
     int i;
 
     alloc = trampoline;
 
-    mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi));
+    mbi = (multiboot_info_t *)copy_mem(mbi_old, sizeof(*mbi));
 
     if ( mbi->flags & MBI_CMDLINE )
-        mbi->cmdline = (u32)reloc_mbi_string((char *)mbi->cmdline);
+        mbi->cmdline = copy_string(mbi->cmdline);
 
     if ( mbi->flags & MBI_MODULES )
     {
-        module_t *mods = reloc_mbi_struct(
-            (module_t *)mbi->mods_addr, mbi->mods_count * sizeof(module_t));
+        module_t *mods;
 
-        mbi->mods_addr = (u32)mods;
+        mbi->mods_addr = copy_mem(mbi->mods_addr, mbi->mods_count * sizeof(module_t));
+
+        mods = (module_t *)mbi->mods_addr;
 
         for ( i = 0; i < mbi->mods_count; i++ )
         {
             if ( mods[i].string )
-                mods[i].string = (u32)reloc_mbi_string((char *)mods[i].string);
+                mods[i].string = copy_string(mods[i].string);
         }
     }
 
     if ( mbi->flags & MBI_MEMMAP )
-        mbi->mmap_addr = (u32)reloc_mbi_struct(
-            (memory_map_t *)mbi->mmap_addr, mbi->mmap_length);
+        mbi->mmap_addr = copy_mem(mbi->mmap_addr, mbi->mmap_length);
 
     if ( mbi->flags & MBI_LOADERNAME )
-        mbi->boot_loader_name = (u32)reloc_mbi_string(
-            (char *)mbi->boot_loader_name);
+        mbi->boot_loader_name = copy_string(mbi->boot_loader_name);
 
     /* Mask features we don't understand or don't relocate. */
     mbi->flags &= (MBI_MEMLIMITS |
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#21 lore raw

PATCH v5 7/16 x86/boot: use %ecx instead of %eax

In reply to Daniel Kiper

Use %ecx instead of %eax to store low memory upper limit from EBDA. This way we do not wipe multiboot protocol identifier. It is needed in reloc() to differentiate between multiboot (v1) and multiboot2 protocol.

---
 xen/arch/x86/boot/head.S |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
xen/arch/x86/boot/head.S +12 -12
index 7e5ae12..ffafcb5 100644
@@ -87,14 +87,14 @@ __start:
         jne     not_multiboot
 
         /* Set up trampoline segment 64k below EBDA */
-        movzwl  0x40e,%eax          /* EBDA segment */
-        cmp     $0xa000,%eax        /* sanity check (high) */
+        movzwl  0x40e,%ecx          /* EBDA segment */
+        cmp     $0xa000,%ecx        /* sanity check (high) */
         jae     0f
-        cmp     $0x4000,%eax        /* sanity check (low) */
+        cmp     $0x4000,%ecx        /* sanity check (low) */
         jae     1f
 0:
-        movzwl  0x413,%eax          /* use base memory size on failure */
-        shl     $10-4,%eax
+        movzwl  0x413,%ecx          /* use base memory size on failure */
+        shl     $10-4,%ecx
 1:
         /*
          * Compare the value in the BDA with the information from the
@@ -106,20 +106,20 @@ __start:
         cmp     $0x100,%edx         /* is the multiboot value too small? */
         jb      2f                  /* if so, do not use it */
         shl     $10-4,%edx
-        cmp     %eax,%edx           /* compare with BDA value */
-        cmovb   %edx,%eax           /* and use the smaller */
+        cmp     %ecx,%edx           /* compare with BDA value */
+        cmovb   %edx,%ecx           /* and use the smaller */
 
 2:      /* Reserve 64kb for the trampoline */
-        sub     $0x1000,%eax
+        sub     $0x1000,%ecx
 
         /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
-        xor     %al, %al
-        shl     $4, %eax
-        mov     %eax,sym_phys(trampoline_phys)
+        xor     %cl, %cl
+        shl     $4, %ecx
+        mov     %ecx,sym_phys(trampoline_phys)
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
-        push    %eax                /* Boot trampoline address. */
+        push    %ecx                /* Boot trampoline address. */
         push    %ebx                /* Multiboot information address. */
         call    reloc
         mov     %eax,sym_phys(multiboot_ptr)
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#22 lore raw

PATCH v5 8/16 x86/boot/reloc: rename some variables and rearrange code a bit

In reply to Daniel Kiper

Replace mbi with mbi_out and mbi_old with mbi_in and rearrange code a bit to make it more readable. Additionally, this way multiboot (v1) protocol implementation and future multiboot2 protocol implementation will use the same variable naming convention.

---
v4 - suggestions/fixes:
- move to stdcall calling convention.

v3 - suggestions/fixes:
- improve commit message
(suggested by Konrad Rzeszutek Wilk).

v2 - suggestions/fixes:
- extract this change from main mutliboot2
protocol implementation
(suggested by Jan Beulich).

---
 xen/arch/x86/boot/reloc.c |   39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
xen/arch/x86/boot/reloc.c +20 -19
index 21b1f32..dc6a435 100644
@@ -63,45 +63,46 @@ static u32 copy_string(u32 src)
     return copy_mem(src, p - src + 1);
 }
 
-multiboot_info_t __stdcall *reloc(u32 mbi_old, u32 trampoline)
+multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline)
 {
-    multiboot_info_t *mbi;
     int i;
+    multiboot_info_t *mbi_out;
 
     alloc = trampoline;
 
-    mbi = (multiboot_info_t *)copy_mem(mbi_old, sizeof(*mbi));
+    mbi_out = (multiboot_info_t *)copy_mem(mbi_in, sizeof(*mbi_out));
 
-    if ( mbi->flags & MBI_CMDLINE )
-        mbi->cmdline = copy_string(mbi->cmdline);
+    if ( mbi_out->flags & MBI_CMDLINE )
+        mbi_out->cmdline = copy_string(mbi_out->cmdline);
 
-    if ( mbi->flags & MBI_MODULES )
+    if ( mbi_out->flags & MBI_MODULES )
     {
         module_t *mods;
 
-        mbi->mods_addr = copy_mem(mbi->mods_addr, mbi->mods_count * sizeof(module_t));
+        mbi_out->mods_addr = copy_mem(mbi_out->mods_addr,
+                                      mbi_out->mods_count * sizeof(module_t));
 
-        mods = (module_t *)mbi->mods_addr;
+        mods = (module_t *)mbi_out->mods_addr;
 
-        for ( i = 0; i < mbi->mods_count; i++ )
+        for ( i = 0; i < mbi_out->mods_count; i++ )
         {
             if ( mods[i].string )
                 mods[i].string = copy_string(mods[i].string);
         }
     }
 
-    if ( mbi->flags & MBI_MEMMAP )
-        mbi->mmap_addr = copy_mem(mbi->mmap_addr, mbi->mmap_length);
+    if ( mbi_out->flags & MBI_MEMMAP )
+        mbi_out->mmap_addr = copy_mem(mbi_out->mmap_addr, mbi_out->mmap_length);
 
-    if ( mbi->flags & MBI_LOADERNAME )
-        mbi->boot_loader_name = copy_string(mbi->boot_loader_name);
+    if ( mbi_out->flags & MBI_LOADERNAME )
+        mbi_out->boot_loader_name = copy_string(mbi_out->boot_loader_name);
 
     /* Mask features we don't understand or don't relocate. */
-    mbi->flags &= (MBI_MEMLIMITS |
-                   MBI_CMDLINE |
-                   MBI_MODULES |
-                   MBI_MEMMAP |
-                   MBI_LOADERNAME);
+    mbi_out->flags &= (MBI_MEMLIMITS |
+                       MBI_CMDLINE |
+                       MBI_MODULES |
+                       MBI_MEMMAP |
+                       MBI_LOADERNAME);
 
-    return mbi;
+    return mbi_out;
 }
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#23 lore raw

PATCH v5 9/16 x86: add multiboot2 protocol support

In reply to Daniel Kiper

Add 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.

---
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         |  144 +++++++++++++++++++++++++++++--
 xen/arch/x86/x86_64/asm-offsets.c |    9 ++
 xen/include/xen/multiboot2.h      |  169 +++++++++++++++++++++++++++++++++++++
 5 files changed, 422 insertions(+), 10 deletions(-)
 create mode 100644 xen/include/xen/multiboot2.h
xen/arch/x86/boot/Makefile +2 -1
index 5fdb5ae..06893d8 100644
@@ -1,6 +1,7 @@
 obj-bin-y += head.o
 
-RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h
+RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h \
+	     $(BASEDIR)/include/xen/multiboot2.h
 
 head.o: reloc.S
 
xen/arch/x86/boot/head.S +103 -4

145 lines not on this page · raw message

xen/arch/x86/boot/reloc.c +139 -5

189 lines not on this page · raw message

xen/arch/x86/x86_64/asm-offsets.c +9 -0
index 05d2b85..0fc1c63 100644
@@ -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 " */<==\"" \
@@ -168,6 +169,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
#30 lore raw

PATCH v5 10/16 efi: create efi_enabled()

In reply to Daniel Kiper

First of all we need to differentiate between legacy BIOS and EFI platforms during runtime, not during build, because one image will have legacy and EFI code and can be executed on both platforms. Additionally, we need more fine grained knowledge about EFI environment and check for EFI platform and EFI loader separately to properly support multiboot2 protocol. In general Xen loaded by this protocol uses memory mappings and loaded modules in similar way to Xen loaded by multiboot (v1) protocol. Hence, create efi_enabled() which checks available features in efi_flags. This patch defines EFI_BOOT, EFI_LOADER and EFI_RS features. EFI_BOOT is equal to old efi_enabled == 1. EFI_RS ease control on runtime services usage. EFI_LOADER tells that Xen was loaded directly from EFI as PE executable.

---
v5 - suggestions/fixes:
- squash three patches into one
(suggested by Jan Beulich),
- introduce all features at once
(suggested by Jan Beulich),
- efi_enabled() returns bool_t
instead of unsigned int
(suggested by Jan Beulich),
- update commit message.

v4 - suggestions/fixes:
- rename EFI_PLATFORM to EFI_BOOT (suggested by Jan Beulich),
- move EFI_BOOT definition to efi struct definition (suggested by Jan Beulich),
- remove unneeded efi.flags initialization (suggested by Jan Beulich),
- use __set_bit() instead of set_bit() if possible (suggested by Jan Beulich),
- do efi_enabled() cleanup
(suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- improve commit message.

v3 - suggestions/fixes:
- define efi struct in xen/arch/x86/efi/stub.c in earlier patch
(suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- improve commit message
(suggested by Jan Beulich).

---
 xen/arch/x86/dmi_scan.c    |    4 ++--
 xen/arch/x86/domain_page.c |    2 +-
 xen/arch/x86/efi/stub.c    |    7 ++++---
 xen/arch/x86/mpparse.c     |    4 ++--
 xen/arch/x86/setup.c       |   14 ++++++++------
 xen/arch/x86/shutdown.c    |    4 ++--
 xen/arch/x86/time.c        |    2 +-
 xen/common/efi/boot.c      |   17 +++++++++++++----
 xen/common/efi/runtime.c   |   15 +++++++++------
 xen/drivers/acpi/osl.c     |    2 +-
 xen/include/xen/efi.h      |    9 +++++++--
 11 files changed, 50 insertions(+), 30 deletions(-)
xen/arch/x86/dmi_scan.c +2 -2
index b049e31..8dcb640 100644
@@ -238,7 +238,7 @@ const char *__init dmi_get_table(paddr_t *base, u32 *len)
 {
 	static unsigned int __initdata instance;
 
-	if (efi_enabled) {
+	if (efi_enabled(EFI_BOOT)) {
 		if (efi_smbios3_size && !(instance & 1)) {
 			*base = efi_smbios3_address;
 			*len = efi_smbios3_size;
@@ -696,7 +696,7 @@ static void __init dmi_decode(struct dmi_header *dm)
 
 void __init dmi_scan_machine(void)
 {
-	if ((!efi_enabled ? dmi_iterate(dmi_decode) :
+	if ((!efi_enabled(EFI_BOOT) ? dmi_iterate(dmi_decode) :
 	                    dmi_efi_iterate(dmi_decode)) == 0)
  		dmi_check_system(dmi_blacklist);
 	else
xen/arch/x86/domain_page.c +1 -1
index d86f8fe..7541b91 100644
@@ -36,7 +36,7 @@ static inline struct vcpu *mapcache_current_vcpu(void)
      * domain's page tables but current may point at another domain's VCPU.
      * Return NULL as though current is not properly set up yet.
      */
-    if ( efi_enabled && efi_rs_using_pgtables() )
+    if ( efi_enabled(EFI_RS) && efi_rs_using_pgtables() )
         return NULL;
 
     /*
xen/arch/x86/efi/stub.c +4 -3
index 07c2bd0..f087023 100644
@@ -4,9 +4,10 @@
 #include <xen/lib.h>
 #include <asm/page.h>
 
-#ifndef efi_enabled
-const bool_t efi_enabled = 0;
-#endif
+bool_t efi_enabled(int feature)
+{
+    return false;
+}
 
 void __init efi_init_memory(void) { }
 
xen/arch/x86/mpparse.c +2 -2
index ef6557c..c3d5bdc 100644
@@ -564,7 +564,7 @@ static inline void __init construct_default_ISA_mptable(int mpc_default_type)
 
 static __init void efi_unmap_mpf(void)
 {
-	if (efi_enabled)
+	if (efi_enabled(EFI_BOOT))
 		clear_fixmap(FIX_EFI_MPF);
 }
 
@@ -722,7 +722,7 @@ void __init find_smp_config (void)
 {
 	unsigned int address;
 
-	if (efi_enabled) {
+	if (efi_enabled(EFI_BOOT)) {
 		efi_check_config();
 		return;
 	}
xen/arch/x86/setup.c +8 -6
index 8ae897a..360ca59 100644
@@ -439,8 +439,8 @@ static void __init parse_video_info(void)
 {
     struct boot_video_info *bvi = &bootsym(boot_vid_info);
 
-    /* The EFI loader fills vga_console_info directly. */
-    if ( efi_enabled )
+    /* vga_console_info is filled directly on EFI platform. */
+    if ( efi_enabled(EFI_BOOT) )
         return;
 
     if ( (bvi->orig_video_isVGA == 1) && (bvi->orig_video_mode == 3) )
@@ -726,7 +726,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
         panic("dom0 kernel not specified. Check bootloader configuration.");
 
-    if ( efi_enabled )
+    if ( efi_enabled(EFI_LOADER) )
     {
         set_pdx_range(xen_phys_start >> PAGE_SHIFT,
                       (xen_phys_start + BOOTSTRAP_MAP_BASE) >> PAGE_SHIFT);
@@ -739,8 +739,10 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         l3_bootmap[l3_table_offset(BOOTSTRAP_MAP_BASE)] =
             l3e_from_paddr(__pa(l2_bootmap), __PAGE_HYPERVISOR);
 
-        memmap_type = loader;
+        memmap_type = "EFI";
     }
+    else if ( efi_enabled(EFI_BOOT) )
+        memmap_type = "EFI";
     else if ( e820_raw_nr != 0 )
     {
         memmap_type = "Xen-e820";
@@ -837,7 +839,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * we can relocate the dom0 kernel and other multiboot modules. Also, on
      * x86/64, we relocate Xen to higher memory.
      */
-    for ( i = 0; !efi_enabled && i < mbi->mods_count; i++ )
+    for ( i = 0; !efi_enabled(EFI_LOADER) && i < mbi->mods_count; i++ )
     {
         if ( mod[i].mod_start & (PAGE_SIZE - 1) )
             panic("Bootloader didn't honor module alignment request.");
@@ -1078,7 +1080,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 ? mbi->mem_upper : __pa(&_start),
+    reserve_e820_ram(&boot_e820, efi_enabled(EFI_BOOT) ? mbi->mem_upper : __pa(&_start),
                      __pa(&_end));
 
     /* Late kexec reservation (dynamic start address). */
xen/arch/x86/shutdown.c +2 -2
index 972e20b..b429fd0 100644
@@ -81,7 +81,7 @@ static void __init set_reboot_type(char *str)
         str++;
     }
 
-    if ( reboot_type == BOOT_EFI && !efi_enabled )
+    if ( reboot_type == BOOT_EFI && !efi_enabled(EFI_RS) )
         reboot_type = BOOT_INVALID;
 }
 custom_param("reboot", set_reboot_type);
@@ -119,7 +119,7 @@ void machine_halt(void)
 static void default_reboot_type(void)
 {
     if ( reboot_type == BOOT_INVALID )
-        reboot_type = efi_enabled ? BOOT_EFI
+        reboot_type = efi_enabled(EFI_RS) ? BOOT_EFI
                                   : acpi_disabled ? BOOT_KBD
                                                   : BOOT_ACPI;
 }
xen/arch/x86/time.c +1 -1
index b316f23..34f82cb 100644
@@ -727,7 +727,7 @@ static unsigned long get_cmos_time(void)
     static bool_t __read_mostly cmos_rtc_probe;
     boolean_param("cmos-rtc-probe", cmos_rtc_probe);
 
-    if ( efi_enabled )
+    if ( efi_enabled(EFI_RS) )
     {
         res = efi_get_time();
         if ( res )
xen/common/efi/boot.c +13 -4
index 125c9ce..d7c484e 100644
@@ -934,6 +934,13 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     char *option_str;
     bool_t use_cfg_file;
 
+    __set_bit(EFI_BOOT, &efi_flags);
+    __set_bit(EFI_LOADER, &efi_flags);
+
+#ifndef CONFIG_ARM /* Disabled until runtime services implemented. */
+    __set_bit(EFI_RS, &efi_flags);
+#endif
+
     efi_init(ImageHandle, SystemTable);
 
     use_cfg_file = efi_arch_use_config_file(SystemTable);
@@ -1153,7 +1160,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
 #ifndef CONFIG_ARM /* TODO - runtime service support */
 
-static bool_t __initdata efi_rs_enable = 1;
 static bool_t __initdata efi_map_uc;
 
 static void __init parse_efi_param(char *s)
@@ -1171,7 +1177,10 @@ static void __init parse_efi_param(char *s)
             *ss = '\0';
 
         if ( !strcmp(s, "rs") )
-            efi_rs_enable = val;
+        {
+            if ( !val )
+                __clear_bit(EFI_RS, &efi_flags);
+        }
         else if ( !strcmp(s, "attr=uc") )
             efi_map_uc = val;
 
@@ -1254,7 +1263,7 @@ void __init efi_init_memory(void)
                desc->PhysicalStart, desc->PhysicalStart + len - 1,
                desc->Type, desc->Attribute);
 
-        if ( !efi_rs_enable ||
+        if ( !efi_enabled(EFI_RS) ||
              (!(desc->Attribute & EFI_MEMORY_RUNTIME) &&
               (!map_bs ||
                (desc->Type != EfiBootServicesCode &&
@@ -1328,7 +1337,7 @@ void __init efi_init_memory(void)
         }
     }
 
-    if ( !efi_rs_enable )
+    if ( !efi_enabled(EFI_RS) )
     {
         efi_fw_vendor = NULL;
         return;
xen/common/efi/runtime.c +9 -6
index c256814..6bffda0 100644
@@ -10,12 +10,6 @@ DEFINE_XEN_GUEST_HANDLE(CHAR16);
 
 #ifndef COMPAT
 
-/*
- * Currently runtime services are not implemented on ARM. To boot Xen with ACPI,
- * set efi_enabled to 1, so that Xen can get the ACPI root pointer from EFI.
- */
-const bool_t efi_enabled = 1;
-
 #ifndef CONFIG_ARM
 # include <asm/i387.h>
 # include <asm/xstate.h>
@@ -43,6 +37,9 @@ UINT64 __read_mostly efi_boot_max_var_store_size;
 UINT64 __read_mostly efi_boot_remain_var_store_size;
 UINT64 __read_mostly efi_boot_max_var_size;
 
+/* Bit fields representing available EFI features/properties. */
+unsigned long efi_flags;
+
 struct efi __read_mostly efi = {
 	.acpi   = EFI_INVALID_TABLE_ADDR,
 	.acpi20 = EFI_INVALID_TABLE_ADDR,
@@ -53,6 +50,12 @@ struct efi __read_mostly efi = {
 
 const struct efi_pci_rom *__read_mostly efi_pci_roms;
 
+/* Test whether EFI_* bits are enabled. */
+bool_t efi_enabled(int feature)
+{
+    return test_bit(feature, &efi_flags);
+}
+
 #ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
 unsigned long efi_rs_enter(void)
 {
xen/drivers/acpi/osl.c +1 -1
index 9a49029..3616dfd 100644
@@ -66,7 +66,7 @@ void __init acpi_os_vprintf(const char *fmt, va_list args)
 
 acpi_physical_address __init acpi_os_get_root_pointer(void)
 {
-	if (efi_enabled) {
+	if (efi_enabled(EFI_BOOT)) {
 		if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
 			return efi.acpi20;
 		else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
xen/include/xen/efi.h +7 -2
index e74dad1..8372ae2 100644
@@ -2,13 +2,17 @@
 #define __XEN_EFI_H__
 
 #ifndef __ASSEMBLY__
+#include <xen/bitops.h>
 #include <xen/types.h>
 #endif
 
-extern const bool_t efi_enabled;
-
 #define EFI_INVALID_TABLE_ADDR (~0UL)
 
+extern unsigned long efi_flags;
+#define EFI_BOOT	0	/* Were we booted from EFI? */
+#define EFI_LOADER	1	/* Were we booted directly from EFI loader? */
+#define EFI_RS		2	/* Can we use runtime services? */
+
 /* Add fields here only if they need to be referenced from non-EFI code. */
 struct efi {
     unsigned long mps;          /* MPS table */
@@ -28,6 +32,7 @@ union compat_pf_efi_info;
 struct xenpf_efi_runtime_call;
 struct compat_pf_efi_runtime_call;
 
+bool_t efi_enabled(int feature);
 void efi_init_memory(void);
 bool_t efi_rs_using_pgtables(void);
 unsigned long efi_get_time(void);
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#34 lore raw

PATCH v5 11/16 efi: build xen.gz with EFI code

In reply to Daniel Kiper

Build 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.

---
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 |   11 +++--------
 xen/arch/x86/xen.lds.S    |    4 ++--
 xen/common/efi/boot.c     |    3 +++
 xen/common/efi/runtime.c  |    6 ++++++
 5 files changed, 15 insertions(+), 11 deletions(-)
xen/arch/x86/Makefile +1 -1
index b18f033..71ec34e 100644
@@ -211,7 +211,7 @@ 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/reloc.S boot/reloc.lnk boot/reloc.bin
 	rm -f note.o
 	$(MAKE) -f $(BASEDIR)/Rules.mk -C test clean
xen/arch/x86/efi/Makefile +3 -8
index 5099430..2a7d3e5 100644
@@ -1,14 +1,9 @@
 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)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
-
-stub.o: $(extra-y)
+obj-y := stub.o
+obj-$(efi) := boot.init.o compat.o relocs-dummy.o runtime.o
xen/arch/x86/xen.lds.S +2 -2
index 2d1d43d..40eb4c5 100644
@@ -262,10 +262,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
index d7c484e..48ef8ad 100644
@@ -1249,6 +1249,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 +6 -0
index 6bffda0..64c632c 100644
@@ -175,6 +175,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:
@@ -309,6 +312,9 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)
     EFI_STATUS status = EFI_NOT_STARTED;
     int rc = 0;
 
+    if ( !efi_enabled(EFI_RS) )
+        return -ENOSYS;
+
     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
#36 lore raw

PATCH v5 12/16 x86/efi: create new early memory allocator

In reply to Daniel Kiper

There 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().

---
v4 - suggestions/fixes:
- move from #2 solution to #2a solution,
- improve commit message.

---
 xen/arch/x86/efi/efi-boot.h |   58 +++++++++++++++++++++++++++++++++++++------
 xen/arch/x86/efi/stub.c     |    2 ++
 xen/arch/x86/setup.c        |    5 ++--
 xen/include/xen/efi.h       |    1 +
 4 files changed, 56 insertions(+), 10 deletions(-)
xen/arch/x86/efi/efi-boot.h +50 -8
index 1fa9e47..3f87b7c 100644
@@ -103,9 +103,56 @@ static void __init relocate_trampoline(unsigned long phys)
         *(u16 *)(*trampoline_ptr + (long)trampoline_ptr) = phys >> 4;
 }
 
+#define EBMALLOC_SIZE	MB(1)
+
+static char __section(".bss.page_aligned") ebmalloc_mem[EBMALLOC_SIZE];
+static char __initdata *ebmalloc_free = NULL;
+
+/* EFI boot allocator. */
+static void __init *ebmalloc(size_t size)
+{
+    void *ptr;
+
+    /*
+     * Init ebmalloc_free on runtime. Static initialization
+     * will not work because it puts virtual address there.
+     */
+    if ( ebmalloc_free == NULL )
+        ebmalloc_free = ebmalloc_mem;
+
+    ptr = ebmalloc_free;
+
+    ebmalloc_free += size;
+
+    if ( ebmalloc_free - ebmalloc_mem > sizeof(ebmalloc_mem) )
+        blexit(L"Out of static memory\r\n");
+
+    return ptr;
+}
+
+void __init free_ebmalloc_unused_mem(void)
+{
+    unsigned long start, end;
+
+    if ( ebmalloc_free )
+    {
+        start = (unsigned long)ebmalloc_free - xen_phys_start;
+        start = PAGE_ALIGN(start + XEN_VIRT_START);
+    }
+    else
+        start = (unsigned long)ebmalloc_mem;
+
+    end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
+
+    destroy_xen_mappings(start, end);
+    init_xenheap_pages(__pa(start), __pa(end));
+
+    printk("Freed %lukB unused BSS memory\n", (end - start) >> 10);
+}
+
 static void __init place_string(u32 *addr, const char *s)
 {
-    static char *__initdata alloc = start;
+    char *alloc = NULL;
 
     if ( s && *s )
     {
@@ -113,7 +160,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
@@ -196,12 +243,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/efi/stub.c +2 -0
index f087023..f7bc042 100644
@@ -9,6 +9,8 @@ bool_t efi_enabled(int feature)
     return false;
 }
 
+void __init free_ebmalloc_unused_mem(void) { }
+
 void __init efi_init_memory(void) { }
 
 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { }
xen/arch/x86/setup.c +3 -2
index 360ca59..bc48351 100644
@@ -520,6 +520,8 @@ static void noinline init_done(void)
 
     system_state = SYS_STATE_active;
 
+    free_ebmalloc_unused_mem();
+
     /* MUST be done prior to removing .init data. */
     unregister_init_virtual_region();
 
@@ -1080,8 +1082,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_BOOT) ? 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/include/xen/efi.h +1 -0
index 8372ae2..147a0e8 100644
@@ -33,6 +33,7 @@ struct xenpf_efi_runtime_call;
 struct compat_pf_efi_runtime_call;
 
 bool_t efi_enabled(int feature);
+void free_ebmalloc_unused_mem(void);
 void efi_init_memory(void);
 bool_t efi_rs_using_pgtables(void);
 unsigned long efi_get_time(void);
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#42 lore raw

PATCH v5 13/16 x86: add multiboot2 protocol support for EFI platforms

In reply to Daniel Kiper

This way Xen can be loaded on EFI platforms using GRUB2 and other boot loaders which support multiboot2 protocol.

---
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          |  243 ++++++++++++++++++++++++++++++++++---
 xen/arch/x86/efi/efi-boot.h       |   49 +++++++-
 xen/arch/x86/efi/stub.c           |   24 ++++
 xen/arch/x86/x86_64/asm-offsets.c |    2 +
 xen/arch/x86/xen.lds.S            |    4 +-
 xen/common/efi/boot.c             |   11 ++
 6 files changed, 312 insertions(+), 21 deletions(-)
xen/arch/x86/boot/head.S +229 -14
index 5e61854..aca5370 100644
@@ -89,6 +89,13 @@ multiboot2_header_start:
                    0, /* Number of the lines - no preference. */ \
                    0  /* Number of bits per pixel - no preference. */
 
+        /* Inhibit bootloader from calling ExitBootServices(). */
+        mb2ht_init MB2_HT(EFI_BS), MB2_HT(OPTIONAL)
+
+        /* EFI64 entry point. */
+        mb2ht_init MB2_HT(ENTRY_ADDRESS_EFI64), MB2_HT(OPTIONAL), \
+                   sym_phys(__efi64_start)
+
         /* Multiboot2 header end tag. */
         mb2ht_init MB2_HT(END), MB2_HT(REQUIRED)
 .Lmultiboot2_header_end:
@@ -100,19 +107,45 @@ multiboot2_header_start:
 gdt_boot_descr:
         .word   6*8-1
         .long   sym_phys(trampoline_gdt)
+        .long   0 /* Needed for 64-bit lgdt */
+
+cs32_switch_addr:
+        .long   sym_phys(cs32_switch)
+        .word   BOOT_CS32
+
+vga_text_buffer:
+        .long   0xb8000
 
 .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.text, "ax", @progbits
 
 bad_cpu:
         mov     $(sym_phys(.Lbad_cpu_msg)),%esi # Error message
-        jmp     print_err
+        jmp     0f
 not_multiboot:
         mov     $(sym_phys(.Lbad_ldr_msg)),%esi # Error message
-print_err:
-        mov     $0xB8000,%edi  # VGA framebuffer
+        jmp     0f
+mb2_no_st:
+        mov     $(sym_phys(.Lbad_ldr_nst)),%esi # Error message
+        jmp     0f
+mb2_no_ih:
+        mov     $(sym_phys(.Lbad_ldr_nih)),%esi # Error message
+        jmp     0f
+mb2_no_bs:
+        mov     $(sym_phys(.Lbad_ldr_nbs)),%esi # Error message
+        xor     %edi,%edi                       # No VGA text buffer
+        jmp     1f
+mb2_efi_ia_32:
+        mov     $(sym_phys(.Lbad_efi_msg)),%esi # Error message
+        xor     %edi,%edi                       # No VGA text buffer
+        jmp     1f
+0:      mov     sym_phys(vga_text_buffer),%edi
 1:      mov     (%esi),%bl
         test    %bl,%bl        # Terminate on '\0' sentinel
         je      .Lhalt
@@ -123,13 +156,173 @@ 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      1b
+        movsb                  # Write a character to the VGA text buffer
         mov     $7,%al
-        stosb                  # Write an attribute to the VGA framebuffer
+        stosb                  # Write an attribute to the VGA text buffer
         jmp     1b
 .Lhalt: hlt
         jmp     .Lhalt
 
+        .code64
+
+__efi64_start:
+        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),%edi
+        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)(%ebx),%ecx
+        and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx
+
+0:
+        /* Check Multiboot2 information total size. */
+        mov     %ecx,%r8d
+        sub     %ebx,%r8d
+        cmp     %r8d,MB2_fixed_total_size(%rbx)
+        jbe     run_bs
+
+        /* Are EFI boot services available? */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI_BS,MB2_tag_type(%rcx)
+        jne     1f
+
+        /* Yes, skip real mode and do not do other unneeded things. */
+        incb    skip_realmode(%rip)
+        jmp     9f
+
+1:
+        /* Get EFI SystemTable address from Multiboot2 information. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%rcx)
+        cmove   MB2_efi64_st(%rcx),%rsi
+        je      9f
+
+        /* Get EFI ImageHandle address from Multiboot2 information. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64_IH,MB2_tag_type(%rcx)
+        cmove   MB2_efi64_ih(%rcx),%rdi
+        je      9f
+
+        /* Is it the end of Multiboot2 information? */
+        cmpl    $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx)
+        je      run_bs
+
+9:
+        /* 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     0b
+
+run_bs:
+        /* Are EFI boot services available? */
+        cmpb    $0,skip_realmode(%rip)
+        jnz     0f
+
+        /* Jump to mb2_no_bs after switching CPU to x86_32 mode. */
+        lea     mb2_no_bs(%rip),%edi
+        jmp     x86_32_switch
+
+0:
+        /* Is EFI SystemTable address provided by boot loader? */
+        test    %rsi,%rsi
+        jnz     1f
+
+        /* Jump to mb2_no_st after switching CPU to x86_32 mode. */
+        lea     mb2_no_st(%rip),%edi
+        jmp     x86_32_switch
+
+1:
+        /* Is EFI ImageHandle address provided by boot loader? */
+        test    %rdi,%rdi
+        jnz     2f
+
+        /* Jump to mb2_no_ih after switching CPU to x86_32 mode. */
+        lea     mb2_no_ih(%rip),%edi
+        jmp     x86_32_switch
+
+2:
+        push    %rax
+        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
+
+        pop     %rdi
+
+        /*
+         * IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable.
+         * OUT: %rax - Highest available memory address below 1 MiB.
+         *
+         * MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag is not provided
+         * on EFI platforms. Hence, it could not be used like
+         * on legacy BIOS platforms.
+         */
+        call    efi_multiboot2
+
+        /* Convert memory address to bytes/16 and store it in safe place. */
+        shr     $4,%eax
+        mov     %eax,%ecx
+
+        pop     %rax
+
+        /* Jump to trampoline_setup after switching CPU to x86_32 mode. */
+        lea     trampoline_setup(%rip),%edi
+
+x86_32_switch:
+        cli
+
+        /* Initialise GDT. */
+        lgdt    gdt_boot_descr(%rip)
+
+        /* Reload code selector. */
+        ljmpl   *cs32_switch_addr(%rip)
+
+        .code32
+
+cs32_switch:
+        /* Initialise basic data segments. */
+        mov     $BOOT_DS,%edx
+        mov     %edx,%ds
+        mov     %edx,%es
+        mov     %edx,%ss
+        /* %esp is initialised 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 +350,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,16 +362,24 @@ __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      trampoline_bios_setup
+
+        /* EFI IA-32 platforms are not supported. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx)
+        je      mb2_efi_ia_32
+
+        /* Bootloader shutdown EFI x64 boot services. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx)
+        je      mb2_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
 
         /* Go to next Multiboot2 information tag. */
         add     MB2_tag_size(%ecx),%ecx
@@ -186,7 +387,7 @@ __start:
         and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx
         jmp     0b
 
-trampoline_setup:
+trampoline_bios_setup:
         /* Set up trampoline segment 64k below EBDA */
         movzwl  0x40e,%ecx          /* EBDA segment */
         cmp     $0xa000,%ecx        /* sanity check (high) */
@@ -202,12 +403,13 @@ trampoline_setup:
          * multiboot structure (if available) and use the smallest.
          */
         cmp     $0x100,%edx         /* is the multiboot value too small? */
-        jb      2f                  /* if so, do not use it */
+        jb      trampoline_setup    /* if so, do not use it */
         shl     $10-4,%edx
         cmp     %ecx,%edx           /* compare with BDA value */
         cmovb   %edx,%ecx           /* and use the smaller */
 
-2:      /* Reserve 64kb for the trampoline */
+trampoline_setup:
+        /* Reserve 64kb for the trampoline. */
         sub     $0x1000,%ecx
 
         /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
@@ -223,14 +425,22 @@ trampoline_setup:
         call    reloc
         mov     %eax,sym_phys(multiboot_ptr)
 
-        /* Initialize BSS (no nasty surprises!) */
+        /*
+         * Do not zero BSS on EFI platform here.
+         * It was initialized earlier.
+         */
+        cmpb    $0,sym_phys(skip_realmode)
+        jnz     1f
+
+        /* Initialize BSS (no nasty surprises!). */
         mov     $sym_phys(__bss_start),%edi
         mov     $sym_phys(__bss_end),%ecx
         sub     %edi,%ecx
-        xor     %eax,%eax
         shr     $2,%ecx
+        xor     %eax,%eax
         rep stosl
 
+1:
         /* Interrogate CPU extended features via CPUID. */
         mov     $0x80000000,%eax
         cpuid
@@ -282,8 +492,13 @@ trampoline_setup:
         cmp     $sym_phys(__trampoline_seg_stop),%edi
         jb      1b
 
+        /* Do not parse command line on EFI platform here. */
+        cmpb    $0,sym_phys(skip_realmode)
+        jnz     1f
+
         call    cmdline_parse_early
 
+1:
         /* Switch to low-memory stack.  */
         mov     sym_phys(trampoline_phys),%edi
         lea     0x10000(%edi),%esp
xen/arch/x86/efi/efi-boot.h +44 -5

62 lines not on this page · raw message

xen/arch/x86/efi/stub.c +24 -0
index f7bc042..d886de6 100644
@@ -3,6 +3,30 @@
 #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>
+
+paddr_t __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    CHAR16 *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. */
+    asm volatile(
+    "    call %2                      \n"
+    "0:  hlt                          \n"
+    "    jmp  0b                      \n"
+       : "+c" (StdErr), "+d" (err) : "g" (StdErr->OutputString)
+       : "rax", "r8", "r9", "r10", "r11", "cc", "memory");
+
+    unreachable();
+}
 
 bool_t efi_enabled(int feature)
 {
xen/arch/x86/x86_64/asm-offsets.c +2 -0
index 0fc1c63..9695ea6 100644
@@ -176,6 +176,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 +2 -2
index 40eb4c5..a6246c0 100644
@@ -323,5 +323,5 @@ 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")
xen/common/efi/boot.c +11 -0
index 48ef8ad..8d81069 100644
@@ -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;
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#49 lore raw

PATCH v5 14/16 x86/boot: implement early command line parser in C

In reply to Daniel Kiper

Current early command line parser implementation in assembler is very difficult to change to relocatable stuff using segment registers. This requires a lot of changes in very weird and fragile code. So, reimplement this functionality in C. This way code will be relocatable out of the box (without playing with segment registers) and much easier to maintain.

---
v4 - suggestions/fixes:
- move to stdcall calling convention (suggested by Jan Beulich),
- define bool_t and use it properly (suggested by Jan Beulich),
- put list of delimiter chars into
static const char[]
(suggested by Jan Beulich),
- use strlen() instead of strlen_opt() (suggested by Jan Beulich),
- change strtoi() to strtoui() and
optimize it a bit
(suggested by Jan Beulich),
- define strchr() and use it in strtoui() (suggested by Jan Beulich),
- optimize vga_parse()
(suggested by Jan Beulich),
- move !cmdline check from assembly to C (suggested by Jan Beulich),
- remove my name from copyright (Oracle requirement) (suggested by Konrad Rzeszutek Wilk).

v3 - suggestions/fixes:
- optimize some code
(suggested by Jan Beulich),
- put VESA data into early_boot_opts_t members (suggested by Jan Beulich),
- rename some functions and variables
(suggested by Jan Beulich),
- move around video.h include in xen/arch/x86/boot/trampoline.S (suggested by Jan Beulich),
- fix coding style
(suggested by Jan Beulich),
- fix build with older GCC
(suggested by Konrad Rzeszutek Wilk),
- remove redundant comments
(suggested by Jan Beulich),
- add some comments
- improve commit message
(suggested by Jan Beulich).

---
 .gitignore                     |    5 +-
 xen/arch/x86/Makefile          |    2 +-
 xen/arch/x86/boot/Makefile     |    7 +-
 xen/arch/x86/boot/build32.mk   |    2 +
 xen/arch/x86/boot/cmdline.S    |  367 ---------------------------------------
 xen/arch/x86/boot/cmdline.c    |  376 ++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/boot/edd.S        |    3 -
 xen/arch/x86/boot/head.S       |    8 +
 xen/arch/x86/boot/trampoline.S |   12 ++
 xen/arch/x86/boot/video.S      |    7 -
 10 files changed, 408 insertions(+), 381 deletions(-)
 delete mode 100644 xen/arch/x86/boot/cmdline.S
 create mode 100644 xen/arch/x86/boot/cmdline.c
.gitignore +3 -2
index d193820..23637d8 100644
@@ -248,9 +248,10 @@ xen/arch/arm/xen.lds
 xen/arch/x86/asm-offsets.s
 xen/arch/x86/boot/mkelf32
 xen/arch/x86/xen.lds
+xen/arch/x86/boot/cmdline.S
 xen/arch/x86/boot/reloc.S
-xen/arch/x86/boot/reloc.bin
-xen/arch/x86/boot/reloc.lnk
+xen/arch/x86/boot/*.bin
+xen/arch/x86/boot/*.lnk
 xen/arch/x86/efi.lds
 xen/arch/x86/efi/check.efi
 xen/arch/x86/efi/disabled
xen/arch/x86/Makefile +1 -1
index 71ec34e..9464b7b 100644
@@ -212,6 +212,6 @@ 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/*.efi efi/disabled efi/mkreloc
-	rm -f boot/reloc.S boot/reloc.lnk boot/reloc.bin
+	rm -f boot/cmdline.S boot/reloc.S boot/*.lnk boot/*.bin
 	rm -f note.o
 	$(MAKE) -f $(BASEDIR)/Rules.mk -C test clean
xen/arch/x86/boot/Makefile +6 -1
index 06893d8..d73cc76 100644
@@ -1,9 +1,14 @@
 obj-bin-y += head.o
 
+CMDLINE_DEPS = video.h
+
 RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h \
 	     $(BASEDIR)/include/xen/multiboot2.h
 
-head.o: reloc.S
+head.o: cmdline.S reloc.S
+
+cmdline.S: cmdline.c $(CMDLINE_DEPS)
+	$(MAKE) -f build32.mk $@ CMDLINE_DEPS="$(CMDLINE_DEPS)"
 
 reloc.S: reloc.c $(RELOC_DEPS)
 	$(MAKE) -f build32.mk $@ RELOC_DEPS="$(RELOC_DEPS)"
xen/arch/x86/boot/build32.mk +2 -0
index 39e6453..3d01698 100644
@@ -32,6 +32,8 @@ CFLAGS := $(filter-out -flto,$(CFLAGS))
 %.o: %.c
 	$(CC) $(CFLAGS) -c -fpic $< -o $@
 
+cmdline.o: cmdline.c $(CMDLINE_DEPS)
+
 reloc.o: reloc.c $(RELOC_DEPS)
 
 .PRECIOUS: %.bin %.lnk
xen/arch/x86/boot/cmdline.S deleted +0 -367

367 lines not on this page · raw message

xen/arch/x86/boot/cmdline.c new file +376 -0

376 lines not on this page · raw message

xen/arch/x86/boot/edd.S +0 -3
index 5c80da6..73371f9 100644
@@ -142,9 +142,6 @@ edd_next:
 edd_done:
         ret
 
-opt_edd:
-        .byte   0                               # edd=on/off/skipmbr
-
 GLOBAL(boot_edd_info_nr)
         .byte   0
 GLOBAL(boot_mbr_signature_nr)
xen/arch/x86/boot/head.S +8 -0
index aca5370..b832b21 100644
@@ -496,6 +496,13 @@ trampoline_setup:
         cmpb    $0,sym_phys(skip_realmode)
         jnz     1f
 
+        /* Bail if there is no command line to parse. */
+        mov     sym_phys(multiboot_ptr),%ebx
+        testl   $MBI_CMDLINE,MB_flags(%ebx)
+        jz      1f
+
+        pushl   $sym_phys(early_boot_opts)
+        pushl   MB_cmdline(%ebx)
         call    cmdline_parse_early
 
 1:
@@ -514,6 +521,7 @@ trampoline_setup:
         /* Jump into the relocated trampoline. */
         lret
 
+cmdline_parse_early:
 #include "cmdline.S"
 
 reloc:
xen/arch/x86/boot/trampoline.S +12 -0
index b013614..8a32728 100644
@@ -220,8 +220,20 @@ trampoline_boot_cpu_entry:
         /* Jump to the common bootstrap entry point. */
         jmp     trampoline_protmode_entry
 
+#include "video.h"
+
+/* Keep in sync with cmdline.c:early_boot_opts_t type! */
+early_boot_opts:
 skip_realmode:
         .byte   0
+opt_edd:
+        .byte   0                               /* edd=on/off/skipmbr */
+opt_edid:
+        .byte   0                               /* EDID parsing option (force/no/default). */
+GLOBAL(boot_vid_mode)
+        .word   VIDEO_80x25                     /* If we don't run at all, assume basic video mode 3 at 80x25. */
+vesa_size:
+        .word   0,0,0                           /* width x depth x height */
 
 GLOBAL(kbd_shift_flags)
         .byte   0
xen/arch/x86/boot/video.S +0 -7
index 2aafbeb..335a51c 100644
@@ -945,7 +945,6 @@ store_edid:
 #endif
         ret
 
-opt_edid:       .byte   0       # EDID parsing option (force/no/default)
 mt_end:         .word   0       # End of video mode table if built
 edit_buf:       .space  6       # Line editor buffer
 card_name:      .word   0       # Pointer to adapter name
@@ -991,12 +990,6 @@ name_bann:      .asciz  "Video adapter: "
 
 force_size:     .word   0       # Use this size instead of the one in BIOS vars
 
-vesa_size:      .word   0,0,0   # width x depth x height
-
-/* If we don't run at all, assume basic video mode 3 at 80x25. */
-        .align  2
-GLOBAL(boot_vid_mode)
-        .word   VIDEO_80x25
 GLOBAL(boot_vid_info)
         .byte   0, 0    /* orig_x, orig_y */
         .byte   3       /* text mode 3    */
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#65 lore raw

PATCH v5 16/16 x86: add multiboot2 protocol support for relocatable images

In reply to Daniel Kiper

Add 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.

---
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          |   19 ++++++++++++++++++-
 xen/arch/x86/x86_64/asm-offsets.c |    1 +
 xen/include/xen/multiboot2.h      |   13 +++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)
xen/arch/x86/boot/head.S +18 -1
index a1b0c05..25a92e0 100644
@@ -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_offset(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
@@ -372,10 +379,19 @@ __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     1f
+
+        mov     MB2_load_base_addr(%ecx),%esi
+        sub     $XEN_IMG_OFFSET,%esi
+        jmp     9f
+
+1:
         /* Get mem_lower from Multiboot2 information. */
         cmpl    $MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO,MB2_tag_type(%ecx)
         cmove   MB2_mem_lower(%ecx),%edx
-        je      trampoline_bios_setup
+        je      9f
 
         /* EFI IA-32 platforms are not supported. */
         cmpl    $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx)
@@ -389,6 +405,7 @@ __start:
         cmpl    $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%ecx)
         je      trampoline_bios_setup
 
+9:
         /* Go to next Multiboot2 information tag. */
         add     MB2_tag_size(%ecx),%ecx
         add     $(MULTIBOOT2_TAG_ALIGN-1),%ecx
xen/arch/x86/x86_64/asm-offsets.c +1 -0
index 9695ea6..022c280 100644
@@ -175,6 +175,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
index 8dd5800..feb4297 100644
@@ -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
#56 lore raw

PATCH v5 15/16 x86: make Xen early boot code relocatable

In reply to Daniel Kiper

Every multiboot protocol (regardless of version) compatible image must specify its load address (in ELF or multiboot header). Multiboot protocol compatible loader have to load image at specified address. However, there is no guarantee that the requested memory region (in case of Xen it starts at 1 MiB and ends at 17 MiB) where image should be loaded initially is a RAM and it is free (legacy BIOS platforms are merciful for Xen but I found at least one EFI platform on which Xen load address conflicts with EFI boot services; it is Dell PowerEdge R820 with latest firmware). To cope with that problem we must make Xen early boot code relocatable 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:
- default load address is changed from 1 MiB to 2 MiB; I did that because initial page tables are using 2 MiB huge pages and this way required updates for them are quite easy; it means that e.g. we avoid spacial cases for start and end of required memory region if it live at address not aligned to 2 MiB,
- %esi and %r15d registers are used as a storage for Xen image load base address (%r15d shortly because %rsi is used for EFI SystemTable address in 64-bit code); both registers are (%esi is mostly) unused in early boot code and preserved during C functions calls,
- %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.

PS I am still not convinced that move to %fs relative addressing is good
idea. As you can see code grows larger due to GDT initialization stuff, etc. However, I cannot see potential gains for now and future (probably it would be if whole Xen code, not early boot one, played segment registers games). Well, maybe in one or two places where base register is not used in full SIB addressing mode. So, question is: does it pay? Does gains overweight all efforts related to %fs games? Maybe we should stay with %esi relative addressing? Of course I am aware that it is not perfect. However, IMO, it is much simpler and clearer.
This is my suggestion. If you agree with me I can change code once again and back to %esi. This is not big problem. If not I am not going to argue longer. I will do what you request. Well, it will be nice if you convince me that your idea is good and I am wrong then... ;-)))

---
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/Makefile          |    4 +-
 xen/arch/x86/Rules.mk          |    4 +
 xen/arch/x86/boot/head.S       |  204 +++++++++++++++++++++++++++++++---------
 xen/arch/x86/boot/trampoline.S |   10 +-
 xen/arch/x86/boot/wakeup.S     |    4 +-
 xen/arch/x86/boot/x86_64.S     |   51 ++++------
 xen/arch/x86/efi/efi-boot.h    |    3 +-
 xen/arch/x86/setup.c           |   31 +++---
 xen/arch/x86/xen.lds.S         |    8 +-
 xen/include/asm-x86/config.h   |    1 +
 xen/include/asm-x86/page.h     |    2 +-
 11 files changed, 217 insertions(+), 105 deletions(-)
xen/arch/x86/Makefile +2 -2
index 9464b7b..df899c1 100644
@@ -89,8 +89,8 @@ all_symbols =
 endif
 
 $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
-	./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) 0x100000 \
-	`$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'`
+	./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) $(XEN_IMG_OFFSET) \
+		`$(NM) -nr $(TARGET)-syms | awk '$$3 == "__end_of_image__" {print "0x"$$1}'`
 
 .PHONY: tests
 tests:
xen/arch/x86/Rules.mk +4 -0
index 42be4bc..dd10afe 100644
@@ -1,6 +1,10 @@
 ########################################
 # x86-specific definitions
 
+XEN_IMG_OFFSET = 0x200000
+
+CFLAGS += -DXEN_IMG_OFFSET=$(XEN_IMG_OFFSET)
+
 CFLAGS += -I$(BASEDIR)/include
 CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-generic
 CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-default
xen/arch/x86/boot/head.S +157 -47

360 lines not on this page · raw message

xen/arch/x86/boot/trampoline.S +9 -1
index 8a32728..cfb47a4 100644
@@ -54,12 +54,20 @@ 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   0x00c0920000001000
 
         .pushsection .trampoline_rel, "a"
         .long   trampoline_gdt + BOOT_PSEUDORM_CS + 2 - .
         .long   trampoline_gdt + BOOT_PSEUDORM_DS + 2 - .
         .popsection
 
+GLOBAL(xen_img_load_base_addr)
+        .long   0
+
 GLOBAL(trampoline_misc_enable_off)
         .quad   0
 
@@ -87,7 +95,7 @@ trampoline_protmode_entry:
         mov     %ecx,%cr4
 
         /* Load pagetable base register. */
-        mov     $sym_phys(idle_pg_table),%eax
+        mov     $sym_offset(idle_pg_table),%eax
         add     bootsym_rel(trampoline_xen_phys_start,4,%eax)
         mov     %eax,%cr3
 
xen/arch/x86/boot/wakeup.S +2 -2
index 08ea9b2..3c56d12 100644
@@ -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_offset(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_offset(idle_pg_table),%eax
         add     bootsym_rel(trampoline_xen_phys_start,4,%eax)
         mov     %eax,%cr3
 
xen/arch/x86/boot/x86_64.S +19 -32

110 lines not on this page · raw message

xen/arch/x86/efi/efi-boot.h +2 -1
index 2622cf7..82f4216 100644
@@ -136,7 +136,7 @@ void __init free_ebmalloc_unused_mem(void)
 
     if ( ebmalloc_free )
     {
-        start = (unsigned long)ebmalloc_free - xen_phys_start;
+        start = (unsigned long)ebmalloc_free - xen_img_load_base_addr;
         start = PAGE_ALIGN(start + XEN_VIRT_START);
     }
     else
@@ -679,6 +679,7 @@ static void __init efi_arch_load_addr_check(EFI_LOADED_IMAGE *loaded_image)
         blexit(L"Xen must be loaded below 4Gb.");
     if ( xen_phys_start & ((1 << L2_PAGETABLE_SHIFT) - 1) )
         blexit(L"Xen must be loaded at a 2Mb boundary.");
+    xen_img_load_base_addr = xen_phys_start;
     trampoline_xen_phys_start = xen_phys_start;
 }
 
xen/arch/x86/setup.c +15 -16
index bc48351..9706b43 100644
@@ -286,9 +286,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;
@@ -674,6 +671,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     printk("Command line: %s\n", cmdline);
 
+    printk("Xen image load base address: 0x%08x\n", xen_img_load_base_addr);
+
     printk("Video information:\n");
 
     /* Print VGA display mode information. */
@@ -861,15 +860,17 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         highmem_start &= ~((1UL << L3_PAGETABLE_SHIFT) - 1);
 #endif
 
+    /* Do not relocate Xen image if boot loader did work for us. */
+    if ( xen_img_load_base_addr )
+        xen_phys_start = xen_img_load_base_addr;
+
     for ( i = boot_e820.nr_map-1; i >= 0; i-- )
     {
         uint64_t s, e, mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
         uint64_t end, limit = ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SHIFT;
 
-        /* Superpage-aligned chunks from BOOTSTRAP_MAP_BASE. */
         s = (boot_e820.map[i].addr + mask) & ~mask;
         e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
-        s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
         if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
             continue;
 
@@ -901,7 +902,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. */
@@ -915,9 +915,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));
@@ -933,7 +932,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);
@@ -943,7 +942,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);
@@ -957,15 +956,14 @@ 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) ==
-                   l2_table_offset((unsigned long)_stext));
             *pl2e++ = l2e_from_pfn(xen_phys_start >> PAGE_SHIFT,
                                    PAGE_HYPERVISOR_RX | _PAGE_PSE);
             for ( i = 1; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
             {
                 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() )
@@ -1019,6 +1017,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                 : "memory" );
 
             bootstrap_map(NULL);
+
+            printk("New Xen image base address: 0x%08lx\n", xen_phys_start);
         }
 
         /* Is the region suitable for relocating the multiboot modules? */
@@ -1082,6 +1082,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, __pa(&_start), __pa(&_end));
 
     /* Late kexec reservation (dynamic start address). */
@@ -1154,14 +1155,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
         set_pdx_range(s >> PAGE_SHIFT, e >> PAGE_SHIFT);
 
-        /* Need to create mappings above BOOTSTRAP_MAP_BASE. */
-        map_s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
+        map_s = s;
         map_e = min_t(uint64_t, e,
                       ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SHIFT);
 
         /* Pass mapped memory to allocator /before/ creating new mappings. */
         init_boot_pages(s, min(map_s, e));
-        s = map_s;
         if ( s < map_e )
         {
             uint64_t mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
xen/arch/x86/xen.lds.S +5 -3
index a6246c0..a0d1ea3 100644
@@ -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 */
@@ -257,12 +257,14 @@ SECTIONS
   .reloc : {
     *(.reloc)
   } :text
-  /* Trick the linker into setting the image size to exactly 16Mb. */
   . = ALIGN(__section_alignment__);
+#endif
+
+  /* Trick the linker into setting the image size to exactly 16Mb. */
   .pad : {
     . = ALIGN(MB(16));
+    __end_of_image__ = .;
   } :text
-#endif
 
   efi = DEFINED(efi) ? efi : .;
 
xen/include/asm-x86/config.h +1 -0
index 6fd84e7..f5a2d2f 100644
@@ -96,6 +96,7 @@ extern unsigned long trampoline_phys;
                  trampoline_phys-__pa(trampoline_start)))
 extern char trampoline_start[], trampoline_end[];
 extern char trampoline_realmode_entry[];
+extern unsigned int xen_img_load_base_addr;
 extern unsigned int trampoline_xen_phys_start;
 extern unsigned char trampoline_cpu_started;
 extern char wakeup_start[];
xen/include/asm-x86/page.h +1 -1
index 4ae387f..7324afe 100644
@@ -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_identmap[L1_PAGETABLE_ENTRIES],
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#66 lore raw
In reply to Daniel Kiper
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

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.

Just in case you aren't aware: The partial revert done by 0b8a172444 ("x86: partially revert use of 2M mappings for hypervisor image") now puts us a step further away from that goal, compared to when you had started your work.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw

Re: [PATCH v5 01/16] x86: allow EFI reboot method neither on EFI platforms...

In reply to Daniel Kiper
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

..nor EFI platforms with runtime services enabled.

---
v5 - suggestions/fixes:
- fix build error
(suggested by Jan Beulich),
- improve commit message.

Not really - it is now stale, as there's no checking of whether runtime service use is allowed. I also don't see what change in behavior this patch brings when viewed on its own. I think instead of fixing the prior build error you'd better have moved this later in the series.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw

Re: [PATCH v5 02/16] x86/boot: remove multiboot1_header_end from symbol table

In reply to Daniel Kiper
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Its visibility is not needed and just pollute symbol table.

With Andrew effectively having NAK-ed v4 of this patch, I don't see why - without further argumentation - this has been included again.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v5 3/16
#8 lore raw

Re: [PATCH v5 03/16] x86/boot: create *.lnk files with linker script

In reply to Daniel Kiper
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Newer GCC (e.g. gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)) does some code optimizations by creating data sections (e.g. jump addresses for C switch/case are calculated using data in .rodata section). This thing is not accepted by *.lnk build recipe which requires that only .text section lives in output. Potentially we can inhibit this GCC behavior by using special options, e.g. -fno-tree-switch-conversion. However, this does not guarantee that in the future new similar optimizations or anything else which creates not accepted sections will not break our build recipes again. I do not mention that probably this is not good idea to just disable random optimizations. So, take over full control on *.lnk linking process by using linker script and merge all text and data sections into one .text section.

Quoted 3 lines

Additionally, remove .got.plt section which is not used in our final code.

I'm still not overly happy with the description, as it make things look like we need this immediately when - aiui - it's only a prereq for your later additions, but nevertheless

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v5 4/16
#10 lore raw

Re: [PATCH v5 04/16] x86/boot/reloc: reduce assembly usage as much as possible

In reply to Daniel Kiper
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

..to increase code readability and ease its maintenance.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#13 lore raw

Re: [PATCH v5 06/16] x86/boot/reloc: create generic alloc and copy functions

In reply to Daniel Kiper
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Create generic alloc and copy functions. We need
separate tools for memory allocation and copy to
provide multiboot2 protocol support.

The amount of casting in this patch alone looks very reasonable now. Before ack-ing this and respective subsequent patches I'd like to see the final result though. To facilitate that I have to re-raise a previously asked question: Do you have a tree somewhere which one could use to look at the final result?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#24 lore raw

Re: [PATCH v5 09/16] x86: add multiboot2 protocol support

In reply to Daniel Kiper
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/boot/reloc.c +12 -0
+        case MULTIBOOT2_TAG_TYPE_MMAP:
+            if ( get_mb2_data(tag, mmap, entry_size) < sizeof(*mmap_src) )
+                break;
+
+            mbi_out->flags |= MBI_MEMMAP;
+            mbi_out->mmap_length = get_mb2_data(tag, mmap, size);
+            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);
+            mbi_out->mmap_length /= get_mb2_data(tag, mmap, entry_size);
+            mbi_out->mmap_length *= sizeof(memory_map_t);
+
+            mbi_out->mmap_addr = alloc_mem(mbi_out->mmap_length);
+

xen/arch/x86/boot/reloc.c multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline) · line 206

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+            mmap_src = get_mb2_data(tag, mmap, entries);
+            mmap_dst = (memory_map_t *)mbi_out->mmap_addr;
+
+            for ( i = 0; i < mbi_out->mmap_length / sizeof(memory_map_t); i++ )
+            {
+                /* Init size member properly. */
+                mmap_dst[i].size = sizeof(memory_map_t);
+                mmap_dst[i].size -= sizeof(((memory_map_t){0}).size);
+                /* Now copy a given region data. */
+                mmap_src = (void *)mmap_src + i * get_mb2_data(tag, mmap, entry_size);

Why do you multiply by i here? The way you've written it you want to increment mmap_src by entry_size _at the end_ of each iteration. Or else you need a second variable.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#31 lore raw

Re: [PATCH v5 10/16] efi: create efi_enabled()

In reply to Daniel Kiper
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

xen/arch/x86/efi/stub.c line 10

Quoted 10 lines
xen/arch/x86/efi/stub.c +4 -3
@@ -4,9 +4,10 @@
 #include <xen/lib.h>
 #include <asm/page.h>
 
-#ifndef efi_enabled
-const bool_t efi_enabled = 0;
-#endif
+bool_t efi_enabled(int feature)
+{
+    return false;
+}

Plain bool please, the more that you use false. And I'm relatively certain I did ask for the parameter type to be unsigned int, as you don't mean to pass negative values.

xen/arch/x86/efi/stub.c void __init noreturn __start_xen(unsigned long mbi_p) · line 745

Quoted 9 lines
xen/arch/x86/efi/stub.c +3 -1
@@ -739,8 +739,10 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         l3_bootmap[l3_table_offset(BOOTSTRAP_MAP_BASE)] =
             l3e_from_paddr(__pa(l2_bootmap), __PAGE_HYPERVISOR);
 
-        memmap_type = loader;
+        memmap_type = "EFI";
     }
+    else if ( efi_enabled(EFI_BOOT) )
+        memmap_type = "EFI";

Is the change ahead of the "else" really necessary?

xen/arch/x86/efi/stub.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1083

Quoted 6 lines
xen/arch/x86/efi/stub.c +1 -1
@@ -1078,7 +1080,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 ? mbi->mem_upper : __pa(&_start),
+    reserve_e820_ram(&boot_e820, efi_enabled(EFI_BOOT) ? mbi->mem_upper : __pa(&_start),

Is this really EFI_BOOT and not EFI_LOADER?

Quoted 9 lines
xen/arch/x86/efi/stub.c +0 -1
@@ -1153,7 +1160,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
 #ifndef CONFIG_ARM /* TODO - runtime service support */
 
-static bool_t __initdata efi_rs_enable = 1;
 static bool_t __initdata efi_map_uc;
 
 static void __init parse_efi_param(char *s)

xen/arch/x86/efi/stub.c static void __init parse_efi_param(char *s) · line 1182

Quoted 7 lines
xen/arch/x86/efi/stub.c +3 -1
@@ -1171,7 +1177,10 @@ static void __init parse_efi_param(char *s)
             *ss = '\0';
 
         if ( !strcmp(s, "rs") )
-            efi_rs_enable = val;
+        {
+            if ( !val )
+                __clear_bit(EFI_RS, &efi_flags);

"else __set_bit(...)" to continue to allow to override an earlier "efi=no-rs".

xen/arch/x86/efi/stub.c UINT64 __read_mostly efi_boot_max_var_store_size; · line 40

Quoted 5 lines
xen/arch/x86/efi/stub.c +1 -0
@@ -43,6 +37,9 @@ UINT64 __read_mostly efi_boot_max_var_store_size;
 UINT64 __read_mostly efi_boot_remain_var_store_size;
 UINT64 __read_mostly efi_boot_max_var_size;
 
+/* Bit fields representing available EFI features/properties. */

Bit field ...

xen/arch/x86/efi/stub.c UINT64 __read_mostly efi_boot_max_var_store_size; · line 41

Quoted 1 line
xen/arch/x86/efi/stub.c +1 -0
+unsigned long efi_flags;

An unsigned int would suffice for now, afaict.

xen/arch/x86/efi/stub.c struct efi __read_mostly efi = { · line 57

Quoted 9 lines
xen/arch/x86/efi/stub.c +5 -0
@@ -53,6 +50,12 @@ struct efi __read_mostly efi = {
 
 const struct efi_pci_rom *__read_mostly efi_pci_roms;
 
+/* Test whether EFI_* bits are enabled. */
+bool_t efi_enabled(int feature)
+{
+    return test_bit(feature, &efi_flags);
+}

Please either make the comment useful, or drop it.

xen/include/xen/efi.h line 5

Quoted 7 lines
xen/include/xen/efi.h +1 -0
@@ -2,13 +2,17 @@
 #define __XEN_EFI_H__
 
 #ifndef __ASSEMBLY__
+#include <xen/bitops.h>

If efi_enabled() doesn't get inlined here I don't see what you need this include for.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#35 lore raw

Re: [PATCH v5 11/16] efi: build xen.gz with EFI code

In reply to Daniel Kiper
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Build 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.

Quoted 7 lines

---
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).

Looks okay. But there's one more thing:

xen/common/efi/runtime.c int efi_runtime_call(struct xenpf_efi_runtime_call *op) · line 316

Quoted 6 lines
xen/common/efi/runtime.c +2 -0
@@ -309,6 +312,9 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)
     EFI_STATUS status = EFI_NOT_STARTED;
     int rc = 0;
 
+    if ( !efi_enabled(EFI_RS) )
+        return -ENOSYS;

I think this should be two checks:

    if ( !efi_enabled(EFI_BOOT) )
        return -ENOSYS;
    if ( !efi_enabled(EFI_RS) )
        return -EOPNOTSUPP;

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#43 lore raw

Re: [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms

In reply to Daniel Kiper

xen/arch/x86/boot/head.S multiboot2_header_start: · line 117

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/boot/head.S +8 -0
@@ -100,19 +107,45 @@ multiboot2_header_start:
 gdt_boot_descr:
         .word   6*8-1
         .long   sym_phys(trampoline_gdt)
+        .long   0 /* Needed for 64-bit lgdt */
+
+cs32_switch_addr:
+        .long   sym_phys(cs32_switch)
+        .word   BOOT_CS32
+
+vga_text_buffer:
+        .long   0xb8000

This now ends up being misaligned. Not a big deal, but anyway.

Quoted 17 lines
xen/arch/x86/boot/head.S +8 -3
         .section .init.text, "ax", @progbits
 
 bad_cpu:
         mov     $(sym_phys(.Lbad_cpu_msg)),%esi # Error message
-        jmp     print_err
+        jmp     0f
 not_multiboot:
         mov     $(sym_phys(.Lbad_ldr_msg)),%esi # Error message
-print_err:
-        mov     $0xB8000,%edi  # VGA framebuffer
+        jmp     0f
+mb2_no_st:
+        mov     $(sym_phys(.Lbad_ldr_nst)),%esi # Error message
+        jmp     0f
+mb2_no_ih:
+        mov     $(sym_phys(.Lbad_ldr_nih)),%esi # Error message
+        jmp     0f

xen/arch/x86/boot/head.S multiboot2_header_start: · line 149

Quoted 10 lines
xen/arch/x86/boot/head.S +9 -0
+mb2_no_bs:
+        mov     $(sym_phys(.Lbad_ldr_nbs)),%esi # Error message
+        xor     %edi,%edi                       # No VGA text buffer
+        jmp     1f
+mb2_efi_ia_32:
+        mov     $(sym_phys(.Lbad_efi_msg)),%esi # Error message
+        xor     %edi,%edi                       # No VGA text buffer
+        jmp     1f
+0:      mov     sym_phys(vga_text_buffer),%edi
 1:      mov     (%esi),%bl

All the labels you add should imo be .L ones. And the two numeric labels, considering their use across other label boundaries, would perhaps better become .L ones too.

xen/arch/x86/boot/head.S print_err: · line 182

Quoted 13 lines
xen/arch/x86/boot/head.S +13 -0
+__efi64_start:
+        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),%edi
+        jmp     x86_32_switch

Does the boot loader, btw, make any guarantees towards placing the image below 4G?

xen/arch/x86/boot/head.S print_err: · line 190

Quoted 7 lines

+.Lefi_multiboot2_proto:

xen/arch/x86/boot/head.S +6 -0
+        /* 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)(%ebx),%ecx

As indicated before - please use %rbx here; there's no need for having a pointless address size prefix.

Quoted 6 lines
xen/arch/x86/boot/head.S +6 -0
+        and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx
+
+0:
+        /* Check Multiboot2 information total size. */
+        mov     %ecx,%r8d
+        sub     %ebx,%r8d

xen/arch/x86/boot/head.S print_err: · line 206

Quoted 10 lines
xen/arch/x86/boot/head.S +10 -0
+        cmp     %r8d,MB2_fixed_total_size(%rbx)
+        jbe     run_bs
+
+        /* Are EFI boot services available? */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI_BS,MB2_tag_type(%rcx)
+        jne     1f
+
+        /* Yes, skip real mode and do not do other unneeded things. */
+        incb    skip_realmode(%rip)
+        jmp     9f

I think this comment need extending: Why again is not skipping real mode fine if there's no such tag, no matter that we got called in 64-bit mode here? Actually, looking further down, wasn't it that you simply abuse that label (you jump to an error label below when it is still zero)? That needs to be said here if so, for someone reading the code in order to understand that there's no actual use of real mode anywhere on this path.

xen/arch/x86/boot/head.S print_err: · line 267

Quoted 7 lines
xen/arch/x86/boot/head.S +7 -0
+        /*
+         * 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

In assembly code please use .startof.(.bss) and .sizeof.(.bss), as being propose for other uses by
https://lists.xenproject.org/archives/html/xen-devel/2016-08/msg02718.html

xen/arch/x86/boot/head.S print_err: · line 277

Quoted 3 lines
xen/arch/x86/boot/head.S +3 -0
+        /*
+         * IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable.
+         * OUT: %rax - Highest available memory address below 1 MiB.

Please be more precise, as "available" leaves open how much space is actually available there, and hence what this can be used for. Also according to ...

xen/arch/x86/boot/head.S print_err: · line 287

Quoted 9 lines
xen/arch/x86/boot/head.S +9 -0
+         * MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag is not provided
+         * on EFI platforms. Hence, it could not be used like
+         * on legacy BIOS platforms.
+         */
+        call    efi_multiboot2
+
+        /* Convert memory address to bytes/16 and store it in safe place. */
+        shr     $4,%eax
+        mov     %eax,%ecx

... the output really is in %eax.

Quoted 10 lines
xen/arch/x86/boot/head.S +5 -1
@@ -223,14 +425,22 @@ trampoline_setup:
         call    reloc
         mov     %eax,sym_phys(multiboot_ptr)
 
-        /* Initialize BSS (no nasty surprises!) */
+        /*
+         * Do not zero BSS on EFI platform here.
+         * It was initialized earlier.
+         */
+        cmpb    $0,sym_phys(skip_realmode)

xen/arch/x86/boot/head.S trampoline_setup: · line 441

Quoted 10 lines
xen/arch/x86/boot/head.S +4 -1
+        jnz     1f
+
+        /* Initialize BSS (no nasty surprises!). */
         mov     $sym_phys(__bss_start),%edi
         mov     $sym_phys(__bss_end),%ecx
         sub     %edi,%ecx
-        xor     %eax,%eax
         shr     $2,%ecx
+        xor     %eax,%eax
         rep stosl

Please avoid pointless code movement like this.

Quoted 25 lines
xen/arch/x86/efi/efi-boot.h +25 -0
+paddr_t __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
+    UINTN cols, gop_mode = ~0, rows;
+
+    __set_bit(EFI_BOOT, &efi_flags);
+    __set_bit(EFI_RS, &efi_flags);
+
+    efi_init(ImageHandle, SystemTable);
+
+    efi_console_set_mode();
+
+    if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
+                           &cols, &rows) == EFI_SUCCESS )
+        efi_arch_console_init(cols, rows);
+
+    gop = efi_get_gop();
+
+    if ( gop )
+        gop_mode = efi_find_gop_mode(gop, 0, 0, 0);
+
+    efi_arch_edd();
+    efi_arch_cpu();
+
+    efi_tables();

xen/arch/x86/efi/efi-boot.h static bool_t __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) · line 726

Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10 -0
+    setup_efi_pci();
+    efi_variables();
+
+    if ( gop )
+        efi_set_gop_mode(gop, gop_mode);
+
+    efi_exit_boot(ImageHandle, SystemTable);
+
+    /* Return highest available memory address below 1 MiB. */
+    return cfg.addr;

Where is it being made certain that there are 64k of space available right below this address, as is being assumed at trampoline_setup?

Quoted 17 lines
xen/arch/x86/efi/stub.c +11 -0
@@ -3,6 +3,30 @@
 #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>
+
+paddr_t __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    CHAR16 *err = L"Xen does not have EFI code build in!!!\r\nSystem halted!!!\r\n";
+    SIMPLE_TEXT_OUTPUT_INTERFACE *StdErr;

xen/arch/x86/efi/stub.c line 26

Quoted 10 lines
xen/arch/x86/efi/stub.c +10 -0
+
+    StdErr = SystemTable->StdErr ? SystemTable->StdErr : SystemTable->ConOut;
+
+    /* Print error message and halt the system. */
+    asm volatile(
+    "    call %2                      \n"
+    "0:  hlt                          \n"
+    "    jmp  0b                      \n"
+       : "+c" (StdErr), "+d" (err) : "g" (StdErr->OutputString)
+       : "rax", "r8", "r9", "r10", "r11", "cc", "memory");

There are explanations missing here: First, a warning should be added alongside the EFI header inclusions, making clear that no services whatsoever can be called. And then the asm() here needs to explain that it open codes an MS-ABI function call. Which then makes me wonder (even if it doesn't matter much) - are the clobbers actually correct? I think you also need to clobber rsi and rdi. Otoh there's no need for an explicit "cc" clobber on x86.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#50 lore raw

Re: [PATCH v5 14/16] x86/boot: implement early command line parser in C

In reply to Daniel Kiper

xen/arch/x86/boot/cmdline.c line 46

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/boot/cmdline.c new file +10 -0
+#define NULL	((void *)0)
+
+#define __packed	__attribute__((__packed__))
+#define __stdcall	__attribute__((__stdcall__))
+
+#define max(x,y) ({ \
+        const typeof(x) _x = (x);       \
+        const typeof(y) _y = (y);       \
+        (void) (&_x == &_y);            \
+        _x > _y ? _x : _y; })

Now that you add a second instance of (some of) these, please move them to a new (local to this directory) header, e.g. defs.h.

xen/arch/x86/boot/cmdline.c line 50

Quoted 3 lines
xen/arch/x86/boot/cmdline.c new file +3 -0
+#define tolower(c) ((c) | 0x20)
+
+typedef unsigned char bool_t;

_Bool and bool please and ...

xen/arch/x86/boot/cmdline.c line 56

Quoted 6 lines
xen/arch/x86/boot/cmdline.c new file +6 -0
+typedef unsigned char u8;
+typedef unsigned short u16;
+typedef unsigned int size_t;
+
+#define FALSE		0
+#define TRUE		1

... these replaced by true and false. In fact I see no reason why you couldn't include xen/stdbool.h here now that it can be more generally used.

xen/arch/x86/boot/cmdline.c line 78

Quoted 7 lines
xen/arch/x86/boot/cmdline.c new file +7 -0
+/*
+ * Space and TAB are obvious delimiters. However, I am
+ * adding "\n" and "\r" here too. Just in case when
+ * crazy bootloader/user puts them somewhere.
+ */
+static const char delim_chars_comma[] = ", \n\r\t";
+static const char delim_chars[] = " \n\r\t";

I realize it's minor, but why two arrays instead of

#define delim_chars (delim_chars_comma + 1)

?

Quoted 10 lines

+/*
+ * static const char *delim_chars = &delim_chars_comma[1];
+ *
+ * Older compilers, e.g. gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21),
+ * put &delim_chars_comma[1] directly into *delim_chars. This means that the address
+ * in *delim_chars is not properly updated during runtime. Newer compilers are much
+ * smarter and build fully relocatable code even if above shown construct is used.
+ * However, define delim_chars[] separately to properly build Xen code on
+ * older systems.
+ */

I have to admit that I don't really understand what you want to say with this comment.

Quoted 25 lines
xen/arch/x86/boot/cmdline.c new file +25 -0
+static unsigned int strtoui(const char *s, const char *stop, const char **next)
+{
+    char l;
+    unsigned int base = 10, ores = 0, res = 0;
+
+    if ( *s == '0' )
+      base = (tolower(*++s) == 'x') ? (++s, 16) : 8;
+
+    for ( ; *s != '\0'; ++s )
+    {
+        if ( stop && strchr(stop, *s) )
+            goto out;
+
+        if ( *s < '0' || (*s > '7' && base == 8) )
+        {
+            res = UINT_MAX;
+            goto out;
+        }
+
+        l = tolower(*s);
+
+        if ( *s > '9' && (base != 16 || l < 'a' || l > 'f') )
+        {
+            res = UINT_MAX;
+            goto out;

xen/arch/x86/boot/cmdline.c line 197

Quoted 10 lines
xen/arch/x86/boot/cmdline.c new file +10 -0
+        }
+
+        res *= base;
+        res += (l >= 'a') ? (l - 'a' + 10) : (*s - '0');
+
+        if ( ores > res )
+        {
+            res = UINT_MAX;
+            goto out;
+        }

Without having spent time to try and find an example, it feels like this check won't catch all possible overflow conditions. If you care about overflow, please make sure you catch all cases.

Quoted 10 lines
xen/arch/x86/boot/trampoline.S +4 -0
@@ -220,8 +220,20 @@ trampoline_boot_cpu_entry:
         /* Jump to the common bootstrap entry point. */
         jmp     trampoline_protmode_entry
 
+#include "video.h"
+
+/* Keep in sync with cmdline.c:early_boot_opts_t type! */
+early_boot_opts:

xen/arch/x86/boot/trampoline.S trampoline_boot_cpu_entry: · line 236

Quoted 10 lines
xen/arch/x86/boot/trampoline.S +8 -0
 skip_realmode:
         .byte   0
+opt_edd:
+        .byte   0                               /* edd=on/off/skipmbr */
+opt_edid:
+        .byte   0                               /* EDID parsing option (force/no/default). */
+GLOBAL(boot_vid_mode)
+        .word   VIDEO_80x25                     /* If we don't run at all, assume basic video mode 3 at 80x25. */
+vesa_size:
+        .word   0,0,0                           /* width x depth x height */

While I don't mind you using the packed attribute on the C variant, please insert a padding byte here and there to make the four words aligned, and add an alignment directive to make the whole structure at least word aligned.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#57 lore raw

Re: [PATCH v5 15/16] x86: make Xen early boot code relocatable

In reply to Daniel Kiper
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Every multiboot protocol (regardless of version) compatible image must specify its load address (in ELF or multiboot header). Multiboot protocol compatible loader have to load image at specified address. However, there is no guarantee that the requested memory region (in case of Xen it starts at 1 MiB and ends at 17 MiB) where image should be loaded initially is a RAM and it is free (legacy BIOS platforms are merciful for Xen but I found at least one EFI platform on which Xen load address conflicts with EFI boot services; it is Dell PowerEdge R820 with latest firmware). To cope with that problem we must make Xen early boot code relocatable 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.

Quoted 6 lines

This patch changes following things:
- default load address is changed from 1 MiB to 2 MiB; I did that because initial page tables are using 2 MiB huge pages and this way required updates for them are quite easy; it means that e.g. we avoid spacial cases for start and end of required memory region if it live at address not aligned to 2 MiB,

Should this be a separate change then, to separate possible regressions due to that from such due to any other of the changes here? And then I don't see why, when making the image relocatable anyway, the link time load address actually still matters.

Quoted 4 lines

- %esi and %r15d registers are used as a storage for Xen image load base address (%r15d shortly because %rsi is used for EFI SystemTable address in 64-bit code); both registers are (%esi is mostly) unused in early boot code and preserved during C functions calls,

In a context where you (also) talk about 64-bit code, %esi can't be called preserved unilaterally. You should make clear that this is for 32-bit function calls.

xen/arch/x86/boot/head.S line 15

Quoted 8 lines
xen/arch/x86/boot/head.S +1 -1
@@ -12,13 +12,16 @@
         .text
         .code32
 
-#define sym_phys(sym)     ((sym) - __XEN_VIRT_START)
+#define sym_offset(sym)   ((sym) - __XEN_VIRT_START)

In a patch already large and hence hard to review, did you really need to do this rename?

xen/arch/x86/boot/head.S vga_text_buffer: · line 133

Quoted 6 lines
xen/arch/x86/boot/head.S +1 -1
@@ -126,26 +130,26 @@ vga_text_buffer:
         .section .init.text, "ax", @progbits
 
 bad_cpu:
-        mov     $(sym_phys(.Lbad_cpu_msg)),%esi # Error message
+        lea     esi_offset(.Lbad_cpu_msg),%esi  # Error message

Why not just

add $sym_offset(.Lbad_cpu_msg),%esi # Error message

? Together with not doing said rename, this would be more obviously correct.

xen/arch/x86/boot/head.S trampoline_bios_setup: · line 446

Quoted 12 lines
xen/arch/x86/boot/head.S +8 -0
@@ -409,36 +436,93 @@ trampoline_bios_setup:
         cmovb   %edx,%ecx           /* and use the smaller */
 
 trampoline_setup:
+        /*
+         * Called on legacy BIOS and EFI platforms.
+         *
+         * Compute 0-15 bits of BOOT_FS segment descriptor base address.
+         */
+        mov     %esi,%edx
+        shl     $16,%edx
+        or      %edx,BOOT_FS+esi_offset(trampoline_gdt)

mov %si,BOOT_FS+esi_offset(trampoline_gdt)

xen/arch/x86/boot/head.S trampoline_bios_setup: · line 452

Quoted 5 lines
xen/arch/x86/boot/head.S +5 -0
+        /* Compute 16-23 bits of BOOT_FS segment descriptor base address. */
+        mov     %esi,%edx
+        shr     $16,%edx
+        and     $0x000000ff,%edx
+        or      %edx,BOOT_FS+4+esi_offset(trampoline_gdt)

mov %dl,BOOT_FS+4+esi_offset(trampoline_gdt)

xen/arch/x86/boot/head.S trampoline_bios_setup: · line 457

Quoted 4 lines
xen/arch/x86/boot/head.S +4 -0
+        /* Compute 24-31 bits of BOOT_FS segment descriptor base address. */
+        mov     %esi,%edx
+        and     $0xff000000,%edx
+        or      %edx,BOOT_FS+4+esi_offset(trampoline_gdt)

mov %dh,BOOT_FS+7+esi_offset(trampoline_gdt)

(with various of the intermediate instructions dropped)

That'll reduce you code size concern for the GDT setup quite a bit.

Quoted 14 lines
xen/arch/x86/boot/head.S +14 -0
+        /*
+         * Initialise %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.
+         *
+         * Please check Intel 64 and IA-32 Architectures Software Developer’s
+         * Manual, Volume 2 (2A, 2B & 2C): Instruction Set Reference,
+         * LGDT and MOV instructions description and
+         * Intel 64 and IA-32 Architectures Software Developer’s
+         * Manual Volume 3 (3A, 3B & 3C): System Programming Guide,
+         * section 3.4.3, Segment Registers for more details.
+         *
+         * AIUI, only GDT address and limit are loaded into GDTR when
+         * lgdt is executed. Segment descriptor is loaded directly from

xen/arch/x86/boot/head.S trampoline_bios_setup: · line 482

Quoted 10 lines
xen/arch/x86/boot/head.S +10 -0
+         * memory into segment register (hiden part) only when relevant
+         * load instruction is used (e.g. mov %edx,%fs). Though GDT content
+         * probably could be stored in CPU cache but nothing suggest that
+         * CPU caching interfere in one way or another with segment descriptor
+         * load. So, it looks that every change in active GDT is immediately
+         * available for relevant segment descriptor load instruction.
+         *
+         * I was not able to find anything which invalidates above.
+         * So, everything suggest that we do not need an extra lgdt here.
+         */

All of this comment except for the first sentence is just stating basic architecture facts. Please drop all that.

xen/arch/x86/boot/head.S trampoline_bios_setup: · line 492

Quoted 11 lines
xen/arch/x86/boot/head.S +4 -1
+        mov     $BOOT_FS,%edx
+        mov     %edx,%fs
+
         /* Reserve 64kb for the trampoline. */
         sub     $0x1000,%ecx
 
         /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
         xor     %cl, %cl
         shl     $4, %ecx
-        mov     %ecx,sym_phys(trampoline_phys)
+        mov     %ecx,fs_offset(trampoline_phys)

Seeing the first instance, together with the earlier comment about not renaming sym_phys() I think this would end up more consistently with using sym_fs() (and then obviously sym_esi()) as names.

Quoted 5 lines
xen/arch/x86/boot/head.S +0 -1
@@ -461,62 +545,88 @@ trampoline_setup:
 
         /* Stash TSC to calculate a good approximation of time-since-boot */
         rdtsc
-        mov     %eax,sym_phys(boot_tsc_stamp)

xen/arch/x86/boot/head.S trampoline_setup: · line 556

Quoted 10 lines
xen/arch/x86/boot/head.S +9 -1
-        mov     %edx,sym_phys(boot_tsc_stamp+4)
+        mov     %eax,fs_offset(boot_tsc_stamp)
+        mov     %edx,fs_offset(boot_tsc_stamp)+4
+
+        /* Update frame addresses in page tables. */
+        mov     $((__page_tables_end-__page_tables_start)/8),%ecx
+1:      testl   $_PAGE_PRESENT,fs_offset(__page_tables_start)-8(,%ecx,8)
+        jz      2f
+        add     %esi,fs_offset(__page_tables_start)-8(,%ecx,8)
+2:      loop    1b

This loop includes the mapping of the low Mb, which I don't think it should modify. Or wait - you move __page_tables_start, which by itself is fragile (but looks to be acceptable if accompanied by a comment explaining why it doesn't cover l1_identmap).

Also, just to double check - all these page table setup adjustments don't require reflecting in xen.efi's page table setup code?

Quoted 5 lines
xen/arch/x86/boot/head.S +2 -2
         /* Apply relocations to bootstrap trampoline. */
-        mov     sym_phys(trampoline_phys),%edx
-        mov     $sym_phys(__trampoline_rel_start),%edi
+        mov     fs_offset(trampoline_phys),%edx
+        mov     $sym_offset(__trampoline_rel_start),%edi

xen/arch/x86/boot/head.S trampoline_setup: · line 591

Quoted 10 lines
xen/arch/x86/boot/head.S +4 -3
+        mov     $sym_offset(__trampoline_rel_stop),%ebx
 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
+        cmp     %ebx,%edi
         jb      1b

And again it looks like the switch to using %ebx here is not needed.

Quoted 4 lines
xen/arch/x86/boot/head.S +1 -1
         /* Patch in the trampoline segment. */
         shr     $4,%edx
-        mov     $sym_phys(__trampoline_seg_start),%edi
+        mov     $sym_offset(__trampoline_seg_start),%edi

xen/arch/x86/boot/head.S trampoline_setup: · line 602

Quoted 10 lines
xen/arch/x86/boot/head.S +4 -3
+        mov     $sym_offset(__trampoline_seg_stop),%ebx
 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
+        cmp     %ebx,%edi
         jb      1b

Same here then, obviously.

xen/arch/x86/boot/trampoline.S trampoline_gdt: · line 61

Quoted 11 lines
xen/arch/x86/boot/trampoline.S +5 -0
@@ -54,12 +54,20 @@ 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   0x00c0920000001000

This does not look like it covers 1Mb, it's more like 1Mb+4k-1.

xen/arch/x86/boot/trampoline.S trampoline_gdt: · line 69

Quoted 7 lines
xen/arch/x86/boot/trampoline.S +2 -0
         .pushsection .trampoline_rel, "a"
         .long   trampoline_gdt + BOOT_PSEUDORM_CS + 2 - .
         .long   trampoline_gdt + BOOT_PSEUDORM_DS + 2 - .
         .popsection
 
+GLOBAL(xen_img_load_base_addr)
+        .long   0

I've yet to understand the purpose of this symbol, but in any case:
If the trampoline code doesn't reference it, why does it get placed here?

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 865

Quoted 7 lines
xen/arch/x86/boot/trampoline.S +3 -0
@@ -861,15 +860,17 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         highmem_start &= ~((1UL << L3_PAGETABLE_SHIFT) - 1);
 #endif
 
+    /* Do not relocate Xen image if boot loader did work for us. */
+    if ( xen_img_load_base_addr )
+        xen_phys_start = xen_img_load_base_addr;

Okay, with this change the question really is: Why do you need the new symbol? I.e. why can't you just use xen_phys_start, just like I managed to re-use it when I introduced boot from EFI?

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 869

Quoted 6 lines
xen/arch/x86/boot/trampoline.S +0 -1
     for ( i = boot_e820.nr_map-1; i >= 0; i-- )
     {
         uint64_t s, e, mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
         uint64_t end, limit = ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SHIFT;
 
-        /* Superpage-aligned chunks from BOOTSTRAP_MAP_BASE. */

I can see that you want to get rid of BOOTSTRAP_MAP_BASE, but please don't delete the comment as a whole.

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 874

Quoted 5 lines
xen/arch/x86/boot/trampoline.S +0 -1
         s = (boot_e820.map[i].addr + mask) & ~mask;
         e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
-        s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
         if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
             continue;

This means you now map memory between 2Mb and 16Mb here. Is this necessary?

Quoted 9 lines
xen/arch/x86/boot/trampoline.S +0 -1
@@ -901,7 +902,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. */

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 919

Quoted 7 lines
xen/arch/x86/boot/trampoline.S +1 -2
@@ -915,9 +915,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);

Assuming _start - XEN_VIRT_START == XEN_IMG_OFFSET, is this change necessary? Or is it rather just simplification, which again should be split from an already complex patch.

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 961

Quoted 6 lines
xen/arch/x86/boot/trampoline.S +0 -2
@@ -957,15 +956,14 @@ 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) ==
-                   l2_table_offset((unsigned long)_stext));

At least when using_2M_mapping() this surely ought to hold?

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 1021

Quoted 6 lines
xen/arch/x86/boot/trampoline.S +2 -0
@@ -1019,6 +1017,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                 : "memory" );
 
             bootstrap_map(NULL);
+
+            printk("New Xen image base address: 0x%08lx\n", xen_phys_start);

I don't see the motivation for adding such a message in this patch, but if, then please use %#lx.

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 1086

Quoted 6 lines
xen/arch/x86/boot/trampoline.S +1 -0
@@ -1082,6 +1082,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, __pa(&_start), __pa(&_end));

Another stray change.

Quoted 13 lines
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 */
@@ -257,12 +257,14 @@ SECTIONS
   .reloc : {

xen/arch/x86/xen.lds.S SECTIONS · line 266

Quoted 10 lines
xen/arch/x86/xen.lds.S +4 -1
     *(.reloc)
   } :text
-  /* Trick the linker into setting the image size to exactly 16Mb. */
   . = ALIGN(__section_alignment__);
+#endif
+
+  /* Trick the linker into setting the image size to exactly 16Mb. */
   .pad : {
     . = ALIGN(MB(16));
+    __end_of_image__ = .;

I see that you use this symbol in xen/arch/x86/Makefile, but I again don't follow why this logic needs to change.

xen/include/asm-x86/page.h extern root_pgentry_t · line 292

Quoted 9 lines
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];

Why do you need 4 of them? I can see why one might not suffice, but two surely should?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#67 lore raw
In reply to Jan Beulich
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

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.

Quoted 4 lines

Just in case you aren't aware: The partial revert done by 0b8a172444 ("x86: partially revert use of 2M mappings for hypervisor image") now puts us a step further away from that goal, compared to when you had started your work.

I am not sure about that. Andrew patches changed xen.gz size significantly. My patches does not do that in significant way. They (precisely it) just move load address from 1 MiB to 2 MiB. So, I do not expect major issues here. However, anyway it should be tested (and it was tested, IIRC, by Konrad some time ago).

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

Re: [PATCH v5 02/16] x86/boot: remove multiboot1_header_end from symbol table

In reply to Jan Beulich
Quoted 8 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Its visibility is not needed and just pollute symbol table.

With Andrew effectively having NAK-ed v4 of this patch, I don't see why - without further argumentation - this has been included again.

I have saw that discussion stopped somewhere in the middle, so, I was not sure what is your final decision. However, if you approve/agree Andrew's NAK then I think that we should use "multiboot2_header_end" label instead of .Lmultiboot2_header_end in patch #9 (x86: add multiboot2 protocol support). Just to be in line with multiboot (v1) protocol header.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#14 lore raw

Re: [PATCH v5 06/16] x86/boot/reloc: create generic alloc and copy functions

In reply to Jan Beulich
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Create generic alloc and copy functions. We need
separate tools for memory allocation and copy to
provide multiboot2 protocol support.

Quoted 7 lines
Quoted 1 line

The amount of casting in this patch alone looks very reasonable now. Before ack-ing this and respective subsequent patches I'd like to see the final result though. To facilitate that I have to re-raise a previously asked question: Do you have a tree somewhere which one could use to look at the final result?

Sadly no.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#25 lore raw

Re: [PATCH v5 09/16] x86: add multiboot2 protocol support

In reply to Jan Beulich
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/boot/reloc.c +17 -0
+        case MULTIBOOT2_TAG_TYPE_MMAP:
+            if ( get_mb2_data(tag, mmap, entry_size) < sizeof(*mmap_src) )
+                break;
+
+            mbi_out->flags |= MBI_MEMMAP;
+            mbi_out->mmap_length = get_mb2_data(tag, mmap, size);
+            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);
+            mbi_out->mmap_length /= get_mb2_data(tag, mmap, entry_size);
+            mbi_out->mmap_length *= sizeof(memory_map_t);
+
+            mbi_out->mmap_addr = alloc_mem(mbi_out->mmap_length);
+
+            mmap_src = get_mb2_data(tag, mmap, entries);
+            mmap_dst = (memory_map_t *)mbi_out->mmap_addr;
+
+            for ( i = 0; i < mbi_out->mmap_length / sizeof(memory_map_t); i++ )
+            {
Quoted 8 lines

xen/arch/x86/boot/reloc.c multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline) · line 206

Quoted 5 lines
xen/arch/x86/boot/reloc.c +5 -0
+                /* Init size member properly. */
+                mmap_dst[i].size = sizeof(memory_map_t);
+                mmap_dst[i].size -= sizeof(((memory_map_t){0}).size);
+                /* Now copy a given region data. */
+                mmap_src = (void *)mmap_src + i * get_mb2_data(tag, mmap, entry_size);

Why do you multiply by i here? The way you've written it you want to increment mmap_src by entry_size _at the end_ of each iteration. Or

This is another option. If you wish I can do that.

Quoted 1 line

else you need a second variable.

I think that former is better.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#68 lore raw
In reply to Daniel Kiper
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 16:15, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

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.

Quoted 4 lines

Just in case you aren't aware: The partial revert done by 0b8a172444 ("x86: partially revert use of 2M mappings for hypervisor image") now puts us a step further away from that goal, compared to when you had started your work.

Quoted 5 lines

I am not sure about that. Andrew patches changed xen.gz size significantly. My patches does not do that in significant way. They (precisely it) just move load address from 1 MiB to 2 MiB. So, I do not expect major issues here. However, anyway it should be tested (and it was tested, IIRC, by Konrad some time ago).

Looks like you didn't understand: This is not about image size. The issue is that the EFI binary, other than xen.gz, now properly uses RX, RO, and RW permissions (and large pages) for the individual pieces of the image. Moving to a single binary would hence result in a (slight) regression unless that gets taken care of beforehand.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw

Re: [PATCH v5 02/16] x86/boot: remove multiboot1_header_end from symbol table

In reply to Daniel Kiper
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 16:27, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Its visibility is not needed and just pollute symbol table.

Quoted 8 lines
Quoted 2 lines

With Andrew effectively having NAK-ed v4 of this patch, I don't see why - without further argumentation - this has been included again.

I have saw that discussion stopped somewhere in the middle, so, I was not sure what is your final decision. However, if you approve/agree Andrew's NAK then I think that we should use "multiboot2_header_end" label instead of .Lmultiboot2_header_end in patch #9 (x86: add multiboot2 protocol support). Just to be in line with multiboot (v1) protocol header.

I don't agree with Andrew, but I also won't approve and commit a patch he did nak. Since I'm of the opinion that I should not have given my ack to his original change, I'm going to nak introduction of another such bogus label.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#15 lore raw

Re: [PATCH v5 06/16] x86/boot/reloc: create generic alloc and copy functions

In reply to Daniel Kiper
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 16:32, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Create generic alloc and copy functions. We need
separate tools for memory allocation and copy to
provide multiboot2 protocol support.

Quoted 7 lines
Quoted 5 lines

The amount of casting in this patch alone looks very reasonable now. Before ack-ing this and respective subsequent patches I'd like to see the final result though. To facilitate that I have to re-raise a previously asked question: Do you have a tree somewhere which one could use to look at the final result?

Sadly no.

Alternatively, could you simply send the final resulting source file?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#26 lore raw

Re: [PATCH v5 09/16] x86: add multiboot2 protocol support

In reply to Daniel Kiper
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 16:41, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/boot/reloc.c +17 -0
+        case MULTIBOOT2_TAG_TYPE_MMAP:
+            if ( get_mb2_data(tag, mmap, entry_size) < sizeof(*mmap_src) )
+                break;
+
+            mbi_out->flags |= MBI_MEMMAP;
+            mbi_out->mmap_length = get_mb2_data(tag, mmap, size);
+            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);
+            mbi_out->mmap_length /= get_mb2_data(tag, mmap, entry_size);
+            mbi_out->mmap_length *= sizeof(memory_map_t);
+
+            mbi_out->mmap_addr = alloc_mem(mbi_out->mmap_length);
+
+            mmap_src = get_mb2_data(tag, mmap, entries);
+            mmap_dst = (memory_map_t *)mbi_out->mmap_addr;
+
+            for ( i = 0; i < mbi_out->mmap_length / sizeof(memory_map_t); i++ )
+            {
Quoted 8 lines

xen/arch/x86/boot/reloc.c multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline) · line 206

Quoted 5 lines
xen/arch/x86/boot/reloc.c +5 -0
+                /* Init size member properly. */
+                mmap_dst[i].size = sizeof(memory_map_t);
+                mmap_dst[i].size -= sizeof(((memory_map_t){0}).size);
+                /* Now copy a given region data. */
+                mmap_src = (void *)mmap_src + i * get_mb2_data(tag, mmap, entry_size);

Why do you multiply by i here? The way you've written it you want to increment mmap_src by entry_size _at the end_ of each iteration. Or

Quoted 1 line

This is another option. If you wish I can do that.

This is not just another option - afaict the code as is won't work for more than one map entry.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#32 lore raw

Re: [PATCH v5 10/16] efi: create efi_enabled()

In reply to Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/efi/stub.c +0 -0
@@ -4,9 +4,10 @@
 #include <xen/lib.h>
 #include <asm/page.h>
 
Quoted 9 lines

xen/arch/x86/efi/stub.c line 10

Quoted 7 lines
xen/arch/x86/efi/stub.c +4 -3
-#ifndef efi_enabled
-const bool_t efi_enabled = 0;
-#endif
+bool_t efi_enabled(int feature)
+{
+    return false;
+}

Plain bool please, the more that you use false. And I'm relatively

What is wrong with bool_t? bool is equal to bool_t.

Quoted 2 lines

certain I did ask for the parameter type to be unsigned int, as you don't mean to pass negative values.

Sure. However, full blown efi_enabled() calls test_bit(). Latter calls constant_test_bit() or variable_test_bit() which take bit position as int. So, I do not think that efi_enabled() should take unsigned int. Or we should change constant_test_bit() and variable_test_bit() respectively. Hmmm... No, we should not. It looks that negative offsets are valid.

Quoted 11 lines

xen/arch/x86/efi/stub.c void __init noreturn __start_xen(unsigned long mbi_p) · line 745

Quoted 9 lines
xen/arch/x86/efi/stub.c +3 -1
@@ -739,8 +739,10 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         l3_bootmap[l3_table_offset(BOOTSTRAP_MAP_BASE)] =
             l3e_from_paddr(__pa(l2_bootmap), __PAGE_HYPERVISOR);
 
-        memmap_type = loader;
+        memmap_type = "EFI";
     }
+    else if ( efi_enabled(EFI_BOOT) )
+        memmap_type = "EFI";

Is the change ahead of the "else" really necessary?

No. However, in this case memmap_type is always "EFI" and we do not need to get this value from loader variable. Which, of course, is always also "EFI" (to be precise pointer to) here but IMO "memmap_type = loader" suggests that memmap_type could be anything else.

Quoted 8 lines

xen/arch/x86/efi/stub.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1083

Quoted 6 lines
xen/arch/x86/efi/stub.c +1 -1
@@ -1078,7 +1080,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 ? mbi->mem_upper : __pa(&_start),
+    reserve_e820_ram(&boot_e820, efi_enabled(EFI_BOOT) ? mbi->mem_upper : __pa(&_start),

Is this really EFI_BOOT and not EFI_LOADER?

Yep, it should be EFI_LOADER. I am not sure why it has changed to EFI_BOOT. Or it did not... Anyway, it is my fault. I will fix it.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#44 lore raw

Re: [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms

In reply to Jan Beulich
Quoted 17 lines · Jan Beulich

xen/arch/x86/boot/head.S multiboot2_header_start: · line 117

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/boot/head.S +8 -0
@@ -100,19 +107,45 @@ multiboot2_header_start:
 gdt_boot_descr:
         .word   6*8-1
         .long   sym_phys(trampoline_gdt)
+        .long   0 /* Needed for 64-bit lgdt */
+
+cs32_switch_addr:
+        .long   sym_phys(cs32_switch)
+        .word   BOOT_CS32
+
+vga_text_buffer:
+        .long   0xb8000

This now ends up being misaligned. Not a big deal, but anyway.

Quoted 1 line
xen/arch/x86/boot/head.S +0 -0
         .section .init.text, "ax", @progbits

I hope that ".align 4" is sufficient here.

Quoted 21 lines
Quoted 21 lines
xen/arch/x86/boot/head.S +14 -3
 bad_cpu:
         mov     $(sym_phys(.Lbad_cpu_msg)),%esi # Error message
-        jmp     print_err
+        jmp     0f
 not_multiboot:
         mov     $(sym_phys(.Lbad_ldr_msg)),%esi # Error message
-print_err:
-        mov     $0xB8000,%edi  # VGA framebuffer
+        jmp     0f
+mb2_no_st:
+        mov     $(sym_phys(.Lbad_ldr_nst)),%esi # Error message
+        jmp     0f
+mb2_no_ih:
+        mov     $(sym_phys(.Lbad_ldr_nih)),%esi # Error message
+        jmp     0f
+mb2_no_bs:
+        mov     $(sym_phys(.Lbad_ldr_nbs)),%esi # Error message
+        xor     %edi,%edi                       # No VGA text buffer
+        jmp     1f
+mb2_efi_ia_32:
+        mov     $(sym_phys(.Lbad_efi_msg)),%esi # Error message
Quoted 8 lines

xen/arch/x86/boot/head.S multiboot2_header_start: · line 149

Quoted 4 lines
xen/arch/x86/boot/head.S +3 -0
+        xor     %edi,%edi                       # No VGA text buffer
+        jmp     1f
+0:      mov     sym_phys(vga_text_buffer),%edi
 1:      mov     (%esi),%bl

All the labels you add should imo be .L ones. And the two numeric labels, considering their use across other label boundaries, would perhaps better become .L ones too.

OK.

Quoted 8 lines
Quoted 8 lines
xen/arch/x86/boot/head.S +8 -0
+__efi64_start:
+        cld
+
+        /* VGA is not available on EFI platforms. */
+        movl   $0,vga_text_buffer(%rip)
+
+        /* Check for Multiboot2 bootloader. */
+        cmp     $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
Quoted 8 lines

xen/arch/x86/boot/head.S print_err: · line 182

Quoted 5 lines
xen/arch/x86/boot/head.S +5 -0
+        je      .Lefi_multiboot2_proto
+
+        /* Jump to not_multiboot after switching CPU to x86_32 mode. */
+        lea     not_multiboot(%rip),%edi
+        jmp     x86_32_switch

Does the boot loader, btw, make any guarantees towards placing the image below 4G?

Yep.

[...]

Quoted 18 lines

xen/arch/x86/boot/head.S print_err: · line 277

Quoted 3 lines
xen/arch/x86/boot/head.S +3 -0
+        /*
+         * IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable.
+         * OUT: %rax - Highest available memory address below 1 MiB.

Please be more precise, as "available" leaves open how much space is actually available there, and hence what this can be used for. Also according to ...

xen/arch/x86/boot/head.S print_err: · line 287

Quoted 9 lines
xen/arch/x86/boot/head.S +9 -0
+         * MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag is not provided
+         * on EFI platforms. Hence, it could not be used like
+         * on legacy BIOS platforms.
+         */
+        call    efi_multiboot2
+
+        /* Convert memory address to bytes/16 and store it in safe place. */
+        shr     $4,%eax
+        mov     %eax,%ecx
Quoted 1 line

... the output really is in %eax.

efi_multiboot2() is called according to System V AMD64 ABI. So, according to it return value is stored in %rax. Hence, from spec point of view comment is correct. Use of %eax is a bit different thing (our need/choice) and if you wish it can be documented accordingly.

Quoted 14 lines
Quoted 14 lines
xen/arch/x86/boot/head.S +8 -1
@@ -223,14 +425,22 @@ trampoline_setup:
         call    reloc
         mov     %eax,sym_phys(multiboot_ptr)
 
-        /* Initialize BSS (no nasty surprises!) */
+        /*
+         * Do not zero BSS on EFI platform here.
+         * It was initialized earlier.
+         */
+        cmpb    $0,sym_phys(skip_realmode)
+        jnz     1f
+
+        /* Initialize BSS (no nasty surprises!). */
         mov     $sym_phys(__bss_start),%edi
Quoted 8 lines

xen/arch/x86/boot/head.S trampoline_setup: · line 441

Quoted 6 lines
xen/arch/x86/boot/head.S +1 -1
         mov     $sym_phys(__bss_end),%ecx
         sub     %edi,%ecx
-        xor     %eax,%eax
         shr     $2,%ecx
+        xor     %eax,%eax
         rep stosl

Please avoid pointless code movement like this.

I think that shr should be close to sub because both operations are related to some extent. However, you are right that maybe this cleanup should be in separate patch. Does it make sense for you?

Quoted 30 lines
Quoted 30 lines
xen/arch/x86/efi/efi-boot.h +30 -0
+paddr_t __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
+    UINTN cols, gop_mode = ~0, rows;
+
+    __set_bit(EFI_BOOT, &efi_flags);
+    __set_bit(EFI_RS, &efi_flags);
+
+    efi_init(ImageHandle, SystemTable);
+
+    efi_console_set_mode();
+
+    if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
+                           &cols, &rows) == EFI_SUCCESS )
+        efi_arch_console_init(cols, rows);
+
+    gop = efi_get_gop();
+
+    if ( gop )
+        gop_mode = efi_find_gop_mode(gop, 0, 0, 0);
+
+    efi_arch_edd();
+    efi_arch_cpu();
+
+    efi_tables();
+    setup_efi_pci();
+    efi_variables();
+
+    if ( gop )
+        efi_set_gop_mode(gop, gop_mode);
Quoted 8 lines

xen/arch/x86/efi/efi-boot.h static bool_t __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) · line 726

Quoted 5 lines
xen/arch/x86/efi/efi-boot.h +5 -0
+
+    efi_exit_boot(ImageHandle, SystemTable);
+
+    /* Return highest available memory address below 1 MiB. */
+    return cfg.addr;

Where is it being made certain that there are 64k of space available right below this address, as is being assumed at trampoline_setup?

You are right. This is a bug. However, the problem is more generic and should be fixed for all boot cases (BIOS, EFI loader and EFI with GRUB2). Additionally, in case of BIOS and EFI with GRUB2 we should check that it is possible to put all data from grub loader in low memory. So, it looks that there is a place for at least two (three?) additional patches. Do you want them at the beginning of or the end of this patch series.

Quoted 23 lines
Quoted 23 lines
xen/arch/x86/efi/stub.c +17 -0
@@ -3,6 +3,30 @@
 #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>
+
+paddr_t __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    CHAR16 *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. */
+    asm volatile(
+    "    call %2                      \n"
Quoted 8 lines

xen/arch/x86/efi/stub.c line 26

Quoted 4 lines
xen/arch/x86/efi/stub.c +4 -0
+    "0:  hlt                          \n"
+    "    jmp  0b                      \n"
+       : "+c" (StdErr), "+d" (err) : "g" (StdErr->OutputString)
+       : "rax", "r8", "r9", "r10", "r11", "cc", "memory");

There are explanations missing here: First, a warning should be added alongside the EFI header inclusions, making clear that no services whatsoever can be called. And then the asm() here needs to explain

I am not convinced but if you wish...

Quoted 1 line

that it open codes an MS-ABI function call. Which then makes me

OK.

Quoted 2 lines

wonder (even if it doesn't matter much) - are the clobbers actually correct? I think you also need to clobber rsi and rdi. Otoh there's no

Nope, MS-ABI says that %rsi and %rdi must be saved and restored by function which uses them. So, we do not need list both registers in clobbers here.

Quoted 1 line

need for an explicit "cc" clobber on x86.

Why?

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#51 lore raw

Re: [PATCH v5 14/16] x86/boot: implement early command line parser in C

In reply to Jan Beulich
Quoted 21 lines · Jan Beulich

xen/arch/x86/boot/cmdline.c line 46

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/boot/cmdline.c new file +10 -0
+#define NULL	((void *)0)
+
+#define __packed	__attribute__((__packed__))
+#define __stdcall	__attribute__((__stdcall__))
+
+#define max(x,y) ({ \
+        const typeof(x) _x = (x);       \
+        const typeof(y) _y = (y);       \
+        (void) (&_x == &_y);            \
+        _x > _y ? _x : _y; })

Now that you add a second instance of (some of) these, please move them to a new (local to this directory) header, e.g. defs.h.

xen/arch/x86/boot/cmdline.c line 50

Quoted 3 lines
xen/arch/x86/boot/cmdline.c new file +3 -0
+#define tolower(c) ((c) | 0x20)
+
+typedef unsigned char bool_t;

_Bool and bool please and ...

Quoted 10 lines

xen/arch/x86/boot/cmdline.c line 56

Quoted 6 lines
xen/arch/x86/boot/cmdline.c new file +6 -0
+typedef unsigned char u8;
+typedef unsigned short u16;
+typedef unsigned int size_t;
+
+#define FALSE		0
+#define TRUE		1

... these replaced by true and false. In fact I see no reason why you couldn't include xen/stdbool.h here now that it can be more generally used.

Maybe we should include xen/stdbool.h in defs.h and move to it (defs.h) all macros, types definitions, etc. from reloc.c and cmdline.c. This way we can share more stuff without duplicating it in both files. Does it make sense?

Quoted 10 lines

xen/arch/x86/boot/cmdline.c line 78

Quoted 7 lines
xen/arch/x86/boot/cmdline.c new file +7 -0
+/*
+ * Space and TAB are obvious delimiters. However, I am
+ * adding "\n" and "\r" here too. Just in case when
+ * crazy bootloader/user puts them somewhere.
+ */
+static const char delim_chars_comma[] = ", \n\r\t";
+static const char delim_chars[] = " \n\r\t";

I realize it's minor, but why two arrays instead of

Quoted 3 lines

#define delim_chars (delim_chars_comma + 1)

?

I can try it.

Quoted 11 lines
Quoted 10 lines

+/*
+ * static const char *delim_chars = &delim_chars_comma[1];
+ *
+ * Older compilers, e.g. gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21),
+ * put &delim_chars_comma[1] directly into *delim_chars. This means that the address
+ * in *delim_chars is not properly updated during runtime. Newer compilers are much
+ * smarter and build fully relocatable code even if above shown construct is used.
+ * However, define delim_chars[] separately to properly build Xen code on
+ * older systems.
+ */

Quoted 2 lines

I have to admit that I don't really understand what you want to say with this comment.

I tried to use following thing suggested by you earlier:
static const char *delim_chars = &delim_chars_comma[1];

Sadly, it does not work because after building/linking by older GCC/linker delim_chars contains static address and cannot be properly relocated during runtime. Newer GCC/linkers are much smarter and all references to delim_chars and finally to &delim_chars_comma[1] are properly relocated during runtime. However, there is a chance that your approach with #define will work with all supported build environments.

Quoted 31 lines
Quoted 31 lines
xen/arch/x86/boot/cmdline.c new file +31 -0
+static unsigned int strtoui(const char *s, const char *stop, const char **next)
+{
+    char l;
+    unsigned int base = 10, ores = 0, res = 0;
+
+    if ( *s == '0' )
+      base = (tolower(*++s) == 'x') ? (++s, 16) : 8;
+
+    for ( ; *s != '\0'; ++s )
+    {
+        if ( stop && strchr(stop, *s) )
+            goto out;
+
+        if ( *s < '0' || (*s > '7' && base == 8) )
+        {
+            res = UINT_MAX;
+            goto out;
+        }
+
+        l = tolower(*s);
+
+        if ( *s > '9' && (base != 16 || l < 'a' || l > 'f') )
+        {
+            res = UINT_MAX;
+            goto out;
+        }
+
+        res *= base;
+        res += (l >= 'a') ? (l - 'a' + 10) : (*s - '0');
+
+        if ( ores > res )
Quoted 8 lines

xen/arch/x86/boot/cmdline.c line 180

Quoted 4 lines
xen/arch/x86/boot/cmdline.c new file +4 -0
+        {
+            res = UINT_MAX;
+            goto out;
+        }

Without having spent time to try and find an example, it feels like this check won't catch all possible overflow conditions. If you care about overflow, please make sure you catch all cases.

Hmmm.... How come? Could you give an example?

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#33 lore raw

Re: [PATCH v5 10/16] efi: create efi_enabled()

In reply to Daniel Kiper
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 19:19, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/efi/stub.c +0 -0
@@ -4,9 +4,10 @@
 #include <xen/lib.h>
 #include <asm/page.h>
 
Quoted 9 lines

xen/arch/x86/efi/stub.c line 10

Quoted 7 lines
xen/arch/x86/efi/stub.c +4 -3
-#ifndef efi_enabled
-const bool_t efi_enabled = 0;
-#endif
+bool_t efi_enabled(int feature)
+{
+    return false;
+}

Plain bool please, the more that you use false. And I'm relatively

Quoted 1 line

What is wrong with bool_t? bool is equal to bool_t.

With the (recent) introduction of bool we want to switch away from bool_t.

Quoted 8 lines
Quoted 2 lines

certain I did ask for the parameter type to be unsigned int, as you don't mean to pass negative values.

Sure. However, full blown efi_enabled() calls test_bit(). Latter calls constant_test_bit() or variable_test_bit() which take bit position as int. So, I do not think that efi_enabled() should take unsigned int. Or we should change constant_test_bit() and variable_test_bit() respectively. Hmmm... No, we should not. It looks that negative offsets are valid.

But in the context here you mean an unsigned value, so you should use an unsigned type. Feel free to ASSERT(... <= INT_MAX) if you really care.

Quoted 12 lines
Quoted 11 lines

xen/arch/x86/efi/stub.c void __init noreturn __start_xen(unsigned long mbi_p) · line 745

Quoted 9 lines
xen/arch/x86/efi/stub.c +3 -1
@@ -739,8 +739,10 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         l3_bootmap[l3_table_offset(BOOTSTRAP_MAP_BASE)] =
             l3e_from_paddr(__pa(l2_bootmap), __PAGE_HYPERVISOR);
 
-        memmap_type = loader;
+        memmap_type = "EFI";
     }
+    else if ( efi_enabled(EFI_BOOT) )
+        memmap_type = "EFI";

Is the change ahead of the "else" really necessary?

Quoted 4 lines

No. However, in this case memmap_type is always "EFI" and we do not need to get this value from loader variable. Which, of course, is always also "EFI" (to be precise pointer to) here but IMO "memmap_type = loader" suggests that memmap_type could be anything else.

Well - it's been okay so far, so I see no reason to change it, unless you want to do this in a separate patch with an acceptable explanation.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#45 lore raw

Re: [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms

In reply to Daniel Kiper
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 21:32, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/boot/head.S +8 -1
@@ -223,14 +425,22 @@ trampoline_setup:
         call    reloc
         mov     %eax,sym_phys(multiboot_ptr)
 
-        /* Initialize BSS (no nasty surprises!) */
+        /*
+         * Do not zero BSS on EFI platform here.
+         * It was initialized earlier.
+         */
+        cmpb    $0,sym_phys(skip_realmode)
+        jnz     1f
+
+        /* Initialize BSS (no nasty surprises!). */
         mov     $sym_phys(__bss_start),%edi
Quoted 8 lines

xen/arch/x86/boot/head.S trampoline_setup: · line 441

Quoted 6 lines
xen/arch/x86/boot/head.S +1 -1
         mov     $sym_phys(__bss_end),%ecx
         sub     %edi,%ecx
-        xor     %eax,%eax
         shr     $2,%ecx
+        xor     %eax,%eax
         rep stosl

Please avoid pointless code movement like this.

Quoted 3 lines

I think that shr should be close to sub because both operations are related to some extent. However, you are right that maybe this cleanup should be in separate patch. Does it make sense for you?

Separating dependent instructions by other unrelated ones can actually improve performance. I agree that performance isn't of much relevance here, but I think I still wouldn't agree to a change like this even if submitted separately.

Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
xen/arch/x86/efi/efi-boot.h +30 -0
+paddr_t __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
+    UINTN cols, gop_mode = ~0, rows;
+
+    __set_bit(EFI_BOOT, &efi_flags);
+    __set_bit(EFI_RS, &efi_flags);
+
+    efi_init(ImageHandle, SystemTable);
+
+    efi_console_set_mode();
+
+    if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
+                           &cols, &rows) == EFI_SUCCESS )
+        efi_arch_console_init(cols, rows);
+
+    gop = efi_get_gop();
+
+    if ( gop )
+        gop_mode = efi_find_gop_mode(gop, 0, 0, 0);
+
+    efi_arch_edd();
+    efi_arch_cpu();
+
+    efi_tables();
+    setup_efi_pci();
+    efi_variables();
+
+    if ( gop )
+        efi_set_gop_mode(gop, gop_mode);
Quoted 8 lines

xen/arch/x86/efi/efi-boot.h static bool_t __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) · line 726

Quoted 5 lines
xen/arch/x86/efi/efi-boot.h +5 -0
+
+    efi_exit_boot(ImageHandle, SystemTable);
+
+    /* Return highest available memory address below 1 MiB. */
+    return cfg.addr;

Where is it being made certain that there are 64k of space available right below this address, as is being assumed at trampoline_setup?

Quoted 7 lines

You are right. This is a bug. However, the problem is more generic and should be fixed for all boot cases (BIOS, EFI loader and EFI with GRUB2). Additionally, in case of BIOS and EFI with GRUB2 we should check that it is possible to put all data from grub loader in low memory. So, it looks that there is a place for at least two (three?) additional patches. Do you want them at the beginning of or the end of this patch series.

If you think there are bugs in pre-existing code, then for having the option of backporting putting such patches at the beginning would be desirable. That said, I'm not convinced there are problems really in need of fixing here (yet the grub environment is different and hence will need taking care of even if we leave the other code paths as they are now).

Quoted 32 lines
Quoted 23 lines
Quoted 23 lines
xen/arch/x86/efi/stub.c +17 -0
@@ -3,6 +3,30 @@
 #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>
+
+paddr_t __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    CHAR16 *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. */
+    asm volatile(
+    "    call %2                      \n"
Quoted 8 lines

xen/arch/x86/efi/stub.c line 26

Quoted 4 lines
xen/arch/x86/efi/stub.c +4 -0
+    "0:  hlt                          \n"
+    "    jmp  0b                      \n"
+       : "+c" (StdErr), "+d" (err) : "g" (StdErr->OutputString)
+       : "rax", "r8", "r9", "r10", "r11", "cc", "memory");

There are explanations missing here: First, a warning should be added alongside the EFI header inclusions, making clear that no services whatsoever can be called. And then the asm() here needs to explain

Quoted 1 line

I am not convinced but if you wish...

Not convinced of what?

Quoted 10 lines
Quoted 1 line

that it open codes an MS-ABI function call. Which then makes me

OK.

Quoted 2 lines

wonder (even if it doesn't matter much) - are the clobbers actually correct? I think you also need to clobber rsi and rdi. Otoh there's no

Nope, MS-ABI says that %rsi and %rdi must be saved and restored by function which uses them. So, we do not need list both registers in clobbers here.

Oh, right, I manage to mix up calling conventions.

Quoted 3 lines
Quoted 1 line

need for an explicit "cc" clobber on x86.

Why?

Because such a clobber gets added to every asm() by the compiler, unless it uses the (new in gcc 6) flag output. I've actually suggested to upstream a patch making it possible to avoid that automatic addition, but there hadn't been a whole lot of useful feedback.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#52 lore raw

Re: [PATCH v5 14/16] x86/boot: implement early command line parser in C

In reply to Daniel Kiper
Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 21:58, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich

xen/arch/x86/boot/cmdline.c line 46

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/boot/cmdline.c new file +10 -0
+#define NULL	((void *)0)
+
+#define __packed	__attribute__((__packed__))
+#define __stdcall	__attribute__((__stdcall__))
+
+#define max(x,y) ({ \
+        const typeof(x) _x = (x);       \
+        const typeof(y) _y = (y);       \
+        (void) (&_x == &_y);            \
+        _x > _y ? _x : _y; })

Now that you add a second instance of (some of) these, please move them to a new (local to this directory) header, e.g. defs.h.

xen/arch/x86/boot/cmdline.c line 50

Quoted 3 lines
xen/arch/x86/boot/cmdline.c new file +3 -0
+#define tolower(c) ((c) | 0x20)
+
+typedef unsigned char bool_t;

_Bool and bool please and ...

Quoted 10 lines

xen/arch/x86/boot/cmdline.c line 56

Quoted 6 lines
xen/arch/x86/boot/cmdline.c new file +6 -0
+typedef unsigned char u8;
+typedef unsigned short u16;
+typedef unsigned int size_t;
+
+#define FALSE		0
+#define TRUE		1

... these replaced by true and false. In fact I see no reason why you couldn't include xen/stdbool.h here now that it can be more generally used.

Quoted 4 lines

Maybe we should include xen/stdbool.h in defs.h and move to it (defs.h) all macros, types definitions, etc. from reloc.c and cmdline.c. This way we can share more stuff without duplicating it in both files. Does it make sense?

Well, that's what I did suggest in the very first comment still visible in context above.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

+/*
+ * static const char *delim_chars = &delim_chars_comma[1];
+ *
+ * Older compilers, e.g. gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21),
+ * put &delim_chars_comma[1] directly into *delim_chars. This means that the address
+ * in *delim_chars is not properly updated during runtime. Newer compilers are much
+ * smarter and build fully relocatable code even if above shown construct is used.
+ * However, define delim_chars[] separately to properly build Xen code on
+ * older systems.
+ */

Quoted 5 lines
Quoted 2 lines

I have to admit that I don't really understand what you want to say with this comment.

I tried to use following thing suggested by you earlier:
static const char *delim_chars = &delim_chars_comma[1];

I've never suggested anything like that. All I suggested is the #define approach you've now said you'd give a try.

Quoted 40 lines
Quoted 31 lines
Quoted 31 lines
xen/arch/x86/boot/cmdline.c new file +31 -0
+static unsigned int strtoui(const char *s, const char *stop, const char **next)
+{
+    char l;
+    unsigned int base = 10, ores = 0, res = 0;
+
+    if ( *s == '0' )
+      base = (tolower(*++s) == 'x') ? (++s, 16) : 8;
+
+    for ( ; *s != '\0'; ++s )
+    {
+        if ( stop && strchr(stop, *s) )
+            goto out;
+
+        if ( *s < '0' || (*s > '7' && base == 8) )
+        {
+            res = UINT_MAX;
+            goto out;
+        }
+
+        l = tolower(*s);
+
+        if ( *s > '9' && (base != 16 || l < 'a' || l > 'f') )
+        {
+            res = UINT_MAX;
+            goto out;
+        }
+
+        res *= base;
+        res += (l >= 'a') ? (l - 'a' + 10) : (*s - '0');
+
+        if ( ores > res )
Quoted 8 lines

xen/arch/x86/boot/cmdline.c line 180

Quoted 4 lines
xen/arch/x86/boot/cmdline.c new file +4 -0
+        {
+            res = UINT_MAX;
+            goto out;
+        }

Without having spent time to try and find an example, it feels like this check won't catch all possible overflow conditions. If you care about overflow, please make sure you catch all cases.

Quoted 1 line

Hmmm.... How come? Could you give an example?

Excuse me, but shouldn't you instead demonstrate the logic is correct? Or - consider what I had said - try to find an example yourself? It's not that difficult: With 16-bit word size 0x3333 * 10 = 0x1fffe, which truncates to 0xfffe and is hence larger than both inputs but still produced an overflow. This easily extends to 32- and 64-bit word size.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#58 lore raw

Re: [PATCH v5 15/16] x86: make Xen early boot code relocatable

In reply to Jan Beulich
Quoted 22 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Every multiboot protocol (regardless of version) compatible image must specify its load address (in ELF or multiboot header). Multiboot protocol compatible loader have to load image at specified address. However, there is no guarantee that the requested memory region (in case of Xen it starts at 1 MiB and ends at 17 MiB) where image should be loaded initially is a RAM and it is free (legacy BIOS platforms are merciful for Xen but I found at least one EFI platform on which Xen load address conflicts with EFI boot services; it is Dell PowerEdge R820 with latest firmware). To cope with that problem we must make Xen early boot code relocatable 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.

Quoted 6 lines

This patch changes following things:
- default load address is changed from 1 MiB to 2 MiB; I did that because initial page tables are using 2 MiB huge pages and this way required updates for them are quite easy; it means that e.g. we avoid spacial cases for start and end of required memory region if it live at address not aligned to 2 MiB,

Quoted 2 lines

Should this be a separate change then, to separate possible regressions due to that from such due to any other of the changes

Potentially yes. However, it should be done properly. Otherwise in case of revert we can break Xen relocatable infrastructure and other things. So, I am not sure does it pays. Anyway, I will check is it possible or not.

Quoted 2 lines

here? And then I don't see why, when making the image relocatable anyway, the link time load address actually still matters.

It matters for multiboot (v1) and multiboot2 compatible boot loaders not supporting relocatable images.

Quoted 8 lines
Quoted 4 lines

- %esi and %r15d registers are used as a storage for Xen image load base address (%r15d shortly because %rsi is used for EFI SystemTable address in 64-bit code); both registers are (%esi is mostly) unused in early boot code and preserved during C functions calls,

In a context where you (also) talk about 64-bit code, %esi can't be called preserved unilaterally. You should make clear that this is for 32-bit function calls.

OK.

Quoted 11 lines

xen/arch/x86/boot/head.S line 15

Quoted 8 lines
xen/arch/x86/boot/head.S +1 -1
@@ -12,13 +12,16 @@
         .text
         .code32
 
-#define sym_phys(sym)     ((sym) - __XEN_VIRT_START)
+#define sym_offset(sym)   ((sym) - __XEN_VIRT_START)

In a patch already large and hence hard to review, did you really need to do this rename?

I think that sym_offset() is better term here. However, if you wish I can leave sym_phys() as is. Though, IMO, sym_phys() name suggests that we are playing with physical addresses and it is not correct in all contexts, e.g. loot at fs_offset() (or sym_fs() as you wish).

Quoted 10 lines

xen/arch/x86/boot/head.S vga_text_buffer: · line 133

Quoted 6 lines
xen/arch/x86/boot/head.S +1 -1
@@ -126,26 +130,26 @@ vga_text_buffer:
         .section .init.text, "ax", @progbits
 
 bad_cpu:
-        mov     $(sym_phys(.Lbad_cpu_msg)),%esi # Error message
+        lea     esi_offset(.Lbad_cpu_msg),%esi  # Error message

Why not just

add $sym_offset(.Lbad_cpu_msg),%esi # Error message

OK.

[...]

Quoted 12 lines
Quoted 12 lines
xen/arch/x86/boot/head.S +6 -2
@@ -461,62 +545,88 @@ trampoline_setup:
 
         /* Stash TSC to calculate a good approximation of time-since-boot */
         rdtsc
-        mov     %eax,sym_phys(boot_tsc_stamp)
-        mov     %edx,sym_phys(boot_tsc_stamp+4)
+        mov     %eax,fs_offset(boot_tsc_stamp)
+        mov     %edx,fs_offset(boot_tsc_stamp)+4
+
+        /* Update frame addresses in page tables. */
+        mov     $((__page_tables_end-__page_tables_start)/8),%ecx
+1:      testl   $_PAGE_PRESENT,fs_offset(__page_tables_start)-8(,%ecx,8)
Quoted 8 lines

xen/arch/x86/boot/head.S trampoline_setup: · line 556

Quoted 3 lines
xen/arch/x86/boot/head.S +3 -0
+        jz      2f
+        add     %esi,fs_offset(__page_tables_start)-8(,%ecx,8)
+2:      loop    1b

This loop includes the mapping of the low Mb, which I don't think it should modify. Or wait - you move __page_tables_start, which by itself is fragile (but looks to be acceptable if accompanied by a comment explaining why it doesn't cover l1_identmap).

OK, I will add relevant comment somewhere.

Quoted 2 lines

Also, just to double check - all these page table setup adjustments don't require reflecting in xen.efi's page table setup code?

I will check it once again but I do not think so.

[...]

Quoted 5 lines
Quoted 5 lines
xen/arch/x86/boot/trampoline.S +0 -0
@@ -54,12 +54,20 @@ trampoline_gdt:
         /* 0x0028: real-mode data @ BOOT_TRAMPOLINE */
         .long   0x0000ffff
Quoted 8 lines

xen/arch/x86/boot/trampoline.S trampoline_gdt: · line 61

Quoted 6 lines
xen/arch/x86/boot/trampoline.S +5 -0
         .long   0x00009200
+        /*
+         * 0x0030: ring 0 Xen data, 16 MiB size, base
+         * address is computed during runtime.
+         */
+        .quad   0x00c0920000001000

This does not look like it covers 1Mb, it's more like 1Mb+4k-1.

I have checked it once again. It covers 16 MiB as required:
4 KiB * 0x1000 = 0x1000000 (no taking into account relocation).

By the way, it looks that we can define this segment as 0x200000 - 0x1000000. However, then sym_fs() should be defined as:

#define sym_fs(sym) %fs:(sym_offset(sym) - XEN_IMG_OFFSET)

Does it make sense?

Quoted 11 lines

xen/arch/x86/boot/trampoline.S trampoline_gdt: · line 69

Quoted 7 lines
xen/arch/x86/boot/trampoline.S +2 -0
         .pushsection .trampoline_rel, "a"
         .long   trampoline_gdt + BOOT_PSEUDORM_CS + 2 - .
         .long   trampoline_gdt + BOOT_PSEUDORM_DS + 2 - .
         .popsection
 
+GLOBAL(xen_img_load_base_addr)
+        .long   0

I've yet to understand the purpose of this symbol, but in any case:
If the trampoline code doesn't reference it, why does it get placed here?

This symbol was used by code which unconditionally relocated Xen image even if boot loader did work for us. I removed most of this code because we agreed that if boot loader relocated Xen image then we do not have to relocate it higher once again. If you are still OK with this idea I can go further, as I planned, and remove all such remnants from next release. However, it looks that then I have to store load address in xen_phys_start from 32-bit assembly code. So, it will be nice if I can define it as "unsigned int" instead of "unsigned long". Is it safe? I am asking because this variable is used in quite important places and I do not want to break something by mistake. At first sight it looks that it is safe but it will be nice if you double check it.

Quoted 11 lines

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 865

Quoted 7 lines
xen/arch/x86/boot/trampoline.S +3 -0
@@ -861,15 +860,17 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         highmem_start &= ~((1UL << L3_PAGETABLE_SHIFT) - 1);
 #endif
 
+    /* Do not relocate Xen image if boot loader did work for us. */
+    if ( xen_img_load_base_addr )
+        xen_phys_start = xen_img_load_base_addr;

Okay, with this change the question really is: Why do you need the new symbol? I.e. why can't you just use xen_phys_start, just like I managed to re-use it when I introduced boot from EFI?

This is what I was going to do in next release... If... Please look above...

Quoted 9 lines

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 869

Quoted 6 lines
xen/arch/x86/boot/trampoline.S +0 -1
     for ( i = boot_e820.nr_map-1; i >= 0; i-- )
     {
         uint64_t s, e, mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
         uint64_t end, limit = ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SHIFT;
 
-        /* Superpage-aligned chunks from BOOTSTRAP_MAP_BASE. */

I can see that you want to get rid of BOOTSTRAP_MAP_BASE, but please don't delete the comment as a whole.

OK.

Quoted 8 lines

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 874

Quoted 5 lines
xen/arch/x86/boot/trampoline.S +0 -1
         s = (boot_e820.map[i].addr + mask) & ~mask;
         e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
-        s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
         if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
             continue;

This means you now map memory between 2Mb and 16Mb here. Is this necessary?

Without this change Xen relocated by boot loader crashes with:

(XEN) Panic on CPU 0:
(XEN) Assertion 'l2e_get_flags(l2e) & _PAGE_PRESENT' failed at x86_64/mm.c:902

So, it must be mapped. However, maybe we should not map this region when Xen is not relocated by boot loader.

Quoted 7 lines
Quoted 7 lines
xen/arch/x86/boot/trampoline.S +0 -1
@@ -901,7 +902,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;
 
Quoted 13 lines

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 919

Quoted 9 lines
xen/arch/x86/boot/trampoline.S +1 -2
             /* Select relocation address. */
@@ -915,9 +915,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);

Assuming _start - XEN_VIRT_START == XEN_IMG_OFFSET, is this change necessary? Or is it rather just simplification, which again should be split from an already complex patch.

Just simplification. I will split it from this patch.

Quoted 8 lines

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 961

Quoted 6 lines
xen/arch/x86/boot/trampoline.S +0 -2
@@ -957,15 +956,14 @@ 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) ==
-                   l2_table_offset((unsigned long)_stext));

At least when using_2M_mapping() this surely ought to hold?

OK.

Quoted 9 lines

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 1021

Quoted 6 lines
xen/arch/x86/boot/trampoline.S +2 -0
@@ -1019,6 +1017,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                 : "memory" );
 
             bootstrap_map(NULL);
+
+            printk("New Xen image base address: 0x%08lx\n", xen_phys_start);

I don't see the motivation for adding such a message in this patch, but if, then please use %#lx.

OK, I will use %#lx.

Quoted 8 lines

xen/arch/x86/boot/trampoline.S void __init noreturn __start_xen(unsigned long mbi_p) · line 1086

Quoted 6 lines
xen/arch/x86/boot/trampoline.S +1 -0
@@ -1082,6 +1082,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, __pa(&_start), __pa(&_end));

Another stray change.

I will fix it.

Quoted 18 lines
Quoted 18 lines
xen/arch/x86/xen.lds.S +2 -2
@@ -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 */
@@ -257,12 +257,14 @@ SECTIONS
   .reloc : {
     *(.reloc)
   } :text
-  /* Trick the linker into setting the image size to exactly 16Mb. */
   . = ALIGN(__section_alignment__);
+#endif
Quoted 8 lines

xen/arch/x86/xen.lds.S SECTIONS · line 266

Quoted 5 lines
xen/arch/x86/xen.lds.S +3 -0
+
+  /* Trick the linker into setting the image size to exactly 16Mb. */
   .pad : {
     . = ALIGN(MB(16));
+    __end_of_image__ = .;

I see that you use this symbol in xen/arch/x86/Makefile, but I again don't follow why this logic needs to change.

Current logic does not work because it gets wrong address from xen/xen-syms. This way boot loader allocates incorrect, usually huge, buffer for Xen image (wait, there is a chance that this is a fix for issues related to 2 MiB mappings found by Andrew). I do not see simple reliable fix for current solution. So, I introduced __end_of_image__ and look for its address. This is much better method to establish end of image address then previous one. However, I can agree that this could be introduced in separate patch.

Quoted 4 lines
Quoted 4 lines
xen/include/asm-x86/page.h +0 -0
@@ -288,7 +288,7 @@ extern root_pgentry_t
 idle_pg_table[ROOT_PAGETABLE_ENTRIES];
Quoted 8 lines

xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 291

Quoted 5 lines
xen/include/asm-x86/page.h +1 -1
 extern l2_pgentry_t  *compat_idle_pg_table_l2;
 extern unsigned int   m2p_compat_vstart;
 extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES],
-    l2_bootmap[L2_PAGETABLE_ENTRIES];
+    l2_bootmap[4*L2_PAGETABLE_ENTRIES];

Why do you need 4 of them? I can see why one might not suffice, but two surely should?

In worst case we need three. One for l1_identmap hook and two for Xen image mapping. So, I am not sure that it pays to complicate assembly mapping code just to save just 1 page. Additionally, you should remember that l2_bootmap is freed after init.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#69 lore raw
In reply to Jan Beulich
Quoted 25 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 16:15, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

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.

Quoted 4 lines

Just in case you aren't aware: The partial revert done by 0b8a172444 ("x86: partially revert use of 2M mappings for hypervisor image") now puts us a step further away from that goal, compared to when you had started your work.

Quoted 5 lines

I am not sure about that. Andrew patches changed xen.gz size significantly. My patches does not do that in significant way. They (precisely it) just move load address from 1 MiB to 2 MiB. So, I do not expect major issues here. However, anyway it should be tested (and it was tested, IIRC, by Konrad some time ago).

Quoted 5 lines

Looks like you didn't understand: This is not about image size. The issue is that the EFI binary, other than xen.gz, now properly uses RX, RO, and RW permissions (and large pages) for the individual pieces of the image. Moving to a single binary would hence result in a (slight) regression unless that gets taken care of beforehand.

OK. However, there is chance that it is quite easy to fix. Please look at my comments for patch #15. Especially regarding _end_of_image__ symbol.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#16 lore raw

Re: [PATCH v5 06/16] x86/boot/reloc: create generic alloc and copy functions

In reply to Jan Beulich
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 16:32, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Create generic alloc and copy functions. We need
separate tools for memory allocation and copy to
provide multiboot2 protocol support.

The amount of casting in this patch alone looks very reasonable now. Before ack-ing this and respective subsequent patches I'd like to see the final result though. To facilitate that I have to re-raise a previously asked question: Do you have a tree somewhere which one could use to look at the final result?

Quoted 3 lines
Quoted 1 line

Sadly no.

Alternatively, could you simply send the final resulting source file?

Please look below...

Daniel

/*
* reloc.c
*
* 32-bit flat memory-map routines for relocating Multiboot structures
* and modules. This is most easily done early with paging disabled. *
* Copyright (c) 2009, Citrix Systems, Inc.
*
* Authors:
* Keir Fraser <[email protected]>
*/

/*
* This entry point is entered from xen/arch/x86/boot/head.S with:
* - 0x4(%esp) = MULTIBOOT_INFORMATION_ADDRESS,
* - 0x8(%esp) = BOOT_TRAMPOLINE_ADDRESS.
*/
asm (

    "    .text                         \n"
    "    .globl _start                 \n"
    "_start:                           \n"
    "    jmp  reloc                    \n"
    );

typedef unsigned int u32;
#include "../../../include/xen/multiboot.h"

#define __stdcall __attribute__((__stdcall__))

#define ALIGN_UP(arg, align) \
                (((arg) + (align) - 1) & ~((typeof(arg))(align) - 1))

static u32 alloc;

static u32 alloc_mem(u32 bytes)

{
    return alloc -= ALIGN_UP(bytes, 16);
}

static u32 copy_mem(u32 src, u32 bytes)

{
    u32 dst, dst_ret;

    dst = alloc_mem(bytes);
    dst_ret = dst;

    while ( bytes-- )
        *(char *)dst++ = *(char *)src++;

    return dst_ret;
}

static u32 copy_string(u32 src)

{
    u32 p;

    if ( src == 0 )
        return 0;

    for ( p = src; *(char *)p != '\0'; p++ )
        continue;

    return copy_mem(src, p - src + 1);
}

multiboot_info_t __stdcall *reloc(u32 mbi_old, u32 trampoline)

{
    multiboot_info_t *mbi;
    int i;

    alloc = trampoline;

    mbi = (multiboot_info_t *)copy_mem(mbi_old, sizeof(*mbi));

    if ( mbi->flags & MBI_CMDLINE )
        mbi->cmdline = copy_string(mbi->cmdline);

    if ( mbi->flags & MBI_MODULES )
    {
        module_t *mods;

        mbi->mods_addr = copy_mem(mbi->mods_addr, mbi->mods_count * sizeof(module_t));

        mods = (module_t *)mbi->mods_addr;

        for ( i = 0; i < mbi->mods_count; i++ )
        {
            if ( mods[i].string )
                mods[i].string = copy_string(mods[i].string);
        }
    }

    if ( mbi->flags & MBI_MEMMAP )
        mbi->mmap_addr = copy_mem(mbi->mmap_addr, mbi->mmap_length);

    if ( mbi->flags & MBI_LOADERNAME )
        mbi->boot_loader_name = copy_string(mbi->boot_loader_name);

    /* Mask features we don't understand or don't relocate. */
    mbi->flags &= (MBI_MEMLIMITS |
                   MBI_CMDLINE |
                   MBI_MODULES |
                   MBI_MEMMAP |
                   MBI_LOADERNAME);

    return mbi;
}

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#27 lore raw

Re: [PATCH v5 09/16] x86: add multiboot2 protocol support

In reply to Jan Beulich
Quoted 29 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 16:41, <[email protected]> wrote:
Quoted 26 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/boot/reloc.c +12 -0
+        case MULTIBOOT2_TAG_TYPE_MMAP:
+            if ( get_mb2_data(tag, mmap, entry_size) < sizeof(*mmap_src) )
+                break;
+
+            mbi_out->flags |= MBI_MEMMAP;
+            mbi_out->mmap_length = get_mb2_data(tag, mmap, size);
+            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);
+            mbi_out->mmap_length /= get_mb2_data(tag, mmap, entry_size);
+            mbi_out->mmap_length *= sizeof(memory_map_t);
+
+            mbi_out->mmap_addr = alloc_mem(mbi_out->mmap_length);
+

xen/arch/x86/boot/reloc.c multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline) · line 206

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+            mmap_src = get_mb2_data(tag, mmap, entries);
+            mmap_dst = (memory_map_t *)mbi_out->mmap_addr;
+
+            for ( i = 0; i < mbi_out->mmap_length / sizeof(memory_map_t); i++ )
+            {
+                /* Init size member properly. */
+                mmap_dst[i].size = sizeof(memory_map_t);
+                mmap_dst[i].size -= sizeof(((memory_map_t){0}).size);
+                /* Now copy a given region data. */
+                mmap_src = (void *)mmap_src + i * get_mb2_data(tag, mmap, entry_size);

Why do you multiply by i here? The way you've written it you want to increment mmap_src by entry_size _at the end_ of each iteration. Or

Quoted 4 lines
Quoted 1 line

This is another option. If you wish I can do that.

This is not just another option - afaict the code as is won't work for more than one map entry.

Ugh... Sorry, you are right. Stupid mistake. I will change this.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#17 lore raw

Re: [PATCH v5 06/16] x86/boot/reloc: create generic alloc and copy functions

In reply to Daniel Kiper
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 17:13, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 16:32, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Create generic alloc and copy functions. We need
separate tools for memory allocation and copy to
provide multiboot2 protocol support.

The amount of casting in this patch alone looks very reasonable now. Before ack-ing this and respective subsequent patches I'd like to see the final result though. To facilitate that I have to re-raise a previously asked question: Do you have a tree somewhere which one could use to look at the final result?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Sadly no.

Alternatively, could you simply send the final resulting source file?

Please look below...

I don't think that was the file at the end of the series, as asked for above? There's no mb2 code in there afaics...

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#59 lore raw

Re: [PATCH v5 15/16] x86: make Xen early boot code relocatable

In reply to Daniel Kiper
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 16:59, <[email protected]> wrote:
Quoted 22 lines · Jan Beulich
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Every multiboot protocol (regardless of version) compatible image must specify its load address (in ELF or multiboot header). Multiboot protocol compatible loader have to load image at specified address. However, there is no guarantee that the requested memory region (in case of Xen it starts at 1 MiB and ends at 17 MiB) where image should be loaded initially is a RAM and it is free (legacy BIOS platforms are merciful for Xen but I found at least one EFI platform on which Xen load address conflicts with EFI boot services; it is Dell PowerEdge R820 with latest firmware). To cope with that problem we must make Xen early boot code relocatable 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:
- default load address is changed from 1 MiB to 2 MiB; I did that because initial page tables are using 2 MiB huge pages and this way required updates for them are quite easy; it means that e.g. we avoid spacial cases for start and end of required memory region if it live at address not aligned to 2 MiB,

Quoted 7 lines
Quoted 2 lines

Should this be a separate change then, to separate possible regressions due to that from such due to any other of the changes

Potentially yes. However, it should be done properly. Otherwise in case of revert we can break Xen relocatable infrastructure and other things. So, I am not sure does it pays. Anyway, I will check is it possible or not.

It's not so much about possibly reverting (we'd rather revert everything if such a need arises) than bisecting.

Quoted 5 lines
Quoted 2 lines

here? And then I don't see why, when making the image relocatable anyway, the link time load address actually still matters.

It matters for multiboot (v1) and multiboot2 compatible boot loaders not supporting relocatable images.

Oh, right.

Quoted 12 lines
Quoted 11 lines

xen/arch/x86/boot/head.S line 15

Quoted 8 lines
xen/arch/x86/boot/head.S +1 -1
@@ -12,13 +12,16 @@
         .text
         .code32
 
-#define sym_phys(sym)     ((sym) - __XEN_VIRT_START)
+#define sym_offset(sym)   ((sym) - __XEN_VIRT_START)

In a patch already large and hence hard to review, did you really need to do this rename?

Quoted 4 lines

I think that sym_offset() is better term here. However, if you wish I can leave sym_phys() as is. Though, IMO, sym_phys() name suggests that we are playing with physical addresses and it is not correct in all contexts, e.g. loot at fs_offset() (or sym_fs() as you wish).

After some more thinking about this I agree sym_phys() isn't ideal anymore after this patch. Still, to avoid unrelated changes in this quite hard to review patch, I'd like to ask that you keep the name here and do just the rename in a subsequent patch.

Quoted 4 lines
Quoted 2 lines

Also, just to double check - all these page table setup adjustments don't require reflecting in xen.efi's page table setup code?

I will check it once again but I do not think so.

Thanks for doing so. You perhaps realize that Andrew said the same for what became 2ce5963727, and then recently we had to fix things.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/boot/trampoline.S +0 -0
@@ -54,12 +54,20 @@ trampoline_gdt:
         /* 0x0028: real-mode data @ BOOT_TRAMPOLINE */
         .long   0x0000ffff
Quoted 8 lines

xen/arch/x86/boot/trampoline.S trampoline_gdt: · line 61

Quoted 6 lines
xen/arch/x86/boot/trampoline.S +5 -0
         .long   0x00009200
+        /*
+         * 0x0030: ring 0 Xen data, 16 MiB size, base
+         * address is computed during runtime.
+         */
+        .quad   0x00c0920000001000

This does not look like it covers 1Mb, it's more like 1Mb+4k-1.

Quoted 2 lines

I have checked it once again. It covers 16 MiB as required:
4 KiB * 0x1000 = 0x1000000 (no taking into account relocation).

I'm sorry, but no. The raw limit value taken from that descriptor is 0x1000, and the G bit is set. That makes the actual limit 0x1000fff.

Quoted 6 lines

By the way, it looks that we can define this segment as 0x200000 - 0x1000000. However, then sym_fs() should be defined as:

#define sym_fs(sym) %fs:(sym_offset(sym) - XEN_IMG_OFFSET)

Does it make sense?

If you feel like it's worth it ...

Quoted 12 lines
Quoted 11 lines

xen/arch/x86/boot/trampoline.S trampoline_gdt: · line 69

Quoted 7 lines
xen/arch/x86/boot/trampoline.S +2 -0
         .pushsection .trampoline_rel, "a"
         .long   trampoline_gdt + BOOT_PSEUDORM_CS + 2 - .
         .long   trampoline_gdt + BOOT_PSEUDORM_DS + 2 - .
         .popsection
 
+GLOBAL(xen_img_load_base_addr)
+        .long   0

I've yet to understand the purpose of this symbol, but in any case:
If the trampoline code doesn't reference it, why does it get placed here?

Quoted 8 lines

This symbol was used by code which unconditionally relocated Xen image even if boot loader did work for us. I removed most of this code because we agreed that if boot loader relocated Xen image then we do not have to relocate it higher once again. If you are still OK with this idea I can go further, as I planned, and remove all such remnants from next release. However, it looks that then I have to store load address in xen_phys_start from 32-bit assembly code. So, it will be nice if I can define it as "unsigned int" instead of "unsigned long". Is it safe?

I don't see why you shouldn't be able to store into the low 32 bits of the variable without altering the high ones (which are all zero).

Quoted 9 lines
Quoted 8 lines

xen/arch/x86/boot/trampoline.S trampoline_gdt:

Quoted 5 lines
xen/arch/x86/boot/trampoline.S +0 -1
         s = (boot_e820.map[i].addr + mask) & ~mask;
         e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
-        s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
         if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
             continue;

This means you now map memory between 2Mb and 16Mb here. Is this necessary?

Quoted 6 lines

Without this change Xen relocated by boot loader crashes with:

(XEN) Panic on CPU 0:
(XEN) Assertion 'l2e_get_flags(l2e) & _PAGE_PRESENT' failed at x86_64/mm.c:902

So, it must be mapped.

That's too little context to be useful for understanding the full background.

Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
xen/arch/x86/xen.lds.S +2 -2
@@ -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 */
@@ -257,12 +257,14 @@ SECTIONS
   .reloc : {
     *(.reloc)
   } :text
-  /* Trick the linker into setting the image size to exactly 16Mb. */
   . = ALIGN(__section_alignment__);
+#endif
Quoted 8 lines

xen/arch/x86/xen.lds.S SECTIONS · line 266

Quoted 5 lines
xen/arch/x86/xen.lds.S +3 -0
+
+  /* Trick the linker into setting the image size to exactly 16Mb. */
   .pad : {
     . = ALIGN(MB(16));
+    __end_of_image__ = .;

I see that you use this symbol in xen/arch/x86/Makefile, but I again don't follow why this logic needs to change.

Quoted 7 lines

Current logic does not work because it gets wrong address from xen/xen-syms. This way boot loader allocates incorrect, usually huge, buffer for Xen image (wait, there is a chance that this is a fix for issues related to 2 MiB mappings found by Andrew). I do not see simple reliable fix for current solution. So, I introduced __end_of_image__ and look for its address. This is much better method to establish end of image address then previous one. However, I can agree that this could be introduced in separate patch.

Yes please, as that also will (hopefully) result in the need for the change getting properly explained.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
xen/include/asm-x86/page.h +0 -0
@@ -288,7 +288,7 @@ extern root_pgentry_t
 idle_pg_table[ROOT_PAGETABLE_ENTRIES];
Quoted 8 lines

xen/include/asm-x86/page.h extern root_pgentry_t idle_pg_table[ROOT_PAGETABLE_ENTRIES]; · line 291

Quoted 5 lines
xen/include/asm-x86/page.h +1 -1
 extern l2_pgentry_t  *compat_idle_pg_table_l2;
 extern unsigned int   m2p_compat_vstart;
 extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES],
-    l2_bootmap[L2_PAGETABLE_ENTRIES];
+    l2_bootmap[4*L2_PAGETABLE_ENTRIES];

Why do you need 4 of them? I can see why one might not suffice, but two surely should?

Quoted 4 lines

In worst case we need three. One for l1_identmap hook and two for Xen image mapping. So, I am not sure that it pays to complicate assembly mapping code just to save just 1 page. Additionally, you should remember that l2_bootmap is freed after init.

Well, I was asking, not saying this needs to change. And you pointing out the l1_identmap aspect makes clear this is fine as is.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#46 lore raw

Re: [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms

In reply to Jan Beulich
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 21:32, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

[...]

Quoted 47 lines
Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
xen/arch/x86/efi/efi-boot.h +30 -0
+paddr_t __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
+    UINTN cols, gop_mode = ~0, rows;
+
+    __set_bit(EFI_BOOT, &efi_flags);
+    __set_bit(EFI_RS, &efi_flags);
+
+    efi_init(ImageHandle, SystemTable);
+
+    efi_console_set_mode();
+
+    if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
+                           &cols, &rows) == EFI_SUCCESS )
+        efi_arch_console_init(cols, rows);
+
+    gop = efi_get_gop();
+
+    if ( gop )
+        gop_mode = efi_find_gop_mode(gop, 0, 0, 0);
+
+    efi_arch_edd();
+    efi_arch_cpu();
+
+    efi_tables();
+    setup_efi_pci();
+    efi_variables();
+
+    if ( gop )
+        efi_set_gop_mode(gop, gop_mode);
Quoted 8 lines

xen/arch/x86/efi/efi-boot.h static bool_t __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) · line 726

Quoted 5 lines
xen/arch/x86/efi/efi-boot.h +5 -0
+
+    efi_exit_boot(ImageHandle, SystemTable);
+
+    /* Return highest available memory address below 1 MiB. */
+    return cfg.addr;

Where is it being made certain that there are 64k of space available right below this address, as is being assumed at trampoline_setup?

Quoted 7 lines

You are right. This is a bug. However, the problem is more generic and should be fixed for all boot cases (BIOS, EFI loader and EFI with GRUB2). Additionally, in case of BIOS and EFI with GRUB2 we should check that it is possible to put all data from grub loader in low memory. So, it looks that there is a place for at least two (three?) additional patches. Do you want them at the beginning of or the end of this patch series.

Quoted 6 lines

If you think there are bugs in pre-existing code, then for having the option of backporting putting such patches at the beginning would be desirable. That said, I'm not convinced there are problems really in need of fixing here (yet the grub environment is different and hence will need taking care of even if we leave the other code paths as they are now).

I think that we should no blindly assume that a given amount of memory is available. However, we do that in a few places including this one which you pointed out. So, it should be fixed. Though, the question is: Is it possible? Right now I am not sure that it is true in all cases mentioned above. There is a chance that in case pointed out by you it is. Anyway, I will check it.

Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
Quoted 17 lines
xen/arch/x86/efi/stub.c +11 -0
@@ -3,6 +3,30 @@
 #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>
+
+paddr_t __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    CHAR16 *err = L"Xen does not have EFI code build in!!!\r\nSystem halted!!!\r\n";
+    SIMPLE_TEXT_OUTPUT_INTERFACE *StdErr;

xen/arch/x86/efi/stub.c line 26

Quoted 10 lines
xen/arch/x86/efi/stub.c +10 -0
+
+    StdErr = SystemTable->StdErr ? SystemTable->StdErr : SystemTable->ConOut;
+
+    /* Print error message and halt the system. */
+    asm volatile(
+    "    call %2                      \n"
+    "0:  hlt                          \n"
+    "    jmp  0b                      \n"
+       : "+c" (StdErr), "+d" (err) : "g" (StdErr->OutputString)
+       : "rax", "r8", "r9", "r10", "r11", "cc", "memory");

There are explanations missing here: First, a warning should be added alongside the EFI header inclusions, making clear that no services whatsoever can be called. And then the asm() here needs to explain

Quoted 3 lines
Quoted 1 line

I am not convinced but if you wish...

Not convinced of what?

About "... a warning should be added alongside the EFI header inclusions, making clear that no services whatsoever can be called". AIUI, "warning" == "comment" here. However, I think that everybody who reads this file is aware that "no services whatsoever can be called". So, I am not sure where is the point.

[...]

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

need for an explicit "cc" clobber on x86.

Why?

Because such a clobber gets added to every asm() by the compiler, unless it uses the (new in gcc 6) flag output. I've actually suggested to upstream a patch making it possible to avoid that automatic addition, but there hadn't been a whole lot of useful feedback.

So, when somebody uses this new flag then "cc" will not be add here. This is not big deal but I think that extra "cc" clobbers does not hurt too.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#53 lore raw

Re: [PATCH v5 14/16] x86/boot: implement early command line parser in C

In reply to Jan Beulich
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 21:58, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

[...]

Quoted 40 lines
Quoted 40 lines
Quoted 39 lines
Quoted 25 lines
xen/arch/x86/boot/cmdline.c new file +25 -0
+static unsigned int strtoui(const char *s, const char *stop, const char **next)
+{
+    char l;
+    unsigned int base = 10, ores = 0, res = 0;
+
+    if ( *s == '0' )
+      base = (tolower(*++s) == 'x') ? (++s, 16) : 8;
+
+    for ( ; *s != '\0'; ++s )
+    {
+        if ( stop && strchr(stop, *s) )
+            goto out;
+
+        if ( *s < '0' || (*s > '7' && base == 8) )
+        {
+            res = UINT_MAX;
+            goto out;
+        }
+
+        l = tolower(*s);
+
+        if ( *s > '9' && (base != 16 || l < 'a' || l > 'f') )
+        {
+            res = UINT_MAX;
+            goto out;

xen/arch/x86/boot/cmdline.c line 197

Quoted 10 lines
xen/arch/x86/boot/cmdline.c new file +10 -0
+        }
+
+        res *= base;
+        res += (l >= 'a') ? (l - 'a' + 10) : (*s - '0');
+
+        if ( ores > res )
+        {
+            res = UINT_MAX;
+            goto out;
+        }

Without having spent time to try and find an example, it feels like this check won't catch all possible overflow conditions. If you care about overflow, please make sure you catch all cases.

Quoted 8 lines
Quoted 1 line

Hmmm.... How come? Could you give an example?

Excuse me, but shouldn't you instead demonstrate the logic is correct? Or - consider what I had said - try to find an example yourself? It's not that difficult: With 16-bit word size 0x3333 * 10 = 0x1fffe, which truncates to 0xfffe and is hence larger than both inputs but still produced an overflow. This easily extends to 32- and 64-bit word size.

Oh, boy. I forgot about multiplication. I think that we can define res as unsigned long and then check that it is < UINT_MAX. If not then return UINT_MAX.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#18 lore raw

Re: [PATCH v5 06/16] x86/boot/reloc: create generic alloc and copy functions

In reply to Jan Beulich
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 17:13, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 16:32, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Create generic alloc and copy functions. We need
separate tools for memory allocation and copy to
provide multiboot2 protocol support.

The amount of casting in this patch alone looks very reasonable now. Before ack-ing this and respective subsequent patches I'd like to see the final result though. To facilitate that I have to re-raise a previously asked question: Do you have a tree somewhere which one could use to look at the final result?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Sadly no.

Alternatively, could you simply send the final resulting source file?

Please look below...

I don't think that was the file at the end of the series, as asked for above? There's no mb2 code in there afaics...

I understood that you need reloc.c after this patch but it looks that I was wrong. So, here it is after applying whole series.

Daniel

/*
* reloc.c
*
* 32-bit flat memory-map routines for relocating Multiboot structures
* and modules. This is most easily done early with paging disabled. *
* Copyright (c) 2009, Citrix Systems, Inc.
* Copyright (c) 2013-2016 Oracle and/or its affiliates. All rights reserved. *
* Authors:
* Keir Fraser <[email protected]>
* Daniel Kiper <[email protected]>
*/

/*
* 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.
 */
asm (
    "    .text                         \n"
    "    .globl _start                 \n"
    "_start:                           \n"
    "    jmp  reloc                    \n"
    );

typedef unsigned int u32;
typedef unsigned long long u64;

#include "../../../include/xen/multiboot.h"
#include "../../../include/xen/multiboot2.h"

#define NULL ((void *)0)

#define __stdcall __attribute__((__stdcall__))

#define ALIGN_UP(arg, align) \
                (((arg) + (align) - 1) & ~((typeof(arg))(align) - 1))

#define get_mb2_data(tag, type, member) (((multiboot2_tag_##type##_t *)(tag))->member)
#define get_mb2_string(tag, type, member) ((u32)get_mb2_data(tag, type, member))

static u32 alloc;

static u32 alloc_mem(u32 bytes)

{
    return alloc -= ALIGN_UP(bytes, 16);
}

static void zero_mem(u32 s, u32 bytes)
{
while ( bytes-- )
*(char *)s++ = 0;
}

static u32 copy_mem(u32 src, u32 bytes)

{
    u32 dst, dst_ret;

    dst = alloc_mem(bytes);
    dst_ret = dst;

    while ( bytes-- )
        *(char *)dst++ = *(char *)src++;

    return dst_ret;
}

static u32 copy_string(u32 src)

{
    u32 p;

    if ( src == 0 )
        return 0;

    for ( p = src; *(char *)p != '\0'; p++ )
        continue;

    return copy_mem(src, p - src + 1);
}

static multiboot_info_t *mbi_mbi(u32 mbi_in)

{
    int i;
    multiboot_info_t *mbi_out;

    mbi_out = (multiboot_info_t *)copy_mem(mbi_in, sizeof(*mbi_out));

    if ( mbi_out->flags & MBI_CMDLINE )
        mbi_out->cmdline = copy_string(mbi_out->cmdline);

    if ( mbi_out->flags & MBI_MODULES )
    {
        module_t *mods;

        mbi_out->mods_addr = copy_mem(mbi_out->mods_addr,
                                      mbi_out->mods_count * sizeof(module_t));

        mods = (module_t *)mbi_out->mods_addr;

        for ( i = 0; i < mbi_out->mods_count; i++ )
        {
            if ( mods[i].string )
                mods[i].string = copy_string(mods[i].string);
        }
    }

    if ( mbi_out->flags & MBI_MEMMAP )
        mbi_out->mmap_addr = copy_mem(mbi_out->mmap_addr, mbi_out->mmap_length);

    if ( mbi_out->flags & MBI_LOADERNAME )
        mbi_out->boot_loader_name = copy_string(mbi_out->boot_loader_name);

    /* Mask features we don't understand or don't relocate. */
    mbi_out->flags &= (MBI_MEMLIMITS |
                       MBI_CMDLINE |
                       MBI_MODULES |
                       MBI_MEMMAP |
                       MBI_LOADERNAME);

    return mbi_out;
}

static multiboot_info_t *mbi2_mbi(u32 mbi_in)

{
    const multiboot2_memory_map_t *mmap_src;
    const multiboot2_tag_t *tag;
    module_t *mbi_out_mods = NULL;
    memory_map_t *mmap_dst;
    multiboot_info_t *mbi_out;
    u32 ptr;
    unsigned int i, mod_idx = 0;

    ptr = alloc_mem(sizeof(*mbi_out));
    mbi_out = (multiboot_info_t *)ptr;
    zero_mem(ptr, sizeof(*mbi_out));

    /* Skip Multiboot2 information fixed part. */
    ptr = ALIGN_UP(mbi_in + sizeof(multiboot2_fixed_t), MULTIBOOT2_TAG_ALIGN);

    /* Get the number of modules. */
    for ( tag = (multiboot2_tag_t *)ptr;
          (u32)tag - mbi_in < ((multiboot2_fixed_t *)mbi_in)->total_size;
          tag = (multiboot2_tag_t *)ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN) )
        if ( tag->type == MULTIBOOT2_TAG_TYPE_MODULE )
            ++mbi_out->mods_count;
        else if ( tag->type == MULTIBOOT2_TAG_TYPE_END )
            break;

    if ( mbi_out->mods_count )
    {
        mbi_out->flags = MBI_MODULES;
        mbi_out->mods_addr = alloc_mem(mbi_out->mods_count * sizeof(module_t));
        mbi_out_mods = (module_t *)mbi_out->mods_addr;
    }

    /* Skip Multiboot2 information fixed part. */
    ptr = ALIGN_UP(mbi_in + sizeof(multiboot2_fixed_t), MULTIBOOT2_TAG_ALIGN);

    /* Put all needed data into mbi_out. */
    for ( tag = (multiboot2_tag_t *)ptr;
          (u32)tag - mbi_in < ((multiboot2_fixed_t *)mbi_in)->total_size;
          tag = (multiboot2_tag_t *)ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN) )
        switch ( tag->type )
        {
        case MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME:
            mbi_out->flags |= MBI_LOADERNAME;
            ptr = get_mb2_string(tag, string, string);
            mbi_out->boot_loader_name = copy_string(ptr);
            break;

        case MULTIBOOT2_TAG_TYPE_CMDLINE:
            mbi_out->flags |= MBI_CMDLINE;
            ptr = get_mb2_string(tag, string, string);
            mbi_out->cmdline = copy_string(ptr);
            break;

        case MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO:
            mbi_out->flags |= MBI_MEMLIMITS;
            mbi_out->mem_lower = get_mb2_data(tag, basic_meminfo, mem_lower);
            mbi_out->mem_upper = get_mb2_data(tag, basic_meminfo, mem_upper);
            break;

        case MULTIBOOT2_TAG_TYPE_MMAP:
            if ( get_mb2_data(tag, mmap, entry_size) < sizeof(*mmap_src) )
                break;

            mbi_out->flags |= MBI_MEMMAP;
            mbi_out->mmap_length = get_mb2_data(tag, mmap, size);
            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);
            mbi_out->mmap_length /= get_mb2_data(tag, mmap, entry_size);
            mbi_out->mmap_length *= sizeof(memory_map_t);

            mbi_out->mmap_addr = alloc_mem(mbi_out->mmap_length);

            mmap_src = get_mb2_data(tag, mmap, entries);
            mmap_dst = (memory_map_t *)mbi_out->mmap_addr;

            for ( i = 0; i < mbi_out->mmap_length / sizeof(memory_map_t); i++ )
            {
                /* Init size member properly. */
                mmap_dst[i].size = sizeof(memory_map_t);
                mmap_dst[i].size -= sizeof(((memory_map_t){0}).size);
                /* Now copy a given region data. */
                mmap_src = (void *)mmap_src + i * get_mb2_data(tag, mmap, entry_size);
                mmap_dst[i].base_addr_low = (u32)mmap_src->addr;
                mmap_dst[i].base_addr_high = (u32)(mmap_src->addr >> 32);
                mmap_dst[i].length_low = (u32)mmap_src->len;
                mmap_dst[i].length_high = (u32)(mmap_src->len >> 32);
                mmap_dst[i].type = mmap_src->type;
            }
            break;

        case MULTIBOOT2_TAG_TYPE_MODULE:
            mbi_out_mods[mod_idx].mod_start = get_mb2_data(tag, module, mod_start);
            mbi_out_mods[mod_idx].mod_end = get_mb2_data(tag, module, mod_end);
            ptr = get_mb2_string(tag, module, cmdline);
            mbi_out_mods[mod_idx].string = copy_string(ptr);
            mbi_out_mods[mod_idx].reserved = 0;
            ++mod_idx;
            break;

        case MULTIBOOT2_TAG_TYPE_END:
            return mbi_out;

        default:
            break;
        }

    return mbi_out;
}

multiboot_info_t __stdcall *reloc(u32 mb_magic, u32 mbi_in, u32 trampoline)

{
    alloc = trampoline;

    if ( mb_magic == MULTIBOOT2_BOOTLOADER_MAGIC )
        return mbi2_mbi(mbi_in);
    else
        return mbi_mbi(mbi_in);
}

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#28 lore raw

Re: [PATCH v5 09/16] x86: add multiboot2 protocol support

In reply to Daniel Kiper
Quoted 7 lines · Daniel Kiper
xen/arch/x86/boot/reloc.c +3 -0
@@ -106,3 +121,122 @@ multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline)
 
     return mbi_out;
 }
+
+static multiboot_info_t *mbi2_mbi(u32 mbi_in)
+{

xen/arch/x86/boot/reloc.c multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline) · line 136

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+    const multiboot2_memory_map_t *mmap_src;
+    const multiboot2_tag_t *tag;
+    module_t *mbi_out_mods = NULL;
+    memory_map_t *mmap_dst;
+    multiboot_info_t *mbi_out;
+    u32 ptr;
+    unsigned int i, mod_idx = 0;
+
+    ptr = alloc_mem(sizeof(*mbi_out));
+    mbi_out = (multiboot_info_t *)ptr;

It occurs to me that a lot of this code would be more simple if you also pulled the

#define _p(val) ((void *)(unsigned long)val)

in from the usual header files. It would shorten a lot of the (multiboot_info_t *) casting, and reduce most multi-line statements to single lines.

Can I also suggest using:

static multiboot_info_t *mbi2_mbi(u32 mbi_in_addr)

{
    const multiboot_info_t *mbi_in = _p(mbi_in_addr);

...

This would avoid repeatedly needing to cast the old mbi_in integer to access fields like ->total_size.

xen/arch/x86/boot/reloc.c multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline) · line 145

Quoted 9 lines
xen/arch/x86/boot/reloc.c +9 -0
+    zero_mem(ptr, sizeof(*mbi_out));
+
+    /* Skip Multiboot2 information fixed part. */
+    ptr = ALIGN_UP(mbi_in + sizeof(multiboot2_fixed_t), MULTIBOOT2_TAG_ALIGN);
+
+    /* Get the number of modules. */
+    for ( tag = (multiboot2_tag_t *)ptr;
+          (u32)tag - mbi_in < ((multiboot2_fixed_t *)mbi_in)->total_size;
+          tag = (multiboot2_tag_t *)ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN) )

Braces here please
{

xen/arch/x86/boot/reloc.c multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline) · line 149

Quoted 4 lines
xen/arch/x86/boot/reloc.c +4 -0
+        if ( tag->type == MULTIBOOT2_TAG_TYPE_MODULE )
+            ++mbi_out->mods_count;
+        else if ( tag->type == MULTIBOOT2_TAG_TYPE_END )
+            break;

}

Given the complexity of the for statement, the exact code contained inside the loop could do with this added clarity.

xen/arch/x86/boot/reloc.c multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline) · line 152

Quoted 3 lines
xen/arch/x86/boot/reloc.c +3 -0
+
+    if ( mbi_out->mods_count )
+    {

In the case that this condition evaluates false, and...

Quoted 53 lines
xen/arch/x86/boot/reloc.c +53 -0
+        mbi_out->flags = MBI_MODULES;
+        mbi_out->mods_addr = alloc_mem(mbi_out->mods_count * sizeof(module_t));
+        mbi_out_mods = (module_t *)mbi_out->mods_addr;
+    }
+
+    /* Skip Multiboot2 information fixed part. */
+    ptr = ALIGN_UP(mbi_in + sizeof(multiboot2_fixed_t), MULTIBOOT2_TAG_ALIGN);
+
+    /* Put all needed data into mbi_out. */
+    for ( tag = (multiboot2_tag_t *)ptr;
+          (u32)tag - mbi_in < ((multiboot2_fixed_t *)mbi_in)->total_size;
+          tag = (multiboot2_tag_t *)ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN) )
+        switch ( tag->type )
+        {
+        case MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME:
+            mbi_out->flags |= MBI_LOADERNAME;
+            ptr = get_mb2_string(tag, string, string);
+            mbi_out->boot_loader_name = copy_string(ptr);
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_CMDLINE:
+            mbi_out->flags |= MBI_CMDLINE;
+            ptr = get_mb2_string(tag, string, string);
+            mbi_out->cmdline = copy_string(ptr);
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO:
+            mbi_out->flags |= MBI_MEMLIMITS;
+            mbi_out->mem_lower = get_mb2_data(tag, basic_meminfo, mem_lower);
+            mbi_out->mem_upper = get_mb2_data(tag, basic_meminfo, mem_upper);
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_MMAP:
+            if ( get_mb2_data(tag, mmap, entry_size) < sizeof(*mmap_src) )
+                break;
+
+            mbi_out->flags |= MBI_MEMMAP;
+            mbi_out->mmap_length = get_mb2_data(tag, mmap, size);
+            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);
+            mbi_out->mmap_length /= get_mb2_data(tag, mmap, entry_size);
+            mbi_out->mmap_length *= sizeof(memory_map_t);
+
+            mbi_out->mmap_addr = alloc_mem(mbi_out->mmap_length);
+
+            mmap_src = get_mb2_data(tag, mmap, entries);
+            mmap_dst = (memory_map_t *)mbi_out->mmap_addr;
+
+            for ( i = 0; i < mbi_out->mmap_length / sizeof(memory_map_t); i++ )
+            {
+                /* Init size member properly. */
+                mmap_dst[i].size = sizeof(memory_map_t);
+                mmap_dst[i].size -= sizeof(((memory_map_t){0}).size);
+                /* Now copy a given region data. */

xen/arch/x86/boot/reloc.c multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline) · line 215

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+                mmap_src = (void *)mmap_src + i * get_mb2_data(tag, mmap, entry_size);
+                mmap_dst[i].base_addr_low = (u32)mmap_src->addr;
+                mmap_dst[i].base_addr_high = (u32)(mmap_src->addr >> 32);
+                mmap_dst[i].length_low = (u32)mmap_src->len;
+                mmap_dst[i].length_high = (u32)(mmap_src->len >> 32);
+                mmap_dst[i].type = mmap_src->type;
+            }
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_MODULE:

... this tag gets found, then a NULL mbi_out_mods gets followed.

I realise that this calculation is a result of a double loop over the tag list, but it would be better to code slightly more resiliently (given both the very liberal use of casting, and the possiblity that something else is modifying the memory while we are looking at it). Something like:

if ( mod_idx < mbi_out->mods_count )
{

xen/arch/x86/boot/reloc.c multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline) · line 221

Quoted 6 lines
xen/arch/x86/boot/reloc.c +6 -0
+            mbi_out_mods[mod_idx].mod_start = get_mb2_data(tag, module, mod_start);
+            mbi_out_mods[mod_idx].mod_end = get_mb2_data(tag, module, mod_end);
+            ptr = get_mb2_string(tag, module, cmdline);
+            mbi_out_mods[mod_idx].string = copy_string(ptr);
+            mbi_out_mods[mod_idx].reserved = 0;
+            ++mod_idx;

}

should do.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#60 lore raw

Re: [PATCH v5 15/16] x86: make Xen early boot code relocatable

In reply to Jan Beulich
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 16:59, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

[...]

Quoted 17 lines
Quoted 12 lines
Quoted 11 lines

xen/arch/x86/boot/head.S line 15

Quoted 8 lines
xen/arch/x86/boot/head.S +1 -1
@@ -12,13 +12,16 @@
         .text
         .code32
 
-#define sym_phys(sym)     ((sym) - __XEN_VIRT_START)
+#define sym_offset(sym)   ((sym) - __XEN_VIRT_START)

In a patch already large and hence hard to review, did you really need to do this rename?

Quoted 4 lines

I think that sym_offset() is better term here. However, if you wish I can leave sym_phys() as is. Though, IMO, sym_phys() name suggests that we are playing with physical addresses and it is not correct in all contexts, e.g. loot at fs_offset() (or sym_fs() as you wish).

Quoted 4 lines

After some more thinking about this I agree sym_phys() isn't ideal anymore after this patch. Still, to avoid unrelated changes in this quite hard to review patch, I'd like to ask that you keep the name here and do just the rename in a subsequent patch.

Granted!

[...]

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

xen/arch/x86/boot/trampoline.S trampoline_gdt: · line 61

Quoted 11 lines
xen/arch/x86/boot/trampoline.S +5 -0
@@ -54,12 +54,20 @@ 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   0x00c0920000001000

This does not look like it covers 1Mb, it's more like 1Mb+4k-1.

Quoted 5 lines
Quoted 2 lines

I have checked it once again. It covers 16 MiB as required:
4 KiB * 0x1000 = 0x1000000 (no taking into account relocation).

I'm sorry, but no. The raw limit value taken from that descriptor is 0x1000, and the G bit is set. That makes the actual limit 0x1000fff.

I was not sure why but this explains it: "When the granularity flag is set, the twelve least significant bits of an offset are not tested when checking the offset against the segment limit. For example, when the granularity flag is set, a limit of 0 results in valid offsets from 0 to 4095." (Intel(R) 64 and IA-32 Architectures Software Developer’s Manual Volume 3 (3A, 3B & 3C): System Programming Guide). So, it means that this should be:

.quad 0x00c0920000000fff

[...]

Quoted 21 lines
Quoted 12 lines
Quoted 11 lines

xen/arch/x86/boot/trampoline.S trampoline_gdt: · line 69

Quoted 7 lines
xen/arch/x86/boot/trampoline.S +2 -0
         .pushsection .trampoline_rel, "a"
         .long   trampoline_gdt + BOOT_PSEUDORM_CS + 2 - .
         .long   trampoline_gdt + BOOT_PSEUDORM_DS + 2 - .
         .popsection
 
+GLOBAL(xen_img_load_base_addr)
+        .long   0

I've yet to understand the purpose of this symbol, but in any case:
If the trampoline code doesn't reference it, why does it get placed here?

Quoted 8 lines

This symbol was used by code which unconditionally relocated Xen image even if boot loader did work for us. I removed most of this code because we agreed that if boot loader relocated Xen image then we do not have to relocate it higher once again. If you are still OK with this idea I can go further, as I planned, and remove all such remnants from next release. However, it looks that then I have to store load address in xen_phys_start from 32-bit assembly code. So, it will be nice if I can define it as "unsigned int" instead of "unsigned long". Is it safe?

Quoted 2 lines

I don't see why you shouldn't be able to store into the low 32 bits of the variable without altering the high ones (which are all zero).

I was thinking about that too but IMO it is not nice. However, if you are OK with that I can do it.

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines

xen/arch/x86/boot/trampoline.S trampoline_gdt:

Quoted 5 lines
xen/arch/x86/boot/trampoline.S +0 -1
         s = (boot_e820.map[i].addr + mask) & ~mask;
         e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
-        s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
         if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
             continue;

This means you now map memory between 2Mb and 16Mb here. Is this necessary?

Without this change Xen relocated by boot loader crashes with:

Quoted 7 lines
Quoted 4 lines

(XEN) Panic on CPU 0:
(XEN) Assertion 'l2e_get_flags(l2e) & _PAGE_PRESENT' failed at x86_64/mm.c:902

So, it must be mapped.

That's too little context to be useful for understanding the full background.

Here it is:

(XEN) Detected 2194.733 MHz processor.
(XEN) Assertion 'l2e_get_flags(l2e) & _PAGE_PRESENT' failed at x86_64/mm.c:902
(XEN) ----[ Xen-4.8-unstable x86_64 debug=y Tainted: C ]----
(XEN) CPU: 0
(XEN) RIP: e008:[<ffff82d0803c55d4>] subarch_init_memory+0x53e/0x5ea
(XEN) RFLAGS: 0000000000010046 CONTEXT: hypervisor

(XEN) rax: ffff830000200000   rbx: ffffffffffffffff   rcx: 0000000000000000
(XEN) rdx: 0000000000000000   rsi: 000000007ea04000   rdi: 8000000000000000
(XEN) rbp: ffff82d080417d78   rsp: ffff82d080417d38   r8:  ffff830000000000
(XEN) r9:  00000007c7ffffff   r10: ffffffffffffffff   r11: 0000000000000000
(XEN) r12: ffff83007ea04008   r13: 0000000000000000   r14: 0000000000000000
(XEN) r15: 0000000000000000   cr0: 000000008005003b   cr4: 00000000000006e0
(XEN) cr3: 000000007ea0c000   cr2: 0000000000000000

(XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: 0000 cs: e008
(XEN) Xen code around <ffff82d0803c55d4> (subarch_init_memory+0x53e/0x5ea):
(XEN) 09 fe 41 f6 c6 01 75 02 <0f> 0b 41 f6 c6 80 74 0f 48 09 fa 49 89 14 24 48 (XEN) Xen stack trace from rsp=ffff82d080417d38:

(XEN)    ffff82d0802324c3 000000000007ea04 ffff82d080417d78 0000000000180000
(XEN)    0000000000000009 0000000000180000 ffff82e000000000 0000000000180000
(XEN)    ffff82d080417db8 ffff82d0803c42af ffff82d080417da8 ffff82d080417fff
(XEN)    ffff83017f1e0670 ffff82d08054cad0 ffff82d08054cad0 0000000000000003
(XEN)    ffff82d080417f08 ffff82d0803ca8d5 0000000000000000 0000000000000001
(XEN)    0000024d00000000 000000000034cc00 000000000000014d 00000000000001f5
(XEN)    00000000000001f5 000000000000019f 000000000000019f 000000000000014e
(XEN)    000000000000014e 0000000000000002 0000000000000001 0000000000000001
(XEN)    0000000000000001 0000000000000001 0000000000000001 0000000000000001
(XEN)    0000000000b42000 ffff83000008eee0 0000000000000000 000000000000000e
(XEN)    0000000000180000 ffff83000008efa0 000000017f1f2000 fffffffffffff001
(XEN)    ffff83000008efb0 ffff82d0803ef99c 0000000000000000 0000000000000000
(XEN)    0000000800000000 000000010000006e 0000000000000003 00000000000002f8
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 ffff82d0802000f3
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN) Xen call trace:
(XEN)    [<ffff82d0803c55d4>] subarch_init_memory+0x53e/0x5ea
(XEN)    [<ffff82d0803c42af>] arch_init_memory+0x2f3/0x5d3
(XEN)    [<ffff82d0803ca8d5>] __start_xen+0x242f/0x2965
(XEN)    [<ffff82d0802000f3>] __high_start+0x53/0x60

(XEN)
(XEN)
(XEN) ****************************************
(XEN) Panic on CPU 0:
(XEN) Assertion 'l2e_get_flags(l2e) & _PAGE_PRESENT' failed at x86_64/mm.c:902 (XEN) ****************************************

Is it sufficient? If not please drop me a line what else do you need.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#29 lore raw

Re: [PATCH v5 09/16] x86: add multiboot2 protocol support

In reply to Andrew Cooper
Quoted 22 lines · Andrew Cooper
Quoted 7 lines · Daniel Kiper
xen/arch/x86/boot/reloc.c +3 -0
@@ -106,3 +121,122 @@ multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline)
 
     return mbi_out;
 }
+
+static multiboot_info_t *mbi2_mbi(u32 mbi_in)
+{

xen/arch/x86/boot/reloc.c multiboot_info_t __stdcall *reloc(u32 mbi_in, u32 trampoline) · line 136

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+    const multiboot2_memory_map_t *mmap_src;
+    const multiboot2_tag_t *tag;
+    module_t *mbi_out_mods = NULL;
+    memory_map_t *mmap_dst;
+    multiboot_info_t *mbi_out;
+    u32 ptr;
+    unsigned int i, mod_idx = 0;
+
+    ptr = alloc_mem(sizeof(*mbi_out));
+    mbi_out = (multiboot_info_t *)ptr;

It occurs to me that a lot of this code would be more simple if you also pulled the

Quoted 7 lines

#define _p(val) ((void *)(unsigned long)val)

in from the usual header files. It would shorten a lot of the (multiboot_info_t *) casting, and reduce most multi-line statements to single lines.

Can I also suggest using:

[...]

Make sense for me. I will try to get all your comments into account.

Thanks a lot,

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#19 lore raw

Re: [PATCH v5 06/16] x86/boot/reloc: create generic alloc and copy functions

In reply to Daniel Kiper
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 21:39, <[email protected]> wrote:

I understood that you need reloc.c after this patch but it looks that I was wrong. So, here it is after applying whole series.

Thanks. Here are my notes:

All callers of alloc_mem() cast the result to a pointer. While most of them also need the result as an integer, there's one exception:

    ptr = alloc_mem(sizeof(*mbi_out));
    mbi_out = (multiboot_info_t *)ptr;
    zero_mem(ptr, sizeof(*mbi_out));

Since this is also the only caller of zero_mem() it tells me that less casting would be needed if alloc_mem() returned void *, and if zero_mem() took void * for its first parameter.

Otoh it looks like copy_{mem,string}() are best left the way they are now.

The amount of casting in e.g.

    for ( tag = (multiboot2_tag_t *)ptr;
          (u32)tag - mbi_in < ((multiboot2_fixed_t *)mbi_in)->total_size;
          tag = (multiboot2_tag_t *)ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN) )

is still ugly, the more that the entire construct exists more than once. One thing to consider (which would make things at least a little less fragile) would be to make tag (and maybe then also mbi_in) a union of u32 and multiboot2_fixed_t *. For parameter passing purposes from reloc() it may then be desirable for this to actually be a transparent union.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#47 lore raw

Re: [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms

In reply to Daniel Kiper
Quoted 39 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 19:07, <[email protected]> wrote:
Quoted 37 lines · Jan Beulich
Quoted 36 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 21:32, <[email protected]> wrote:
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/efi/stub.c +17 -0
@@ -3,6 +3,30 @@
 #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>
+
+paddr_t __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    CHAR16 *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. */
+    asm volatile(
+    "    call %2                      \n"
Quoted 8 lines

xen/arch/x86/efi/stub.c line 26

Quoted 4 lines
xen/arch/x86/efi/stub.c +4 -0
+    "0:  hlt                          \n"
+    "    jmp  0b                      \n"
+       : "+c" (StdErr), "+d" (err) : "g" (StdErr->OutputString)
+       : "rax", "r8", "r9", "r10", "r11", "cc", "memory");

There are explanations missing here: First, a warning should be added alongside the EFI header inclusions, making clear that no services whatsoever can be called. And then the asm() here needs to explain

I am not convinced but if you wish...

Quoted 7 lines
Quoted 1 line

Not convinced of what?

About "... a warning should be added alongside the EFI header inclusions, making clear that no services whatsoever can be called". AIUI, "warning" == "comment" here. However, I think that everybody who reads this file is aware that "no services whatsoever can be called". So, I am not sure where is the point.

Odd - you do an EFI call here (in the asm()) and talk about reader's awareness?

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

need for an explicit "cc" clobber on x86.

Why?

Quoted 8 lines
Quoted 4 lines

Because such a clobber gets added to every asm() by the compiler, unless it uses the (new in gcc 6) flag output. I've actually suggested to upstream a patch making it possible to avoid that automatic addition, but there hadn't been a whole lot of useful feedback.

So, when somebody uses this new flag then "cc" will not be add here. This is not big deal but I think that extra "cc" clobbers does not hurt too.

It surely doesn't hurt, but it makes code bigger and hence results in it taking longer to be read and parsed (for all of these - even if just slightly). I'm sorry, but I'm opposed to adding unnecessary stuff.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#54 lore raw

Re: [PATCH v5 14/16] x86/boot: implement early command line parser in C

In reply to Daniel Kiper
Quoted 58 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 21:31, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 21:58, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

[...]

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+static unsigned int strtoui(const char *s, const char *stop, const char

**next)

Quoted 39 lines
Quoted 39 lines
Quoted 38 lines
Quoted 24 lines
xen/arch/x86/boot/cmdline.c new file +24 -0
+{
+    char l;
+    unsigned int base = 10, ores = 0, res = 0;
+
+    if ( *s == '0' )
+      base = (tolower(*++s) == 'x') ? (++s, 16) : 8;
+
+    for ( ; *s != '\0'; ++s )
+    {
+        if ( stop && strchr(stop, *s) )
+            goto out;
+
+        if ( *s < '0' || (*s > '7' && base == 8) )
+        {
+            res = UINT_MAX;
+            goto out;
+        }
+
+        l = tolower(*s);
+
+        if ( *s > '9' && (base != 16 || l < 'a' || l > 'f') )
+        {
+            res = UINT_MAX;
+            goto out;

xen/arch/x86/boot/cmdline.c line 197

Quoted 10 lines
xen/arch/x86/boot/cmdline.c new file +10 -0
+        }
+
+        res *= base;
+        res += (l >= 'a') ? (l - 'a' + 10) : (*s - '0');
+
+        if ( ores > res )
+        {
+            res = UINT_MAX;
+            goto out;
+        }

Without having spent time to try and find an example, it feels like this check won't catch all possible overflow conditions. If you care about overflow, please make sure you catch all cases.

Quoted 8 lines
Quoted 1 line

Hmmm.... How come? Could you give an example?

Excuse me, but shouldn't you instead demonstrate the logic is correct? Or - consider what I had said - try to find an example yourself? It's not that difficult: With 16-bit word size 0x3333 * 10 = 0x1fffe, which truncates to 0xfffe and is hence larger than both inputs but still produced an overflow. This easily extends to 32- and 64-bit word size.

Quoted 3 lines

Oh, boy. I forgot about multiplication. I think that we can define res as unsigned long and then check that it is < UINT_MAX. If not then return UINT_MAX.

Aren't we in 32-bit code here, i.e. sizeof(int) == sizeof(long)?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#61 lore raw

Re: [PATCH v5 15/16] x86: make Xen early boot code relocatable

In reply to Daniel Kiper
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 22:50, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 16:59, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/boot/head.S +0 -0
@@ -12,13 +12,16 @@
         .text
         .code32
 
Quoted 5 lines

xen/arch/x86/boot/head.S line 15

Quoted 2 lines
xen/arch/x86/boot/head.S +1 -1
-#define sym_phys(sym)     ((sym) - __XEN_VIRT_START)
+#define sym_offset(sym)   ((sym) - __XEN_VIRT_START)

In a patch already large and hence hard to review, did you really need to do this rename?

I think that sym_offset() is better term here. However, if you wish I can leave sym_phys() as is. Though, IMO, sym_phys() name suggests that we are playing with physical addresses and it is not correct in all contexts, e.g. loot at fs_offset() (or sym_fs() as you wish).

Quoted 6 lines
Quoted 4 lines

After some more thinking about this I agree sym_phys() isn't ideal anymore after this patch. Still, to avoid unrelated changes in this quite hard to review patch, I'd like to ask that you keep the name here and do just the rename in a subsequent patch.

Granted!

Btw., to save on typing and since you will need to touch this anyway
- can I talk you into using sym_offs() instead of sym_offset()?

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 11 lines

xen/arch/x86/boot/head.S line 22

Quoted 7 lines
xen/arch/x86/boot/head.S +2 -0
         .pushsection .trampoline_rel, "a"
         .long   trampoline_gdt + BOOT_PSEUDORM_CS + 2 - .
         .long   trampoline_gdt + BOOT_PSEUDORM_DS + 2 - .
         .popsection
 
+GLOBAL(xen_img_load_base_addr)
+        .long   0

I've yet to understand the purpose of this symbol, but in any case:
If the trampoline code doesn't reference it, why does it get placed here?

This symbol was used by code which unconditionally relocated Xen image even if boot loader did work for us. I removed most of this code because we agreed that if boot loader relocated Xen image then we do not have to relocate it higher once again. If you are still OK with this idea I can go further, as I planned, and remove all such remnants from next release. However, it looks that then I have to store load address in xen_phys_start from 32-bit assembly code. So, it will be nice if I can define it as "unsigned int" instead of "unsigned long". Is it safe?

Quoted 5 lines
Quoted 2 lines

I don't see why you shouldn't be able to store into the low 32 bits of the variable without altering the high ones (which are all zero).

I was thinking about that too but IMO it is not nice. However, if you are OK with that I can do it.

Well, imo that's something which is perfectly fine in assembly code.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 8 lines

xen/arch/x86/boot/head.S

Quoted 5 lines
xen/arch/x86/boot/head.S +0 -1
         s = (boot_e820.map[i].addr + mask) & ~mask;
         e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
-        s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
         if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
             continue;

This means you now map memory between 2Mb and 16Mb here. Is this necessary?

Without this change Xen relocated by boot loader crashes with:

(XEN) Panic on CPU 0:
(XEN) Assertion 'l2e_get_flags(l2e) & _PAGE_PRESENT' failed at x86_64/mm.c:902

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

So, it must be mapped.

That's too little context to be useful for understanding the full background.

Here it is:
[...]
Is it sufficient? If not please drop me a line what else do you need.

I'm sorry, but no. I didn't mean the whole register and stack dump. I meant an explanation of _why_ this assertion triggers (after all it doesn't trigger without your patches, and hence I can't just go and check the relevant source files).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#48 lore raw

Re: [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms

In reply to Jan Beulich
Quoted 41 lines · Jan Beulich
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 19:07, <[email protected]> wrote:
Quoted 38 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 21:32, <[email protected]> wrote:
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/efi/stub.c +17 -0
@@ -3,6 +3,30 @@
 #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>
+
+paddr_t __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    CHAR16 *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. */
+    asm volatile(
+    "    call %2                      \n"
Quoted 8 lines

xen/arch/x86/efi/stub.c line 26

Quoted 4 lines
xen/arch/x86/efi/stub.c +4 -0
+    "0:  hlt                          \n"
+    "    jmp  0b                      \n"
+       : "+c" (StdErr), "+d" (err) : "g" (StdErr->OutputString)
+       : "rax", "r8", "r9", "r10", "r11", "cc", "memory");

There are explanations missing here: First, a warning should be added alongside the EFI header inclusions, making clear that no services whatsoever can be called. And then the asm() here needs to explain

Quoted 1 line

I am not convinced but if you wish...

Not convinced of what?

Quoted 8 lines
Quoted 5 lines

About "... a warning should be added alongside the EFI header inclusions, making clear that no services whatsoever can be called". AIUI, "warning" == "comment" here. However, I think that everybody who reads this file is aware that "no services whatsoever can be called". So, I am not sure where is the point.

Odd - you do an EFI call here (in the asm()) and talk about reader's awareness?

I do this in quite strange way just to display clear error from file called stub.c which contains just mostly function stubs. So, I have a feeling that sane reader will be conscious here and will not expect code which does sensible stuff. However, if you still think that these are insufficient then I can add warninng/comment which assures potential reader that this is a stub file and most functions does nothing except efi_multiboot2().

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

need for an explicit "cc" clobber on x86.

Why?

Because such a clobber gets added to every asm() by the compiler, unless it uses the (new in gcc 6) flag output. I've actually suggested to upstream a patch making it possible to avoid that automatic addition, but there hadn't been a whole lot of useful feedback.

Quoted 7 lines
Quoted 3 lines

So, when somebody uses this new flag then "cc" will not be add here. This is not big deal but I think that extra "cc" clobbers does not hurt too.

It surely doesn't hurt, but it makes code bigger and hence results in it taking longer to be read and parsed (for all of these - even if just slightly). I'm sorry, but I'm opposed to adding unnecessary stuff.

As you wish...

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#55 lore raw

Re: [PATCH v5 14/16] x86/boot: implement early command line parser in C

In reply to Jan Beulich
Quoted 58 lines · Jan Beulich
Quoted 58 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 21:31, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.08.16 at 21:58, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

[...]

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+static unsigned int strtoui(const char *s, const char *stop, const char

**next)

Quoted 47 lines
Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
xen/arch/x86/boot/cmdline.c new file +30 -0
+{
+    char l;
+    unsigned int base = 10, ores = 0, res = 0;
+
+    if ( *s == '0' )
+      base = (tolower(*++s) == 'x') ? (++s, 16) : 8;
+
+    for ( ; *s != '\0'; ++s )
+    {
+        if ( stop && strchr(stop, *s) )
+            goto out;
+
+        if ( *s < '0' || (*s > '7' && base == 8) )
+        {
+            res = UINT_MAX;
+            goto out;
+        }
+
+        l = tolower(*s);
+
+        if ( *s > '9' && (base != 16 || l < 'a' || l > 'f') )
+        {
+            res = UINT_MAX;
+            goto out;
+        }
+
+        res *= base;
+        res += (l >= 'a') ? (l - 'a' + 10) : (*s - '0');
+
+        if ( ores > res )
Quoted 8 lines

xen/arch/x86/boot/cmdline.c line 180

Quoted 4 lines
xen/arch/x86/boot/cmdline.c new file +4 -0
+        {
+            res = UINT_MAX;
+            goto out;
+        }

Without having spent time to try and find an example, it feels like this check won't catch all possible overflow conditions. If you care about overflow, please make sure you catch all cases.

Quoted 1 line

Hmmm.... How come? Could you give an example?

Excuse me, but shouldn't you instead demonstrate the logic is correct? Or - consider what I had said - try to find an example yourself? It's not that difficult: With 16-bit word size 0x3333 * 10 = 0x1fffe, which truncates to 0xfffe and is hence larger than both inputs but still produced an overflow. This easily extends to 32- and 64-bit word size.

Quoted 5 lines
Quoted 3 lines

Oh, boy. I forgot about multiplication. I think that we can define res as unsigned long and then check that it is < UINT_MAX. If not then return UINT_MAX.

Aren't we in 32-bit code here, i.e. sizeof(int) == sizeof(long)?

Yep, this should be unsigned long long here.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#62 lore raw

Re: [PATCH v5 15/16] x86: make Xen early boot code relocatable

In reply to Jan Beulich
Quoted 27 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 22:50, <[email protected]> wrote:
Quoted 24 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 16:59, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/boot/head.S +0 -0
@@ -12,13 +12,16 @@
         .text
         .code32
 
Quoted 5 lines

xen/arch/x86/boot/head.S line 15

Quoted 2 lines
xen/arch/x86/boot/head.S +1 -1
-#define sym_phys(sym)     ((sym) - __XEN_VIRT_START)
+#define sym_offset(sym)   ((sym) - __XEN_VIRT_START)

In a patch already large and hence hard to review, did you really need to do this rename?

Quoted 4 lines

I think that sym_offset() is better term here. However, if you wish I can leave sym_phys() as is. Though, IMO, sym_phys() name suggests that we are playing with physical addresses and it is not correct in all contexts, e.g. loot at fs_offset() (or sym_fs() as you wish).

After some more thinking about this I agree sym_phys() isn't ideal anymore after this patch. Still, to avoid unrelated changes in this quite hard to review patch, I'd like to ask that you keep the name here and do just the rename in a subsequent patch.

Quoted 4 lines
Quoted 1 line

Granted!

Btw., to save on typing and since you will need to touch this anyway
- can I talk you into using sym_offs() instead of sym_offset()?

Sure thing!

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 11 lines

xen/arch/x86/boot/head.S line 22

Quoted 7 lines
xen/arch/x86/boot/head.S +2 -0
         .pushsection .trampoline_rel, "a"
         .long   trampoline_gdt + BOOT_PSEUDORM_CS + 2 - .
         .long   trampoline_gdt + BOOT_PSEUDORM_DS + 2 - .
         .popsection
 
+GLOBAL(xen_img_load_base_addr)
+        .long   0

I've yet to understand the purpose of this symbol, but in any case:
If the trampoline code doesn't reference it, why does it get placed here?

This symbol was used by code which unconditionally relocated Xen image even if boot loader did work for us. I removed most of this code because we agreed that if boot loader relocated Xen image then we do not have to relocate it higher once again. If you are still OK with this idea I can go further, as I planned, and remove all such remnants from next release. However, it looks that then I have to store load address in xen_phys_start from 32-bit assembly code. So, it will be nice if I can define it as "unsigned int" instead of "unsigned long". Is it safe?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I don't see why you shouldn't be able to store into the low 32 bits of the variable without altering the high ones (which are all zero).

I was thinking about that too but IMO it is not nice. However, if you are OK with that I can do it.

Well, imo that's something which is perfectly fine in assembly code.

OK, I will do that.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 9 lines
Quoted 8 lines

xen/arch/x86/boot/head.S

Quoted 5 lines
xen/arch/x86/boot/head.S +0 -1
         s = (boot_e820.map[i].addr + mask) & ~mask;
         e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
-        s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
         if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
             continue;

This means you now map memory between 2Mb and 16Mb here. Is this necessary?

Quoted 6 lines

Without this change Xen relocated by boot loader crashes with:

(XEN) Panic on CPU 0:
(XEN) Assertion 'l2e_get_flags(l2e) & _PAGE_PRESENT' failed at x86_64/mm.c:902

So, it must be mapped.

That's too little context to be useful for understanding the full background.

Quoted 8 lines
Quoted 3 lines

Here it is:
[...]
Is it sufficient? If not please drop me a line what else do you need.

I'm sorry, but no. I didn't mean the whole register and stack dump. I meant an explanation of _why_ this assertion triggers (after all it doesn't trigger without your patches, and hence I can't just go and check the relevant source files).

AIUI, if Xen image is not relocated by boot loader (e.g. GRUB2) then region 2 MiB - 16 MiB is mapped. Later Xen after relocating itself marks 1 MiB - 16 MiB region as NX (if it is supported by hardware) in subarch_init_memory(). However, if boot loader relocate Xen then region 2 MiB - 16 MiB is not mapped if change under consideration is not applied. Then ASSERT(l2e_get_flags(l2e) & _PAGE_PRESENT) in subarch_init_memory() is triggered and Xen crashes.

I hope that helps.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#63 lore raw

Re: [PATCH v5 15/16] x86: make Xen early boot code relocatable

Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 01.09.16 at 23:19, <[email protected]> wrote:
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 22:50, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 16:59, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
         s = (boot_e820.map[i].addr + mask) & ~mask;
         e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
-        s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
         if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
             continue;

This means you now map memory between 2Mb and 16Mb here. Is this necessary?

Quoted 6 lines

Without this change Xen relocated by boot loader crashes with:

(XEN) Panic on CPU 0:
(XEN) Assertion 'l2e_get_flags(l2e) & _PAGE_PRESENT' failed at x86_64/mm.c:902

So, it must be mapped.

That's too little context to be useful for understanding the full background.

Quoted 8 lines
Quoted 3 lines

Here it is:
[...]
Is it sufficient? If not please drop me a line what else do you need.

I'm sorry, but no. I didn't mean the whole register and stack dump. I meant an explanation of _why_ this assertion triggers (after all it doesn't trigger without your patches, and hence I can't just go and check the relevant source files).

Quoted 6 lines

AIUI, if Xen image is not relocated by boot loader (e.g. GRUB2) then region 2 MiB - 16 MiB is mapped. Later Xen after relocating itself marks 1 MiB - 16 MiB region as NX (if it is supported by hardware) in subarch_init_memory(). However, if boot loader relocate Xen then region 2 MiB - 16 MiB is not mapped if change under consideration is not applied. Then ASSERT(l2e_get_flags(l2e) & _PAGE_PRESENT) in subarch_init_memory() is triggered and Xen crashes.

Ah, I see now. But instead of altering the setup.c logic even for the not relocated case, perhaps you'd better establish the here expected mapping in the relocated case? I'm rather hesitant to see that setup.c logic change for pre-existing cases; it may alternatively be acceptable to make the line you delete conditional.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#64 lore raw

Re: [PATCH v5 15/16] x86: make Xen early boot code relocatable

Quoted 42 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 01.09.16 at 23:19, <[email protected]> wrote:
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 22:50, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 31.08.16 at 16:59, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
         s = (boot_e820.map[i].addr + mask) & ~mask;
         e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
-        s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
         if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
             continue;

This means you now map memory between 2Mb and 16Mb here. Is this necessary?

Quoted 6 lines

Without this change Xen relocated by boot loader crashes with:

(XEN) Panic on CPU 0:
(XEN) Assertion 'l2e_get_flags(l2e) & _PAGE_PRESENT' failed at x86_64/mm.c:902

So, it must be mapped.

That's too little context to be useful for understanding the full background.

Quoted 8 lines
Quoted 3 lines

Here it is:
[...]
Is it sufficient? If not please drop me a line what else do you need.

I'm sorry, but no. I didn't mean the whole register and stack dump. I meant an explanation of _why_ this assertion triggers (after all it doesn't trigger without your patches, and hence I can't just go and check the relevant source files).

Quoted 6 lines

AIUI, if Xen image is not relocated by boot loader (e.g. GRUB2) then region 2 MiB - 16 MiB is mapped. Later Xen after relocating itself marks 1 MiB - 16 MiB region as NX (if it is supported by hardware) in subarch_init_memory(). However, if boot loader relocate Xen then region 2 MiB - 16 MiB is not mapped if change under consideration is not applied. Then ASSERT(l2e_get_flags(l2e) & _PAGE_PRESENT) in subarch_init_memory() is triggered and Xen crashes.

Quoted 5 lines

Ah, I see now. But instead of altering the setup.c logic even for the not relocated case, perhaps you'd better establish the here expected mapping in the relocated case? I'm rather hesitant to see that setup.c logic change for pre-existing cases; it may alternatively be acceptable to make the line you delete conditional.

...or map 2 MiB - 16 MiB region in xen/arch/x86/boot/head.S. It could be done in similar way to Xen image mapping. However, this should be tested...

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#37 lore raw

Re: [PATCH v5 12/16] x86/efi: create new early memory allocator

In reply to Daniel Kiper

xen/arch/x86/efi/efi-boot.h static void __init relocate_trampoline(unsigned long phys) · line 108

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/efi/efi-boot.h +3 -0
@@ -103,9 +103,56 @@ static void __init relocate_trampoline(unsigned long phys)
         *(u16 *)(*trampoline_ptr + (long)trampoline_ptr) = phys >> 4;
 }
 
+#define EBMALLOC_SIZE	MB(1)
+
+static char __section(".bss.page_aligned") ebmalloc_mem[EBMALLOC_SIZE];

You need to specify the alignment of the object (using the relatively new __aligned() construct).

xen/arch/x86/efi/efi-boot.h static void __init relocate_trampoline(unsigned long phys) · line 119

Quoted 11 lines
xen/arch/x86/efi/efi-boot.h +11 -0
+static char __initdata *ebmalloc_free = NULL;
+
+/* EFI boot allocator. */
+static void __init *ebmalloc(size_t size)
+{
+    void *ptr;
+
+    /*
+     * Init ebmalloc_free on runtime. Static initialization
+     * will not work because it puts virtual address there.
+     */

I don't understand this static allocation comment: We have this issue elsewhere (and use bootsym() as needed), and we do not have this issue at all in xen.efi (which this code also gets built for). So I think at the very least the comment needs improvement. And then, if static initialization indeed can't be used, then a static symbol's initializer of NULL is pointless and hence should be omitted.

xen/arch/x86/efi/efi-boot.h static void __init relocate_trampoline(unsigned long phys) · line 125

Quoted 6 lines
xen/arch/x86/efi/efi-boot.h +6 -0
+    if ( ebmalloc_free == NULL )
+        ebmalloc_free = ebmalloc_mem;
+
+    ptr = ebmalloc_free;
+
+    ebmalloc_free += size;

No minimal (at least pointer size) alignment getting enforced somewhere here?

Quoted 8 lines
xen/arch/x86/efi/efi-boot.h +8 -0
+void __init free_ebmalloc_unused_mem(void)
+{
+    unsigned long start, end;
+
+    if ( ebmalloc_free )
+    {
+        start = (unsigned long)ebmalloc_free - xen_phys_start;
+        start = PAGE_ALIGN(start + XEN_VIRT_START);

xen/arch/x86/efi/efi-boot.h static void __init relocate_trampoline(unsigned long phys) · line 150

Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10 -0
+    }
+    else
+        start = (unsigned long)ebmalloc_mem;
+
+    end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
+
+    destroy_xen_mappings(start, end);
+    init_xenheap_pages(__pa(start), __pa(end));
+
+    printk("Freed %lukB unused BSS memory\n", (end - start) >> 10);

XENLOG_INFO

And then - wouldn't this better go into xen/common/efi/boot.c, even if ARM64 does not have a use for it right away? The code certainly isn't really x86-specific.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#20 lore raw

Re: [PATCH v5 06/16] x86/boot/reloc: create generic alloc and copy functions

In reply to Daniel Kiper
Quoted 14 lines · Daniel Kiper
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

Create generic alloc and copy functions. We need
separate tools for memory allocation and copy to
provide multiboot2 protocol support.

Quoted 7 lines
Quoted 1 line

The amount of casting in this patch alone looks very reasonable now. Before ack-ing this and respective subsequent patches I'd like to see the final result though. To facilitate that I have to re-raise a previously asked question: Do you have a tree somewhere which one could use to look at the final result?

Quoted 4 lines

Sadly no.

Daniel

Daniel,

I'd encourage you to go to https://github.com/xen-project/xen and "fork" the project and use that space to push your branches. It's free (as in beer) hosting for any long series and you can enable
https://travis-ci.org to do some basic build tests on patch series before you mail them out.

Signature · 1 line
Doug Goldstein

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#38 lore raw

Re: [PATCH v5 12/16] x86/efi: create new early memory allocator

In reply to Jan Beulich
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:

[...]

Quoted 10 lines
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10 -0
+static char __initdata *ebmalloc_free = NULL;
+
+/* EFI boot allocator. */
+static void __init *ebmalloc(size_t size)
+{
+    void *ptr;
+
+    /*
+     * Init ebmalloc_free on runtime. Static initialization
+     * will not work because it puts virtual address there.
Quoted 8 lines
Quoted 1 line

+ */

I don't understand this static allocation comment: We have this issue elsewhere (and use bootsym() as needed), and we do not have this issue at all in xen.efi (which this code also gets built for). So I think at the very least the comment needs improvement. And then, if static initialization indeed can't be used, then a static symbol's initializer of NULL is pointless and hence should be omitted.

You have to remember that xen/arch/x86/efi/efi-boot.h stuff is build into xen.efi and xen.gz. Of course xen.efi with

static char __initdata *ebmalloc_free = ebmalloc_mem;

works, however, xen.gz does not. Sadly, I have not found simpler solution for that issue, so, I do initialization during runtime.

Quoted 9 lines

xen/arch/x86/efi/efi-boot.h static void __init relocate_trampoline(unsigned long phys) · line 125

Quoted 6 lines
xen/arch/x86/efi/efi-boot.h +6 -0
+    if ( ebmalloc_free == NULL )
+        ebmalloc_free = ebmalloc_mem;
+
+    ptr = ebmalloc_free;
+
+    ebmalloc_free += size;

No minimal (at least pointer size) alignment getting enforced somewhere here?

For what?

Quoted 12 lines
Quoted 12 lines
xen/arch/x86/efi/efi-boot.h +12 -0
+void __init free_ebmalloc_unused_mem(void)
+{
+    unsigned long start, end;
+
+    if ( ebmalloc_free )
+    {
+        start = (unsigned long)ebmalloc_free - xen_phys_start;
+        start = PAGE_ALIGN(start + XEN_VIRT_START);
+    }
+    else
+        start = (unsigned long)ebmalloc_mem;
+
Quoted 8 lines

xen/arch/x86/efi/efi-boot.h static void __init relocate_trampoline(unsigned long phys) · line 150

Quoted 6 lines
xen/arch/x86/efi/efi-boot.h +6 -0
+    end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem);
+
+    destroy_xen_mappings(start, end);
+    init_xenheap_pages(__pa(start), __pa(end));
+
+    printk("Freed %lukB unused BSS memory\n", (end - start) >> 10);

XENLOG_INFO

OK.

Quoted 3 lines

And then - wouldn't this better go into xen/common/efi/boot.c, even if ARM64 does not have a use for it right away? The code certainly isn't really x86-specific.

Sure thing. However, if it is not used by ARM64 then I think ebmalloc stuff should not be moved to xen/common/efi/boot.c.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#39 lore raw

Re: [PATCH v5 12/16] x86/efi: create new early memory allocator

Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 07.09.16 at 14:05, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/efi/efi-boot.h +10 -0
+static char __initdata *ebmalloc_free = NULL;
+
+/* EFI boot allocator. */
+static void __init *ebmalloc(size_t size)
+{
+    void *ptr;
+
+    /*
+     * Init ebmalloc_free on runtime. Static initialization
+     * will not work because it puts virtual address there.
Quoted 8 lines
Quoted 1 line

+ */

I don't understand this static allocation comment: We have this issue elsewhere (and use bootsym() as needed), and we do not have this issue at all in xen.efi (which this code also gets built for). So I think at the very least the comment needs improvement. And then, if static initialization indeed can't be used, then a static symbol's initializer of NULL is pointless and hence should be omitted.

Quoted 7 lines

You have to remember that xen/arch/x86/efi/efi-boot.h stuff is build into xen.efi and xen.gz. Of course xen.efi with

static char __initdata *ebmalloc_free = ebmalloc_mem;

works, however, xen.gz does not. Sadly, I have not found simpler solution for that issue, so, I do initialization during runtime.

Which all is in line with my request of improving the comment.

Quoted 11 lines
Quoted 9 lines

xen/arch/x86/efi/efi-boot.h static void __init relocate_trampoline(unsigned long phys) · line 125

Quoted 6 lines
xen/arch/x86/efi/efi-boot.h +6 -0
+    if ( ebmalloc_free == NULL )
+        ebmalloc_free = ebmalloc_mem;
+
+    ptr = ebmalloc_free;
+
+    ebmalloc_free += size;

No minimal (at least pointer size) alignment getting enforced somewhere here?

For what?

To avoid the penalty unaligned accesses incur? And that's alongside the fact that it's simply bad practice to knowingly but without actual need cause unaligned accesses even if they work fine.

Quoted 6 lines
Quoted 3 lines

And then - wouldn't this better go into xen/common/efi/boot.c, even if ARM64 does not have a use for it right away? The code certainly isn't really x86-specific.

Sure thing. However, if it is not used by ARM64 then I think ebmalloc stuff should not be moved to xen/common/efi/boot.c.

Being architecture independent it has all reasons to be moved there. Agreed there may be compiler warnings for these then being unused static functions, but I'd rather see this code get #ifdef-ed out for ARM for the time being than it needing to be moved over later on. And of course a question to be asked first is whether in fact there is something in common or ARM specific code that could benefit from using this new allocator, if you already introduce it.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#40 lore raw

Re: [PATCH v5 12/16] x86/efi: create new early memory allocator

Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 07.09.16 at 14:05, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/efi/efi-boot.h +10 -0
+static char __initdata *ebmalloc_free = NULL;
+
+/* EFI boot allocator. */
+static void __init *ebmalloc(size_t size)
+{
+    void *ptr;
+
+    /*
+     * Init ebmalloc_free on runtime. Static initialization
+     * will not work because it puts virtual address there.
Quoted 8 lines
Quoted 1 line

+ */

I don't understand this static allocation comment: We have this issue elsewhere (and use bootsym() as needed), and we do not have this issue at all in xen.efi (which this code also gets built for). So I think at the very least the comment needs improvement. And then, if static initialization indeed can't be used, then a static symbol's initializer of NULL is pointless and hence should be omitted.

You have to remember that xen/arch/x86/efi/efi-boot.h stuff is build into xen.efi and xen.gz. Of course xen.efi with

Quoted 6 lines
Quoted 4 lines

static char __initdata *ebmalloc_free = ebmalloc_mem;

works, however, xen.gz does not. Sadly, I have not found simpler solution for that issue, so, I do initialization during runtime.

Which all is in line with my request of improving the comment.

OK.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

xen/arch/x86/efi/efi-boot.h static void __init relocate_trampoline(unsigned long phys) · line 125

Quoted 6 lines
xen/arch/x86/efi/efi-boot.h +6 -0
+    if ( ebmalloc_free == NULL )
+        ebmalloc_free = ebmalloc_mem;
+
+    ptr = ebmalloc_free;
+
+    ebmalloc_free += size;

No minimal (at least pointer size) alignment getting enforced somewhere here?

Quoted 5 lines
Quoted 1 line

For what?

To avoid the penalty unaligned accesses incur? And that's alongside the fact that it's simply bad practice to knowingly but without actual need cause unaligned accesses even if they work fine.

I expected that but I do not think it is very important here. Anyway, I am still not sure why you say "at least pointer size". Because sizeof(void *) assures proper alignment on any architecture? Additionally, will this alignment sufficiently replace alignment provided by current efi_arch_allocate_mmap_buffer() implementation?

Quoted 11 lines
Quoted 6 lines
Quoted 3 lines

And then - wouldn't this better go into xen/common/efi/boot.c, even if ARM64 does not have a use for it right away? The code certainly isn't really x86-specific.

Sure thing. However, if it is not used by ARM64 then I think ebmalloc stuff should not be moved to xen/common/efi/boot.c.

Being architecture independent it has all reasons to be moved there. Agreed there may be compiler warnings for these then being unused static functions, but I'd rather see this code get #ifdef-ed out for ARM for the time being than it needing to be

OK.

Quoted 4 lines

moved over later on. And of course a question to be asked first is whether in fact there is something in common or ARM specific code that could benefit from using this new allocator, if you already introduce it.

I think that it is x86 specific stuff and should stay here as is. However, potentially it can be common allocator for both architectures. Though I do not see gains on ARM itself.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#41 lore raw

Re: [PATCH v5 12/16] x86/efi: create new early memory allocator

Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 08.09.16 at 10:29, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 07.09.16 at 14:05, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich

xen/arch/x86/efi/efi-boot.h static void __init relocate_trampoline(unsigned long phys) · line 125

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.08.16 at 00:43, <[email protected]> wrote:
xen/arch/x86/efi/efi-boot.h +6 -0
+    if ( ebmalloc_free == NULL )
+        ebmalloc_free = ebmalloc_mem;
+
+    ptr = ebmalloc_free;
+
+    ebmalloc_free += size;

No minimal (at least pointer size) alignment getting enforced somewhere here?

For what?

Quoted 7 lines
Quoted 3 lines

To avoid the penalty unaligned accesses incur? And that's alongside the fact that it's simply bad practice to knowingly but without actual need cause unaligned accesses even if they work fine.

I expected that but I do not think it is very important here. Anyway, I am still not sure why you say "at least pointer size". Because sizeof(void *) assures proper alignment on any architecture?

Yes, this gives (on "normal" architectures at least) machine word size alignment, which commonly is good enough for everything except SIMD data (or things similar to it).

Quoted 2 lines

Additionally, will this alignment sufficiently replace alignment provided by current efi_arch_allocate_mmap_buffer() implementation?

Just compare __alignof__(EFI_MEMORY_DESCRIPTOR) and __alignof__(void *).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel