Skip to contentSkip to conversation

[4.17] EFI: don't convert memory marked for runtime use to ordinary RAM

PATCH In review Jan Beulich 2 participants 2 messages Oct 11, 2022 – Oct 20, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 [4.17] EFI: don't convert memory marked for runtime use to ordinary RAM

efi_init_memory() in both relevant places is treating EFI_MEMORY_RUNTIME higher priority than the type of the range. To avoid accessing memory at runtime which was re-used for other purposes, make efi_arch_process_memory_map() follow suit. While in theory the same would apply to EfiACPIReclaimMemory, we don't actually "reclaim" or clobber that memory (converted to E820_ACPI on x86) there (and it would be a bug if the Dom0 kernel tried to reclaim the range, bypassing Xen's memory management, plus it would be at least bogus if it clobbered that space), hence that type's handling can be left alone.

Fixes bf6501a62e80 ("x86-64: EFI boot code")
Fixes facac0af87ef ("x86-64: EFI runtime code")
Fixes 6d70ea10d49f ("Add ARM EFI boot support")

---
v3: Alter Arm change to leave EfiACPIReclaimMemory handling alone.
v2: Amend description.

xen/arch/arm/efi/efi-boot.h +2 -1
@@ -183,7 +183,8 @@ static EFI_STATUS __init efi_process_mem
 
     for ( Index = 0; Index < (mmap_size / desc_size); Index++ )
     {
-        if ( desc_ptr->Attribute & EFI_MEMORY_WB &&
+        if ( !(desc_ptr->Attribute & EFI_MEMORY_RUNTIME) &&
+             (desc_ptr->Attribute & EFI_MEMORY_WB) &&
              (desc_ptr->Type == EfiConventionalMemory ||
               desc_ptr->Type == EfiLoaderCode ||
               desc_ptr->Type == EfiLoaderData ||
xen/arch/x86/efi/efi-boot.h +3 -1
@@ -185,7 +185,9 @@ static void __init efi_arch_process_memo
             /* fall through */
         case EfiLoaderCode:
         case EfiLoaderData:
-            if ( desc->Attribute & EFI_MEMORY_WB )
+            if ( desc->Attribute & EFI_MEMORY_RUNTIME )
+                type = E820_RESERVED;
+            else if ( desc->Attribute & EFI_MEMORY_WB )
                 type = E820_RAM;
             else
         case EfiUnusableMemory:
Reviewed-by on v3 1/1
#1 lore raw

Hi Jan,

Sorry I missed this patch.

Quoted 10 lines · Jan Beulich

efi_init_memory() in both relevant places is treating EFI_MEMORY_RUNTIME higher priority than the type of the range. To avoid accessing memory at runtime which was re-used for other purposes, make efi_arch_process_memory_map() follow suit. While in theory the same would apply to EfiACPIReclaimMemory, we don't actually "reclaim" or clobber that memory (converted to E820_ACPI on x86) there (and it would be a bug if the Dom0 kernel tried to reclaim the range, bypassing Xen's memory management, plus it would be at least bogus if it clobbered that space), hence that type's handling can be left alone.

Quoted 6 lines
Fixes bf6501a62e80 ("x86-64: EFI boot code")
Fixes facac0af87ef ("x86-64: EFI runtime code")
Fixes 6d70ea10d49f ("Add ARM EFI boot support")

Cheers,

Signature · 1 line
Julien Grall