2007-07-18 01:37:04 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* hypercall.h
|
|
|
|
*
|
|
|
|
* Linux-specific hypervisor handling.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002-2004, K A Fraser
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation; or, when distributed
|
|
|
|
* separately from the Linux kernel or incorporated into other
|
|
|
|
* software packages, subject to the following license:
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this source file (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy, modify,
|
|
|
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
* and to permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2008-10-23 07:01:39 +00:00
|
|
|
#ifndef _ASM_X86_XEN_HYPERCALL_H
|
|
|
|
#define _ASM_X86_XEN_HYPERCALL_H
|
2007-07-18 01:37:04 +00:00
|
|
|
|
2008-12-16 20:37:07 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/spinlock.h>
|
2007-07-18 01:37:04 +00:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/string.h>
|
2008-12-16 20:37:07 +00:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
2010-12-16 22:33:27 +00:00
|
|
|
#include <trace/events/xen.h>
|
|
|
|
|
2008-12-16 20:37:07 +00:00
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/pgtable.h>
|
2017-06-26 12:49:46 +00:00
|
|
|
#include <asm/smap.h>
|
2007-07-18 01:37:04 +00:00
|
|
|
|
|
|
|
#include <xen/interface/xen.h>
|
|
|
|
#include <xen/interface/sched.h>
|
|
|
|
#include <xen/interface/physdev.h>
|
2011-09-23 18:44:17 +00:00
|
|
|
#include <xen/interface/platform.h>
|
2012-06-07 11:56:51 +00:00
|
|
|
#include <xen/interface/xen-mca.h>
|
2007-07-18 01:37:04 +00:00
|
|
|
|
2017-06-07 07:20:12 +00:00
|
|
|
struct xen_dm_op_buf;
|
|
|
|
|
2008-07-08 22:06:37 +00:00
|
|
|
/*
|
|
|
|
* The hypercall asms have to meet several constraints:
|
|
|
|
* - Work on 32- and 64-bit.
|
|
|
|
* The two architectures put their arguments in different sets of
|
|
|
|
* registers.
|
|
|
|
*
|
|
|
|
* - Work around asm syntax quirks
|
|
|
|
* It isn't possible to specify one of the rNN registers in a
|
|
|
|
* constraint, so we use explicit register variables to get the
|
|
|
|
* args into the right place.
|
|
|
|
*
|
|
|
|
* - Mark all registers as potentially clobbered
|
|
|
|
* Even unused parameters can be clobbered by the hypervisor, so we
|
|
|
|
* need to make sure gcc knows it.
|
|
|
|
*
|
|
|
|
* - Avoid compiler bugs.
|
|
|
|
* This is the tricky part. Because x86_32 has such a constrained
|
|
|
|
* register set, gcc versions below 4.3 have trouble generating
|
|
|
|
* code when all the arg registers and memory are trashed by the
|
|
|
|
* asm. There are syntactically simpler ways of achieving the
|
|
|
|
* semantics below, but they cause the compiler to crash.
|
|
|
|
*
|
|
|
|
* The only combination I found which works is:
|
|
|
|
* - assign the __argX variables first
|
|
|
|
* - list all actually used parameters as "+r" (__argX)
|
|
|
|
* - clobber the rest
|
|
|
|
*
|
|
|
|
* The result certainly isn't pretty, and it really shows up cpp's
|
|
|
|
* weakness as as macro language. Sorry. (But let's just give thanks
|
|
|
|
* there aren't more than 5 arguments...)
|
|
|
|
*/
|
|
|
|
|
2007-07-18 01:37:04 +00:00
|
|
|
extern struct { char _entry[32]; } hypercall_page[];
|
|
|
|
|
2008-07-08 22:06:37 +00:00
|
|
|
#define __HYPERCALL "call hypercall_page+%c[offset]"
|
|
|
|
#define __HYPERCALL_ENTRY(x) \
|
|
|
|
[offset] "i" (__HYPERVISOR_##x * sizeof(hypercall_page[0]))
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
#define __HYPERCALL_RETREG "eax"
|
|
|
|
#define __HYPERCALL_ARG1REG "ebx"
|
|
|
|
#define __HYPERCALL_ARG2REG "ecx"
|
|
|
|
#define __HYPERCALL_ARG3REG "edx"
|
|
|
|
#define __HYPERCALL_ARG4REG "esi"
|
|
|
|
#define __HYPERCALL_ARG5REG "edi"
|
|
|
|
#else
|
|
|
|
#define __HYPERCALL_RETREG "rax"
|
|
|
|
#define __HYPERCALL_ARG1REG "rdi"
|
|
|
|
#define __HYPERCALL_ARG2REG "rsi"
|
|
|
|
#define __HYPERCALL_ARG3REG "rdx"
|
|
|
|
#define __HYPERCALL_ARG4REG "r10"
|
|
|
|
#define __HYPERCALL_ARG5REG "r8"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define __HYPERCALL_DECLS \
|
|
|
|
register unsigned long __res asm(__HYPERCALL_RETREG); \
|
|
|
|
register unsigned long __arg1 asm(__HYPERCALL_ARG1REG) = __arg1; \
|
|
|
|
register unsigned long __arg2 asm(__HYPERCALL_ARG2REG) = __arg2; \
|
|
|
|
register unsigned long __arg3 asm(__HYPERCALL_ARG3REG) = __arg3; \
|
|
|
|
register unsigned long __arg4 asm(__HYPERCALL_ARG4REG) = __arg4; \
|
2016-01-21 22:49:09 +00:00
|
|
|
register unsigned long __arg5 asm(__HYPERCALL_ARG5REG) = __arg5; \
|
|
|
|
register void *__sp asm(_ASM_SP);
|
2008-07-08 22:06:37 +00:00
|
|
|
|
2016-01-21 22:49:09 +00:00
|
|
|
#define __HYPERCALL_0PARAM "=r" (__res), "+r" (__sp)
|
2008-07-08 22:06:37 +00:00
|
|
|
#define __HYPERCALL_1PARAM __HYPERCALL_0PARAM, "+r" (__arg1)
|
|
|
|
#define __HYPERCALL_2PARAM __HYPERCALL_1PARAM, "+r" (__arg2)
|
|
|
|
#define __HYPERCALL_3PARAM __HYPERCALL_2PARAM, "+r" (__arg3)
|
|
|
|
#define __HYPERCALL_4PARAM __HYPERCALL_3PARAM, "+r" (__arg4)
|
|
|
|
#define __HYPERCALL_5PARAM __HYPERCALL_4PARAM, "+r" (__arg5)
|
|
|
|
|
|
|
|
#define __HYPERCALL_0ARG()
|
|
|
|
#define __HYPERCALL_1ARG(a1) \
|
|
|
|
__HYPERCALL_0ARG() __arg1 = (unsigned long)(a1);
|
|
|
|
#define __HYPERCALL_2ARG(a1,a2) \
|
|
|
|
__HYPERCALL_1ARG(a1) __arg2 = (unsigned long)(a2);
|
|
|
|
#define __HYPERCALL_3ARG(a1,a2,a3) \
|
|
|
|
__HYPERCALL_2ARG(a1,a2) __arg3 = (unsigned long)(a3);
|
|
|
|
#define __HYPERCALL_4ARG(a1,a2,a3,a4) \
|
|
|
|
__HYPERCALL_3ARG(a1,a2,a3) __arg4 = (unsigned long)(a4);
|
|
|
|
#define __HYPERCALL_5ARG(a1,a2,a3,a4,a5) \
|
|
|
|
__HYPERCALL_4ARG(a1,a2,a3,a4) __arg5 = (unsigned long)(a5);
|
|
|
|
|
|
|
|
#define __HYPERCALL_CLOBBER5 "memory"
|
|
|
|
#define __HYPERCALL_CLOBBER4 __HYPERCALL_CLOBBER5, __HYPERCALL_ARG5REG
|
|
|
|
#define __HYPERCALL_CLOBBER3 __HYPERCALL_CLOBBER4, __HYPERCALL_ARG4REG
|
|
|
|
#define __HYPERCALL_CLOBBER2 __HYPERCALL_CLOBBER3, __HYPERCALL_ARG3REG
|
|
|
|
#define __HYPERCALL_CLOBBER1 __HYPERCALL_CLOBBER2, __HYPERCALL_ARG2REG
|
|
|
|
#define __HYPERCALL_CLOBBER0 __HYPERCALL_CLOBBER1, __HYPERCALL_ARG1REG
|
|
|
|
|
2007-07-18 01:37:04 +00:00
|
|
|
#define _hypercall0(type, name) \
|
|
|
|
({ \
|
2008-07-08 22:06:37 +00:00
|
|
|
__HYPERCALL_DECLS; \
|
|
|
|
__HYPERCALL_0ARG(); \
|
|
|
|
asm volatile (__HYPERCALL \
|
|
|
|
: __HYPERCALL_0PARAM \
|
|
|
|
: __HYPERCALL_ENTRY(name) \
|
|
|
|
: __HYPERCALL_CLOBBER0); \
|
2007-07-18 01:37:04 +00:00
|
|
|
(type)__res; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define _hypercall1(type, name, a1) \
|
|
|
|
({ \
|
2008-07-08 22:06:37 +00:00
|
|
|
__HYPERCALL_DECLS; \
|
|
|
|
__HYPERCALL_1ARG(a1); \
|
|
|
|
asm volatile (__HYPERCALL \
|
|
|
|
: __HYPERCALL_1PARAM \
|
|
|
|
: __HYPERCALL_ENTRY(name) \
|
|
|
|
: __HYPERCALL_CLOBBER1); \
|
2007-07-18 01:37:04 +00:00
|
|
|
(type)__res; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define _hypercall2(type, name, a1, a2) \
|
|
|
|
({ \
|
2008-07-08 22:06:37 +00:00
|
|
|
__HYPERCALL_DECLS; \
|
|
|
|
__HYPERCALL_2ARG(a1, a2); \
|
|
|
|
asm volatile (__HYPERCALL \
|
|
|
|
: __HYPERCALL_2PARAM \
|
|
|
|
: __HYPERCALL_ENTRY(name) \
|
|
|
|
: __HYPERCALL_CLOBBER2); \
|
2007-07-18 01:37:04 +00:00
|
|
|
(type)__res; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define _hypercall3(type, name, a1, a2, a3) \
|
|
|
|
({ \
|
2008-07-08 22:06:37 +00:00
|
|
|
__HYPERCALL_DECLS; \
|
|
|
|
__HYPERCALL_3ARG(a1, a2, a3); \
|
|
|
|
asm volatile (__HYPERCALL \
|
|
|
|
: __HYPERCALL_3PARAM \
|
|
|
|
: __HYPERCALL_ENTRY(name) \
|
|
|
|
: __HYPERCALL_CLOBBER3); \
|
2007-07-18 01:37:04 +00:00
|
|
|
(type)__res; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define _hypercall4(type, name, a1, a2, a3, a4) \
|
|
|
|
({ \
|
2008-07-08 22:06:37 +00:00
|
|
|
__HYPERCALL_DECLS; \
|
|
|
|
__HYPERCALL_4ARG(a1, a2, a3, a4); \
|
|
|
|
asm volatile (__HYPERCALL \
|
|
|
|
: __HYPERCALL_4PARAM \
|
|
|
|
: __HYPERCALL_ENTRY(name) \
|
|
|
|
: __HYPERCALL_CLOBBER4); \
|
2007-07-18 01:37:04 +00:00
|
|
|
(type)__res; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define _hypercall5(type, name, a1, a2, a3, a4, a5) \
|
|
|
|
({ \
|
2008-07-08 22:06:37 +00:00
|
|
|
__HYPERCALL_DECLS; \
|
|
|
|
__HYPERCALL_5ARG(a1, a2, a3, a4, a5); \
|
|
|
|
asm volatile (__HYPERCALL \
|
|
|
|
: __HYPERCALL_5PARAM \
|
|
|
|
: __HYPERCALL_ENTRY(name) \
|
|
|
|
: __HYPERCALL_CLOBBER5); \
|
2007-07-18 01:37:04 +00:00
|
|
|
(type)__res; \
|
|
|
|
})
|
|
|
|
|
2009-02-09 20:05:49 +00:00
|
|
|
static inline long
|
|
|
|
privcmd_call(unsigned call,
|
|
|
|
unsigned long a1, unsigned long a2,
|
|
|
|
unsigned long a3, unsigned long a4,
|
|
|
|
unsigned long a5)
|
|
|
|
{
|
|
|
|
__HYPERCALL_DECLS;
|
|
|
|
__HYPERCALL_5ARG(a1, a2, a3, a4, a5);
|
|
|
|
|
2017-06-26 12:49:46 +00:00
|
|
|
stac();
|
2009-02-09 20:05:49 +00:00
|
|
|
asm volatile("call *%[call]"
|
|
|
|
: __HYPERCALL_5PARAM
|
|
|
|
: [call] "a" (&hypercall_page[call])
|
|
|
|
: __HYPERCALL_CLOBBER5);
|
2017-06-26 12:49:46 +00:00
|
|
|
clac();
|
2009-02-09 20:05:49 +00:00
|
|
|
|
|
|
|
return (long)__res;
|
|
|
|
}
|
|
|
|
|
2007-07-18 01:37:04 +00:00
|
|
|
static inline int
|
|
|
|
HYPERVISOR_set_trap_table(struct trap_info *table)
|
|
|
|
{
|
|
|
|
return _hypercall1(int, set_trap_table, table);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_mmu_update(struct mmu_update *req, int count,
|
|
|
|
int *success_count, domid_t domid)
|
|
|
|
{
|
|
|
|
return _hypercall4(int, mmu_update, req, count, success_count, domid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_mmuext_op(struct mmuext_op *op, int count,
|
|
|
|
int *success_count, domid_t domid)
|
|
|
|
{
|
|
|
|
return _hypercall4(int, mmuext_op, op, count, success_count, domid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
|
|
|
|
{
|
|
|
|
return _hypercall2(int, set_gdt, frame_list, entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
|
|
|
|
{
|
|
|
|
return _hypercall2(int, stack_switch, ss, esp);
|
|
|
|
}
|
|
|
|
|
2008-07-08 22:07:02 +00:00
|
|
|
#ifdef CONFIG_X86_32
|
2007-07-18 01:37:04 +00:00
|
|
|
static inline int
|
|
|
|
HYPERVISOR_set_callbacks(unsigned long event_selector,
|
|
|
|
unsigned long event_address,
|
|
|
|
unsigned long failsafe_selector,
|
|
|
|
unsigned long failsafe_address)
|
|
|
|
{
|
|
|
|
return _hypercall4(int, set_callbacks,
|
|
|
|
event_selector, event_address,
|
|
|
|
failsafe_selector, failsafe_address);
|
|
|
|
}
|
2008-07-08 22:07:02 +00:00
|
|
|
#else /* CONFIG_X86_64 */
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_set_callbacks(unsigned long event_address,
|
|
|
|
unsigned long failsafe_address,
|
|
|
|
unsigned long syscall_address)
|
|
|
|
{
|
|
|
|
return _hypercall3(int, set_callbacks,
|
|
|
|
event_address, failsafe_address,
|
|
|
|
syscall_address);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_X86_{32,64} */
|
2007-07-18 01:37:04 +00:00
|
|
|
|
2008-03-17 23:37:15 +00:00
|
|
|
static inline int
|
|
|
|
HYPERVISOR_callback_op(int cmd, void *arg)
|
|
|
|
{
|
|
|
|
return _hypercall2(int, callback_op, cmd, arg);
|
|
|
|
}
|
|
|
|
|
2007-07-18 01:37:04 +00:00
|
|
|
static inline int
|
|
|
|
HYPERVISOR_fpu_taskswitch(int set)
|
|
|
|
{
|
|
|
|
return _hypercall1(int, fpu_taskswitch, set);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2008-05-26 22:31:02 +00:00
|
|
|
HYPERVISOR_sched_op(int cmd, void *arg)
|
2007-07-18 01:37:04 +00:00
|
|
|
{
|
2011-02-17 11:04:20 +00:00
|
|
|
return _hypercall2(int, sched_op, cmd, arg);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline long
|
|
|
|
HYPERVISOR_set_timer_op(u64 timeout)
|
|
|
|
{
|
|
|
|
unsigned long timeout_hi = (unsigned long)(timeout>>32);
|
|
|
|
unsigned long timeout_lo = (unsigned long)timeout;
|
|
|
|
return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
|
|
|
|
}
|
|
|
|
|
2012-06-07 11:56:51 +00:00
|
|
|
static inline int
|
|
|
|
HYPERVISOR_mca(struct xen_mc *mc_op)
|
|
|
|
{
|
|
|
|
mc_op->interface_version = XEN_MCA_INTERFACE_VERSION;
|
|
|
|
return _hypercall1(int, mca, mc_op);
|
|
|
|
}
|
|
|
|
|
2011-09-23 18:44:17 +00:00
|
|
|
static inline int
|
2015-11-23 10:36:12 +00:00
|
|
|
HYPERVISOR_platform_op(struct xen_platform_op *op)
|
2011-09-23 18:44:17 +00:00
|
|
|
{
|
2015-11-23 10:36:12 +00:00
|
|
|
op->interface_version = XENPF_INTERFACE_VERSION;
|
|
|
|
return _hypercall1(int, platform_op, op);
|
2011-09-23 18:44:17 +00:00
|
|
|
}
|
|
|
|
|
2007-07-18 01:37:04 +00:00
|
|
|
static inline int
|
|
|
|
HYPERVISOR_set_debugreg(int reg, unsigned long value)
|
|
|
|
{
|
|
|
|
return _hypercall2(int, set_debugreg, reg, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long
|
|
|
|
HYPERVISOR_get_debugreg(int reg)
|
|
|
|
{
|
|
|
|
return _hypercall1(unsigned long, get_debugreg, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_update_descriptor(u64 ma, u64 desc)
|
|
|
|
{
|
2009-03-12 11:54:54 +00:00
|
|
|
if (sizeof(u64) == sizeof(long))
|
|
|
|
return _hypercall2(int, update_descriptor, ma, desc);
|
2007-07-18 01:37:04 +00:00
|
|
|
return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
|
|
|
|
}
|
|
|
|
|
2015-09-04 12:50:33 +00:00
|
|
|
static inline long
|
2007-07-18 01:37:04 +00:00
|
|
|
HYPERVISOR_memory_op(unsigned int cmd, void *arg)
|
|
|
|
{
|
2015-09-04 12:50:33 +00:00
|
|
|
return _hypercall2(long, memory_op, cmd, arg);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2014-04-17 12:57:37 +00:00
|
|
|
HYPERVISOR_multicall(void *call_list, uint32_t nr_calls)
|
2007-07-18 01:37:04 +00:00
|
|
|
{
|
|
|
|
return _hypercall2(int, multicall, call_list, nr_calls);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_update_va_mapping(unsigned long va, pte_t new_val,
|
|
|
|
unsigned long flags)
|
|
|
|
{
|
2008-07-08 22:06:36 +00:00
|
|
|
if (sizeof(new_val) == sizeof(long))
|
|
|
|
return _hypercall3(int, update_va_mapping, va,
|
|
|
|
new_val.pte, flags);
|
|
|
|
else
|
|
|
|
return _hypercall4(int, update_va_mapping, va,
|
|
|
|
new_val.pte, new_val.pte >> 32, flags);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
2012-10-19 19:25:37 +00:00
|
|
|
extern int __must_check xen_event_channel_op_compat(int, void *);
|
2007-07-18 01:37:04 +00:00
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_event_channel_op(int cmd, void *arg)
|
|
|
|
{
|
|
|
|
int rc = _hypercall2(int, event_channel_op, cmd, arg);
|
2012-10-19 19:25:37 +00:00
|
|
|
if (unlikely(rc == -ENOSYS))
|
|
|
|
rc = xen_event_channel_op_compat(cmd, arg);
|
2007-07-18 01:37:04 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_xen_version(int cmd, void *arg)
|
|
|
|
{
|
|
|
|
return _hypercall2(int, xen_version, cmd, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_console_io(int cmd, int count, char *str)
|
|
|
|
{
|
|
|
|
return _hypercall3(int, console_io, cmd, count, str);
|
|
|
|
}
|
|
|
|
|
2013-03-12 15:06:23 +00:00
|
|
|
extern int __must_check xen_physdev_op_compat(int, void *);
|
2012-10-19 19:25:37 +00:00
|
|
|
|
2007-07-18 01:37:04 +00:00
|
|
|
static inline int
|
|
|
|
HYPERVISOR_physdev_op(int cmd, void *arg)
|
|
|
|
{
|
|
|
|
int rc = _hypercall2(int, physdev_op, cmd, arg);
|
2012-10-19 19:25:37 +00:00
|
|
|
if (unlikely(rc == -ENOSYS))
|
2013-03-12 15:06:23 +00:00
|
|
|
rc = xen_physdev_op_compat(cmd, arg);
|
2007-07-18 01:37:04 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count)
|
|
|
|
{
|
|
|
|
return _hypercall3(int, grant_table_op, cmd, uop, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_update_va_mapping_otherdomain(unsigned long va, pte_t new_val,
|
|
|
|
unsigned long flags, domid_t domid)
|
|
|
|
{
|
2008-07-08 22:06:36 +00:00
|
|
|
if (sizeof(new_val) == sizeof(long))
|
|
|
|
return _hypercall4(int, update_va_mapping_otherdomain, va,
|
|
|
|
new_val.pte, flags, domid);
|
|
|
|
else
|
|
|
|
return _hypercall5(int, update_va_mapping_otherdomain, va,
|
|
|
|
new_val.pte, new_val.pte >> 32,
|
|
|
|
flags, domid);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_vm_assist(unsigned int cmd, unsigned int type)
|
|
|
|
{
|
|
|
|
return _hypercall2(int, vm_assist, cmd, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args)
|
|
|
|
{
|
|
|
|
return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
|
|
|
|
}
|
|
|
|
|
2008-07-08 22:07:04 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_set_segment_base(int reg, unsigned long value)
|
|
|
|
{
|
|
|
|
return _hypercall2(int, set_segment_base, reg, value);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-18 01:37:04 +00:00
|
|
|
static inline int
|
2011-02-17 11:04:20 +00:00
|
|
|
HYPERVISOR_suspend(unsigned long start_info_mfn)
|
2007-07-18 01:37:04 +00:00
|
|
|
{
|
2011-02-17 11:04:20 +00:00
|
|
|
struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For a PV guest the tools require that the start_info mfn be
|
|
|
|
* present in rdx/edx when the hypercall is made. Per the
|
|
|
|
* hypercall calling convention this is the third hypercall
|
|
|
|
* argument, which is start_info_mfn here.
|
|
|
|
*/
|
2011-02-17 11:04:20 +00:00
|
|
|
return _hypercall3(int, sched_op, SCHEDOP_shutdown, &r, start_info_mfn);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
HYPERVISOR_nmi_op(unsigned long op, unsigned long arg)
|
|
|
|
{
|
|
|
|
return _hypercall2(int, nmi_op, op, arg);
|
|
|
|
}
|
|
|
|
|
2010-05-14 11:38:24 +00:00
|
|
|
static inline unsigned long __must_check
|
|
|
|
HYPERVISOR_hvm_op(int op, void *arg)
|
|
|
|
{
|
|
|
|
return _hypercall2(unsigned long, hvm_op, op, arg);
|
|
|
|
}
|
|
|
|
|
2011-05-26 16:02:21 +00:00
|
|
|
static inline int
|
|
|
|
HYPERVISOR_tmem_op(
|
|
|
|
struct tmem_op *op)
|
|
|
|
{
|
|
|
|
return _hypercall1(int, tmem_op, op);
|
|
|
|
}
|
|
|
|
|
2015-08-10 20:34:33 +00:00
|
|
|
static inline int
|
|
|
|
HYPERVISOR_xenpmu_op(unsigned int op, void *arg)
|
|
|
|
{
|
|
|
|
return _hypercall2(int, xenpmu_op, op, arg);
|
|
|
|
}
|
|
|
|
|
2017-02-13 17:03:23 +00:00
|
|
|
static inline int
|
|
|
|
HYPERVISOR_dm_op(
|
2017-06-07 07:20:12 +00:00
|
|
|
domid_t dom, unsigned int nr_bufs, struct xen_dm_op_buf *bufs)
|
2017-02-13 17:03:23 +00:00
|
|
|
{
|
2017-06-26 12:49:46 +00:00
|
|
|
int ret;
|
|
|
|
stac();
|
|
|
|
ret = _hypercall3(int, dm_op, dom, nr_bufs, bufs);
|
|
|
|
clac();
|
|
|
|
return ret;
|
2017-02-13 17:03:23 +00:00
|
|
|
}
|
|
|
|
|
2008-05-26 22:31:01 +00:00
|
|
|
static inline void
|
|
|
|
MULTI_fpu_taskswitch(struct multicall_entry *mcl, int set)
|
|
|
|
{
|
|
|
|
mcl->op = __HYPERVISOR_fpu_taskswitch;
|
|
|
|
mcl->args[0] = set;
|
2010-12-16 22:33:27 +00:00
|
|
|
|
|
|
|
trace_xen_mc_entry(mcl, 1);
|
2008-05-26 22:31:01 +00:00
|
|
|
}
|
|
|
|
|
2007-07-18 01:37:04 +00:00
|
|
|
static inline void
|
|
|
|
MULTI_update_va_mapping(struct multicall_entry *mcl, unsigned long va,
|
|
|
|
pte_t new_val, unsigned long flags)
|
|
|
|
{
|
|
|
|
mcl->op = __HYPERVISOR_update_va_mapping;
|
|
|
|
mcl->args[0] = va;
|
2008-07-08 22:06:36 +00:00
|
|
|
if (sizeof(new_val) == sizeof(long)) {
|
|
|
|
mcl->args[1] = new_val.pte;
|
|
|
|
mcl->args[2] = flags;
|
|
|
|
} else {
|
|
|
|
mcl->args[1] = new_val.pte;
|
|
|
|
mcl->args[2] = new_val.pte >> 32;
|
|
|
|
mcl->args[3] = flags;
|
|
|
|
}
|
2010-12-16 22:33:27 +00:00
|
|
|
|
|
|
|
trace_xen_mc_entry(mcl, sizeof(new_val) == sizeof(long) ? 3 : 4);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MULTI_grant_table_op(struct multicall_entry *mcl, unsigned int cmd,
|
|
|
|
void *uop, unsigned int count)
|
|
|
|
{
|
|
|
|
mcl->op = __HYPERVISOR_grant_table_op;
|
|
|
|
mcl->args[0] = cmd;
|
|
|
|
mcl->args[1] = (unsigned long)uop;
|
|
|
|
mcl->args[2] = count;
|
2010-12-16 22:33:27 +00:00
|
|
|
|
|
|
|
trace_xen_mc_entry(mcl, 3);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MULTI_update_va_mapping_otherdomain(struct multicall_entry *mcl, unsigned long va,
|
|
|
|
pte_t new_val, unsigned long flags,
|
|
|
|
domid_t domid)
|
|
|
|
{
|
|
|
|
mcl->op = __HYPERVISOR_update_va_mapping_otherdomain;
|
|
|
|
mcl->args[0] = va;
|
2008-07-08 22:06:36 +00:00
|
|
|
if (sizeof(new_val) == sizeof(long)) {
|
|
|
|
mcl->args[1] = new_val.pte;
|
|
|
|
mcl->args[2] = flags;
|
|
|
|
mcl->args[3] = domid;
|
|
|
|
} else {
|
|
|
|
mcl->args[1] = new_val.pte;
|
|
|
|
mcl->args[2] = new_val.pte >> 32;
|
|
|
|
mcl->args[3] = flags;
|
|
|
|
mcl->args[4] = domid;
|
|
|
|
}
|
2010-12-16 22:33:27 +00:00
|
|
|
|
|
|
|
trace_xen_mc_entry(mcl, sizeof(new_val) == sizeof(long) ? 4 : 5);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MULTI_update_descriptor(struct multicall_entry *mcl, u64 maddr,
|
|
|
|
struct desc_struct desc)
|
|
|
|
{
|
|
|
|
mcl->op = __HYPERVISOR_update_descriptor;
|
2008-07-08 22:07:11 +00:00
|
|
|
if (sizeof(maddr) == sizeof(long)) {
|
|
|
|
mcl->args[0] = maddr;
|
|
|
|
mcl->args[1] = *(unsigned long *)&desc;
|
|
|
|
} else {
|
|
|
|
mcl->args[0] = maddr;
|
|
|
|
mcl->args[1] = maddr >> 32;
|
|
|
|
mcl->args[2] = desc.a;
|
|
|
|
mcl->args[3] = desc.b;
|
|
|
|
}
|
2010-12-16 22:33:27 +00:00
|
|
|
|
|
|
|
trace_xen_mc_entry(mcl, sizeof(maddr) == sizeof(long) ? 2 : 4);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MULTI_memory_op(struct multicall_entry *mcl, unsigned int cmd, void *arg)
|
|
|
|
{
|
|
|
|
mcl->op = __HYPERVISOR_memory_op;
|
|
|
|
mcl->args[0] = cmd;
|
|
|
|
mcl->args[1] = (unsigned long)arg;
|
2010-12-16 22:33:27 +00:00
|
|
|
|
|
|
|
trace_xen_mc_entry(mcl, 2);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MULTI_mmu_update(struct multicall_entry *mcl, struct mmu_update *req,
|
|
|
|
int count, int *success_count, domid_t domid)
|
|
|
|
{
|
|
|
|
mcl->op = __HYPERVISOR_mmu_update;
|
|
|
|
mcl->args[0] = (unsigned long)req;
|
|
|
|
mcl->args[1] = count;
|
|
|
|
mcl->args[2] = (unsigned long)success_count;
|
|
|
|
mcl->args[3] = domid;
|
2010-12-16 22:33:27 +00:00
|
|
|
|
|
|
|
trace_xen_mc_entry(mcl, 4);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MULTI_mmuext_op(struct multicall_entry *mcl, struct mmuext_op *op, int count,
|
|
|
|
int *success_count, domid_t domid)
|
|
|
|
{
|
|
|
|
mcl->op = __HYPERVISOR_mmuext_op;
|
|
|
|
mcl->args[0] = (unsigned long)op;
|
|
|
|
mcl->args[1] = count;
|
|
|
|
mcl->args[2] = (unsigned long)success_count;
|
|
|
|
mcl->args[3] = domid;
|
2010-12-16 22:33:27 +00:00
|
|
|
|
|
|
|
trace_xen_mc_entry(mcl, 4);
|
2007-07-18 01:37:04 +00:00
|
|
|
}
|
xen: Core Xen implementation
This patch is a rollup of all the core pieces of the Xen
implementation, including:
- booting and setup
- pagetable setup
- privileged instructions
- segmentation
- interrupt flags
- upcalls
- multicall batching
BOOTING AND SETUP
The vmlinux image is decorated with ELF notes which tell the Xen
domain builder what the kernel's requirements are; the domain builder
then constructs the address space accordingly and starts the kernel.
Xen has its own entrypoint for the kernel (contained in an ELF note).
The ELF notes are set up by xen-head.S, which is included into head.S.
In principle it could be linked separately, but it seems to provoke
lots of binutils bugs.
Because the domain builder starts the kernel in a fairly sane state
(32-bit protected mode, paging enabled, flat segments set up), there's
not a lot of setup needed before starting the kernel proper. The main
steps are:
1. Install the Xen paravirt_ops, which is simply a matter of a
structure assignment.
2. Set init_mm to use the Xen-supplied pagetables (analogous to the
head.S generated pagetables in a native boot).
3. Reserve address space for Xen, since it takes a chunk at the top
of the address space for its own use.
4. Call start_kernel()
PAGETABLE SETUP
Once we hit the main kernel boot sequence, it will end up calling back
via paravirt_ops to set up various pieces of Xen specific state. One
of the critical things which requires a bit of extra care is the
construction of the initial init_mm pagetable. Because Xen places
tight constraints on pagetables (an active pagetable must always be
valid, and must always be mapped read-only to the guest domain), we
need to be careful when constructing the new pagetable to keep these
constraints in mind. It turns out that the easiest way to do this is
use the initial Xen-provided pagetable as a template, and then just
insert new mappings for memory where a mapping doesn't already exist.
This means that during pagetable setup, it uses a special version of
xen_set_pte which ignores any attempt to remap a read-only page as
read-write (since Xen will map its own initial pagetable as RO), but
lets other changes to the ptes happen, so that things like NX are set
properly.
PRIVILEGED INSTRUCTIONS AND SEGMENTATION
When the kernel runs under Xen, it runs in ring 1 rather than ring 0.
This means that it is more privileged than user-mode in ring 3, but it
still can't run privileged instructions directly. Non-performance
critical instructions are dealt with by taking a privilege exception
and trapping into the hypervisor and emulating the instruction, but
more performance-critical instructions have their own specific
paravirt_ops. In many cases we can avoid having to do any hypercalls
for these instructions, or the Xen implementation is quite different
from the normal native version.
The privileged instructions fall into the broad classes of:
Segmentation: setting up the GDT and the GDT entries, LDT,
TLS and so on. Xen doesn't allow the GDT to be directly
modified; all GDT updates are done via hypercalls where the new
entries can be validated. This is important because Xen uses
segment limits to prevent the guest kernel from damaging the
hypervisor itself.
Traps and exceptions: Xen uses a special format for trap entrypoints,
so when the kernel wants to set an IDT entry, it needs to be
converted to the form Xen expects. Xen sets int 0x80 up specially
so that the trap goes straight from userspace into the guest kernel
without going via the hypervisor. sysenter isn't supported.
Kernel stack: The esp0 entry is extracted from the tss and provided to
Xen.
TLB operations: the various TLB calls are mapped into corresponding
Xen hypercalls.
Control registers: all the control registers are privileged. The most
important is cr3, which points to the base of the current pagetable,
and we handle it specially.
Another instruction we treat specially is CPUID, even though its not
privileged. We want to control what CPU features are visible to the
rest of the kernel, and so CPUID ends up going into a paravirt_op.
Xen implements this mainly to disable the ACPI and APIC subsystems.
INTERRUPT FLAGS
Xen maintains its own separate flag for masking events, which is
contained within the per-cpu vcpu_info structure. Because the guest
kernel runs in ring 1 and not 0, the IF flag in EFLAGS is completely
ignored (and must be, because even if a guest domain disables
interrupts for itself, it can't disable them overall).
(A note on terminology: "events" and interrupts are effectively
synonymous. However, rather than using an "enable flag", Xen uses a
"mask flag", which blocks event delivery when it is non-zero.)
There are paravirt_ops for each of cli/sti/save_fl/restore_fl, which
are implemented to manage the Xen event mask state. The only thing
worth noting is that when events are unmasked, we need to explicitly
see if there's a pending event and call into the hypervisor to make
sure it gets delivered.
UPCALLS
Xen needs a couple of upcall (or callback) functions to be implemented
by each guest. One is the event upcalls, which is how events
(interrupts, effectively) are delivered to the guests. The other is
the failsafe callback, which is used to report errors in either
reloading a segment register, or caused by iret. These are
implemented in i386/kernel/entry.S so they can jump into the normal
iret_exc path when necessary.
MULTICALL BATCHING
Xen provides a multicall mechanism, which allows multiple hypercalls
to be issued at once in order to mitigate the cost of trapping into
the hypervisor. This is particularly useful for context switches,
since the 4-5 hypercalls they would normally need (reload cr3, update
TLS, maybe update LDT) can be reduced to one. This patch implements a
generic batching mechanism for hypercalls, which gets used in many
places in the Xen code.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ian Pratt <ian.pratt@xensource.com>
Cc: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Cc: Adrian Bunk <bunk@stusta.de>
2007-07-18 01:37:04 +00:00
|
|
|
|
|
|
|
static inline void
|
|
|
|
MULTI_set_gdt(struct multicall_entry *mcl, unsigned long *frames, int entries)
|
|
|
|
{
|
|
|
|
mcl->op = __HYPERVISOR_set_gdt;
|
|
|
|
mcl->args[0] = (unsigned long)frames;
|
|
|
|
mcl->args[1] = entries;
|
2010-12-16 22:33:27 +00:00
|
|
|
|
|
|
|
trace_xen_mc_entry(mcl, 2);
|
xen: Core Xen implementation
This patch is a rollup of all the core pieces of the Xen
implementation, including:
- booting and setup
- pagetable setup
- privileged instructions
- segmentation
- interrupt flags
- upcalls
- multicall batching
BOOTING AND SETUP
The vmlinux image is decorated with ELF notes which tell the Xen
domain builder what the kernel's requirements are; the domain builder
then constructs the address space accordingly and starts the kernel.
Xen has its own entrypoint for the kernel (contained in an ELF note).
The ELF notes are set up by xen-head.S, which is included into head.S.
In principle it could be linked separately, but it seems to provoke
lots of binutils bugs.
Because the domain builder starts the kernel in a fairly sane state
(32-bit protected mode, paging enabled, flat segments set up), there's
not a lot of setup needed before starting the kernel proper. The main
steps are:
1. Install the Xen paravirt_ops, which is simply a matter of a
structure assignment.
2. Set init_mm to use the Xen-supplied pagetables (analogous to the
head.S generated pagetables in a native boot).
3. Reserve address space for Xen, since it takes a chunk at the top
of the address space for its own use.
4. Call start_kernel()
PAGETABLE SETUP
Once we hit the main kernel boot sequence, it will end up calling back
via paravirt_ops to set up various pieces of Xen specific state. One
of the critical things which requires a bit of extra care is the
construction of the initial init_mm pagetable. Because Xen places
tight constraints on pagetables (an active pagetable must always be
valid, and must always be mapped read-only to the guest domain), we
need to be careful when constructing the new pagetable to keep these
constraints in mind. It turns out that the easiest way to do this is
use the initial Xen-provided pagetable as a template, and then just
insert new mappings for memory where a mapping doesn't already exist.
This means that during pagetable setup, it uses a special version of
xen_set_pte which ignores any attempt to remap a read-only page as
read-write (since Xen will map its own initial pagetable as RO), but
lets other changes to the ptes happen, so that things like NX are set
properly.
PRIVILEGED INSTRUCTIONS AND SEGMENTATION
When the kernel runs under Xen, it runs in ring 1 rather than ring 0.
This means that it is more privileged than user-mode in ring 3, but it
still can't run privileged instructions directly. Non-performance
critical instructions are dealt with by taking a privilege exception
and trapping into the hypervisor and emulating the instruction, but
more performance-critical instructions have their own specific
paravirt_ops. In many cases we can avoid having to do any hypercalls
for these instructions, or the Xen implementation is quite different
from the normal native version.
The privileged instructions fall into the broad classes of:
Segmentation: setting up the GDT and the GDT entries, LDT,
TLS and so on. Xen doesn't allow the GDT to be directly
modified; all GDT updates are done via hypercalls where the new
entries can be validated. This is important because Xen uses
segment limits to prevent the guest kernel from damaging the
hypervisor itself.
Traps and exceptions: Xen uses a special format for trap entrypoints,
so when the kernel wants to set an IDT entry, it needs to be
converted to the form Xen expects. Xen sets int 0x80 up specially
so that the trap goes straight from userspace into the guest kernel
without going via the hypervisor. sysenter isn't supported.
Kernel stack: The esp0 entry is extracted from the tss and provided to
Xen.
TLB operations: the various TLB calls are mapped into corresponding
Xen hypercalls.
Control registers: all the control registers are privileged. The most
important is cr3, which points to the base of the current pagetable,
and we handle it specially.
Another instruction we treat specially is CPUID, even though its not
privileged. We want to control what CPU features are visible to the
rest of the kernel, and so CPUID ends up going into a paravirt_op.
Xen implements this mainly to disable the ACPI and APIC subsystems.
INTERRUPT FLAGS
Xen maintains its own separate flag for masking events, which is
contained within the per-cpu vcpu_info structure. Because the guest
kernel runs in ring 1 and not 0, the IF flag in EFLAGS is completely
ignored (and must be, because even if a guest domain disables
interrupts for itself, it can't disable them overall).
(A note on terminology: "events" and interrupts are effectively
synonymous. However, rather than using an "enable flag", Xen uses a
"mask flag", which blocks event delivery when it is non-zero.)
There are paravirt_ops for each of cli/sti/save_fl/restore_fl, which
are implemented to manage the Xen event mask state. The only thing
worth noting is that when events are unmasked, we need to explicitly
see if there's a pending event and call into the hypervisor to make
sure it gets delivered.
UPCALLS
Xen needs a couple of upcall (or callback) functions to be implemented
by each guest. One is the event upcalls, which is how events
(interrupts, effectively) are delivered to the guests. The other is
the failsafe callback, which is used to report errors in either
reloading a segment register, or caused by iret. These are
implemented in i386/kernel/entry.S so they can jump into the normal
iret_exc path when necessary.
MULTICALL BATCHING
Xen provides a multicall mechanism, which allows multiple hypercalls
to be issued at once in order to mitigate the cost of trapping into
the hypervisor. This is particularly useful for context switches,
since the 4-5 hypercalls they would normally need (reload cr3, update
TLS, maybe update LDT) can be reduced to one. This patch implements a
generic batching mechanism for hypercalls, which gets used in many
places in the Xen code.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ian Pratt <ian.pratt@xensource.com>
Cc: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Cc: Adrian Bunk <bunk@stusta.de>
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
MULTI_stack_switch(struct multicall_entry *mcl,
|
|
|
|
unsigned long ss, unsigned long esp)
|
|
|
|
{
|
|
|
|
mcl->op = __HYPERVISOR_stack_switch;
|
|
|
|
mcl->args[0] = ss;
|
|
|
|
mcl->args[1] = esp;
|
2010-12-16 22:33:27 +00:00
|
|
|
|
|
|
|
trace_xen_mc_entry(mcl, 2);
|
xen: Core Xen implementation
This patch is a rollup of all the core pieces of the Xen
implementation, including:
- booting and setup
- pagetable setup
- privileged instructions
- segmentation
- interrupt flags
- upcalls
- multicall batching
BOOTING AND SETUP
The vmlinux image is decorated with ELF notes which tell the Xen
domain builder what the kernel's requirements are; the domain builder
then constructs the address space accordingly and starts the kernel.
Xen has its own entrypoint for the kernel (contained in an ELF note).
The ELF notes are set up by xen-head.S, which is included into head.S.
In principle it could be linked separately, but it seems to provoke
lots of binutils bugs.
Because the domain builder starts the kernel in a fairly sane state
(32-bit protected mode, paging enabled, flat segments set up), there's
not a lot of setup needed before starting the kernel proper. The main
steps are:
1. Install the Xen paravirt_ops, which is simply a matter of a
structure assignment.
2. Set init_mm to use the Xen-supplied pagetables (analogous to the
head.S generated pagetables in a native boot).
3. Reserve address space for Xen, since it takes a chunk at the top
of the address space for its own use.
4. Call start_kernel()
PAGETABLE SETUP
Once we hit the main kernel boot sequence, it will end up calling back
via paravirt_ops to set up various pieces of Xen specific state. One
of the critical things which requires a bit of extra care is the
construction of the initial init_mm pagetable. Because Xen places
tight constraints on pagetables (an active pagetable must always be
valid, and must always be mapped read-only to the guest domain), we
need to be careful when constructing the new pagetable to keep these
constraints in mind. It turns out that the easiest way to do this is
use the initial Xen-provided pagetable as a template, and then just
insert new mappings for memory where a mapping doesn't already exist.
This means that during pagetable setup, it uses a special version of
xen_set_pte which ignores any attempt to remap a read-only page as
read-write (since Xen will map its own initial pagetable as RO), but
lets other changes to the ptes happen, so that things like NX are set
properly.
PRIVILEGED INSTRUCTIONS AND SEGMENTATION
When the kernel runs under Xen, it runs in ring 1 rather than ring 0.
This means that it is more privileged than user-mode in ring 3, but it
still can't run privileged instructions directly. Non-performance
critical instructions are dealt with by taking a privilege exception
and trapping into the hypervisor and emulating the instruction, but
more performance-critical instructions have their own specific
paravirt_ops. In many cases we can avoid having to do any hypercalls
for these instructions, or the Xen implementation is quite different
from the normal native version.
The privileged instructions fall into the broad classes of:
Segmentation: setting up the GDT and the GDT entries, LDT,
TLS and so on. Xen doesn't allow the GDT to be directly
modified; all GDT updates are done via hypercalls where the new
entries can be validated. This is important because Xen uses
segment limits to prevent the guest kernel from damaging the
hypervisor itself.
Traps and exceptions: Xen uses a special format for trap entrypoints,
so when the kernel wants to set an IDT entry, it needs to be
converted to the form Xen expects. Xen sets int 0x80 up specially
so that the trap goes straight from userspace into the guest kernel
without going via the hypervisor. sysenter isn't supported.
Kernel stack: The esp0 entry is extracted from the tss and provided to
Xen.
TLB operations: the various TLB calls are mapped into corresponding
Xen hypercalls.
Control registers: all the control registers are privileged. The most
important is cr3, which points to the base of the current pagetable,
and we handle it specially.
Another instruction we treat specially is CPUID, even though its not
privileged. We want to control what CPU features are visible to the
rest of the kernel, and so CPUID ends up going into a paravirt_op.
Xen implements this mainly to disable the ACPI and APIC subsystems.
INTERRUPT FLAGS
Xen maintains its own separate flag for masking events, which is
contained within the per-cpu vcpu_info structure. Because the guest
kernel runs in ring 1 and not 0, the IF flag in EFLAGS is completely
ignored (and must be, because even if a guest domain disables
interrupts for itself, it can't disable them overall).
(A note on terminology: "events" and interrupts are effectively
synonymous. However, rather than using an "enable flag", Xen uses a
"mask flag", which blocks event delivery when it is non-zero.)
There are paravirt_ops for each of cli/sti/save_fl/restore_fl, which
are implemented to manage the Xen event mask state. The only thing
worth noting is that when events are unmasked, we need to explicitly
see if there's a pending event and call into the hypervisor to make
sure it gets delivered.
UPCALLS
Xen needs a couple of upcall (or callback) functions to be implemented
by each guest. One is the event upcalls, which is how events
(interrupts, effectively) are delivered to the guests. The other is
the failsafe callback, which is used to report errors in either
reloading a segment register, or caused by iret. These are
implemented in i386/kernel/entry.S so they can jump into the normal
iret_exc path when necessary.
MULTICALL BATCHING
Xen provides a multicall mechanism, which allows multiple hypercalls
to be issued at once in order to mitigate the cost of trapping into
the hypervisor. This is particularly useful for context switches,
since the 4-5 hypercalls they would normally need (reload cr3, update
TLS, maybe update LDT) can be reduced to one. This patch implements a
generic batching mechanism for hypercalls, which gets used in many
places in the Xen code.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ian Pratt <ian.pratt@xensource.com>
Cc: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Cc: Adrian Bunk <bunk@stusta.de>
2007-07-18 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
2008-10-23 07:01:39 +00:00
|
|
|
#endif /* _ASM_X86_XEN_HYPERCALL_H */
|