On Fri, Aug 19, 2022, Like Xu wrote: > From: Like Xu <likexu@xxxxxxxxxxx> > > On virtual platforms without PDCM support (e.g. AMD), #GP > failure on MSR_IA32_PERF_CAPABILITIES is completely avoidable. > > Signed-off-by: Like Xu <likexu@xxxxxxxxxxx> > --- > x86/pmu.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/x86/pmu.c b/x86/pmu.c > index 4eb92d8..25fafbe 100644 > --- a/x86/pmu.c > +++ b/x86/pmu.c > @@ -669,7 +669,8 @@ int main(int ac, char **av) > > check_counters(); > > - if (rdmsr(MSR_IA32_PERF_CAPABILITIES) & PMU_CAP_FW_WRITES) { > + if (this_cpu_has(X86_FEATURE_PDCM) && > + (rdmsr(MSR_IA32_PERF_CAPABILITIES) & PMU_CAP_FW_WRITES)) { pmu_pebs.c ends up with similar code. Maybe add a helper? static inline u64 this_cpu_perf_capabilities(void) { if (!this_cpu_has(X86_FEATURE_PDCM)) return 0; rdmsr(MSR_IA32_PERF_CAPABILITIES); } Or even better, if we end up with a lib/pmu and something like "struct pmu_caps", the RDMSR can be done once in the library's init routine.