Deleted Added
full compact
vmm.c (257422) vmm.c (258075)
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 unchanged lines hidden (view full) ---

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 *
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 unchanged lines hidden (view full) ---

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: head/sys/amd64/vmm/vmm.c 257422 2013-10-31 05:20:11Z neel $
26 * $FreeBSD: head/sys/amd64/vmm/vmm.c 258075 2013-11-12 22:51:03Z neel $
27 */
28
29#include <sys/cdefs.h>
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/amd64/vmm/vmm.c 257422 2013-10-31 05:20:11Z neel $");
30__FBSDID("$FreeBSD: head/sys/amd64/vmm/vmm.c 258075 2013-11-12 22:51:03Z neel $");
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/module.h>
36#include <sys/sysctl.h>
37#include <sys/malloc.h>
38#include <sys/pcpu.h>

--- 15 unchanged lines hidden (view full) ---

54
55#include <machine/vm.h>
56#include <machine/pcb.h>
57#include <machine/smp.h>
58#include <x86/apicreg.h>
59#include <machine/vmparam.h>
60
61#include <machine/vmm.h>
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/module.h>
36#include <sys/sysctl.h>
37#include <sys/malloc.h>
38#include <sys/pcpu.h>

--- 15 unchanged lines hidden (view full) ---

54
55#include <machine/vm.h>
56#include <machine/pcb.h>
57#include <machine/smp.h>
58#include <x86/apicreg.h>
59#include <machine/vmparam.h>
60
61#include <machine/vmm.h>
62#include <machine/vmm_dev.h>
63
62#include "vmm_ktr.h"
63#include "vmm_host.h"
64#include "vmm_mem.h"
65#include "vmm_util.h"
64#include "vmm_ktr.h"
65#include "vmm_host.h"
66#include "vmm_mem.h"
67#include "vmm_util.h"
66#include <machine/vmm_dev.h>
68#include "vioapic.h"
67#include "vlapic.h"
68#include "vmm_msr.h"
69#include "vmm_ipi.h"
70#include "vmm_stat.h"
71#include "vmm_lapic.h"
72
73#include "io/ppt.h"
74#include "io/iommu.h"

--- 26 unchanged lines hidden (view full) ---

