x86/pvh: Retrieve memory map from Xen
authorWei Liu <wei.liu2@citrix.com>
Tue, 14 Nov 2017 18:19:09 +0000 (18:19 +0000)
committerWei Liu <wei.liu2@citrix.com>
Tue, 16 Jan 2018 18:34:04 +0000 (18:34 +0000)
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
xen/arch/x86/e820.c
xen/arch/x86/guest/pvh-boot.c
xen/arch/x86/guest/xen.c
xen/arch/x86/setup.c
xen/include/asm-x86/e820.h
xen/include/asm-x86/guest/hypercall.h

index 7c572bade251cabab2a4d7ba7fca7b075acf0add..b422a684ee676c03cb4a0fe1b224ea723016c3c3 100644 (file)
@@ -134,8 +134,7 @@ static struct change_member *change_point[2*E820MAX] __initdata;
 static struct e820entry *overlap_list[E820MAX] __initdata;
 static struct e820entry new_bios[E820MAX] __initdata;
 
-static int __init sanitize_e820_map(struct e820entry *biosmap,
-                                    unsigned int *pnr_map)
+int __init sanitize_e820_map(struct e820entry *biosmap, unsigned int *pnr_map)
 {
     struct change_member *change_tmp;
     unsigned long current_type, last_type;
index 186e3326575424323447e32edac9901870937d75..be3122b16ce7deda9b64de66c0a6f83e0191cea9 100644 (file)
@@ -22,6 +22,7 @@
 #include <xen/lib.h>
 #include <xen/mm.h>
 
+#include <asm/e820.h>
 #include <asm/guest.h>
 
 #include <public/arch-x86/hvm/start_info.h>
@@ -70,10 +71,29 @@ static void __init convert_pvh_info(void)
     }
 }
 
+static void __init get_memory_map(void)
+{
+    struct xen_memory_map memmap = {
+        .nr_entries = E820MAX,
+    };
+
+    set_xen_guest_handle(memmap.buffer, e820_raw.map);
+    BUG_ON(xen_hypercall_memory_op(XENMEM_memory_map, &memmap));
+    e820_raw.nr_map = memmap.nr_entries;
+
+    /* :( Various toolstacks don't sort the memory map. */
+    sanitize_e820_map(e820_raw.map, &e820_raw.nr_map);
+}
+
 multiboot_info_t *__init pvh_init(void)
 {
     convert_pvh_info();
 
+    probe_hypervisor();
+    ASSERT(xen_guest);
+
+    get_memory_map();
+
     return &pvh_mbi;
 }
 
index 10b90d0f6111282c4e5cb12348349e99149b00b0..c253ebd9831bf50bf4d8bcbcc4feca42d9fb47c8 100644 (file)
@@ -54,6 +54,9 @@ static void __init find_xen_leaves(void)
 
 void __init probe_hypervisor(void)
 {
+    if ( xen_guest )
+        return;
+
     /* Too early to use cpu_has_hypervisor */
     if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) )
         return;
index c485bfb5a7b0f3919d7fd97396a866f5a78845ce..9d47d2edbca16c9aede4a5bd185159c06aa291a8 100644 (file)
@@ -796,7 +796,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
         panic("dom0 kernel not specified. Check bootloader configuration.");
 
-    if ( efi_enabled(EFI_LOADER) )
+    if ( pvh_boot )
+    {
+        /* pvh_init() already filled in e820_raw */
+        memmap_type = "PVH-e820";
+    }
+    else if ( efi_enabled(EFI_LOADER) )
     {
         set_pdx_range(xen_phys_start >> PAGE_SHIFT,
                       (xen_phys_start + BOOTSTRAP_MAP_BASE) >> PAGE_SHIFT);
index 28defa8545f9cc451384729b8721616bff50d36c..ee317b17aa0f387eb5e64b6c81ce2de74bd6a522 100644 (file)
@@ -23,6 +23,7 @@ struct e820map {
     struct e820entry map[E820MAX];
 };
 
+extern int sanitize_e820_map(struct e820entry *biosmap, unsigned int *pnr_map);
 extern int e820_all_mapped(u64 start, u64 end, unsigned type);
 extern int reserve_e820_ram(struct e820map *e820, uint64_t s, uint64_t e);
 extern int e820_change_range_type(
index a05041d30b75982c9f1c35e9cf38ac687b222822..e0b00f97fb9a8cea57deaa36ae72e663dad66fc1 100644 (file)
@@ -91,6 +91,11 @@ static inline long xen_hypercall_sched_op(unsigned int cmd, void *arg)
     return _hypercall64_2(long, __HYPERVISOR_sched_op, cmd, arg);
 }
 
+static inline long xen_hypercall_memory_op(unsigned int cmd, void *arg)
+{
+    return _hypercall64_2(long, __HYPERVISOR_memory_op, cmd, arg);
+}
+
 /*
  * Higher level hypercall helpers
  */