From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.20 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796149327; b=EOm3dXRdrBCIep5KVQR2W5LuKKgvV9fmFTDcEwMo9YfoGkzDqHVpYFUBlLrN9q7z6Tx4 vzX2c87o17Cgmg/Key0z7x4JdvWgGN6M1kxNZXLbQNqM1vZVjyMyTCxMX+50k1yKPVrRr n+iG1HVv7kUH+8ps7WZ8IxXZgG0qIybJVGYSy1P59X/OoLVmb2s2CHBAnEThBb1JBoIbx 5tj6KELD9+MO1vW51qmw5keEhusoDkqSzNt8iH+X3CeYBCYxHppytp8DX8nDiOd9Ev0F+ XrpRl6y5zWeOcXxIpbiksh0q47Kqk2km0ZUNNeORCRiT83AwfDoYOu/MJgrbDQHyyRA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796149327; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:Content-Language: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=jj+zDZRH4lBCqundswepZ3ymxoAuaynI3RMfl2+1m/g=; b=minhdpqXLsixfShNkWeL7WnFgcky6aVPxBmqe0wCHDr0WHImgKo7wWh+eg963NDXF119 uw1TxBwT/mTwbFJqlHTBB7xLIlpCvYW6pJNfNGJltAgLXWEAx+83+HQ+x9mLSLk2A1yO6 6cZ5yW/ZvY3+hTx4QmfMMtdl1mTKzGXhD0/tnm5KVKP5BlANWYlK97QKuFnFIdn42GNGy Lqt1GvBD5gBQkEAgj1EIamvM7AL3emAg0OZYparLKznCK2PRKEZ3e9EH2sBDfbXCu5bWW TBcUzdgQDmZb9gODQJF6zuANIMPWVOCqg8VqNobCc0idxlZ9rslDhi5saGXDrJ5F/6w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=eNsV3OtX; arc=none smtp.remote-ip=198.175.65.20 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19D38606A31A; Tue, 1 Dec 2026 18:22:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 19D38606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=eNsV3OtX DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796149327; x=1827685327; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=jj+zDZRH4lBCqundswepZ3ymxoAuaynI3RMfl2+1m/g=; b=eNsV3OtX43zRDO6O+04xSn/SYQCKVvAzk35mFKA+AhUl+ZeNgktmDcBv gko498FgeFUkXtrAnCBs+Vu4whpf6BAmGbAj+WNk/wovD2GOP18yEbYEn f1RpdYC+GBCXs7XM0Ot/zI3tSxlBNfwy8Ni9Aa++2JYHzA6yImPB6GAcx ckhlFpboIWoPLfUTlZHlmQ3DTTackwP1GKU3/wtUFd3u9mZXwnlwbhI1H 7qzpSWzLPuPDl9m6mVxcgxawAu8Ax+uzqvfzGSZcmxmxCREmf7I8Lkc/+ aOHuvQ0Et8H07Zpb38Jf1BHy831OzUnSIIRVr1RUNb4xB3rrXVyqf9Rd2 w==; X-CSE-ConnectionGUID: dGEgQhYlRXqLGH/ztnUM3g== X-CSE-MsgGUID: 0Gl68TX/TbGsivEWggp6EQ== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5084243" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="5084243" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 10:21:17 -0800 X-CSE-ConnectionGUID: Ck9JqGYkSEq4h957BNbt3A== X-CSE-MsgGUID: 8VF97BIPR5Wdag1z46e3Yw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13873814" Received: from soc-cp83kr3.clients.intel.com (HELO [10.122.184.203]) ([10.122.184.203]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 10:21:16 -0800 Message-ID: Date: Tue, 1 Dec 2026 12:21:14 -0600 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v10 18/18] KVM: selftests: Add Topdown PERF_METRICS test To: "Mi, Dapeng" , Sean Christopherson , Paolo Bonzini , Peter Zijlstra Cc: kvm@vger.kernel.org, Jim Mattson , Yosry Ahmed , Andi Kleen , Stephane Eranian , linux-kernel@vger.kernel.org, Mingwei Zhang , Das Sandipan , Shukla Manali , Xudong Hao References: <20261124213901.120572-1-zide.chen@intel.com> <20261124213901.120572-19-zide.chen@intel.com> <52cf1381-d759-490e-aff1-b824372a77fe@linux.intel.com> Content-Language: en-US From: "Chen, Zide" In-Reply-To: <52cf1381-d759-490e-aff1-b824372a77fe@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/1/2026 3:35 AM, Mi, Dapeng wrote: >> diff --git a/tools/testing/selftests/kvm/x86/pmu_perf_metrics_test.c b/tools/testing/selftests/kvm/x86/pmu_perf_metrics_test.c >> new file mode 100644 >> index 000000000000..07a6c948e4cd >> --- /dev/null >> +++ b/tools/testing/selftests/kvm/x86/pmu_perf_metrics_test.c >> @@ -0,0 +1,391 @@ >> +// SPDX-License-Identifier: GPL-2.0-only >> +/* >> + * Test for KVM Topdown Microarchitecture Analysis (TMA) and PERF_METRICS. >> + * >> + * Copyright (C) 2026, Intel Corporation >> + */ >> + >> +#include >> + >> +#include "processor.h" >> +#include "pmu.h" >> + >> +/* Number of iterations of the loop for the guest measurement payload. */ >> +#define NUM_LOOPS 10 >> +#define PERF_METRICS_TEST_VAL 0x12345678ULL > > The sum of 4 metric fields is 0x114, which is far away from 0xff. Could we > change it to an available value? Nice catch! While WRMSR does not enforce the arithmetic sum of the Level-1 metric fields (only validating reserved bits), using an architecturally valid value whose Level-1 metrics sum to 0xff avoids confusion. I will update it to 0x12345663ULL (0x12 + 0x34 + 0x56 + 0x63 == 0xff). >> +#define SLOTS_TEST_VAL 0x12345ULL >> + >> +static void guest_test_rdpmc(u32 rdpmc_idx, bool expect_success, u64 expected_val) >> +{ >> + u8 vector; >> + u64 val; >> + >> + vector = rdpmc_safe(rdpmc_idx, &val); >> + __GUEST_ASSERT(expect_success ? !vector : vector == GP_VECTOR, >> + "Expected %s on RDPMC(0x%x), got %s", >> + expect_success ? "no fault" : "#GP", rdpmc_idx, ex_str(vector)); >> + if (expect_success) >> + GUEST_ASSERT_EQ(val, expected_val); >> + >> + if (!is_forced_emulation_enabled) >> + return; >> + >> + vector = rdpmc_safe_fep(rdpmc_idx, &val); >> + __GUEST_ASSERT(expect_success ? !vector : vector == GP_VECTOR, >> + "Expected %s on FEP RDPMC(0x%x), got %s", >> + expect_success ? "no fault" : "#GP", rdpmc_idx, ex_str(vector)); >> + if (expect_success) >> + GUEST_ASSERT_EQ(val, expected_val); >> +} > > There is a similar guest_test_rdpmc() helper in pmu_counters_test.c. Better > move the helper into a common header and then avoid the duplication. guest_test_rdpmc() is just ~15 lines of test assertion glue. Moving it into pmu.h requires exporting ad-hoc assertion macros like GUEST_ASSERT_PMC_MSR_ACCESS and GUEST_ASSERT_PMC_VALUE, and it encodes test-specific expectations (#GP vs exact match) into an architectural header. I guess in selftests, a little duplicated assertion is often preferred over polluting common headers. This is unlike GUEST_MEASURE_EVENT(), which is a complex inline assembly primitive where duplication would be error-prone and a maintenance burden. That said, if you still feel strongly about deduplicating it, I am open to moving it. > Others look good to me. Thanks.