From patchwork Mon Jan 29 11:06:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandipan Das X-Patchwork-Id: 193398 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp490250dyb; Mon, 29 Jan 2024 03:08:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHv5ju3qxieYyIz1DxFITGsewX4PPPFqH4f284eXAGPJ8YPGfbh6hLWdiHcEB7LmRDF2xrD X-Received: by 2002:a05:6a20:768a:b0:19c:7c49:4cf with SMTP id k10-20020a056a20768a00b0019c7c4904cfmr1679713pzf.43.1706526503595; Mon, 29 Jan 2024 03:08:23 -0800 (PST) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x4-20020a17090a9dc400b0028d8f9e1579si5425213pjv.63.2024.01.29.03.08.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 03:08:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42586-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=I03bmjOW; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-42586-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42586-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7B0D1B230AC for ; Mon, 29 Jan 2024 11:07:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B36C95B21C; Mon, 29 Jan 2024 11:07:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="I03bmjOW" Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2041.outbound.protection.outlook.com [40.107.243.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 095965A0F7; Mon, 29 Jan 2024 11:06:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706526421; cv=fail; b=Her0OLNVUxZwokvxR82ba5lNAVvrJogQ97v4Ui0bjYD7LPOT37iCR/NqhBQq78YPkTU51vez1ogBIyaR+TdV80zQ4V69FbTDNji1HOhJ2zdwFPvJd+nR8NgwPrRulZ4xbFs69aGQgPKFrhiSWNo0Lz+uo1+kGttp1NRkFvttYNM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706526421; c=relaxed/simple; bh=x1TZWCu6dynIBSbOD8RL8/h6gbt3uVx5/vLY9/pxHAk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fyo/LPagVjAZNq+JvBmPo665lKJuuJcB3rwKy6xT5vv1aUpYz05K9HMF1esV87fEgwFsmnT89arqO7/TiW05ZBRBWJYdvNjdrwlYS2LiZxl+OJ1n5l9Hldgy/tvH6wY3WbIiOO4WXu7wFsNVXIGYJLdi0bJEWDvRzVFHHyUi7O8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=I03bmjOW; arc=fail smtp.client-ip=40.107.243.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WDkhL3EklKTAXbiNu5ox/fyYMP10PZb9NKXveig8RQBIer8aWwOdPzbHjsVL/DRGRLHOkmyAbu1g1GnLuKXM0JmC+1EuRyhVQh/oZupn9kNfcrmJ3WmK0kuOtdprpzerFfRaH1dQD07gEgHdf7KE4/sreYxK15kHHLjvQNC9RVgmlgpSv4nWbKxVtMeZ7wnbY7yjTvQwTRg7DJE6FrKm3gPCsHqEwEm6eE4XvJpi2M24Pkf6yAhO/vulkvSCCT1BA3xgETuoMHLgL4A0feVfU0xJiGIZ3/Y4vZpCLzZTE51jRaipF281xhYQMpGpPKnslBsyTAYF9dCny0y3jToivg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Eqxqn2kHV+oLH7wRUXODzvm3WnIbOCipuP0XSA6FRDQ=; b=OJEaMAQL9zWAGx8a6Om9+C3Y88U//vTBirZvvk66eeRA6nuEVJkCKvCW/WEorXGQ6eerEmGgZ7kn7V7N3Ibg5tXXLW+bG4Lj3ytyp2ppmjvFiWgcv6lDRezQLtyRPgDOeDnmllF46p+9/a1afN4ctbrhT/Jy0nIo5R+5vL9b6gvz5WvZSfUewl9DmSNWVY6e5KOW0lQ+USFKoZ4+76iDRX3kysJPRaOnlL+DodFsJqOEzJTRQ416mu1do3+2ZU7qsAywYGX1IemoDtnH0iHz1jJze/Q0GCZg2vz1suzkW+sGTFbWDtJCvgi/Ph5bk34Yz46DK+5pLpcukb9cb0MkFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Eqxqn2kHV+oLH7wRUXODzvm3WnIbOCipuP0XSA6FRDQ=; b=I03bmjOWclGrKRjBC0rFPyRmSs2bG1OcVyNC6zZWtEF3tfDxOeuR0wmCGQlX5+zfCqRr8o9hq4r1KBQY2ao8cIWOZz9DXER05lgnZzpRQL7y9qOa6hlGrhosyPKBHkGephZ8plzr80QeSrTh49FrAoGGuRaU1EmQrUIoLRCCS3Y= Received: from DS7PR03CA0076.namprd03.prod.outlook.com (2603:10b6:5:3bb::21) by CYXPR12MB9444.namprd12.prod.outlook.com (2603:10b6:930:d6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.32; Mon, 29 Jan 2024 11:06:57 +0000 Received: from DS1PEPF00017096.namprd05.prod.outlook.com (2603:10b6:5:3bb:cafe::46) by DS7PR03CA0076.outlook.office365.com (2603:10b6:5:3bb::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.34 via Frontend Transport; Mon, 29 Jan 2024 11:06:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017096.mail.protection.outlook.com (10.167.18.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Mon, 29 Jan 2024 11:06:56 +0000 Received: from sindhu.amdval.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 29 Jan 2024 05:06:51 -0600 From: Sandipan Das To: , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v3 1/3] perf/x86/amd/lbr: Use freeze based on availability Date: Mon, 29 Jan 2024 16:36:24 +0530 Message-ID: <12f378d5c9459e765c6c3a14b092e6f91da596e3.1706526029.git.sandipan.das@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017096:EE_|CYXPR12MB9444:EE_ X-MS-Office365-Filtering-Correlation-Id: 9906cb89-158d-4e81-3d19-08dc20ba6889 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 46KpmL5D49VKh4UgyRAhJ+yocCQ3M8MlB1kKDQ6KH7EKy8cdyKCztvE6NZ5zG7gX6EX7euyFjkREqn79kV4gqE299keM+sBNLPllHXMhZlK5TISsLRib2fmFdWQyKcEYMDrTnhe69hjr2bfDveOQ5Rre3f49wPXvNdwvcyTPrevCAvOKIyH/51cx5MM3HZDxcQ+wcRaeYM32/h3eXsoLDD382xcXJ8n8twKDbZ966xVktq9ORd6oyKjJuIfN6en+M6mdDBwLZBX2gobm6hmzwH3qQ3qB7cUosua/j2TKjmJ27lZRE0Ei4dhIsAWxPGy1ld/SHtAFojuUvGtnCePnCCwNsgvyPi2XQ14N1KleNc4Gvey0lgf7cEdBfUTJDmf7hTfbqCpvObzYsXrTlEBuD9s1+uOno55VSVzE1okuaL2fmzwtsx2n/C1oIyNKt2cvmfvLWIWjXo16jIvnFNK+nyqmTBMtHhYhBK+CoPq29FUyhL6e13ZcGvlKifE8GGfBvfw/Si9GDW7mAHOiM4MKr329h2veJGyKfWetNo+ooeXo0TVY/dmYw9P6/bZY3FX0uIGVfWwAxgps0aHBcw+J+XUA+if+am6XGPOCwR4fv/j4IJgMiaphu477YrO0E8Ym5w2K/DiUwrDzB60BzJygYj90u/+3QmRUGwP6WEh9GQExPjGLRX/95wxe1FBlxbWz72laz0YK6N6lZ6l2G1FeVO0ppcLvyv/LhAEsYoO5kEKJxqsvBA5PgJD4oYsQpRy28UOjeSoPR+N/ylb0/aGvSg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(136003)(39860400002)(346002)(376002)(230922051799003)(451199024)(1800799012)(64100799003)(82310400011)(186009)(36840700001)(46966006)(40470700004)(2616005)(83380400001)(8676002)(426003)(16526019)(26005)(336012)(41300700001)(4326008)(7416002)(5660300002)(8936002)(36756003)(2906002)(44832011)(316002)(54906003)(110136005)(70206006)(70586007)(86362001)(6666004)(478600001)(356005)(47076005)(81166007)(40480700001)(40460700003)(82740400003)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2024 11:06:56.8816 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9906cb89-158d-4e81-3d19-08dc20ba6889 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017096.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYXPR12MB9444 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789422735346929217 X-GMAIL-MSGID: 1789422735346929217 Currently, it is assumed that LBR Freeze is supported on all processors which have CPUID leaf 0x80000022[EAX] bit 1 set. This is incorrect as the feature availability is additionally dependent on CPUID leaf 0x80000022[EAX] bit 2 being set which may not be set for all Zen 4 processors. Define a new feature bit for LBR and PMC freeze and set the freeze enable bit (FLBRI) in DebugCtl (MSR 0x1d9) conditionally. It should still be possible to use LBR without freeze for profile-guided optimization of user programs by using an user-only branch filter during profiling. When the user-only filter is enabled, branches are no longer recorded after the transition to CPL 0 upon PMI arrival. When branch entries are read in the PMI handler, the branch stack does not change. E.g. $ perf record -j any,u -e ex_ret_brn_tkn ./workload Since the feature bit is visible under flags in /proc/cpuinfo, it can be used to determine the feasibility of use-cases which require LBR Freeze to be supported by the hardware such as profile-guided optimization of kernels. Fixes: ca5b7c0d9621 ("perf/x86/amd/lbr: Add LbrExtV2 branch record support") Signed-off-by: Sandipan Das --- arch/x86/events/amd/core.c | 4 ++-- arch/x86/events/amd/lbr.c | 16 ++++++++++------ arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/kernel/cpu/scattered.c | 1 + 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index 4ee6390b45c9..ffdfaee08b08 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -905,8 +905,8 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *regs) if (!status) goto done; - /* Read branch records before unfreezing */ - if (status & GLOBAL_STATUS_LBRS_FROZEN) { + /* Read branch records */ + if (x86_pmu.lbr_nr) { amd_pmu_lbr_read(); status &= ~GLOBAL_STATUS_LBRS_FROZEN; } diff --git a/arch/x86/events/amd/lbr.c b/arch/x86/events/amd/lbr.c index eb31f850841a..110e34c59643 100644 --- a/arch/x86/events/amd/lbr.c +++ b/arch/x86/events/amd/lbr.c @@ -400,10 +400,12 @@ void amd_pmu_lbr_enable_all(void) wrmsrl(MSR_AMD64_LBR_SELECT, lbr_select); } - rdmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl); - rdmsrl(MSR_AMD_DBG_EXTN_CFG, dbg_extn_cfg); + if (cpu_feature_enabled(X86_FEATURE_AMD_LBR_PMC_FREEZE)) { + rdmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl); + wrmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl | DEBUGCTLMSR_FREEZE_LBRS_ON_PMI); + } - wrmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl | DEBUGCTLMSR_FREEZE_LBRS_ON_PMI); + rdmsrl(MSR_AMD_DBG_EXTN_CFG, dbg_extn_cfg); wrmsrl(MSR_AMD_DBG_EXTN_CFG, dbg_extn_cfg | DBG_EXTN_CFG_LBRV2EN); } @@ -416,10 +418,12 @@ void amd_pmu_lbr_disable_all(void) return; rdmsrl(MSR_AMD_DBG_EXTN_CFG, dbg_extn_cfg); - rdmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl); - wrmsrl(MSR_AMD_DBG_EXTN_CFG, dbg_extn_cfg & ~DBG_EXTN_CFG_LBRV2EN); - wrmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl & ~DEBUGCTLMSR_FREEZE_LBRS_ON_PMI); + + if (cpu_feature_enabled(X86_FEATURE_AMD_LBR_PMC_FREEZE)) { + rdmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl); + wrmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl & ~DEBUGCTLMSR_FREEZE_LBRS_ON_PMI); + } } __init int amd_pmu_lbr_init(void) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 4af140cf5719..e47ea31b019d 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -97,7 +97,7 @@ #define X86_FEATURE_SYSENTER32 ( 3*32+15) /* "" sysenter in IA32 userspace */ #define X86_FEATURE_REP_GOOD ( 3*32+16) /* REP microcode works well */ #define X86_FEATURE_AMD_LBR_V2 ( 3*32+17) /* AMD Last Branch Record Extension Version 2 */ -/* FREE, was #define X86_FEATURE_LFENCE_RDTSC ( 3*32+18) "" LFENCE synchronizes RDTSC */ +#define X86_FEATURE_AMD_LBR_PMC_FREEZE ( 3*32+18) /* AMD LBR and PMC Freeze */ #define X86_FEATURE_ACC_POWER ( 3*32+19) /* AMD Accumulated Power Mechanism */ #define X86_FEATURE_NOPL ( 3*32+20) /* The NOPL (0F 1F) instructions */ #define X86_FEATURE_ALWAYS ( 3*32+21) /* "" Always-present feature */ diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c index 0dad49a09b7a..a515328d9d7d 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -49,6 +49,7 @@ static const struct cpuid_bit cpuid_bits[] = { { X86_FEATURE_BMEC, CPUID_EBX, 3, 0x80000020, 0 }, { X86_FEATURE_PERFMON_V2, CPUID_EAX, 0, 0x80000022, 0 }, { X86_FEATURE_AMD_LBR_V2, CPUID_EAX, 1, 0x80000022, 0 }, + { X86_FEATURE_AMD_LBR_PMC_FREEZE, CPUID_EAX, 2, 0x80000022, 0 }, { 0, 0, 0, 0, 0 } }; From patchwork Mon Jan 29 11:06:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandipan Das X-Patchwork-Id: 193397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp490076dyb; Mon, 29 Jan 2024 03:08:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxeuYD8u/moR6SorkhankWl5eypAnW1mjHLpf8/P9osMGW7XT8rh7qJ29uqXGj96cNYjGX X-Received: by 2002:a17:906:3c0b:b0:a2c:5138:f5d2 with SMTP id h11-20020a1709063c0b00b00a2c5138f5d2mr3770352ejg.17.1706526482310; Mon, 29 Jan 2024 03:08:02 -0800 (PST) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w21-20020a17090652d500b00a31069e005dsi3303963ejn.264.2024.01.29.03.08.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 03:08:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42587-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=FisUofuE; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-42587-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42587-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BEA9C1F22531 for ; Mon, 29 Jan 2024 11:08:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE0365D759; Mon, 29 Jan 2024 11:07:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="FisUofuE" Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2047.outbound.protection.outlook.com [40.107.100.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA99B56B96; Mon, 29 Jan 2024 11:07:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.47 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706526439; cv=fail; b=d4bCZ/L7hRd6IPYsoZ4aAMZx4lTCxOuAoJWGjwcpDqdR74PsZYgmdJMKgNxGNqE35W4QPzxESsUO7zu/TUejMTDtSSY/VxL6DwoM/Lwy1HPgA7GKf9BAk1rCl5SyQ4PjelVDK2dvWXj8JKqPv53dIuv3Tzej7Gggpj8dv6OZcqs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706526439; c=relaxed/simple; bh=SkgdEr20X+54nnsJiGd+jtnxsvYF5+dU0TXZ/CCy/pM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GLvnlcbRCOHRvgz/QAlMNtT5EfTpDMcoSsOEcsWUzo/AXC6dPbUuuHySmOt7BjX3CLrsJ92tos5CEvOstVgEd2N34nV/Y/xwRJMYwYcNpr5t66GZqOpluZmGAJ+JFf9ITgfU1V3WVaV5G5oDzJ7HqHJ4TFaZwb7Hh3hsQlPkSms= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=FisUofuE; arc=fail smtp.client-ip=40.107.100.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O/hhYOSTW5VJJ5G0QjCO/JiOn9wKA+a3YG5ApL6FYJCf+b6oD4cuvpMfysviscccXOrzp6ugJSvfM7slx4PonHPzLhESeK0CU40H81lMM0/qjzJsNVTZKCKhPR8DB08xW6HSeWrccZeHQzvC2wX+SIgrQsJtm/5fSdhK/gakuynIM2FmqdNIsN5oYErTGodOImScYN++tktSPwJ5lXc8Xa+85DOqmBIBeJNp5LO9jsEMp9lkWBJBguXtSi5DGG7rNZrtFTN/w6eht4p3ah8FFn9JHpEBQoEWfTVavKk/cjigG/xREPOPDMn+ttt1Ju4rnToYqFQ9rRg8c1I2MqLpPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vQLMv0TBjQm7us/LaGvFyZIRMe1q+hi8pizCeO6Dmy8=; b=HJ7SOMRANrGOOfJ5tzWEfpUezBJEel7m09HA7SRW01hla/867xjjhG392bP9qAy+IMBFmB7vrqiwjYuxMrkm6ea3FyX/FwS7amJekDOCZ/g4L/b+CYKgqIvNne5AMi+yRTltV2PlImDb0zYFqF173MUd3a0/luzluQ8XJjHHo9M5fend2xoQuxIn8+mLybqZdFiXUxV8FDMfuaXo0G4Yvv0njb+YQbf/HRGapJfD9QUWlbegaRbiODefT8o4hthOFYdyhWMNOu6P/FNoSRZhWqMWhRVD4x3az4DUqErJTxaH2+nHd9mchPLsIP0BgPUVWHOpEQI7b7XfMym21xkZHA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vQLMv0TBjQm7us/LaGvFyZIRMe1q+hi8pizCeO6Dmy8=; b=FisUofuE7Hi8YxbY2nHe2Hyh+i35AAC5rXcr7cz3f43qdPuuHh7Fz+4aYABARWqiL0aAy/lqZvE/+9OOLT+PRwGvkpktGPcpthXJUvdxMCVL2ljqytEpyK9sIVM6bxirfqEFpFUPuJRSu4Ft49RJjtjSp7mcdC/XoLt6pUam7Qw= Received: from DM6PR21CA0017.namprd21.prod.outlook.com (2603:10b6:5:174::27) by MW4PR12MB7312.namprd12.prod.outlook.com (2603:10b6:303:21a::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27; Mon, 29 Jan 2024 11:07:14 +0000 Received: from DS1PEPF0001709C.namprd05.prod.outlook.com (2603:10b6:5:174:cafe::3) by DM6PR21CA0017.outlook.office365.com (2603:10b6:5:174::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.9 via Frontend Transport; Mon, 29 Jan 2024 11:07:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0001709C.mail.protection.outlook.com (10.167.18.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7228.16 via Frontend Transport; Mon, 29 Jan 2024 11:07:14 +0000 Received: from sindhu.amdval.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 29 Jan 2024 05:07:09 -0600 From: Sandipan Das To: , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v3 2/3] perf/x86/amd/lbr: Discard erroneous branch entries Date: Mon, 29 Jan 2024 16:36:25 +0530 Message-ID: <3ad2aa305f7396d41a40e3f054f740d464b16b7f.1706526029.git.sandipan.das@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709C:EE_|MW4PR12MB7312:EE_ X-MS-Office365-Filtering-Correlation-Id: 703c873b-f242-4a69-a68b-08dc20ba72fc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KQixVHjhR/31fKXI66bOnl6daUHJQHs6KaJm0caxb7VP7EKLgYyRAkoHXcnf5LbdDxQfAoQitCyDELEHYa1+09X2Ncb7m5gw91FSzMfuxNZFej8Nk608rwFPjEhIK9Ek+aMIhXDad+pTNAfdl1JxL8Im2ioEyoT8FbW7O3vJKJ92bDBGvwog0rrQnZ4p117/ZsMZ9hL5GIpy4m8aTKltVRBllf/TKTtF5vZuDtyGCiCXHHRytQsM5uQimKuYC+aNJblTyMnanO5yUZGi+vhXv5tG3YFZEn6vAbQkKkazcz0vxaOIRTa9pL7rJQOztWVKlvq9g5/kXKoJcioypqsBUrvUfyQK4dviwwcFy0lrmRGfMuBjElsye7/UdOGpY2mkvwOGEvUPo2NScJGd5ejthI8JbM8Wcv3j4fHvCUOim1lp00VerVLq2f7TOAmdW+O/T9pBxtv7EXU5I/3RqoYSvikCfdyTqcI1cjTZMvL4d1v328X1iDrN9W5ASSvIML0x8W3iPKSJs9em63q2crS9XC97wlgbykTk3n+CdKjGZSB1QHJx6HU3znPKp9LDoek16BLuRxsrtkadW7Y6lPxVf00196tOZy7GczuHw8GaycphcNcRLwRs6IKdsPzedlLEH4eLGJ/FgyPkaakAPdnp9BChe33uMMUZphvxIlawyZjNUvTIwWXY23+vlt5sfOlWnIKQI3kDqIrlUBml7INurFFm/O6p8xtG+52XaZy+IPynXcJPILzG716j10zygBWP X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(39860400002)(346002)(376002)(136003)(230922051799003)(451199024)(82310400011)(186009)(1800799012)(64100799003)(40470700004)(46966006)(36840700001)(36860700001)(83380400001)(36756003)(47076005)(54906003)(316002)(70206006)(110136005)(70586007)(86362001)(8936002)(8676002)(966005)(478600001)(6666004)(4326008)(26005)(16526019)(2906002)(336012)(426003)(44832011)(7416002)(2616005)(5660300002)(41300700001)(356005)(40480700001)(40460700003)(81166007)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2024 11:07:14.3371 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 703c873b-f242-4a69-a68b-08dc20ba72fc X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0001709C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7312 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789422712430892379 X-GMAIL-MSGID: 1789422712430892379 The Revision Guide for AMD Family 19h Model 10-1Fh processors, found at the link below, declares Erratum 1452 which states that non-branch entries may erroneously be recorded in the Last Branch Record (LBR) stack with the valid and spec bits set. Such entries can be recognized by inspecting bit 61 of the corresponding LastBranchStackToIp register. This bit is currently reserved but if found to be set, the associated branch entry should be discarded. Link: https://bugzilla.kernel.org/attachment.cgi?id=305518 Signed-off-by: Sandipan Das --- arch/x86/events/amd/lbr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/events/amd/lbr.c b/arch/x86/events/amd/lbr.c index 110e34c59643..43bf2dbcdb82 100644 --- a/arch/x86/events/amd/lbr.c +++ b/arch/x86/events/amd/lbr.c @@ -173,9 +173,11 @@ void amd_pmu_lbr_read(void) /* * Check if a branch has been logged; if valid = 0, spec = 0 - * then no branch was recorded + * then no branch was recorded; if reserved = 1 then an + * erroneous branch was recorded (see erratum 1452) */ - if (!entry.to.split.valid && !entry.to.split.spec) + if ((!entry.to.split.valid && !entry.to.split.spec) || + entry.to.split.reserved) continue; perf_clear_branch_entry_bitfields(br + out); From patchwork Mon Jan 29 11:06:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandipan Das X-Patchwork-Id: 193399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp490508dyb; Mon, 29 Jan 2024 03:08:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBJaTNYtECDWASqgGMknH7LlzFxnRIQ2SabrfA05V3BsWQImo47UEwTSEVhHNzgQlEnFI/ X-Received: by 2002:a2e:9ad8:0:b0:2cf:1bf2:15c4 with SMTP id p24-20020a2e9ad8000000b002cf1bf215c4mr3641597ljj.28.1706526537547; Mon, 29 Jan 2024 03:08:57 -0800 (PST) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q2-20020a056402248200b0055d36e96166si3239781eda.444.2024.01.29.03.08.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 03:08:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42588-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=x56ToNpY; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-42588-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42588-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 007301F227A0 for ; Mon, 29 Jan 2024 11:08:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1962F5EE82; Mon, 29 Jan 2024 11:07:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="x56ToNpY" Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2077.outbound.protection.outlook.com [40.107.212.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BCE1604A6; Mon, 29 Jan 2024 11:07:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706526457; cv=fail; b=OZOAKcGt7uunuIVCOTAo3/xfRoF/2YpXR0iJHd4lGxDZ1xk2T8lG5I2A92ea/WqC+2/+FR7jxitq8UwBaaWNOFCTKiucStrLek+4KSQMvUJixI6WJ4CJ5o5H6Gbg8tbxqMp/7EdrFttMOs2eip8ItSQMhh3kopinZjMaUCO0RW8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706526457; c=relaxed/simple; bh=gV2MKB5K6UVyjqqJUMBcPmK3kixaTcrJgvfs09bwCYU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WaQ1u9ZftaCh/N93zMFXpZVZ3Pm+Luo855qMSQM9vFx65o/9RcVaZzoHJIBCe7B5ppMIH6oT2vs1XcEUSCFHnvgGnO51EaxiWx5k01VHCmyjl5e+dQOQ9AF0ia2oDIvC8S01zvaj/WD2sgUodYW8f9W/pky46FSTbvAP6DQiK38= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=x56ToNpY; arc=fail smtp.client-ip=40.107.212.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AwuwNl7nYCy+N2xAxm4syTHpTuJ9m4Oy2qhM514t8CLYb3HeuGN+IFkDtzQw+Iqmtnu3d3yIFXsVmeiv6ZzkpkO0rC9W4K35vSKNNYIi3V7n/WEX29z6AOqUgSFzCevNc2GIjOqwBuDYabhnYmMbvBZAqt3qurRkN0Quq0fw2ND0wMcqwxkrTknaUmpKAlSliLAJ0YoVUfG24Z5RfRt1UXIgkqHLLws/Vtb8o4FORb9MqtuyNi185PvHBt/O+TRtm+3quXMCQfJLedYVmkwDakkVezxHmAB3hNfO7bvd+RXCNq1hZ6JZz7wUKPGtjSHPZvIptMBdkQBhtZR7f8AnHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VPMy8QQOvVtzv+5yS5UcoCje3KI+shnpnly5qLELA8w=; b=VikRFJM2kGf0A8G853zCkS9rav9iYVjYDx7KapHKn+CMa2K3NCZvNcqckYTrm89kOVL1JKbE5jv2tg2AmYBk39j9riqZOcFBOSZlvgQZL7XpFA5sBA84YJsqU4qmwbbwskwjiEk2U1+HpfvvN4yrWcFOETgCmhbJ7mSHMS31BXYs1laXXx4Qp8zuEvXWb3QesX97LCG8bi0YLZbpcNPhgbGy9mJLZk0PSvxgbmE0roE71RlCBFE1+2PYjbU5weM9dK9dPtiNm/2KVz9NGCy/Za1Uji+7qbDg94ZTCDmzQWgsktpUTw5SfjWlpWs6XXTDOlpY3F0OhZebHO/f8h+l1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VPMy8QQOvVtzv+5yS5UcoCje3KI+shnpnly5qLELA8w=; b=x56ToNpYdqtTN/vlX1vIXGS07s2a2QHfcVoIxNq6avTgvT/0/5zYzzjiP0eJi0jd52/XJxPa9yz9Ah4tkEkDPt1jXFZoo+Sq5iN+aulTTZ76rKlCwaZrYlA6qwDYJcQpCilU+mIuCDk1il1yU25722qqqZPl0DWrNC3C/i3deUg= Received: from DS7PR03CA0070.namprd03.prod.outlook.com (2603:10b6:5:3bb::15) by IA1PR12MB7637.namprd12.prod.outlook.com (2603:10b6:208:427::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.32; Mon, 29 Jan 2024 11:07:33 +0000 Received: from DS1PEPF00017096.namprd05.prod.outlook.com (2603:10b6:5:3bb:cafe::5f) by DS7PR03CA0070.outlook.office365.com (2603:10b6:5:3bb::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.32 via Frontend Transport; Mon, 29 Jan 2024 11:07:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017096.mail.protection.outlook.com (10.167.18.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Mon, 29 Jan 2024 11:07:32 +0000 Received: from sindhu.amdval.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 29 Jan 2024 05:07:26 -0600 From: Sandipan Das To: , CC: , , , , , , , , , , , , , , , , Subject: [PATCH v3 3/3] perf/x86/amd/core: Avoid register reset when CPU is dead Date: Mon, 29 Jan 2024 16:36:26 +0530 Message-ID: <550a026764342cf7e5812680e3e2b91fe662b5ac.1706526029.git.sandipan.das@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017096:EE_|IA1PR12MB7637:EE_ X-MS-Office365-Filtering-Correlation-Id: 84f62cbe-498d-400b-9040-08dc20ba7de6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tTqJW20Ojp8i5j1lJ4EUh+czBZvucvUBYJMcgg59LiY9aAiUVbzzIU1PVqJgHRRophA8Ka20PEIWmavxctq/I5hFerByZypfK4+vRKhIpt+l3/Ap5ctKHah1Kj/9Tr7nYjyzIXhsDElc6LAE62ikl2ZQ0m9EHxesgagb/TMeWPSazMygTuTXhTV59h8Jo2cd5C72T66ebg/rGobIgLDJr0Ss1NaZxFI3yqfwOQudMfm43iOJUCma1c7zYbHGILe1+iPSRhELeZ1ZMSg6rkaqI+IUpJ4mWebb18Xmv3mnsxqXnfk0wHmsHAkRc31Lh3Tkm8CXa6g1YWyxFnsK6KOML1CnjcWUwRO52cp5lBhnvZhDTsZ+mVo/b8BSam59dTHhb3qENHwRw5juhJbimx++VVPo8c2lAsc905lFxhV8hHnnliUp8puiYVlVB6dQHUhPdhGP03XBkKFwzJOINXylCeuuvvJBh2OnQLx4CjdGufCqpIFZ+JmJgsjMo8O1P0fZbyW+ZHz85HFpCeAPx/oLb0Wc1k7Gz+lB2dBfDLPDn3NWBnTYPPfzWrMO1pXQRv9T1G5GHqc0tCSMHpnCVW+iscxBARE5K6rDoOYoFcZR1AjXYNmSEALQpeqgIg+J994I+/VoQaULkjySZKfu+tkXtGfGmnHx7YwHvUIn3QyTbh/1FQ2ma60WxGUstdiDXuE5+cOMQ3UU0B7/g+WDc+O01EVDFLhkM4xdiMVIUoffK0ghr0QA4o/xVqNYoF9Xo/7H3X+8bDD/M+hVltNnIeIDdQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(136003)(39860400002)(346002)(376002)(230922051799003)(451199024)(1800799012)(64100799003)(82310400011)(186009)(36840700001)(46966006)(40470700004)(2616005)(83380400001)(8676002)(426003)(16526019)(26005)(336012)(41300700001)(4326008)(7416002)(5660300002)(8936002)(36756003)(2906002)(44832011)(316002)(54906003)(110136005)(70206006)(70586007)(86362001)(478600001)(966005)(356005)(47076005)(81166007)(40480700001)(40460700003)(82740400003)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2024 11:07:32.5848 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 84f62cbe-498d-400b-9040-08dc20ba7de6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017096.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7637 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789422770626838339 X-GMAIL-MSGID: 1789422770626838339 When bringing a CPU online, some of the PMC and LBR related registers are reset. The same is done when a CPU is taken offline although that is unnecessary. This currently happens in the "cpu_dead" callback which is also incorrect as the callback runs on a control CPU instead of the one that is being taken offline. This also affects hibernation and suspend to RAM on some platforms as reported in the link below. Link: https://lore.kernel.org/all/20231026170330.4657-3-mario.limonciello@amd.com/ Reported-by: Mario Limonciello Fixes: 21d59e3e2c40 ("perf/x86/amd/core: Detect PerfMonV2 support") Signed-off-by: Sandipan Das --- arch/x86/events/amd/core.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index ffdfaee08b08..63514c311f44 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -604,7 +604,6 @@ static void amd_pmu_cpu_dead(int cpu) kfree(cpuhw->lbr_sel); cpuhw->lbr_sel = NULL; - amd_pmu_cpu_reset(cpu); if (!x86_pmu.amd_nb_constraints) return;