From nobody Tue Oct 24 13:38:29 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 4SFCnK5rL1z4y3s4; Tue, 24 Oct 2023 13:38:29 +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 4SFCnK4w3Bz4ZVs; Tue, 24 Oct 2023 13:38:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698154709; 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=qH6f/DwY0BljJKLnsOlU98DlS8qvE4DJAONyD2hsp+o=; b=qDNfwGk7SRQBkgwXXMNpKNJ3EHZxZJGT2V5xHcXdeSVbIfbdty1FHiKyllaA4U41dWCWy/ UJjfWffD6FjfFBwBLwffU0O/ZrjMgAvlZocaIwyhJsX/E1bT2r099WD9g9qKTH9N+5neij RIDCr4RBtBoEglhjD8SxFGMmtK6jkhkAoSTjmF8juMkvCOfvzL03G1FogsyejTYHbALwrs 4mVn2CbnrE3K+OCntvj5bYXOzYDW2DAhAAwMmnHiW0MCcJfRJBREvI+u2i5916JaspEPFE 4i1SWFMWVGfGEBB4bREaO87i+SR94Dnm90jXt2wPKRE9/wzxSzAkJ9/yj6BD/g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698154709; a=rsa-sha256; cv=none; b=a7g2/npYfC5V9mJDtFr2iMNL+OROD1CWju3TcRxu0LQw8y8nUpUe7q/HHtw3sgiYV0vXm7 H2s4T/DWxM1jDgzu5JgX/G/eenkpL8/gI5m1C7Pv4SY2B74tZHyOP0M6bvFW9FEEz9wSqQ Uv4/l/K7tzpKbIFACYl2ovVJ5tRx+ZShfRJRIgrVSy94Aj3WQ3B//RPY4rjUx55mqFK8P4 imTE1EjNBH/jeTuBw25quGPSO/FC4NycaX0HKeVsiR/RgzXtljKiIdHt5+1dvOGc/BryK+ QhcXaoGfg/CxbuRrdUAnyrn4wu8qSaFCbqTasZv1fqccoBK5xxjc1p3JezomtA== 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=1698154709; 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=qH6f/DwY0BljJKLnsOlU98DlS8qvE4DJAONyD2hsp+o=; b=cyUe+X4DkiecKLx/GuctVBM8t3Z9NrNcV0T8ioBreA9o5XnKnc6j05e9ABCp1ankW43G2U 8yNcE33PV3/QgmzX8ZGErJMKtYAvIbLYfLm8vM9APzDXKKSZoiejMv5Mqdk5VkSMak0sXP cW9o7pHTi4AVnfAyf/UUNuG3E0z6KIZ0yOy6zBp0EUPBB3kDqtE+CEMY9WyuuOZFmgBFuH A7q3cc35zbZRz65oJrhsz10utIkFzGTDGJrVpPEwVjipAAYvqOle5AxNZP9+R9xjJYKiqq vnvWiKQSP8CIAELZq0agCseX73SemD9xsZwjJrAMGOBjciXBDJMedZzDIGP3rg== 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 4SFCnK41JMz9d3; Tue, 24 Oct 2023 13:38:29 +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 39ODcTRD089580; Tue, 24 Oct 2023 13:38:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39ODcTdl089577; Tue, 24 Oct 2023 13:38:29 GMT (envelope-from git) Date: Tue, 24 Oct 2023 13:38:29 GMT Message-Id: <202310241338.39ODcTdl089577@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: c038e80498b3 - stable/14 - bhyve: Remove init_snapshot() and initialize static vars 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: c038e80498b38027f31e86d9e3bf6b418ed4d5f1 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c038e80498b38027f31e86d9e3bf6b418ed4d5f1 commit c038e80498b38027f31e86d9e3bf6b418ed4d5f1 Author: Vitaliy Gusev AuthorDate: 2023-10-17 14:16:08 +0000 Commit: Mark Johnston CommitDate: 2023-10-24 13:21:08 +0000 bhyve: Remove init_snapshot() and initialize static vars vCPU threads are starting before init_snapshot() is called. That can lead to corruption of vcpu_lock userspace mutex (snapshot.c) and then VM hangs in acquiring that mutex. init_snapshot() initializes only static variables (mutex, cv) and that code can be optimized and removed. Fixes: 9a9a248964696 ("bhyve: init checkput before caph_enter") Reviewed by: markj MFC after: 1 week Sponsored by: vStack (cherry picked from commit 7de582874eb9d08f3f87d11ed9e2b9ce8306db79) --- usr.sbin/bhyve/bhyverun.c | 3 --- usr.sbin/bhyve/snapshot.c | 21 +++------------------ usr.sbin/bhyve/snapshot.h | 1 - 3 files changed, 3 insertions(+), 22 deletions(-) diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index eda9711bccb8..581e45a7492c 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -1016,9 +1016,6 @@ main(int argc, char *argv[]) setproctitle("%s", vmname); #ifdef BHYVE_SNAPSHOT - /* initialize mutex/cond variables */ - init_snapshot(); - /* * checkpointing thread for communication with bhyvectl */ diff --git a/usr.sbin/bhyve/snapshot.c b/usr.sbin/bhyve/snapshot.c index 86c76e679e53..5f2b5e1fafe4 100644 --- a/usr.sbin/bhyve/snapshot.c +++ b/usr.sbin/bhyve/snapshot.c @@ -137,8 +137,9 @@ static const struct vm_snapshot_kern_info snapshot_kern_structs[] = { }; static cpuset_t vcpus_active, vcpus_suspended; -static pthread_mutex_t vcpu_lock; -static pthread_cond_t vcpus_idle, vcpus_can_run; +static pthread_mutex_t vcpu_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t vcpus_idle = PTHREAD_COND_INITIALIZER; +static pthread_cond_t vcpus_can_run = PTHREAD_COND_INITIALIZER; static bool checkpoint_active; /* @@ -1395,22 +1396,6 @@ vm_do_checkpoint(struct vmctx *ctx, const nvlist_t *nvl) } IPC_COMMAND(ipc_cmd_set, checkpoint, vm_do_checkpoint); -void -init_snapshot(void) -{ - int err; - - err = pthread_mutex_init(&vcpu_lock, NULL); - if (err != 0) - errc(1, err, "checkpoint mutex init"); - err = pthread_cond_init(&vcpus_idle, NULL); - if (err != 0) - errc(1, err, "checkpoint cv init (vcpus_idle)"); - err = pthread_cond_init(&vcpus_can_run, NULL); - if (err != 0) - errc(1, err, "checkpoint cv init (vcpus_can_run)"); -} - /* * Create the listening socket for IPC with bhyvectl */ diff --git a/usr.sbin/bhyve/snapshot.h b/usr.sbin/bhyve/snapshot.h index fdfbbcbe0cb8..b60773cb99c0 100644 --- a/usr.sbin/bhyve/snapshot.h +++ b/usr.sbin/bhyve/snapshot.h @@ -100,7 +100,6 @@ int vm_resume_devices(void); int get_checkpoint_msg(int conn_fd, struct vmctx *ctx); void *checkpoint_thread(void *param); int init_checkpoint_thread(struct vmctx *ctx); -void init_snapshot(void); int load_restore_file(const char *filename, struct restore_state *rstate);