3d407d2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
3d407d2
From: Peter Jones <pjones@redhat.com>
3d407d2
Date: Mon, 1 Aug 2022 14:07:50 -0400
3d407d2
Subject: [PATCH] efi: allocate the initrd within the bounds expressed by the
3d407d2
 kernel
3d407d2
3d407d2
Currently on x86, only linux kernels built with CONFIG_RELOCATABLE for
3d407d2
x86_64 can be loaded above 4G, but the maximum address for the initramfs
3d407d2
is specified via a HdrS field.  This allows us to utilize that value,
3d407d2
and unless loading the kernel above 4G, uses the value present there.
3d407d2
If loading kernel above 4G is allowed, we assume loading the initramfs
3d407d2
above 4G also works; in practice this has been true in the kernel code
3d407d2
for quite some time.
3d407d2
3d407d2
Resolves: rhbz#2112134
3d407d2
3d407d2
Signed-off-by: Peter Jones <pjones@redhat.com>
3d407d2
---
3d407d2
 grub-core/loader/i386/efi/linux.c | 6 ++++++
3d407d2
 1 file changed, 6 insertions(+)
3d407d2
3d407d2
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
3d407d2
index e6b8998e5e..d003b474ee 100644
3d407d2
--- a/grub-core/loader/i386/efi/linux.c
3d407d2
+++ b/grub-core/loader/i386/efi/linux.c
3d407d2
@@ -190,6 +190,8 @@ grub_linuxefi_unload (void *data)
3d407d2
   cmd_initrdefi->data = 0;
3d407d2
   grub_free (context);
3d407d2
 
3d407d2
+  max_addresses[INITRD_MAX_ADDRESS].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
3d407d2
+
3d407d2
   return GRUB_ERR_NONE;
3d407d2
 }
3d407d2
 
3d407d2
@@ -426,11 +428,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
3d407d2
     }
3d407d2
 #endif
3d407d2
 
3d407d2
+  max_addresses[INITRD_MAX_ADDRESS].addr = lh->initrd_addr_max;
3d407d2
 #if defined(__x86_64__)
3d407d2
   if (lh->xloadflags & LINUX_XLF_CAN_BE_LOADED_ABOVE_4G)
3d407d2
     {
3d407d2
       grub_dprintf ("linux", "Loading kernel above 4GB is supported; enabling.\n");
3d407d2
       max_addresses[KERNEL_NO_LIMIT].addr = GRUB_EFI_MAX_USABLE_ADDRESS;
3d407d2
+      max_addresses[INITRD_MAX_ADDRESS].addr = GRUB_EFI_MAX_USABLE_ADDRESS;
3d407d2
     }
3d407d2
   else
3d407d2
     {
3d407d2
@@ -560,6 +564,8 @@ fail:
3d407d2
 
3d407d2
   grub_dl_unref (my_mod);
3d407d2
 
3d407d2
+  max_addresses[INITRD_MAX_ADDRESS].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
3d407d2
+
3d407d2
   if (lh)
3d407d2
     kernel_free (cmdline, lh->cmdline_size + 1);
3d407d2