x86/cpu: introduce an optional hook for early hypervisor initialization

Hypervisor detection is done very early on x86, and so can be used to also do
some very early hypervisor related initialization.  Such initialization is
required when running as a Xen PVH guest, as for example the PIT needs to be
replaced with an hypervisor based timecounter.

Introduce an optional hook that gets called as part of the early hypervisor
detection.

No functional change intended.

Sponsored by: Cloud Software Group
Reviewed by: markj kib
Differential revision: https://reviews.freebsd.org/D43763
This commit is contained in:
Roger Pau Monné 2024-02-02 11:36:52 +01:00
parent f0cf86c075
commit 4401b06851

View file

@ -1343,6 +1343,7 @@ SYSINIT(hook_tsc_freq, SI_SUB_CONFIGURE, SI_ORDER_ANY, hook_tsc_freq, NULL);
static struct {
const char *vm_cpuid;
int vm_guest;
void (*init)(void);
} vm_cpuids[] = {
{ "XenVMMXenVMM", VM_GUEST_XEN }, /* XEN */
{ "Microsoft Hv", VM_GUEST_HV }, /* Microsoft Hyper-V */
@ -1355,6 +1356,7 @@ static struct {
static void
identify_hypervisor_cpuid_base(void)
{
void (*init_fn)(void) = NULL;
u_int leaf, regs[4];
int i;
@ -1391,6 +1393,7 @@ identify_hypervisor_cpuid_base(void)
if (strncmp((const char *)&regs[1],
vm_cpuids[i].vm_cpuid, 12) == 0) {
vm_guest = vm_cpuids[i].vm_guest;
init_fn = vm_cpuids[i].init;
break;
}
@ -1423,10 +1426,13 @@ identify_hypervisor_cpuid_base(void)
* preferred.
*/
vm_guest != VM_GUEST_HV)
return;
break;
}
}
}
if (init_fn != NULL)
init_fn();
}
void