From: mlarkin Date: Tue, 30 May 2017 20:31:24 +0000 (+0000) Subject: event injection framework, will be used for other features coming shortly X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5e15c3693c1e3206a6476352e8c40804c2e13366;p=openbsd event injection framework, will be used for other features coming shortly ok deraadt --- diff --git a/sys/arch/amd64/amd64/vmm.c b/sys/arch/amd64/amd64/vmm.c index d1184e5cd7c..8a7e4e16f91 100644 --- a/sys/arch/amd64/amd64/vmm.c +++ b/sys/arch/amd64/amd64/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.151 2017/05/30 19:31:28 mlarkin Exp $ */ +/* $OpenBSD: vmm.c,v 1.152 2017/05/30 20:31:24 mlarkin Exp $ */ /* * Copyright (c) 2014 Mike Larkin * @@ -3681,6 +3681,29 @@ vcpu_run_vmx(struct vcpu *vcpu, struct vm_run_params *vrp) } } + /* Inject event if present */ + if (vcpu->vc_event != 0) { + eii = (vcpu->vc_event & 0xFF); + eii |= (1ULL << 31); /* Valid */ + eii |= (1ULL << 11); /* Send error code */ + eii |= (3ULL << 8); /* Hardware Exception */ + if (vmwrite(VMCS_ENTRY_INTERRUPTION_INFO, eii)) { + printf("%s: can't vector event to guest\n", + __func__); + ret = EINVAL; + break; + } + + if (vmwrite(VMCS_ENTRY_EXCEPTION_ERROR_CODE, 0)) { + printf("%s: can't write error code to guest\n", + __func__); + ret = EINVAL; + break; + } + + vcpu->vc_event = 0; + } + if (vcpu->vc_vmx_vpid_enabled) { /* Invalidate old TLB mappings */ vid.vid_vpid = vcpu->vc_parent->vm_id; @@ -5492,6 +5515,14 @@ vcpu_run_svm(struct vcpu *vcpu, struct vm_run_params *vrp) vmcb->v_intr_vector = 0; } + /* Inject event if present */ + if (vcpu->vc_event != 0) { + vmcb->v_eventinj = (vcpu->vc_event) | (1 << 31); + vmcb->v_eventinj |= (1ULL << 1); /* Send error code */ + vmcb->v_eventinj |= (3ULL << 8); /* Hardware Exception */ + vcpu->vc_event = 0; + } + /* Start / resume the VCPU */ #ifdef VMM_DEBUG KERNEL_ASSERT_LOCKED(); diff --git a/sys/arch/amd64/include/vmmvar.h b/sys/arch/amd64/include/vmmvar.h index 9f8a4cbb863..db758e9d02c 100644 --- a/sys/arch/amd64/include/vmmvar.h +++ b/sys/arch/amd64/include/vmmvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmmvar.h,v 1.40 2017/05/30 17:49:47 mlarkin Exp $ */ +/* $OpenBSD: vmmvar.h,v 1.41 2017/05/30 20:31:24 mlarkin Exp $ */ /* * Copyright (c) 2014 Mike Larkin * @@ -721,6 +721,8 @@ struct vcpu { struct vcpu_gueststate vc_gueststate; + uint8_t vc_event; + /* VMX only */ uint64_t vc_vmx_basic; uint64_t vc_vmx_entry_ctls;