diff options
| author | maxv <maxv@NetBSD.org> | 2019-02-21 11:58:04 +0000 |
|---|---|---|
| committer | maxv <maxv@NetBSD.org> | 2019-02-21 11:58:04 +0000 |
| commit | ca7ab3d3e4a48cf7cf3f9306cb842e1fbce788e5 (patch) | |
| tree | ccdf2b74a868a77970f3d94ddc136ba79cb9b835 /sys/dev | |
| parent | 8768529adba5573e5a55c8eac3417742c5e07931 (diff) | |
Clarify the gTLB code a little.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/nvmm/x86/nvmm_x86_svm.c | 34 | ||||
| -rw-r--r-- | sys/dev/nvmm/x86/nvmm_x86_vmx.c | 32 |
2 files changed, 41 insertions, 25 deletions
diff --git a/sys/dev/nvmm/x86/nvmm_x86_svm.c b/sys/dev/nvmm/x86/nvmm_x86_svm.c index ceda5fa6920..d11c186881f 100644 --- a/sys/dev/nvmm/x86/nvmm_x86_svm.c +++ b/sys/dev/nvmm/x86/nvmm_x86_svm.c @@ -1,4 +1,4 @@ -/* $NetBSD: nvmm_x86_svm.c,v 1.27 2019/02/18 12:17:45 maxv Exp $ */ +/* $NetBSD: nvmm_x86_svm.c,v 1.28 2019/02/21 11:58:04 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.27 2019/02/18 12:17:45 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.28 2019/02/21 11:58:04 maxv Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -502,7 +502,7 @@ static const size_t svm_conf_sizes[NVMM_X86_NCONF] = { struct svm_cpudata { /* General */ bool shared_asid; - bool tlb_want_flush; + bool gtlb_want_flush; /* VMCB */ struct vmcb *vmcb; @@ -977,7 +977,7 @@ svm_inkernel_handle_msr(struct nvmm_machine *mach, struct nvmm_cpu *vcpu, } if ((vmcb->state.efer ^ exit->u.msr.val) & EFER_TLB_FLUSH) { - cpudata->tlb_want_flush = true; + cpudata->gtlb_want_flush = true; } vmcb->state.efer = exit->u.msr.val | EFER_SVME; svm_vmcb_cache_flush(vmcb, VMCB_CTRL_VMCB_CLEAN_CR); @@ -1185,21 +1185,30 @@ svm_vcpu_guest_misc_leave(struct nvmm_cpu *vcpu) wrmsr(MSR_KERNELGSBASE, cpudata->kernelgsbase); } +/* -------------------------------------------------------------------------- */ + +static inline void +svm_gtlb_catchup(struct nvmm_cpu *vcpu, int hcpu) +{ + struct svm_cpudata *cpudata = vcpu->cpudata; + + if (vcpu->hcpu_last != hcpu || cpudata->shared_asid) { + cpudata->gtlb_want_flush = true; + } +} + static int svm_vcpu_run(struct nvmm_machine *mach, struct nvmm_cpu *vcpu, struct nvmm_exit *exit) { struct svm_cpudata *cpudata = vcpu->cpudata; struct vmcb *vmcb = cpudata->vmcb; - bool tlb_need_flush = false; int hcpu, s; kpreempt_disable(); hcpu = cpu_number(); - if (vcpu->hcpu_last != hcpu || cpudata->shared_asid) { - tlb_need_flush = true; - } + svm_gtlb_catchup(vcpu, hcpu); if (vcpu->hcpu_last != hcpu) { vmcb->ctrl.tsc_offset = cpudata->tsc_offset + @@ -1211,7 +1220,7 @@ svm_vcpu_run(struct nvmm_machine *mach, struct nvmm_cpu *vcpu, svm_vcpu_guest_misc_enter(vcpu); while (1) { - if (cpudata->tlb_want_flush || tlb_need_flush) { + if (cpudata->gtlb_want_flush) { vmcb->ctrl.tlb_ctrl = svm_ctrl_tlb_flush; } else { vmcb->ctrl.tlb_ctrl = 0; @@ -1226,8 +1235,7 @@ svm_vcpu_run(struct nvmm_machine *mach, struct nvmm_cpu *vcpu, svm_vmcb_cache_default(vmcb); if (vmcb->ctrl.exitcode != VMCB_EXITCODE_INVALID) { - cpudata->tlb_want_flush = false; - tlb_need_flush = false; + cpudata->gtlb_want_flush = false; vcpu->hcpu_last = hcpu; } @@ -1751,7 +1759,7 @@ svm_vcpu_setstate(struct nvmm_cpu *vcpu, void *data, uint64_t flags) struct fxsave *fpustate; if (svm_state_tlb_flush(vmcb, state, flags)) { - cpudata->tlb_want_flush = true; + cpudata->gtlb_want_flush = true; } if (flags & NVMM_X64_STATE_SEGS) { @@ -1985,7 +1993,7 @@ svm_tlb_flush(struct pmap *pm) if (error) continue; cpudata = vcpu->cpudata; - cpudata->tlb_want_flush = true; + cpudata->gtlb_want_flush = true; nvmm_vcpu_put(vcpu); } } diff --git a/sys/dev/nvmm/x86/nvmm_x86_vmx.c b/sys/dev/nvmm/x86/nvmm_x86_vmx.c index bb6d21794f1..876584e1f64 100644 --- a/sys/dev/nvmm/x86/nvmm_x86_vmx.c +++ b/sys/dev/nvmm/x86/nvmm_x86_vmx.c @@ -1,4 +1,4 @@ -/* $NetBSD: nvmm_x86_vmx.c,v 1.7 2019/02/18 12:17:45 maxv Exp $ */ +/* $NetBSD: nvmm_x86_vmx.c,v 1.8 2019/02/21 11:58:04 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.7 2019/02/18 12:17:45 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.8 2019/02/21 11:58:04 maxv Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -637,7 +637,7 @@ static const size_t vmx_conf_sizes[NVMM_X86_NCONF] = { struct vmx_cpudata { /* General */ uint64_t asid; - bool tlb_want_flush; + bool gtlb_want_flush; /* VMCS */ struct vmcs *vmcs; @@ -1601,6 +1601,8 @@ vmx_vcpu_guest_misc_leave(struct nvmm_cpu *vcpu) wrmsr(MSR_KERNELGSBASE, cpudata->kernelgsbase); } +/* --------------------------------------------------------------------- */ + #define VMX_INVVPID_ADDRESS 0 #define VMX_INVVPID_CONTEXT 1 #define VMX_INVVPID_ALL 2 @@ -1609,13 +1611,22 @@ vmx_vcpu_guest_misc_leave(struct nvmm_cpu *vcpu) #define VMX_INVEPT_CONTEXT 1 #define VMX_INVEPT_ALL 2 +static inline void +vmx_gtlb_catchup(struct nvmm_cpu *vcpu, int hcpu) +{ + struct vmx_cpudata *cpudata = vcpu->cpudata; + + if (vcpu->hcpu_last != hcpu) { + cpudata->gtlb_want_flush = true; + } +} + static int vmx_vcpu_run(struct nvmm_machine *mach, struct nvmm_cpu *vcpu, struct nvmm_exit *exit) { struct vmx_machdata *machdata = mach->machdata; struct vmx_cpudata *cpudata = vcpu->cpudata; - bool tlb_need_flush = false; struct vpid_desc vpid_desc; struct ept_desc ept_desc; struct cpu_info *ci; @@ -1628,6 +1639,8 @@ vmx_vcpu_run(struct nvmm_machine *mach, struct nvmm_cpu *vcpu, ci = curcpu(); hcpu = cpu_number(); + vmx_gtlb_catchup(vcpu, hcpu); + if (__predict_false(kcpuset_isset(machdata->ept_want_flush, hcpu))) { vmx_vmread(VMCS_EPTP, &ept_desc.eptp); ept_desc.mbz = 0; @@ -1636,10 +1649,6 @@ vmx_vcpu_run(struct nvmm_machine *mach, struct nvmm_cpu *vcpu, } if (vcpu->hcpu_last != hcpu) { - tlb_need_flush = true; - } - - if (vcpu->hcpu_last != hcpu) { vmx_vmwrite(VMCS_HOST_TR_SELECTOR, ci->ci_tss_sel); vmx_vmwrite(VMCS_HOST_TR_BASE, (uint64_t)ci->ci_tss); vmx_vmwrite(VMCS_HOST_GDTR_BASE, (uint64_t)ci->ci_gdt); @@ -1653,12 +1662,11 @@ vmx_vcpu_run(struct nvmm_machine *mach, struct nvmm_cpu *vcpu, vmx_vcpu_guest_misc_enter(vcpu); while (1) { - if (cpudata->tlb_want_flush || tlb_need_flush) { + if (cpudata->gtlb_want_flush) { vpid_desc.vpid = cpudata->asid; vpid_desc.addr = 0; vmx_invvpid(vmx_tlb_flush_op, &vpid_desc); - cpudata->tlb_want_flush = false; - tlb_need_flush = false; + cpudata->gtlb_want_flush = false; } s = splhigh(); @@ -2217,7 +2225,7 @@ vmx_vcpu_setstate(struct nvmm_cpu *vcpu, void *data, uint64_t flags) vmx_vmcs_enter(vcpu); if (vmx_state_tlb_flush(state, flags)) { - cpudata->tlb_want_flush = true; + cpudata->gtlb_want_flush = true; } if (flags & NVMM_X64_STATE_SEGS) { |
