grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>,
	seth.goldberg@oracle.com
Cc: The development of GNU GRUB <grub-devel@gnu.org>,
	keir@xen.org, ian.campbell@citrix.com,
	stefano.stabellini@eu.citrix.com,
	Daniel Kiper <daniel.kiper@oracle.com>,
	linux-kernel@vger.kernel.org, ross.philipson@citrix.com,
	jbeulich@suse.com, boris.ostrovsky@oracle.com,
	xen-devel@lists.xen.org, richard.l.maliszewski@intel.com,
	david.woodhouse@intel.com
Subject: Re: EFI and multiboot2 devlopment work for Xen
Date: Mon, 28 Oct 2013 12:26:03 -0400	[thread overview]
Message-ID: <20131028162603.GA4716@phenom.dumpdata.com> (raw)
In-Reply-To: <52663D54.2020800@gmail.com>

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

On Tue, Oct 22, 2013 at 10:54:44AM +0200, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 21.10.2013 23:16, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> > Mail is big, I think I got your essential points but I didn't read it whole.
> > On 21.10.2013 14:57, Daniel Kiper wrote:
> >> Hi,
> >>
> >> During work on multiboot2 protocol support for Xen it was discovered
> >> that memory map passed via relevant tag could not represent wide range
> >> of memory types available on EFI platforms. Additionally, GRUB2
> >> implementation calls ExitBootServices() on them just before jumping
> >> into loaded image. In this situation loaded system could not clearly
> >> identify reserved memory regions, EFI runtime services regions and others.
> >>
> > Will a multiboot2 tag with whole EFI memory map solve your problem?
> I added such a tag in documentation and wrote a patch for it (attached).
> Awaiting for someone to test it to commit

Great! I think from Xen perspective we first need to have Xen be able
to understand multiboot2 - that is something Daniel had been working on.
I will let Daniel talk more about it.

Seth, would you have any time to test the patch against Solaris to
make sure it works?

Thanks!
> 





[-- Attachment #2: efi.diff --]
[-- Type: text/plain, Size: 4747 bytes --]

=== modified file 'grub-core/loader/i386/multiboot_mbi.c'
--- grub-core/loader/i386/multiboot_mbi.c	2013-10-14 14:33:44 +0000
+++ grub-core/loader/i386/multiboot_mbi.c	2013-10-22 06:57:45 +0000
@@ -36,6 +36,10 @@
 #include <grub/net.h>
 #include <grub/i18n.h>
 
+#ifdef GRUB_MACHINE_EFI
+#include <grub/efi/efi.h>
+#endif
+
 /* The bits in the required part of flags field we don't support.  */
 #define UNSUPPORTED_FLAGS			0x0000fff8
 
@@ -579,6 +583,12 @@
   ptrdest += sizeof (struct grub_vbe_mode_info_block);
 #endif
 
+#ifdef GRUB_MACHINE_EFI
+  err = grub_efi_finish_boot_services (NULL, NULL, NULL, NULL, NULL);
+  if (err)
+    return err;
+#endif
+
   return GRUB_ERR_NONE;
 }
 

=== modified file 'grub-core/loader/multiboot.c'
--- grub-core/loader/multiboot.c	2013-09-23 11:35:33 +0000
+++ grub-core/loader/multiboot.c	2013-10-22 06:51:30 +0000
@@ -131,12 +131,6 @@
   if (err)
     return err;
 
-#ifdef GRUB_MACHINE_EFI
-  err = grub_efi_finish_boot_services (NULL, NULL, NULL, NULL, NULL);
-  if (err)
-    return err;
-#endif
-
 #if defined (__i386__) || defined (__x86_64__)
   grub_relocator32_boot (grub_multiboot_relocator, state, 0);
 #else

=== modified file 'grub-core/loader/multiboot_mbi2.c'
--- grub-core/loader/multiboot_mbi2.c	2013-10-14 14:33:44 +0000
+++ grub-core/loader/multiboot_mbi2.c	2013-10-22 06:57:58 +0000
@@ -295,9 +295,55 @@
 #endif
 }
 
