ia64/xen-unstable

view tools/libxc/xenguest.h @ 19691:f44438bc79ac

libxc: Exchange a page for PV guest

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>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jun 01 14:15:48 2009 +0100 (2009-06-01)
parents bd39df93a29e
children
line source
1 /******************************************************************************
2 * xenguest.h
3 *
4 * A library for guest domain management in Xen.
5 *
6 * Copyright (c) 2003-2004, K A Fraser.
7 */
9 #ifndef XENGUEST_H
10 #define XENGUEST_H
12 #define XCFLAGS_LIVE 1
13 #define XCFLAGS_DEBUG 2
14 #define XCFLAGS_HVM 4
15 #define XCFLAGS_STDVGA 8
18 /**
19 * This function will save a running domain.
20 *
21 * @parm xc_handle a handle to an open hypervisor interface
22 * @parm fd the file descriptor to save a domain to
23 * @parm dom the id of the domain
24 * @return 0 on success, -1 on failure
25 */
26 int xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
27 uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
28 int (*suspend)(void), int hvm,
29 void *(*init_qemu_maps)(int, unsigned), /* HVM only */
30 void (*qemu_flip_buffer)(int, int)); /* HVM only */
33 /**
34 * This function will restore a saved domain.
35 *
36 * @parm xc_handle a handle to an open hypervisor interface
37 * @parm fd the file descriptor to restore a domain from
38 * @parm dom the id of the domain
39 * @parm store_evtchn the store event channel for this domain to use
40 * @parm store_mfn returned with the mfn of the store page
41 * @parm hvm non-zero if this is a HVM restore
42 * @parm pae non-zero if this HVM domain has PAE support enabled
43 * @parm superpages non-zero to allocate guest memory with superpages
44 * @return 0 on success, -1 on failure
45 */
46 int xc_domain_restore(int xc_handle, int io_fd, uint32_t dom,
47 unsigned int store_evtchn, unsigned long *store_mfn,
48 unsigned int console_evtchn, unsigned long *console_mfn,
49 unsigned int hvm, unsigned int pae, int superpages);
51 /**
52 * This function will create a domain for a paravirtualized Linux
53 * using file names pointing to kernel and ramdisk
54 *
55 * @parm xc_handle a handle to an open hypervisor interface
56 * @parm domid the id of the domain
57 * @parm mem_mb memory size in megabytes
58 * @parm image_name name of the kernel image file
59 * @parm ramdisk_name name of the ramdisk image file
60 * @parm cmdline command line string
61 * @parm flags domain creation flags
62 * @parm store_evtchn the store event channel for this domain to use
63 * @parm store_mfn returned with the mfn of the store page
64 * @parm console_evtchn the console event channel for this domain to use
65 * @parm conole_mfn returned with the mfn of the console page
66 * @parm superpages populate memory in guest with superpages
67 * @return 0 on success, -1 on failure
68 */
69 int xc_linux_build(int xc_handle,
70 uint32_t domid,
71 unsigned int mem_mb,
72 const char *image_name,
73 const char *ramdisk_name,
74 const char *cmdline,
75 const char *features,
76 unsigned long flags,
77 unsigned int store_evtchn,
78 unsigned long *store_mfn,
79 unsigned int console_evtchn,
80 unsigned long *console_mfn,
81 int superpages);
83 /** The same interface, but the dom structure is managed by the caller */
84 struct xc_dom_image;
85 int xc_dom_linux_build(int xc_handle,
86 struct xc_dom_image *dom,
87 uint32_t domid,
88 unsigned int mem_mb,
89 const char *image_name,
90 const char *ramdisk_name,
91 unsigned long flags,
92 unsigned int store_evtchn,
93 unsigned long *store_mfn,
94 unsigned int console_evtchn,
95 unsigned long *console_mfn,
96 int superpages);
98 /**
99 * This function will create a domain for a paravirtualized Linux
100 * using buffers for kernel and initrd
101 *
102 * @parm xc_handle a handle to an open hypervisor interface
103 * @parm domid the id of the domain
104 * @parm mem_mb memory size in megabytes
105 * @parm image_buffer buffer containing kernel image
106 * @parm image_size size of the kernel image buffer
107 * @parm initrd_buffer name of the ramdisk image file
108 * @parm initrd_size size of the ramdisk buffer
109 * @parm cmdline command line string
110 * @parm flags domain creation flags
111 * @parm store_evtchn the store event channel for this domain to use
112 * @parm store_mfn returned with the mfn of the store page
113 * @parm console_evtchn the console event channel for this domain to use
114 * @parm conole_mfn returned with the mfn of the console page
115 * @parm superpages populate memory in guest with superpages
116 * @return 0 on success, -1 on failure
117 */
118 int xc_linux_build_mem(int xc_handle,
119 uint32_t domid,
120 unsigned int mem_mb,
121 const char *image_buffer,
122 unsigned long image_size,
123 const char *initrd_buffer,
124 unsigned long initrd_size,
125 const char *cmdline,
126 const char *features,
127 unsigned long flags,
128 unsigned int store_evtchn,
129 unsigned long *store_mfn,
130 unsigned int console_evtchn,
131 unsigned long *console_mfn,
132 int superpages);
134 int xc_hvm_build(int xc_handle,
135 uint32_t domid,
136 int memsize,
137 const char *image_name);
139 int xc_hvm_build_target_mem(int xc_handle,
140 uint32_t domid,
141 int memsize,
142 int target,
143 const char *image_name);
145 int xc_hvm_build_mem(int xc_handle,
146 uint32_t domid,
147 int memsize,
148 const char *image_buffer,
149 unsigned long image_size);
151 int xc_suspend_evtchn_release(int xce, int suspend_evtchn);
153 int xc_suspend_evtchn_init(int xc, int xce, int domid, int port);
155 int xc_await_suspend(int xce, int suspend_evtchn);
157 int xc_mark_page_online(int xc, unsigned long start,
158 unsigned long end, uint32_t *status);
160 int xc_mark_page_offline(int xc, unsigned long start,
161 unsigned long end, uint32_t *status);
163 int xc_query_page_offline_status(int xc, unsigned long start,
164 unsigned long end, uint32_t *status);
166 int xc_exchange_page(int xc_handle, int domid, xen_pfn_t mfn);
169 /**
170 * This function map m2p table
171 * @parm xc_handle a handle to an open hypervisor interface
172 * @parm max_mfn the max pfn
173 * @parm prot the flags to map, such as read/write etc
174 * @parm mfn0 return the first mfn, can be NULL
175 * @return mapped m2p table on success, NULL on failure
176 */
177 xen_pfn_t *xc_map_m2p(int xc_handle,
178 unsigned long max_mfn,
179 int prot,
180 unsigned long *mfn0);
181 #endif /* XENGUEST_H */