From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796085914; b=iZIHm8YgcR6hpPVxNZflqyb+if1+sH26Ab6QNIqcFLtRpuG9O6dagonjv6iQ7lJgOu9O UpyZUSEVNe8RLtXBx0Z/No20LjwmUAH0bAc+7qvD71Y7NPdx5iCzEFtXp3JvVqTFuCuzI OqJ+GVVePkenKOQuhKN1laSVlXffIKOjuGOAJODMZuhTLZxiZrf3AUoevVSxE7QVVcCjP +1jh+kb6lMQaR4IiZivVyDfZwoaiIMeDuMzkbHsZcFKjjpZHsmCjsdg6D+Pdi6WCo9cyj uY2b9xicjBAuquv/phA8cJRhiW63CRKWPJSwIzyIYnhN8GuAPK8D40zkAZJWL6i0ZJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796085914; 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=AAUDXVFIWm4OucFHHagSl9cUqSeaxRZ8XoNa0JtJ+Vg=; b=K1d7aicaf5i0Bhh1SwMTMDWNKuO2X6LjyOAOX4AvEdZTcShv39ExTfkKY3PEKo5AAbsM S5oxe4GLey1gt1XcYmqXw2ijgVjwiddZ2VxfhNZdIDXBCR3xZsR5PE3zokmgCthSJOGTQ IlFPp/6+v/3J8W34mjusslGXbY6R2nWMONVr6KgQVrHV90V2kVUNLGzCQWXP7obPoXUI1 APZMeJ3yrcBtptDKzsMP/UNc1NVecZbXBRP16deKiWCRQq9Au+eCx3/tsTwa6mY8KTmNg bQ+qhje4R+SYT/qviFLfw+UO4loNdcyVJ4uC2xONcqu1JOMQkiotQhYhjBDx6/YV/qA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=NAy4k2HY; arc=none smtp.remote-ip=198.175.65.9 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 9FCAC606A31A; Tue, 1 Dec 2026 00:45:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9FCAC606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=NAy4k2HY DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796085914; x=1827621914; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=AAUDXVFIWm4OucFHHagSl9cUqSeaxRZ8XoNa0JtJ+Vg=; b=NAy4k2HY8C+4x1jN8bXiJZxiwbTAwNhOU+GmHBUiQFnrFqqnBjp3IUON yYfwzmkH0++xgBe1VTqb2iC4Ft02ihBKbdi4iIkeFOjHBxqYkJ4WL1cp+ bOsn5HXOaayFrs/tPqJEoEZOdFz7UzJX7+5wN37zuEpocZV4eC/U3WgtJ kfEK2j3DqeSKfuRlsOC1bVIBREoxZRkpRAp7Quxp4NeaWtWcPxQD1MbTX KFFGlLKG2f9rUoEjvndw1XObl6KgOzjgCtFrdtNoCkqEMoTUBCx3WtFzB QhOSx+BFf/9CV//xzzuUWqTE+iBaVfZs6vIeE5+tUM2xgeuZa6ydGNr9R Q==; X-CSE-ConnectionGUID: bBQUAkyiSiuJe9lRwRkNmA== X-CSE-MsgGUID: v4uG8Qk7TyediOQfWCLDTQ== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4845868" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4845868" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 16:45:14 -0800 X-CSE-ConnectionGUID: CcCMXRsGTTGQzD9wH8W3jg== X-CSE-MsgGUID: ZtKuds/FR0WUP48riTHhlw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13678307" Received: from spr.sh.intel.com ([10.112.229.196]) by fmviesa010.fm.intel.com with ESMTP; 30 Nov 2026 16:45:07 -0800 From: Dapeng Mi To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Adrian Hunter , Alexander Shishkin , Andi Kleen , Eranian Stephane Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Dapeng Mi , Zide Chen , Falcon Thomas , Xudong Hao , Dapeng Mi Subject: [Patch v2 00/16] perf/x86/intel: Fix multiple sampling and PEBS bugs (Part I) Date: Tue, 1 Dec 2026 08:36:52 +0800 Message-Id: <20261201003708.1806748-1-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-kernel@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 This series resolves several recently discovered sampling issues, alongside a few potential bugs highlighted during the Sashiko review. - Missing validation for 'bts_active' prior to handling BTS events, which could lead to kernel crashes. - A lockdep warning regarding a missing 'ctx->mutex' hold during LBR counter event initialization. - PEBS sampling failures following CPU offline/online transitions on both legacy PEBS and arch-PEBS. - Missing calls to x86_pmu_update_perf_regs() on multiple PEBS/IRQ error paths, presenting a risk of out-of-bounds memory accesses during SIMD register sampling. - Stale or incorrect counts reported by PEBS events on platforms lacking counter snapshot support. - Incorrect count and sample period calculations for non-auto-reload PEBS events (typically used in sample frequency mode) on arch-PEBS. Patch Layout: - Patches 01-02: Ensure 'bts_active' is verified before processing BTS events to prevent potential kernel crashes. - Patch 03: Address the lockdep warning triggered by for_each_sibling_event() while iterating LBR counter events. - Patches 04-06: Fix PEBS sampling failures following CPU offline/online transitions on both legacy PEBS and arch-PEBS. - Patches 07-08: Correct two incorrect iteration boundaries in the PEBS buffer drain helpers. - Patches 09-10: Ensure x86_pmu_update_perf_regs() is invoked on all necessary error paths to eliminate the risk of out-of-bounds memory accesses. - Patch 11: Fix stale counts reported by PEBS events without counter snapshot support. - Patch 12: Ensure sample records are output to user space for non-auto-reload events only when the full sample period has elapsed. - Patch 13: Initialize 'arch_pebs_index' to 0 prior to writing the MSR, preventing a potential #GP due to uninitialized reserved bits. - Patch 14: Restrict programming of the ACR reload value to events with non-zero 'config2' fields, avoiding invalid reload values from being written to the matching MSR. - Patches 15-16: Resolve incorrect event count and sample period calculations for non-auto-reload PEBS events on arch-PEBS. Changes: v1 -> v2: - Split the complete patch series into two parts to keep the size of each submission manageable, following the discovery of several additional issues since v1. This series represents Part I (focusing on simpler/foundational fixes). - Addressed newly identified BTS issues. (patches 01-02) - Added missing calls to x86_pmu_update_perf_regs() on multiple error paths to prevent potential out-of-bounds memory accesses. (patches 09-10) - Fixed event count and sample period calculation bugs for non-auto-reload events on arch-PEBS. (patches 15-16) - Applied miscellaneous cleanups to address findings from Sashiko reviews. - Rebased the series onto the latest perf/core branch (targeting 7.4). Tests: - Run perf stats/recording/LBR recording tests on SPR/DMR/NVL platforms, no issue is found. History: v1: https://lore.kernel.org/all/20260928074309.898043-1-dapeng1.mi@linux.intel.com/ Dapeng Mi (16): perf/x86/intel: Reject BTS events when BTS is not active perf/x86/intel: Check if BTS is active before handling BTS interrupt perf/x86/intel: Guard leader sibling walk on nr_siblings perf/x86/intel: Reset active_fixed_ctrl_val on CPU teardown perf/x86/intel: Reset active_pebs_data_cfg on CPU teardown perf/x86/intel: Reset cached acr_cfg_b[] and cfg_c_val[] on CPU teardown perf/x86/intel: Pass correct PEBS counter mask to no-drain update path perf/x86/intel: Limit PEBS counter iteration to valid array bounds perf/x86/intel: Avoid calling perf_get_regs_user() for SIMD sampling perf/x86/intel: Don't inject fake PEBS overflow for non-guest PEBS event perf/x86/intel: Fix stale PEBS count without counter-group support perf/x86/intel: Check period setting return value for PEBS events perf/x86/intel: Initialize arch_pebs_index to 0 before writing MSR perf/x86/intel: Only program ACR reload value for events with config2 perf/x86/intel: Reject ACR/arch-PEBS events with sample_period > 2^32 perf/x86/intel: Fix incorrect count calculation for arch-PEBS events arch/x86/events/core.c | 28 +++++- arch/x86/events/intel/bts.c | 7 +- arch/x86/events/intel/core.c | 174 ++++++++++++++++++++++++++++++++--- arch/x86/events/intel/ds.c | 77 ++++++++++------ arch/x86/events/perf_event.h | 3 + 5 files changed, 241 insertions(+), 48 deletions(-) base-commit: 86a52e8d105ff74d5fa8c1694df53aa026f7dd62 -- 2.34.1