Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2567100lkm; Mon, 20 Sep 2021 18:54:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFiPQeQ6D2exOqTwTMrzF6ybwGe2Yg/RcZHdkm5nHU8hJjw67UH/p1sMX5Vda85pVqxuFa X-Received: by 2002:a6b:5918:: with SMTP id n24mr6322726iob.108.1632188870583; Mon, 20 Sep 2021 18:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188870; cv=none; d=google.com; s=arc-20160816; b=JnL3BmH9RatFKAEdcLDJ89JZfORxhNnr3qyaZyA9bGQHo+SvGfVJ8oJ9DjQ5GXcy79 YlcVQoTh+Eg+f6RoLcU6fm6hfDHUwl6q45RwD+OaAUpO6rK50mgz09M0vTuYQgNJJ6BC VnXWfoY2JEc0wPZpZWsCKYQiAGdNf9RTj3feNzfYgIy/umTv7nDmY/LE22QNh9aPNqyh 15pjNVTBjpIxeVmab/nOFEmX4hLo61hQiiUgSK0fHbNOmQ/J4UyhlIAO1mhTUwsXGN7n YcjMpu02Gpe5PlbstDKcs3yGUPnsheELNGyYpoZZGHaDn3c2CbvEGJ1i7nAmg7CluA3h jhMA== 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=atNqXw07hxhsawSxGb8RxLHOROWRB0pufZB1+2yzaM8=; b=tjXNwL8qC4yh40JhfV47JkN/4HQUzDf03mv4ZfnOxAkLnig9FZaM4yMw0CWMBlWZqp 0i5QN0xz79Nr4z/8kr2SuERw6IPJ09865qDYLWiSud+g239VH4P7PD9AI6cPpIKc+EU1 rJtk2LWoPbD6bze+MywrGQIFDAeqaCywiI/G05WJf5RT3AjyqdH+n2RLV6np6Ls2ID16 xlClUmWfpzKw1TPXRIN2BMV336pNNG1GJAmCzTmNfIluJDhk+RSAQh+mSK2dv+wEaGpV bJtbLA2XOjFxZ/dxvyuOrsFNqwowRVnccvE52XOTRFF3WzxYoegQxz7Nukud6xV7hUZJ qOPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QrqftarU; 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 i12si13202849jaf.41.2021.09.20.18.47.38; Mon, 20 Sep 2021 18:47:50 -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=QrqftarU; 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 S1347878AbhITRgd (ORCPT + 99 others); Mon, 20 Sep 2021 13:36:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:40476 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351511AbhITReQ (ORCPT ); Mon, 20 Sep 2021 13:34:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 40D3861371; Mon, 20 Sep 2021 17:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157539; bh=lDFGd8wpY728jByum1SEv9lNvXopa5/+pnFqTaQx1FU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QrqftarUc4TOZRKVEYX12YZb99a5wH4zG46V4rb0LVM/+3H9R0xsFOpmXWnl6zwfA ivFbEwfOjNaqTg0H0theYGHArQCxZPAjh69o/3NE3hpXH0WRdU7OIiNRUBm4RjvQRi Hcg7T4H8ifVVtPi7rK1qi2E/khX1KHEPC7/ymh0I= 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 4.19 008/293] perf/x86/amd/ibs: Work around erratum #1197 Date: Mon, 20 Sep 2021 18:39:30 +0200 Message-Id: <20210920163933.542738778@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@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 2410bd4bb48f..2d9e1372b070 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; @@ -674,6 +675,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; } @@ -767,6 +772,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