Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp2905698pxb; Mon, 6 Sep 2021 07:58:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6sRY0UiueuTIzyvWrQ7fxdjxmuwdnQ4bHN+ok/7j70gnUmMoffvtTXgW7DmRjpTtvfXWu X-Received: by 2002:a17:907:3393:: with SMTP id zj19mr13520682ejb.535.1630940297653; Mon, 06 Sep 2021 07:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630940297; cv=none; d=google.com; s=arc-20160816; b=XIeZQgHazx24Wjyjl9T6AbZt30AH7HFXbftRtiSxBiohY4KC8+OAVqnUI5zSrjhpEU Peq02OF0ITl6GM2jdiFkKVg5lMDtWffmjZ6s8VBrXXEBL9V2mMEF9ZfKAw2X1PRls5Qy nEyQoohBc2/cv6itQqwXbqwwlf6HqGCmqZU04n8cIf2Or2yx4gK4iC8XVqBmaZoOsWqR hTzWNZ8cOomiYAOXvT4FksnATy/JGx64/kswNBTTsEMm+iiK4fT/Itw69XA1mC6PKIRj n+2Fzs4JHACUvtVUyTddxjF9brdH+AMgK3WT7NRDZNcMRDhagWOfyuXLJKg49N2qK8z/ TZTg== 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=8I/Yu3RpDl84j+1X2X5hMKWxKNi27zSWbDGmdQCZYp8=; b=F3m85YCzrp2F1ppIDH5QrWF7zQym/ASQ+aHTjGTTJOe+u+VB7p3YVnaZgPoVL8B6Qc uitK/Wo5Ml2hYvhXBfLQuZS3HppR9QF7TMy0TgzTwn1aTf5fm8ZT7xRwBjiH3lPuRowO lqM3Draf7FrY5obLM7bqKw0+cekSm5gXXuZ9i5OvqmOUS8Zo5tMtbF/S9lGyo8PIgWl3 w+1XM70jCfH+lDQF1W3/aTL98p2JgX3nlj/HVDvvx2HOs5CbMEgj+siQ7RARaBbBxW1B NfZp1zKR+IlN+gJEfslY2S3j6dvPUgYbkfxPVPypRrjEULNgDLR5SAOin10Sq1zWLJcY u4hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wBBkjn4L; 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 l20si7694250ejn.131.2021.09.06.07.57.41; Mon, 06 Sep 2021 07:58:17 -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=wBBkjn4L; 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 S242942AbhIFM7Q (ORCPT + 99 others); Mon, 6 Sep 2021 08:59:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:34572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242819AbhIFM6l (ORCPT ); Mon, 6 Sep 2021 08:58:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D9D216103E; Mon, 6 Sep 2021 12:57:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1630933056; bh=tdjlYTaRlUajVrYooywOn6HHZajWtuu8PEPU3aqSCnM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wBBkjn4LOH1vVUq+s6OUbMQFLu5ADSiB+MRcPgT3JfGt7uWjf+WBGOLSvKvYHxgZE PM0zPLDwoVtLj8udbh7bi9xUMu3E28Jlp/mA8gDio7hhXfSjVS9tGr35tZGtIe7m7z JtGVFcZ1f7jK7Bo1bvOwQWtssfEJEcnkTUQt6a0M= 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.13 13/24] perf/x86/amd/ibs: Work around erratum #1197 Date: Mon, 6 Sep 2021 14:55:42 +0200 Message-Id: <20210906125449.557513018@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210906125449.112564040@linuxfoundation.org> References: <20210906125449.112564040@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 40669eac9d6d..921f47b9bb24 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; @@ -672,6 +673,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; } @@ -769,6 +774,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