Skip to contentSkip to conversation

x86/dom0: add extra RAM regions as UNUSABLE for PVH memory map

PATCH Superseded Roger Pau Monne 2 participants 2 messages May 3, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/dom0: add extra RAM regions as UNUSABLE for PVH memory map

When running as PVH Dom0 the native memory map is used in order to craft a tailored memory map for Dom0 taking into account it's memory limit.

Dom0 memory is always going to be smaller than the total amount of memory present on the host, so in order to prevent Dom0 from relocating PCI BARs over RAM regions mark all the RAM regions not available to Dom0 as UNUSABLE in the memory map.

---
Changes since v1:
- Report the ranges as UNUSABLE instead of RESERVED.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Juergen Gross <[email protected]>
---
NB: I haven't seen any system where Dom0 would relocate the BARs over RAM regions, but AFAICT given the current memory map provided to Dom0 this is a possibility that should be avoided.

---
 xen/arch/x86/hvm/dom0_build.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
xen/arch/x86/hvm/dom0_build.c +17 -8
index b237508072..9a441ab4cf 100644
@@ -314,8 +314,10 @@ static __init void pvh_setup_e820(struct domain *d, unsigned long nr_pages)
 
     /*
      * Craft the e820 memory map for Dom0 based on the hardware e820 map.
+     * Add an extra entry in case we have to split a RAM entry into a RAM and a
+     * RESERVED one in order to truncate it.
      */
-    d->arch.e820 = xzalloc_array(struct e820entry, e820.nr_map);
+    d->arch.e820 = xzalloc_array(struct e820entry, e820.nr_map + 1);
     if ( !d->arch.e820 )
         panic("Unable to allocate memory for Dom0 e820 map");
     entry_guest = d->arch.e820;
@@ -323,19 +325,20 @@ static __init void pvh_setup_e820(struct domain *d, unsigned long nr_pages)
     /* Clamp e820 memory map to match the memory assigned to Dom0 */
     for ( i = 0, entry = e820.map; i < e820.nr_map; i++, entry++ )
     {
+        *entry_guest = *entry;
+
         if ( entry->type != E820_RAM )
-        {
-            *entry_guest = *entry;
             goto next;
-        }
 
         if ( nr_pages == cur_pages )
         {
             /*
-             * We already have all the assigned memory,
-             * skip this entry
+             * We already have all the requested memory, turn this RAM region
+             * into a RESERVED region in order to prevent Dom0 from placing
+             * BARs in this area.
              */
-            continue;
+            entry_guest->type = E820_RESERVED;
+            goto next;
         }
 
         /*
@@ -358,6 +361,12 @@ static __init void pvh_setup_e820(struct domain *d, unsigned long nr_pages)
         {
             /* Truncate region */
             entry_guest->size = (nr_pages - cur_pages) << PAGE_SHIFT;
+            /* Add the remaining of the RAM region as RESERVED. */
+            entry_guest++;
+            d->arch.nr_e820++;
+            entry_guest->type = E820_RESERVED;
+            entry_guest->addr = start + ((nr_pages - cur_pages) << PAGE_SHIFT);
+            entry_guest->size = end - entry_guest->addr;
             cur_pages = nr_pages;
         }
         else
@@ -367,9 +376,9 @@ static __init void pvh_setup_e820(struct domain *d, unsigned long nr_pages)
  next:
         d->arch.nr_e820++;
         entry_guest++;
+        ASSERT(d->arch.nr_e820 <= e820.nr_map + 1);
     }
     ASSERT(cur_pages == nr_pages);
-    ASSERT(d->arch.nr_e820 <= e820.nr_map);
 }
 
 static int __init pvh_setup_p2m(struct domain *d)
Signature · 7 lines
2.17.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 03.05.18 at 16:13, <[email protected]> wrote:

Changes since v1:
- Report the ranges as UNUSABLE instead of RESERVED.

Ehem:

xen/arch/x86/hvm/dom0_build.c static __init void pvh_setup_e820(struct domain *d, · line 319

Quoted 9 lines
xen/arch/x86/hvm/dom0_build.c +2 -0
@@ -314,8 +314,10 @@ static __init void pvh_setup_e820(struct domain *d, 
 unsigned long nr_pages)
 
     /*
      * Craft the e820 memory map for Dom0 based on the hardware e820 map.
+     * Add an extra entry in case we have to split a RAM entry into a RAM and a
+     * RESERVED one in order to truncate it.

Here.

Quoted 9 lines
xen/arch/x86/hvm/dom0_build.c +2 -2
@@ -323,19 +325,20 @@ static __init void pvh_setup_e820(struct domain *d, unsigned long nr_pages)
     /* Clamp e820 memory map to match the memory assigned to Dom0 */
     for ( i = 0, entry = e820.map; i < e820.nr_map; i++, entry++ )
     {
+        *entry_guest = *entry;
+
         if ( entry->type != E820_RAM )
-        {
-            *entry_guest = *entry;

xen/arch/x86/hvm/dom0_build.c static __init void pvh_setup_e820(struct domain *d, unsigned long nr_pages) · line 337

Quoted 10 lines
xen/arch/x86/hvm/dom0_build.c +2 -3
             goto next;
-        }
 
         if ( nr_pages == cur_pages )
         {
             /*
-             * We already have all the assigned memory,
-             * skip this entry
+             * We already have all the requested memory, turn this RAM region
+             * into a RESERVED region in order to prevent Dom0 from placing

And here.

xen/arch/x86/hvm/dom0_build.c static __init void pvh_setup_e820(struct domain *d, unsigned long nr_pages) · line 340

Quoted 4 lines
xen/arch/x86/hvm/dom0_build.c +2 -1
+             * BARs in this area.
              */
-            continue;
+            entry_guest->type = E820_RESERVED;

And here.

xen/arch/x86/hvm/dom0_build.c static __init void pvh_setup_e820(struct domain *d, unsigned long nr_pages) · line 367

Quoted 8 lines
xen/arch/x86/hvm/dom0_build.c +4 -0
@@ -358,6 +361,12 @@ static __init void pvh_setup_e820(struct domain *d, unsigned long nr_pages)
         {
             /* Truncate region */
             entry_guest->size = (nr_pages - cur_pages) << PAGE_SHIFT;
+            /* Add the remaining of the RAM region as RESERVED. */
+            entry_guest++;
+            d->arch.nr_e820++;
+            entry_guest->type = E820_RESERVED;

And yet one more.

Jan

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