Skip to contentSkip to conversation

xen/arm: during efi boot, improve the check for usable memory

PATCH In review Stefano Stabellini 2 participants 2 messages Jan 14, 2020 – Jan 15, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen/arm: during efi boot, improve the check for usable memory

When booting via EFI, the EFI memory map has information about memory regions and their type. Improve the check for the type and attribute of each memory region to figure out whether it is usable memory or not. This patch brings the check on par with Linux v5.5-rc6 and makes more memory reusable as normal memory by Xen (except that Linux also reuses EFI_PERSISTENT_MEMORY, which we do not).

Specifically, this patch also reuses memory marked as EfiLoaderCode/Data, and it uses both Attribute and Type for the check (Attribute needs to be EFI_MEMORY_WB).

---
Changes in v2:
- improve commit message
- do not allocate memory marked as EFI_PERSISTENT_MEMORY
- do not change map_bs' behavior

---
 xen/arch/arm/efi/efi-boot.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
xen/arch/arm/efi/efi-boot.h +7 -4
index d7bf934077..6527cb0bdf 100644
@@ -149,10 +149,13 @@ static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR *
 
     for ( Index = 0; Index < (mmap_size / desc_size); Index++ )
     {
-        if ( desc_ptr->Type == EfiConventionalMemory ||
-             (!map_bs &&
-              (desc_ptr->Type == EfiBootServicesCode ||
-               desc_ptr->Type == EfiBootServicesData)) )
+        if ( desc_ptr->Attribute & EFI_MEMORY_WB &&
+             (desc_ptr->Type == EfiConventionalMemory ||
+              desc_ptr->Type == EfiLoaderCode ||
+              desc_ptr->Type == EfiLoaderData ||
+              (!map_bs &&
+               (desc_ptr->Type == EfiBootServicesCode ||
+                desc_ptr->Type == EfiBootServicesData))) )
         {
             if ( !meminfo_add_bank(&bootinfo.mem, desc_ptr) )
             {
Signature · 7 lines
2.17.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v2 1/1
#1 lore raw

Hi Stefano,

Quoted 7 lines · Stefano Stabellini

When booting via EFI, the EFI memory map has information about memory regions and their type. Improve the check for the type and attribute of each memory region to figure out whether it is usable memory or not. This patch brings the check on par with Linux v5.5-rc6 and makes more memory reusable as normal memory by Xen (except that Linux also reuses EFI_PERSISTENT_MEMORY, which we do not).

Quoted 7 lines

Specifically, this patch also reuses memory marked as EfiLoaderCode/Data, and it uses both Attribute and Type for the check (Attribute needs to be EFI_MEMORY_WB).

Cheers,

Quoted 33 lines

---
Changes in v2:
- improve commit message
- do not allocate memory marked as EFI_PERSISTENT_MEMORY
- do not change map_bs' behavior

---
  xen/arch/arm/efi/efi-boot.h | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
xen/arch/arm/efi/efi-boot.h +7 -4
index d7bf934077..6527cb0bdf 100644
@@ -149,10 +149,13 @@ static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR *
 
      for ( Index = 0; Index < (mmap_size / desc_size); Index++ )
      {
-        if ( desc_ptr->Type == EfiConventionalMemory ||
-             (!map_bs &&
-              (desc_ptr->Type == EfiBootServicesCode ||
-               desc_ptr->Type == EfiBootServicesData)) )
+        if ( desc_ptr->Attribute & EFI_MEMORY_WB &&
+             (desc_ptr->Type == EfiConventionalMemory ||
+              desc_ptr->Type == EfiLoaderCode ||
+              desc_ptr->Type == EfiLoaderData ||
+              (!map_bs &&
+               (desc_ptr->Type == EfiBootServicesCode ||
+                desc_ptr->Type == EfiBootServicesData))) )
          {
              if ( !meminfo_add_bank(&bootinfo.mem, desc_ptr) )
              {
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel