All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues
@ 2015-07-20 14:35 Daniel Kiper
  2015-07-20 14:35 ` [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files Daniel Kiper
                   ` (13 more replies)
  0 siblings, 14 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Hi,

This patch series:
  - enables EFI boot services usage in loaded images
    by multiboot2 protocol,
  - add support for multiboot2 protocol compatible
    relocatable images,
  - fixes two minor issues.

Daniel

 .gitignore                            |    3 ++
 grub-core/Makefile.core.def           |    1 +
 grub-core/lib/i386/relocator.c        |   53 +++++++++++++++++++++
 grub-core/lib/i386/relocator64_efi.S  |   77 ++++++++++++++++++++++++++++++
 grub-core/lib/relocator.c             |    2 +-
 grub-core/loader/i386/multiboot_mbi.c |    6 ++-
 grub-core/loader/multiboot.c          |   41 +++++++++++++---
 grub-core/loader/multiboot_elfxx.c    |   28 ++++++++---
 grub-core/loader/multiboot_mbi2.c     |  199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
 include/grub/i386/multiboot.h         |   11 +++++
 include/grub/i386/relocator.h         |   21 +++++++++
 include/grub/multiboot.h              |    4 +-
 include/multiboot2.h                  |   49 +++++++++++++++++++
 13 files changed, 423 insertions(+), 72 deletions(-)

Daniel Kiper (6):
      gitignore: Ignore *.orig, *.rej and *.swp files
      relocator: Do not use memory region if its starta is smaller than size
      i386/relocator: Add grub_relocator64_efi relocator
      multiboot2: Add tags used to pass ImageHandle to loaded image
      multiboot2: Add support for relocatable images
      multiboot2: Do not pass memory maps to image if EFI boot services are enabled



^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
@ 2015-07-20 14:35 ` Daniel Kiper
  2015-07-20 14:35 ` Daniel Kiper
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 .gitignore |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/.gitignore b/.gitignore
index 18ab8e8..6d25d39 100644
--- a/.gitignore
+++ b/.gitignore
@@ -147,6 +147,7 @@ mod-*.c
 missing
 netboot_test
 *.o
+*.orig
 *.a
 ohci_test
 partmap_test
@@ -160,9 +161,11 @@ po/stamp-po
 printf_test
 priority_queue_unit_test
 pseries_test
+*.rej
 stamp-h
 stamp-h1
 stamp-h.in
+*.swp
 symlist.c
 symlist.h
 trigtables.c
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 67+ messages in thread

* [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
  2015-07-20 14:35 ` [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files Daniel Kiper
@ 2015-07-20 14:35 ` Daniel Kiper
  2015-08-11 17:00   ` Konrad Rzeszutek Wilk
                     ` (3 more replies)
  2015-07-20 14:35 ` [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size Daniel Kiper
                   ` (11 subsequent siblings)
  13 siblings, 4 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 .gitignore |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/.gitignore b/.gitignore
index 18ab8e8..6d25d39 100644
--- a/.gitignore
+++ b/.gitignore
@@ -147,6 +147,7 @@ mod-*.c
 missing
 netboot_test
 *.o
+*.orig
 *.a
 ohci_test
 partmap_test
@@ -160,9 +161,11 @@ po/stamp-po
 printf_test
 priority_queue_unit_test
 pseries_test
+*.rej
 stamp-h
 stamp-h1
 stamp-h.in
+*.swp
 symlist.c
 symlist.h
 trigtables.c
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 67+ messages in thread

* [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
  2015-07-20 14:35 ` [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files Daniel Kiper
  2015-07-20 14:35 ` Daniel Kiper
@ 2015-07-20 14:35 ` Daniel Kiper
  2015-07-20 14:35 ` Daniel Kiper
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

malloc_in_range() should not use memory region if its starta is smaller
than size. Otherwise target wraps around and points to region which is
usually not a RAM, e.g.:

loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000
lib/relocator.c:1241: min_addr = 0x0, max_addr = 0xffffffffffffffff, target = 0x800000
lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned 0x1 size 0x3f800000
lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned 0x1 size 0x3f800000
lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned 0x1 size 0x3f800000
lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000
lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 grub-core/lib/relocator.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
index f759c7f..4eee0c5 100644
--- a/grub-core/lib/relocator.c
+++ b/grub-core/lib/relocator.c
@@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,
 	      /* Found an usable address.  */
 	      goto found;
 	  }
-	if (isinsidebefore && !isinsideafter && !from_low_priv)
+	if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size)
 	  {
 	    target = starta - size;
 	    if (target > end - size)
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 67+ messages in thread

* [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
                   ` (2 preceding siblings ...)
  2015-07-20 14:35 ` [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size Daniel Kiper
@ 2015-07-20 14:35 ` Daniel Kiper
  2015-07-21  6:42   ` Andrei Borzenkov
                     ` (3 more replies)
  2015-07-20 14:35 ` [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator Daniel Kiper
                   ` (9 subsequent siblings)
  13 siblings, 4 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

malloc_in_range() should not use memory region if its starta is smaller
than size. Otherwise target wraps around and points to region which is
usually not a RAM, e.g.:

loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000
lib/relocator.c:1241: min_addr = 0x0, max_addr = 0xffffffffffffffff, target = 0x800000
lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned 0x1 size 0x3f800000
lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned 0x1 size 0x3f800000
lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned 0x1 size 0x3f800000
lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000
lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 grub-core/lib/relocator.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
index f759c7f..4eee0c5 100644
--- a/grub-core/lib/relocator.c
+++ b/grub-core/lib/relocator.c
@@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,
 	      /* Found an usable address.  */
 	      goto found;
 	  }
-	if (isinsidebefore && !isinsideafter && !from_low_priv)
+	if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size)
 	  {
 	    target = starta - size;
 	    if (target > end - size)
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 67+ messages in thread

* [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
                   ` (3 preceding siblings ...)
  2015-07-20 14:35 ` Daniel Kiper
@ 2015-07-20 14:35 ` Daniel Kiper
  2015-07-20 14:35 ` Daniel Kiper
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Add grub_relocator64_efi relocator. It will be used on EFI 64-bit platforms
when multiboot2 compatible image requests MULTIBOOT_TAG_TYPE_EFI_BS. Relocator
will set lower parts of %rax and %rbx accordingly to multiboot2 specification.
On the other hand processor mode, just before jumping into loaded image, will
be set accordingly to Unified Extensible Firmware Interface Specification,
Version 2.4 Errata B, section 2.3.4, x64 Platforms, boot services. This way
loaded image will be able to use EFI boot services without any issues.

If idea is accepted I will prepare grub_relocator32_efi relocator too.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 grub-core/Makefile.core.def          |    1 +
 grub-core/lib/i386/relocator.c       |   53 +++++++++++++++++++++++
 grub-core/lib/i386/relocator64_efi.S |   77 ++++++++++++++++++++++++++++++++++
 grub-core/loader/multiboot.c         |   29 +++++++++++--
 grub-core/loader/multiboot_mbi2.c    |   19 +++++++--
 include/grub/i386/multiboot.h        |   11 +++++
 include/grub/i386/relocator.h        |   21 ++++++++++
 include/multiboot2.h                 |    9 ++++
 8 files changed, 213 insertions(+), 7 deletions(-)
 create mode 100644 grub-core/lib/i386/relocator64_efi.S

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index a6101de..d583549 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1519,6 +1519,7 @@ module = {
   x86 = lib/i386/relocator_common_c.c;
   ieee1275 = lib/ieee1275/relocator.c;
   efi = lib/efi/relocator.c;
+  x86_64_efi = lib/i386/relocator64_efi.S;
   mips = lib/mips/relocator_asm.S;
   mips = lib/mips/relocator.c;
   powerpc = lib/powerpc/relocator_asm.S;
diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c
index 71dd4f0..459027e 100644
--- a/grub-core/lib/i386/relocator.c
+++ b/grub-core/lib/i386/relocator.c
@@ -69,6 +69,19 @@ extern grub_uint64_t grub_relocator64_rsi;
 extern grub_addr_t grub_relocator64_cr3;
 extern struct grub_i386_idt grub_relocator16_idt;
 
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+extern grub_uint8_t grub_relocator64_efi_start;
+extern grub_uint8_t grub_relocator64_efi_end;
+extern grub_uint64_t grub_relocator64_efi_rax;
+extern grub_uint64_t grub_relocator64_efi_rbx;
+extern grub_uint64_t grub_relocator64_efi_rcx;
+extern grub_uint64_t grub_relocator64_efi_rdx;
+extern grub_uint64_t grub_relocator64_efi_rip;
+extern grub_uint64_t grub_relocator64_efi_rsi;
+#endif
+#endif
+
 #define RELOCATOR_SIZEOF(x)	(&grub_relocator##x##_end - &grub_relocator##x##_start)
 
 grub_err_t
@@ -214,3 +227,43 @@ grub_relocator64_boot (struct grub_relocator *rel,
   /* Not reached.  */
   return GRUB_ERR_NONE;
 }
+
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+grub_err_t
+grub_relocator64_efi_boot (struct grub_relocator *rel,
+			   struct grub_relocator64_efi_state state)
+{
+  grub_err_t err;
+  void *relst;
+  grub_relocator_chunk_t ch;
+
+  err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
+					  0x40000000 - RELOCATOR_SIZEOF (64_efi),
+					  RELOCATOR_SIZEOF (64_efi), 16,
+					  GRUB_RELOCATOR_PREFERENCE_NONE, 1);
+  if (err)
+    return err;
+
+  grub_relocator64_efi_rax = state.rax;
+  grub_relocator64_efi_rbx = state.rbx;
+  grub_relocator64_efi_rcx = state.rcx;
+  grub_relocator64_efi_rdx = state.rdx;
+  grub_relocator64_efi_rip = state.rip;
+  grub_relocator64_efi_rsi = state.rsi;
+
+  grub_memmove (get_virtual_current_address (ch), &grub_relocator64_efi_start,
+		RELOCATOR_SIZEOF (64_efi));
+
+  err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch),
+				       &relst, NULL);
+  if (err)
+    return err;
+
+  ((void (*) (void)) relst) ();
+
+  /* Not reached.  */
+  return GRUB_ERR_NONE;
+}
+#endif
+#endif
diff --git a/grub-core/lib/i386/relocator64_efi.S b/grub-core/lib/i386/relocator64_efi.S
new file mode 100644
index 0000000..fcd1964
--- /dev/null
+++ b/grub-core/lib/i386/relocator64_efi.S
@@ -0,0 +1,77 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009,2010  Free Software Foundation, Inc.
+ *  Copyright (C) 2014,2015  Oracle Co.
+ *      Author: Daniel Kiper
+ *
+ *  GRUB 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB 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 GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "relocator_common.S"
+
+	.p2align	4	/* force 16-byte alignment */
+
+VARIABLE(grub_relocator64_efi_start)
+	PREAMBLE
+
+	.code64
+
+	/* mov imm64, %rax */
+	.byte 	0x48
+	.byte	0xb8
+VARIABLE(grub_relocator64_efi_rsi)
+	.quad	0
+
+	movq	%rax, %rsi
+
+	/* mov imm64, %rax */
+	.byte 	0x48
+	.byte	0xb8
+VARIABLE(grub_relocator64_efi_rax)
+	.quad	0
+
+	/* mov imm64, %rbx */
+	.byte 	0x48
+	.byte	0xbb
+VARIABLE(grub_relocator64_efi_rbx)
+	.quad	0
+
+	/* mov imm64, %rcx */
+	.byte 	0x48
+	.byte	0xb9
+VARIABLE(grub_relocator64_efi_rcx)
+	.quad	0
+
+	/* mov imm64, %rdx */
+	.byte 	0x48
+	.byte	0xba
+VARIABLE(grub_relocator64_efi_rdx)
+	.quad	0
+
+	/* Cleared direction flag is of no problem with any current
+	   payload and makes this implementation easier.  */
+	cld
+
+#ifdef __APPLE__
+	.byte 0xff, 0x25
+	.quad 0
+#else
+	jmp *LOCAL(jump_addr) (%rip)
+#endif
+
+LOCAL(jump_addr):
+VARIABLE(grub_relocator64_efi_rip)
+	.quad	0
+
+VARIABLE(grub_relocator64_efi_end)
diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
index fd8f28e..ca7154f 100644
--- a/grub-core/loader/multiboot.c
+++ b/grub-core/loader/multiboot.c
@@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)
   return err;
 }
 
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+#define grub_relocator_efi_boot	grub_relocator64_efi_boot
+#endif
+#endif
+
 static grub_err_t
 grub_multiboot_boot (void)
 {
   grub_err_t err;
+  grub_uint32_t target;
   struct grub_relocator32_state state = MULTIBOOT_INITIAL_STATE;
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+  struct grub_relocator64_efi_state state_efi = MULTIBOOT_EFI_INITIAL_STATE;
+#endif
+#endif
 
-  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
-
-  err = grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER);
+  err = grub_multiboot_make_mbi (&target);
 
   if (err)
     return err;
 
+  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
+  state.MULTIBOOT_MBI_REGISTER = target;
+
 #if defined (__i386__) || defined (__x86_64__)
+#ifdef GRUB_MACHINE_EFI
+  state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip;
+  state_efi.MULTIBOOT_EFI_MBI_REGISTER = target;
+
+  if (grub_efi_is_finished)
+    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
+  else
+    grub_relocator_efi_boot (grub_multiboot_relocator, state_efi);
+#else
   grub_relocator32_boot (grub_multiboot_relocator, state, 0);
+#endif
 #else
   grub_relocator32_boot (grub_multiboot_relocator, state);
 #endif
diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
index d7c19bc..8d66e3f 100644
--- a/grub-core/loader/multiboot_mbi2.c
+++ b/grub-core/loader/multiboot_mbi2.c
@@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
   grub_err_t err;
   struct multiboot_header_tag *tag;
   struct multiboot_header_tag_address *addr_tag = NULL;
-  int entry_specified = 0;
-  grub_addr_t entry = 0;
+  int entry_specified = 0, efi_entry_specified = 0;
+  grub_addr_t entry = 0, efi_entry = 0;
   grub_uint32_t console_required = 0;
   struct multiboot_header_tag_framebuffer *fbtag = NULL;
   int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
@@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;
 	break;
 
+      case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64:
+#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__)
+	efi_entry_specified = 1;
+	efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr;
+#endif
+	break;
+
       case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS:
 	if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags
 	    & MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED))
@@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	break;
 
       case MULTIBOOT_HEADER_TAG_EFI_BS:
+#ifdef GRUB_MACHINE_EFI
 	keep_bs = 1;
+#endif
 	break;
 
       default:
@@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	break;
       }
 
-  if (addr_tag && !entry_specified)
+  if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified))
     {
       grub_free (buffer);
       return grub_error (GRUB_ERR_UNKNOWN_OS,
@@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	}
     }
 
-  if (entry_specified)
+  if (keep_bs && efi_entry_specified)
+    grub_multiboot_payload_eip = efi_entry;
+  else if (entry_specified)
     grub_multiboot_payload_eip = entry;
 
   if (fbtag)
diff --git a/include/grub/i386/multiboot.h b/include/grub/i386/multiboot.h
index a1b9488..807a1de 100644
--- a/include/grub/i386/multiboot.h
+++ b/include/grub/i386/multiboot.h
@@ -30,6 +30,17 @@
 #define MULTIBOOT_MBI_REGISTER ebx
 #define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_I386
 
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+#define MULTIBOOT_EFI_INITIAL_STATE  { .rax = MULTIBOOT_BOOTLOADER_MAGIC,	\
+    .rcx = 0,									\
+    .rdx = 0,									\
+      }
+#define MULTIBOOT_EFI_ENTRY_REGISTER rip
+#define MULTIBOOT_EFI_MBI_REGISTER rbx
+#endif
+#endif
+
 #define MULTIBOOT_ELF32_MACHINE EM_386
 #define MULTIBOOT_ELF64_MACHINE EM_X86_64
 
diff --git a/include/grub/i386/relocator.h b/include/grub/i386/relocator.h
index 5f89a7e..2a56c3b 100644
--- a/include/grub/i386/relocator.h
+++ b/include/grub/i386/relocator.h
@@ -65,6 +65,20 @@ struct grub_relocator64_state
   grub_addr_t cr3;
 };
 
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+struct grub_relocator64_efi_state
+{
+  grub_uint64_t rax;
+  grub_uint64_t rbx;
+  grub_uint64_t rcx;
+  grub_uint64_t rdx;
+  grub_uint64_t rip;
+  grub_uint64_t rsi;
+};
+#endif
+#endif
+
 grub_err_t grub_relocator16_boot (struct grub_relocator *rel,
 				  struct grub_relocator16_state state);
 
@@ -76,4 +90,11 @@ grub_err_t grub_relocator64_boot (struct grub_relocator *rel,
 				  struct grub_relocator64_state state,
 				  grub_addr_t min_addr, grub_addr_t max_addr);
 
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel,
+				      struct grub_relocator64_efi_state state);
+#endif
+#endif
+
 #endif /* ! GRUB_RELOCATOR_CPU_HEADER */
diff --git a/include/multiboot2.h b/include/multiboot2.h
index 9d48627..b3977e3 100644
--- a/include/multiboot2.h
+++ b/include/multiboot2.h
@@ -69,6 +69,7 @@
 #define MULTIBOOT_HEADER_TAG_FRAMEBUFFER  5
 #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
 #define MULTIBOOT_HEADER_TAG_EFI_BS  7
+#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
 
 #define MULTIBOOT_ARCHITECTURE_I386  0
 #define MULTIBOOT_ARCHITECTURE_MIPS32  4
@@ -133,6 +134,14 @@ struct multiboot_header_tag_entry_address
   multiboot_uint32_t entry_addr;
 };
 
+struct multiboot_header_tag_entry_address_efi64
+{
+  multiboot_uint16_t type;
+  multiboot_uint16_t flags;
+  multiboot_uint32_t size;
+  multiboot_uint32_t entry_addr;
+};
+
 struct multiboot_header_tag_console_flags
 {
   multiboot_uint16_t type;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 67+ messages in thread

* [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
                   ` (4 preceding siblings ...)
  2015-07-20 14:35 ` [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator Daniel Kiper
@ 2015-07-20 14:35 ` Daniel Kiper
  2015-08-11 17:02     ` Konrad Rzeszutek Wilk
                     ` (2 more replies)
  2015-07-20 14:35 ` [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image Daniel Kiper
                   ` (7 subsequent siblings)
  13 siblings, 3 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Add grub_relocator64_efi relocator. It will be used on EFI 64-bit platforms
when multiboot2 compatible image requests MULTIBOOT_TAG_TYPE_EFI_BS. Relocator
will set lower parts of %rax and %rbx accordingly to multiboot2 specification.
On the other hand processor mode, just before jumping into loaded image, will
be set accordingly to Unified Extensible Firmware Interface Specification,
Version 2.4 Errata B, section 2.3.4, x64 Platforms, boot services. This way
loaded image will be able to use EFI boot services without any issues.

If idea is accepted I will prepare grub_relocator32_efi relocator too.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 grub-core/Makefile.core.def          |    1 +
 grub-core/lib/i386/relocator.c       |   53 +++++++++++++++++++++++
 grub-core/lib/i386/relocator64_efi.S |   77 ++++++++++++++++++++++++++++++++++
 grub-core/loader/multiboot.c         |   29 +++++++++++--
 grub-core/loader/multiboot_mbi2.c    |   19 +++++++--
 include/grub/i386/multiboot.h        |   11 +++++
 include/grub/i386/relocator.h        |   21 ++++++++++
 include/multiboot2.h                 |    9 ++++
 8 files changed, 213 insertions(+), 7 deletions(-)
 create mode 100644 grub-core/lib/i386/relocator64_efi.S

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index a6101de..d583549 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1519,6 +1519,7 @@ module = {
   x86 = lib/i386/relocator_common_c.c;
   ieee1275 = lib/ieee1275/relocator.c;
   efi = lib/efi/relocator.c;
+  x86_64_efi = lib/i386/relocator64_efi.S;
   mips = lib/mips/relocator_asm.S;
   mips = lib/mips/relocator.c;
   powerpc = lib/powerpc/relocator_asm.S;
diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c
index 71dd4f0..459027e 100644
--- a/grub-core/lib/i386/relocator.c
+++ b/grub-core/lib/i386/relocator.c
@@ -69,6 +69,19 @@ extern grub_uint64_t grub_relocator64_rsi;
 extern grub_addr_t grub_relocator64_cr3;
 extern struct grub_i386_idt grub_relocator16_idt;
 
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+extern grub_uint8_t grub_relocator64_efi_start;
+extern grub_uint8_t grub_relocator64_efi_end;
+extern grub_uint64_t grub_relocator64_efi_rax;
+extern grub_uint64_t grub_relocator64_efi_rbx;
+extern grub_uint64_t grub_relocator64_efi_rcx;
+extern grub_uint64_t grub_relocator64_efi_rdx;
+extern grub_uint64_t grub_relocator64_efi_rip;
+extern grub_uint64_t grub_relocator64_efi_rsi;
+#endif
+#endif
+
 #define RELOCATOR_SIZEOF(x)	(&grub_relocator##x##_end - &grub_relocator##x##_start)
 
 grub_err_t
@@ -214,3 +227,43 @@ grub_relocator64_boot (struct grub_relocator *rel,
   /* Not reached.  */
   return GRUB_ERR_NONE;
 }
+
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+grub_err_t
+grub_relocator64_efi_boot (struct grub_relocator *rel,
+			   struct grub_relocator64_efi_state state)
+{
+  grub_err_t err;
+  void *relst;
+  grub_relocator_chunk_t ch;
+
+  err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
+					  0x40000000 - RELOCATOR_SIZEOF (64_efi),
+					  RELOCATOR_SIZEOF (64_efi), 16,
+					  GRUB_RELOCATOR_PREFERENCE_NONE, 1);
+  if (err)
+    return err;
+
+  grub_relocator64_efi_rax = state.rax;
+  grub_relocator64_efi_rbx = state.rbx;
+  grub_relocator64_efi_rcx = state.rcx;
+  grub_relocator64_efi_rdx = state.rdx;
+  grub_relocator64_efi_rip = state.rip;
+  grub_relocator64_efi_rsi = state.rsi;
+
+  grub_memmove (get_virtual_current_address (ch), &grub_relocator64_efi_start,
+		RELOCATOR_SIZEOF (64_efi));
+
+  err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch),
+				       &relst, NULL);
+  if (err)
+    return err;
+
+  ((void (*) (void)) relst) ();
+
+  /* Not reached.  */
+  return GRUB_ERR_NONE;
+}
+#endif
+#endif
diff --git a/grub-core/lib/i386/relocator64_efi.S b/grub-core/lib/i386/relocator64_efi.S
new file mode 100644
index 0000000..fcd1964
--- /dev/null
+++ b/grub-core/lib/i386/relocator64_efi.S
@@ -0,0 +1,77 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009,2010  Free Software Foundation, Inc.
+ *  Copyright (C) 2014,2015  Oracle Co.
+ *      Author: Daniel Kiper
+ *
+ *  GRUB 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB 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 GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "relocator_common.S"
+
+	.p2align	4	/* force 16-byte alignment */
+
+VARIABLE(grub_relocator64_efi_start)
+	PREAMBLE
+
+	.code64
+
+	/* mov imm64, %rax */
+	.byte 	0x48
+	.byte	0xb8
+VARIABLE(grub_relocator64_efi_rsi)
+	.quad	0
+
+	movq	%rax, %rsi
+
+	/* mov imm64, %rax */
+	.byte 	0x48
+	.byte	0xb8
+VARIABLE(grub_relocator64_efi_rax)
+	.quad	0
+
+	/* mov imm64, %rbx */
+	.byte 	0x48
+	.byte	0xbb
+VARIABLE(grub_relocator64_efi_rbx)
+	.quad	0
+
+	/* mov imm64, %rcx */
+	.byte 	0x48
+	.byte	0xb9
+VARIABLE(grub_relocator64_efi_rcx)
+	.quad	0
+
+	/* mov imm64, %rdx */
+	.byte 	0x48
+	.byte	0xba
+VARIABLE(grub_relocator64_efi_rdx)
+	.quad	0
+
+	/* Cleared direction flag is of no problem with any current
+	   payload and makes this implementation easier.  */
+	cld
+
+#ifdef __APPLE__
+	.byte 0xff, 0x25
+	.quad 0
+#else
+	jmp *LOCAL(jump_addr) (%rip)
+#endif
+
+LOCAL(jump_addr):
+VARIABLE(grub_relocator64_efi_rip)
+	.quad	0
+
+VARIABLE(grub_relocator64_efi_end)
diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
index fd8f28e..ca7154f 100644
--- a/grub-core/loader/multiboot.c
+++ b/grub-core/loader/multiboot.c
@@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)
   return err;
 }
 
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+#define grub_relocator_efi_boot	grub_relocator64_efi_boot
+#endif
+#endif
+
 static grub_err_t
 grub_multiboot_boot (void)
 {
   grub_err_t err;
+  grub_uint32_t target;
   struct grub_relocator32_state state = MULTIBOOT_INITIAL_STATE;
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+  struct grub_relocator64_efi_state state_efi = MULTIBOOT_EFI_INITIAL_STATE;
+#endif
+#endif
 
-  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
-
-  err = grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER);
+  err = grub_multiboot_make_mbi (&target);
 
   if (err)
     return err;
 
+  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
+  state.MULTIBOOT_MBI_REGISTER = target;
+
 #if defined (__i386__) || defined (__x86_64__)
+#ifdef GRUB_MACHINE_EFI
+  state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip;
+  state_efi.MULTIBOOT_EFI_MBI_REGISTER = target;
+
+  if (grub_efi_is_finished)
+    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
+  else
+    grub_relocator_efi_boot (grub_multiboot_relocator, state_efi);
+#else
   grub_relocator32_boot (grub_multiboot_relocator, state, 0);
+#endif
 #else
   grub_relocator32_boot (grub_multiboot_relocator, state);
 #endif
diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
index d7c19bc..8d66e3f 100644
--- a/grub-core/loader/multiboot_mbi2.c
+++ b/grub-core/loader/multiboot_mbi2.c
@@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
   grub_err_t err;
   struct multiboot_header_tag *tag;
   struct multiboot_header_tag_address *addr_tag = NULL;
-  int entry_specified = 0;
-  grub_addr_t entry = 0;
+  int entry_specified = 0, efi_entry_specified = 0;
+  grub_addr_t entry = 0, efi_entry = 0;
   grub_uint32_t console_required = 0;
   struct multiboot_header_tag_framebuffer *fbtag = NULL;
   int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
@@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;
 	break;
 
+      case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64:
+#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__)
+	efi_entry_specified = 1;
+	efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr;
+#endif
+	break;
+
       case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS:
 	if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags
 	    & MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED))
@@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	break;
 
       case MULTIBOOT_HEADER_TAG_EFI_BS:
+#ifdef GRUB_MACHINE_EFI
 	keep_bs = 1;
+#endif
 	break;
 
       default:
@@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	break;
       }
 
-  if (addr_tag && !entry_specified)
+  if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified))
     {
       grub_free (buffer);
       return grub_error (GRUB_ERR_UNKNOWN_OS,
@@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	}
     }
 
-  if (entry_specified)
+  if (keep_bs && efi_entry_specified)
+    grub_multiboot_payload_eip = efi_entry;
+  else if (entry_specified)
     grub_multiboot_payload_eip = entry;
 
   if (fbtag)
diff --git a/include/grub/i386/multiboot.h b/include/grub/i386/multiboot.h
index a1b9488..807a1de 100644
--- a/include/grub/i386/multiboot.h
+++ b/include/grub/i386/multiboot.h
@@ -30,6 +30,17 @@
 #define MULTIBOOT_MBI_REGISTER ebx
 #define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_I386
 
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+#define MULTIBOOT_EFI_INITIAL_STATE  { .rax = MULTIBOOT_BOOTLOADER_MAGIC,	\
+    .rcx = 0,									\
+    .rdx = 0,									\
+      }
+#define MULTIBOOT_EFI_ENTRY_REGISTER rip
+#define MULTIBOOT_EFI_MBI_REGISTER rbx
+#endif
+#endif
+
 #define MULTIBOOT_ELF32_MACHINE EM_386
 #define MULTIBOOT_ELF64_MACHINE EM_X86_64
 
diff --git a/include/grub/i386/relocator.h b/include/grub/i386/relocator.h
index 5f89a7e..2a56c3b 100644
--- a/include/grub/i386/relocator.h
+++ b/include/grub/i386/relocator.h
@@ -65,6 +65,20 @@ struct grub_relocator64_state
   grub_addr_t cr3;
 };
 
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+struct grub_relocator64_efi_state
+{
+  grub_uint64_t rax;
+  grub_uint64_t rbx;
+  grub_uint64_t rcx;
+  grub_uint64_t rdx;
+  grub_uint64_t rip;
+  grub_uint64_t rsi;
+};
+#endif
+#endif
+
 grub_err_t grub_relocator16_boot (struct grub_relocator *rel,
 				  struct grub_relocator16_state state);
 
@@ -76,4 +90,11 @@ grub_err_t grub_relocator64_boot (struct grub_relocator *rel,
 				  struct grub_relocator64_state state,
 				  grub_addr_t min_addr, grub_addr_t max_addr);
 
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel,
+				      struct grub_relocator64_efi_state state);
+#endif
+#endif
+
 #endif /* ! GRUB_RELOCATOR_CPU_HEADER */
diff --git a/include/multiboot2.h b/include/multiboot2.h
index 9d48627..b3977e3 100644
--- a/include/multiboot2.h
+++ b/include/multiboot2.h
@@ -69,6 +69,7 @@
 #define MULTIBOOT_HEADER_TAG_FRAMEBUFFER  5
 #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
 #define MULTIBOOT_HEADER_TAG_EFI_BS  7
+#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
 
 #define MULTIBOOT_ARCHITECTURE_I386  0
 #define MULTIBOOT_ARCHITECTURE_MIPS32  4
@@ -133,6 +134,14 @@ struct multiboot_header_tag_entry_address
   multiboot_uint32_t entry_addr;
 };
 
+struct multiboot_header_tag_entry_address_efi64
+{
+  multiboot_uint16_t type;
+  multiboot_uint16_t flags;
+  multiboot_uint32_t size;
+  multiboot_uint32_t entry_addr;
+};
+
 struct multiboot_header_tag_console_flags
 {
   multiboot_uint16_t type;
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 67+ messages in thread

* [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
                   ` (5 preceding siblings ...)
  2015-07-20 14:35 ` Daniel Kiper
@ 2015-07-20 14:35 ` Daniel Kiper
  2015-07-20 14:35 ` Daniel Kiper
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Add tags used to pass ImageHandle to loaded image. It is used
by at least ExitBootServices() function.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 grub-core/loader/multiboot_mbi2.c |   46 +++++++++++++++++++++++++++++--------
 include/multiboot2.h              |   16 +++++++++++++
 2 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
index 8d66e3f..dc9c709 100644
--- a/grub-core/loader/multiboot_mbi2.c
+++ b/grub-core/loader/multiboot_mbi2.c
@@ -172,6 +172,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	      case MULTIBOOT_TAG_TYPE_NETWORK:
 	      case MULTIBOOT_TAG_TYPE_EFI_MMAP:
 	      case MULTIBOOT_TAG_TYPE_EFI_BS:
+	      case MULTIBOOT_TAG_TYPE_EFI32_IH:
+	      case MULTIBOOT_TAG_TYPE_EFI64_IH:
 		break;
 
 	      default:
@@ -407,16 +409,18 @@ grub_multiboot_get_mbi_size (void)
 		 + grub_get_multiboot_mmap_count ()
 		 * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN)
     + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN)
+#ifdef GRUB_MACHINE_EFI
     + ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN)
     + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi64_ih), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
+		+ efi_mmap_size, MULTIBOOT_TAG_ALIGN)
+#endif
     + ALIGN_UP (sizeof (struct multiboot_tag_old_acpi)
 		+ sizeof (struct grub_acpi_rsdp_v10), MULTIBOOT_TAG_ALIGN)
     + acpiv2_size ()
     + net_size ()
-#ifdef GRUB_MACHINE_EFI
-    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
-		+ efi_mmap_size, MULTIBOOT_TAG_ALIGN)
-#endif
     + sizeof (struct multiboot_tag_vbe) + MULTIBOOT_TAG_ALIGN - 1
     + sizeof (struct multiboot_tag_apm) + MULTIBOOT_TAG_ALIGN - 1;
 }
@@ -906,11 +910,35 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
 
   if (keep_bs)
     {
-      struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
-      tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
-      tag->size = sizeof (struct multiboot_tag);
-      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
-	/ sizeof (grub_properly_aligned_t);
+      {
+	struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
+	tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
+	tag->size = sizeof (struct multiboot_tag);
+	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	  / sizeof (grub_properly_aligned_t);
+      }
+
+#ifdef __x86_64__
+      {
+	struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig;
+	tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH;
+	tag->size = sizeof (*tag);
+	tag->pointer = (grub_addr_t) grub_efi_image_handle;
+	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	  / sizeof (grub_properly_aligned_t);
+      }
+#endif
+
+#ifdef __i386__
+      {
+	struct multiboot_tag_efi32_ih *tag = (struct multiboot_tag_efi32_ih *) ptrorig;
+	tag->type = MULTIBOOT_TAG_TYPE_EFI32_IH;
+	tag->size = sizeof (*tag);
+	tag->pointer = (grub_addr_t) grub_efi_image_handle;
+	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	  / sizeof (grub_properly_aligned_t);
+      }
+#endif
     }
 #endif
 
diff --git a/include/multiboot2.h b/include/multiboot2.h
index b3977e3..9f97ddc 100644
--- a/include/multiboot2.h
+++ b/include/multiboot2.h
@@ -60,6 +60,8 @@
 #define MULTIBOOT_TAG_TYPE_NETWORK           16
 #define MULTIBOOT_TAG_TYPE_EFI_MMAP          17
 #define MULTIBOOT_TAG_TYPE_EFI_BS            18
+#define MULTIBOOT_TAG_TYPE_EFI32_IH          19
+#define MULTIBOOT_TAG_TYPE_EFI64_IH          20
 
 #define MULTIBOOT_HEADER_TAG_END  0
 #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
@@ -379,6 +381,20 @@ struct multiboot_tag_efi_mmap
   multiboot_uint8_t efi_mmap[0];
 }; 
 
+struct multiboot_tag_efi32_ih
+{
+  multiboot_uint32_t type;
+  multiboot_uint32_t size;
+  multiboot_uint32_t pointer;
+};
+
+struct multiboot_tag_efi64_ih
+{
+  multiboot_uint32_t type;
+  multiboot_uint32_t size;
+  multiboot_uint64_t pointer;
+};
+
 #endif /* ! ASM_FILE */
 
 #endif /* ! MULTIBOOT_HEADER */
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 67+ messages in thread

