debuggers.hg

view xen/arch/x86/domain.c @ 3669:677cb76cff18

bitkeeper revision 1.1159.212.78 (4202391ehUS0T4TJglUpPqBH3oGjNQ)

Move domain builder to be subarch-specific. Fix pfn_info structure and
page reference-counting to be 64-bit clean.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Thu Feb 03 14:45:50 2005 +0000 (2005-02-03)
parents d55d523078f7
children 26a00896163a d3f0465c034e
line source
1 /******************************************************************************
2 * arch/x86/domain.c
3 *
4 * x86-specific domain handling (e.g., register setup and context switching).
5 */
7 /*
8 * Copyright (C) 1995 Linus Torvalds
9 *
10 * Pentium III FXSR, SSE support
11 * Gareth Hughes <gareth@valinux.com>, May 2000
12 */
14 #include <xen/config.h>
15 #include <xen/init.h>
16 #include <xen/lib.h>
17 #include <xen/errno.h>
18 #include <xen/sched.h>
19 #include <xen/smp.h>
20 #include <xen/delay.h>
21 #include <xen/softirq.h>
22 #include <asm/regs.h>
23 #include <asm/mc146818rtc.h>
24 #include <asm/system.h>
25 #include <asm/io.h>
26 #include <asm/processor.h>
27 #include <asm/desc.h>
28 #include <asm/i387.h>
29 #include <asm/mpspec.h>
30 #include <asm/ldt.h>
31 #include <xen/irq.h>
32 #include <xen/event.h>
33 #include <asm/shadow.h>
34 #include <xen/console.h>
35 #include <xen/elf.h>
36 #include <asm/vmx.h>
37 #include <asm/vmx_vmcs.h>
38 #include <xen/kernel.h>
39 #include <public/io/ioreq.h>
40 #include <xen/multicall.h>
42 /* opt_noreboot: If true, machine will need manual reset on error. */
43 static int opt_noreboot = 0;
44 boolean_param("noreboot", opt_noreboot);
46 static void default_idle(void)
47 {
48 __cli();
49 if ( !softirq_pending(smp_processor_id()) )
50 safe_halt();
51 else
52 __sti();
53 }
55 static __attribute_used__ void idle_loop(void)
56 {
57 int cpu = smp_processor_id();
58 for ( ; ; )
59 {
60 irq_stat[cpu].idle_timestamp = jiffies;
61 while ( !softirq_pending(cpu) )
62 default_idle();
63 do_softirq();
64 }
65 }
67 void startup_cpu_idle_loop(void)
68 {
69 /* Just some sanity to ensure that the scheduler is set up okay. */
70 ASSERT(current->domain->id == IDLE_DOMAIN_ID);
71 domain_unpause_by_systemcontroller(current->domain);
72 __enter_scheduler();
74 /*
75 * Declares CPU setup done to the boot processor.
76 * Therefore memory barrier to ensure state is visible.
77 */
78 smp_mb();
79 init_idle();
81 idle_loop();
82 }
84 static long no_idt[2];
85 static int reboot_mode;
86 int reboot_thru_bios = 0;
88 #ifdef CONFIG_SMP
89 int reboot_smp = 0;
90 static int reboot_cpu = -1;
91 /* shamelessly grabbed from lib/vsprintf.c for readability */
92 #define is_digit(c) ((c) >= '0' && (c) <= '9')
93 #endif
96 static inline void kb_wait(void)
97 {
98 int i;
100 for (i=0; i<0x10000; i++)
101 if ((inb_p(0x64) & 0x02) == 0)
102 break;
103 }
106 void machine_restart(char * __unused)
107 {
108 #ifdef CONFIG_SMP
109 int cpuid;
110 #endif
112 if ( opt_noreboot )
113 {
114 printk("Reboot disabled on cmdline: require manual reset\n");
115 for ( ; ; ) __asm__ __volatile__ ("hlt");
116 }
118 #ifdef CONFIG_SMP
119 cpuid = GET_APIC_ID(apic_read(APIC_ID));
121 /* KAF: Need interrupts enabled for safe IPI. */
122 __sti();
124 if (reboot_smp) {
126 /* check to see if reboot_cpu is valid
127 if its not, default to the BSP */
128 if ((reboot_cpu == -1) ||
129 (reboot_cpu > (NR_CPUS -1)) ||
130 !(phys_cpu_present_map & (1<<cpuid)))
131 reboot_cpu = boot_cpu_physical_apicid;
133 reboot_smp = 0; /* use this as a flag to only go through this once*/
134 /* re-run this function on the other CPUs
135 it will fall though this section since we have
136 cleared reboot_smp, and do the reboot if it is the
137 correct CPU, otherwise it halts. */
138 if (reboot_cpu != cpuid)
139 smp_call_function((void *)machine_restart , NULL, 1, 0);
140 }
142 /* if reboot_cpu is still -1, then we want a tradional reboot,
143 and if we are not running on the reboot_cpu,, halt */
144 if ((reboot_cpu != -1) && (cpuid != reboot_cpu)) {
145 for (;;)
146 __asm__ __volatile__ ("hlt");
147 }
148 /*
149 * Stop all CPUs and turn off local APICs and the IO-APIC, so
150 * other OSs see a clean IRQ state.
151 */
152 smp_send_stop();
153 disable_IO_APIC();
154 #endif
155 #ifdef CONFIG_VMX
156 stop_vmx();
157 #endif
159 if(!reboot_thru_bios) {
160 /* rebooting needs to touch the page at absolute addr 0 */
161 *((unsigned short *)__va(0x472)) = reboot_mode;
162 for (;;) {
163 int i;
164 for (i=0; i<100; i++) {
165 kb_wait();
166 udelay(50);
167 outb(0xfe,0x64); /* pulse reset low */
168 udelay(50);
169 }
170 /* That didn't work - force a triple fault.. */
171 __asm__ __volatile__("lidt %0": "=m" (no_idt));
172 __asm__ __volatile__("int3");
173 }
174 }
176 panic("Need to reinclude BIOS reboot code\n");
177 }
180 void __attribute__((noreturn)) __machine_halt(void *unused)
181 {
182 for ( ; ; )
183 __asm__ __volatile__ ( "cli; hlt" );
184 }
186 void machine_halt(void)
187 {
188 smp_call_function(__machine_halt, NULL, 1, 1);
189 __machine_halt(NULL);
190 }
192 void dump_pageframe_info(struct domain *d)
193 {
194 struct pfn_info *page;
196 if ( d->tot_pages < 10 )
197 {
198 list_for_each_entry ( page, &d->page_list, list )
199 {
200 printk("Page %08x: caf=%08x, taf=%08x\n",
201 page_to_phys(page), page->count_info,
202 page->u.inuse.type_info);
203 }
204 }
206 page = virt_to_page(d->shared_info);
207 printk("Shared_info@%08x: caf=%08x, taf=%08x\n",
208 page_to_phys(page), page->count_info,
209 page->u.inuse.type_info);
210 }
212 struct domain *arch_alloc_domain_struct(void)
213 {
214 return xmalloc(struct domain);
215 }
217 void arch_free_domain_struct(struct domain *d)
218 {
219 xfree(d);
220 }
222 struct exec_domain *arch_alloc_exec_domain_struct(void)
223 {
224 return xmalloc(struct exec_domain);
225 }
227 void arch_free_exec_domain_struct(struct exec_domain *ed)
228 {
229 xfree(ed);
230 }
232 void free_perdomain_pt(struct domain *d)
233 {
234 free_xenheap_page((unsigned long)d->mm_perdomain_pt);
235 }
237 static void continue_idle_task(struct exec_domain *ed)
238 {
239 reset_stack_and_jump(idle_loop);
240 }
242 static void continue_nonidle_task(struct exec_domain *ed)
243 {
244 reset_stack_and_jump(ret_from_intr);
245 }
247 void arch_do_createdomain(struct exec_domain *ed)
248 {
249 struct domain *d = ed->domain;
251 SET_DEFAULT_FAST_TRAP(&ed->thread);
253 if ( d->id == IDLE_DOMAIN_ID )
254 {
255 ed->thread.schedule_tail = continue_idle_task;
256 }
257 else
258 {
259 ed->thread.schedule_tail = continue_nonidle_task;
261 d->shared_info = (void *)alloc_xenheap_page();
262 memset(d->shared_info, 0, PAGE_SIZE);
263 ed->vcpu_info = &d->shared_info->vcpu_data[ed->eid];
264 SHARE_PFN_WITH_DOMAIN(virt_to_page(d->shared_info), d);
265 machine_to_phys_mapping[virt_to_phys(d->shared_info) >>
266 PAGE_SHIFT] = INVALID_P2M_ENTRY;
268 d->mm_perdomain_pt = (l1_pgentry_t *)alloc_xenheap_page();
269 memset(d->mm_perdomain_pt, 0, PAGE_SIZE);
270 machine_to_phys_mapping[virt_to_phys(d->mm_perdomain_pt) >>
271 PAGE_SHIFT] = INVALID_P2M_ENTRY;
272 ed->mm.perdomain_ptes = d->mm_perdomain_pt;
273 }
274 }
276 #ifdef CONFIG_VMX
277 void arch_vmx_do_resume(struct exec_domain *ed)
278 {
279 u64 vmcs_phys_ptr = (u64) virt_to_phys(ed->thread.arch_vmx.vmcs);
281 load_vmcs(&ed->thread.arch_vmx, vmcs_phys_ptr);
282 vmx_do_resume(ed);
283 reset_stack_and_jump(vmx_asm_do_resume);
284 }
286 void arch_vmx_do_launch(struct exec_domain *ed)
287 {
288 u64 vmcs_phys_ptr = (u64) virt_to_phys(ed->thread.arch_vmx.vmcs);
290 load_vmcs(&ed->thread.arch_vmx, vmcs_phys_ptr);
291 vmx_do_launch(ed);
292 reset_stack_and_jump(vmx_asm_do_launch);
293 }
295 static void monitor_mk_pagetable(struct exec_domain *ed)
296 {
297 unsigned long mpfn;
298 l2_pgentry_t *mpl2e;
299 struct pfn_info *mpfn_info;
300 struct mm_struct *m = &ed->mm;
301 struct domain *d = ed->domain;
303 mpfn_info = alloc_domheap_page(NULL);
304 ASSERT( mpfn_info );
306 mpfn = (unsigned long) (mpfn_info - frame_table);
307 mpl2e = (l2_pgentry_t *) map_domain_mem(mpfn << L1_PAGETABLE_SHIFT);
308 memset(mpl2e, 0, PAGE_SIZE);
310 memcpy(&mpl2e[DOMAIN_ENTRIES_PER_L2_PAGETABLE],
311 &idle_pg_table[DOMAIN_ENTRIES_PER_L2_PAGETABLE],
312 HYPERVISOR_ENTRIES_PER_L2_PAGETABLE * sizeof(l2_pgentry_t));
314 m->monitor_table = mk_pagetable(mpfn << L1_PAGETABLE_SHIFT);
315 m->shadow_mode = SHM_full_32;
317 mpl2e[PERDOMAIN_VIRT_START >> L2_PAGETABLE_SHIFT] =
318 mk_l2_pgentry((__pa(d->mm_perdomain_pt) & PAGE_MASK)
319 | __PAGE_HYPERVISOR);
321 unmap_domain_mem(mpl2e);
322 }
324 /*
325 * Free the pages for monitor_table and guest_pl2e_cache
326 */
327 static void monitor_rm_pagetable(struct exec_domain *ed)
328 {
329 struct mm_struct *m = &ed->mm;
330 l2_pgentry_t *mpl2e;
331 unsigned long mpfn;
333 mpl2e = (l2_pgentry_t *) map_domain_mem(pagetable_val(m->monitor_table));
334 /*
335 * First get the pfn for guest_pl2e_cache by looking at monitor_table
336 */
337 mpfn = l2_pgentry_val(mpl2e[LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT])
338 >> PAGE_SHIFT;
340 free_domheap_page(&frame_table[mpfn]);
341 unmap_domain_mem(mpl2e);
343 /*
344 * Then free monitor_table.
345 */
346 mpfn = (pagetable_val(m->monitor_table)) >> PAGE_SHIFT;
347 free_domheap_page(&frame_table[mpfn]);
349 m->monitor_table = mk_pagetable(0);
350 }
352 static int vmx_final_setup_guestos(struct exec_domain *ed,
353 full_execution_context_t *full_context)
354 {
355 int error;
356 execution_context_t *context;
357 struct vmcs_struct *vmcs;
359 context = &full_context->cpu_ctxt;
361 /*
362 * Create a new VMCS
363 */
364 if (!(vmcs = alloc_vmcs())) {
365 printk("Failed to create a new VMCS\n");
366 return -ENOMEM;
367 }
369 memset(&ed->thread.arch_vmx, 0, sizeof (struct arch_vmx_struct));
371 ed->thread.arch_vmx.vmcs = vmcs;
372 error = construct_vmcs(&ed->thread.arch_vmx, context, full_context, VMCS_USE_HOST_ENV);
373 if (error < 0) {
374 printk("Failed to construct a new VMCS\n");
375 goto out;
376 }
378 monitor_mk_pagetable(ed);
379 ed->thread.schedule_tail = arch_vmx_do_launch;
380 clear_bit(VMX_CPU_STATE_PG_ENABLED, &ed->thread.arch_vmx.cpu_state);
382 #if defined (__i386)
383 ed->thread.arch_vmx.vmx_platform.real_mode_data =
384 (unsigned long *) context->esi;
385 #endif
387 if (ed == ed->domain->exec_domain[0]) {
388 /*
389 * Required to do this once per domain
390 */
391 memset(&ed->domain->shared_info->evtchn_mask[0], 0xff,
392 sizeof(ed->domain->shared_info->evtchn_mask));
393 clear_bit(IOPACKET_PORT, &ed->domain->shared_info->evtchn_mask[0]);
394 }
396 return 0;
398 out:
399 free_vmcs(vmcs);
400 ed->thread.arch_vmx.vmcs = 0;
401 return error;
402 }
403 #endif
405 int arch_final_setup_guestos(struct exec_domain *d, full_execution_context_t *c)
406 {
407 unsigned long phys_basetab;
408 int i, rc;
410 clear_bit(EDF_DONEFPUINIT, &d->ed_flags);
411 if ( c->flags & ECF_I387_VALID )
412 set_bit(EDF_DONEFPUINIT, &d->ed_flags);
414 memcpy(&d->thread.user_ctxt,
415 &c->cpu_ctxt,
416 sizeof(d->thread.user_ctxt));
418 /* Clear IOPL for unprivileged domains. */
419 if (!IS_PRIV(d->domain))
420 d->thread.user_ctxt.eflags &= 0xffffcfff;
422 /*
423 * This is sufficient! If the descriptor DPL differs from CS RPL then we'll
424 * #GP. If DS, ES, FS, GS are DPL 0 then they'll be cleared automatically.
425 * If SS RPL or DPL differs from CS RPL then we'll #GP.
426 */
427 if (!(c->flags & ECF_VMX_GUEST))
428 if ( ((d->thread.user_ctxt.cs & 3) == 0) ||
429 ((d->thread.user_ctxt.ss & 3) == 0) )
430 return -EINVAL;
432 memcpy(&d->thread.i387,
433 &c->fpu_ctxt,
434 sizeof(d->thread.i387));
436 memcpy(d->thread.traps,
437 &c->trap_ctxt,
438 sizeof(d->thread.traps));
440 if ( (rc = (int)set_fast_trap(d, c->fast_trap_idx)) != 0 )
441 return rc;
443 d->mm.ldt_base = c->ldt_base;
444 d->mm.ldt_ents = c->ldt_ents;
446 d->thread.guestos_ss = c->guestos_ss;
447 d->thread.guestos_sp = c->guestos_esp;
449 for ( i = 0; i < 8; i++ )
450 (void)set_debugreg(d, i, c->debugreg[i]);
452 d->thread.event_selector = c->event_callback_cs;
453 d->thread.event_address = c->event_callback_eip;
454 d->thread.failsafe_selector = c->failsafe_callback_cs;
455 d->thread.failsafe_address = c->failsafe_callback_eip;
457 phys_basetab = c->pt_base;
458 d->mm.pagetable = mk_pagetable(phys_basetab);
459 if ( !get_page_and_type(&frame_table[phys_basetab>>PAGE_SHIFT], d->domain,
460 PGT_base_page_table) )
461 return -EINVAL;
463 /* Failure to set GDT is harmless. */
464 SET_GDT_ENTRIES(d, DEFAULT_GDT_ENTRIES);
465 SET_GDT_ADDRESS(d, DEFAULT_GDT_ADDRESS);
466 if ( c->gdt_ents != 0 )
467 {
468 if ( (rc = (int)set_gdt(d, c->gdt_frames, c->gdt_ents)) != 0 )
469 {
470 put_page_and_type(&frame_table[phys_basetab>>PAGE_SHIFT]);
471 return rc;
472 }
473 }
475 #ifdef CONFIG_VMX
476 if (c->flags & ECF_VMX_GUEST)
477 return vmx_final_setup_guestos(d, c);
478 #endif
480 return 0;
481 }
483 void new_thread(struct exec_domain *d,
484 unsigned long start_pc,
485 unsigned long start_stack,
486 unsigned long start_info)
487 {
488 execution_context_t *ec = &d->thread.user_ctxt;
490 /*
491 * Initial register values:
492 * DS,ES,FS,GS = FLAT_RING1_DS
493 * CS:EIP = FLAT_RING1_CS:start_pc
494 * SS:ESP = FLAT_RING1_DS:start_stack
495 * ESI = start_info
496 * [EAX,EBX,ECX,EDX,EDI,EBP are zero]
497 */
498 ec->ds = ec->es = ec->fs = ec->gs = ec->ss = FLAT_GUESTOS_DS;
499 ec->cs = FLAT_GUESTOS_CS;
500 ec->eip = start_pc;
501 ec->esp = start_stack;
502 ec->esi = start_info;
504 __save_flags(ec->eflags);
505 ec->eflags |= X86_EFLAGS_IF;
506 }
509 /*
510 * This special macro can be used to load a debugging register
511 */
512 #define loaddebug(thread,register) \
513 __asm__("mov %0,%%db" #register \
514 : /* no output */ \
515 :"r" (thread->debugreg[register]))
517 void switch_to(struct exec_domain *prev_p, struct exec_domain *next_p)
518 {
519 struct thread_struct *next = &next_p->thread;
520 struct tss_struct *tss = init_tss + smp_processor_id();
521 execution_context_t *stack_ec = get_execution_context();
522 int i;
523 #ifdef CONFIG_VMX
524 unsigned long vmx_domain = next_p->thread.arch_vmx.flags;
525 #endif
527 __cli();
529 /* Switch guest general-register state. */
530 if ( !is_idle_task(prev_p->domain) )
531 {
532 memcpy(&prev_p->thread.user_ctxt,
533 stack_ec,
534 sizeof(*stack_ec));
535 unlazy_fpu(prev_p);
536 CLEAR_FAST_TRAP(&prev_p->thread);
537 }
539 if ( !is_idle_task(next_p->domain) )
540 {
541 memcpy(stack_ec,
542 &next_p->thread.user_ctxt,
543 sizeof(*stack_ec));
545 /* Maybe switch the debug registers. */
546 if ( unlikely(next->debugreg[7]) )
547 {
548 loaddebug(next, 0);
549 loaddebug(next, 1);
550 loaddebug(next, 2);
551 loaddebug(next, 3);
552 /* no 4 and 5 */
553 loaddebug(next, 6);
554 loaddebug(next, 7);
555 }
557 #ifdef CONFIG_VMX
558 if ( vmx_domain )
559 {
560 /* Switch page tables. */
561 write_ptbase(&next_p->mm);
563 set_current(next_p);
564 /* Switch GDT and LDT. */
565 __asm__ __volatile__ ("lgdt %0" : "=m" (*next_p->mm.gdt));
567 __sti();
568 return;
569 }
570 #endif
572 SET_FAST_TRAP(&next_p->thread);
574 #ifdef __i386__
575 /* Switch the guest OS ring-1 stack. */
576 tss->esp1 = next->guestos_sp;
577 tss->ss1 = next->guestos_ss;
578 #endif
580 /* Switch page tables. */
581 write_ptbase(&next_p->mm);
582 }
584 if ( unlikely(prev_p->thread.io_bitmap != NULL) )
585 {
586 for ( i = 0; i < sizeof(prev_p->thread.io_bitmap_sel) * 8; i++ )
587 if ( !test_bit(i, &prev_p->thread.io_bitmap_sel) )
588 memset(&tss->io_bitmap[i * IOBMP_BYTES_PER_SELBIT],
589 ~0U, IOBMP_BYTES_PER_SELBIT);
590 tss->bitmap = IOBMP_INVALID_OFFSET;
591 }
593 if ( unlikely(next_p->thread.io_bitmap != NULL) )
594 {
595 for ( i = 0; i < sizeof(next_p->thread.io_bitmap_sel) * 8; i++ )
596 if ( !test_bit(i, &next_p->thread.io_bitmap_sel) )
597 memcpy(&tss->io_bitmap[i * IOBMP_BYTES_PER_SELBIT],
598 &next_p->thread.io_bitmap[i * IOBMP_BYTES_PER_SELBIT],
599 IOBMP_BYTES_PER_SELBIT);
600 tss->bitmap = IOBMP_OFFSET;
601 }
603 set_current(next_p);
605 /* Switch GDT and LDT. */
606 __asm__ __volatile__ ("lgdt %0" : "=m" (*next_p->mm.gdt));
607 load_LDT(next_p);
609 __sti();
610 }
613 /* XXX Currently the 'domain' field is ignored! XXX */
614 long do_iopl(domid_t domain, unsigned int new_io_pl)
615 {
616 execution_context_t *ec = get_execution_context();
617 ec->eflags = (ec->eflags & 0xffffcfff) | ((new_io_pl&3) << 12);
618 return 0;
619 }
621 unsigned long hypercall_create_continuation(
622 unsigned int op, unsigned int nr_args, ...)
623 {
624 struct mc_state *mcs = &mc_state[smp_processor_id()];
625 execution_context_t *ec;
626 unsigned long *preg;
627 unsigned int i;
628 va_list args;
630 va_start(args, nr_args);
632 if ( test_bit(_MCSF_in_multicall, &mcs->flags) )
633 {
634 __set_bit(_MCSF_call_preempted, &mcs->flags);
636 for ( i = 0; i < nr_args; i++ )
637 mcs->call.args[i] = va_arg(args, unsigned long);
638 }
639 else
640 {
641 ec = get_execution_context();
642 #if defined(__i386__)
643 ec->eax = op;
644 ec->eip -= 2; /* re-execute 'int 0x82' */
646 for ( i = 0, preg = &ec->ebx; i < nr_args; i++, preg++ )
647 *preg = va_arg(args, unsigned long);
648 #else
649 preg = NULL; /* XXX x86/64 */
650 #endif
651 }
653 va_end(args);
655 return op;
656 }
658 static void relinquish_list(struct domain *d, struct list_head *list)
659 {
660 struct list_head *ent;
661 struct pfn_info *page;
662 unsigned long x, y;
664 /* Use a recursive lock, as we may enter 'free_domheap_page'. */
665 spin_lock_recursive(&d->page_alloc_lock);
667 ent = list->next;
668 while ( ent != list )
669 {
670 page = list_entry(ent, struct pfn_info, list);
672 /* Grab a reference to the page so it won't disappear from under us. */
673 if ( unlikely(!get_page(page, d)) )
674 {
675 /* Couldn't get a reference -- someone is freeing this page. */
676 ent = ent->next;
677 continue;
678 }
680 if ( test_and_clear_bit(_PGT_pinned, &page->u.inuse.type_info) )
681 put_page_and_type(page);
683 if ( test_and_clear_bit(_PGC_allocated, &page->count_info) )
684 put_page(page);
686 /*
687 * Forcibly invalidate base page tables at this point to break circular
688 * 'linear page table' references. This is okay because MMU structures
689 * are not shared across domains and this domain is now dead. Thus base
690 * tables are not in use so a non-zero count means circular reference.
691 */
692 y = page->u.inuse.type_info;
693 for ( ; ; )
694 {
695 x = y;
696 if ( likely((x & (PGT_type_mask|PGT_validated)) !=
697 (PGT_base_page_table|PGT_validated)) )
698 break;
700 y = cmpxchg(&page->u.inuse.type_info, x, x & ~PGT_validated);
701 if ( likely(y == x) )
702 {
703 free_page_type(page, PGT_base_page_table);
704 break;
705 }
706 }
708 /* Follow the list chain and /then/ potentially free the page. */
709 ent = ent->next;
710 put_page(page);
711 }
713 spin_unlock_recursive(&d->page_alloc_lock);
714 }
716 #ifdef CONFIG_VMX
717 static void vmx_domain_relinquish_memory(struct exec_domain *ed)
718 {
719 struct domain *d = ed->domain;
721 /*
722 * Free VMCS
723 */
724 ASSERT(ed->thread.arch_vmx.vmcs);
725 free_vmcs(ed->thread.arch_vmx.vmcs);
726 ed->thread.arch_vmx.vmcs = 0;
728 monitor_rm_pagetable(ed);
730 if (ed == d->exec_domain[0]) {
731 int i;
732 unsigned long pfn;
734 for (i = 0; i < ENTRIES_PER_L1_PAGETABLE; i++) {
735 unsigned long l1e;
737 l1e = l1_pgentry_val(d->mm_perdomain_pt[i]);
738 if (l1e & _PAGE_PRESENT) {
739 pfn = l1e >> PAGE_SHIFT;
740 free_domheap_page(&frame_table[pfn]);
741 }
742 }
743 }
745 }
746 #endif
748 void domain_relinquish_memory(struct domain *d)
749 {
750 struct exec_domain *ed;
752 /* Ensure that noone is running over the dead domain's page tables. */
753 synchronise_pagetables(~0UL);
755 /* Exit shadow mode before deconstructing final guest page table. */
756 shadow_mode_disable(d);
758 /* Drop the in-use reference to the page-table base. */
759 for_each_exec_domain ( d, ed )
760 {
761 if ( pagetable_val(ed->mm.pagetable) != 0 )
762 put_page_and_type(&frame_table[pagetable_val(ed->mm.pagetable) >>
763 PAGE_SHIFT]);
764 }
766 #ifdef CONFIG_VMX
767 if ( VMX_DOMAIN(d->exec_domain[0]) )
768 for_each_exec_domain ( d, ed )
769 vmx_domain_relinquish_memory(ed);
770 #endif
772 /*
773 * Relinquish GDT mappings. No need for explicit unmapping of the LDT as
774 * it automatically gets squashed when the guest's mappings go away.
775 */
776 for_each_exec_domain(d, ed)
777 destroy_gdt(ed);
779 /* Relinquish every page of memory. */
780 relinquish_list(d, &d->xenpage_list);
781 relinquish_list(d, &d->page_list);
782 }