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

[Xen-devel] [PATCH RFC v1 26/74] x86/pvh: Retrieve memory map from Xen



Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/arch/x86/e820.c                   |  3 +--
 xen/arch/x86/guest/pvh-boot.c         | 21 +++++++++++++++++++++
 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, 37 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 b93761f948..da213dfee0 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>
@@ -69,10 +70,30 @@ static void __init convert_pvh_info(void)
     }
 }
 
+static void __init get_memory_map(void)
+{
+    struct xen_memory_map memmap = {
+        .nr_entries = E820MAX,
+        .buffer.p = e820_raw.map,
+    };
+    int rc = xen_hypercall_memory_op(XENMEM_memory_map, &memmap);
+
+    ASSERT(rc == 0);
+    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 c5b43414c9..152e471c06 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 d8059f23b5..edb43bf2cb 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 38791088fb..4bb749f240 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®.