From patchwork Tue Oct 31 09:29:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mi, Dapeng" X-Patchwork-Id: 160032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b90f:0:b0:403:3b70:6f57 with SMTP id t15csp108874vqg; Tue, 31 Oct 2023 02:22:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFR0z1RfhZUpX1md8dMJYadqJHSBYyTQPEo0rSIixG7gV7tNthonPB3p4kpJMrX+fAETYG X-Received: by 2002:a17:902:d492:b0:1cc:361b:7b10 with SMTP id c18-20020a170902d49200b001cc361b7b10mr5216051plg.24.1698744138217; Tue, 31 Oct 2023 02:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698744138; cv=none; d=google.com; s=arc-20160816; b=mGuBAtqMWoq/W1lMA/oyCMbdR15Nf0Aoyo2Kgt/DyAOJFJSUcU0DimCpU/0p1y4Yol fvqzUqxoYDctUj13iHRP3egw50dCclmOPLxy0I3DoEC7NwgXyJhjVTRfyaxut9J/VWvv UrJHimY6d21Zi/cE4wFkZ7DwVWXeWhLapwbA89Mr/NtoI1semUAK58GmR0/2k4w6B1+m /Sb6hqZWN7JfKBsbe1HRiIV2rAu9q7oOq1v6i31M0+rzHwA7SFO9vQVjwUOts6Y0WSOn oUQJ2eLWWd14gZgZMByM2ra0fP14+pXObJ52h0NojyyKz++JMJoNts6IC6381vil79MI vgbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=B+0MshwLV/DpfjNdkFno6rBuEKezzJjEruxroCSkB6w=; fh=E3ilibYCxplRFz20OpOkjMj1lMKBPGRzcx1abGX98y8=; b=pOBzR4fOsWKbpkffyfXOfmxfnMlUSVxc//l7LWBN+PT2EjXzYFWNrWCfO+LjPCUVOc CvigTqxykAMBMIH/IWAnHj0r3DluU4zegWYCZg0+DkkmRidvGAJDaC6I/F4q7fFf3yKZ 34YAhBKShi8j+NARiUYGTqTwp+3VdNHsEDMsFP6dciSKl88X23eDCedc6XvSIKQ5y7oh axy//l2oZ3eH/buLqiqnVI0RiqAd7E4Jn7r2MNtORfQoa7CeYZ+bm1SW+0W5hvEk52j9 5KAFVKo7C6PQdv2pe+cjYTcECARbtf6TMhJj4uKWQ/m3wtLgksvb/BvJVmXbSZgKrR9u 4eVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B8h1ZqJ5; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id t13-20020a1709028c8d00b001ca7fab771esi727596plo.609.2023.10.31.02.22.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 02:22:18 -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=@intel.com header.s=Intel header.b=B8h1ZqJ5; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id D18C680A801F; Tue, 31 Oct 2023 02:22:05 -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 S1343852AbjJaJVy (ORCPT + 34 others); Tue, 31 Oct 2023 05:21:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343834AbjJaJVw (ORCPT ); Tue, 31 Oct 2023 05:21:52 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FD9CDA; Tue, 31 Oct 2023 02:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698744110; x=1730280110; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y4GdVfvr4r3TS2jPrXzPuftPnG1qKJX1nHclPM7uF4Y=; b=B8h1ZqJ5LJ0kXzUMbyieDxzE9uMPKbngWyyUyqaj7szBaKtFugZH9mWO GemQSRSQ+SeK+sIunqhrZdDfZboNE+D8NWuY1cMzyFu0AWA3P++XJ3Vem 53rVh1A8d0fo57ASxEFGTg8G/+5X6MRfH+jWsQr9TsdiFuu7EznvyuSUb IyWwjruBB615rYVFCWqk+DIXDrayEqYIT3K1GJJOMrlSVfDQ3fh/MHgXZ loOY7HHRT3qZCAFeFd7ZKSHqjY/aTqd3u/QaUH9Aea67ZtA7NZ2J1aDkU MG78U9iNpoHej9IT3hzbuHdu2qOWO+0zY7YeGj+H6fHQAJGps3+q7wpTm g==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="385435956" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="385435956" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 02:21:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="877445519" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="877445519" Received: from dmi-pnp-i7.sh.intel.com ([10.239.159.155]) by fmsmga002.fm.intel.com with ESMTP; 31 Oct 2023 02:21:47 -0700 From: Dapeng Mi To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhang Xiong , Jim Mattson , Mingwei Zhang , Like Xu , Dapeng Mi , Dapeng Mi Subject: [kvm-unit-tests Patch v2 1/5] x86: pmu: Remove duplicate code in pmu_init() Date: Tue, 31 Oct 2023 17:29:17 +0800 Message-Id: <20231031092921.2885109-2-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231031092921.2885109-1-dapeng1.mi@linux.intel.com> References: <20231031092921.2885109-1-dapeng1.mi@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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]); Tue, 31 Oct 2023 02:22:05 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781262332968246056 X-GMAIL-MSGID: 1781262332968246056 From: Xiong Zhang There are totally same code in pmu_init() helper, remove the duplicate code. Signed-off-by: Xiong Zhang Signed-off-by: Dapeng Mi Reviewed-by: Jim Mattson --- lib/x86/pmu.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/x86/pmu.c b/lib/x86/pmu.c index 0f2afd650bc9..d06e94553024 100644 --- a/lib/x86/pmu.c +++ b/lib/x86/pmu.c @@ -16,11 +16,6 @@ void pmu_init(void) pmu.fixed_counter_width = (cpuid_10.d >> 5) & 0xff; } - if (pmu.version > 1) { - pmu.nr_fixed_counters = cpuid_10.d & 0x1f; - pmu.fixed_counter_width = (cpuid_10.d >> 5) & 0xff; - } - pmu.nr_gp_counters = (cpuid_10.a >> 8) & 0xff; pmu.gp_counter_width = (cpuid_10.a >> 16) & 0xff; pmu.gp_counter_mask_length = (cpuid_10.a >> 24) & 0xff; From patchwork Tue Oct 31 09:29:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mi, Dapeng" X-Patchwork-Id: 160033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b90f:0:b0:403:3b70:6f57 with SMTP id t15csp108880vqg; Tue, 31 Oct 2023 02:22:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRSP3aov0PAWWu4sb4WdJoK0pu9oT0lzHUOHdmpgHUzKZaJMpY88zyH156L50mzHbZROoO X-Received: by 2002:a05:6a21:19b:b0:154:d3ac:2076 with SMTP id le27-20020a056a21019b00b00154d3ac2076mr12483418pzb.40.1698744140027; Tue, 31 Oct 2023 02:22:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698744140; cv=none; d=google.com; s=arc-20160816; b=XOjKks3LNOxQDh0FCuYjlK769uXhQUw3iciSgminKKsFYpkNNHYFKW5JJ2mqfII+mD qKc9lHfHXEbgg4fLcgX6QYJnc/dwUGP38otiKzBCWQJ9CVXk0YNIja4g2V7smSJsx4s9 q5x15GyH/ZOacJ68ewcJGrggfGPD/kOA0BFLsAQetL3LAJtR6omxs6e4B9/xzBo4wdXr WUcXJPw5bsg+fQ/sDgaXYMgICcPmQWRYO/ApFAtR/+4QMntrYpEJhcz/vVQsH2uu3eCW 4KhVaXYWz/xkW0+sBdk30YG3nnqRv1Pfjoi8dvEpyv3vnMsWF3ZqSOlyHJeXvN1qwLJ8 mScA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ej3DljTufToQynyR394aevZoQLCSwYFpVc4yJfu/Krc=; fh=E3ilibYCxplRFz20OpOkjMj1lMKBPGRzcx1abGX98y8=; b=T+ZIl10Oe8RUfC9l+BQNrxynLix6XapasolYuRprLHZOrgBXDIxOfXU1086btyiJNn DrOoBQl7r1Oh4gzFOrgGCjPGNKQr/j39MG9dgxGG9+SuXZ7TRZfavxISqoNJpu9okaod 9Z5Z4D+VEPLxiylNdrX7kwYdXlJT2TASuXioZFo3+WlfNnOjoRBQkYyz85ClcYb4EIYr NjAs1lya5fr/3jg0p9MN5VqJeiXxT2H/d6L0f07icq4uYnI/RACivFKoYxdKSi8pOcju 4f3OkcipI3BCbSdr5fcQzY72vboo5nrpYlGvtssxp5O624oX0wn+uZd5vn0VQN2iY2z8 /Aiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VFYiVkBm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id nn6-20020a17090b38c600b002790fa91d77si724045pjb.145.2023.10.31.02.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 02:22:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VFYiVkBm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 75FD6803512E; Tue, 31 Oct 2023 02:22:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229705AbjJaJV5 (ORCPT + 34 others); Tue, 31 Oct 2023 05:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343848AbjJaJVz (ORCPT ); Tue, 31 Oct 2023 05:21:55 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78978B7; Tue, 31 Oct 2023 02:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698744113; x=1730280113; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JgrwofphKXeC1nxCQjenJBStSCQKow/wnGaMmvGi9t4=; b=VFYiVkBmBGD8kRqe+DrujLEQl94s4282pp2UDRfP6B+mCP3LPo4tEcEV LW5hdXni+qVAErm3OdSN23R2sk5rMjNhHsuYjAktL4i2G5Kk/Gs3S4Vuq ZzOjPX5QCUDdHQTj2/8dD8Nx0BgwdZZXFCLbMoZyz//YBH8dsrWa3rzDI rKwO/vt4e7nz8LdJ8wzyVZ76dG+PICJrJiAEcHHkVieSknL/7vMPJLU1t 32JCw1K3H0cDiVxXy52XguuwVxMzhIHfjogyQr2fMoQNr9f9WzDkJx0AT +z5rzr3FuZjECeNXboDWwZ0ZODTX86w5iwb+k4fu2g3W+z/g6RXPk5oGg A==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="385435968" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="385435968" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 02:21:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="877445524" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="877445524" Received: from dmi-pnp-i7.sh.intel.com ([10.239.159.155]) by fmsmga002.fm.intel.com with ESMTP; 31 Oct 2023 02:21:50 -0700 From: Dapeng Mi To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhang Xiong , Jim Mattson , Mingwei Zhang , Like Xu , Dapeng Mi , Dapeng Mi Subject: [kvm-unit-tests Patch v2 2/5] x86: pmu: Improve loop() to force to generate llc/branch misses Date: Tue, 31 Oct 2023 17:29:18 +0800 Message-Id: <20231031092921.2885109-3-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231031092921.2885109-1-dapeng1.mi@linux.intel.com> References: <20231031092921.2885109-1-dapeng1.mi@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 31 Oct 2023 02:22:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781262335463905747 X-GMAIL-MSGID: 1781262335463905747 Current loop() helper is a very simple adding loop function, it can't garantee that LLC misses and branch misses would be always triggered in the loop() running, especailly along with the larger and larger LLC size and better and better branch predictor in new CPUs. In this situation 0 LLC/branch misses count would be seen more and more easily just like what we see on Sapphire Rapids. It's ambiguous to take 0 as a valid result in tests since we can't confirm if the PMU function works correctly or it's just disabled. So this patch improves current loop() function and introduces random jump and clflush instructions to force to generate LLC and branch misses. Since random jump and clflush instructions are involved, all pre-defined valid count ranges are also update accordingly. Signed-off-by: Dapeng Mi --- x86/pmu.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/x86/pmu.c b/x86/pmu.c index 0def28695c70..1df5794b7ef8 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -11,7 +11,7 @@ #include "libcflat.h" #include -#define N 1000000 +#define N 1000000ULL // These values match the number of instructions and branches in the // assembly block in check_emulated_instr(). @@ -28,25 +28,25 @@ typedef struct { struct pmu_event { const char *name; uint32_t unit_sel; - int min; - int max; + uint64_t min; + uint64_t max; } intel_gp_events[] = { - {"core cycles", 0x003c, 1*N, 50*N}, + {"core cycles", 0x003c, 1*N, 500*N}, {"instructions", 0x00c0, 10*N, 10.2*N}, - {"ref cycles", 0x013c, 1*N, 30*N}, - {"llc references", 0x4f2e, 1, 2*N}, - {"llc misses", 0x412e, 1, 1*N}, - {"branches", 0x00c4, 1*N, 1.1*N}, - {"branch misses", 0x00c5, 0, 0.1*N}, + {"ref cycles", 0x013c, 1*N, 300*N}, + {"llc references", 0x4f2e, 0.1*N, 2*N}, + {"llc misses", 0x412e, 0.1*N, 1*N}, + {"branches", 0x00c4, 3*N, 3.3*N}, + {"branch misses", 0x00c5, 0.1*N, 0.3*N}, }, amd_gp_events[] = { - {"core cycles", 0x0076, 1*N, 50*N}, + {"core cycles", 0x0076, 1*N, 500*N}, {"instructions", 0x00c0, 10*N, 10.2*N}, - {"branches", 0x00c2, 1*N, 1.1*N}, - {"branch misses", 0x00c3, 0, 0.1*N}, + {"branches", 0x00c2, 3*N, 3.3*N}, + {"branch misses", 0x00c3, 0.1*N, 0.3*N}, }, fixed_events[] = { {"fixed 1", MSR_CORE_PERF_FIXED_CTR0, 10*N, 10.2*N}, - {"fixed 2", MSR_CORE_PERF_FIXED_CTR0 + 1, 1*N, 30*N}, - {"fixed 3", MSR_CORE_PERF_FIXED_CTR0 + 2, 0.1*N, 30*N} + {"fixed 2", MSR_CORE_PERF_FIXED_CTR0 + 1, 1*N, 500*N}, + {"fixed 3", MSR_CORE_PERF_FIXED_CTR0 + 2, 0.1*N, 300*N}, }; char *buf; @@ -56,10 +56,15 @@ static unsigned int gp_events_size; static inline void loop(void) { - unsigned long tmp, tmp2, tmp3; + unsigned long tmp, tmp2, tmp3, tmp4; - asm volatile("1: mov (%1), %2; add $64, %1; nop; nop; nop; nop; nop; nop; nop; loop 1b" - : "=c"(tmp), "=r"(tmp2), "=r"(tmp3): "0"(N), "1"(buf)); + asm volatile("1: dec %0; jz 3f; mov (%1), %2; add $64, %1; nop; \n" + " rdrand %3; and $7, %3; jnz 2f; clflush (%1); jmp 1b\n" + "2: nop; jmp 1b;" + "3: nop" + : "=c"(tmp), "=r"(tmp2), "=r"(tmp3), "=r"(tmp4) + : "0"(N), "1"(buf) + : "memory"); } @@ -202,7 +207,7 @@ static noinline void __measure(pmu_counter_t *evt, uint64_t count) static bool verify_event(uint64_t count, struct pmu_event *e) { - // printf("%d <= %ld <= %d\n", e->min, count, e->max); + // printf("%ld <= %ld <= %ld\n", e->min, count, e->max); return count >= e->min && count <= e->max; } From patchwork Tue Oct 31 09:29:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mi, Dapeng" X-Patchwork-Id: 160035 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b90f:0:b0:403:3b70:6f57 with SMTP id t15csp108919vqg; Tue, 31 Oct 2023 02:22:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEH/LyhTjs0qBm1ZWPx4fs6CG9hgYRZJRQ2hqcJcnyj5/Rbuh945+JtJdp13PbU8kNL4iQj X-Received: by 2002:a05:6e02:1b82:b0:357:503e:4681 with SMTP id h2-20020a056e021b8200b00357503e4681mr16258253ili.24.1698744148306; Tue, 31 Oct 2023 02:22:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698744148; cv=none; d=google.com; s=arc-20160816; b=czb78FTMflF4fHAh+db/6p2EBR26gKDqmX+SnQ8YjPRYrTwTM7XMbEzvBXvL2iBDos Lan/mC+97hBpXTDEYkyHr/W3LQxACKRPpMnbSnhru6FmV6EnBQVC/nRT+kKfmpTbHa4w FWOWPLFMza9SIL/tCB1k78znCAhH97P5SVgfNp32hHpzBjhJPEU26XzNy0qi6C7X+KHQ T9BuZHSkAs/ckrVKEwqQMYgMdgEhNPFkpHUzVJ8dRvPo6MfQp+9ojPqpqVmmGEoQi01N 26ttChEUMAOwR7k6mVL3+BBLK2ASG70Skc2jJiuABWrsMzGzNavP8CcmNspCwctCDCo1 2+kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LBGI7qUY1GSsCPPZFubYI35avsIyXBhNEW3q/colzXo=; fh=E3ilibYCxplRFz20OpOkjMj1lMKBPGRzcx1abGX98y8=; b=SqCtceAZ/FfGHfCSHfqFL+SLo/TEuWqjGk4a/NMCfsL0AegUn4Y7p9FifmFvQmSNBv KWEHbKhr/U6uDHjxoCCdlnaWtlZv7w2/8ZYsHQ3QMB43IrbscYgc0HgYE1gtemlUl8ME AUF7I6/k38oSMZptdQOZmlc7K3+ngBH1NcMcTzDMuLxt4Fl2XFK06V2GBEeVovXSoVK9 K3UDuigDiM0hsk7Vu9imPzi2ei79mxpXmoZnWM1iR1h/vBBEupiXZ2HcYcIguQ+85daT xFLz002o0UWqoGqPfv9eIas/SdzXUFiurgZWdfkpIgSR+jJAcv6NXXWuUXJTpdhqU+0V A1Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="iWx4M9u/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id c5-20020a6566c5000000b0055793097dbesi770738pgw.469.2023.10.31.02.22.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 02:22:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="iWx4M9u/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 671D9803513C; Tue, 31 Oct 2023 02:22:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343867AbjJaJWB (ORCPT + 34 others); Tue, 31 Oct 2023 05:22:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343853AbjJaJV6 (ORCPT ); Tue, 31 Oct 2023 05:21:58 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA494F5; Tue, 31 Oct 2023 02:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698744115; x=1730280115; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UFdm8PB2RMdMC4FZjkejhXgoSvo9XB2tTzL2mbbsxug=; b=iWx4M9u/9A9OWr3wBgyb7kE2Du0NZCDOL0eH9IQaQpiwvTtQuXt6m36Q CSWkZWhJtmKfyZBybPIV/3riyz0IXZQqxL7fE1VnAgjX9lNEjpsra0w7u pKzGtHjCTjfKySWSs6wimh5WkeJ61bydumltAL4YKhs91cUwlpLrvVsBI 05APr/LxjkdaJ5DexTyrCFVKkbiZNDLHCWW9QhuhfsDxD3QQVOy9ko8N8 AJGlKmPFWxAHCu3fIMsKHBTvtFiG89ygXTZXDanuycdJo+VIhXrQOgjju 7N58szOrVQf+rz3GRBj7VV+CgbRCDFvtRUSE7yXvfjAp68WZOelLyj9u1 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="385435973" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="385435973" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 02:21:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="877445527" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="877445527" Received: from dmi-pnp-i7.sh.intel.com ([10.239.159.155]) by fmsmga002.fm.intel.com with ESMTP; 31 Oct 2023 02:21:53 -0700 From: Dapeng Mi To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhang Xiong , Jim Mattson , Mingwei Zhang , Like Xu , Dapeng Mi , Dapeng Mi Subject: [kvm-unit-tests Patch v2 3/5] x86: pmu: Enlarge cnt array length to 64 in check_counters_many() Date: Tue, 31 Oct 2023 17:29:19 +0800 Message-Id: <20231031092921.2885109-4-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231031092921.2885109-1-dapeng1.mi@linux.intel.com> References: <20231031092921.2885109-1-dapeng1.mi@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 31 Oct 2023 02:22:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781262344226242335 X-GMAIL-MSGID: 1781262344226242335 Considering there are already 8 GP counters and 4 fixed counters on latest Intel CPUs, like Sapphire Rapids. The original cnt array length 10 is definitely not enough to cover all supported PMU counters on these new CPUs and it would cause PMU counter validation failures. It's probably more and more GP and fixed counters are introduced in the future and then directly extends the cnt array length to 64. Signed-off-by: Dapeng Mi --- x86/pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x86/pmu.c b/x86/pmu.c index 1df5794b7ef8..6bd8f6d53f55 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -259,7 +259,7 @@ static void check_fixed_counters(void) static void check_counters_many(void) { - pmu_counter_t cnt[10]; + pmu_counter_t cnt[64]; int i, n; for (i = 0, n = 0; n < pmu.nr_gp_counters; i++) { From patchwork Tue Oct 31 09:29:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mi, Dapeng" X-Patchwork-Id: 160034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b90f:0:b0:403:3b70:6f57 with SMTP id t15csp108911vqg; Tue, 31 Oct 2023 02:22:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHa64vobWUcB9PtDCo+fM1HnO1MYM1N69SxP8jq66RpQ6VNYKRq5d+F/YYOSazDHw1fDAi X-Received: by 2002:a05:6a00:2d09:b0:68a:52ec:3d36 with SMTP id fa9-20020a056a002d0900b0068a52ec3d36mr10662387pfb.31.1698744145881; Tue, 31 Oct 2023 02:22:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698744145; cv=none; d=google.com; s=arc-20160816; b=zzu9ahMg5SPWpLEmuCdE4BozppCy/NWlAR9WHG1Ih4SfYwvRswVgAMJJhKdCMh+xIR +67wQicCnERQwItRiBIII+7Kfu1nREEW7qLd56SWCMsMFNTWa7qJDm2QHveFtaDL4KYD kXJ6MKHfM5q8QWCXlL4AWDQSAEDRuLEqBZl0v206uvL7CiDDimEf/GSwps45H+e2XHwu t8oX41ry+YwgHbRQRaGHHTB2sEkB58q3VSGwyIzH9Zz+c2YXCjOVbAuKesgz5fc20Yx6 iWD/gn/RFIDymeZ2MqCJh3WTLk4Qibfq137tnOy/UGbIyCMlpUjf2DEywkJhENezXWJc IqpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=h+p8MypFEn87KtzkX8EEd2/54TFm0UDegN17PnjoJ30=; fh=E3ilibYCxplRFz20OpOkjMj1lMKBPGRzcx1abGX98y8=; b=pMnxFm/bItmPyQLEEFXVOsctdCyIgL/Yj3JISo5yC4fMA9hLyBGyjMZ47SmpZqorJj zFeKsCrsd4qakD1yvm8gah0wPiMWX/C5xY1z3QdDHt5qg3Wkt1Tkl0G4CH66T3yJoPWG XcuSMHtHDnFUkgzAPRCatc/mmmzeI8Ho2n+ktsziBWFfJjvayMEfa/22Q99j4cI3IFGU 63fUAjtUS5nFEwOn1m7AvmXN2lH/uslTq2gDA8dJX0iWnI4OZ5uIpKOFAKRIHGT4f2nl UqIqTT1o+bitbHZGMA9o/+KqYeYUXlnNBhb+bf/GFjTwgxoKGc2No6SeNkHeQH0t8lc5 iG7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ng6mG7EJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id u11-20020a6540cb000000b005b90990ab02si778266pgp.419.2023.10.31.02.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 02:22:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ng6mG7EJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 86ABE802E8BD; Tue, 31 Oct 2023 02:22:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343885AbjJaJWF (ORCPT + 34 others); Tue, 31 Oct 2023 05:22:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343877AbjJaJWC (ORCPT ); Tue, 31 Oct 2023 05:22:02 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D77E110; Tue, 31 Oct 2023 02:21:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698744119; x=1730280119; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hGJvfX2hIKMvWkOHT5amNhhbAWNGgZop9FcOLKuXuaA=; b=Ng6mG7EJ4znXJ+IDS1nfquItUA+grbWRFMielJRLsPj/K6+x8rm9Ztw2 rVvi50cEyUfdVcEtkLmuBBfzg/eoXZvZl+9DZlrKKU/JpwPar892mWq3U B4Rmh4AN2B1FA1xhSAqqqM3kmcacUmNCSymaIDoFx7ZG28S9gV/csx60d 4sx9Ro62HOJY7kRXBGLtrMg4uI2hO9cFMmGTC51DXf7CqIl9qPDyo9/po I1EXWRMCoK/huf1HnABjbvw+Ke7kakRBqee9IKth9vaBjXYp5UIJTWgo3 ZOsVdRl4V5ZE042yd67F5C3FW1BE9FuzKb1NhBB1wgG7pvgRyO+BleGF8 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="385435983" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="385435983" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 02:21:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="877445531" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="877445531" Received: from dmi-pnp-i7.sh.intel.com ([10.239.159.155]) by fmsmga002.fm.intel.com with ESMTP; 31 Oct 2023 02:21:55 -0700 From: Dapeng Mi To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhang Xiong , Jim Mattson , Mingwei Zhang , Like Xu , Dapeng Mi , Dapeng Mi Subject: [kvm-unit-tests Patch v2 4/5] x86: pmu: Support validation for Intel PMU fixed counter 3 Date: Tue, 31 Oct 2023 17:29:20 +0800 Message-Id: <20231031092921.2885109-5-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231031092921.2885109-1-dapeng1.mi@linux.intel.com> References: <20231031092921.2885109-1-dapeng1.mi@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Tue, 31 Oct 2023 02:22:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781262341183905172 X-GMAIL-MSGID: 1781262341183905172 Intel CPUs, like Sapphire Rapids, introduces a new fixed counter (fixed counter 3) to counter/sample topdown.slots event, but current code still doesn't cover this new fixed counter. So this patch adds code to validate this new fixed counter can count slots event correctly. Signed-off-by: Dapeng Mi --- x86/pmu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/x86/pmu.c b/x86/pmu.c index 6bd8f6d53f55..404dc7b62ac2 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -47,6 +47,7 @@ struct pmu_event { {"fixed 1", MSR_CORE_PERF_FIXED_CTR0, 10*N, 10.2*N}, {"fixed 2", MSR_CORE_PERF_FIXED_CTR0 + 1, 1*N, 500*N}, {"fixed 3", MSR_CORE_PERF_FIXED_CTR0 + 2, 0.1*N, 300*N}, + {"fixed 4", MSR_CORE_PERF_FIXED_CTR0 + 3, 1*N, 5000*N}, }; char *buf; From patchwork Tue Oct 31 09:29:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mi, Dapeng" X-Patchwork-Id: 160036 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b90f:0:b0:403:3b70:6f57 with SMTP id t15csp109067vqg; Tue, 31 Oct 2023 02:22:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHznxDu5hN5yWUxYikfAJ5p3mE3uXMHJERp/b67JET1AwG9yaBZusGA/Fza236XILYALeA X-Received: by 2002:a05:6808:309d:b0:3a7:7d4:4f91 with SMTP id bl29-20020a056808309d00b003a707d44f91mr16333634oib.14.1698744169769; Tue, 31 Oct 2023 02:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698744169; cv=none; d=google.com; s=arc-20160816; b=q1qsKdmWWghf6zFKscYDRN4xjcitBsTh33vOR4uKGGyhiTB7Dn6ZrN8PR/b3pltofS 1PytJ19W3eYTkvOkCp94wvkF5AJAw7kQbfjrM0kLyLtC9sh9j9CXUhY/FFrfldbCUNzM Ohzs7ikxDQSa/VrbSSykEP2/gWOE1QeoDQ90vj2LKGVSLZe4FjsCptyK8FRF0se4HRFn as9oqji9mq9pDxR4sFFwjUNZEFr0wWtjWcszcbWFJV6jeXtq96BxDW5Y3f5/JuMJP3DP KZIaCdEdJ0UjrT2ID8kKRYuMlV3w2rxQE/zEhtWa1K81Dv7xDYu8iPqDzId4QiVA7T7m yTVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uB5jcPqU60w2I9rfaezCeVkReEPIv1pcC3nWkarvyfw=; fh=E3ilibYCxplRFz20OpOkjMj1lMKBPGRzcx1abGX98y8=; b=AzP5+NfLv1OLNSzYiik+aqOJgHWzoK1sEyPjRtoiv3HAvSJ4K2uSGUSnDus0ew8dVm oL50b8o6iGbxfqWlL0ZSupQxBsVzU9reGOIS0wUr4uYjEAW1ceJPgbcj68LiLkyxnGOq +t7CJmcOHCjdgc5+mFIro8JLPVA0y4DW2g3jS5xLsGQxLcQwO41w93Er0BUGSZ6F0Zp5 bR2WJ6qyyzvoTIYYM65ApW1mOEPxICv58M5EmRlqPEycAW7HRIl0yqUZeWArzRx2acUc LJ+0fkuiY7bHuUKO8RMC5+Gqo66uXD893H6ZewbA8HjXeqKIGHVvRFlndu3w9Godhw3x OZCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KNM+3pQn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id fc39-20020a056a002e2700b006be246c6decsi743622pfb.351.2023.10.31.02.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 02:22:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KNM+3pQn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 0FEC68035128; Tue, 31 Oct 2023 02:22:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343848AbjJaJWR (ORCPT + 34 others); Tue, 31 Oct 2023 05:22:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343890AbjJaJWH (ORCPT ); Tue, 31 Oct 2023 05:22:07 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E16ACB7; Tue, 31 Oct 2023 02:22:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698744121; x=1730280121; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PuCRcyvXo/0paorC4geEOaVKWI0b7CqKhedXiIXoy0A=; b=KNM+3pQnGpmUUNQuHOdJcxhEJDaYVJgfWRz9AWWnmosWzV4A0ehXWcI/ lTcQ7n0+M5pnMKJBkf7mAKGCvzPElMZkNpf5A9oZyhQsxywtri3MP8CXR k+90mWDkWu3TC4irj/W8bzCV+I2k/DHt5GPwcdHwI79hTSZAfusPp/HyN PW/VWy8IGJjj6uj0A3mLEhTsllOP8qkA/F5oCa4zIVLB4aeMhtaNtTJMv ER38hCNC5tuW4J9Vl35gLh/DUYqMexeTcluHlsSHkjBrOuOgz7f7D9ZQX u5wKjKuiKo+1MBhBytx85ub/awqH/MP194ZIgD+flMns1Ibf4ouBRS9Rl Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="385435997" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="385435997" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 02:22:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="877445536" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="877445536" Received: from dmi-pnp-i7.sh.intel.com ([10.239.159.155]) by fmsmga002.fm.intel.com with ESMTP; 31 Oct 2023 02:21:58 -0700 From: Dapeng Mi To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhang Xiong , Jim Mattson , Mingwei Zhang , Like Xu , Dapeng Mi , Dapeng Mi Subject: [kvm-unit-tests Patch v2 5/5] x86: pmu: Add asserts to warn inconsistent fixed events and counters Date: Tue, 31 Oct 2023 17:29:21 +0800 Message-Id: <20231031092921.2885109-6-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231031092921.2885109-1-dapeng1.mi@linux.intel.com> References: <20231031092921.2885109-1-dapeng1.mi@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 31 Oct 2023 02:22:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781262366617468583 X-GMAIL-MSGID: 1781262366617468583 Current PMU code doesn't check whether the number of fixed counters is larger than pre-defined fixed events. If so, it would cause out of range memory access. So add asserts to warn this invalid case. Signed-off-by: Dapeng Mi --- x86/pmu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/x86/pmu.c b/x86/pmu.c index 404dc7b62ac2..3ce05f0a1d38 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -117,8 +117,12 @@ static struct pmu_event* get_counter_event(pmu_counter_t *cnt) for (i = 0; i < gp_events_size; i++) if (gp_events[i].unit_sel == (cnt->config & 0xffff)) return &gp_events[i]; - } else - return &fixed_events[cnt->ctr - MSR_CORE_PERF_FIXED_CTR0]; + } else { + int idx = cnt->ctr - MSR_CORE_PERF_FIXED_CTR0; + + assert(idx < ARRAY_SIZE(fixed_events)); + return &fixed_events[idx]; + } return (void*)0; } @@ -251,6 +255,7 @@ static void check_fixed_counters(void) }; int i; + assert(pmu.nr_fixed_counters <= ARRAY_SIZE(fixed_events)); for (i = 0; i < pmu.nr_fixed_counters; i++) { cnt.ctr = fixed_events[i].unit_sel; measure_one(&cnt); @@ -272,6 +277,7 @@ static void check_counters_many(void) gp_events[i % gp_events_size].unit_sel; n++; } + assert(pmu.nr_fixed_counters <= ARRAY_SIZE(fixed_events)); for (i = 0; i < pmu.nr_fixed_counters; i++) { cnt[n].ctr = fixed_events[i].unit_sel; cnt[n].config = EVNTSEL_OS | EVNTSEL_USR;