From nobody Mon Jun 19 19:54:37 2023 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 4QlL7y0Wb6z4fchb; Mon, 19 Jun 2023 19:54:38 +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 4QlL7x5qGfz3vZx; Mon, 19 Jun 2023 19:54:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687204477; 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=jFtJoFSZ0CWRim1pRA81Iyv2Ca3AkF05viQwZULNaac=; b=gAHa5r3VHpnptBbbDcqNO2FH+QW2/Pa6BYiXwrdT1fCd2+LqVXW1QXZUSHYBexVZPX5sf8 8RbIeF8eQ3LlJb1AnQTKIUee1QrXXGkkIaX8vyvzVwfHnAJ+vxu2oldR6EVrKwlc0qrw0e kmaQLhcrCNtFOYapakIn+RwGqlz1K1DlX+A78wJdqQ3UsRDpREfVno1DRXqowxL9WvbEgA Ca5uz35fB1E91kklAE47TtJDbibPQRuISJfMCXAUGLJN2nsvo4POJeTHJWxptcJWdsprnM 7DvqpyJ+QeOwOB7oCB+Nh7TwMzW/faXxyYQ1m1z/QqlTEZjQGSLZkD4gGrHUDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687204477; 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=jFtJoFSZ0CWRim1pRA81Iyv2Ca3AkF05viQwZULNaac=; b=cJBswBOgiX+OP3KtrxBACpT4YlQz7ZL+SIIKd8sWBJ8J8VripHLyM+YnEQn6qfjHWBoepb ooZPGsEQK+9pXY5LKPgBlWBjyYGdcGaEFoMv16FvuYvsl182RrcAof7YeYiCvW3VJoSVI0 +yYC9zuVpHRYtCU+MKrNKhrZMwkkCEm4GRwrPoz9viP3Q47nt1KSBeqzmQ2JSL44CUJ+71 PtW9FB5b4MDCjPYe0fhfGPBqDLEtu12b8ALwWDF99LH3Tc+aDp7jbAH2j2M0p5LuJFHrdE OiWx/Pl6V0C2XK/kPBIitb7jxriT/ssogAQz1AdTMrCjsclt1796UHIkOtTaKg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687204477; a=rsa-sha256; cv=none; b=SyXqCe9ae4XPpTydeUn+hHGpHuDyeuol6T9ClQJQebQtN31ohSYS+0wvjzEOpUpNGQJAeD s1ZhexVtnBVARq6qha2RCbjkvkvfJwK4gSiDPO+tfMTJ8qWTn4AkovaTBbddErLd6LA98q kLdDIQ6sFA6NNFJdKkJ4kv/FwfNV7TdtqBK9+Vho2kZ8gT/rAYYgjPMcHZ6eq6rf6FxbXp HMjXz8D/jwDaNzy31dJTcFkhZhOvf7th0wqqs0YlLRhEhof3Gg3vjsBwfsYTwqiKkSEgxZ 0L4TsptIdMLLb1EQ0v3+g1BX5ryJynG8uaTAeznpYkJHeLXI0/7NQ74gRp8d0A== 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 4QlL7x4wc3zVkm; Mon, 19 Jun 2023 19:54:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 35JJsbbV012957; Mon, 19 Jun 2023 19:54:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35JJsbDD012956; Mon, 19 Jun 2023 19:54:37 GMT (envelope-from git) Date: Mon, 19 Jun 2023 19:54:37 GMT Message-Id: <202306191954.35JJsbDD012956@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: eb9fac0edbc7 - main - bhyve: Refactor vmexit_suspend() a bit 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: 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: eb9fac0edbc7ed5435f693ba3d3826363d8a7110 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=eb9fac0edbc7ed5435f693ba3d3826363d8a7110 commit eb9fac0edbc7ed5435f693ba3d3826363d8a7110 Author: Mark Johnston AuthorDate: 2023-06-19 19:46:32 +0000 Commit: Mark Johnston CommitDate: 2023-06-19 19:46:32 +0000 bhyve: Refactor vmexit_suspend() a bit Move some of its logic into fbsdrun_deletecpu(). This makes it easier to split vmexit handlers into a separate file, which in turn makes landing arm64 support easier. Also increase the scope of the mutex and use it to synchronize updates to the vcpu mask. No functional change intended. Reviewed by: corvink, jhb MFC after: 2 weeks Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D40573 --- usr.sbin/bhyve/bhyverun.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index 888fbe1cd8fc..9eef1ea7225d 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -553,17 +553,31 @@ fbsdrun_addcpu(struct vcpu_info *vi) assert(error == 0); } -static int +static void fbsdrun_deletecpu(int vcpu) { + static pthread_mutex_t resetcpu_mtx = PTHREAD_MUTEX_INITIALIZER; + static pthread_cond_t resetcpu_cond = PTHREAD_COND_INITIALIZER; + pthread_mutex_lock(&resetcpu_mtx); if (!CPU_ISSET(vcpu, &cpumask)) { fprintf(stderr, "Attempting to delete unknown cpu %d\n", vcpu); exit(4); } - CPU_CLR_ATOMIC(vcpu, &cpumask); - return (CPU_EMPTY(&cpumask)); + CPU_CLR(vcpu, &cpumask); + + if (vcpu != BSP) { + pthread_cond_signal(&resetcpu_cond); + pthread_mutex_unlock(&resetcpu_mtx); + pthread_exit(NULL); + /* NOTREACHED */ + } + + while (!CPU_EMPTY(&cpumask)) { + pthread_cond_wait(&resetcpu_cond, &resetcpu_mtx); + } + pthread_mutex_unlock(&resetcpu_mtx); } static int @@ -818,9 +832,6 @@ fail: return (VMEXIT_ABORT); } -static pthread_mutex_t resetcpu_mtx = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t resetcpu_cond = PTHREAD_COND_INITIALIZER; - static int vmexit_suspend(struct vmctx *ctx, struct vcpu *vcpu, struct vm_run *vmrun) { @@ -834,19 +845,6 @@ vmexit_suspend(struct vmctx *ctx, struct vcpu *vcpu, struct vm_run *vmrun) fbsdrun_deletecpu(vcpuid); - if (vcpuid != BSP) { - pthread_mutex_lock(&resetcpu_mtx); - pthread_cond_signal(&resetcpu_cond); - pthread_mutex_unlock(&resetcpu_mtx); - pthread_exit(NULL); - } - - pthread_mutex_lock(&resetcpu_mtx); - while (!CPU_EMPTY(&cpumask)) { - pthread_cond_wait(&resetcpu_cond, &resetcpu_mtx); - } - pthread_mutex_unlock(&resetcpu_mtx); - switch (how) { case VM_SUSPEND_RESET: exit(0);