From nobody Thu Jan 26 22:34:59 2023 X-Original-To: dev-commits-src-branches@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 4P2wWR6wYQz3cCXb; Thu, 26 Jan 2023 22:34:59 +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 4P2wWR6Rmcz4DP7; Thu, 26 Jan 2023 22:34:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674772499; 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=d6kj4md8fBjc2MwksgPQwPN9KuuzMv/xoSqOlk5ZKQI=; b=lxagimmA+9iSHPdILVnaSVsgSkRqdCzokBhwITIsrkbXzUeMGdqGgAqy6BztR2yV+Pdthq BqekaRPhq1TNV2fPR+wJwehyblqxt3GC3Y0f4/d1mcqyOEqNLebfMgMSkkkSDfkTq8SM9A SwvzRU7XO4ShMko4SIYSyBwABByqfuUmib8wmgHIHnyiUzxierjV9oRla0RATW1qrHPmWH mTWcbWpjIVsWmYTUgYKi+iDzlgI2T2aDsQgC4OIeB+oKV3Yvyrx7jzFsALP3uGrVss9/mz wYSNy9mxeIz3FAU/Cded7Nqis2SPjGEyAfgaXk36NAM1RWLQ3Abs+uXrgBHU+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674772499; 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=d6kj4md8fBjc2MwksgPQwPN9KuuzMv/xoSqOlk5ZKQI=; b=j2qxbj1UfdxE0ZtNiXmNpwqPzm8ENYlLXmwU+WCC8i8HlEnSVBZsVgItVJ64jXMFHstghp UjYYCnAyqTNay0twzmqnaZRU+KzH1T39cvF+QWK5gCSN2xqMNIHGwnvoz1yHD7ESFFRJ4Z vhQjMJL/aN6G65ZSposqNf/14AxMwxS8D96LWTumv3IFg/pVxgL6E8SW9g0Mi34/Kl8bh2 WIUQjQbehbKhaADtNUDVuku1BPvCo5k+6ZhXiSLyF2GUWN0rDj1efVUYpglHJzRSA/mZww PVUdldh0gFrwBQk5lAoQWD644wba7TlZDxEfZ8x4ntQTbDhyCELypADLVVv4LQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674772499; a=rsa-sha256; cv=none; b=KpG9vOajJeEC8FdrqhVH/P304KvObnUKHGW0vff7+7dVBaeotfFkyydNgOiUsoHK6w5Jth 6/XGnFTdByIVhJF2v3uRYMetCtPep+RSf+fIrJrTpyFDij9+JaCFFLeNn+QTj+3nEIvFNa TKre1YCYYTuwvFgcbo8hCNEgepDWHctBhcGLPtCSkeCklgOuJGGk9degAEAKi6JpbjnGpI 4MU/0gDCCcqN8yP71qiLNuW2HHJSXuTEYFB/LYiWdr6pb94pvkzEZH6Z6xtdBuPJG//fqw +qsZ10uLCSKceWW1YimaTmQLZnQkMYKy1QDFgCS8cvl1VB+tx235NPysiHkPyw== 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 4P2wWR5Z26zmdL; Thu, 26 Jan 2023 22:34:59 +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 30QMYx9M051505; Thu, 26 Jan 2023 22:34:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30QMYxgF051504; Thu, 26 Jan 2023 22:34:59 GMT (envelope-from git) Date: Thu, 26 Jan 2023 22:34:59 GMT Message-Id: <202301262234.30QMYxgF051504@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: e57a5e80e913 - stable/13 - bhyve: Simplify setting vCPU capabilities. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e57a5e80e9139ce80834a3a0cbba762de630a610 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=e57a5e80e9139ce80834a3a0cbba762de630a610 commit e57a5e80e9139ce80834a3a0cbba762de630a610 Author: John Baldwin AuthorDate: 2022-12-21 18:31:16 +0000 Commit: John Baldwin CommitDate: 2023-01-26 22:17:43 +0000 bhyve: Simplify setting vCPU capabilities. - Enable VM_CAP_IPI_EXIT in fbsdrun_set_capabilities along with other capabilities enabled on all vCPUs. - Don't call fbsdrun_set_capabilities a second time on the BSP in spinup_vcpu. - To preserve previous behavior, don't unconditionally enable unrestricted guest mode on the BSP (this unbreaks single-vCPU guests on Nehalem systems, though supporting such setups is of dubious value). Other places that enbale UG on the BSP are careful to check the result of the operation and fail if it is not available. - Don't set any capabilities in spinup_ap(). These are now all redundant with earlier settings from spinup_vcpu(). - While here, axe a stale comment from fbsdrun_addcpu(). This function is now always called from the main thread for all vCPUs. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37642 (cherry picked from commit 461663ddbad02a4a5135673d545695b1a9f25ed0) --- usr.sbin/bhyve/bhyverun.c | 28 +++++++++++++++------------- usr.sbin/bhyve/bhyverun.h | 1 - usr.sbin/bhyve/spinup_ap.c | 14 -------------- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index 8bc419504771..72f806e97993 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -552,12 +552,6 @@ fbsdrun_addcpu(struct vmctx *ctx, int newcpu, uint64_t rip, bool suspend) { int error; - /* - * The 'newcpu' must be activated in the context of 'fromcpu'. If - * vm_activate_cpu() is delayed until newcpu's pthread starts running - * then vmm.ko is out-of-sync with bhyve and this can create a race - * with vm_suspend(). - */ error = vm_activate_cpu(ctx, newcpu); if (error != 0) err(EX_OSERR, "could not activate CPU %d", newcpu); @@ -1044,7 +1038,7 @@ num_vcpus_allowed(struct vmctx *ctx) return (1); } -void +static void fbsdrun_set_capabilities(struct vmctx *ctx, int cpu) { int err, tmp; @@ -1086,6 +1080,9 @@ fbsdrun_set_capabilities(struct vmctx *ctx, int cpu) } vm_set_capability(ctx, cpu, VM_CAP_ENABLE_INVPCID, 1); + + err = vm_set_capability(ctx, cpu, VM_CAP_IPI_EXIT, 1); + assert(err == 0); } static struct vmctx * @@ -1157,14 +1154,19 @@ spinup_vcpu(struct vmctx *ctx, int vcpu, bool suspend) int error; uint64_t rip; - error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RIP, &rip); - assert(error == 0); + if (vcpu != BSP) { + fbsdrun_set_capabilities(ctx, vcpu); - fbsdrun_set_capabilities(ctx, vcpu); - error = vm_set_capability(ctx, vcpu, VM_CAP_UNRESTRICTED_GUEST, 1); - assert(error == 0); + /* + * Enable the 'unrestricted guest' mode for APs. + * + * APs startup in power-on 16-bit mode. + */ + error = vm_set_capability(ctx, vcpu, VM_CAP_UNRESTRICTED_GUEST, 1); + assert(error == 0); + } - error = vm_set_capability(ctx, vcpu, VM_CAP_IPI_EXIT, 1); + error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RIP, &rip); assert(error == 0); fbsdrun_addcpu(ctx, vcpu, rip, suspend); diff --git a/usr.sbin/bhyve/bhyverun.h b/usr.sbin/bhyve/bhyverun.h index 1e1e5f9880f8..d3eb8c8b23da 100644 --- a/usr.sbin/bhyve/bhyverun.h +++ b/usr.sbin/bhyve/bhyverun.h @@ -45,7 +45,6 @@ void *paddr_guest2host(struct vmctx *ctx, uintptr_t addr, size_t len); uintptr_t paddr_host2guest(struct vmctx *ctx, void *addr); #endif -void fbsdrun_set_capabilities(struct vmctx *ctx, int cpu); int fbsdrun_virtio_msix(void); int vmexit_task_switch(struct vmctx *, struct vm_exit *, int *vcpu); diff --git a/usr.sbin/bhyve/spinup_ap.c b/usr.sbin/bhyve/spinup_ap.c index e23265f8b82b..af8d40030a08 100644 --- a/usr.sbin/bhyve/spinup_ap.c +++ b/usr.sbin/bhyve/spinup_ap.c @@ -87,20 +87,6 @@ spinup_ap(struct vmctx *ctx, int newcpu, uint64_t rip) error = vcpu_reset(ctx, newcpu); assert(error == 0); - fbsdrun_set_capabilities(ctx, newcpu); - - /* - * Enable the 'unrestricted guest' mode for 'newcpu'. - * - * Set up the processor state in power-on 16-bit mode, with the CS:IP - * init'd to the specified low-mem 4K page. - */ - error = vm_set_capability(ctx, newcpu, VM_CAP_UNRESTRICTED_GUEST, 1); - assert(error == 0); - - error = vm_set_capability(ctx, newcpu, VM_CAP_IPI_EXIT, 1); - assert(error == 0); - spinup_ap_realmode(ctx, newcpu, &rip); vm_resume_cpu(ctx, newcpu);