Skip to contentSkip to conversation

multiboot2: Add two extensions

PATCH Superseded Daniel Kiper 5 participants 43 messages Mar 15, 2016 – Mar 16, 2016

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover multiboot2: Add two extensions

Hi,

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

Earlier versions of this patch series are extensively tested and used internally at least in Oracle. It should be mentioned that this release does not change any functionality introduced by earlier releases. It just takes into account comments posted by various people.

Daniel

 grub-core/Makefile.core.def           |    1 +
 grub-core/lib/i386/relocator64.S      |   11 ++++
 grub-core/lib/x86_64/efi/relocator.c  |   76 ++++++++++++++++++++++++++
 grub-core/loader/i386/multiboot_mbi.c |   13 ++++-
 grub-core/loader/multiboot.c          |   62 +++++++++++++++++----
 grub-core/loader/multiboot_elfxx.c    |   52 ++++++++++++------
 grub-core/loader/multiboot_mbi2.c     |  232 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
 include/grub/i386/multiboot.h         |   11 ++++
 include/grub/i386/relocator.h         |   21 +++++++
 include/grub/multiboot.h              |   22 +++++++-
 include/multiboot2.h                  |   41 ++++++++++++++
 11 files changed, 441 insertions(+), 101 deletions(-)

Daniel Kiper (4):
i386/relocator: Add grub_relocator64_efi relocator
multiboot2: Add tags used to pass ImageHandle to loaded image
multiboot2: Do not pass memory maps to image if EFI boot services are enabled
multiboot2: Add support for relocatable images

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

#1 lore raw

PATCH v4 1/4 i386/relocator: Add grub_relocator64_efi relocator

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.

---
v4 - suggestions/fixes:
- move EFI platform specific C code to separate file (suggested by Vladimir 'phcoder' Serbinenko),
- add some comments
(suggested by Vladimir 'phcoder' Serbinenko).

v3 - suggestions/fixes:
- reuse grub-core/lib/i386/relocator64.S code instead of creating separate assembly file (suggested by Vladimir 'phcoder' Serbinenko),
- grub_multiboot_boot() cleanup
(suggested by Vladimir 'phcoder' Serbinenko),
- reuse multiboot_header_tag_entry_address struct instead of creating new one for EFI 64-bit entry point (suggested by Vladimir 'phcoder' Serbinenko).

---
 grub-core/Makefile.core.def          |    1 +
 grub-core/lib/i386/relocator64.S     |   11 +++++
 grub-core/lib/x86_64/efi/relocator.c |   76 ++++++++++++++++++++++++++++++++++
 grub-core/loader/multiboot.c         |   51 ++++++++++++++++++++---
 grub-core/loader/multiboot_mbi2.c    |   19 +++++++--
 include/grub/i386/multiboot.h        |   11 +++++
 include/grub/i386/relocator.h        |   21 ++++++++++
 include/multiboot2.h                 |    1 +
 8 files changed, 182 insertions(+), 9 deletions(-)
 create mode 100644 grub-core/lib/x86_64/efi/relocator.c
grub-core/Makefile.core.def +1 -0
index 58b4208..21ad0dd 100644
@@ -1531,6 +1531,7 @@ module = {
   i386_xen = lib/i386/xen/relocator.S;
   x86_64_xen = lib/x86_64/xen/relocator.S;
   xen = lib/i386/relocator_common_c.c;
+  x86_64_efi = lib/x86_64/efi/relocator.c;
 
   extra_dist = lib/i386/relocator_common.S;
   extra_dist = kern/powerpc/cache_flush.S;
grub-core/lib/i386/relocator64.S +11 -0
index e4648d8..75725cf 100644
@@ -73,6 +73,14 @@ VARIABLE(grub_relocator64_rsp)
 
 	movq	%rax, %rsp
 
+	/*
+	 * Here is grub_relocator64_efi_start() entry point.
+	 * Following code is shared between grub_relocator64_efi_start()
+	 * and grub_relocator64_start().
+	 *
+	 * Think twice before changing anything below!!!
+	 */
+VARIABLE(grub_relocator64_efi_start)
 	/* mov imm64, %rax */
 	.byte 	0x48
 	.byte	0xb8
@@ -120,6 +128,9 @@ LOCAL(jump_addr):
 VARIABLE(grub_relocator64_rip)
 	.quad	0
 
+	/* Here grub_relocator64_efi_start() ends. Ufff... */
+VARIABLE(grub_relocator64_efi_end)
+
 #ifndef __x86_64__
 	.p2align	4
 LOCAL(gdt):
grub-core/lib/x86_64/efi/relocator.c new file +76 -0

76 lines not on this page · raw message

grub-core/loader/multiboot.c +46 -5

63 lines not on this page · raw message

grub-core/loader/multiboot_mbi2.c +15 -4
index f147d67..a3dca90 100644
@@ -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 *) 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)
include/grub/i386/multiboot.h +11 -0
index a1b9488..807a1de 100644
@@ -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
 
include/grub/i386/relocator.h +21 -0
index 5f89a7e..2a56c3b 100644
@@ -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 */
include/multiboot2.h +1 -0
index 8b8c156..46e7b71 100644
@@ -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
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [GRUB2 PATCH v4 1/4] i386/relocator: Add grub_relocator64_efi relocator

Other than 2 typos (inline). Looks good. Let's give it a day if somebody wants to object, then I'll commit it

grub-core/lib/i386/relocator64.S VARIABLE(grub_relocator64_rsp) · line 82

Quoted 11 lines

movq %rax, %rsp

grub-core/lib/i386/relocator64.S +7 -0
+       /*
+        * Here is grub_relocator64_efi_start() entry point.
+        * Following code is shared between grub_relocator64_efi_start()
+        * and grub_relocator64_start().
+        *
+        * Think twice before changing anything below!!!
+        */

above?

grub-core/lib/i386/relocator64.S LOCAL(jump_addr): · line 133

Quoted 4 lines
grub-core/lib/i386/relocator64.S +3 -0
+       /* Here grub_relocator64_efi_start() ends. Ufff... */
+VARIABLE(grub_relocator64_efi_end)
+

Probably without _start. Comment probably applies even more here than above.
Are you ok with me moving ends to the same place when comitting? This
would make the code less error-prone.

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko

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

#3 lore raw

Re: [GRUB2 PATCH v4 1/4] i386/relocator: Add grub_relocator64_efi relocator

In reply to Daniel Kiper

Other than 2 typos (inline). Looks good. Let's give it a day if somebody wants to object, then I'll commit it

grub-core/lib/i386/relocator64.S VARIABLE(grub_relocator64_rsp) · line 82

Quoted 11 lines

movq %rax, %rsp

grub-core/lib/i386/relocator64.S +7 -0
+       /*
+        * Here is grub_relocator64_efi_start() entry point.
+        * Following code is shared between grub_relocator64_efi_start()
+        * and grub_relocator64_start().
+        *
+        * Think twice before changing anything below!!!
+        */

above?

grub-core/lib/i386/relocator64.S LOCAL(jump_addr): · line 133

Quoted 4 lines
grub-core/lib/i386/relocator64.S +3 -0
+       /* Here grub_relocator64_efi_start() ends. Ufff... */
+VARIABLE(grub_relocator64_efi_end)
+

Probably without _start. Comment probably applies even more here than above.
Are you ok with me moving ends to the same place when comitting? This
would make the code less error-prone.

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#4 lore raw

Re: [GRUB2 PATCH v4 1/4] i386/relocator: Add grub_relocator64_efi relocator

Quoted 14 lines · Vladimir 'phcoder' Serbinenko

Other than 2 typos (inline). Looks good. Let's give it a day if somebody wants to object, then I'll commit it

grub-core/lib/i386/relocator64.S VARIABLE(grub_relocator64_rsp) · line 82

Quoted 11 lines

movq %rax, %rsp

grub-core/lib/i386/relocator64.S +7 -0
+       /*
+        * Here is grub_relocator64_efi_start() entry point.
+        * Following code is shared between grub_relocator64_efi_start()
+        * and grub_relocator64_start().
+        *
+        * Think twice before changing anything below!!!
+        */
Quoted 1 line

above?

Why? Everything outside of grub_relocator64_efi_start (above grub_relocator64_efi_start) and grub_relocator64_efi_end (below grub_relocator64_efi_end) is used by one function. So, we can quite safely change anything there. However, everything between grub_relocator64_efi_start (__below__ grub_relocator64_efi_start label) and grub_relocator64_efi_end is owned by two functions. Hence, every change should take into account that. Am I missing something?

Quoted 5 lines

grub-core/lib/i386/relocator64.S LOCAL(jump_addr): · line 133

Quoted 4 lines
grub-core/lib/i386/relocator64.S +3 -0
+       /* Here grub_relocator64_efi_start() ends. Ufff... */
+VARIABLE(grub_relocator64_efi_end)
+

Probably without _start. Comment probably applies even more here than above.

Nope, grub_relocator64_efi_start is entry point, so, grub_relocator64_efi_end label marks end of grub_relocator64_efi_start() func.

Quoted 1 line

Are you ok with me moving ends to the same place when comitting? This

If you wish. However, I think that grub_relocator64_efi_start() should contain only code/data which is really used by it. Otherwise, it could make some confusion. Why unused code/data is owned by grub_relocator64_efi_start()? Is by design or by mistake?

Quoted 1 line

would make the code less error-prone.

I am not convinced that it will be less error-prone then. If we wish that maybe we should not share code in that way... ;-)))

Daniel

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

#5 lore raw

Re: [GRUB2 PATCH v4 1/4] i386/relocator: Add grub_relocator64_efi relocator

In reply to Vladimir 'phcoder' Serbinenko
Quoted 14 lines · Vladimir 'phcoder' Serbinenko

Other than 2 typos (inline). Looks good. Let's give it a day if somebody wants to object, then I'll commit it

grub-core/lib/i386/relocator64.S VARIABLE(grub_relocator64_rsp) · line 82

Quoted 11 lines

movq %rax, %rsp

grub-core/lib/i386/relocator64.S +7 -0
+       /*
+        * Here is grub_relocator64_efi_start() entry point.
+        * Following code is shared between grub_relocator64_efi_start()
+        * and grub_relocator64_start().
+        *
+        * Think twice before changing anything below!!!
+        */
Quoted 1 line

above?

Why? Everything outside of grub_relocator64_efi_start (above grub_relocator64_efi_start) and grub_relocator64_efi_end (below grub_relocator64_efi_end) is used by one function. So, we can quite safely change anything there. However, everything between grub_relocator64_efi_start (__below__ grub_relocator64_efi_start label) and grub_relocator64_efi_end is owned by two functions. Hence, every change should take into account that. Am I missing something?

Quoted 5 lines

grub-core/lib/i386/relocator64.S LOCAL(jump_addr): · line 133

Quoted 4 lines
grub-core/lib/i386/relocator64.S +3 -0
+       /* Here grub_relocator64_efi_start() ends. Ufff... */
+VARIABLE(grub_relocator64_efi_end)
+

Probably without _start. Comment probably applies even more here than above.

Nope, grub_relocator64_efi_start is entry point, so, grub_relocator64_efi_end label marks end of grub_relocator64_efi_start() func.

Quoted 1 line

Are you ok with me moving ends to the same place when comitting? This

If you wish. However, I think that grub_relocator64_efi_start() should contain only code/data which is really used by it. Otherwise, it could make some confusion. Why unused code/data is owned by grub_relocator64_efi_start()? Is by design or by mistake?

Quoted 1 line

would make the code less error-prone.

I am not convinced that it will be less error-prone then. If we wish that maybe we should not share code in that way... ;-)))

Daniel

#6 lore raw

PATCH v4 2/4 multiboot2: Add tags used to pass ImageHandle to loaded image

In reply to Daniel Kiper

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

---
v4 - suggestions/fixes:
- reduce number of #ifdefs in grub_multiboot_get_mbi_size() (suggested by Vladimir 'phcoder' Serbinenko).

