git: d555f6b974a1 - releng/15.2 - amd64/vmm: Don't advertise AMD PerfMonV2 or performance counters

From: Colin Percival <cperciva_at_FreeBSD.org>
Date: Sat, 14 Nov 2026 17:26:23 UTC
The branch releng/15.2 has been updated by cperciva:

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

commit d555f6b974a1b6264f7e438af45db833356bbb82
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2026-11-02 17:15:33 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-11-14 17:25:44 +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.
    
    Approved by:    re (cperciva)
    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
    
    (cherry picked from commit 8fb539b081dbfe3e93e607a5d4d36184c53c8aaf)
    (cherry picked from commit ade540f274d52366b46da2898b2c264b4e89883a)
---
 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: