nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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