From nobody Mon Apr 29 14:21:42 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VSlrR1XZSz5JQpm; Mon, 29 Apr 2024 14:21:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VSlrQ6k8Fz4GT6; Mon, 29 Apr 2024 14:21:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714400502; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kRe/i9WnTO4F9lLkbkZSxN32KroFdHPNUk8oMmc4J+A=; b=e35PljwU+Kia/Lyr9VKH99g19UPNPkZx2Qugle5Qnhb7AilXrf5HjsM1vG+lVZBu7TTlE0 DipW0ioBoPX6RSlXpLB3jcONaWZ+m+Hyky0d8hKHpORN1lLGVMu6GZu9sdzfh8NBnLR3Xs /cB0jpjosgsZ2E/EEeehI7kt2LzOfPvfh1oW25ZbYSTFXAmDWebCVe+TedetnFkJHI93+8 Dae5iiD45ibcfdswr2dObEwJbDTYwtnaimFulVFq+p4oG6MEsEFd779mr7E8OYNYsaWcOl oKI7cR0idzv/oHl8m+iYqhrgryCETuiwJZG2t03fZVOgMA76qrJZv02+qab76w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714400502; a=rsa-sha256; cv=none; b=eB2ihFwXnM9c84CzSI0QtYhu+BRWeGmxklJ34+1BGVceyyO400FgRsjwEMUTsWZJSvPsph /XwWfnaUT3vxRg/LJqwvJ7GsX6t4j5ce4LFPF2CAZXrBsHHt+Tmzbc5AA0qYxny4Q7Qfqc LZAbUBbHGv9uKiL3v4uHxA5a9/u5KREyy3gNF51AvBTsvTvkl7DzHVH6dBS1ep/jOPwwOE ZYtBRvLkF7/GcB6CaGcnSAbuOtIVmIvAwO0248+/ucSAceRjGeIE6mzGC1uVnHgZ3CsSiT 6SKfaRf9eC3KEsYWXyPeYYqvFYXPGQXa8aH1xpLFfFTB4z5PaVvCI88WKAqaNw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714400502; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kRe/i9WnTO4F9lLkbkZSxN32KroFdHPNUk8oMmc4J+A=; b=kjMq2yIh79SG6xKSebam4N1KZnofNOOn2h9e7RbW486P4F5LJlmKuYrLQNqc61/PNJ0HK6 U+Q7HEG87rxigTSjTI/Pfh48o/6z+EuZ+K4hNGNVeLYhd1bfEIu0CiRIMaZQXprtIcUgbv qgDlGNzOwubC5BXNxYpSEGmrn75yyYkOYNbYYvyLSYY6Tp8JMuD0v8WNVKPAe3wXF+lOgW NCpTE7RSHNCGs1TTb/iMeGz7udz9s18Yg0cntNyj+p/ZtIlUoOqKaNhIavo5pcOuLxSg4m 8O1kHE4qPHG8Zt6yGp96FSmVK/4DuYl0d/I9DyUMF72LhF1y9IdZ6cP/ue+wtg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VSlrQ62Syz1BZN; Mon, 29 Apr 2024 14:21:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43TELgti059151; Mon, 29 Apr 2024 14:21:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43TELgki059148; Mon, 29 Apr 2024 14:21:42 GMT (envelope-from git) Date: Mon, 29 Apr 2024 14:21:42 GMT Message-Id: <202404291421.43TELgki059148@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 1ee7a8fa58c3 - main - arm64/vmm: Handle VM_EXITCODE_SUSPENDED List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1ee7a8fa58c3fe7161683f2a7d2e37dc5c672b46 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1ee7a8fa58c3fe7161683f2a7d2e37dc5c672b46 commit 1ee7a8fa58c3fe7161683f2a7d2e37dc5c672b46 Author: Mark Johnston AuthorDate: 2024-04-29 14:19:27 +0000 Commit: Mark Johnston CommitDate: 2024-04-29 14:19:27 +0000 arm64/vmm: Handle VM_EXITCODE_SUSPENDED This is required for bhyve reboot to work. In particular, unless we suspend vcpu threads here, vm_reinit() will fail with EBUSY. The implementation is copied from amd64; in the not-too-distant future the amd64 and arm64 copies of vmm.c and vmm_dev.c will be merged, so for now it's useful to minimize diffs between amd64 and arm64. Reviewed by: corvink, andrew MFC after: 2 weeks Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D44934 --- sys/arm64/vmm/vmm.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/sys/arm64/vmm/vmm.c b/sys/arm64/vmm/vmm.c index 2685e5869b4f..a2cc63448f19 100644 --- a/sys/arm64/vmm/vmm.c +++ b/sys/arm64/vmm/vmm.c @@ -1716,6 +1716,54 @@ vm_handle_paging(struct vcpu *vcpu, bool *retu) return (0); } +static int +vm_handle_suspend(struct vcpu *vcpu, bool *retu) +{ + struct vm *vm = vcpu->vm; + int error, i; + struct thread *td; + + error = 0; + td = curthread; + + CPU_SET_ATOMIC(vcpu->vcpuid, &vm->suspended_cpus); + + /* + * Wait until all 'active_cpus' have suspended themselves. + * + * Since a VM may be suspended at any time including when one or + * more vcpus are doing a rendezvous we need to call the rendezvous + * handler while we are waiting to prevent a deadlock. + */ + vcpu_lock(vcpu); + while (error == 0) { + if (CPU_CMP(&vm->suspended_cpus, &vm->active_cpus) == 0) + break; + + vcpu_require_state_locked(vcpu, VCPU_SLEEPING); + msleep_spin(vcpu, &vcpu->mtx, "vmsusp", hz); + vcpu_require_state_locked(vcpu, VCPU_FROZEN); + if (td_ast_pending(td, TDA_SUSPEND)) { + vcpu_unlock(vcpu); + error = thread_check_susp(td, false); + vcpu_lock(vcpu); + } + } + vcpu_unlock(vcpu); + + /* + * Wakeup the other sleeping vcpus and return to userspace. + */ + for (i = 0; i < vm->maxcpus; i++) { + if (CPU_ISSET(i, &vm->suspended_cpus)) { + vcpu_notify_event(vm_vcpu(vm, i)); + } + } + + *retu = true; + return (error); +} + int vm_run(struct vcpu *vcpu) { @@ -1788,6 +1836,11 @@ restart: error = vm_handle_paging(vcpu, &retu); break; + case VM_EXITCODE_SUSPENDED: + vcpu->nextpc = vme->pc; + error = vm_handle_suspend(vcpu, &retu); + break; + default: /* Handle in userland */ vcpu->nextpc = vme->pc;