Source-Changes-HG archive

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

[src/trunk]: src Stop taking care of the INT/NMI windows in the kernel, the e...



details:   https://anonhg.NetBSD.org/src/rev/49fe31bc14b9
branches:  trunk
changeset: 450916:49fe31bc14b9
user:      maxv <maxv%NetBSD.org@localhost>
date:      Mon Apr 29 18:54:25 2019 +0000

description:
Stop taking care of the INT/NMI windows in the kernel, the emulator is
supposed to do that itself.

diffstat:

 doc/TODO.nvmm                   |   4 ----
 lib/libnvmm/libnvmm.3           |  22 +++++++---------------
 sys/dev/nvmm/x86/nvmm_x86_svm.c |  15 ++-------------
 sys/dev/nvmm/x86/nvmm_x86_vmx.c |  34 +++++++---------------------------
 4 files changed, 16 insertions(+), 59 deletions(-)

diffs (179 lines):

diff -r 4383d3654995 -r 49fe31bc14b9 doc/TODO.nvmm
--- a/doc/TODO.nvmm     Mon Apr 29 17:27:57 2019 +0000
+++ b/doc/TODO.nvmm     Mon Apr 29 18:54:25 2019 +0000
@@ -10,10 +10,6 @@
    On Intel that's not complicated, but on old AMD CPUs, we need to disassemble
    the instruction, and I don't like that.
 
- * Maybe we shouldn't modify the INT/NMI windows during event injection. The
-   virtualizer is supposed to inject the event only when these windows allow
-   it. (Eg Qemu does.)
-
  * We need a cleaner way to handle CPUID exits. It is not complicated to solve,
    but I'm still not sure which design is the cleanest.
 
diff -r 4383d3654995 -r 49fe31bc14b9 lib/libnvmm/libnvmm.3
--- a/lib/libnvmm/libnvmm.3     Mon Apr 29 17:27:57 2019 +0000
+++ b/lib/libnvmm/libnvmm.3     Mon Apr 29 18:54:25 2019 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: libnvmm.3,v 1.14 2019/04/07 14:13:03 maxv Exp $
+.\"    $NetBSD: libnvmm.3,v 1.15 2019/04/29 18:54:25 maxv Exp $
 .\"
 .\" Copyright (c) 2018, 2019 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -470,15 +470,15 @@
 in-NMI context.
 .El
 .Pp
-In this case,
-.Fn nvmm_vcpu_inject
-will return
-.Er EAGAIN ,
-and NVMM will cause a VM exit with reason
+VMM software can manage interrupt and NMI window-exiting via the
+.Va intr
+component of the VCPU state.
+When such window-exiting is enabled, NVMM will cause a VM exit with reason
 .Cd NVMM_EXIT_INT_READY
 or
 .Cd NVMM_EXIT_NMI_READY
-to indicate that VMM software can now reinject the desired event.
+to indicate that the guest is now able to handle the corresponding class
+of interrupts.
 .Ss Assist Callbacks
 In order to assist emulation of certain operations,
 .Nm
@@ -633,14 +633,6 @@
 .It Bq Er EPERM
 An attempt was made to access a machine that does not belong to the process.
 .El
-.Pp
-In addition,
-.Fn nvmm_vcpu_inject
-uses the following error codes:
-.Bl -tag -width [ENOBUFS]
-.It Bq Er EAGAIN
-The VCPU cannot receive the event immediately.
-.El
 .Sh SEE ALSO
 .Xr nvmm 4
 .Sh AUTHORS
