grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] use central copy of grub_efi_find_mmap_size
@ 2018-07-13 16:34 Leif Lindholm
  2018-07-13 16:34 ` [PATCH 1/3] loader/i386/linux: " Leif Lindholm
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Leif Lindholm @ 2018-07-13 16:34 UTC (permalink / raw)
  To: grub-devel; +Cc: Daniel Kiper

There were multiple local implementations of functions to determine the
size of buffer required to hold a UEFI memory map. Drop these and switch to
grub_efi_find_mmap_size() in kern/efi/mm.c.

I'm not going to lie. I no longer have an ia64 cross-toolchain, so that one
is not even compile tested.

Leif Lindholm (3):
  loader/i386/linux: use central copy of grub_efi_find_mmap_size
  loader/ia64/linux: use central copy of grub_efi_find_mmap_size
  loader/multiboot_mbi2: use central copy of grub_efi_find_mmap_size

 grub-core/loader/i386/linux.c     | 51 +--------------------------------------
 grub-core/loader/ia64/efi/linux.c | 46 ++---------------------------------
 grub-core/loader/multiboot_mbi2.c | 38 +----------------------------
 3 files changed, 4 insertions(+), 131 deletions(-)

-- 
2.11.0



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

* [PATCH 1/3] loader/i386/linux: use central copy of grub_efi_find_mmap_size
  2018-07-13 16:34 [PATCH 0/3] use central copy of grub_efi_find_mmap_size Leif Lindholm
@ 2018-07-13 16:34 ` Leif Lindholm
  2018-07-13 16:34 ` [PATCH 2/3] loader/ia64/linux: " Leif Lindholm
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Leif Lindholm @ 2018-07-13 16:34 UTC (permalink / raw)
  To: grub-devel; +Cc: Daniel Kiper

Delete local copy of function to determine required buffer size for the
UEFI memory map, use helper in kern/efi/mm.c.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
---
 grub-core/loader/i386/linux.c | 51 +------------------------------------------
 1 file changed, 1 insertion(+), 50 deletions(-)

diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
index 44301e126..ab02add53 100644
--- a/grub-core/loader/i386/linux.c
+++ b/grub-core/loader/i386/linux.c
@@ -101,55 +101,6 @@ page_align (grub_size_t size)
   return (size + (1 << 12) - 1) & (~((1 << 12) - 1));
 }
 
-#ifdef GRUB_MACHINE_EFI
-/* Find the optimal number of pages for the memory map. Is it better to
-   move this code to efi/mm.c?  */
-static grub_efi_uintn_t
-find_efi_mmap_size (void)
-{
-  static grub_efi_uintn_t mmap_size = 0;
-
-  if (mmap_size != 0)
-    return mmap_size;
-
-  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 = mmap_size;
-
-      mmap = grub_malloc (cur_mmap_size);
-      if (! mmap)
-	return 0;
-
-      ret = grub_efi_get_memory_map (&cur_mmap_size, mmap, 0, &desc_size, 0);
-      grub_free (mmap);
-
-      if (ret < 0)
-	{
-	  grub_error (GRUB_ERR_IO, "cannot get memory map");
-	  return 0;
-	}
-      else if (ret > 0)
-	break;
-
-      if (mmap_size < cur_mmap_size)
-	mmap_size = cur_mmap_size;
-      mmap_size += (1 << 12);
-    }
-
-  /* Increase the size a bit for safety, because GRUB allocates more on
-     later, and EFI itself may allocate more.  */
-  mmap_size += (3 << 12);
-
-  mmap_size = page_align (mmap_size);
-  return mmap_size;
-}
-
-#endif
-
 /* Helper for find_mmap_size.  */
 static int
 count_hook (grub_uint64_t addr __attribute__ ((unused)),
@@ -560,7 +511,7 @@ grub_linux_boot (void)
   ctx.real_size = ALIGN_UP (cl_offset + maximal_cmdline_size, 4096);
 
 #ifdef GRUB_MACHINE_EFI
-  efi_mmap_size = find_efi_mmap_size ();
+  efi_mmap_size = grub_efi_find_mmap_size ();
   if (efi_mmap_size == 0)
     return grub_errno;
 #endif
-- 
2.11.0



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

* [PATCH 2/3] loader/ia64/linux: use central copy of grub_efi_find_mmap_size
  2018-07-13 16:34 [PATCH 0/3] use central copy of grub_efi_find_mmap_size Leif Lindholm
  2018-07-13 16:34 ` [PATCH 1/3] loader/i386/linux: " Leif Lindholm
