]> xenbits.xensource.com Git - people/iwj/xen.git/commitdiff
xen: mark xenstore/console pages as RAM
authorRoger Pau Monne <roger.pau@citrix.com>
Thu, 11 Jan 2018 11:41:18 +0000 (11:41 +0000)
committerRoger Pau Monne <roger.pau@citrix.com>
Fri, 12 Jan 2018 15:47:32 +0000 (15:47 +0000)
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@citrix.com>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
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
xen/arch/x86/guest/xen.c
xen/common/page_alloc.c
xen/drivers/char/xen_pv_console.c
xen/include/asm-x86/guest/xen.h

index b422a684ee676c03cb4a0fe1b224ea723016c3c3..590ea985ef082e1101120b37817e12be473a14d1 100644 (file)
@@ -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);
 
index d4968b47aaeb552e831384048191b674736af5fe..27a6c477531e6a51d7c1b5e3a81f866e77202e47 100644 (file)
 #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
index 5616a8226376a1727a62423e3a54e123d8fc0a78..49b2a917513e262f6d5455bc062fdb6d537bf68c 100644 (file)
 #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. */
index f5aca4c69ebf1bdcf010946ccda5624ec8c320c0..d4f0532101d45d9ce495a1c9509bfd498f3ad05f 100644 (file)
@@ -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:
index b3e684f7568bcbf058384ec47eb7e9a545133229..62255fda8bff25e573fbed8297429f44da549788 100644 (file)
 #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__ */