Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1418300pxb; Fri, 10 Sep 2021 05:37:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMjO2cap1NvHIPBTiah45b/ARa2rp7kImjAkxWE6vDpcNPP1+ikvE2wceJlQtoNMe6oiQ/ X-Received: by 2002:a92:d18c:: with SMTP id z12mr6379380ilz.59.1631277460125; Fri, 10 Sep 2021 05:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631277460; cv=none; d=google.com; s=arc-20160816; b=PmpaA/UXMJoTF/YuO1R8Fp5WXmEf/uo9TAEemY0Xp2s/G9esizRsHRuPFUB7xJLl8Z FU4sefSIgnXhK50H6NBK0bZfh8kFB6a2BOdCYOdtHau3mpMKipxBGzFgMsPNIT225Mlc jpRI3TGB/aNZIXu3DxJfg/l02LHao0eLuk2xYsQfq6prCMRRPEQq02hUzbC7SNGopA0f 4mKABR7wqVkXsswY4cHOyfXB+/CxDv/TfsGWcflkUdvNwP1OMEFTjprTIYbATjes05ts 7xURvPAVf/TnQNwcwevOF2MVWHxs3dk+ZWGPoo7Xe55DBh/qh2PId7YaUILt6uCfgg/0 bB1Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=clRqs6QGtaq28TVc3Z0Vcg8GUMQcGfIGsyfayoUu+YM=; b=kMHqLuz2x4aLPt8Kf5nuUvJWKVfHPKAPhIGqGPvj+QYp76Nx7S8EGR2zHY142oE37E yuULd3OU36HR8bTMFxkP4fC2U+gFEPKNJWCb9bx7KwrFQDpDg1ASIRHJJs95znTKDhQy CavrBaCXqY2hyf93KmIU8BviIeqPZ4qzXToVQKYeKyoW880l7jysfQ2IdSluiCRXigeO U3TiYVO60OrqcR043a5BYFUg6McOATrQPd7W9vsCb+hbHPqYJDnHCO1d9nMejEoByMWZ zNLsj0UBmjN0gMAMBKr/2Y4pavFs5EH8hGlaBRnecV6KQ9PaB9Qm/te7NFAFSPSTMq06 wckA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i6ijUnPu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l5si5507011jaj.63.2021.09.10.05.37.26; Fri, 10 Sep 2021 05:37:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i6ijUnPu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233558AbhIJMgz (ORCPT + 99 others); Fri, 10 Sep 2021 08:36:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:53226 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234118AbhIJMfj (ORCPT ); Fri, 10 Sep 2021 08:35:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 95A1A611C0; Fri, 10 Sep 2021 12:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631277268; bh=R+pFxqUfFaswkHSpX4l232ejy8W9LWJkctYPypdexeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i6ijUnPufRElixe7AgtVGjXaalpieGWPQyefrUjNhO8X4LoJ02DbYVoI1d30ItS3f 10hdJpCNLha77Y1/f5XmUiQzHkQGqKQpbZWoqFdDl4kVQRXPxk8acVef0+U23CYBk1 LMOdU1T0Gj9bQsHPeKldb4Wxhas0yMxWsAhAV5/o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kim Phillips , "Peter Zijlstra (Intel)" , Ingo Molnar , Sasha Levin Subject: [PATCH 5.4 14/37] perf/x86/amd/ibs: Work around erratum #1197 Date: Fri, 10 Sep 2021 14:30:17 +0200 Message-Id: <20210910122917.642099145@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210910122917.149278545@linuxfoundation.org> References: <20210910122917.149278545@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kim Phillips [ Upstream commit 26db2e0c51fe83e1dd852c1321407835b481806e ] Erratum #1197 "IBS (Instruction Based Sampling) Register State May be Incorrect After Restore From CC6" is published in a document: "Revision Guide for AMD Family 19h Models 00h-0Fh Processors" 56683 Rev. 1.04 July 2021 https://bugzilla.kernel.org/show_bug.cgi?id=206537 Implement the erratum's suggested workaround and ignore IBS samples if MSRC001_1031 == 0. Signed-off-by: Kim Phillips Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20210817221048.88063-3-kim.phillips@amd.com Signed-off-by: Sasha Levin --- arch/x86/events/amd/ibs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index 39169885adfa..ff07040287c4 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -90,6 +90,7 @@ struct perf_ibs { unsigned long offset_mask[1]; int offset_max; unsigned int fetch_count_reset_broken : 1; + unsigned int fetch_ignore_if_zero_rip : 1; struct cpu_perf_ibs __percpu *pcpu; struct attribute **format_attrs; @@ -663,6 +664,10 @@ fail: if (check_rip && (ibs_data.regs[2] & IBS_RIP_INVALID)) { regs.flags &= ~PERF_EFLAGS_EXACT; } else { + /* Workaround for erratum #1197 */ + if (perf_ibs->fetch_ignore_if_zero_rip && !(ibs_data.regs[1])) + goto out; + set_linear_ip(®s, ibs_data.regs[1]); regs.flags |= PERF_EFLAGS_EXACT; } @@ -756,6 +761,9 @@ static __init void perf_event_ibs_init(void) if (boot_cpu_data.x86 >= 0x16 && boot_cpu_data.x86 <= 0x18) perf_ibs_fetch.fetch_count_reset_broken = 1; + if (boot_cpu_data.x86 == 0x19 && boot_cpu_data.x86_model < 0x10) + perf_ibs_fetch.fetch_ignore_if_zero_rip = 1; + perf_ibs_pmu_init(&perf_ibs_fetch, "ibs_fetch"); if (ibs_caps & IBS_CAPS_OPCNT) { -- 2.30.2