From nobody Wed Dec 31 12:28:59 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 8A50DC4332F for ; Sat, 4 Nov 2023 00:04:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232060AbjKDAED (ORCPT ); Fri, 3 Nov 2023 20:04:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbjKDADi (ORCPT ); Fri, 3 Nov 2023 20:03:38 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9559170C for ; Fri, 3 Nov 2023 17:03:12 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9cb10a5d44so1561409276.0 for ; Fri, 03 Nov 2023 17:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699056191; x=1699660991; 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=fb8zK0NPqfOOMlkznlpiln6Hi6vwYDSmOtwhx6NLtA4=; b=E535Frjfi5cszIDTrzQfIYALqzpxcvR2HuuPpKmh4+Cmep+Nso/htlhdJDdQPsj8XH o17KQW4PDOSMwhOD7brxh0fa5LmibYN7/7Bh/lKoQMi87wKvKLxNqO12DV/wxeK719Ht XF2sYFqAln7YrzBnZmhjDnmsBZA5yk/n5AgwXuSp9iPepju9G2su2galyjAp/lzYe0kK IEgalKGQka0e/Bo0aydzBYLplEt0VXuWcPXul7/lrEVzn+5XKzr+MmxC5AXgR/H9QvWT fWsDR4o1m/MoyU1aQNzwNmMNuVHLoabljSuv3lGSEbdyr95qzL7dmVjyNKpA0E2zBPMa ijJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699056191; x=1699660991; 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=fb8zK0NPqfOOMlkznlpiln6Hi6vwYDSmOtwhx6NLtA4=; b=RinHCFcX68kMs1WXBS9+QezjfLViLEYGJIQ7cLCJp/AhNyV1fJoGAwytAiKJ/k6yej kJ6c+FQLDVfgfMrBS91GlI/iam7Z8/8uTpXdKTXX+DGgC29PTHZdDJR4av8nUQHUe0fr c/5OZJYC6+Fn5tjTeQY91bXEkQ0ZEWtADY3Gqv9TMaUVlhlODs9vdfOvRlxsi9DKtvEU knvfh+te+wHEDWPVfQJiLfNbQ1pthuIgryIbAO4BC4DSXAQUaq1XaCMiSWYCVKy6knU6 yXk2cRmQFPdZ0AyL8znwlqkYlqB4sFvavbwPrtU8swQ7ZPZCJKdUi+q3YIoqUSjdecng K0Xg== X-Gm-Message-State: AOJu0Yxa52Xtzu0n+NHcwcjd1RPBFIKwUNEmq3z8CO9fMIkdedb6+PYJ saAsxDnZyvvvfAnwozjg5ZMBEazsxh0= X-Google-Smtp-Source: AGHT+IEL2LRxWRcp04nBCCFP9y3lvnJP6fCOOR+pw/pOdCrhn01YAnoUjLyuXZZ/zPvkrHOPsQUb6e0bD1Y= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:2589:0:b0:d9a:c946:c18c with SMTP id l131-20020a252589000000b00d9ac946c18cmr449384ybl.6.1699056191288; Fri, 03 Nov 2023 17:03:11 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 3 Nov 2023 17:02:34 -0700 In-Reply-To: <20231104000239.367005-1-seanjc@google.com> Mime-Version: 1.0 References: <20231104000239.367005-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231104000239.367005-17-seanjc@google.com> Subject: [PATCH v6 16/20] 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 , Jinrong Liang , Like Xu , Jim Mattson , Aaron Lewis 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 problem KVM's "enable_pmu" param, open coding strings in multiple places is just asking for a false negatives and/or runtime errors due to typos. 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 b103c462701b..1885e758eb4d 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -1214,6 +1214,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 780f62e6a0f2..e6cf76d3499b 100644 --- a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c +++ b/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c @@ -536,7 +536,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 b6e4f57a8651..95bdb6d5af50 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 @@ -906,7 +906,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.42.0.869.gea05f2083d-goog