Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1566912rda; Mon, 23 Oct 2023 17:29:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhaeKdBp8sKX1/fH4D9o7WA8V7DVztkYA1y4b3b8JVYTCNhOOsZoPV2f/59jIpceYpcIkk X-Received: by 2002:a05:6358:9f88:b0:168:e98e:7c21 with SMTP id fy8-20020a0563589f8800b00168e98e7c21mr2280708rwb.24.1698107340948; Mon, 23 Oct 2023 17:29:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698107340; cv=none; d=google.com; s=arc-20160816; b=BaOH1SDqZq65IztvTeugsuAchWX1L69iN6QgKQDIRlUMheiXhjpbYcOxEc4+x9qcm9 OdCDrWzXwXw5QZEsXSYlLkBTQMMSRo0h7AtZx2JsJ0wL0Cpz0W5pW8IpP823KK/VxgKe 2Elp9eoXlwjUfzsFdTDmnpDinB/DwhWpEcHJWBIjvC7hDHj4abJR2op+nUOiVK/15zKc DzI6hj32fp/DCyTeoJXpDDz0OqaaBK+weKXUUlbEu53fpknDGDPVjpNH1ThitREObGXK 3DYCtMP8y3wDs0hKyq7opZGLFpe2wJ2U9d0OgbjqJtMSvEYXpmYHDom5gAuY7rDOEXIy sFPA== 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=14wArEVnBNhNrbZ4s3cIhEfuNUwYxvC64ZUFQ1mIX8Y=; fh=D//PLXZS63mgWSQM2kcZZyW+2k64a7rh3i2k12EZPR4=; b=b2zEtCC1Hoysn0J7C5uQY4FgowDK6WKxbKdUe1+qTTeYPhctYS31flLIjuuzxe5Xki 1KQV1UenR0Lxgr4/7+GwEuI+a6oKd6wqfiKR6ir7KdXd2Yh/Au+d4V8hML7Tqa5nyFZ9 2VKWiW4IxIr+TbFAM5F37VfUZs8KwNPXtYhACDvXotFOf/WhsypcOmKTWvNmqN3ALdg2 sQ4z3I26MMGS0IM3DwmdBN60F+GmLOkV4nebF/q9Blm9AbaTBQKS4sLvAocS1BAtT+h3 Phb87+hxm5vpGbXQ9/F3U0sJzkDyiS+rhkfX5MIczsUL0+7BEzeXzCIwP6nZMBMoo/gE Ndsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nTIWCNrV; 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 bu24-20020a632958000000b005b8ddd7bc56si1112514pgb.94.2023.10.23.17.29.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 17:29:00 -0700 (PDT) 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=nTIWCNrV; 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 4E46D809A79B; Mon, 23 Oct 2023 17:28:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231713AbjJXA1r (ORCPT + 99 others); Mon, 23 Oct 2023 20:27:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231817AbjJXA1c (ORCPT ); Mon, 23 Oct 2023 20:27:32 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE2D210DB for ; Mon, 23 Oct 2023 17:27:01 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a81cd8d267so75335057b3.1 for ; Mon, 23 Oct 2023 17:27:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698107219; x=1698712019; 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=14wArEVnBNhNrbZ4s3cIhEfuNUwYxvC64ZUFQ1mIX8Y=; b=nTIWCNrVOi4oWDJcxrd7dX3VpfEMFgMw8vyCBc5tB6ggMhlwXYvOVBzyw+AvzF5wob gIDwhJIR7mXT/3UhsK4+N4PepcSIAcF6ceRhc7vg27nO09eSrVvpNF2Yr7fiAwSpMUBs fNuITbfgNemreJ7n4sHVWJHGr9uuhAOZLOrPjG9yQoR5MX6kqxBAGHRErUjdg7N+Btpw 7VBnYJ2jAVz2PKA9Ul013LZogOOTXE+Lpd6t3n5/KSGcNXWh3ig4b24fcdTWd8rwa5+0 nCtvEEqRCFPKJazlIL7DcnQbqA/N0saxzc71dxG7pCZhJCcME+RrsL//Xc3aB1BEbXpR f2Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698107219; x=1698712019; 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=14wArEVnBNhNrbZ4s3cIhEfuNUwYxvC64ZUFQ1mIX8Y=; b=RBx80dlB7ea3NJj27dzbMImaJcbMrO8bM/01JRFq5uucQ5y67loEkIbmmRF1sP1Bcq ylL26q5bvtzFo+AN5xHfETNYLsUognKq1eWa1Ry/w9FWOYPVfRUPCkZdn/1riy5p/XJn s1nBApTIIr6lv+rgZLnMgPeq/fdVDLifvEEcNUW4QkyMZeOfsXlIgObVIZ3jmUNQZCTI otB/5nG1cOF+f2n6bNhUn0qV6OeA1QzxQg86pRMkSq6EfLsXlUlrqZ85uPN8eJ8s4lDT 29M+wPTX6iQidjpQ4z3YTha6IrSgSMSNE2XyTineE6bnLG+EpkuQuP6jRZhomDSAYVvS 6JAQ== X-Gm-Message-State: AOJu0YzQrel3JlLiqF2oVY4XzoGGJPIFrCaGRH1s3E75mmho/BgO7X66 uDH21B5CA5rjapD4dFZAhW7G3RT/mgE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:ccd4:0:b0:58c:b45f:3e94 with SMTP id o203-20020a0dccd4000000b0058cb45f3e94mr209290ywd.8.1698107218929; Mon, 23 Oct 2023 17:26:58 -0700 (PDT) Reply-To: Sean Christopherson Date: Mon, 23 Oct 2023 17:26:32 -0700 In-Reply-To: <20231024002633.2540714-1-seanjc@google.com> Mime-Version: 1.0 References: <20231024002633.2540714-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Message-ID: <20231024002633.2540714-13-seanjc@google.com> Subject: [PATCH v5 12/13] KVM: selftests: Add functional test for Intel's fixed PMU counters From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jinrong Liang , 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,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]); Mon, 23 Oct 2023 17:28:58 -0700 (PDT) From: Jinrong Liang Extend the fixed counters test to verify that supported counters can actually be enabled in the control MSRs, that unsupported counters cannot, and that enabled counters actually count. Co-developed-by: Like Xu Signed-off-by: Like Xu Signed-off-by: Jinrong Liang [sean: fold into the rd/wr access test, massage changelog] Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86_64/pmu_counters_test.c | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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 f1d9cdd69a17..1c392ad156f4 100644 --- a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c +++ b/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c @@ -266,7 +266,6 @@ static void guest_rd_wr_counters(uint32_t base_msr, uint8_t nr_possible_counters vector = wrmsr_safe(msr, 0); GUEST_ASSERT_PMC_MSR_ACCESS(WRMSR, msr, expect_gp, vector); } - GUEST_DONE(); } static void guest_test_gp_counters(void) @@ -280,6 +279,7 @@ static void guest_test_gp_counters(void) base_msr = MSR_IA32_PERFCTR0; guest_rd_wr_counters(base_msr, MAX_NR_GP_COUNTERS, nr_gp_counters, 0); + GUEST_DONE(); } static void test_gp_counters(uint8_t nr_gp_counters, uint64_t perf_cap) @@ -302,6 +302,7 @@ static void guest_test_fixed_counters(void) { uint64_t supported_bitmask = 0; uint8_t nr_fixed_counters = 0; + uint8_t i; /* KVM provides fixed counters iff the vPMU version is 2+. */ if (this_cpu_property(X86_PROPERTY_PMU_VERSION) >= 2) @@ -316,6 +317,32 @@ static void guest_test_fixed_counters(void) guest_rd_wr_counters(MSR_CORE_PERF_FIXED_CTR0, MAX_NR_FIXED_COUNTERS, nr_fixed_counters, supported_bitmask); + + for (i = 0; i < MAX_NR_FIXED_COUNTERS; i++) { + uint8_t vector; + uint64_t val; + + if (i >= nr_fixed_counters && !(supported_bitmask & BIT_ULL(i))) { + vector = wrmsr_safe(MSR_CORE_PERF_FIXED_CTR_CTRL, BIT_ULL(4 * i)); + __GUEST_ASSERT(vector == GP_VECTOR, + "Expected #GP for counter %u in FIXED_CTRL_CTRL", i); + + vector = wrmsr_safe(MSR_CORE_PERF_GLOBAL_CTRL, BIT_ULL(PMC_IDX_FIXED + i)); + __GUEST_ASSERT(vector == GP_VECTOR, + "Expected #GP for counter %u in PERF_GLOBAL_CTRL", i); + continue; + } + + wrmsr(MSR_CORE_PERF_FIXED_CTR0 + i, 0); + wrmsr(MSR_CORE_PERF_FIXED_CTR_CTRL, BIT_ULL(4 * i)); + wrmsr(MSR_CORE_PERF_GLOBAL_CTRL, BIT_ULL(PMC_IDX_FIXED + i)); + __asm__ __volatile__("loop ." : "+c"((int){NUM_BRANCHES})); + wrmsr(MSR_CORE_PERF_GLOBAL_CTRL, 0); + val = rdmsr(MSR_CORE_PERF_FIXED_CTR0 + i); + + GUEST_ASSERT_NE(val, 0); + } + GUEST_DONE(); } static void test_fixed_counters(uint8_t nr_fixed_counters, -- 2.42.0.758.gaed0368e0e-goog