c2f7a5
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
c2f7a5
From: Peter Jones <pjones@redhat.com>
c2f7a5
Date: Thu, 30 Aug 2018 11:10:18 -0400
c2f7a5
Subject: [PATCH] Try to pick better locations for kernel and initrd
c2f7a5
c2f7a5
Don't limit allocations on 64-bit platforms to < 0x3fffffff; use
c2f7a5
__UINTPTR_MAX__ or __INTPTR_MAX__.
c2f7a5
c2f7a5
Signed-off-by: Peter Jones <pjones@redhat.com>
c2f7a5
---
c2f7a5
 grub-core/kern/efi/mm.c           | 2 +-
c2f7a5
 grub-core/loader/i386/efi/linux.c | 7 ++++---
c2f7a5
 include/grub/arm64/efi/memory.h   | 2 +-
c2f7a5
 include/grub/x86_64/efi/memory.h  | 4 ++--
c2f7a5
 4 files changed, 8 insertions(+), 7 deletions(-)
c2f7a5
c2f7a5
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
c2f7a5
index 306924f73a4..4c00f4cc9d3 100644
c2f7a5
--- a/grub-core/kern/efi/mm.c
c2f7a5
+++ b/grub-core/kern/efi/mm.c
c2f7a5
@@ -122,7 +122,7 @@ grub_efi_allocate_pages_max (grub_efi_physical_address_t max,
c2f7a5
   grub_efi_boot_services_t *b;
c2f7a5
   grub_efi_physical_address_t address = max;
c2f7a5
 
c2f7a5
-  if (max > 0xffffffff)
c2f7a5
+  if (max >= GRUB_EFI_MAX_USABLE_ADDRESS)
c2f7a5
     return 0;
c2f7a5
 
c2f7a5
   b = grub_efi_system_table->boot_services;
c2f7a5
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
c2f7a5
index ea9f5134e67..fddf54762a7 100644
c2f7a5
--- a/grub-core/loader/i386/efi/linux.c
c2f7a5
+++ b/grub-core/loader/i386/efi/linux.c
c2f7a5
@@ -28,6 +28,7 @@
c2f7a5
 #include <grub/efi/efi.h>
c2f7a5
 #include <grub/efi/linux.h>
c2f7a5
 #include <grub/tpm.h>
c2f7a5
+#include <grub/cpu/efi/memory.h>
c2f7a5
 
c2f7a5
 GRUB_MOD_LICENSE ("GPLv3+");
c2f7a5
 
c2f7a5
@@ -108,7 +109,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
c2f7a5
       size += ALIGN_UP (grub_file_size (files[i]), 4);
c2f7a5
     }
c2f7a5
 
c2f7a5
-  initrd_mem = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(size));
c2f7a5
+  initrd_mem = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS, BYTES_TO_PAGES(size));
c2f7a5
   if (!initrd_mem)
c2f7a5
     {
c2f7a5
       grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate initrd"));
c2f7a5
@@ -209,7 +210,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
c2f7a5
       goto fail;
c2f7a5
     }
c2f7a5
 
c2f7a5
-  params = grub_efi_allocate_pages_max (0x3fffffff,
c2f7a5
+  params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS,
c2f7a5
 					BYTES_TO_PAGES(sizeof(*params)));
c2f7a5
   if (! params)
c2f7a5
     {
c2f7a5
@@ -309,7 +310,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
c2f7a5
 					   BYTES_TO_PAGES(lh->init_size));
c2f7a5
 
c2f7a5
   if (!kernel_mem)
c2f7a5
-    kernel_mem = grub_efi_allocate_pages_max(0x3fffffff,
c2f7a5
+    kernel_mem = grub_efi_allocate_pages_max(GRUB_EFI_MAX_USABLE_ADDRESS,
c2f7a5
 					     BYTES_TO_PAGES(lh->init_size));
c2f7a5
 
c2f7a5
   if (!kernel_mem)
c2f7a5
diff --git a/include/grub/arm64/efi/memory.h b/include/grub/arm64/efi/memory.h
c2f7a5
index c6cb3241714..af62f56cf7e 100644
c2f7a5
--- a/include/grub/arm64/efi/memory.h
c2f7a5
+++ b/include/grub/arm64/efi/memory.h
c2f7a5
@@ -1,6 +1,6 @@
c2f7a5
 #ifndef GRUB_MEMORY_CPU_HEADER
c2f7a5
 #include <grub/efi/memory.h>
c2f7a5
 
c2f7a5
-#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL
c2f7a5
+#define GRUB_EFI_MAX_USABLE_ADDRESS __UINTPTR_MAX__
c2f7a5
 
c2f7a5
 #endif /* ! GRUB_MEMORY_CPU_HEADER */
c2f7a5
diff --git a/include/grub/x86_64/efi/memory.h b/include/grub/x86_64/efi/memory.h
c2f7a5
index fb7437f7b5f..70bce170850 100644
c2f7a5
--- a/include/grub/x86_64/efi/memory.h
c2f7a5
+++ b/include/grub/x86_64/efi/memory.h
c2f7a5
@@ -2,9 +2,9 @@
c2f7a5
 #include <grub/efi/memory.h>
c2f7a5
 
c2f7a5
 #if defined (__code_model_large__)
c2f7a5
-#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffffffULL
c2f7a5
+#define GRUB_EFI_MAX_USABLE_ADDRESS __UINTPTR_MAX__
c2f7a5
 #else
c2f7a5
-#define GRUB_EFI_MAX_USABLE_ADDRESS 0x7fffffffffffffffULL
c2f7a5
+#define GRUB_EFI_MAX_USABLE_ADDRESS __INTPTR_MAX__
c2f7a5
 #endif
c2f7a5
 
c2f7a5
 #endif /* ! GRUB_MEMORY_CPU_HEADER */