* [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
                   ` (6 preceding siblings ...)
  2015-07-20 14:35 ` [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image Daniel Kiper
@ 2015-07-20 14:35 ` Daniel Kiper
  2015-08-11 18:38   ` Konrad Rzeszutek Wilk
                     ` (2 more replies)
  2015-07-20 14:35 ` [PATCH v2 5/6] multiboot2: Add support for relocatable images Daniel Kiper
                   ` (5 subsequent siblings)
  13 siblings, 3 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Add tags used to pass ImageHandle to loaded image. It is used
by at least ExitBootServices() function.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 grub-core/loader/multiboot_mbi2.c |   46 +++++++++++++++++++++++++++++--------
 include/multiboot2.h              |   16 +++++++++++++
 2 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
index 8d66e3f..dc9c709 100644
--- a/grub-core/loader/multiboot_mbi2.c
+++ b/grub-core/loader/multiboot_mbi2.c
@@ -172,6 +172,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	      case MULTIBOOT_TAG_TYPE_NETWORK:
 	      case MULTIBOOT_TAG_TYPE_EFI_MMAP:
 	      case MULTIBOOT_TAG_TYPE_EFI_BS:
+	      case MULTIBOOT_TAG_TYPE_EFI32_IH:
+	      case MULTIBOOT_TAG_TYPE_EFI64_IH:
 		break;
 
 	      default:
@@ -407,16 +409,18 @@ grub_multiboot_get_mbi_size (void)
 		 + grub_get_multiboot_mmap_count ()
 		 * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN)
     + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN)
+#ifdef GRUB_MACHINE_EFI
     + ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN)
     + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi64_ih), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
+		+ efi_mmap_size, MULTIBOOT_TAG_ALIGN)
+#endif
     + ALIGN_UP (sizeof (struct multiboot_tag_old_acpi)
 		+ sizeof (struct grub_acpi_rsdp_v10), MULTIBOOT_TAG_ALIGN)
     + acpiv2_size ()
     + net_size ()
-#ifdef GRUB_MACHINE_EFI
-    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
-		+ efi_mmap_size, MULTIBOOT_TAG_ALIGN)
-#endif
     + sizeof (struct multiboot_tag_vbe) + MULTIBOOT_TAG_ALIGN - 1
     + sizeof (struct multiboot_tag_apm) + MULTIBOOT_TAG_ALIGN - 1;
 }
@@ -906,11 +910,35 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
 
   if (keep_bs)
     {
-      struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
-      tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
-      tag->size = sizeof (struct multiboot_tag);
-      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
-	/ sizeof (grub_properly_aligned_t);
+      {
+	struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
+	tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
+	tag->size = sizeof (struct multiboot_tag);
+	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	  / sizeof (grub_properly_aligned_t);
+      }
+
+#ifdef __x86_64__
+      {
+	struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig;
+	tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH;
+	tag->size = sizeof (*tag);
+	tag->pointer = (grub_addr_t) grub_efi_image_handle;
+	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	  / sizeof (grub_properly_aligned_t);
+      }
+#endif
+
+#ifdef __i386__
+      {
+	struct multiboot_tag_efi32_ih *tag = (struct multiboot_tag_efi32_ih *) ptrorig;
+	tag->type = MULTIBOOT_TAG_TYPE_EFI32_IH;
+	tag->size = sizeof (*tag);
+	tag->pointer = (grub_addr_t) grub_efi_image_handle;
+	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	  / sizeof (grub_properly_aligned_t);
+      }
+#endif
     }
 #endif
 
diff --git a/include/multiboot2.h b/include/multiboot2.h
index b3977e3..9f97ddc 100644
--- a/include/multiboot2.h
+++ b/include/multiboot2.h
@@ -60,6 +60,8 @@
 #define MULTIBOOT_TAG_TYPE_NETWORK           16
 #define MULTIBOOT_TAG_TYPE_EFI_MMAP          17
 #define MULTIBOOT_TAG_TYPE_EFI_BS            18
+#define MULTIBOOT_TAG_TYPE_EFI32_IH          19
+#define MULTIBOOT_TAG_TYPE_EFI64_IH          20
 
 #define MULTIBOOT_HEADER_TAG_END  0
 #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
@@ -379,6 +381,20 @@ struct multiboot_tag_efi_mmap
   multiboot_uint8_t efi_mmap[0];
 }; 
 
+struct multiboot_tag_efi32_ih
+{
+  multiboot_uint32_t type;
+  multiboot_uint32_t size;
+  multiboot_uint32_t pointer;
+};
+
+struct multiboot_tag_efi64_ih
+{
+  multiboot_uint32_t type;
+  multiboot_uint32_t size;
+  multiboot_uint64_t pointer;
+};
+
 #endif /* ! ASM_FILE */
 
 #endif /* ! MULTIBOOT_HEADER */
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 67+ messages in thread

* [PATCH v2 5/6] multiboot2: Add support for relocatable images
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
                   ` (8 preceding siblings ...)
  2015-07-20 14:35 ` [PATCH v2 5/6] multiboot2: Add support for relocatable images Daniel Kiper
@ 2015-07-20 14:35 ` Daniel Kiper
  2015-07-20 14:35 ` [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled Daniel Kiper
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 grub-core/loader/i386/multiboot_mbi.c |    6 ++--
 grub-core/loader/multiboot.c          |   12 +++++--
 grub-core/loader/multiboot_elfxx.c    |   28 +++++++++++----
 grub-core/loader/multiboot_mbi2.c     |   63 +++++++++++++++++++++++++++++----
 include/grub/multiboot.h              |    4 ++-
 include/multiboot2.h                  |   24 +++++++++++++
 6 files changed, 118 insertions(+), 19 deletions(-)

diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c
index 956d0e3..abdb98b 100644
--- a/grub-core/loader/i386/multiboot_mbi.c
+++ b/grub-core/loader/i386/multiboot_mbi.c
@@ -72,7 +72,8 @@ load_kernel (grub_file_t file, const char *filename,
   grub_err_t err;
   if (grub_multiboot_quirks & GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE)
     {
-      err = grub_multiboot_load_elf (file, filename, buffer);
+      err = grub_multiboot_load_elf (file, filename, buffer, 0, 0, 0, 0,
+				     GRUB_RELOCATOR_PREFERENCE_NONE, NULL, 0);
       if (err == GRUB_ERR_UNKNOWN_OS && (header->flags & MULTIBOOT_AOUT_KLUDGE))
 	grub_errno = err = GRUB_ERR_NONE;
     }
@@ -118,7 +119,8 @@ load_kernel (grub_file_t file, const char *filename,
       return GRUB_ERR_NONE;
     }
 
-  return grub_multiboot_load_elf (file, filename, buffer);
+  return grub_multiboot_load_elf (file, filename, buffer, 0, 0, 0, 0,
+				  GRUB_RELOCATOR_PREFERENCE_NONE, NULL, 0);
 }
 
 static struct multiboot_header *
diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
index ca7154f..1b1f7a9 100644
--- a/grub-core/loader/multiboot.c
+++ b/grub-core/loader/multiboot.c
@@ -190,12 +190,18 @@ static grub_uint64_t highest_load;
 /* Load ELF32 or ELF64.  */
 grub_err_t
 grub_multiboot_load_elf (grub_file_t file, const char *filename,
-			 void *buffer)
+			 void *buffer, int relocatable, grub_uint32_t min_addr,
+			 grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
+			 grub_uint32_t *base_addr, int avoid_efi_boot_services)
 {
   if (grub_multiboot_is_elf32 (buffer))
-    return grub_multiboot_load_elf32 (file, filename, buffer);
+    return grub_multiboot_load_elf32 (file, filename, buffer, relocatable,
+				      min_addr, max_addr, align, preference,
+				      base_addr, avoid_efi_boot_services);
   else if (grub_multiboot_is_elf64 (buffer))
-    return grub_multiboot_load_elf64 (file, filename, buffer);
+    return grub_multiboot_load_elf64 (file, filename, buffer, relocatable,
+				      min_addr, max_addr, align, preference,
+				      base_addr, avoid_efi_boot_services);
 
   return grub_error (GRUB_ERR_UNKNOWN_OS, N_("invalid arch-dependent ELF magic"));
 }
diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c
index 6a220bd..4fce685 100644
--- a/grub-core/loader/multiboot_elfxx.c
+++ b/grub-core/loader/multiboot_elfxx.c
@@ -51,7 +51,10 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer)
 }
 
 static grub_err_t
-CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, void *buffer)
+CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename,
+				     void *buffer, int relocatable, grub_uint32_t min_addr,
+				     grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
+				     grub_uint32_t *base_addr, int avoid_efi_boot_services)
 {
   Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;
   char *phdr_base;
@@ -89,19 +92,30 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
 	  if (phdr(i)->p_paddr + phdr(i)->p_memsz > highest_load)
 	    highest_load = phdr(i)->p_paddr + phdr(i)->p_memsz;
 
-	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n",
-			i, (long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr);
+	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx,"
+			"align=0x%lx, relocatable=%d, avoid_efi_boot_services=%d\n", i,
+			(long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr,
+			(long) align, relocatable, avoid_efi_boot_services);
 
 	  {
 	    grub_relocator_chunk_t ch;
-	    err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, 
-						   &ch, phdr(i)->p_paddr,
-						   phdr(i)->p_memsz);
+
+	    if (relocatable)
+	      err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
+						      min_addr, max_addr - phdr(i)->p_memsz,
+						      phdr(i)->p_memsz, align ? align : 1,
+						      preference, avoid_efi_boot_services);
+	    else
+	      err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
+						     &ch, phdr(i)->p_paddr,
+						     phdr(i)->p_memsz);
 	    if (err)
 	      {
 		grub_dprintf ("multiboot_loader", "Error loading phdr %d\n", i);
 		return err;
 	      }
+	    if (base_addr)
+	      *base_addr = get_physical_target_address (ch);
 	    source = get_virtual_current_address (ch);
 	  }
 
@@ -208,7 +222,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
 						    + 1, sh->sh_size,
 						    sh->sh_addralign,
 						    GRUB_RELOCATOR_PREFERENCE_NONE,
-						    0);
+						    avoid_efi_boot_services);
 	    if (err)
 	      {
 		grub_dprintf ("multiboot_loader", "Error loading shdr %d\n", i);
diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
index dc9c709..7ac64ec 100644
--- a/grub-core/loader/multiboot_mbi2.c
+++ b/grub-core/loader/multiboot_mbi2.c
@@ -68,6 +68,7 @@ static grub_size_t elf_sec_num, elf_sec_entsize;
 static unsigned elf_sec_shstrndx;
 static void *elf_sections;
 static int keep_bs = 0;
+static grub_uint32_t base_addr = 0;
 
 void
 grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,
@@ -107,11 +108,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
   grub_err_t err;
   struct multiboot_header_tag *tag;
   struct multiboot_header_tag_address *addr_tag = NULL;
-  int entry_specified = 0, efi_entry_specified = 0;
+  int entry_specified = 0, efi_entry_specified = 0, relocatable = 0;
   grub_addr_t entry = 0, efi_entry = 0;
-  grub_uint32_t console_required = 0;
+  grub_uint32_t console_required = 0, min_addr = 0;
+  grub_uint32_t max_addr = 0, preference = 0;
   struct multiboot_header_tag_framebuffer *fbtag = NULL;
   int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
+  grub_size_t align = 0;
 
   buffer = grub_malloc (MULTIBOOT_SEARCH);
   if (!buffer)
@@ -174,6 +177,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	      case MULTIBOOT_TAG_TYPE_EFI_BS:
 	      case MULTIBOOT_TAG_TYPE_EFI32_IH:
 	      case MULTIBOOT_TAG_TYPE_EFI64_IH:
+	      case MULTIBOOT_TAG_TYPE_BASE_ADDR:
 		break;
 
 	      default:
@@ -215,6 +219,26 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	accepted_consoles |= GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER;
 	break;
 
+      case MULTIBOOT_HEADER_TAG_RELOCATABLE:
+	relocatable = 1;
+	min_addr = ((struct multiboot_header_tag_relocatable *) tag)->min_addr;
+	max_addr = ((struct multiboot_header_tag_relocatable *) tag)->max_addr;
+	align = ((struct multiboot_header_tag_relocatable *) tag)->align;
+	switch (((struct multiboot_header_tag_relocatable *) tag)->preference)
+	  {
+	  case MULTIBOOT_LOAD_PREFERENCE_LOW:
+	    preference = GRUB_RELOCATOR_PREFERENCE_LOW;
+	    break;
+
+	  case MULTIBOOT_LOAD_PREFERENCE_HIGH:
+	    preference = GRUB_RELOCATOR_PREFERENCE_HIGH;
+	    break;
+
+	  default:
+	    preference = GRUB_RELOCATOR_PREFERENCE_NONE;
+	  }
+	break;
+
 	/* GRUB always page-aligns modules.  */
       case MULTIBOOT_HEADER_TAG_MODULE_ALIGN:
 	break;
@@ -260,15 +284,22 @@ grub_multiboot_load (grub_file_t file, const char *filename)
       else
 	code_size = load_size;
 
-      err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, 
-					     &ch, load_addr,
-					     code_size);
+      if (relocatable)
+	err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
+						min_addr, max_addr - code_size,
+						code_size, align ? align : 1,
+						preference, keep_bs);
+      else
+	err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
+					       &ch, load_addr,
+					       code_size);
       if (err)
 	{
 	  grub_dprintf ("multiboot_loader", "Error loading aout kludge\n");
 	  grub_free (buffer);
 	  return err;
 	}
+      base_addr = get_physical_target_address (ch);
       source = get_virtual_current_address (ch);
 
       if ((grub_file_seek (file, offset)) == (grub_off_t) -1)
@@ -290,7 +321,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
     }
   else
     {
-      err = grub_multiboot_load_elf (file, filename, buffer);
+      err = grub_multiboot_load_elf (file, filename, buffer,
+				     relocatable, min_addr, max_addr,
+				     align, preference, &base_addr, keep_bs);
       if (err)
 	{
 	  grub_free (buffer);
@@ -303,6 +336,14 @@ grub_multiboot_load (grub_file_t file, const char *filename)
   else if (entry_specified)
     grub_multiboot_payload_eip = entry;
 
+  if (relocatable)
+    {
+      if (base_addr > min_addr)
+	grub_multiboot_payload_eip += base_addr - min_addr;
+      else
+	grub_multiboot_payload_eip -= min_addr - base_addr;
+    }
+
   if (fbtag)
     err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER,
 				      accepted_consoles,
@@ -409,6 +450,7 @@ grub_multiboot_get_mbi_size (void)
 		 + grub_get_multiboot_mmap_count ()
 		 * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN)
     + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_base_addr), MULTIBOOT_TAG_ALIGN)
 #ifdef GRUB_MACHINE_EFI
     + ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN)
     + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
@@ -693,6 +735,15 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
   ptrorig += (2 * sizeof (grub_uint32_t)) / sizeof (grub_properly_aligned_t);
 
   {
+    struct multiboot_tag_base_addr *tag = (struct multiboot_tag_base_addr *) ptrorig;
+    tag->type = MULTIBOOT_TAG_TYPE_BASE_ADDR;
+    tag->size = sizeof (struct multiboot_tag_base_addr); 
+    tag->base_addr = base_addr;
+    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+       / sizeof (grub_properly_aligned_t);
+  }
+
+  {
     struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig;
     tag->type = MULTIBOOT_TAG_TYPE_CMDLINE;
     tag->size = sizeof (struct multiboot_tag_string) + cmdline_size; 
diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h
index e13c084..ec322b0 100644
--- a/include/grub/multiboot.h
+++ b/include/grub/multiboot.h
@@ -94,7 +94,9 @@ grub_multiboot_load (grub_file_t file, const char *filename);
 /* Load ELF32 or ELF64.  */
 grub_err_t
 grub_multiboot_load_elf (grub_file_t file, const char *filename,
-			 void *buffer);
+			 void *buffer, int relocatable, grub_uint32_t min_addr,
+			 grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
+			 grub_uint32_t *base_addr, int avoid_efi_boot_services);
 extern grub_size_t grub_multiboot_pure_size;
 extern grub_size_t grub_multiboot_alloc_mbi;
 extern grub_uint32_t grub_multiboot_payload_eip;
diff --git a/include/multiboot2.h b/include/multiboot2.h
index 9f97ddc..941a95d 100644
--- a/include/multiboot2.h
+++ b/include/multiboot2.h
@@ -62,6 +62,7 @@
 #define MULTIBOOT_TAG_TYPE_EFI_BS            18
 #define MULTIBOOT_TAG_TYPE_EFI32_IH          19
 #define MULTIBOOT_TAG_TYPE_EFI64_IH          20
+#define MULTIBOOT_TAG_TYPE_BASE_ADDR         21
 
 #define MULTIBOOT_HEADER_TAG_END  0
 #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
@@ -72,11 +73,16 @@
 #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
 #define MULTIBOOT_HEADER_TAG_EFI_BS  7
 #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
+#define MULTIBOOT_HEADER_TAG_RELOCATABLE  10
 
 #define MULTIBOOT_ARCHITECTURE_I386  0
 #define MULTIBOOT_ARCHITECTURE_MIPS32  4
 #define MULTIBOOT_HEADER_TAG_OPTIONAL 1
 
+#define MULTIBOOT_LOAD_PREFERENCE_NONE 0
+#define MULTIBOOT_LOAD_PREFERENCE_LOW 1
+#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2
+
 #define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
 #define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
 
@@ -169,6 +175,17 @@ struct multiboot_header_tag_module_align
   multiboot_uint32_t size;
 };
 
+struct multiboot_header_tag_relocatable
+{
+  multiboot_uint16_t type;
+  multiboot_uint16_t flags;
+  multiboot_uint32_t size;
+  multiboot_uint32_t min_addr;
+  multiboot_uint32_t max_addr;
+  multiboot_uint32_t align;
+  multiboot_uint32_t preference;
+};
+
 struct multiboot_color
 {
   multiboot_uint8_t red;
@@ -395,6 +412,13 @@ struct multiboot_tag_efi64_ih
   multiboot_uint64_t pointer;
 };
 
+struct multiboot_tag_base_addr
+{
+  multiboot_uint32_t type;
+  multiboot_uint32_t size;
+  multiboot_uint32_t base_addr;
+};
+
 #endif /* ! ASM_FILE */
 
 #endif /* ! MULTIBOOT_HEADER */
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 67+ messages in thread

* [PATCH v2 5/6] multiboot2: Add support for relocatable images
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
                   ` (7 preceding siblings ...)
  2015-07-20 14:35 ` Daniel Kiper
@ 2015-07-20 14:35 ` Daniel Kiper
  2015-08-11 18:51   ` Konrad Rzeszutek Wilk
                     ` (3 more replies)
  2015-07-20 14:35 ` Daniel Kiper
                   ` (4 subsequent siblings)
  13 siblings, 4 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 grub-core/loader/i386/multiboot_mbi.c |    6 ++--
 grub-core/loader/multiboot.c          |   12 +++++--
 grub-core/loader/multiboot_elfxx.c    |   28 +++++++++++----
 grub-core/loader/multiboot_mbi2.c     |   63 +++++++++++++++++++++++++++++----
 include/grub/multiboot.h              |    4 ++-
 include/multiboot2.h                  |   24 +++++++++++++
 6 files changed, 118 insertions(+), 19 deletions(-)

diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c
index 956d0e3..abdb98b 100644
--- a/grub-core/loader/i386/multiboot_mbi.c
+++ b/grub-core/loader/i386/multiboot_mbi.c
@@ -72,7 +72,8 @@ load_kernel (grub_file_t file, const char *filename,
   grub_err_t err;
   if (grub_multiboot_quirks & GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE)
     {
-      err = grub_multiboot_load_elf (file, filename, buffer);
+      err = grub_multiboot_load_elf (file, filename, buffer, 0, 0, 0, 0,
+				     GRUB_RELOCATOR_PREFERENCE_NONE, NULL, 0);
       if (err == GRUB_ERR_UNKNOWN_OS && (header->flags & MULTIBOOT_AOUT_KLUDGE))
 	grub_errno = err = GRUB_ERR_NONE;
     }
@@ -118,7 +119,8 @@ load_kernel (grub_file_t file, const char *filename,
       return GRUB_ERR_NONE;
     }
 
-  return grub_multiboot_load_elf (file, filename, buffer);
+  return grub_multiboot_load_elf (file, filename, buffer, 0, 0, 0, 0,
+				  GRUB_RELOCATOR_PREFERENCE_NONE, NULL, 0);
 }
 
 static struct multiboot_header *
diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
index ca7154f..1b1f7a9 100644
--- a/grub-core/loader/multiboot.c
+++ b/grub-core/loader/multiboot.c
@@ -190,12 +190,18 @@ static grub_uint64_t highest_load;
 /* Load ELF32 or ELF64.  */
 grub_err_t
 grub_multiboot_load_elf (grub_file_t file, const char *filename,
-			 void *buffer)
+			 void *buffer, int relocatable, grub_uint32_t min_addr,
+			 grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
+			 grub_uint32_t *base_addr, int avoid_efi_boot_services)
 {
   if (grub_multiboot_is_elf32 (buffer))
-    return grub_multiboot_load_elf32 (file, filename, buffer);
+    return grub_multiboot_load_elf32 (file, filename, buffer, relocatable,
+				      min_addr, max_addr, align, preference,
+				      base_addr, avoid_efi_boot_services);
   else if (grub_multiboot_is_elf64 (buffer))
-    return grub_multiboot_load_elf64 (file, filename, buffer);
+    return grub_multiboot_load_elf64 (file, filename, buffer, relocatable,
+				      min_addr, max_addr, align, preference,
+				      base_addr, avoid_efi_boot_services);
 
   return grub_error (GRUB_ERR_UNKNOWN_OS, N_("invalid arch-dependent ELF magic"));
 }
diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c
index 6a220bd..4fce685 100644
--- a/grub-core/loader/multiboot_elfxx.c
+++ b/grub-core/loader/multiboot_elfxx.c
@@ -51,7 +51,10 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer)
 }
 
 static grub_err_t
-CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, void *buffer)
+CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename,
+				     void *buffer, int relocatable, grub_uint32_t min_addr,
+				     grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
+				     grub_uint32_t *base_addr, int avoid_efi_boot_services)
 {
   Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;
   char *phdr_base;
@@ -89,19 +92,30 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
 	  if (phdr(i)->p_paddr + phdr(i)->p_memsz > highest_load)
 	    highest_load = phdr(i)->p_paddr + phdr(i)->p_memsz;
 
-	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n",
-			i, (long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr);
+	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx,"
+			"align=0x%lx, relocatable=%d, avoid_efi_boot_services=%d\n", i,
+			(long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr,
+			(long) align, relocatable, avoid_efi_boot_services);
 
 	  {
 	    grub_relocator_chunk_t ch;
-	    err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, 
-						   &ch, phdr(i)->p_paddr,
-						   phdr(i)->p_memsz);
+
+	    if (relocatable)
+	      err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
+						      min_addr, max_addr - phdr(i)->p_memsz,
+						      phdr(i)->p_memsz, align ? align : 1,
+						      preference, avoid_efi_boot_services);
+	    else
+	      err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
+						     &ch, phdr(i)->p_paddr,
+						     phdr(i)->p_memsz);
 	    if (err)
 	      {
 		grub_dprintf ("multiboot_loader", "Error loading phdr %d\n", i);
 		return err;
 	      }
+	    if (base_addr)
+	      *base_addr = get_physical_target_address (ch);
 	    source = get_virtual_current_address (ch);
 	  }
 
@@ -208,7 +222,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
 						    + 1, sh->sh_size,
 						    sh->sh_addralign,
 						    GRUB_RELOCATOR_PREFERENCE_NONE,
-						    0);
+						    avoid_efi_boot_services);
 	    if (err)
 	      {
 		grub_dprintf ("multiboot_loader", "Error loading shdr %d\n", i);
diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
index dc9c709..7ac64ec 100644
--- a/grub-core/loader/multiboot_mbi2.c
+++ b/grub-core/loader/multiboot_mbi2.c
@@ -68,6 +68,7 @@ static grub_size_t elf_sec_num, elf_sec_entsize;
 static unsigned elf_sec_shstrndx;
 static void *elf_sections;
 static int keep_bs = 0;
+static grub_uint32_t base_addr = 0;
 
 void
 grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,
@@ -107,11 +108,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
   grub_err_t err;
   struct multiboot_header_tag *tag;
   struct multiboot_header_tag_address *addr_tag = NULL;
-  int entry_specified = 0, efi_entry_specified = 0;
+  int entry_specified = 0, efi_entry_specified = 0, relocatable = 0;
   grub_addr_t entry = 0, efi_entry = 0;
-  grub_uint32_t console_required = 0;
+  grub_uint32_t console_required = 0, min_addr = 0;
+  grub_uint32_t max_addr = 0, preference = 0;
   struct multiboot_header_tag_framebuffer *fbtag = NULL;
   int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
+  grub_size_t align = 0;
 
   buffer = grub_malloc (MULTIBOOT_SEARCH);
   if (!buffer)
@@ -174,6 +177,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	      case MULTIBOOT_TAG_TYPE_EFI_BS:
 	      case MULTIBOOT_TAG_TYPE_EFI32_IH:
 	      case MULTIBOOT_TAG_TYPE_EFI64_IH:
+	      case MULTIBOOT_TAG_TYPE_BASE_ADDR:
 		break;
 
 	      default:
@@ -215,6 +219,26 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	accepted_consoles |= GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER;
 	break;
 
+      case MULTIBOOT_HEADER_TAG_RELOCATABLE:
+	relocatable = 1;
+	min_addr = ((struct multiboot_header_tag_relocatable *) tag)->min_addr;
+	max_addr = ((struct multiboot_header_tag_relocatable *) tag)->max_addr;
+	align = ((struct multiboot_header_tag_relocatable *) tag)->align;
+	switch (((struct multiboot_header_tag_relocatable *) tag)->preference)
+	  {
+	  case MULTIBOOT_LOAD_PREFERENCE_LOW:
+	    preference = GRUB_RELOCATOR_PREFERENCE_LOW;
+	    break;
+
+	  case MULTIBOOT_LOAD_PREFERENCE_HIGH:
+	    preference = GRUB_RELOCATOR_PREFERENCE_HIGH;
+	    break;
+
+	  default:
+	    preference = GRUB_RELOCATOR_PREFERENCE_NONE;
+	  }
+	break;
+
 	/* GRUB always page-aligns modules.  */
       case MULTIBOOT_HEADER_TAG_MODULE_ALIGN:
 	break;
@@ -260,15 +284,22 @@ grub_multiboot_load (grub_file_t file, const char *filename)
       else
 	code_size = load_size;
 
-      err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, 
-					     &ch, load_addr,
-					     code_size);
+      if (relocatable)
+	err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
+						min_addr, max_addr - code_size,
+						code_size, align ? align : 1,
+						preference, keep_bs);
+      else
+	err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
+					       &ch, load_addr,
+					       code_size);
       if (err)
 	{
 	  grub_dprintf ("multiboot_loader", "Error loading aout kludge\n");
 	  grub_free (buffer);
 	  return err;
 	}
+      base_addr = get_physical_target_address (ch);
       source = get_virtual_current_address (ch);
 
       if ((grub_file_seek (file, offset)) == (grub_off_t) -1)
@@ -290,7 +321,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
     }
   else
     {
-      err = grub_multiboot_load_elf (file, filename, buffer);
+      err = grub_multiboot_load_elf (file, filename, buffer,
+				     relocatable, min_addr, max_addr,
+				     align, preference, &base_addr, keep_bs);
       if (err)
 	{
 	  grub_free (buffer);
@@ -303,6 +336,14 @@ grub_multiboot_load (grub_file_t file, const char *filename)
   else if (entry_specified)
     grub_multiboot_payload_eip = entry;
 
+  if (relocatable)
+    {
+      if (base_addr > min_addr)
+	grub_multiboot_payload_eip += base_addr - min_addr;
+      else
+	grub_multiboot_payload_eip -= min_addr - base_addr;
+    }
+
   if (fbtag)
     err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER,
 				      accepted_consoles,
@@ -409,6 +450,7 @@ grub_multiboot_get_mbi_size (void)
 		 + grub_get_multiboot_mmap_count ()
 		 * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN)
     + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_base_addr), MULTIBOOT_TAG_ALIGN)
 #ifdef GRUB_MACHINE_EFI
     + ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN)
     + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
@@ -693,6 +735,15 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
   ptrorig += (2 * sizeof (grub_uint32_t)) / sizeof (grub_properly_aligned_t);
 
   {
+    struct multiboot_tag_base_addr *tag = (struct multiboot_tag_base_addr *) ptrorig;
+    tag->type = MULTIBOOT_TAG_TYPE_BASE_ADDR;
+    tag->size = sizeof (struct multiboot_tag_base_addr); 
+    tag->base_addr = base_addr;
+    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+       / sizeof (grub_properly_aligned_t);
+  }
+
+  {
     struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig;
     tag->type = MULTIBOOT_TAG_TYPE_CMDLINE;
     tag->size = sizeof (struct multiboot_tag_string) + cmdline_size; 
diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h
index e13c084..ec322b0 100644
--- a/include/grub/multiboot.h
+++ b/include/grub/multiboot.h
@@ -94,7 +94,9 @@ grub_multiboot_load (grub_file_t file, const char *filename);
 /* Load ELF32 or ELF64.  */
 grub_err_t
 grub_multiboot_load_elf (grub_file_t file, const char *filename,
-			 void *buffer);
+			 void *buffer, int relocatable, grub_uint32_t min_addr,
+			 grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
+			 grub_uint32_t *base_addr, int avoid_efi_boot_services);
 extern grub_size_t grub_multiboot_pure_size;
 extern grub_size_t grub_multiboot_alloc_mbi;
 extern grub_uint32_t grub_multiboot_payload_eip;
diff --git a/include/multiboot2.h b/include/multiboot2.h
index 9f97ddc..941a95d 100644
--- a/include/multiboot2.h
+++ b/include/multiboot2.h
@@ -62,6 +62,7 @@
 #define MULTIBOOT_TAG_TYPE_EFI_BS            18
 #define MULTIBOOT_TAG_TYPE_EFI32_IH          19
 #define MULTIBOOT_TAG_TYPE_EFI64_IH          20
+#define MULTIBOOT_TAG_TYPE_BASE_ADDR         21
 
 #define MULTIBOOT_HEADER_TAG_END  0
 #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
@@ -72,11 +73,16 @@
 #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
 #define MULTIBOOT_HEADER_TAG_EFI_BS  7
 #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
+#define MULTIBOOT_HEADER_TAG_RELOCATABLE  10
 
 #define MULTIBOOT_ARCHITECTURE_I386  0
 #define MULTIBOOT_ARCHITECTURE_MIPS32  4
 #define MULTIBOOT_HEADER_TAG_OPTIONAL 1
 
+#define MULTIBOOT_LOAD_PREFERENCE_NONE 0
+#define MULTIBOOT_LOAD_PREFERENCE_LOW 1
+#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2
+
 #define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
 #define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
 
@@ -169,6 +175,17 @@ struct multiboot_header_tag_module_align
   multiboot_uint32_t size;
 };
 
+struct multiboot_header_tag_relocatable
+{
+  multiboot_uint16_t type;
+  multiboot_uint16_t flags;
+  multiboot_uint32_t size;
+  multiboot_uint32_t min_addr;
+  multiboot_uint32_t max_addr;
+  multiboot_uint32_t align;
+  multiboot_uint32_t preference;
+};
+
 struct multiboot_color
 {
   multiboot_uint8_t red;
@@ -395,6 +412,13 @@ struct multiboot_tag_efi64_ih
   multiboot_uint64_t pointer;
 };
 
+struct multiboot_tag_base_addr
+{
+  multiboot_uint32_t type;
+  multiboot_uint32_t size;
+  multiboot_uint32_t base_addr;
+};
+
 #endif /* ! ASM_FILE */
 
 #endif /* ! MULTIBOOT_HEADER */
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 67+ messages in thread

* [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
                   ` (9 preceding siblings ...)
  2015-07-20 14:35 ` Daniel Kiper
@ 2015-07-20 14:35 ` Daniel Kiper
  2015-07-20 14:35 ` Daniel Kiper
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Do not pass memory maps to image if it asked for EFI boot services. Maps are
usually invalid in that case and they can confuse potential user. Image should
get memory map itself just before ExitBootServices() call.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 grub-core/loader/multiboot_mbi2.c |   71 ++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 36 deletions(-)

diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
index 7ac64ec..26e955c 100644
--- a/grub-core/loader/multiboot_mbi2.c
+++ b/grub-core/loader/multiboot_mbi2.c
@@ -431,7 +431,7 @@ static grub_size_t
 grub_multiboot_get_mbi_size (void)
 {
 #ifdef GRUB_MACHINE_EFI
-  if (!efi_mmap_size)
+  if (!keep_bs && !efi_mmap_size)
     find_efi_mmap_size ();    
 #endif
   return 2 * sizeof (grub_uint32_t) + sizeof (struct multiboot_tag)
@@ -805,12 +805,13 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
       }
   }
 
-  {
-    struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
-    grub_fill_multiboot_mmap (tag);
-    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
-      / sizeof (grub_properly_aligned_t);
-  }
+  if (!keep_bs)
+    {
+      struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
+      grub_fill_multiboot_mmap (tag);
+      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	/ sizeof (grub_properly_aligned_t);
+    }
 
   {
     struct multiboot_tag_elf_sections *tag
@@ -826,18 +827,19 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
       / sizeof (grub_properly_aligned_t);
   }
 
-  {
-    struct multiboot_tag_basic_meminfo *tag
-      = (struct multiboot_tag_basic_meminfo *) ptrorig;
-    tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO;
-    tag->size = sizeof (struct multiboot_tag_basic_meminfo); 
+  if (!keep_bs)
+    {
+      struct multiboot_tag_basic_meminfo *tag
+	= (struct multiboot_tag_basic_meminfo *) ptrorig;
+      tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO;
+      tag->size = sizeof (struct multiboot_tag_basic_meminfo);
 
-    /* Convert from bytes to kilobytes.  */
-    tag->mem_lower = grub_mmap_get_lower () / 1024;
-    tag->mem_upper = grub_mmap_get_upper () / 1024;
-    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
-       / sizeof (grub_properly_aligned_t);
-  }
+      /* Convert from bytes to kilobytes.  */
+      tag->mem_lower = grub_mmap_get_lower () / 1024;
+      tag->mem_upper = grub_mmap_get_upper () / 1024;
+      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	/ sizeof (grub_properly_aligned_t);
+    }
 
   {
     struct grub_net_network_level_interface *net;
@@ -936,27 +938,24 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
     grub_efi_uintn_t efi_desc_size;
     grub_efi_uint32_t efi_desc_version;
 
-    tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP;
-    tag->size = sizeof (*tag) + efi_mmap_size;
-
     if (!keep_bs)
-      err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL,
-					   &efi_desc_size, &efi_desc_version);
-    else
       {
-	if (grub_efi_get_memory_map (&efi_mmap_size, (void *) tag->efi_mmap,
-				     NULL,
-				     &efi_desc_size, &efi_desc_version) <= 0)
-	  err = grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
+	tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP;
+	tag->size = sizeof (*tag) + efi_mmap_size;
+
+	err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL,
+					     &efi_desc_size, &efi_desc_version);
+
+	if (err)
+	  return err;
+
+	tag->descr_size = efi_desc_size;
+	tag->descr_vers = efi_desc_version;
+	tag->size = sizeof (*tag) + efi_mmap_size;
+
+	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	  / sizeof (grub_properly_aligned_t);
       }
-    if (err)
-      return err;
-    tag->descr_size = efi_desc_size;
-    tag->descr_vers = efi_desc_version;
-    tag->size = sizeof (*tag) + efi_mmap_size;
-
-    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
-      / sizeof (grub_properly_aligned_t);
   }
 
   if (keep_bs)
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 67+ messages in thread

* [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
                   ` (10 preceding siblings ...)
  2015-07-20 14:35 ` [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled Daniel Kiper
@ 2015-07-20 14:35 ` Daniel Kiper
  2015-08-11 18:59   ` Konrad Rzeszutek Wilk
  2015-08-11 18:59   ` Konrad Rzeszutek Wilk
  2015-08-24 17:11 ` [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
  2015-08-24 17:11 ` Daniel Kiper
  13 siblings, 2 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-07-20 14:35 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Do not pass memory maps to image if it asked for EFI boot services. Maps are
usually invalid in that case and they can confuse potential user. Image should
get memory map itself just before ExitBootServices() call.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 grub-core/loader/multiboot_mbi2.c |   71 ++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 36 deletions(-)

diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
index 7ac64ec..26e955c 100644
--- a/grub-core/loader/multiboot_mbi2.c
+++ b/grub-core/loader/multiboot_mbi2.c
@@ -431,7 +431,7 @@ static grub_size_t
 grub_multiboot_get_mbi_size (void)
 {
 #ifdef GRUB_MACHINE_EFI
-  if (!efi_mmap_size)
+  if (!keep_bs && !efi_mmap_size)
     find_efi_mmap_size ();    
 #endif
   return 2 * sizeof (grub_uint32_t) + sizeof (struct multiboot_tag)
@@ -805,12 +805,13 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
       }
   }
 
-  {
-    struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
-    grub_fill_multiboot_mmap (tag);
-    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
-      / sizeof (grub_properly_aligned_t);
-  }
+  if (!keep_bs)
+    {
+      struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
+      grub_fill_multiboot_mmap (tag);
+      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	/ sizeof (grub_properly_aligned_t);
+    }
 
   {
     struct multiboot_tag_elf_sections *tag
@@ -826,18 +827,19 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
       / sizeof (grub_properly_aligned_t);
   }
 
-  {
-    struct multiboot_tag_basic_meminfo *tag
-      = (struct multiboot_tag_basic_meminfo *) ptrorig;
-    tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO;
-    tag->size = sizeof (struct multiboot_tag_basic_meminfo); 
+  if (!keep_bs)
+    {
+      struct multiboot_tag_basic_meminfo *tag
+	= (struct multiboot_tag_basic_meminfo *) ptrorig;
+      tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO;
+      tag->size = sizeof (struct multiboot_tag_basic_meminfo);
 
-    /* Convert from bytes to kilobytes.  */
-    tag->mem_lower = grub_mmap_get_lower () / 1024;
-    tag->mem_upper = grub_mmap_get_upper () / 1024;
-    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
-       / sizeof (grub_properly_aligned_t);
-  }
+      /* Convert from bytes to kilobytes.  */
+      tag->mem_lower = grub_mmap_get_lower () / 1024;
+      tag->mem_upper = grub_mmap_get_upper () / 1024;
+      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	/ sizeof (grub_properly_aligned_t);
+    }
 
   {
     struct grub_net_network_level_interface *net;
@@ -936,27 +938,24 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
     grub_efi_uintn_t efi_desc_size;
     grub_efi_uint32_t efi_desc_version;
 
-    tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP;
-    tag->size = sizeof (*tag) + efi_mmap_size;
-
     if (!keep_bs)
-      err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL,
-					   &efi_desc_size, &efi_desc_version);
-    else
       {
-	if (grub_efi_get_memory_map (&efi_mmap_size, (void *) tag->efi_mmap,
-				     NULL,
-				     &efi_desc_size, &efi_desc_version) <= 0)
-	  err = grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
+	tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP;
+	tag->size = sizeof (*tag) + efi_mmap_size;
+
+	err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL,
+					     &efi_desc_size, &efi_desc_version);
+
+	if (err)
+	  return err;
+
+	tag->descr_size = efi_desc_size;
+	tag->descr_vers = efi_desc_version;
+	tag->size = sizeof (*tag) + efi_mmap_size;
+
+	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	  / sizeof (grub_properly_aligned_t);
       }
-    if (err)
-      return err;
-    tag->descr_size = efi_desc_size;
-    tag->descr_vers = efi_desc_version;
-    tag->size = sizeof (*tag) + efi_mmap_size;
-
-    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
-      / sizeof (grub_properly_aligned_t);
   }
 
   if (keep_bs)
-- 
1.7.10.4



^ permalink raw reply related	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2015-07-20 14:35 ` Daniel Kiper
@ 2015-07-21  6:42   ` Andrei Borzenkov
  2015-07-21  6:42   ` Andrei Borzenkov
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 67+ messages in thread
From: Andrei Borzenkov @ 2015-07-21  6:42 UTC (permalink / raw)
  To: The development of GNU GRUB
  Cc: Juergen Gross, wei.liu2, keir, Ian Campbell, Stefano Stabellini,
	andrew.cooper3, Roy Franz, Sun, Ning, david.vrabel, Jan Beulich,
	Vladimir Serbinenko, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, Fu Wei

On Mon, Jul 20, 2015 at 5:35 PM, Daniel Kiper <daniel.kiper@oracle.com> wrote:
> malloc_in_range() should not use memory region if its starta is smaller
> than size. Otherwise target wraps around and points to region which is
> usually not a RAM, e.g.:
>
> loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000
> lib/relocator.c:1241: min_addr = 0x0, max_addr = 0xffffffffffffffff, target = 0x800000
> lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned 0x1 size 0x3f800000
> lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned 0x1 size 0x3f800000
> lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned 0x1 size 0x3f800000
> lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000
> lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000
>
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/lib/relocator.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
> index f759c7f..4eee0c5 100644
> --- a/grub-core/lib/relocator.c
> +++ b/grub-core/lib/relocator.c
> @@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,
>               /* Found an usable address.  */
>               goto found;
>           }
> -       if (isinsidebefore && !isinsideafter && !from_low_priv)
> +       if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size)

That's too late, we need to check end of region on previous iteration.
Consider region of 128 bytes, requested size 129 and alignment 256.
Than starta still ends up high in memory.

>           {
>             target = starta - size;
>             if (target > end - size)
> --
> 1.7.10.4
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2015-07-20 14:35 ` Daniel Kiper
  2015-07-21  6:42   ` Andrei Borzenkov
@ 2015-07-21  6:42   ` Andrei Borzenkov
  2015-11-09 18:44     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-09 18:44     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2016-02-12 14:57   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2016-02-12 14:57   ` Vladimir 'φ-coder/phcoder' Serbinenko
  3 siblings, 2 replies; 67+ messages in thread
From: Andrei Borzenkov @ 2015-07-21  6:42 UTC (permalink / raw)
  To: The development of GNU GRUB
  Cc: Juergen Gross, wei.liu2, keir, Ian Campbell, Stefano Stabellini,
	andrew.cooper3, Roy Franz, Sun, Ning, david.vrabel, Jan Beulich,
	Vladimir Serbinenko, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, Fu Wei

On Mon, Jul 20, 2015 at 5:35 PM, Daniel Kiper <daniel.kiper@oracle.com> wrote:
> malloc_in_range() should not use memory region if its starta is smaller
> than size. Otherwise target wraps around and points to region which is
> usually not a RAM, e.g.:
>
> loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000
> lib/relocator.c:1241: min_addr = 0x0, max_addr = 0xffffffffffffffff, target = 0x800000
> lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned 0x1 size 0x3f800000
> lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned 0x1 size 0x3f800000
> lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned 0x1 size 0x3f800000
> lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000
> lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000
>
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/lib/relocator.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
> index f759c7f..4eee0c5 100644
> --- a/grub-core/lib/relocator.c
> +++ b/grub-core/lib/relocator.c
> @@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,
>               /* Found an usable address.  */
>               goto found;
>           }
> -       if (isinsidebefore && !isinsideafter && !from_low_priv)
> +       if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size)

