Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp879075ybv; Wed, 19 Feb 2020 11:08:09 -0800 (PST) X-Google-Smtp-Source: APXvYqzV/lnVRSU7x8oZsO5PaHUPvq/HjqjFPDc8pOEjnbSsyPCvltTUIrrqxkElYvZsRHUkxh/x X-Received: by 2002:a9d:7f8d:: with SMTP id t13mr19217340otp.175.1582139289443; Wed, 19 Feb 2020 11:08:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582139289; cv=none; d=google.com; s=arc-20160816; b=iQkIi4u8pphWWUi3cLZf615BgRqvHUQ2lutcllf11aGliLC1T7Iyyl4Ef+PkfSeTXs QYwk0PnkA0bS3P5E89H94bPeT2FHHG5U1fPaHI2CgKj1rZ7RhnEIRbjx+4gBuY1DGbF8 mcrH69LsPNelE3OZnwCrQ+rl4CnUrWW4CVk88VW/mB+DCWYMgOOu8DkXcUzSPke/aWkj v4FzUlYgtd2lOdhP+4TeuagGDzsn1ibnWd/pjeRPQKL20mTwpeljfL1iHW2OIscBautF 5EB1GwkvmCzvLANIrrgv7FZHzawzGzp3A3p1GX4ZO46ZvEjydMQWk8O2ODkaU5w4PkVr cVKA== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=1cYOz4nmloe/Qev+RTxyyqNB+Du/el1JUifxKUmelM4=; b=Hkiu8nqj4Y3Z7YqOXrcxRTmvSurA3GWVcCfjRPtFP8So97Tav0C5Ghs54Pmhpz5KPW FzoRWRxq7DKQtAlYcQjItfV4BmKKYa4J3ilq8CBD4xU/h1h6FWwfucfAKHbJYMoJWWYe MbgS/tTtoFjj3oA9xDkpoBbgf2LhkHeFRRUyzsHDX61gxv3ZvLLzGhXhTOYQDyd78VTV gB8nVM3D+eG0cPqFYVmSKyFWa3kzQHbKKrhmI9SNYrr3SYYJcrBZg6lzMfHW+KWgqnmK khfEjHtA12H9OHNlNto0pz43YsqCEkrBLep73ifMeG6p2xzi8IRr7pjcRqNHPd0qk6VJ 7exw== ARC-Authentication-Results: i=1; mx.google.com; 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 e1si342273otr.8.2020.02.19.11.07.57; Wed, 19 Feb 2020 11:08:09 -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; 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 S1726764AbgBSTHl (ORCPT + 99 others); Wed, 19 Feb 2020 14:07:41 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:39118 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726613AbgBSTHl (ORCPT ); Wed, 19 Feb 2020 14:07:41 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1j4Uh2-0002Ro-UH; Wed, 19 Feb 2020 20:07:33 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 8527C1C20D7; Wed, 19 Feb 2020 20:07:32 +0100 (CET) Date: Wed, 19 Feb 2020 19:07:32 -0000 From: "tip-bot2 for Kim Phillips" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/cpu/amd: Enable the fixed Instructions Retired counter IRPERF Cc: Kim Phillips , Borislav Petkov , Peter Zijlstra , stable@vger.kernel.org, x86 , LKML In-Reply-To: <20200214201805.13830-1-kim.phillips@amd.com> References: <20200214201805.13830-1-kim.phillips@amd.com> MIME-Version: 1.0 Message-ID: <158213925220.13786.9146323471825204537.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 21b5ee59ef18e27d85810584caf1f7ddc705ea83 Gitweb: https://git.kernel.org/tip/21b5ee59ef18e27d85810584caf1f7ddc705ea83 Author: Kim Phillips AuthorDate: Wed, 19 Feb 2020 18:52:43 +01:00 Committer: Borislav Petkov CommitterDate: Wed, 19 Feb 2020 20:01:54 +01:00 x86/cpu/amd: Enable the fixed Instructions Retired counter IRPERF 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 --- arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/kernel/cpu/amd.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index ebe1685..d5e517d 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -512,6 +512,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 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index ac83a0f..1f875fb 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -28,6 +28,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); /* @@ -972,6 +973,15 @@ static void init_amd(struct cpuinfo_x86 *c) /* 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 @@ -1099,6 +1109,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) {