vmm.c (38f1b189cd839bd8aa122ae06cc084810ca1e395) | vmm.c (98ed632c63bec8b8cfe7f8849f74ba15657bd06b) |
---|---|
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 --- 58 unchanged lines hidden (view full) --- 67 int flags; 68 int pincpu; /* host cpuid this vcpu is bound to */ 69 int hostcpu; /* host cpuid this vcpu last ran on */ 70 uint64_t guest_msrs[VMM_MSR_NUM]; 71 struct vlapic *vlapic; 72 int vcpuid; 73 struct savefpu *guestfpu; /* guest fpu state */ 74 void *stats; | 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 --- 58 unchanged lines hidden (view full) --- 67 int flags; 68 int pincpu; /* host cpuid this vcpu is bound to */ 69 int hostcpu; /* host cpuid this vcpu last ran on */ 70 uint64_t guest_msrs[VMM_MSR_NUM]; 71 struct vlapic *vlapic; 72 int vcpuid; 73 struct savefpu *guestfpu; /* guest fpu state */ 74 void *stats; |
75 struct vm_exit exitinfo; |
|
75}; 76#define VCPU_F_PINNED 0x0001 77#define VCPU_F_RUNNING 0x0002 78 79#define VCPU_PINCPU(vm, vcpuid) \ 80 ((vm->vcpu[vcpuid].flags & VCPU_F_PINNED) ? vm->vcpu[vcpuid].pincpu : -1) 81 82#define VCPU_UNPIN(vm, vcpuid) (vm->vcpu[vcpuid].flags &= ~VCPU_F_PINNED) --- 22 unchanged lines hidden (view full) --- 105 cpuset_t active_cpus; 106}; 107 108static struct vmm_ops *ops; 109#define VMM_INIT() (ops != NULL ? (*ops->init)() : 0) 110#define VMM_CLEANUP() (ops != NULL ? (*ops->cleanup)() : 0) 111 112#define VMINIT(vm) (ops != NULL ? (*ops->vminit)(vm): NULL) | 76}; 77#define VCPU_F_PINNED 0x0001 78#define VCPU_F_RUNNING 0x0002 79 80#define VCPU_PINCPU(vm, vcpuid) \ 81 ((vm->vcpu[vcpuid].flags & VCPU_F_PINNED) ? vm->vcpu[vcpuid].pincpu : -1) 82 83#define VCPU_UNPIN(vm, vcpuid) (vm->vcpu[vcpuid].flags &= ~VCPU_F_PINNED) --- 22 unchanged lines hidden (view full) --- 106 cpuset_t active_cpus; 107}; 108 109static struct vmm_ops *ops; 110#define VMM_INIT() (ops != NULL ? (*ops->init)() : 0) 111#define VMM_CLEANUP() (ops != NULL ? (*ops->cleanup)() : 0) 112 113#define VMINIT(vm) (ops != NULL ? (*ops->vminit)(vm): NULL) |
113#define VMRUN(vmi, vcpu, rip, vmexit) \ 114 (ops != NULL ? (*ops->vmrun)(vmi, vcpu, rip, vmexit) : ENXIO) | 114#define VMRUN(vmi, vcpu, rip) \ 115 (ops != NULL ? (*ops->vmrun)(vmi, vcpu, rip) : ENXIO) |
115#define VMCLEANUP(vmi) (ops != NULL ? (*ops->vmcleanup)(vmi) : NULL) 116#define VMMMAP(vmi, gpa, hpa, len, attr, prot, spm) \ 117 (ops != NULL ? (*ops->vmmmap)(vmi, gpa, hpa, len, attr, prot, spm) : ENXIO) 118#define VMGETREG(vmi, vcpu, num, retval) \ 119 (ops != NULL ? (*ops->vmgetreg)(vmi, vcpu, num, retval) : ENXIO) 120#define VMSETREG(vmi, vcpu, num, val) \ 121 (ops != NULL ? (*ops->vmsetreg)(vmi, vcpu, num, val) : ENXIO) 122#define VMGETDESC(vmi, vcpu, num, desc) \ --- 36 unchanged lines hidden (view full) --- 159 vcpu->hostcpu = -1; 160 vcpu->vcpuid = vcpu_id; 161 vcpu->vlapic = vlapic_init(vm, vcpu_id); 162 vcpu->guestfpu = fpu_save_area_alloc(); 163 fpu_save_area_reset(vcpu->guestfpu); 164 vcpu->stats = vmm_stat_alloc(); 165} 166 | 116#define VMCLEANUP(vmi) (ops != NULL ? (*ops->vmcleanup)(vmi) : NULL) 117#define VMMMAP(vmi, gpa, hpa, len, attr, prot, spm) \ 118 (ops != NULL ? (*ops->vmmmap)(vmi, gpa, hpa, len, attr, prot, spm) : ENXIO) 119#define VMGETREG(vmi, vcpu, num, retval) \ 120 (ops != NULL ? (*ops->vmgetreg)(vmi, vcpu, num, retval) : ENXIO) 121#define VMSETREG(vmi, vcpu, num, val) \ 122 (ops != NULL ? (*ops->vmsetreg)(vmi, vcpu, num, val) : ENXIO) 123#define VMGETDESC(vmi, vcpu, num, desc) \ --- 36 unchanged lines hidden (view full) --- 160 vcpu->hostcpu = -1; 161 vcpu->vcpuid = vcpu_id; 162 vcpu->vlapic = vlapic_init(vm, vcpu_id); 163 vcpu->guestfpu = fpu_save_area_alloc(); 164 fpu_save_area_reset(vcpu->guestfpu); 165 vcpu->stats = vmm_stat_alloc(); 166} 167 |
168struct vm_exit * 169vm_exitinfo(struct vm *vm, int cpuid) 170{ 171 struct vcpu *vcpu; 172 173 if (cpuid < 0 || cpuid >= VM_MAXCPU) 174 panic("vm_exitinfo: invalid cpuid %d", cpuid); 175 176 vcpu = &vm->vcpu[cpuid]; 177 178 return (&vcpu->exitinfo); 179} 180 |
|
167static int 168vmm_init(void) 169{ 170 int error; 171 172 vmm_ipi_init(); 173 174 error = vmm_mem_init(); --- 365 unchanged lines hidden (view full) --- 540 541 pcb = PCPU_GET(curpcb); 542 set_pcb_flags(pcb, PCB_FULL_IRET); 543 544 vcpu->hostcpu = curcpu; 545 546 restore_guest_msrs(vm, vcpuid); 547 restore_guest_fpustate(vcpu); | 181static int 182vmm_init(void) 183{ 184 int error; 185 186 vmm_ipi_init(); 187 188 error = vmm_mem_init(); --- 365 unchanged lines hidden (view full) --- 554 555 pcb = PCPU_GET(curpcb); 556 set_pcb_flags(pcb, PCB_FULL_IRET); 557 558 vcpu->hostcpu = curcpu; 559 560 restore_guest_msrs(vm, vcpuid); 561 restore_guest_fpustate(vcpu); |
548 error = VMRUN(vm->cookie, vcpuid, vmrun->rip, &vmrun->vm_exit); | 562 error = VMRUN(vm->cookie, vcpuid, vmrun->rip); |
549 save_guest_fpustate(vcpu); 550 restore_host_msrs(vm, vcpuid); 551 552 vmm_stat_incr(vm, vcpuid, VCPU_TOTAL_RUNTIME, rdtsc() - tscval); 553 | 563 save_guest_fpustate(vcpu); 564 restore_host_msrs(vm, vcpuid); 565 566 vmm_stat_incr(vm, vcpuid, VCPU_TOTAL_RUNTIME, rdtsc() - tscval); 567 |
568 /* copy the exit information */ 569 bcopy(&vcpu->exitinfo, &vmrun->vm_exit, sizeof(struct vm_exit)); 570 |
|
554 critical_exit(); 555 556 return (error); 557} 558 559int 560vm_inject_event(struct vm *vm, int vcpuid, int type, 561 int vector, uint32_t code, int code_valid) --- 169 unchanged lines hidden --- | 571 critical_exit(); 572 573 return (error); 574} 575 576int 577vm_inject_event(struct vm *vm, int vcpuid, int type, 578 int vector, uint32_t code, int code_valid) --- 169 unchanged lines hidden --- |