From nobody Fri Dec 19 00:19:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47F79C4167B for ; Sat, 2 Dec 2023 00:06:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442036AbjLBAGL (ORCPT ); Fri, 1 Dec 2023 19:06:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442029AbjLBAFW (ORCPT ); Fri, 1 Dec 2023 19:05:22 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10FB81FFA for ; Fri, 1 Dec 2023 16:05:01 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5d3b6fa30e2so33984927b3.2 for ; Fri, 01 Dec 2023 16:05:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701475501; x=1702080301; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=LHL30gA5759oBkqLVOdiwNG9MowlKjvY2Plkf191Sjc=; b=aKzhoMfHutmUd00tVdlpbVRzOAgoTSSuMtgDX7p2aB/sMfMvG+XUOUBdGRqeTzZ9yQ qUNkrwjurQUAj4q79q+GkTeFY7f8a8714pw2l7w3RnF4h69kHHnkTrI9AdDjZnsFvDB6 QGk6UvKb5ikv+r5g0CfWXQ7qwnWX76C/7BPNlAA+0Gb0Jl1UWIOmAD9Q8iJo/c9uAQup EgVYWwumWC2Lu7e0Hv92RK4WDRHXUQ23/ruwt0SjiKmGMCiyM2zEGI9Zf82sWXqrjwsT qT/260sngaeTFohtqjxTU/AbiX8Agp6FzzTyGUOyyzml8wagaLie7I6lG+1g1IRKaF2F vsgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701475501; x=1702080301; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LHL30gA5759oBkqLVOdiwNG9MowlKjvY2Plkf191Sjc=; b=GLi8I6jDWFLwusbrh0jIrudJ1RgUNzZ4+j57yOzk2N5O7VL3IxyzwSUBWdCyGXyhXy axqcp2TThNQSBE3J6SYPc4V8DVPkWKoewMOfD26LjhiSVuhFvc1EpD3hZRPUAd+qvbeA R9e4/l2SGjlWRe32DSnIqH0FaDTyz+pHbn9LWBpgtczk9QN9mtc8JW4fE7LoXNS3FzT3 qQBFiIGTFK7InsiMcMVtnrBiJTA/qrvuFuWifspEWgR4M+F8OgvHEXB9SfNTk4Edy7QO tVWia1kIV9KwX51D4Zv+h70R3zqjyBMTB6+RV0hRgbcKCsiq0/+Abq5lew0obNysNLXs XDmg== X-Gm-Message-State: AOJu0YyEw7CwRVdTrGVdfVcaawbaWuG5JYdNPO7TnJ+3IqrIfwkUYY77 yTD9Ai4H3MGZjSWW5cz1PV3dNzMmUOE= X-Google-Smtp-Source: AGHT+IGNOIVMDFDd6sXnN06oX7tDusskXuJbQYhmBpvaaSvhC2Af7noKsZAHhVeG9PJOEHwkDYRcZld5NrE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a5b:a01:0:b0:db4:7d21:8cea with SMTP id k1-20020a5b0a01000000b00db47d218ceamr763455ybq.5.1701475500865; Fri, 01 Dec 2023 16:05:00 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 1 Dec 2023 16:04:10 -0800 In-Reply-To: <20231202000417.922113-1-seanjc@google.com> Mime-Version: 1.0 References: <20231202000417.922113-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Message-ID: <20231202000417.922113-22-seanjc@google.com> Subject: [PATCH v9 21/28] KVM: selftests: Add a helper to query if the PMU module param is enabled From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kan Liang , Dapeng Mi , Jim Mattson , Jinrong Liang , Aaron Lewis , Like Xu Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86_64/processor.h | 5 +++++ tools/testing/selftests/kvm/x86_64/pmu_counters_test.c | 2 +- tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c | 2 +- tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index 92d4f8ecc730..ee082ae58f40 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -1217,6 +1217,11 @@ static inline uint8_t xsetbv_safe(uint32_t index, ui= nt64_t value) =20 bool kvm_is_tdp_enabled(void); =20 +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); 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 4c7133ddcda8..9e9dc4084c0d 100644 --- a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c +++ b/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c @@ -545,7 +545,7 @@ static void test_intel_counters(void) =20 int main(int argc, char *argv[]) { - TEST_REQUIRE(get_kvm_param_bool("enable_pmu")); + TEST_REQUIRE(kvm_is_pmu_enabled()); =20 TEST_REQUIRE(host_cpu_is_intel); TEST_REQUIRE(kvm_cpu_has_p(X86_PROPERTY_PMU_VERSION)); diff --git a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c b/t= ools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c index 7ec9fbed92e0..fa407e2ccb2f 100644 --- a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c +++ b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c @@ -867,7 +867,7 @@ int main(int argc, char *argv[]) struct kvm_vcpu *vcpu, *vcpu2 =3D NULL; struct kvm_vm *vm; =20 - 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)); =20 diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c b/tools= /testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c index ebbcb0a3f743..562b0152a122 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c @@ -237,7 +237,7 @@ int main(int argc, char *argv[]) { union perf_capabilities host_cap; =20 - TEST_REQUIRE(get_kvm_param_bool("enable_pmu")); + TEST_REQUIRE(kvm_is_pmu_enabled()); TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_PDCM)); =20 TEST_REQUIRE(kvm_cpu_has_p(X86_PROPERTY_PMU_VERSION)); --=20 2.43.0.rc2.451.g8631bc7472-goog