[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231121115457.76269-9-cloudliang@tencent.com>
Date: Tue, 21 Nov 2023 19:54:56 +0800
From: Jinrong Liang <ljr.kernel@...il.com>
To: Sean Christopherson <seanjc@...gle.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>, Like Xu <likexu@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Aaron Lewis <aaronlewis@...gle.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jinrong Liang <cloudliang@...cent.com>,
Jinrong Liang <ljr.kernel@...il.com>, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH 8/9] KVM: selftests: Test AMD Guest PerfCtrExtCore
From: Jinrong Liang <cloudliang@...cent.com>
Add test case for AMD Guest PerfCtrExtCore.
Signed-off-by: Jinrong Liang <cloudliang@...cent.com>
---
.../selftests/kvm/x86_64/pmu_counters_test.c | 31 +++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c b/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c
index 07cb9694e225..ca5b352ea6ae 100644
--- a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c
+++ b/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c
@@ -863,6 +863,36 @@ static void test_amd_pmu_version(void)
}
}
+static void guest_test_perfctr_core(void)
+{
+ bool expect_gp = !this_cpu_has(X86_FEATURE_PERFCTR_CORE);
+ unsigned int i;
+
+ for (i = 0; i < AMD64_NR_COUNTERS_CORE; i++) {
+ guest_wr_rd_amd_counters(MSR_F15H_PERF_CTR0 + i * 2, expect_gp, 0xffff);
+ guest_wr_rd_amd_counters(MSR_F15H_PERF_CTL0 + i * 2, expect_gp, 0);
+ }
+
+ GUEST_DONE();
+}
+
+static void test_amd_perfctr_core(void)
+{
+ bool kvm_pmu_has_perfctr_core = kvm_cpu_has(X86_FEATURE_PERFCTR_CORE);
+ struct kvm_vcpu *vcpu;
+ struct kvm_vm *vm;
+ unsigned int i;
+
+ for (i = 0; i <= kvm_pmu_has_perfctr_core; i++) {
+ vm = pmu_vm_create_with_one_vcpu(&vcpu, guest_test_perfctr_core);
+
+ vcpu_set_or_clear_cpuid_feature(vcpu, X86_FEATURE_PERFCTR_CORE, i);
+
+ run_vcpu(vcpu);
+ kvm_vm_free(vm);
+ }
+}
+
int main(int argc, char *argv[])
{
TEST_REQUIRE(kvm_is_pmu_enabled());
@@ -881,6 +911,7 @@ int main(int argc, char *argv[])
test_amd_zen_events();
test_amd_counters_num();
test_amd_pmu_version();
+ test_amd_perfctr_core();
} else {
TEST_FAIL("Unknown CPU vendor");
}
--
2.39.3
Powered by blists - more mailing lists