vmmapi.c revision 241486
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$
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD$");
31
32#include <sys/types.h>
33#include <sys/sysctl.h>
34#include <sys/ioctl.h>
35#include <sys/mman.h>
36
37#include <machine/specialreg.h>
38
39#include <stdio.h>
40#include <stdlib.h>
41#include <assert.h>
42#include <string.h>
43#include <fcntl.h>
44#include <unistd.h>
45
46#include <machine/vmm.h>
47#include <machine/vmm_dev.h>
48
49#include "vmmapi.h"
50#include "mptable.h"
51
52#define BIOS_ROM_BASE		(0xf0000)
53#define BIOS_ROM_SIZE		(0x10000)
54
55struct vmctx {
56	int	fd;
57	char	*name;
58};
59
60#define	CREATE(x)  sysctlbyname("hw.vmm.create", NULL, NULL, (x), strlen((x)))
61#define	DESTROY(x) sysctlbyname("hw.vmm.destroy", NULL, NULL, (x), strlen((x)))
62
63static int
64vm_device_open(const char *name)
65{
66        int fd, len;
67        char *vmfile;
68
69	len = strlen("/dev/vmm/") + strlen(name) + 1;
70	vmfile = malloc(len);
71	assert(vmfile != NULL);
72	snprintf(vmfile, len, "/dev/vmm/%s", name);
73
74        /* Open the device file */
75        fd = open(vmfile, O_RDWR, 0);
76
77	free(vmfile);
78        return (fd);
79}
80
81int
82vm_create(const char *name)
83{
84
85	return (CREATE((char *)name));
86}
87
88struct vmctx *
89vm_open(const char *name)
90{
91	struct vmctx *vm;
92
93	vm = malloc(sizeof(struct vmctx) + strlen(name) + 1);
94	assert(vm != NULL);
95
96	vm->fd = -1;
97	vm->name = (char *)(vm + 1);
98	strcpy(vm->name, name);
99
100	if ((vm->fd = vm_device_open(vm->name)) < 0)
101		goto err;
102
103	return (vm);
104err:
105	vm_destroy(vm);
106	return (NULL);
107}
108
109void
110vm_destroy(struct vmctx *vm)
111{
112	assert(vm != NULL);
113
114	if (vm->fd >= 0)
115		close(vm->fd);
116	DESTROY(vm->name);
117
118	free(vm);
119}
120
121size_t
122vmm_get_mem_total(void)
123{
124	size_t mem_total = 0;
125	size_t oldlen = sizeof(mem_total);
126	int error;
127	error = sysctlbyname("hw.vmm.mem_total", &mem_total, &oldlen, NULL, 0);
128	if (error)
129		return -1;
130	return mem_total;
131}
132
133size_t
134vmm_get_mem_free(void)
135{
136	size_t mem_free = 0;
137	size_t oldlen = sizeof(mem_free);
138	int error;
139	error = sysctlbyname("hw.vmm.mem_free", &mem_free, &oldlen, NULL, 0);
140	if (error)
141		return -1;
142	return mem_free;
143}
144
145int
146vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len)
147{
148	int error;
149	struct vm_memory_segment seg;
150
151	bzero(&seg, sizeof(seg));
152	seg.gpa = gpa;
153	error = ioctl(ctx->fd, VM_GET_MEMORY_SEG, &seg);
154	*ret_len = seg.len;
155	return (error);
156}
157
158int
159vm_setup_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len, char **mapaddr)
160{
161	int error;
162	struct vm_memory_segment seg;
163
164	/*
165	 * Create and optionally map 'len' bytes of memory at guest
166	 * physical address 'gpa'
167	 */
168	bzero(&seg, sizeof(seg));
169	seg.gpa = gpa;
170	seg.len = len;
171	error = ioctl(ctx->fd, VM_MAP_MEMORY, &seg);
172	if (error == 0 && mapaddr != NULL) {
173		*mapaddr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED,
174				ctx->fd, gpa);
175	}
176	return (error);
177}
178
179char *
180vm_map_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len)
181{
182
183	/* Map 'len' bytes of memory at guest physical address 'gpa' */
184	return ((char *)mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED,
185		     ctx->fd, gpa));
186}
187
188int
189vm_set_desc(struct vmctx *ctx, int vcpu, int reg,
190	    uint64_t base, uint32_t limit, uint32_t access)
191{
192	int error;
193	struct vm_seg_desc vmsegdesc;
194
195	bzero(&vmsegdesc, sizeof(vmsegdesc));
196	vmsegdesc.cpuid = vcpu;
197	vmsegdesc.regnum = reg;
198	vmsegdesc.desc.base = base;
199	vmsegdesc.desc.limit = limit;
200	vmsegdesc.desc.access = access;
201
202	error = ioctl(ctx->fd, VM_SET_SEGMENT_DESCRIPTOR, &vmsegdesc);
203	return (error);
204}
205
206int
207vm_get_desc(struct vmctx *ctx, int vcpu, int reg,
208	    uint64_t *base, uint32_t *limit, uint32_t *access)
209{
210	int error;
211	struct vm_seg_desc vmsegdesc;
212
213	bzero(&vmsegdesc, sizeof(vmsegdesc));
214	vmsegdesc.cpuid = vcpu;
215	vmsegdesc.regnum = reg;
216
217	error = ioctl(ctx->fd, VM_GET_SEGMENT_DESCRIPTOR, &vmsegdesc);
218	if (error == 0) {
219		*base = vmsegdesc.desc.base;
220		*limit = vmsegdesc.desc.limit;
221		*access = vmsegdesc.desc.access;
222	}
223	return (error);
224}
225
226int
227vm_set_register(struct vmctx *ctx, int vcpu, int reg, uint64_t val)
228{
229	int error;
230	struct vm_register vmreg;
231
232	bzero(&vmreg, sizeof(vmreg));
233	vmreg.cpuid = vcpu;
234	vmreg.regnum = reg;
235	vmreg.regval = val;
236
237	error = ioctl(ctx->fd, VM_SET_REGISTER, &vmreg);
238	return (error);
239}
240
241int
242vm_get_register(struct vmctx *ctx, int vcpu, int reg, uint64_t *ret_val)
243{
244	int error;
245	struct vm_register vmreg;
246
247	bzero(&vmreg, sizeof(vmreg));
248	vmreg.cpuid = vcpu;
249	vmreg.regnum = reg;
250
251	error = ioctl(ctx->fd, VM_GET_REGISTER, &vmreg);
252	*ret_val = vmreg.regval;
253	return (error);
254}
255
256int
257vm_get_pinning(struct vmctx *ctx, int vcpu, int *host_cpuid)
258{
259	int error;
260	struct vm_pin vmpin;
261
262	bzero(&vmpin, sizeof(vmpin));
263	vmpin.vm_cpuid = vcpu;
264
265	error = ioctl(ctx->fd, VM_GET_PINNING, &vmpin);
266	*host_cpuid = vmpin.host_cpuid;
267	return (error);
268}
269
270int
271vm_set_pinning(struct vmctx *ctx, int vcpu, int host_cpuid)
272{
273	int error;
274	struct vm_pin vmpin;
275
276	bzero(&vmpin, sizeof(vmpin));
277	vmpin.vm_cpuid = vcpu;
278	vmpin.host_cpuid = host_cpuid;
279
280	error = ioctl(ctx->fd, VM_SET_PINNING, &vmpin);
281	return (error);
282}
283
284int
285vm_run(struct vmctx *ctx, int vcpu, uint64_t rip, struct vm_exit *vmexit)
286{
287	int error;
288	struct vm_run vmrun;
289
290	bzero(&vmrun, sizeof(vmrun));
291	vmrun.cpuid = vcpu;
292	vmrun.rip = rip;
293
294	error = ioctl(ctx->fd, VM_RUN, &vmrun);
295	bcopy(&vmrun.vm_exit, vmexit, sizeof(struct vm_exit));
296	return (error);
297}
298
299static int
300vm_inject_event_real(struct vmctx *ctx, int vcpu, enum vm_event_type type,
301		     int vector, int error_code, int error_code_valid)
302{
303	struct vm_event ev;
304
305	bzero(&ev, sizeof(ev));
306	ev.cpuid = vcpu;
307	ev.type = type;
308	ev.vector = vector;
309	ev.error_code = error_code;
310	ev.error_code_valid = error_code_valid;
311
312	return (ioctl(ctx->fd, VM_INJECT_EVENT, &ev));
313}
314
315int
316vm_inject_event(struct vmctx *ctx, int vcpu, enum vm_event_type type,
317		int vector)
318{
319
320	return (vm_inject_event_real(ctx, vcpu, type, vector, 0, 0));
321}
322
323int
324vm_inject_event2(struct vmctx *ctx, int vcpu, enum vm_event_type type,
325		 int vector, int error_code)
326{
327
328	return (vm_inject_event_real(ctx, vcpu, type, vector, error_code, 1));
329}
330
331int
332vm_build_tables(struct vmctx *ctxt, int ncpu, int ioapic,
333		void *oemtbl, int oemtblsz)
334{
335
336	return (vm_build_mptable(ctxt, BIOS_ROM_BASE, BIOS_ROM_SIZE, ncpu,
337				 ioapic, oemtbl, oemtblsz));
338}
339
340int
341vm_apicid2vcpu(struct vmctx *ctx, int apicid)
342{
343	/*
344	 * The apic id associated with the 'vcpu' has the same numerical value
345	 * as the 'vcpu' itself.
346	 */
347	return (apicid);
348}
349
350int
351vm_lapic_irq(struct vmctx *ctx, int vcpu, int vector)
352{
353	struct vm_lapic_irq vmirq;
354
355	bzero(&vmirq, sizeof(vmirq));
356	vmirq.cpuid = vcpu;
357	vmirq.vector = vector;
358
359	return (ioctl(ctx->fd, VM_LAPIC_IRQ, &vmirq));
360}
361
362int
363vm_inject_nmi(struct vmctx *ctx, int vcpu)
364{
365	struct vm_nmi vmnmi;
366
367	bzero(&vmnmi, sizeof(vmnmi));
368	vmnmi.cpuid = vcpu;
369
370	return (ioctl(ctx->fd, VM_INJECT_NMI, &vmnmi));
371}
372
373static struct {
374	const char	*name;
375	int		type;
376} capstrmap[] = {
377	{ "hlt_exit",		VM_CAP_HALT_EXIT },
378	{ "mtrap_exit",		VM_CAP_MTRAP_EXIT },
379	{ "pause_exit",		VM_CAP_PAUSE_EXIT },
380	{ "unrestricted_guest",	VM_CAP_UNRESTRICTED_GUEST },
381	{ 0 }
382};
383
384int
385vm_capability_name2type(const char *capname)
386{
387	int i;
388
389	for (i = 0; capstrmap[i].name != NULL && capname != NULL; i++) {
390		if (strcmp(capstrmap[i].name, capname) == 0)
391			return (capstrmap[i].type);
392	}
393
394	return (-1);
395}
396
397const char *
398vm_capability_type2name(int type)
399{
400	int i;
401
402	for (i = 0; capstrmap[i].name != NULL; i++) {
403		if (capstrmap[i].type == type)
404			return (capstrmap[i].name);
405	}
406
407	return (NULL);
408}
409
410int
411vm_get_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap,
412		  int *retval)
413{
414	int error;
415	struct vm_capability vmcap;
416
417	bzero(&vmcap, sizeof(vmcap));
418	vmcap.cpuid = vcpu;
419	vmcap.captype = cap;
420
421	error = ioctl(ctx->fd, VM_GET_CAPABILITY, &vmcap);
422	*retval = vmcap.capval;
423	return (error);
424}
425
426int
427vm_set_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap, int val)
428{
429	struct vm_capability vmcap;
430
431	bzero(&vmcap, sizeof(vmcap));
432	vmcap.cpuid = vcpu;
433	vmcap.captype = cap;
434	vmcap.capval = val;
435
436	return (ioctl(ctx->fd, VM_SET_CAPABILITY, &vmcap));
437}
438
439int
440vm_assign_pptdev(struct vmctx *ctx, int bus, int slot, int func)
441{
442	struct vm_pptdev pptdev;
443
444	bzero(&pptdev, sizeof(pptdev));
445	pptdev.bus = bus;
446	pptdev.slot = slot;
447	pptdev.func = func;
448
449	return (ioctl(ctx->fd, VM_BIND_PPTDEV, &pptdev));
450}
451
452int
453vm_unassign_pptdev(struct vmctx *ctx, int bus, int slot, int func)
454{
455	struct vm_pptdev pptdev;
456
457	bzero(&pptdev, sizeof(pptdev));
458	pptdev.bus = bus;
459	pptdev.slot = slot;
460	pptdev.func = func;
461
462	return (ioctl(ctx->fd, VM_UNBIND_PPTDEV, &pptdev));
463}
464
465int
466vm_map_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func,
467		   vm_paddr_t gpa, size_t len, vm_paddr_t hpa)
468{
469	struct vm_pptdev_mmio pptmmio;
470
471	bzero(&pptmmio, sizeof(pptmmio));
472	pptmmio.bus = bus;
473	pptmmio.slot = slot;
474	pptmmio.func = func;
475	pptmmio.gpa = gpa;
476	pptmmio.len = len;
477	pptmmio.hpa = hpa;
478
479	return (ioctl(ctx->fd, VM_MAP_PPTDEV_MMIO, &pptmmio));
480}
481
482int
483vm_setup_msi(struct vmctx *ctx, int vcpu, int bus, int slot, int func,
484	     int destcpu, int vector, int numvec)
485{
486	struct vm_pptdev_msi pptmsi;
487
488	bzero(&pptmsi, sizeof(pptmsi));
489	pptmsi.vcpu = vcpu;
490	pptmsi.bus = bus;
491	pptmsi.slot = slot;
492	pptmsi.func = func;
493	pptmsi.destcpu = destcpu;
494	pptmsi.vector = vector;
495	pptmsi.numvec = numvec;
496
497	return (ioctl(ctx->fd, VM_PPTDEV_MSI, &pptmsi));
498}
499
500int
501vm_setup_msix(struct vmctx *ctx, int vcpu, int bus, int slot, int func,
502	      int idx, uint32_t msg, uint32_t vector_control, uint64_t addr)
503{
504	struct vm_pptdev_msix pptmsix;
505
506	bzero(&pptmsix, sizeof(pptmsix));
507	pptmsix.vcpu = vcpu;
508	pptmsix.bus = bus;
509	pptmsix.slot = slot;
510	pptmsix.func = func;
511	pptmsix.idx = idx;
512	pptmsix.msg = msg;
513	pptmsix.addr = addr;
514	pptmsix.vector_control = vector_control;
515
516	return ioctl(ctx->fd, VM_PPTDEV_MSIX, &pptmsix);
517}
518
519uint64_t *
520vm_get_stats(struct vmctx *ctx, int vcpu, struct timeval *ret_tv,
521	     int *ret_entries)
522{
523	int error;
524
525	static struct vm_stats vmstats;
526
527	vmstats.cpuid = vcpu;
528
529	error = ioctl(ctx->fd, VM_STATS, &vmstats);
530	if (error == 0) {
531		if (ret_entries)
532			*ret_entries = vmstats.num_entries;
533		if (ret_tv)
534			*ret_tv = vmstats.tv;
535		return (vmstats.statbuf);
536	} else
537		return (NULL);
538}
539
540const char *
541vm_get_stat_desc(struct vmctx *ctx, int index)
542{
543	static struct vm_stat_desc statdesc;
544
545	statdesc.index = index;
546	if (ioctl(ctx->fd, VM_STAT_DESC, &statdesc) == 0)
547		return (statdesc.desc);
548	else
549		return (NULL);
550}
551
552int
553vm_get_x2apic_state(struct vmctx *ctx, int vcpu, enum x2apic_state *state)
554{
555	int error;
556	struct vm_x2apic x2apic;
557
558	bzero(&x2apic, sizeof(x2apic));
559	x2apic.cpuid = vcpu;
560
561	error = ioctl(ctx->fd, VM_GET_X2APIC_STATE, &x2apic);
562	*state = x2apic.state;
563	return (error);
564}
565
566int
567vm_set_x2apic_state(struct vmctx *ctx, int vcpu, enum x2apic_state state)
568{
569	int error;
570	struct vm_x2apic x2apic;
571
572	bzero(&x2apic, sizeof(x2apic));
573	x2apic.cpuid = vcpu;
574	x2apic.state = state;
575
576	error = ioctl(ctx->fd, VM_SET_X2APIC_STATE, &x2apic);
577
578	return (error);
579}
580
581/*
582 * From Intel Vol 3a:
583 * Table 9-1. IA-32 Processor States Following Power-up, Reset or INIT
584 */
585int
586vcpu_reset(struct vmctx *vmctx, int vcpu)
587{
588	int error;
589	uint64_t rflags, rip, cr0, cr4, zero, desc_base, rdx;
590	uint32_t desc_access, desc_limit;
591	uint16_t sel;
592
593	zero = 0;
594
595	rflags = 0x2;
596	error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RFLAGS, rflags);
597	if (error)
598		goto done;
599
600	rip = 0xfff0;
601	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RIP, rip)) != 0)
602		goto done;
603
604	cr0 = CR0_NE;
605	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR0, cr0)) != 0)
606		goto done;
607
608	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR3, zero)) != 0)
609		goto done;
610
611	cr4 = 0;
612	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR4, cr4)) != 0)
613		goto done;
614
615	/*
616	 * CS: present, r/w, accessed, 16-bit, byte granularity, usable
617	 */
618	desc_base = 0xffff0000;
619	desc_limit = 0xffff;
620	desc_access = 0x0093;
621	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_CS,
622			    desc_base, desc_limit, desc_access);
623	if (error)
624		goto done;
625
626	sel = 0xf000;
627	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CS, sel)) != 0)
628		goto done;
629
630	/*
631	 * SS,DS,ES,FS,GS: present, r/w, accessed, 16-bit, byte granularity
632	 */
633	desc_base = 0;
634	desc_limit = 0xffff;
635	desc_access = 0x0093;
636	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_SS,
637			    desc_base, desc_limit, desc_access);
638	if (error)
639		goto done;
640
641	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_DS,
642			    desc_base, desc_limit, desc_access);
643	if (error)
644		goto done;
645
646	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_ES,
647			    desc_base, desc_limit, desc_access);
648	if (error)
649		goto done;
650
651	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_FS,
652			    desc_base, desc_limit, desc_access);
653	if (error)
654		goto done;
655
656	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_GS,
657			    desc_base, desc_limit, desc_access);
658	if (error)
659		goto done;
660
661	sel = 0;
662	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_SS, sel)) != 0)
663		goto done;
664	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_DS, sel)) != 0)
665		goto done;
666	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_ES, sel)) != 0)
667		goto done;
668	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_FS, sel)) != 0)
669		goto done;
670	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_GS, sel)) != 0)
671		goto done;
672
673	/* General purpose registers */
674	rdx = 0xf00;
675	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RAX, zero)) != 0)
676		goto done;
677	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RBX, zero)) != 0)
678		goto done;
679	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RCX, zero)) != 0)
680		goto done;
681	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RDX, rdx)) != 0)
682		goto done;
683	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RSI, zero)) != 0)
684		goto done;
685	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RDI, zero)) != 0)
686		goto done;
687	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RBP, zero)) != 0)
688		goto done;
689	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RSP, zero)) != 0)
690		goto done;
691
692	/* GDTR, IDTR */
693	desc_base = 0;
694	desc_limit = 0xffff;
695	desc_access = 0;
696	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_GDTR,
697			    desc_base, desc_limit, desc_access);
698	if (error != 0)
699		goto done;
700
701	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_IDTR,
702			    desc_base, desc_limit, desc_access);
703	if (error != 0)
704		goto done;
705
706	/* TR */
707	desc_base = 0;
708	desc_limit = 0xffff;
709	desc_access = 0x0000008b;
710	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_TR, 0, 0, desc_access);
711	if (error)
712		goto done;
713
714	sel = 0;
715	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_TR, sel)) != 0)
716		goto done;
717
718	/* LDTR */
719	desc_base = 0;
720	desc_limit = 0xffff;
721	desc_access = 0x00000082;
722	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_LDTR, desc_base,
723			    desc_limit, desc_access);
724	if (error)
725		goto done;
726
727	sel = 0;
728	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_LDTR, 0)) != 0)
729		goto done;
730
731	/* XXX cr2, debug registers */
732
733	error = 0;
734done:
735	return (error);
736}
737