The branch main has been updated by aokblast: URL: https://cgit.FreeBSD.org/src/commit/?id=86691d52a6d3796ad36ba474cf0a9493f6d99202
commit 86691d52a6d3796ad36ba474cf0a9493f6d99202 Author: ShengYi Hung <[email protected]> AuthorDate: 2026-07-10 09:21:11 +0000 Commit: ShengYi Hung <[email protected]> CommitDate: 2026-07-11 08:39:36 +0000 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 --- sys/x86/include/kvm.h | 7 +++---- 1 file 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_ */