v3 - suggestions/fixes:
- mbi EFI related stuff size calculation
should depend on target architecture
(suggested by Konrad Rzeszutek Wilk),
- use plain type instead of pointer
dereference as sizeof() argument
(suggested by Konrad Rzeszutek Wilk),
- improve commit message
(suggested by Konrad Rzeszutek Wilk).

---
 grub-core/loader/multiboot_mbi2.c |   42 ++++++++++++++++++++++++++++++-------
 include/multiboot2.h              |   16 ++++++++++++++
 2 files changed, 51 insertions(+), 7 deletions(-)
grub-core/loader/multiboot_mbi2.c +35 -7
index a3dca90..6c04402 100644
@@ -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,13 +409,15 @@ 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_efi32), MULTIBOOT_TAG_ALIGN)
-    + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
     + 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_efi32), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi64), 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
@@ -907,11 +911,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 __i386__
+      {
+	struct multiboot_tag_efi32_ih *tag = (struct multiboot_tag_efi32_ih *) ptrorig;
+	tag->type = MULTIBOOT_TAG_TYPE_EFI32_IH;
+	tag->size = sizeof (struct multiboot_tag_efi32_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 __x86_64__
+      {
+	struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig;
+	tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH;
+	tag->size = 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
     }
 #endif
 
include/multiboot2.h +16 -0
index 46e7b71..f5bebe1 100644
@@ -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
@@ -371,6 +373,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 */
Signature · 1 line
1.7.10.4
#7 lore raw

Re: [GRUB2 PATCH v4 2/4] multiboot2: Add tags used to pass ImageHandle to loaded image

Looks good. Let's give others a day to comment before committing

Quoted 142 lines · Daniel Kiper

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

Signed-off-by Daniel Kiper <[email protected] <javascript:;>>

---
v4 - suggestions/fixes:
- reduce number of #ifdefs in grub_multiboot_get_mbi_size() (suggested by Vladimir 'phcoder' Serbinenko).

v3 - suggestions/fixes:
- mbi EFI related stuff size calculation
should depend on target architecture
(suggested by Konrad Rzeszutek Wilk),
- use plain type instead of pointer
dereference as sizeof() argument
(suggested by Konrad Rzeszutek Wilk),
- improve commit message
(suggested by Konrad Rzeszutek Wilk).

---
 grub-core/loader/multiboot_mbi2.c |   42
++++++++++++++++++++++++++++++-------
 include/multiboot2.h              |   16 ++++++++++++++
 2 files changed, 51 insertions(+), 7 deletions(-)
grub-core/loader/multiboot_mbi2.c +2 -0
index a3dca90..6c04402 100644
@@ -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:

grub-core/loader/multiboot_mbi2.c +4 -2
@@ -407,13 +409,15 @@ 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_efi32), MULTIBOOT_TAG_ALIGN)
-    + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
     + 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_efi32), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih),
 MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi64), 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

grub-core/loader/multiboot_mbi2.c +29 -5
@@ -907,11 +911,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 __i386__
+      {
+       struct multiboot_tag_efi32_ih *tag = (struct
 multiboot_tag_efi32_ih *) ptrorig;
+       tag->type = MULTIBOOT_TAG_TYPE_EFI32_IH;
+       tag->size = sizeof (struct multiboot_tag_efi32_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 __x86_64__
+      {
+       struct multiboot_tag_efi64_ih *tag = (struct
 multiboot_tag_efi64_ih *) ptrorig;
+       tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH;
+       tag->size = 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
     }

#endif

include/multiboot2.h +16 -1
index 46e7b71..f5bebe1 100644
@@ -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
@@ -371,6 +373,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

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko

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

#8 lore raw

Re: [GRUB2 PATCH v4 2/4] multiboot2: Add tags used to pass ImageHandle to loaded image

In reply to Daniel Kiper

Looks good. Let's give others a day to comment before committing

Quoted 142 lines · Daniel Kiper

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

Signed-off-by Daniel Kiper <[email protected] <javascript:;>>

---
v4 - suggestions/fixes:
- reduce number of #ifdefs in grub_multiboot_get_mbi_size() (suggested by Vladimir 'phcoder' Serbinenko).

v3 - suggestions/fixes:
- mbi EFI related stuff size calculation
should depend on target architecture
(suggested by Konrad Rzeszutek Wilk),
- use plain type instead of pointer
dereference as sizeof() argument
(suggested by Konrad Rzeszutek Wilk),
- improve commit message
(suggested by Konrad Rzeszutek Wilk).

---
 grub-core/loader/multiboot_mbi2.c |   42
++++++++++++++++++++++++++++++-------
 include/multiboot2.h              |   16 ++++++++++++++
 2 files changed, 51 insertions(+), 7 deletions(-)
grub-core/loader/multiboot_mbi2.c +2 -0
index a3dca90..6c04402 100644
@@ -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:

grub-core/loader/multiboot_mbi2.c +4 -2
@@ -407,13 +409,15 @@ 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_efi32), MULTIBOOT_TAG_ALIGN)
-    + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
     + 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_efi32), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih),
 MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi64), 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

grub-core/loader/multiboot_mbi2.c +29 -5
@@ -907,11 +911,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 __i386__
+      {
+       struct multiboot_tag_efi32_ih *tag = (struct
 multiboot_tag_efi32_ih *) ptrorig;
+       tag->type = MULTIBOOT_TAG_TYPE_EFI32_IH;
+       tag->size = sizeof (struct multiboot_tag_efi32_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 __x86_64__
+      {
+       struct multiboot_tag_efi64_ih *tag = (struct
 multiboot_tag_efi64_ih *) ptrorig;
+       tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH;
+       tag->size = 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
     }

#endif

include/multiboot2.h +16 -1
index 46e7b71..f5bebe1 100644
@@ -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
@@ -371,6 +373,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

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
Reviewed-by on v4 2/4
#9 lore raw

Re: [GRUB2 PATCH v4 2/4] multiboot2: Add tags used to pass ImageHandle to loaded image

In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper

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

Quoted 128 lines

---
v4 - suggestions/fixes:
- reduce number of #ifdefs in grub_multiboot_get_mbi_size() (suggested by Vladimir 'phcoder' Serbinenko).

v3 - suggestions/fixes:
- mbi EFI related stuff size calculation
should depend on target architecture
(suggested by Konrad Rzeszutek Wilk),
- use plain type instead of pointer
dereference as sizeof() argument
(suggested by Konrad Rzeszutek Wilk),
- improve commit message
(suggested by Konrad Rzeszutek Wilk).

---
 grub-core/loader/multiboot_mbi2.c |   42 ++++++++++++++++++++++++++++++-------
 include/multiboot2.h              |   16 ++++++++++++++
 2 files changed, 51 insertions(+), 7 deletions(-)
grub-core/loader/multiboot_mbi2.c +35 -7
index a3dca90..6c04402 100644
@@ -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,13 +409,15 @@ 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_efi32), MULTIBOOT_TAG_ALIGN)
-    + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
     + 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_efi32), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi64), 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
@@ -907,11 +911,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 __i386__
+      {
+	struct multiboot_tag_efi32_ih *tag = (struct multiboot_tag_efi32_ih *) ptrorig;
+	tag->type = MULTIBOOT_TAG_TYPE_EFI32_IH;
+	tag->size = sizeof (struct multiboot_tag_efi32_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 __x86_64__
+      {
+	struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig;
+	tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH;
+	tag->size = 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
     }
 #endif
 
include/multiboot2.h +16 -0
index 46e7b71..f5bebe1 100644
@@ -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
@@ -371,6 +373,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 */
Signature · 1 line
1.7.10.4
Reviewed-by on v4 2/4
#10 lore raw

Re: [GRUB2 PATCH v4 2/4] multiboot2: Add tags used to pass ImageHandle to loaded image

In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper

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

Quoted 128 lines

---
v4 - suggestions/fixes:
- reduce number of #ifdefs in grub_multiboot_get_mbi_size() (suggested by Vladimir 'phcoder' Serbinenko).

v3 - suggestions/fixes:
- mbi EFI related stuff size calculation
should depend on target architecture
(suggested by Konrad Rzeszutek Wilk),
- use plain type instead of pointer
dereference as sizeof() argument
(suggested by Konrad Rzeszutek Wilk),
- improve commit message
(suggested by Konrad Rzeszutek Wilk).

---
 grub-core/loader/multiboot_mbi2.c |   42 ++++++++++++++++++++++++++++++-------
 include/multiboot2.h              |   16 ++++++++++++++
 2 files changed, 51 insertions(+), 7 deletions(-)
grub-core/loader/multiboot_mbi2.c +35 -7
index a3dca90..6c04402 100644
@@ -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,13 +409,15 @@ 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_efi32), MULTIBOOT_TAG_ALIGN)
-    + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
     + 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_efi32), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih), MULTIBOOT_TAG_ALIGN)
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi64), 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
@@ -907,11 +911,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 __i386__
+      {
+	struct multiboot_tag_efi32_ih *tag = (struct multiboot_tag_efi32_ih *) ptrorig;
+	tag->type = MULTIBOOT_TAG_TYPE_EFI32_IH;
+	tag->size = sizeof (struct multiboot_tag_efi32_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 __x86_64__
+      {
+	struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig;
+	tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH;
+	tag->size = 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
     }
 #endif
 
include/multiboot2.h +16 -0
index 46e7b71..f5bebe1 100644
@@ -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
@@ -371,6 +373,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 */
Signature · 1 line
1.7.10.4

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

#11 lore raw

PATCH v4 3/4 multiboot2: Do not pass memory maps to image if EFI boot services are enabled

In reply to Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services. Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services. If we keep boot services then it is easier to not provide maps. However, if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

---
v3 - suggestions/fixes:
- improve commit message
(suggested by Konrad Rzeszutek Wilk and Vladimir 'phcoder' Serbinenko).

---
 grub-core/loader/multiboot_mbi2.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
grub-core/loader/multiboot_mbi2.c +8 -9
index 6c04402..ad1553b 100644
@@ -390,7 +390,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)
@@ -755,6 +755,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
       }
   }
 
+  if (!keep_bs)
     {
       struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
       grub_fill_multiboot_mmap (tag);
@@ -776,6 +777,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
       / sizeof (grub_properly_aligned_t);
   }
 
+  if (!keep_bs)
     {
       struct multiboot_tag_basic_meminfo *tag
 	= (struct multiboot_tag_basic_meminfo *) ptrorig;
@@ -886,21 +888,17 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
     grub_efi_uintn_t efi_desc_size;
     grub_efi_uint32_t efi_desc_version;
 
+    if (!keep_bs)
+      {
 	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");
-      }
+
 	if (err)
 	  return err;
+
 	tag->descr_size = efi_desc_size;
 	tag->descr_vers = efi_desc_version;
 	tag->size = sizeof (*tag) + efi_mmap_size;
@@ -908,6 +906,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
 	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
 	  / sizeof (grub_properly_aligned_t);
       }
+  }
 
   if (keep_bs)
     {
Signature · 1 line
1.7.10.4
#12 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

Quoted 1 line · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services.

.. I would change this sentence a bit.

If image requested EFI boot services then skip multiboot2 memory maps.

Quoted 3 lines

Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services.

s/would already finish/would have finished/ ?

Quoted 1 line

If we keep boot services then it is easier to not provide maps. However,

s/easier/safer?/

Quoted 2 lines

if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

s/them// ?

That is making an assumption that the user of Multiboot2 + EFI will do this. Which is OK since only Xen is using it.. but is this inline with the spec? Can you ignore not providing this information?

That aside - why not sync the multiboot memory map with what the EFI one will be? Or is it too to complex to move the memory map creation to a later phase of the bootup?

Wish there was some multboot memory map flag indicating 'STALE-CHECK-EFI'..

Quoted 77 lines

---
v3 - suggestions/fixes:
- improve commit message
(suggested by Konrad Rzeszutek Wilk and Vladimir 'phcoder' Serbinenko).

---
 grub-core/loader/multiboot_mbi2.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
grub-core/loader/multiboot_mbi2.c +8 -9
index 6c04402..ad1553b 100644
@@ -390,7 +390,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)
@@ -755,6 +755,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
       }
   }
 
