- u32 cr0;
-
- cr0 = read_cr0();
- if (!(cr0 & 8))
- write_cr0(cr0|8);
-}
-
-static void copy_in_guest_info(struct lguest *lg, struct lguest_pages *pages)
-{
- if (__get_cpu_var(last_guest) != lg || lg->last_pages != pages) {
- __get_cpu_var(last_guest) = lg;
- lg->last_pages = pages;
- lg->changed = CHANGED_ALL;
- }
-
- /* These are pretty cheap, so we do them unconditionally. */
- pages->state.host_cr3 = __pa(current->mm->pgd);
- map_switcher_in_guest(lg, pages);
- pages->state.guest_tss.esp1 = lg->esp1;
- pages->state.guest_tss.ss1 = lg->ss1;
-
- /* Copy direct trap entries. */
- if (lg->changed & CHANGED_IDT)
- copy_traps(lg, pages->state.guest_idt, default_idt_entries);
-
- /* Copy all GDT entries but the TSS. */
- if (lg->changed & CHANGED_GDT)
- copy_gdt(lg, pages->state.guest_gdt);
- /* If only the TLS entries have changed, copy them. */
- else if (lg->changed & CHANGED_GDT_TLS)
- copy_gdt_tls(lg, pages->state.guest_gdt);
-
- lg->changed = 0;
-}
-
-static void run_guest_once(struct lguest *lg, struct lguest_pages *pages)
-{
- unsigned int clobber;
-
- copy_in_guest_info(lg, pages);
-
- /* Put eflags on stack, lcall does rest: suitable for iret return. */
- asm volatile("pushf; lcall *lguest_entry"
- : "=a"(clobber), "=b"(clobber)
- : "0"(pages), "1"(__pa(lg->pgdirs[lg->pgdidx].pgdir))
- : "memory", "%edx", "%ecx", "%edi", "%esi");
-}
-
-int run_guest(struct lguest *lg, unsigned long __user *user)
-{
- while (!lg->dead) {
- unsigned int cr2 = 0; /* Damn gcc */
-
- /* Hypercalls first: we might have been out to userspace */
- do_hypercalls(lg);
- if (lg->dma_is_pending) {
- if (put_user(lg->pending_dma, user) ||
- put_user(lg->pending_key, user+1))
+ /* We stop running once the Guest is dead. */
+ while (!cpu->lg->dead) {
+ /* First we run any hypercalls the Guest wants done. */
+ if (cpu->hcall)
+ do_hypercalls(cpu);
+
+ /* It's possible the Guest did a NOTIFY hypercall to the
+ * Launcher, in which case we return from the read() now. */
+ if (cpu->pending_notify) {
+ if (put_user(cpu->pending_notify, user))