diff -r 4383d3654995 -r 49fe31bc14b9 sys/dev/nvmm/x86/nvmm_x86_svm.c
--- a/sys/dev/nvmm/x86/nvmm_x86_svm.c   Mon Apr 29 17:27:57 2019 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86_svm.c   Mon Apr 29 18:54:25 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmm_x86_svm.c,v 1.43 2019/04/28 14:22:13 maxv Exp $   */
+/*     $NetBSD: nvmm_x86_svm.c,v 1.44 2019/04/29 18:54:25 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.43 2019/04/28 14:22:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.44 2019/04/29 18:54:25 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -677,18 +677,7 @@
                type = SVM_EVENT_TYPE_HW_INT;
                if (event->vector == 2) {
                        type = SVM_EVENT_TYPE_NMI;
-               }
-               if (type == SVM_EVENT_TYPE_NMI) {
-                       if (cpudata->nmi_window_exit) {
-                               return EAGAIN;
-                       }
                        svm_event_waitexit_enable(vcpu, true);
-               } else {
-                       if (((vmcb->state.rflags & PSL_I) == 0) ||
-                           ((vmcb->ctrl.intr & VMCB_CTRL_INTR_SHADOW) != 0)) {
-                               svm_event_waitexit_enable(vcpu, false);
-                               return EAGAIN;
-                       }
                }
                err = 0;
                break;
diff -r 4383d3654995 -r 49fe31bc14b9 sys/dev/nvmm/x86/nvmm_x86_vmx.c
--- a/sys/dev/nvmm/x86/nvmm_x86_vmx.c   Mon Apr 29 17:27:57 2019 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86_vmx.c   Mon Apr 29 18:54:25 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmm_x86_vmx.c,v 1.31 2019/04/28 14:22:13 maxv Exp $   */
+/*     $NetBSD: nvmm_x86_vmx.c,v 1.32 2019/04/29 18:54:26 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.31 2019/04/28 14:22:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.32 2019/04/29 18:54:26 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -996,8 +996,8 @@
     struct nvmm_event *event)
 {
        struct vmx_cpudata *cpudata = vcpu->cpudata;
-       int type = 0, err = 0, ret = 0;
-       uint64_t info, intstate, rflags;
+       int type = 0, err = 0, ret = EINVAL;
+       uint64_t info;
 
        if (event->vector >= 256) {
                return EINVAL;
@@ -1010,42 +1010,21 @@
                type = INTR_TYPE_EXT_INT;
                if (event->vector == 2) {
                        type = INTR_TYPE_NMI;
-               }
-               intstate = vmx_vmread(VMCS_GUEST_INTERRUPTIBILITY);
-               if (type == INTR_TYPE_NMI) {
-                       if (cpudata->nmi_window_exit) {
-                               ret = EAGAIN;
-                               goto out;
-                       }
                        vmx_event_waitexit_enable(vcpu, true);
-               } else {
-                       rflags = vmx_vmread(VMCS_GUEST_RFLAGS);
-                       if ((rflags & PSL_I) == 0 ||
-                           (intstate & (INT_STATE_STI|INT_STATE_MOVSS)) != 0) {
-                               vmx_event_waitexit_enable(vcpu, false);
-                               ret = EAGAIN;
-                               goto out;
-                       }
                }
                err = 0;
                break;
        case NVMM_EVENT_INTERRUPT_SW:
-               ret = EINVAL;
                goto out;
        case NVMM_EVENT_EXCEPTION:
-               if (event->vector == 2 || event->vector >= 32) {
-                       ret = EINVAL;
+               if (event->vector == 2 || event->vector >= 32)
                        goto out;
-               }
-               if (event->vector == 3 || event->vector == 0) {
-                       ret = EINVAL;
+               if (event->vector == 3 || event->vector == 0)
                        goto out;
-               }
                type = INTR_TYPE_HW_EXC;
                err = vmx_event_has_error(event->vector);
                break;
        default:
-               ret = EAGAIN;
                goto out;
        }
 
@@ -1058,6 +1037,7 @@
        vmx_vmwrite(VMCS_ENTRY_EXCEPTION_ERROR, event->u.error);
 
        cpudata->evt_pending = true;
+       ret = 0;
 
 out:
        vmx_vmcs_leave(vcpu);



Home | Main Index | Thread Index | Old Index