101 boolean_t wired;
102 vm_object_t object;
103};
104#define VM_MAX_MEMORY_SEGMENTS 2
105
106struct vm {
107 void *cookie; /* processor-specific data */
108 void *iommu; /* iommu-specific data */
69#include "vlapic.h"
70#include "vmm_msr.h"
71#include "vmm_ipi.h"
72#include "vmm_stat.h"
73#include "vmm_lapic.h"
74
75#include "io/ppt.h"
76#include "io/iommu.h"

--- 26 unchanged lines hidden (view full) ---

103 boolean_t wired;
104 vm_object_t object;
105};
106#define VM_MAX_MEMORY_SEGMENTS 2
107
108struct vm {
109 void *cookie; /* processor-specific data */
110 void *iommu; /* iommu-specific data */
111 struct vioapic *vioapic; /* virtual ioapic */
109 struct vmspace *vmspace; /* guest's address space */
110 struct vcpu vcpu[VM_MAXCPU];
111 int num_mem_segs;
112 struct mem_seg mem_segs[VM_MAX_MEMORY_SEGMENTS];
113 char name[VM_MAX_NAMELEN];
114
115 /*
116 * Set of active vcpus.

--- 178 unchanged lines hidden (view full) ---

295
296 vmspace = VMSPACE_ALLOC(VM_MIN_ADDRESS, VM_MAXUSER_ADDRESS);
297 if (vmspace == NULL)
298 return (ENOMEM);
299
300 vm = malloc(sizeof(struct vm), M_VM, M_WAITOK | M_ZERO);
301 strcpy(vm->name, name);
302 vm->cookie = VMINIT(vm, vmspace_pmap(vmspace));
112 struct vmspace *vmspace; /* guest's address space */
113 struct vcpu vcpu[VM_MAXCPU];
114 int num_mem_segs;
115 struct mem_seg mem_segs[VM_MAX_MEMORY_SEGMENTS];
116 char name[VM_MAX_NAMELEN];
117
118 /*
119 * Set of active vcpus.

--- 178 unchanged lines hidden (view full) ---

298
299 vmspace = VMSPACE_ALLOC(VM_MIN_ADDRESS, VM_MAXUSER_ADDRESS);
300 if (vmspace == NULL)
301 return (ENOMEM);
302
303 vm = malloc(sizeof(struct vm), M_VM, M_WAITOK | M_ZERO);
304 strcpy(vm->name, name);
305 vm->cookie = VMINIT(vm, vmspace_pmap(vmspace));
306 vm->vioapic = vioapic_init(vm);
303
304 for (i = 0; i < VM_MAXCPU; i++) {
305 vcpu_init(vm, i);
306 guest_msrs_init(vm, i);
307 }
308
309 vm_activate_cpu(vm, BSP);
310 vm->vmspace = vmspace;

--- 25 unchanged lines hidden (view full) ---

336 for (i = 0; i < vm->num_mem_segs; i++)
337 vm_free_mem_seg(vm, &vm->mem_segs[i]);
338
339 vm->num_mem_segs = 0;
340
341 for (i = 0; i < VM_MAXCPU; i++)
342 vcpu_cleanup(&vm->vcpu[i]);
343
307
308 for (i = 0; i < VM_MAXCPU; i++) {
309 vcpu_init(vm, i);
310 guest_msrs_init(vm, i);
311 }
312
313 vm_activate_cpu(vm, BSP);
314 vm->vmspace = vmspace;

--- 25 unchanged lines hidden (view full) ---

340 for (i = 0; i < vm->num_mem_segs; i++)
341 vm_free_mem_seg(vm, &vm->mem_segs[i]);
342
343 vm->num_mem_segs = 0;
344
345 for (i = 0; i < VM_MAXCPU; i++)
346 vcpu_cleanup(&vm->vcpu[i]);
347
348 vioapic_cleanup(vm->vioapic);
349
344 VMSPACE_FREE(vm->vmspace);
345
346 VMCLEANUP(vm->cookie);
347
348 free(vm, M_VM);
349}
350
351const char *

--- 581 unchanged lines hidden (view full) ---

933static int
934vm_handle_inst_emul(struct vm *vm, int vcpuid, boolean_t *retu)
935{
936 struct vie *vie;
937 struct vcpu *vcpu;
938 struct vm_exit *vme;
939 int error, inst_length;
940 uint64_t rip, gla, gpa, cr3;
350 VMSPACE_FREE(vm->vmspace);
351
352 VMCLEANUP(vm->cookie);
353
354 free(vm, M_VM);
355}
356
357const char *

--- 581 unchanged lines hidden (view full) ---

939static int
940vm_handle_inst_emul(struct vm *vm, int vcpuid, boolean_t *retu)
941{
942 struct vie *vie;
943 struct vcpu *vcpu;
944 struct vm_exit *vme;
945 int error, inst_length;
946 uint64_t rip, gla, gpa, cr3;
947 mem_region_read_t mread;
948 mem_region_write_t mwrite;
941
942 vcpu = &vm->vcpu[vcpuid];
943 vme = &vcpu->exitinfo;
944
945 rip = vme->rip;
946 inst_length = vme->inst_length;
947
948 gla = vme->u.inst_emul.gla;

--- 6 unchanged lines hidden (view full) ---

955 /* Fetch, decode and emulate the faulting instruction */
956 if (vmm_fetch_instruction(vm, vcpuid, rip, inst_length, cr3, vie) != 0)
957 return (EFAULT);
958
959 if (vmm_decode_instruction(vm, vcpuid, gla, vie) != 0)
960 return (EFAULT);
961
962 /* return to userland unless this is a local apic access */
949
950 vcpu = &vm->vcpu[vcpuid];
951 vme = &vcpu->exitinfo;
952
953 rip = vme->rip;
954 inst_length = vme->inst_length;
955
956 gla = vme->u.inst_emul.gla;

--- 6 unchanged lines hidden (view full) ---

963 /* Fetch, decode and emulate the faulting instruction */
964 if (vmm_fetch_instruction(vm, vcpuid, rip, inst_length, cr3, vie) != 0)
965 return (EFAULT);
966
967 if (vmm_decode_instruction(vm, vcpuid, gla, vie) != 0)
968 return (EFAULT);
969
970 /* return to userland unless this is a local apic access */
963 if (gpa < DEFAULT_APIC_BASE || gpa >= DEFAULT_APIC_BASE + PAGE_SIZE) {
971 if (gpa >= DEFAULT_APIC_BASE && gpa < DEFAULT_APIC_BASE + PAGE_SIZE) {
972 mread = lapic_mmio_read;
973 mwrite = lapic_mmio_write;
974 } else if (gpa >= VIOAPIC_BASE && gpa < VIOAPIC_BASE + VIOAPIC_SIZE) {
975 mread = vioapic_mmio_read;
976 mwrite = vioapic_mmio_write;
977 } else {
964 *retu = TRUE;
965 return (0);
966 }
967
978 *retu = TRUE;
979 return (0);
980 }
981
968 error = vmm_emulate_instruction(vm, vcpuid, gpa, vie,
969 lapic_mmio_read, lapic_mmio_write, 0);
982 error = vmm_emulate_instruction(vm, vcpuid, gpa, vie, mread, mwrite, 0);
970
971 /* return to userland to spin up the AP */
972 if (error == 0 && vme->exitcode == VM_EXITCODE_SPINUP_AP)
973 *retu = TRUE;
974
975 return (error);
976}
977

