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 If guest events were being processed when a...



details:   https://anonhg.NetBSD.org/src/rev/a55db318cbf4
branches:  trunk
changeset: 450851:a55db318cbf4
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Apr 27 09:06:18 2019 +0000

description:
If guest events were being processed when a #VMEXIT occurred, reschedule
the events rather than dismissing them. This can happen for instance when a
guest wants to process an exception and an #NPF occurs on the guest IDT. In
practice it occurs only when the host swapped out specific guest pages.

diffstat:

 sys/dev/nvmm/x86/nvmm_x86_svm.c |  17 ++++++++++++++---
 sys/dev/nvmm/x86/nvmm_x86_vmx.c |  25 ++++++++++++++++++++++---
 2 files changed, 36 insertions(+), 6 deletions(-)

diffs (98 lines):

diff -r 333edd0e76ee -r a55db318cbf4 sys/dev/nvmm/x86/nvmm_x86_svm.c
--- a/sys/dev/nvmm/x86/nvmm_x86_svm.c   Sat Apr 27 08:49:19 2019 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86_svm.c   Sat Apr 27 09:06:18 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmm_x86_svm.c,v 1.40 2019/04/24 18:19:28 maxv Exp $   */
+/*     $NetBSD: nvmm_x86_svm.c,v 1.41 2019/04/27 09:06:18 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.40 2019/04/24 18:19:28 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.41 2019/04/27 09:06:18 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1259,6 +1259,17 @@
        }
 }
 
+static inline void
+svm_exit_evt(struct svm_cpudata *cpudata, struct vmcb *vmcb)
+{
+       cpudata->evt_pending = false;
+
+       if (__predict_false(vmcb->ctrl.exitintinfo & VMCB_CTRL_EXITINTINFO_V)) {
+               vmcb->ctrl.eventinj = vmcb->ctrl.exitintinfo;
+               cpudata->evt_pending = true;
+       }
+}
+
 static int
 svm_vcpu_run(struct nvmm_machine *mach, struct nvmm_cpu *vcpu,
     struct nvmm_exit *exit)
@@ -1310,7 +1321,7 @@
                        cpudata->gtsc_want_update = false;
                        vcpu->hcpu_last = hcpu;
                }
-               cpudata->evt_pending = false;
+               svm_exit_evt(cpudata, vmcb);
 
                switch (vmcb->ctrl.exitcode) {
                case VMCB_EXITCODE_INTR:
diff -r 333edd0e76ee -r a55db318cbf4 sys/dev/nvmm/x86/nvmm_x86_vmx.c
--- a/sys/dev/nvmm/x86/nvmm_x86_vmx.c   Sat Apr 27 08:49:19 2019 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86_vmx.c   Sat Apr 27 09:06:18 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmm_x86_vmx.c,v 1.28 2019/04/27 08:16:19 maxv Exp $   */
+/*     $NetBSD: nvmm_x86_vmx.c,v 1.29 2019/04/27 09:06:18 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.28 2019/04/27 08:16:19 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.29 2019/04/27 09:06:18 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1844,6 +1844,25 @@
        kcpuset_clear(cpudata->htlb_want_flush, cpu_number());
 }
 
+static inline void
+vmx_exit_evt(struct vmx_cpudata *cpudata)
+{
+       uint64_t info, err;
+
+       cpudata->evt_pending = false;
+
+       info = vmx_vmread(VMCS_IDT_VECTORING_INFO);
+       if (__predict_true((info & INTR_INFO_VALID) == 0)) {
+               return;
+       }
+       err = vmx_vmread(VMCS_IDT_VECTORING_ERROR);
+
+       vmx_vmwrite(VMCS_ENTRY_INTR_INFO, info);
+       vmx_vmwrite(VMCS_ENTRY_EXCEPTION_ERROR, err);
+
+       cpudata->evt_pending = true;
+}
+
 static int
 vmx_vcpu_run(struct nvmm_machine *mach, struct nvmm_cpu *vcpu,
     struct nvmm_exit *exit)
@@ -1909,7 +1928,7 @@
                        exit->reason = NVMM_EXIT_INVALID;
                        break;
                }
-               cpudata->evt_pending = false;
+               vmx_exit_evt(cpudata);
 
                launched = true;
 



Home | Main Index | Thread Index | Old Index