Linux Perf Users
 help / color / mirror / Atom feed
From: Zide Chen <zide.chen@intel.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	Eranian Stephane <eranian@google.com>
Cc: Chun-Tse Shao <ctshao@google.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Dapeng Mi <dapeng1.mi@linux.intel.com>,
	Zide Chen <zide.chen@intel.com>
Subject: [PATCH 00/12] perf/x86/intel/uncore: Fix 64-bit counter config
Date: Fri,  4 Dec 2026 20:22:41 -0700	[thread overview]
Message-ID: <20261205032253.258646-1-zide.chen@intel.com> (raw)

Problem statements
==================

Several functional bugs, counter clobbering, and register truncation
issues affect Intel uncore PMU drivers across multiple server platforms:

- On DMR, all MMIO counter control registers have an 8-byte stride and
  64-bit layout, but lacked both 8-byte stride flag and 64-bit ops.
  Consequently, programming counter 1 at offset +4 clobbered counter 0,
  while config bits above bit 31 were silently truncated.

- On SKX, SNR, and ICX, PCI uncore ops only wrote the lower 32 bits,
  silently dropping extended umasks on enable and leaving them
  uncleared on disable.

- On SPR/EMR/GNR/SRF, IMC and HBM types erroneously inherited
  SPR_UNCORE_COMMON_FORMAT(), exposing non-existent extended umask bits
  32-55 in the sysfs format ABI.

- On DMR, the IMC threshold format was defined as "config:23-32",
  overlapping bit 23 (inv) and lacking event_mask_ext, which caused
  bit 32 to be truncated.

- Additionally, PCU filter band mask calculation on HSW-EP and SNR
  truncated upper bands and overflowed.

Solutions
=========

Historically, Intel MMIO and PCI uncore counter control registers
defaulted to 32-bit with a 4-byte stride, while 64-bit handling and
8-byte strides were added ad-hoc via custom per-box flags
(UNCORE_BOX_FLAG_CTL_OFFS8) and customized callbacks.

This series addresses these issues by handling 64-bit counter control
registers in a generic, unified way, anticipating that modern and
future platforms will increasingly support an 8-byte stride and 64-bit
layout by default.

Move stride tracking to where the property naturally belongs: replace
the UNCORE_BOX_FLAG_CTL_OFFS8 flag in struct intel_uncore_box with a
1-bit ctl_offs8 field in struct intel_uncore_type, and apply it to all
DMR MMIO types.

Handle fixed counters in generic discovery MMIO ops, allowing
spr_uncore_mmio_ops to be dropped. Audit and correct event formats and
event_mask_ext across platforms: narrow SPR/EMR/GNR/SRF IMC and HBM
event formats to skx_uncore_format_group without event_mask_ext, and
fix DMR IMC threshold format range to "config:24-32" with
DMR_IMC_EVENT_MASK_EXT.

Handle 64-bit control registers in generic MMIO/PCI and SNB-EP PCI ops,
gated by uncore_box_has_ext_event_ctl() to protect 4-byte stride units.
This allows redundant custom ops to be dropped:
- SPR uncore PCI types (spr_uncore_m2m, spr_uncore_upi) switch to
  exported intel_generic_uncore_pci_ops, dropping spr_uncore_pci_ops.
- SKX, SNR, and ICX PCI types switch to ivbep_uncore_pci_ops:
  snr_uncore_pcie3 corrects a write-ordering defect, while the
  remaining 5 types (skx_uncore_upi, skx_uncore_m2m, snr_uncore_m2m,
  icx_uncore_m2m, icx_uncore_upi) drop redundant custom ops and
  custom init callbacks.

Patch Series Summary
====================

- Patches 01-02 (Miscellaneous fixes):
  Note: Patch 2 is not strictly related to 64-bit handling, but is
  included here so that SKX, SNR and ICX PCI ops can be dropped.

- Patches 03-04 (8-byte stride):
  Convert UNCORE_BOX_FLAG_CTL_OFFS8 to a type flag and apply 8-byte
  control stride to all DMR MMIO uncore types.

- Patch 06 (event_mask_ext):
  Narrow SPR/EMR/GNR/SRF IMC and HBM event formats and drop
  event_mask_ext. (Placed after Patch 05 to avoid temporary .ops
  assignments.)

- Patches 05, 07-11 (intel_uncore_ops):
  Handle 64-bit control registers in generic MMIO/PCI and SNB-EP PCI
  ops, and drop redundant custom ops.

- Patch 12 (event_mask_ext):
  Fix DMR IMC threshold format. This patch is placed after Patch 07 so
  that bit 32 can be programmed, preserving bisectability.

Tests
=====

Extensively tested on DMR, SPR, GNR, ICX, CLX, HSW, SNR, SRF, covering
64-bit control writes, 8-byte and 4-byte strides, sysfs format
compliance. Confirmed bug fixes and observed no regressions. For example:

1. DMR 8-byte stride multi-counter concurrency (Patches 03, 04):
   # perf stat -a -e '{uncore_imc_0/event=0x04,umask=0xc5/,uncore_imc_0/event=0x04,umask=0xca/}' -- sleep 1
   - Without series: Counter 1 was clobbered and read all 0.

2. DMR IMC threshold format narrowing & inv separation (Patch 12):
   # perf stat -a -e uncore_imc_0/event=0x04,umask=0xc5,thresh=512/ -- sleep 1
   - Without series: Format was config:23-32; perf accepted invalid
     thresh=512.
   - With series: Format is config:24-32; perf strictly rejects
     thresh > 511.

3. ICX M2M extended umask request filtering (Patches 09, 11):
   # perf stat -a -e uncore_m2m_0/event=0x37,umask=0x0701/ -- sleep 1
   # perf stat -a -e uncore_m2m_0/event=0x38,umask=0x1c01/ -- sleep 1
   - Without series: Upper dword dropped; events read 0.

4. SPR/EMR/GNR/SRF IMC sysfs format narrowing & ABI compliance (Patch 06):
   # perf stat -a -e uncore_imc_0/event=0x05,umask=0x0100/ -- sleep 1
   - Without series: Format was config:8-15,32-55; accepted umask > 255.
   - With series: Format is config:8-15; perf rejects umask > 255.

5. DMR Programming upper dword on MMIO boxes (Patch 07):
   # perf stat -a -e uncore_otc_0/event=0x15,umask=0x00004ff000/ -- sleep 1
   - Without series: Bits 32+ dropped; DMR OTC counted 0.

6. SPR MMIO fixed counters via GENERIC_PMON_CTL_EN (Patch 05):
   # perf stat -a -e uncore_imc_0/clockticks/ -- sleep 2
   - Expected: No regression.

7. PCI ops consolidation onto ivbep_uncore_pci_ops (Patch 11):
   # perf stat -a -e uncore_upi_0/event=0x01,umask=0x00/ -e uncore_m2m_0/event=0x01,umask=0x00/ -- sleep 1 (CLX)
   # perf stat -a -e uncore_m2m/event=0x01,umask=0x00/ -- sleep 1 (SNR)
   - Expected: No regression.

8. ICX UPI/M3UPI ops consolidation and box control fix (Patches 02, 11):
   # perf stat -a -e uncore_upi_0/event=0x01,umask=0x00/ -e uncore_m3upi_0/event=0x01,umask=0x00/ -- sleep 1
   - Expected: No regression.

Notes
=====

There are more Intel uncore fixes in the pipeline:
- Miscellaneous bug fixes: Addresses hardware quirks and constraint
  bugs, as well as out-of-bounds reads and NULL dereferences.
- Memory leak and device lifecycle fixes: Resolves dynamic uncore type
  leaks on module unload, a use-after-free race on PCI device removal,
  and other lifecycle issues.
- Code cleanup: Deduplicates repetitive sysfs event format attributes
  and bitmasks across client and server uncore drivers.

