diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index cf3584112ca..99194f24e18 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -98,7 +98,7 @@ static int acpi; static char *progname; static const int BSP = 0; -static int cpumask; +static cpuset_t cpumask; static void vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip); @@ -199,30 +199,26 @@ fbsdrun_start_thread(void *param) } void -fbsdrun_addcpu(struct vmctx *ctx, int vcpu, uint64_t rip) +fbsdrun_addcpu(struct vmctx *ctx, int fromcpu, int newcpu, uint64_t rip) { int error; - if (cpumask & (1 << vcpu)) { - fprintf(stderr, "addcpu: attempting to add existing cpu %d\n", - vcpu); - exit(1); - } + assert(fromcpu == BSP); - atomic_set_int(&cpumask, 1 << vcpu); + CPU_SET_ATOMIC(newcpu, &cpumask); /* * Set up the vmexit struct to allow execution to start * at the given RIP */ - vmexit[vcpu].rip = rip; - vmexit[vcpu].inst_length = 0; + vmexit[newcpu].rip = rip; + vmexit[newcpu].inst_length = 0; - mt_vmm_info[vcpu].mt_ctx = ctx; - mt_vmm_info[vcpu].mt_vcpu = vcpu; + mt_vmm_info[newcpu].mt_ctx = ctx; + mt_vmm_info[newcpu].mt_vcpu = newcpu; - error = pthread_create(&mt_vmm_info[vcpu].mt_thr, NULL, - fbsdrun_start_thread, &mt_vmm_info[vcpu]); + error = pthread_create(&mt_vmm_info[newcpu].mt_thr, NULL, + fbsdrun_start_thread, &mt_vmm_info[newcpu]); assert(error == 0); } @@ -230,14 +226,14 @@ static int fbsdrun_deletecpu(struct vmctx *ctx, int vcpu) { - if ((cpumask & (1 << vcpu)) == 0) { + if (!CPU_ISSET(vcpu, &cpumask)) { fprintf(stderr, "addcpu: attempting to delete unknown cpu %d\n", vcpu); exit(1); } - atomic_clear_int(&cpumask, 1 << vcpu); - return (cpumask == 0); + CPU_CLR_ATOMIC(vcpu, &cpumask); + return (CPU_EMPTY(&cpumask)); } static int @@ -745,7 +741,7 @@ main(int argc, char *argv[]) /* * Add CPU 0 */ - fbsdrun_addcpu(ctx, BSP, rip); + fbsdrun_addcpu(ctx, BSP, BSP, rip); /* * Head off to the main event dispatch loop diff --git a/usr.sbin/bhyve/bhyverun.h b/usr.sbin/bhyve/bhyverun.h index 738d5b68bb0..f18d42fc3f0 100644 --- a/usr.sbin/bhyve/bhyverun.h +++ b/usr.sbin/bhyve/bhyverun.h @@ -43,7 +43,7 @@ extern char *vmname; void *paddr_guest2host(struct vmctx *ctx, uintptr_t addr, size_t len); void fbsdrun_set_capabilities(struct vmctx *ctx, int cpu); -void fbsdrun_addcpu(struct vmctx *ctx, int cpu, uint64_t rip); +void fbsdrun_addcpu(struct vmctx *ctx, int fromcpu, int newcpu, uint64_t rip); int fbsdrun_muxed(void); int fbsdrun_vmexit_on_hlt(void); int fbsdrun_vmexit_on_pause(void); diff --git a/usr.sbin/bhyve/spinup_ap.c b/usr.sbin/bhyve/spinup_ap.c index 729108ae1ee..c597023aeb4 100644 --- a/usr.sbin/bhyve/spinup_ap.c +++ b/usr.sbin/bhyve/spinup_ap.c @@ -98,7 +98,7 @@ spinup_ap(struct vmctx *ctx, int vcpu, int newcpu, uint64_t rip) spinup_ap_realmode(ctx, newcpu, &rip); - fbsdrun_addcpu(ctx, newcpu, rip); + fbsdrun_addcpu(ctx, vcpu, newcpu, rip); return (newcpu); }