]> xenbits.xensource.com Git - mini-os.git/commitdiff
mini-os: don't assume contiguous RAM when initializing in PVH mode
authorJuergen Gross <jgross@suse.com>
Tue, 21 Dec 2021 08:46:29 +0000 (09:46 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 21 Dec 2021 10:53:49 +0000 (10:53 +0000)
Sizing the available memory should respect memory holes, so look at
the memory map when setting the boundary for the memory allocator.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
arch/x86/mm.c
e820.c
include/e820.h

index 8df93daadad6303891ac527d7f3b931f8d9b366d..3bf6170a4543d712f2d03732232ab5cb351c448c 100644 (file)
@@ -107,7 +107,6 @@ void arch_mm_preinit(void *p)
 {
     long ret;
     domid_t domid = DOMID_SELF;
-    unsigned long max;
 
     pt_base = page_table_base;
     first_free_pfn = PFN_UP(to_phys(&_end));
@@ -117,11 +116,8 @@ void arch_mm_preinit(void *p)
         xprintk("could not get memory size\n");
         do_exit();
     }
-    last_free_pfn = ret;
 
-    max = e820_get_maxpfn();
-    if ( max < last_free_pfn )
-        last_free_pfn = max;
+    last_free_pfn = e820_get_maxpfn(ret);
 }
 #endif
 
diff --git a/e820.c b/e820.c
index 70286cb8094704bbee34aed7165f6d3336937422..4c726d1f3879b2975a1de42eaf9705032ff62015 100644 (file)
--- a/e820.c
+++ b/e820.c
@@ -285,10 +285,10 @@ void arch_print_memmap(void)
 }
 #endif
 
-unsigned long e820_get_maxpfn(void)
+unsigned long e820_get_maxpfn(unsigned long pages)
 {
     int i;
-    unsigned long pfn, max = 0;
+    unsigned long pfns = 0, start = 0;
 
     e820_get_memmap();
 
@@ -296,10 +296,12 @@ unsigned long e820_get_maxpfn(void)
     {
         if ( e820_map[i].type != E820_RAM )
             continue;
-        pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT;
-        if ( pfn > max )
-            max = pfn;
+        pfns = e820_map[i].size >> PAGE_SHIFT;
+        start = e820_map[i].addr >> PAGE_SHIFT;
+        if ( pages <= pfns )
+            return start + pages;
+        pages -= pfns;
     }
 
-    return max;
+    return start + pfns;
 }
index af2129fec22d311766fe9846366c3fdb2844d871..6a57f05ec28f6a098fd7ce52c601ea2ff6a0a71f 100644 (file)
@@ -49,6 +49,6 @@ struct __packed e820entry {
 extern struct e820entry e820_map[];
 extern unsigned e820_entries;
 
-unsigned long e820_get_maxpfn(void);
+unsigned long e820_get_maxpfn(unsigned long pages);
 
 #endif /*__E820_HEADER*/