Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1405816rdb; Fri, 1 Dec 2023 16:06:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbCLCJY+SSTvD8Pmg2o9of/JMHfQtQ5gFuefNTuHUilftPlMrIvcj8uMQkwS4aLGHn3IkC X-Received: by 2002:a05:6a20:43a4:b0:18f:97c:9297 with SMTP id i36-20020a056a2043a400b0018f097c9297mr268914pzl.124.1701475601032; Fri, 01 Dec 2023 16:06:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701475601; cv=none; d=google.com; s=arc-20160816; b=RaxsNYfEq9mKDoNo+g3+2w+y6wz9fKCJtjcTbgEtWGytltTTHnWrOeObPB1K/2/YPg vfnH7lUBbx8VzqvoimPHrjqL0wEd+RYWCHoTahPLDKhvXWZITVTr0vs3FT3dZrU6lPU5 45g/UlHI88JQ4QC9dm31UdJhvS7mNt2V672ocCIeUbzJMxFTDQotMXgxXSELckdv0awu AxlpKDJdVwnxxizJRbGTLCFlzg6+3k36pvEsaS5JCA+mR/jsezSj0vB6e1KB/F7xlFvF QpGhCCopYr0af2BEn0Ouxy8hZDftap6/E8cJwoYdJfiF1z8YOywjPAhLu8CTSyptzkNq ZaSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=LHL30gA5759oBkqLVOdiwNG9MowlKjvY2Plkf191Sjc=; fh=gm96CM+cG0KJxn7vnhn0c1c98ILNP1HHUrKfrGecw3M=; b=akksbyBCD03AJMrpj5vpw1huUkH+ATtt9dd98dbV9LxJIf5ku1ejEw259/ZCQuro38 UIrN2hUpLZTdAZY5tEGFU0OcJ6u2M2zpbNvlQMGKJQY6mhp/1nSLIWZn6LkZV9gjMKPd 7Lkef1ysptnbgYhTWhfhRymWL/vyHmvk9/9SIzlZaj1/TD+GRNZd2Z9d6wmy3Zh76PiR SJU4PJvNbA3QuqiggXiYFKOR69RiXphbX53dFMu/SOCEczWX+WSOr71xF0wjctn1txfp zRK8mQ/2pCEklIu2Ik6rkXoUcJfpsfxLrJzjaLMiHNoN+8kzU/+rbohcydOr/y/isjoC hltA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aKzhoMfH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id iz2-20020a170902ef8200b001cc55bca838si4026712plb.576.2023.12.01.16.06.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 16:06:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aKzhoMfH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 6A4A483014B8; Fri, 1 Dec 2023 16:06:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442013AbjLBAGJ (ORCPT + 99 others); Fri, 1 Dec 2023 19:06:09 -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-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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 01 Dec 2023 16:06:34 -0800 (PST) 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, 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); 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) 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)); diff --git a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c b/tools/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 = 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)); 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; - 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)); -- 2.43.0.rc2.451.g8631bc7472-goog