+  if (!keep_bs)
     {
       struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
       grub_fill_multiboot_mmap (tag);
@@ -776,6 +777,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
       / sizeof (grub_properly_aligned_t);
   }
 
+  if (!keep_bs)
     {
       struct multiboot_tag_basic_meminfo *tag
 	= (struct multiboot_tag_basic_meminfo *) ptrorig;
@@ -886,21 +888,17 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
     grub_efi_uintn_t efi_desc_size;
     grub_efi_uint32_t efi_desc_version;
 
+    if (!keep_bs)
+      {
 	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");
-      }
+
 	if (err)
 	  return err;
+
 	tag->descr_size = efi_desc_size;
 	tag->descr_vers = efi_desc_version;
 	tag->size = sizeof (*tag) + efi_mmap_size;
@@ -908,6 +906,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
 	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
 	  / sizeof (grub_properly_aligned_t);
       }
+  }
 
   if (keep_bs)
     {
Signature · 1 line
1.7.10.4
#13 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

Quoted 17 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services.

.. I would change this sentence a bit.

If image requested EFI boot services then skip multiboot2 memory maps.

Quoted 3 lines

Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services.

s/would already finish/would have finished/ ?

Quoted 1 line

If we keep boot services then it is easier to not provide maps. However,

s/easier/safer?/

Quoted 8 lines
Quoted 2 lines

if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

s/them// ?

That is making an assumption that the user of Multiboot2 + EFI will do this. Which is OK since only Xen is using it.. but is this inline with the spec? Can you ignore not providing this information?

AIUI, spec does not require that anything must be provided. Of course on every platform GRUB2 should provide minimal set of system information to properly boot loaded image. However, docs does not say which set make sense or not. This is role of image to know what it requires to properly run on a given platform. And I think that it make sense.

Quoted 3 lines

That aside - why not sync the multiboot memory map with what the EFI one will be? Or is it too to complex to move the memory map creation to a later phase of the bootup?

IIRC, GRUB2 does some allocations after getting memory map and it is quite complicated to change that.

Quoted 1 line

Wish there was some multboot memory map flag indicating 'STALE-CHECK-EFI'..

Why provide map which is invalid and must be verified with something else? Let's ignore (do not provide) invalid data and use correct one without any additional (unneeded) checks.

Daniel

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

#14 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

In reply to Konrad Rzeszutek Wilk
Quoted 17 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services.

.. I would change this sentence a bit.

If image requested EFI boot services then skip multiboot2 memory maps.

Quoted 3 lines

Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services.

s/would already finish/would have finished/ ?

Quoted 1 line

If we keep boot services then it is easier to not provide maps. However,

s/easier/safer?/

Quoted 8 lines
Quoted 2 lines

if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

s/them// ?

That is making an assumption that the user of Multiboot2 + EFI will do this. Which is OK since only Xen is using it.. but is this inline with the spec? Can you ignore not providing this information?

AIUI, spec does not require that anything must be provided. Of course on every platform GRUB2 should provide minimal set of system information to properly boot loaded image. However, docs does not say which set make sense or not. This is role of image to know what it requires to properly run on a given platform. And I think that it make sense.

Quoted 3 lines

That aside - why not sync the multiboot memory map with what the EFI one will be? Or is it too to complex to move the memory map creation to a later phase of the bootup?

IIRC, GRUB2 does some allocations after getting memory map and it is quite complicated to change that.

Quoted 1 line

Wish there was some multboot memory map flag indicating 'STALE-CHECK-EFI'..

Why provide map which is invalid and must be verified with something else? Let's ignore (do not provide) invalid data and use correct one without any additional (unneeded) checks.

Daniel

#15 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

Quoted 40 lines · Daniel Kiper
Quoted 17 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services.

.. I would change this sentence a bit.

If image requested EFI boot services then skip multiboot2 memory maps.

Quoted 3 lines

Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services.

s/would already finish/would have finished/ ?

Quoted 1 line

If we keep boot services then it is easier to not provide maps. However,

s/easier/safer?/

Quoted 8 lines
Quoted 2 lines

if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

s/them// ?

That is making an assumption that the user of Multiboot2 + EFI will do this. Which is OK since only Xen is using it.. but is this inline with the spec? Can you ignore not providing this information?

AIUI, spec does not require that anything must be provided. Of course on every platform GRUB2 should provide minimal set of system information to properly boot loaded image. However, docs does not say which set make sense or not. This is role of image to know what it requires to properly run on a given platform. And I think that it make sense.

Quoted 3 lines

That aside - why not sync the multiboot memory map with what the EFI one will be? Or is it too to complex to move the memory map creation to a later phase of the bootup?

Quoted 9 lines

IIRC, GRUB2 does some allocations after getting memory map and it is quite complicated to change that.

Quoted 1 line

Wish there was some multboot memory map flag indicating 'STALE-CHECK-EFI'..

Why provide map which is invalid and must be verified with something else? Let's ignore (do not provide) invalid data and use correct one without any additional (unneeded) checks.

If you are *not* calling exit efi boot services from grub, there is no sense to provide EFI memory map at all, because to exit boot services [from OS], you *have to* fetch current memory map to get the map key to exit boot services.

basically it means, if BS is not disabled and grub is still providing EFI memory map, the OS has to assume this map is not valid - which is bad and better not to provide (potentially) invalid data in first place.

rgds,
toomas
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#16 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

In reply to Daniel Kiper
Quoted 40 lines · Daniel Kiper
Quoted 17 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services.

.. I would change this sentence a bit.

If image requested EFI boot services then skip multiboot2 memory maps.

Quoted 3 lines

Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services.

s/would already finish/would have finished/ ?

Quoted 1 line

If we keep boot services then it is easier to not provide maps. However,

s/easier/safer?/

Quoted 8 lines
Quoted 2 lines

if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

s/them// ?

That is making an assumption that the user of Multiboot2 + EFI will do this. Which is OK since only Xen is using it.. but is this inline with the spec? Can you ignore not providing this information?

AIUI, spec does not require that anything must be provided. Of course on every platform GRUB2 should provide minimal set of system information to properly boot loaded image. However, docs does not say which set make sense or not. This is role of image to know what it requires to properly run on a given platform. And I think that it make sense.

Quoted 3 lines

That aside - why not sync the multiboot memory map with what the EFI one will be? Or is it too to complex to move the memory map creation to a later phase of the bootup?

Quoted 9 lines

IIRC, GRUB2 does some allocations after getting memory map and it is quite complicated to change that.

Quoted 1 line

Wish there was some multboot memory map flag indicating 'STALE-CHECK-EFI'..

Why provide map which is invalid and must be verified with something else? Let's ignore (do not provide) invalid data and use correct one without any additional (unneeded) checks.

If you are *not* calling exit efi boot services from grub, there is no sense to provide EFI memory map at all, because to exit boot services [from OS], you *have to* fetch current memory map to get the map key to exit boot services.

basically it means, if BS is not disabled and grub is still providing EFI memory map, the OS has to assume this map is not valid - which is bad and better not to provide (potentially) invalid data in first place.

rgds,
toomas

#17 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

Quoted 50 lines · Toomas Soome
Quoted 2 lines

On 16. märts 2016, at 12:02, Daniel Kiper <[email protected]

Quoted 9 lines · <javascript:;>> wrote:
Quoted 7 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services.

.. I would change this sentence a bit.

If image requested EFI boot services then skip multiboot2 memory maps.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services.

s/would already finish/would have finished/ ?

Quoted 1 line

If we keep boot services then it is easier to not provide maps.

However,

Quoted 18 lines
Quoted 11 lines

s/easier/safer?/

Quoted 2 lines

if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

s/them// ?

That is making an assumption that the user of Multiboot2 + EFI will do this. Which is OK since only Xen is using it.. but is this inline with the spec? Can you ignore not providing this information?

AIUI, spec does not require that anything must be provided. Of course on every platform GRUB2 should provide minimal set of system information to properly boot loaded image. However, docs does not say which set make sense or not. This is role of image to know what it requires to properly run on a given platform. And I think that it make sense.

Quoted 8 lines
Quoted 3 lines

That aside - why not sync the multiboot memory map with what the EFI one will be? Or is it too to complex to move the memory map creation to a later phase of the bootup?

IIRC, GRUB2 does some allocations after getting memory map and it is quite complicated to change that.

Quoted 1 line

Wish there was some multboot memory map flag indicating

'STALE-CHECK-EFI'..

Quoted 2 lines

Why provide map which is invalid and must be verified with something

else?

Quoted 9 lines
Quoted 3 lines

Let's ignore (do not provide) invalid data and use correct one without any additional (unneeded) checks.

If you are *not* calling exit efi boot services from grub, there is no sense to provide EFI memory map at all, because to exit boot services [from OS], you *have to* fetch current memory map to get the map key to exit boot services.

But this doesn't apply for e820-like and simple maps which are unaffected by bootloader allocations

Quoted 7 lines

basically it means, if BS is not disabled and grub is still providing EFI memory map, the OS has to assume this map is not valid - which is bad and better not to provide (potentially) invalid data in first place.

rgds,
toomas

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko

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

#18 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

Quoted 56 lines · Vladimir 'phcoder' Serbinenko
Quoted 54 lines · Toomas Soome
Quoted 2 lines

On 16. märts 2016, at 12:02, Daniel Kiper <[email protected]

Quoted 9 lines · <javascript:;>> wrote:
Quoted 7 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services.

.. I would change this sentence a bit.

If image requested EFI boot services then skip multiboot2 memory maps.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services.

s/would already finish/would have finished/ ?

Quoted 1 line

If we keep boot services then it is easier to not provide maps.

However,

Quoted 18 lines
Quoted 11 lines

s/easier/safer?/

Quoted 2 lines

if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

s/them// ?

That is making an assumption that the user of Multiboot2 + EFI will do this. Which is OK since only Xen is using it.. but is this inline with the spec? Can you ignore not providing this information?

AIUI, spec does not require that anything must be provided. Of course on every platform GRUB2 should provide minimal set of system information to properly boot loaded image. However, docs does not say which set make sense or not. This is role of image to know what it requires to properly run on a given platform. And I think that it make sense.

Quoted 8 lines
Quoted 3 lines

That aside - why not sync the multiboot memory map with what the EFI one will be? Or is it too to complex to move the memory map creation to a later phase of the bootup?

IIRC, GRUB2 does some allocations after getting memory map and it is quite complicated to change that.

Quoted 1 line

Wish there was some multboot memory map flag indicating

'STALE-CHECK-EFI'..

Quoted 2 lines

Why provide map which is invalid and must be verified with something

else?

Quoted 3 lines

Let's ignore (do not provide) invalid data and use correct one without any additional (unneeded) checks.

Quoted 7 lines
Quoted 5 lines

If you are *not* calling exit efi boot services from grub, there is no sense to provide EFI memory map at all, because to exit boot services [from OS], you *have to* fetch current memory map to get the map key to exit boot services.

But this doesn't apply for e820-like and simple maps which are unaffected by bootloader allocations

Right. I think we are all on the same page then.

If EFI and payload (OS) has requested to be the one executing ExitBootServices then don't provide the memory map?

But if the payload hasn't specified what to do with ExitBootServices, GRUB is free to do so and provide the map.

Quoted 5 lines
Quoted 5 lines

basically it means, if BS is not disabled and grub is still providing EFI memory map, the OS has to assume this map is not valid - which is bad and better not to provide (potentially) invalid data in first place.

Right.

And the description of the patch (to my reading) was not exactly clear on this.

Perhaps just updating the description of the patch and repositing as reply here would suffice?

Quoted 9 lines
Quoted 3 lines

rgds,
toomas

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#19 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

In reply to Vladimir 'phcoder' Serbinenko
Quoted 56 lines · Vladimir 'phcoder' Serbinenko
Quoted 54 lines · Toomas Soome
Quoted 2 lines

On 16. märts 2016, at 12:02, Daniel Kiper <[email protected]

Quoted 9 lines · <javascript:;>> wrote:
Quoted 7 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services.

.. I would change this sentence a bit.

If image requested EFI boot services then skip multiboot2 memory maps.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services.

s/would already finish/would have finished/ ?

Quoted 1 line

If we keep boot services then it is easier to not provide maps.

However,

Quoted 18 lines
Quoted 11 lines

s/easier/safer?/

Quoted 2 lines

if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

s/them// ?

That is making an assumption that the user of Multiboot2 + EFI will do this. Which is OK since only Xen is using it.. but is this inline with the spec? Can you ignore not providing this information?

AIUI, spec does not require that anything must be provided. Of course on every platform GRUB2 should provide minimal set of system information to properly boot loaded image. However, docs does not say which set make sense or not. This is role of image to know what it requires to properly run on a given platform. And I think that it make sense.

Quoted 8 lines
Quoted 3 lines

That aside - why not sync the multiboot memory map with what the EFI one will be? Or is it too to complex to move the memory map creation to a later phase of the bootup?

IIRC, GRUB2 does some allocations after getting memory map and it is quite complicated to change that.

Quoted 1 line

Wish there was some multboot memory map flag indicating

'STALE-CHECK-EFI'..

Quoted 2 lines

Why provide map which is invalid and must be verified with something

else?

Quoted 3 lines

Let's ignore (do not provide) invalid data and use correct one without any additional (unneeded) checks.

Quoted 7 lines
Quoted 5 lines

If you are *not* calling exit efi boot services from grub, there is no sense to provide EFI memory map at all, because to exit boot services [from OS], you *have to* fetch current memory map to get the map key to exit boot services.

But this doesn't apply for e820-like and simple maps which are unaffected by bootloader allocations

Right. I think we are all on the same page then.

If EFI and payload (OS) has requested to be the one executing ExitBootServices then don't provide the memory map?

But if the payload hasn't specified what to do with ExitBootServices, GRUB is free to do so and provide the map.

Quoted 5 lines
Quoted 5 lines

basically it means, if BS is not disabled and grub is still providing EFI memory map, the OS has to assume this map is not valid - which is bad and better not to provide (potentially) invalid data in first place.

Right.

And the description of the patch (to my reading) was not exactly clear on this.

Perhaps just updating the description of the patch and repositing as reply here would suffice?

Quoted 9 lines
Quoted 3 lines

rgds,
toomas

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko

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

#20 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

In reply to Daniel Kiper
Quoted 1 line · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services.

.. I would change this sentence a bit.

If image requested EFI boot services then skip multiboot2 memory maps.

Quoted 3 lines

Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services.

s/would already finish/would have finished/ ?

Quoted 1 line

If we keep boot services then it is easier to not provide maps. However,

s/easier/safer?/

Quoted 2 lines

if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

s/them// ?

That is making an assumption that the user of Multiboot2 + EFI will do this. Which is OK since only Xen is using it.. but is this inline with the spec? Can you ignore not providing this information?

That aside - why not sync the multiboot memory map with what the EFI one will be? Or is it too to complex to move the memory map creation to a later phase of the bootup?

Wish there was some multboot memory map flag indicating 'STALE-CHECK-EFI'..

Quoted 77 lines

---
v3 - suggestions/fixes:
- improve commit message
(suggested by Konrad Rzeszutek Wilk and Vladimir 'phcoder' Serbinenko).

---
 grub-core/loader/multiboot_mbi2.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
grub-core/loader/multiboot_mbi2.c +8 -9
index 6c04402..ad1553b 100644
@@ -390,7 +390,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)
@@ -755,6 +755,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
       }
   }
 