That's too late, we need to check end of region on previous iteration.
Consider region of 128 bytes, requested size 129 and alignment 256.
Than starta still ends up high in memory.

>           {
>             target = starta - size;
>             if (target > end - size)
> --
> 1.7.10.4
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-07-20 14:35 ` Daniel Kiper
@ 2015-08-11 17:00   ` Konrad Rzeszutek Wilk
  2015-08-11 17:00   ` Konrad Rzeszutek Wilk
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 67+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-08-11 17:00 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, wei.liu2, keir, ian.campbell,
	stefano.stabellini, andrew.cooper3, roy.franz, ning.sun,
	david.vrabel, jbeulich, phcoder, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei

On Mon, Jul 20, 2015 at 04:35:49PM +0200, Daniel Kiper wrote:
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

but really - this is quite easy to review :-)

> ---
>  .gitignore |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/.gitignore b/.gitignore
> index 18ab8e8..6d25d39 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -147,6 +147,7 @@ mod-*.c
>  missing
>  netboot_test
>  *.o
> +*.orig
>  *.a
>  ohci_test
>  partmap_test
> @@ -160,9 +161,11 @@ po/stamp-po
>  printf_test
>  priority_queue_unit_test
>  pseries_test
> +*.rej
>  stamp-h
>  stamp-h1
>  stamp-h.in
> +*.swp
>  symlist.c
>  symlist.h
>  trigtables.c
> -- 
> 1.7.10.4
> 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-07-20 14:35 ` Daniel Kiper
  2015-08-11 17:00   ` Konrad Rzeszutek Wilk
@ 2015-08-11 17:00   ` Konrad Rzeszutek Wilk
  2015-08-12  9:04   ` Ian Campbell
  2015-08-12  9:04   ` Ian Campbell
  3 siblings, 0 replies; 67+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-08-11 17:00 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, wei.liu2, keir, ian.campbell,
	stefano.stabellini, andrew.cooper3, roy.franz, ning.sun,
	david.vrabel, jbeulich, phcoder, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei

On Mon, Jul 20, 2015 at 04:35:49PM +0200, Daniel Kiper wrote:
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

but really - this is quite easy to review :-)

> ---
>  .gitignore |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/.gitignore b/.gitignore
> index 18ab8e8..6d25d39 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -147,6 +147,7 @@ mod-*.c
>  missing
>  netboot_test
>  *.o
> +*.orig
>  *.a
>  ohci_test
>  partmap_test
> @@ -160,9 +161,11 @@ po/stamp-po
>  printf_test
>  priority_queue_unit_test
>  pseries_test
> +*.rej
>  stamp-h
>  stamp-h1
>  stamp-h.in
> +*.swp
>  symlist.c
>  symlist.h
>  trigtables.c
> -- 
> 1.7.10.4
> 


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
  2015-07-20 14:35 ` Daniel Kiper
@ 2015-08-11 17:02     ` Konrad Rzeszutek Wilk
  2015-11-09 20:05   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-09 20:05   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2 siblings, 0 replies; 67+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-08-11 17:02 UTC (permalink / raw)
  To: Daniel Kiper, arvidjaar
  Cc: jgross, grub-devel, wei.liu2, keir, ian.campbell,
	stefano.stabellini, andrew.cooper3, roy.franz, ning.sun,
	david.vrabel, jbeulich, phcoder, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei

On Mon, Jul 20, 2015 at 04:35:51PM +0200, Daniel Kiper wrote:
> Add grub_relocator64_efi relocator. It will be used on EFI 64-bit platforms
> when multiboot2 compatible image requests MULTIBOOT_TAG_TYPE_EFI_BS. Relocator
> will set lower parts of %rax and %rbx accordingly to multiboot2 specification.
> On the other hand processor mode, just before jumping into loaded image, will
> be set accordingly to Unified Extensible Firmware Interface Specification,
> Version 2.4 Errata B, section 2.3.4, x64 Platforms, boot services. This way
> loaded image will be able to use EFI boot services without any issues.

Andrei, Valdimir: ping?

> 
> If idea is accepted I will prepare grub_relocator32_efi relocator too.
> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/Makefile.core.def          |    1 +
>  grub-core/lib/i386/relocator.c       |   53 +++++++++++++++++++++++
>  grub-core/lib/i386/relocator64_efi.S |   77 ++++++++++++++++++++++++++++++++++
>  grub-core/loader/multiboot.c         |   29 +++++++++++--
>  grub-core/loader/multiboot_mbi2.c    |   19 +++++++--
>  include/grub/i386/multiboot.h        |   11 +++++
>  include/grub/i386/relocator.h        |   21 ++++++++++
>  include/multiboot2.h                 |    9 ++++
>  8 files changed, 213 insertions(+), 7 deletions(-)
>  create mode 100644 grub-core/lib/i386/relocator64_efi.S
> 
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index a6101de..d583549 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -1519,6 +1519,7 @@ module = {
>    x86 = lib/i386/relocator_common_c.c;
>    ieee1275 = lib/ieee1275/relocator.c;
>    efi = lib/efi/relocator.c;
> +  x86_64_efi = lib/i386/relocator64_efi.S;
>    mips = lib/mips/relocator_asm.S;
>    mips = lib/mips/relocator.c;
>    powerpc = lib/powerpc/relocator_asm.S;
> diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c
> index 71dd4f0..459027e 100644
> --- a/grub-core/lib/i386/relocator.c
> +++ b/grub-core/lib/i386/relocator.c
> @@ -69,6 +69,19 @@ extern grub_uint64_t grub_relocator64_rsi;
>  extern grub_addr_t grub_relocator64_cr3;
>  extern struct grub_i386_idt grub_relocator16_idt;
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +extern grub_uint8_t grub_relocator64_efi_start;
> +extern grub_uint8_t grub_relocator64_efi_end;
> +extern grub_uint64_t grub_relocator64_efi_rax;
> +extern grub_uint64_t grub_relocator64_efi_rbx;
> +extern grub_uint64_t grub_relocator64_efi_rcx;
> +extern grub_uint64_t grub_relocator64_efi_rdx;
> +extern grub_uint64_t grub_relocator64_efi_rip;
> +extern grub_uint64_t grub_relocator64_efi_rsi;
> +#endif
> +#endif
> +
>  #define RELOCATOR_SIZEOF(x)	(&grub_relocator##x##_end - &grub_relocator##x##_start)
>  
>  grub_err_t
> @@ -214,3 +227,43 @@ grub_relocator64_boot (struct grub_relocator *rel,
>    /* Not reached.  */
>    return GRUB_ERR_NONE;
>  }
> +
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +grub_err_t
> +grub_relocator64_efi_boot (struct grub_relocator *rel,
> +			   struct grub_relocator64_efi_state state)
> +{
> +  grub_err_t err;
> +  void *relst;
> +  grub_relocator_chunk_t ch;
> +
> +  err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
> +					  0x40000000 - RELOCATOR_SIZEOF (64_efi),
> +					  RELOCATOR_SIZEOF (64_efi), 16,
> +					  GRUB_RELOCATOR_PREFERENCE_NONE, 1);
> +  if (err)
> +    return err;
> +
> +  grub_relocator64_efi_rax = state.rax;
> +  grub_relocator64_efi_rbx = state.rbx;
> +  grub_relocator64_efi_rcx = state.rcx;
> +  grub_relocator64_efi_rdx = state.rdx;
> +  grub_relocator64_efi_rip = state.rip;
> +  grub_relocator64_efi_rsi = state.rsi;
> +
> +  grub_memmove (get_virtual_current_address (ch), &grub_relocator64_efi_start,
> +		RELOCATOR_SIZEOF (64_efi));
> +
> +  err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch),
> +				       &relst, NULL);
> +  if (err)
> +    return err;
> +
> +  ((void (*) (void)) relst) ();
> +
> +  /* Not reached.  */
> +  return GRUB_ERR_NONE;
> +}
> +#endif
> +#endif
> diff --git a/grub-core/lib/i386/relocator64_efi.S b/grub-core/lib/i386/relocator64_efi.S
> new file mode 100644
> index 0000000..fcd1964
> --- /dev/null
> +++ b/grub-core/lib/i386/relocator64_efi.S
> @@ -0,0 +1,77 @@
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2009,2010  Free Software Foundation, Inc.
> + *  Copyright (C) 2014,2015  Oracle Co.
> + *      Author: Daniel Kiper
> + *
> + *  GRUB 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 3 of the License, or
> + *  (at your option) any later version.
> + *
> + *  GRUB 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 GRUB.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include "relocator_common.S"
> +
> +	.p2align	4	/* force 16-byte alignment */
> +
> +VARIABLE(grub_relocator64_efi_start)
> +	PREAMBLE
> +
> +	.code64
> +
> +	/* mov imm64, %rax */
> +	.byte 	0x48
> +	.byte	0xb8
> +VARIABLE(grub_relocator64_efi_rsi)
> +	.quad	0
> +
> +	movq	%rax, %rsi
> +
> +	/* mov imm64, %rax */
> +	.byte 	0x48
> +	.byte	0xb8
> +VARIABLE(grub_relocator64_efi_rax)
> +	.quad	0
> +
> +	/* mov imm64, %rbx */
> +	.byte 	0x48
> +	.byte	0xbb
> +VARIABLE(grub_relocator64_efi_rbx)
> +	.quad	0
> +
> +	/* mov imm64, %rcx */
> +	.byte 	0x48
> +	.byte	0xb9
> +VARIABLE(grub_relocator64_efi_rcx)
> +	.quad	0
> +
> +	/* mov imm64, %rdx */
> +	.byte 	0x48
> +	.byte	0xba
> +VARIABLE(grub_relocator64_efi_rdx)
> +	.quad	0
> +
> +	/* Cleared direction flag is of no problem with any current
> +	   payload and makes this implementation easier.  */
> +	cld
> +
> +#ifdef __APPLE__
> +	.byte 0xff, 0x25
> +	.quad 0
> +#else
> +	jmp *LOCAL(jump_addr) (%rip)
> +#endif
> +
> +LOCAL(jump_addr):
> +VARIABLE(grub_relocator64_efi_rip)
> +	.quad	0
> +
> +VARIABLE(grub_relocator64_efi_end)
> diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
> index fd8f28e..ca7154f 100644
> --- a/grub-core/loader/multiboot.c
> +++ b/grub-core/loader/multiboot.c
> @@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)
>    return err;
>  }
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +#define grub_relocator_efi_boot	grub_relocator64_efi_boot
> +#endif
> +#endif
> +
>  static grub_err_t
>  grub_multiboot_boot (void)
>  {
>    grub_err_t err;
> +  grub_uint32_t target;
>    struct grub_relocator32_state state = MULTIBOOT_INITIAL_STATE;
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +  struct grub_relocator64_efi_state state_efi = MULTIBOOT_EFI_INITIAL_STATE;
> +#endif
> +#endif
>  
> -  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
> -
> -  err = grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER);
> +  err = grub_multiboot_make_mbi (&target);
>  
>    if (err)
>      return err;
>  
> +  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
> +  state.MULTIBOOT_MBI_REGISTER = target;
> +
>  #if defined (__i386__) || defined (__x86_64__)
> +#ifdef GRUB_MACHINE_EFI
> +  state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip;
> +  state_efi.MULTIBOOT_EFI_MBI_REGISTER = target;
> +
> +  if (grub_efi_is_finished)
> +    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
> +  else
> +    grub_relocator_efi_boot (grub_multiboot_relocator, state_efi);
> +#else
>    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
> +#endif
>  #else
>    grub_relocator32_boot (grub_multiboot_relocator, state);
>  #endif
> diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> index d7c19bc..8d66e3f 100644
> --- a/grub-core/loader/multiboot_mbi2.c
> +++ b/grub-core/loader/multiboot_mbi2.c
> @@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>    grub_err_t err;
>    struct multiboot_header_tag *tag;
>    struct multiboot_header_tag_address *addr_tag = NULL;
> -  int entry_specified = 0;
> -  grub_addr_t entry = 0;
> +  int entry_specified = 0, efi_entry_specified = 0;
> +  grub_addr_t entry = 0, efi_entry = 0;
>    grub_uint32_t console_required = 0;
>    struct multiboot_header_tag_framebuffer *fbtag = NULL;
>    int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
> @@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;
>  	break;
>  
> +      case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64:
> +#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__)
> +	efi_entry_specified = 1;
> +	efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr;
> +#endif
> +	break;
> +
>        case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS:
>  	if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags
>  	    & MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED))
> @@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	break;
>  
>        case MULTIBOOT_HEADER_TAG_EFI_BS:
> +#ifdef GRUB_MACHINE_EFI
>  	keep_bs = 1;
> +#endif
>  	break;
>  
>        default:
> @@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	break;
>        }
>  
> -  if (addr_tag && !entry_specified)
> +  if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified))
>      {
>        grub_free (buffer);
>        return grub_error (GRUB_ERR_UNKNOWN_OS,
> @@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	}
>      }
>  
> -  if (entry_specified)
> +  if (keep_bs && efi_entry_specified)
> +    grub_multiboot_payload_eip = efi_entry;
> +  else if (entry_specified)
>      grub_multiboot_payload_eip = entry;
>  
>    if (fbtag)
> diff --git a/include/grub/i386/multiboot.h b/include/grub/i386/multiboot.h
> index a1b9488..807a1de 100644
> --- a/include/grub/i386/multiboot.h
> +++ b/include/grub/i386/multiboot.h
> @@ -30,6 +30,17 @@
>  #define MULTIBOOT_MBI_REGISTER ebx
>  #define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_I386
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +#define MULTIBOOT_EFI_INITIAL_STATE  { .rax = MULTIBOOT_BOOTLOADER_MAGIC,	\
> +    .rcx = 0,									\
> +    .rdx = 0,									\
> +      }
> +#define MULTIBOOT_EFI_ENTRY_REGISTER rip
> +#define MULTIBOOT_EFI_MBI_REGISTER rbx
> +#endif
> +#endif
> +
>  #define MULTIBOOT_ELF32_MACHINE EM_386
>  #define MULTIBOOT_ELF64_MACHINE EM_X86_64
>  
> diff --git a/include/grub/i386/relocator.h b/include/grub/i386/relocator.h
> index 5f89a7e..2a56c3b 100644
> --- a/include/grub/i386/relocator.h
> +++ b/include/grub/i386/relocator.h
> @@ -65,6 +65,20 @@ struct grub_relocator64_state
>    grub_addr_t cr3;
>  };
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +struct grub_relocator64_efi_state
> +{
> +  grub_uint64_t rax;
> +  grub_uint64_t rbx;
> +  grub_uint64_t rcx;
> +  grub_uint64_t rdx;
> +  grub_uint64_t rip;
> +  grub_uint64_t rsi;
> +};
> +#endif
> +#endif
> +
>  grub_err_t grub_relocator16_boot (struct grub_relocator *rel,
>  				  struct grub_relocator16_state state);
>  
> @@ -76,4 +90,11 @@ grub_err_t grub_relocator64_boot (struct grub_relocator *rel,
>  				  struct grub_relocator64_state state,
>  				  grub_addr_t min_addr, grub_addr_t max_addr);
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel,
> +				      struct grub_relocator64_efi_state state);
> +#endif
> +#endif
> +
>  #endif /* ! GRUB_RELOCATOR_CPU_HEADER */
> diff --git a/include/multiboot2.h b/include/multiboot2.h
> index 9d48627..b3977e3 100644
> --- a/include/multiboot2.h
> +++ b/include/multiboot2.h
> @@ -69,6 +69,7 @@
>  #define MULTIBOOT_HEADER_TAG_FRAMEBUFFER  5
>  #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
>  #define MULTIBOOT_HEADER_TAG_EFI_BS  7
> +#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
>  
>  #define MULTIBOOT_ARCHITECTURE_I386  0
>  #define MULTIBOOT_ARCHITECTURE_MIPS32  4
> @@ -133,6 +134,14 @@ struct multiboot_header_tag_entry_address
>    multiboot_uint32_t entry_addr;
>  };
>  
> +struct multiboot_header_tag_entry_address_efi64
> +{
> +  multiboot_uint16_t type;
> +  multiboot_uint16_t flags;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t entry_addr;
> +};
> +
>  struct multiboot_header_tag_console_flags
>  {
>    multiboot_uint16_t type;
> -- 
> 1.7.10.4
> 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
@ 2015-08-11 17:02     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 67+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-08-11 17:02 UTC (permalink / raw)
  To: Daniel Kiper, phcoder, arvidjaar
  Cc: jgross, grub-devel, wei.liu2, keir, ian.campbell,
	stefano.stabellini, andrew.cooper3, roy.franz, ning.sun,
	david.vrabel, jbeulich, phcoder, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei

On Mon, Jul 20, 2015 at 04:35:51PM +0200, Daniel Kiper wrote:
> Add grub_relocator64_efi relocator. It will be used on EFI 64-bit platforms
> when multiboot2 compatible image requests MULTIBOOT_TAG_TYPE_EFI_BS. Relocator
> will set lower parts of %rax and %rbx accordingly to multiboot2 specification.
> On the other hand processor mode, just before jumping into loaded image, will
> be set accordingly to Unified Extensible Firmware Interface Specification,
> Version 2.4 Errata B, section 2.3.4, x64 Platforms, boot services. This way
> loaded image will be able to use EFI boot services without any issues.

Andrei, Valdimir: ping?

> 
> If idea is accepted I will prepare grub_relocator32_efi relocator too.
> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/Makefile.core.def          |    1 +
>  grub-core/lib/i386/relocator.c       |   53 +++++++++++++++++++++++
>  grub-core/lib/i386/relocator64_efi.S |   77 ++++++++++++++++++++++++++++++++++
>  grub-core/loader/multiboot.c         |   29 +++++++++++--
>  grub-core/loader/multiboot_mbi2.c    |   19 +++++++--
>  include/grub/i386/multiboot.h        |   11 +++++
>  include/grub/i386/relocator.h        |   21 ++++++++++
>  include/multiboot2.h                 |    9 ++++
>  8 files changed, 213 insertions(+), 7 deletions(-)
>  create mode 100644 grub-core/lib/i386/relocator64_efi.S
> 
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index a6101de..d583549 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -1519,6 +1519,7 @@ module = {
>    x86 = lib/i386/relocator_common_c.c;
>    ieee1275 = lib/ieee1275/relocator.c;
>    efi = lib/efi/relocator.c;
> +  x86_64_efi = lib/i386/relocator64_efi.S;
>    mips = lib/mips/relocator_asm.S;
>    mips = lib/mips/relocator.c;
>    powerpc = lib/powerpc/relocator_asm.S;
> diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c
> index 71dd4f0..459027e 100644
> --- a/grub-core/lib/i386/relocator.c
> +++ b/grub-core/lib/i386/relocator.c
> @@ -69,6 +69,19 @@ extern grub_uint64_t grub_relocator64_rsi;
>  extern grub_addr_t grub_relocator64_cr3;
>  extern struct grub_i386_idt grub_relocator16_idt;
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +extern grub_uint8_t grub_relocator64_efi_start;
> +extern grub_uint8_t grub_relocator64_efi_end;
> +extern grub_uint64_t grub_relocator64_efi_rax;
> +extern grub_uint64_t grub_relocator64_efi_rbx;
> +extern grub_uint64_t grub_relocator64_efi_rcx;
> +extern grub_uint64_t grub_relocator64_efi_rdx;
> +extern grub_uint64_t grub_relocator64_efi_rip;
> +extern grub_uint64_t grub_relocator64_efi_rsi;
> +#endif
> +#endif
> +
>  #define RELOCATOR_SIZEOF(x)	(&grub_relocator##x##_end - &grub_relocator##x##_start)
>  
>  grub_err_t
> @@ -214,3 +227,43 @@ grub_relocator64_boot (struct grub_relocator *rel,
>    /* Not reached.  */
>    return GRUB_ERR_NONE;
>  }
> +
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +grub_err_t
> +grub_relocator64_efi_boot (struct grub_relocator *rel,
> +			   struct grub_relocator64_efi_state state)
> +{
> +  grub_err_t err;
> +  void *relst;
> +  grub_relocator_chunk_t ch;
> +
> +  err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
> +					  0x40000000 - RELOCATOR_SIZEOF (64_efi),
> +					  RELOCATOR_SIZEOF (64_efi), 16,
> +					  GRUB_RELOCATOR_PREFERENCE_NONE, 1);
> +  if (err)
> +    return err;
> +
> +  grub_relocator64_efi_rax = state.rax;
> +  grub_relocator64_efi_rbx = state.rbx;
> +  grub_relocator64_efi_rcx = state.rcx;
> +  grub_relocator64_efi_rdx = state.rdx;
> +  grub_relocator64_efi_rip = state.rip;
> +  grub_relocator64_efi_rsi = state.rsi;
> +
> +  grub_memmove (get_virtual_current_address (ch), &grub_relocator64_efi_start,
> +		RELOCATOR_SIZEOF (64_efi));
> +
> +  err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch),
> +				       &relst, NULL);
> +  if (err)
> +    return err;
> +
> +  ((void (*) (void)) relst) ();
> +
> +  /* Not reached.  */
> +  return GRUB_ERR_NONE;
> +}
> +#endif
> +#endif
> diff --git a/grub-core/lib/i386/relocator64_efi.S b/grub-core/lib/i386/relocator64_efi.S
> new file mode 100644
> index 0000000..fcd1964
> --- /dev/null
> +++ b/grub-core/lib/i386/relocator64_efi.S
> @@ -0,0 +1,77 @@
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2009,2010  Free Software Foundation, Inc.
> + *  Copyright (C) 2014,2015  Oracle Co.
> + *      Author: Daniel Kiper
> + *
> + *  GRUB 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 3 of the License, or
> + *  (at your option) any later version.
> + *
> + *  GRUB 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 GRUB.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include "relocator_common.S"
> +
> +	.p2align	4	/* force 16-byte alignment */
> +
> +VARIABLE(grub_relocator64_efi_start)
> +	PREAMBLE
> +
> +	.code64
> +
> +	/* mov imm64, %rax */
> +	.byte 	0x48
> +	.byte	0xb8
> +VARIABLE(grub_relocator64_efi_rsi)
> +	.quad	0
> +
> +	movq	%rax, %rsi
> +
> +	/* mov imm64, %rax */
> +	.byte 	0x48
> +	.byte	0xb8
> +VARIABLE(grub_relocator64_efi_rax)
> +	.quad	0
> +
> +	/* mov imm64, %rbx */
> +	.byte 	0x48
> +	.byte	0xbb
> +VARIABLE(grub_relocator64_efi_rbx)
> +	.quad	0
> +
> +	/* mov imm64, %rcx */
> +	.byte 	0x48
> +	.byte	0xb9
> +VARIABLE(grub_relocator64_efi_rcx)
> +	.quad	0
> +
> +	/* mov imm64, %rdx */
> +	.byte 	0x48
> +	.byte	0xba
> +VARIABLE(grub_relocator64_efi_rdx)
> +	.quad	0
> +
> +	/* Cleared direction flag is of no problem with any current
> +	   payload and makes this implementation easier.  */
> +	cld
> +
> +#ifdef __APPLE__
> +	.byte 0xff, 0x25
> +	.quad 0
> +#else
> +	jmp *LOCAL(jump_addr) (%rip)
> +#endif
> +
> +LOCAL(jump_addr):
> +VARIABLE(grub_relocator64_efi_rip)
> +	.quad	0
> +
> +VARIABLE(grub_relocator64_efi_end)
> diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
> index fd8f28e..ca7154f 100644
> --- a/grub-core/loader/multiboot.c
> +++ b/grub-core/loader/multiboot.c
> @@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)
>    return err;
>  }
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +#define grub_relocator_efi_boot	grub_relocator64_efi_boot
> +#endif
> +#endif
> +
>  static grub_err_t
>  grub_multiboot_boot (void)
>  {
>    grub_err_t err;
> +  grub_uint32_t target;
>    struct grub_relocator32_state state = MULTIBOOT_INITIAL_STATE;
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +  struct grub_relocator64_efi_state state_efi = MULTIBOOT_EFI_INITIAL_STATE;
> +#endif
> +#endif
>  
> -  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
> -
> -  err = grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER);
> +  err = grub_multiboot_make_mbi (&target);
>  
>    if (err)
>      return err;
>  
> +  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
> +  state.MULTIBOOT_MBI_REGISTER = target;
> +
>  #if defined (__i386__) || defined (__x86_64__)
> +#ifdef GRUB_MACHINE_EFI
> +  state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip;
> +  state_efi.MULTIBOOT_EFI_MBI_REGISTER = target;
> +
> +  if (grub_efi_is_finished)
> +    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
> +  else
> +    grub_relocator_efi_boot (grub_multiboot_relocator, state_efi);
> +#else
>    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
> +#endif
>  #else
>    grub_relocator32_boot (grub_multiboot_relocator, state);
>  #endif
> diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> index d7c19bc..8d66e3f 100644
> --- a/grub-core/loader/multiboot_mbi2.c
> +++ b/grub-core/loader/multiboot_mbi2.c
> @@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>    grub_err_t err;
>    struct multiboot_header_tag *tag;
>    struct multiboot_header_tag_address *addr_tag = NULL;
> -  int entry_specified = 0;
> -  grub_addr_t entry = 0;
> +  int entry_specified = 0, efi_entry_specified = 0;
> +  grub_addr_t entry = 0, efi_entry = 0;
>    grub_uint32_t console_required = 0;
>    struct multiboot_header_tag_framebuffer *fbtag = NULL;
>    int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
> @@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;
>  	break;
>  
> +      case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64:
> +#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__)
> +	efi_entry_specified = 1;
> +	efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr;
> +#endif
> +	break;
> +
>        case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS:
>  	if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags
>  	    & MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED))
> @@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	break;
>  
>        case MULTIBOOT_HEADER_TAG_EFI_BS:
> +#ifdef GRUB_MACHINE_EFI
>  	keep_bs = 1;
> +#endif
>  	break;
>  
>        default:
> @@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	break;
>        }
>  
> -  if (addr_tag && !entry_specified)
> +  if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified))
>      {
>        grub_free (buffer);
>        return grub_error (GRUB_ERR_UNKNOWN_OS,
> @@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	}
>      }
>  
> -  if (entry_specified)
> +  if (keep_bs && efi_entry_specified)
> +    grub_multiboot_payload_eip = efi_entry;
> +  else if (entry_specified)
>      grub_multiboot_payload_eip = entry;
>  
>    if (fbtag)
> diff --git a/include/grub/i386/multiboot.h b/include/grub/i386/multiboot.h
> index a1b9488..807a1de 100644
> --- a/include/grub/i386/multiboot.h
> +++ b/include/grub/i386/multiboot.h
> @@ -30,6 +30,17 @@
>  #define MULTIBOOT_MBI_REGISTER ebx
>  #define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_I386
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +#define MULTIBOOT_EFI_INITIAL_STATE  { .rax = MULTIBOOT_BOOTLOADER_MAGIC,	\
> +    .rcx = 0,									\
> +    .rdx = 0,									\
> +      }
> +#define MULTIBOOT_EFI_ENTRY_REGISTER rip
> +#define MULTIBOOT_EFI_MBI_REGISTER rbx
> +#endif
> +#endif
> +
>  #define MULTIBOOT_ELF32_MACHINE EM_386
>  #define MULTIBOOT_ELF64_MACHINE EM_X86_64
>  
> diff --git a/include/grub/i386/relocator.h b/include/grub/i386/relocator.h
> index 5f89a7e..2a56c3b 100644
> --- a/include/grub/i386/relocator.h
> +++ b/include/grub/i386/relocator.h
> @@ -65,6 +65,20 @@ struct grub_relocator64_state
>    grub_addr_t cr3;
>  };
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +struct grub_relocator64_efi_state
> +{
> +  grub_uint64_t rax;
> +  grub_uint64_t rbx;
> +  grub_uint64_t rcx;
> +  grub_uint64_t rdx;
> +  grub_uint64_t rip;
> +  grub_uint64_t rsi;
> +};
> +#endif
> +#endif
> +
>  grub_err_t grub_relocator16_boot (struct grub_relocator *rel,
>  				  struct grub_relocator16_state state);
>  
> @@ -76,4 +90,11 @@ grub_err_t grub_relocator64_boot (struct grub_relocator *rel,
>  				  struct grub_relocator64_state state,
>  				  grub_addr_t min_addr, grub_addr_t max_addr);
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel,
> +				      struct grub_relocator64_efi_state state);
> +#endif
> +#endif
> +
>  #endif /* ! GRUB_RELOCATOR_CPU_HEADER */
> diff --git a/include/multiboot2.h b/include/multiboot2.h
> index 9d48627..b3977e3 100644
> --- a/include/multiboot2.h
> +++ b/include/multiboot2.h
> @@ -69,6 +69,7 @@
>  #define MULTIBOOT_HEADER_TAG_FRAMEBUFFER  5
>  #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
>  #define MULTIBOOT_HEADER_TAG_EFI_BS  7
> +#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
>  
>  #define MULTIBOOT_ARCHITECTURE_I386  0
>  #define MULTIBOOT_ARCHITECTURE_MIPS32  4
> @@ -133,6 +134,14 @@ struct multiboot_header_tag_entry_address
>    multiboot_uint32_t entry_addr;
>  };
>  
> +struct multiboot_header_tag_entry_address_efi64
> +{
> +  multiboot_uint16_t type;
> +  multiboot_uint16_t flags;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t entry_addr;
> +};
> +
>  struct multiboot_header_tag_console_flags
>  {
>    multiboot_uint16_t type;
> -- 
> 1.7.10.4
> 


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image
  2015-07-20 14:35 ` Daniel Kiper
@ 2015-08-11 18:38   ` Konrad Rzeszutek Wilk
  2015-08-11 18:38   ` Konrad Rzeszutek Wilk
       [not found]   ` <CAEaD8JOaS=J22k+Sq=8Ou77pO6yvtgxSLiwuMjAoirSipJhW6g@mail.gmail.com>
  2 siblings, 0 replies; 67+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-08-11 18:38 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, wei.liu2, keir, ian.campbell,
	stefano.stabellini, andrew.cooper3, roy.franz, ning.sun,
	david.vrabel, jbeulich, phcoder, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei

On Mon, Jul 20, 2015 at 04:35:52PM +0200, Daniel Kiper wrote:
> Add tags used to pass ImageHandle to loaded image. It is used

s/loaded image/loaded image if requested./
> by at least ExitBootServices() function.
> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/loader/multiboot_mbi2.c |   46 +++++++++++++++++++++++++++++--------
>  include/multiboot2.h              |   16 +++++++++++++
>  2 files changed, 53 insertions(+), 9 deletions(-)
> 
> diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> index 8d66e3f..dc9c709 100644
> --- a/grub-core/loader/multiboot_mbi2.c
> +++ b/grub-core/loader/multiboot_mbi2.c
> @@ -172,6 +172,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	      case MULTIBOOT_TAG_TYPE_NETWORK:
>  	      case MULTIBOOT_TAG_TYPE_EFI_MMAP:
>  	      case MULTIBOOT_TAG_TYPE_EFI_BS:
> +	      case MULTIBOOT_TAG_TYPE_EFI32_IH:
> +	      case MULTIBOOT_TAG_TYPE_EFI64_IH:
>  		break;
>  
>  	      default:
> @@ -407,16 +409,18 @@ grub_multiboot_get_mbi_size (void)
>  		 + grub_get_multiboot_mmap_count ()
>  		 * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN)
>      + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN)
> +#ifdef GRUB_MACHINE_EFI
>      + ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN)
>      + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
> +    + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih), MULTIBOOT_TAG_ALIGN)

Shouldn't they be wrapped with #ifdef __x86_64__ (for efi64_ih) and #ifdef __i386__
for the other?

Or two functions (in the header?) wrapped with proper #ifdef machinery?

> +    + ALIGN_UP (sizeof (struct multiboot_tag_efi64_ih), MULTIBOOT_TAG_ALIGN)
> +    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
> +		+ efi_mmap_size, MULTIBOOT_TAG_ALIGN)
> +#endif
>      + ALIGN_UP (sizeof (struct multiboot_tag_old_acpi)
>  		+ sizeof (struct grub_acpi_rsdp_v10), MULTIBOOT_TAG_ALIGN)
>      + acpiv2_size ()
>      + net_size ()
> -#ifdef GRUB_MACHINE_EFI
> -    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
> -		+ efi_mmap_size, MULTIBOOT_TAG_ALIGN)
> -#endif
>      + sizeof (struct multiboot_tag_vbe) + MULTIBOOT_TAG_ALIGN - 1
>      + sizeof (struct multiboot_tag_apm) + MULTIBOOT_TAG_ALIGN - 1;
>  }
> @@ -906,11 +910,35 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
>  
>    if (keep_bs)
>      {
> -      struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
> -      tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
> -      tag->size = sizeof (struct multiboot_tag);
> -      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> -	/ sizeof (grub_properly_aligned_t);
> +      {
> +	struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
> +	tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
> +	tag->size = sizeof (struct multiboot_tag);
> +	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +	  / sizeof (grub_properly_aligned_t);
> +      }
> +
> +#ifdef __x86_64__
> +      {
> +	struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig;
> +	tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH;
> +	tag->size = sizeof (*tag);

The other places where sizeof is used ends up using the full structure so it :

sizeof (struct multiboot_tag_efi64_ih)

> +	tag->pointer = (grub_addr_t) grub_efi_image_handle;
> +	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +	  / sizeof (grub_properly_aligned_t);
> +      }
> +#endif
> +
> +#ifdef __i386__
> +      {
> +	struct multiboot_tag_efi32_ih *tag = (struct multiboot_tag_efi32_ih *) ptrorig;
> +	tag->type = MULTIBOOT_TAG_TYPE_EFI32_IH;
> +	tag->size = sizeof (*tag);

Ditto.
> +	tag->pointer = (grub_addr_t) grub_efi_image_handle;
> +	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +	  / sizeof (grub_properly_aligned_t);
> +      }
> +#endif
>      }
>  #endif
>  
> diff --git a/include/multiboot2.h b/include/multiboot2.h
> index b3977e3..9f97ddc 100644
> --- a/include/multiboot2.h
> +++ b/include/multiboot2.h
> @@ -60,6 +60,8 @@
>  #define MULTIBOOT_TAG_TYPE_NETWORK           16
>  #define MULTIBOOT_TAG_TYPE_EFI_MMAP          17
>  #define MULTIBOOT_TAG_TYPE_EFI_BS            18
> +#define MULTIBOOT_TAG_TYPE_EFI32_IH          19
> +#define MULTIBOOT_TAG_TYPE_EFI64_IH          20
>  
>  #define MULTIBOOT_HEADER_TAG_END  0
>  #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
> @@ -379,6 +381,20 @@ struct multiboot_tag_efi_mmap
>    multiboot_uint8_t efi_mmap[0];
>  }; 
>  
> +struct multiboot_tag_efi32_ih
> +{
> +  multiboot_uint32_t type;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t pointer;
> +};
> +
> +struct multiboot_tag_efi64_ih
> +{
> +  multiboot_uint32_t type;
> +  multiboot_uint32_t size;
> +  multiboot_uint64_t pointer;
> +};
> +
>  #endif /* ! ASM_FILE */
>  
>  #endif /* ! MULTIBOOT_HEADER */
> -- 
> 1.7.10.4
> 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image
  2015-07-20 14:35 ` Daniel Kiper
  2015-08-11 18:38   ` Konrad Rzeszutek Wilk
@ 2015-08-11 18:38   ` Konrad Rzeszutek Wilk
       [not found]     ` <CAEaD8JOPxLVECcUqjj2-x5AeXjbQ9Cd7bOaoe8UPU2t7wdoxpA@mail.gmail.com>
       [not found]   ` <CAEaD8JOaS=J22k+Sq=8Ou77pO6yvtgxSLiwuMjAoirSipJhW6g@mail.gmail.com>
  2 siblings, 1 reply; 67+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-08-11 18:38 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, wei.liu2, keir, ian.campbell,
	stefano.stabellini, andrew.cooper3, roy.franz, ning.sun,
	david.vrabel, jbeulich, phcoder, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei

On Mon, Jul 20, 2015 at 04:35:52PM +0200, Daniel Kiper wrote:
> Add tags used to pass ImageHandle to loaded image. It is used

s/loaded image/loaded image if requested./
> by at least ExitBootServices() function.
> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/loader/multiboot_mbi2.c |   46 +++++++++++++++++++++++++++++--------
>  include/multiboot2.h              |   16 +++++++++++++
>  2 files changed, 53 insertions(+), 9 deletions(-)
> 
> diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> index 8d66e3f..dc9c709 100644
> --- a/grub-core/loader/multiboot_mbi2.c
> +++ b/grub-core/loader/multiboot_mbi2.c
> @@ -172,6 +172,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	      case MULTIBOOT_TAG_TYPE_NETWORK:
>  	      case MULTIBOOT_TAG_TYPE_EFI_MMAP:
>  	      case MULTIBOOT_TAG_TYPE_EFI_BS:
> +	      case MULTIBOOT_TAG_TYPE_EFI32_IH:
> +	      case MULTIBOOT_TAG_TYPE_EFI64_IH:
>  		break;
>  
>  	      default:
> @@ -407,16 +409,18 @@ grub_multiboot_get_mbi_size (void)
>  		 + grub_get_multiboot_mmap_count ()
>  		 * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN)
>      + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN)
> +#ifdef GRUB_MACHINE_EFI
>      + ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN)
>      + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
> +    + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih), MULTIBOOT_TAG_ALIGN)

Shouldn't they be wrapped with #ifdef __x86_64__ (for efi64_ih) and #ifdef __i386__
for the other?

Or two functions (in the header?) wrapped with proper #ifdef machinery?

> +    + ALIGN_UP (sizeof (struct multiboot_tag_efi64_ih), MULTIBOOT_TAG_ALIGN)
> +    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
> +		+ efi_mmap_size, MULTIBOOT_TAG_ALIGN)
> +#endif
>      + ALIGN_UP (sizeof (struct multiboot_tag_old_acpi)
>  		+ sizeof (struct grub_acpi_rsdp_v10), MULTIBOOT_TAG_ALIGN)
>      + acpiv2_size ()
>      + net_size ()
> -#ifdef GRUB_MACHINE_EFI
> -    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
> -		+ efi_mmap_size, MULTIBOOT_TAG_ALIGN)
> -#endif
>      + sizeof (struct multiboot_tag_vbe) + MULTIBOOT_TAG_ALIGN - 1
>      + sizeof (struct multiboot_tag_apm) + MULTIBOOT_TAG_ALIGN - 1;
>  }
> @@ -906,11 +910,35 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
>  
>    if (keep_bs)
>      {
> -      struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
> -      tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
> -      tag->size = sizeof (struct multiboot_tag);
> -      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> -	/ sizeof (grub_properly_aligned_t);
> +      {
> +	struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
> +	tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
> +	tag->size = sizeof (struct multiboot_tag);
> +	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +	  / sizeof (grub_properly_aligned_t);
> +      }
> +
> +#ifdef __x86_64__
> +      {
> +	struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig;
> +	tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH;
> +	tag->size = sizeof (*tag);

The other places where sizeof is used ends up using the full structure so it :

sizeof (struct multiboot_tag_efi64_ih)

> +	tag->pointer = (grub_addr_t) grub_efi_image_handle;
> +	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +	  / sizeof (grub_properly_aligned_t);
> +      }
> +#endif
> +
> +#ifdef __i386__
> +      {
> +	struct multiboot_tag_efi32_ih *tag = (struct multiboot_tag_efi32_ih *) ptrorig;
> +	tag->type = MULTIBOOT_TAG_TYPE_EFI32_IH;
> +	tag->size = sizeof (*tag);

Ditto.
> +	tag->pointer = (grub_addr_t) grub_efi_image_handle;
> +	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +	  / sizeof (grub_properly_aligned_t);
> +      }
> +#endif
>      }
>  #endif
>  
> diff --git a/include/multiboot2.h b/include/multiboot2.h
> index b3977e3..9f97ddc 100644
> --- a/include/multiboot2.h
> +++ b/include/multiboot2.h
> @@ -60,6 +60,8 @@
>  #define MULTIBOOT_TAG_TYPE_NETWORK           16
>  #define MULTIBOOT_TAG_TYPE_EFI_MMAP          17
>  #define MULTIBOOT_TAG_TYPE_EFI_BS            18
> +#define MULTIBOOT_TAG_TYPE_EFI32_IH          19
> +#define MULTIBOOT_TAG_TYPE_EFI64_IH          20
>  
>  #define MULTIBOOT_HEADER_TAG_END  0
>  #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
> @@ -379,6 +381,20 @@ struct multiboot_tag_efi_mmap
>    multiboot_uint8_t efi_mmap[0];
>  }; 
>  
> +struct multiboot_tag_efi32_ih
> +{
> +  multiboot_uint32_t type;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t pointer;
> +};
> +
> +struct multiboot_tag_efi64_ih
> +{
> +  multiboot_uint32_t type;
> +  multiboot_uint32_t size;
> +  multiboot_uint64_t pointer;
> +};
> +
>  #endif /* ! ASM_FILE */
>  
>  #endif /* ! MULTIBOOT_HEADER */
> -- 
> 1.7.10.4
> 


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
  2015-07-20 14:35 ` [PATCH v2 5/6] multiboot2: Add support for relocatable images Daniel Kiper
  2015-08-11 18:51   ` Konrad Rzeszutek Wilk
@ 2015-08-11 18:51   ` Konrad Rzeszutek Wilk
  2015-11-09 20:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-09 20:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
  3 siblings, 0 replies; 67+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-08-11 18:51 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, wei.liu2, keir, ian.campbell,
	stefano.stabellini, andrew.cooper3, roy.franz, ning.sun,
	david.vrabel, jbeulich, phcoder, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei

