vmm(4): remove vm teardown from vcpu run path
authordv <dv@openbsd.org>
Sun, 12 Jun 2022 19:48:12 +0000 (19:48 +0000)
committerdv <dv@openbsd.org>
Sun, 12 Jun 2022 19:48:12 +0000 (19:48 +0000)
Remove the calling of vm_teardown from the code path in vm_run after
vmm has exited the vm/vcpu and is on its way back to userland/vmd(8).
vmd(8) and other vmm(4) users should use the VMM_IOC_TERM ioctl(2)
instead.

Help testing from Mischa Peters, OK mlarkin@

sys/arch/amd64/amd64/vmm.c

index 323a778..c977798 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vmm.c,v 1.312 2022/06/01 17:47:18 dv Exp $    */
+/*     $OpenBSD: vmm.c,v 1.313 2022/06/12 19:48:12 dv Exp $    */
 /*
  * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
  *
@@ -4488,22 +4488,8 @@ vm_run(struct vm_run_params *vrp)
                ret = vcpu_run_svm(vcpu, vrp);
        }
 
-       /*
-        * We can set the VCPU states here without CAS because once
-        * a VCPU is in state RUNNING or REQTERM, only the VCPU itself
-        * can switch the state.
-        */
        atomic_dec_int(&vm->vm_vcpus_running);
-       if (vcpu->vc_state == VCPU_STATE_REQTERM) {
-               vrp->vrp_exit_reason = VM_EXIT_TERMINATED;
-               vcpu->vc_state = VCPU_STATE_TERMINATED;
-               if (vm->vm_vcpus_running == 0) {
-                       rw_enter_write(&vmm_softc->vm_lock);
-                       vm_teardown(vm);
-                       rw_exit_write(&vmm_softc->vm_lock);
-               }
-               ret = 0;
-       } else if (ret == 0 || ret == EAGAIN) {
+       if (ret == 0 || ret == EAGAIN) {
                /* If we are exiting, populate exit data so vmd can help. */
                vrp->vrp_exit_reason = (ret == 0) ? VM_EXIT_NONE
                    : vcpu->vc_gueststate.vg_exit_reason;