diff options
| author | ShengYi Hung <aokblast@FreeBSD.org> | 2026-07-10 09:21:11 +0000 |
|---|---|---|
| committer | ShengYi Hung <aokblast@FreeBSD.org> | 2026-07-11 08:39:36 +0000 |
| commit | 86691d52a6d3796ad36ba474cf0a9493f6d99202 (patch) | |
| tree | 8041e39ceac47a4ea3bcb1406e5dfe20a809bd57 | |
| parent | 9bb576da3f6089ccb423966d65918e1fce346a32 (diff) | |
kvm: Support non-default CPUID leaf
KVM does not always use 0x40000000 as its CPUID base. For example, QEMU
adds a 0x100 offset when nested virtualization is detected and the host
exposes Hyper-V enlightenment hints. To accommodate this behavior,
switch the detection logic to use the CPUID leaf returned by do_cpuid(),
making the implementation more flexible.
See:
https://github.com/qemu/qemu/blob/master/target/i386/kvm/kvm.c#L2300
Reviewed by: kib
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D58146
| -rw-r--r-- | sys/x86/include/kvm.h | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/sys/x86/include/kvm.h b/sys/x86/include/kvm.h index 83dd20fa8d23..5414075f89d6 100644 --- a/sys/x86/include/kvm.h +++ b/sys/x86/include/kvm.h @@ -45,7 +45,7 @@ #include <machine/md_var.h> #define KVM_CPUID_SIGNATURE 0x40000000 -#define KVM_CPUID_FEATURES_LEAF 0x40000001 +#define KVM_CPUID_FEATURES_LEAF(base) ((base) + 1) #define KVM_FEATURE_CLOCKSOURCE 0x00000001 #define KVM_FEATURE_CLOCKSOURCE2 0x00000008 @@ -63,8 +63,7 @@ static inline bool kvm_cpuid_features_leaf_supported(void) { return (vm_guest == VM_GUEST_KVM && - KVM_CPUID_FEATURES_LEAF > hv_base && - KVM_CPUID_FEATURES_LEAF <= hv_high); + KVM_CPUID_FEATURES_LEAF(hv_base) <= hv_high); } static inline void @@ -73,7 +72,7 @@ kvm_cpuid_get_features(u_int *regs) if (!kvm_cpuid_features_leaf_supported()) regs[0] = regs[1] = regs[2] = regs[3] = 0; else - do_cpuid(KVM_CPUID_FEATURES_LEAF, regs); + do_cpuid(KVM_CPUID_FEATURES_LEAF(hv_base), regs); } #endif /* !_X86_KVM_H_ */ |