+#ifdef GRUB_MACHINE_EFI
+
+static grub_efi_uintn_t efi_mmap_size = 0;
+
+/* Find the optimal number of pages for the memory map. Is it better to
+   move this code to efi/mm.c?  */
+static void
+find_efi_mmap_size (void)
+{
+  efi_mmap_size = (1 << 12);
+  while (1)
+    {
+      int ret;
+      grub_efi_memory_descriptor_t *mmap;
+      grub_efi_uintn_t desc_size;
+      grub_efi_uintn_t cur_mmap_size = efi_mmap_size;
+
+      mmap = grub_malloc (cur_mmap_size);
+      if (! mmap)
+	return;
+
+      ret = grub_efi_get_memory_map (&cur_mmap_size, mmap, 0, &desc_size, 0);
+      grub_free (mmap);
+
+      if (ret < 0)
+	return;
+      else if (ret > 0)
+	break;
+
+      if (efi_mmap_size < cur_mmap_size)
+	efi_mmap_size = cur_mmap_size;
+      efi_mmap_size += (1 << 12);
+    }
+
+  /* Increase the size a bit for safety, because GRUB allocates more on
+     later, and EFI itself may allocate more.  */
+  efi_mmap_size += (3 << 12);
+
+  efi_mmap_size = ALIGN_UP (efi_mmap_size, 4096);
+}
+#endif
+
 static grub_size_t
 grub_multiboot_get_mbi_size (void)
 {
+#ifdef GRUB_MACHINE_EFI
+  if (!efi_mmap_size)
+    find_efi_mmap_size ();    
+#endif
   return 2 * sizeof (grub_uint32_t) + sizeof (struct multiboot_tag)
     + (sizeof (struct multiboot_tag_string)
        + ALIGN_UP (cmdline_size, MULTIBOOT_TAG_ALIGN))
@@ -318,6 +364,10 @@
     + ALIGN_UP (sizeof (struct multiboot_tag_old_acpi)
 		+ sizeof (struct grub_acpi_rsdp_v10), MULTIBOOT_TAG_ALIGN)
     + acpiv2_size ()
+#ifdef GRUB_MACHINE_EFI
+    + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap)
+		+ efi_mmap_size, MULTIBOOT_TAG_ALIGN)
+#endif
     + sizeof (struct multiboot_tag_vbe) + MULTIBOOT_TAG_ALIGN - 1
     + sizeof (struct multiboot_tag_apm) + MULTIBOOT_TAG_ALIGN - 1;
 }
@@ -760,6 +810,28 @@
   }
 #endif
 
+#ifdef GRUB_MACHINE_EFI
+  {
+    struct multiboot_tag_efi_mmap *tag = (struct multiboot_tag_efi_mmap *) ptrorig;
+    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;
+
+    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);
+  }
+#endif
+
   {
     struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
     tag->type = MULTIBOOT_TAG_TYPE_END;

=== modified file 'include/multiboot2.h'
--- include/multiboot2.h	2010-09-21 00:06:14 +0000
+++ include/multiboot2.h	2013-10-22 06:37:55 +0000
@@ -58,6 +58,7 @@
 #define MULTIBOOT_TAG_TYPE_ACPI_OLD          14
 #define MULTIBOOT_TAG_TYPE_ACPI_NEW          15
 #define MULTIBOOT_TAG_TYPE_NETWORK           16
+#define MULTIBOOT_TAG_TYPE_EFI_MMAP          17
 
 #define MULTIBOOT_HEADER_TAG_END  0
 #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
@@ -361,6 +362,15 @@
   multiboot_uint8_t dhcpack[0];
 };
 
