Skip to contentSkip to conversation

tools/init-xenstore-domain: fix memory map for PVH stubdom

PATCH In review Juergen Gross 2 participants 2 messages Jul 12, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/init-xenstore-domain: fix memory map for PVH stubdom

In case of maxmem != memsize the E820 map of the PVH stubdom is wrong, as it is missing the RAM above memsize.

Additionally the memory map should only specify the Xen special pages as reserved.

---
V2:
- don't change mmio area settings (Anthony Perard)

---
 tools/helpers/init-xenstore-domain.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
tools/helpers/init-xenstore-domain.c +9 -5
index b4f3c65a8a..2d9ab6f1c5 100644
@@ -71,8 +71,9 @@ static int build(xc_interface *xch)
     char cmdline[512];
     int rv, xs_fd;
     struct xc_dom_image *dom = NULL;
-    int limit_kb = (maxmem ? : (memory + 1)) * 1024;
+    int limit_kb = (maxmem ? : memory) * 1024 + X86_HVM_NR_SPECIAL_PAGES * 4;
     uint64_t mem_size = MB(memory);
+    uint64_t max_size = MB(maxmem ? : memory);
     struct e820entry e820[3];
     struct xen_domctl_createdomain config = {
         .ssidref = SECINITSID_DOMU,
@@ -165,13 +166,16 @@ static int build(xc_interface *xch)
         dom->mmio_start = LAPIC_BASE_ADDRESS;
         dom->max_vcpus = 1;
         e820[0].addr = 0;
-        e820[0].size = dom->lowmem_end;
+        e820[0].size = (max_size > LAPIC_BASE_ADDRESS) ?
+                       LAPIC_BASE_ADDRESS : max_size;
         e820[0].type = E820_RAM;
-        e820[1].addr = LAPIC_BASE_ADDRESS;
-        e820[1].size = dom->mmio_size;
+        e820[1].addr = (X86_HVM_END_SPECIAL_REGION -
+                        X86_HVM_NR_SPECIAL_PAGES) << XC_PAGE_SHIFT;
+        e820[1].size = X86_HVM_NR_SPECIAL_PAGES << XC_PAGE_SHIFT;
         e820[1].type = E820_RESERVED;
         e820[2].addr = GB(4);
-        e820[2].size = dom->highmem_end - GB(4);
+        e820[2].size = (max_size > LAPIC_BASE_ADDRESS) ?
+                       max_size - LAPIC_BASE_ADDRESS : 0;
         e820[2].type = E820_RAM;
     }
 
Signature · 1 line
2.35.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Juergen Gross

In case of maxmem != memsize the E820 map of the PVH stubdom is wrong, as it is missing the RAM above memsize.

Additionally the memory map should only specify the Xen special pages as reserved.

---
V2:
- don't change mmio area settings (Anthony Perard)

Thanks,

Signature · 1 line
Anthony PERARD