+  if (!keep_bs)
     {
       struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
       grub_fill_multiboot_mmap (tag);
@@ -776,6 +777,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
       / sizeof (grub_properly_aligned_t);
   }
 
+  if (!keep_bs)
     {
       struct multiboot_tag_basic_meminfo *tag
 	= (struct multiboot_tag_basic_meminfo *) ptrorig;
@@ -886,21 +888,17 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
     grub_efi_uintn_t efi_desc_size;
     grub_efi_uint32_t efi_desc_version;
 
+    if (!keep_bs)
+      {
 	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");
-      }
+
 	if (err)
 	  return err;
+
 	tag->descr_size = efi_desc_size;
 	tag->descr_vers = efi_desc_version;
 	tag->size = sizeof (*tag) + efi_mmap_size;
@@ -908,6 +906,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
 	ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
 	  / sizeof (grub_properly_aligned_t);
       }
+  }
 
   if (keep_bs)
     {
Signature · 1 line
1.7.10.4

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

#21 lore raw

PATCH v4 3/4 multiboot2: Do not pass memory maps to image if EFI boot services are enabled

In reply to Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services. Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services. If we keep boot services then it is easier to not provide maps. However, if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

---
v3 - suggestions/fixes:
- improve commit message
(suggested by Konrad Rzeszutek Wilk and Vladimir 'phcoder' Serbinenko).

---
 grub-core/loader/multiboot_mbi2.c |   71 ++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 36 deletions(-)
grub-core/loader/multiboot_mbi2.c +35 -36
index 6c04402..ad1553b 100644
@@ -390,7 +390,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)
@@ -755,12 +755,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
@@ -776,18 +777,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;
@@ -886,27 +888,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)
Signature · 1 line
1.7.10.4
#22 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

Looks good. Let's give a day for others to comment. Is the second email the version for commit?

Quoted 140 lines · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services. Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services. If we keep boot services then it is easier to not provide maps. However, if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

Signed-off-by Daniel Kiper <[email protected] <javascript:;>>
Reviewed-by Konrad Rzeszutek Wilk <[email protected] <javascript:;>>

---
v3 - suggestions/fixes:
- improve commit message
(suggested by Konrad Rzeszutek Wilk and Vladimir 'phcoder'
Serbinenko).

---
 grub-core/loader/multiboot_mbi2.c |   71
++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 36 deletions(-)
grub-core/loader/multiboot_mbi2.c +8 -7
index 6c04402..ad1553b 100644
@@ -390,7 +390,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)
@@ -755,12 +755,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
grub-core/loader/multiboot_mbi2.c +27 -30
@@ -776,18 +777,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;
@@ -886,27 +888,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

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko

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

#23 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

In reply to Daniel Kiper

Looks good. Let's give a day for others to comment. Is the second email the version for commit?

Quoted 140 lines · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services. Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services. If we keep boot services then it is easier to not provide maps. However, if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

Signed-off-by Daniel Kiper <[email protected] <javascript:;>>
Reviewed-by Konrad Rzeszutek Wilk <[email protected] <javascript:;>>

---
v3 - suggestions/fixes:
- improve commit message
(suggested by Konrad Rzeszutek Wilk and Vladimir 'phcoder'
Serbinenko).

---
 grub-core/loader/multiboot_mbi2.c |   71
++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 36 deletions(-)
grub-core/loader/multiboot_mbi2.c +8 -7
index 6c04402..ad1553b 100644
@@ -390,7 +390,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)
@@ -755,12 +755,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
grub-core/loader/multiboot_mbi2.c +27 -30
@@ -776,18 +777,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;
@@ -886,27 +888,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

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#24 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

15.03.2016 19:07, Vladimir 'phcoder' Serbinenko пишет:

Quoted 13 lines

Looks good. Let's give a day for others to comment. Is the second email the version for commit?

Quoted 8 lines · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services. Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services. If we keep boot services then it is easier to not provide maps. However, if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

Are there any existing users of it that rely on memory map provided by bootloader? What if image explicitly requested non-optional memory map? According to multiboot specification it is valid and bootloader must either provide requested information or fail load.

Quoted 133 lines
Quoted 132 lines
Signed-off-by Daniel Kiper <[email protected] <javascript:;>>
Reviewed-by Konrad Rzeszutek Wilk <[email protected] <javascript:;>>

---
v3 - suggestions/fixes:
- improve commit message
(suggested by Konrad Rzeszutek Wilk and Vladimir 'phcoder'
Serbinenko).

---
 grub-core/loader/multiboot_mbi2.c |   71
++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 36 deletions(-)
grub-core/loader/multiboot_mbi2.c +8 -7
index 6c04402..ad1553b 100644
@@ -390,7 +390,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)
@@ -755,12 +755,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
grub-core/loader/multiboot_mbi2.c +27 -30
@@ -776,18 +777,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;
@@ -886,27 +888,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

#25 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

Quoted 17 lines · Andrei Borzenkov

15.03.2016 19:07, Vladimir 'phcoder' Serbinenko пишет:

Quoted 1 line

Looks good. Let's give a day for others to comment. Is the second email

the

Quoted 3 lines

version for commit?

On Tuesday, March 15, 2016, Daniel Kiper <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines

Do not pass memory maps to image if it asked for EFI boot services. Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services. If we keep boot services then it is easier to not provide maps. However, if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

Quoted 5 lines

Are there any existing users of it that rely on memory map provided by bootloader? What if image explicitly requested non-optional memory map? According to multiboot specification it is valid and bootloader must either provide requested information or fail load.

I think you have a point. @Daniel, is current behavior a problem for you? Don't you just ignore the memory map in this case?

Quoted 100 lines
Quoted 3 lines
Quoted 3 lines
Signed-off-by Daniel Kiper <[email protected] <javascript:;>>

<javascript:;>>

Quoted 81 lines
Quoted 81 lines

---
v3 - suggestions/fixes:
- improve commit message
(suggested by Konrad Rzeszutek Wilk and Vladimir 'phcoder'
Serbinenko).

---
 grub-core/loader/multiboot_mbi2.c |   71
++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 36 deletions(-)
grub-core/loader/multiboot_mbi2.c +8 -7
index 6c04402..ad1553b 100644
@@ -390,7 +390,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)
@@ -755,12 +755,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
grub-core/loader/multiboot_mbi2.c +12 -11
@@ -776,18 +777,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;
@@ -886,27 +888,24 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
     grub_efi_uintn_t efi_desc_size;
     grub_efi_uint32_t efi_desc_version;
 
Quoted 5 lines

grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target)

Quoted 5 lines
grub-core/loader/multiboot_mbi2.c +0 -4
-    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,

Quoted 9 lines

grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target) · line 902

Quoted 9 lines
grub-core/loader/multiboot_mbi2.c +0 -5
 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)
Quoted 40 lines

<=

Quoted 2 lines

grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target) · line 904

Quoted 2 lines
grub-core/loader/multiboot_mbi2.c +0 -1
 0)
-         err = grub_error (GRUB_ERR_IO, "couldn't retrieve memory

map");

Quoted 34 lines
Quoted 33 lines
grub-core/loader/multiboot_mbi2.c +15 -9
+       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

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

#26 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

In reply to Andrei Borzenkov
Quoted 17 lines · Andrei Borzenkov

15.03.2016 19:07, Vladimir 'phcoder' Serbinenko пишет:

Quoted 1 line

Looks good. Let's give a day for others to comment. Is the second email

the

Quoted 3 lines

version for commit?

On Tuesday, March 15, 2016, Daniel Kiper <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines

Do not pass memory maps to image if it asked for EFI boot services. Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services. If we keep boot services then it is easier to not provide maps. However, if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

Quoted 5 lines

Are there any existing users of it that rely on memory map provided by bootloader? What if image explicitly requested non-optional memory map? According to multiboot specification it is valid and bootloader must either provide requested information or fail load.

I think you have a point. @Daniel, is current behavior a problem for you? Don't you just ignore the memory map in this case?

Quoted 140 lines
Quoted 3 lines
Quoted 3 lines
Signed-off-by Daniel Kiper <[email protected] <javascript:;>>

<javascript:;>>

Quoted 81 lines
Quoted 81 lines

---
v3 - suggestions/fixes:
- improve commit message
(suggested by Konrad Rzeszutek Wilk and Vladimir 'phcoder'
Serbinenko).

---
 grub-core/loader/multiboot_mbi2.c |   71
++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 36 deletions(-)
grub-core/loader/multiboot_mbi2.c +8 -7
index 6c04402..ad1553b 100644
@@ -390,7 +390,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)
@@ -755,12 +755,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
grub-core/loader/multiboot_mbi2.c +12 -11
@@ -776,18 +777,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;
@@ -886,27 +888,24 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
     grub_efi_uintn_t efi_desc_size;
     grub_efi_uint32_t efi_desc_version;
 
