Page MenuHomeFreeBSD

D37162.diff
No OneTemporary

D37162.diff

diff --git a/sys/amd64/include/vmm.h b/sys/amd64/include/vmm.h
--- a/sys/amd64/include/vmm.h
+++ b/sys/amd64/include/vmm.h
@@ -258,7 +258,7 @@
void *vm_gpa_hold_global(struct vm *vm, vm_paddr_t gpa, size_t len,
int prot, void **cookie);
void vm_gpa_release(void *cookie);
-bool vm_mem_allocated(struct vm *vm, int vcpuid, vm_paddr_t gpa);
+bool vm_mem_allocated(struct vcpu *vcpu, vm_paddr_t gpa);
int vm_get_register(struct vcpu *vcpu, int reg, uint64_t *retval);
int vm_set_register(struct vcpu *vcpu, int reg, uint64_t val);
@@ -269,11 +269,11 @@
int vm_run(struct vm *vm, struct vm_run *vmrun);
int vm_suspend(struct vm *vm, enum vm_suspend_how how);
int vm_inject_nmi(struct vm *vm, int vcpu);
-int vm_nmi_pending(struct vm *vm, int vcpuid);
-void vm_nmi_clear(struct vm *vm, int vcpuid);
+int vm_nmi_pending(struct vcpu *vcpu);
+void vm_nmi_clear(struct vcpu *vcpu);
int vm_inject_extint(struct vm *vm, int vcpu);
-int vm_extint_pending(struct vm *vm, int vcpuid);
-void vm_extint_clear(struct vm *vm, int vcpuid);
+int vm_extint_pending(struct vcpu *vcpu);
+void vm_extint_clear(struct vcpu *vcpu);
int vcpu_vcpuid(struct vcpu *vcpu);
struct vm *vcpu_vm(struct vcpu *vcpu);
struct vcpu *vm_vcpu(struct vm *vm, int cpu);
@@ -289,12 +289,12 @@
int vm_suspend_cpu(struct vm *vm, int vcpu);
int vm_resume_cpu(struct vm *vm, int vcpu);
int vm_restart_instruction(struct vcpu *vcpu);
-struct vm_exit *vm_exitinfo(struct vm *vm, int vcpuid);
-void vm_exit_suspended(struct vm *vm, int vcpuid, uint64_t rip);
-void vm_exit_debug(struct vm *vm, int vcpuid, uint64_t rip);
-void vm_exit_rendezvous(struct vm *vm, int vcpuid, uint64_t rip);
-void vm_exit_astpending(struct vm *vm, int vcpuid, uint64_t rip);
-void vm_exit_reqidle(struct vm *vm, int vcpuid, uint64_t rip);
+struct vm_exit *vm_exitinfo(struct vcpu *vcpu);
+void vm_exit_suspended(struct vcpu *vcpu, uint64_t rip);
+void vm_exit_debug(struct vcpu *vcpu, uint64_t rip);
+void vm_exit_rendezvous(struct vcpu *vcpu, uint64_t rip);
+void vm_exit_astpending(struct vcpu *vcpu, uint64_t rip);
+void vm_exit_reqidle(struct vcpu *vcpu, uint64_t rip);
int vm_snapshot_req(struct vm *vm, struct vm_snapshot_meta *meta);
int vm_restore_time(struct vm *vm);
@@ -342,7 +342,7 @@
return (*info->iptr);
}
-int vcpu_debugged(struct vm *vm, int vcpuid);
+int vcpu_debugged(struct vcpu *vcpu);
/*
* Return true if device indicated by bus/slot/func is supposed to be a
@@ -366,14 +366,14 @@
enum vcpu_state vcpu_get_state(struct vcpu *vcpu, int *hostcpu);
static int __inline
-vcpu_is_running(struct vm *vm, int vcpu, int *hostcpu)
+vcpu_is_running(struct vcpu *vcpu, int *hostcpu)
{
- return (vcpu_get_state(vm_vcpu(vm, vcpu), hostcpu) == VCPU_RUNNING);
+ return (vcpu_get_state(vcpu, hostcpu) == VCPU_RUNNING);
}
#ifdef _SYS_PROC_H_
static int __inline
-vcpu_should_yield(struct vm *vm, int vcpu)
+vcpu_should_yield(struct vcpu *vcpu)
{
struct thread *td;
@@ -417,7 +417,7 @@
*
* Return value is 0 on success and non-zero on failure.
*/
-int vm_exit_intinfo(struct vm *vm, int vcpuid, uint64_t intinfo);
+int vm_exit_intinfo(struct vcpu *vcpu, uint64_t intinfo);
/*
* This function is called before every VM-entry to retrieve a pending
@@ -427,7 +427,7 @@
* Returns 0 if there are no events that need to be injected into the guest
* and non-zero otherwise.
*/
-int vm_entry_intinfo(struct vm *vm, int vcpuid, uint64_t *info);
+int vm_entry_intinfo(struct vcpu *vcpu, uint64_t *info);
int vm_get_intinfo(struct vm *vm, int vcpuid, uint64_t *info1, uint64_t *info2);
@@ -435,10 +435,8 @@
* Function used to keep track of the guest's TSC offset. The
* offset is used by the virutalization extensions to provide a consistent
* value for the Time Stamp Counter to the guest.
- *
- * Return value is 0 on success and non-zero on failure.
*/
-int vm_set_tsc_offset(struct vm *vm, int vcpu_id, uint64_t offset);
+void vm_set_tsc_offset(struct vcpu *vcpu, uint64_t offset);
enum vm_reg_name vm_segment_name(int seg_encoding);
@@ -470,8 +468,8 @@
void vm_copyin(struct vm_copyinfo *copyinfo, void *kaddr, size_t len);
void vm_copyout(const void *kaddr, struct vm_copyinfo *copyinfo, size_t len);
-int vcpu_trace_exceptions(struct vm *vm, int vcpuid);
-int vcpu_trap_wbinvd(struct vm *vm, int vcpuid);
+int vcpu_trace_exceptions(struct vcpu *vcpu);
+int vcpu_trap_wbinvd(struct vcpu *vcpu);
#endif /* KERNEL */
#ifdef _KERNEL
@@ -790,27 +788,27 @@
int errcode);
static __inline void
-vm_inject_ud(void *vm, int vcpuid)
+vm_inject_ud(struct vcpu *vcpu)
{
- vm_inject_fault(vm, vcpuid, IDT_UD, 0, 0);
+ vm_inject_fault(vcpu, IDT_UD, 0, 0);
}
static __inline void
-vm_inject_gp(void *vm, int vcpuid)
+vm_inject_gp(struct vcpu *vcpu)
{
- vm_inject_fault(vm, vcpuid, IDT_GP, 1, 0);
+ vm_inject_fault(vcpu, IDT_GP, 1, 0);
}
static __inline void
-vm_inject_ac(void *vm, int vcpuid, int errcode)
+vm_inject_ac(struct vcpu *vcpu, int errcode)
{
- vm_inject_fault(vm, vcpuid, IDT_AC, 1, errcode);
+ vm_inject_fault(vcpu, IDT_AC, 1, errcode);
}
static __inline void
-vm_inject_ss(void *vm, int vcpuid, int errcode)
+vm_inject_ss(struct vcpu *vcpu, int errcode)
{
- vm_inject_fault(vm, vcpuid, IDT_SS, 1, errcode);
+ vm_inject_fault(vcpu, IDT_SS, 1, errcode);
}
void vm_inject_pf(void *vm, int vcpuid, int error_code, uint64_t cr2);
diff --git a/sys/amd64/vmm/amd/svm.h b/sys/amd64/vmm/amd/svm.h
--- a/sys/amd64/vmm/amd/svm.h
+++ b/sys/amd64/vmm/amd/svm.h
@@ -69,8 +69,7 @@
void svm_launch(uint64_t pa, struct svm_regctx *gctx, struct pcpu *pcpu);
#ifdef BHYVE_SNAPSHOT
-int svm_set_tsc_offset(struct svm_softc *sc, struct svm_vcpu *vcpu,
- uint64_t offset);
+void svm_set_tsc_offset(struct svm_vcpu *vcpu, uint64_t offset);
#endif
#endif /* _SVM_H_ */
diff --git a/sys/amd64/vmm/amd/svm.c b/sys/amd64/vmm/amd/svm.c
--- a/sys/amd64/vmm/amd/svm.c
+++ b/sys/amd64/vmm/amd/svm.c
@@ -282,10 +282,9 @@
}
#ifdef BHYVE_SNAPSHOT
-int
-svm_set_tsc_offset(struct svm_softc *sc, struct svm_vcpu *vcpu, uint64_t offset)
+void
+svm_set_tsc_offset(struct svm_vcpu *vcpu, uint64_t offset)
{
- int error;
struct vmcb_ctrl *ctrl;
ctrl = svm_get_vmcb_ctrl(vcpu);
@@ -294,9 +293,7 @@
svm_set_dirty(vcpu, VMCB_CACHE_I);
SVM_CTR1(vcpu, "tsc offset changed to %#lx", offset);
- error = vm_set_tsc_offset(sc->vm, vcpu->vcpuid, offset);
-
- return (error);
+ vm_set_tsc_offset(vcpu->vcpu, offset);
}
#endif
@@ -464,7 +461,7 @@
* Intercept everything when tracing guest exceptions otherwise
* just intercept machine check exception.
*/
- if (vcpu_trace_exceptions(sc->vm, vcpu->vcpuid)) {
+ if (vcpu_trace_exceptions(vcpu->vcpu)) {
for (n = 0; n < 32; n++) {
/*
* Skip unimplemented vectors in the exception bitmap.
@@ -504,7 +501,7 @@
svm_enable_intercept(vcpu, VMCB_CTRL2_INTCPT, VMCB_INTCPT_CLGI);
svm_enable_intercept(vcpu, VMCB_CTRL2_INTCPT, VMCB_INTCPT_SKINIT);
svm_enable_intercept(vcpu, VMCB_CTRL2_INTCPT, VMCB_INTCPT_ICEBP);
- if (vcpu_trap_wbinvd(sc->vm, vcpu->vcpuid)) {
+ if (vcpu_trap_wbinvd(vcpu->vcpu)) {
svm_enable_intercept(vcpu, VMCB_CTRL2_INTCPT,
VMCB_INTCPT_WBINVD);
}
@@ -992,9 +989,7 @@
{
struct vmcb_ctrl *ctrl;
uint64_t intinfo;
- int vcpuid;
- vcpuid = vcpu->vcpuid;
ctrl = svm_get_vmcb_ctrl(vcpu);
intinfo = ctrl->exitintinfo;
if (!VMCB_EXITINTINFO_VALID(intinfo))
@@ -1009,7 +1004,7 @@
SVM_CTR2(vcpu, "SVM:Pending INTINFO(0x%lx), vector=%d.\n", intinfo,
VMCB_EXITINTINFO_VECTOR(intinfo));
vmm_stat_incr(vcpu->vcpu, VCPU_EXITINTINFO, 1);
- vm_exit_intinfo(svm_sc->vm, vcpuid, intinfo);
+ vm_exit_intinfo(vcpu->vcpu, intinfo);
}
#ifdef INVARIANTS
@@ -1149,10 +1144,9 @@
struct vm_exit *vme;
struct vmcb_state *state;
uint64_t changed, lma, oldval;
- int error __diagused, vcpuid;
+ int error __diagused;
state = svm_get_vmcb_state(vcpu);
- vcpuid = vcpu->vcpuid;
oldval = state->efer;
SVM_CTR2(vcpu, "wrmsr(efer) %#lx/%#lx", oldval, newval);
@@ -1179,7 +1173,7 @@
goto gpf;
if (newval & EFER_NXE) {
- if (!vm_cpuid_capability(sc->vm, vcpuid, VCC_NO_EXECUTE))
+ if (!vm_cpuid_capability(vcpu->vcpu, VCC_NO_EXECUTE))
goto gpf;
}
@@ -1188,19 +1182,19 @@
* this is fixed flag guest attempt to set EFER_LMSLE as an error.
*/
if (newval & EFER_LMSLE) {
- vme = vm_exitinfo(sc->vm, vcpuid);
+ vme = vm_exitinfo(vcpu->vcpu);
vm_exit_svm(vme, VMCB_EXIT_MSR, 1, 0);
*retu = true;
return (0);
}
if (newval & EFER_FFXSR) {
- if (!vm_cpuid_capability(sc->vm, vcpuid, VCC_FFXSR))
+ if (!vm_cpuid_capability(vcpu->vcpu, VCC_FFXSR))
goto gpf;
}
if (newval & EFER_TCE) {
- if (!vm_cpuid_capability(sc->vm, vcpuid, VCC_TCE))
+ if (!vm_cpuid_capability(vcpu->vcpu, VCC_TCE))
goto gpf;
}
@@ -1219,18 +1213,17 @@
int error;
if (lapic_msr(num))
- error = lapic_wrmsr(sc->vm, vcpu->vcpuid, num, val, retu);
+ error = lapic_wrmsr(vcpu->vcpu, num, val, retu);
else if (num == MSR_EFER)
error = svm_write_efer(sc, vcpu, val, retu);
else
- error = svm_wrmsr(sc, vcpu, num, val, retu);
+ error = svm_wrmsr(vcpu, num, val, retu);
return (error);
}
static int
-emulate_rdmsr(struct svm_softc *sc, struct svm_vcpu *vcpu, u_int num,
- bool *retu)
+emulate_rdmsr(struct svm_vcpu *vcpu, u_int num, bool *retu)
{
struct vmcb_state *state;
struct svm_regctx *ctx;
@@ -1238,9 +1231,9 @@
int error;
if (lapic_msr(num))
- error = lapic_rdmsr(sc->vm, vcpu->vcpuid, num, &result, retu);
+ error = lapic_rdmsr(vcpu->vcpu, num, &result, retu);
else
- error = svm_rdmsr(sc, vcpu, num, &result, retu);
+ error = svm_rdmsr(vcpu, num, &result, retu);
if (error == 0) {
state = svm_get_vmcb_state(vcpu);
@@ -1335,14 +1328,12 @@
uint64_t code, info1, info2, val;
uint32_t eax, ecx, edx;
int error __diagused, errcode_valid, handled, idtvec, reflect;
- int vcpuid;
bool retu;
ctx = svm_get_guest_regctx(vcpu);
vmcb = svm_get_vmcb(vcpu);
state = &vmcb->state;
ctrl = &vmcb->ctrl;
- vcpuid = vcpu->vcpuid;
handled = 0;
code = ctrl->exitcode;
@@ -1487,7 +1478,7 @@
} else {
SVM_CTR1(vcpu, "rdmsr %#x", ecx);
vmm_stat_incr(vcpu->vcpu, VMEXIT_RDMSR, 1);
- if (emulate_rdmsr(svm_sc, vcpu, ecx, &retu)) {
+ if (emulate_rdmsr(vcpu, ecx, &retu)) {
vmexit->exitcode = VM_EXITCODE_RDMSR;
vmexit->u.msr.code = ecx;
} else if (!retu) {
@@ -1504,8 +1495,9 @@
break;
case VMCB_EXIT_CPUID:
vmm_stat_incr(vcpu->vcpu, VMEXIT_CPUID, 1);
- handled = x86_emulate_cpuid(svm_sc->vm, vcpuid, &state->rax,
- &ctx->sctx_rbx, &ctx->sctx_rcx, &ctx->sctx_rdx);
+ handled = x86_emulate_cpuid(vcpu->vcpu,
+ &state->rax, &ctx->sctx_rbx, &ctx->sctx_rcx,
+ &ctx->sctx_rdx);
break;
case VMCB_EXIT_HLT:
vmm_stat_incr(vcpu->vcpu, VMEXIT_HLT, 1);
@@ -1522,7 +1514,7 @@
SVM_CTR2(vcpu, "nested page fault with "
"reserved bits set: info1(%#lx) info2(%#lx)",
info1, info2);
- } else if (vm_mem_allocated(svm_sc->vm, vcpuid, info2)) {
+ } else if (vm_mem_allocated(vcpu->vcpu, info2)) {
vmexit->exitcode = VM_EXITCODE_PAGING;
vmexit->u.paging.gpa = info2;
vmexit->u.paging.fault_type = npf_fault_type(info1);
@@ -1596,9 +1588,8 @@
svm_inj_intinfo(struct svm_softc *svm_sc, struct svm_vcpu *vcpu)
{
uint64_t intinfo;
- int vcpuid = vcpu->vcpuid;
- if (!vm_entry_intinfo(svm_sc->vm, vcpuid, &intinfo))
+ if (!vm_entry_intinfo(vcpu->vcpu, &intinfo))
return;
KASSERT(VMCB_EXITINTINFO_VALID(intinfo), ("%s: entry intinfo is not "
@@ -1624,7 +1615,6 @@
uint8_t v_tpr;
int vector, need_intr_window;
int extint_pending;
- int vcpuid = vcpu->vcpuid;
state = svm_get_vmcb_state(vcpu);
ctrl = svm_get_vmcb_ctrl(vcpu);
@@ -1650,7 +1640,7 @@
svm_inj_intinfo(sc, vcpu);
/* NMI event has priority over interrupts. */
- if (vm_nmi_pending(sc->vm, vcpuid)) {
+ if (vm_nmi_pending(vcpu->vcpu)) {
if (nmi_blocked(vcpu)) {
/*
* Can't inject another NMI if the guest has not
@@ -1686,7 +1676,7 @@
*/
ipi_cpu(curcpu, IPI_AST); /* XXX vmm_ipinum? */
} else {
- vm_nmi_clear(sc->vm, vcpuid);
+ vm_nmi_clear(vcpu->vcpu);
/* Inject NMI, vector number is not used */
svm_eventinject(vcpu, VMCB_EVENTINJ_TYPE_NMI,
@@ -1699,7 +1689,7 @@
}
}
- extint_pending = vm_extint_pending(sc->vm, vcpuid);
+ extint_pending = vm_extint_pending(vcpu->vcpu);
if (!extint_pending) {
if (!vlapic_pending_intr(vlapic, &vector))
goto done;
@@ -1742,7 +1732,7 @@
if (!extint_pending) {
vlapic_intr_accepted(vlapic, vector);
} else {
- vm_extint_clear(sc->vm, vcpuid);
+ vm_extint_clear(vcpu->vcpu);
vatpic_intr_accepted(sc->vm, vector);
}
@@ -2003,18 +1993,15 @@
struct vmcb_ctrl *ctrl;
struct vm_exit *vmexit;
struct vlapic *vlapic;
- struct vm *vm;
uint64_t vmcb_pa;
- int handled, vcpuid;
+ int handled;
uint16_t ldt_sel;
vcpu = vcpui;
- vcpuid = vcpu->vcpuid;
svm_sc = vcpu->sc;
- vm = svm_sc->vm;
state = svm_get_vmcb_state(vcpu);
ctrl = svm_get_vmcb_ctrl(vcpu);
- vmexit = vm_exitinfo(vm, vcpuid);
+ vmexit = vm_exitinfo(vcpu->vcpu);
vlapic = vm_lapic(vcpu->vcpu);
gctx = svm_get_guest_regctx(vcpu);
@@ -2045,7 +2032,7 @@
vmm_stat_incr(vcpu->vcpu, VCPU_MIGRATIONS, 1);
}
- svm_msr_guest_enter(svm_sc, vcpu);
+ svm_msr_guest_enter(vcpu);
/* Update Guest RIP */
state->rip = rip;
@@ -2062,32 +2049,32 @@
if (vcpu_suspended(evinfo)) {
enable_gintr();
- vm_exit_suspended(vm, vcpuid, state->rip);
+ vm_exit_suspended(vcpu->vcpu, state->rip);
break;
}
if (vcpu_rendezvous_pending(evinfo)) {
enable_gintr();
- vm_exit_rendezvous(vm, vcpuid, state->rip);
+ vm_exit_rendezvous(vcpu->vcpu, state->rip);
break;
}
if (vcpu_reqidle(evinfo)) {
enable_gintr();
- vm_exit_reqidle(vm, vcpuid, state->rip);
+ vm_exit_reqidle(vcpu->vcpu, state->rip);
break;
}
/* We are asked to give the cpu by scheduler. */
- if (vcpu_should_yield(vm, vcpuid)) {
+ if (vcpu_should_yield(vcpu->vcpu)) {
enable_gintr();
- vm_exit_astpending(vm, vcpuid, state->rip);
+ vm_exit_astpending(vcpu->vcpu, state->rip);
break;
}
- if (vcpu_debugged(vm, vcpuid)) {
+ if (vcpu_debugged(vcpu->vcpu)) {
enable_gintr();
- vm_exit_debug(vm, vcpuid, state->rip);
+ vm_exit_debug(vcpu->vcpu, state->rip);
break;
}
@@ -2140,7 +2127,7 @@
handled = svm_vmexit(svm_sc, vcpu, vmexit);
} while (handled);
- svm_msr_guest_exit(svm_sc, vcpu);
+ svm_msr_guest_exit(vcpu);
return (0);
}
@@ -2446,7 +2433,7 @@
vcpu = vcpui;
err = 0;
- running = vcpu_is_running(vcpu->sc->vm, vcpu->vcpuid, &hostcpu);
+ running = vcpu_is_running(vcpu->vcpu, &hostcpu);
if (running && hostcpu != curcpu) {
printf("%s: %s%d is running", __func__, vm_name(vcpu->sc->vm),
vcpu->vcpuid);
@@ -2642,11 +2629,10 @@
svm_restore_tsc(void *vcpui, uint64_t offset)
{
struct svm_vcpu *vcpu = vcpui;
- int err;
- err = svm_set_tsc_offset(vcpu->sc, vcpu, offset);
+ svm_set_tsc_offset(vcpu, offset);
- return (err);
+ return (0);
}
#endif
diff --git a/sys/amd64/vmm/amd/svm_msr.h b/sys/amd64/vmm/amd/svm_msr.h
--- a/sys/amd64/vmm/amd/svm_msr.h
+++ b/sys/amd64/vmm/amd/svm_msr.h
@@ -36,12 +36,10 @@
void svm_msr_init(void);
void svm_msr_guest_init(struct svm_softc *sc, struct svm_vcpu *vcpu);
-void svm_msr_guest_enter(struct svm_softc *sc, struct svm_vcpu *vcpu);
-void svm_msr_guest_exit(struct svm_softc *sc, struct svm_vcpu *vcpu);
+void svm_msr_guest_enter(struct svm_vcpu *vcpu);
+void svm_msr_guest_exit(struct svm_vcpu *vcpu);
-int svm_wrmsr(struct svm_softc *sc, struct svm_vcpu *vcpu, u_int num,
- uint64_t val, bool *retu);
-int svm_rdmsr(struct svm_softc *sc, struct svm_vcpu *vcpu, u_int num,
- uint64_t *result, bool *retu);
+int svm_wrmsr(struct svm_vcpu *vcpu, u_int num, uint64_t val, bool *retu);
+int svm_rdmsr(struct svm_vcpu *vcpu, u_int num, uint64_t *result, bool *retu);
#endif /* _SVM_MSR_H_ */
diff --git a/sys/amd64/vmm/amd/svm_msr.c b/sys/amd64/vmm/amd/svm_msr.c
--- a/sys/amd64/vmm/amd/svm_msr.c
+++ b/sys/amd64/vmm/amd/svm_msr.c
@@ -86,7 +86,7 @@
}
void
-svm_msr_guest_enter(struct svm_softc *sc, struct svm_vcpu *vcpu)
+svm_msr_guest_enter(struct svm_vcpu *vcpu)
{
/*
* Save host MSRs (if any) and restore guest MSRs (if any).
@@ -94,7 +94,7 @@
}
void
-svm_msr_guest_exit(struct svm_softc *sc, struct svm_vcpu *vcpu)
+svm_msr_guest_exit(struct svm_vcpu *vcpu)
{
/*
* Save guest MSRs (if any) and restore host MSRs.
@@ -108,8 +108,7 @@
}
int
-svm_rdmsr(struct svm_softc *sc, struct svm_vcpu *vcpu, u_int num,
- uint64_t *result, bool *retu)
+svm_rdmsr(struct svm_vcpu *vcpu, u_int num, uint64_t *result, bool *retu)
{
int error = 0;
@@ -142,8 +141,7 @@
}
int
-svm_wrmsr(struct svm_softc *sc, struct svm_vcpu *vcpu, u_int num, uint64_t val,
- bool *retu)
+svm_wrmsr(struct svm_vcpu *vcpu, u_int num, uint64_t val, bool *retu)
{
int error = 0;
@@ -175,7 +173,7 @@
break;
#ifdef BHYVE_SNAPSHOT
case MSR_TSC:
- error = svm_set_tsc_offset(sc, vcpu, val - rdtsc());
+ svm_set_tsc_offset(vcpu, val - rdtsc());
break;
#endif
case MSR_EXTFEATURES:
diff --git a/sys/amd64/vmm/intel/vmx.h b/sys/amd64/vmm/intel/vmx.h
--- a/sys/amd64/vmm/intel/vmx.h
+++ b/sys/amd64/vmm/intel/vmx.h
@@ -176,8 +176,7 @@
u_long vmx_fix_cr0(u_long cr0);
u_long vmx_fix_cr4(u_long cr4);
-int vmx_set_tsc_offset(struct vmx *vmx, struct vmx_vcpu *vcpu,
- uint64_t offset);
+int vmx_set_tsc_offset(struct vmx_vcpu *vcpu, uint64_t offset);
extern char vmx_exit_guest[];
extern char vmx_exit_guest_flush_rsb[];
diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c
--- a/sys/amd64/vmm/intel/vmx.c
+++ b/sys/amd64/vmm/intel/vmx.c
@@ -1148,7 +1148,7 @@
error += vmwrite(VMCS_EPTP, vmx->eptp);
error += vmwrite(VMCS_PIN_BASED_CTLS, pinbased_ctls);
error += vmwrite(VMCS_PRI_PROC_BASED_CTLS, procbased_ctls);
- if (vcpu_trap_wbinvd(vmx->vm, vcpuid)) {
+ if (vcpu_trap_wbinvd(vcpu->vcpu)) {
KASSERT(cap_wbinvd_exit, ("WBINVD trap not available"));
procbased_ctls2 |= PROCBASED2_WBINVD_EXITING;
}
@@ -1168,7 +1168,7 @@
}
/* exception bitmap */
- if (vcpu_trace_exceptions(vmx->vm, vcpuid))
+ if (vcpu_trace_exceptions(vcpu->vcpu))
exc_bitmap = 0xffffffff;
else
exc_bitmap = 1 << IDT_MC;
@@ -1226,11 +1226,11 @@
}
static int
-vmx_handle_cpuid(struct vm *vm, int vcpu, struct vmxctx *vmxctx)
+vmx_handle_cpuid(struct vmx_vcpu *vcpu, struct vmxctx *vmxctx)
{
int handled;
- handled = x86_emulate_cpuid(vm, vcpu, (uint64_t *)&vmxctx->guest_rax,
+ handled = x86_emulate_cpuid(vcpu->vcpu, (uint64_t *)&vmxctx->guest_rax,
(uint64_t *)&vmxctx->guest_rbx, (uint64_t *)&vmxctx->guest_rcx,
(uint64_t *)&vmxctx->guest_rdx);
return (handled);
@@ -1395,7 +1395,7 @@
}
int
-vmx_set_tsc_offset(struct vmx *vmx, struct vmx_vcpu *vcpu, uint64_t offset)
+vmx_set_tsc_offset(struct vmx_vcpu *vcpu, uint64_t offset)
{
int error;
@@ -1408,7 +1408,7 @@
error = vmwrite(VMCS_TSC_OFFSET, offset);
#ifdef BHYVE_SNAPSHOT
if (error == 0)
- error = vm_set_tsc_offset(vmx->vm, vcpu->vcpuid, offset);
+ vm_set_tsc_offset(vcpu->vcpu, offset);
#endif
return (error);
}
@@ -1419,7 +1419,7 @@
VMCS_INTERRUPTIBILITY_MOVSS_BLOCKING)
static void
-vmx_inject_nmi(struct vmx *vmx, struct vmx_vcpu *vcpu)
+vmx_inject_nmi(struct vmx_vcpu *vcpu)
{
uint32_t gi __diagused, info;
@@ -1441,12 +1441,12 @@
VMX_CTR0(vcpu, "Injecting vNMI");
/* Clear the request */
- vm_nmi_clear(vmx->vm, vcpu->vcpuid);
+ vm_nmi_clear(vcpu->vcpu);
}
static void
-vmx_inject_interrupts(struct vmx *vmx, struct vmx_vcpu *vcpu,
- struct vlapic *vlapic, uint64_t guestrip)
+vmx_inject_interrupts(struct vmx_vcpu *vcpu, struct vlapic *vlapic,
+ uint64_t guestrip)
{
int vector, need_nmi_exiting, extint_pending;
uint64_t rflags, entryinfo;
@@ -1463,7 +1463,7 @@
}
}
- if (vm_entry_intinfo(vmx->vm, vcpu->vcpuid, &entryinfo)) {
+ if (vm_entry_intinfo(vcpu->vcpu, &entryinfo)) {
KASSERT((entryinfo & VMCS_INTR_VALID) != 0, ("%s: entry "
"intinfo is not valid: %#lx", __func__, entryinfo));
@@ -1488,7 +1488,7 @@
vmcs_write(VMCS_ENTRY_INTR_INFO, info);
}
- if (vm_nmi_pending(vmx->vm, vcpu->vcpuid)) {
+ if (vm_nmi_pending(vcpu->vcpu)) {
/*
* If there are no conditions blocking NMI injection then
* inject it directly here otherwise enable "NMI window
@@ -1505,7 +1505,7 @@
if ((gi & (HWINTR_BLOCKING | NMI_BLOCKING)) == 0) {
info = vmcs_read(VMCS_ENTRY_INTR_INFO);
if ((info & VMCS_INTR_VALID) == 0) {
- vmx_inject_nmi(vmx, vcpu);
+ vmx_inject_nmi(vcpu);
need_nmi_exiting = 0;
} else {
VMX_CTR1(vcpu, "Cannot inject NMI "
@@ -1520,7 +1520,7 @@
vmx_set_nmi_window_exiting(vcpu);
}
- extint_pending = vm_extint_pending(vmx->vm, vcpu->vcpuid);
+ extint_pending = vm_extint_pending(vcpu->vcpu);
if (!extint_pending && virtual_interrupt_delivery) {
vmx_inject_pir(vlapic);
@@ -1553,7 +1553,7 @@
("invalid vector %d from local APIC", vector));
} else {
/* Ask the legacy pic for a vector to inject */
- vatpic_pending_intr(vmx->vm, &vector);
+ vatpic_pending_intr(vcpu->vmx->vm, &vector);
/*
* From the Intel SDM, Volume 3, Section "Maskable
@@ -1603,8 +1603,8 @@
/* Update the Local APIC ISR */
vlapic_intr_accepted(vlapic, vector);
} else {
- vm_extint_clear(vmx->vm, vcpu->vcpuid);
- vatpic_intr_accepted(vmx->vm, vector);
+ vm_extint_clear(vcpu->vcpu);
+ vatpic_intr_accepted(vcpu->vmx->vm, vector);
/*
* After we accepted the current ExtINT the PIC may
@@ -2319,21 +2319,20 @@
}
static int
-emulate_wrmsr(struct vmx *vmx, struct vmx_vcpu *vcpu, u_int num, uint64_t val,
- bool *retu)
+emulate_wrmsr(struct vmx_vcpu *vcpu, u_int num, uint64_t val, bool *retu)
{
int error;
if (lapic_msr(num))
- error = lapic_wrmsr(vmx->vm, vcpu->vcpuid, num, val, retu);
+ error = lapic_wrmsr(vcpu->vcpu, num, val, retu);
else
- error = vmx_wrmsr(vmx, vcpu, num, val, retu);
+ error = vmx_wrmsr(vcpu, num, val, retu);
return (error);
}
static int
-emulate_rdmsr(struct vmx *vmx, struct vmx_vcpu *vcpu, u_int num, bool *retu)
+emulate_rdmsr(struct vmx_vcpu *vcpu, u_int num, bool *retu)
{
struct vmxctx *vmxctx;
uint64_t result;
@@ -2341,9 +2340,9 @@
int error;
if (lapic_msr(num))
- error = lapic_rdmsr(vmx->vm, vcpu->vcpuid, num, &result, retu);
+ error = lapic_rdmsr(vcpu->vcpu, num, &result, retu);
else
- error = vmx_rdmsr(vmx, vcpu, num, &result, retu);
+ error = vmx_rdmsr(vcpu, num, &result, retu);
if (error == 0) {
eax = result;
@@ -2415,7 +2414,7 @@
idtvec_err = vmcs_idt_vectoring_err();
exitintinfo |= (uint64_t)idtvec_err << 32;
}
- error = vm_exit_intinfo(vmx->vm, vcpuid, exitintinfo);
+ error = vm_exit_intinfo(vcpu->vcpu, exitintinfo);
KASSERT(error == 0, ("%s: vm_set_intinfo error %d",
__func__, error));
@@ -2515,7 +2514,7 @@
ecx = vmxctx->guest_rcx;
VMX_CTR1(vcpu, "rdmsr 0x%08x", ecx);
SDT_PROBE4(vmm, vmx, exit, rdmsr, vmx, vcpuid, vmexit, ecx);
- error = emulate_rdmsr(vmx, vcpu, ecx, &retu);
+ error = emulate_rdmsr(vcpu, ecx, &retu);
if (error) {
vmexit->exitcode = VM_EXITCODE_RDMSR;
vmexit->u.msr.code = ecx;
@@ -2537,8 +2536,8 @@
ecx, (uint64_t)edx << 32 | eax);
SDT_PROBE5(vmm, vmx, exit, wrmsr, vmx, vmexit, vcpuid, ecx,
(uint64_t)edx << 32 | eax);
- error = emulate_wrmsr(vmx, vcpu, ecx,
- (uint64_t)edx << 32 | eax, &retu);
+ error = emulate_wrmsr(vcpu, ecx, (uint64_t)edx << 32 | eax,
+ &retu);
if (error) {
vmexit->exitcode = VM_EXITCODE_WRMSR;
vmexit->u.msr.code = ecx;
@@ -2612,8 +2611,8 @@
case EXIT_REASON_NMI_WINDOW:
SDT_PROBE3(vmm, vmx, exit, nmiwindow, vmx, vcpuid, vmexit);
/* Exit to allow the pending virtual NMI to be injected */
- if (vm_nmi_pending(vmx->vm, vcpuid))
- vmx_inject_nmi(vmx, vcpu);
+ if (vm_nmi_pending(vcpu->vcpu))
+ vmx_inject_nmi(vcpu);
vmx_clear_nmi_window_exiting(vcpu);
vmm_stat_incr(vcpu->vcpu, VMEXIT_NMI_WINDOW, 1);
return (1);
@@ -2643,7 +2642,7 @@
case EXIT_REASON_CPUID:
vmm_stat_incr(vcpu->vcpu, VMEXIT_CPUID, 1);
SDT_PROBE3(vmm, vmx, exit, cpuid, vmx, vcpuid, vmexit);
- handled = vmx_handle_cpuid(vmx->vm, vcpuid, vmxctx);
+ handled = vmx_handle_cpuid(vcpu, vmxctx);
break;
case EXIT_REASON_EXCEPTION:
vmm_stat_incr(vcpu->vcpu, VMEXIT_EXCEPTION, 1);
@@ -2734,7 +2733,7 @@
* this must be an instruction that accesses MMIO space.
*/
gpa = vmcs_gpa();
- if (vm_mem_allocated(vmx->vm, vcpuid, gpa) ||
+ if (vm_mem_allocated(vcpu->vcpu, gpa) ||
apic_access_fault(vcpu, gpa)) {
vmexit->exitcode = VM_EXITCODE_PAGING;
vmexit->inst_length = 0;
@@ -3012,10 +3011,9 @@
static int
vmx_run(void *vcpui, register_t rip, pmap_t pmap, struct vm_eventinfo *evinfo)
{
- int rc, handled, launched, vcpuid;
+ int rc, handled, launched;
struct vmx *vmx;
struct vmx_vcpu *vcpu;
- struct vm *vm;
struct vmxctx *vmxctx;
struct vmcs *vmcs;
struct vm_exit *vmexit;
@@ -3026,18 +3024,16 @@
vcpu = vcpui;
vmx = vcpu->vmx;
- vm = vmx->vm;
- vcpuid = vcpu->vcpuid;
vmcs = vcpu->vmcs;
vmxctx = &vcpu->ctx;
vlapic = vm_lapic(vcpu->vcpu);
- vmexit = vm_exitinfo(vm, vcpuid);
+ vmexit = vm_exitinfo(vcpu->vcpu);
launched = 0;
KASSERT(vmxctx->pmap == pmap,
("pmap %p different than ctx pmap %p", pmap, vmxctx->pmap));
- vmx_msr_guest_enter(vmx, vcpu);
+ vmx_msr_guest_enter(vcpu);
VMPTRLD(vmcs);
@@ -3077,7 +3073,7 @@
* pmap_invalidate_ept().
*/
disable_intr();
- vmx_inject_interrupts(vmx, vcpu, vlapic, rip);
+ vmx_inject_interrupts(vcpu, vlapic, rip);
/*
* Check for vcpu suspension after injecting events because
@@ -3086,33 +3082,33 @@
*/
if (vcpu_suspended(evinfo)) {
enable_intr();
- vm_exit_suspended(vmx->vm, vcpuid, rip);
+ vm_exit_suspended(vcpu->vcpu, rip);
break;
}
if (vcpu_rendezvous_pending(evinfo)) {
enable_intr();
- vm_exit_rendezvous(vmx->vm, vcpuid, rip);
+ vm_exit_rendezvous(vcpu->vcpu, rip);
break;
}
if (vcpu_reqidle(evinfo)) {
enable_intr();
- vm_exit_reqidle(vmx->vm, vcpuid, rip);
+ vm_exit_reqidle(vcpu->vcpu, rip);
break;
}
- if (vcpu_should_yield(vm, vcpuid)) {
+ if (vcpu_should_yield(vcpu->vcpu)) {
enable_intr();
- vm_exit_astpending(vmx->vm, vcpuid, rip);
+ vm_exit_astpending(vcpu->vcpu, rip);
vmx_astpending_trace(vcpu, rip);
handled = HANDLED;
break;
}
- if (vcpu_debugged(vm, vcpuid)) {
+ if (vcpu_debugged(vcpu->vcpu)) {
enable_intr();
- vm_exit_debug(vmx->vm, vcpuid, rip);
+ vm_exit_debug(vcpu->vcpu, rip);
break;
}
@@ -3214,7 +3210,7 @@
vmexit->exitcode);
VMCLEAR(vmcs);
- vmx_msr_guest_exit(vmx, vcpu);
+ vmx_msr_guest_exit(vcpu);
return (0);
}
@@ -3390,7 +3386,7 @@
struct vmx_vcpu *vcpu = vcpui;
struct vmx *vmx = vcpu->vmx;
- running = vcpu_is_running(vmx->vm, vcpu->vcpuid, &hostcpu);
+ running = vcpu_is_running(vcpu->vcpu, &hostcpu);
if (running && hostcpu != curcpu)
panic("vmx_getreg: %s%d is running", vm_name(vmx->vm),
vcpu->vcpuid);
@@ -3413,7 +3409,7 @@
struct vmx_vcpu *vcpu = vcpui;
struct vmx *vmx = vcpu->vmx;
- running = vcpu_is_running(vmx->vm, vcpu->vcpuid, &hostcpu);
+ running = vcpu_is_running(vcpu->vcpu, &hostcpu);
if (running && hostcpu != curcpu)
panic("vmx_setreg: %s%d is running", vm_name(vmx->vm),
vcpu->vcpuid);
@@ -3480,7 +3476,7 @@
struct vmx_vcpu *vcpu = vcpui;
struct vmx *vmx = vcpu->vmx;
- running = vcpu_is_running(vmx->vm, vcpu->vcpuid, &hostcpu);
+ running = vcpu_is_running(vcpu->vcpu, &hostcpu);
if (running && hostcpu != curcpu)
panic("vmx_getdesc: %s%d is running", vm_name(vmx->vm),
vcpu->vcpuid);
@@ -3495,7 +3491,7 @@
struct vmx_vcpu *vcpu = vcpui;
struct vmx *vmx = vcpu->vmx;
- running = vcpu_is_running(vmx->vm, vcpu->vcpuid, &hostcpu);
+ running = vcpu_is_running(vcpu->vcpu, &hostcpu);
if (running && hostcpu != curcpu)
panic("vmx_setdesc: %s%d is running", vm_name(vmx->vm),
vcpu->vcpuid);
@@ -3806,7 +3802,7 @@
struct vm_exit *vmexit;
uint8_t rvi, ppr;
- vmexit = vm_exitinfo(vlapic->vm, vlapic->vcpuid);
+ vmexit = vm_exitinfo(vlapic->vcpu);
KASSERT(vmexit->exitcode == VM_EXITCODE_HLT,
("vmx_pending_intr: exitcode not 'HLT'"));
rvi = vmexit->u.hlt.intr_status & APIC_TPR_INT;
@@ -3875,7 +3871,7 @@
uint64_t mask, val;
KASSERT(vector >= 0 && vector <= 255, ("invalid vector %d", vector));
- KASSERT(!vcpu_is_running(vlapic->vm, vlapic->vcpuid, NULL),
+ KASSERT(!vcpu_is_running(vlapic->vcpu, NULL),
("vmx_set_tmr: vcpu cannot be running"));
vlapic_vtx = (struct vlapic_vtx *)vlapic;
@@ -4132,7 +4128,7 @@
vmx = vcpu->vmx;
vmcs = vcpu->vmcs;
- run = vcpu_is_running(vmx->vm, vcpu->vcpuid, &hostcpu);
+ run = vcpu_is_running(vcpu->vcpu, &hostcpu);
if (run && hostcpu != curcpu) {
printf("%s: %s%d is running", __func__, vm_name(vmx->vm),
vcpu->vcpuid);
@@ -4235,7 +4231,7 @@
vmx = vcpu->vmx;
vmcs = vcpu->vmcs;
- running = vcpu_is_running(vmx->vm, vcpu->vcpuid, &hostcpu);
+ running = vcpu_is_running(vcpu->vcpu, &hostcpu);
if (running && hostcpu != curcpu) {
printf("%s: %s%d is running", __func__, vm_name(vmx->vm),
vcpu->vcpuid);
@@ -4245,7 +4241,7 @@
if (!running)
VMPTRLD(vmcs);
- error = vmx_set_tsc_offset(vmx, vcpu, offset);
+ error = vmx_set_tsc_offset(vcpu, offset);
if (!running)
VMCLEAR(vmcs);
diff --git a/sys/amd64/vmm/intel/vmx_msr.h b/sys/amd64/vmm/intel/vmx_msr.h
--- a/sys/amd64/vmm/intel/vmx_msr.h
+++ b/sys/amd64/vmm/intel/vmx_msr.h
@@ -36,13 +36,11 @@
void vmx_msr_init(void);
void vmx_msr_guest_init(struct vmx *vmx, struct vmx_vcpu *vcpu);
void vmx_msr_guest_enter_tsc_aux(struct vmx *vmx, struct vmx_vcpu *vcpu);
-void vmx_msr_guest_enter(struct vmx *vmx, struct vmx_vcpu *vcpu);
-void vmx_msr_guest_exit(struct vmx *vmx, struct vmx_vcpu *vcpu);
+void vmx_msr_guest_enter(struct vmx_vcpu *vcpu);
+void vmx_msr_guest_exit(struct vmx_vcpu *vcpu);
void vmx_msr_guest_exit_tsc_aux(struct vmx *vmx, struct vmx_vcpu *vcpu);
-int vmx_rdmsr(struct vmx *, struct vmx_vcpu *vcpu, u_int num, uint64_t *val,
- bool *retu);
-int vmx_wrmsr(struct vmx *, struct vmx_vcpu *vcpu, u_int num, uint64_t val,
- bool *retu);
+int vmx_rdmsr(struct vmx_vcpu *vcpu, u_int num, uint64_t *val, bool *retu);
+int vmx_wrmsr(struct vmx_vcpu *vcpu, u_int num, uint64_t val, bool *retu);
uint32_t vmx_revision(void);
diff --git a/sys/amd64/vmm/intel/vmx_msr.c b/sys/amd64/vmm/intel/vmx_msr.c
--- a/sys/amd64/vmm/intel/vmx_msr.c
+++ b/sys/amd64/vmm/intel/vmx_msr.c
@@ -344,7 +344,7 @@
}
void
-vmx_msr_guest_enter(struct vmx *vmx, struct vmx_vcpu *vcpu)
+vmx_msr_guest_enter(struct vmx_vcpu *vcpu)
{
/* Save host MSRs (in particular, KGSBASE) and restore guest MSRs */
@@ -367,7 +367,7 @@
}
void
-vmx_msr_guest_exit(struct vmx *vmx, struct vmx_vcpu *vcpu)
+vmx_msr_guest_exit(struct vmx_vcpu *vcpu)
{
/* Save guest MSRs */
@@ -404,8 +404,7 @@
}
int
-vmx_rdmsr(struct vmx *vmx, struct vmx_vcpu *vcpu, u_int num, uint64_t *val,
- bool *retu)
+vmx_rdmsr(struct vmx_vcpu *vcpu, u_int num, uint64_t *val, bool *retu)
{
int error;
@@ -447,8 +446,7 @@
}
int
-vmx_wrmsr(struct vmx *vmx, struct vmx_vcpu *vcpu, u_int num, uint64_t val,
- bool *retu)
+vmx_wrmsr(struct vmx_vcpu *vcpu, u_int num, uint64_t val, bool *retu)
{
uint64_t changed;
int error;
@@ -496,7 +494,7 @@
vm_inject_gp(vcpu->vcpu);
break;
case MSR_TSC:
- error = vmx_set_tsc_offset(vmx, vcpu, val - rdtsc());
+ error = vmx_set_tsc_offset(vcpu, val - rdtsc());
break;
case MSR_TSC_AUX:
if (vmx_have_msr_tsc_aux)
diff --git a/sys/amd64/vmm/io/vlapic.c b/sys/amd64/vmm/io/vlapic.c
--- a/sys/amd64/vmm/io/vlapic.c
+++ b/sys/amd64/vmm/io/vlapic.c
@@ -1160,7 +1160,7 @@
break;
vlapic2->boot_state = BS_RUNNING;
- vmexit = vm_exitinfo(vlapic->vm, vlapic->vcpuid);
+ vmexit = vm_exitinfo(vlapic->vcpu);
vmexit->exitcode = VM_EXITCODE_SPINUP_AP;
vmexit->u.spinup_ap.vcpu = i;
vmexit->u.spinup_ap.rip = vec << PAGE_SHIFT;
@@ -1187,7 +1187,7 @@
}
if (!CPU_EMPTY(&ipimask)) {
- vmexit = vm_exitinfo(vlapic->vm, vlapic->vcpuid);
+ vmexit = vm_exitinfo(vlapic->vcpu);
vmexit->exitcode = VM_EXITCODE_IPI;
vmexit->u.ipi.mode = mode;
vmexit->u.ipi.vector = vec;
diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c
--- a/sys/amd64/vmm/vmm.c
+++ b/sys/amd64/vmm/vmm.c
@@ -366,28 +366,21 @@
}
int
-vcpu_trace_exceptions(struct vm *vm, int vcpuid)
+vcpu_trace_exceptions(struct vcpu *vcpu)
{
return (trace_guest_exceptions);
}
int
-vcpu_trap_wbinvd(struct vm *vm, int vcpuid)
+vcpu_trap_wbinvd(struct vcpu *vcpu)
{
return (trap_wbinvd);
}
struct vm_exit *
-vm_exitinfo(struct vm *vm, int cpuid)
+vm_exitinfo(struct vcpu *vcpu)
{
- struct vcpu *vcpu;
-
- if (cpuid < 0 || cpuid >= vm->maxcpus)
- panic("vm_exitinfo: invalid cpuid %d", cpuid);
-
- vcpu = &vm->vcpu[cpuid];
-
return (&vcpu->exitinfo);
}
@@ -680,14 +673,15 @@
* an implicit lock on 'vm->mem_maps[]'.
*/
bool
-vm_mem_allocated(struct vm *vm, int vcpuid, vm_paddr_t gpa)
+vm_mem_allocated(struct vcpu *vcpu, vm_paddr_t gpa)
{
+ struct vm *vm = vcpu->vm;
struct mem_map *mm;
int i;
#ifdef INVARIANTS
int hostcpu, state;
- state = vcpu_get_state(vm_vcpu(vm, vcpuid), &hostcpu);
+ state = vcpu_get_state(vcpu, &hostcpu);
KASSERT(state == VCPU_RUNNING && hostcpu == curcpu,
("%s: invalid vcpu state %d/%d", __func__, state, hostcpu));
#endif
@@ -1410,20 +1404,20 @@
*/
if (vm->rendezvous_func != NULL || vm->suspend || vcpu->reqidle)
break;
- if (vm_nmi_pending(vm, vcpuid))
+ if (vm_nmi_pending(vcpu))
break;
if (!intr_disabled) {
- if (vm_extint_pending(vm, vcpuid) ||
+ if (vm_extint_pending(vcpu) ||
vlapic_pending_intr(vcpu->vlapic, NULL)) {
break;
}
}
/* Don't go to sleep if the vcpu thread needs to yield */
- if (vcpu_should_yield(vm, vcpuid))
+ if (vcpu_should_yield(vcpu))
break;
- if (vcpu_debugged(vm, vcpuid))
+ if (vcpu_debugged(vcpu))
break;
/*
@@ -1701,14 +1695,15 @@
}
void
-vm_exit_suspended(struct vm *vm, int vcpuid, uint64_t rip)
+vm_exit_suspended(struct vcpu *vcpu, uint64_t rip)
{
+ struct vm *vm = vcpu->vm;
struct vm_exit *vmexit;
KASSERT(vm->suspend > VM_SUSPEND_NONE && vm->suspend < VM_SUSPEND_LAST,
("vm_exit_suspended: invalid suspend type %d", vm->suspend));
- vmexit = vm_exitinfo(vm, vcpuid);
+ vmexit = vm_exitinfo(vcpu);
vmexit->rip = rip;
vmexit->inst_length = 0;
vmexit->exitcode = VM_EXITCODE_SUSPENDED;
@@ -1716,52 +1711,53 @@
}
void
-vm_exit_debug(struct vm *vm, int vcpuid, uint64_t rip)
+vm_exit_debug(struct vcpu *vcpu, uint64_t rip)
{
struct vm_exit *vmexit;
- vmexit = vm_exitinfo(vm, vcpuid);
+ vmexit = vm_exitinfo(vcpu);
vmexit->rip = rip;
vmexit->inst_length = 0;
vmexit->exitcode = VM_EXITCODE_DEBUG;
}
void
-vm_exit_rendezvous(struct vm *vm, int vcpuid, uint64_t rip)
+vm_exit_rendezvous(struct vcpu *vcpu, uint64_t rip)
{
struct vm_exit *vmexit;
- KASSERT(vm->rendezvous_func != NULL, ("rendezvous not in progress"));
+ KASSERT(vcpu->vm->rendezvous_func != NULL,
+ ("rendezvous not in progress"));
- vmexit = vm_exitinfo(vm, vcpuid);
+ vmexit = vm_exitinfo(vcpu);
vmexit->rip = rip;
vmexit->inst_length = 0;
vmexit->exitcode = VM_EXITCODE_RENDEZVOUS;
- vmm_stat_incr(vm_vcpu(vm, vcpuid), VMEXIT_RENDEZVOUS, 1);
+ vmm_stat_incr(vcpu, VMEXIT_RENDEZVOUS, 1);
}
void
-vm_exit_reqidle(struct vm *vm, int vcpuid, uint64_t rip)
+vm_exit_reqidle(struct vcpu *vcpu, uint64_t rip)
{
struct vm_exit *vmexit;
- vmexit = vm_exitinfo(vm, vcpuid);
+ vmexit = vm_exitinfo(vcpu);
vmexit->rip = rip;
vmexit->inst_length = 0;
vmexit->exitcode = VM_EXITCODE_REQIDLE;
- vmm_stat_incr(vm_vcpu(vm, vcpuid), VMEXIT_REQIDLE, 1);
+ vmm_stat_incr(vcpu, VMEXIT_REQIDLE, 1);
}
void
-vm_exit_astpending(struct vm *vm, int vcpuid, uint64_t rip)
+vm_exit_astpending(struct vcpu *vcpu, uint64_t rip)
{
struct vm_exit *vmexit;
- vmexit = vm_exitinfo(vm, vcpuid);
+ vmexit = vm_exitinfo(vcpu);
vmexit->rip = rip;
vmexit->inst_length = 0;
vmexit->exitcode = VM_EXITCODE_BOGUS;
- vmm_stat_incr(vm_vcpu(vm, vcpuid), VMEXIT_ASTPENDING, 1);
+ vmm_stat_incr(vcpu, VMEXIT_ASTPENDING, 1);
}
int
@@ -1915,16 +1911,10 @@
}
int
-vm_exit_intinfo(struct vm *vm, int vcpuid, uint64_t info)
+vm_exit_intinfo(struct vcpu *vcpu, uint64_t info)
{
- struct vcpu *vcpu;
int type, vector;
- if (vcpuid < 0 || vcpuid >= vm->maxcpus)
- return (EINVAL);
-
- vcpu = &vm->vcpu[vcpuid];
-
if (info & VM_INTINFO_VALID) {
type = info & VM_INTINFO_TYPE;
vector = info & 0xff;
@@ -1937,7 +1927,7 @@
} else {
info = 0;
}
- VCPU_CTR2(vm, vcpuid, "%s: info1(%#lx)", __func__, info);
+ VMM_CTR2(vcpu, "%s: info1(%#lx)", __func__, info);
vcpu->exitintinfo = info;
return (0);
}
@@ -1997,7 +1987,7 @@
}
static int
-nested_fault(struct vm *vm, int vcpuid, uint64_t info1, uint64_t info2,
+nested_fault(struct vcpu *vcpu, uint64_t info1, uint64_t info2,
uint64_t *retinfo)
{
enum exc_class exc1, exc2;
@@ -2013,9 +2003,9 @@
type1 = info1 & VM_INTINFO_TYPE;
vector1 = info1 & 0xff;
if (type1 == VM_INTINFO_HWEXCEPTION && vector1 == IDT_DF) {
- VCPU_CTR2(vm, vcpuid, "triple fault: info1(%#lx), info2(%#lx)",
+ VMM_CTR2(vcpu, "triple fault: info1(%#lx), info2(%#lx)",
info1, info2);
- vm_suspend(vm, VM_SUSPEND_TRIPLEFAULT);
+ vm_suspend(vcpu->vm, VM_SUSPEND_TRIPLEFAULT);
*retinfo = 0;
return (0);
}
@@ -2055,17 +2045,11 @@
}
int
-vm_entry_intinfo(struct vm *vm, int vcpuid, uint64_t *retinfo)
+vm_entry_intinfo(struct vcpu *vcpu, uint64_t *retinfo)
{
- struct vcpu *vcpu;
uint64_t info1, info2;
int valid;
- KASSERT(vcpuid >= 0 &&
- vcpuid < vm->maxcpus, ("invalid vcpu %d", vcpuid));
-
- vcpu = &vm->vcpu[vcpuid];
-
info1 = vcpu->exitintinfo;
vcpu->exitintinfo = 0;
@@ -2073,12 +2057,12 @@
if (vcpu->exception_pending) {
info2 = vcpu_exception_intinfo(vcpu);
vcpu->exception_pending = 0;
- VCPU_CTR2(vm, vcpuid, "Exception %d delivered: %#lx",
+ VMM_CTR2(vcpu, "Exception %d delivered: %#lx",
vcpu->exc_vector, info2);
}
if ((info1 & VM_INTINFO_VALID) && (info2 & VM_INTINFO_VALID)) {
- valid = nested_fault(vm, vcpuid, info1, info2, retinfo);
+ valid = nested_fault(vcpu, info1, info2, retinfo);
} else if (info1 & VM_INTINFO_VALID) {
*retinfo = info1;
valid = 1;
@@ -2210,28 +2194,14 @@
}
int
-vm_nmi_pending(struct vm *vm, int vcpuid)
+vm_nmi_pending(struct vcpu *vcpu)
{
- struct vcpu *vcpu;
-
- if (vcpuid < 0 || vcpuid >= vm->maxcpus)
- panic("vm_nmi_pending: invalid vcpuid %d", vcpuid);
-
- vcpu = &vm->vcpu[vcpuid];
-
return (vcpu->nmi_pending);
}
void
-vm_nmi_clear(struct vm *vm, int vcpuid)
+vm_nmi_clear(struct vcpu *vcpu)
{
- struct vcpu *vcpu;
-
- if (vcpuid < 0 || vcpuid >= vm->maxcpus)
- panic("vm_nmi_pending: invalid vcpuid %d", vcpuid);
-
- vcpu = &vm->vcpu[vcpuid];
-
if (vcpu->nmi_pending == 0)
panic("vm_nmi_clear: inconsistent nmi_pending state");
@@ -2257,28 +2227,14 @@
}
int
-vm_extint_pending(struct vm *vm, int vcpuid)
+vm_extint_pending(struct vcpu *vcpu)
{
- struct vcpu *vcpu;
-
- if (vcpuid < 0 || vcpuid >= vm->maxcpus)
- panic("vm_extint_pending: invalid vcpuid %d", vcpuid);
-
- vcpu = &vm->vcpu[vcpuid];
-
return (vcpu->extint_pending);
}
void
-vm_extint_clear(struct vm *vm, int vcpuid)
+vm_extint_clear(struct vcpu *vcpu)
{
- struct vcpu *vcpu;
-
- if (vcpuid < 0 || vcpuid >= vm->maxcpus)
- panic("vm_extint_pending: invalid vcpuid %d", vcpuid);
-
- vcpu = &vm->vcpu[vcpuid];
-
if (vcpu->extint_pending == 0)
panic("vm_extint_clear: inconsistent extint_pending state");
@@ -2488,10 +2444,10 @@
}
int
-vcpu_debugged(struct vm *vm, int vcpuid)
+vcpu_debugged(struct vcpu *vcpu)
{
- return (CPU_ISSET(vcpuid, &vm->debug_cpus));
+ return (CPU_ISSET(vcpu->vcpuid, &vcpu->vm->debug_cpus));
}
cpuset_t
@@ -2951,18 +2907,10 @@
return (ret);
}
-int
-vm_set_tsc_offset(struct vm *vm, int vcpuid, uint64_t offset)
+void
+vm_set_tsc_offset(struct vcpu *vcpu, uint64_t offset)
{
- struct vcpu *vcpu;
-
- if (vcpuid < 0 || vcpuid >= vm_get_maxcpus(vm))
- return (EINVAL);
-
- vcpu = &vm->vcpu[vcpuid];
vcpu->tsc_offset = offset;
-
- return (0);
}
int
diff --git a/sys/amd64/vmm/vmm_dev.c b/sys/amd64/vmm/vmm_dev.c
--- a/sys/amd64/vmm/vmm_dev.c
+++ b/sys/amd64/vmm/vmm_dev.c
@@ -857,7 +857,7 @@
break;
case VM_SET_INTINFO:
vmii = (struct vm_intinfo *)data;
- error = vm_exit_intinfo(sc->vm, vmii->vcpuid, vmii->info1);
+ error = vm_exit_intinfo(vcpu, vmii->info1);
break;
case VM_GET_INTINFO:
vmii = (struct vm_intinfo *)data;
diff --git a/sys/amd64/vmm/vmm_lapic.h b/sys/amd64/vmm/vmm_lapic.h
--- a/sys/amd64/vmm/vmm_lapic.h
+++ b/sys/amd64/vmm/vmm_lapic.h
@@ -31,13 +31,12 @@
#ifndef _VMM_LAPIC_H_
#define _VMM_LAPIC_H_
+struct vcpu;
struct vm;
bool lapic_msr(u_int num);
-int lapic_rdmsr(struct vm *vm, int cpu, u_int msr, uint64_t *rval,
- bool *retu);
-int lapic_wrmsr(struct vm *vm, int cpu, u_int msr, uint64_t wval,
- bool *retu);
+int lapic_rdmsr(struct vcpu *vcpu, u_int msr, uint64_t *rval, bool *retu);
+int lapic_wrmsr(struct vcpu *vcpu, u_int msr, uint64_t wval, bool *retu);
int lapic_mmio_read(struct vcpu *vcpu, uint64_t gpa,
uint64_t *rval, int size, void *arg);
diff --git a/sys/amd64/vmm/vmm_lapic.c b/sys/amd64/vmm/vmm_lapic.c
--- a/sys/amd64/vmm/vmm_lapic.c
+++ b/sys/amd64/vmm/vmm_lapic.c
@@ -156,13 +156,13 @@
}
int
-lapic_rdmsr(struct vm *vm, int cpu, u_int msr, uint64_t *rval, bool *retu)
+lapic_rdmsr(struct vcpu *vcpu, u_int msr, uint64_t *rval, bool *retu)
{
int error;
u_int offset;
struct vlapic *vlapic;
- vlapic = vm_lapic(vm_vcpu(vm, cpu));
+ vlapic = vm_lapic(vcpu);
if (msr == MSR_APICBASE) {
*rval = vlapic_get_apicbase(vlapic);
@@ -176,13 +176,13 @@
}
int
-lapic_wrmsr(struct vm *vm, int cpu, u_int msr, uint64_t val, bool *retu)
+lapic_wrmsr(struct vcpu *vcpu, u_int msr, uint64_t val, bool *retu)
{
int error;
u_int offset;
struct vlapic *vlapic;
- vlapic = vm_lapic(vm_vcpu(vm, cpu));
+ vlapic = vm_lapic(vcpu);
if (msr == MSR_APICBASE) {
error = vlapic_set_apicbase(vlapic, val);
diff --git a/sys/amd64/vmm/x86.h b/sys/amd64/vmm/x86.h
--- a/sys/amd64/vmm/x86.h
+++ b/sys/amd64/vmm/x86.h
@@ -66,7 +66,7 @@
*/
#define CPUID_0000_0001_FEAT0_VMX (1<<5)
-int x86_emulate_cpuid(struct vm *vm, int vcpu_id, uint64_t *rax, uint64_t *rbx,
+int x86_emulate_cpuid(struct vcpu *vcpu, uint64_t *rax, uint64_t *rbx,
uint64_t *rcx, uint64_t *rdx);
enum vm_cpuid_capability {
@@ -81,7 +81,7 @@
* Return 'true' if the capability 'cap' is enabled in this virtual cpu
* and 'false' otherwise.
*/
-bool vm_cpuid_capability(struct vm *vm, int vcpuid, enum vm_cpuid_capability);
+bool vm_cpuid_capability(struct vcpu *vcpu, enum vm_cpuid_capability);
#define VMM_MTRR_VAR_MAX 10
#define VMM_MTRR_DEF_MASK \
diff --git a/sys/amd64/vmm/x86.c b/sys/amd64/vmm/x86.c
--- a/sys/amd64/vmm/x86.c
+++ b/sys/amd64/vmm/x86.c
@@ -87,9 +87,11 @@
}
int
-x86_emulate_cpuid(struct vm *vm, int vcpu_id, uint64_t *rax, uint64_t *rbx,
+x86_emulate_cpuid(struct vcpu *vcpu, uint64_t *rax, uint64_t *rbx,
uint64_t *rcx, uint64_t *rdx)
{
+ struct vm *vm = vcpu_vm(vcpu);
+ int vcpu_id = vcpu_vcpuid(vcpu);
const struct xsave_limits *limits;
uint64_t cr4;
int error, enable_invpcid, enable_rdpid, enable_rdtscp, level,
@@ -349,7 +351,7 @@
*/
regs[2] &= ~CPUID2_OSXSAVE;
if (regs[2] & CPUID2_XSAVE) {
- error = vm_get_register(vm_vcpu(vm, vcpu_id),
+ error = vm_get_register(vcpu,
VM_REG_GUEST_CR4, &cr4);
if (error)
panic("x86_emulate_cpuid: error %d "
@@ -637,7 +639,7 @@
}
bool
-vm_cpuid_capability(struct vm *vm, int vcpuid, enum vm_cpuid_capability cap)
+vm_cpuid_capability(struct vcpu *vcpu, enum vm_cpuid_capability cap)
{
bool rv;

File Metadata

Mime Type
text/plain
Expires
Wed, Jan 8, 2:59 PM (36 m, 6 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15723489
Default Alt Text
D37162.diff (43 KB)

Event Timeline