From nobody Fri Dec 19 08:02:01 2025 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2043.outbound.protection.outlook.com [40.107.102.43]) (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 22D6547F47; Sun, 17 Dec 2023 17:26:21 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="nspm5gwX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I49QaEYsvo0dskWCzTdYZiyVh2Sy3SqZ13Ta7SYqmG6XSwiMUgaV5WEbIABrEcR61PaXLW4cnP3butX1Fq9a8IugYUx92h2tBcBjJmdBiCjlajTaIvzGt1er2Q2S/c0htl/DbIFmVfPqKUGj/r0vcPOwR8aOLSsb6onqjeq+syFNSYIiIYSc4hVWxPF4BBVeo7aUgNrZ2WvlWAj/kjXstvpn4vG6FR7bJKhxWhJZ+2Q0YPO5T/aU2XmT7O5XKZhji7bibB432hycCUqjzWYZmw4SvGFWJnGO1LfHPbzCnqdV+phQeuc41Igm9ITtLfy9d6Wa+KOFGK5zELn+3fOJYA== 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=tV4uGHwqLjarhGvfZYQ9bTWmlI9hqRdeI+LjEqCl/Iw=; b=D2g0Xa8SdKhnBVPwt7F6G22oV7fBvdQ/1OP51uTOkbSSkcTuqzx4r+YEjdadpiE5eH2LTtlIC5+y4fb2IXe5X2to56M0eU6FvPJXe+3pmrDHLSn96rdeInnJDYc6uSaD9m/VdOfA7vGcI8p1KnFzMKPAS8L7OhEI7pFvt3cM3BBEq30lY7eM8z7eBAcn5dvdE/V+cN6bbtmTUkjAF2a4ufjSaWPFEBLGHSyZ0LiG3IiKQ0IkvHsSfFhSGLLe6S3SMPB48DStPWBQeEVxTn4dN5OQZiD4GlWH7kkaHgEUcR3DakD2kV8vIjQIBpy2FUWIG4AW60uSejgY4SOWxishug== 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=tV4uGHwqLjarhGvfZYQ9bTWmlI9hqRdeI+LjEqCl/Iw=; b=nspm5gwXekz7icpAPRvluWsGykoGVYberFbIAqi9GiA/6jFcF65u5QEN6V5TUTpEANpFUxYamYK28DE6dlm8ga61hfXLQxcw6vOqBGrAiG98UyjGPMO/7fjVbAvjq3DpZjru/LB22E40AHbxx5Ljy5V3lb2ZIuc3sCwRS0Po4+Y= Received: from MN2PR15CA0010.namprd15.prod.outlook.com (2603:10b6:208:1b4::23) by CH3PR12MB8850.namprd12.prod.outlook.com (2603:10b6:610:167::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.37; Sun, 17 Dec 2023 17:26:17 +0000 Received: from BL6PEPF0001AB57.namprd02.prod.outlook.com (2603:10b6:208:1b4:cafe::63) by MN2PR15CA0010.outlook.office365.com (2603:10b6:208:1b4::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.37 via Frontend Transport; Sun, 17 Dec 2023 17:26:17 +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 BL6PEPF0001AB57.mail.protection.outlook.com (10.167.241.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7113.14 via Frontend Transport; Sun, 17 Dec 2023 17:26:16 +0000 Received: from sindhu.amd.com (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; Sun, 17 Dec 2023 11:26:11 -0600 From: Sandipan Das To: , CC: , , , , , , , , , , , , , , , , Subject: [PATCH 1/3] perf/x86/amd/lbr: Use freeze based on availability Date: Sun, 17 Dec 2023 22:55:43 +0530 Message-ID: <1d9106579c7781746ca39860bda8061c56d6dc48.1702833179.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 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB57:EE_|CH3PR12MB8850:EE_ X-MS-Office365-Filtering-Correlation-Id: 27cce6f0-b367-4689-0eec-08dbff2546d3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7A0tf2gw+Zgt3ISpA/zYBaM/NIy2FBVFWj/LKN2mVlUbir9t8/3stvfRWONwGP3SHiBBiNTcjIyuRtiCmOgVde/BN/gRWZDMKmrU1zA/k3n+9T5NT1xxGCehTq1gKBhv5+Jr9z13iyS0cvG+yHHq+qvOe66fLDop8VLYikcMBlS53SF//FFteDCv48pcIgYJ58P0Jcd6HgyQc+j4miW78mH4bEG2i5jx2KOiNJlCkYAfbFAZy9Z0Sr+W06xk5xa92MBraqcr9GRtdZ9VgQIp4GzHNwaKMWCj5HGykk4FCdG26Hh5lY/Ot3zXTSoTAYPHEtq7n8aaM5Xm6SK8tk2NHd2yGKTVatsS6ThGiobUVCluEjD+Zyna+cy3Vj8G3x0jmBUrXGsVzZck+V2PhtDzQgVXqGRcgn4tByKZeJss0PzlL/dK1gIciAccvtmYm87h76tjUSIeCgDTs4mUExeqMv2FUA+T2VlAttdYOT6hAvVSSjAxRJ1ldZHbvSVlF1GaNb9PUeSjknU4vdBD3bsfCTsUNF2DoRicZFBdRo/ytGyLRPQ/uxUDLrJwg8nbiJGgDHObHP6WnPm7zX0+Lcy9CXtANOyeR7JedZlr67Pz7EF39EeLxHdKxvvIShDTCtaWTCpQhmUjQDETmtpx17JoLW0aQPRZJBTWAT7VI7+gcBqEIIixUjMlDL4nZuJVJXNRYdn53yr+yqAm6w7v7qOZ4fEno2Rvvn1Vp1cdkfi+9Rl2H8WZxVxXf+LeoyfNELFxpFWyVtXHVLGn6IjuyvBPFw== 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)(346002)(376002)(39860400002)(136003)(396003)(230922051799003)(186009)(1800799012)(64100799003)(451199024)(82310400011)(46966006)(40470700004)(36840700001)(40480700001)(478600001)(2616005)(70206006)(336012)(426003)(83380400001)(6666004)(316002)(70586007)(54906003)(110136005)(5660300002)(44832011)(47076005)(7696005)(8676002)(8936002)(4326008)(36860700001)(26005)(16526019)(40460700003)(2906002)(81166007)(356005)(7416002)(82740400003)(41300700001)(86362001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2023 17:26:16.9698 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 27cce6f0-b367-4689-0eec-08dbff2546d3 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: BL6PEPF0001AB57.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8850 Content-Type: text/plain; charset="utf-8" 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 Fixes: ca5b7c0d9621 ("perf/x86/amd/lbr: Add LbrExtV2 branch record support") Signed-off-by: Sandipan Das Cc: stable@vger.kernel.org --- 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; =20 - /* Read branch records before unfreezing */ - if (status & GLOBAL_STATUS_LBRS_FROZEN) { + /* Read branch records */ + if (x86_pmu.lbr_nr) { amd_pmu_lbr_read(); status &=3D ~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); } =20 - 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); + } =20 - 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); } =20 @@ -416,10 +418,12 @@ void amd_pmu_lbr_disable_all(void) return; =20 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); + } } =20 __init int amd_pmu_lbr_init(void) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index 4af140cf5719..9790e906d5e5 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 userspac= e */ #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 Exten= sion Version 2 */ -/* FREE, was #define X86_FEATURE_LFENCE_RDTSC ( 3*32+18) "" LFENCE synchr= onizes RDTSC */ +#define X86_FEATURE_AMD_LBR_PMC_FREEZE ( 3*32+18) /* "" AMD LBR and PMC Fr= eeze */ #define X86_FEATURE_ACC_POWER ( 3*32+19) /* AMD Accumulated Power Mechani= sm */ #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/scattere= d.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[] =3D { { 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 } }; =20 --=20 2.34.1 From nobody Fri Dec 19 08:02:01 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2041.outbound.protection.outlook.com [40.107.93.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 1518047F63; Sun, 17 Dec 2023 17:26:38 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="5TiMi6JG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Oe8NpMkzH5vkj2gQBI5yadd4GeWy7deIyurA/tP+1CPwP+tmvzuP71PHzVL8S6opkZEBk2mEGv2ydAF05KPOGkiYAgz1lNFxT/Ym/NcRHYRlB0ouG8WFxgyeXss1JSNnOkCCymbDC7ueWD5Bk+5uhyVZ5EM+ZqglTzLbzL+kTDJ3KDo+mrzdRPx4uIYBI5Klm/tTN78xs28ZyodwQt/C8WY3Dt+gTxDZijfjLu14FBEvdqRFPI4/1OTuZ1afoBj/3cLj4Rq0GgBdnt91isU2+XJV84pdAaTk//VWFpXT9P86AlRapRNPDVry4nz83oFF9PJcJOskDnnHd8v2Nx9BXA== 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=ydyLI1JyiusH1IXsvEMKMa9VpjWP+LtHHDwty7qcHak=; b=QyS6H3lc0KwUl6Ib5N3vDWbrP0zmu0r8GvsAgBFVHFqf0HvkAc2PRAZC7m300nbpVpWKGyndoLoUTvSNoTiSEGgGQiNEbFTULzDdD+pWhX8LRaMfmzMcNg/m/E+KnTr0Dln+A/UZ/dVSXrK8dTNE/l/BVx1H7ME5oQwzsBMI5padPvEuLCJ8A9klidcj5NZq0vggaOrRZdeQlq49Nm7SstzFo5hqCIrqNfXCMfy8ytakB7NtfMYKNqU97AGBqD4a+tIcT5YQEVvL5X/FYi9VMTxmXP66b/5vkPh6+CTnAROBL+4cXFoGafnWYq8ga74LShETD6nvR3kVAmSAe29n1g== 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=ydyLI1JyiusH1IXsvEMKMa9VpjWP+LtHHDwty7qcHak=; b=5TiMi6JGu7/TU3wPOPE1Lbfr4gowkyqsv5/Pcegh/RI955bOaATeFToGblnNtHvKFjBHLTWt+9ErTLro7EbkkhCKgbuod+MdY4VarxrDySCn4qjjpLLfyvP0M51OoBTU7OoPqYw9pjOFoyB0qDrvNybnyM0A5DWGGABadbW+MYk= Received: from BL1P221CA0028.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::18) by DM6PR12MB4941.namprd12.prod.outlook.com (2603:10b6:5:1b8::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.37; Sun, 17 Dec 2023 17:26:35 +0000 Received: from BL6PEPF0001AB55.namprd02.prod.outlook.com (2603:10b6:208:2c5:cafe::d3) by BL1P221CA0028.outlook.office365.com (2603:10b6:208:2c5::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.37 via Frontend Transport; Sun, 17 Dec 2023 17:26:35 +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 BL6PEPF0001AB55.mail.protection.outlook.com (10.167.241.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7113.14 via Frontend Transport; Sun, 17 Dec 2023 17:26:34 +0000 Received: from sindhu.amd.com (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; Sun, 17 Dec 2023 11:26:29 -0600 From: Sandipan Das To: , CC: , , , , , , , , , , , , , , , , Subject: [PATCH 2/3] perf/x86/amd/lbr: Discard erroneous branch entries Date: Sun, 17 Dec 2023 22:55:44 +0530 Message-ID: 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 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB55:EE_|DM6PR12MB4941:EE_ X-MS-Office365-Filtering-Correlation-Id: 6f1480ca-f42b-4cab-8c5b-08dbff25518a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ksRnrKFycEuR48ujMYtpyO6kt/XWtFaljpoisjYOm4lyy3G5Zivn+vmMCgAkNevg4J4bR/GauD8R9fWT1Q+jPpW1PJMULNeljk/QqhgUXCObk7+hztZpiBOlga44pXsPR1hJWidAI6RrT2x6mHM7jgGOEZdV2VM0rgkz1WyBzk/JFD39A7lt4I/Ofs3nBxoC7jijIR7XDrk0jee0iiqMAytXwHCV5JvuENxg4Rr38Nh1JfIROhqsMx8loD9iOJoNmXpyq49Nh5s8v/QPCKsmT69xz2g+1O46hMjMxyB6CKJW77qJ09V0pr+yOc6r739amNOQzX4SvRwYBv85HFxA0gy40EeS/Uz4oLTXs5jPBJ1s0BXcR5saYnGm1Bo+CwVU3Ff7oSXVWxDtdqk6LMU2vW2nZdHpZc+ZYC8jNIH2HHAKPktYaX8MR4nBgqzmsIqSbmsjKzKsdMT1ryEyKOtkq2ApziQ+yrpDiaHbKLU2Y+bhwNjiD4yKBgNLcPO/9V9ohe50E2rtCgU1TMhFvLzZ4301GUmJW7GJ5Y2AcEIjs9I+QCYyUXQk1lkPPLRJ1YBJgZX2l5Ub8vj8e0VRxASe3tx/BEQx0RrCyBXUiYCfytUDssGZCUpKJiQvdBpQ8bw9Eob9L66v3gPZ9UqMuv1OmOgODBbGXSwqt/vLkyzaS8tCxNUsFU2ebbq1+zmw//sC78WG70vDf2WPmgqVKp6NNuDlkJeYvdCz8tqu1yJhPqWEWUo8GCjhvVXNS+D4x2NF 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)(39860400002)(376002)(346002)(136003)(396003)(230922051799003)(1800799012)(451199024)(186009)(82310400011)(64100799003)(40470700004)(46966006)(36840700001)(40460700003)(47076005)(83380400001)(2616005)(16526019)(426003)(336012)(26005)(36860700001)(4326008)(8676002)(8936002)(44832011)(41300700001)(5660300002)(7416002)(478600001)(966005)(6666004)(7696005)(2906002)(316002)(70206006)(54906003)(70586007)(110136005)(36756003)(81166007)(356005)(86362001)(82740400003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2023 17:26:34.9495 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6f1480ca-f42b-4cab-8c5b-08dbff25518a 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: BL6PEPF0001AB55.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4941 Content-Type: text/plain; charset="utf-8" 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=3D305518 Signed-off-by: Sandipan Das Cc: stable@vger.kernel.org --- 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) =20 /* * Check if a branch has been logged; if valid =3D 0, spec =3D 0 - * then no branch was recorded + * then no branch was recorded; if reserved =3D 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; =20 perf_clear_branch_entry_bitfields(br + out); --=20 2.34.1 From nobody Fri Dec 19 08:02:01 2025 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2050.outbound.protection.outlook.com [40.107.94.50]) (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 610F14654F; Sun, 17 Dec 2023 17:26:56 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="qjnovyJs" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PPo33fa+NlJtW0a6+euYsE7DWkvcO5/H1KerAvi1tWwJQuuWH5RF+ZgA03FH7FMRIvxljgQnIDUgaPKOJ0KK7uGzAeM6bcfhssh41FJr246iVvW81vbW32VwEo5wg7+3A+E0caAIC5oxRZH99VCPiycf8OCtKAie7KpqTYRBjHvwTe97a2he7e0ia4GM0eBPrie5EP7qQ2cYbykGMmsLoxFgsyf8uWowLzWXoILtI0p25WU2EiENn8pWfRD2dl9Gj36GNPiFRR3vzmFMtwiZdzoYt585rlfhi0zXzmlfdjFBoqk0/+15UpbMIZsqjfTr4BRVS8OtCegRd8NUniX2Lg== 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=2eo7ojfjoAaEajf+ncOHJPmHUNqXulD9sOKy5D6mNvM=; b=e+wEtJ3XgacGFe+aZKs4H+YeJerBfPFP+sQMYs0AUo2X97wWHT/MZCR/GZ6NCIUX2MzdQIyx0fElcfvuoV81+X+heY+f4ce6qnJ7lFeUztfSV2MiBSCWkZ7q9RruLrI2dmFRDa6Qu+yxPt4dkIjytwzAsLV7/7P7+qZ2xf0ugWDXdDCXD9Tt9rz2PZuQPfWNgqgiG29fv0Or3m1jLDnW/WqKx/d6q+w1g4Pr9Zaln+TogfJ8aKh9BjVaHJC9cgk2emXVZuEeghS/nWdPVKP4RAAIkmoFYlGgKFr8H+ouSWF5ayyo7Lq/jiP8RvgCqAh5iTPJ8SrtfT1C1ecRBtWF3g== 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=2eo7ojfjoAaEajf+ncOHJPmHUNqXulD9sOKy5D6mNvM=; b=qjnovyJs3uZM8K/3UeTj8NodAP0pQCo16eRxTGnPwTLh4xE6V11XHCnL+I/1Bat7Lr6BQpAuxd+Bl+PfdiS/UXqaCXRTYRkxMBMIJzrFsMoN95F82/Z4cc9Nrv+0ZP+C9T4neQS7mOEFekU8zw4WfY7v8PaBh057gVLIbxeAJ1w= Received: from BL0PR1501CA0006.namprd15.prod.outlook.com (2603:10b6:207:17::19) by BL1PR12MB5110.namprd12.prod.outlook.com (2603:10b6:208:312::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.37; Sun, 17 Dec 2023 17:26:53 +0000 Received: from BL6PEPF0001AB59.namprd02.prod.outlook.com (2603:10b6:207:17:cafe::9f) by BL0PR1501CA0006.outlook.office365.com (2603:10b6:207:17::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.32 via Frontend Transport; Sun, 17 Dec 2023 17:26:53 +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 BL6PEPF0001AB59.mail.protection.outlook.com (10.167.241.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7113.14 via Frontend Transport; Sun, 17 Dec 2023 17:26:53 +0000 Received: from sindhu.amd.com (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; Sun, 17 Dec 2023 11:26:47 -0600 From: Sandipan Das To: , CC: , , , , , , , , , , , , , , , , Subject: [PATCH 3/3] perf/x86/amd/core: Avoid register reset when CPU is dead Date: Sun, 17 Dec 2023 22:55:45 +0530 Message-ID: <602bb64ca452b843a3df8376f731f07e92039589.1702833179.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 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB59:EE_|BL1PR12MB5110:EE_ X-MS-Office365-Filtering-Correlation-Id: 2406684a-4c45-4383-9270-08dbff255c56 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PO5cczoITIdCrnfvmwX/lTZ/ESc3dxneJPgPYmKvRoyPZmf+7ZgY8POs6atPRL4QRSXrvOvhXSogywYwXVss48a7uTYuOgLfBD5JQJNCjlIcbyH6x6C9g0VlHNcdHHJ/OcJH9BYR7TnLqNmioh9ycFhPa5k7ezBlBIp4C5R0t8K2CmK9HVVL7JNTOt3Ol2f089gSP6Jc2lB1VAqIKkip/tAZ5iJ6D8symaUDO9s5Ai5SOMdhlNa134DuWpQzl69q5YYQPWmSWL2EaZLm9VYGB3S1qkdE06C4lwdEQU4753LgJ0tSjR+xQ9weAA5nsXVr+5vjDxCNAXX0vjfx+Ki93gm8SmT8MaJt59wzcOXBuHfxFkTBzcTV1Sr5sh3fipYaQOpKv8/HQb2LsuT/poOewtFROyl03UmQBMcvSQYvGm1LzEXXrHuJpXTrwSIqTN+TLE/GF53AOwTPXeQ+w5Ut9Rio32lRP3hRkQZhluwIfjKH+HpM7OShiC1b08o6dobFw8MTxa/5b+Y+e2dejq1e28qfNDiulyhrNkNeI+YUjbjcHTwjlRUa8i7HVGVGBv5XJbnEP4hoiWIzzFNyuruesa1UZ5AgCVsZkx+tDSYQ0T0TqFwxHONoa1GveGhd0yv4ICMl4fzd4npWazkh32kaekhuCMPrB8lyBH+7j76092Ede4B0ph5F2ni0sArJr0DEPDyRFPt9/DlSZB+gkq+00pp8b7xKeXS2HG11jpUuZe7AsT7C3/WS3d9em0Ps4AjR48Ti40vTXenwBDlVZewQFQ== 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)(376002)(39860400002)(136003)(396003)(346002)(230922051799003)(64100799003)(186009)(82310400011)(451199024)(1800799012)(46966006)(36840700001)(40470700004)(40480700001)(426003)(16526019)(336012)(26005)(2616005)(40460700003)(356005)(82740400003)(36756003)(86362001)(81166007)(47076005)(83380400001)(44832011)(5660300002)(7696005)(36860700001)(8936002)(8676002)(4326008)(70586007)(70206006)(54906003)(316002)(110136005)(7416002)(966005)(2906002)(478600001)(41300700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2023 17:26:53.0794 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2406684a-4c45-4383-9270-08dbff255c56 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: BL6PEPF0001AB59.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5110 Content-Type: text/plain; charset="utf-8" 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@a= md.com/ Reported-by: Mario Limonciello Fixes: 21d59e3e2c40 ("perf/x86/amd/core: Detect PerfMonV2 support") Signed-off-by: Sandipan Das Cc: stable@vger.kernel.org --- 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) =20 kfree(cpuhw->lbr_sel); cpuhw->lbr_sel =3D NULL; - amd_pmu_cpu_reset(cpu); =20 if (!x86_pmu.amd_nb_constraints) return; --=20 2.34.1