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