bhyve: Register hlt and pause vmexit handlers unconditionally

These exit handlers might not be used if the corresponding VM
capabilities are not set, but there is no harm in putting them into the
handler table regardless.  Doing so simplifies initialization code,
makes it easier to split vmexit handlers into a separate file, and lets
us declare the handler table as const.

Reviewed by:	corvink, jhb
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40572
This commit is contained in:
Mark Johnston 2023-06-19 15:46:02 -04:00
parent 1da1a26436
commit 15c1f0cc2c

View File

@ -930,7 +930,7 @@ vmexit_ipi(struct vmctx *ctx __unused, struct vcpu *vcpu __unused,
return (error);
}
static vmexit_handler_t handler[VM_EXITCODE_MAX] = {
static const vmexit_handler_t handler[VM_EXITCODE_MAX] = {
[VM_EXITCODE_INOUT] = vmexit_inout,
[VM_EXITCODE_INOUT_STR] = vmexit_inout,
[VM_EXITCODE_VMX] = vmexit_vmx,
@ -946,6 +946,8 @@ static vmexit_handler_t handler[VM_EXITCODE_MAX] = {
[VM_EXITCODE_DEBUG] = vmexit_debug,
[VM_EXITCODE_BPT] = vmexit_breakpoint,
[VM_EXITCODE_IPI] = vmexit_ipi,
[VM_EXITCODE_HLT] = vmexit_hlt,
[VM_EXITCODE_PAUSE] = vmexit_pause,
};
static void
@ -1012,7 +1014,7 @@ num_vcpus_allowed(struct vmctx *ctx, struct vcpu *vcpu)
}
static void
fbsdrun_set_capabilities(struct vcpu *vcpu, bool bsp)
fbsdrun_set_capabilities(struct vcpu *vcpu)
{
int err, tmp;
@ -1023,8 +1025,6 @@ fbsdrun_set_capabilities(struct vcpu *vcpu, bool bsp)
exit(4);
}
vm_set_capability(vcpu, VM_CAP_HALT_EXIT, 1);
if (bsp)
handler[VM_EXITCODE_HLT] = vmexit_hlt;
}
if (get_config_bool_default("x86.vmexit_on_pause", false)) {
@ -1038,8 +1038,6 @@ fbsdrun_set_capabilities(struct vcpu *vcpu, bool bsp)
exit(4);
}
vm_set_capability(vcpu, VM_CAP_PAUSE_EXIT, 1);
if (bsp)
handler[VM_EXITCODE_PAUSE] = vmexit_pause;
}
if (get_config_bool_default("x86.x2apic", false))
@ -1130,7 +1128,7 @@ spinup_vcpu(struct vcpu_info *vi, bool bsp)
int error;
if (!bsp) {
fbsdrun_set_capabilities(vi->vcpu, false);
fbsdrun_set_capabilities(vi->vcpu);
/*
* Enable the 'unrestricted guest' mode for APs.
@ -1432,7 +1430,7 @@ main(int argc, char *argv[])
exit(4);
}
fbsdrun_set_capabilities(bsp, true);
fbsdrun_set_capabilities(bsp);
/* Allocate per-VCPU resources. */
vcpu_info = calloc(guest_ncpus, sizeof(*vcpu_info));