Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp819486rdf; Fri, 3 Nov 2023 17:04:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5UppBe03IgyobuxP04t9H1/aBpgfY18Mh5zYicO+B6rbuaxnTpdEppXTFEh5gGS8Auria X-Received: by 2002:a05:6a21:7185:b0:180:def9:20e1 with SMTP id wq5-20020a056a21718500b00180def920e1mr17261685pzb.22.1699056282356; Fri, 03 Nov 2023 17:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699056282; cv=none; d=google.com; s=arc-20160816; b=uTjkXqQIDnj/pp6qQF/quQjLt02u6Z8ZkzGydleuv6Dy7x4AFiLHMRpFuyPCAnxnR6 sr1Tpq7p+qLzFLVmVVTPPcjzg44phGYkIM5JNRRRqRIN18MuE/+ZKZ8V8E72OvuB+tOP etWHV8r7i5xVeubjhWW3WX3os7fLDgZG7wGPu6lqPwGWWWPPufV8NwTHAYcduDe04INE +64qGx1Uil+VzMDT4yCe7fYNJpLAH+kTy7OgbNbkUz1rUKGJULehLyrfituNFJzievU4 sxJqfdIoXKhg3ZUE9wkQ9RqjycVs7OwidklgAk2u9ZUq2428066n2XFdn60+SknEDFm2 RyuA== 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=fb8zK0NPqfOOMlkznlpiln6Hi6vwYDSmOtwhx6NLtA4=; fh=z/UQYx9FUD9Bz9JyYrmi2ijAScp29gktKr8lejSUuXU=; b=e0LPXg0geeg7wJXXAqKlXtcz23jwPbW4nEi4/XaiQei0HqdXZFjZmLfD/Zi1M616mH kmWWtKi7mqSOFHwb06D+qQp+z6amtRI64pbYGlxgqvG8R0dBh2SgzaSeFKLbbD0MPFbi pUhDCkBQheypYTb8jOxBJp/DEqT9UnmKlpn4HPZaK1fO105+SKhE2H7oUySBVsPiZIu0 OTc/kV1mWKvJI0qdqK0pl7ddpc1QvAbJM/EkFGWssCTL/yNiX8tUPC3m8fnPfquR54bk yrfR4c3G+KtfrX1WcHoJhYtT5Jois+GQujATfCJ8kXHlybuI2PhKOtOe8ghJAHo+rPz8 piIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=E535Frjf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id m22-20020a656a16000000b00563deb65f93si2701523pgu.200.2023.11.03.17.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 17:04:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=E535Frjf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 5793081B5A90; Fri, 3 Nov 2023 17:04:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231627AbjKDAD7 (ORCPT + 99 others); Fri, 3 Nov 2023 20:03:59 -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-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 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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 03 Nov 2023 17:04:37 -0700 (PDT) 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, 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 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) 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 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 = 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.42.0.869.gea05f2083d-goog