vmm.c (268976) | vmm.c (270070) |
---|---|
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: stable/10/sys/amd64/vmm/vmm.c 268976 2014-07-22 04:39:16Z jhb $ | 26 * $FreeBSD: stable/10/sys/amd64/vmm/vmm.c 270070 2014-08-17 00:52:07Z grehan $ |
27 */ 28 29#include <sys/cdefs.h> | 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: stable/10/sys/amd64/vmm/vmm.c 268976 2014-07-22 04:39:16Z jhb $"); | 30__FBSDID("$FreeBSD: stable/10/sys/amd64/vmm/vmm.c 270070 2014-08-17 00:52:07Z grehan $"); |
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> --- 298 unchanged lines hidden (view full) --- 337 338int 339vm_create(const char *name, struct vm **retvm) 340{ 341 int i; 342 struct vm *vm; 343 struct vmspace *vmspace; 344 | 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> --- 298 unchanged lines hidden (view full) --- 337 338int 339vm_create(const char *name, struct vm **retvm) 340{ 341 int i; 342 struct vm *vm; 343 struct vmspace *vmspace; 344 |
345 const int BSP = 0; 346 | |
347 /* 348 * If vmm.ko could not be successfully initialized then don't attempt 349 * to create the virtual machine. 350 */ 351 if (!vmm_initialized) 352 return (ENXIO); 353 354 if (name == NULL || strlen(name) >= VM_MAX_NAMELEN) --- 13 unchanged lines hidden (view full) --- 368 vm->vatpic = vatpic_init(vm); 369 vm->vatpit = vatpit_init(vm); 370 371 for (i = 0; i < VM_MAXCPU; i++) { 372 vcpu_init(vm, i); 373 guest_msrs_init(vm, i); 374 } 375 | 345 /* 346 * If vmm.ko could not be successfully initialized then don't attempt 347 * to create the virtual machine. 348 */ 349 if (!vmm_initialized) 350 return (ENXIO); 351 352 if (name == NULL || strlen(name) >= VM_MAX_NAMELEN) --- 13 unchanged lines hidden (view full) --- 366 vm->vatpic = vatpic_init(vm); 367 vm->vatpit = vatpit_init(vm); 368 369 for (i = 0; i < VM_MAXCPU; i++) { 370 vcpu_init(vm, i); 371 guest_msrs_init(vm, i); 372 } 373 |
376 vm_activate_cpu(vm, BSP); 377 | |
378 *retvm = vm; 379 return (0); 380} 381 382static void 383vm_free_mem_seg(struct vm *vm, struct mem_seg *seg) 384{ 385 --- 903 unchanged lines hidden (view full) --- 1289 pmap_t pmap; 1290 void *rptr, *sptr; 1291 1292 vcpuid = vmrun->cpuid; 1293 1294 if (vcpuid < 0 || vcpuid >= VM_MAXCPU) 1295 return (EINVAL); 1296 | 374 *retvm = vm; 375 return (0); 376} 377 378static void 379vm_free_mem_seg(struct vm *vm, struct mem_seg *seg) 380{ 381 --- 903 unchanged lines hidden (view full) --- 1285 pmap_t pmap; 1286 void *rptr, *sptr; 1287 1288 vcpuid = vmrun->cpuid; 1289 1290 if (vcpuid < 0 || vcpuid >= VM_MAXCPU) 1291 return (EINVAL); 1292 |
1293 if (!CPU_ISSET(vcpuid, &vm->active_cpus)) 1294 return (EINVAL); 1295 1296 if (CPU_ISSET(vcpuid, &vm->suspended_cpus)) 1297 return (EINVAL); 1298 |
|
1297 rptr = &vm->rendezvous_func; 1298 sptr = &vm->suspend; 1299 pmap = vmspace_pmap(vm->vmspace); 1300 vcpu = &vm->vcpu[vcpuid]; 1301 vme = &vcpu->exitinfo; 1302 rip = vmrun->rip; 1303restart: 1304 critical_enter(); --- 398 unchanged lines hidden (view full) --- 1703 state = vcpu->state; 1704 if (hostcpu != NULL) 1705 *hostcpu = vcpu->hostcpu; 1706 vcpu_unlock(vcpu); 1707 1708 return (state); 1709} 1710 | 1299 rptr = &vm->rendezvous_func; 1300 sptr = &vm->suspend; 1301 pmap = vmspace_pmap(vm->vmspace); 1302 vcpu = &vm->vcpu[vcpuid]; 1303 vme = &vcpu->exitinfo; 1304 rip = vmrun->rip; 1305restart: 1306 critical_enter(); --- 398 unchanged lines hidden (view full) --- 1705 state = vcpu->state; 1706 if (hostcpu != NULL) 1707 *hostcpu = vcpu->hostcpu; 1708 vcpu_unlock(vcpu); 1709 1710 return (state); 1711} 1712 |
1711void | 1713int |
1712vm_activate_cpu(struct vm *vm, int vcpuid) 1713{ 1714 | 1714vm_activate_cpu(struct vm *vm, int vcpuid) 1715{ 1716 |
1715 KASSERT(vcpuid >= 0 && vcpuid < VM_MAXCPU, 1716 ("vm_activate_cpu: invalid vcpuid %d", vcpuid)); 1717 KASSERT(!CPU_ISSET(vcpuid, &vm->active_cpus), 1718 ("vm_activate_cpu: vcpuid %d is already active", vcpuid)); | 1717 if (vcpuid < 0 || vcpuid >= VM_MAXCPU) 1718 return (EINVAL); |
1719 | 1719 |
1720 if (CPU_ISSET(vcpuid, &vm->active_cpus)) 1721 return (EBUSY); 1722 |
|
1720 VCPU_CTR0(vm, vcpuid, "activated"); 1721 CPU_SET_ATOMIC(vcpuid, &vm->active_cpus); | 1723 VCPU_CTR0(vm, vcpuid, "activated"); 1724 CPU_SET_ATOMIC(vcpuid, &vm->active_cpus); |
1725 return (0); |
|
1722} 1723 1724cpuset_t 1725vm_active_cpus(struct vm *vm) 1726{ 1727 1728 return (vm->active_cpus); 1729} 1730 | 1726} 1727 1728cpuset_t 1729vm_active_cpus(struct vm *vm) 1730{ 1731 1732 return (vm->active_cpus); 1733} 1734 |
1735cpuset_t 1736vm_suspended_cpus(struct vm *vm) 1737{ 1738 1739 return (vm->suspended_cpus); 1740} 1741 |
|
1731void * 1732vcpu_stats(struct vm *vm, int vcpuid) 1733{ 1734 1735 return (vm->vcpu[vcpuid].stats); 1736} 1737 1738int --- 161 unchanged lines hidden --- | 1742void * 1743vcpu_stats(struct vm *vm, int vcpuid) 1744{ 1745 1746 return (vm->vcpu[vcpuid].stats); 1747} 1748 1749int --- 161 unchanged lines hidden --- |