From patchwork Fri Sep 22 10:14:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 143553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5754220vqi; Fri, 22 Sep 2023 10:32:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqMPatDh7dzd9qv5zAQNUXqTv15Eb0o7iqhLh1ivp/g3EjsLd7kecF4INX0Hqb2nB8rMYT X-Received: by 2002:a17:902:b697:b0:1c5:c546:febf with SMTP id c23-20020a170902b69700b001c5c546febfmr108278pls.35.1695403921845; Fri, 22 Sep 2023 10:32:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695403921; cv=none; d=google.com; s=arc-20160816; b=ziy9HspzcrHM0b/psXp+SAzPe1HBNym+H6qP34mg+pP7hQvp7O2CV/dzCbzEd8Tkp7 2BZ3OolXWciUHmfgKu8ulUIBwM7pRoaLdT0fGBYt/I8aRiL29fB0oU53wP2dvCbjJz3m 9OBX9VvwYzx+VLjA/mvNizMOuwfNx1GV7KlU+QKo1tsDhYePraczqUVATas/WvHAZCXk jXdWQokQSt7skZIYFDFu7sn4SynJwJbRQdRWVT6zpFV6nklY8rtLRYIKSgD3uhK7vm4s CR/schy/eirL8w8QmilEXo2HfzWrFejVm9m6+y6fSf0LszkqF+7MefQkpR0DqH+rrVuZ P1nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=m6oKo80YM1jv6r3dEtqSy8VqmOuvE51r2r/UpE6b6WA=; fh=8Vtzy/VB1rbRFa+4ba5MgfvN82IpndldC8wgFMigx4s=; b=zBRf3+iVZQBWjMiw/lyOD96Sh6k9KvLqaxz3vlAlwJZbdOxa4Vr7k9TpK3Ouo80m91 hMeIW09P7E81xDLldFPrgFoTGNsmm8NAiL7n9p5RvUbq5nZqyI0wuaD6l6P7wexI36bG ho/NORVPmztbTgrFBzlKOfLwObfc1J6yf3lUqLDujYTtdepCRjHLO+GfFeSnmprO8Kkv 8vd2NZ4Dix99R39Haljmq8MEJ4zofj+hl6nscgrjm9IJupn6K6k47Mp2of38B/LvJvDD y6wRXBB0+u8+0o5XLSMU2rmARIrRSckX1kAtfdVria/fQY6zl00yllSKVfnRGe3TRN1J b6oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XPIFrP7g; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=F2pDuttE; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id m9-20020a170902e40900b001c08c0baedcsi3952225ple.67.2023.09.22.10.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 10:32:01 -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=@linutronix.de header.s=2020 header.b=XPIFrP7g; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=F2pDuttE; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 298768562968; Fri, 22 Sep 2023 03:14:56 -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 S233042AbjIVKOu (ORCPT + 30 others); Fri, 22 Sep 2023 06:14:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbjIVKOt (ORCPT ); Fri, 22 Sep 2023 06:14:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B5D794; Fri, 22 Sep 2023 03:14:43 -0700 (PDT) Date: Fri, 22 Sep 2023 10:14:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695377681; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m6oKo80YM1jv6r3dEtqSy8VqmOuvE51r2r/UpE6b6WA=; b=XPIFrP7gCRpEGWyLDNuWxXA0sCne93JpjTdyp6BU1husnrxfvU6Kbz5oIg5R3X5zdp34mS AXncqMNEEVBMiHEU9NsmTf64xhU1L95n29i8eZqd9oKpQLxgm6q2rpoi2yFQRDvgR3xMrg Cq/vO2kf97yDh5tF349Y3rIb2+uetemGzvjyoyX0dQ1WXbk4D2nApUG0yyIs+Mex2JxZ8v MYgFCkbZznmDd7O7xAP1KZI4o4zyb9UNu4slsjp1IHuzso8Vob78M352XMR782ts6cOAvQ jvT4FRVi4h/QWNjmBQetcdebcFJDjR6VT5Pz1IoPa9DQp3VgNqQQQOy6lanZbA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695377681; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m6oKo80YM1jv6r3dEtqSy8VqmOuvE51r2r/UpE6b6WA=; b=F2pDuttEpQX0/SnFCJ72XshohTQdxryFfALtK+b7dk1lnSfdR+c8jzttptWTYDHdMJi92p d5B8zkLuepYDMxAQ== From: "tip-bot2 for Sandipan Das" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/urgent] perf/x86/amd/core: Fix overflow reset on hotplug Cc: Sandipan Das , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?q?=3C882a87511af40792ba69bb0e9026f19a2e71e8a3=2E1694696?= =?utf-8?q?888=2Egit=2Esandipan=2Edas=40amd=2Ecom=3E?= References: =?utf-8?q?=3C882a87511af40792ba69bb0e9026f19a2e71e8a3=2E16946968?= =?utf-8?q?88=2Egit=2Esandipan=2Edas=40amd=2Ecom=3E?= MIME-Version: 1.0 Message-ID: <169537768083.27769.536098722468135960.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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]); Fri, 22 Sep 2023 03:14:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777074020738296791 X-GMAIL-MSGID: 1777759862510401539 The following commit has been merged into the perf/urgent branch of tip: Commit-ID: 23d2626b841c2adccdeb477665313c02dff02dc3 Gitweb: https://git.kernel.org/tip/23d2626b841c2adccdeb477665313c02dff02dc3 Author: Sandipan Das AuthorDate: Thu, 14 Sep 2023 19:36:04 +05:30 Committer: Ingo Molnar CommitterDate: Fri, 22 Sep 2023 12:05:14 +02:00 perf/x86/amd/core: Fix overflow reset on hotplug Kernels older than v5.19 do not support PerfMonV2 and the PMI handler does not clear the overflow bits of the PerfCntrGlobalStatus register. Because of this, loading a recent kernel using kexec from an older kernel can result in inconsistent register states on Zen 4 systems. The PMI handler of the new kernel gets confused and shows a warning when an overflow occurs because some of the overflow bits are set even if the corresponding counters are inactive. These are remnants from overflows that were handled by the older kernel. During CPU hotplug, the PerfCntrGlobalCtl and PerfCntrGlobalStatus registers should always be cleared for PerfMonV2-capable processors. However, a condition used for NB event constaints applicable only to older processors currently prevents this from happening. Move the reset sequence to an appropriate place and also clear the LBR Freeze bit. Fixes: 21d59e3e2c40 ("perf/x86/amd/core: Detect PerfMonV2 support") Signed-off-by: Sandipan Das Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/882a87511af40792ba69bb0e9026f19a2e71e8a3.1694696888.git.sandipan.das@amd.com --- arch/x86/events/amd/core.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index abadd5f..ed626bf 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -534,8 +534,12 @@ static void amd_pmu_cpu_reset(int cpu) /* Clear enable bits i.e. PerfCntrGlobalCtl.PerfCntrEn */ wrmsrl(MSR_AMD64_PERF_CNTR_GLOBAL_CTL, 0); - /* Clear overflow bits i.e. PerfCntrGLobalStatus.PerfCntrOvfl */ - wrmsrl(MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_CLR, amd_pmu_global_cntr_mask); + /* + * Clear freeze and overflow bits i.e. PerfCntrGLobalStatus.LbrFreeze + * and PerfCntrGLobalStatus.PerfCntrOvfl + */ + wrmsrl(MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_CLR, + GLOBAL_STATUS_LBRS_FROZEN | amd_pmu_global_cntr_mask); } static int amd_pmu_cpu_prepare(int cpu) @@ -570,6 +574,7 @@ static void amd_pmu_cpu_starting(int cpu) int i, nb_id; cpuc->perf_ctr_virt_mask = AMD64_EVENTSEL_HOSTONLY; + amd_pmu_cpu_reset(cpu); if (!x86_pmu.amd_nb_constraints) return; @@ -591,8 +596,6 @@ static void amd_pmu_cpu_starting(int cpu) cpuc->amd_nb->nb_id = nb_id; cpuc->amd_nb->refcnt++; - - amd_pmu_cpu_reset(cpu); } static void amd_pmu_cpu_dead(int cpu) @@ -601,6 +604,7 @@ 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; @@ -613,8 +617,6 @@ static void amd_pmu_cpu_dead(int cpu) cpuhw->amd_nb = NULL; } - - amd_pmu_cpu_reset(cpu); } static inline void amd_pmu_set_global_ctl(u64 ctl)