git: 8fb539b081db - main - amd64/vmm: Don't advertise AMD PerfMonV2 or performance counters

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Fri, 06 Nov 2026 15:57:30 UTC
The branch main has been updated by christos:

URL: https://cgit.FreeBSD.org/src/commit/?id=8fb539b081dbfe3e93e607a5d4d36184c53c8aaf

commit 8fb539b081dbfe3e93e607a5d4d36184c53c8aaf
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2026-11-02 17:15:33 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2026-11-06 15:57:18 +0000

    amd64/vmm: Don't advertise AMD PerfMonV2 or performance counters
    
    vmm does not handle CPUID leaf 0x80000022, so a FreeBSD guest on a
    Family 19h or later host panics on "kldload hwpmc", which trusts the
    PerfMonV2 bit and writes AMD_PMC_GLOBAL_CTL.
    
    Tested by:      Osvaldo Janeri Filho <ojanerif@amd.com>
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Reviewed by:    markj, kib
    Differential Revision:  https://reviews.freebsd.org/D61141
---
 sys/amd64/vmm/x86.c | 11 +++++++++++
 sys/amd64/vmm/x86.h |  1 +
 2 files changed, 12 insertions(+)

diff --git a/sys/amd64/vmm/x86.c b/sys/amd64/vmm/x86.c
index ee6be833cc7e..4c779c450d96 100644
--- a/sys/amd64/vmm/x86.c
+++ b/sys/amd64/vmm/x86.c
@@ -299,6 +299,17 @@ x86_emulate_cpuid(struct vcpu *vcpu, uint64_t *rax, uint64_t *rbx,
 			regs[3] = 0;
 			break;
 
+		case CPUID_8000_0022:
+			/*
+			 * AMD uses this leaf to advertise performance
+			 * counters and PerfMonV2. vmm implements neither.
+			 */
+			regs[0] = 0;
+			regs[1] = 0;
+			regs[2] = 0;
+			regs[3] = 0;
+			break;
+
 		case CPUID_0000_0001:
 			do_cpuid(1, regs);
 
diff --git a/sys/amd64/vmm/x86.h b/sys/amd64/vmm/x86.h
index 97e759847abb..97bd9dd5cad8 100644
--- a/sys/amd64/vmm/x86.h
+++ b/sys/amd64/vmm/x86.h
@@ -53,6 +53,7 @@
 #define CPUID_8000_0008	(0x80000008)
 #define CPUID_8000_001D	(0x8000001D)
 #define CPUID_8000_001E	(0x8000001E)
+#define CPUID_8000_0022	(0x80000022)
 
 /*
  * CPUID instruction Fn0000_0001: