ia64/xen-unstable

view tools/libxc/xc_linux_restore.c @ 8964:8946b6dcd49e

Fix x86_64 Xen build.

event_callback_cs and failsafe_callback_cs are x86_32 only.

Signed-off-by: Ian Campbell <Ian.Campbell@XenSource.com>
author Ian.Campbell@xensource.com
date Wed Feb 22 17:26:39 2006 +0000 (2006-02-22)
parents 8d6edcf06f9b
children 71f938468929
line source
1 /******************************************************************************
2 * xc_linux_restore.c
3 *
4 * Restore the state of a Linux session.
5 *
6 * Copyright (c) 2003, K A Fraser.
7 */
9 #include <stdlib.h>
10 #include <unistd.h>
12 #include "xg_private.h"
13 #include "xg_save_restore.h"
15 /* max mfn of the whole machine */
16 static unsigned long max_mfn;
18 /* virtual starting address of the hypervisor */
19 static unsigned long hvirt_start;
21 /* #levels of page tables used by the currrent guest */
22 static unsigned int pt_levels;
24 /* total number of pages used by the current guest */
25 static unsigned long max_pfn;
27 /* Live mapping of the table mapping each PFN to its current MFN. */
28 static unsigned long *live_p2m = NULL;
30 /* A table mapping each PFN to its new MFN. */
31 static unsigned long *p2m = NULL;
34 static ssize_t
35 read_exact(int fd, void *buf, size_t count)
36 {
37 int r = 0, s;
38 unsigned char *b = buf;
40 while (r < count) {
41 s = read(fd, &b[r], count - r);
42 if ((s == -1) && (errno == EINTR))
43 continue;
44 if (s <= 0) {
45 break;
46 }
47 r += s;
48 }
50 return (r == count) ? 1 : 0;
51 }
53 /*
54 ** In the state file (or during transfer), all page-table pages are
55 ** converted into a 'canonical' form where references to actual mfns
56 ** are replaced with references to the corresponding pfns.
57 ** This function inverts that operation, replacing the pfn values with
58 ** the (now known) appropriate mfn values.
59 */
60 int uncanonicalize_pagetable(unsigned long type, void *page)
61 {
62 int i, pte_last;
63 unsigned long pfn;
64 uint64_t pte;
66 pte_last = PAGE_SIZE / ((pt_levels == 2)? 4 : 8);
68 /* Now iterate through the page table, uncanonicalizing each PTE */
69 for(i = 0; i < pte_last; i++) {
71 if(pt_levels == 2)
72 pte = ((uint32_t *)page)[i];
73 else
74 pte = ((uint64_t *)page)[i];
76 if(pte & _PAGE_PRESENT) {
78 pfn = (pte >> PAGE_SHIFT) & 0xffffffff;
80 if(pfn >= max_pfn) {
81 /* This "page table page" is probably not one; bail. */
82 ERR("Frame number in type %lu page table is out of range: "
83 "i=%d pfn=0x%lx max_pfn=%lu",
84 type >> 28, i, pfn, max_pfn);
85 return 0;
86 }
89 pte &= 0xffffff0000000fffULL;
90 pte |= (uint64_t)p2m[pfn] << PAGE_SHIFT;
92 if(pt_levels == 2)
93 ((uint32_t *)page)[i] = (uint32_t)pte;
94 else
95 ((uint64_t *)page)[i] = (uint64_t)pte;
99 }
100 }
102 return 1;
103 }
105 int xc_linux_restore(int xc_handle, int io_fd,
106 uint32_t dom, unsigned long nr_pfns,
107 unsigned int store_evtchn, unsigned long *store_mfn,
108 unsigned int console_evtchn, unsigned long *console_mfn)
109 {
110 DECLARE_DOM0_OP;
111 int rc = 1, i, n;
112 unsigned long mfn, pfn;
113 unsigned int prev_pc, this_pc;
114 int verify = 0;
115 int nraces = 0;
117 /* The new domain's shared-info frame number. */
118 unsigned long shared_info_frame;
119 unsigned char shared_info_page[PAGE_SIZE]; /* saved contents from file */
120 shared_info_t *shared_info = (shared_info_t *)shared_info_page;
122 /* A copy of the CPU context of the guest. */
123 vcpu_guest_context_t ctxt;
125 /* A table containing the type of each PFN (/not/ MFN!). */
126 unsigned long *pfn_type = NULL;
128 /* A table of MFNs to map in the current region */
129 unsigned long *region_mfn = NULL;
131 /* Types of the pfns in the current region */
132 unsigned long region_pfn_type[MAX_BATCH_SIZE];
134 /* A temporary mapping, and a copy, of one frame of guest memory. */
135 unsigned long *page = NULL;
137 /* A copy of the pfn-to-mfn table frame list. */
138 unsigned long *p2m_frame_list = NULL;
140 /* A temporary mapping of the guest's start_info page. */
141 start_info_t *start_info;
143 char *region_base;
145 xc_mmu_t *mmu = NULL;
147 /* used by debug verify code */
148 unsigned long buf[PAGE_SIZE/sizeof(unsigned long)];
150 struct mmuext_op pin[MAX_PIN_BATCH];
151 unsigned int nr_pins;
154 max_pfn = nr_pfns;
156 DPRINTF("xc_linux_restore start: max_pfn = %lx\n", max_pfn);
159 if(!get_platform_info(xc_handle, dom,
160 &max_mfn, &hvirt_start, &pt_levels)) {
161 ERR("Unable to get platform info.");
162 return 1;
163 }
166 if (mlock(&ctxt, sizeof(ctxt))) {
167 /* needed for build dom0 op, but might as well do early */
168 ERR("Unable to mlock ctxt");
169 return 1;
170 }
173 /* Read the saved P2M frame list */
174 if(!(p2m_frame_list = malloc(P2M_FL_SIZE))) {
175 ERR("Couldn't allocate p2m_frame_list array");
176 goto out;
177 }
179 if (!read_exact(io_fd, p2m_frame_list, P2M_FL_SIZE)) {
180 ERR("read p2m_frame_list failed");
181 goto out;
182 }
185 /* We want zeroed memory so use calloc rather than malloc. */
186 p2m = calloc(sizeof(unsigned long), max_pfn);
187 pfn_type = calloc(sizeof(unsigned long), max_pfn);
188 region_mfn = calloc(sizeof(unsigned long), MAX_BATCH_SIZE);
190 if ((p2m == NULL) || (pfn_type == NULL) || (region_mfn == NULL)) {
191 ERR("memory alloc failed");
192 errno = ENOMEM;
193 goto out;
194 }
196 if (mlock(region_mfn, sizeof(unsigned long) * MAX_BATCH_SIZE)) {
197 ERR("Could not mlock region_mfn");
198 goto out;
199 }
201 /* Get the domain's shared-info frame. */
202 op.cmd = DOM0_GETDOMAININFO;
203 op.u.getdomaininfo.domain = (domid_t)dom;
204 if (xc_dom0_op(xc_handle, &op) < 0) {
205 ERR("Could not get information on new domain");
206 goto out;
207 }
208 shared_info_frame = op.u.getdomaininfo.shared_info_frame;
210 if(xc_domain_setmaxmem(xc_handle, dom, PFN_TO_KB(max_pfn)) != 0) {
211 errno = ENOMEM;
212 goto out;
213 }
215 if(xc_domain_memory_increase_reservation(
216 xc_handle, dom, max_pfn, 0, 0, NULL) != 0) {
217 ERR("Failed to increase reservation by %lx KB", PFN_TO_KB(max_pfn));
218 errno = ENOMEM;
219 goto out;
220 }
222 DPRINTF("Increased domain reservation by %lx KB\n", PFN_TO_KB(max_pfn));
224 /* Build the pfn-to-mfn table. We choose MFN ordering returned by Xen. */
225 if (xc_get_pfn_list(xc_handle, dom, p2m, max_pfn) != max_pfn) {
226 ERR("Did not read correct number of frame numbers for new dom");
227 goto out;
228 }
230 if(!(mmu = xc_init_mmu_updates(xc_handle, dom))) {
231 ERR("Could not initialise for MMU updates");
232 goto out;
233 }
236 DPRINTF("Reloading memory pages: 0%%\n");
238 /*
239 * Now simply read each saved frame into its new machine frame.
240 * We uncanonicalise page tables as we go.
241 */
242 prev_pc = 0;
244 n = 0;
245 while (1) {
247 int j;
249 this_pc = (n * 100) / max_pfn;
250 if ( (this_pc - prev_pc) >= 5 )
251 {
252 PPRINTF("\b\b\b\b%3d%%", this_pc);
253 prev_pc = this_pc;
254 }
256 if (!read_exact(io_fd, &j, sizeof(int))) {
257 ERR("Error when reading batch size");
258 goto out;
259 }
261 PPRINTF("batch %d\n",j);
263 if (j == -1) {
264 verify = 1;
265 fprintf(stderr, "Entering page verify mode\n");
266 continue;
267 }
269 if (j == 0)
270 break; /* our work here is done */
272 if (j > MAX_BATCH_SIZE) {
273 ERR("Max batch size exceeded. Giving up.");
274 goto out;
275 }
277 if (!read_exact(io_fd, region_pfn_type, j*sizeof(unsigned long))) {
278 ERR("Error when reading region pfn types");
279 goto out;
280 }
282 for (i = 0; i < j; i++) {
284 if ((region_pfn_type[i] & LTAB_MASK) == XTAB)
285 region_mfn[i] = 0; /* we know map will fail, but don't care */
286 else
287 region_mfn[i] = p2m[region_pfn_type[i] & ~LTAB_MASK];
289 }
291 if (!(region_base = xc_map_foreign_batch(
292 xc_handle, dom, PROT_WRITE, region_mfn, j))) {
293 ERR("map batch failed");
294 goto out;
295 }
297 for ( i = 0; i < j; i++ )
298 {
299 void *page;
300 unsigned long pagetype;
302 pfn = region_pfn_type[i] & ~LTAB_MASK;
303 pagetype = region_pfn_type[i] & LTAB_MASK;
305 if (pagetype == XTAB)
306 /* a bogus/unmapped page: skip it */
307 continue;
309 if (pfn > max_pfn) {
310 ERR("pfn out of range");
311 goto out;
312 }
314 pfn_type[pfn] = pagetype;
316 mfn = p2m[pfn];
318 /* In verify mode, we use a copy; otherwise we work in place */
319 page = verify ? (void *)buf : (region_base + i*PAGE_SIZE);
321 if (!read_exact(io_fd, page, PAGE_SIZE)) {
322 ERR("Error when reading page (type was %lx)", pagetype);
323 goto out;
324 }
326 pagetype &= LTABTYPE_MASK;
328 if(pagetype >= L1TAB && pagetype <= L4TAB) {
330 /*
331 ** A page table page - need to 'uncanonicalize' it, i.e.
332 ** replace all the references to pfns with the corresponding
333 ** mfns for the new domain.
334 **
335 ** On PAE we need to ensure that PGDs are in MFNs < 4G, and
336 ** so we may need to update the p2m after the main loop.
337 ** Hence we defer canonicalization of L1s until then.
338 */
339 if(pt_levels != 3 || pagetype != L1TAB) {
341 if(!uncanonicalize_pagetable(pagetype, page)) {
342 /*
343 ** Failing to uncanonicalize a page table can be ok
344 ** under live migration since the pages type may have
345 ** changed by now (and we'll get an update later).
346 */
347 DPRINTF("PT L%ld race on pfn=%08lx mfn=%08lx\n",
348 pagetype >> 28, pfn, mfn);
349 nraces++;
350 continue;
351 }
353 }
355 } else if(pagetype != NOTAB) {
357 ERR("Bogus page type %lx page table is out of range: "
358 "i=%d max_pfn=%lu", pagetype, i, max_pfn);
359 goto out;
361 }
364 if (verify) {
366 int res = memcmp(buf, (region_base + i*PAGE_SIZE), PAGE_SIZE);
368 if (res) {
370 int v;
372 DPRINTF("************** pfn=%lx type=%lx gotcs=%08lx "
373 "actualcs=%08lx\n", pfn, pfn_type[pfn],
374 csum_page(region_base + i*PAGE_SIZE),
375 csum_page(buf));
377 for (v = 0; v < 4; v++) {
379 unsigned long *p = (unsigned long *)
380 (region_base + i*PAGE_SIZE);
381 if (buf[v] != p[v])
382 DPRINTF(" %d: %08lx %08lx\n", v, buf[v], p[v]);
383 }
384 }
385 }
387 if (xc_add_mmu_update(xc_handle, mmu,
388 (((unsigned long long)mfn) << PAGE_SHIFT)
389 | MMU_MACHPHYS_UPDATE, pfn)) {
390 ERR("failed machpys update mfn=%lx pfn=%lx", mfn, pfn);
391 goto out;
392 }
393 } /* end of 'batch' for loop */
395 munmap(region_base, j*PAGE_SIZE);
396 n+= j; /* crude stats */
397 }
399 DPRINTF("Received all pages (%d races)\n", nraces);
401 if(pt_levels == 3) {
403 /*
404 ** XXX SMH on PAE we need to ensure PGDs are in MFNs < 4G. This
405 ** is a little awkward and involves (a) finding all such PGDs and
406 ** replacing them with 'lowmem' versions; (b) upating the p2m[]
407 ** with the new info; and (c) canonicalizing all the L1s using the
408 ** (potentially updated) p2m[].
409 **
410 ** This is relatively slow (and currently involves two passes through
411 ** the pfn_type[] array), but at least seems to be correct. May wish
412 ** to consider more complex approaches to optimize this later.
413 */
415 int j, k;
417 /* First pass: find all L3TABs current in > 4G mfns and get new mfns */
418 for (i = 0; i < max_pfn; i++) {
420 if (((pfn_type[i] & LTABTYPE_MASK)==L3TAB) && (p2m[i]>0xfffffUL)) {
422 unsigned long new_mfn;
423 uint64_t l3ptes[4];
424 uint64_t *l3tab;
426 l3tab = (uint64_t *)
427 xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
428 PROT_READ, p2m[i]);
430 for(j = 0; j < 4; j++)
431 l3ptes[j] = l3tab[j];
433 munmap(l3tab, PAGE_SIZE);
435 if (!(new_mfn=xc_make_page_below_4G(xc_handle, dom, p2m[i]))) {
436 ERR("Couldn't get a page below 4GB :-(");
437 goto out;
438 }
440 p2m[i] = new_mfn;
441 if (xc_add_mmu_update(xc_handle, mmu,
442 (((unsigned long long)new_mfn)
443 << PAGE_SHIFT) |
444 MMU_MACHPHYS_UPDATE, i)) {
445 ERR("Couldn't m2p on PAE root pgdir");
446 goto out;
447 }
449 l3tab = (uint64_t *)
450 xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
451 PROT_READ | PROT_WRITE, p2m[i]);
453 for(j = 0; j < 4; j++)
454 l3tab[j] = l3ptes[j];
456 munmap(l3tab, PAGE_SIZE);
458 }
459 }
461 /* Second pass: find all L1TABs and uncanonicalize them */
462 j = 0;
464 for(i = 0; i < max_pfn; i++) {
466 if (((pfn_type[i] & LTABTYPE_MASK)==L1TAB)) {
467 region_mfn[j] = p2m[i];
468 j++;
469 }
471 if(i == (max_pfn-1) || j == MAX_BATCH_SIZE) {
473 if (!(region_base = xc_map_foreign_batch(
474 xc_handle, dom, PROT_READ | PROT_WRITE,
475 region_mfn, j))) {
476 ERR("map batch failed");
477 goto out;
478 }
480 for(k = 0; k < j; k++) {
481 if(!uncanonicalize_pagetable(L1TAB,
482 region_base + k*PAGE_SIZE)) {
483 ERR("failed uncanonicalize pt!");
484 goto out;
485 }
486 }
488 munmap(region_base, j*PAGE_SIZE);
489 j = 0;
490 }
491 }
493 }
496 if (xc_finish_mmu_updates(xc_handle, mmu)) {
497 ERR("Error doing finish_mmu_updates()");
498 goto out;
499 }
502 /*
503 * Pin page tables. Do this after writing to them as otherwise Xen
504 * will barf when doing the type-checking.
505 */
506 nr_pins = 0;
507 for (i = 0; i < max_pfn; i++) {
509 if (i == (max_pfn-1) || nr_pins == MAX_PIN_BATCH) {
510 if (xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0) {
511 ERR("Failed to pin batch of %d page tables", nr_pins);
512 goto out;
513 }
514 nr_pins = 0;
515 }
517 if ( (pfn_type[i] & LPINTAB) == 0 )
518 continue;
520 switch(pfn_type[i]) {
522 case (L1TAB|LPINTAB):
523 pin[nr_pins].cmd = MMUEXT_PIN_L1_TABLE;
524 break;
526 case (L2TAB|LPINTAB):
527 pin[nr_pins].cmd = MMUEXT_PIN_L2_TABLE;
528 break;
530 case (L3TAB|LPINTAB):
531 pin[nr_pins].cmd = MMUEXT_PIN_L3_TABLE;
532 break;
534 case (L4TAB|LPINTAB):
535 pin[nr_pins].cmd = MMUEXT_PIN_L4_TABLE;
536 break;
538 default:
539 continue;
540 }
542 pin[nr_pins].arg1.mfn = p2m[i];
543 nr_pins++;
545 }
547 DPRINTF("\b\b\b\b100%%\n");
548 DPRINTF("Memory reloaded.\n");
550 /* Get the list of PFNs that are not in the psuedo-phys map */
551 {
552 unsigned int count;
553 unsigned long *pfntab;
554 int rc;
556 if (!read_exact(io_fd, &count, sizeof(count))) {
557 ERR("Error when reading pfn count");
558 goto out;
559 }
561 if(!(pfntab = malloc(sizeof(unsigned long) * count))) {
562 ERR("Out of memory");
563 goto out;
564 }
566 if (!read_exact(io_fd, pfntab, sizeof(unsigned long)*count)) {
567 ERR("Error when reading pfntab");
568 goto out;
569 }
571 for (i = 0; i < count; i++) {
573 unsigned long pfn = pfntab[i];
575 if(pfn > max_pfn)
576 /* shouldn't happen - continue optimistically */
577 continue;
579 pfntab[i] = p2m[pfn];
580 p2m[pfn] = INVALID_P2M_ENTRY; // not in pseudo-physical map
581 }
583 if (count > 0) {
585 struct xen_memory_reservation reservation = {
586 .extent_start = pfntab,
587 .nr_extents = count,
588 .extent_order = 0,
589 .domid = dom
590 };
592 if ((rc = xc_memory_op(xc_handle, XENMEM_decrease_reservation,
593 &reservation)) != count) {
594 ERR("Could not decrease reservation : %d", rc);
595 goto out;
596 } else
597 DPRINTF("Decreased reservation by %d pages\n", count);
598 }
599 }
601 if (!read_exact(io_fd, &ctxt, sizeof(ctxt)) ||
602 !read_exact(io_fd, shared_info_page, PAGE_SIZE)) {
603 ERR("Error when reading ctxt or shared info page");
604 goto out;
605 }
607 /* Uncanonicalise the suspend-record frame number and poke resume rec. */
608 pfn = ctxt.user_regs.edx;
609 if ((pfn >= max_pfn) || (pfn_type[pfn] != NOTAB)) {
610 ERR("Suspend record frame number is bad");
611 goto out;
612 }
613 ctxt.user_regs.edx = mfn = p2m[pfn];
614 start_info = xc_map_foreign_range(
615 xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, mfn);
616 start_info->nr_pages = max_pfn;
617 start_info->shared_info = shared_info_frame << PAGE_SHIFT;
618 start_info->flags = 0;
619 *store_mfn = start_info->store_mfn = p2m[start_info->store_mfn];
620 start_info->store_evtchn = store_evtchn;
621 *console_mfn = start_info->console_mfn = p2m[start_info->console_mfn];
622 start_info->console_evtchn = console_evtchn;
623 munmap(start_info, PAGE_SIZE);
625 /* Uncanonicalise each GDT frame number. */
626 if (ctxt.gdt_ents > 8192) {
627 ERR("GDT entry count out of range");
628 goto out;
629 }
631 for (i = 0; i < ctxt.gdt_ents; i += 512) {
632 pfn = ctxt.gdt_frames[i];
633 if ((pfn >= max_pfn) || (pfn_type[pfn] != NOTAB)) {
634 ERR("GDT frame number is bad");
635 goto out;
636 }
637 ctxt.gdt_frames[i] = p2m[pfn];
638 }
640 /* Uncanonicalise the page table base pointer. */
641 pfn = ctxt.ctrlreg[3] >> PAGE_SHIFT;
643 if (pfn >= max_pfn) {
644 ERR("PT base is bad: pfn=%lu max_pfn=%lu type=%08lx",
645 pfn, max_pfn, pfn_type[pfn]);
646 goto out;
647 }
649 if ((pt_levels == 2) && ((pfn_type[pfn]&LTABTYPE_MASK) != L2TAB)) {
650 ERR("PT base is bad. pfn=%lu nr=%lu type=%08lx %08lx",
651 pfn, max_pfn, pfn_type[pfn], (unsigned long)L2TAB);
652 goto out;
653 }
655 if ((pt_levels == 3) && ((pfn_type[pfn]&LTABTYPE_MASK) != L3TAB)) {
656 ERR("PT base is bad. pfn=%lu nr=%lu type=%08lx %08lx",
657 pfn, max_pfn, pfn_type[pfn], (unsigned long)L3TAB);
658 goto out;
659 }
661 ctxt.ctrlreg[3] = p2m[pfn] << PAGE_SHIFT;
663 /* clear any pending events and the selector */
664 memset(&(shared_info->evtchn_pending[0]), 0,
665 sizeof (shared_info->evtchn_pending));
666 for ( i = 0; i < MAX_VIRT_CPUS; i++ )
667 shared_info->vcpu_info[i].evtchn_pending_sel = 0;
669 /* Copy saved contents of shared-info page. No checking needed. */
670 page = xc_map_foreign_range(
671 xc_handle, dom, PAGE_SIZE, PROT_WRITE, shared_info_frame);
672 memcpy(page, shared_info, sizeof(shared_info_t));
673 munmap(page, PAGE_SIZE);
675 /* Uncanonicalise the pfn-to-mfn table frame-number list. */
676 for (i = 0; i < P2M_FL_ENTRIES; i++) {
677 pfn = p2m_frame_list[i];
678 if ((pfn >= max_pfn) || (pfn_type[pfn] != NOTAB)) {
679 ERR("PFN-to-MFN frame number is bad");
680 goto out;
681 }
683 p2m_frame_list[i] = p2m[pfn];
684 }
686 /* Copy the P2M we've constructed to the 'live' P2M */
687 if (!(live_p2m = xc_map_foreign_batch(xc_handle, dom, PROT_WRITE,
688 p2m_frame_list, P2M_FL_ENTRIES))) {
689 ERR("Couldn't map p2m table");
690 goto out;
691 }
693 memcpy(live_p2m, p2m, P2M_SIZE);
694 munmap(live_p2m, P2M_SIZE);
696 /*
697 * Safety checking of saved context:
698 * 1. user_regs is fine, as Xen checks that on context switch.
699 * 2. fpu_ctxt is fine, as it can't hurt Xen.
700 * 3. trap_ctxt needs the code selectors checked.
701 * 4. ldt base must be page-aligned, no more than 8192 ents, ...
702 * 5. gdt already done, and further checking is done by Xen.
703 * 6. check that kernel_ss is safe.
704 * 7. pt_base is already done.
705 * 8. debugregs are checked by Xen.
706 * 9. callback code selectors need checking.
707 */
708 for ( i = 0; i < 256; i++ ) {
709 ctxt.trap_ctxt[i].vector = i;
710 if ((ctxt.trap_ctxt[i].cs & 3) == 0)
711 ctxt.trap_ctxt[i].cs = FLAT_KERNEL_CS;
712 }
713 if ((ctxt.kernel_ss & 3) == 0)
714 ctxt.kernel_ss = FLAT_KERNEL_DS;
715 #if defined(__i386__)
716 if ((ctxt.event_callback_cs & 3) == 0)
717 ctxt.event_callback_cs = FLAT_KERNEL_CS;
718 if ((ctxt.failsafe_callback_cs & 3) == 0)
719 ctxt.failsafe_callback_cs = FLAT_KERNEL_CS;
720 #endif
721 if (((ctxt.ldt_base & (PAGE_SIZE - 1)) != 0) ||
722 (ctxt.ldt_ents > 8192) ||
723 (ctxt.ldt_base > hvirt_start) ||
724 ((ctxt.ldt_base + ctxt.ldt_ents*8) > hvirt_start)) {
725 ERR("Bad LDT base or size");
726 goto out;
727 }
729 DPRINTF("Domain ready to be built.\n");
731 op.cmd = DOM0_SETVCPUCONTEXT;
732 op.u.setvcpucontext.domain = (domid_t)dom;
733 op.u.setvcpucontext.vcpu = 0;
734 op.u.setvcpucontext.ctxt = &ctxt;
735 rc = xc_dom0_op(xc_handle, &op);
737 if (rc != 0) {
738 ERR("Couldn't build the domain");
739 goto out;
740 }
742 out:
743 if ( (rc != 0) && (dom != 0) )
744 xc_domain_destroy(xc_handle, dom);
745 free(mmu);
746 free(p2m);
747 free(pfn_type);
749 DPRINTF("Restore exit with rc=%d\n", rc);
751 return rc;
752 }