git: 13643df2c8df - main - vmm/amd64: Bhyve returns bogus cpuid 8000_001D leaf

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

URL: https://cgit.FreeBSD.org/src/commit/?id=13643df2c8dfb3f7eed5b630135b98bac90a90a5

commit 13643df2c8dfb3f7eed5b630135b98bac90a90a5
Author:     Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
AuthorDate: 2025-10-17 16:29:32 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-25 21:29:06 +0000

    vmm/amd64: Bhyve returns bogus cpuid 8000_001D leaf
    
    This is a port of this bhyve improvement coming from illumos:
    
      16223 bhyve returns bogus cpuid 8000_001D leaf
      https://www.illumos.org/issues/16223
    
    This fixes an issue in the CPUID emulation discovered on AMD CPUs.
    
    Reviewed by:            chuck, corvink, markj
    MFC after:              1 month
    Sponsored by:           The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D53210
---
 sys/amd64/vmm/vmm_cpuid.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/sys/amd64/vmm/vmm_cpuid.c b/sys/amd64/vmm/vmm_cpuid.c
index 568042241243..3549578d7ddd 100644
--- a/sys/amd64/vmm/vmm_cpuid.c
+++ b/sys/amd64/vmm/vmm_cpuid.c
@@ -6,7 +6,7 @@
  *
  * Copyright 2014 Pluribus Networks Inc.
  * Copyright 2018 Joyent, Inc.
- * Copyright 2022 Oxide Computer Company
+ * Copyright 2024 Oxide Computer Company
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -564,10 +564,15 @@ legacy_emulate_cpuid(struct vcpu *vcpu, uint32_t *eax, uint32_t *ebx,
 				break;
 			}
 
-			logical_cpus = MIN(0xfff, logical_cpus - 1);
-			regs[0] = (logical_cpus << 14) | (1 << 8) |
-			    (level << 5) | func;
-			regs[1] = func > 0 ? CACHE_LINE_SIZE - 1 : 0;
+			if (level == 0) {
+				regs[0] = 0;
+				regs[1] = 0;
+			} else {
+				logical_cpus = MIN(0xfff, logical_cpus - 1);
+				regs[0] = (logical_cpus << 14) | (1 << 8) |
+				    (level << 5) | func;
+				regs[1] = func > 0 ? CACHE_LINE_SIZE - 1 : 0;
+			}
 
 			/*
 			 * ecx: Number of cache ways for non-fully