The EFI spec defines special-purpose memory in ยง7.2. That memory
serves as a hint to the OS to avoid allocating this memory for core
OS data or code that can not be relocated. So let's ignore it when
allocating from conventional memory.

Signed-off-by: Ilias Apalodimas <ilias.apalodi...@linaro.org>
---
 lib/efi_loader/efi_memory.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index c6f1dd09456e..74732e37f8aa 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -422,7 +422,8 @@ static efi_status_t efi_check_allocated(u64 addr, bool 
must_be_allocated)
 
                if (addr >= start && addr < end) {
                        if (must_be_allocated ^
-                           (item->desc.type == EFI_CONVENTIONAL_MEMORY))
+                           (item->desc.type == EFI_CONVENTIONAL_MEMORY) &&
+                           !(item->desc.attribute & EFI_MEMORY_SP))
                                return EFI_SUCCESS;
                        else
                                return EFI_NOT_FOUND;
@@ -460,6 +461,9 @@ static uint64_t efi_find_free_memory(uint64_t len, uint64_t 
max_addr)
                if (desc->type != EFI_CONVENTIONAL_MEMORY)
                        continue;
 
+               if (desc->attribute & EFI_MEMORY_SP)
+                       continue;
+
                /* Out of bounds for max_addr */
                if ((ret + len) > max_addr)
                        continue;
-- 
2.45.2

Reply via email to