HomeFreeBSD

hwpmc: Disable AMD PMCs if in an unsupported VM

Description

hwpmc: Disable AMD PMCs if in an unsupported VM

AMD does not have a CPUID bit to indicate the lack of K8 PMCs. If all
other PMC features are not present we should test an event selector to
see if it stores and returns a value. If the VM is implemented
correctly, this should result in a #GP on the initial wrmsr_safe. Bhyve
and a few other VMs ignore writes, so I got one step further and test
that it retains the OS and USR bits.

Tested on Zen 5 native and a Zen 5 Bhyve virtual machine. This code
should not run on any recent hardware, except in a VM, as it checks that
the core counter extension is missing.

PR: 268943
Reported by: Sandipan Das, John F. Carr <jfc@mit.edu>
Reviewed by: mhorne, imp
Sponsored by: Netflix
MFC after: 1 week
Pull Request: https://github.com/freebsd/freebsd-src/pull/2272/changes

Details

Provenance
ali_mashtizadeh.comAuthored on Jun 5 2026, 11:48 PM
mhorneCommitted on Jun 9 2026, 7:46 PM
Parents
rG8f9aabbdbcd5: OpenSSL: update MAINTAINERS/CODEOWNERS
Branches
Unknown
Tags
Unknown