From nobody Fri Mar 17 10:29:25 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 4PdL396wFFz3yBTZ; Fri, 17 Mar 2023 10:29:25 +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 4PdL396TD5z3GXX; Fri, 17 Mar 2023 10:29:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679048965; 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=JvP3D8fZoq2vXuwa9xyWjZta4skgch3LiphTNtMygOA=; b=qsj+S93Rp4aV9CjhXr+6njL8eSQuyri8uFnQ3OLpD05QJuzT5COh1XYlJi8rfltVkYd4NG SOp00CKOCq6yaM8olkRGzTdGaxNHb1yxnaFuX4oxIHm+UU8A/Sr41+prS3psnFBKguJOeS sZcOs+1PEo1r6PMxJ/lzy7qn8r7GSPkiU9HdgfSjfR88siySG19zmJZAQoYMG0UX1q3sCv 4EJldmoBSB1M4MI8dPb+rfdDZffo8rORy+GdQU5lVQpwLW6Iy2FTcp0gLQymnlOYFDxbkd zteF7z/E9MK00G7b6tiVaR1jmTikYIfCjFebCBxXoWCVBzzWVfzVXUCK6nDoyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679048965; 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=JvP3D8fZoq2vXuwa9xyWjZta4skgch3LiphTNtMygOA=; b=EY4TWK1M3lTqkVyRr+6Be0Ab6G4MgA1wjSAtYduiSQqM4yv+2a4KEPRjvtQMqc9JrRPTJB i1AKeyBu/4MGOQYqt9VagjMlUGULcnBqeIJESuyprIzJZINzwcssqnLy1X8d1rzomd7Qj/ XWYQPoZod3wGt0uBnntkEqwUIpO59KPfLFJJaCLaUv+SQEHvvM4zOgnQ5/Arczz8ljZ6lE xqFx5CEK8LXS4Jja4G3cj5ZY1lu88F4B97qmjr1G0vW4hxTvSWDGY93kJmNmX9x9bs7q4f 3pVkNaKjiIxCMK9fLXHio6pF1DEo5kkbX+y2cVBCxE7jzhpRh3eWkfujqq+uXA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679048965; a=rsa-sha256; cv=none; b=By+P807BKx0rz9kop3kKZzmoktExu3NGj9mJfjWRgEdgmY5QQO2JF91UxcIGn58B8btiMZ NxpwV9M9QVH58XRl7oZbvawSfpXsU4GO/x0KyafvzBxDwJSKjIN6F4Lt4rIitBaaqv9uI+ J2NgQLLNRFuLFWmdH8e5U1IydTqYjCatFqJJ9k0J9aI37GIQooEYLUReMyVLPc18PD8CYV RUC6GNbuDfUAoJCyrqnno274o6yIkvk5tkMNS9aN6mpcUfmoLjEe7rW48nSg7BDcos9jSu 9+p8CCISCvN1Rqt11M27K8UqamXiZHs/9y0akhYeyIBnh6r71/9HDd+FkBdADg== 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 4PdL395ZgXzMZp; Fri, 17 Mar 2023 10:29:25 +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 32HATPRD067357; Fri, 17 Mar 2023 10:29:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32HATPNY067355; Fri, 17 Mar 2023 10:29:25 GMT (envelope-from git) Date: Fri, 17 Mar 2023 10:29:25 GMT Message-Id: <202303171029.32HATPNY067355@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: f6a333f85524 - stable/13 - bhyve: fix resume for vms with guest_ncpus > 1 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: corvink X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f6a333f85524fb51c2d15478ba3cc3d65354cf4a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=f6a333f85524fb51c2d15478ba3cc3d65354cf4a commit f6a333f85524fb51c2d15478ba3cc3d65354cf4a Author: Vitaliy Gusev AuthorDate: 2023-02-28 10:28:40 +0000 Commit: Corvin Köhne CommitDate: 2023-03-17 10:26:33 +0000 bhyve: fix resume for vms with guest_ncpus > 1 This error occurs because vm->vcpu[1] has not been allocated yet when vm_snapshot_vm() is called. To fix this, move spinup_vcpu() before restore code. Reviewed by: corvink, markj MFC after: 2 weeks Sponsored by: vStack Differential Revision: https://reviews.freebsd.org/D38477 (cherry picked from commit 9ff3e8b7f09034202ad1f24f4fbbe52cf7f56117) --- usr.sbin/bhyve/bhyverun.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index caa284a8dd63..3ff83f55474b 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -552,7 +552,7 @@ fbsdrun_start_thread(void *param) } static void -fbsdrun_addcpu(struct vmctx *ctx, int newcpu, bool suspend) +fbsdrun_addcpu(struct vmctx *ctx, int newcpu) { int error; @@ -562,8 +562,7 @@ fbsdrun_addcpu(struct vmctx *ctx, int newcpu, bool suspend) CPU_SET_ATOMIC(newcpu, &cpumask); - if (suspend) - vm_suspend_cpu(ctx, newcpu); + vm_suspend_cpu(ctx, newcpu); mt_vmm_info[newcpu].mt_ctx = ctx; mt_vmm_info[newcpu].mt_vcpu = newcpu; @@ -1138,7 +1137,7 @@ do_open(const char *vmname) } static void -spinup_vcpu(struct vmctx *ctx, int vcpu, bool suspend) +spinup_vcpu(struct vmctx *ctx, int vcpu) { int error; @@ -1154,7 +1153,7 @@ spinup_vcpu(struct vmctx *ctx, int vcpu, bool suspend) assert(error == 0); } - fbsdrun_addcpu(ctx, vcpu, suspend); + fbsdrun_addcpu(ctx, vcpu); } static bool @@ -1488,6 +1487,16 @@ main(int argc, char *argv[]) assert(error == 0); } + /* Allocate per-VCPU resources. */ + mt_vmm_info = calloc(guest_ncpus, sizeof(*mt_vmm_info)); + + /* + * Add all vCPUs. + */ + for (int vcpu = 0; vcpu < guest_ncpus; vcpu++) { + spinup_vcpu(ctx, vcpu); + } + #ifdef BHYVE_SNAPSHOT if (restore_file != NULL) { fprintf(stdout, "Pausing pci devs...\r\n"); @@ -1564,9 +1573,6 @@ main(int argc, char *argv[]) #endif #ifdef BHYVE_SNAPSHOT - if (restore_file != NULL) - destroy_restore_state(&rstate); - /* initialize mutex/cond variables */ init_snapshot(); @@ -1576,24 +1582,18 @@ main(int argc, char *argv[]) if (init_checkpoint_thread(ctx) < 0) printf("Failed to start checkpoint thread!\r\n"); - if (restore_file != NULL) + if (restore_file != NULL) { + destroy_restore_state(&rstate); vm_restore_time(ctx); -#endif - - /* Allocate per-VCPU resources. */ - mt_vmm_info = calloc(guest_ncpus, sizeof(*mt_vmm_info)); - /* - * Add all vCPUs. - */ - for (int vcpu = 0; vcpu < guest_ncpus; vcpu++) { - bool suspend = (vcpu != BSP); -#ifdef BHYVE_SNAPSHOT - if (restore_file != NULL) - suspend = false; -#endif - spinup_vcpu(ctx, vcpu, suspend); + for (int i = 0; i < guest_ncpus; i++) { + if (i == BSP) + continue; + vm_resume_cpu(ctx, i); + } } +#endif + vm_resume_cpu(ctx, BSP); /* * Head off to the main event dispatch loop