Blame SOURCES/0306-kern-efi-mm-Implement-runtime-addition-of-pages.patch

fd0330
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
fd0330
From: Patrick Steinhardt <ps@pks.im>
fd0330
Date: Thu, 21 Apr 2022 15:24:22 +1000
fd0330
Subject: [PATCH] kern/efi/mm: Implement runtime addition of pages
fd0330
fd0330
Adjust the interface of grub_efi_mm_add_regions() to take a set of
fd0330
GRUB_MM_ADD_REGION_* flags, which most notably is currently only the
fd0330
GRUB_MM_ADD_REGION_CONSECUTIVE flag. This allows us to set the function
fd0330
up as callback for the memory subsystem and have it call out to us in
fd0330
case there's not enough pages available in the current heap.
fd0330
fd0330
Signed-off-by: Patrick Steinhardt <ps@pks.im>
fd0330
Signed-off-by: Daniel Axtens <dja@axtens.net>
fd0330
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
fd0330
Tested-by: Patrick Steinhardt <ps@pks.im>
fd0330
(cherry picked from commit 1df2934822df4c1170dde069d97cfbf7a9572bba)
fd0330
---
fd0330
 grub-core/kern/efi/mm.c | 15 +++++++++++----
fd0330
 1 file changed, 11 insertions(+), 4 deletions(-)
fd0330
fd0330
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
fd0330
index e0ebc65dba..016ba6cf2f 100644
fd0330
--- a/grub-core/kern/efi/mm.c
fd0330
+++ b/grub-core/kern/efi/mm.c
fd0330
@@ -518,7 +518,8 @@ static grub_err_t
fd0330
 add_memory_regions (grub_efi_memory_descriptor_t *memory_map,
fd0330
 		    grub_efi_uintn_t desc_size,
fd0330
 		    grub_efi_memory_descriptor_t *memory_map_end,
fd0330
-		    grub_efi_uint64_t required_pages)
fd0330
+		    grub_efi_uint64_t required_pages,
fd0330
+		    unsigned int flags)
fd0330
 {
fd0330
   grub_efi_memory_descriptor_t *desc;
fd0330
 
fd0330
@@ -532,6 +533,10 @@ add_memory_regions (grub_efi_memory_descriptor_t *memory_map,
fd0330
 
fd0330
       start = desc->physical_start;
fd0330
       pages = desc->num_pages;
fd0330
+
fd0330
+      if (pages < required_pages && (flags & GRUB_MM_ADD_REGION_CONSECUTIVE))
fd0330
+	continue;
fd0330
+
fd0330
       if (pages > required_pages)
fd0330
 	{
fd0330
 	  start += PAGES_TO_BYTES (pages - required_pages);
fd0330
@@ -672,7 +677,7 @@ grub_nx_init (void)
fd0330
 }
fd0330
 
fd0330
 static grub_err_t
fd0330
-grub_efi_mm_add_regions (grub_size_t required_bytes)
fd0330
+grub_efi_mm_add_regions (grub_size_t required_bytes, unsigned int flags)
fd0330
 {
fd0330
   grub_efi_memory_descriptor_t *memory_map;
fd0330
   grub_efi_memory_descriptor_t *memory_map_end;
fd0330
@@ -729,7 +734,8 @@ grub_efi_mm_add_regions (grub_size_t required_bytes)
fd0330
   /* Allocate memory regions for GRUB's memory management.  */
fd0330
   err = add_memory_regions (filtered_memory_map, desc_size,
fd0330
 			    filtered_memory_map_end,
fd0330
-			    BYTES_TO_PAGES (required_bytes));
fd0330
+			    BYTES_TO_PAGES (required_bytes),
fd0330
+			    flags);
fd0330
   if (err != GRUB_ERR_NONE)
fd0330
     return err;
fd0330
 
fd0330
@@ -756,8 +762,9 @@ grub_efi_mm_add_regions (grub_size_t required_bytes)
fd0330
 void
fd0330
 grub_efi_mm_init (void)
fd0330
 {
fd0330
-  if (grub_efi_mm_add_regions (DEFAULT_HEAP_SIZE) != GRUB_ERR_NONE)
fd0330
+  if (grub_efi_mm_add_regions (DEFAULT_HEAP_SIZE, GRUB_MM_ADD_REGION_NONE) != GRUB_ERR_NONE)
fd0330
     grub_fatal ("%s", grub_errmsg);
fd0330
+  grub_mm_add_region_fn = grub_efi_mm_add_regions;
fd0330
 }
fd0330
 
fd0330
 #if defined (__aarch64__) || defined (__arm__) || defined (__riscv)