nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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