bhyve: fix resume for vms with guest_ncpus > 1

This error occurs because vm->vcpu[1] has not been allocated yet when
vm_snapshot_vm() is called.

To fix this, move spinup_vcpu() before restore code.

Reviewed by:		corvink, markj
MFC after:		2 weeks
Sponsored by:		vStack
Differential Revision:	https://reviews.freebsd.org/D38477
This commit is contained in:
Vitaliy Gusev 2023-02-28 11:28:40 +01:00 committed by Corvin Köhne
parent 8104fc31a2
commit 9ff3e8b7f0
No known key found for this signature in database
GPG Key ID: D854DA56315E026A

View File

@ -552,7 +552,7 @@ fbsdrun_start_thread(void *param)
}
static void
fbsdrun_addcpu(struct vmctx *ctx, int newcpu, bool suspend)
fbsdrun_addcpu(struct vmctx *ctx, int newcpu)
{
int error;
@ -562,8 +562,7 @@ fbsdrun_addcpu(struct vmctx *ctx, int newcpu, bool suspend)
CPU_SET_ATOMIC(newcpu, &cpumask);
if (suspend)
vm_suspend_cpu(ctx, newcpu);
vm_suspend_cpu(ctx, newcpu);
mt_vmm_info[newcpu].mt_ctx = ctx;
mt_vmm_info[newcpu].mt_vcpu = newcpu;
@ -1138,7 +1137,7 @@ do_open(const char *vmname)
}
static void
spinup_vcpu(struct vmctx *ctx, int vcpu, bool suspend)
spinup_vcpu(struct vmctx *ctx, int vcpu)
{
int error;
@ -1154,7 +1153,7 @@ spinup_vcpu(struct vmctx *ctx, int vcpu, bool suspend)
assert(error == 0);
}
fbsdrun_addcpu(ctx, vcpu, suspend);
fbsdrun_addcpu(ctx, vcpu);
}
static bool
@ -1488,6 +1487,16 @@ main(int argc, char *argv[])
assert(error == 0);
}
/* Allocate per-VCPU resources. */
mt_vmm_info = calloc(guest_ncpus, sizeof(*mt_vmm_info));
/*
* Add all vCPUs.
*/
for (int vcpu = 0; vcpu < guest_ncpus; vcpu++) {
spinup_vcpu(ctx, vcpu);
}
#ifdef BHYVE_SNAPSHOT
if (restore_file != NULL) {
fprintf(stdout, "Pausing pci devs...\r\n");
@ -1564,9 +1573,6 @@ main(int argc, char *argv[])
#endif
#ifdef BHYVE_SNAPSHOT
if (restore_file != NULL)
destroy_restore_state(&rstate);
/* initialize mutex/cond variables */
init_snapshot();
@ -1576,24 +1582,18 @@ main(int argc, char *argv[])
if (init_checkpoint_thread(ctx) < 0)
printf("Failed to start checkpoint thread!\r\n");
if (restore_file != NULL)
if (restore_file != NULL) {
destroy_restore_state(&rstate);
vm_restore_time(ctx);
#endif
/* Allocate per-VCPU resources. */
mt_vmm_info = calloc(guest_ncpus, sizeof(*mt_vmm_info));
/*
* Add all vCPUs.
*/
for (int vcpu = 0; vcpu < guest_ncpus; vcpu++) {
bool suspend = (vcpu != BSP);
#ifdef BHYVE_SNAPSHOT
if (restore_file != NULL)
suspend = false;
#endif
spinup_vcpu(ctx, vcpu, suspend);
for (int i = 0; i < guest_ncpus; i++) {
if (i == BSP)
continue;
vm_resume_cpu(ctx, i);
}
}
#endif
vm_resume_cpu(ctx, BSP);
/*
* Head off to the main event dispatch loop