bhyverun.c revision 268887
1/*-
2 * Copyright (c) 2011 NetApp, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: stable/10/usr.sbin/bhyve/bhyverun.c 268887 2014-07-19 20:13:01Z jhb $
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: stable/10/usr.sbin/bhyve/bhyverun.c 268887 2014-07-19 20:13:01Z jhb $");
31
32#include <sys/types.h>
33#include <sys/mman.h>
34#include <sys/time.h>
35
36#include <machine/atomic.h>
37#include <machine/segments.h>
38
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42#include <err.h>
43#include <libgen.h>
44#include <unistd.h>
45#include <assert.h>
46#include <errno.h>
47#include <pthread.h>
48#include <pthread_np.h>
49#include <sysexits.h>
50
51#include <machine/vmm.h>
52#include <vmmapi.h>
53
54#include "bhyverun.h"
55#include "acpi.h"
56#include "inout.h"
57#include "dbgport.h"
58#include "ioapic.h"
59#include "mem.h"
60#include "mevent.h"
61#include "mptbl.h"
62#include "pci_emul.h"
63#include "pci_lpc.h"
64#include "smbiostbl.h"
65#include "xmsr.h"
66#include "spinup_ap.h"
67#include "rtc.h"
68
69#define GUEST_NIO_PORT		0x488	/* guest upcalls via i/o port */
70
71#define	VMEXIT_SWITCH		0	/* force vcpu switch in mux mode */
72#define	VMEXIT_CONTINUE		1	/* continue from next instruction */
73#define	VMEXIT_RESTART		2	/* restart current instruction */
74#define	VMEXIT_ABORT		3	/* abort the vm run loop */
75#define	VMEXIT_RESET		4	/* guest machine has reset */
76#define	VMEXIT_POWEROFF		5	/* guest machine has powered off */
77
78#define MB		(1024UL * 1024)
79#define GB		(1024UL * MB)
80
81typedef int (*vmexit_handler_t)(struct vmctx *, struct vm_exit *, int *vcpu);
82
83char *vmname;
84
85int guest_ncpus;
86char *guest_uuid_str;
87
88static int pincpu = -1;
89static int guest_vmexit_on_hlt, guest_vmexit_on_pause;
90static int virtio_msix = 1;
91static int x2apic_mode = 0;	/* default is xAPIC */
92
93static int strictio;
94static int strictmsr = 1;
95
96static int acpi;
97
98static char *progname;
99static const int BSP = 0;
100
101static int cpumask;
102
103static void vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip);
104
105struct vm_exit vmexit[VM_MAXCPU];
106
107struct bhyvestats {
108        uint64_t        vmexit_bogus;
109        uint64_t        vmexit_bogus_switch;
110        uint64_t        vmexit_hlt;
111        uint64_t        vmexit_pause;
112        uint64_t        vmexit_mtrap;
113        uint64_t        vmexit_inst_emul;
114        uint64_t        cpu_switch_rotate;
115        uint64_t        cpu_switch_direct;
116        int             io_reset;
117} stats;
118
119struct mt_vmm_info {
120	pthread_t	mt_thr;
121	struct vmctx	*mt_ctx;
122	int		mt_vcpu;
123} mt_vmm_info[VM_MAXCPU];
124
125static void
126usage(int code)
127{
128
129        fprintf(stderr,
130                "Usage: %s [-aehwAHIPW] [-g <gdb port>] [-s <pci>]\n"
131		"       %*s [-c vcpus] [-p pincpu] [-m mem] [-l <lpc>] <vm>\n"
132		"       -a: local apic is in xAPIC mode (deprecated)\n"
133		"       -A: create an ACPI table\n"
134		"       -g: gdb port\n"
135		"       -c: # cpus (default 1)\n"
136		"       -p: pin vcpu 'n' to host cpu 'pincpu + n'\n"
137		"       -H: vmexit from the guest on hlt\n"
138		"       -P: vmexit from the guest on pause\n"
139		"       -W: force virtio to use single-vector MSI\n"
140		"       -e: exit on unhandled I/O access\n"
141		"       -h: help\n"
142		"       -s: <slot,driver,configinfo> PCI slot config\n"
143		"       -l: LPC device configuration\n"
144		"       -m: memory size in MB\n"
145		"       -w: ignore unimplemented MSRs\n"
146		"       -x: local apic is in x2APIC mode\n"
147		"       -Y: disable MPtable generation\n"
148		"       -U: uuid\n",
149		progname, (int)strlen(progname), "");
150
151	exit(code);
152}
153
154void *
155paddr_guest2host(struct vmctx *ctx, uintptr_t gaddr, size_t len)
156{
157
158	return (vm_map_gpa(ctx, gaddr, len));
159}
160
161int
162fbsdrun_vmexit_on_pause(void)
163{
164
165	return (guest_vmexit_on_pause);
166}
167
168int
169fbsdrun_vmexit_on_hlt(void)
170{
171
172	return (guest_vmexit_on_hlt);
173}
174
175int
176fbsdrun_virtio_msix(void)
177{
178
179	return (virtio_msix);
180}
181
182static void *
183fbsdrun_start_thread(void *param)
184{
185	char tname[MAXCOMLEN + 1];
186	struct mt_vmm_info *mtp;
187	int vcpu;
188
189	mtp = param;
190	vcpu = mtp->mt_vcpu;
191
192	snprintf(tname, sizeof(tname), "vcpu %d", vcpu);
193	pthread_set_name_np(mtp->mt_thr, tname);
194
195	vm_loop(mtp->mt_ctx, vcpu, vmexit[vcpu].rip);
196
197	/* not reached */
198	exit(1);
199	return (NULL);
200}
201
202void
203fbsdrun_addcpu(struct vmctx *ctx, int vcpu, uint64_t rip)
204{
205	int error;
206
207	if (cpumask & (1 << vcpu)) {
208		fprintf(stderr, "addcpu: attempting to add existing cpu %d\n",
209		    vcpu);
210		exit(1);
211	}
212
213	atomic_set_int(&cpumask, 1 << vcpu);
214
215	/*
216	 * Set up the vmexit struct to allow execution to start
217	 * at the given RIP
218	 */
219	vmexit[vcpu].rip = rip;
220	vmexit[vcpu].inst_length = 0;
221
222	mt_vmm_info[vcpu].mt_ctx = ctx;
223	mt_vmm_info[vcpu].mt_vcpu = vcpu;
224
225	error = pthread_create(&mt_vmm_info[vcpu].mt_thr, NULL,
226	    fbsdrun_start_thread, &mt_vmm_info[vcpu]);
227	assert(error == 0);
228}
229
230static int
231fbsdrun_deletecpu(struct vmctx *ctx, int vcpu)
232{
233
234	if ((cpumask & (1 << vcpu)) == 0) {
235		fprintf(stderr, "addcpu: attempting to delete unknown cpu %d\n",
236		    vcpu);
237		exit(1);
238	}
239
240	atomic_clear_int(&cpumask, 1 << vcpu);
241	return (cpumask == 0);
242}
243
244static int
245vmexit_catch_reset(void)
246{
247        stats.io_reset++;
248        return (VMEXIT_RESET);
249}
250
251static int
252vmexit_catch_inout(void)
253{
254	return (VMEXIT_ABORT);
255}
256
257static int
258vmexit_handle_notify(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu,
259		     uint32_t eax)
260{
261#if BHYVE_DEBUG
262	/*
263	 * put guest-driven debug here
264	 */
265#endif
266        return (VMEXIT_CONTINUE);
267}
268
269static int
270vmexit_inout(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu)
271{
272	int error;
273	int bytes, port, in, out;
274	uint32_t eax;
275	int vcpu;
276
277	vcpu = *pvcpu;
278
279	port = vme->u.inout.port;
280	bytes = vme->u.inout.bytes;
281	eax = vme->u.inout.eax;
282	in = vme->u.inout.in;
283	out = !in;
284
285	/* We don't deal with these */
286	if (vme->u.inout.string || vme->u.inout.rep)
287		return (VMEXIT_ABORT);
288
289	/* Special case of guest reset */
290	if (out && port == 0x64 && (uint8_t)eax == 0xFE)
291		return (vmexit_catch_reset());
292
293        /* Extra-special case of host notifications */
294        if (out && port == GUEST_NIO_PORT)
295                return (vmexit_handle_notify(ctx, vme, pvcpu, eax));
296
297	error = emulate_inout(ctx, vcpu, in, port, bytes, &eax, strictio);
298	if (error == INOUT_OK && in)
299		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, eax);
300
301	switch (error) {
302	case INOUT_OK:
303		return (VMEXIT_CONTINUE);
304	case INOUT_RESET:
305		return (VMEXIT_RESET);
306	case INOUT_POWEROFF:
307		return (VMEXIT_POWEROFF);
308	default:
309		fprintf(stderr, "Unhandled %s%c 0x%04x\n",
310			in ? "in" : "out",
311			bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'), port);
312		return (vmexit_catch_inout());
313	}
314}
315
316static int
317vmexit_rdmsr(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu)
318{
319	uint64_t val;
320	uint32_t eax, edx;
321	int error;
322
323	val = 0;
324	error = emulate_rdmsr(ctx, *pvcpu, vme->u.msr.code, &val);
325	if (error != 0) {
326		fprintf(stderr, "rdmsr to register %#x on vcpu %d\n",
327		    vme->u.msr.code, *pvcpu);
328		if (strictmsr) {
329			error = vm_inject_exception2(ctx, *pvcpu, IDT_GP, 0);
330			assert(error == 0);
331			return (VMEXIT_RESTART);
332		}
333	}
334
335	eax = val;
336	error = vm_set_register(ctx, *pvcpu, VM_REG_GUEST_RAX, eax);
337	assert(error == 0);
338
339	edx = val >> 32;
340	error = vm_set_register(ctx, *pvcpu, VM_REG_GUEST_RDX, edx);
341	assert(error == 0);
342
343	return (VMEXIT_CONTINUE);
344}
345
346static int
347vmexit_wrmsr(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu)
348{
349	int error;
350
351	error = emulate_wrmsr(ctx, *pvcpu, vme->u.msr.code, vme->u.msr.wval);
352	if (error != 0) {
353		fprintf(stderr, "wrmsr to register %#x(%#lx) on vcpu %d\n",
354		    vme->u.msr.code, vme->u.msr.wval, *pvcpu);
355		if (strictmsr) {
356			error = vm_inject_exception2(ctx, *pvcpu, IDT_GP, 0);
357			assert(error == 0);
358			return (VMEXIT_RESTART);
359		}
360	}
361	return (VMEXIT_CONTINUE);
362}
363
364static int
365vmexit_spinup_ap(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu)
366{
367	int newcpu;
368	int retval = VMEXIT_CONTINUE;
369
370	newcpu = spinup_ap(ctx, *pvcpu,
371			   vme->u.spinup_ap.vcpu, vme->u.spinup_ap.rip);
372
373	return (retval);
374}
375
376static int
377vmexit_spindown_cpu(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu)
378{
379	int lastcpu;
380
381	lastcpu = fbsdrun_deletecpu(ctx, *pvcpu);
382	if (!lastcpu)
383		pthread_exit(NULL);
384	return (vmexit_catch_reset());
385}
386
387static int
388vmexit_vmx(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
389{
390
391	fprintf(stderr, "vm exit[%d]\n", *pvcpu);
392	fprintf(stderr, "\treason\t\tVMX\n");
393	fprintf(stderr, "\trip\t\t0x%016lx\n", vmexit->rip);
394	fprintf(stderr, "\tinst_length\t%d\n", vmexit->inst_length);
395	fprintf(stderr, "\tstatus\t\t%d\n", vmexit->u.vmx.status);
396	fprintf(stderr, "\texit_reason\t%u\n", vmexit->u.vmx.exit_reason);
397	fprintf(stderr, "\tqualification\t0x%016lx\n",
398	    vmexit->u.vmx.exit_qualification);
399	fprintf(stderr, "\tinst_type\t\t%d\n", vmexit->u.vmx.inst_type);
400	fprintf(stderr, "\tinst_error\t\t%d\n", vmexit->u.vmx.inst_error);
401
402	return (VMEXIT_ABORT);
403}
404
405static int
406vmexit_bogus(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
407{
408
409	stats.vmexit_bogus++;
410
411	return (VMEXIT_RESTART);
412}
413
414static int
415vmexit_hlt(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
416{
417
418	stats.vmexit_hlt++;
419
420	/*
421	 * Just continue execution with the next instruction. We use
422	 * the HLT VM exit as a way to be friendly with the host
423	 * scheduler.
424	 */
425	return (VMEXIT_CONTINUE);
426}
427
428static int
429vmexit_pause(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
430{
431
432	stats.vmexit_pause++;
433
434	return (VMEXIT_CONTINUE);
435}
436
437static int
438vmexit_mtrap(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
439{
440
441	stats.vmexit_mtrap++;
442
443	return (VMEXIT_RESTART);
444}
445
446static int
447vmexit_inst_emul(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu)
448{
449	int err;
450	stats.vmexit_inst_emul++;
451
452	err = emulate_mem(ctx, *pvcpu, vmexit->u.inst_emul.gpa,
453			  &vmexit->u.inst_emul.vie);
454
455	if (err) {
456		if (err == EINVAL) {
457			fprintf(stderr,
458			    "Failed to emulate instruction at 0x%lx\n",
459			    vmexit->rip);
460		} else if (err == ESRCH) {
461			fprintf(stderr, "Unhandled memory access to 0x%lx\n",
462			    vmexit->u.inst_emul.gpa);
463		}
464
465		return (VMEXIT_ABORT);
466	}
467
468	return (VMEXIT_CONTINUE);
469}
470
471static vmexit_handler_t handler[VM_EXITCODE_MAX] = {
472	[VM_EXITCODE_INOUT]  = vmexit_inout,
473	[VM_EXITCODE_VMX]    = vmexit_vmx,
474	[VM_EXITCODE_BOGUS]  = vmexit_bogus,
475	[VM_EXITCODE_RDMSR]  = vmexit_rdmsr,
476	[VM_EXITCODE_WRMSR]  = vmexit_wrmsr,
477	[VM_EXITCODE_MTRAP]  = vmexit_mtrap,
478	[VM_EXITCODE_INST_EMUL] = vmexit_inst_emul,
479	[VM_EXITCODE_SPINUP_AP] = vmexit_spinup_ap,
480	[VM_EXITCODE_SPINDOWN_CPU] = vmexit_spindown_cpu,
481};
482
483static void
484vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip)
485{
486	cpuset_t mask;
487	int error, rc, prevcpu;
488	enum vm_exitcode exitcode;
489
490	if (pincpu >= 0) {
491		CPU_ZERO(&mask);
492		CPU_SET(pincpu + vcpu, &mask);
493		error = pthread_setaffinity_np(pthread_self(),
494					       sizeof(mask), &mask);
495		assert(error == 0);
496	}
497
498	while (1) {
499		error = vm_run(ctx, vcpu, rip, &vmexit[vcpu]);
500		if (error != 0)
501			break;
502
503		prevcpu = vcpu;
504
505		exitcode = vmexit[vcpu].exitcode;
506		if (exitcode >= VM_EXITCODE_MAX || handler[exitcode] == NULL) {
507			fprintf(stderr, "vm_loop: unexpected exitcode 0x%x\n",
508			    exitcode);
509			exit(1);
510		}
511
512                rc = (*handler[exitcode])(ctx, &vmexit[vcpu], &vcpu);
513
514		switch (rc) {
515		case VMEXIT_CONTINUE:
516                        rip = vmexit[vcpu].rip + vmexit[vcpu].inst_length;
517			break;
518		case VMEXIT_RESTART:
519                        rip = vmexit[vcpu].rip;
520			break;
521		case VMEXIT_RESET:
522			exit(0);
523		default:
524			exit(1);
525		}
526	}
527	fprintf(stderr, "vm_run error %d, errno %d\n", error, errno);
528}
529
530static int
531num_vcpus_allowed(struct vmctx *ctx)
532{
533	int tmp, error;
534
535	error = vm_get_capability(ctx, BSP, VM_CAP_UNRESTRICTED_GUEST, &tmp);
536
537	/*
538	 * The guest is allowed to spinup more than one processor only if the
539	 * UNRESTRICTED_GUEST capability is available.
540	 */
541	if (error == 0)
542		return (VM_MAXCPU);
543	else
544		return (1);
545}
546
547void
548fbsdrun_set_capabilities(struct vmctx *ctx, int cpu)
549{
550	int err, tmp;
551
552	if (fbsdrun_vmexit_on_hlt()) {
553		err = vm_get_capability(ctx, cpu, VM_CAP_HALT_EXIT, &tmp);
554		if (err < 0) {
555			fprintf(stderr, "VM exit on HLT not supported\n");
556			exit(1);
557		}
558		vm_set_capability(ctx, cpu, VM_CAP_HALT_EXIT, 1);
559		if (cpu == BSP)
560			handler[VM_EXITCODE_HLT] = vmexit_hlt;
561	}
562
563        if (fbsdrun_vmexit_on_pause()) {
564		/*
565		 * pause exit support required for this mode
566		 */
567		err = vm_get_capability(ctx, cpu, VM_CAP_PAUSE_EXIT, &tmp);
568		if (err < 0) {
569			fprintf(stderr,
570			    "SMP mux requested, no pause support\n");
571			exit(1);
572		}
573		vm_set_capability(ctx, cpu, VM_CAP_PAUSE_EXIT, 1);
574		if (cpu == BSP)
575			handler[VM_EXITCODE_PAUSE] = vmexit_pause;
576        }
577
578	if (x2apic_mode)
579		err = vm_set_x2apic_state(ctx, cpu, X2APIC_ENABLED);
580	else
581		err = vm_set_x2apic_state(ctx, cpu, X2APIC_DISABLED);
582
583	if (err) {
584		fprintf(stderr, "Unable to set x2apic state (%d)\n", err);
585		exit(1);
586	}
587
588	vm_set_capability(ctx, cpu, VM_CAP_ENABLE_INVPCID, 1);
589}
590
591int
592main(int argc, char *argv[])
593{
594	int c, error, gdb_port, err, bvmcons;
595	int max_vcpus, mptgen;
596	struct vmctx *ctx;
597	uint64_t rip;
598	size_t memsize;
599
600	bvmcons = 0;
601	progname = basename(argv[0]);
602	gdb_port = 0;
603	guest_ncpus = 1;
604	memsize = 256 * MB;
605	mptgen = 1;
606
607	while ((c = getopt(argc, argv, "abehwxAHIPWYp:g:c:s:m:l:U:")) != -1) {
608		switch (c) {
609		case 'a':
610			x2apic_mode = 0;
611			break;
612		case 'A':
613			acpi = 1;
614			break;
615		case 'b':
616			bvmcons = 1;
617			break;
618		case 'p':
619			pincpu = atoi(optarg);
620			break;
621                case 'c':
622			guest_ncpus = atoi(optarg);
623			break;
624		case 'g':
625			gdb_port = atoi(optarg);
626			break;
627		case 'l':
628			if (lpc_device_parse(optarg) != 0) {
629				errx(EX_USAGE, "invalid lpc device "
630				    "configuration '%s'", optarg);
631			}
632			break;
633		case 's':
634			if (pci_parse_slot(optarg) != 0)
635				exit(1);
636			else
637				break;
638                case 'm':
639			error = vm_parse_memsize(optarg, &memsize);
640			if (error)
641				errx(EX_USAGE, "invalid memsize '%s'", optarg);
642			break;
643		case 'H':
644			guest_vmexit_on_hlt = 1;
645			break;
646		case 'I':
647			/*
648			 * The "-I" option was used to add an ioapic to the
649			 * virtual machine.
650			 *
651			 * An ioapic is now provided unconditionally for each
652			 * virtual machine and this option is now deprecated.
653			 */
654			break;
655		case 'P':
656			guest_vmexit_on_pause = 1;
657			break;
658		case 'e':
659			strictio = 1;
660			break;
661		case 'U':
662			guest_uuid_str = optarg;
663			break;
664		case 'w':
665			strictmsr = 0;
666			break;
667		case 'W':
668			virtio_msix = 0;
669			break;
670		case 'x':
671			x2apic_mode = 1;
672			break;
673		case 'Y':
674			mptgen = 0;
675			break;
676		case 'h':
677			usage(0);
678		default:
679			usage(1);
680		}
681	}
682	argc -= optind;
683	argv += optind;
684
685	if (argc != 1)
686		usage(1);
687
688	vmname = argv[0];
689
690	ctx = vm_open(vmname);
691	if (ctx == NULL) {
692		perror("vm_open");
693		exit(1);
694	}
695
696	max_vcpus = num_vcpus_allowed(ctx);
697	if (guest_ncpus > max_vcpus) {
698		fprintf(stderr, "%d vCPUs requested but only %d available\n",
699			guest_ncpus, max_vcpus);
700		exit(1);
701	}
702
703	fbsdrun_set_capabilities(ctx, BSP);
704
705	err = vm_setup_memory(ctx, memsize, VM_MMAP_ALL);
706	if (err) {
707		fprintf(stderr, "Unable to setup memory (%d)\n", err);
708		exit(1);
709	}
710
711	init_mem();
712	init_inout();
713	ioapic_init(ctx);
714
715	rtc_init(ctx);
716
717	/*
718	 * Exit if a device emulation finds an error in it's initilization
719	 */
720	if (init_pci(ctx) != 0)
721		exit(1);
722
723	if (gdb_port != 0)
724		init_dbgport(gdb_port);
725
726	if (bvmcons)
727		init_bvmcons();
728
729	error = vm_get_register(ctx, BSP, VM_REG_GUEST_RIP, &rip);
730	assert(error == 0);
731
732	/*
733	 * build the guest tables, MP etc.
734	 */
735	if (mptgen) {
736		error = mptable_build(ctx, guest_ncpus);
737		if (error)
738			exit(1);
739	}
740
741	error = smbios_build(ctx);
742	assert(error == 0);
743
744	if (acpi) {
745		error = acpi_build(ctx, guest_ncpus);
746		assert(error == 0);
747	}
748
749	/*
750	 * Change the proc title to include the VM name.
751	 */
752	setproctitle("%s", vmname);
753
754	/*
755	 * Add CPU 0
756	 */
757	fbsdrun_addcpu(ctx, BSP, rip);
758
759	/*
760	 * Head off to the main event dispatch loop
761	 */
762	mevent_dispatch();
763
764	exit(1);
765}
766