@ 2018-07-13 16:34 ` Leif Lindholm
  2018-07-13 16:34 ` [PATCH 3/3] loader/multiboot_mbi2: " Leif Lindholm
  2018-09-06 13:46 ` [PATCH 0/3] " Daniel Kiper
  3 siblings, 0 replies; 5+ messages in thread
From: Leif Lindholm @ 2018-07-13 16:34 UTC (permalink / raw)
  To: grub-devel; +Cc: Daniel Kiper

Delete local copy of function to determine required buffer size for the
UEFI memory map, use helper in kern/efi/mm.c.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
---
 grub-core/loader/ia64/efi/linux.c | 46 ++-------------------------------------
 1 file changed, 2 insertions(+), 44 deletions(-)

diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c
index 750330d45..96fce713a 100644
--- a/grub-core/loader/ia64/efi/linux.c
+++ b/grub-core/loader/ia64/efi/linux.c
@@ -133,48 +133,6 @@ query_fpswa (void)
     } 
 }
 
-/* Find the optimal number of pages for the memory map. Is it better to
-   move this code to efi/mm.c?  */
-static grub_efi_uintn_t
-find_mmap_size (void)
-{
-  static grub_efi_uintn_t mmap_size = 0;
-
-  if (mmap_size != 0)
-    return mmap_size;
-  
-  mmap_size = (1 << 12);
-  while (1)
-    {
-      int ret;
-      grub_efi_memory_descriptor_t *mmap;
-      grub_efi_uintn_t desc_size;
-      
-      mmap = grub_malloc (mmap_size);
-      if (! mmap)
-	return 0;
-
-      ret = grub_efi_get_memory_map (&mmap_size, mmap, 0, &desc_size, 0);
-      grub_free (mmap);
-      
-      if (ret < 0)
-	{
-	  grub_error (GRUB_ERR_IO, "cannot get memory map");
-	  return 0;
-	}
-      else if (ret > 0)
-	break;
-
-      mmap_size += (1 << 12);
-    }
-
-  /* Increase the size a bit for safety, because GRUB allocates more on
-     later, and EFI itself may allocate more.  */
-  mmap_size += (1 << 12);
-
-  return page_align (mmap_size);
-}
-
 static void
 free_pages (void)
 {
@@ -212,7 +170,7 @@ allocate_pages (grub_uint64_t align, grub_uint64_t size_pages,
 
   size = size_pages << 12;
 
-  mmap_size = find_mmap_size ();
+  mmap_size = grub_efi_find_mmap_size ();
   if (!mmap_size)
     return 0;
 
@@ -323,7 +281,7 @@ grub_linux_boot (void)
   /* MDT.
      Must be done after grub_machine_fini because map_key is used by
      exit_boot_services.  */
-  mmap_size = find_mmap_size ();
+  mmap_size = grub_efi_find_mmap_size ();
   if (! mmap_size)
     return grub_errno;
   mmap_buf = grub_efi_allocate_any_pages (page_align (mmap_size) >> 12);
-- 
2.11.0



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

* [PATCH 3/3] loader/multiboot_mbi2: use central copy of grub_efi_find_mmap_size
  2018-07-13 16:34 [PATCH 0/3] use central copy of grub_efi_find_mmap_size Leif Lindholm
  2018-07-13 16:34 ` [PATCH 1/3] loader/i386/linux: " Leif Lindholm
  2018-07-13 16:34 ` [PATCH 2/3] loader/ia64/linux: " Leif Lindholm
@ 2018-07-13 16:34 ` Leif Lindholm
  2018-09-06 13:46 ` [PATCH 0/3] " Daniel Kiper
  3 siblings, 0 replies; 5+ messages in thread
From: Leif Lindholm @ 2018-07-13 16:34 UTC (permalink / raw)
  To: grub-devel; +Cc: Daniel Kiper

Delete local copy of function to determine required buffer size for the
UEFI memory map, use helper in kern/efi/mm.c.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
---
 grub-core/loader/multiboot_mbi2.c | 38 +-------------------------------------
 1 file changed, 1 insertion(+), 37 deletions(-)

diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c
index 4df659595..747e10850 100644
--- a/grub-core/loader/multiboot_mbi2.c
+++ b/grub-core/loader/multiboot_mbi2.c
@@ -407,42 +407,6 @@ acpiv2_size (void)
 
 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
@@ -463,7 +427,7 @@ grub_multiboot2_get_mbi_size (void)
 {
 #ifdef GRUB_MACHINE_EFI
   if (!keep_bs && !efi_mmap_size)
-    find_efi_mmap_size ();    
+    efi_mmap_size = grub_efi_find_mmap_size ();
 #endif
   return 2 * sizeof (grub_uint32_t) + sizeof (struct multiboot_tag)
     + sizeof (struct multiboot_tag)
-- 
2.11.0



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

* Re: [PATCH 0/3] use central copy of grub_efi_find_mmap_size
  2018-07-13 16:34 [PATCH 0/3] use central copy of grub_efi_find_mmap_size Leif Lindholm
                   ` (2 preceding siblings ...)
  2018-07-13 16:34 ` [PATCH 3/3] loader/multiboot_mbi2: " Leif Lindholm
@ 2018-09-06 13:46 ` Daniel Kiper
  3 siblings, 0 replies; 5+ messages in thread
