direct-io.hg

view tools/libxc/xc_linux_restore.c @ 8500:dd5649730b32

Fix a couple of bogus dom0_op names:
setdomaininfo -> setvcpucontext
pincpudomain -> setvcpuaffinity

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Jan 06 12:53:19 2006 +0100 (2006-01-06)
parents 7acd50d945d7
children 8d6edcf06f9b
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 /* Only have to worry about vcpu 0 even for SMP */
174 if (xc_vcpu_getcontext( xc_handle, dom, 0, &ctxt)) {
175 ERR("Could not get vcpu context");
176 goto out;
177 }
180 /* Read the saved P2M frame list */
181 if(!(p2m_frame_list = malloc(P2M_FL_SIZE))) {
182 ERR("Couldn't allocate p2m_frame_list array");
183 goto out;
184 }
186 if (!read_exact(io_fd, p2m_frame_list, P2M_FL_SIZE)) {
187 ERR("read p2m_frame_list failed");
188 goto out;
189 }
192 /* We want zeroed memory so use calloc rather than malloc. */
193 p2m = calloc(sizeof(unsigned long), max_pfn);
194 pfn_type = calloc(sizeof(unsigned long), max_pfn);
195 region_mfn = calloc(sizeof(unsigned long), MAX_BATCH_SIZE);
197 if ((p2m == NULL) || (pfn_type == NULL) || (region_mfn == NULL)) {
198 ERR("memory alloc failed");
199 errno = ENOMEM;
200 goto out;
201 }
203 if (mlock(region_mfn, sizeof(unsigned long) * MAX_BATCH_SIZE)) {
204 ERR("Could not mlock region_mfn");
205 goto out;
206 }
208 /* Get the domain's shared-info frame. */
209 op.cmd = DOM0_GETDOMAININFO;
210 op.u.getdomaininfo.domain = (domid_t)dom;
211 if (xc_dom0_op(xc_handle, &op) < 0) {
212 ERR("Could not get information on new domain");
213 goto out;
214 }
215 shared_info_frame = op.u.getdomaininfo.shared_info_frame;
217 if(xc_domain_setmaxmem(xc_handle, dom, PFN_TO_KB(max_pfn)) != 0) {
218 errno = ENOMEM;
219 goto out;
220 }
222 if(xc_domain_memory_increase_reservation(
223 xc_handle, dom, max_pfn, 0, 0, NULL) != 0) {
224 ERR("Failed to increase reservation by %lx KB", PFN_TO_KB(max_pfn));
225 errno = ENOMEM;
226 goto out;
227 }
229 DPRINTF("Increased domain reservation by %lx KB\n", PFN_TO_KB(max_pfn));
231 /* Build the pfn-to-mfn table. We choose MFN ordering returned by Xen. */
232 if (xc_get_pfn_list(xc_handle, dom, p2m, max_pfn) != max_pfn) {
233 ERR("Did not read correct number of frame numbers for new dom");
234 goto out;
235 }
237 if(!(mmu = xc_init_mmu_updates(xc_handle, dom))) {
238 ERR("Could not initialise for MMU updates");
239 goto out;
240 }
243 DPRINTF("Reloading memory pages: 0%%\n");
245 /*
246 * Now simply read each saved frame into its new machine frame.
247 * We uncanonicalise page tables as we go.
248 */
249 prev_pc = 0;
251 n = 0;
252 while (1) {
254 int j;
256 this_pc = (n * 100) / max_pfn;
257 if ( (this_pc - prev_pc) >= 5 )
258 {
259 PPRINTF("\b\b\b\b%3d%%", this_pc);
260 prev_pc = this_pc;
261 }
263 if (!read_exact(io_fd, &j, sizeof(int))) {
264 ERR("Error when reading batch size");
265 goto out;
266 }
268 PPRINTF("batch %d\n",j);
270 if (j == -1) {
271 verify = 1;
272 fprintf(stderr, "Entering page verify mode\n");
273 continue;
274 }
276 if (j == 0)
277 break; /* our work here is done */
279 if (j > MAX_BATCH_SIZE) {
280 ERR("Max batch size exceeded. Giving up.");
281 goto out;
282 }
284 if (!read_exact(io_fd, region_pfn_type, j*sizeof(unsigned long))) {
285 ERR("Error when reading region pfn types");
286 goto out;
287 }
289 for (i = 0; i < j; i++) {
291 if ((region_pfn_type[i] & LTAB_MASK) == XTAB)
292 region_mfn[i] = 0; /* we know map will fail, but don't care */
293 else
294 region_mfn[i] = p2m[region_pfn_type[i] & ~LTAB_MASK];
296 }
298 if (!(region_base = xc_map_foreign_batch(
299 xc_handle, dom, PROT_WRITE, region_mfn, j))) {
300 ERR("map batch failed");
301 goto out;
302 }
304 for ( i = 0; i < j; i++ )
305 {
306 void *page;
307 unsigned long pagetype;
309 pfn = region_pfn_type[i] & ~LTAB_MASK;
310 pagetype = region_pfn_type[i] & LTAB_MASK;
312 if (pagetype == XTAB)
313 /* a bogus/unmapped page: skip it */
314 continue;
316 if (pfn > max_pfn) {
317 ERR("pfn out of range");
318 goto out;
319 }
321 pfn_type[pfn] = pagetype;
323 mfn = p2m[pfn];
325 /* In verify mode, we use a copy; otherwise we work in place */
326 page = verify ? (void *)buf : (region_base + i*PAGE_SIZE);
328 if (!read_exact(io_fd, page, PAGE_SIZE)) {
329 ERR("Error when reading page (type was %lx)", pagetype);
330 goto out;
331 }
333 pagetype &= LTABTYPE_MASK;
335 if(pagetype >= L1TAB && pagetype <= L4TAB) {
337 /*
338 ** A page table page - need to 'uncanonicalize' it, i.e.
339 ** replace all the references to pfns with the corresponding
340 ** mfns for the new domain.
341 **
342 ** On PAE we need to ensure that PGDs are in MFNs < 4G, and
343 ** so we may need to update the p2m after the main loop.
344 ** Hence we defer canonicalization of L1s until then.
345 */
346 if(pt_levels != 3 || pagetype != L1TAB) {
348 if(!uncanonicalize_pagetable(pagetype, page)) {
349 /*
350 ** Failing to uncanonicalize a page table can be ok
351 ** under live migration since the pages type may have
352 ** changed by now (and we'll get an update later).
353 */
354 DPRINTF("PT L%ld race on pfn=%08lx mfn=%08lx\n",
355 pagetype >> 28, pfn, mfn);
356 nraces++;
357 continue;
358 }
360 }
362 } else if(pagetype != NOTAB) {
364 ERR("Bogus page type %lx page table is out of range: "
365 "i=%d max_pfn=%lu", pagetype, i, max_pfn);
366 goto out;
368 }
371 if (verify) {
373 int res = memcmp(buf, (region_base + i*PAGE_SIZE), PAGE_SIZE);
375 if (res) {
377 int v;
379 DPRINTF("************** pfn=%lx type=%lx gotcs=%08lx "
380 "actualcs=%08lx\n", pfn, pfn_type[pfn],
381 csum_page(region_base + i*PAGE_SIZE),
382 csum_page(buf));
384 for (v = 0; v < 4; v++) {
386 unsigned long *p = (unsigned long *)
387 (region_base + i*PAGE_SIZE);
388 if (buf[v] != p[v])
389 DPRINTF(" %d: %08lx %08lx\n", v, buf[v], p[v]);
390 }
391 }
392 }
394 if (xc_add_mmu_update(xc_handle, mmu,
395 (((unsigned long long)mfn) << PAGE_SHIFT)
396 | MMU_MACHPHYS_UPDATE, pfn)) {
397 ERR("failed machpys update mfn=%lx pfn=%lx", mfn, pfn);
398 goto out;
399 }
400 } /* end of 'batch' for loop */
402 munmap(region_base, j*PAGE_SIZE);
403 n+= j; /* crude stats */
404 }
406 DPRINTF("Received all pages (%d races)\n", nraces);
408 if(pt_levels == 3) {
410 /*
411 ** XXX SMH on PAE we need to ensure PGDs are in MFNs < 4G. This
412 ** is a little awkward and involves (a) finding all such PGDs and
413 ** replacing them with 'lowmem' versions; (b) upating the p2m[]
414 ** with the new info; and (c) canonicalizing all the L1s using the
415 ** (potentially updated) p2m[].
416 **
417 ** This is relatively slow (and currently involves two passes through
418 ** the pfn_type[] array), but at least seems to be correct. May wish
419 ** to consider more complex approaches to optimize this later.
420 */
422 int j, k;
424 /* First pass: find all L3TABs current in > 4G mfns and get new mfns */
425 for (i = 0; i < max_pfn; i++) {
427 if (((pfn_type[i] & LTABTYPE_MASK)==L3TAB) && (p2m[i]>0xfffffUL)) {
429 unsigned long new_mfn;
430 uint64_t l3ptes[4];
431 uint64_t *l3tab;
433 l3tab = (uint64_t *)
434 xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
435 PROT_READ, p2m[i]);
437 for(j = 0; j < 4; j++)
438 l3ptes[j] = l3tab[j];
440 munmap(l3tab, PAGE_SIZE);
442 if (!(new_mfn=xc_make_page_below_4G(xc_handle, dom, p2m[i]))) {
443 ERR("Couldn't get a page below 4GB :-(");
444 goto out;
445 }
447 p2m[i] = new_mfn;
448 if (xc_add_mmu_update(xc_handle, mmu,
449 (((unsigned long long)new_mfn)
450 << PAGE_SHIFT) |
451 MMU_MACHPHYS_UPDATE, i)) {
452 ERR("Couldn't m2p on PAE root pgdir");
453 goto out;
454 }
456 l3tab = (uint64_t *)
457 xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
458 PROT_READ | PROT_WRITE, p2m[i]);
460 for(j = 0; j < 4; j++)
461 l3tab[j] = l3ptes[j];
463 munmap(l3tab, PAGE_SIZE);
465 }
466 }
468 /* Second pass: find all L1TABs and uncanonicalize them */
469 j = 0;
471 for(i = 0; i < max_pfn; i++) {
473 if (((pfn_type[i] & LTABTYPE_MASK)==L1TAB)) {
474 region_mfn[j] = p2m[i];
475 j++;
476 }
478 if(i == (max_pfn-1) || j == MAX_BATCH_SIZE) {
480 if (!(region_base = xc_map_foreign_batch(
481 xc_handle, dom, PROT_READ | PROT_WRITE,
482 region_mfn, j))) {
483 ERR("map batch failed");
484 goto out;
485 }
487 for(k = 0; k < j; k++) {
488 if(!uncanonicalize_pagetable(L1TAB,
489 region_base + k*PAGE_SIZE)) {
490 ERR("failed uncanonicalize pt!");
491 goto out;
492 }
493 }
495 munmap(region_base, j*PAGE_SIZE);
496 j = 0;
497 }
498 }
500 }
503 if (xc_finish_mmu_updates(xc_handle, mmu)) {
504 ERR("Error doing finish_mmu_updates()");
505 goto out;
506 }
509 /*
510 * Pin page tables. Do this after writing to them as otherwise Xen
511 * will barf when doing the type-checking.
512 */
513 nr_pins = 0;
514 for (i = 0; i < max_pfn; i++) {
516 if (i == (max_pfn-1) || nr_pins == MAX_PIN_BATCH) {
517 if (xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0) {
518 ERR("Failed to pin batch of %d page tables", nr_pins);
519 goto out;
520 }
521 nr_pins = 0;
522 }
524 if ( (pfn_type[i] & LPINTAB) == 0 )
525 continue;
527 switch(pfn_type[i]) {
529 case (L1TAB|LPINTAB):
530 pin[nr_pins].cmd = MMUEXT_PIN_L1_TABLE;
531 break;
533 case (L2TAB|LPINTAB):
534 pin[nr_pins].cmd = MMUEXT_PIN_L2_TABLE;
535 break;
537 case (L3TAB|LPINTAB):
538 pin[nr_pins].cmd = MMUEXT_PIN_L3_TABLE;
539 break;
541 case (L4TAB|LPINTAB):
542 pin[nr_pins].cmd = MMUEXT_PIN_L4_TABLE;
543 break;
545 default:
546 continue;
547 }
549 pin[nr_pins].arg1.mfn = p2m[i];
550 nr_pins++;
552 }
554 DPRINTF("\b\b\b\b100%%\n");
555 DPRINTF("Memory reloaded.\n");
557 /* Get the list of PFNs that are not in the psuedo-phys map */
558 {
559 unsigned int count;
560 unsigned long *pfntab;
561 int rc;
563 if (!read_exact(io_fd, &count, sizeof(count))) {
564 ERR("Error when reading pfn count");
565 goto out;
566 }
568 if(!(pfntab = malloc(sizeof(unsigned long) * count))) {
569 ERR("Out of memory");
570 goto out;
571 }
573 if (!read_exact(io_fd, pfntab, sizeof(unsigned long)*count)) {
574 ERR("Error when reading pfntab");
575 goto out;
576 }
578 for (i = 0; i < count; i++) {
580 unsigned long pfn = pfntab[i];
582 if(pfn > max_pfn)
583 /* shouldn't happen - continue optimistically */
584 continue;
586 pfntab[i] = p2m[pfn];
587 p2m[pfn] = INVALID_P2M_ENTRY; // not in pseudo-physical map
588 }
590 if (count > 0) {
592 struct xen_memory_reservation reservation = {
593 .extent_start = pfntab,
594 .nr_extents = count,
595 .extent_order = 0,
596 .domid = dom
597 };
599 if ((rc = xc_memory_op(xc_handle, XENMEM_decrease_reservation,
600 &reservation)) != count) {
601 ERR("Could not decrease reservation : %d", rc);
602 goto out;
603 } else
604 DPRINTF("Decreased reservation by %d pages\n", count);
605 }
606 }
608 if (!read_exact(io_fd, &ctxt, sizeof(ctxt)) ||
609 !read_exact(io_fd, shared_info_page, PAGE_SIZE)) {
610 ERR("Error when reading ctxt or shared info page");
611 goto out;
612 }
614 /* Uncanonicalise the suspend-record frame number and poke resume rec. */
615 pfn = ctxt.user_regs.edx;
616 if ((pfn >= max_pfn) || (pfn_type[pfn] != NOTAB)) {
617 ERR("Suspend record frame number is bad");
618 goto out;
619 }
620 ctxt.user_regs.edx = mfn = p2m[pfn];
621 start_info = xc_map_foreign_range(
622 xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, mfn);
623 start_info->nr_pages = max_pfn;
624 start_info->shared_info = shared_info_frame << PAGE_SHIFT;
625 start_info->flags = 0;
626 *store_mfn = start_info->store_mfn = p2m[start_info->store_mfn];
627 start_info->store_evtchn = store_evtchn;
628 *console_mfn = start_info->console_mfn = p2m[start_info->console_mfn];
629 start_info->console_evtchn = console_evtchn;
630 munmap(start_info, PAGE_SIZE);
632 /* Uncanonicalise each GDT frame number. */
633 if (ctxt.gdt_ents > 8192) {
634 ERR("GDT entry count out of range");
635 goto out;
636 }
638 for (i = 0; i < ctxt.gdt_ents; i += 512) {
639 pfn = ctxt.gdt_frames[i];
640 if ((pfn >= max_pfn) || (pfn_type[pfn] != NOTAB)) {
641 ERR("GDT frame number is bad");
642 goto out;
643 }
644 ctxt.gdt_frames[i] = p2m[pfn];
645 }
647 /* Uncanonicalise the page table base pointer. */
648 pfn = ctxt.ctrlreg[3] >> PAGE_SHIFT;
650 if (pfn >= max_pfn) {
651 ERR("PT base is bad: pfn=%lu max_pfn=%lu type=%08lx",
652 pfn, max_pfn, pfn_type[pfn]);
653 goto out;
654 }
656 if ((pt_levels == 2) && ((pfn_type[pfn]&LTABTYPE_MASK) != L2TAB)) {
657 ERR("PT base is bad. pfn=%lu nr=%lu type=%08lx %08lx",
658 pfn, max_pfn, pfn_type[pfn], (unsigned long)L2TAB);
659 goto out;
660 }
662 if ((pt_levels == 3) && ((pfn_type[pfn]&LTABTYPE_MASK) != L3TAB)) {
663 ERR("PT base is bad. pfn=%lu nr=%lu type=%08lx %08lx",
664 pfn, max_pfn, pfn_type[pfn], (unsigned long)L3TAB);
665 goto out;
666 }
668 ctxt.ctrlreg[3] = p2m[pfn] << PAGE_SHIFT;
670 /* clear any pending events and the selector */
671 memset(&(shared_info->evtchn_pending[0]), 0,
672 sizeof (shared_info->evtchn_pending));
673 for ( i = 0; i < MAX_VIRT_CPUS; i++ )
674 shared_info->vcpu_info[i].evtchn_pending_sel = 0;
676 /* Copy saved contents of shared-info page. No checking needed. */
677 page = xc_map_foreign_range(
678 xc_handle, dom, PAGE_SIZE, PROT_WRITE, shared_info_frame);
679 memcpy(page, shared_info, sizeof(shared_info_t));
680 munmap(page, PAGE_SIZE);
682 /* Uncanonicalise the pfn-to-mfn table frame-number list. */
683 for (i = 0; i < P2M_FL_ENTRIES; i++) {
684 pfn = p2m_frame_list[i];
685 if ((pfn >= max_pfn) || (pfn_type[pfn] != NOTAB)) {
686 ERR("PFN-to-MFN frame number is bad");
687 goto out;
688 }
690 p2m_frame_list[i] = p2m[pfn];
691 }
693 /* Copy the P2M we've constructed to the 'live' P2M */
694 if (!(live_p2m = xc_map_foreign_batch(xc_handle, dom, PROT_WRITE,
695 p2m_frame_list, P2M_FL_ENTRIES))) {
696 ERR("Couldn't map p2m table");
697 goto out;
698 }
700 memcpy(live_p2m, p2m, P2M_SIZE);
701 munmap(live_p2m, P2M_SIZE);
703 /*
704 * Safety checking of saved context:
705 * 1. user_regs is fine, as Xen checks that on context switch.
706 * 2. fpu_ctxt is fine, as it can't hurt Xen.
707 * 3. trap_ctxt needs the code selectors checked.
708 * 4. ldt base must be page-aligned, no more than 8192 ents, ...
709 * 5. gdt already done, and further checking is done by Xen.
710 * 6. check that kernel_ss is safe.
711 * 7. pt_base is already done.
712 * 8. debugregs are checked by Xen.
713 * 9. callback code selectors need checking.
714 */
715 for ( i = 0; i < 256; i++ ) {
716 ctxt.trap_ctxt[i].vector = i;
717 if ((ctxt.trap_ctxt[i].cs & 3) == 0)
718 ctxt.trap_ctxt[i].cs = FLAT_KERNEL_CS;
719 }
720 if ((ctxt.kernel_ss & 3) == 0)
721 ctxt.kernel_ss = FLAT_KERNEL_DS;
722 #if defined(__i386__)
723 if ((ctxt.event_callback_cs & 3) == 0)
724 ctxt.event_callback_cs = FLAT_KERNEL_CS;
725 if ((ctxt.failsafe_callback_cs & 3) == 0)
726 ctxt.failsafe_callback_cs = FLAT_KERNEL_CS;
727 #endif
728 if (((ctxt.ldt_base & (PAGE_SIZE - 1)) != 0) ||
729 (ctxt.ldt_ents > 8192) ||
730 (ctxt.ldt_base > hvirt_start) ||
731 ((ctxt.ldt_base + ctxt.ldt_ents*8) > hvirt_start)) {
732 ERR("Bad LDT base or size");
733 goto out;
734 }
736 DPRINTF("Domain ready to be built.\n");
738 op.cmd = DOM0_SETVCPUCONTEXT;
739 op.u.setvcpucontext.domain = (domid_t)dom;
740 op.u.setvcpucontext.vcpu = 0;
741 op.u.setvcpucontext.ctxt = &ctxt;
742 rc = xc_dom0_op(xc_handle, &op);
744 if (rc != 0) {
745 ERR("Couldn't build the domain");
746 goto out;
747 }
749 out:
750 if ( (rc != 0) && (dom != 0) )
751 xc_domain_destroy(xc_handle, dom);
752 free(mmu);
753 free(p2m);
754 free(pfn_type);
756 DPRINTF("Restore exit with rc=%d\n", rc);
758 return rc;
759 }