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

[Xen-changelog] [xen stable-4.10] xen: mark xenstore/console pages as RAM



commit 60dd95357cca09c5ed3c4f3d57c11b732ea8befd
Author:     Roger Pau Monne <roger.pau@xxxxxxxxxx>
AuthorDate: Thu Jan 11 11:41:18 2018 +0000
Commit:     Roger Pau Monne <roger.pau@xxxxxxxxxx>
CommitDate: Fri Jan 12 15:47:32 2018 +0000

    xen: mark xenstore/console pages as RAM
    
    This si required so that later they can be shared with the guest if
    Xen is running in shim mode.
    
    Also prevent them from being used by Xen by marking them as bad pages
    in init_boot_pages.
    
    Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
    Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
    ---
    Changes since v1:
     - Remove adding the pages to dom_io, there's no need since they are
       already marked as bad pages.
     - Use a static global array to store the memory address of this
       special pages, so Xen avoids having to call
       xen_hypercall_hvm_get_param twice.
---
 xen/arch/x86/e820.c               |  4 ++++
 xen/arch/x86/guest/xen.c          | 43 +++++++++++++++++++++++++++++++++++++++
 xen/common/page_alloc.c           | 15 ++++++++++++++
 xen/drivers/char/xen_pv_console.c |  4 ++++
 xen/include/asm-x86/guest/xen.h   | 14 +++++++++++++
 5 files changed, 80 insertions(+)

diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c
index b422a684ee..590ea985ef 100644
--- a/xen/arch/x86/e820.c
+++ b/xen/arch/x86/e820.c
@@ -9,6 +9,7 @@
 #include <asm/processor.h>
 #include <asm/mtrr.h>
 #include <asm/msr.h>
+#include <asm/guest.h>
 
 /*
  * opt_mem: Limit maximum address of physical RAM.
@@ -699,6 +700,9 @@ unsigned long __init init_e820(const char *str, struct 
e820map *raw)
 
     machine_specific_memory_setup(raw);
 
+    if ( xen_guest )
+        hypervisor_fixup_e820(&e820);
+
     printk("%s RAM map:\n", str);
     print_e820_memory_map(e820.map, e820.nr_map);
 
diff --git a/xen/arch/x86/guest/xen.c b/xen/arch/x86/guest/xen.c
index d4968b47aa..27a6c47753 100644
--- a/xen/arch/x86/guest/xen.c
+++ b/xen/arch/x86/guest/xen.c
@@ -32,12 +32,14 @@
 #include <asm/processor.h>
 
 #include <public/arch-x86/cpuid.h>
+#include <public/hvm/params.h>
 
 bool __read_mostly xen_guest;
 
 static __read_mostly uint32_t xen_cpuid_base;
 extern char hypercall_page[];
 static struct rangeset *mem;
+static unsigned long __initdata reserved_pages[2];
 
 DEFINE_PER_CPU(unsigned int, vcpu_id);
 
@@ -279,6 +281,47 @@ int hypervisor_free_unused_page(mfn_t mfn)
     return rangeset_remove_range(mem, mfn_x(mfn), mfn_x(mfn));
 }
 
+static void __init mark_pfn_as_ram(struct e820map *e820, uint64_t pfn)
+{
+    if ( !e820_add_range(e820, pfn << PAGE_SHIFT,
+                         (pfn << PAGE_SHIFT) + PAGE_SIZE, E820_RAM) )
+        if ( !e820_change_range_type(e820, pfn << PAGE_SHIFT,
+                                     (pfn << PAGE_SHIFT) + PAGE_SIZE,
+                                     E820_RESERVED, E820_RAM) )
+            panic("Unable to add/change memory type of pfn %#lx to RAM", pfn);
+}
+
+void __init hypervisor_fixup_e820(struct e820map *e820)
+{
+    uint64_t pfn = 0;
+    unsigned int i = 0;
+    long rc;
+
+    ASSERT(xen_guest);
+
+#define MARK_PARAM_RAM(p) ({                    \
+    rc = xen_hypercall_hvm_get_param(p, &pfn);  \
+    if ( rc )                                   \
+        panic("Unable to get " #p);             \
+    mark_pfn_as_ram(e820, pfn);                 \
+    ASSERT(i < ARRAY_SIZE(reserved_pages));     \
+    reserved_pages[i++] = pfn << PAGE_SHIFT;    \
+})
+    MARK_PARAM_RAM(HVM_PARAM_STORE_PFN);
+    if ( !pv_console )
+        MARK_PARAM_RAM(HVM_PARAM_CONSOLE_PFN);
+#undef MARK_PARAM_RAM
+}
+
+const unsigned long *__init hypervisor_reserved_pages(unsigned int *size)
+{
+    ASSERT(xen_guest);
+
+    *size = ARRAY_SIZE(reserved_pages);
+
+    return reserved_pages;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 5616a82263..49b2a91751 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -143,6 +143,7 @@
 #include <asm/numa.h>
 #include <asm/flushtlb.h>
 #ifdef CONFIG_X86
+#include <asm/guest.h>
 #include <asm/p2m.h>
 #include <asm/setup.h> /* for highmem_start only */
 #else
