[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2 24/62] x86/pvh: Retrieve memory map from Xen



Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
v2: fixed clang build, dropped rb tag
---
 xen/arch/x86/e820.c                   |  3 +--
 xen/arch/x86/guest/pvh-boot.c         | 20 ++++++++++++++++++++
 xen/arch/x86/guest/xen.c              |  3 +++
 xen/arch/x86/setup.c                  |  7 ++++++-
 xen/include/asm-x86/e820.h            |  1 +
 xen/include/asm-x86/guest/hypercall.h |  5 +++++
 6 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c
index 7c572bade2..b422a684ee 100644
--- a/xen/arch/x86/e820.c
+++ b/xen/arch/x86/e820.c
@@ -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;
diff --git a/xen/arch/x86/guest/pvh-boot.c b/xen/arch/x86/guest/pvh-boot.c
index 186e332657..be3122b16c 100644
--- a/xen/arch/x86/guest/pvh-boot.c
+++ b/xen/arch/x86/guest/pvh-boot.c
@@ -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;
 }
 
diff --git a/xen/arch/x86/guest/xen.c b/xen/arch/x86/guest/xen.c
index 10b90d0f61..c253ebd983 100644
--- a/xen/arch/x86/guest/xen.c
+++ b/xen/arch/x86/guest/xen.c
@@ -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;
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 53ffccb9c5..9c3d7563f3 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -795,7 +795,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);
diff --git a/xen/include/asm-x86/e820.h b/xen/include/asm-x86/e820.h
index 28defa8545..ee317b17aa 100644
--- a/xen/include/asm-x86/e820.h
+++ b/xen/include/asm-x86/e820.h
@@ -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(
diff --git a/xen/include/asm-x86/guest/hypercall.h 
b/xen/include/asm-x86/guest/hypercall.h
index a05041d30b..e0b00f97fb 100644
--- a/xen/include/asm-x86/guest/hypercall.h
+++ b/xen/include/asm-x86/guest/hypercall.h
@@ -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
  */
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.