git: 03c3c444709d - main - vmm/amd64: support CPUID functions 0x40000100 and above

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 25 Nov 2026 21:35:56 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=03c3c444709d13fa9aa7046bbf9445272407e5a8

commit 03c3c444709d13fa9aa7046bbf9445272407e5a8
Author:     Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
AuthorDate: 2026-05-07 14:33:44 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-25 21:29:07 +0000

    vmm/amd64: support CPUID functions 0x40000100 and above
    
    CPUID functions 0x40000100 and above mirror the original contents of
    the hypervisor CPUID functions at 0x40000000. This allows a guest to
    query the real hypervisor signature and features when the the default
    hypervisor functions at 0x40000000 have been overridden to identify
    as something else, such as KVM or HyperV.
    
    Reviewed by:            chuck, markj
    MFC after:              1 month
    Sponsored by:           The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D60122
---
 sys/amd64/vmm/vmm_cpuid.c | 7 ++++++-
 sys/amd64/vmm/x86.h       | 2 ++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/sys/amd64/vmm/vmm_cpuid.c b/sys/amd64/vmm/vmm_cpuid.c
index 140c972df026..58fbce0cc5e3 100644
--- a/sys/amd64/vmm/vmm_cpuid.c
+++ b/sys/amd64/vmm/vmm_cpuid.c
@@ -538,6 +538,9 @@ legacy_emulate_cpuid(struct vcpu *vcpu, uint32_t *eax, uint32_t *ebx,
 	if (cpu_exthigh != 0 && func >= 0x80000000) {
 		if (func > cpu_exthigh)
 			func = cpu_exthigh;
+	} else if (func >= CPUID_VM_SIGNATURE + CPUID_VM_BHYVE_OFF) {
+		if (func > CPUID_VM_HIGH + CPUID_VM_BHYVE_OFF)
+			func = CPUID_VM_HIGH + CPUID_VM_BHYVE_OFF;
 	} else if (func >= CPUID_VM_SIGNATURE) {
 		if (func > CPUID_VM_HIGH)
 			func = CPUID_VM_HIGH;
@@ -1053,13 +1056,15 @@ legacy_emulate_cpuid(struct vcpu *vcpu, uint32_t *eax, uint32_t *ebx,
 			break;
 
 		case CPUID_VM_SIGNATURE:
-			regs[0] = CPUID_VM_HIGH;
+		case CPUID_VM_SIGNATURE + CPUID_VM_BHYVE_OFF:
+			regs[0] = CPUID_VM_HIGH + (func - CPUID_VM_SIGNATURE);
 			bcopy(bhyve_id, &regs[1], 4);
 			bcopy(bhyve_id + 4, &regs[2], 4);
 			bcopy(bhyve_id + 8, &regs[3], 4);
 			break;
 
 		case CPUID_BHYVE_FEATURES:
+		case CPUID_BHYVE_FEATURES + CPUID_VM_BHYVE_OFF:
 			regs[0] = CPUID_BHYVE_FEAT_EXT_DEST_ID;
 			regs[1] = 0;
 			regs[2] = 0;
diff --git a/sys/amd64/vmm/x86.h b/sys/amd64/vmm/x86.h
index 1bd05aea86e2..afd84207e576 100644
--- a/sys/amd64/vmm/x86.h
+++ b/sys/amd64/vmm/x86.h
@@ -60,6 +60,8 @@
 #define	CPUID_VM_SIGNATURE	0x40000000
 #define	CPUID_VM_HIGH		CPUID_BHYVE_FEATURES
 
+#define	CPUID_VM_BHYVE_OFF	0x100
+
 /*
  * CPUID instruction Fn0000_0001:
  */