Skip to content

Commit 6f19c31

Browse files
Kullu14sean-jc
authored andcommitted
KVM: selftests: Treat AMD Family 17h+ as supporting branch insns retired
When detecting AMD PMU support for encoding "branch instructions retired" as event 0xc2,0, simply check for Family 17h+ as all Zen CPUs support said encoding, and AMD will maintain the encoding for backwards compatibility on future CPUs. Note, the kernel proper also interprets Family 17h+ as Zen (see the sole caller of init_amd_zen_common()). Fixes: bef9a70 ("selftests: kvm/x86: Add test for KVM_SET_PMU_EVENT_FILTER") Suggested-by: Sandipan Das <sandipan.das@amd.com> Signed-off-by: Manali Shukla <manali.shukla@amd.com> Link: https://lore.kernel.org/r/20240605050835.30491-1-manali.shukla@amd.com Co-developed-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent f626279 commit 6f19c31

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ struct __kvm_pmu_event_filter {
3232

3333
/*
3434
* This event list comprises Intel's known architectural events, plus AMD's
35-
* "retired branch instructions" for Zen1-Zen3 (and* possibly other AMD CPUs).
36-
* Note, AMD and Intel use the same encoding for instructions retired.
35+
* Branch Instructions Retired for Zen CPUs. Note, AMD and Intel use the
36+
* same encoding for Instructions Retired.
3737
*/
3838
kvm_static_assert(INTEL_ARCH_INSTRUCTIONS_RETIRED == AMD_ZEN_INSTRUCTIONS_RETIRED);
3939

@@ -353,38 +353,13 @@ static bool use_intel_pmu(void)
353353
kvm_pmu_has(X86_PMU_FEATURE_BRANCH_INSNS_RETIRED);
354354
}
355355

356-
static bool is_zen1(uint32_t family, uint32_t model)
357-
{
358-
return family == 0x17 && model <= 0x0f;
359-
}
360-
361-
static bool is_zen2(uint32_t family, uint32_t model)
362-
{
363-
return family == 0x17 && model >= 0x30 && model <= 0x3f;
364-
}
365-
366-
static bool is_zen3(uint32_t family, uint32_t model)
367-
{
368-
return family == 0x19 && model <= 0x0f;
369-
}
370-
371356
/*
372-
* Determining AMD support for a PMU event requires consulting the AMD
373-
* PPR for the CPU or reference material derived therefrom. The AMD
374-
* test code herein has been verified to work on Zen1, Zen2, and Zen3.
375-
*
376-
* Feel free to add more AMD CPUs that are documented to support event
377-
* select 0xc2 umask 0 as "retired branch instructions."
357+
* On AMD, all Family 17h+ CPUs (Zen and its successors) use event encoding
358+
* 0xc2,0 for Branch Instructions Retired.
378359
*/
379360
static bool use_amd_pmu(void)
380361
{
381-
uint32_t family = kvm_cpu_family();
382-
uint32_t model = kvm_cpu_model();
383-
384-
return host_cpu_is_amd &&
385-
(is_zen1(family, model) ||
386-
is_zen2(family, model) ||
387-
is_zen3(family, model));
362+
return host_cpu_is_amd && kvm_cpu_family() >= 0x17;
388363
}
389364

390365
/*

0 commit comments

Comments
 (0)