On Mon, Jul 20, 2015 at 04:35:53PM +0200, Daniel Kiper wrote:

This parts needs a bit of details I think.

As in why can't the ELF note that is present in the binary
be satisfied. Or under what conditions would the existing code
not work?

> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/loader/i386/multiboot_mbi.c |    6 ++--
>  grub-core/loader/multiboot.c          |   12 +++++--
>  grub-core/loader/multiboot_elfxx.c    |   28 +++++++++++----
>  grub-core/loader/multiboot_mbi2.c     |   63 +++++++++++++++++++++++++++++----
>  include/grub/multiboot.h              |    4 ++-
>  include/multiboot2.h                  |   24 +++++++++++++
>  6 files changed, 118 insertions(+), 19 deletions(-)
> 
> diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c
> index 956d0e3..abdb98b 100644
> --- a/grub-core/loader/i386/multiboot_mbi.c
> +++ b/grub-core/loader/i386/multiboot_mbi.c
> @@ -72,7 +72,8 @@ load_kernel (grub_file_t file, const char *filename,
>    grub_err_t err;
>    if (grub_multiboot_quirks & GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE)
>      {
> -      err = grub_multiboot_load_elf (file, filename, buffer);
> +      err = grub_multiboot_load_elf (file, filename, buffer, 0, 0, 0, 0,
> +				     GRUB_RELOCATOR_PREFERENCE_NONE, NULL, 0);
>        if (err == GRUB_ERR_UNKNOWN_OS && (header->flags & MULTIBOOT_AOUT_KLUDGE))
>  	grub_errno = err = GRUB_ERR_NONE;
>      }
> @@ -118,7 +119,8 @@ load_kernel (grub_file_t file, const char *filename,
>        return GRUB_ERR_NONE;
>      }
>  
> -  return grub_multiboot_load_elf (file, filename, buffer);
> +  return grub_multiboot_load_elf (file, filename, buffer, 0, 0, 0, 0,
> +				  GRUB_RELOCATOR_PREFERENCE_NONE, NULL, 0);

Oh boy. That is a bit hard to read. Perhaps another function could be introduced?

grub_multiboot_load_elf_ignore_reloc ? which would just pass the three
parameters and set the rest to the 0 options?


>  }
>  
>  static struct multiboot_header *
> diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
> index ca7154f..1b1f7a9 100644
> --- a/grub-core/loader/multiboot.c
> +++ b/grub-core/loader/multiboot.c
> @@ -190,12 +190,18 @@ static grub_uint64_t highest_load;
>  /* Load ELF32 or ELF64.  */
>  grub_err_t
>  grub_multiboot_load_elf (grub_file_t file, const char *filename,
> -			 void *buffer)
> +			 void *buffer, int relocatable, grub_uint32_t min_addr,
> +			 grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
> +			 grub_uint32_t *base_addr, int avoid_efi_boot_services)

s/int/bool/ ?

>  {
>    if (grub_multiboot_is_elf32 (buffer))
> -    return grub_multiboot_load_elf32 (file, filename, buffer);
> +    return grub_multiboot_load_elf32 (file, filename, buffer, relocatable,
> +				      min_addr, max_addr, align, preference,
> +				      base_addr, avoid_efi_boot_services);
>    else if (grub_multiboot_is_elf64 (buffer))
> -    return grub_multiboot_load_elf64 (file, filename, buffer);
> +    return grub_multiboot_load_elf64 (file, filename, buffer, relocatable,
> +				      min_addr, max_addr, align, preference,
> +				      base_addr, avoid_efi_boot_services);
>  
>    return grub_error (GRUB_ERR_UNKNOWN_OS, N_("invalid arch-dependent ELF magic"));
>  }
> diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c
> index 6a220bd..4fce685 100644
> --- a/grub-core/loader/multiboot_elfxx.c
> +++ b/grub-core/loader/multiboot_elfxx.c
> @@ -51,7 +51,10 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer)
>  }
>  
>  static grub_err_t
> -CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, void *buffer)
> +CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename,
> +				     void *buffer, int relocatable, grub_uint32_t min_addr,
> +				     grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
> +				     grub_uint32_t *base_addr, int avoid_efi_boot_services)
>  {
>    Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;
>    char *phdr_base;
> @@ -89,19 +92,30 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
>  	  if (phdr(i)->p_paddr + phdr(i)->p_memsz > highest_load)
>  	    highest_load = phdr(i)->p_paddr + phdr(i)->p_memsz;
>  
> -	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n",
> -			i, (long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr);
> +	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx,"
> +			"align=0x%lx, relocatable=%d, avoid_efi_boot_services=%d\n", i,

%d to %s 
> +			(long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr,
> +			(long) align, relocatable, avoid_efi_boot_services);

and then

avoid_efi_boot_services ? "yes" : "no"

>  
>  	  {
>  	    grub_relocator_chunk_t ch;
> -	    err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, 
> -						   &ch, phdr(i)->p_paddr,
> -						   phdr(i)->p_memsz);
> +
> +	    if (relocatable)
> +	      err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
> +						      min_addr, max_addr - phdr(i)->p_memsz,
> +						      phdr(i)->p_memsz, align ? align : 1,
> +						      preference, avoid_efi_boot_services);
> +	    else
> +	      err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
> +						     &ch, phdr(i)->p_paddr,
> +						     phdr(i)->p_memsz);
>  	    if (err)
>  	      {
>  		grub_dprintf ("multiboot_loader", "Error loading phdr %d\n", i);
>  		return err;
>  	      }
> +	    if (base_addr)
> +	      *base_addr = get_physical_target_address (ch);
>  	    source = get_virtual_current_address (ch);
>  	  }
>  
> @@ -208,7 +222,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
>  						    + 1, sh->sh_size,
>  						    sh->sh_addralign,
>  						    GRUB_RELOCATOR_PREFERENCE_NONE,
> -						    0);
> +						    avoid_efi_boot_services);
>  	    if (err)
>  	      {
>  		grub_dprintf ("multiboot_loader", "Error loading shdr %d\n", i);
> diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> index dc9c709..7ac64ec 100644
> --- a/grub-core/loader/multiboot_mbi2.c
> +++ b/grub-core/loader/multiboot_mbi2.c
> @@ -68,6 +68,7 @@ static grub_size_t elf_sec_num, elf_sec_entsize;
>  static unsigned elf_sec_shstrndx;
>  static void *elf_sections;
>  static int keep_bs = 0;
> +static grub_uint32_t base_addr = 0;
>  
>  void
>  grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,
> @@ -107,11 +108,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>    grub_err_t err;
>    struct multiboot_header_tag *tag;
>    struct multiboot_header_tag_address *addr_tag = NULL;
> -  int entry_specified = 0, efi_entry_specified = 0;
> +  int entry_specified = 0, efi_entry_specified = 0, relocatable = 0;
>    grub_addr_t entry = 0, efi_entry = 0;
> -  grub_uint32_t console_required = 0;
> +  grub_uint32_t console_required = 0, min_addr = 0;
> +  grub_uint32_t max_addr = 0, preference = 0;
>    struct multiboot_header_tag_framebuffer *fbtag = NULL;
>    int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
> +  grub_size_t align = 0;
>  
>    buffer = grub_malloc (MULTIBOOT_SEARCH);
>    if (!buffer)
> @@ -174,6 +177,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	      case MULTIBOOT_TAG_TYPE_EFI_BS:
>  	      case MULTIBOOT_TAG_TYPE_EFI32_IH:
>  	      case MULTIBOOT_TAG_TYPE_EFI64_IH:
> +	      case MULTIBOOT_TAG_TYPE_BASE_ADDR:
>  		break;
>  
>  	      default:
> @@ -215,6 +219,26 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	accepted_consoles |= GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER;
>  	break;
>  
> +      case MULTIBOOT_HEADER_TAG_RELOCATABLE:
> +	relocatable = 1;

How about:
	struct multiboot_header_tag_relocatable *_tag = (struct multiboot_header_tag_relocatable *)tag;

and then you don't have to use the casting?



> +	min_addr = ((struct multiboot_header_tag_relocatable *) tag)->min_addr;
> +	max_addr = ((struct multiboot_header_tag_relocatable *) tag)->max_addr;
> +	align = ((struct multiboot_header_tag_relocatable *) tag)->align;
> +	switch (((struct multiboot_header_tag_relocatable *) tag)->preference)
> +	  {
> +	  case MULTIBOOT_LOAD_PREFERENCE_LOW:
> +	    preference = GRUB_RELOCATOR_PREFERENCE_LOW;
> +	    break;
> +
> +	  case MULTIBOOT_LOAD_PREFERENCE_HIGH:
> +	    preference = GRUB_RELOCATOR_PREFERENCE_HIGH;
> +	    break;
> +
> +	  default:
> +	    preference = GRUB_RELOCATOR_PREFERENCE_NONE;
> +	  }
> +	break;
> +
>  	/* GRUB always page-aligns modules.  */
>        case MULTIBOOT_HEADER_TAG_MODULE_ALIGN:
>  	break;
> @@ -260,15 +284,22 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>        else
>  	code_size = load_size;
>  
> -      err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, 
> -					     &ch, load_addr,
> -					     code_size);
> +      if (relocatable)
> +	err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
> +						min_addr, max_addr - code_size,
> +						code_size, align ? align : 1,
> +						preference, keep_bs);
> +      else
> +	err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
> +					       &ch, load_addr,
> +					       code_size);
>        if (err)
>  	{
>  	  grub_dprintf ("multiboot_loader", "Error loading aout kludge\n");
>  	  grub_free (buffer);
>  	  return err;
>  	}
> +      base_addr = get_physical_target_address (ch);
>        source = get_virtual_current_address (ch);
>  
>        if ((grub_file_seek (file, offset)) == (grub_off_t) -1)
> @@ -290,7 +321,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>      }
>    else
>      {
> -      err = grub_multiboot_load_elf (file, filename, buffer);
> +      err = grub_multiboot_load_elf (file, filename, buffer,
> +				     relocatable, min_addr, max_addr,
> +				     align, preference, &base_addr, keep_bs);
>        if (err)
>  	{
>  	  grub_free (buffer);
> @@ -303,6 +336,14 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>    else if (entry_specified)
>      grub_multiboot_payload_eip = entry;
>  
> +  if (relocatable)
> +    {
> +      if (base_addr > min_addr)
> +	grub_multiboot_payload_eip += base_addr - min_addr;
> +      else
> +	grub_multiboot_payload_eip -= min_addr - base_addr;
> +    }
> +
>    if (fbtag)
>      err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER,
>  				      accepted_consoles,
> @@ -409,6 +450,7 @@ grub_multiboot_get_mbi_size (void)
>  		 + grub_get_multiboot_mmap_count ()
>  		 * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN)
>      + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN)
> +    + ALIGN_UP (sizeof (struct multiboot_tag_base_addr), MULTIBOOT_TAG_ALIGN)
>  #ifdef GRUB_MACHINE_EFI
>      + ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN)
>      + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
> @@ -693,6 +735,15 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
>    ptrorig += (2 * sizeof (grub_uint32_t)) / sizeof (grub_properly_aligned_t);
>  
>    {
> +    struct multiboot_tag_base_addr *tag = (struct multiboot_tag_base_addr *) ptrorig;
> +    tag->type = MULTIBOOT_TAG_TYPE_BASE_ADDR;
> +    tag->size = sizeof (struct multiboot_tag_base_addr); 

You have an extra space at the end.

> +    tag->base_addr = base_addr;
> +    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +       / sizeof (grub_properly_aligned_t);
> +  }
> +
> +  {
>      struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig;
>      tag->type = MULTIBOOT_TAG_TYPE_CMDLINE;
>      tag->size = sizeof (struct multiboot_tag_string) + cmdline_size; 
> diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h
> index e13c084..ec322b0 100644
> --- a/include/grub/multiboot.h
> +++ b/include/grub/multiboot.h
> @@ -94,7 +94,9 @@ grub_multiboot_load (grub_file_t file, const char *filename);
>  /* Load ELF32 or ELF64.  */
>  grub_err_t
>  grub_multiboot_load_elf (grub_file_t file, const char *filename,
> -			 void *buffer);
> +			 void *buffer, int relocatable, grub_uint32_t min_addr,
> +			 grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
> +			 grub_uint32_t *base_addr, int avoid_efi_boot_services);
>  extern grub_size_t grub_multiboot_pure_size;
>  extern grub_size_t grub_multiboot_alloc_mbi;
>  extern grub_uint32_t grub_multiboot_payload_eip;
> diff --git a/include/multiboot2.h b/include/multiboot2.h
> index 9f97ddc..941a95d 100644
> --- a/include/multiboot2.h
> +++ b/include/multiboot2.h
> @@ -62,6 +62,7 @@
>  #define MULTIBOOT_TAG_TYPE_EFI_BS            18
>  #define MULTIBOOT_TAG_TYPE_EFI32_IH          19
>  #define MULTIBOOT_TAG_TYPE_EFI64_IH          20
> +#define MULTIBOOT_TAG_TYPE_BASE_ADDR         21
>  
>  #define MULTIBOOT_HEADER_TAG_END  0
>  #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
> @@ -72,11 +73,16 @@
>  #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
>  #define MULTIBOOT_HEADER_TAG_EFI_BS  7
>  #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
> +#define MULTIBOOT_HEADER_TAG_RELOCATABLE  10
>  
>  #define MULTIBOOT_ARCHITECTURE_I386  0
>  #define MULTIBOOT_ARCHITECTURE_MIPS32  4
>  #define MULTIBOOT_HEADER_TAG_OPTIONAL 1
>  
> +#define MULTIBOOT_LOAD_PREFERENCE_NONE 0
> +#define MULTIBOOT_LOAD_PREFERENCE_LOW 1
> +#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2
> +
>  #define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
>  #define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
>  
> @@ -169,6 +175,17 @@ struct multiboot_header_tag_module_align
>    multiboot_uint32_t size;
>  };
>  
> +struct multiboot_header_tag_relocatable
> +{
> +  multiboot_uint16_t type;
> +  multiboot_uint16_t flags;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t min_addr;
> +  multiboot_uint32_t max_addr;
> +  multiboot_uint32_t align;
> +  multiboot_uint32_t preference;
> +};
> +
>  struct multiboot_color
>  {
>    multiboot_uint8_t red;
> @@ -395,6 +412,13 @@ struct multiboot_tag_efi64_ih
>    multiboot_uint64_t pointer;
>  };
>  
> +struct multiboot_tag_base_addr
> +{
> +  multiboot_uint32_t type;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t base_addr;
> +};
> +
>  #endif /* ! ASM_FILE */
>  
>  #endif /* ! MULTIBOOT_HEADER */
> -- 
> 1.7.10.4
> 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
  2015-07-20 14:35 ` [PATCH v2 5/6] multiboot2: Add support for relocatable images Daniel Kiper
@ 2015-08-11 18:51   ` Konrad Rzeszutek Wilk
  2015-08-11 18:51   ` Konrad Rzeszutek Wilk
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 67+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-08-11 18:51 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, wei.liu2, keir, ian.campbell,
	stefano.stabellini, andrew.cooper3, roy.franz, ning.sun,
	david.vrabel, jbeulich, phcoder, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei

On Mon, Jul 20, 2015 at 04:35:53PM +0200, Daniel Kiper wrote:

This parts needs a bit of details I think.

As in why can't the ELF note that is present in the binary
be satisfied. Or under what conditions would the existing code
not work?

> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/loader/i386/multiboot_mbi.c |    6 ++--
>  grub-core/loader/multiboot.c          |   12 +++++--
>  grub-core/loader/multiboot_elfxx.c    |   28 +++++++++++----
>  grub-core/loader/multiboot_mbi2.c     |   63 +++++++++++++++++++++++++++++----
>  include/grub/multiboot.h              |    4 ++-
>  include/multiboot2.h                  |   24 +++++++++++++
>  6 files changed, 118 insertions(+), 19 deletions(-)
> 
> diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c
> index 956d0e3..abdb98b 100644
> --- a/grub-core/loader/i386/multiboot_mbi.c
> +++ b/grub-core/loader/i386/multiboot_mbi.c
> @@ -72,7 +72,8 @@ load_kernel (grub_file_t file, const char *filename,
>    grub_err_t err;
>    if (grub_multiboot_quirks & GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE)
>      {
> -      err = grub_multiboot_load_elf (file, filename, buffer);
> +      err = grub_multiboot_load_elf (file, filename, buffer, 0, 0, 0, 0,
> +				     GRUB_RELOCATOR_PREFERENCE_NONE, NULL, 0);
>        if (err == GRUB_ERR_UNKNOWN_OS && (header->flags & MULTIBOOT_AOUT_KLUDGE))
>  	grub_errno = err = GRUB_ERR_NONE;
>      }
> @@ -118,7 +119,8 @@ load_kernel (grub_file_t file, const char *filename,
>        return GRUB_ERR_NONE;
>      }
>  
> -  return grub_multiboot_load_elf (file, filename, buffer);
> +  return grub_multiboot_load_elf (file, filename, buffer, 0, 0, 0, 0,
> +				  GRUB_RELOCATOR_PREFERENCE_NONE, NULL, 0);

Oh boy. That is a bit hard to read. Perhaps another function could be introduced?

grub_multiboot_load_elf_ignore_reloc ? which would just pass the three
parameters and set the rest to the 0 options?


>  }
>  
>  static struct multiboot_header *
> diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
> index ca7154f..1b1f7a9 100644
> --- a/grub-core/loader/multiboot.c
> +++ b/grub-core/loader/multiboot.c
> @@ -190,12 +190,18 @@ static grub_uint64_t highest_load;
>  /* Load ELF32 or ELF64.  */
>  grub_err_t
>  grub_multiboot_load_elf (grub_file_t file, const char *filename,
> -			 void *buffer)
> +			 void *buffer, int relocatable, grub_uint32_t min_addr,
> +			 grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
> +			 grub_uint32_t *base_addr, int avoid_efi_boot_services)

s/int/bool/ ?

>  {
>    if (grub_multiboot_is_elf32 (buffer))
> -    return grub_multiboot_load_elf32 (file, filename, buffer);
> +    return grub_multiboot_load_elf32 (file, filename, buffer, relocatable,
> +				      min_addr, max_addr, align, preference,
> +				      base_addr, avoid_efi_boot_services);
>    else if (grub_multiboot_is_elf64 (buffer))
> -    return grub_multiboot_load_elf64 (file, filename, buffer);
> +    return grub_multiboot_load_elf64 (file, filename, buffer, relocatable,
> +				      min_addr, max_addr, align, preference,
> +				      base_addr, avoid_efi_boot_services);
>  
>    return grub_error (GRUB_ERR_UNKNOWN_OS, N_("invalid arch-dependent ELF magic"));
>  }
> diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c
> index 6a220bd..4fce685 100644
> --- a/grub-core/loader/multiboot_elfxx.c
> +++ b/grub-core/loader/multiboot_elfxx.c
> @@ -51,7 +51,10 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer)
>  }
>  
>  static grub_err_t
> -CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, void *buffer)
> +CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename,
> +				     void *buffer, int relocatable, grub_uint32_t min_addr,
> +				     grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
> +				     grub_uint32_t *base_addr, int avoid_efi_boot_services)
>  {
>    Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;
>    char *phdr_base;
> @@ -89,19 +92,30 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
>  	  if (phdr(i)->p_paddr + phdr(i)->p_memsz > highest_load)
>  	    highest_load = phdr(i)->p_paddr + phdr(i)->p_memsz;
>  
> -	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n",
> -			i, (long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr);
> +	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx,"
> +			"align=0x%lx, relocatable=%d, avoid_efi_boot_services=%d\n", i,

%d to %s 
> +			(long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr,
> +			(long) align, relocatable, avoid_efi_boot_services);

and then

avoid_efi_boot_services ? "yes" : "no"

>  
>  	  {
>  	    grub_relocator_chunk_t ch;
> -	    err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, 
> -						   &ch, phdr(i)->p_paddr,
> -						   phdr(i)->p_memsz);
> +
> +	    if (relocatable)
> +	      err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
> +						      min_addr, max_addr - phdr(i)->p_memsz,
> +						      phdr(i)->p_memsz, align ? align : 1,
> +						      preference, avoid_efi_boot_services);
> +	    else
> +	      err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
> +						     &ch, phdr(i)->p_paddr,
> +						     phdr(i)->p_memsz);
>  	    if (err)
>  	      {
>  		grub_dprintf ("multiboot_loader", "Error loading phdr %d\n", i);
>  		return err;
>  	      }
> +	    if (base_addr)
> +	      *base_addr = get_physical_target_address (ch);
>  	    source = get_virtual_current_address (ch);
>  	  }
>  
> @@ -208,7 +222,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
>  						    + 1, sh->sh_size,
>  						    sh->sh_addralign,
>  						    GRUB_RELOCATOR_PREFERENCE_NONE,
> -						    0);
> +						    avoid_efi_boot_services);
>  	    if (err)
>  	      {
>  		grub_dprintf ("multiboot_loader", "Error loading shdr %d\n", i);
> diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> index dc9c709..7ac64ec 100644
> --- a/grub-core/loader/multiboot_mbi2.c
> +++ b/grub-core/loader/multiboot_mbi2.c
> @@ -68,6 +68,7 @@ static grub_size_t elf_sec_num, elf_sec_entsize;
>  static unsigned elf_sec_shstrndx;
>  static void *elf_sections;
>  static int keep_bs = 0;
> +static grub_uint32_t base_addr = 0;
>  
>  void
>  grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,
> @@ -107,11 +108,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>    grub_err_t err;
>    struct multiboot_header_tag *tag;
>    struct multiboot_header_tag_address *addr_tag = NULL;
> -  int entry_specified = 0, efi_entry_specified = 0;
> +  int entry_specified = 0, efi_entry_specified = 0, relocatable = 0;
>    grub_addr_t entry = 0, efi_entry = 0;
> -  grub_uint32_t console_required = 0;
> +  grub_uint32_t console_required = 0, min_addr = 0;
> +  grub_uint32_t max_addr = 0, preference = 0;
>    struct multiboot_header_tag_framebuffer *fbtag = NULL;
>    int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
> +  grub_size_t align = 0;
>  
>    buffer = grub_malloc (MULTIBOOT_SEARCH);
>    if (!buffer)
> @@ -174,6 +177,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	      case MULTIBOOT_TAG_TYPE_EFI_BS:
>  	      case MULTIBOOT_TAG_TYPE_EFI32_IH:
>  	      case MULTIBOOT_TAG_TYPE_EFI64_IH:
> +	      case MULTIBOOT_TAG_TYPE_BASE_ADDR:
>  		break;
>  
>  	      default:
> @@ -215,6 +219,26 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	accepted_consoles |= GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER;
>  	break;
>  
> +      case MULTIBOOT_HEADER_TAG_RELOCATABLE:
> +	relocatable = 1;

How about:
	struct multiboot_header_tag_relocatable *_tag = (struct multiboot_header_tag_relocatable *)tag;

and then you don't have to use the casting?



> +	min_addr = ((struct multiboot_header_tag_relocatable *) tag)->min_addr;
> +	max_addr = ((struct multiboot_header_tag_relocatable *) tag)->max_addr;
> +	align = ((struct multiboot_header_tag_relocatable *) tag)->align;
> +	switch (((struct multiboot_header_tag_relocatable *) tag)->preference)
> +	  {
> +	  case MULTIBOOT_LOAD_PREFERENCE_LOW:
> +	    preference = GRUB_RELOCATOR_PREFERENCE_LOW;
> +	    break;
> +
> +	  case MULTIBOOT_LOAD_PREFERENCE_HIGH:
> +	    preference = GRUB_RELOCATOR_PREFERENCE_HIGH;
> +	    break;
> +
> +	  default:
> +	    preference = GRUB_RELOCATOR_PREFERENCE_NONE;
> +	  }
> +	break;
> +
>  	/* GRUB always page-aligns modules.  */
>        case MULTIBOOT_HEADER_TAG_MODULE_ALIGN:
>  	break;
> @@ -260,15 +284,22 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>        else
>  	code_size = load_size;
>  
> -      err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, 
> -					     &ch, load_addr,
> -					     code_size);
> +      if (relocatable)
> +	err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
> +						min_addr, max_addr - code_size,
> +						code_size, align ? align : 1,
> +						preference, keep_bs);
> +      else
> +	err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
> +					       &ch, load_addr,
> +					       code_size);
>        if (err)
>  	{
>  	  grub_dprintf ("multiboot_loader", "Error loading aout kludge\n");
>  	  grub_free (buffer);
>  	  return err;
>  	}
> +      base_addr = get_physical_target_address (ch);
>        source = get_virtual_current_address (ch);
>  
>        if ((grub_file_seek (file, offset)) == (grub_off_t) -1)
> @@ -290,7 +321,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>      }
>    else
>      {
> -      err = grub_multiboot_load_elf (file, filename, buffer);
> +      err = grub_multiboot_load_elf (file, filename, buffer,
> +				     relocatable, min_addr, max_addr,
> +				     align, preference, &base_addr, keep_bs);
>        if (err)
>  	{
>  	  grub_free (buffer);
> @@ -303,6 +336,14 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>    else if (entry_specified)
>      grub_multiboot_payload_eip = entry;
>  
> +  if (relocatable)
> +    {
> +      if (base_addr > min_addr)
> +	grub_multiboot_payload_eip += base_addr - min_addr;
> +      else
> +	grub_multiboot_payload_eip -= min_addr - base_addr;
> +    }
> +
>    if (fbtag)
>      err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER,
>  				      accepted_consoles,
> @@ -409,6 +450,7 @@ grub_multiboot_get_mbi_size (void)
>  		 + grub_get_multiboot_mmap_count ()
>  		 * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN)
>      + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN)
> +    + ALIGN_UP (sizeof (struct multiboot_tag_base_addr), MULTIBOOT_TAG_ALIGN)
>  #ifdef GRUB_MACHINE_EFI
>      + ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN)
>      + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
> @@ -693,6 +735,15 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
>    ptrorig += (2 * sizeof (grub_uint32_t)) / sizeof (grub_properly_aligned_t);
>  
>    {
> +    struct multiboot_tag_base_addr *tag = (struct multiboot_tag_base_addr *) ptrorig;
> +    tag->type = MULTIBOOT_TAG_TYPE_BASE_ADDR;
> +    tag->size = sizeof (struct multiboot_tag_base_addr); 

You have an extra space at the end.

> +    tag->base_addr = base_addr;
> +    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +       / sizeof (grub_properly_aligned_t);
> +  }
> +
> +  {
>      struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig;
>      tag->type = MULTIBOOT_TAG_TYPE_CMDLINE;
>      tag->size = sizeof (struct multiboot_tag_string) + cmdline_size; 
> diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h
> index e13c084..ec322b0 100644
> --- a/include/grub/multiboot.h
> +++ b/include/grub/multiboot.h
> @@ -94,7 +94,9 @@ grub_multiboot_load (grub_file_t file, const char *filename);
>  /* Load ELF32 or ELF64.  */
>  grub_err_t
>  grub_multiboot_load_elf (grub_file_t file, const char *filename,
> -			 void *buffer);
> +			 void *buffer, int relocatable, grub_uint32_t min_addr,
> +			 grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
> +			 grub_uint32_t *base_addr, int avoid_efi_boot_services);
>  extern grub_size_t grub_multiboot_pure_size;
>  extern grub_size_t grub_multiboot_alloc_mbi;
>  extern grub_uint32_t grub_multiboot_payload_eip;
> diff --git a/include/multiboot2.h b/include/multiboot2.h
> index 9f97ddc..941a95d 100644
> --- a/include/multiboot2.h
> +++ b/include/multiboot2.h
> @@ -62,6 +62,7 @@
>  #define MULTIBOOT_TAG_TYPE_EFI_BS            18
>  #define MULTIBOOT_TAG_TYPE_EFI32_IH          19
>  #define MULTIBOOT_TAG_TYPE_EFI64_IH          20
> +#define MULTIBOOT_TAG_TYPE_BASE_ADDR         21
>  
>  #define MULTIBOOT_HEADER_TAG_END  0
>  #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
> @@ -72,11 +73,16 @@
>  #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
>  #define MULTIBOOT_HEADER_TAG_EFI_BS  7
>  #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
> +#define MULTIBOOT_HEADER_TAG_RELOCATABLE  10
>  
>  #define MULTIBOOT_ARCHITECTURE_I386  0
>  #define MULTIBOOT_ARCHITECTURE_MIPS32  4
>  #define MULTIBOOT_HEADER_TAG_OPTIONAL 1
>  
> +#define MULTIBOOT_LOAD_PREFERENCE_NONE 0
> +#define MULTIBOOT_LOAD_PREFERENCE_LOW 1
> +#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2
> +
>  #define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
>  #define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
>  
> @@ -169,6 +175,17 @@ struct multiboot_header_tag_module_align
>    multiboot_uint32_t size;
>  };
>  
> +struct multiboot_header_tag_relocatable
> +{
> +  multiboot_uint16_t type;
> +  multiboot_uint16_t flags;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t min_addr;
> +  multiboot_uint32_t max_addr;
> +  multiboot_uint32_t align;
> +  multiboot_uint32_t preference;
> +};
> +
>  struct multiboot_color
>  {
>    multiboot_uint8_t red;
> @@ -395,6 +412,13 @@ struct multiboot_tag_efi64_ih
>    multiboot_uint64_t pointer;
>  };
>  
> +struct multiboot_tag_base_addr
> +{
> +  multiboot_uint32_t type;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t base_addr;
> +};
> +
>  #endif /* ! ASM_FILE */
>  
>  #endif /* ! MULTIBOOT_HEADER */
> -- 
> 1.7.10.4
> 


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled
  2015-07-20 14:35 ` Daniel Kiper
  2015-08-11 18:59   ` Konrad Rzeszutek Wilk
@ 2015-08-11 18:59   ` Konrad Rzeszutek Wilk
  1 sibling, 0 replies; 67+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-08-11 18:59 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, wei.liu2, keir, ian.campbell,
	stefano.stabellini, andrew.cooper3, roy.franz, ning.sun,
	david.vrabel, jbeulich, phcoder, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei

On Mon, Jul 20, 2015 at 04:35:54PM +0200, Daniel Kiper wrote:
> Do not pass memory maps to image if it asked for EFI boot services. Maps are
> usually invalid in that case and they can confuse potential user. Image should
> get memory map itself just before ExitBootServices() call.

Can we point to some commits in Linux or Xen in which these situations
arose? 

Wait, I think there even was one commit in grub.

Aha:

ommit e75fdee420a7ad95e9a465c9699adc2e2e970440
Author: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Date:   Tue Mar 26 11:34:56 2013 +0100

        * grub-core/kern/efi/mm.c (grub_efi_finish_boot_services):
        Try terminating EFI services several times due to quirks in some
        implementations.

Otherwise:

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/loader/multiboot_mbi2.c |   71 ++++++++++++++++++-------------------
>  1 file changed, 35 insertions(+), 36 deletions(-)
> 
> diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> index 7ac64ec..26e955c 100644
> --- a/grub-core/loader/multiboot_mbi2.c
> +++ b/grub-core/loader/multiboot_mbi2.c
> @@ -431,7 +431,7 @@ static grub_size_t
>  grub_multiboot_get_mbi_size (void)
>  {
>  #ifdef GRUB_MACHINE_EFI
> -  if (!efi_mmap_size)
> +  if (!keep_bs && !efi_mmap_size)
>      find_efi_mmap_size ();    
>  #endif
>    return 2 * sizeof (grub_uint32_t) + sizeof (struct multiboot_tag)
> @@ -805,12 +805,13 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
>        }
>    }
>  
> -  {
> -    struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
> -    grub_fill_multiboot_mmap (tag);
> -    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> -      / sizeof (grub_properly_aligned_t);
> -  }
> +  if (!keep_bs)
> +    {
> +      struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
> +      grub_fill_multiboot_mmap (tag);
> +      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +	/ sizeof (grub_properly_aligned_t);
> +    }
>  
>    {
>      struct multiboot_tag_elf_sections *tag
> @@ -826,18 +827,19 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
>        / sizeof (grub_properly_aligned_t);
>    }
>  
> -  {
> -    struct multiboot_tag_basic_meminfo *tag
> -      = (struct multiboot_tag_basic_meminfo *) ptrorig;
> -    tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO;
> -    tag->size = sizeof (struct multiboot_tag_basic_meminfo); 
> +  if (!keep_bs)
> +    {
> +      struct multiboot_tag_basic_meminfo *tag
> +	= (struct multiboot_tag_basic_meminfo *) ptrorig;
> +      tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO;
> +      tag->size = sizeof (struct multiboot_tag_basic_meminfo);
>  
> -    /* Convert from bytes to kilobytes.  */
> -    tag->mem_lower = grub_mmap_get_lower () / 1024;
> -    tag->mem_upper = grub_mmap_get_upper () / 1024;
> -    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> -       / sizeof (grub_properly_aligned_t);
> -  }
> +      /* Convert from bytes to kilobytes.  */
> +      tag->mem_lower = grub_mmap_get_lower () / 1024;
> +      tag->mem_upper = grub_mmap_get_upper () / 1024;
> +      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +	/ sizeof (grub_properly_aligned_t);
> +    }
>  
>    {
>      struct grub_net_network_level_interface *net;
> @@ -936,27 +938,24 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
>      grub_efi_uintn_t efi_desc_size;
>      grub_efi_uint32_t efi_desc_version;
>  
> -    tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP;
> -    tag->size = sizeof (*tag) + efi_mmap_size;
> -
>      if (!keep_bs)
> -      err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL,
> -					   &efi_desc_size, &efi_desc_version);
> -    else
>        {
> -	if (grub_efi_get_memory_map (&efi_mmap_size, (void *) tag->efi_mmap,
> -				     NULL,
> -				     &efi_desc_size, &efi_desc_version) <= 0)
> -	  err = grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
> +	tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP;
> +	tag->size = sizeof (*tag) + efi_mmap_size;
> +
> +	err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL,
> +					     &efi_desc_size, &efi_desc_version);
> +
> +	if (err)
> +	  return err;
> +
> +	tag->descr_size = efi_desc_size;
> +	tag->descr_vers = efi_desc_version;
> +	tag->size = sizeof (*tag) + efi_mmap_size;
> +
> +	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +	  / sizeof (grub_properly_aligned_t);
>        }
> -    if (err)
> -      return err;
> -    tag->descr_size = efi_desc_size;
> -    tag->descr_vers = efi_desc_version;
> -    tag->size = sizeof (*tag) + efi_mmap_size;
> -
> -    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> -      / sizeof (grub_properly_aligned_t);
>    }
>  
>    if (keep_bs)
> -- 
> 1.7.10.4
> 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled
  2015-07-20 14:35 ` Daniel Kiper
@ 2015-08-11 18:59   ` Konrad Rzeszutek Wilk
  2015-08-18 12:29     ` Daniel Kiper
  2015-08-18 12:29     ` Daniel Kiper
  2015-08-11 18:59   ` Konrad Rzeszutek Wilk
  1 sibling, 2 replies; 67+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-08-11 18:59 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, wei.liu2, keir, ian.campbell,
	stefano.stabellini, andrew.cooper3, roy.franz, ning.sun,
	david.vrabel, jbeulich, phcoder, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei

On Mon, Jul 20, 2015 at 04:35:54PM +0200, Daniel Kiper wrote:
> Do not pass memory maps to image if it asked for EFI boot services. Maps are
> usually invalid in that case and they can confuse potential user. Image should
> get memory map itself just before ExitBootServices() call.

Can we point to some commits in Linux or Xen in which these situations
arose? 

Wait, I think there even was one commit in grub.

Aha:

ommit e75fdee420a7ad95e9a465c9699adc2e2e970440
Author: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Date:   Tue Mar 26 11:34:56 2013 +0100

        * grub-core/kern/efi/mm.c (grub_efi_finish_boot_services):
        Try terminating EFI services several times due to quirks in some
        implementations.

Otherwise:

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/loader/multiboot_mbi2.c |   71 ++++++++++++++++++-------------------
>  1 file changed, 35 insertions(+), 36 deletions(-)
> 
> diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> index 7ac64ec..26e955c 100644
> --- a/grub-core/loader/multiboot_mbi2.c
> +++ b/grub-core/loader/multiboot_mbi2.c
> @@ -431,7 +431,7 @@ static grub_size_t
>  grub_multiboot_get_mbi_size (void)
>  {
>  #ifdef GRUB_MACHINE_EFI
> -  if (!efi_mmap_size)
> +  if (!keep_bs && !efi_mmap_size)
>      find_efi_mmap_size ();    
>  #endif
>    return 2 * sizeof (grub_uint32_t) + sizeof (struct multiboot_tag)
> @@ -805,12 +805,13 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
>        }
>    }
>  
> -  {
> -    struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
> -    grub_fill_multiboot_mmap (tag);
> -    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> -      / sizeof (grub_properly_aligned_t);
> -  }
> +  if (!keep_bs)
> +    {
> +      struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
> +      grub_fill_multiboot_mmap (tag);
> +      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +	/ sizeof (grub_properly_aligned_t);
> +    }
>  
>    {
>      struct multiboot_tag_elf_sections *tag
> @@ -826,18 +827,19 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
>        / sizeof (grub_properly_aligned_t);
>    }
>  
> -  {
> -    struct multiboot_tag_basic_meminfo *tag
> -      = (struct multiboot_tag_basic_meminfo *) ptrorig;
> -    tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO;
> -    tag->size = sizeof (struct multiboot_tag_basic_meminfo); 
> +  if (!keep_bs)
> +    {
> +      struct multiboot_tag_basic_meminfo *tag
> +	= (struct multiboot_tag_basic_meminfo *) ptrorig;
> +      tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO;
> +      tag->size = sizeof (struct multiboot_tag_basic_meminfo);
>  
> -    /* Convert from bytes to kilobytes.  */
> -    tag->mem_lower = grub_mmap_get_lower () / 1024;
> -    tag->mem_upper = grub_mmap_get_upper () / 1024;
> -    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> -       / sizeof (grub_properly_aligned_t);
> -  }
> +      /* Convert from bytes to kilobytes.  */
> +      tag->mem_lower = grub_mmap_get_lower () / 1024;
> +      tag->mem_upper = grub_mmap_get_upper () / 1024;
> +      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +	/ sizeof (grub_properly_aligned_t);
> +    }
>  
>    {
>      struct grub_net_network_level_interface *net;
> @@ -936,27 +938,24 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
>      grub_efi_uintn_t efi_desc_size;
>      grub_efi_uint32_t efi_desc_version;
>  
> -    tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP;
> -    tag->size = sizeof (*tag) + efi_mmap_size;
> -
>      if (!keep_bs)
> -      err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL,
> -					   &efi_desc_size, &efi_desc_version);
> -    else
>        {
> -	if (grub_efi_get_memory_map (&efi_mmap_size, (void *) tag->efi_mmap,
> -				     NULL,
> -				     &efi_desc_size, &efi_desc_version) <= 0)
> -	  err = grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
> +	tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP;
> +	tag->size = sizeof (*tag) + efi_mmap_size;
> +
> +	err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL,
> +					     &efi_desc_size, &efi_desc_version);
> +
> +	if (err)
> +	  return err;
> +
> +	tag->descr_size = efi_desc_size;
> +	tag->descr_vers = efi_desc_version;
> +	tag->size = sizeof (*tag) + efi_mmap_size;
> +
> +	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +	  / sizeof (grub_properly_aligned_t);
>        }
> -    if (err)
> -      return err;
> -    tag->descr_size = efi_desc_size;
> -    tag->descr_vers = efi_desc_version;
> -    tag->size = sizeof (*tag) + efi_mmap_size;
> -
> -    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> -      / sizeof (grub_properly_aligned_t);
>    }
>  
>    if (keep_bs)
> -- 
> 1.7.10.4
> 


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-07-20 14:35 ` Daniel Kiper
                     ` (2 preceding siblings ...)
  2015-08-12  9:04   ` Ian Campbell
