From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796441668; b=v4yW5dHMV7q/i50vl2YJieXe7Fsg/gsSAhZn9gwEJXjB3KW6TcmDNv8qnQ1+5MbH9vqR 0w/pGSFaAePl3RH5p+MrGNx7Ne7j0frkxMX58EPYVU8tlO6V5UcjlB2kAxALAec30X4/K oIMhEwXiWW2ryws2g12I8jqej3znqRiOhvWH+uTPJ0q5wFMF4PwNXuKq2X6VlFgo23N1E vEsW0fCJlJazO8x0n3Xfm9qWqPKnGZfzdXvuiV7wBpau9hsOVRulbPfp8BHcXiH/ig4wB M6PFOCwuk355QOmXWabrJ1jhv7osIqT/lvcoVSX83zJHWKQTqg29YHiZMz0TtMLCdIw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796441668; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=M/98FoaYcSWYqTrHMq27JTRKhihsG5fw7rFVbkrFZUY=; b=zznzIzsfUXDCCNWsUAhnFAwLV1l9+l8lgK4PfJ9YQdb+4zl9/9dJQTfcBFgX+a56z2RV ll4R33SyBpsyKr/4JEsdrPx0cr49No4c1pWYj7zFsR8TUZdbOjo07MBZEoyAGBhU0Q15u IZ0DmVHJRk7s8rlgryBYv0PweU1JvAos4AVBNCb5QyAjBCw8wLtfeqjafHzPmJtJdJ4wK ItD3H3sIQFXrxW7KibZkhWuvEp7JLU5ZCE4h+Y7ZErtEugzMdPHjoKwKFrS2yC5g602Lc JvTlSYl/W1xXnRJYWZ8tCnqyYwIaCG1hOmAWKNPZUuvQnwXM/+RkIs8vknmc4c4fioA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=nB+iWyPR; arc=none smtp.remote-ip=192.198.163.17 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A516606A322; Sat, 5 Dec 2026 03:34:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1A516606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=nB+iWyPR DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796441668; x=1827977668; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=M/98FoaYcSWYqTrHMq27JTRKhihsG5fw7rFVbkrFZUY=; b=nB+iWyPRTpPMtMWXmdjSQ4dhHfFJs/q5M/1VD0P0qNL14FEjd4GqofxZ BRakA/eNei6EJX4GU07KXvtMxfJrhNzOJfGqe1bUCutxhgJBphjoZt+vI wcZCyvg9Zpch8B5SqBmrH9XXghzRQtXdlwqyDsNu4S1SA5NQslQc3m5Kh yH/48gT5eHlGNKwpDRW85omW8nOkg3dSOdCsNu1QJpQGvEaLEH8VfHZhk TOxe4c4w2bNkFcqhB9xnw+OGy5asFwy/MRiiAtm9cS+KaBNnGYXTY+4U9 S5OHfzs2ae3prHMp87S9hs9IyOaq/SpNleucfyKTNt4Jqk7UPX771YPQk w==; X-CSE-ConnectionGUID: 5VhJ3ttDTh6XIb4/D6BWIg== X-CSE-MsgGUID: toxCKuFwTU2S/Ts3QPrisw== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5439689" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5439689" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 19:34:27 -0800 X-CSE-ConnectionGUID: NB+WuLVHRR6w2Kz4/QEobg== X-CSE-MsgGUID: CMEgt/MqQJmICO62PKuVBw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14787676" Received: from 9cc2c43eec6b.jf.intel.com ([10.54.77.29]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 19:34:26 -0800 From: Zide Chen To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Adrian Hunter , Alexander Shishkin , Andi Kleen , Eranian Stephane Cc: Chun-Tse Shao , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Dapeng Mi , Zide Chen Subject: [PATCH 00/12] perf/x86/intel/uncore: Fix 64-bit counter config Date: Fri, 4 Dec 2026 20:22:41 -0700 Message-ID: <20261205032253.258646-1-zide.chen@intel.com> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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