nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0281-efi-use-enumerated-array-positions-for-our-allocatio.patch

d3c3ab
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d3c3ab
From: Peter Jones <pjones@redhat.com>
d3c3ab
Date: Mon, 1 Aug 2022 14:06:30 -0400
d3c3ab
Subject: [PATCH] efi: use enumerated array positions for our allocation
d3c3ab
 choices
d3c3ab
d3c3ab
In our kernel allocator on EFI systems, we currently have a growing
d3c3ab
amount of code that references the various allocation policies by
d3c3ab
position in the array, and of course maintenance of this code scales
d3c3ab
very poorly.
d3c3ab
d3c3ab
This patch changes them to be enumerated, so they're easier to refer to
d3c3ab
farther along in the code without confusion.
d3c3ab
d3c3ab
Signed-off-by: Peter Jones <pjones@redhat.com>
d3c3ab
(cherry picked from commit 6768026270cca015d7fef0ecc8a4119e9b3d3923)
d3c3ab
---
d3c3ab
 grub-core/loader/i386/efi/linux.c | 31 ++++++++++++++++++++-----------
d3c3ab
 1 file changed, 20 insertions(+), 11 deletions(-)
d3c3ab
d3c3ab
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
d3c3ab
index dc98077378..781a333162 100644
d3c3ab
--- a/grub-core/loader/i386/efi/linux.c
d3c3ab
+++ b/grub-core/loader/i386/efi/linux.c
d3c3ab
@@ -61,17 +61,26 @@ struct allocation_choice {
d3c3ab
     grub_efi_allocate_type_t alloc_type;
d3c3ab
 };
d3c3ab
 
d3c3ab
-static struct allocation_choice max_addresses[4] =
d3c3ab
+enum {
d3c3ab
+    KERNEL_PREF_ADDRESS,
d3c3ab
+    KERNEL_4G_LIMIT,
d3c3ab
+    KERNEL_NO_LIMIT,
d3c3ab
+};
d3c3ab
+
d3c3ab
+static struct allocation_choice max_addresses[] =
d3c3ab
   {
d3c3ab
     /* the kernel overrides this one with pref_address and
d3c3ab
      * GRUB_EFI_ALLOCATE_ADDRESS */
d3c3ab
-    { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
d3c3ab
+    [KERNEL_PREF_ADDRESS] =
d3c3ab
+      { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
d3c3ab
+    /* If the flag in params is set, this one gets changed to be above 4GB. */
d3c3ab
+    [KERNEL_4G_LIMIT] =
d3c3ab
+      { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
d3c3ab
     /* this one is always below 4GB, which we still *prefer* even if the flag
d3c3ab
      * is set. */
d3c3ab
-    { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
d3c3ab
-    /* If the flag in params is set, this one gets changed to be above 4GB. */
d3c3ab
-    { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
d3c3ab
-    { 0, 0 }
d3c3ab
+    [KERNEL_NO_LIMIT] =
d3c3ab
+      { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
d3c3ab
+    { NO_MEM, 0, 0 }
d3c3ab
   };
d3c3ab
 static struct allocation_choice saved_addresses[4];
d3c3ab
 
d3c3ab
@@ -418,7 +427,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
d3c3ab
   if (lh->xloadflags & LINUX_XLF_CAN_BE_LOADED_ABOVE_4G)
d3c3ab
     {
d3c3ab
       grub_dprintf ("linux", "Loading kernel above 4GB is supported; enabling.\n");
d3c3ab
-      max_addresses[2].addr = GRUB_EFI_MAX_USABLE_ADDRESS;
d3c3ab
+      max_addresses[KERNEL_NO_LIMIT].addr = GRUB_EFI_MAX_USABLE_ADDRESS;
d3c3ab
     }
d3c3ab
   else
d3c3ab
     {
d3c3ab
@@ -491,11 +500,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
d3c3ab
   grub_dprintf ("linux", "lh->pref_address: %p\n", (void *)(grub_addr_t)lh->pref_address);
d3c3ab
   if (lh->pref_address < (grub_uint64_t)GRUB_EFI_MAX_ALLOCATION_ADDRESS)
d3c3ab
     {
d3c3ab
-      max_addresses[0].addr = lh->pref_address;
d3c3ab
-      max_addresses[0].alloc_type = GRUB_EFI_ALLOCATE_ADDRESS;
d3c3ab
+      max_addresses[KERNEL_PREF_ADDRESS].addr = lh->pref_address;
d3c3ab
+      max_addresses[KERNEL_PREF_ADDRESS].alloc_type = GRUB_EFI_ALLOCATE_ADDRESS;
d3c3ab
     }
d3c3ab
-  max_addresses[1].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
d3c3ab
-  max_addresses[2].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
d3c3ab
+  max_addresses[KERNEL_4G_LIMIT].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
d3c3ab
+  max_addresses[KERNEL_NO_LIMIT].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
d3c3ab
   kernel_size = lh->init_size;
d3c3ab
   kernel_mem = kernel_alloc (kernel_size, GRUB_EFI_RUNTIME_SERVICES_CODE,
d3c3ab
 			     N_("can't allocate kernel"));