@ 2015-08-12  9:04   ` Ian Campbell
  3 siblings, 0 replies; 67+ messages in thread
From: Ian Campbell @ 2015-08-12  9:04 UTC (permalink / raw)
  To: Daniel Kiper, xen-devel, grub-devel
  Cc: jgross, keir, andrew.cooper3, stefano.stabellini, roy.franz,
	ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei


(Having written the below I see too late that this is a grub patch not a
Xen one, a tag in the subject for such cross posted patches would be useful
please. Anyway, my opinion counts for very little in this context but I
leave it below since already I wrote it. I notice that xen.git#.gitignore
_does_ list *.rej, which I think is wrong...)

On Mon, 2015-07-20 at 16:35 +0200, Daniel Kiper wrote:
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>

At least *.rej and perhaps *.orig are indicative of a failed patch
application, I think I want them to appear in "git status".

By way of comparison Linux's .gitignore includes *.orig but not *.rej and
Qemu's includes neither.

So nack to the addition of *.rej from me. I'm more or less ambivalent about
*.orig.

> ---
>  .gitignore |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/.gitignore b/.gitignore
> index 18ab8e8..6d25d39 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -147,6 +147,7 @@ mod-*.c
>  missing
>  netboot_test
>  *.o
> +*.orig
>  *.a
>  ohci_test
>  partmap_test
> @@ -160,9 +161,11 @@ po/stamp-po
>  printf_test
>  priority_queue_unit_test
>  pseries_test
> +*.rej
>  stamp-h
>  stamp-h1
>  stamp-h.in
> +*.swp
>  symlist.c
>  symlist.h
>  trigtables.c

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-07-20 14:35 ` Daniel Kiper
  2015-08-11 17:00   ` Konrad Rzeszutek Wilk
  2015-08-11 17:00   ` Konrad Rzeszutek Wilk
@ 2015-08-12  9:04   ` Ian Campbell
  2015-11-04 12:03     ` Vladimir 'phcoder' Serbinenko
  2015-11-04 12:03     ` Vladimir 'phcoder' Serbinenko
  2015-08-12  9:04   ` Ian Campbell
  3 siblings, 2 replies; 67+ messages in thread
From: Ian Campbell @ 2015-08-12  9:04 UTC (permalink / raw)
  To: Daniel Kiper, xen-devel, grub-devel
  Cc: jgross, keir, andrew.cooper3, stefano.stabellini, roy.franz,
	ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei


(Having written the below I see too late that this is a grub patch not a
Xen one, a tag in the subject for such cross posted patches would be useful
please. Anyway, my opinion counts for very little in this context but I
leave it below since already I wrote it. I notice that xen.git#.gitignore
_does_ list *.rej, which I think is wrong...)

On Mon, 2015-07-20 at 16:35 +0200, Daniel Kiper wrote:
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>

At least *.rej and perhaps *.orig are indicative of a failed patch
application, I think I want them to appear in "git status".

By way of comparison Linux's .gitignore includes *.orig but not *.rej and
Qemu's includes neither.

So nack to the addition of *.rej from me. I'm more or less ambivalent about
*.orig.

> ---
>  .gitignore |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/.gitignore b/.gitignore
> index 18ab8e8..6d25d39 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -147,6 +147,7 @@ mod-*.c
>  missing
>  netboot_test
>  *.o
> +*.orig
>  *.a
>  ohci_test
>  partmap_test
> @@ -160,9 +161,11 @@ po/stamp-po
>  printf_test
>  priority_queue_unit_test
>  pseries_test
> +*.rej
>  stamp-h
>  stamp-h1
>  stamp-h.in
> +*.swp
>  symlist.c
>  symlist.h
>  trigtables.c


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled
  2015-08-11 18:59   ` Konrad Rzeszutek Wilk
@ 2015-08-18 12:29     ` Daniel Kiper
  2015-08-18 12:29     ` Daniel Kiper
  1 sibling, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-08-18 12:29 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: jgross, grub-devel, wei.liu2, keir, ian.campbell,
	stefano.stabellini, andrew.cooper3, roy.franz, ning.sun,
	david.vrabel, jbeulich, phcoder, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei

On Tue, Aug 11, 2015 at 02:59:56PM -0400, Konrad Rzeszutek Wilk wrote:
> On Mon, Jul 20, 2015 at 04:35:54PM +0200, Daniel Kiper wrote:
> > Do not pass memory maps to image if it asked for EFI boot services. Maps are
> > usually invalid in that case and they can confuse potential user. Image should
> > get memory map itself just before ExitBootServices() call.
>
> Can we point to some commits in Linux or Xen in which these situations
> arose?
>
> Wait, I think there even was one commit in grub.
>
> Aha:
>
> ommit e75fdee420a7ad95e9a465c9699adc2e2e970440
> Author: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
> Date:   Tue Mar 26 11:34:56 2013 +0100
>
>         * grub-core/kern/efi/mm.c (grub_efi_finish_boot_services):
>         Try terminating EFI services several times due to quirks in some
>         implementations.
>
> Otherwise:
>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Nope, this is a bit different problem. In general GRUB2 assumes that
EFI boot services memory regions are free and specify them as such
in relevant maps. However, this is not true if you jump into loaded
image with EFI boot services enabled. So, we should not expose this
maps to the user when he/she asked for access to EFI boot services.
This is not very big issue for him/her because he/she can get memory
map from EFI just before ExitBootServices() call. This way they will
have latest valid memory map.

Daniel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled
  2015-08-11 18:59   ` Konrad Rzeszutek Wilk
  2015-08-18 12:29     ` Daniel Kiper
@ 2015-08-18 12:29     ` Daniel Kiper
  1 sibling, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-08-18 12:29 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: jgross, grub-devel, wei.liu2, keir, ian.campbell,
	stefano.stabellini, andrew.cooper3, roy.franz, ning.sun,
	david.vrabel, jbeulich, phcoder, xen-devel, qiaowei.ren,
	richard.l.maliszewski, gang.wei, fu.wei

On Tue, Aug 11, 2015 at 02:59:56PM -0400, Konrad Rzeszutek Wilk wrote:
> On Mon, Jul 20, 2015 at 04:35:54PM +0200, Daniel Kiper wrote:
> > Do not pass memory maps to image if it asked for EFI boot services. Maps are
> > usually invalid in that case and they can confuse potential user. Image should
> > get memory map itself just before ExitBootServices() call.
>
> Can we point to some commits in Linux or Xen in which these situations
> arose?
>
> Wait, I think there even was one commit in grub.
>
> Aha:
>
> ommit e75fdee420a7ad95e9a465c9699adc2e2e970440
> Author: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
> Date:   Tue Mar 26 11:34:56 2013 +0100
>
>         * grub-core/kern/efi/mm.c (grub_efi_finish_boot_services):
>         Try terminating EFI services several times due to quirks in some
>         implementations.
>
> Otherwise:
>
> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Nope, this is a bit different problem. In general GRUB2 assumes that
EFI boot services memory regions are free and specify them as such
in relevant maps. However, this is not true if you jump into loaded
image with EFI boot services enabled. So, we should not expose this
maps to the user when he/she asked for access to EFI boot services.
This is not very big issue for him/her because he/she can get memory
map from EFI just before ExitBootServices() call. This way they will
have latest valid memory map.

Daniel


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
                   ` (12 preceding siblings ...)
  2015-08-24 17:11 ` [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
@ 2015-08-24 17:11 ` Daniel Kiper
  13 siblings, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-08-24 17:11 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Guys, especially GRUB2 maintainers,

On Mon, Jul 20, 2015 at 04:35:48PM +0200, Daniel Kiper wrote:
> Hi,
>
> This patch series:
>   - enables EFI boot services usage in loaded images
>     by multiboot2 protocol,
>   - add support for multiboot2 protocol compatible
>     relocatable images,
>   - fixes two minor issues.

Is it possible to get your comments to this patch series
(I would like to thank you Andrei and Konrad for review)?
We need this functionality as Xen community and as Oracle.
Hence, it will be nice to know that we go in good direction.
So, if you think that we should change something please
drop me a line.

I know that you are busy but please, at least, tell us when
you take a look at it.

Daniel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues
  2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
                   ` (11 preceding siblings ...)
  2015-07-20 14:35 ` Daniel Kiper
@ 2015-08-24 17:11 ` Daniel Kiper
  2015-08-24 17:11 ` Daniel Kiper
  13 siblings, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-08-24 17:11 UTC (permalink / raw)
  To: xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, phcoder, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

Guys, especially GRUB2 maintainers,

On Mon, Jul 20, 2015 at 04:35:48PM +0200, Daniel Kiper wrote:
> Hi,
>
> This patch series:
>   - enables EFI boot services usage in loaded images
>     by multiboot2 protocol,
>   - add support for multiboot2 protocol compatible
>     relocatable images,
>   - fixes two minor issues.

Is it possible to get your comments to this patch series
(I would like to thank you Andrei and Konrad for review)?
We need this functionality as Xen community and as Oracle.
Hence, it will be nice to know that we go in good direction.
So, if you think that we should change something please
drop me a line.

I know that you are busy but please, at least, tell us when
you take a look at it.

Daniel


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-08-12  9:04   ` Ian Campbell
  2015-11-04 12:03     ` Vladimir 'phcoder' Serbinenko
@ 2015-11-04 12:03     ` Vladimir 'phcoder' Serbinenko
  1 sibling, 0 replies; 67+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2015-11-04 12:03 UTC (permalink / raw)
  To: Ian Campbell
  Cc: jgross, grub-devel, keir, stefano.stabellini, andrew.cooper3,
	Daniel Kiper, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei


[-- Attachment #1.1: Type: text/plain, Size: 1540 bytes --]

Le 12 août 2015 11:04 AM, "Ian Campbell" <ian.campbell@citrix.com> a écrit :
>
>
> (Having written the below I see too late that this is a grub patch not a
> Xen one, a tag in the subject for such cross posted patches would be
useful
> please. Anyway, my opinion counts for very little in this context but I
> leave it below since already I wrote it. I notice that xen.git#.gitignore
> _does_ list *.rej, which I think is wrong...)
>
> On Mon, 2015-07-20 at 16:35 +0200, Daniel Kiper wrote:
> > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
>
> At least *.rej and perhaps *.orig are indicative of a failed patch
> application, I think I want them to appear in "git status".
>
> By way of comparison Linux's .gitignore includes *.orig but not *.rej and
> Qemu's includes neither.
>
> So nack to the addition of *.rej from me. I'm more or less ambivalent
about
> *.orig.
>
I have to agree. You should clean up *.rej *.orig after fixing conflicts
> > ---
> >  .gitignore |    3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/.gitignore b/.gitignore
> > index 18ab8e8..6d25d39 100644
> > --- a/.gitignore
> > +++ b/.gitignore
> > @@ -147,6 +147,7 @@ mod-*.c
> >  missing
> >  netboot_test
> >  *.o
> > +*.orig
> >  *.a
> >  ohci_test
> >  partmap_test
> > @@ -160,9 +161,11 @@ po/stamp-po
> >  printf_test
> >  priority_queue_unit_test
> >  pseries_test
> > +*.rej
> >  stamp-h
> >  stamp-h1
> >  stamp-h.in
> > +*.swp
> >  symlist.c
> >  symlist.h
> >  trigtables.c

[-- Attachment #1.2: Type: text/html, Size: 2181 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-08-12  9:04   ` Ian Campbell
@ 2015-11-04 12:03     ` Vladimir 'phcoder' Serbinenko
  2015-11-09 15:29       ` Daniel Kiper
  2015-11-09 15:29       ` Daniel Kiper
  2015-11-04 12:03     ` Vladimir 'phcoder' Serbinenko
  1 sibling, 2 replies; 67+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2015-11-04 12:03 UTC (permalink / raw)
  To: Ian Campbell
  Cc: jgross, grub-devel, keir, stefano.stabellini, andrew.cooper3,
	Daniel Kiper, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

[-- Attachment #1: Type: text/plain, Size: 1540 bytes --]

Le 12 août 2015 11:04 AM, "Ian Campbell" <ian.campbell@citrix.com> a écrit :
>
>
> (Having written the below I see too late that this is a grub patch not a
> Xen one, a tag in the subject for such cross posted patches would be
useful
> please. Anyway, my opinion counts for very little in this context but I
> leave it below since already I wrote it. I notice that xen.git#.gitignore
> _does_ list *.rej, which I think is wrong...)
>
> On Mon, 2015-07-20 at 16:35 +0200, Daniel Kiper wrote:
> > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
>
> At least *.rej and perhaps *.orig are indicative of a failed patch
> application, I think I want them to appear in "git status".
>
> By way of comparison Linux's .gitignore includes *.orig but not *.rej and
> Qemu's includes neither.
>
> So nack to the addition of *.rej from me. I'm more or less ambivalent
about
> *.orig.
>
I have to agree. You should clean up *.rej *.orig after fixing conflicts
> > ---
> >  .gitignore |    3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/.gitignore b/.gitignore
> > index 18ab8e8..6d25d39 100644
> > --- a/.gitignore
> > +++ b/.gitignore
> > @@ -147,6 +147,7 @@ mod-*.c
> >  missing
> >  netboot_test
> >  *.o
> > +*.orig
> >  *.a
> >  ohci_test
> >  partmap_test
> > @@ -160,9 +161,11 @@ po/stamp-po
> >  printf_test
> >  priority_queue_unit_test
> >  pseries_test
> > +*.rej
> >  stamp-h
> >  stamp-h1
> >  stamp-h.in
> > +*.swp
> >  symlist.c
> >  symlist.h
> >  trigtables.c

[-- Attachment #2: Type: text/html, Size: 2181 bytes --]

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-11-04 12:03     ` Vladimir 'phcoder' Serbinenko
  2015-11-09 15:29       ` Daniel Kiper
@ 2015-11-09 15:29       ` Daniel Kiper
  1 sibling, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-11-09 15:29 UTC (permalink / raw)
  To: Vladimir 'phcoder' Serbinenko
  Cc: jgross, grub-devel, keir, Ian Campbell, stefano.stabellini,
	andrew.cooper3, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

On Wed, Nov 04, 2015 at 01:03:56PM +0100, Vladimir 'phcoder' Serbinenko wrote:
> Le 12 août 2015 11:04 AM, "Ian Campbell" <ian.campbell@citrix.com> a écrit :
> >
> >
> > (Having written the below I see too late that this is a grub patch not a
> > Xen one, a tag in the subject for such cross posted patches would be
> useful
> > please. Anyway, my opinion counts for very little in this context but I
> > leave it below since already I wrote it. I notice that xen.git#.gitignore
> > _does_ list *.rej, which I think is wrong...)
> >
> > On Mon, 2015-07-20 at 16:35 +0200, Daniel Kiper wrote:
> > > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> >
> > At least *.rej and perhaps *.orig are indicative of a failed patch
> > application, I think I want them to appear in "git status".
> >
> > By way of comparison Linux's .gitignore includes *.orig but not *.rej and
> > Qemu's includes neither.
> >
> > So nack to the addition of *.rej from me. I'm more or less ambivalent
> about
> > *.orig.
> >
> I have to agree. You should clean up *.rej *.orig after fixing conflicts

Thanks for comment on this. Could you review rest of this patchset?
I am working on v3 and it will be nice to take your (and others if
possible) comments into it.

Daniel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-11-04 12:03     ` Vladimir 'phcoder' Serbinenko
@ 2015-11-09 15:29       ` Daniel Kiper
  2015-11-09 15:34         ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-09 15:34         ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-09 15:29       ` Daniel Kiper
  1 sibling, 2 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-11-09 15:29 UTC (permalink / raw)
  To: Vladimir 'phcoder' Serbinenko
  Cc: jgross, grub-devel, keir, Ian Campbell, stefano.stabellini,
	andrew.cooper3, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

On Wed, Nov 04, 2015 at 01:03:56PM +0100, Vladimir 'phcoder' Serbinenko wrote:
> Le 12 août 2015 11:04 AM, "Ian Campbell" <ian.campbell@citrix.com> a écrit :
> >
> >
> > (Having written the below I see too late that this is a grub patch not a
> > Xen one, a tag in the subject for such cross posted patches would be
> useful
> > please. Anyway, my opinion counts for very little in this context but I
> > leave it below since already I wrote it. I notice that xen.git#.gitignore
> > _does_ list *.rej, which I think is wrong...)
> >
> > On Mon, 2015-07-20 at 16:35 +0200, Daniel Kiper wrote:
> > > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> >
> > At least *.rej and perhaps *.orig are indicative of a failed patch
> > application, I think I want them to appear in "git status".
> >
> > By way of comparison Linux's .gitignore includes *.orig but not *.rej and
> > Qemu's includes neither.
> >
> > So nack to the addition of *.rej from me. I'm more or less ambivalent
> about
> > *.orig.
> >
> I have to agree. You should clean up *.rej *.orig after fixing conflicts

Thanks for comment on this. Could you review rest of this patchset?
I am working on v3 and it will be nice to take your (and others if
possible) comments into it.

Daniel


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-11-09 15:29       ` Daniel Kiper
  2015-11-09 15:34         ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-11-09 15:34         ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-09 15:34 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, keir, Ian Campbell, stefano.stabellini,
	andrew.cooper3, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei


[-- Attachment #1.1: Type: text/plain, Size: 1381 bytes --]

On 09.11.2015 16:29, Daniel Kiper wrote:
> On Wed, Nov 04, 2015 at 01:03:56PM +0100, Vladimir 'phcoder' Serbinenko wrote:
>> Le 12 août 2015 11:04 AM, "Ian Campbell" <ian.campbell@citrix.com> a écrit :
>>>
>>>
>>> (Having written the below I see too late that this is a grub patch not a
>>> Xen one, a tag in the subject for such cross posted patches would be
>> useful
>>> please. Anyway, my opinion counts for very little in this context but I
>>> leave it below since already I wrote it. I notice that xen.git#.gitignore
>>> _does_ list *.rej, which I think is wrong...)
>>>
>>> On Mon, 2015-07-20 at 16:35 +0200, Daniel Kiper wrote:
>>>> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
>>>
>>> At least *.rej and perhaps *.orig are indicative of a failed patch
>>> application, I think I want them to appear in "git status".
>>>
>>> By way of comparison Linux's .gitignore includes *.orig but not *.rej and
>>> Qemu's includes neither.
>>>
>>> So nack to the addition of *.rej from me. I'm more or less ambivalent
>> about
>>> *.orig.
>>>
>> I have to agree. You should clean up *.rej *.orig after fixing conflicts
> 
> Thanks for comment on this. Could you review rest of this patchset?
> I am working on v3 and it will be nice to take your (and others if
> possible) comments into it.
> 
I will go through them today
> Daniel
> 



[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-11-09 15:29       ` Daniel Kiper
@ 2015-11-09 15:34         ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-09 15:39           ` Daniel Kiper
  2015-11-09 15:39           ` Daniel Kiper
  2015-11-09 15:34         ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 2 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-09 15:34 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, keir, Ian Campbell, stefano.stabellini,
	andrew.cooper3, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

[-- Attachment #1: Type: text/plain, Size: 1381 bytes --]

On 09.11.2015 16:29, Daniel Kiper wrote:
> On Wed, Nov 04, 2015 at 01:03:56PM +0100, Vladimir 'phcoder' Serbinenko wrote:
>> Le 12 août 2015 11:04 AM, "Ian Campbell" <ian.campbell@citrix.com> a écrit :
>>>
>>>
>>> (Having written the below I see too late that this is a grub patch not a
>>> Xen one, a tag in the subject for such cross posted patches would be
>> useful
>>> please. Anyway, my opinion counts for very little in this context but I
>>> leave it below since already I wrote it. I notice that xen.git#.gitignore
>>> _does_ list *.rej, which I think is wrong...)
>>>
>>> On Mon, 2015-07-20 at 16:35 +0200, Daniel Kiper wrote:
>>>> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
>>>
>>> At least *.rej and perhaps *.orig are indicative of a failed patch
>>> application, I think I want them to appear in "git status".
>>>
>>> By way of comparison Linux's .gitignore includes *.orig but not *.rej and
>>> Qemu's includes neither.
>>>
>>> So nack to the addition of *.rej from me. I'm more or less ambivalent
>> about
>>> *.orig.
>>>
>> I have to agree. You should clean up *.rej *.orig after fixing conflicts
> 
> Thanks for comment on this. Could you review rest of this patchset?
> I am working on v3 and it will be nice to take your (and others if
> possible) comments into it.
> 
I will go through them today
> Daniel
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-11-09 15:34         ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-09 15:39           ` Daniel Kiper
@ 2015-11-09 15:39           ` Daniel Kiper
  1 sibling, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-11-09 15:39 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: jgross, grub-devel, keir, Ian Campbell, stefano.stabellini,
	andrew.cooper3, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

On Mon, Nov 09, 2015 at 04:34:20PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 09.11.2015 16:29, Daniel Kiper wrote:
> > On Wed, Nov 04, 2015 at 01:03:56PM +0100, Vladimir 'phcoder' Serbinenko wrote:
> >> Le 12 août 2015 11:04 AM, "Ian Campbell" <ian.campbell@citrix.com> a écrit :
> >>>
> >>>
> >>> (Having written the below I see too late that this is a grub patch not a
> >>> Xen one, a tag in the subject for such cross posted patches would be
> >> useful
> >>> please. Anyway, my opinion counts for very little in this context but I
> >>> leave it below since already I wrote it. I notice that xen.git#.gitignore
> >>> _does_ list *.rej, which I think is wrong...)
> >>>
> >>> On Mon, 2015-07-20 at 16:35 +0200, Daniel Kiper wrote:
> >>>> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> >>>
> >>> At least *.rej and perhaps *.orig are indicative of a failed patch
> >>> application, I think I want them to appear in "git status".
> >>>
> >>> By way of comparison Linux's .gitignore includes *.orig but not *.rej and
> >>> Qemu's includes neither.
> >>>
> >>> So nack to the addition of *.rej from me. I'm more or less ambivalent
> >> about
> >>> *.orig.
> >>>
> >> I have to agree. You should clean up *.rej *.orig after fixing conflicts
> >
> > Thanks for comment on this. Could you review rest of this patchset?
> > I am working on v3 and it will be nice to take your (and others if
> > possible) comments into it.
> >
> I will go through them today

Thanks a lot!

Daniel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-11-09 15:34         ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-11-09 15:39           ` Daniel Kiper
  2015-11-09 20:22             ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-09 20:22             ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-09 15:39           ` Daniel Kiper
  1 sibling, 2 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-11-09 15:39 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: jgross, grub-devel, keir, Ian Campbell, stefano.stabellini,
	andrew.cooper3, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

On Mon, Nov 09, 2015 at 04:34:20PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 09.11.2015 16:29, Daniel Kiper wrote:
> > On Wed, Nov 04, 2015 at 01:03:56PM +0100, Vladimir 'phcoder' Serbinenko wrote:
> >> Le 12 août 2015 11:04 AM, "Ian Campbell" <ian.campbell@citrix.com> a écrit :
> >>>
> >>>
> >>> (Having written the below I see too late that this is a grub patch not a
> >>> Xen one, a tag in the subject for such cross posted patches would be
> >> useful
> >>> please. Anyway, my opinion counts for very little in this context but I
> >>> leave it below since already I wrote it. I notice that xen.git#.gitignore
> >>> _does_ list *.rej, which I think is wrong...)
> >>>
> >>> On Mon, 2015-07-20 at 16:35 +0200, Daniel Kiper wrote:
> >>>> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> >>>
> >>> At least *.rej and perhaps *.orig are indicative of a failed patch
> >>> application, I think I want them to appear in "git status".
> >>>
> >>> By way of comparison Linux's .gitignore includes *.orig but not *.rej and
> >>> Qemu's includes neither.
> >>>
> >>> So nack to the addition of *.rej from me. I'm more or less ambivalent
> >> about
> >>> *.orig.
> >>>
> >> I have to agree. You should clean up *.rej *.orig after fixing conflicts
> >
> > Thanks for comment on this. Could you review rest of this patchset?
> > I am working on v3 and it will be nice to take your (and others if
> > possible) comments into it.
> >
> I will go through them today

Thanks a lot!

Daniel


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2015-07-21  6:42   ` Andrei Borzenkov
@ 2015-11-09 18:44     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-09 18:44     ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-09 18:44 UTC (permalink / raw)
  To: Andrei Borzenkov, The development of GNU GRUB
  Cc: Juergen Gross, wei.liu2, keir, Ian Campbell, Stefano Stabellini,
	andrew.cooper3, Roy Franz, Sun, Ning, david.vrabel, Jan Beulich,
	xen-devel, qiaowei.ren, richard.l.maliszewski, gang.wei, Fu Wei


[-- Attachment #1.1: Type: text/plain, Size: 2242 bytes --]

On 21.07.2015 08:42, Andrei Borzenkov wrote:
> On Mon, Jul 20, 2015 at 5:35 PM, Daniel Kiper <daniel.kiper@oracle.com> wrote:
>> malloc_in_range() should not use memory region if its starta is smaller
>> than size. Otherwise target wraps around and points to region which is
>> usually not a RAM, e.g.:
>>
>> loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000
>> lib/relocator.c:1241: min_addr = 0x0, max_addr = 0xffffffffffffffff, target = 0x800000
>> lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned 0x1 size 0x3f800000
>> lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned 0x1 size 0x3f800000
>> lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned 0x1 size 0x3f800000
>> lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000
>> lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000
>>
>> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
>> ---
>>  grub-core/lib/relocator.c |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
>> index f759c7f..4eee0c5 100644
>> --- a/grub-core/lib/relocator.c
>> +++ b/grub-core/lib/relocator.c
>> @@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,
>>               /* Found an usable address.  */
>>               goto found;
>>           }
>> -       if (isinsidebefore && !isinsideafter && !from_low_priv)
>> +       if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size)
> 
> That's too late, we need to check end of region on previous iteration.
> Consider region of 128 bytes, requested size 129 and alignment 256.
> Than starta still ends up high in memory.
> 
Agreed, we need a check earlier. It makes sense to split this block with
an if (from_low_priv) as both flows are completely separate and
splitting them will make it more readable
>>           {
>>             target = starta - size;
>>             if (target > end - size)
>> --
>> 1.7.10.4
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
> 



[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2015-07-21  6:42   ` Andrei Borzenkov
  2015-11-09 18:44     ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-11-09 18:44     ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-09 18:44 UTC (permalink / raw)
  To: Andrei Borzenkov, The development of GNU GRUB
  Cc: Juergen Gross, wei.liu2, keir, Ian Campbell, Stefano Stabellini,
	andrew.cooper3, Roy Franz, Sun, Ning, david.vrabel, Jan Beulich,
	xen-devel, qiaowei.ren, richard.l.maliszewski, gang.wei, Fu Wei

[-- Attachment #1: Type: text/plain, Size: 2242 bytes --]

On 21.07.2015 08:42, Andrei Borzenkov wrote:
> On Mon, Jul 20, 2015 at 5:35 PM, Daniel Kiper <daniel.kiper@oracle.com> wrote:
>> malloc_in_range() should not use memory region if its starta is smaller
>> than size. Otherwise target wraps around and points to region which is
>> usually not a RAM, e.g.:
>>
>> loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000
>> lib/relocator.c:1241: min_addr = 0x0, max_addr = 0xffffffffffffffff, target = 0x800000
>> lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned 0x1 size 0x3f800000
>> lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned 0x1 size 0x3f800000
>> lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned 0x1 size 0x3f800000
>> lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000
>> lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000
>>
>> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
>> ---
>>  grub-core/lib/relocator.c |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
>> index f759c7f..4eee0c5 100644
>> --- a/grub-core/lib/relocator.c
>> +++ b/grub-core/lib/relocator.c
>> @@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,
>>               /* Found an usable address.  */
>>               goto found;
>>           }
>> -       if (isinsidebefore && !isinsideafter && !from_low_priv)
>> +       if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size)
> 
> That's too late, we need to check end of region on previous iteration.
> Consider region of 128 bytes, requested size 129 and alignment 256.
> Than starta still ends up high in memory.
> 
Agreed, we need a check earlier. It makes sense to split this block with
an if (from_low_priv) as both flows are completely separate and
splitting them will make it more readable
>>           {
>>             target = starta - size;
>>             if (target > end - size)
>> --
>> 1.7.10.4
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Fwd: Re: [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image
       [not found]     ` <CAEaD8JOPxLVECcUqjj2-x5AeXjbQ9Cd7bOaoe8UPU2t7wdoxpA@mail.gmail.com>
@ 2015-11-09 19:12       ` Vladimir 'phcoder' Serbinenko
  0 siblings, 0 replies; 67+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2015-11-09 19:12 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 5936 bytes --]

---------- Message transféré ----------
De : "Vladimir 'phcoder' Serbinenko" <phcoder@gmail.com>
Date : 9 nov. 2015 8:12 PM
Objet : Re: [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to
loaded image
À : "Konrad Rzeszutek Wilk" <konrad.wilk@oracle.com>
Cc :


Le 11 août 2015 8:38 PM, "Konrad Rzeszutek Wilk" <konrad.wilk@oracle.com> a
écrit :
>
> On Mon, Jul 20, 2015 at 04:35:52PM +0200, Daniel Kiper wrote:
> > Add tags used to pass ImageHandle to loaded image. It is used
>
> s/loaded image/loaded image if requested./
> > by at least ExitBootServices() function.
> >
> > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> > ---
> >  grub-core/loader/multiboot_mbi2.c |   46
+++++++++++++++++++++++++++++--------
> >  include/multiboot2.h              |   16 +++++++++++++
> >  2 files changed, 53 insertions(+), 9 deletions(-)
> >
> > diff --git a/grub-core/loader/multiboot_mbi2.c
b/grub-core/loader/multiboot_mbi2.c
> > index 8d66e3f..dc9c709 100644
> > --- a/grub-core/loader/multiboot_mbi2.c
> > +++ b/grub-core/loader/multiboot_mbi2.c
> > @@ -172,6 +172,8 @@ grub_multiboot_load (grub_file_t file, const char
*filename)
> >             case MULTIBOOT_TAG_TYPE_NETWORK:
> >             case MULTIBOOT_TAG_TYPE_EFI_MMAP:
> >             case MULTIBOOT_TAG_TYPE_EFI_BS:
> > +           case MULTIBOOT_TAG_TYPE_EFI32_IH:
> > +           case MULTIBOOT_TAG_TYPE_EFI64_IH:
> >               break;
> >
> >             default:
> > @@ -407,16 +409,18 @@ grub_multiboot_get_mbi_size (void)
> >                + grub_get_multiboot_mmap_count ()
> >                * sizeof (struct multiboot_mmap_entry)),
MULTIBOOT_TAG_ALIGN)
> >      + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer),
MULTIBOOT_TAG_ALIGN)
> > +#ifdef GRUB_MACHINE_EFI
> >      + ALIGN_UP (sizeof (struct multiboot_tag_efi32),
MULTIBOOT_TAG_ALIGN)
> >      + ALIGN_UP (sizeof (struct multiboot_tag_efi64),
MULTIBOOT_TAG_ALIGN)
> > +    + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih),
MULTIBOOT_TAG_ALIGN)
>
> Shouldn't they be wrapped with #ifdef __x86_64__ (for efi64_ih) and
#ifdef __i386__
> for the other?
>
No need. It's just few bytes but not adding ifdef makes it more readable
> Or two functions (in the header?) wrapped with proper #ifdef machinery?
>
> > +    + ALIGN_UP (sizeof (struct multiboot_tag_efi64_ih),
MULTIBOOT_TAG_ALIGN)
> > +    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
> > +             + efi_mmap_size, MULTIBOOT_TAG_ALIGN)
> > +#endif
> >      + ALIGN_UP (sizeof (struct multiboot_tag_old_acpi)
> >               + sizeof (struct grub_acpi_rsdp_v10), MULTIBOOT_TAG_ALIGN)
> >      + acpiv2_size ()
> >      + net_size ()
> > -#ifdef GRUB_MACHINE_EFI
> > -    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
> > -             + efi_mmap_size, MULTIBOOT_TAG_ALIGN)
> > -#endif
> >      + sizeof (struct multiboot_tag_vbe) + MULTIBOOT_TAG_ALIGN - 1
> >      + sizeof (struct multiboot_tag_apm) + MULTIBOOT_TAG_ALIGN - 1;
> >  }
> > @@ -906,11 +910,35 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
> >
> >    if (keep_bs)
> >      {
> > -      struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
> > -      tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
> > -      tag->size = sizeof (struct multiboot_tag);
> > -      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> > -     / sizeof (grub_properly_aligned_t);
> > +      {
> > +     struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
> > +     tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
> > +     tag->size = sizeof (struct multiboot_tag);
> > +     ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> > +       / sizeof (grub_properly_aligned_t);
> > +      }
> > +
> > +#ifdef __x86_64__
> > +      {
> > +     struct multiboot_tag_efi64_ih *tag = (struct
multiboot_tag_efi64_ih *) ptrorig;
> > +     tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH;
> > +     tag->size = sizeof (*tag);
>
> The other places where sizeof is used ends up using the full structure so
it :
>
> sizeof (struct multiboot_tag_efi64_ih)
>
sizeof (*tag) is fine and is actually better
> > +     tag->pointer = (grub_addr_t) grub_efi_image_handle;
> > +     ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> > +       / sizeof (grub_properly_aligned_t);
> > +      }
> > +#endif
> > +
> > +#ifdef __i386__
> > +      {
> > +     struct multiboot_tag_efi32_ih *tag = (struct
multiboot_tag_efi32_ih *) ptrorig;
> > +     tag->type = MULTIBOOT_TAG_TYPE_EFI32_IH;
> > +     tag->size = sizeof (*tag);
>
> Ditto.
> > +     tag->pointer = (grub_addr_t) grub_efi_image_handle;
> > +     ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> > +       / sizeof (grub_properly_aligned_t);
> > +      }
> > +#endif
> >      }
> >  #endif
> >
> > diff --git a/include/multiboot2.h b/include/multiboot2.h
> > index b3977e3..9f97ddc 100644
> > --- a/include/multiboot2.h
> > +++ b/include/multiboot2.h
> > @@ -60,6 +60,8 @@
> >  #define MULTIBOOT_TAG_TYPE_NETWORK           16
> >  #define MULTIBOOT_TAG_TYPE_EFI_MMAP          17
> >  #define MULTIBOOT_TAG_TYPE_EFI_BS            18
> > +#define MULTIBOOT_TAG_TYPE_EFI32_IH          19
> > +#define MULTIBOOT_TAG_TYPE_EFI64_IH          20
> >
> >  #define MULTIBOOT_HEADER_TAG_END  0
> >  #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
> > @@ -379,6 +381,20 @@ struct multiboot_tag_efi_mmap
> >    multiboot_uint8_t efi_mmap[0];
> >  };
> >
> > +struct multiboot_tag_efi32_ih
> > +{
> > +  multiboot_uint32_t type;
> > +  multiboot_uint32_t size;
> > +  multiboot_uint32_t pointer;
> > +};
> > +
> > +struct multiboot_tag_efi64_ih
> > +{
> > +  multiboot_uint32_t type;
> > +  multiboot_uint32_t size;
> > +  multiboot_uint64_t pointer;
> > +};
> > +
> >  #endif /* ! ASM_FILE */
> >
> >  #endif /* ! MULTIBOOT_HEADER */
> > --
> > 1.7.10.4
> >

