Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1189103ybf; Thu, 27 Feb 2020 06:32:50 -0800 (PST) X-Google-Smtp-Source: APXvYqzrJ9U5F3pfmIo6QiPQntOjOLUVExDT5GRf2xdaLwxNxKXSr5RQxoA9QBRGKwEcSPms+w2g X-Received: by 2002:a05:6830:10da:: with SMTP id z26mr3399415oto.27.1582813969371; Thu, 27 Feb 2020 06:32:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582813969; cv=none; d=google.com; s=arc-20160816; b=xJDYhrslsL/QsueSYkY4+9yzAYm+kWPodWiJ5Lc6PKGfawCfmKOogPaNwjXMCO3M43 xiPSIiTBPlFZ6zbqr0edee/kpB5ukDyv0DV2ZeFs2frweibSBt2EZJNGwzaSintL6OXM YR+Z2SuSP/rhqXJ6g1NhyjswIINKfbRjIEt9rwNkI8RVf5D0h2g2NMCoD43ecUkQct32 O5Z97N7/b3vlhVqR4C2Wh+AG3HWLBum0R55PULfIdQibCkjl8sYmZYzjjaQrxSu8KZ/U Hpv7xfyMHpC9Y2lt5dVlQUvhLXEq8aujLUVmPQkIkYcpmhlXVeLptP9Qs7t1Lo5/iL+/ Uh4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=a44PRZwvXdV5sdMFdKxYCME6YgaRaSbNIUk1eU5plU0=; b=ZAqDdUkCbvZi8lQ7N/W8U8xbPRLasGylXFVqBGF5X4BVjDX7jrOz2BDFX2fwI/VHQB xJurY8mRQ4hbm2rPru3xabkHzrdBI7ApHqvvZTm2RroQSQ8Hkhe631w31DLwL6qtTv/H j5TSolgB6oEb8v+B9744akjLkZSw6mmHzOXLRZmWIgqleG8MJjZy5K68yvXYsRfoZrKy zc9BWTWcxWuxCOIvMpFrYdqb8q2Wwclpr43ulshCscN5U5rm4E/XvfPp09EKRXM/MfAF 2hn7LGF+1C1TRRDykFPId4pASIDAyiIccs8FmUSyNXIendoYxdaSz183jpIuCK2Tok4d qg0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RsDgClC6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t7si1250024oij.175.2020.02.27.06.32.36; Thu, 27 Feb 2020 06:32:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RsDgClC6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387732AbgB0ObT (ORCPT + 99 others); Thu, 27 Feb 2020 09:31:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:39906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387516AbgB0OEE (ORCPT ); Thu, 27 Feb 2020 09:04:04 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9FE8F20578; Thu, 27 Feb 2020 14:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812242; bh=nFipeVugtVswHfpnVxsrrfKfmR2Tjq+wQ2MwbxCg2TU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RsDgClC6xLCQ7U0vAc2A9lQfFwr8jnFOZik9ddhIPVoqWg/lvv3KvwQyDsuaKUd6C M8Drdtw1PlUv5pRdyb9/ekZi77aLDJyGlhn2lCw65cb4Elwskhi3p4QV4QyCSB5eZc 0lMTGCgndi8E91OeL+J8Ql9pwTtwnG7H0PrRjmAI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kim Phillips , Borislav Petkov , Peter Zijlstra Subject: [PATCH 4.19 39/97] x86/cpu/amd: Enable the fixed Instructions Retired counter IRPERF Date: Thu, 27 Feb 2020 14:36:47 +0100 Message-Id: <20200227132220.935540589@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132214.553656188@linuxfoundation.org> References: <20200227132214.553656188@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kim Phillips commit 21b5ee59ef18e27d85810584caf1f7ddc705ea83 upstream. Commit aaf248848db50 ("perf/x86/msr: Add AMD IRPERF (Instructions Retired) performance counter") added support for access to the free-running counter via 'perf -e msr/irperf/', but when exercised, it always returns a 0 count: BEFORE: $ perf stat -e instructions,msr/irperf/ true Performance counter stats for 'true': 624,833 instructions 0 msr/irperf/ Simply set its enable bit - HWCR bit 30 - to make it start counting. Enablement is restricted to all machines advertising IRPERF capability, except those susceptible to an erratum that makes the IRPERF return bad values. That erratum occurs in Family 17h models 00-1fh [1], but not in F17h models 20h and above [2]. AFTER (on a family 17h model 31h machine): $ perf stat -e instructions,msr/irperf/ true Performance counter stats for 'true': 621,690 instructions 622,490 msr/irperf/ [1] Revision Guide for AMD Family 17h Models 00h-0Fh Processors [2] Revision Guide for AMD Family 17h Models 30h-3Fh Processors The revision guides are available from the bugzilla Link below. [ bp: Massage commit message. ] Fixes: aaf248848db50 ("perf/x86/msr: Add AMD IRPERF (Instructions Retired) performance counter") Signed-off-by: Kim Phillips Signed-off-by: Borislav Petkov Cc: Peter Zijlstra Cc: stable@vger.kernel.org Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537 Link: http://lkml.kernel.org/r/20200214201805.13830-1-kim.phillips@amd.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/kernel/cpu/amd.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -455,6 +455,8 @@ #define MSR_K7_HWCR 0xc0010015 #define MSR_K7_HWCR_SMMLOCK_BIT 0 #define MSR_K7_HWCR_SMMLOCK BIT_ULL(MSR_K7_HWCR_SMMLOCK_BIT) +#define MSR_K7_HWCR_IRPERF_EN_BIT 30 +#define MSR_K7_HWCR_IRPERF_EN BIT_ULL(MSR_K7_HWCR_IRPERF_EN_BIT) #define MSR_K7_FID_VID_CTL 0xc0010041 #define MSR_K7_FID_VID_STATUS 0xc0010042 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -25,6 +25,7 @@ static const int amd_erratum_383[]; static const int amd_erratum_400[]; +static const int amd_erratum_1054[]; static bool cpu_has_amd_erratum(struct cpuinfo_x86 *cpu, const int *erratum); /* @@ -983,6 +984,15 @@ static void init_amd(struct cpuinfo_x86 /* AMD CPUs don't reset SS attributes on SYSRET, Xen does. */ if (!cpu_has(c, X86_FEATURE_XENPV)) set_cpu_bug(c, X86_BUG_SYSRET_SS_ATTRS); + + /* + * Turn on the Instructions Retired free counter on machines not + * susceptible to erratum #1054 "Instructions Retired Performance + * Counter May Be Inaccurate". + */ + if (cpu_has(c, X86_FEATURE_IRPERF) && + !cpu_has_amd_erratum(c, amd_erratum_1054)) + msr_set_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT); } #ifdef CONFIG_X86_32 @@ -1110,6 +1120,10 @@ static const int amd_erratum_400[] = static const int amd_erratum_383[] = AMD_OSVW_ERRATUM(3, AMD_MODEL_RANGE(0x10, 0, 0, 0xff, 0xf)); +/* #1054: Instructions Retired Performance Counter May Be Inaccurate */ +static const int amd_erratum_1054[] = + AMD_OSVW_ERRATUM(0, AMD_MODEL_RANGE(0x17, 0, 0, 0x2f, 0xf)); + static bool cpu_has_amd_erratum(struct cpuinfo_x86 *cpu, const int *erratum) {