if (child == -1) { + EPRINTLN("Monitor mode fork failed: %s", + strerror(errno)); + exit(BHYVE_EXIT_ERROR); + } + if (child == 0) + break; + while ((error = waitpid(child, &status, 0)) == -1 && errno == EINTR) + ; + if (error == -1) { + EPRINTLN("Monitor mode wait failed: %s", + strerror(errno)); + exit(BHYVE_EXIT_ERROR); + } + if (WIFSIGNALED(status)) { + EPRINTLN("Child process was killed by signal %d", + WTERMSIG(status)); + exit(BHYVE_EXIT_ERROR); + } else { + status = WEXITSTATUS(status); + if (status != BHYVE_EXIT_RESET) + exit(status); + } + if (vm_reinit(ctx) != 0) { + EPRINTLN("Monitor mode reinit failed: %s", + strerror(errno)); + exit(BHYVE_EXIT_ERROR); + }; + } + } + bsp = vm_vcpu_open(ctx, BSP); max_vcpus = num_vcpus_allowed(ctx, bsp); if (guest_ncpus > max_vcpus) { @@ -880,23 +937,6 @@ main(int argc, char *argv[]) vcpu_info[vcpuid].vcpu = vm_vcpu_open(ctx, vcpuid); } - calc_mem_affinity(memsize); - memflags = 0; - if (get_config_bool_default("memory.wired", false)) - memflags |= VM_MEM_F_WIRED; - if (get_config_bool_default("memory.guest_in_core", false)) - memflags |= VM_MEM_F_INCORE; - vm_set_memflags(ctx, memflags); - error = vm_setup_memory_domains(ctx, VM_MMAP_ALL, guest_domains, - guest_ndomains); - if (error) { - fprintf(stderr, "Unable to setup memory (%d)\n", errno); - exit(4); - } - - set_vcpu_affinities(); - init_mem(guest_ncpus); - init_bootrom(ctx); if (bhyve_init_platform(ctx, bsp) != 0) exit(BHYVE_EXIT_ERROR); diff --git a/usr.sbin/bhyve/riscv/bhyverun_machdep.c b/usr.sbin/bhyve/riscv/bhyverun_machdep.c index f4c248ee662a..a90a508901bc 100644 --- a/usr.sbin/bhyve/riscv/bhyverun_machdep.c +++ b/usr.sbin/bhyve/riscv/bhyverun_machdep.c @@ -101,6 +101,7 @@ bhyve_usage(int code) " -D: destroy on power-off\n" " -h: help\n" " -k: key=value flat config file\n" + " -M: monitor mode\n" " -m: memory size\n" " -o: set config 'var' to 'value'\n" " -p: pin 'vcpu' to 'hostcpu'\n" @@ -119,7 +120,7 @@ bhyve_optparse(int argc, char **argv) const char *optstr; int c; - optstr = "hCDSWk:f:o:p:c:s:m:U:"; + optstr = "hCDMSWk:f:o:p:c:s:m:U:"; while ((c = getopt(argc, argv, optstr)) != -1) { switch (c) { case 'c': @@ -137,6 +138,9 @@ bhyve_optparse(int argc, char **argv) case 'k': bhyve_parse_simple_config_file(optarg); break; + case 'M': + set_config_bool("monitor", true); + break; case 'm': set_config_value("memory.size", optarg); break;