# HG changeset patch
# User Alex Olson <alex.ol...@starlab.io>
# Date 1634322959 18000
#      Fri Oct 15 13:35:59 2021 -0500
# Node ID 4eda9c0cf72d0fe0c217c251bdef2c5628e0c0a6
# Parent  5bf5c12411d3a4a7e0a552203b40bfe59d5c7789
make efi_memmap_reserve handle gaps like e820_protect_region already does

This revision corrects an inconsistency in the way efi_memmap_reserve
deals with requests that lie within a gap in the memory map.

In such cases, e820_protect_region() created a new range in the map,
however efi_memmap_reserve was doing nothing since its logic was
based on finding an overlapping range.

This revision makes efi_memmap_reserve add a new range.  Unlike
the e820 case, the EFI memory map have an "attributes" field as well
and it is somewhat ambigious how to define the attributes of a new map.
Since we are only using this for reserved ranges, the attributes are set to zero
for simplicity...

Signed-off-by: Alex Olson <alex.ol...@starlab.io>

diff -r 5bf5c12411d3 -r 4eda9c0cf72d tboot/common/efi_memmap.c
--- a/tboot/common/efi_memmap.c Wed Sep 15 16:53:34 2021 +0200
+++ b/tboot/common/efi_memmap.c Fri Oct 15 13:35:59 2021 -0500
@@ -144,6 +144,8 @@
  * Region has to be aligned to page size, function will round non-aligned
  * values. Base address is rounded down, length - up.
  * 
+ * If the specified region lies within a gap, a new region will be added
+ *
  * @param base   starting address
  * @param length length of region to reserve
  */
@@ -164,6 +166,7 @@
     uint64_t end = base + length;
     efi_mem_descr_t* desc = NULL;
     uint32_t i = 0;
+    bool in_range = false;
 
     while ((desc = efi_memmap_walk(desc)) != NULL) {
         uint64_t desc_base = desc->physical_start;
@@ -185,6 +188,9 @@
             goto cont;
         }
 
+        /* In all cases below, the current range is involved */
+        in_range = true;
+
         /* case 1: the current ram range is within the range:
            base, desc_base, desc_end, end */
         if ((base <= desc_base) && (desc_end <= end)) {
@@ -250,6 +256,15 @@
         ++i;
     }
 
+    /* Insert the new region */
+    if ( !in_range ) {
+
+        desc = efi_memmap_walk(NULL);
+        if( !insert_after_region(0, base, length, EFI_RESERVED_TYPE, 0) ) {
+            return false;
+        }
+    }
+
     return true;
 }
 


_______________________________________________
tboot-devel mailing list
tboot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tboot-devel

Reply via email to