Zide Chen (12):
  perf/x86/intel/uncore: Fix PCU filter band mask calculation
  perf/x86/intel/uncore: Fix ICX UPI and M3UPI box control offset
  perf/x86/intel/uncore: Replace CTL_OFFS8 box flag with type flag
  perf/x86/intel/uncore: Fix DMR MMIO counter control stride
  perf/x86/intel/uncore: Drop spr_uncore_mmio_ops for generic MMIO
  perf/x86/intel/uncore: Fix SPR/EMR/GNR/SRF IMC and HBM event formats
  perf/x86/intel/uncore: Program upper dword in generic ops
  perf/x86/intel/uncore: Drop spr_uncore_pci_ops for generic PCI
  perf/x86/intel/uncore: Fix SKX/SNR/ICX PCI extended umask truncation
  perf/x86/intel/uncore: Program SNR PCIe3 upper filter before enable
  perf/x86/intel/uncore: Consolidate SKX, SNR and ICX PCI uncore ops
  perf/x86/intel/uncore: Fix DMR IMC threshold field

 arch/x86/events/intel/uncore.h           |  53 +++++-
 arch/x86/events/intel/uncore_discovery.c |  25 ++-
 arch/x86/events/intel/uncore_discovery.h |   2 +
 arch/x86/events/intel/uncore_snbep.c     | 201 +++++------------------
 4 files changed, 108 insertions(+), 173 deletions(-)

base-commit: 86a52e8d105ff74d5fa8c1694df53aa026f7dd62

--
2.56.1


             reply	other threads:[~2026-12-05  3:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  3:22 Zide Chen [this message]
2026-12-05  3:22 ` [PATCH 01/12] perf/x86/intel/uncore: Fix PCU filter band mask calculation Zide Chen
2026-12-05  3:22 ` [PATCH 02/12] perf/x86/intel/uncore: Fix ICX UPI and M3UPI box control offset Zide Chen
2026-12-05  3:22 ` [PATCH 03/12] perf/x86/intel/uncore: Replace CTL_OFFS8 box flag with type flag Zide Chen
2026-12-05  3:22 ` [PATCH 04/12] perf/x86/intel/uncore: Fix DMR MMIO counter control stride Zide Chen
2026-12-05  3:22 ` [PATCH 05/12] perf/x86/intel/uncore: Drop spr_uncore_mmio_ops for generic MMIO Zide Chen
2026-12-05  3:22 ` [PATCH 06/12] perf/x86/intel/uncore: Fix SPR/EMR/GNR/SRF IMC and HBM event formats Zide Chen
2026-12-05  3:49   ` sashiko-bot
2026-12-05  4:41     ` Chen, Zide
2026-12-05  3:22 ` [PATCH 07/12] perf/x86/intel/uncore: Program upper dword in generic ops Zide Chen
2026-12-05  3:22 ` [PATCH 08/12] perf/x86/intel/uncore: Drop spr_uncore_pci_ops for generic PCI Zide Chen
2026-12-05  3:46   ` sashiko-bot
2026-12-05  4:41     ` Chen, Zide
2026-12-05  3:22 ` [PATCH 09/12] perf/x86/intel/uncore: Fix SKX/SNR/ICX PCI extended umask truncation Zide Chen
2026-12-05  3:22 ` [PATCH 10/12] perf/x86/intel/uncore: Program SNR PCIe3 upper filter before enable Zide Chen
2026-12-05  3:22 ` [PATCH 11/12] perf/x86/intel/uncore: Consolidate SKX, SNR and ICX PCI uncore ops Zide Chen
2026-12-05  3:53   ` sashiko-bot
2026-12-05  4:42     ` Chen, Zide
2026-12-05  3:22 ` [PATCH 12/12] perf/x86/intel/uncore: Fix DMR IMC threshold field Zide Chen
2026-12-05  3:54 ` [PATCH 00/12] perf/x86/intel/uncore: Fix 64-bit counter config sashiko-bot

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=20261205032253.258646-1-zide.chen@intel.com \
    --to=zide.chen@intel.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ctshao@google.com \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox