Skip to content

Commit

Permalink
KVM: selftests: Add a helper to query if the PMU module param is enabled
Browse files Browse the repository at this point in the history
Add a helper to probe KVM's "enable_pmu" param, open coding strings in
multiple places is just asking for false negatives and/or runtime errors
due to typos.

Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Tested-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Link: https://lore.kernel.org/r/20240109230250.424295-23-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
  • Loading branch information
sean-jc committed Jan 30, 2024
1 parent b55e7ad commit c85e986
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions tools/testing/selftests/kvm/include/x86_64/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,11 @@ static inline uint8_t xsetbv_safe(uint32_t index, uint64_t value)

bool kvm_is_tdp_enabled(void);

static inline bool kvm_is_pmu_enabled(void)
{
return get_kvm_param_bool("enable_pmu");
}

uint64_t *__vm_get_page_table_entry(struct kvm_vm *vm, uint64_t vaddr,
int *level);
uint64_t *vm_get_page_table_entry(struct kvm_vm *vm, uint64_t vaddr);
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/x86_64/pmu_counters_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ static void test_intel_counters(void)

int main(int argc, char *argv[])
{
TEST_REQUIRE(get_kvm_param_bool("enable_pmu"));
TEST_REQUIRE(kvm_is_pmu_enabled());

TEST_REQUIRE(host_cpu_is_intel);
TEST_REQUIRE(kvm_cpu_has_p(X86_PROPERTY_PMU_VERSION));
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ int main(int argc, char *argv[])
struct kvm_vcpu *vcpu, *vcpu2 = NULL;
struct kvm_vm *vm;

TEST_REQUIRE(get_kvm_param_bool("enable_pmu"));
TEST_REQUIRE(kvm_is_pmu_enabled());
TEST_REQUIRE(kvm_has_cap(KVM_CAP_PMU_EVENT_FILTER));
TEST_REQUIRE(kvm_has_cap(KVM_CAP_PMU_EVENT_MASKED_EVENTS));

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ int main(int argc, char *argv[])
{
union perf_capabilities host_cap;

TEST_REQUIRE(get_kvm_param_bool("enable_pmu"));
TEST_REQUIRE(kvm_is_pmu_enabled());
TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_PDCM));

TEST_REQUIRE(kvm_cpu_has_p(X86_PROPERTY_PMU_VERSION));
Expand Down

0 comments on commit c85e986

Please sign in to comment.