+struct multiboot_tag_efi_mmap
+{
+  multiboot_uint32_t type;
+  multiboot_uint32_t size;
+  multiboot_uint32_t descr_size;
+  multiboot_uint32_t descr_vers;
+  multiboot_uint8_t efi_mmap[0];
+}; 
+
 #endif /* ! ASM_FILE */
 
 #endif /* ! MULTIBOOT_HEADER */


  parent reply	other threads:[~2013-10-28 16:27 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-21 12:57 EFI and multiboot2 devlopment work for Xen Daniel Kiper
2013-10-21 13:36 ` Jan Beulich
2013-10-21 14:23   ` Konrad Rzeszutek Wilk
2013-10-21 14:37     ` Jan Beulich
2013-10-21 18:46       ` Daniel Kiper
2013-10-22  7:16         ` Jan Beulich
2013-10-21 18:39   ` Daniel Kiper
2013-10-22  7:15     ` Jan Beulich
2013-10-21 13:54 ` Peter Jones
2013-10-21 18:57   ` Daniel Kiper
2013-10-22  9:26     ` Ian Campbell
2013-10-22  9:31       ` Jan Beulich
2013-10-22  9:45         ` Ian Campbell
2013-10-22  9:59           ` Jan Beulich
2013-10-22 13:42             ` Konrad Rzeszutek Wilk
2013-10-22 13:53               ` Ian Campbell
2013-10-22 14:09                 ` Konrad Rzeszutek Wilk
2013-10-22 14:24                   ` Ian Campbell
2013-10-22 14:51                     ` Konrad Rzeszutek Wilk
2013-10-22 14:59                       ` Jan Beulich
2013-10-22 15:35                       ` Peter Jones
2013-10-22 15:39                       ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-10-22 16:31                         ` Konrad Rzeszutek Wilk
2013-10-22 15:22                     ` [Xen-devel] " Ian Campbell
2013-10-22 16:26                       ` Konrad Rzeszutek Wilk
2013-10-23  8:32                         ` Ian Campbell
2013-10-23 13:13                           ` Konrad Rzeszutek Wilk
2013-10-23 14:07                             ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-10-23 17:13                               ` Andrey Borzenkov
2013-10-23 16:17                             ` Jan Beulich
2013-10-23 16:14                           ` Jan Beulich
2013-10-23 17:01                             ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-10-24  6:53                               ` Jan Beulich
2013-10-22 14:10                 ` Jan Beulich
2013-10-22 14:18                 ` Woodhouse, David
2013-10-22 14:57                   ` Konrad Rzeszutek Wilk
2013-10-22 15:21                     ` Ian Campbell
2013-10-22 16:24                       ` Konrad Rzeszutek Wilk
2013-10-22 16:27                         ` Ian Campbell
2013-10-22 15:23                   ` Ian Campbell
2013-10-22 14:43               ` Konrad Rzeszutek Wilk
2013-10-22 15:25                 ` Woodhouse, David
2013-10-22 15:32                   ` Matthew Garrett
2013-10-22 15:42                     ` Woodhouse, David
2013-10-22 16:01                       ` Daniel Kiper
2013-10-22 16:08                         ` Ian Campbell
2013-10-22 16:14                           ` Daniel Kiper
2013-10-22 16:25                             ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-10-22 16:31                               ` Ian Campbell
2013-10-22 16:38                             ` Konrad Rzeszutek Wilk
2013-10-22 16:24                         ` Vladimir 'φ-coder/phcoder' Serbinenko
     [not found]                           ` <CE8BF72A.243C%richard.l.maliszewski@intel.com>
2013-10-22 16:51                             ` Daniel Kiper
2013-10-22 17:09                               ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-10-22 17:21                               ` Maliszewski, Richard L
2013-10-23  7:53                                 ` Daniel Kiper
2013-10-22 16:35                   ` Konrad Rzeszutek Wilk
2013-10-23  6:49                     ` Michael Chang
2013-10-23  6:51                       ` Michael Chang
2013-10-23  6:56               ` Daniel Kiper
2013-10-21 20:53 ` Seth Goldberg
2013-10-21 21:27   ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-10-21 21:27     ` Seth Goldberg
2013-10-21 21:16 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-10-22  8:54   ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-10-23  7:05     ` Daniel Kiper
2013-10-23  8:28       ` Seth Goldberg
2013-10-23 10:43       ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-10-28 16:26     ` Konrad Rzeszutek Wilk [this message]
2013-10-28 18:01       ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-10-29  8:28         ` Jan Beulich
2013-10-30 11:19           ` Is: Wrap-up Was: " Daniel Kiper
2013-10-30 11:38             ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-11-04 20:41             ` Stefano Stabellini
2013-11-05 19:15               ` Leif Lindholm
2013-10-28 18:42       ` Seth Goldberg
2013-10-22 17:12   ` Andrey Borzenkov
2013-10-22 17:20     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-10-23  7:43   ` Daniel Kiper
2013-10-23  8:44     ` Vladimir 'φ-coder/phcoder' Serbinenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131028162603.GA4716@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=daniel.kiper@oracle.com \
    --cc=david.woodhouse@intel.com \
    --cc=grub-devel@gnu.org \
    --cc=ian.campbell@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=keir@xen.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phcoder@gmail.com \
    --cc=richard.l.maliszewski@intel.com \
    --cc=ross.philipson@citrix.com \
    --cc=seth.goldberg@oracle.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).