From nobody Fri Jan 05 06:22:05 2024 X-Original-To: dev-commits-src-main@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 4T5tf5673yz56F84; Fri, 5 Jan 2024 06:22:05 +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 4T5tf55Sg1z4lNP; Fri, 5 Jan 2024 06:22:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704435725; 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=7zc8Yu3Sai3+AW3g5A8SZyErXlhjy6mAxUH8FmM3Ga0=; b=eEBXVJzfJeXHP967p80OcoqLCurL/32sgC2Awf1TFASU1SXmj18njWOUpJSeY0XvOfdjCa 3nDOGHmmZkQupwecIj2RVoZnNbiamxSDS4qiPbrH/dTBh4fyyVJ/7GF05RHXt8q3qZ0LXc NnH98SbhYgLlxFmaZ0aoZTIkVVXPEWR4N5I9MYe4PT5wPHpYcr+2KLZ15zPY8Tgmo2lWN3 +PKiQdDb5ML4xmtPV1t4n+zMPXQkPEAHGpmRa3QmIBrqjEXnKZGWzvo5iVjRB9eVIvK5vx 1NDKBV0pd9Vmeu4q4pU61czttQtJboKrvmoc+Mc851Fl5Um2mHyXqcwA2pm2og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704435725; 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=7zc8Yu3Sai3+AW3g5A8SZyErXlhjy6mAxUH8FmM3Ga0=; b=lYgxQPk06/YHApxBokywR5bTpYCOrLnHyyLBnyQU/wc19WLJmLxbDNRu8ZuYXn2QIJQLYD Qb6N+f29drna69Dk13GhBvNBFjUh/2JBhyt6uWHmnSix//wZB/rSQ6FuXdkjevZj5jVyAZ jxhzixGX+aOW/iXA47xcrSCD5q1ElDsl6EmBZhbKKwo4SL5XdMPBkSazkVGfbP7foEy9UU 2ogOsW7bsCaDeKQs3uxTzOgJJwm0hL0Kmxuw66eiLhkKoCNt1BPwB3sh+eFznzeiPhq5qO CxhiMClD7ajkYK+nG7OuOV1dx8GSbfZvzNUipMAgM2W08OveHoEfij/aTmYSxA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704435725; a=rsa-sha256; cv=none; b=LJSWLcydE/l7P/Hh2dlhU65c1kcQCYtSJf7BdyI1aelezQKaRVWUyrsBYVScItxut2qGNt P5CDuREhi+sd4jVlHD9rqL3H9pXKIL90R9YQhR3L4fdKSzSI+sVOA8FaIgQLDQQypEc88Y mjJ3xaCvrWOyl+iRcsNuzP+72CGUXFPgK7qrTvpW+/HsS9DzeetruNtzV6N0JBq4cW5Dn7 s/Ss/hiAlZJz3n0Ceo+ycUDXXWggx58ruOSb50VafmaRdx/FfUXMKEfMEdFUWvtUtL0ayb JFa6SKkQR7z0EJCjK95Xz/MglODRyN0/0Cm1RBCj6MnSNtOjjBeE6dBCbQt0Yg== 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 4T5tf54WPlzmQ7; Fri, 5 Jan 2024 06:22:05 +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 4056M5YY029020; Fri, 5 Jan 2024 06:22:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4056M58o029017; Fri, 5 Jan 2024 06:22:05 GMT (envelope-from git) Date: Fri, 5 Jan 2024 06:22:05 GMT Message-Id: <202401050622.4056M58o029017@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 24cd5c26fe3e - main - bhyveload: support guest rebooting from the loader List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 24cd5c26fe3ef7181e85467d9d55afbd76af5a2c Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=24cd5c26fe3ef7181e85467d9d55afbd76af5a2c commit 24cd5c26fe3ef7181e85467d9d55afbd76af5a2c Author: Kyle Evans AuthorDate: 2024-01-05 06:21:15 +0000 Commit: Kyle Evans CommitDate: 2024-01-05 06:21:15 +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 Differential Revision: https://reviews.freebsd.org/D43300 --- 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 f75ef27dd958..37338e77d621 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