From: Daniel Kiper @ 2018-09-06 13:46 UTC (permalink / raw)
  To: Leif Lindholm; +Cc: grub-devel

On Fri, Jul 13, 2018 at 05:34:42PM +0100, Leif Lindholm wrote:
> There were multiple local implementations of functions to determine the
> size of buffer required to hold a UEFI memory map. Drop these and switch to
> grub_efi_find_mmap_size() in kern/efi/mm.c.
>
> I'm not going to lie. I no longer have an ia64 cross-toolchain, so that one
> is not even compile tested.
>
> Leif Lindholm (3):
>   loader/i386/linux: use central copy of grub_efi_find_mmap_size
>   loader/ia64/linux: use central copy of grub_efi_find_mmap_size
>   loader/multiboot_mbi2: use central copy of grub_efi_find_mmap_size
>
>  grub-core/loader/i386/linux.c     | 51 +--------------------------------------
>  grub-core/loader/ia64/efi/linux.c | 46 ++---------------------------------
>  grub-core/loader/multiboot_mbi2.c | 38 +----------------------------
>  3 files changed, 4 insertions(+), 131 deletions(-)

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> for whole patch series.

Daniel


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

end of thread, other threads:[~2018-09-06 13:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-13 16:34 [PATCH 0/3] use central copy of grub_efi_find_mmap_size Leif Lindholm
2018-07-13 16:34 ` [PATCH 1/3] loader/i386/linux: " Leif Lindholm
2018-07-13 16:34 ` [PATCH 2/3] loader/ia64/linux: " Leif Lindholm
2018-07-13 16:34 ` [PATCH 3/3] loader/multiboot_mbi2: " Leif Lindholm
2018-09-06 13:46 ` [PATCH 0/3] " Daniel Kiper

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