Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/nvmm/x86 Clarify the gTLB code a little.



details:   https://anonhg.NetBSD.org/src/rev/16f17060507c
branches:  trunk
changeset: 449079:16f17060507c
user:      maxv <maxv%NetBSD.org@localhost>
date:      Thu Feb 21 11:58:04 2019 +0000

description:
Clarify the gTLB code a little.

diffstat:

 sys/dev/nvmm/x86/nvmm_x86_svm.c |  34 +++++++++++++++++++++-------------
 sys/dev/nvmm/x86/nvmm_x86_vmx.c |  32 ++++++++++++++++++++------------
 2 files changed, 41 insertions(+), 25 deletions(-)

diffs (212 lines):

diff -r 3f17a9914d81 -r 16f17060507c sys/dev/nvmm/x86/nvmm_x86_svm.c
--- a/sys/dev/nvmm/x86/nvmm_x86_svm.c   Thu Feb 21 08:52:53 2019 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86_svm.c   Thu Feb 21 11:58:04 2019 +0000
@@ -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 @@
 struct svm_cpudata {
        /* General */
        bool shared_asid;
-       bool tlb_want_flush;
+       bool gtlb_want_flush;
 
        /* VMCB */
        struct vmcb *vmcb;
@@ -977,7 +977,7 @@
                        }
                        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 @@
        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_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_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 @@
        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 @@
                if (error)
                        continue;
                cpudata = vcpu->cpudata;
-               cpudata->tlb_want_flush = true;
+               cpudata->gtlb_want_flush = true;
                nvmm_vcpu_put(vcpu);
        }
 }
diff -r 3f17a9914d81 -r 16f17060507c sys/dev/nvmm/x86/nvmm_x86_vmx.c
--- a/sys/dev/nvmm/x86/nvmm_x86_vmx.c   Thu Feb 21 08:52:53 2019 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86_vmx.c   Thu Feb 21 11:58:04 2019 +0000
@@ -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 @@
 struct vmx_cpudata {
        /* General */
        uint64_t asid;
-       bool tlb_want_flush;
+       bool gtlb_want_flush;
 
        /* VMCS */
        struct vmcs *vmcs;
@@ -1601,6 +1601,8 @@
        wrmsr(MSR_KERNELGSBASE, cpudata->kernelgsbase);
 }
 
+/* --------------------------------------------------------------------- */
+
 #define VMX_INVVPID_ADDRESS            0
 #define VMX_INVVPID_CONTEXT            1
 #define VMX_INVVPID_ALL                        2
@@ -1609,13 +1611,22 @@
 #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 @@
        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 @@
        }
 
        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_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_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) {



Home | Main Index | Thread Index | Old Index