The branch main has been updated by bnovkov: URL: https://cgit.FreeBSD.org/src/commit/?id=ef821f9ba66af44cd7a760451ecd706cd24b1ecb
commit ef821f9ba66af44cd7a760451ecd706cd24b1ecb Author: Bojan Novković <[email protected]> AuthorDate: 2026-08-23 12:56:31 +0000 Commit: Bojan Novković <[email protected]> CommitDate: 2026-09-18 10:28:32 +0000 bhyve: Add an option to prevent automatic restart in monitor mode Monitor mode will currently unconditionally restart the guest if it reboots, which can be incovenient in certain situations (e.g., resetting the guest after a panic). Address this by introducing a way to prevent automatic guest restarts in monitor mode. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D59123 --- usr.sbin/bhyve/aarch64/bhyverun_machdep.c | 9 +++++++-- usr.sbin/bhyve/amd64/bhyverun_machdep.c | 11 ++++++++--- usr.sbin/bhyve/bhyve.8 | 11 +++++++++-- usr.sbin/bhyve/bhyve_config.5 | 9 +++++++-- usr.sbin/bhyve/bhyverun.c | 7 ++++--- usr.sbin/bhyve/riscv/bhyverun_machdep.c | 9 +++++++-- 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/usr.sbin/bhyve/aarch64/bhyverun_machdep.c b/usr.sbin/bhyve/aarch64/bhyverun_machdep.c index 1f13ad38dedb..311170c6952b 100644 --- a/usr.sbin/bhyve/aarch64/bhyverun_machdep.c +++ b/usr.sbin/bhyve/aarch64/bhyverun_machdep.c @@ -112,6 +112,7 @@ bhyve_usage(int code) " -k: key=value flat config file\n" " -M: monitor mode\n" " -m: memory size\n" + " -N: don't reboot while in monitor mode\n" " -o: set config 'var' to 'value'\n" " -p: pin 'vcpu' to 'hostcpu'\n" " -S: guest memory cannot be swapped\n" @@ -129,7 +130,7 @@ bhyve_optparse(int argc, char **argv) const char *optstr; int c; - optstr = "hCDMSWk:f:o:p:G:c:s:m:U:"; + optstr = "hCDMNSWk:f:o:p:G:c:s:m:U:"; while ((c = getopt(argc, argv, optstr)) != -1) { switch (c) { case 'c': @@ -154,7 +155,10 @@ bhyve_optparse(int argc, char **argv) set_config_value("memory.size", optarg); break; case 'M': - set_config_bool("monitor", true); + set_config_bool("monitor.enabled", true); + break; + case 'N': + set_config_bool("monitor.no_reboot", true); break; case 'o': if (!bhyve_parse_config_option(optarg)) { @@ -196,6 +200,7 @@ bhyve_optparse(int argc, char **argv) /* Handle backwards compatibility aliases in config options. */ bhyve_cfg_warn("virtio_msix", "virtio.msix"); + bhyve_cfg_warn("monitor", "monitor.enabled"); } void diff --git a/usr.sbin/bhyve/amd64/bhyverun_machdep.c b/usr.sbin/bhyve/amd64/bhyverun_machdep.c index ea1bad0d4eaa..3d498879cd58 100644 --- a/usr.sbin/bhyve/amd64/bhyverun_machdep.c +++ b/usr.sbin/bhyve/amd64/bhyverun_machdep.c @@ -98,6 +98,7 @@ bhyve_usage(int code) " -l: LPC device configuration\n" " -M: monitor mode\n" " -m: memory size\n" + " -N: don't reboot while in monitor mode\n" " -n: NUMA domain specification\n" " -o: set config 'var' to 'value'\n" " -P: vmexit from the guest on pause\n" @@ -125,9 +126,9 @@ bhyve_optparse(int argc, char **argv) int c; #ifdef BHYVE_SNAPSHOT - optstr = "aehuwxACDHIMPSWYk:f:o:p:G:c:s:m:n:l:K:U:r:"; + optstr = "aehuwxACDHIMNPSWYk:f:o:p:G:c:s:m:n:l:K:U:r:"; #else - optstr = "aehuwxACDHIMPSWYk:f:o:p:G:c:s:m:n:l:K:U:"; + optstr = "aehuwxACDHIMNPSWYk:f:o:p:G:c:s:m:n:l:K:U:"; #endif while ((c = getopt(argc, argv, optstr)) != -1) { switch (c) { @@ -203,7 +204,7 @@ bhyve_optparse(int argc, char **argv) set_config_value("memory.size", optarg); break; case 'M': - set_config_bool("monitor", true); + set_config_bool("monitor.enabled", true); break; case 'n': if (bhyve_numa_parse(optarg) != 0) @@ -214,6 +215,9 @@ bhyve_optparse(int argc, char **argv) if (!get_config_bool("acpi_tables")) errx(EX_USAGE, "NUMA emulation requires ACPI"); break; + case 'N': + set_config_bool("monitor.no_reboot", true); + break; case 'o': if (!bhyve_parse_config_option(optarg)) { errx(EX_USAGE, @@ -268,6 +272,7 @@ bhyve_optparse(int argc, char **argv) bhyve_cfg_warn("lpc.bootrom", "bootrom"); bhyve_cfg_warn("lpc.bootvars", "bootvars"); bhyve_cfg_warn("virtio_msix", "virtio.msix"); + bhyve_cfg_warn("monitor", "monitor.enabled"); } void diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8 index 2203f7dc17c7..a0b79e83d4ab 100644 --- a/usr.sbin/bhyve/bhyve.8 +++ b/usr.sbin/bhyve/bhyve.8 @@ -26,7 +26,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd June 5, 2026 +.Dd August 23, 2026 .Dt BHYVE 8 .Os .Sh NAME @@ -34,7 +34,7 @@ .Nd "run a guest operating system inside a virtual machine" .Sh SYNOPSIS .Nm -.Op Fl aCDeHhMPSuWwxY +.Op Fl aCDeHhMNPSuWwxY .Oo .Sm off .Fl c\~ @@ -345,6 +345,13 @@ See the flag in .Xr cpuset 1 for a list of valid NUMA memory allocation policies and their formats. +.It Fl N +Prevent monitor mode from automatically rebooting the virtual machine. +This option has no effect unless the +.Va monitor.enabled +configuration option is enabled or +.Fl M +was specified. .It Fl o Ar var Ns Cm = Ns Ar value Set the configuration variable .Ar var diff --git a/usr.sbin/bhyve/bhyve_config.5 b/usr.sbin/bhyve/bhyve_config.5 index aca87bbe08b1..37a740aec3ec 100644 --- a/usr.sbin/bhyve/bhyve_config.5 +++ b/usr.sbin/bhyve/bhyve_config.5 @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd August 14, 2026 +.Dd September 17, 2026 .Dt BHYVE_CONFIG 5 .Os .Sh NAME @@ -236,12 +236,17 @@ to store its service files, such as the checkpoint socket. Overriding this path is useful when running .Xr bhyve 8 as an unprivileged user. -.It Va monitor Ta bool Ta false Ta +.It Va monitor.enabled Ta bool Ta false Ta Run the VM in .Ql monitor mode. More details are provided in .Xr bhyve 8 . +.It Va monitor.no_reboot Ta bool Ta false Ta +Prevent monitor mode from automatically rebooting the virtual machine. +This option has no effect unless the +.Va monitor.enabled +configuration option is enabled. .It Va vcpu.N.cpuset Ta string Ta none Ta Comma-separated host CPU IDs and ranges to which virtual CPU .Em N diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index aa1a28f406e0..eec5bf2fb629 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -752,7 +752,7 @@ do_open(const char *vmname) int error, flags; bool romboot, monitor; - monitor = get_config_bool_default("monitor", false); + monitor = get_config_bool_default("monitor.enabled", false); romboot = bootrom_boot(); /* @@ -943,7 +943,7 @@ main(int argc, char *argv[]) init_mem(guest_ncpus); init_bootrom(ctx); - if (get_config_bool_default("monitor", false)) { + if (get_config_bool_default("monitor.enabled", false)) { int monitor_pipe[2]; pid_t child; @@ -978,7 +978,8 @@ main(int argc, char *argv[]) exit(BHYVE_EXIT_ERROR); } else { status = WEXITSTATUS(status); - if (status != BHYVE_EXIT_RESET) + if (get_config_bool_default("monitor.no_reboot", false) || + status != BHYVE_EXIT_RESET) exit(status); } if (vm_reinit(ctx) != 0) { diff --git a/usr.sbin/bhyve/riscv/bhyverun_machdep.c b/usr.sbin/bhyve/riscv/bhyverun_machdep.c index b467ff9f52d9..50e68c958ab3 100644 --- a/usr.sbin/bhyve/riscv/bhyverun_machdep.c +++ b/usr.sbin/bhyve/riscv/bhyverun_machdep.c @@ -106,6 +106,7 @@ bhyve_usage(int code) " -k: key=value flat config file\n" " -M: monitor mode\n" " -m: memory size\n" + " -N: don't reboot while in monitor mode\n" " -o: set config 'var' to 'value'\n" " -p: pin 'vcpu' to 'hostcpu'\n" " -S: guest memory cannot be swapped\n" @@ -123,7 +124,7 @@ bhyve_optparse(int argc, char **argv) const char *optstr; int c; - optstr = "hCDMSWk:f:o:p:c:s:m:U:"; + optstr = "hCDMNSWk:f:o:p:c:s:m:U:"; while ((c = getopt(argc, argv, optstr)) != -1) { switch (c) { case 'c': @@ -142,11 +143,14 @@ bhyve_optparse(int argc, char **argv) bhyve_parse_simple_config_file(optarg); break; case 'M': - set_config_bool("monitor", true); + set_config_bool("monitor.enabled", true); break; case 'm': set_config_value("memory.size", optarg); break; + case 'N': + set_config_bool("monitor.no_reboot", true); + break; case 'o': if (!bhyve_parse_config_option(optarg)) { errx(EX_USAGE, @@ -187,6 +191,7 @@ bhyve_optparse(int argc, char **argv) /* Handle backwards compatibility aliases in config options. */ bhyve_cfg_warn("virtio_msix", "virtio.msix"); + bhyve_cfg_warn("monitor", "monitor.enabled"); } void