Quoted 5 lines

grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target)

Quoted 5 lines
grub-core/loader/multiboot_mbi2.c +0 -4
-    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,

Quoted 9 lines

grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target) · line 902

Quoted 9 lines
grub-core/loader/multiboot_mbi2.c +0 -5
 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)

<=

Quoted 2 lines

grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target) · line 904

Quoted 2 lines
grub-core/loader/multiboot_mbi2.c +0 -1
 0)
-         err = grub_error (GRUB_ERR_IO, "couldn't retrieve memory

map");

Quoted 34 lines
Quoted 33 lines
grub-core/loader/multiboot_mbi2.c +15 -9
+       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

#27 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

Quoted 18 lines · Vladimir 'phcoder' Serbinenko
Quoted 17 lines · Andrei Borzenkov

15.03.2016 19:07, Vladimir 'phcoder' Serbinenko пишет:

Quoted 1 line

Looks good. Let's give a day for others to comment. Is the second email

the

Quoted 3 lines

version for commit?

On Tuesday, March 15, 2016, Daniel Kiper <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines

Do not pass memory maps to image if it asked for EFI boot services. Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services. If we keep boot services then it is easier to not provide maps. However, if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

Quoted 6 lines
Quoted 5 lines

Are there any existing users of it that rely on memory map provided by bootloader? What if image explicitly requested non-optional memory map? According to multiboot specification it is valid and bootloader must either provide requested information or fail load.

I think you have a point. @Daniel, is current behavior a problem for you?

Do you think about MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST tag? If yes it looks that multiboot2 doc is a bit imprecise and/or GRUB2 code is wrong.

multiboot2 doc says:

[...]

If this tag is present and ‘optional’ is set to ‘0’ information conveyed by requested tag types must be present. If bootloader is unable to supply this information it must fail with an error
Note: it doesn’t garantee that any tags of type ‘mbi_tag_types’ will actually be present. E.g. on a videoless system even if you requested tag ‘8’ no tags of type ‘8’ will be present in mbi.

[...]

However, grub_multiboot_load() just looks for MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST tag. If it exists and if ‘optional’ is set to ‘0’ then grub_multiboot_load() verify list of requested tags. If unknown value is found then multiboot2 command fails with "grub_error (GRUB_ERR_UNKNOWN_OS, "unsupported information tag: 0x%x", ...". I cannot find additional checks anywhere...

So, AIUI, "If bootloader is unable to supply..." should be read as "If bootloader does not support..." or even "If bootloader do not understand..." or something like that. This does not mean that bootloader must have requested data in hand and provide it to image. It means that bootloader must understand what image ask for. And in this term my patch does not violate spec implied by implementation (well, multiboot2 doc makes some confusion; see below). Image may ask/request for any memory map. However, if a given map (or set of maps) is not available or it could be provided but could make confusion in some cases then it can/should not be provided.

Anyway, I think that maybe multiboot2 doc should be fixed and more precise MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST tag description should be provided. Or GRUB2 implementation is wrong then...

Quoted 1 line

Don't you just ignore the memory map in this case?

Yes to some extent. However, I think that loader should not provide data which is known as (potentially) incorrect/faulty.

Daniel

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

#28 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

In reply to Vladimir 'phcoder' Serbinenko
Quoted 18 lines · Vladimir 'phcoder' Serbinenko
Quoted 17 lines · Andrei Borzenkov

15.03.2016 19:07, Vladimir 'phcoder' Serbinenko пишет:

Quoted 1 line

Looks good. Let's give a day for others to comment. Is the second email

the

Quoted 3 lines

version for commit?

On Tuesday, March 15, 2016, Daniel Kiper <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines

Do not pass memory maps to image if it asked for EFI boot services. Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services. If we keep boot services then it is easier to not provide maps. However, if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

Quoted 6 lines
Quoted 5 lines

Are there any existing users of it that rely on memory map provided by bootloader? What if image explicitly requested non-optional memory map? According to multiboot specification it is valid and bootloader must either provide requested information or fail load.

I think you have a point. @Daniel, is current behavior a problem for you?

Do you think about MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST tag? If yes it looks that multiboot2 doc is a bit imprecise and/or GRUB2 code is wrong.

multiboot2 doc says:

[...]

If this tag is present and ‘optional’ is set to ‘0’ information conveyed by requested tag types must be present. If bootloader is unable to supply this information it must fail with an error
Note: it doesn’t garantee that any tags of type ‘mbi_tag_types’ will actually be present. E.g. on a videoless system even if you requested tag ‘8’ no tags of type ‘8’ will be present in mbi.

[...]

However, grub_multiboot_load() just looks for MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST tag. If it exists and if ‘optional’ is set to ‘0’ then grub_multiboot_load() verify list of requested tags. If unknown value is found then multiboot2 command fails with "grub_error (GRUB_ERR_UNKNOWN_OS, "unsupported information tag: 0x%x", ...". I cannot find additional checks anywhere...

So, AIUI, "If bootloader is unable to supply..." should be read as "If bootloader does not support..." or even "If bootloader do not understand..." or something like that. This does not mean that bootloader must have requested data in hand and provide it to image. It means that bootloader must understand what image ask for. And in this term my patch does not violate spec implied by implementation (well, multiboot2 doc makes some confusion; see below). Image may ask/request for any memory map. However, if a given map (or set of maps) is not available or it could be provided but could make confusion in some cases then it can/should not be provided.

Anyway, I think that maybe multiboot2 doc should be fixed and more precise MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST tag description should be provided. Or GRUB2 implementation is wrong then...

Quoted 1 line

Don't you just ignore the memory map in this case?

Yes to some extent. However, I think that loader should not provide data which is known as (potentially) incorrect/faulty.

Daniel

#29 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

In reply to Vladimir 'phcoder' Serbinenko

15.03.2016 19:07, Vladimir 'phcoder' Serbinenko пишет:

Quoted 13 lines

Looks good. Let's give a day for others to comment. Is the second email the version for commit?

Quoted 8 lines · Daniel Kiper

Do not pass memory maps to image if it asked for EFI boot services. Main reason for not providing maps is because they will likely be invalid. We do a few allocations after filling them, e.g. for relocator needs. Usually we do not care as we would already finish boot services. If we keep boot services then it is easier to not provide maps. However, if image needs memory maps and they are not provided by bootloader then it should get them itself just before ExitBootServices() call.

Are there any existing users of it that rely on memory map provided by bootloader? What if image explicitly requested non-optional memory map? According to multiboot specification it is valid and bootloader must either provide requested information or fail load.

Quoted 127 lines
Quoted 127 lines
Signed-off-by Daniel Kiper <[email protected] <javascript:;>>
Reviewed-by Konrad Rzeszutek Wilk <[email protected] <javascript:;>>

---
v3 - suggestions/fixes:
- improve commit message
(suggested by Konrad Rzeszutek Wilk and Vladimir 'phcoder'
Serbinenko).

---
 grub-core/loader/multiboot_mbi2.c |   71
++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 36 deletions(-)
grub-core/loader/multiboot_mbi2.c +8 -7
index 6c04402..ad1553b 100644
@@ -390,7 +390,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)
@@ -755,12 +755,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
grub-core/loader/multiboot_mbi2.c +27 -29
@@ -776,18 +777,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;
@@ -886,27 +888,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);
   }
Quoted 6 lines
Quoted 5 lines

if (keep_bs)
--
1.7.10.4

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

#30 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

In reply to Vladimir 'phcoder' Serbinenko
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

Looks good. Let's give a day for others to comment. Is the second email the version for commit?

Yep, as you asked for.

Daniel

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

#31 lore raw

Re: [GRUB2 PATCH v4 3/4 - FOR REVIEW ONLY] multiboot2: Do not pass memory maps to image if EFI boot services are enabled

In reply to Vladimir 'phcoder' Serbinenko
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

Looks good. Let's give a day for others to comment. Is the second email the version for commit?

Yep, as you asked for.

Daniel

#32 lore raw

PATCH v4 4/4 multiboot2: Add support for relocatable images

In reply to Daniel Kiper

Currently multiboot2 protocol loads image exactly at address specified in ELF or multiboot2 header. This solution works quite well on legacy BIOS platforms. It is possible because memory regions are placed at predictable addresses (though I was not able to find any spec which says that it is strong requirement, so, it looks that it is just a goodwill of hardware designers). However, EFI platforms are more volatile. Even if required memory regions live at specific addresses then they are sometimes simply not free (e.g. used by boot/runtime services on Dell PowerEdge R820 and OVMF). This means that you are not able to just set up final image destination on build time. You have to provide method to relocate image contents to real load address which is usually different than load address specified in ELF and multiboot2 headers.

This patch provides all needed machinery to do self relocation in image code. First of all GRUB2 reads min_addr (min. load addr), max_addr (max. load addr), align (required image alignment), preference (it says which memory regions are preferred by image, e.g. none, low, high) from multiboot_header_tag_relocatable header tag contained in binary (at this stage load addresses from multiboot2 and/or ELF headers are ignored). Later loader tries to fulfill request (not only that one) and if it succeeds then it informs image about real load address via multiboot_tag_load_base_addr tag. At this stage GRUB2 role is finished. Starting from now executable must cope with relocations itself using whole static and dynamic knowledge provided by boot loader.

This patch does not provide functionality which could do relocations using ELF relocation data. However, I was asked by Konrad Rzeszutek Wilk and Vladimir 'phcoder' Serbinenko to investigate that thing. It looks that relevant machinery could be added to existing code (including this patch) without huge effort. Additionally, ELF relocation could live in parallel with self relocation provided by this patch. However, during research I realized that first of all we should establish the details how ELF relocatable image should look like and how it should be build. At least to build proper test/example files.

So, this patch just provides support for self relocatable images. If ELF file with relocs is loaded then GRUB2 complains loudly and ignores it. Support for such files will be added later.

This patch was tested with Xen image which uses that functionality. However, this Xen feature is still under development and new patchset will be released in about 3-4 weeks.

---
v4 - suggestions/fixes:
- pack grub_multiboot_load_elf() arguments into struct (suggested by Juergen Gross, Konrad Rzeszutek Wilk and Vladimir 'phcoder' Serbinenko),
- fix entry point address calculation (suggested by Vladimir 'phcoder' Serbinenko),
- fail if ELF file has relocs sections (suggested by Vladimir 'phcoder' Serbinenko).

v3 - suggestions/fixes:
- reduce number of casts
(suggested by Konrad Rzeszutek Wilk),
- remove unneeded space at the end of line
(suggested by Konrad Rzeszutek Wilk),
- improve commit message
(suggested by Konrad Rzeszutek Wilk).

---
 grub-core/loader/i386/multiboot_mbi.c |   13 ++++-
 grub-core/loader/multiboot.c          |   11 ++--
 grub-core/loader/multiboot_elfxx.c    |   52 +++++++++++------
 grub-core/loader/multiboot_mbi2.c     |   98 ++++++++++++++++++++++++++-------
 include/grub/multiboot.h              |   22 +++++++-
 include/multiboot2.h                  |   24 ++++++++
 6 files changed, 172 insertions(+), 48 deletions(-)
