From 59f844ed70f7370da58fa5e26112a42af7c282cb Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Sun, 1 May 2016 14:47:11 +0100 Subject: [PATCH] Map the domains shared_info at boot Signed-off-by: Andrew Cooper --- arch/x86/include/arch/mm.h | 2 +- arch/x86/include/arch/traps.h | 9 ++++----- arch/x86/setup.c | 29 +++++++++++++++++++++++++++++ include/xen/memory.h | 18 ++++++++++++++++++ 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/arch/mm.h b/arch/x86/include/arch/mm.h index 4059eba..e4b520c 100644 --- a/arch/x86/include/arch/mm.h +++ b/arch/x86/include/arch/mm.h @@ -44,7 +44,7 @@ static inline unsigned long virt_to_pfn(const void *va) #if defined(CONFIG_PV) #define m2p ((unsigned long *)MACH2PHYS_VIRT_START) -extern struct start_info *start_info; +extern start_info_t *start_info; static inline void *mfn_to_virt(unsigned long mfn) { diff --git a/arch/x86/include/arch/traps.h b/arch/x86/include/arch/traps.h index 4808b08..8965e4b 100644 --- a/arch/x86/include/arch/traps.h +++ b/arch/x86/include/arch/traps.h @@ -6,6 +6,8 @@ #include #include +#include + /* * Arch-specific function to initialise the exception entry points, etc. */ @@ -52,11 +54,8 @@ static inline unsigned int cpu_regs_ss(const struct cpu_regs *regs) extern uint8_t boot_stack[3 * PAGE_SIZE]; extern uint8_t user_stack[PAGE_SIZE]; -#if defined(CONFIG_PV) -#include - -extern struct start_info *start_info; -#endif +extern start_info_t *start_info; +extern shared_info_t shared_info; #endif /* XTF_X86_TRAPS_H */ diff --git a/arch/x86/setup.c b/arch/x86/setup.c index bd2a505..657b5a1 100644 --- a/arch/x86/setup.c +++ b/arch/x86/setup.c @@ -7,6 +7,7 @@ #include #include #include +#include #include /* @@ -32,6 +33,8 @@ const char environment_description[] = ENVIRONMENT_DESCRIPTION; start_info_t *start_info = NULL; #endif +shared_info_t shared_info __page_aligned_bss; + static void collect_cpuid(cpuid_count_fn_t cpuid_fn) { unsigned int tmp, eax, ebx, ecx, edx, addr = 0; @@ -168,6 +171,31 @@ static void setup_pv_console(void) init_pv_console(cons_ring, cons_evtchn); } +static void map_shared_info(void) +{ + int rc; + + if ( IS_DEFINED(CONFIG_HVM) ) + { + struct xen_add_to_physmap xatp = + { + .domid = DOMID_SELF, + .space = XENMAPSPACE_shared_info, + .idx = 0, + .gfn = virt_to_gfn(&shared_info), + }; + + rc = hypercall_memory_op(XENMEM_add_to_physmap, &xatp); + } + else /* PV */ + rc = hypercall_update_va_mapping( + &shared_info, start_info->shared_info | PF_SYM(RW, P), + UVMF_INVLPG); + + if ( rc ) + panic("Failed to map shared_info: %d\n", rc); +} + static void qemu_console_write(const char *buf, size_t len) { asm volatile("rep; outsb" @@ -196,6 +224,7 @@ void arch_setup(void) init_hypercalls(); setup_pv_console(); + map_shared_info(); } /* diff --git a/include/xen/memory.h b/include/xen/memory.h index 5e517ff..37ed16f 100644 --- a/include/xen/memory.h +++ b/include/xen/memory.h @@ -17,6 +17,24 @@ struct xen_memory_reservation { domid_t domid; }; +#define XENMEM_add_to_physmap 7 + +struct xen_add_to_physmap { + domid_t domid; + uint16_t size; + +#define XENMAPSPACE_shared_info 0 +#define XENMAPSPACE_grant_table 1 +#define XENMAPSPACE_gmfn 2 +#define XENMAPSPACE_gmfn_range 3 +#define XENMAPSPACE_gmfn_foreign 4 +#define XENMAPSPACE_dev_mmio 5 + unsigned int space; + + unsigned long idx; + unsigned long gfn; +}; + #define XENMEM_exchange 11 struct xen_memory_exchange { -- 2.39.5