From nobody Mon Jan 22 17:30:03 2024 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 4TJcfz5pMRz57r6T; Mon, 22 Jan 2024 17:30:03 +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 4TJcfz4ykGz4f6t; Mon, 22 Jan 2024 17:30:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705944603; 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=6d/BZFWchlz1MyCAENYTn281nVx3WR7GhLN0oTaZWgQ=; b=TRqTvgbyY6eCkBC7iEzfqzk5K1YVGQmX5ppDSCriZwB9wDE5N/PVDmr7n5AnUxMh518I4i 7+EOCAQMlPamtFUlojU8L/VzvXCvAH+aleoxynfymPFq2a1FjwsRor6o23qtySeGslb2QP Q4L4rNljSExoNxMnmhHF1FYwp60NX2C0lOCh+slX2njzbRBDkZ4QEOQiDANJw610QKxWYT 8nyZ5nkh/2/uBsNSNcZ8tNVutXEIlz17DooyfzAfWYaqksX6crA8GLvQWsycpDpdiqUnQP tdq3Xr07OxsXF1XSBdCb3GTwaIKN97yE2ZqUCUICMbwZ7feWMCl/t4yPNd0Xhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705944603; 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=6d/BZFWchlz1MyCAENYTn281nVx3WR7GhLN0oTaZWgQ=; b=w6mbxo4AWQkSi6PyDfDRC307gTt6DhHC6eKOxcfCVbaTgItRv+bWjyL7ElP2upWbmok870 5KMWtmFF7iHOJwpO0Dy2DQm92tt9jnxS4GyAFcNMpjY2y15/6+iB0ll+Z8FRzkKvQcKBY2 JUomjkctaeRTqz/8OyGQ8WpE2mAP4MgMJKSQybMyDHGufIfdb/jOTNGf41vQlla3TSRowC yy52VJnoXBZ45ROuyJ2C4lQtD4lBpErZn4YJoVwuHXhWH+HisbszqYmQvIwEVYqMD4LaMT +/6kRIrYy6w0ssvQRkPqW+HVKB8SI0xV7CoyIy7mPNl5oztarae8wMoUNYBcjg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705944603; a=rsa-sha256; cv=none; b=yg6cyQkFXf1t9SwHms7Q3oBjeXG6jrJYqvY0exbtCzoErUjopI+Yb7Dh8vBeBL0WpzRHU8 vjnXE/pUDUdhaNROt9RX56yqLa5EccUmfTohYoxXMiIsx6JK1oo4DgSWlRTw3LgScj9vjT d5R1zQVUYhKe4sOKXXjlKR15Ql1TznDBcL/2At4rs/A4tWlvNhxVos8ihSM2SUVFGAIz2w 0jS9alrbwmUdCBKGYC5kSz0C2SOGZhattzPS/9/I8P6LqhkV5LzPnbhjngfvYx6BrBV01I aA2tmXSI32lqcAy8orgrS4Wj8rLtYMWH5XhtgPPCkMXB1KIQOdnaieqjnkp+Mg== 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 4TJcfz44qtz19Zg; Mon, 22 Jan 2024 17:30:03 +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 40MHU3VZ008648; Mon, 22 Jan 2024 17:30:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40MHU3m0008644; Mon, 22 Jan 2024 17:30:03 GMT (envelope-from git) Date: Mon, 22 Jan 2024 17:30:03 GMT Message-Id: <202401221730.40MHU3m0008644@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: 3b01995df47a - stable/14 - bhyveload: support guest rebooting from the loader 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 3b01995df47a0184ecbb6777b88a3a0bd3c6797c Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=3b01995df47a0184ecbb6777b88a3a0bd3c6797c commit 3b01995df47a0184ecbb6777b88a3a0bd3c6797c Author: Kyle Evans AuthorDate: 2024-01-05 06:21:15 +0000 Commit: Kyle Evans CommitDate: 2024-01-22 17:18:58 +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 16131dacecaa..4f16f58bfc9f 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; @@ -543,6 +553,8 @@ cb_exit(void *arg __unused, int v) { tcsetattr(consout_fd, TCSAFLUSH, &oldterm); + if (v == USERBOOT_EXIT_REBOOT) + longjmp(jb, JMP_REBOOT); exit(v); } @@ -628,7 +640,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 = { @@ -769,6 +781,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