From patchwork Tue Oct 24 07:57:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mi, Dapeng" X-Patchwork-Id: 157267 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1780338vqx; Tue, 24 Oct 2023 00:51:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsWfiTGlYfAIiTWguyL5/5TjeFijjfIrYzEWvmmKmeQpMQhlprwRzm99ry/QwCYQXaSiAO X-Received: by 2002:a17:90a:c70c:b0:267:f9c4:c0a8 with SMTP id o12-20020a17090ac70c00b00267f9c4c0a8mr8527387pjt.4.1698133899355; Tue, 24 Oct 2023 00:51:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698133899; cv=none; d=google.com; s=arc-20160816; b=JW0cux/T6GrxtHyfhtUWGFE2ocNU9YF/vmx/WTQJxVaIogs9blMBQRJma2/QOFR3c4 lY/Ve35JSX5xzCPooAbXEPGaYLB2h9wg2mcXfUJMlZFI+kaBnTAosE61+cgD14JCLwTm YXgGKr4GKMQdnUxZjx3ifK/RoNmOLQq7iO6+zJwHyGHvsmHjpKXfkDRY8j5hxyXlG99z xm8G+9O9TT1nsQgVHIl61J/vqfOPXq9JaLQ2A9WytzRD9CsKM8gHzkGJNY/LzwgUrNgK xLTyXe1IGvAilouCXbRuAOdW17/ADEb3s5Z2PC1uVqNsIA9/YJ2vuVupclFSMmWjOSbG FmgQ== 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=TYnYj8oLVQWVejMFovvJzEi9pKvEtCfU220LSRIAuJs/STU+FfvUQeJ5WQX9aTecV2 Bpl2xGm8mJ2dcIx0Dl5wbwncDT6jYpi5GeWI+40w3PwAtIeV7R9KbrjPdGTAZdDw77hj M9gEw6zPph+0oimJ1/kQ6APrjz8BpbkNkXvMIRDAqZKUZctTtVoBgEBNch4l/OoXAzhe xFKV2n5WDbnIJDdtPpx3fMqXq/m6hJjGfCcRlW3XZp51me2eJhV5Sy7czWqAZ9OLH+5r M9tVsD3ps5xgwnVhgJCqmDFeV4hEFy0RsJJN4KgDt+PE8tQMbidC0roRLrROntoqZ78Y rfXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C+a8I5hz; 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 r61-20020a17090a43c300b0027782fd462esi10678522pjg.5.2023.10.24.00.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 00:51:39 -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=C+a8I5hz; 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 234FA808A91B; Tue, 24 Oct 2023 00:51: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 S233773AbjJXHvB (ORCPT + 26 others); Tue, 24 Oct 2023 03:51:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233760AbjJXHu6 (ORCPT ); Tue, 24 Oct 2023 03:50:58 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA350118; Tue, 24 Oct 2023 00:50: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=1698133855; x=1729669855; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y4GdVfvr4r3TS2jPrXzPuftPnG1qKJX1nHclPM7uF4Y=; b=C+a8I5hz/snaRZa6cNTUVVPd8RqNlA21RTBnyZ4r5JoxGk6D9FQ+H1pC 9QBV1KzH99JJlG4Gvv3JDr4dluluyBiBrX3+P6aP1zEIQBFKEYRj1bDiW 78HQMluccYeEuXdDtvObNp4oFyMIr2VGnUAUtbubNRs1KWgoMiBebB3VO p3JPhSCg7WgTTygVF8ibt+4DUNLIvqCDJxS9v+MGLF+7FhTOnTUPHGGNz Sp6pea13iKpaDMWQ+xjt34PQWot6sMh2CWmiWD3mLZoVpqArCDgjyS7KJ QE+PDxHUpetyeEcYOpBv53mZlv+16OErFU6eX8gvLcqpZlLxpa1Gqu1wI w==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="367235184" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="367235184" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 00:50:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="1089766233" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="1089766233" Received: from dmi-pnp-i7.sh.intel.com ([10.239.159.155]) by fmsmga005.fm.intel.com with ESMTP; 24 Oct 2023 00:50:52 -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 1/5] x86: pmu: Remove duplicate code in pmu_init() Date: Tue, 24 Oct 2023 15:57:44 +0800 Message-Id: <20231024075748.1675382-2-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231024075748.1675382-1-dapeng1.mi@linux.intel.com> References: <20231024075748.1675382-1-dapeng1.mi@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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, 24 Oct 2023 00:51:20 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780622451569910051 X-GMAIL-MSGID: 1780622451569910051 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 --- 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 24 07:57:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mi, Dapeng" X-Patchwork-Id: 157270 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1780448vqx; Tue, 24 Oct 2023 00:51:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHx841iDq05oXweirvQiAKsJKzRoQCcilLDkyI2Y7fLTChUzV/NjN+eFFUDYIEVCvFABOYi X-Received: by 2002:aa7:9622:0:b0:68b:eb3d:8030 with SMTP id r2-20020aa79622000000b0068beb3d8030mr11966430pfg.1.1698133914894; Tue, 24 Oct 2023 00:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698133914; cv=none; d=google.com; s=arc-20160816; b=tPUgMO7boUZXA1V+Hjs9B23nd5JJ02yDh/1lgYsBmiMbSgqtLDaxEh1J356lZPP5At QyOPWa5gPwMFVOkJEd8hvMRB9qDmYxPl1HbN1mOLCPn6+czepdYoykgpQVDaBKgWZ40F c6wc4mYR75CtJ1tImRNGPBW/SGVb6Yvdnnn1uuMBzn4Htx2mrrd8t6nOb0QndsNDpcv8 mi1q3NvsBNXCZmuk4uDWP3nGGJmkV65Xd8v0HVFc/ozDVlqsVOJ7+1APBLdZlmw4MTUa 9tpAmQHVQUEzLWzWqiqmIywQyQnwCX/E6HejHQTqehSvSq4OcqrMGVV6BQm+iNfvEEYg HzFw== 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=TcwO5nm75xh6Wlbj3X2+N26Vm6pCG1Z8f4KHrMnKUzM=; fh=E3ilibYCxplRFz20OpOkjMj1lMKBPGRzcx1abGX98y8=; b=wdiXgbEVazmWc5dWhk5u16TIBGIFbv3uwEdatibJo8e/3285licSWvDHHbWULG0Ltx fHyShsCw7yDnCGQHpvkm1IoY/FDGcKgVO/3WGTFyJ764PHcyg47ULSSMPsUFpsOFZS0Y 1qSN0ixanlsydq0m362QRYP1JMCruK/S8r/xU0paDlKBU6LndKI2m9gGqHj1wyWOQ9vZ Q72TyLsTFfsCyH2uqppBWgLrP8DVSkPPh2DBgLJJ7Bf/sjvKwaZ2NSknV91jfDrObidf ETgPhR3nJxDJj13g4rW0j8ZMsQaEeW1bVviPrPJ8frOHaVIOH2wh5QzSEl2a0yBfvPzm 8HnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=a8VMyX1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id u186-20020a6385c3000000b0056a19c7c2e5si7625375pgd.361.2023.10.24.00.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 00:51:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=a8VMyX1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id F1138806E4FD; Tue, 24 Oct 2023 00:51:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233815AbjJXHvL (ORCPT + 26 others); Tue, 24 Oct 2023 03:51:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233780AbjJXHvE (ORCPT ); Tue, 24 Oct 2023 03:51:04 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9208210C1; Tue, 24 Oct 2023 00:51: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=1698133861; x=1729669861; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=u6MzaXZPQ2+ms1NvX7VYQhNTuFQzAl/oK9iR7mXcQ0U=; b=a8VMyX1mIV1AQ4t1re4RhdyDbX+1wty1mjNGGFQ0LrJp1njK6tpilLvh Mnv1Hv7xGbSsHf2b1rrRpO69xDJFMmB4u3ZQ42oH9p2XA/kJw4/32oZDR x9cv8QapxGu1fSJAJNgRfpd6RODsy/jkvfFAersWEtBD2UY8LMr24gzaS j4OswjeImYaY9MScfYrDtMXaodClL1FXGby/z4mXn7Cw8iZgA4NQqASQX Y3yHaeMk3dt5aYr5ohLBxOOEni32KxK1p2P7u/HX05+zQ8eNhRvQO5lZE sb/tABgLSnVNHtzHJyjs1A8BcZz0daFiLUPHzLt5/zm5e8v2m4ITJGE1K A==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="367235196" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="367235196" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 00:51:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="1089766271" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="1089766271" Received: from dmi-pnp-i7.sh.intel.com ([10.239.159.155]) by fmsmga005.fm.intel.com with ESMTP; 24 Oct 2023 00:50: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 2/5] x86: pmu: Change the minimum value of llc_misses event to 0 Date: Tue, 24 Oct 2023 15:57:45 +0800 Message-Id: <20231024075748.1675382-3-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231024075748.1675382-1-dapeng1.mi@linux.intel.com> References: <20231024075748.1675382-1-dapeng1.mi@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 00:51:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780622468127019972 X-GMAIL-MSGID: 1780622468127019972 Along with the CPU HW's upgrade and optimization, the count of LLC misses event for running loop() helper could be 0 just like seen on Sapphire Rapids. So modify the lower limit of possible count range for LLC misses events to 0 to avoid LLC misses event test failure on Sapphire Rapids. 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 0def28695c70..7443fdab5c8a 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -35,7 +35,7 @@ struct pmu_event { {"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}, + {"llc misses", 0x412e, 0, 1*N}, {"branches", 0x00c4, 1*N, 1.1*N}, {"branch misses", 0x00c5, 0, 0.1*N}, }, amd_gp_events[] = { From patchwork Tue Oct 24 07:57:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mi, Dapeng" X-Patchwork-Id: 157268 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1780402vqx; Tue, 24 Oct 2023 00:51:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhbaFCFUOfj5YHHDs2o96ygWQezL7DunLahXuNhIYmKYGEHaZ3VsbvK2ZUPE58Py+TFmYo X-Received: by 2002:a17:902:d506:b0:1c8:75d9:f7dc with SMTP id b6-20020a170902d50600b001c875d9f7dcmr18790508plg.28.1698133909213; Tue, 24 Oct 2023 00:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698133909; cv=none; d=google.com; s=arc-20160816; b=fREcI3VFgJLiqGlHjo5X47bM/REaCwf6mUZZtT6RtGg2Q9J6NyKFlmeTyp5YU6JVJs 25SgRI563wh10wqB7ho+9+uCbDexgVHi7BrJZCRc9h+NooyChaTe4Hg3zTw/WW+/dRps cbv1rHl578ZBEG6Ha7PBQrNlu6MGL43J/keHhSLUcI9HY1AZS1i4VulvgqPdgGYF3pJE dO9OEsMsFhMDMdA+dlUm3Dz3iCdApvNRPW6MKOXkynWOZ2efhpPYSaX8solF4Uv8uHkf LF+vfh7AsAlRW9aG922HOJaYJTZCDUZ7wf55mFGFEg9LLDxXBmBeDpLPhC9d/mavY3Ay k4tg== 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=L81E/Emnscmi2jwx8JYVPLtMoKsgpsZcHXwc/ho8Vf0=; fh=E3ilibYCxplRFz20OpOkjMj1lMKBPGRzcx1abGX98y8=; b=pJmgbvlI+v5sztKFgHXG+AEAnte7QOGR3JEKoAZ0pLCEVOFYbWJPkkL3+cGPUeiRhN B+MjblWhCitmGaGj+SXxawJL75J9+0WRGRMtIghe7ClJX492f73BQWTks0Ns+11dUexM Ds7E1hG3Qmg5jsUkGpbm6JosMSzDrkghYJkqxhuy39v638X4bQKJg7M4KZ8kDn7h2E/B QI+zWHnPNdrqIy+ndb67pIz0r65tMq67N2oOMG8lfCoTowXgdzHvaGJa4QJYTpweUGfU MtoLv5A1Yn3xtnn70L5LGJiBzNUlT3OuZOxXI9OXJRhxK66WdWrafXq5Q0P4Dq7oVjry JqMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kISNShtq; 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 oj16-20020a17090b4d9000b0027ce5a78453si8143313pjb.29.2023.10.24.00.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 00:51:49 -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=kISNShtq; 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 5B855804C6C1; Tue, 24 Oct 2023 00:51:46 -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 S233788AbjJXHvU (ORCPT + 26 others); Tue, 24 Oct 2023 03:51:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233802AbjJXHvK (ORCPT ); Tue, 24 Oct 2023 03:51:10 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ACB210C0; Tue, 24 Oct 2023 00:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698133866; x=1729669866; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+AbwY0EJ42oSmqGLiVvQ29v7o8KNMXXfoBc4PPnmCiI=; b=kISNShtqH1NKYVqoeMA/X3Nys0ayQ5vRgzaKmt+ISwAL4KyMaHguRu/s pIcciA8HuQekBNSTwwFeixR0BA1yTXix9x219snIskl5E8NmsQ76ezyWc fRkGggtQP+Xp0Ihd2ObUZKzfiQj2Jv1fBs1iZq40O3JqHGTTYH+fe453H GZZWCJtnSKodehBrlcKgUapz2xP4ZaOT/0UjbSzHVANN0lyL34l2soTnX teNDfP65ePPrZJFVh0mzDrSe/Q2+VFYRHE/4+sAzgpM2NeIjYgXRUYFtG JYN22qVssrtM6izjsA6VkhSZI9QbN/YZ0qu6dHWoqbkVN+HE7vjA8nC9v g==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="367235211" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="367235211" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 00:51:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="1089766298" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="1089766298" Received: from dmi-pnp-i7.sh.intel.com ([10.239.159.155]) by fmsmga005.fm.intel.com with ESMTP; 24 Oct 2023 00:51:02 -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 3/5] x86: pmu: Enlarge cnt array length to 64 in check_counters_many() Date: Tue, 24 Oct 2023 15:57:46 +0800 Message-Id: <20231024075748.1675382-4-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231024075748.1675382-1-dapeng1.mi@linux.intel.com> References: <20231024075748.1675382-1-dapeng1.mi@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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, 24 Oct 2023 00:51:46 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780622461936845825 X-GMAIL-MSGID: 1780622461936845825 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 7443fdab5c8a..1bebf493d4a4 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -254,7 +254,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 24 07:57:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mi, Dapeng" X-Patchwork-Id: 157269 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1780425vqx; Tue, 24 Oct 2023 00:51:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwk01XcJWruVh1DljeM+NOJicVRqm61xfpjvbiF0eLQSL276WQ6JGEb2xiWHq+xmkNQudp X-Received: by 2002:a05:620a:4484:b0:779:da55:b327 with SMTP id x4-20020a05620a448400b00779da55b327mr6116178qkp.11.1698133912107; Tue, 24 Oct 2023 00:51:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698133912; cv=none; d=google.com; s=arc-20160816; b=pcyJ1gKyu+wHkTz+Nl0GtgrxOybQvNtTx97J1PFeV2fpJj75tu0lAH1UqyceD/UzmB CNv/jRw9kVLLOx7HEIbZMKyRGceasj1X6LYV0b0NZorSyxAINT2JgrRjB8V0BtkLYUPI 4zZmWMPFleQo4WMBGZ+0rOCJolu3kMSFN0Ja10HKNAl6kbtWyPIHpxNzULDD0/iHDHef HgMCeDq+2zOrDXwDGH1sk80Bsfx7CnP1saip+mTQmIfMkGNymyeZNq00TPHDjo0HKjOf +i5+pRADt7H5h3C44SMR+Gz/V163UZAbxg9mm6SFuv2oYsm/THvRFVdHAUlw6V7ingai KdQg== 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=R39lYkLNqiE1jd5O4cqufNqxDuhiAmGNvmI8FHd6P6s=; fh=E3ilibYCxplRFz20OpOkjMj1lMKBPGRzcx1abGX98y8=; b=j3lyXm8v3xDR0DT+vzSrjKYv3ektdtuvb0o+UsOXaS0fODuQ2FPr0RnMxcLRrebgve zau/stLU4D34M/cWb2QxjtCY8v67b9yAPSi+jAgHaQ34R1rVf0f/4TFnvdh90+MSf964 iOFHCg2QVmqqltXw5zJ/GSquRvgo2aWG392YIUcuDvxKOl+N5JRQxFJblbaDsuwZMRl3 gLtvvgjwJU8wRnaL5OhDWI7wNAk4AChm2EAB/qXmxKFyCdklKutJyMDcSj9HXbFfSRZx tleZmeXfcSrxBzUw03zaTLnBnz0By5CvCEKx3NuYeS3vO8gTaUW+YX2BZo8us3zeGYs9 S2MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RaKhpeOY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id u21-20020a656715000000b00578a30162c8si7822725pgf.537.2023.10.24.00.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 00:51:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RaKhpeOY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 9DC05804C53A; Tue, 24 Oct 2023 00:51:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233851AbjJXHva (ORCPT + 26 others); Tue, 24 Oct 2023 03:51:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233839AbjJXHvN (ORCPT ); Tue, 24 Oct 2023 03:51:13 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC87910C8; Tue, 24 Oct 2023 00:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698133869; x=1729669869; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UbICHGnYTIwYlJEuHD00SpbTkeQ8YKitQTi1EDFv9go=; b=RaKhpeOYB4NmxmK6dDYdj4mUlLZqGm1QAPL6AIp1vCx+eZNgEERiuNmV 5nQ32fKTl7aGf4Gg5NXNvUTNTLaR6OyqoCN7GNUhPtRGdBEADb+EYsY74 CQMWE8UR+mtWaIoY3ldsYvPYZ/JBC6NvHoYZiKMk5RkTuPV1VqjvRUU57 tJ1JiCGkGL4UrbpsGZCA9UfEvy06PyrslWlDWHkmaX5pedry9h8kCb0oM Qi1YFdBmEGTUM+aelWElE1YOXk1YdOK2D8v+sCV9YddeXbioivIlJ9jxK 4Q6EvFWMbLkVoaL56Mr06CuZAzD7QRu4OzDlTcpPwgNJ+uJ0ZF8/csK0D A==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="367235220" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="367235220" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 00:51:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="1089766319" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="1089766319" Received: from dmi-pnp-i7.sh.intel.com ([10.239.159.155]) by fmsmga005.fm.intel.com with ESMTP; 24 Oct 2023 00:51:06 -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 4/5] x86: pmu: Support validation for Intel PMU fixed counter 3 Date: Tue, 24 Oct 2023 15:57:47 +0800 Message-Id: <20231024075748.1675382-5-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231024075748.1675382-1-dapeng1.mi@linux.intel.com> References: <20231024075748.1675382-1-dapeng1.mi@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 00:51:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780622464914820704 X-GMAIL-MSGID: 1780622464914820704 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 add code to validate this new fixed counter. Signed-off-by: Dapeng Mi --- x86/pmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x86/pmu.c b/x86/pmu.c index 1bebf493d4a4..41165e168d8e 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -46,7 +46,8 @@ struct pmu_event { }, 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 3", MSR_CORE_PERF_FIXED_CTR0 + 2, 0.1*N, 30*N}, + {"fixed 4", MSR_CORE_PERF_FIXED_CTR0 + 3, 1*N, 100*N} }; char *buf; From patchwork Tue Oct 24 07:57:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mi, Dapeng" X-Patchwork-Id: 157271 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1780558vqx; Tue, 24 Oct 2023 00:52:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/mkB4F2K0ICTMOj7e91c/OCnN9UhxPQ15paAniwW05bzdVYKn2KK8cTbnCk42+qTnqy6y X-Received: by 2002:a05:6e02:1bac:b0:352:6251:2364 with SMTP id n12-20020a056e021bac00b0035262512364mr16435738ili.11.1698133931592; Tue, 24 Oct 2023 00:52:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698133931; cv=none; d=google.com; s=arc-20160816; b=N9YW/ihHX7w5um9fPMfgITkOfV5Wr3riEIp/lzxtkujaXR8Wj/+pK1rz0XNm6dBYoH F4O/ZlyqVVy1Gi+WZdiYdBY6H+GYDQLN/jszdDnNubgaJvsMzGYxyHQ9ttVRbiOlZLvT 024wJThbrWJW4WGOvb9vlNJIeioFVehA8TOqAiByMOovM/mHhVMgQwnkLrcuKKFfiiNN drW/KuGiIYd8Kxy2OghOV3AYJLkXHJBXPu2yyka9mVwmxEO4J90EGICk0kV+o03wvIWm 7uxB7+/NV4QEWqR80/rh5ev9xzei1pvGQnbWhmcU7ayji6VbLDaHb5HhptVR46FU4VAf 0SHw== 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=p4UQUT2cU3JOZfm3LbL3EhL2KO4kHrMGHSyOrtfXAAk=; fh=E3ilibYCxplRFz20OpOkjMj1lMKBPGRzcx1abGX98y8=; b=QCSRkO73Lf9Mqu+DXvsxXYKQ4XDJM0hwHhqArpCq2tX7sS1PDUeCy3hfWD9VCOXEsD WWQwUEi92/aGQPECxXt1crM1x+8BmDqUgZhGafmJM0dA/9Lb1NcKfGIzWgOfoHa0gmXN wv31un69kxks9ZSc4KfH6UC6qPvxlNyBwbTDlorHYXz4NDCqt5PMoQGkao/XGou79CPJ HuhqnZsLlBovPUIlh5kOWpIdDSrPgzsCF5h4mRSUwCIf8AVeEl/kJYKKuYewxUNAOk2T LBarK0pxEKiqveaLrLenEYqcNeNwDpRQS86Mygq0O0I52mVbliHtTS+0TxqUW35SIa6a /dzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=N8rwUd8V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id f4-20020aa79684000000b00690c1e51cdfsi7891531pfk.188.2023.10.24.00.52.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 00:52:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=N8rwUd8V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 87E7A805E47B; Tue, 24 Oct 2023 00:52:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233912AbjJXHwA (ORCPT + 26 others); Tue, 24 Oct 2023 03:52:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233906AbjJXHvp (ORCPT ); Tue, 24 Oct 2023 03:51:45 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 940BC19B2; Tue, 24 Oct 2023 00:51:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698133892; x=1729669892; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BxG6wVyvyosYY4Ew029SXkTfwIymBHDUnYzPxlYLnc0=; b=N8rwUd8Vfz10b3+yfXbpyIklM80BHmv79H79LfbKILrctxGFFb/eZZcY iYB8DzKzwrtkUORxiCYNLkl4geEdz7WmHhqqiT7pYJHBgYso28oVsxeDD dzC0Id5JSclHJqf1gx/MfPyGvGTscJ8y8GublJ3PhKZncKDtFqaxr3+HV 7a/TbvMQWoanzonou9d4Z9YdIPlYkfhj/bp9ogqYkQaLEt57eyfxVeLOi AkS0WEL+00MChAKpMrofpPtNFMnB9V2eOWmS3uzOtir3ssluSsxrcXjTJ KaxteSJb/NKZuytvZaorfy6eVrU9CUK35jl8tu8PinurugJOpiTMDLwak g==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="367235231" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="367235231" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 00:51:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="1089766330" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="1089766330" Received: from dmi-pnp-i7.sh.intel.com ([10.239.159.155]) by fmsmga005.fm.intel.com with ESMTP; 24 Oct 2023 00:51:10 -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 5/5] x86: pmu: Add asserts to warn inconsistent fixed events and counters Date: Tue, 24 Oct 2023 15:57:48 +0800 Message-Id: <20231024075748.1675382-6-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231024075748.1675382-1-dapeng1.mi@linux.intel.com> References: <20231024075748.1675382-1-dapeng1.mi@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 24 Oct 2023 00:52:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780622485639784669 X-GMAIL-MSGID: 1780622485639784669 Current PMU code deosn't check whether PMU fixed counter number is larger than pre-defined fixed events. If so, it would cause memory access out of range. So add assert 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 41165e168d8e..a1d615fbab3d 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -112,8 +112,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; } @@ -246,6 +250,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); @@ -267,6 +272,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;