ia64/xen-unstable

view tools/libxc/xc_dom.h @ 19639:205b1badbcfd

Add support for superpages (hugepages) in PV domain

This patch adds the option "superpages" to the domain configuration
file. If it is set, the domain is populated using 2M pages.

This code does not support fallback to small pages. If the domain can
not be created with 2M pages, the create will fail.

The patch also includes support for saving and restoring domains with
the superpage flag set. However, if a domain has freed small pages
within its physical page array and then extended the array, the
restore will fill in those freed pages. It will then attempt to
allocate more than its memory limit and will fail. This is
significant because apparently Linux does this during boot, thus a
freshly booted Linux image can not be saved and restored successfully.

Signed-off-by: Dave McCracken <dcm@mccr.org>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 26 09:58:38 2009 +0100 (2009-05-26)
parents 7df072566b8c
children
line source
1 #include <xen/libelf/libelf.h>
3 #define INVALID_P2M_ENTRY ((xen_pfn_t)-1)
5 /* --- typedefs and structs ---------------------------------------- */
7 typedef uint64_t xen_vaddr_t;
8 typedef uint64_t xen_paddr_t;
10 #define PRIpfn PRI_xen_pfn
12 struct xc_dom_seg {
13 xen_vaddr_t vstart;
14 xen_vaddr_t vend;
15 xen_pfn_t pfn;
16 };
18 struct xc_dom_mem {
19 struct xc_dom_mem *next;
20 void *mmap_ptr;
21 size_t mmap_len;
22 unsigned char memory[0];
23 };
25 struct xc_dom_phys {
26 struct xc_dom_phys *next;
27 void *ptr;
28 xen_pfn_t first;
29 xen_pfn_t count;
30 };
32 struct xc_dom_image {
33 /* files */
34 void *kernel_blob;
35 size_t kernel_size;
36 void *ramdisk_blob;
37 size_t ramdisk_size;
39 /* arguments and parameters */
40 char *cmdline;
41 uint32_t f_requested[XENFEAT_NR_SUBMAPS];
43 /* info from (elf) kernel image */
44 struct elf_dom_parms parms;
45 char *guest_type;
47 /* memory layout */
48 struct xc_dom_seg kernel_seg;
49 struct xc_dom_seg ramdisk_seg;
50 struct xc_dom_seg p2m_seg;
51 struct xc_dom_seg pgtables_seg;
52 struct xc_dom_seg devicetree_seg;
53 xen_pfn_t start_info_pfn;
54 xen_pfn_t console_pfn;
55 xen_pfn_t xenstore_pfn;
56 xen_pfn_t shared_info_pfn;
57 xen_pfn_t bootstack_pfn;
58 xen_vaddr_t virt_alloc_end;
59 xen_vaddr_t bsd_symtab_start;
61 /* initial page tables */
62 unsigned int pgtables;
63 unsigned int pg_l4;
64 unsigned int pg_l3;
65 unsigned int pg_l2;
66 unsigned int pg_l1;
67 unsigned int alloc_bootstack;
68 unsigned int extra_pages;
69 xen_vaddr_t virt_pgtab_end;
71 /* other state info */
72 uint32_t f_active[XENFEAT_NR_SUBMAPS];
73 xen_pfn_t *p2m_host;
74 void *p2m_guest;
76 /* physical memory */
77 xen_pfn_t total_pages;
78 struct xc_dom_phys *phys_pages;
79 int realmodearea_log;
81 /* malloc memory pool */
82 struct xc_dom_mem *memblocks;
84 /* memory footprint stats */
85 size_t alloc_malloc;
86 size_t alloc_mem_map;
87 size_t alloc_file_map;
88 size_t alloc_domU_map;
90 /* misc xen domain config stuff */
91 unsigned long flags;
92 unsigned int console_evtchn;
93 unsigned int xenstore_evtchn;
94 xen_pfn_t shared_info_mfn;
96 int guest_xc;
97 domid_t guest_domid;
98 int8_t vhpt_size_log2; /* for IA64 */
99 int shadow_enabled;
101 int xen_version;
102 xen_capabilities_info_t xen_caps;
104 /* kernel loader, arch hooks */
105 struct xc_dom_loader *kernel_loader;
106 void *private_loader;
108 /* kernel loader */
109 struct xc_dom_arch *arch_hooks;
110 /* allocate up to virt_alloc_end */
111 int (*allocate) (struct xc_dom_image * dom, xen_vaddr_t up_to);
112 };
114 /* --- pluggable kernel loader ------------------------------------- */
116 struct xc_dom_loader {
117 char *name;
118 int (*probe) (struct xc_dom_image * dom);
119 int (*parser) (struct xc_dom_image * dom);
120 int (*loader) (struct xc_dom_image * dom);
122 struct xc_dom_loader *next;
123 };
125 #define __init __attribute__ ((constructor))
126 void xc_dom_register_loader(struct xc_dom_loader *loader);
128 /* --- arch specific hooks ----------------------------------------- */
130 struct xc_dom_arch {
131 /* pagetable setup */
132 int (*alloc_magic_pages) (struct xc_dom_image * dom);
133 int (*count_pgtables) (struct xc_dom_image * dom);
134 int (*setup_pgtables) (struct xc_dom_image * dom);
136 /* arch-specific data structs setup */
137 int (*start_info) (struct xc_dom_image * dom);
138 int (*shared_info) (struct xc_dom_image * dom, void *shared_info);
139 int (*vcpu) (struct xc_dom_image * dom, void *vcpu_ctxt);
141 char *guest_type;
142 char *native_protocol;
143 int page_shift;
144 int sizeof_pfn;
146 struct xc_dom_arch *next;
147 };
148 void xc_dom_register_arch_hooks(struct xc_dom_arch *hooks);
150 #define XC_DOM_PAGE_SHIFT(dom) ((dom)->arch_hooks->page_shift)
151 #define XC_DOM_PAGE_SIZE(dom) (1 << (dom)->arch_hooks->page_shift)
153 /* --- main functions ---------------------------------------------- */
155 struct xc_dom_image *xc_dom_allocate(const char *cmdline, const char *features);
156 void xc_dom_release_phys(struct xc_dom_image *dom);
157 void xc_dom_release(struct xc_dom_image *dom);
158 int xc_dom_mem_init(struct xc_dom_image *dom, unsigned int mem_mb);
160 size_t xc_dom_check_gzip(void *blob, size_t ziplen);
161 int xc_dom_do_gunzip(void *src, size_t srclen, void *dst, size_t dstlen);
162 int xc_dom_try_gunzip(struct xc_dom_image *dom, void **blob, size_t * size);
164 int xc_dom_kernel_file(struct xc_dom_image *dom, const char *filename);
165 int xc_dom_ramdisk_file(struct xc_dom_image *dom, const char *filename);
166 int xc_dom_kernel_mem(struct xc_dom_image *dom, const void *mem,
167 size_t memsize);
168 int xc_dom_ramdisk_mem(struct xc_dom_image *dom, const void *mem,
169 size_t memsize);
171 int xc_dom_parse_image(struct xc_dom_image *dom);
172 struct xc_dom_arch *xc_dom_find_arch_hooks(char *guest_type);
173 int xc_dom_build_image(struct xc_dom_image *dom);
174 int xc_dom_update_guest_p2m(struct xc_dom_image *dom);
176 int xc_dom_boot_xen_init(struct xc_dom_image *dom, int xc, domid_t domid);
177 int xc_dom_boot_mem_init(struct xc_dom_image *dom, int superpages);
178 void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,
179 xen_pfn_t count);
180 int xc_dom_boot_image(struct xc_dom_image *dom);
181 int xc_dom_compat_check(struct xc_dom_image *dom);
183 /* --- debugging bits ---------------------------------------------- */
185 extern FILE *xc_dom_logfile;
187 void xc_dom_loginit(void);
188 int xc_dom_printf(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
189 int xc_dom_panic_func(const char *file, int line, xc_error_code err,
190 const char *fmt, ...)
191 __attribute__ ((format(printf, 4, 5)));
192 #define xc_dom_panic(err, fmt, args...) \
193 xc_dom_panic_func(__FILE__, __LINE__, err, fmt, ## args)
194 #define xc_dom_trace(mark) \
195 xc_dom_printf("%s:%d: trace %s\n", __FILE__, __LINE__, mark)
197 void xc_dom_log_memory_footprint(struct xc_dom_image *dom);
199 /* --- simple memory pool ------------------------------------------ */
201 void *xc_dom_malloc(struct xc_dom_image *dom, size_t size);
202 void *xc_dom_malloc_page_aligned(struct xc_dom_image *dom, size_t size);
203 void *xc_dom_malloc_filemap(struct xc_dom_image *dom,
204 const char *filename, size_t * size);
205 char *xc_dom_strdup(struct xc_dom_image *dom, const char *str);
207 /* --- alloc memory pool ------------------------------------------- */
209 int xc_dom_alloc_page(struct xc_dom_image *dom, char *name);
210 int xc_dom_alloc_segment(struct xc_dom_image *dom,
211 struct xc_dom_seg *seg, char *name,
212 xen_vaddr_t start, xen_vaddr_t size);
214 /* --- misc bits --------------------------------------------------- */
216 void *xc_dom_pfn_to_ptr(struct xc_dom_image *dom, xen_pfn_t first,
217 xen_pfn_t count);
218 void xc_dom_unmap_one(struct xc_dom_image *dom, xen_pfn_t pfn);
219 void xc_dom_unmap_all(struct xc_dom_image *dom);
221 static inline void *xc_dom_seg_to_ptr(struct xc_dom_image *dom,
222 struct xc_dom_seg *seg)
223 {
224 xen_vaddr_t segsize = seg->vend - seg->vstart;
225 unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
226 xen_pfn_t pages = (segsize + page_size - 1) / page_size;
228 return xc_dom_pfn_to_ptr(dom, seg->pfn, pages);
229 }
231 static inline void *xc_dom_vaddr_to_ptr(struct xc_dom_image *dom,
232 xen_vaddr_t vaddr)
233 {
234 unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
235 xen_pfn_t page = (vaddr - dom->parms.virt_base) / page_size;
236 unsigned int offset = (vaddr - dom->parms.virt_base) % page_size;
237 void *ptr = xc_dom_pfn_to_ptr(dom, page, 0);
238 return (ptr ? (ptr + offset) : NULL);
239 }
241 static inline int xc_dom_feature_translated(struct xc_dom_image *dom)
242 {
243 return elf_xen_feature_get(XENFEAT_auto_translated_physmap, dom->f_active);
244 }
246 static inline xen_pfn_t xc_dom_p2m_host(struct xc_dom_image *dom, xen_pfn_t pfn)
247 {
248 if (dom->shadow_enabled)
249 return pfn;
250 return dom->p2m_host[pfn];
251 }
253 static inline xen_pfn_t xc_dom_p2m_guest(struct xc_dom_image *dom,
254 xen_pfn_t pfn)
255 {
256 if (xc_dom_feature_translated(dom))
257 return pfn;
258 return dom->p2m_host[pfn];
259 }
261 /* --- arch bits --------------------------------------------------- */
263 int arch_setup_meminit(struct xc_dom_image *dom, int superpages);
264 int arch_setup_bootearly(struct xc_dom_image *dom);
265 int arch_setup_bootlate(struct xc_dom_image *dom);
267 /*
268 * Local variables:
269 * mode: C
270 * c-set-style: "BSD"
271 * c-basic-offset: 4
272 * tab-width: 4
273 * indent-tabs-mode: nil
274 * End:
275 */