@@ -303,6 +304,20 @@ void __init init_boot_pages(paddr_t ps, paddr_t pe)
             badpage++;
         }
     }
+
+    if ( xen_guest )
+    {
+        badpage = hypervisor_reserved_pages(&array_size);
+        if ( badpage )
+        {
+            for ( i = 0; i < array_size; i++ )
+            {
+                bootmem_region_zap(*badpage >> PAGE_SHIFT,
+                                   (*badpage >> PAGE_SHIFT) + 1);
+                badpage++;
+            }
+        }
+    }
 #endif
 
     /* Check new pages against the bad-page list. */
diff --git a/xen/drivers/char/xen_pv_console.c 
b/xen/drivers/char/xen_pv_console.c
index f5aca4c69e..d4f0532101 100644
--- a/xen/drivers/char/xen_pv_console.c
+++ b/xen/drivers/char/xen_pv_console.c
@@ -35,6 +35,8 @@ static evtchn_port_t cons_evtchn;
 static serial_rx_fn cons_rx_handler;
 static DEFINE_SPINLOCK(tx_lock);
 
+bool pv_console;
+
 void __init pv_console_init(void)
 {
     long r;
@@ -60,6 +62,8 @@ void __init pv_console_init(void)
 
     printk("Initialised PV console at 0x%p with pfn %#lx and evtchn %#x\n",
             cons_ring, raw_pfn, cons_evtchn);
+    pv_console = true;
+
     return;
 
  error:
diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h
index b3e684f756..62255fda8b 100644
--- a/xen/include/asm-x86/guest/xen.h
+++ b/xen/include/asm-x86/guest/xen.h
@@ -29,12 +29,15 @@
 #ifdef CONFIG_XEN_GUEST
 
 extern bool xen_guest;
+extern bool pv_console;
 
 void probe_hypervisor(void);
 void hypervisor_setup(void);
 void hypervisor_ap_setup(void);
 int hypervisor_alloc_unused_page(mfn_t *mfn);
 int hypervisor_free_unused_page(mfn_t mfn);
+void hypervisor_fixup_e820(struct e820map *e820);
+const unsigned long *hypervisor_reserved_pages(unsigned int *size);
 
 DECLARE_PER_CPU(unsigned int, vcpu_id);
 DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
@@ -42,6 +45,7 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
 #else
 
 #define xen_guest 0
+#define pv_console 0
 
 static inline void probe_hypervisor(void) {};
 static inline void hypervisor_setup(void)
@@ -53,6 +57,16 @@ static inline void hypervisor_ap_setup(void)
     ASSERT_UNREACHABLE();
 }
 
+static inline void hypervisor_fixup_e820(struct e820map *e820)
+{
+    ASSERT_UNREACHABLE();
+}
+static inline const unsigned long *hypervisor_reserved_pages(unsigned int 
*size)
+{
+    ASSERT_UNREACHABLE();
+    return NULL;
+};
+
 #endif /* CONFIG_XEN_GUEST */
 #endif /* __X86_GUEST_XEN_H__ */
 
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.10

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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