grub-core/loader/i386/multiboot_mbi.c +11 -2
index f60b702..fd7b41b 100644
@@ -70,9 +70,18 @@ load_kernel (grub_file_t file, const char *filename,
 	     char *buffer, struct multiboot_header *header)
 {
   grub_err_t err;
+  mbi_load_data_t mld;
+
+  mld.file = file;
+  mld.filename = filename;
+  mld.buffer = buffer;
+  mld.mbi_ver = 1;
+  mld.relocatable = 0;
+  mld.avoid_efi_boot_services = 0;
+
   if (grub_multiboot_quirks & GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE)
     {
-      err = grub_multiboot_load_elf (file, filename, buffer);
+      err = grub_multiboot_load_elf (&mld);
       if (err == GRUB_ERR_NONE) {
 	return GRUB_ERR_NONE;
       }
@@ -121,7 +130,7 @@ 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 (&mld);
 }
 
 static struct multiboot_header *
grub-core/loader/multiboot.c +5 -6
index 18038fd..bd9d5b3 100644
@@ -207,13 +207,12 @@ 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)
+grub_multiboot_load_elf (mbi_load_data_t *mld)
 {
-  if (grub_multiboot_is_elf32 (buffer))
-    return grub_multiboot_load_elf32 (file, filename, buffer);
-  else if (grub_multiboot_is_elf64 (buffer))
-    return grub_multiboot_load_elf64 (file, filename, buffer);
+  if (grub_multiboot_is_elf32 (mld->buffer))
+    return grub_multiboot_load_elf32 (mld);
+  else if (grub_multiboot_is_elf64 (mld->buffer))
+    return grub_multiboot_load_elf64 (mld);
 
   return grub_error (GRUB_ERR_UNKNOWN_OS, N_("invalid arch-dependent ELF magic"));
 }
grub-core/loader/multiboot_elfxx.c +34 -18

132 lines not on this page · raw message

grub-core/loader/multiboot_mbi2.c +78 -20

216 lines not on this page · raw message

include/grub/multiboot.h +20 -2
index e13c084..c96492b 100644
@@ -91,10 +91,28 @@ grub_multiboot_set_console (int console_type, int accepted_consoles,
 			    int console_required);
 grub_err_t
 grub_multiboot_load (grub_file_t file, const char *filename);
+
+struct mbi_load_data
+{
+  grub_file_t file;
+  const char *filename;
+  void *buffer;
+  unsigned int mbi_ver;
+  int relocatable;
+  grub_uint32_t min_addr;
+  grub_uint32_t max_addr;
+  grub_size_t align;
+  grub_uint32_t preference;
+  grub_uint32_t link_base_addr;
+  grub_uint32_t load_base_addr;
+  int avoid_efi_boot_services;
+};
+typedef struct mbi_load_data mbi_load_data_t;
+
 /* Load ELF32 or ELF64.  */
 grub_err_t
-grub_multiboot_load_elf (grub_file_t file, const char *filename,
-			 void *buffer);
+grub_multiboot_load_elf (mbi_load_data_t *mld);
+
 extern grub_size_t grub_multiboot_pure_size;
 extern grub_size_t grub_multiboot_alloc_mbi;
 extern grub_uint32_t grub_multiboot_payload_eip;
include/multiboot2.h +24 -0
index f5bebe1..5a3db5a 100644
@@ -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_LOAD_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
 
@@ -161,6 +167,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;
@@ -387,6 +404,13 @@ struct multiboot_tag_efi64_ih
   multiboot_uint64_t pointer;
 };
 
+struct multiboot_tag_load_base_addr
+{
+  multiboot_uint32_t type;
+  multiboot_uint32_t size;
+  multiboot_uint32_t load_base_addr;
+};
+
 #endif /* ! ASM_FILE */
 
 #endif /* ! MULTIBOOT_HEADER */
Signature · 7 lines
1.7.10.4


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

Re: [GRUB2 PATCH v4 4/4] multiboot2: Add support for relocatable images

Quoted 15 lines
(quoted diff) +2 -0
+           if (mld->relocatable)
+             err = grub_relocator_alloc_chunk_align

(grub_multiboot_relocator, &ch,
+ mld->min_addr,
mld->max_addr - phdr(i)->p_memsz,
+ phdr(i)->p_memsz,
mld->align ? mld->align : 1,
+ mld->preference,
mld->avoid_efi_boot_services);

(quoted diff) +2 -0
+           else
+             err = grub_relocator_alloc_chunk_addr

(grub_multiboot_relocator,

grub-core/loader/multiboot_elfxx.c CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi · line 110

Quoted 2 lines
grub-core/loader/multiboot_elfxx.c +2 -0
+                                                    &ch, phdr(i)->p_paddr,
+                                                    phdr(i)->p_memsz);

I believe this is faulty if you have more than one PHDR. You load every PHDR individually to essentially random address. Pieces have no reasonable way to find each other. Moreover entry point calculation is also faulty. Imagine sth like this:
PHDR 1M-2M
PHDR 2M-5M
Entry point 2.5M (in second PHDR)
then if first PHDR is loaded to 1M and second to 10M then base and link addr are both 1M, so entry point will be calculated as 2.5M, which points to no segment. I see 2 solutions:
1) Look where entry falls in original layout, then adjust it in accordance with where this phdr will be loaded. This requires least efforts. Finding different PHDRs is still impossible but it will be possible in the future with relocations.
2) Allocate a buffer of size highest - lowest and load everything into this buffer keeping relative offsets. If we do this, then we need to document if it's required for boorloader to behave this way or not. If it is, we can in future provide a tag to say that image is fine with rearrangement of PHDR, if it ever becomes relevant (I heavily doubt it).
I guess that xen is a single phdr image and so essentially any code will work with it.
This problem appears in couple of other places, I'll skip commenting on them explicitly.

Quoted 10 lines
grub-core/loader/multiboot_mbi2.c +4 -0
+  if (mld.relocatable)
+    {
+      if (mld.load_base_addr >= mld.link_base_addr)
+       grub_multiboot_payload_eip += mld.load_base_addr -

mld.link_base_addr;

(quoted diff) +2 -0
+      else
+       grub_multiboot_payload_eip -= mld.link_base_addr -

mld.load_base_addr;
+ }

Both branches are mathematically equivalent. Any reason to have if at all?

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko

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

#34 lore raw

Re: [GRUB2 PATCH v4 4/4] multiboot2: Add support for relocatable images

In reply to Daniel Kiper
Quoted 15 lines
(quoted diff) +2 -0
+           if (mld->relocatable)
+             err = grub_relocator_alloc_chunk_align

(grub_multiboot_relocator, &ch,
+ mld->min_addr,
mld->max_addr - phdr(i)->p_memsz,
+ phdr(i)->p_memsz,
mld->align ? mld->align : 1,
+ mld->preference,
mld->avoid_efi_boot_services);

(quoted diff) +2 -0
+           else
+             err = grub_relocator_alloc_chunk_addr

(grub_multiboot_relocator,

grub-core/loader/multiboot_elfxx.c CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi · line 110

Quoted 2 lines
grub-core/loader/multiboot_elfxx.c +2 -0
+                                                    &ch, phdr(i)->p_paddr,
+                                                    phdr(i)->p_memsz);

I believe this is faulty if you have more than one PHDR. You load every PHDR individually to essentially random address. Pieces have no reasonable way to find each other. Moreover entry point calculation is also faulty. Imagine sth like this:
PHDR 1M-2M
PHDR 2M-5M
Entry point 2.5M (in second PHDR)
then if first PHDR is loaded to 1M and second to 10M then base and link addr are both 1M, so entry point will be calculated as 2.5M, which points to no segment. I see 2 solutions:
1) Look where entry falls in original layout, then adjust it in accordance with where this phdr will be loaded. This requires least efforts. Finding different PHDRs is still impossible but it will be possible in the future with relocations.
2) Allocate a buffer of size highest - lowest and load everything into this buffer keeping relative offsets. If we do this, then we need to document if it's required for boorloader to behave this way or not. If it is, we can in future provide a tag to say that image is fine with rearrangement of PHDR, if it ever becomes relevant (I heavily doubt it).
I guess that xen is a single phdr image and so essentially any code will work with it.
This problem appears in couple of other places, I'll skip commenting on them explicitly.

Quoted 10 lines
grub-core/loader/multiboot_mbi2.c +4 -0
+  if (mld.relocatable)
+    {
+      if (mld.load_base_addr >= mld.link_base_addr)
+       grub_multiboot_payload_eip += mld.load_base_addr -

mld.link_base_addr;

(quoted diff) +2 -0
+      else
+       grub_multiboot_payload_eip -= mld.link_base_addr -

mld.load_base_addr;
+ }

Both branches are mathematically equivalent. Any reason to have if at all?

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#35 lore raw

Re: [GRUB2 PATCH v4 4/4] multiboot2: Add support for relocatable images

Quoted 32 lines · Vladimir 'phcoder' Serbinenko
Quoted 12 lines
(quoted diff) +2 -0
+           if (mld->relocatable)
+             err = grub_relocator_alloc_chunk_align

(grub_multiboot_relocator, &ch,
+ mld->min_addr,
mld->max_addr - phdr(i)->p_memsz,
+ phdr(i)->p_memsz,
mld->align ? mld->align : 1,
+ mld->preference,
mld->avoid_efi_boot_services);

(quoted diff) +2 -0
+           else
+             err = grub_relocator_alloc_chunk_addr
Quoted 5 lines

(grub_multiboot_relocator,
+ &ch,
phdr(i)->p_paddr,
+ phdr(i)->p_memsz);

I believe this is faulty if you have more than one PHDR. You load every PHDR individually to essentially random address. Pieces have no reasonable way to find each other. Moreover entry point calculation is also faulty. Imagine sth like this:
PHDR 1M-2M
PHDR 2M-5M
Entry point 2.5M (in second PHDR)
then if first PHDR is loaded to 1M and second to 10M then base and link addr are both 1M, so entry point will be calculated as 2.5M, which points to no segment. I see 2 solutions:
1) Look where entry falls in original layout, then adjust it in accordance with where this phdr will be loaded. This requires least efforts. Finding different PHDRs is still impossible but it will be possible in the future with relocations.
2) Allocate a buffer of size highest - lowest and load everything into

Quoted 9 lines

this buffer keeping relative offsets. If we do this, then we need to document if it's required for boorloader to behave this way or not. If it is, we can in future provide a tag to say that image is fine with rearrangement of PHDR, if it ever becomes relevant (I heavily doubt it). I guess that xen is a single phdr image and so essentially any code will work with it.
This problem appears in couple of other places, I'll skip commenting on them explicitly.

I take back the part "requires least effort" for solution 1. Solution 2 is probably simpler and less error-prone as developper doesn't control if binutils decode to put several phdrs.

Quoted 18 lines

+ if (mld.relocatable)

Quoted 9 lines
grub-core/loader/multiboot_mbi2.c +3 -0
+    {
+      if (mld.load_base_addr >= mld.link_base_addr)
+       grub_multiboot_payload_eip += mld.load_base_addr -

mld.link_base_addr;

(quoted diff) +2 -0
+      else
+       grub_multiboot_payload_eip -= mld.link_base_addr -

mld.load_base_addr;
+ }

Both branches are mathematically equivalent. Any reason to have if at all?

--
Regards
Vladimir 'phcoder' Serbinenko

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko

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

#36 lore raw

Re: [GRUB2 PATCH v4 4/4] multiboot2: Add support for relocatable images

In reply to Vladimir 'phcoder' Serbinenko
Quoted 32 lines · Vladimir 'phcoder' Serbinenko
Quoted 12 lines
(quoted diff) +2 -0
+           if (mld->relocatable)
+             err = grub_relocator_alloc_chunk_align

(grub_multiboot_relocator, &ch,
+ mld->min_addr,
mld->max_addr - phdr(i)->p_memsz,
+ phdr(i)->p_memsz,
mld->align ? mld->align : 1,
+ mld->preference,
mld->avoid_efi_boot_services);

(quoted diff) +2 -0
+           else
+             err = grub_relocator_alloc_chunk_addr
Quoted 5 lines

(grub_multiboot_relocator,
+ &ch,
phdr(i)->p_paddr,
+ phdr(i)->p_memsz);

I believe this is faulty if you have more than one PHDR. You load every PHDR individually to essentially random address. Pieces have no reasonable way to find each other. Moreover entry point calculation is also faulty. Imagine sth like this:
PHDR 1M-2M
PHDR 2M-5M
Entry point 2.5M (in second PHDR)
then if first PHDR is loaded to 1M and second to 10M then base and link addr are both 1M, so entry point will be calculated as 2.5M, which points to no segment. I see 2 solutions:
1) Look where entry falls in original layout, then adjust it in accordance with where this phdr will be loaded. This requires least efforts. Finding different PHDRs is still impossible but it will be possible in the future with relocations.
2) Allocate a buffer of size highest - lowest and load everything into

