From patchwork Fri Jan 17 23:41:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13944041 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 24BBF1DE8B5 for ; Fri, 17 Jan 2025 23:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737157329; cv=none; b=kh1saXyyr+tjW9/esWeloNsh8U0XPfwyMLu/AeApdyNB9lV8dst99eywzTRDsHoxi29wGsS4FwYlLUiOlnXwCcALtOMunaoAHWm9FZn2IWhP0UoEGp/kRG8EkbImsa4uNLctfdtcmYr3XZtOF1rueaoaUlpfrByNRGXucv2nyMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737157329; c=relaxed/simple; bh=POfrsUNWIq048XGnB7sBSN8xdPfF9XX/t9xz+NiNUvk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=V4zgK+Ck1lIZqC6mzSQKRO0o2rViJqLtzS1xv8qikIKqv5gBkvn8Ey0XSBkE6/vpWdq+7bShUSwH0jQTxlP99oTC5tPPeH9MT1+zgK1P2nwT6vqZF7FsPo8qDA2gP+KjS7Vo6KGAdTcPQtXQh9gcQGtUBhuklT7EuCnx/FoCvV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zaJAw/tq; arc=none smtp.client-ip=209.85.216.74 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zaJAw/tq" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2f2a9f056a8so5147840a91.2 for ; Fri, 17 Jan 2025 15:42:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737157327; x=1737762127; 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=u5+M48xEYsPxfpNh5jdjkOZetq5qZE6t5SXp0yc/k2M=; b=zaJAw/tqRmIs1TdEJJKbSEHfCyDrrCvpuUlSbJlAYMOdbIbpo14Y9bEzXe2dicGGGq LyAUYK3RP9IV34VjwqNPg1cgWhnf4dOj0+4qTQ2sC+rF25aCsstuTsNGHaQxHKarKHYe oPoT3BhDCLaTVBB6/NEuCyptJ4EWGuzYmw3Q9heuEjTmZh9PAVH5c8mKjQ+O60wpBNSE rzrsKK+vqkTju3zg6J1zXX8Aw+QRukvfWOazSpha9ceqfa1FLs1OlqKYO1Ti7YqQSQTv B6Ob0HRftwY1aH1ytjoXVRWh48T5GpPGSBRHLj/y2nmvzZgXsysDfm0S4+FyW+ALNaPt /sQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737157327; x=1737762127; 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=u5+M48xEYsPxfpNh5jdjkOZetq5qZE6t5SXp0yc/k2M=; b=Fhow0A3BVviEMt9eLOlDPjHGez8qgkxNWLnqR0xvBNhlW+yQ8kLXhk9QxNEz5ygrBW SWAAE6OahdcrkXvmd2i0cit7AuPRLj2ScOOJSJos5gXpOzwxHqqvaA3eVZ9FSND4bPBY tMz0wSYW0VbgXdaObcdHU/gD6jUtC5JWJ3KKKh5lCGrOFZLfLWK7+xL4rqe9SuQ1U+mT Vh94Fx7b6t7IrOMIuTD9C11c9ixxaw2gWBOMWDZP4IG1RN40I2vuWtw+n9BUhNgtlKpm 7pwJZJ7csg8GcETbCKcojYKt1xIxUGFDGYzfE4Fqbl+2NgmQCEYbIYzVyNK98iZuoOOC zzlg== X-Gm-Message-State: AOJu0YyiCc5xgrXqwI9wk3HajPLDNJA8CmzcQ7hwy1CoiY0pGKl2gbr1 7xpZN91XVvR3rRiKmrftt9txQ6dy8Vv/0PEsNwlhWzt0ubDQPXiLwEc3avIb7PLMEaeW2SoriS2 IWA== X-Google-Smtp-Source: AGHT+IGl6m0HjxHGktxDhc1qkC2rHr/QX1dmPhJzqq7Pyp3+7VIqcRHqfV4KIdxMFGQd93i0eQhdjm9Q+jM= X-Received: from pfbcg12.prod.google.com ([2002:a05:6a00:290c:b0:72d:b526:23ec]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:338b:b0:729:597:4f97 with SMTP id d2e1a72fcca58-72dafbd26d3mr8487641b3a.20.1737157327404; Fri, 17 Jan 2025 15:42:07 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 17 Jan 2025 15:41:59 -0800 In-Reply-To: <20250117234204.2600624-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250117234204.2600624-1-seanjc@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250117234204.2600624-2-seanjc@google.com> Subject: [PATCH 1/5] KVM: selftests: Make Intel arch events globally available in PMU counters test From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel test robot Wrap PMU counter test's array of Intel architectrual in a helper function so that the events can be queried in multiple locations. Add a comment to explain the need for a wrapper. No functional change intended. Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86/pmu_counters_test.c | 84 +++++++++++-------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/tools/testing/selftests/kvm/x86/pmu_counters_test.c b/tools/testing/selftests/kvm/x86/pmu_counters_test.c index accd7ecd3e5f..fe7d72fc8a75 100644 --- a/tools/testing/selftests/kvm/x86/pmu_counters_test.c +++ b/tools/testing/selftests/kvm/x86/pmu_counters_test.c @@ -33,6 +33,53 @@ static uint8_t kvm_pmu_version; static bool kvm_has_perf_caps; +#define X86_PMU_FEATURE_NULL \ +({ \ + struct kvm_x86_pmu_feature feature = {}; \ + \ + feature; \ +}) + +static bool pmu_is_null_feature(struct kvm_x86_pmu_feature event) +{ + return !(*(u64 *)&event); +} + +struct kvm_intel_pmu_event { + struct kvm_x86_pmu_feature gp_event; + struct kvm_x86_pmu_feature fixed_event; +}; + +/* + * Wrap the array to appease the compiler, as the macros used to construct each + * kvm_x86_pmu_feature use syntax that's only valid in function scope, and the + * compiler often thinks the feature definitions aren't compile-time constants. + */ +static struct kvm_intel_pmu_event intel_event_to_feature(uint8_t idx) +{ + const struct kvm_intel_pmu_event __intel_event_to_feature[] = { + [INTEL_ARCH_CPU_CYCLES_INDEX] = { X86_PMU_FEATURE_CPU_CYCLES, X86_PMU_FEATURE_CPU_CYCLES_FIXED }, + [INTEL_ARCH_INSTRUCTIONS_RETIRED_INDEX] = { X86_PMU_FEATURE_INSNS_RETIRED, X86_PMU_FEATURE_INSNS_RETIRED_FIXED }, + /* + * Note, the fixed counter for reference cycles is NOT the same as the + * general purpose architectural event. The fixed counter explicitly + * counts at the same frequency as the TSC, whereas the GP event counts + * at a fixed, but uarch specific, frequency. Bundle them here for + * simplicity. + */ + [INTEL_ARCH_REFERENCE_CYCLES_INDEX] = { X86_PMU_FEATURE_REFERENCE_CYCLES, X86_PMU_FEATURE_REFERENCE_TSC_CYCLES_FIXED }, + [INTEL_ARCH_LLC_REFERENCES_INDEX] = { X86_PMU_FEATURE_LLC_REFERENCES, X86_PMU_FEATURE_NULL }, + [INTEL_ARCH_LLC_MISSES_INDEX] = { X86_PMU_FEATURE_LLC_MISSES, X86_PMU_FEATURE_NULL }, + [INTEL_ARCH_BRANCHES_RETIRED_INDEX] = { X86_PMU_FEATURE_BRANCH_INSNS_RETIRED, X86_PMU_FEATURE_NULL }, + [INTEL_ARCH_BRANCHES_MISPREDICTED_INDEX] = { X86_PMU_FEATURE_BRANCHES_MISPREDICTED, X86_PMU_FEATURE_NULL }, + [INTEL_ARCH_TOPDOWN_SLOTS_INDEX] = { X86_PMU_FEATURE_TOPDOWN_SLOTS, X86_PMU_FEATURE_TOPDOWN_SLOTS_FIXED }, + }; + + kvm_static_assert(ARRAY_SIZE(__intel_event_to_feature) == NR_INTEL_ARCH_EVENTS); + + return __intel_event_to_feature[idx]; +} + static struct kvm_vm *pmu_vm_create_with_one_vcpu(struct kvm_vcpu **vcpu, void *guest_code, uint8_t pmu_version, @@ -197,41 +244,8 @@ static void __guest_test_arch_event(uint8_t idx, struct kvm_x86_pmu_feature even GUEST_TEST_EVENT(idx, event, pmc, pmc_msr, ctrl_msr, ctrl_msr_value, KVM_FEP); } -#define X86_PMU_FEATURE_NULL \ -({ \ - struct kvm_x86_pmu_feature feature = {}; \ - \ - feature; \ -}) - -static bool pmu_is_null_feature(struct kvm_x86_pmu_feature event) -{ - return !(*(u64 *)&event); -} - static void guest_test_arch_event(uint8_t idx) { - const struct { - struct kvm_x86_pmu_feature gp_event; - struct kvm_x86_pmu_feature fixed_event; - } intel_event_to_feature[] = { - [INTEL_ARCH_CPU_CYCLES_INDEX] = { X86_PMU_FEATURE_CPU_CYCLES, X86_PMU_FEATURE_CPU_CYCLES_FIXED }, - [INTEL_ARCH_INSTRUCTIONS_RETIRED_INDEX] = { X86_PMU_FEATURE_INSNS_RETIRED, X86_PMU_FEATURE_INSNS_RETIRED_FIXED }, - /* - * Note, the fixed counter for reference cycles is NOT the same - * as the general purpose architectural event. The fixed counter - * explicitly counts at the same frequency as the TSC, whereas - * the GP event counts at a fixed, but uarch specific, frequency. - * Bundle them here for simplicity. - */ - [INTEL_ARCH_REFERENCE_CYCLES_INDEX] = { X86_PMU_FEATURE_REFERENCE_CYCLES, X86_PMU_FEATURE_REFERENCE_TSC_CYCLES_FIXED }, - [INTEL_ARCH_LLC_REFERENCES_INDEX] = { X86_PMU_FEATURE_LLC_REFERENCES, X86_PMU_FEATURE_NULL }, - [INTEL_ARCH_LLC_MISSES_INDEX] = { X86_PMU_FEATURE_LLC_MISSES, X86_PMU_FEATURE_NULL }, - [INTEL_ARCH_BRANCHES_RETIRED_INDEX] = { X86_PMU_FEATURE_BRANCH_INSNS_RETIRED, X86_PMU_FEATURE_NULL }, - [INTEL_ARCH_BRANCHES_MISPREDICTED_INDEX] = { X86_PMU_FEATURE_BRANCHES_MISPREDICTED, X86_PMU_FEATURE_NULL }, - [INTEL_ARCH_TOPDOWN_SLOTS_INDEX] = { X86_PMU_FEATURE_TOPDOWN_SLOTS, X86_PMU_FEATURE_TOPDOWN_SLOTS_FIXED }, - }; - uint32_t nr_gp_counters = this_cpu_property(X86_PROPERTY_PMU_NR_GP_COUNTERS); uint32_t pmu_version = guest_get_pmu_version(); /* PERF_GLOBAL_CTRL exists only for Architectural PMU Version 2+. */ @@ -249,7 +263,7 @@ static void guest_test_arch_event(uint8_t idx) else base_pmc_msr = MSR_IA32_PERFCTR0; - gp_event = intel_event_to_feature[idx].gp_event; + gp_event = intel_event_to_feature(idx).gp_event; GUEST_ASSERT_EQ(idx, gp_event.f.bit); GUEST_ASSERT(nr_gp_counters); @@ -270,7 +284,7 @@ static void guest_test_arch_event(uint8_t idx) if (!guest_has_perf_global_ctrl) return; - fixed_event = intel_event_to_feature[idx].fixed_event; + fixed_event = intel_event_to_feature(idx).fixed_event; if (pmu_is_null_feature(fixed_event) || !this_pmu_has(fixed_event)) return; From patchwork Fri Jan 17 23:42:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13944042 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 B46B31DED69 for ; Fri, 17 Jan 2025 23:42:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737157331; cv=none; b=hH/J2/fmR9r8BojMHTLOqKI/vSXhZYxxKefmx81aen+QSizpDEln8WP7CIcK/bLNTr788IDBkNxe6IfK0FI4fjPPKfcYxch7K39yXBE2hb7094hzeUB/jLsDO41+XcILaGXRmNLhyp+lLc2hxFCw0QaIIQ/LrjIctugLB8DWI0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737157331; c=relaxed/simple; bh=oG+UNPon4gkSzKdzs76TaMgdm7fkMHtHqq0XNrKfbac=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OhUXlBQZEauuJEK8gAkIc4ySVHpj1gUTCyM1LprZmocfpzzL5q8LryzJbvl/eJ11sxxYEHDJPm7DkRVGP8D/aFAlOzRawQDuh6SlCpe2GUQbvoWSnLbM5XAf86C4G8KGdNiZBHDrMaViKNa7Kny4SFahTSpKAC22NBTWtbm91V0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=bjs9ww2y; arc=none smtp.client-ip=209.85.216.74 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bjs9ww2y" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef9e4c5343so7336861a91.0 for ; Fri, 17 Jan 2025 15:42:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737157329; x=1737762129; 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=qd1PnZJsvM1FzfBG7zwCaXko40uxMjzFk7maIYC2yc0=; b=bjs9ww2ydi8/jh0zu4aifgdlP1gNWRTmCTFSVBIq9zdLIAPLtPm/SnxKBbURgI+YM0 5PvlYyXqudXlkLm+fIfOmCMyvbd4Q11G14YZvixLnuancvRypWR/rXCbDpfZuDY0vksG p9DENB7pfqmmK08vU/cj1InwVu0SOJTu235EGDW7O4dk7kBJzbxBerodd41s/moHw4XI 2nq0bza8WlEOLayH/TDhRbXXesN4HKxCdKCVxLtcZbNZfj2xG3snh6BXGeNMs5Y+aKrn UGyvi/sax2KZoncoZo440SMzbPQnXVdBg7pm1e8gefu8HiCI5CHHnQz86e7xmsR76gBM m5GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737157329; x=1737762129; 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=qd1PnZJsvM1FzfBG7zwCaXko40uxMjzFk7maIYC2yc0=; b=kpIoxfKbPd4pPMX/DEhKJafvPOgRkbReJQ2Dk+8qpE1GUF0FjqKtfYLGmMw/BbDorC /C5xcnw27zQFyQrWpyVoFdu6LzpYcsm6iFae1SG4k+UzIETMPpIXKXckjpTUdQaB11wd b3RgF5NB7RYRSTsY/SKZQ9t87GxNm2v9Ra6WOsU4s8Qi8MP5VlTP1ZTrPRQEuslKALdl 2PQ2w6eXuxWVpW5PLgBNKCVMgwYSFvKcljhASL1bNLYglEmYsBXVexM5+C0aV54+Mslf qfHFJPvaYK8UheqwCiSXBS+gcDO6x12DTtUJ6YzfhfwIizTDdQ6+nq2zs06i5GsY7ZVL ilcQ== X-Gm-Message-State: AOJu0YzUMK6ZTGpWJLZCE05jBHJGrUnM1aeG5ZLui+BOzsZLc3xKPe1f Jh5hxdtNTaisTfduu40ikixzPbTo3f11vh7EmqLUPFmTqJ9bX9g9yvC1UN/E9AxGBqBQtS9Lz+f k0A== X-Google-Smtp-Source: AGHT+IGCq4VoYgzT8eHzKMuymfKx5/9tPYD6kuhsV64xxrafdgTzhG03udUQ7XcpETuQac3CcCLzzoXi8Es= X-Received: from pjtd5.prod.google.com ([2002:a17:90b:45:b0:2ee:53fe:d0fc]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5146:b0:2ea:a25d:3baa with SMTP id 98e67ed59e1d1-2f782c6639dmr6107387a91.5.1737157329063; Fri, 17 Jan 2025 15:42:09 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 17 Jan 2025 15:42:00 -0800 In-Reply-To: <20250117234204.2600624-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250117234204.2600624-1-seanjc@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250117234204.2600624-3-seanjc@google.com> Subject: [PATCH 2/5] KVM: selftests: Only validate counts for hardware-supported arch events From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel test robot In the Intel PMU counters test, only validate the counts for architectural events that are supported in hardware. If an arch event isn't supported, the event selector may enable a completely different event, and thus the logic for the expected count is bogus. This fixes test failures on pre-Icelake systems due to the encoding for the architectural Top-Down Slots event corresponding to something else (at least on the Skylake family of CPUs). Note, validation relies on *hardware* support, not KVM support and not guest support. Architectural events are all about enumerating the event selector encoding; lack of enumeration for an architectural event doesn't mean the event itself is unsupported, i.e. the event should still count as expected even if KVM and/or guest CPUID doesn't enumerate the event as being "architectural". Note #2, it's desirable to _program_ the architectural event encoding even if hardware doesn't support the event. The count can't be validated when the event is fully enabled, but KVM should still let the guest program the event selector, and the PMC shouldn't count if the event is disabled. Fixes: 4f1bd6b16074 ("KVM: selftests: Test Intel PMU architectural events on gp counters") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202501141009.30c629b4-lkp@intel.com Debugged-by: Dapeng Mi Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86/pmu_counters_test.c | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/x86/pmu_counters_test.c b/tools/testing/selftests/kvm/x86/pmu_counters_test.c index fe7d72fc8a75..8159615ad492 100644 --- a/tools/testing/selftests/kvm/x86/pmu_counters_test.c +++ b/tools/testing/selftests/kvm/x86/pmu_counters_test.c @@ -29,6 +29,8 @@ /* Total number of instructions retired within the measured section. */ #define NUM_INSNS_RETIRED (NUM_LOOPS * NUM_INSNS_PER_LOOP + NUM_EXTRA_INSNS) +/* Track which architectural events are supported by hardware. */ +static uint32_t hardware_pmu_arch_events; static uint8_t kvm_pmu_version; static bool kvm_has_perf_caps; @@ -89,6 +91,7 @@ static struct kvm_vm *pmu_vm_create_with_one_vcpu(struct kvm_vcpu **vcpu, vm = vm_create_with_one_vcpu(vcpu, guest_code); sync_global_to_guest(vm, kvm_pmu_version); + sync_global_to_guest(vm, hardware_pmu_arch_events); /* * Set PERF_CAPABILITIES before PMU version as KVM disallows enabling @@ -152,7 +155,7 @@ static void guest_assert_event_count(uint8_t idx, uint64_t count; count = _rdpmc(pmc); - if (!this_pmu_has(event)) + if (!(hardware_pmu_arch_events & BIT(idx))) goto sanity_checks; switch (idx) { @@ -560,7 +563,7 @@ static void test_fixed_counters(uint8_t pmu_version, uint64_t perf_capabilities, static void test_intel_counters(void) { - uint8_t nr_arch_events = kvm_cpu_property(X86_PROPERTY_PMU_EBX_BIT_VECTOR_LENGTH); + uint8_t nr_arch_events = this_cpu_property(X86_PROPERTY_PMU_EBX_BIT_VECTOR_LENGTH); uint8_t nr_fixed_counters = kvm_cpu_property(X86_PROPERTY_PMU_NR_FIXED_COUNTERS); uint8_t nr_gp_counters = kvm_cpu_property(X86_PROPERTY_PMU_NR_GP_COUNTERS); uint8_t pmu_version = kvm_cpu_property(X86_PROPERTY_PMU_VERSION); @@ -582,18 +585,26 @@ static void test_intel_counters(void) /* * Detect the existence of events that aren't supported by selftests. - * This will (obviously) fail any time the kernel adds support for a - * new event, but it's worth paying that price to keep the test fresh. + * This will (obviously) fail any time hardware adds support for a new + * event, but it's worth paying that price to keep the test fresh. */ TEST_ASSERT(nr_arch_events <= NR_INTEL_ARCH_EVENTS, "New architectural event(s) detected; please update this test (length = %u, mask = %x)", - nr_arch_events, kvm_cpu_property(X86_PROPERTY_PMU_EVENTS_MASK)); + nr_arch_events, this_cpu_property(X86_PROPERTY_PMU_EVENTS_MASK)); /* - * Force iterating over known arch events regardless of whether or not - * KVM/hardware supports a given event. + * Iterate over known arch events irrespective of KVM/hardware support + * to verify that KVM doesn't reject programming of events just because + * the *architectural* encoding is unsupported. Track which events are + * supported in hardware; the guest side will validate supported events + * count correctly, even if *enumeration* of the event is unsupported + * by KVM and/or isn't exposed to the guest. */ nr_arch_events = max_t(typeof(nr_arch_events), nr_arch_events, NR_INTEL_ARCH_EVENTS); + for (i = 0; i < nr_arch_events; i++) { + if (this_pmu_has(intel_event_to_feature(i).gp_event)) + hardware_pmu_arch_events |= BIT(i); + } for (v = 0; v <= max_pmu_version; v++) { for (i = 0; i < ARRAY_SIZE(perf_caps); i++) { From patchwork Fri Jan 17 23:42:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13944043 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 6BC2B1DEFCD for ; Fri, 17 Jan 2025 23:42:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737157333; cv=none; b=Wf1B7z4UpIvUMRwNNJ2pRt9PSgaPhY4QneGe8K7PcG8YOMHJpNhei6PoUXgVtOSDuH0lYinR11LcHl6eO452E9T3NNZtWov52CKkfnRyz7qQD414LxVyRLWbleHo5s/m7fB92d6ITu7KPl0a2tTOrEk8eLq3u4XFrT+wFBp80N0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737157333; c=relaxed/simple; bh=UgNzJe2HpFIZOmF+tKSnwRW92d2shs8YrcRwvXNVrKA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DfMOeUq/mQEla863l8bWl+xW6Mbfc8krFOJ/Gc7rSdUU2ortwoh4LYO33nXcor6uFKNzzoDtcas7wGTYSVcdGUANMrMIAbMPeGyJX71qkiE+3l/8OWcptRkorO/8Iqu8tnoFrN4NMLfo3xUMq95LGPUhJZixl3I3bS5MEfJ6UUA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QTQIc0kt; arc=none smtp.client-ip=209.85.214.202 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QTQIc0kt" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-216430a88b0so54146755ad.0 for ; Fri, 17 Jan 2025 15:42:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737157331; x=1737762131; 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=F2492f7FPUKL3RQM1y5e+QPeaYBUqrrlq2XUG+1uNeI=; b=QTQIc0ktWy/K/nbmTD2o7Wm9lruGxnLybuSVz6V6GVLsZWOGtFHeWUmKH99HR3rOJx xkJ4WzEiBazESX58cCe9HTKMO6/mvtGF271pbq9SCzYKaPImXrkSa0RqdWQI4hRS+skZ QM+14ha1XE9hvkeJuuStgfC6KXTPoBqC01Wd69lTzYlYpUafMptgAeaYOgFhTUGrQQYs HZxLvbmbAkyEEmdvtTtoRY0SxeXQyk0FsWp89b8NNJC39a3rmDJbym7TjS+AKQTAzNY+ IsFBHjYXYTTn2M67Cx7hsDPSbOrzE8tEy+UWyPP57kkDuZrMQskgInORO0Llj9BxnfnB YX9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737157331; x=1737762131; 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=F2492f7FPUKL3RQM1y5e+QPeaYBUqrrlq2XUG+1uNeI=; b=tsaTLYG1YwBHZv5JI39QmpaF0yLEOMun8ki+6sg50FhvTx073uP0FqgJM+JjVM4nze DD62A59a8Y8trz9nzyuZSVviuoCcvnqU/3T8piRbXIyEhWgnFJBcfb/unWtuol9h6Rru xm4841QYdL4MB0S+TqTl4BZeCuen/W8n0yheH+B2zh/wTmUyjV8hB5HtQDF9UK78teoH pjoGZbsrF55cTobPXequwZrWDhPyhL/3gdyeHC3ETx5hlV3wMYgjonp5uW4/mMolwIdm uuJRUnEjNsXIsGLxMwKl9iFk9nG8FRDudpPQlDuZyMUnYEPi4k2GkQr9QhIVEPAEB5L3 M2/Q== X-Gm-Message-State: AOJu0Yyzo9FMD9EEcK839SGeMlBgcW3O0hWKLrJ7ew6FJ2CnfWMk5zNj 7UGepC5UZyZ4we2yfDJC0lps0+4jvVLtZHwdCj/1YQUTAknSo3G2P4BdimAKP2mhzXNU3OLMCNK 3Zg== X-Google-Smtp-Source: AGHT+IEutRKWetWajOjuPthgKFxwMopyW+ltQmCIIbAd9AjyS3fmj4hN5vvPtxTp1Msub1a8TFENrUJtLiI= X-Received: from pgbcm6.prod.google.com ([2002:a05:6a02:a06:b0:801:d783:5f1e]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:32a3:b0:1e8:bd15:6801 with SMTP id adf61e73a8af0-1eb2158bd23mr7439870637.29.1737157330717; Fri, 17 Jan 2025 15:42:10 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 17 Jan 2025 15:42:01 -0800 In-Reply-To: <20250117234204.2600624-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250117234204.2600624-1-seanjc@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250117234204.2600624-4-seanjc@google.com> Subject: [PATCH 3/5] KVM: selftests: Remove dead code in Intel PMU counters test From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel test robot Drop the local "nr_arch_events" in the Intel PMU counters test as the test asserts that "nr_arch_events <= NR_INTEL_ARCH_EVENTS", and then sets nr_arch_events to the max of the two. I.e. nr_arch_events is guaranteed to be NR_INTEL_ARCH_EVENTS for the meat of the test, just use NR_INTEL_ARCH_EVENTS directly. No functional change intended. Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86/pmu_counters_test.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/x86/pmu_counters_test.c b/tools/testing/selftests/kvm/x86/pmu_counters_test.c index 8159615ad492..5d6a5b9c17b3 100644 --- a/tools/testing/selftests/kvm/x86/pmu_counters_test.c +++ b/tools/testing/selftests/kvm/x86/pmu_counters_test.c @@ -563,7 +563,6 @@ static void test_fixed_counters(uint8_t pmu_version, uint64_t perf_capabilities, static void test_intel_counters(void) { - uint8_t nr_arch_events = this_cpu_property(X86_PROPERTY_PMU_EBX_BIT_VECTOR_LENGTH); uint8_t nr_fixed_counters = kvm_cpu_property(X86_PROPERTY_PMU_NR_FIXED_COUNTERS); uint8_t nr_gp_counters = kvm_cpu_property(X86_PROPERTY_PMU_NR_GP_COUNTERS); uint8_t pmu_version = kvm_cpu_property(X86_PROPERTY_PMU_VERSION); @@ -588,9 +587,10 @@ static void test_intel_counters(void) * This will (obviously) fail any time hardware adds support for a new * event, but it's worth paying that price to keep the test fresh. */ - TEST_ASSERT(nr_arch_events <= NR_INTEL_ARCH_EVENTS, + TEST_ASSERT(this_cpu_property(X86_PROPERTY_PMU_EBX_BIT_VECTOR_LENGTH) <= NR_INTEL_ARCH_EVENTS, "New architectural event(s) detected; please update this test (length = %u, mask = %x)", - nr_arch_events, this_cpu_property(X86_PROPERTY_PMU_EVENTS_MASK)); + this_cpu_property(X86_PROPERTY_PMU_EBX_BIT_VECTOR_LENGTH), + this_cpu_property(X86_PROPERTY_PMU_EVENTS_MASK)); /* * Iterate over known arch events irrespective of KVM/hardware support @@ -600,8 +600,7 @@ static void test_intel_counters(void) * count correctly, even if *enumeration* of the event is unsupported * by KVM and/or isn't exposed to the guest. */ - nr_arch_events = max_t(typeof(nr_arch_events), nr_arch_events, NR_INTEL_ARCH_EVENTS); - for (i = 0; i < nr_arch_events; i++) { + for (i = 0; i < NR_INTEL_ARCH_EVENTS; i++) { if (this_pmu_has(intel_event_to_feature(i).gp_event)) hardware_pmu_arch_events |= BIT(i); } @@ -620,8 +619,8 @@ static void test_intel_counters(void) * vector length. */ if (v == pmu_version) { - for (k = 1; k < (BIT(nr_arch_events) - 1); k++) - test_arch_events(v, perf_caps[i], nr_arch_events, k); + for (k = 1; k < (BIT(NR_INTEL_ARCH_EVENTS) - 1); k++) + test_arch_events(v, perf_caps[i], NR_INTEL_ARCH_EVENTS, k); } /* * Test single bits for all PMU version and lengths up @@ -630,11 +629,11 @@ static void test_intel_counters(void) * host length). Explicitly test a mask of '0' and all * ones i.e. all events being available and unavailable. */ - for (j = 0; j <= nr_arch_events + 1; j++) { + for (j = 0; j <= NR_INTEL_ARCH_EVENTS + 1; j++) { test_arch_events(v, perf_caps[i], j, 0); test_arch_events(v, perf_caps[i], j, 0xff); - for (k = 0; k < nr_arch_events; k++) + for (k = 0; k < NR_INTEL_ARCH_EVENTS; k++) test_arch_events(v, perf_caps[i], j, BIT(k)); } From patchwork Fri Jan 17 23:42:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13944044 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 7F9A71DEFD0 for ; Fri, 17 Jan 2025 23:42:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737157335; cv=none; b=bRKQpHIZZs638+kDOcxWOzokUMsQYql0nxsdvLfYksTG5ZVYlP+rF/Z+pUKL7znVElKGsZooP2/SDyvHcHeBQfP9U6VMY9QHoeKqUOKc3JVqWINXLccQfhisCHunqYTx0SQQoZFFn5mZJlDSdNBlR/voDPJEPkgfgm5JbMzYS+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737157335; c=relaxed/simple; bh=ZOZoGCVVjfxwPE63Fb+anUDkEumJG2NT8k4n4QFHs9A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jYYSLfDys2lwMNVbKXUxrvbO6eNxLDcHHHVeuWgnLbosD8tmN3BuTQs3gQuyGopo+SeMTko0WhtUjWvYgxrJdr0N1/MG0SnCPi6Wlxo7kxlfduQnWj/lOGiedBmz7niBtYwTbqhYoliy5S92jY+7E+8JCFI36RtRIsFrlb/rvVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0QUH+eUl; arc=none smtp.client-ip=209.85.214.201 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0QUH+eUl" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2165433e229so54687595ad.1 for ; Fri, 17 Jan 2025 15:42:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737157332; x=1737762132; 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=UJQf1vg2Z73BDDDgXp9DDB+nVYcRI9guP/ajlKCHN4g=; b=0QUH+eUlWNblb9wLmi7wRjDMcnGuyvQ5X+6Ow5xJvRGjPSd522/NY3V45u1dVZqoft N0r2Y86MTmr/PcXqduqhJSWGCHobg+b+06zADV+Qc+Leugaao/UG/tdJHkK+HgcVjw8W V43ci0F8ZymPvrJtFdCI/qr6gO8KC58JqNsIG6LCT4byvqTPUw9lq5sRGqD2m2bBHHfk hhAjBgBOC+U2Za7WIiz+BrMPltjM00ncRczg/pwqG4EPYr/ymknlz+b1LErfvPOg8kbQ dLVUl2a3S/uM/NeiTV2+zL/Cv3MqwNe5S3DE6deqqy7Y1P3rZlOuvos08GoT2yq8IrYO nAkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737157332; x=1737762132; 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=UJQf1vg2Z73BDDDgXp9DDB+nVYcRI9guP/ajlKCHN4g=; b=EMjz/PYDEr8DQvwIJ89/so4jwAGdQY5bNK5zs4pfYdE58V2uYQOhL6BmavCbaLRIcU Fqz6Iz2wEUhlKhAt2Et2p/T5HOi6Uaj1ZPbbV3ub5lb8w4CxUVYk4mBhNEvpu6vL4vtq FuRbVzx26xD5fb6x8fk5POytlcUyIlrspue4XAQErCdWgdgE21ByFFhA6SAIjcZAxUUP Kdet8IGjuPHPyPBqgzeZF4OABhC+ky59L8mF/M6LveH8MmeExf+uxUU6ct9+k13TXNPJ d6ScUY/E85J4p+zABSjN/IY1iQi4E1EX9CP6FBwmVhxSvO54c46VV+IZwAdNw+79faej n6ow== X-Gm-Message-State: AOJu0YyDrqlRdr7iiOPpHzyZFoSNtuHx63WTPNZN/kXMe+9qypy4Iu0F 2aO/1P+g8CojX7pbITi+mQKrCgUVlY9EvV0a5J/mOdgJXLqFLzahkzYYdrAzIs8bQhnv7g5tQgq 54A== X-Google-Smtp-Source: AGHT+IHAZZuFQSpQ2KtVwY8a38VsEnuTS+M1mZ9T6GgAxDV6x3yWEr1YlzfIlLku3fU1H6bhMmu72cUeHNs= X-Received: from pllq16.prod.google.com ([2002:a17:902:7890:b0:212:5134:8485]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:947:b0:216:5b64:90f6 with SMTP id d9443c01a7336-21c355fa2eamr68609215ad.45.1737157332542; Fri, 17 Jan 2025 15:42:12 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 17 Jan 2025 15:42:02 -0800 In-Reply-To: <20250117234204.2600624-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250117234204.2600624-1-seanjc@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250117234204.2600624-5-seanjc@google.com> Subject: [PATCH 4/5] KVM: selftests: Drop the "feature event" param from guest test helpers From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel test robot Now that validation of event count is tied to hardware support for event, and not to guest support for an event, drop the unused "event" parameter from the various helpers. No functional change intended. Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86/pmu_counters_test.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/kvm/x86/pmu_counters_test.c b/tools/testing/selftests/kvm/x86/pmu_counters_test.c index 5d6a5b9c17b3..ea1485a08c78 100644 --- a/tools/testing/selftests/kvm/x86/pmu_counters_test.c +++ b/tools/testing/selftests/kvm/x86/pmu_counters_test.c @@ -148,9 +148,7 @@ static uint8_t guest_get_pmu_version(void) * Sanity check that in all cases, the event doesn't count when it's disabled, * and that KVM correctly emulates the write of an arbitrary value. */ -static void guest_assert_event_count(uint8_t idx, - struct kvm_x86_pmu_feature event, - uint32_t pmc, uint32_t pmc_msr) +static void guest_assert_event_count(uint8_t idx, uint32_t pmc, uint32_t pmc_msr) { uint64_t count; @@ -223,7 +221,7 @@ do { \ ); \ } while (0) -#define GUEST_TEST_EVENT(_idx, _event, _pmc, _pmc_msr, _ctrl_msr, _value, FEP) \ +#define GUEST_TEST_EVENT(_idx, _pmc, _pmc_msr, _ctrl_msr, _value, FEP) \ do { \ wrmsr(_pmc_msr, 0); \ \ @@ -234,17 +232,16 @@ do { \ else \ GUEST_MEASURE_EVENT(_ctrl_msr, _value, "nop", FEP); \ \ - guest_assert_event_count(_idx, _event, _pmc, _pmc_msr); \ + guest_assert_event_count(_idx, _pmc, _pmc_msr); \ } while (0) -static void __guest_test_arch_event(uint8_t idx, struct kvm_x86_pmu_feature event, - uint32_t pmc, uint32_t pmc_msr, +static void __guest_test_arch_event(uint8_t idx, uint32_t pmc, uint32_t pmc_msr, uint32_t ctrl_msr, uint64_t ctrl_msr_value) { - GUEST_TEST_EVENT(idx, event, pmc, pmc_msr, ctrl_msr, ctrl_msr_value, ""); + GUEST_TEST_EVENT(idx, pmc, pmc_msr, ctrl_msr, ctrl_msr_value, ""); if (is_forced_emulation_enabled) - GUEST_TEST_EVENT(idx, event, pmc, pmc_msr, ctrl_msr, ctrl_msr_value, KVM_FEP); + GUEST_TEST_EVENT(idx, pmc, pmc_msr, ctrl_msr, ctrl_msr_value, KVM_FEP); } static void guest_test_arch_event(uint8_t idx) @@ -280,7 +277,7 @@ static void guest_test_arch_event(uint8_t idx) if (guest_has_perf_global_ctrl) wrmsr(MSR_CORE_PERF_GLOBAL_CTRL, BIT_ULL(i)); - __guest_test_arch_event(idx, gp_event, i, base_pmc_msr + i, + __guest_test_arch_event(idx, i, base_pmc_msr + i, MSR_P6_EVNTSEL0 + i, eventsel); } @@ -295,7 +292,7 @@ static void guest_test_arch_event(uint8_t idx) wrmsr(MSR_CORE_PERF_FIXED_CTR_CTRL, FIXED_PMC_CTRL(i, FIXED_PMC_KERNEL)); - __guest_test_arch_event(idx, fixed_event, i | INTEL_RDPMC_FIXED, + __guest_test_arch_event(idx, i | INTEL_RDPMC_FIXED, MSR_CORE_PERF_FIXED_CTR0 + i, MSR_CORE_PERF_GLOBAL_CTRL, FIXED_PMC_GLOBAL_CTRL_ENABLE(i)); From patchwork Fri Jan 17 23:42:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13944045 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 DED781DF27E for ; Fri, 17 Jan 2025 23:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737157336; cv=none; b=c7dP1kPQpqqWpWRKAxy6V0iDb/MXvaibzBdDXc8N/paH05PYV5Qb+8yEkqQnxyLFFRgUq1/SJgdl0h9e53rKFbFRPJ3dlgRkmuMo8c9wip0S3f/4DUALWPYlPx3vMs3zt6ANpQ24iBmkzVmjKxM88Ft/Hpm2jPrF8TgWDpQNntg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737157336; c=relaxed/simple; bh=DAhep5Ase+lzMS0yxjMlf3nQhuSF+WH7RFRAClM9nmA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cyhK9ZkihHmdAyRMjGyI/KvV5RGtH8LoK0lB53sKQ40u+qicCGH1ptkqjA4nb2E8umTnmwJbAC5eGFvTPB2XyLGJh5EUTEat9d3rV4aznwnqlBiuC2WxcTcfdw+B4sPZqCl+i7L+Cj4+MNMZSBUqV5BS0cQR7Yyb7ouItrU4OYQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=va0eWlAA; arc=none smtp.client-ip=209.85.214.202 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="va0eWlAA" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-21655569152so51840865ad.2 for ; Fri, 17 Jan 2025 15:42:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737157334; x=1737762134; 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=Pxxocry5JF8tR6kff16FhjmhaVcMoVJgF5laflTBa1A=; b=va0eWlAAB30fE2SsWaElGtzOWLGoKezL4arLdK9/Hs2ba6mRz94L7iBkC05jwpnTy/ xyZ21DAPfwM9FgeTf30wQZXivGqQLDHmQpkHBzR7wtgT2vbeEHeth21HF/qd2qidbnKH OlN65K64C0HSJ5Uvg5CWnQmZ8QYq+6DSQ2QcpUU8KkK29Tzm1zuh3djsh2VzWtYGNBK5 K81arHTdwcVJaP3MK6Djxx2nDRlrkXwg+Yc785F9n7CGaWPd7B2Q89h7/sH5ZwVFFm7w kjNFflLxR9sYEYj+UMnJPVNUZi1zDCNPhnRMQKHhHannzGM1Ntm/nJk11jEhZYt7FilL VPZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737157334; x=1737762134; 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=Pxxocry5JF8tR6kff16FhjmhaVcMoVJgF5laflTBa1A=; b=oW1ClcqawHy+5F/xCGshsOA8UvskYdNlDosezY3BnUEhKV2z8v62bgh37QKlRfgSOx B6wlV4h5VX2G8TRk0pZUmkZg2hxFuO+YbWpCYKhc3bhhLQa5vcsNlyVlM3NydJqXI27S aagoHBArUF4yefMLQxc4HXyY3WFYp0LtFMjaOZWorrJ8Dm81zKlLcBbHYauCtAmkPjBR uPvqDUhNMNeA79e49mhDmrqJ/xqFH+2rPocYbRxsIQMsFLrLpqtMVR8tnmTmNh7ZX7Be qUrhTkj0cKN+kph8pkbEAEy+IbaO7Zyhk40GYB2nqeWI0Wcp2NsTprxneGw0GL5bSQdA dzKg== X-Gm-Message-State: AOJu0Yx4RnKC+LOyiHhZodFjN6z3hBsJN3OmrEKlrw2Ie5/yEQ1aUohJ xHca2Rwlm6UMIodwYd5Caq2SErhALMftDQUQJcJgzExEnNWAOw30uxAkStGCmc/0Axc/uNq7y6e +xA== X-Google-Smtp-Source: AGHT+IEaLt2kHxRo8izrrxWWtdVHMGzvIZ9FdNE/IPsW8hD4WzO+hrVwOHBFnStH3DvZx+QCOFX/xnP1GWQ= X-Received: from pfbcg12.prod.google.com ([2002:a05:6a00:290c:b0:72d:b526:23ec]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:928b:b0:72d:8d98:c257 with SMTP id d2e1a72fcca58-72daf930ff5mr6435991b3a.2.1737157334291; Fri, 17 Jan 2025 15:42:14 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 17 Jan 2025 15:42:03 -0800 In-Reply-To: <20250117234204.2600624-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250117234204.2600624-1-seanjc@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250117234204.2600624-6-seanjc@google.com> Subject: [PATCH 5/5] KVM: selftests: Print out the actual Top-Down Slots count on failure From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel test robot Print out the expected vs. actual count of the Top-Down Slots event on failure in the Intel PMU counters test. GUEST_ASSERT() only expands constants/macros, i.e. only prints the value of the expected count, which makes it difficult to debug and triage failures. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/x86/pmu_counters_test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86/pmu_counters_test.c b/tools/testing/selftests/kvm/x86/pmu_counters_test.c index ea1485a08c78..8aaaf25b6111 100644 --- a/tools/testing/selftests/kvm/x86/pmu_counters_test.c +++ b/tools/testing/selftests/kvm/x86/pmu_counters_test.c @@ -174,7 +174,9 @@ static void guest_assert_event_count(uint8_t idx, uint32_t pmc, uint32_t pmc_msr GUEST_ASSERT_NE(count, 0); break; case INTEL_ARCH_TOPDOWN_SLOTS_INDEX: - GUEST_ASSERT(count >= NUM_INSNS_RETIRED); + __GUEST_ASSERT(count >= NUM_INSNS_RETIRED, + "Expected top-down slots >= %u, got count = %lu", + NUM_INSNS_RETIRED, count); break; default: break;