[PATCH RESEND 4/5] KVM: x86: selftests: Allow the PMU event filter test for Hygon

Zhiquan Li posted 5 patches 1 day, 5 hours ago
[PATCH RESEND 4/5] KVM: x86: selftests: Allow the PMU event filter test for Hygon
Posted by Zhiquan Li 1 day, 5 hours ago
At present, the PMU event filter test is only available for Intel and
AMD architecture conditionally, but it is applicable for Hygon
architecture as well.

Since all known Hygon processors can re-use the test cases, so it isn't
necessary to create a wrapper like other architectures, using the
"host_cpu_is_hygon" variable should be enough.

Signed-off-by: Zhiquan Li <zhiquan_li@163.com>
---
 tools/testing/selftests/kvm/x86/pmu_event_filter_test.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c b/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c
index 1c5b7611db24..e6badd9a2a2a 100644
--- a/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c
+++ b/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c
@@ -842,14 +842,14 @@ int main(int argc, char *argv[])
 	TEST_REQUIRE(kvm_has_cap(KVM_CAP_PMU_EVENT_FILTER));
 	TEST_REQUIRE(kvm_has_cap(KVM_CAP_PMU_EVENT_MASKED_EVENTS));
 
-	TEST_REQUIRE(use_intel_pmu() || use_amd_pmu());
+	TEST_REQUIRE(use_intel_pmu() || use_amd_pmu() || host_cpu_is_hygon);
 	guest_code = use_intel_pmu() ? intel_guest_code : amd_guest_code;
 
 	vm = vm_create_with_one_vcpu(&vcpu, guest_code);
 
 	TEST_REQUIRE(sanity_check_pmu(vcpu));
 
-	if (use_amd_pmu())
+	if (use_amd_pmu() || host_cpu_is_hygon)
 		test_amd_deny_list(vcpu);
 
 	test_without_filter(vcpu);
@@ -862,7 +862,7 @@ int main(int argc, char *argv[])
 	    supports_event_mem_inst_retired() &&
 	    kvm_cpu_property(X86_PROPERTY_PMU_NR_GP_COUNTERS) >= 3)
 		vcpu2 = vm_vcpu_add(vm, 2, intel_masked_events_guest_code);
-	else if (use_amd_pmu())
+	else if (use_amd_pmu() || host_cpu_is_hygon)
 		vcpu2 = vm_vcpu_add(vm, 2, amd_masked_events_guest_code);
 
 	if (vcpu2)
-- 
2.43.0
Re: [PATCH RESEND 4/5] KVM: x86: selftests: Allow the PMU event filter test for Hygon
Posted by Sean Christopherson 16 hours ago
On Mon, Feb 09, 2026, Zhiquan Li wrote:
> At present, the PMU event filter test is only available for Intel and
> AMD architecture conditionally, but it is applicable for Hygon
> architecture as well.
> 
> Since all known Hygon processors can re-use the test cases, so it isn't
> necessary to create a wrapper like other architectures, using the
> "host_cpu_is_hygon" variable should be enough.
> 
> Signed-off-by: Zhiquan Li <zhiquan_li@163.com>
> ---
>  tools/testing/selftests/kvm/x86/pmu_event_filter_test.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c b/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c
> index 1c5b7611db24..e6badd9a2a2a 100644
> --- a/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c
> +++ b/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c
> @@ -842,14 +842,14 @@ int main(int argc, char *argv[])
>  	TEST_REQUIRE(kvm_has_cap(KVM_CAP_PMU_EVENT_FILTER));
>  	TEST_REQUIRE(kvm_has_cap(KVM_CAP_PMU_EVENT_MASKED_EVENTS));
>  
> -	TEST_REQUIRE(use_intel_pmu() || use_amd_pmu());
> +	TEST_REQUIRE(use_intel_pmu() || use_amd_pmu() || host_cpu_is_hygon);

Manually handling every check is rather silly, just do:

diff --git a/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c b/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c
index 1c5b7611db24..93b61c077991 100644
--- a/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c
+++ b/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c
@@ -361,7 +361,8 @@ static bool use_intel_pmu(void)
  */
 static bool use_amd_pmu(void)
 {
-       return host_cpu_is_amd && kvm_cpu_family() >= 0x17;
+       return (host_cpu_is_amd && kvm_cpu_family() >= 0x17) ||
+              host_cpu_is_hygon;
 }
 
 /*
Re: [PATCH RESEND 4/5] KVM: x86: selftests: Allow the PMU event filter test for Hygon
Posted by Zhiquan Li 23 minutes ago
On 2/10/26 00:38, Sean Christopherson wrote:
> Manually handling every check is rather silly, just do:
> 
> diff --git a/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c b/tools/
> testing/selftests/kvm/x86/pmu_event_filter_test.c
> index 1c5b7611db24..93b61c077991 100644
> --- a/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c
> +++ b/tools/testing/selftests/kvm/x86/pmu_event_filter_test.c
> @@ -361,7 +361,8 @@ static bool use_intel_pmu(void)
>   */
>  static bool use_amd_pmu(void)
>  {
> - return host_cpu_is_amd && kvm_cpu_family() >= 0x17;
> + return (host_cpu_is_amd && kvm_cpu_family() >= 0x17) ||
> + host_cpu_is_hygon;
>  }
>  
>  /*

No problem, let me simplify it in V2 patch. Thanks!

Best Regards,
Zhiquan