Module Name:    src
Committed By:   maxv
Date:           Mon Apr 29 18:54:26 UTC 2019

Modified Files:
        src/doc: TODO.nvmm
        src/lib/libnvmm: libnvmm.3
        src/sys/dev/nvmm/x86: nvmm_x86_svm.c nvmm_x86_vmx.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/doc/TODO.nvmm
cvs rdiff -u -r1.14 -r1.15 src/lib/libnvmm/libnvmm.3
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/TODO.nvmm
diff -u src/doc/TODO.nvmm:1.2 src/doc/TODO.nvmm:1.3
--- src/doc/TODO.nvmm:1.2	Sun Apr 21 06:48:37 2019
+++ src/doc/TODO.nvmm	Mon Apr 29 18:54:25 2019
@@ -10,10 +10,6 @@ Known issues in NVMM, low priority in mo
    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.
 

Index: src/lib/libnvmm/libnvmm.3
diff -u src/lib/libnvmm/libnvmm.3:1.14 src/lib/libnvmm/libnvmm.3:1.15
--- src/lib/libnvmm/libnvmm.3:1.14	Sun Apr  7 14:13:03 2019
+++ src/lib/libnvmm/libnvmm.3	Mon Apr 29 18:54:25 2019
@@ -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 @@ the event is a non-maskable interrupt (N
 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 @@ A query was made on a machine or a VCPU 
 .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

Index: src/sys/dev/nvmm/x86/nvmm_x86_svm.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.43 src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.44
--- src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.43	Sun Apr 28 14:22:13 2019
+++ src/sys/dev/nvmm/x86/nvmm_x86_svm.c	Mon Apr 29 18:54:25 2019
@@ -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 @@ svm_vcpu_inject(struct nvmm_machine *mac
 		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;

Index: src/sys/dev/nvmm/x86/nvmm_x86_vmx.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.31 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.32
--- src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.31	Sun Apr 28 14:22:13 2019
+++ src/sys/dev/nvmm/x86/nvmm_x86_vmx.c	Mon Apr 29 18:54:26 2019
@@ -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 @@ vmx_vcpu_inject(struct nvmm_machine *mac
     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 @@ vmx_vcpu_inject(struct nvmm_machine *mac
 		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_vcpu_inject(struct nvmm_machine *mac
 	vmx_vmwrite(VMCS_ENTRY_EXCEPTION_ERROR, event->u.error);
 
 	cpudata->evt_pending = true;
+	ret = 0;
 
 out:
 	vmx_vmcs_leave(vcpu);

Reply via email to