Quoted 9 lines

this buffer keeping relative offsets. If we do this, then we need to document if it's required for boorloader to behave this way or not. If it is, we can in future provide a tag to say that image is fine with rearrangement of PHDR, if it ever becomes relevant (I heavily doubt it). I guess that xen is a single phdr image and so essentially any code will work with it.
This problem appears in couple of other places, I'll skip commenting on them explicitly.

I take back the part "requires least effort" for solution 1. Solution 2 is probably simpler and less error-prone as developper doesn't control if binutils decode to put several phdrs.

Quoted 18 lines

+ if (mld.relocatable)

Quoted 9 lines
grub-core/loader/multiboot_mbi2.c +3 -0
+    {
+      if (mld.load_base_addr >= mld.link_base_addr)
+       grub_multiboot_payload_eip += mld.load_base_addr -

mld.link_base_addr;

(quoted diff) +2 -0
+      else
+       grub_multiboot_payload_eip -= mld.link_base_addr -

mld.load_base_addr;
+ }

Both branches are mathematically equivalent. Any reason to have if at all?

--
Regards
Vladimir 'phcoder' Serbinenko

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#37 lore raw

Re: [GRUB2 PATCH v4 4/4] multiboot2: Add support for relocatable images

Quoted 20 lines · Vladimir 'phcoder' Serbinenko
Quoted 17 lines · Vladimir 'phcoder' Serbinenko
Quoted 17 lines
(quoted diff) +2 -0
+           if (mld->relocatable)
+             err = grub_relocator_alloc_chunk_align

(grub_multiboot_relocator, &ch,
+ mld->min_addr,
mld->max_addr - phdr(i)->p_memsz,
+ phdr(i)->p_memsz,
mld->align ? mld->align : 1,
+ mld->preference,
mld->avoid_efi_boot_services);

(quoted diff) +2 -0
+           else
+             err = grub_relocator_alloc_chunk_addr

(grub_multiboot_relocator,
+ &ch,
phdr(i)->p_paddr,
+ phdr(i)->p_memsz);

Quoted 1 line
Quoted 1 line

I believe this is faulty if you have more than one PHDR. You load every

Argh... You are right!

Quoted 5 lines
Quoted 5 lines

PHDR individually to essentially random address. Pieces have no reasonable way to find each other. Moreover entry point calculation is also faulty. Imagine sth like this:
PHDR 1M-2M
PHDR 2M-5M

Quoted 8 lines
Quoted 8 lines

Entry point 2.5M (in second PHDR)
then if first PHDR is loaded to 1M and second to 10M then base and link addr are both 1M, so entry point will be calculated as 2.5M, which points to no segment. I see 2 solutions:
1) Look where entry falls in original layout, then adjust it in accordance with where this phdr will be loaded. This requires least efforts. Finding different PHDRs is still impossible but it will be possible in the future with relocations.

It looks that we should store somewhere and export to image via relevant tags link addresses and load addresses. Hmmm... Maybe we should just provide load addresses to image. Image can have link addresses in its data. And this probably does not require huge changes.

Quoted 10 lines
Quoted 10 lines

2) Allocate a buffer of size highest - lowest and load everything into this buffer keeping relative offsets. If we do this, then we need to document if it's required for boorloader to behave this way or not. If it is, we can in future provide a tag to say that image is fine with rearrangement of PHDR, if it ever becomes relevant (I heavily doubt it). I guess that xen is a single phdr image and so essentially any code will work with it.
This problem appears in couple of other places, I'll skip commenting on them explicitly.

Quoted 3 lines

I take back the part "requires least effort" for solution 1. Solution 2 is probably simpler and less error-prone as developper doesn't control if binutils decode to put several phdrs.

#2 looks promising but what if PHDR_1 is at 1 MiB - 2 MiB and PHDR_2 is at 808 MiB - 809 MiB? Then we will allocate more than 800 MiB just for an unusable hole. So, I think that we should go that way if solution #1 is too complicated.

Quoted 11 lines
Quoted 11 lines

+ if (mld.relocatable)

Quoted 9 lines
grub-core/loader/multiboot_mbi2.c +3 -0
+    {
+      if (mld.load_base_addr >= mld.link_base_addr)
+       grub_multiboot_payload_eip += mld.load_base_addr -

mld.link_base_addr;

(quoted diff) +2 -0
+      else
+       grub_multiboot_payload_eip -= mld.link_base_addr -

mld.load_base_addr;
+ }

Both branches are mathematically equivalent. Any reason to have if at all?

Yep, you are right. However, it looks that real life (C?) is more complicated. I am trying to avoid wrap around here if mld.load_base_addr < mld.link_base_addr. If you look at C operator precedence then everything should work. However, I am not 100% sure that a given compiler will not optimize/break my stuff. So, maybe we should use signed 64-bit int here.

Daniel

#38 lore raw

Re: [GRUB2 PATCH v4 4/4] multiboot2: Add support for relocatable images

Quoted 39 lines · Daniel Kiper
Quoted 20 lines · Vladimir 'phcoder' Serbinenko
Quoted 17 lines · Vladimir 'phcoder' Serbinenko
Quoted 17 lines
(quoted diff) +2 -0
+           if (mld->relocatable)
+             err = grub_relocator_alloc_chunk_align

(grub_multiboot_relocator, &ch,
+ mld->min_addr,
mld->max_addr - phdr(i)->p_memsz,
+ phdr(i)->p_memsz,
mld->align ? mld->align : 1,
+ mld->preference,
mld->avoid_efi_boot_services);

(quoted diff) +2 -0
+           else
+             err = grub_relocator_alloc_chunk_addr

(grub_multiboot_relocator,
+ &ch,
phdr(i)->p_paddr,
+ phdr(i)->p_memsz);

Quoted 1 line
Quoted 1 line

I believe this is faulty if you have more than one PHDR. You load every

Argh... You are right!

Quoted 5 lines
Quoted 5 lines

PHDR individually to essentially random address. Pieces have no reasonable way to find each other. Moreover entry point calculation is also faulty. Imagine sth like this:
PHDR 1M-2M
PHDR 2M-5M

Quoted 8 lines
Quoted 8 lines

Entry point 2.5M (in second PHDR)
then if first PHDR is loaded to 1M and second to 10M then base and link addr are both 1M, so entry point will be calculated as 2.5M, which points to no segment. I see 2 solutions:
1) Look where entry falls in original layout, then adjust it in accordance with where this phdr will be loaded. This requires least efforts. Finding different PHDRs is still impossible but it will be possible in the future with relocations.

Quoted 12 lines

It looks that we should store somewhere and export to image via relevant tags link addresses and load addresses. Hmmm... Maybe we should just provide load addresses to image. Image can have link addresses in its data. And this probably does not require huge changes.

Quoted 7 lines
Quoted 7 lines

2) Allocate a buffer of size highest - lowest and load everything into this buffer keeping relative offsets. If we do this, then we need to document if it's required for boorloader to behave this way or not. If it is, we can in future provide a tag to say that image is fine with rearrangement of PHDR, if it ever becomes relevant (I heavily doubt it). I guess that xen is a single phdr image and so essentially any code will work with it.

Won't be in Xen 4.7.

Quoted 11 lines
Quoted 6 lines
Quoted 3 lines

This problem appears in couple of other places, I'll skip commenting on them explicitly.

I take back the part "requires least effort" for solution 1. Solution 2 is probably simpler and less error-prone as developper doesn't control if binutils decode to put several phdrs.

#2 looks promising but what if PHDR_1 is at 1 MiB - 2 MiB and PHDR_2 is at 808 MiB - 809 MiB? Then we will allocate more than 800 MiB just for an unusable hole. So, I think that we should go that way if solution #1 is too complicated.

Daniel, my xSplice patches make the Xen have two ELF PHDRS: 1)the PT_LOAD and 2) PT_NOTE (which points to smack in the .text section) so you can try that as an example payload.

(If you want to put your patches on top of mine:
git://xenbits.xen.org/people/konradwilk/xen.git #xsplice.v4)

Quoted 13 lines
Quoted 11 lines
Quoted 11 lines

+ if (mld.relocatable)

Quoted 9 lines
grub-core/loader/multiboot_mbi2.c +3 -0
+    {
+      if (mld.load_base_addr >= mld.link_base_addr)
+       grub_multiboot_payload_eip += mld.load_base_addr -

mld.link_base_addr;

(quoted diff) +2 -0
+      else
+       grub_multiboot_payload_eip -= mld.link_base_addr -

mld.load_base_addr;
+ }

Quoted 1 line
Quoted 1 line

Both branches are mathematically equivalent. Any reason to have if at all?

Quoted 7 lines

Yep, you are right. However, it looks that real life (C?) is more complicated. I am trying to avoid wrap around here if mld.load_base_addr < mld.link_base_addr. If you look at C operator precedence then everything should work. However, I am not 100% sure that a given compiler will not optimize/break my stuff. So, maybe we should use signed 64-bit int here.

Daniel

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

#39 lore raw

Re: [GRUB2 PATCH v4 4/4] multiboot2: Add support for relocatable images

Quoted 66 lines · Konrad Rzeszutek Wilk
Quoted 39 lines · Daniel Kiper
Quoted 20 lines · Vladimir 'phcoder' Serbinenko
Quoted 17 lines · Vladimir 'phcoder' Serbinenko
Quoted 17 lines
(quoted diff) +2 -0
+           if (mld->relocatable)
+             err = grub_relocator_alloc_chunk_align

(grub_multiboot_relocator, &ch,
+ mld->min_addr,
mld->max_addr - phdr(i)->p_memsz,
+ phdr(i)->p_memsz,
mld->align ? mld->align : 1,
+ mld->preference,
mld->avoid_efi_boot_services);

(quoted diff) +2 -0
+           else
+             err = grub_relocator_alloc_chunk_addr

(grub_multiboot_relocator,
+ &ch,
phdr(i)->p_paddr,
+ phdr(i)->p_memsz);

Quoted 1 line
Quoted 1 line

I believe this is faulty if you have more than one PHDR. You load every

Argh... You are right!

Quoted 5 lines
Quoted 5 lines

PHDR individually to essentially random address. Pieces have no reasonable way to find each other. Moreover entry point calculation is also faulty. Imagine sth like this:
PHDR 1M-2M
PHDR 2M-5M

Quoted 8 lines
Quoted 8 lines

Entry point 2.5M (in second PHDR)
then if first PHDR is loaded to 1M and second to 10M then base and link addr are both 1M, so entry point will be calculated as 2.5M, which points to no segment. I see 2 solutions:
1) Look where entry falls in original layout, then adjust it in accordance with where this phdr will be loaded. This requires least efforts. Finding different PHDRs is still impossible but it will be possible in the future with relocations.

Quoted 12 lines

It looks that we should store somewhere and export to image via relevant tags link addresses and load addresses. Hmmm... Maybe we should just provide load addresses to image. Image can have link addresses in its data. And this probably does not require huge changes.

Quoted 7 lines
Quoted 7 lines

2) Allocate a buffer of size highest - lowest and load everything into this buffer keeping relative offsets. If we do this, then we need to document if it's required for boorloader to behave this way or not. If it is, we can in future provide a tag to say that image is fine with rearrangement of PHDR, if it ever becomes relevant (I heavily doubt it). I guess that xen is a single phdr image and so essentially any code will work with it.

Won't be in Xen 4.7.

Quoted 11 lines
Quoted 6 lines
Quoted 3 lines

This problem appears in couple of other places, I'll skip commenting on them explicitly.

I take back the part "requires least effort" for solution 1. Solution 2 is probably simpler and less error-prone as developper doesn't control if binutils decode to put several phdrs.

#2 looks promising but what if PHDR_1 is at 1 MiB - 2 MiB and PHDR_2 is at 808 MiB - 809 MiB? Then we will allocate more than 800 MiB just for an unusable hole. So, I think that we should go that way if solution #1 is too complicated.

