From 2ba075906411a715047318df56419acbe4033139 Mon Sep 17 00:00:00 2001 From: dv Date: Mon, 22 Nov 2021 12:55:40 +0000 Subject: [PATCH] vmm(4): copyout guest state on VM_EXIT_NONE Partly related to a bug reported by kn@. We should be copying out the guest exit state (including registers) when we succesfully return from the vcpu run loop even if we don't require an emulation assist from userland/vmd(8). This condition was introduced when I removed the use of yield() and instead exit the kernel if the scheduler says we've hogged the cpu. ok mlarkin@ --- sys/arch/amd64/amd64/vmm.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sys/arch/amd64/amd64/vmm.c b/sys/arch/amd64/amd64/vmm.c index 61cc95def08..2535558cce5 100644 --- a/sys/arch/amd64/amd64/vmm.c +++ b/sys/arch/amd64/amd64/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.294 2021/10/26 16:29:49 deraadt Exp $ */ +/* $OpenBSD: vmm.c,v 1.295 2021/11/22 12:55:40 dv Exp $ */ /* * Copyright (c) 2014 Mike Larkin * @@ -4301,9 +4301,10 @@ vm_run(struct vm_run_params *vrp) rw_exit_write(&vmm_softc->vm_lock); } ret = 0; - } else if (ret == EAGAIN) { + } else if (ret == 0 || ret == EAGAIN) { /* If we are exiting, populate exit data so vmd can help. */ - vrp->vrp_exit_reason = vcpu->vc_gueststate.vg_exit_reason; + vrp->vrp_exit_reason = (ret == 0) ? VM_EXIT_NONE + : vcpu->vc_gueststate.vg_exit_reason; vrp->vrp_irqready = vcpu->vc_irqready; vcpu->vc_state = VCPU_STATE_STOPPED; @@ -4312,9 +4313,6 @@ vm_run(struct vm_run_params *vrp) ret = EFAULT; } else ret = 0; - } else if (ret == 0) { - vrp->vrp_exit_reason = VM_EXIT_NONE; - vcpu->vc_state = VCPU_STATE_STOPPED; } else { vrp->vrp_exit_reason = VM_EXIT_TERMINATED; vcpu->vc_state = VCPU_STATE_TERMINATED; -- 2.20.1