[-- Attachment #2: Type: text/html, Size: 7969 bytes --]

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
  2015-07-20 14:35 ` Daniel Kiper
  2015-08-11 17:02     ` Konrad Rzeszutek Wilk
  2015-11-09 20:05   ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-11-09 20:05   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2 siblings, 0 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-09 20:05 UTC (permalink / raw)
  To: Daniel Kiper, xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei


[-- Attachment #1.1: Type: text/plain, Size: 13434 bytes --]

On 20.07.2015 16:35, Daniel Kiper wrote:
> Add grub_relocator64_efi relocator. It will be used on EFI 64-bit platforms
> when multiboot2 compatible image requests MULTIBOOT_TAG_TYPE_EFI_BS. Relocator
> will set lower parts of %rax and %rbx accordingly to multiboot2 specification.
> On the other hand processor mode, just before jumping into loaded image, will
> be set accordingly to Unified Extensible Firmware Interface Specification,
> Version 2.4 Errata B, section 2.3.4, x64 Platforms, boot services. This way
> loaded image will be able to use EFI boot services without any issues.
> 
> If idea is accepted I will prepare grub_relocator32_efi relocator too.
> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/Makefile.core.def          |    1 +
>  grub-core/lib/i386/relocator.c       |   53 +++++++++++++++++++++++
>  grub-core/lib/i386/relocator64_efi.S |   77 ++++++++++++++++++++++++++++++++++
>  grub-core/loader/multiboot.c         |   29 +++++++++++--
>  grub-core/loader/multiboot_mbi2.c    |   19 +++++++--
>  include/grub/i386/multiboot.h        |   11 +++++
>  include/grub/i386/relocator.h        |   21 ++++++++++
>  include/multiboot2.h                 |    9 ++++
>  8 files changed, 213 insertions(+), 7 deletions(-)
>  create mode 100644 grub-core/lib/i386/relocator64_efi.S
> 
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index a6101de..d583549 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -1519,6 +1519,7 @@ module = {
>    x86 = lib/i386/relocator_common_c.c;
>    ieee1275 = lib/ieee1275/relocator.c;
>    efi = lib/efi/relocator.c;
> +  x86_64_efi = lib/i386/relocator64_efi.S;
>    mips = lib/mips/relocator_asm.S;
>    mips = lib/mips/relocator.c;
>    powerpc = lib/powerpc/relocator_asm.S;
> diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c
> index 71dd4f0..459027e 100644
> --- a/grub-core/lib/i386/relocator.c
> +++ b/grub-core/lib/i386/relocator.c
> @@ -69,6 +69,19 @@ extern grub_uint64_t grub_relocator64_rsi;
>  extern grub_addr_t grub_relocator64_cr3;
>  extern struct grub_i386_idt grub_relocator16_idt;
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +extern grub_uint8_t grub_relocator64_efi_start;
> +extern grub_uint8_t grub_relocator64_efi_end;
> +extern grub_uint64_t grub_relocator64_efi_rax;
> +extern grub_uint64_t grub_relocator64_efi_rbx;
> +extern grub_uint64_t grub_relocator64_efi_rcx;
> +extern grub_uint64_t grub_relocator64_efi_rdx;
> +extern grub_uint64_t grub_relocator64_efi_rip;
> +extern grub_uint64_t grub_relocator64_efi_rsi;
> +#endif
> +#endif
> +
>  #define RELOCATOR_SIZEOF(x)	(&grub_relocator##x##_end - &grub_relocator##x##_start)
>  
>  grub_err_t
> @@ -214,3 +227,43 @@ grub_relocator64_boot (struct grub_relocator *rel,
>    /* Not reached.  */
>    return GRUB_ERR_NONE;
>  }
> +
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +grub_err_t
> +grub_relocator64_efi_boot (struct grub_relocator *rel,
> +			   struct grub_relocator64_efi_state state)
> +{
> +  grub_err_t err;
> +  void *relst;
> +  grub_relocator_chunk_t ch;
> +
> +  err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
> +					  0x40000000 - RELOCATOR_SIZEOF (64_efi),
> +					  RELOCATOR_SIZEOF (64_efi), 16,
> +					  GRUB_RELOCATOR_PREFERENCE_NONE, 1);
> +  if (err)
> +    return err;
> +
> +  grub_relocator64_efi_rax = state.rax;
> +  grub_relocator64_efi_rbx = state.rbx;
> +  grub_relocator64_efi_rcx = state.rcx;
> +  grub_relocator64_efi_rdx = state.rdx;
> +  grub_relocator64_efi_rip = state.rip;
> +  grub_relocator64_efi_rsi = state.rsi;
> +
> +  grub_memmove (get_virtual_current_address (ch), &grub_relocator64_efi_start,
> +		RELOCATOR_SIZEOF (64_efi));
> +
> +  err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch),
> +				       &relst, NULL);
> +  if (err)
> +    return err;
> +
> +  ((void (*) (void)) relst) ();
> +
> +  /* Not reached.  */
> +  return GRUB_ERR_NONE;
> +}
> +#endif
> +#endif
> diff --git a/grub-core/lib/i386/relocator64_efi.S b/grub-core/lib/i386/relocator64_efi.S
> new file mode 100644
> index 0000000..fcd1964
> --- /dev/null
> +++ b/grub-core/lib/i386/relocator64_efi.S
> @@ -0,0 +1,77 @@
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2009,2010  Free Software Foundation, Inc.
> + *  Copyright (C) 2014,2015  Oracle Co.
> + *      Author: Daniel Kiper
> + *
> + *  GRUB 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 3 of the License, or
> + *  (at your option) any later version.
> + *
> + *  GRUB 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 GRUB.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include "relocator_common.S"
> +
> +	.p2align	4	/* force 16-byte alignment */
> +
> +VARIABLE(grub_relocator64_efi_start)
> +	PREAMBLE
> +
> +	.code64
> +
> +	/* mov imm64, %rax */
> +	.byte 	0x48
> +	.byte	0xb8
> +VARIABLE(grub_relocator64_efi_rsi)
> +	.quad	0
> +
> +	movq	%rax, %rsi
> +
> +	/* mov imm64, %rax */
> +	.byte 	0x48
> +	.byte	0xb8
> +VARIABLE(grub_relocator64_efi_rax)
> +	.quad	0
> +
> +	/* mov imm64, %rbx */
> +	.byte 	0x48
> +	.byte	0xbb
> +VARIABLE(grub_relocator64_efi_rbx)
> +	.quad	0
> +
> +	/* mov imm64, %rcx */
> +	.byte 	0x48
> +	.byte	0xb9
> +VARIABLE(grub_relocator64_efi_rcx)
> +	.quad	0
> +
> +	/* mov imm64, %rdx */
> +	.byte 	0x48
> +	.byte	0xba
> +VARIABLE(grub_relocator64_efi_rdx)
> +	.quad	0
> +
> +	/* Cleared direction flag is of no problem with any current
> +	   payload and makes this implementation easier.  */
> +	cld
> +
> +#ifdef __APPLE__
> +	.byte 0xff, 0x25
> +	.quad 0
> +#else
> +	jmp *LOCAL(jump_addr) (%rip)
> +#endif
> +
> +LOCAL(jump_addr):
> +VARIABLE(grub_relocator64_efi_rip)
> +	.quad	0
> +
This repeats relocator64 almost exactly. Can we avoid code duplication?
It's fine to compile it twice but code duplication is bad.
> +VARIABLE(grub_relocator64_efi_end)
> diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
> index fd8f28e..ca7154f 100644
> --- a/grub-core/loader/multiboot.c
> +++ b/grub-core/loader/multiboot.c
> @@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)
>    return err;
>  }
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +#define grub_relocator_efi_boot	grub_relocator64_efi_boot
> +#endif
> +#endif
> +
>  static grub_err_t
>  grub_multiboot_boot (void)
>  {
>    grub_err_t err;
> +  grub_uint32_t target;
>    struct grub_relocator32_state state = MULTIBOOT_INITIAL_STATE;
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +  struct grub_relocator64_efi_state state_efi = MULTIBOOT_EFI_INITIAL_STATE;
> +#endif
> +#endif
>  
> -  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
> -
> -  err = grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER);
> +  err = grub_multiboot_make_mbi (&target);
>  
>    if (err)
>      return err;
>  
> +  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
> +  state.MULTIBOOT_MBI_REGISTER = target;
> +
>  #if defined (__i386__) || defined (__x86_64__)
> +#ifdef GRUB_MACHINE_EFI
> +  state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip;
> +  state_efi.MULTIBOOT_EFI_MBI_REGISTER = target;
> +
> +  if (grub_efi_is_finished)
> +    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
> +  else
> +    grub_relocator_efi_boot (grub_multiboot_relocator, state_efi);
> +#else
>    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
> +#endif
>  #else
>    grub_relocator32_boot (grub_multiboot_relocator, state);
>  #endif
This becomes hairy. I think it's time to split it into platform-specific
functions and/or use tricks like
#ifndef GRUB_MACHINE_EFI
#define grub_efi_is_finished 0
#endif
> diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> index d7c19bc..8d66e3f 100644
> --- a/grub-core/loader/multiboot_mbi2.c
> +++ b/grub-core/loader/multiboot_mbi2.c
> @@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>    grub_err_t err;
>    struct multiboot_header_tag *tag;
>    struct multiboot_header_tag_address *addr_tag = NULL;
> -  int entry_specified = 0;
> -  grub_addr_t entry = 0;
> +  int entry_specified = 0, efi_entry_specified = 0;
> +  grub_addr_t entry = 0, efi_entry = 0;
>    grub_uint32_t console_required = 0;
>    struct multiboot_header_tag_framebuffer *fbtag = NULL;
>    int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
> @@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;
>  	break;
>  
> +      case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64:
> +#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__)
> +	efi_entry_specified = 1;
> +	efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr;
> +#endif
> +	break;
> +
Why do we need separate handling of EFI entry point? Why can't we use
the same structure?
>        case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS:
>  	if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags
>  	    & MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED))
> @@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	break;
>  
>        case MULTIBOOT_HEADER_TAG_EFI_BS:
> +#ifdef GRUB_MACHINE_EFI
>  	keep_bs = 1;
> +#endif
>  	break;
>  
>        default:
> @@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	break;
>        }
>  
> -  if (addr_tag && !entry_specified)
> +  if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified))
>      {
>        grub_free (buffer);
>        return grub_error (GRUB_ERR_UNKNOWN_OS,
> @@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	}
>      }
>  
> -  if (entry_specified)
> +  if (keep_bs && efi_entry_specified)
> +    grub_multiboot_payload_eip = efi_entry;
> +  else if (entry_specified)
>      grub_multiboot_payload_eip = entry;
>  
This seems redundant.
>    if (fbtag)
> diff --git a/include/grub/i386/multiboot.h b/include/grub/i386/multiboot.h
> index a1b9488..807a1de 100644
> --- a/include/grub/i386/multiboot.h
> +++ b/include/grub/i386/multiboot.h
> @@ -30,6 +30,17 @@
>  #define MULTIBOOT_MBI_REGISTER ebx
>  #define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_I386
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +#define MULTIBOOT_EFI_INITIAL_STATE  { .rax = MULTIBOOT_BOOTLOADER_MAGIC,	\
> +    .rcx = 0,									\
> +    .rdx = 0,									\
> +      }
> +#define MULTIBOOT_EFI_ENTRY_REGISTER rip
> +#define MULTIBOOT_EFI_MBI_REGISTER rbx
> +#endif
> +#endif
> +
>  #define MULTIBOOT_ELF32_MACHINE EM_386
>  #define MULTIBOOT_ELF64_MACHINE EM_X86_64
>  
> diff --git a/include/grub/i386/relocator.h b/include/grub/i386/relocator.h
> index 5f89a7e..2a56c3b 100644
> --- a/include/grub/i386/relocator.h
> +++ b/include/grub/i386/relocator.h
> @@ -65,6 +65,20 @@ struct grub_relocator64_state
>    grub_addr_t cr3;
>  };
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +struct grub_relocator64_efi_state
> +{
> +  grub_uint64_t rax;
> +  grub_uint64_t rbx;
> +  grub_uint64_t rcx;
> +  grub_uint64_t rdx;
> +  grub_uint64_t rip;
> +  grub_uint64_t rsi;
> +};
> +#endif
> +#endif
> +
>  grub_err_t grub_relocator16_boot (struct grub_relocator *rel,
>  				  struct grub_relocator16_state state);
>  
> @@ -76,4 +90,11 @@ grub_err_t grub_relocator64_boot (struct grub_relocator *rel,
>  				  struct grub_relocator64_state state,
>  				  grub_addr_t min_addr, grub_addr_t max_addr);
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel,
> +				      struct grub_relocator64_efi_state state);
> +#endif
> +#endif
> +
>  #endif /* ! GRUB_RELOCATOR_CPU_HEADER */
> diff --git a/include/multiboot2.h b/include/multiboot2.h
> index 9d48627..b3977e3 100644
> --- a/include/multiboot2.h
> +++ b/include/multiboot2.h
> @@ -69,6 +69,7 @@
>  #define MULTIBOOT_HEADER_TAG_FRAMEBUFFER  5
>  #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
>  #define MULTIBOOT_HEADER_TAG_EFI_BS  7
> +#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
>  
>  #define MULTIBOOT_ARCHITECTURE_I386  0
>  #define MULTIBOOT_ARCHITECTURE_MIPS32  4
> @@ -133,6 +134,14 @@ struct multiboot_header_tag_entry_address
>    multiboot_uint32_t entry_addr;
>  };
>  
> +struct multiboot_header_tag_entry_address_efi64
> +{
> +  multiboot_uint16_t type;
> +  multiboot_uint16_t flags;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t entry_addr;
> +};
> +
Ditto
>  struct multiboot_header_tag_console_flags
>  {
>    multiboot_uint16_t type;
> 



[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
  2015-07-20 14:35 ` Daniel Kiper
  2015-08-11 17:02     ` Konrad Rzeszutek Wilk
@ 2015-11-09 20:05   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-10 14:38       ` Daniel Kiper
  2015-11-09 20:05   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2 siblings, 1 reply; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-09 20:05 UTC (permalink / raw)
  To: Daniel Kiper, xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

[-- Attachment #1: Type: text/plain, Size: 13434 bytes --]

On 20.07.2015 16:35, Daniel Kiper wrote:
> Add grub_relocator64_efi relocator. It will be used on EFI 64-bit platforms
> when multiboot2 compatible image requests MULTIBOOT_TAG_TYPE_EFI_BS. Relocator
> will set lower parts of %rax and %rbx accordingly to multiboot2 specification.
> On the other hand processor mode, just before jumping into loaded image, will
> be set accordingly to Unified Extensible Firmware Interface Specification,
> Version 2.4 Errata B, section 2.3.4, x64 Platforms, boot services. This way
> loaded image will be able to use EFI boot services without any issues.
> 
> If idea is accepted I will prepare grub_relocator32_efi relocator too.
> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/Makefile.core.def          |    1 +
>  grub-core/lib/i386/relocator.c       |   53 +++++++++++++++++++++++
>  grub-core/lib/i386/relocator64_efi.S |   77 ++++++++++++++++++++++++++++++++++
>  grub-core/loader/multiboot.c         |   29 +++++++++++--
>  grub-core/loader/multiboot_mbi2.c    |   19 +++++++--
>  include/grub/i386/multiboot.h        |   11 +++++
>  include/grub/i386/relocator.h        |   21 ++++++++++
>  include/multiboot2.h                 |    9 ++++
>  8 files changed, 213 insertions(+), 7 deletions(-)
>  create mode 100644 grub-core/lib/i386/relocator64_efi.S
> 
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index a6101de..d583549 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -1519,6 +1519,7 @@ module = {
>    x86 = lib/i386/relocator_common_c.c;
>    ieee1275 = lib/ieee1275/relocator.c;
>    efi = lib/efi/relocator.c;
> +  x86_64_efi = lib/i386/relocator64_efi.S;
>    mips = lib/mips/relocator_asm.S;
>    mips = lib/mips/relocator.c;
>    powerpc = lib/powerpc/relocator_asm.S;
> diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c
> index 71dd4f0..459027e 100644
> --- a/grub-core/lib/i386/relocator.c
> +++ b/grub-core/lib/i386/relocator.c
> @@ -69,6 +69,19 @@ extern grub_uint64_t grub_relocator64_rsi;
>  extern grub_addr_t grub_relocator64_cr3;
>  extern struct grub_i386_idt grub_relocator16_idt;
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +extern grub_uint8_t grub_relocator64_efi_start;
> +extern grub_uint8_t grub_relocator64_efi_end;
> +extern grub_uint64_t grub_relocator64_efi_rax;
> +extern grub_uint64_t grub_relocator64_efi_rbx;
> +extern grub_uint64_t grub_relocator64_efi_rcx;
> +extern grub_uint64_t grub_relocator64_efi_rdx;
> +extern grub_uint64_t grub_relocator64_efi_rip;
> +extern grub_uint64_t grub_relocator64_efi_rsi;
> +#endif
> +#endif
> +
>  #define RELOCATOR_SIZEOF(x)	(&grub_relocator##x##_end - &grub_relocator##x##_start)
>  
>  grub_err_t
> @@ -214,3 +227,43 @@ grub_relocator64_boot (struct grub_relocator *rel,
>    /* Not reached.  */
>    return GRUB_ERR_NONE;
>  }
> +
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +grub_err_t
> +grub_relocator64_efi_boot (struct grub_relocator *rel,
> +			   struct grub_relocator64_efi_state state)
> +{
> +  grub_err_t err;
> +  void *relst;
> +  grub_relocator_chunk_t ch;
> +
> +  err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
> +					  0x40000000 - RELOCATOR_SIZEOF (64_efi),
> +					  RELOCATOR_SIZEOF (64_efi), 16,
> +					  GRUB_RELOCATOR_PREFERENCE_NONE, 1);
> +  if (err)
> +    return err;
> +
> +  grub_relocator64_efi_rax = state.rax;
> +  grub_relocator64_efi_rbx = state.rbx;
> +  grub_relocator64_efi_rcx = state.rcx;
> +  grub_relocator64_efi_rdx = state.rdx;
> +  grub_relocator64_efi_rip = state.rip;
> +  grub_relocator64_efi_rsi = state.rsi;
> +
> +  grub_memmove (get_virtual_current_address (ch), &grub_relocator64_efi_start,
> +		RELOCATOR_SIZEOF (64_efi));
> +
> +  err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch),
> +				       &relst, NULL);
> +  if (err)
> +    return err;
> +
> +  ((void (*) (void)) relst) ();
> +
> +  /* Not reached.  */
> +  return GRUB_ERR_NONE;
> +}
> +#endif
> +#endif
> diff --git a/grub-core/lib/i386/relocator64_efi.S b/grub-core/lib/i386/relocator64_efi.S
> new file mode 100644
> index 0000000..fcd1964
> --- /dev/null
> +++ b/grub-core/lib/i386/relocator64_efi.S
> @@ -0,0 +1,77 @@
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2009,2010  Free Software Foundation, Inc.
> + *  Copyright (C) 2014,2015  Oracle Co.
> + *      Author: Daniel Kiper
> + *
> + *  GRUB 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 3 of the License, or
> + *  (at your option) any later version.
> + *
> + *  GRUB 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 GRUB.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include "relocator_common.S"
> +
> +	.p2align	4	/* force 16-byte alignment */
> +
> +VARIABLE(grub_relocator64_efi_start)
> +	PREAMBLE
> +
> +	.code64
> +
> +	/* mov imm64, %rax */
> +	.byte 	0x48
> +	.byte	0xb8
> +VARIABLE(grub_relocator64_efi_rsi)
> +	.quad	0
> +
> +	movq	%rax, %rsi
> +
> +	/* mov imm64, %rax */
> +	.byte 	0x48
> +	.byte	0xb8
> +VARIABLE(grub_relocator64_efi_rax)
> +	.quad	0
> +
> +	/* mov imm64, %rbx */
> +	.byte 	0x48
> +	.byte	0xbb
> +VARIABLE(grub_relocator64_efi_rbx)
> +	.quad	0
> +
> +	/* mov imm64, %rcx */
> +	.byte 	0x48
> +	.byte	0xb9
> +VARIABLE(grub_relocator64_efi_rcx)
> +	.quad	0
> +
> +	/* mov imm64, %rdx */
> +	.byte 	0x48
> +	.byte	0xba
> +VARIABLE(grub_relocator64_efi_rdx)
> +	.quad	0
> +
> +	/* Cleared direction flag is of no problem with any current
> +	   payload and makes this implementation easier.  */
> +	cld
> +
> +#ifdef __APPLE__
> +	.byte 0xff, 0x25
> +	.quad 0
> +#else
> +	jmp *LOCAL(jump_addr) (%rip)
> +#endif
> +
> +LOCAL(jump_addr):
> +VARIABLE(grub_relocator64_efi_rip)
> +	.quad	0
> +
This repeats relocator64 almost exactly. Can we avoid code duplication?
It's fine to compile it twice but code duplication is bad.
> +VARIABLE(grub_relocator64_efi_end)
> diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
> index fd8f28e..ca7154f 100644
> --- a/grub-core/loader/multiboot.c
> +++ b/grub-core/loader/multiboot.c
> @@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)
>    return err;
>  }
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +#define grub_relocator_efi_boot	grub_relocator64_efi_boot
> +#endif
> +#endif
> +
>  static grub_err_t
>  grub_multiboot_boot (void)
>  {
>    grub_err_t err;
> +  grub_uint32_t target;
>    struct grub_relocator32_state state = MULTIBOOT_INITIAL_STATE;
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +  struct grub_relocator64_efi_state state_efi = MULTIBOOT_EFI_INITIAL_STATE;
> +#endif
> +#endif
>  
> -  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
> -
> -  err = grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER);
> +  err = grub_multiboot_make_mbi (&target);
>  
>    if (err)
>      return err;
>  
> +  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
> +  state.MULTIBOOT_MBI_REGISTER = target;
> +
>  #if defined (__i386__) || defined (__x86_64__)
> +#ifdef GRUB_MACHINE_EFI
> +  state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip;
> +  state_efi.MULTIBOOT_EFI_MBI_REGISTER = target;
> +
> +  if (grub_efi_is_finished)
> +    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
> +  else
> +    grub_relocator_efi_boot (grub_multiboot_relocator, state_efi);
> +#else
>    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
> +#endif
>  #else
>    grub_relocator32_boot (grub_multiboot_relocator, state);
>  #endif
This becomes hairy. I think it's time to split it into platform-specific
functions and/or use tricks like
#ifndef GRUB_MACHINE_EFI
#define grub_efi_is_finished 0
#endif
> diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> index d7c19bc..8d66e3f 100644
> --- a/grub-core/loader/multiboot_mbi2.c
> +++ b/grub-core/loader/multiboot_mbi2.c
> @@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>    grub_err_t err;
>    struct multiboot_header_tag *tag;
>    struct multiboot_header_tag_address *addr_tag = NULL;
> -  int entry_specified = 0;
> -  grub_addr_t entry = 0;
> +  int entry_specified = 0, efi_entry_specified = 0;
> +  grub_addr_t entry = 0, efi_entry = 0;
>    grub_uint32_t console_required = 0;
>    struct multiboot_header_tag_framebuffer *fbtag = NULL;
>    int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
> @@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;
>  	break;
>  
> +      case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64:
> +#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__)
> +	efi_entry_specified = 1;
> +	efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr;
> +#endif
> +	break;
> +
Why do we need separate handling of EFI entry point? Why can't we use
the same structure?
>        case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS:
>  	if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags
>  	    & MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED))
> @@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	break;
>  
>        case MULTIBOOT_HEADER_TAG_EFI_BS:
> +#ifdef GRUB_MACHINE_EFI
>  	keep_bs = 1;
> +#endif
>  	break;
>  
>        default:
> @@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	break;
>        }
>  
> -  if (addr_tag && !entry_specified)
> +  if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified))
>      {
>        grub_free (buffer);
>        return grub_error (GRUB_ERR_UNKNOWN_OS,
> @@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	}
>      }
>  
> -  if (entry_specified)
> +  if (keep_bs && efi_entry_specified)
> +    grub_multiboot_payload_eip = efi_entry;
> +  else if (entry_specified)
>      grub_multiboot_payload_eip = entry;
>  
This seems redundant.
>    if (fbtag)
> diff --git a/include/grub/i386/multiboot.h b/include/grub/i386/multiboot.h
> index a1b9488..807a1de 100644
> --- a/include/grub/i386/multiboot.h
> +++ b/include/grub/i386/multiboot.h
> @@ -30,6 +30,17 @@
>  #define MULTIBOOT_MBI_REGISTER ebx
>  #define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_I386
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +#define MULTIBOOT_EFI_INITIAL_STATE  { .rax = MULTIBOOT_BOOTLOADER_MAGIC,	\
> +    .rcx = 0,									\
> +    .rdx = 0,									\
> +      }
> +#define MULTIBOOT_EFI_ENTRY_REGISTER rip
> +#define MULTIBOOT_EFI_MBI_REGISTER rbx
> +#endif
> +#endif
> +
>  #define MULTIBOOT_ELF32_MACHINE EM_386
>  #define MULTIBOOT_ELF64_MACHINE EM_X86_64
>  
> diff --git a/include/grub/i386/relocator.h b/include/grub/i386/relocator.h
> index 5f89a7e..2a56c3b 100644
> --- a/include/grub/i386/relocator.h
> +++ b/include/grub/i386/relocator.h
> @@ -65,6 +65,20 @@ struct grub_relocator64_state
>    grub_addr_t cr3;
>  };
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +struct grub_relocator64_efi_state
> +{
> +  grub_uint64_t rax;
> +  grub_uint64_t rbx;
> +  grub_uint64_t rcx;
> +  grub_uint64_t rdx;
> +  grub_uint64_t rip;
> +  grub_uint64_t rsi;
> +};
> +#endif
> +#endif
> +
>  grub_err_t grub_relocator16_boot (struct grub_relocator *rel,
>  				  struct grub_relocator16_state state);
>  
> @@ -76,4 +90,11 @@ grub_err_t grub_relocator64_boot (struct grub_relocator *rel,
>  				  struct grub_relocator64_state state,
>  				  grub_addr_t min_addr, grub_addr_t max_addr);
>  
> +#ifdef GRUB_MACHINE_EFI
> +#ifdef __x86_64__
> +grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel,
> +				      struct grub_relocator64_efi_state state);
> +#endif
> +#endif
> +
>  #endif /* ! GRUB_RELOCATOR_CPU_HEADER */
> diff --git a/include/multiboot2.h b/include/multiboot2.h
> index 9d48627..b3977e3 100644
> --- a/include/multiboot2.h
> +++ b/include/multiboot2.h
> @@ -69,6 +69,7 @@
>  #define MULTIBOOT_HEADER_TAG_FRAMEBUFFER  5
>  #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
>  #define MULTIBOOT_HEADER_TAG_EFI_BS  7
> +#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
>  
>  #define MULTIBOOT_ARCHITECTURE_I386  0
>  #define MULTIBOOT_ARCHITECTURE_MIPS32  4
> @@ -133,6 +134,14 @@ struct multiboot_header_tag_entry_address
>    multiboot_uint32_t entry_addr;
>  };
>  
> +struct multiboot_header_tag_entry_address_efi64
> +{
> +  multiboot_uint16_t type;
> +  multiboot_uint16_t flags;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t entry_addr;
> +};
> +
Ditto
>  struct multiboot_header_tag_console_flags
>  {
>    multiboot_uint16_t type;
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image
       [not found]   ` <CAEaD8JOaS=J22k+Sq=8Ou77pO6yvtgxSLiwuMjAoirSipJhW6g@mail.gmail.com>
@ 2015-11-09 20:06     ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 0 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-09 20:06 UTC (permalink / raw)
  To: Daniel Kiper, The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 5577 bytes --]

On 09.11.2015 20:15, Vladimir 'phcoder' Serbinenko wrote:
> Lgtm
> 
> Le 20 juil. 2015 4:36 PM, "Daniel Kiper" <daniel.kiper@oracle.com
> <mailto:daniel.kiper@oracle.com>> a écrit :
> 
>     Add tags used to pass ImageHandle to loaded image. It is used
>     by at least ExitBootServices() function.
> 
>     Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com
>     <mailto:daniel.kiper@oracle.com>>
>     ---
>      grub-core/loader/multiboot_mbi2.c |   46
>     +++++++++++++++++++++++++++++--------
>      include/multiboot2.h              |   16 +++++++++++++
>      2 files changed, 53 insertions(+), 9 deletions(-)
> 
>     diff --git a/grub-core/loader/multiboot_mbi2.c
>     b/grub-core/loader/multiboot_mbi2.c
>     index 8d66e3f..dc9c709 100644
>     --- a/grub-core/loader/multiboot_mbi2.c
>     +++ b/grub-core/loader/multiboot_mbi2.c
>     @@ -172,6 +172,8 @@ grub_multiboot_load (grub_file_t file, const
>     char *filename)
>                   case MULTIBOOT_TAG_TYPE_NETWORK:
>                   case MULTIBOOT_TAG_TYPE_EFI_MMAP:
>                   case MULTIBOOT_TAG_TYPE_EFI_BS:
>     +             case MULTIBOOT_TAG_TYPE_EFI32_IH:
>     +             case MULTIBOOT_TAG_TYPE_EFI64_IH:
>                     break;
> 
>                   default:
>     @@ -407,16 +409,18 @@ grub_multiboot_get_mbi_size (void)
>                      + grub_get_multiboot_mmap_count ()
>                      * sizeof (struct multiboot_mmap_entry)),
>     MULTIBOOT_TAG_ALIGN)
>          + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer),
>     MULTIBOOT_TAG_ALIGN)
>     +#ifdef GRUB_MACHINE_EFI
>          + ALIGN_UP (sizeof (struct multiboot_tag_efi32),
>     MULTIBOOT_TAG_ALIGN)
>          + ALIGN_UP (sizeof (struct multiboot_tag_efi64),
>     MULTIBOOT_TAG_ALIGN)
>     +    + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih),
>     MULTIBOOT_TAG_ALIGN)
>     +    + ALIGN_UP (sizeof (struct multiboot_tag_efi64_ih),
>     MULTIBOOT_TAG_ALIGN)
>     +    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
>     +               + efi_mmap_size, MULTIBOOT_TAG_ALIGN)
>     +#endif
>          + ALIGN_UP (sizeof (struct multiboot_tag_old_acpi)
>                     + sizeof (struct grub_acpi_rsdp_v10),
>     MULTIBOOT_TAG_ALIGN)
>          + acpiv2_size ()
>          + net_size ()
>     -#ifdef GRUB_MACHINE_EFI
>     -    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
>     -               + efi_mmap_size, MULTIBOOT_TAG_ALIGN)
>     -#endif
>          + sizeof (struct multiboot_tag_vbe) + MULTIBOOT_TAG_ALIGN - 1
>          + sizeof (struct multiboot_tag_apm) + MULTIBOOT_TAG_ALIGN - 1;
>      }
>     @@ -906,11 +910,35 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
> 
>        if (keep_bs)
>          {
>     -      struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
>     -      tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
>     -      tag->size = sizeof (struct multiboot_tag);
>     -      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
>     -       / sizeof (grub_properly_aligned_t);
>     +      {
>     +       struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
>     +       tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
>     +       tag->size = sizeof (struct multiboot_tag);
>     +       ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
>     +         / sizeof (grub_properly_aligned_t);
>     +      }
>     +
>     +#ifdef __x86_64__
>     +      {
>     +       struct multiboot_tag_efi64_ih *tag = (struct
>     multiboot_tag_efi64_ih *) ptrorig;
>     +       tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH;
>     +       tag->size = sizeof (*tag);
>     +       tag->pointer = (grub_addr_t) grub_efi_image_handle;
>     +       ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
>     +         / sizeof (grub_properly_aligned_t);
>     +      }
>     +#endif
>     +
>     +#ifdef __i386__
>     +      {
>     +       struct multiboot_tag_efi32_ih *tag = (struct
>     multiboot_tag_efi32_ih *) ptrorig;
>     +       tag->type = MULTIBOOT_TAG_TYPE_EFI32_IH;
>     +       tag->size = sizeof (*tag);
>     +       tag->pointer = (grub_addr_t) grub_efi_image_handle;
>     +       ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
>     +         / sizeof (grub_properly_aligned_t);
>     +      }
>     +#endif
>          }
>      #endif
> 
>     diff --git a/include/multiboot2.h b/include/multiboot2.h
>     index b3977e3..9f97ddc 100644
>     --- a/include/multiboot2.h
>     +++ b/include/multiboot2.h
>     @@ -60,6 +60,8 @@
>      #define MULTIBOOT_TAG_TYPE_NETWORK           16
>      #define MULTIBOOT_TAG_TYPE_EFI_MMAP          17
>      #define MULTIBOOT_TAG_TYPE_EFI_BS            18
>     +#define MULTIBOOT_TAG_TYPE_EFI32_IH          19
>     +#define MULTIBOOT_TAG_TYPE_EFI64_IH          20
> 
>      #define MULTIBOOT_HEADER_TAG_END  0
>      #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
>     @@ -379,6 +381,20 @@ struct multiboot_tag_efi_mmap
>        multiboot_uint8_t efi_mmap[0];
>      };
> 
>     +struct multiboot_tag_efi32_ih
>     +{
>     +  multiboot_uint32_t type;
>     +  multiboot_uint32_t size;
>     +  multiboot_uint32_t pointer;
>     +};
>     +
>     +struct multiboot_tag_efi64_ih
>     +{
>     +  multiboot_uint32_t type;
>     +  multiboot_uint32_t size;
>     +  multiboot_uint64_t pointer;
>     +};
>     +
>      #endif /* ! ASM_FILE */
> 
>      #endif /* ! MULTIBOOT_HEADER */
>     --
>     1.7.10.4
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
  2015-07-20 14:35 ` [PATCH v2 5/6] multiboot2: Add support for relocatable images Daniel Kiper
  2015-08-11 18:51   ` Konrad Rzeszutek Wilk
  2015-08-11 18:51   ` Konrad Rzeszutek Wilk
@ 2015-11-09 20:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-09 20:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
  3 siblings, 0 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-09 20:08 UTC (permalink / raw)
  To: Daniel Kiper, xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei


[-- Attachment #1.1: Type: text/plain, Size: 14098 bytes --]

On 20.07.2015 16:35, Daniel Kiper wrote:
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
What is handling the actual relocation? Why doesn't this patch include
support for ELF relocations?
> ---
>  grub-core/loader/i386/multiboot_mbi.c |    6 ++--
>  grub-core/loader/multiboot.c          |   12 +++++--
>  grub-core/loader/multiboot_elfxx.c    |   28 +++++++++++----
>  grub-core/loader/multiboot_mbi2.c     |   63 +++++++++++++++++++++++++++++----
>  include/grub/multiboot.h              |    4 ++-
>  include/multiboot2.h                  |   24 +++++++++++++
>  6 files changed, 118 insertions(+), 19 deletions(-)
> 
> diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c
> index 956d0e3..abdb98b 100644
> --- a/grub-core/loader/i386/multiboot_mbi.c
> +++ b/grub-core/loader/i386/multiboot_mbi.c
> @@ -72,7 +72,8 @@ load_kernel (grub_file_t file, const char *filename,
>    grub_err_t err;
>    if (grub_multiboot_quirks & GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE)
>      {
> -      err = grub_multiboot_load_elf (file, filename, buffer);
> +      err = grub_multiboot_load_elf (file, filename, buffer, 0, 0, 0, 0,
> +				     GRUB_RELOCATOR_PREFERENCE_NONE, NULL, 0);
>        if (err == GRUB_ERR_UNKNOWN_OS && (header->flags & MULTIBOOT_AOUT_KLUDGE))
>  	grub_errno = err = GRUB_ERR_NONE;
>      }
> @@ -118,7 +119,8 @@ load_kernel (grub_file_t file, const char *filename,
>        return GRUB_ERR_NONE;
>      }
>  
> -  return grub_multiboot_load_elf (file, filename, buffer);
> +  return grub_multiboot_load_elf (file, filename, buffer, 0, 0, 0, 0,
> +				  GRUB_RELOCATOR_PREFERENCE_NONE, NULL, 0);
>  }
>  
>  static struct multiboot_header *
> diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
> index ca7154f..1b1f7a9 100644
> --- a/grub-core/loader/multiboot.c
> +++ b/grub-core/loader/multiboot.c
> @@ -190,12 +190,18 @@ static grub_uint64_t highest_load;
>  /* Load ELF32 or ELF64.  */
>  grub_err_t
>  grub_multiboot_load_elf (grub_file_t file, const char *filename,
> -			 void *buffer)
> +			 void *buffer, int relocatable, grub_uint32_t min_addr,
> +			 grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
> +			 grub_uint32_t *base_addr, int avoid_efi_boot_services)
>  {
>    if (grub_multiboot_is_elf32 (buffer))
> -    return grub_multiboot_load_elf32 (file, filename, buffer);
> +    return grub_multiboot_load_elf32 (file, filename, buffer, relocatable,
> +				      min_addr, max_addr, align, preference,
> +				      base_addr, avoid_efi_boot_services);
>    else if (grub_multiboot_is_elf64 (buffer))
> -    return grub_multiboot_load_elf64 (file, filename, buffer);
> +    return grub_multiboot_load_elf64 (file, filename, buffer, relocatable,
> +				      min_addr, max_addr, align, preference,
> +				      base_addr, avoid_efi_boot_services);
>  
>    return grub_error (GRUB_ERR_UNKNOWN_OS, N_("invalid arch-dependent ELF magic"));
>  }
> diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c
> index 6a220bd..4fce685 100644
> --- a/grub-core/loader/multiboot_elfxx.c
> +++ b/grub-core/loader/multiboot_elfxx.c
> @@ -51,7 +51,10 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer)
>  }
>  
>  static grub_err_t
> -CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, void *buffer)
> +CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename,
> +				     void *buffer, int relocatable, grub_uint32_t min_addr,
> +				     grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
> +				     grub_uint32_t *base_addr, int avoid_efi_boot_services)
>  {
>    Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;
>    char *phdr_base;
> @@ -89,19 +92,30 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
>  	  if (phdr(i)->p_paddr + phdr(i)->p_memsz > highest_load)
>  	    highest_load = phdr(i)->p_paddr + phdr(i)->p_memsz;
>  
> -	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n",
> -			i, (long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr);
> +	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx,"
> +			"align=0x%lx, relocatable=%d, avoid_efi_boot_services=%d\n", i,
> +			(long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr,
> +			(long) align, relocatable, avoid_efi_boot_services);
>  
>  	  {
>  	    grub_relocator_chunk_t ch;
> -	    err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, 
> -						   &ch, phdr(i)->p_paddr,
> -						   phdr(i)->p_memsz);
> +
> +	    if (relocatable)
> +	      err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
> +						      min_addr, max_addr - phdr(i)->p_memsz,
> +						      phdr(i)->p_memsz, align ? align : 1,
> +						      preference, avoid_efi_boot_services);
> +	    else
> +	      err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
> +						     &ch, phdr(i)->p_paddr,
> +						     phdr(i)->p_memsz);
>  	    if (err)
>  	      {
>  		grub_dprintf ("multiboot_loader", "Error loading phdr %d\n", i);
>  		return err;
>  	      }
> +	    if (base_addr)
> +	      *base_addr = get_physical_target_address (ch);
>  	    source = get_virtual_current_address (ch);
>  	  }
>  
> @@ -208,7 +222,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
>  						    + 1, sh->sh_size,
>  						    sh->sh_addralign,
>  						    GRUB_RELOCATOR_PREFERENCE_NONE,
> -						    0);
> +						    avoid_efi_boot_services);
>  	    if (err)
>  	      {
>  		grub_dprintf ("multiboot_loader", "Error loading shdr %d\n", i);
> diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> index dc9c709..7ac64ec 100644
> --- a/grub-core/loader/multiboot_mbi2.c
> +++ b/grub-core/loader/multiboot_mbi2.c
> @@ -68,6 +68,7 @@ static grub_size_t elf_sec_num, elf_sec_entsize;
>  static unsigned elf_sec_shstrndx;
>  static void *elf_sections;
>  static int keep_bs = 0;
> +static grub_uint32_t base_addr = 0;
>  
>  void
>  grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,
> @@ -107,11 +108,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>    grub_err_t err;
>    struct multiboot_header_tag *tag;
>    struct multiboot_header_tag_address *addr_tag = NULL;
> -  int entry_specified = 0, efi_entry_specified = 0;
> +  int entry_specified = 0, efi_entry_specified = 0, relocatable = 0;
>    grub_addr_t entry = 0, efi_entry = 0;
> -  grub_uint32_t console_required = 0;
> +  grub_uint32_t console_required = 0, min_addr = 0;
> +  grub_uint32_t max_addr = 0, preference = 0;
>    struct multiboot_header_tag_framebuffer *fbtag = NULL;
>    int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
> +  grub_size_t align = 0;
>  
>    buffer = grub_malloc (MULTIBOOT_SEARCH);
>    if (!buffer)
> @@ -174,6 +177,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	      case MULTIBOOT_TAG_TYPE_EFI_BS:
>  	      case MULTIBOOT_TAG_TYPE_EFI32_IH:
>  	      case MULTIBOOT_TAG_TYPE_EFI64_IH:
> +	      case MULTIBOOT_TAG_TYPE_BASE_ADDR:
>  		break;
>  
>  	      default:
> @@ -215,6 +219,26 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	accepted_consoles |= GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER;
>  	break;
>  
> +      case MULTIBOOT_HEADER_TAG_RELOCATABLE:
> +	relocatable = 1;
> +	min_addr = ((struct multiboot_header_tag_relocatable *) tag)->min_addr;
> +	max_addr = ((struct multiboot_header_tag_relocatable *) tag)->max_addr;
> +	align = ((struct multiboot_header_tag_relocatable *) tag)->align;
> +	switch (((struct multiboot_header_tag_relocatable *) tag)->preference)
> +	  {
> +	  case MULTIBOOT_LOAD_PREFERENCE_LOW:
> +	    preference = GRUB_RELOCATOR_PREFERENCE_LOW;
> +	    break;
> +
> +	  case MULTIBOOT_LOAD_PREFERENCE_HIGH:
> +	    preference = GRUB_RELOCATOR_PREFERENCE_HIGH;
> +	    break;
> +
> +	  default:
> +	    preference = GRUB_RELOCATOR_PREFERENCE_NONE;
> +	  }
> +	break;
> +
>  	/* GRUB always page-aligns modules.  */
>        case MULTIBOOT_HEADER_TAG_MODULE_ALIGN:
>  	break;
> @@ -260,15 +284,22 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>        else
>  	code_size = load_size;
>  
> -      err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, 
> -					     &ch, load_addr,
> -					     code_size);
> +      if (relocatable)
> +	err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
> +						min_addr, max_addr - code_size,
> +						code_size, align ? align : 1,
> +						preference, keep_bs);
> +      else
> +	err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
> +					       &ch, load_addr,
> +					       code_size);
>        if (err)
>  	{
>  	  grub_dprintf ("multiboot_loader", "Error loading aout kludge\n");
>  	  grub_free (buffer);
>  	  return err;
>  	}
> +      base_addr = get_physical_target_address (ch);
>        source = get_virtual_current_address (ch);
>  
>        if ((grub_file_seek (file, offset)) == (grub_off_t) -1)
> @@ -290,7 +321,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>      }
>    else
>      {
> -      err = grub_multiboot_load_elf (file, filename, buffer);
> +      err = grub_multiboot_load_elf (file, filename, buffer,
> +				     relocatable, min_addr, max_addr,
> +				     align, preference, &base_addr, keep_bs);
>        if (err)
>  	{
>  	  grub_free (buffer);
> @@ -303,6 +336,14 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>    else if (entry_specified)
>      grub_multiboot_payload_eip = entry;
>  
> +  if (relocatable)
> +    {
> +      if (base_addr > min_addr)
> +	grub_multiboot_payload_eip += base_addr - min_addr;
> +      else
> +	grub_multiboot_payload_eip -= min_addr - base_addr;
> +    }
> +
>    if (fbtag)
>      err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER,
>  				      accepted_consoles,
> @@ -409,6 +450,7 @@ grub_multiboot_get_mbi_size (void)
>  		 + grub_get_multiboot_mmap_count ()
>  		 * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN)
>      + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN)
> +    + ALIGN_UP (sizeof (struct multiboot_tag_base_addr), MULTIBOOT_TAG_ALIGN)
>  #ifdef GRUB_MACHINE_EFI
>      + ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN)
>      + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
> @@ -693,6 +735,15 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
>    ptrorig += (2 * sizeof (grub_uint32_t)) / sizeof (grub_properly_aligned_t);
>  
>    {
> +    struct multiboot_tag_base_addr *tag = (struct multiboot_tag_base_addr *) ptrorig;
> +    tag->type = MULTIBOOT_TAG_TYPE_BASE_ADDR;
> +    tag->size = sizeof (struct multiboot_tag_base_addr); 
> +    tag->base_addr = base_addr;
> +    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +       / sizeof (grub_properly_aligned_t);
> +  }
> +
> +  {
>      struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig;
>      tag->type = MULTIBOOT_TAG_TYPE_CMDLINE;
>      tag->size = sizeof (struct multiboot_tag_string) + cmdline_size; 
> diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h
> index e13c084..ec322b0 100644
> --- a/include/grub/multiboot.h
> +++ b/include/grub/multiboot.h
> @@ -94,7 +94,9 @@ grub_multiboot_load (grub_file_t file, const char *filename);
>  /* Load ELF32 or ELF64.  */
>  grub_err_t
>  grub_multiboot_load_elf (grub_file_t file, const char *filename,
> -			 void *buffer);
> +			 void *buffer, int relocatable, grub_uint32_t min_addr,
> +			 grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
> +			 grub_uint32_t *base_addr, int avoid_efi_boot_services);
>  extern grub_size_t grub_multiboot_pure_size;
>  extern grub_size_t grub_multiboot_alloc_mbi;
>  extern grub_uint32_t grub_multiboot_payload_eip;
> diff --git a/include/multiboot2.h b/include/multiboot2.h
> index 9f97ddc..941a95d 100644
> --- a/include/multiboot2.h
> +++ b/include/multiboot2.h
> @@ -62,6 +62,7 @@
>  #define MULTIBOOT_TAG_TYPE_EFI_BS            18
>  #define MULTIBOOT_TAG_TYPE_EFI32_IH          19
>  #define MULTIBOOT_TAG_TYPE_EFI64_IH          20
> +#define MULTIBOOT_TAG_TYPE_BASE_ADDR         21
>  
>  #define MULTIBOOT_HEADER_TAG_END  0
>  #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
> @@ -72,11 +73,16 @@
>  #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
>  #define MULTIBOOT_HEADER_TAG_EFI_BS  7
>  #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
> +#define MULTIBOOT_HEADER_TAG_RELOCATABLE  10
>  
>  #define MULTIBOOT_ARCHITECTURE_I386  0
>  #define MULTIBOOT_ARCHITECTURE_MIPS32  4
>  #define MULTIBOOT_HEADER_TAG_OPTIONAL 1
>  
> +#define MULTIBOOT_LOAD_PREFERENCE_NONE 0
> +#define MULTIBOOT_LOAD_PREFERENCE_LOW 1
> +#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2
> +
>  #define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
>  #define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
>  
> @@ -169,6 +175,17 @@ struct multiboot_header_tag_module_align
>    multiboot_uint32_t size;
>  };
>  
> +struct multiboot_header_tag_relocatable
> +{
> +  multiboot_uint16_t type;
> +  multiboot_uint16_t flags;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t min_addr;
> +  multiboot_uint32_t max_addr;
> +  multiboot_uint32_t align;
> +  multiboot_uint32_t preference;
> +};
> +
>  struct multiboot_color
>  {
>    multiboot_uint8_t red;
> @@ -395,6 +412,13 @@ struct multiboot_tag_efi64_ih
>    multiboot_uint64_t pointer;
>  };
>  
> +struct multiboot_tag_base_addr
> +{
> +  multiboot_uint32_t type;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t base_addr;
> +};
> +
>  #endif /* ! ASM_FILE */
>  
>  #endif /* ! MULTIBOOT_HEADER */
> 



[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
  2015-07-20 14:35 ` [PATCH v2 5/6] multiboot2: Add support for relocatable images Daniel Kiper
                     ` (2 preceding siblings ...)
  2015-11-09 20:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-11-09 20:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-10 14:52       ` Daniel Kiper
  3 siblings, 1 reply; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-09 20:08 UTC (permalink / raw)
  To: Daniel Kiper, xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

