nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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