All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Kim Phillips <kim.phillips@amd.com>,
	Borislav Petkov <bp@suse.de>,
	Peter Zijlstra <peterz@infradead.org>
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	[thread overview]
Message-ID: <20200227132220.935540589@linuxfoundation.org> (raw)
In-Reply-To: <20200227132214.553656188@linuxfoundation.org>

From: Kim Phillips <kim.phillips@amd.com>

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 <kim.phillips@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
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 <gregkh@linuxfoundation.org>

---
 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)
 {



  parent reply	other threads:[~2020-02-27 14:31 UTC|newest]

Thread overview: 109+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-27 13:36 [PATCH 4.19 00/97] 4.19.107-stable review Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 01/97] iommu/qcom: Fix bogus detach logic Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 02/97] ALSA: hda: Use scnprintf() for printing texts for sysfs/procfs Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 03/97] ALSA: hda/realtek - Apply quirk for MSI GP63, too Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 04/97] ALSA: hda/realtek - Apply quirk for yet another MSI laptop Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 05/97] ASoC: sun8i-codec: Fix setting DAI data format Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 06/97] ecryptfs: fix a memory leak bug in parse_tag_1_packet() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 07/97] ecryptfs: fix a memory leak bug in ecryptfs_init_messaging() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 08/97] thunderbolt: Prevent crash if non-active NVMem file is read Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 09/97] USB: misc: iowarrior: add support for 2 OEMed devices Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 10/97] USB: misc: iowarrior: add support for the 28 and 28L devices Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 11/97] USB: misc: iowarrior: add support for the 100 device Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 12/97] floppy: check FDC index for errors before assigning it Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 13/97] vt: fix scrollback flushing on background consoles Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 14/97] vt: selection, handle pending signals in paste_selection Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 15/97] vt: selection, close sel_buffer race Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 16/97] vt: vt_ioctl: fix race in VT_RESIZEX Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 17/97] staging: android: ashmem: Disallow ashmem memory from being remapped Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 18/97] staging: vt6656: fix sign of rx_dbm to bb_pre_ed_rssi Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 19/97] xhci: Force Maximum Packet size for Full-speed bulk devices to valid range Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 20/97] xhci: fix runtime pm enabling for quirky Intel hosts Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 21/97] xhci: Fix memory leak when caching protocol extended capability PSI tables - take 2 Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 22/97] usb: host: xhci: update event ring dequeue pointer on purpose Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 23/97] USB: core: add endpoint-blacklist quirk Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 24/97] USB: quirks: blacklist duplicate ep on Sound Devices USBPre2 Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 25/97] usb: uas: fix a plug & unplug racing Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 26/97] USB: Fix novation SourceControl XL after suspend Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 27/97] USB: hub: Dont record a connect-change event during reset-resume Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 28/97] USB: hub: Fix the broken detection of USB3 device in SMSC hub Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 29/97] usb: dwc2: Fix SET/CLEAR_FEATURE and GET_STATUS flows Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 30/97] usb: dwc3: gadget: Check for IOC/LST bit in TRB->ctrl fields Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 31/97] staging: rtl8188eu: Fix potential security hole Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 32/97] staging: rtl8188eu: Fix potential overuse of kernel memory Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 33/97] staging: rtl8723bs: Fix potential security hole Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 34/97] staging: rtl8723bs: Fix potential overuse of kernel memory Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 35/97] powerpc/tm: Fix clearing MSR[TS] in current when reclaiming on signal delivery Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 36/97] jbd2: fix ocfs2 corrupt when clearing block group bits Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 37/97] x86/mce/amd: Publish the bank pointer only after setup has succeeded Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 38/97] x86/mce/amd: Fix kobject lifetime Greg Kroah-Hartman
2020-02-27 13:36 ` Greg Kroah-Hartman [this message]
2020-02-27 13:36 ` [PATCH 4.19 40/97] serial: 8250: Check UPF_IRQ_SHARED in advance Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 41/97] tty/serial: atmel: manage shutdown in case of RS485 or ISO7816 mode Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 42/97] tty: serial: imx: setup the correct sg entry for tx dma Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 43/97] serdev: ttyport: restore client ops on deregistration Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 44/97] MAINTAINERS: Update drm/i915 bug filing URL Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 45/97] Revert "ipc,sem: remove uneeded sem_undo_list lock usage in exit_sem()" Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 46/97] mm/memcontrol.c: lost css_put in memcg_expand_shrinker_maps() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 47/97] nvme-multipath: Fix memory leak with ana_log_buf Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 48/97] genirq/irqdomain: Make sure all irq domain flags are distinct Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 49/97] mm/vmscan.c: dont round up scan size for online memory cgroup Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 50/97] drm/amdgpu/soc15: fix xclk for raven Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.19 51/97] xhci: apply XHCI_PME_STUCK_QUIRK to Intel Comet Lake platforms Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 52/97] KVM: nVMX: Dont emulate instructions in guest mode Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 53/97] KVM: x86: dont notify userspace IOAPIC on edge-triggered interrupt EOI Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 54/97] tty: serial: qcom_geni_serial: Fix UART hang Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 55/97] tty: serial: qcom_geni_serial: Remove interrupt storm Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 56/97] tty: serial: qcom_geni_serial: Remove use of *_relaxed() and mb() Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 57/97] tty: serial: qcom_geni_serial: Remove set_rfr_wm() and related variables Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 58/97] tty: serial: qcom_geni_serial: Remove xfer_mode variable Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 59/97] tty: serial: qcom_geni_serial: Fix RX cancel command failure Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 60/97] lib/stackdepot: Fix outdated comments Greg Kroah-Hartman
2020-02-28 13:05   ` Pavel Machek
2020-02-28 13:24     ` Greg Kroah-Hartman
2020-02-28 13:30       ` Greg Kroah-Hartman
2020-02-28 18:05         ` Sasha Levin
2020-02-27 13:37 ` [PATCH 4.19 61/97] lib/stackdepot.c: fix global out-of-bounds in stack_slabs Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 62/97] drm/nouveau/kms/gv100-: Re-set LUT after clearing for modesets Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 63/97] ext4: fix a data race in EXT4_I(inode)->i_disksize Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 64/97] ext4: add cond_resched() to __ext4_find_entry() Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 65/97] ext4: fix potential race between online resizing and write operations Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 66/97] ext4: fix potential race between s_group_info online resizing and access Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 67/97] ext4: fix potential race between s_flex_groups " Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 68/97] ext4: fix mount failure with quota configured as module Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 69/97] ext4: rename s_journal_flag_rwsem to s_writepages_rwsem Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 70/97] ext4: fix race between writepages and enabling EXT4_EXTENTS_FL Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 71/97] KVM: nVMX: Refactor IO bitmap checks into helper function Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 72/97] KVM: nVMX: Check IO instruction VM-exit conditions Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 73/97] KVM: nVMX: handle nested posted interrupts when apicv is disabled for L1 Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 74/97] KVM: apic: avoid calculating pending eoi from an uninitialized val Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 75/97] btrfs: fix bytes_may_use underflow in prealloc error condtition Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 76/97] btrfs: reset fs_root to NULL on error in open_ctree Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 77/97] btrfs: do not check delayed items are empty for single transaction cleanup Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 78/97] Btrfs: fix btrfs_wait_ordered_range() so that it waits for all ordered extents Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 79/97] Revert "dmaengine: imx-sdma: Fix memory leak" Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 80/97] scsi: Revert "RDMA/isert: Fix a recently introduced regression related to logout" Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 81/97] scsi: Revert "target: iscsi: Wait for all commands to finish before freeing a session" Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 82/97] usb: gadget: composite: Fix bMaxPower for SuperSpeedPlus Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 83/97] usb: dwc2: Fix in ISOC request length checking Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 84/97] staging: rtl8723bs: fix copy of overlapping memory Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 85/97] staging: greybus: use after free in gb_audio_manager_remove_all() Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 86/97] ecryptfs: replace BUG_ON with error handling code Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 87/97] iommu/vt-d: Fix compile warning from intel-svm.h Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 88/97] genirq/proc: Reject invalid affinity masks (again) Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 89/97] bpf, offload: Replace bitwise AND by logical AND in bpf_prog_offload_info_fill Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 90/97] ALSA: rawmidi: Avoid bit fields for state flags Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 91/97] ALSA: seq: Avoid concurrent access to queue flags Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 92/97] ALSA: seq: Fix concurrent access to queue current tick/time Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 93/97] netfilter: xt_hashlimit: limit the max size of hashtable Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 94/97] rxrpc: Fix call RCU cleanup using non-bh-safe locks Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 95/97] ata: ahci: Add shutdown to freeze hardware resources of ahci Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 96/97] xen: Enable interrupts when calling _cond_resched() Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.19 97/97] s390/mm: Explicitly compare PAGE_DEFAULT_KEY against zero in storage_key_init_range Greg Kroah-Hartman
2020-02-27 15:51 ` [PATCH 4.19 00/97] 4.19.107-stable review Chris Paterson
2020-02-28 13:51   ` Greg Kroah-Hartman
     [not found] ` <20200227132214.553656188-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
2020-02-27 18:52   ` Jon Hunter
2020-02-27 18:52     ` Jon Hunter
2020-02-27 19:41 ` Guenter Roeck
2020-02-28  3:35 ` Naresh Kamboju
2020-02-28  3:39 ` shuah

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200227132220.935540589@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=bp@suse.de \
    --cc=kim.phillips@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.