[-- Attachment #1: Type: text/plain, Size: 14098 bytes --]

On 20.07.2015 16:35, Daniel Kiper wrote:
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
What is handling the actual relocation? Why doesn't this patch include
support for ELF relocations?
> ---
>  grub-core/loader/i386/multiboot_mbi.c |    6 ++--
>  grub-core/loader/multiboot.c          |   12 +++++--
>  grub-core/loader/multiboot_elfxx.c    |   28 +++++++++++----
>  grub-core/loader/multiboot_mbi2.c     |   63 +++++++++++++++++++++++++++++----
>  include/grub/multiboot.h              |    4 ++-
>  include/multiboot2.h                  |   24 +++++++++++++
>  6 files changed, 118 insertions(+), 19 deletions(-)
> 
> diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c
> index 956d0e3..abdb98b 100644
> --- a/grub-core/loader/i386/multiboot_mbi.c
> +++ b/grub-core/loader/i386/multiboot_mbi.c
> @@ -72,7 +72,8 @@ load_kernel (grub_file_t file, const char *filename,
>    grub_err_t err;
>    if (grub_multiboot_quirks & GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE)
>      {
> -      err = grub_multiboot_load_elf (file, filename, buffer);
> +      err = grub_multiboot_load_elf (file, filename, buffer, 0, 0, 0, 0,
> +				     GRUB_RELOCATOR_PREFERENCE_NONE, NULL, 0);
>        if (err == GRUB_ERR_UNKNOWN_OS && (header->flags & MULTIBOOT_AOUT_KLUDGE))
>  	grub_errno = err = GRUB_ERR_NONE;
>      }
> @@ -118,7 +119,8 @@ load_kernel (grub_file_t file, const char *filename,
>        return GRUB_ERR_NONE;
>      }
>  
> -  return grub_multiboot_load_elf (file, filename, buffer);
> +  return grub_multiboot_load_elf (file, filename, buffer, 0, 0, 0, 0,
> +				  GRUB_RELOCATOR_PREFERENCE_NONE, NULL, 0);
>  }
>  
>  static struct multiboot_header *
> diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
> index ca7154f..1b1f7a9 100644
> --- a/grub-core/loader/multiboot.c
> +++ b/grub-core/loader/multiboot.c
> @@ -190,12 +190,18 @@ static grub_uint64_t highest_load;
>  /* Load ELF32 or ELF64.  */
>  grub_err_t
>  grub_multiboot_load_elf (grub_file_t file, const char *filename,
> -			 void *buffer)
> +			 void *buffer, int relocatable, grub_uint32_t min_addr,
> +			 grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
> +			 grub_uint32_t *base_addr, int avoid_efi_boot_services)
>  {
>    if (grub_multiboot_is_elf32 (buffer))
> -    return grub_multiboot_load_elf32 (file, filename, buffer);
> +    return grub_multiboot_load_elf32 (file, filename, buffer, relocatable,
> +				      min_addr, max_addr, align, preference,
> +				      base_addr, avoid_efi_boot_services);
>    else if (grub_multiboot_is_elf64 (buffer))
> -    return grub_multiboot_load_elf64 (file, filename, buffer);
> +    return grub_multiboot_load_elf64 (file, filename, buffer, relocatable,
> +				      min_addr, max_addr, align, preference,
> +				      base_addr, avoid_efi_boot_services);
>  
>    return grub_error (GRUB_ERR_UNKNOWN_OS, N_("invalid arch-dependent ELF magic"));
>  }
> diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c
> index 6a220bd..4fce685 100644
> --- a/grub-core/loader/multiboot_elfxx.c
> +++ b/grub-core/loader/multiboot_elfxx.c
> @@ -51,7 +51,10 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer)
>  }
>  
>  static grub_err_t
> -CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, void *buffer)
> +CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename,
> +				     void *buffer, int relocatable, grub_uint32_t min_addr,
> +				     grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
> +				     grub_uint32_t *base_addr, int avoid_efi_boot_services)
>  {
>    Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;
>    char *phdr_base;
> @@ -89,19 +92,30 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
>  	  if (phdr(i)->p_paddr + phdr(i)->p_memsz > highest_load)
>  	    highest_load = phdr(i)->p_paddr + phdr(i)->p_memsz;
>  
> -	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n",
> -			i, (long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr);
> +	  grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx,"
> +			"align=0x%lx, relocatable=%d, avoid_efi_boot_services=%d\n", i,
> +			(long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr,
> +			(long) align, relocatable, avoid_efi_boot_services);
>  
>  	  {
>  	    grub_relocator_chunk_t ch;
> -	    err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, 
> -						   &ch, phdr(i)->p_paddr,
> -						   phdr(i)->p_memsz);
> +
> +	    if (relocatable)
> +	      err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
> +						      min_addr, max_addr - phdr(i)->p_memsz,
> +						      phdr(i)->p_memsz, align ? align : 1,
> +						      preference, avoid_efi_boot_services);
> +	    else
> +	      err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
> +						     &ch, phdr(i)->p_paddr,
> +						     phdr(i)->p_memsz);
>  	    if (err)
>  	      {
>  		grub_dprintf ("multiboot_loader", "Error loading phdr %d\n", i);
>  		return err;
>  	      }
> +	    if (base_addr)
> +	      *base_addr = get_physical_target_address (ch);
>  	    source = get_virtual_current_address (ch);
>  	  }
>  
> @@ -208,7 +222,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi
>  						    + 1, sh->sh_size,
>  						    sh->sh_addralign,
>  						    GRUB_RELOCATOR_PREFERENCE_NONE,
> -						    0);
> +						    avoid_efi_boot_services);
>  	    if (err)
>  	      {
>  		grub_dprintf ("multiboot_loader", "Error loading shdr %d\n", i);
> diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> index dc9c709..7ac64ec 100644
> --- a/grub-core/loader/multiboot_mbi2.c
> +++ b/grub-core/loader/multiboot_mbi2.c
> @@ -68,6 +68,7 @@ static grub_size_t elf_sec_num, elf_sec_entsize;
>  static unsigned elf_sec_shstrndx;
>  static void *elf_sections;
>  static int keep_bs = 0;
> +static grub_uint32_t base_addr = 0;
>  
>  void
>  grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,
> @@ -107,11 +108,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>    grub_err_t err;
>    struct multiboot_header_tag *tag;
>    struct multiboot_header_tag_address *addr_tag = NULL;
> -  int entry_specified = 0, efi_entry_specified = 0;
> +  int entry_specified = 0, efi_entry_specified = 0, relocatable = 0;
>    grub_addr_t entry = 0, efi_entry = 0;
> -  grub_uint32_t console_required = 0;
> +  grub_uint32_t console_required = 0, min_addr = 0;
> +  grub_uint32_t max_addr = 0, preference = 0;
>    struct multiboot_header_tag_framebuffer *fbtag = NULL;
>    int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
> +  grub_size_t align = 0;
>  
>    buffer = grub_malloc (MULTIBOOT_SEARCH);
>    if (!buffer)
> @@ -174,6 +177,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	      case MULTIBOOT_TAG_TYPE_EFI_BS:
>  	      case MULTIBOOT_TAG_TYPE_EFI32_IH:
>  	      case MULTIBOOT_TAG_TYPE_EFI64_IH:
> +	      case MULTIBOOT_TAG_TYPE_BASE_ADDR:
>  		break;
>  
>  	      default:
> @@ -215,6 +219,26 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>  	accepted_consoles |= GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER;
>  	break;
>  
> +      case MULTIBOOT_HEADER_TAG_RELOCATABLE:
> +	relocatable = 1;
> +	min_addr = ((struct multiboot_header_tag_relocatable *) tag)->min_addr;
> +	max_addr = ((struct multiboot_header_tag_relocatable *) tag)->max_addr;
> +	align = ((struct multiboot_header_tag_relocatable *) tag)->align;
> +	switch (((struct multiboot_header_tag_relocatable *) tag)->preference)
> +	  {
> +	  case MULTIBOOT_LOAD_PREFERENCE_LOW:
> +	    preference = GRUB_RELOCATOR_PREFERENCE_LOW;
> +	    break;
> +
> +	  case MULTIBOOT_LOAD_PREFERENCE_HIGH:
> +	    preference = GRUB_RELOCATOR_PREFERENCE_HIGH;
> +	    break;
> +
> +	  default:
> +	    preference = GRUB_RELOCATOR_PREFERENCE_NONE;
> +	  }
> +	break;
> +
>  	/* GRUB always page-aligns modules.  */
>        case MULTIBOOT_HEADER_TAG_MODULE_ALIGN:
>  	break;
> @@ -260,15 +284,22 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>        else
>  	code_size = load_size;
>  
> -      err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, 
> -					     &ch, load_addr,
> -					     code_size);
> +      if (relocatable)
> +	err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
> +						min_addr, max_addr - code_size,
> +						code_size, align ? align : 1,
> +						preference, keep_bs);
> +      else
> +	err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
> +					       &ch, load_addr,
> +					       code_size);
>        if (err)
>  	{
>  	  grub_dprintf ("multiboot_loader", "Error loading aout kludge\n");
>  	  grub_free (buffer);
>  	  return err;
>  	}
> +      base_addr = get_physical_target_address (ch);
>        source = get_virtual_current_address (ch);
>  
>        if ((grub_file_seek (file, offset)) == (grub_off_t) -1)
> @@ -290,7 +321,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>      }
>    else
>      {
> -      err = grub_multiboot_load_elf (file, filename, buffer);
> +      err = grub_multiboot_load_elf (file, filename, buffer,
> +				     relocatable, min_addr, max_addr,
> +				     align, preference, &base_addr, keep_bs);
>        if (err)
>  	{
>  	  grub_free (buffer);
> @@ -303,6 +336,14 @@ grub_multiboot_load (grub_file_t file, const char *filename)
>    else if (entry_specified)
>      grub_multiboot_payload_eip = entry;
>  
> +  if (relocatable)
> +    {
> +      if (base_addr > min_addr)
> +	grub_multiboot_payload_eip += base_addr - min_addr;
> +      else
> +	grub_multiboot_payload_eip -= min_addr - base_addr;
> +    }
> +
>    if (fbtag)
>      err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER,
>  				      accepted_consoles,
> @@ -409,6 +450,7 @@ grub_multiboot_get_mbi_size (void)
>  		 + grub_get_multiboot_mmap_count ()
>  		 * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN)
>      + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN)
> +    + ALIGN_UP (sizeof (struct multiboot_tag_base_addr), MULTIBOOT_TAG_ALIGN)
>  #ifdef GRUB_MACHINE_EFI
>      + ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN)
>      + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
> @@ -693,6 +735,15 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
>    ptrorig += (2 * sizeof (grub_uint32_t)) / sizeof (grub_properly_aligned_t);
>  
>    {
> +    struct multiboot_tag_base_addr *tag = (struct multiboot_tag_base_addr *) ptrorig;
> +    tag->type = MULTIBOOT_TAG_TYPE_BASE_ADDR;
> +    tag->size = sizeof (struct multiboot_tag_base_addr); 
> +    tag->base_addr = base_addr;
> +    ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
> +       / sizeof (grub_properly_aligned_t);
> +  }
> +
> +  {
>      struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig;
>      tag->type = MULTIBOOT_TAG_TYPE_CMDLINE;
>      tag->size = sizeof (struct multiboot_tag_string) + cmdline_size; 
> diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h
> index e13c084..ec322b0 100644
> --- a/include/grub/multiboot.h
> +++ b/include/grub/multiboot.h
> @@ -94,7 +94,9 @@ grub_multiboot_load (grub_file_t file, const char *filename);
>  /* Load ELF32 or ELF64.  */
>  grub_err_t
>  grub_multiboot_load_elf (grub_file_t file, const char *filename,
> -			 void *buffer);
> +			 void *buffer, int relocatable, grub_uint32_t min_addr,
> +			 grub_uint32_t max_addr, grub_size_t align, grub_uint32_t preference,
> +			 grub_uint32_t *base_addr, int avoid_efi_boot_services);
>  extern grub_size_t grub_multiboot_pure_size;
>  extern grub_size_t grub_multiboot_alloc_mbi;
>  extern grub_uint32_t grub_multiboot_payload_eip;
> diff --git a/include/multiboot2.h b/include/multiboot2.h
> index 9f97ddc..941a95d 100644
> --- a/include/multiboot2.h
> +++ b/include/multiboot2.h
> @@ -62,6 +62,7 @@
>  #define MULTIBOOT_TAG_TYPE_EFI_BS            18
>  #define MULTIBOOT_TAG_TYPE_EFI32_IH          19
>  #define MULTIBOOT_TAG_TYPE_EFI64_IH          20
> +#define MULTIBOOT_TAG_TYPE_BASE_ADDR         21
>  
>  #define MULTIBOOT_HEADER_TAG_END  0
>  #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
> @@ -72,11 +73,16 @@
>  #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
>  #define MULTIBOOT_HEADER_TAG_EFI_BS  7
>  #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
> +#define MULTIBOOT_HEADER_TAG_RELOCATABLE  10
>  
>  #define MULTIBOOT_ARCHITECTURE_I386  0
>  #define MULTIBOOT_ARCHITECTURE_MIPS32  4
>  #define MULTIBOOT_HEADER_TAG_OPTIONAL 1
>  
> +#define MULTIBOOT_LOAD_PREFERENCE_NONE 0
> +#define MULTIBOOT_LOAD_PREFERENCE_LOW 1
> +#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2
> +
>  #define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
>  #define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
>  
> @@ -169,6 +175,17 @@ struct multiboot_header_tag_module_align
>    multiboot_uint32_t size;
>  };
>  
> +struct multiboot_header_tag_relocatable
> +{
> +  multiboot_uint16_t type;
> +  multiboot_uint16_t flags;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t min_addr;
> +  multiboot_uint32_t max_addr;
> +  multiboot_uint32_t align;
> +  multiboot_uint32_t preference;
> +};
> +
>  struct multiboot_color
>  {
>    multiboot_uint8_t red;
> @@ -395,6 +412,13 @@ struct multiboot_tag_efi64_ih
>    multiboot_uint64_t pointer;
>  };
>  
> +struct multiboot_tag_base_addr
> +{
> +  multiboot_uint32_t type;
> +  multiboot_uint32_t size;
> +  multiboot_uint32_t base_addr;
> +};
> +
>  #endif /* ! ASM_FILE */
>  
>  #endif /* ! MULTIBOOT_HEADER */
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-11-09 15:39           ` Daniel Kiper
@ 2015-11-09 20:22             ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-09 20:22             ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-09 20:22 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, keir, Ian Campbell, stefano.stabellini,
	andrew.cooper3, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei


[-- Attachment #1.1: Type: text/plain, Size: 1801 bytes --]

On 09.11.2015 16:39, Daniel Kiper wrote:
> On Mon, Nov 09, 2015 at 04:34:20PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
>> On 09.11.2015 16:29, Daniel Kiper wrote:
>>> On Wed, Nov 04, 2015 at 01:03:56PM +0100, Vladimir 'phcoder' Serbinenko wrote:
>>>> Le 12 août 2015 11:04 AM, "Ian Campbell" <ian.campbell@citrix.com> a écrit :
>>>>>
>>>>>
>>>>> (Having written the below I see too late that this is a grub patch not a
>>>>> Xen one, a tag in the subject for such cross posted patches would be
>>>> useful
>>>>> please. Anyway, my opinion counts for very little in this context but I
>>>>> leave it below since already I wrote it. I notice that xen.git#.gitignore
>>>>> _does_ list *.rej, which I think is wrong...)
>>>>>
>>>>> On Mon, 2015-07-20 at 16:35 +0200, Daniel Kiper wrote:
>>>>>> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
>>>>>
>>>>> At least *.rej and perhaps *.orig are indicative of a failed patch
>>>>> application, I think I want them to appear in "git status".
>>>>>
>>>>> By way of comparison Linux's .gitignore includes *.orig but not *.rej and
>>>>> Qemu's includes neither.
>>>>>
>>>>> So nack to the addition of *.rej from me. I'm more or less ambivalent
>>>> about
>>>>> *.orig.
>>>>>
>>>> I have to agree. You should clean up *.rej *.orig after fixing conflicts
>>>
>>> Thanks for comment on this. Could you review rest of this patchset?
>>> I am working on v3 and it will be nice to take your (and others if
>>> possible) comments into it.
>>>
>> I will go through them today
> 
> Thanks a lot!
> 
All reviewed. Some of them already good but they have dependencies. Feel
free to either fix concerns with dependencies or rebase in a way to get
the good ones committed first in a meaningful way
> Daniel
> 



[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
  2015-11-09 15:39           ` Daniel Kiper
  2015-11-09 20:22             ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-11-09 20:22             ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-09 20:22 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, keir, Ian Campbell, stefano.stabellini,
	andrew.cooper3, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

[-- Attachment #1: Type: text/plain, Size: 1801 bytes --]

On 09.11.2015 16:39, Daniel Kiper wrote:
> On Mon, Nov 09, 2015 at 04:34:20PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
>> On 09.11.2015 16:29, Daniel Kiper wrote:
>>> On Wed, Nov 04, 2015 at 01:03:56PM +0100, Vladimir 'phcoder' Serbinenko wrote:
>>>> Le 12 août 2015 11:04 AM, "Ian Campbell" <ian.campbell@citrix.com> a écrit :
>>>>>
>>>>>
>>>>> (Having written the below I see too late that this is a grub patch not a
>>>>> Xen one, a tag in the subject for such cross posted patches would be
>>>> useful
>>>>> please. Anyway, my opinion counts for very little in this context but I
>>>>> leave it below since already I wrote it. I notice that xen.git#.gitignore
>>>>> _does_ list *.rej, which I think is wrong...)
>>>>>
>>>>> On Mon, 2015-07-20 at 16:35 +0200, Daniel Kiper wrote:
>>>>>> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
>>>>>
>>>>> At least *.rej and perhaps *.orig are indicative of a failed patch
>>>>> application, I think I want them to appear in "git status".
>>>>>
>>>>> By way of comparison Linux's .gitignore includes *.orig but not *.rej and
>>>>> Qemu's includes neither.
>>>>>
>>>>> So nack to the addition of *.rej from me. I'm more or less ambivalent
>>>> about
>>>>> *.orig.
>>>>>
>>>> I have to agree. You should clean up *.rej *.orig after fixing conflicts
>>>
>>> Thanks for comment on this. Could you review rest of this patchset?
>>> I am working on v3 and it will be nice to take your (and others if
>>> possible) comments into it.
>>>
>> I will go through them today
> 
> Thanks a lot!
> 
All reviewed. Some of them already good but they have dependencies. Feel
free to either fix concerns with dependencies or rebase in a way to get
the good ones committed first in a meaningful way
> Daniel
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
  2015-11-09 20:05   ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-11-10 14:38       ` Daniel Kiper
  0 siblings, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-11-10 14:38 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: jgross, grub-devel, keir, ian.campbell, andrew.cooper3,
	stefano.stabellini, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

On Mon, Nov 09, 2015 at 09:05:15PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 20.07.2015 16:35, Daniel Kiper wrote:
> > Add grub_relocator64_efi relocator. It will be used on EFI 64-bit platforms
> > when multiboot2 compatible image requests MULTIBOOT_TAG_TYPE_EFI_BS. Relocator
> > will set lower parts of %rax and %rbx accordingly to multiboot2 specification.
> > On the other hand processor mode, just before jumping into loaded image, will
> > be set accordingly to Unified Extensible Firmware Interface Specification,
> > Version 2.4 Errata B, section 2.3.4, x64 Platforms, boot services. This way
> > loaded image will be able to use EFI boot services without any issues.
> >
> > If idea is accepted I will prepare grub_relocator32_efi relocator too.
> >
> > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> > ---
> >  grub-core/Makefile.core.def          |    1 +
> >  grub-core/lib/i386/relocator.c       |   53 +++++++++++++++++++++++
> >  grub-core/lib/i386/relocator64_efi.S |   77 ++++++++++++++++++++++++++++++++++
> >  grub-core/loader/multiboot.c         |   29 +++++++++++--
> >  grub-core/loader/multiboot_mbi2.c    |   19 +++++++--
> >  include/grub/i386/multiboot.h        |   11 +++++
> >  include/grub/i386/relocator.h        |   21 ++++++++++
> >  include/multiboot2.h                 |    9 ++++
> >  8 files changed, 213 insertions(+), 7 deletions(-)
> >  create mode 100644 grub-core/lib/i386/relocator64_efi.S
> >
> > diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> > index a6101de..d583549 100644
> > --- a/grub-core/Makefile.core.def
> > +++ b/grub-core/Makefile.core.def
> > @@ -1519,6 +1519,7 @@ module = {
> >    x86 = lib/i386/relocator_common_c.c;
> >    ieee1275 = lib/ieee1275/relocator.c;
> >    efi = lib/efi/relocator.c;
> > +  x86_64_efi = lib/i386/relocator64_efi.S;
> >    mips = lib/mips/relocator_asm.S;
> >    mips = lib/mips/relocator.c;
> >    powerpc = lib/powerpc/relocator_asm.S;
> > diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c
> > index 71dd4f0..459027e 100644
> > --- a/grub-core/lib/i386/relocator.c
> > +++ b/grub-core/lib/i386/relocator.c
> > @@ -69,6 +69,19 @@ extern grub_uint64_t grub_relocator64_rsi;
> >  extern grub_addr_t grub_relocator64_cr3;
> >  extern struct grub_i386_idt grub_relocator16_idt;
> >
> > +#ifdef GRUB_MACHINE_EFI
> > +#ifdef __x86_64__
> > +extern grub_uint8_t grub_relocator64_efi_start;
> > +extern grub_uint8_t grub_relocator64_efi_end;
> > +extern grub_uint64_t grub_relocator64_efi_rax;
> > +extern grub_uint64_t grub_relocator64_efi_rbx;
> > +extern grub_uint64_t grub_relocator64_efi_rcx;
> > +extern grub_uint64_t grub_relocator64_efi_rdx;
> > +extern grub_uint64_t grub_relocator64_efi_rip;
> > +extern grub_uint64_t grub_relocator64_efi_rsi;
> > +#endif
> > +#endif
> > +
> >  #define RELOCATOR_SIZEOF(x)	(&grub_relocator##x##_end - &grub_relocator##x##_start)
> >
> >  grub_err_t
> > @@ -214,3 +227,43 @@ grub_relocator64_boot (struct grub_relocator *rel,
> >    /* Not reached.  */
> >    return GRUB_ERR_NONE;
> >  }
> > +
> > +#ifdef GRUB_MACHINE_EFI
> > +#ifdef __x86_64__
> > +grub_err_t
> > +grub_relocator64_efi_boot (struct grub_relocator *rel,
> > +			   struct grub_relocator64_efi_state state)
> > +{
> > +  grub_err_t err;
> > +  void *relst;
> > +  grub_relocator_chunk_t ch;
> > +
> > +  err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
> > +					  0x40000000 - RELOCATOR_SIZEOF (64_efi),
> > +					  RELOCATOR_SIZEOF (64_efi), 16,
> > +					  GRUB_RELOCATOR_PREFERENCE_NONE, 1);
> > +  if (err)
> > +    return err;
> > +
> > +  grub_relocator64_efi_rax = state.rax;
> > +  grub_relocator64_efi_rbx = state.rbx;
> > +  grub_relocator64_efi_rcx = state.rcx;
> > +  grub_relocator64_efi_rdx = state.rdx;
> > +  grub_relocator64_efi_rip = state.rip;
> > +  grub_relocator64_efi_rsi = state.rsi;
> > +
> > +  grub_memmove (get_virtual_current_address (ch), &grub_relocator64_efi_start,
> > +		RELOCATOR_SIZEOF (64_efi));
> > +
> > +  err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch),
> > +				       &relst, NULL);
> > +  if (err)
> > +    return err;
> > +
> > +  ((void (*) (void)) relst) ();
> > +
> > +  /* Not reached.  */
> > +  return GRUB_ERR_NONE;
> > +}
> > +#endif
> > +#endif
> > diff --git a/grub-core/lib/i386/relocator64_efi.S b/grub-core/lib/i386/relocator64_efi.S
> > new file mode 100644
> > index 0000000..fcd1964
> > --- /dev/null
> > +++ b/grub-core/lib/i386/relocator64_efi.S
> > @@ -0,0 +1,77 @@
> > +/*
> > + *  GRUB  --  GRand Unified Bootloader
> > + *  Copyright (C) 2009,2010  Free Software Foundation, Inc.
> > + *  Copyright (C) 2014,2015  Oracle Co.
> > + *      Author: Daniel Kiper
> > + *
> > + *  GRUB 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 3 of the License, or
> > + *  (at your option) any later version.
> > + *
> > + *  GRUB 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 GRUB.  If not, see <http://www.gnu.org/licenses/>.
> > + */
> > +
> > +#include "relocator_common.S"
> > +
> > +	.p2align	4	/* force 16-byte alignment */
> > +
> > +VARIABLE(grub_relocator64_efi_start)
> > +	PREAMBLE
> > +
> > +	.code64
> > +
> > +	/* mov imm64, %rax */
> > +	.byte 	0x48
> > +	.byte	0xb8
> > +VARIABLE(grub_relocator64_efi_rsi)
> > +	.quad	0
> > +
> > +	movq	%rax, %rsi
> > +
> > +	/* mov imm64, %rax */
> > +	.byte 	0x48
> > +	.byte	0xb8
> > +VARIABLE(grub_relocator64_efi_rax)
> > +	.quad	0
> > +
> > +	/* mov imm64, %rbx */
> > +	.byte 	0x48
> > +	.byte	0xbb
> > +VARIABLE(grub_relocator64_efi_rbx)
> > +	.quad	0
> > +
> > +	/* mov imm64, %rcx */
> > +	.byte 	0x48
> > +	.byte	0xb9
> > +VARIABLE(grub_relocator64_efi_rcx)
> > +	.quad	0
> > +
> > +	/* mov imm64, %rdx */
> > +	.byte 	0x48
> > +	.byte	0xba
> > +VARIABLE(grub_relocator64_efi_rdx)
> > +	.quad	0
> > +
> > +	/* Cleared direction flag is of no problem with any current
> > +	   payload and makes this implementation easier.  */
> > +	cld
> > +
> > +#ifdef __APPLE__
> > +	.byte 0xff, 0x25
> > +	.quad 0
> > +#else
> > +	jmp *LOCAL(jump_addr) (%rip)
> > +#endif
> > +
> > +LOCAL(jump_addr):
> > +VARIABLE(grub_relocator64_efi_rip)
> > +	.quad	0
> > +
> This repeats relocator64 almost exactly. Can we avoid code duplication?
> It's fine to compile it twice but code duplication is bad.

I will try to do that.

> > +VARIABLE(grub_relocator64_efi_end)
> > diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
> > index fd8f28e..ca7154f 100644
> > --- a/grub-core/loader/multiboot.c
> > +++ b/grub-core/loader/multiboot.c
> > @@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)
> >    return err;
> >  }
> >
> > +#ifdef GRUB_MACHINE_EFI
> > +#ifdef __x86_64__
> > +#define grub_relocator_efi_boot	grub_relocator64_efi_boot
> > +#endif
> > +#endif
> > +
> >  static grub_err_t
> >  grub_multiboot_boot (void)
> >  {
> >    grub_err_t err;
> > +  grub_uint32_t target;
> >    struct grub_relocator32_state state = MULTIBOOT_INITIAL_STATE;
> > +#ifdef GRUB_MACHINE_EFI
> > +#ifdef __x86_64__
> > +  struct grub_relocator64_efi_state state_efi = MULTIBOOT_EFI_INITIAL_STATE;
> > +#endif
> > +#endif
> >
> > -  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
> > -
> > -  err = grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER);
> > +  err = grub_multiboot_make_mbi (&target);
> >
> >    if (err)
> >      return err;
> >
> > +  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
> > +  state.MULTIBOOT_MBI_REGISTER = target;
> > +
> >  #if defined (__i386__) || defined (__x86_64__)
> > +#ifdef GRUB_MACHINE_EFI
> > +  state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip;
> > +  state_efi.MULTIBOOT_EFI_MBI_REGISTER = target;
> > +
> > +  if (grub_efi_is_finished)
> > +    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
> > +  else
> > +    grub_relocator_efi_boot (grub_multiboot_relocator, state_efi);
> > +#else
> >    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
> > +#endif
> >  #else
> >    grub_relocator32_boot (grub_multiboot_relocator, state);
> >  #endif
> This becomes hairy. I think it's time to split it into platform-specific
> functions and/or use tricks like
> #ifndef GRUB_MACHINE_EFI
> #define grub_efi_is_finished 0
> #endif

OK.

> > diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> > index d7c19bc..8d66e3f 100644
> > --- a/grub-core/loader/multiboot_mbi2.c
> > +++ b/grub-core/loader/multiboot_mbi2.c
> > @@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
> >    grub_err_t err;
> >    struct multiboot_header_tag *tag;
> >    struct multiboot_header_tag_address *addr_tag = NULL;
> > -  int entry_specified = 0;
> > -  grub_addr_t entry = 0;
> > +  int entry_specified = 0, efi_entry_specified = 0;
> > +  grub_addr_t entry = 0, efi_entry = 0;
> >    grub_uint32_t console_required = 0;
> >    struct multiboot_header_tag_framebuffer *fbtag = NULL;
> >    int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
> > @@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
> >  	entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;
> >  	break;
> >
> > +      case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64:
> > +#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__)
> > +	efi_entry_specified = 1;
> > +	efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr;
> > +#endif
> > +	break;
> > +
> Why do we need separate handling of EFI entry point? Why can't we use
> the same structure?

Make sense.

> >        case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS:
> >  	if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags
> >  	    & MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED))
> > @@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
> >  	break;
> >
> >        case MULTIBOOT_HEADER_TAG_EFI_BS:
> > +#ifdef GRUB_MACHINE_EFI
> >  	keep_bs = 1;
> > +#endif
> >  	break;
> >
> >        default:
> > @@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
> >  	break;
> >        }
> >
> > -  if (addr_tag && !entry_specified)
> > +  if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified))
> >      {
> >        grub_free (buffer);
> >        return grub_error (GRUB_ERR_UNKNOWN_OS,
> > @@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
> >  	}
> >      }
> >
> > -  if (entry_specified)
> > +  if (keep_bs && efi_entry_specified)
> > +    grub_multiboot_payload_eip = efi_entry;
> > +  else if (entry_specified)
> >      grub_multiboot_payload_eip = entry;
> >
> This seems redundant.

What is wrong here?

Daniel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
@ 2015-11-10 14:38       ` Daniel Kiper
  0 siblings, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-11-10 14:38 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: jgross, grub-devel, keir, ian.campbell, andrew.cooper3,
	stefano.stabellini, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

On Mon, Nov 09, 2015 at 09:05:15PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 20.07.2015 16:35, Daniel Kiper wrote:
> > Add grub_relocator64_efi relocator. It will be used on EFI 64-bit platforms
> > when multiboot2 compatible image requests MULTIBOOT_TAG_TYPE_EFI_BS. Relocator
> > will set lower parts of %rax and %rbx accordingly to multiboot2 specification.
> > On the other hand processor mode, just before jumping into loaded image, will
> > be set accordingly to Unified Extensible Firmware Interface Specification,
> > Version 2.4 Errata B, section 2.3.4, x64 Platforms, boot services. This way
> > loaded image will be able to use EFI boot services without any issues.
> >
> > If idea is accepted I will prepare grub_relocator32_efi relocator too.
> >
> > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> > ---
> >  grub-core/Makefile.core.def          |    1 +
> >  grub-core/lib/i386/relocator.c       |   53 +++++++++++++++++++++++
> >  grub-core/lib/i386/relocator64_efi.S |   77 ++++++++++++++++++++++++++++++++++
> >  grub-core/loader/multiboot.c         |   29 +++++++++++--
> >  grub-core/loader/multiboot_mbi2.c    |   19 +++++++--
> >  include/grub/i386/multiboot.h        |   11 +++++
> >  include/grub/i386/relocator.h        |   21 ++++++++++
> >  include/multiboot2.h                 |    9 ++++
> >  8 files changed, 213 insertions(+), 7 deletions(-)
> >  create mode 100644 grub-core/lib/i386/relocator64_efi.S
> >
> > diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> > index a6101de..d583549 100644
> > --- a/grub-core/Makefile.core.def
> > +++ b/grub-core/Makefile.core.def
> > @@ -1519,6 +1519,7 @@ module = {
> >    x86 = lib/i386/relocator_common_c.c;
> >    ieee1275 = lib/ieee1275/relocator.c;
> >    efi = lib/efi/relocator.c;
> > +  x86_64_efi = lib/i386/relocator64_efi.S;
> >    mips = lib/mips/relocator_asm.S;
> >    mips = lib/mips/relocator.c;
> >    powerpc = lib/powerpc/relocator_asm.S;
> > diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c
> > index 71dd4f0..459027e 100644
> > --- a/grub-core/lib/i386/relocator.c
> > +++ b/grub-core/lib/i386/relocator.c
> > @@ -69,6 +69,19 @@ extern grub_uint64_t grub_relocator64_rsi;
> >  extern grub_addr_t grub_relocator64_cr3;
> >  extern struct grub_i386_idt grub_relocator16_idt;
> >
> > +#ifdef GRUB_MACHINE_EFI
> > +#ifdef __x86_64__
> > +extern grub_uint8_t grub_relocator64_efi_start;
> > +extern grub_uint8_t grub_relocator64_efi_end;
> > +extern grub_uint64_t grub_relocator64_efi_rax;
> > +extern grub_uint64_t grub_relocator64_efi_rbx;
> > +extern grub_uint64_t grub_relocator64_efi_rcx;
> > +extern grub_uint64_t grub_relocator64_efi_rdx;
> > +extern grub_uint64_t grub_relocator64_efi_rip;
> > +extern grub_uint64_t grub_relocator64_efi_rsi;
> > +#endif
> > +#endif
> > +
> >  #define RELOCATOR_SIZEOF(x)	(&grub_relocator##x##_end - &grub_relocator##x##_start)
> >
> >  grub_err_t
> > @@ -214,3 +227,43 @@ grub_relocator64_boot (struct grub_relocator *rel,
> >    /* Not reached.  */
> >    return GRUB_ERR_NONE;
> >  }
> > +
> > +#ifdef GRUB_MACHINE_EFI
> > +#ifdef __x86_64__
> > +grub_err_t
> > +grub_relocator64_efi_boot (struct grub_relocator *rel,
> > +			   struct grub_relocator64_efi_state state)
> > +{
> > +  grub_err_t err;
> > +  void *relst;
> > +  grub_relocator_chunk_t ch;
> > +
> > +  err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
> > +					  0x40000000 - RELOCATOR_SIZEOF (64_efi),
> > +					  RELOCATOR_SIZEOF (64_efi), 16,
> > +					  GRUB_RELOCATOR_PREFERENCE_NONE, 1);
> > +  if (err)
> > +    return err;
> > +
> > +  grub_relocator64_efi_rax = state.rax;
> > +  grub_relocator64_efi_rbx = state.rbx;
> > +  grub_relocator64_efi_rcx = state.rcx;
> > +  grub_relocator64_efi_rdx = state.rdx;
> > +  grub_relocator64_efi_rip = state.rip;
> > +  grub_relocator64_efi_rsi = state.rsi;
> > +
> > +  grub_memmove (get_virtual_current_address (ch), &grub_relocator64_efi_start,
> > +		RELOCATOR_SIZEOF (64_efi));
> > +
> > +  err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch),
> > +				       &relst, NULL);
> > +  if (err)
> > +    return err;
> > +
> > +  ((void (*) (void)) relst) ();
> > +
> > +  /* Not reached.  */
> > +  return GRUB_ERR_NONE;
> > +}
> > +#endif
> > +#endif
> > diff --git a/grub-core/lib/i386/relocator64_efi.S b/grub-core/lib/i386/relocator64_efi.S
> > new file mode 100644
> > index 0000000..fcd1964
> > --- /dev/null
> > +++ b/grub-core/lib/i386/relocator64_efi.S
> > @@ -0,0 +1,77 @@
> > +/*
> > + *  GRUB  --  GRand Unified Bootloader
> > + *  Copyright (C) 2009,2010  Free Software Foundation, Inc.
> > + *  Copyright (C) 2014,2015  Oracle Co.
> > + *      Author: Daniel Kiper
> > + *
> > + *  GRUB 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 3 of the License, or
> > + *  (at your option) any later version.
> > + *
> > + *  GRUB 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 GRUB.  If not, see <http://www.gnu.org/licenses/>.
> > + */
> > +
> > +#include "relocator_common.S"
> > +
> > +	.p2align	4	/* force 16-byte alignment */
> > +
> > +VARIABLE(grub_relocator64_efi_start)
> > +	PREAMBLE
> > +
> > +	.code64
> > +
> > +	/* mov imm64, %rax */
> > +	.byte 	0x48
> > +	.byte	0xb8
> > +VARIABLE(grub_relocator64_efi_rsi)
> > +	.quad	0
> > +
> > +	movq	%rax, %rsi
> > +
> > +	/* mov imm64, %rax */
> > +	.byte 	0x48
> > +	.byte	0xb8
> > +VARIABLE(grub_relocator64_efi_rax)
> > +	.quad	0
> > +
> > +	/* mov imm64, %rbx */
> > +	.byte 	0x48
> > +	.byte	0xbb
> > +VARIABLE(grub_relocator64_efi_rbx)
> > +	.quad	0
> > +
> > +	/* mov imm64, %rcx */
> > +	.byte 	0x48
> > +	.byte	0xb9
> > +VARIABLE(grub_relocator64_efi_rcx)
> > +	.quad	0
> > +
> > +	/* mov imm64, %rdx */
> > +	.byte 	0x48
> > +	.byte	0xba
> > +VARIABLE(grub_relocator64_efi_rdx)
> > +	.quad	0
> > +
> > +	/* Cleared direction flag is of no problem with any current
> > +	   payload and makes this implementation easier.  */
> > +	cld
> > +
> > +#ifdef __APPLE__
> > +	.byte 0xff, 0x25
> > +	.quad 0
> > +#else
> > +	jmp *LOCAL(jump_addr) (%rip)
> > +#endif
> > +
> > +LOCAL(jump_addr):
> > +VARIABLE(grub_relocator64_efi_rip)
> > +	.quad	0
> > +
> This repeats relocator64 almost exactly. Can we avoid code duplication?
> It's fine to compile it twice but code duplication is bad.

I will try to do that.

> > +VARIABLE(grub_relocator64_efi_end)
> > diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
> > index fd8f28e..ca7154f 100644
> > --- a/grub-core/loader/multiboot.c
> > +++ b/grub-core/loader/multiboot.c
> > @@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)
> >    return err;
> >  }
> >
> > +#ifdef GRUB_MACHINE_EFI
> > +#ifdef __x86_64__
> > +#define grub_relocator_efi_boot	grub_relocator64_efi_boot
> > +#endif
> > +#endif
> > +
> >  static grub_err_t
> >  grub_multiboot_boot (void)
> >  {
> >    grub_err_t err;
> > +  grub_uint32_t target;
> >    struct grub_relocator32_state state = MULTIBOOT_INITIAL_STATE;
> > +#ifdef GRUB_MACHINE_EFI
> > +#ifdef __x86_64__
> > +  struct grub_relocator64_efi_state state_efi = MULTIBOOT_EFI_INITIAL_STATE;
> > +#endif
> > +#endif
> >
> > -  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
> > -
> > -  err = grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER);
> > +  err = grub_multiboot_make_mbi (&target);
> >
> >    if (err)
> >      return err;
> >
> > +  state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
> > +  state.MULTIBOOT_MBI_REGISTER = target;
> > +
> >  #if defined (__i386__) || defined (__x86_64__)
> > +#ifdef GRUB_MACHINE_EFI
> > +  state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip;
> > +  state_efi.MULTIBOOT_EFI_MBI_REGISTER = target;
> > +
> > +  if (grub_efi_is_finished)
> > +    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
> > +  else
> > +    grub_relocator_efi_boot (grub_multiboot_relocator, state_efi);
> > +#else
> >    grub_relocator32_boot (grub_multiboot_relocator, state, 0);
> > +#endif
> >  #else
> >    grub_relocator32_boot (grub_multiboot_relocator, state);
> >  #endif
> This becomes hairy. I think it's time to split it into platform-specific
> functions and/or use tricks like
> #ifndef GRUB_MACHINE_EFI
> #define grub_efi_is_finished 0
> #endif

OK.

> > diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
> > index d7c19bc..8d66e3f 100644
> > --- a/grub-core/loader/multiboot_mbi2.c
> > +++ b/grub-core/loader/multiboot_mbi2.c
> > @@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
> >    grub_err_t err;
> >    struct multiboot_header_tag *tag;
> >    struct multiboot_header_tag_address *addr_tag = NULL;
> > -  int entry_specified = 0;
> > -  grub_addr_t entry = 0;
> > +  int entry_specified = 0, efi_entry_specified = 0;
> > +  grub_addr_t entry = 0, efi_entry = 0;
> >    grub_uint32_t console_required = 0;
> >    struct multiboot_header_tag_framebuffer *fbtag = NULL;
> >    int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
> > @@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)
> >  	entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;
> >  	break;
> >
> > +      case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64:
> > +#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__)
> > +	efi_entry_specified = 1;
> > +	efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr;
> > +#endif
> > +	break;
> > +
> Why do we need separate handling of EFI entry point? Why can't we use
> the same structure?

Make sense.

> >        case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS:
> >  	if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags
> >  	    & MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED))
> > @@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
> >  	break;
> >
> >        case MULTIBOOT_HEADER_TAG_EFI_BS:
> > +#ifdef GRUB_MACHINE_EFI
> >  	keep_bs = 1;
> > +#endif
> >  	break;
> >
> >        default:
> > @@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
> >  	break;
> >        }
> >
> > -  if (addr_tag && !entry_specified)
> > +  if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified))
> >      {
> >        grub_free (buffer);
> >        return grub_error (GRUB_ERR_UNKNOWN_OS,
> > @@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)
> >  	}
> >      }
> >
> > -  if (entry_specified)
> > +  if (keep_bs && efi_entry_specified)
> > +    grub_multiboot_payload_eip = efi_entry;
> > +  else if (entry_specified)
> >      grub_multiboot_payload_eip = entry;
> >
> This seems redundant.

What is wrong here?

Daniel


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
  2015-11-09 20:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-11-10 14:52       ` Daniel Kiper
  0 siblings, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-11-10 14:52 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: jgross, grub-devel, keir, ian.campbell, andrew.cooper3,
	stefano.stabellini, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

On Mon, Nov 09, 2015 at 09:08:35PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 20.07.2015 16:35, Daniel Kiper wrote:
> > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> What is handling the actual relocation?

In Xen we get image offset from GRUB2 and using this value we calculate
relative addresses. We are using %fs for it.

> Why doesn't this patch include support for ELF relocations?

This is another option. We considered it too. However, in our case
relative addressing looks simpler then ELF relocations. However, if
you wish I can add this functionality when this patch series is
included in upstream GRUB2. Is it OK for you?

Daniel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
@ 2015-11-10 14:52       ` Daniel Kiper
  0 siblings, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-11-10 14:52 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: jgross, grub-devel, keir, ian.campbell, andrew.cooper3,
	stefano.stabellini, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

On Mon, Nov 09, 2015 at 09:08:35PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 20.07.2015 16:35, Daniel Kiper wrote:
> > Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> What is handling the actual relocation?

In Xen we get image offset from GRUB2 and using this value we calculate
relative addresses. We are using %fs for it.

> Why doesn't this patch include support for ELF relocations?

This is another option. We considered it too. However, in our case
relative addressing looks simpler then ELF relocations. However, if
you wish I can add this functionality when this patch series is
included in upstream GRUB2. Is it OK for you?

Daniel


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
       [not found]         ` <20151112131555.GW26902@olila.local.net-space.pl>
@ 2015-11-12 13:26           ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-12 13:26           ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-12 13:26 UTC (permalink / raw)
  To: Daniel Kiper, The development of GRUB 2, xen-devel


[-- Attachment #1.1: Type: text/plain, Size: 2007 bytes --]

On 12.11.2015 14:15, Daniel Kiper wrote:
> On Tue, Nov 10, 2015 at 04:23:46PM +0100, Vladimir 'phcoder' Serbinenko wrote:
>> Le 10 nov. 2015 3:52 PM, "Daniel Kiper" <daniel.kiper@oracle.com> a écrit :
>>> On Mon, Nov 09, 2015 at 09:08:35PM +0100, Vladimir 'φ-coder/phcoder'
>> Serbinenko wrote:
>>>> On 20.07.2015 16:35, Daniel Kiper wrote:
>>>>> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
>>>> What is handling the actual relocation?
>>>
>>> In Xen we get image offset from GRUB2 and using this value we calculate
>>> relative addresses. We are using %fs for it.
>>>
>>>> Why doesn't this patch include support for ELF relocations?
>>>
>>> This is another option. We considered it too. However, in our case
>>> relative addressing looks simpler then ELF relocations.
>> How is it simpler than to have a fully relocated binary when you start?
> 
> Xen ELF file does not have relocations.
> 
>> How do you pass the offset?
> 
> Via MULTIBOOT_TAG_TYPE_BASE_ADDR tag.
> 
>> Does xen have any relocation entries?
> 
> No.
> 
Can we then settle on using your interface but saying that bootloader
has to execute all ELF relocations? Since you don't have them, you
wouldn't be affected by the change but it would allow easy creation of
relocatable binaries. Feel free in the first patch just to have a check
for absence of relocation entries. x86-64 has only about 5 relocations
we care about so should be easy to implement. We can reuse code in dl.c.
>> Was such xen already released? Just looking for how it should
>> be in perspective and how to get there
> 
> We agreed (in Xen community) that we would like to have multiboot2 protocol
> with additional features set in stone at first. So, this patch series just
> propose some changes which are required by Xen but they are not used by any
> Xen release yet. Additionally, we want that these extensions are quite generic
> and could be used by other projects if they need them too.
> 
> Daniel
> 



[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
       [not found]         ` <20151112131555.GW26902@olila.local.net-space.pl>
  2015-11-12 13:26           ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-11-12 13:26           ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-12 13:33             ` Daniel Kiper
  2015-11-12 13:33             ` Daniel Kiper
  1 sibling, 2 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-12 13:26 UTC (permalink / raw)
  To: Daniel Kiper, The development of GRUB 2, xen-devel

[-- Attachment #1: Type: text/plain, Size: 2007 bytes --]

On 12.11.2015 14:15, Daniel Kiper wrote:
> On Tue, Nov 10, 2015 at 04:23:46PM +0100, Vladimir 'phcoder' Serbinenko wrote:
>> Le 10 nov. 2015 3:52 PM, "Daniel Kiper" <daniel.kiper@oracle.com> a écrit :
>>> On Mon, Nov 09, 2015 at 09:08:35PM +0100, Vladimir 'φ-coder/phcoder'
>> Serbinenko wrote:
>>>> On 20.07.2015 16:35, Daniel Kiper wrote:
>>>>> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
>>>> What is handling the actual relocation?
>>>
>>> In Xen we get image offset from GRUB2 and using this value we calculate
>>> relative addresses. We are using %fs for it.
>>>
>>>> Why doesn't this patch include support for ELF relocations?
>>>
>>> This is another option. We considered it too. However, in our case
>>> relative addressing looks simpler then ELF relocations.
>> How is it simpler than to have a fully relocated binary when you start?
> 
> Xen ELF file does not have relocations.
> 
>> How do you pass the offset?
> 
> Via MULTIBOOT_TAG_TYPE_BASE_ADDR tag.
> 
>> Does xen have any relocation entries?
> 
> No.
> 
Can we then settle on using your interface but saying that bootloader
has to execute all ELF relocations? Since you don't have them, you
wouldn't be affected by the change but it would allow easy creation of
relocatable binaries. Feel free in the first patch just to have a check
for absence of relocation entries. x86-64 has only about 5 relocations
we care about so should be easy to implement. We can reuse code in dl.c.
>> Was such xen already released? Just looking for how it should
>> be in perspective and how to get there
> 
> We agreed (in Xen community) that we would like to have multiboot2 protocol
> with additional features set in stone at first. So, this patch series just
> propose some changes which are required by Xen but they are not used by any
> Xen release yet. Additionally, we want that these extensions are quite generic
> and could be used by other projects if they need them too.
> 
> Daniel
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
  2015-11-12 13:26           ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-11-12 13:33             ` Daniel Kiper
@ 2015-11-12 13:33             ` Daniel Kiper
  1 sibling, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-11-12 13:33 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: The development of GRUB 2, xen-devel

On Thu, Nov 12, 2015 at 02:26:21PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 12.11.2015 14:15, Daniel Kiper wrote:
> > On Tue, Nov 10, 2015 at 04:23:46PM +0100, Vladimir 'phcoder' Serbinenko wrote:
> >> Le 10 nov. 2015 3:52 PM, "Daniel Kiper" <daniel.kiper@oracle.com> a écrit :
> >>> On Mon, Nov 09, 2015 at 09:08:35PM +0100, Vladimir 'φ-coder/phcoder'
> >> Serbinenko wrote:
> >>>> On 20.07.2015 16:35, Daniel Kiper wrote:
> >>>>> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> >>>> What is handling the actual relocation?
> >>>
> >>> In Xen we get image offset from GRUB2 and using this value we calculate
> >>> relative addresses. We are using %fs for it.
> >>>
> >>>> Why doesn't this patch include support for ELF relocations?
> >>>
> >>> This is another option. We considered it too. However, in our case
> >>> relative addressing looks simpler then ELF relocations.
> >> How is it simpler than to have a fully relocated binary when you start?
> >
> > Xen ELF file does not have relocations.
> >
> >> How do you pass the offset?
> >
> > Via MULTIBOOT_TAG_TYPE_BASE_ADDR tag.
> >
> >> Does xen have any relocation entries?
> >
> > No.
> >
> Can we then settle on using your interface but saying that bootloader
> has to execute all ELF relocations? Since you don't have them, you
> wouldn't be affected by the change but it would allow easy creation of
> relocatable binaries. Feel free in the first patch just to have a check
> for absence of relocation entries. x86-64 has only about 5 relocations
> we care about so should be easy to implement. We can reuse code in dl.c.

Granted!

Daniel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
  2015-11-12 13:26           ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-11-12 13:33             ` Daniel Kiper
  2015-11-12 13:33             ` Daniel Kiper
  1 sibling, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2015-11-12 13:33 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: The development of GRUB 2, xen-devel

On Thu, Nov 12, 2015 at 02:26:21PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 12.11.2015 14:15, Daniel Kiper wrote:
> > On Tue, Nov 10, 2015 at 04:23:46PM +0100, Vladimir 'phcoder' Serbinenko wrote:
> >> Le 10 nov. 2015 3:52 PM, "Daniel Kiper" <daniel.kiper@oracle.com> a écrit :
> >>> On Mon, Nov 09, 2015 at 09:08:35PM +0100, Vladimir 'φ-coder/phcoder'
> >> Serbinenko wrote:
> >>>> On 20.07.2015 16:35, Daniel Kiper wrote:
> >>>>> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> >>>> What is handling the actual relocation?
> >>>
> >>> In Xen we get image offset from GRUB2 and using this value we calculate
> >>> relative addresses. We are using %fs for it.
> >>>
> >>>> Why doesn't this patch include support for ELF relocations?
> >>>
> >>> This is another option. We considered it too. However, in our case
> >>> relative addressing looks simpler then ELF relocations.
> >> How is it simpler than to have a fully relocated binary when you start?
> >
> > Xen ELF file does not have relocations.
> >
> >> How do you pass the offset?
> >
> > Via MULTIBOOT_TAG_TYPE_BASE_ADDR tag.
> >
> >> Does xen have any relocation entries?
> >
> > No.
> >
> Can we then settle on using your interface but saying that bootloader
> has to execute all ELF relocations? Since you don't have them, you
> wouldn't be affected by the change but it would allow easy creation of
> relocatable binaries. Feel free in the first patch just to have a check
> for absence of relocation entries. x86-64 has only about 5 relocations
> we care about so should be easy to implement. We can reuse code in dl.c.

Granted!

Daniel


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
  2015-11-10 14:38       ` Daniel Kiper
  (?)
  (?)
@ 2015-11-12 13:45       ` Vladimir 'φ-coder/phcoder' Serbinenko
  -1 siblings, 0 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-12 13:45 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, keir, ian.campbell, andrew.cooper3,
	stefano.stabellini, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei


[-- Attachment #1.1: Type: text/plain, Size: 394 bytes --]

On 10.11.2015 15:38, Daniel Kiper wrote:
>>> -  if (entry_specified)
>>> > > +  if (keep_bs && efi_entry_specified)
>>> > > +    grub_multiboot_payload_eip = efi_entry;
>>> > > +  else if (entry_specified)
>>> > >      grub_multiboot_payload_eip = entry;
>>> > >
>> > This seems redundant.
> What is wrong here?
I just mean that if we use a single structure this code could go away


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
  2015-11-10 14:38       ` Daniel Kiper
  (?)
@ 2015-11-12 13:45       ` Vladimir 'φ-coder/phcoder' Serbinenko
  -1 siblings, 0 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-11-12 13:45 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, keir, ian.campbell, andrew.cooper3,
	stefano.stabellini, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

[-- Attachment #1: Type: text/plain, Size: 394 bytes --]

On 10.11.2015 15:38, Daniel Kiper wrote:
>>> -  if (entry_specified)
>>> > > +  if (keep_bs && efi_entry_specified)
>>> > > +    grub_multiboot_payload_eip = efi_entry;
>>> > > +  else if (entry_specified)
>>> > >      grub_multiboot_payload_eip = entry;
>>> > >
>> > This seems redundant.
> What is wrong here?
I just mean that if we use a single structure this code could go away


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2015-07-20 14:35 ` Daniel Kiper
                     ` (2 preceding siblings ...)
  2016-02-12 14:57   ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2016-02-12 14:57   ` Vladimir 'φ-coder/phcoder' Serbinenko
  3 siblings, 0 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2016-02-12 14:57 UTC (permalink / raw)
  To: Daniel Kiper, xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei


[-- Attachment #1.1: Type: text/plain, Size: 1533 bytes --]

Applied, thanks
On 20.07.2015 16:35, Daniel Kiper wrote:
> malloc_in_range() should not use memory region if its starta is smaller
> than size. Otherwise target wraps around and points to region which is
> usually not a RAM, e.g.:
> 
> loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000
> lib/relocator.c:1241: min_addr = 0x0, max_addr = 0xffffffffffffffff, target = 0x800000
> lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned 0x1 size 0x3f800000
> lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned 0x1 size 0x3f800000
> lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned 0x1 size 0x3f800000
> lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000
> lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000
> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/lib/relocator.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
> index f759c7f..4eee0c5 100644
> --- a/grub-core/lib/relocator.c
> +++ b/grub-core/lib/relocator.c
> @@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,
>  	      /* Found an usable address.  */
>  	      goto found;
>  	  }
> -	if (isinsidebefore && !isinsideafter && !from_low_priv)
> +	if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size)
>  	  {
>  	    target = starta - size;
>  	    if (target > end - size)
> 



[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2015-07-20 14:35 ` Daniel Kiper
  2015-07-21  6:42   ` Andrei Borzenkov
  2015-07-21  6:42   ` Andrei Borzenkov
@ 2016-02-12 14:57   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2016-02-12 19:01     ` Daniel Kiper
  2016-02-12 19:01     ` Daniel Kiper
  2016-02-12 14:57   ` Vladimir 'φ-coder/phcoder' Serbinenko
  3 siblings, 2 replies; 67+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2016-02-12 14:57 UTC (permalink / raw)
  To: Daniel Kiper, xen-devel, grub-devel
  Cc: jgross, keir, ian.campbell, andrew.cooper3, stefano.stabellini,
	roy.franz, ning.sun, david.vrabel, jbeulich, wei.liu2,
	qiaowei.ren, richard.l.maliszewski, gang.wei, fu.wei

[-- Attachment #1: Type: text/plain, Size: 1533 bytes --]

Applied, thanks
On 20.07.2015 16:35, Daniel Kiper wrote:
> malloc_in_range() should not use memory region if its starta is smaller
> than size. Otherwise target wraps around and points to region which is
> usually not a RAM, e.g.:
> 
> loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000
> lib/relocator.c:1241: min_addr = 0x0, max_addr = 0xffffffffffffffff, target = 0x800000
> lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned 0x1 size 0x3f800000
> lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned 0x1 size 0x3f800000
> lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned 0x1 size 0x3f800000
> lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000
> lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000
> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> ---
>  grub-core/lib/relocator.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
> index f759c7f..4eee0c5 100644
> --- a/grub-core/lib/relocator.c
> +++ b/grub-core/lib/relocator.c
> @@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,
>  	      /* Found an usable address.  */
>  	      goto found;
>  	  }
> -	if (isinsidebefore && !isinsideafter && !from_low_priv)
> +	if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size)
>  	  {
>  	    target = starta - size;
>  	    if (target > end - size)
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2016-02-12 14:57   ` Vladimir 'φ-coder/phcoder' Serbinenko
  2016-02-12 19:01     ` Daniel Kiper
@ 2016-02-12 19:01     ` Daniel Kiper
  1 sibling, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2016-02-12 19:01 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: jgross, grub-devel, keir, ian.campbell, andrew.cooper3,
	stefano.stabellini, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

On Fri, Feb 12, 2016 at 03:57:59PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> Applied, thanks

Thanks but here http://lists.gnu.org/archive/html/grub-devel/2015-07/msg00100.html
Andrei and later here http://lists.gnu.org/archive/html/grub-devel/2015-11/msg00110.html
you expressed concerns that patch is wrong and it should be fixed. Does anything have changed?

Daniel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2016-02-12 14:57   ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2016-02-12 19:01     ` Daniel Kiper
  2016-02-12 19:12       ` Vladimir 'phcoder' Serbinenko
  2016-02-12 19:12       ` Vladimir 'phcoder' Serbinenko
  2016-02-12 19:01     ` Daniel Kiper
  1 sibling, 2 replies; 67+ messages in thread
From: Daniel Kiper @ 2016-02-12 19:01 UTC (permalink / raw)
  To: Vladimir 'φ-coder/phcoder' Serbinenko
  Cc: jgross, grub-devel, keir, ian.campbell, andrew.cooper3,
	stefano.stabellini, roy.franz, ning.sun, david.vrabel, jbeulich,
	wei.liu2, xen-devel, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

On Fri, Feb 12, 2016 at 03:57:59PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> Applied, thanks

Thanks but here http://lists.gnu.org/archive/html/grub-devel/2015-07/msg00100.html
Andrei and later here http://lists.gnu.org/archive/html/grub-devel/2015-11/msg00110.html
you expressed concerns that patch is wrong and it should be fixed. Does anything have changed?

Daniel


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2016-02-12 19:01     ` Daniel Kiper
@ 2016-02-12 19:12       ` Vladimir 'phcoder' Serbinenko
  2016-02-12 19:12       ` Vladimir 'phcoder' Serbinenko
  1 sibling, 0 replies; 67+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2016-02-12 19:12 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, keir, ian.campbell, andrew.cooper3,
	stefano.stabellini, roy.franz, ning.sun, david.vrabel, jbeulich,
	xen-devel, wei.liu2, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei


[-- Attachment #1.1: Type: text/plain, Size: 556 bytes --]

Le ven. 12 févr. 2016 20:01, Daniel Kiper <daniel.kiper@oracle.com> a
écrit :

> On Fri, Feb 12, 2016 at 03:57:59PM +0100, Vladimir 'φ-coder/phcoder'
> Serbinenko wrote:
> > Applied, thanks
>
> Thanks but here
> http://lists.gnu.org/archive/html/grub-devel/2015-07/msg00100.html
> Andrei and later here
> http://lists.gnu.org/archive/html/grub-devel/2015-11/msg00110.html
> you expressed concerns that patch is wrong and it should be fixed. Does
> anything have changed?
>
>
> Daniel
>
Yes, I changed your patch before committing

>

[-- Attachment #1.2: Type: text/html, Size: 1179 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2016-02-12 19:01     ` Daniel Kiper
  2016-02-12 19:12       ` Vladimir 'phcoder' Serbinenko
@ 2016-02-12 19:12       ` Vladimir 'phcoder' Serbinenko
  2016-02-12 19:55         ` Daniel Kiper
  2016-02-12 19:55         ` Daniel Kiper
  1 sibling, 2 replies; 67+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2016-02-12 19:12 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: jgross, grub-devel, keir, ian.campbell, andrew.cooper3,
	stefano.stabellini, roy.franz, ning.sun, david.vrabel, jbeulich,
	xen-devel, wei.liu2, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

[-- Attachment #1: Type: text/plain, Size: 556 bytes --]

Le ven. 12 févr. 2016 20:01, Daniel Kiper <daniel.kiper@oracle.com> a
écrit :

> On Fri, Feb 12, 2016 at 03:57:59PM +0100, Vladimir 'φ-coder/phcoder'
> Serbinenko wrote:
> > Applied, thanks
>
> Thanks but here
> http://lists.gnu.org/archive/html/grub-devel/2015-07/msg00100.html
> Andrei and later here
> http://lists.gnu.org/archive/html/grub-devel/2015-11/msg00110.html
> you expressed concerns that patch is wrong and it should be fixed. Does
> anything have changed?
>
>
> Daniel
>
Yes, I changed your patch before committing

>

[-- Attachment #2: Type: text/html, Size: 1179 bytes --]

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2016-02-12 19:12       ` Vladimir 'phcoder' Serbinenko
  2016-02-12 19:55         ` Daniel Kiper
@ 2016-02-12 19:55         ` Daniel Kiper
  1 sibling, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2016-02-12 19:55 UTC (permalink / raw)
  To: Vladimir 'phcoder' Serbinenko
  Cc: jgross, grub-devel, keir, ian.campbell, andrew.cooper3,
	stefano.stabellini, roy.franz, ning.sun, david.vrabel, jbeulich,
	xen-devel, wei.liu2, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

On Fri, Feb 12, 2016 at 07:12:52PM +0000, Vladimir 'phcoder' Serbinenko wrote:
> Le ven. 12 févr. 2016 20:01, Daniel Kiper <daniel.kiper@oracle.com> a
> écrit :
>
> > On Fri, Feb 12, 2016 at 03:57:59PM +0100, Vladimir 'φ-coder/phcoder'
> > Serbinenko wrote:
> > > Applied, thanks
> >
> > Thanks but here
> > http://lists.gnu.org/archive/html/grub-devel/2015-07/msg00100.html
> > Andrei and later here
> > http://lists.gnu.org/archive/html/grub-devel/2015-11/msg00110.html
> > you expressed concerns that patch is wrong and it should be fixed. Does
> > anything have changed?
> >
> >
> > Daniel
> >
> Yes, I changed your patch before committing

Great! Thanks a lot!

Daniel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
  2016-02-12 19:12       ` Vladimir 'phcoder' Serbinenko
@ 2016-02-12 19:55         ` Daniel Kiper
  2016-02-12 19:55         ` Daniel Kiper
  1 sibling, 0 replies; 67+ messages in thread
From: Daniel Kiper @ 2016-02-12 19:55 UTC (permalink / raw)
  To: Vladimir 'phcoder' Serbinenko
  Cc: jgross, grub-devel, keir, ian.campbell, andrew.cooper3,
	stefano.stabellini, roy.franz, ning.sun, david.vrabel, jbeulich,
	xen-devel, wei.liu2, qiaowei.ren, richard.l.maliszewski,
	gang.wei, fu.wei

On Fri, Feb 12, 2016 at 07:12:52PM +0000, Vladimir 'phcoder' Serbinenko wrote:
> Le ven. 12 févr. 2016 20:01, Daniel Kiper <daniel.kiper@oracle.com> a
> écrit :
>
> > On Fri, Feb 12, 2016 at 03:57:59PM +0100, Vladimir 'φ-coder/phcoder'
> > Serbinenko wrote:
> > > Applied, thanks
> >
> > Thanks but here
> > http://lists.gnu.org/archive/html/grub-devel/2015-07/msg00100.html
> > Andrei and later here
> > http://lists.gnu.org/archive/html/grub-devel/2015-11/msg00110.html
> > you expressed concerns that patch is wrong and it should be fixed. Does
> > anything have changed?
> >
> >
> > Daniel
> >
> Yes, I changed your patch before committing

Great! Thanks a lot!

Daniel


^ permalink raw reply	[flat|nested] 67+ messages in thread

end of thread, other threads:[~2016-02-12 19:55 UTC | newest]

Thread overview: 67+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-20 14:35 [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
2015-07-20 14:35 ` [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files Daniel Kiper
2015-07-20 14:35 ` Daniel Kiper
2015-08-11 17:00   ` Konrad Rzeszutek Wilk
2015-08-11 17:00   ` Konrad Rzeszutek Wilk
2015-08-12  9:04   ` Ian Campbell
2015-11-04 12:03     ` Vladimir 'phcoder' Serbinenko
2015-11-09 15:29       ` Daniel Kiper
2015-11-09 15:34         ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-09 15:39           ` Daniel Kiper
2015-11-09 20:22             ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-09 20:22             ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-09 15:39           ` Daniel Kiper
2015-11-09 15:34         ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-09 15:29       ` Daniel Kiper
2015-11-04 12:03     ` Vladimir 'phcoder' Serbinenko
2015-08-12  9:04   ` Ian Campbell
2015-07-20 14:35 ` [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size Daniel Kiper
2015-07-20 14:35 ` Daniel Kiper
2015-07-21  6:42   ` Andrei Borzenkov
2015-07-21  6:42   ` Andrei Borzenkov
2015-11-09 18:44     ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-09 18:44     ` Vladimir 'φ-coder/phcoder' Serbinenko
2016-02-12 14:57   ` Vladimir 'φ-coder/phcoder' Serbinenko
2016-02-12 19:01     ` Daniel Kiper
2016-02-12 19:12       ` Vladimir 'phcoder' Serbinenko
2016-02-12 19:12       ` Vladimir 'phcoder' Serbinenko
2016-02-12 19:55         ` Daniel Kiper
2016-02-12 19:55         ` Daniel Kiper
2016-02-12 19:01     ` Daniel Kiper
2016-02-12 14:57   ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-07-20 14:35 ` [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator Daniel Kiper
2015-07-20 14:35 ` Daniel Kiper
2015-08-11 17:02   ` Konrad Rzeszutek Wilk
2015-08-11 17:02     ` Konrad Rzeszutek Wilk
2015-11-09 20:05   ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-10 14:38     ` Daniel Kiper
2015-11-10 14:38       ` Daniel Kiper
2015-11-12 13:45       ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-12 13:45       ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-09 20:05   ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-07-20 14:35 ` [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image Daniel Kiper
2015-07-20 14:35 ` Daniel Kiper
2015-08-11 18:38   ` Konrad Rzeszutek Wilk
2015-08-11 18:38   ` Konrad Rzeszutek Wilk
     [not found]     ` <CAEaD8JOPxLVECcUqjj2-x5AeXjbQ9Cd7bOaoe8UPU2t7wdoxpA@mail.gmail.com>
2015-11-09 19:12       ` Fwd: " Vladimir 'phcoder' Serbinenko
     [not found]   ` <CAEaD8JOaS=J22k+Sq=8Ou77pO6yvtgxSLiwuMjAoirSipJhW6g@mail.gmail.com>
2015-11-09 20:06     ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-07-20 14:35 ` [PATCH v2 5/6] multiboot2: Add support for relocatable images Daniel Kiper
2015-08-11 18:51   ` Konrad Rzeszutek Wilk
2015-08-11 18:51   ` Konrad Rzeszutek Wilk
2015-11-09 20:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-09 20:08   ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-10 14:52     ` Daniel Kiper
2015-11-10 14:52       ` Daniel Kiper
     [not found]       ` <CAEaD8JMUUnSd7MMTANouZ1oQvYA00c49V8ENgUGUY+K8HcE_+Q@mail.gmail.com>
     [not found]         ` <20151112131555.GW26902@olila.local.net-space.pl>
2015-11-12 13:26           ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-12 13:26           ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-12 13:33             ` Daniel Kiper
2015-11-12 13:33             ` Daniel Kiper
2015-07-20 14:35 ` Daniel Kiper
2015-07-20 14:35 ` [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled Daniel Kiper
2015-07-20 14:35 ` Daniel Kiper
2015-08-11 18:59   ` Konrad Rzeszutek Wilk
2015-08-18 12:29     ` Daniel Kiper
2015-08-18 12:29     ` Daniel Kiper
2015-08-11 18:59   ` Konrad Rzeszutek Wilk
2015-08-24 17:11 ` [PATCH v2 0/6] multiboot2: Add two extensions and fix some issues Daniel Kiper
2015-08-24 17:11 ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.