Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp637792rdd; Tue, 9 Jan 2024 15:16:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0M5PcRiYqkc8WfMbKzYQ52tKWjrknxBWYIAsADKxOVJloOyPrxEnsTYV9hx4bCXQ5uiUT X-Received: by 2002:a17:903:22ca:b0:1d4:ac23:d055 with SMTP id y10-20020a17090322ca00b001d4ac23d055mr68589plg.53.1704842181559; Tue, 09 Jan 2024 15:16:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704842181; cv=none; d=google.com; s=arc-20160816; b=LkNU4w6ExnbxMtoOnhIf6E5OMM+avDuijnrljyzL+OmRcR5h+5QxB4XzMFoNw99bJN BK4fI99ChddjfwFCuUqIhvYMbldUoioES/BjXs+00v4dFEMBo4DIDqGHzhbFzEQm7bXH KBaTqOpydURCsgZ0yM3bSOX5WOIzEa1gBX1TRgTSZdRLNU5cqPe0KiXrQcCseX6UHVxU 7688feqUJ8pu3AT3XHkIQm+GcWgg2KMr1TOh9sktEVidkG0eoe0sDKTdDK6DiILRkXd9 5JXsVY6J1LnaP+Nvmj8AOlDHwb8/G4mny5HbCRAgozO502AH9wBbLZluoo89qnxhqotl 1ijw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=UmbwugfbZjx9BroAj5L+ZfHrFa8HDb/zVhEfTcoxtfc=; fh=gm96CM+cG0KJxn7vnhn0c1c98ILNP1HHUrKfrGecw3M=; b=rqrNG/SvJfUl+IsXHkuJXzSYJUl3OclX3hjDpMlO5KS0CDi2mRiGJOD40RrHPPRpHQ 7mbpFsTbolrsS0CcTRFNnNJXKAPlbwo7fs+XHzG1CklIiD6M7FFDQiCCb0jDjdQwGc9Z A5oOVEl7XQtYhXHmQfx84VC1f7La+tTM/1DI4zDOnixOADQ8bCMxRFfmBNYxPfK3pCse MWD5nEZ/HoDW8t6hTYyRZKty2Yqa1jyOx2HTivtINbm4XmiC6znkVdbTFJwLonvgBviS T7wHuZpK7+eICeLSYD95NeR3wTiCjoEfqGlvR2OJ60COlIwZ9nbSGwNkqHbD7sGwIHG+ EIWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PNBGrC20; spf=pass (google.com: domain of linux-kernel+bounces-21509-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21509-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ju13-20020a170903428d00b001d0940db070si2305768plb.498.2024.01.09.15.16.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 15:16:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21509-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PNBGrC20; spf=pass (google.com: domain of linux-kernel+bounces-21509-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21509-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 82D8FB266EC for ; Tue, 9 Jan 2024 23:10:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 82BA6495F6; Tue, 9 Jan 2024 23:03:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PNBGrC20" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5254B48CEC for ; Tue, 9 Jan 2024 23:03:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5f240ace2efso48088047b3.1 for ; Tue, 09 Jan 2024 15:03:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704841412; x=1705446212; 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=UmbwugfbZjx9BroAj5L+ZfHrFa8HDb/zVhEfTcoxtfc=; b=PNBGrC20KjTlNRwSmRKglaBQjnWMvV2NhhcSeGpSO/eGbavokHb/tkfZE+BEBoEKrA +NR40h+6MmYuAfYNBdv9VpTE/UthS6U7sGharyAphHCgt3Wz+6OwkpMyiE5DTMXYr0i5 n56s+CvBO7pmwLu0fTzrlTpWdbqnocEml/qNodSZ9oZY6+3uXZ690PMwR9OdnZS/x6WD lUugeQDOiA5BaAP0WZiSjKl6iODsx6uvSwyoqFjF0QFnpi53j+Wa3WK4wcUcFqzHLukF 7wGmDxp/etNP3oiaAkore0cHA2YxrTV2NNjsUsJHx/X4QU3EdPCYA4FuhdpFgT3Ia6oj RWzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704841412; x=1705446212; 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=UmbwugfbZjx9BroAj5L+ZfHrFa8HDb/zVhEfTcoxtfc=; b=GeG2HVKIJzQJGc6R8BW4nOhMaRnnwVahK3L/zt+JbD2g4wzq3IjqZLuU62NdE/MsYQ 0Qyyh3gcXqL8H2cwMvtZywDsemsUTjKc5g64Nptp+PRtK0p3Rl4CWEbQGsjVg/gHsFu5 7PjPrSx1DKxOsqYMXkxDYeOx/xb+e9+LtBfnrouEIBSzXLaK5sZRV75Ghng3Dj9DKUt1 I5gtYhf81yT7bC/vV8J2a3dveW+ouEhJvHducUGFt1pgEtz/+dc7Nxe9ohbBHWJNzBBc fN5+LyYwkVQaun3PY+Bhdcv+EWrk7RubJLWkJ+IIzM3wus/EfxomTyHZmPpTzZ+nWTi1 zAJQ== X-Gm-Message-State: AOJu0YzuKWoYoFQ5c/yWnNCK0iRTMaTuaxIU2KJrBkR8YYsUmnLDuiZm jMG8rwMDtjE/uCNc2TCuIeMxKlSDmOq4U6ruPg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:b03:b0:5e3:2a36:b4d with SMTP id cj3-20020a05690c0b0300b005e32a360b4dmr88378ywb.1.1704841412585; Tue, 09 Jan 2024 15:03:32 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 9 Jan 2024 15:02:40 -0800 In-Reply-To: <20240109230250.424295-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240109230250.424295-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20240109230250.424295-21-seanjc@google.com> Subject: [PATCH v10 20/29] 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, Kan Liang , Dapeng Mi , Jim Mattson , Jinrong Liang , Aaron Lewis , Like Xu Content-Type: text/plain; charset="UTF-8" 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] Reviewed-by: Dapeng Mi Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86_64/pmu_counters_test.c | 31 ++++++++++++++++++- 1 file changed, 30 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 b07294af71a3..f5dedd112471 100644 --- a/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c +++ b/tools/testing/selftests/kvm/x86_64/pmu_counters_test.c @@ -332,7 +332,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) @@ -350,6 +349,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 pmu_version, uint64_t perf_capabilities, @@ -373,6 +373,7 @@ static void guest_test_fixed_counters(void) { uint64_t supported_bitmask = 0; uint8_t nr_fixed_counters = 0; + uint8_t i; /* Fixed counters require Architectural vPMU Version 2+. */ if (guest_get_pmu_version() >= 2) @@ -387,6 +388,34 @@ 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, + FIXED_PMC_CTRL(i, FIXED_PMC_KERNEL)); + __GUEST_ASSERT(vector == GP_VECTOR, + "Expected #GP for counter %u in FIXED_CTR_CTRL", i); + + vector = wrmsr_safe(MSR_CORE_PERF_GLOBAL_CTRL, + FIXED_PMC_GLOBAL_CTRL_ENABLE(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, FIXED_PMC_CTRL(i, FIXED_PMC_KERNEL)); + wrmsr(MSR_CORE_PERF_GLOBAL_CTRL, FIXED_PMC_GLOBAL_CTRL_ENABLE(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 pmu_version, uint64_t perf_capabilities, -- 2.43.0.472.g3155946c3a-goog