--- 166 unchanged lines hidden (view full) ---

1144}
1145
1146struct vlapic *
1147vm_lapic(struct vm *vm, int cpu)
1148{
1149 return (vm->vcpu[cpu].vlapic);
1150}
1151
983
984 /* return to userland to spin up the AP */
985 if (error == 0 && vme->exitcode == VM_EXITCODE_SPINUP_AP)
986 *retu = TRUE;
987
988 return (error);
989}
990

--- 166 unchanged lines hidden (view full) ---

1157}
1158
1159struct vlapic *
1160vm_lapic(struct vm *vm, int cpu)
1161{
1162 return (vm->vcpu[cpu].vlapic);
1163}
1164
1165struct vioapic *
1166vm_ioapic(struct vm *vm)
1167{
1168
1169 return (vm->vioapic);
1170}
1171
1152boolean_t
1153vmm_is_pptdev(int bus, int slot, int func)
1154{
1155 int found, i, n;
1156 int b, s, f;
1157 char *val, *cp, *cp2;
1158
1159 /*

--- 148 unchanged lines hidden (view full) ---

1308}
1309
1310struct vmspace *
1311vm_get_vmspace(struct vm *vm)
1312{
1313
1314 return (vm->vmspace);
1315}
1172boolean_t
1173vmm_is_pptdev(int bus, int slot, int func)
1174{
1175 int found, i, n;
1176 int b, s, f;
1177 char *val, *cp, *cp2;
1178
1179 /*

--- 148 unchanged lines hidden (view full) ---

1328}
1329
1330struct vmspace *
1331vm_get_vmspace(struct vm *vm)
1332{
1333
1334 return (vm->vmspace);
1335}
1336
1337int
1338vm_apicid2vcpuid(struct vm *vm, int apicid)
1339{
1340 /*
1341 * XXX apic id is assumed to be numerically identical to vcpu id
1342 */
1343 return (apicid);
1344}