vmm.c (246188) | vmm.c (246686) |
---|---|
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 246188 2013-02-01 01:16:26Z neel $ | 26 * $FreeBSD: head/sys/amd64/vmm/vmm.c 246686 2013-02-11 20:36:07Z neel $ |
27 */ 28 29#include <sys/cdefs.h> | 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/amd64/vmm/vmm.c 246188 2013-02-01 01:16:26Z neel $"); | 30__FBSDID("$FreeBSD: head/sys/amd64/vmm/vmm.c 246686 2013-02-11 20:36:07Z 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> --- 26 unchanged lines hidden (view full) --- 65#include "io/iommu.h" 66 67struct vlapic; 68 69struct vcpu { 70 int flags; 71 enum vcpu_state state; 72 struct mtx mtx; | 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> --- 26 unchanged lines hidden (view full) --- 65#include "io/iommu.h" 66 67struct vlapic; 68 69struct vcpu { 70 int flags; 71 enum vcpu_state state; 72 struct mtx mtx; |
73 int pincpu; /* host cpuid this vcpu is bound to */ | |
74 int hostcpu; /* host cpuid this vcpu last ran on */ 75 uint64_t guest_msrs[VMM_MSR_NUM]; 76 struct vlapic *vlapic; 77 int vcpuid; 78 struct savefpu *guestfpu; /* guest fpu state */ 79 void *stats; 80 struct vm_exit exitinfo; 81 enum x2apic_state x2apic_state; 82 int nmi_pending; 83}; | 73 int hostcpu; /* host cpuid this vcpu last ran on */ 74 uint64_t guest_msrs[VMM_MSR_NUM]; 75 struct vlapic *vlapic; 76 int vcpuid; 77 struct savefpu *guestfpu; /* guest fpu state */ 78 void *stats; 79 struct vm_exit exitinfo; 80 enum x2apic_state x2apic_state; 81 int nmi_pending; 82}; |
84#define VCPU_F_PINNED 0x0001 | |
85 | 83 |
86#define VCPU_PINCPU(vm, vcpuid) \ 87 ((vm->vcpu[vcpuid].flags & VCPU_F_PINNED) ? vm->vcpu[vcpuid].pincpu : -1) 88 89#define VCPU_UNPIN(vm, vcpuid) (vm->vcpu[vcpuid].flags &= ~VCPU_F_PINNED) 90 91#define VCPU_PIN(vm, vcpuid, host_cpuid) \ 92do { \ 93 vm->vcpu[vcpuid].flags |= VCPU_F_PINNED; \ 94 vm->vcpu[vcpuid].pincpu = host_cpuid; \ 95} while(0) 96 | |
97#define vcpu_lock_init(v) mtx_init(&((v)->mtx), "vcpu lock", 0, MTX_SPIN) 98#define vcpu_lock(v) mtx_lock_spin(&((v)->mtx)) 99#define vcpu_unlock(v) mtx_unlock_spin(&((v)->mtx)) 100 101#define VM_MAX_MEMORY_SEGMENTS 2 102 103struct vm { 104 void *cookie; /* processor-specific data */ --- 484 unchanged lines hidden (view full) --- 589 return (EINVAL); 590 591 if (!is_segment_register(reg) && !is_descriptor_table(reg)) 592 return (EINVAL); 593 594 return (VMSETDESC(vm->cookie, vcpu, reg, desc)); 595} 596 | 84#define vcpu_lock_init(v) mtx_init(&((v)->mtx), "vcpu lock", 0, MTX_SPIN) 85#define vcpu_lock(v) mtx_lock_spin(&((v)->mtx)) 86#define vcpu_unlock(v) mtx_unlock_spin(&((v)->mtx)) 87 88#define VM_MAX_MEMORY_SEGMENTS 2 89 90struct vm { 91 void *cookie; /* processor-specific data */ --- 484 unchanged lines hidden (view full) --- 576 return (EINVAL); 577 578 if (!is_segment_register(reg) && !is_descriptor_table(reg)) 579 return (EINVAL); 580 581 return (VMSETDESC(vm->cookie, vcpu, reg, desc)); 582} 583 |
597int 598vm_get_pinning(struct vm *vm, int vcpuid, int *cpuid) 599{ 600 601 if (vcpuid < 0 || vcpuid >= VM_MAXCPU) 602 return (EINVAL); 603 604 *cpuid = VCPU_PINCPU(vm, vcpuid); 605 606 return (0); 607} 608 609int 610vm_set_pinning(struct vm *vm, int vcpuid, int host_cpuid) 611{ 612 struct thread *td; 613 614 if (vcpuid < 0 || vcpuid >= VM_MAXCPU) 615 return (EINVAL); 616 617 td = curthread; /* XXXSMP only safe when muxing vcpus */ 618 619 /* unpin */ 620 if (host_cpuid < 0) { 621 VCPU_UNPIN(vm, vcpuid); 622 thread_lock(td); 623 sched_unbind(td); 624 thread_unlock(td); 625 return (0); 626 } 627 628 if (CPU_ABSENT(host_cpuid)) 629 return (EINVAL); 630 631 /* 632 * XXX we should check that 'host_cpuid' has not already been pinned 633 * by another vm. 634 */ 635 thread_lock(td); 636 sched_bind(td, host_cpuid); 637 thread_unlock(td); 638 VCPU_PIN(vm, vcpuid, host_cpuid); 639 640 return (0); 641} 642 | |
643static void 644restore_guest_fpustate(struct vcpu *vcpu) 645{ 646 647 /* flush host state to the pcb */ 648 fpuexit(curthread); 649 650 /* restore guest FPU state */ --- 388 unchanged lines hidden --- | 584static void 585restore_guest_fpustate(struct vcpu *vcpu) 586{ 587 588 /* flush host state to the pcb */ 589 fpuexit(curthread); 590 591 /* restore guest FPU state */ --- 388 unchanged lines hidden --- |