Quoted 6 lines

Daniel, my xSplice patches make the Xen have two ELF PHDRS: 1)the PT_LOAD and 2) PT_NOTE (which points to smack in the .text section) so you can try that as an example payload.

(If you want to put your patches on top of mine:
git://xenbits.xen.org/people/konradwilk/xen.git #xsplice.v4)

Thanks, but multiboot2 loads just PT_LOAD segments.

Daniel

#40 lore raw

Re: [GRUB2 PATCH v4 4/4] multiboot2: Add support for relocatable images

In reply to Konrad Rzeszutek Wilk
Quoted 66 lines · Konrad Rzeszutek Wilk
Quoted 39 lines · Daniel Kiper
Quoted 20 lines · Vladimir 'phcoder' Serbinenko
Quoted 17 lines · Vladimir 'phcoder' Serbinenko
Quoted 17 lines
(quoted diff) +2 -0
+           if (mld->relocatable)
+             err = grub_relocator_alloc_chunk_align

(grub_multiboot_relocator, &ch,
+ mld->min_addr,
mld->max_addr - phdr(i)->p_memsz,
+ phdr(i)->p_memsz,
mld->align ? mld->align : 1,
+ mld->preference,
mld->avoid_efi_boot_services);

(quoted diff) +2 -0
+           else
+             err = grub_relocator_alloc_chunk_addr

(grub_multiboot_relocator,
+ &ch,
phdr(i)->p_paddr,
+ phdr(i)->p_memsz);

Quoted 1 line
Quoted 1 line

I believe this is faulty if you have more than one PHDR. You load every

Argh... You are right!

Quoted 5 lines
Quoted 5 lines

PHDR individually to essentially random address. Pieces have no reasonable way to find each other. Moreover entry point calculation is also faulty. Imagine sth like this:
PHDR 1M-2M
PHDR 2M-5M

Quoted 8 lines
Quoted 8 lines

Entry point 2.5M (in second PHDR)
then if first PHDR is loaded to 1M and second to 10M then base and link addr are both 1M, so entry point will be calculated as 2.5M, which points to no segment. I see 2 solutions:
1) Look where entry falls in original layout, then adjust it in accordance with where this phdr will be loaded. This requires least efforts. Finding different PHDRs is still impossible but it will be possible in the future with relocations.

Quoted 12 lines

It looks that we should store somewhere and export to image via relevant tags link addresses and load addresses. Hmmm... Maybe we should just provide load addresses to image. Image can have link addresses in its data. And this probably does not require huge changes.

Quoted 7 lines
Quoted 7 lines

2) Allocate a buffer of size highest - lowest and load everything into this buffer keeping relative offsets. If we do this, then we need to document if it's required for boorloader to behave this way or not. If it is, we can in future provide a tag to say that image is fine with rearrangement of PHDR, if it ever becomes relevant (I heavily doubt it). I guess that xen is a single phdr image and so essentially any code will work with it.

Won't be in Xen 4.7.

Quoted 11 lines
Quoted 6 lines
Quoted 3 lines

This problem appears in couple of other places, I'll skip commenting on them explicitly.

I take back the part "requires least effort" for solution 1. Solution 2 is probably simpler and less error-prone as developper doesn't control if binutils decode to put several phdrs.

#2 looks promising but what if PHDR_1 is at 1 MiB - 2 MiB and PHDR_2 is at 808 MiB - 809 MiB? Then we will allocate more than 800 MiB just for an unusable hole. So, I think that we should go that way if solution #1 is too complicated.

Quoted 6 lines

Daniel, my xSplice patches make the Xen have two ELF PHDRS: 1)the PT_LOAD and 2) PT_NOTE (which points to smack in the .text section) so you can try that as an example payload.

(If you want to put your patches on top of mine:
git://xenbits.xen.org/people/konradwilk/xen.git #xsplice.v4)

Thanks, but multiboot2 loads just PT_LOAD segments.

Daniel

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

#41 lore raw

Re: [GRUB2 PATCH v4 4/4] multiboot2: Add support for relocatable images

In reply to Daniel Kiper
Quoted 70 lines · Daniel Kiper
Quoted 1 line · Vladimir 'phcoder' Serbinenko

On Tuesday, March 15, 2016, Vladimir 'phcoder' Serbinenko <

[email protected] <javascript:;>>

Quoted 9 lines
Quoted 7 lines · wrote:
Quoted 7 lines
(quoted diff) +2 -0
+           if (mld->relocatable)
+             err = grub_relocator_alloc_chunk_align

(grub_multiboot_relocator, &ch,
+ mld->min_addr,
mld->max_addr - phdr(i)->p_memsz,
+

phdr(i)->p_memsz,

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

mld->align ? mld->align : 1,
+ mld->preference,
mld->avoid_efi_boot_services);

(quoted diff) +2 -0
+           else
+             err = grub_relocator_alloc_chunk_addr

(grub_multiboot_relocator,
+ &ch,
phdr(i)->p_paddr,
+

phdr(i)->p_memsz);

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

I believe this is faulty if you have more than one PHDR. You load every

Argh... You are right!

Quoted 1 line
Quoted 1 line

PHDR individually to essentially random address. Pieces have no

reasonable

Quoted 1 line
Quoted 1 line

way to find each other. Moreover entry point calculation is also

faulty.

Quoted 6 lines
Quoted 6 lines

Imagine sth like this:
PHDR 1M-2M
PHDR 2M-5M
Entry point 2.5M (in second PHDR)
then if first PHDR is loaded to 1M and second to 10M then base and link addr are both 1M, so entry point will be calculated as 2.5M, which

points

Quoted 2 lines
Quoted 2 lines

to no segment. I see 2 solutions:
1) Look where entry falls in original layout, then adjust it in

accordance

Quoted 1 line
Quoted 1 line

with where this phdr will be loaded. This requires least efforts.

Finding

Quoted 1 line
Quoted 1 line

different PHDRs is still impossible but it will be possible in the

future

Quoted 1 line
Quoted 1 line

with relocations.

It looks that we should store somewhere and export to image via relevant tags
link addresses and load addresses. Hmmm... Maybe we should just provide load
addresses to image. Image can have link addresses in its data. And this probably does not require huge changes.

Quoted 3 lines
Quoted 3 lines

2) Allocate a buffer of size highest - lowest and load everything into this buffer keeping relative offsets. If we do this, then we need to document if it's required for boorloader to behave this way or not. If

it

Quoted 2 lines
Quoted 2 lines

is, we can in future provide a tag to say that image is fine with rearrangement of PHDR, if it ever becomes relevant (I heavily doubt

it).

Quoted 1 line
Quoted 1 line

I guess that xen is a single phdr image and so essentially any code

will

Quoted 5 lines
Quoted 4 lines

work with it.
This problem appears in couple of other places, I'll skip commenting on them explicitly.

I take back the part "requires least effort" for solution 1. Solution 2

Quoted 9 lines

is

Quoted 2 lines

probably simpler and less error-prone as developper doesn't control if binutils decode to put several phdrs.

#2 looks promising but what if PHDR_1 is at 1 MiB - 2 MiB and PHDR_2 is at 808 MiB - 809 MiB? Then we will allocate more than 800 MiB just for an unusable hole. So, I think that we should go that way if solution #1 is too complicated.

If 'RELOCATABLE' means 'image is fine with any of its phdr going anywhere' then why would it declare such a layout if it's fine with second phdr going right after the first one? Why not describe the same thing as 1-2M and 2-3M?

Quoted 24 lines
Quoted 11 lines
Quoted 11 lines

+ if (mld.relocatable)

Quoted 9 lines
grub-core/loader/multiboot_mbi2.c +3 -0
+    {
+      if (mld.load_base_addr >= mld.link_base_addr)
+       grub_multiboot_payload_eip += mld.load_base_addr -

mld.link_base_addr;

(quoted diff) +2 -0
+      else
+       grub_multiboot_payload_eip -= mld.link_base_addr -

mld.load_base_addr;
+ }

Quoted 1 line
Quoted 1 line

Both branches are mathematically equivalent. Any reason to have if at

all?

Yep, you are right. However, it looks that real life (C?) is more complicated.
I am trying to avoid wrap around here if mld.load_base_addr < mld.link_base_addr.
If you look at C operator precedence then everything should work. However, I am not 100% sure that a given compiler will not optimize/break my stuff. So, maybe we should use signed 64-bit int here.

Daniel

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko

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

#42 lore raw

Re: [GRUB2 PATCH v4 4/4] multiboot2: Add support for relocatable images

In reply to Vladimir 'phcoder' Serbinenko
Quoted 20 lines · Vladimir 'phcoder' Serbinenko
Quoted 17 lines · Vladimir 'phcoder' Serbinenko
Quoted 17 lines
(quoted diff) +2 -0
+           if (mld->relocatable)
+             err = grub_relocator_alloc_chunk_align

(grub_multiboot_relocator, &ch,
+ mld->min_addr,
mld->max_addr - phdr(i)->p_memsz,
+ phdr(i)->p_memsz,
mld->align ? mld->align : 1,
+ mld->preference,
mld->avoid_efi_boot_services);

(quoted diff) +2 -0
+           else
+             err = grub_relocator_alloc_chunk_addr

(grub_multiboot_relocator,
+ &ch,
phdr(i)->p_paddr,
+ phdr(i)->p_memsz);

Quoted 1 line
Quoted 1 line

I believe this is faulty if you have more than one PHDR. You load every

Argh... You are right!

Quoted 5 lines
Quoted 5 lines

PHDR individually to essentially random address. Pieces have no reasonable way to find each other. Moreover entry point calculation is also faulty. Imagine sth like this:
PHDR 1M-2M
PHDR 2M-5M

Quoted 8 lines
Quoted 8 lines

Entry point 2.5M (in second PHDR)
then if first PHDR is loaded to 1M and second to 10M then base and link addr are both 1M, so entry point will be calculated as 2.5M, which points to no segment. I see 2 solutions:
1) Look where entry falls in original layout, then adjust it in accordance with where this phdr will be loaded. This requires least efforts. Finding different PHDRs is still impossible but it will be possible in the future with relocations.

It looks that we should store somewhere and export to image via relevant tags link addresses and load addresses. Hmmm... Maybe we should just provide load addresses to image. Image can have link addresses in its data. And this probably does not require huge changes.

Quoted 10 lines
Quoted 10 lines

2) Allocate a buffer of size highest - lowest and load everything into this buffer keeping relative offsets. If we do this, then we need to document if it's required for boorloader to behave this way or not. If it is, we can in future provide a tag to say that image is fine with rearrangement of PHDR, if it ever becomes relevant (I heavily doubt it). I guess that xen is a single phdr image and so essentially any code will work with it.
This problem appears in couple of other places, I'll skip commenting on them explicitly.

Quoted 3 lines

I take back the part "requires least effort" for solution 1. Solution 2 is probably simpler and less error-prone as developper doesn't control if binutils decode to put several phdrs.

#2 looks promising but what if PHDR_1 is at 1 MiB - 2 MiB and PHDR_2 is at 808 MiB - 809 MiB? Then we will allocate more than 800 MiB just for an unusable hole. So, I think that we should go that way if solution #1 is too complicated.

Quoted 11 lines
Quoted 11 lines

+ if (mld.relocatable)

Quoted 9 lines
grub-core/loader/multiboot_mbi2.c +3 -0
+    {
+      if (mld.load_base_addr >= mld.link_base_addr)
+       grub_multiboot_payload_eip += mld.load_base_addr -

mld.link_base_addr;

(quoted diff) +2 -0
+      else
+       grub_multiboot_payload_eip -= mld.link_base_addr -

mld.load_base_addr;
+ }

Both branches are mathematically equivalent. Any reason to have if at all?

Yep, you are right. However, it looks that real life (C?) is more complicated. I am trying to avoid wrap around here if mld.load_base_addr < mld.link_base_addr. If you look at C operator precedence then everything should work. However, I am not 100% sure that a given compiler will not optimize/break my stuff. So, maybe we should use signed 64-bit int here.

Daniel

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