From nobody Mon Jan 22 17:30:06 2024 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 4TJcg26KYnz57rDM; Mon, 22 Jan 2024 17:30:06 +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 4TJcg23MWvz4fTt; Mon, 22 Jan 2024 17:30:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705944606; 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=J94xTE78ii2gYU0wljEpsDBOdOU2Z716qxykqgQcpYg=; b=na1oV0E1hUEFpNN1fppTenvnKZ5feuoxG7vtb8eaMH0l83Jo+dG9kqXHl9SOUjv2SqMNEb 2IzZ2b42inS/18Hzrc+66auv7Zs66GCFJcK0V7tVlufVhl2ey61AStM0/p2fe9diZchB2H PiNgcrfmWbuRB1PS1/h1CImm9Dq8bv+LZXrkuhfEHez9J4YTmr1RKrJP/z2k95hPU1vq7M FkrNyzGdZYm3wWK2iwj1nQ5iBn94Q97C1Wl8V7EVGVx6W8arFQgkyjoLLmikBpw4/j8D66 lLGgwLiFA5RZCFpTNIAhnKwvpDS3r5yw7ZDxtN23Kx0roBZn2vMqrZkzlsZRWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705944606; 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=J94xTE78ii2gYU0wljEpsDBOdOU2Z716qxykqgQcpYg=; b=X+0qu1Bbn50AxAFX0zL4mbNgxuGIYbXtD86+NdoiUoxO1qpJoXDDcv0j3H1XLUePJyK/qI ZN/U6DmVfAlHoJUxEK0b3G8HBrL2uS5eW3kM58YsUZxDdNLJSqapym8GDq27w5VSkAmmpB A/+tuX6KW+cKeqeB9WpzNV0+SVF/lcBBgZd0K2FIwIy4YmKitA3kGEFrb9AWTtbcM2dZUD HnngN93xCvoI9ttks6j155a1Z4a6XzVch/FZZjQuVbyEGGhnIlbHM6Eh4J4xa3fYdWQ9gS huGZP1DaVVvbrT6cxwutNocNVVCsmeEt3wrN8EUSMVoHGKRkR+4rQ/zG2wgLtQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705944606; a=rsa-sha256; cv=none; b=Igr4T1ctIFCvzgUG+kW8ve8b5jXJavJw18MMSN5/837+S8tt0v9svPE1fwD80muDUD7SYa GPTU7Oo1D0HQtGt4ATSDR/hu9StiU3xL6T4FyC+3htrnrE6LTw01tuMtO6dkb81vQYSm5z GflRh78FdiOzwDv5M6LVMD2HD97/YNFwTjE7c9vHrdTXN+q65fdd4VtVaJHXPSsZ+KE0dg fJMyL7YVcNKZ6Rs27PhgtNcbskNRbFe5JTffow5e7n+I4ryfu037FEINcG76pGBYQmH2xL wjNbde8t3RptIIk6ZjGn3f5qDEUs27CgKkL2Zc7bZJN6ZKccROVWvqhqlU4MWw== 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 4TJcg222cPz19lt; Mon, 22 Jan 2024 17:30:06 +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 40MHU6JX009488; Mon, 22 Jan 2024 17:30:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40MHU6Ua009483; Mon, 22 Jan 2024 17:30:06 GMT (envelope-from git) Date: Mon, 22 Jan 2024 17:30:06 GMT Message-Id: <202401221730.40MHU6Ua009483@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 482ab31c64cd - stable/13 - bhyveload: support guest rebooting from the loader 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 482ab31c64cd6da8f1044eaef87212581dc4884d Auto-Submitted: auto-generated The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=482ab31c64cd6da8f1044eaef87212581dc4884d commit 482ab31c64cd6da8f1044eaef87212581dc4884d Author: Kyle Evans AuthorDate: 2024-01-05 06:21:15 +0000 Commit: Kyle Evans CommitDate: 2024-01-22 17:17:52 +0000 bhyveload: support guest rebooting from the loader userboot has a EXIT_REBOOT code that it uses when the 'reboot' loader command is executed. Use that and longjmp back to reinit the VM entirely with a reboot request. This fixes the 'reboot' option in the loader menu to actually reboot rather than shutdown the VM. The JMP_* constants are introduced to keep track of why we're doing a longjmp, though they aren't currently used. We'll notably still do a complete reload of the interpreter to give the rebooted VM that new loader smell. It just seemed forward thinking to just keep track of the different setjmp points. While we're here, we don't actually need to keep the fd we passed to fdlopen(3), so let's avoid leaking it. Reviewed by: markj (cherry picked from commit 24cd5c26fe3ef7181e85467d9d55afbd76af5a2c) --- usr.sbin/bhyveload/bhyveload.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyveload/bhyveload.c b/usr.sbin/bhyveload/bhyveload.c index d4f282bcc178..f2a91f95ce89 100644 --- a/usr.sbin/bhyveload/bhyveload.c +++ b/usr.sbin/bhyveload/bhyveload.c @@ -89,6 +89,16 @@ #define NDISKS 32 +/* + * Reason for our loader reload and reentry, though these aren't really used + * at the moment. + */ +enum { + /* 0 cannot be allocated; setjmp(3) return. */ + JMP_SWAPLOADER = 0x01, + JMP_REBOOT, +}; + static struct termios term, oldterm; static int disk_fd[NDISKS]; static int ndisks; @@ -542,6 +552,8 @@ cb_exit(void *arg __unused, int v) { tcsetattr(consout_fd, TCSAFLUSH, &oldterm); + if (v == USERBOOT_EXIT_REBOOT) + longjmp(jb, JMP_REBOOT); exit(v); } @@ -625,7 +637,7 @@ cb_swap_interpreter(void *arg __unused, const char *interp_req) if (asprintf(&loader, "userboot_%s.so", interp_req) == -1) err(EX_OSERR, "malloc"); - longjmp(jb, 1); + longjmp(jb, JMP_SWAPLOADER); } static struct loader_callbacks cb = { @@ -766,6 +778,8 @@ loader_open(int bootfd) loader_hdl = fdlopen(fd, RTLD_LOCAL); if (!loader_hdl) errx(EX_OSERR, "dlopen: %s", dlerror()); + if (fd != explicit_loader_fd) + close(fd); } int