mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
This patch support exchange a page for a suspended PV guest from user
space.
The basic idea to offline a page is:
1) mark a page offline pending
2) If the page is owned by a HVM domain, user have to live migrate it.
In future, with stub-domain support, we can also exchange the page
without migration.
3) If the page is owned by a PV domain, we will try to exchange the
offline pending page to a new one and free the old page.
This patch achieves item 3.
The method to exchange the offline pending page for PV domain is:
1) Suspend the guest.
2) If the page is being granted out, return with offline pending.
3) Get a copy for the content
4) Scan all page table page to see if any reference to the offending
page, if yes, make the entry to be non-present to reduce the reference
count.
5) After update all page tables, user space tools will try to exchange
the old page. If the new mfn has no reference anymore (i.e.
count_info & count_mask =3D 1), the exchange will allocate a new page,
update the m2p and return success, otherwise it will return fail.
6) If step 5 is success, user space tools will update the content of
the new page change the p2m table, and change all entries scaned in
step 4 to point to new entry.
if step failed, it will try to undo step 4 to revert page table.
7) Resume the guest.
Please refer to thread in
http://www.mailinglistarchive.com/xen-devel@lists.xensource.com/msg63084.html
for more information.
Signed-off-by: Jiang, Yunhong <yunhong.jiang@intel.com>
182 lines
6.7 KiB
C
182 lines
6.7 KiB
C
/******************************************************************************
|
|
* xenguest.h
|
|
*
|
|
* A library for guest domain management in Xen.
|
|
*
|
|
* Copyright (c) 2003-2004, K A Fraser.
|
|
*/
|
|
|
|
#ifndef XENGUEST_H
|
|
#define XENGUEST_H
|
|
|
|
#define XCFLAGS_LIVE 1
|
|
#define XCFLAGS_DEBUG 2
|
|
#define XCFLAGS_HVM 4
|
|
#define XCFLAGS_STDVGA 8
|
|
|
|
|
|
/**
|
|
* This function will save a running domain.
|
|
*
|
|
* @parm xc_handle a handle to an open hypervisor interface
|
|
* @parm fd the file descriptor to save a domain to
|
|
* @parm dom the id of the domain
|
|
* @return 0 on success, -1 on failure
|
|
*/
|
|
int xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
|
|
uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
|
|
int (*suspend)(void), int hvm,
|
|
void *(*init_qemu_maps)(int, unsigned), /* HVM only */
|
|
void (*qemu_flip_buffer)(int, int)); /* HVM only */
|
|
|
|
|
|
/**
|
|
* This function will restore a saved domain.
|
|
*
|
|
* @parm xc_handle a handle to an open hypervisor interface
|
|
* @parm fd the file descriptor to restore a domain from
|
|
* @parm dom the id of the domain
|
|
* @parm store_evtchn the store event channel for this domain to use
|
|
* @parm store_mfn returned with the mfn of the store page
|
|
* @parm hvm non-zero if this is a HVM restore
|
|
* @parm pae non-zero if this HVM domain has PAE support enabled
|
|
* @parm superpages non-zero to allocate guest memory with superpages
|
|
* @return 0 on success, -1 on failure
|
|
*/
|
|
int xc_domain_restore(int xc_handle, int io_fd, uint32_t dom,
|
|
unsigned int store_evtchn, unsigned long *store_mfn,
|
|
unsigned int console_evtchn, unsigned long *console_mfn,
|
|
unsigned int hvm, unsigned int pae, int superpages);
|
|
|
|
/**
|
|
* This function will create a domain for a paravirtualized Linux
|
|
* using file names pointing to kernel and ramdisk
|
|
*
|
|
* @parm xc_handle a handle to an open hypervisor interface
|
|
* @parm domid the id of the domain
|
|
* @parm mem_mb memory size in megabytes
|
|
* @parm image_name name of the kernel image file
|
|
* @parm ramdisk_name name of the ramdisk image file
|
|
* @parm cmdline command line string
|
|
* @parm flags domain creation flags
|
|
* @parm store_evtchn the store event channel for this domain to use
|
|
* @parm store_mfn returned with the mfn of the store page
|
|
* @parm console_evtchn the console event channel for this domain to use
|
|
* @parm conole_mfn returned with the mfn of the console page
|
|
* @parm superpages populate memory in guest with superpages
|
|
* @return 0 on success, -1 on failure
|
|
*/
|
|
int xc_linux_build(int xc_handle,
|
|
uint32_t domid,
|
|
unsigned int mem_mb,
|
|
const char *image_name,
|
|
const char *ramdisk_name,
|
|
const char *cmdline,
|
|
const char *features,
|
|
unsigned long flags,
|
|
unsigned int store_evtchn,
|
|
unsigned long *store_mfn,
|
|
unsigned int console_evtchn,
|
|
unsigned long *console_mfn,
|
|
int superpages);
|
|
|
|
/** The same interface, but the dom structure is managed by the caller */
|
|
struct xc_dom_image;
|
|
int xc_dom_linux_build(int xc_handle,
|
|
struct xc_dom_image *dom,
|
|
uint32_t domid,
|
|
unsigned int mem_mb,
|
|
const char *image_name,
|
|
const char *ramdisk_name,
|
|
unsigned long flags,
|
|
unsigned int store_evtchn,
|
|
unsigned long *store_mfn,
|
|
unsigned int console_evtchn,
|
|
unsigned long *console_mfn,
|
|
int superpages);
|
|
|
|
/**
|
|
* This function will create a domain for a paravirtualized Linux
|
|
* using buffers for kernel and initrd
|
|
*
|
|
* @parm xc_handle a handle to an open hypervisor interface
|
|
* @parm domid the id of the domain
|
|
* @parm mem_mb memory size in megabytes
|
|
* @parm image_buffer buffer containing kernel image
|
|
* @parm image_size size of the kernel image buffer
|
|
* @parm initrd_buffer name of the ramdisk image file
|
|
* @parm initrd_size size of the ramdisk buffer
|
|
* @parm cmdline command line string
|
|
* @parm flags domain creation flags
|
|
* @parm store_evtchn the store event channel for this domain to use
|
|
* @parm store_mfn returned with the mfn of the store page
|
|
* @parm console_evtchn the console event channel for this domain to use
|
|
* @parm conole_mfn returned with the mfn of the console page
|
|
* @parm superpages populate memory in guest with superpages
|
|
* @return 0 on success, -1 on failure
|
|
*/
|
|
int xc_linux_build_mem(int xc_handle,
|
|
uint32_t domid,
|
|
unsigned int mem_mb,
|
|
const char *image_buffer,
|
|
unsigned long image_size,
|
|
const char *initrd_buffer,
|
|
unsigned long initrd_size,
|
|
const char *cmdline,
|
|
const char *features,
|
|
unsigned long flags,
|
|
unsigned int store_evtchn,
|
|
unsigned long *store_mfn,
|
|
unsigned int console_evtchn,
|
|
unsigned long *console_mfn,
|
|
int superpages);
|
|
|
|
int xc_hvm_build(int xc_handle,
|
|
uint32_t domid,
|
|
int memsize,
|
|
const char *image_name);
|
|
|
|
int xc_hvm_build_target_mem(int xc_handle,
|
|
uint32_t domid,
|
|
int memsize,
|
|
int target,
|
|
const char *image_name);
|
|
|
|
int xc_hvm_build_mem(int xc_handle,
|
|
uint32_t domid,
|
|
int memsize,
|
|
const char *image_buffer,
|
|
unsigned long image_size);
|
|
|
|
int xc_suspend_evtchn_release(int xce, int suspend_evtchn);
|
|
|
|
int xc_suspend_evtchn_init(int xc, int xce, int domid, int port);
|
|
|
|
int xc_await_suspend(int xce, int suspend_evtchn);
|
|
|
|
int xc_mark_page_online(int xc, unsigned long start,
|
|
unsigned long end, uint32_t *status);
|
|
|
|
int xc_mark_page_offline(int xc, unsigned long start,
|
|
unsigned long end, uint32_t *status);
|
|
|
|
int xc_query_page_offline_status(int xc, unsigned long start,
|
|
unsigned long end, uint32_t *status);
|
|
|
|
int xc_exchange_page(int xc_handle, int domid, xen_pfn_t mfn);
|
|
|
|
|
|
/**
|
|
* This function map m2p table
|
|
* @parm xc_handle a handle to an open hypervisor interface
|
|
* @parm max_mfn the max pfn
|
|
* @parm prot the flags to map, such as read/write etc
|
|
* @parm mfn0 return the first mfn, can be NULL
|
|
* @return mapped m2p table on success, NULL on failure
|
|
*/
|
|
xen_pfn_t *xc_map_m2p(int xc_handle,
|
|
unsigned long max_mfn,
|
|
int prot,
|
|
unsigned long *mfn0);
|
|
#endif /* XENGUEST_H */
|