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=1796085956; b=fOoDK7a3E9U0sOPr68jSIOYDHYShiOWXAYKH+4YDK5Ic1gmh8DPe3A9NjaVYzSz2aj5q igyUR44rRfIepv4gA8qy1pD5+HS3xYfBC/GiS1Wzuv6O3ihW826GU6wSMf9aElOD+eWo9 uH9rkpYkazZgW9wtJGgK6ib3xNaK1XkFJImwGh/7AWMpwx6LEMuym6xfVmqKaNEaU7xTP H6AwU2SBeVoQrwVlDbJU18XHzdZRtYwOZVgp/FUVM7k2pMxTW4nWW5cTs32Rt48ap6BtD grzYJ+5ofEzndQTReIfoAG4//Q260nNNAdhJYC3XOmCkDAKOKc2fkiHBAV0NVt0nD5A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796085956; 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:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=sZHsvtPcznu5qwMkB/Km6PqrnqmDoPz7tJEvJlTC0uw=; b=f8U+r4RIGmFuf3he2RDYDkWDYhUj259kXuiPVzn36+TGbKz1HbnyZGn+ANrsGfKobO9l 1DDL9R00pNE+WJkIq5SsjOVi2MvMz30MSCncV+dgRqkYkg6dUWsArgkOHhsVdEOUrJ9be b/McxdRcqTMgyfpP1a1Hp0matl5qLZ2fQSPN7+Bnz8/uBmk4Puu7Q6W0lPhoWVu03qsq1 Qiwga9dAhOdpW+xZVRNNgQxoojdFp1NpkNOrJRGQR+cFoU37Js4Lrf52W7m38dS+VleY0 WxJpJ+UHi0GEqJRcgks5h58WkAtT7fprpHBEwEmvsdP6PG33IzjRBHkrQBnmZgYWaLQ== 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=MuyoUlAx; 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 EAC45606A32F; Tue, 1 Dec 2026 00:45:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EAC45606A32F 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=MuyoUlAx DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796085955; x=1827621955; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sZHsvtPcznu5qwMkB/Km6PqrnqmDoPz7tJEvJlTC0uw=; b=MuyoUlAxWq5PcowWwDLNpi4yDtorWmE3uDfbgi8rcjDXz00/5Sa9Uw2R xz+XPm3vA4Rvc3mr69cFMuiCki2l6UV4wpqca3xCodohGbt5Ew2yWKsI/ VgZIP2sOiT7wUC+qFxOP8AD/FiEQCcUyxQcP/umlwJBKrTM8tfHYEH+jO 16nlJYhrkzIkb/thGGNMJEQ+XbcqITZELJlJgbdy5ODBJB+UZCxEMdZ2q TxRHyJ8jCTV9rO78rmH7rqdvd5WZRUowYt4YBFcH3RjOC80Rs39WTRPAw 4tt0doLHBOSIBUmWSeyz+CsCCmP62g81vjzzArY+5dmYZoIKWvWesOsho A==; X-CSE-ConnectionGUID: Y2hL7DLBTbqNRHLhLxwnuA== X-CSE-MsgGUID: nj/Eu31yTpuKga8LndmIhw== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4845957" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4845957" 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:55 -0800 X-CSE-ConnectionGUID: hkd+fhgpSXCOiiepEnIznw== X-CSE-MsgGUID: NOXcxV4XQcSjC7ywYzT3CQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13678524" Received: from spr.sh.intel.com ([10.112.229.196]) by fmviesa010.fm.intel.com with ESMTP; 30 Nov 2026 16:45:48 -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 06/16] perf/x86/intel: Reset cached acr_cfg_b[] and cfg_c_val[] on CPU teardown Date: Tue, 1 Dec 2026 08:36:58 +0800 Message-Id: <20261201003708.1806748-7-dapeng1.mi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261201003708.1806748-1-dapeng1.mi@linux.intel.com> References: <20261201003708.1806748-1-dapeng1.mi@linux.intel.com> 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 The acr_cfg_b[] and cfg_c_val[] arrays cache the last values written to the *_CFG_B and *_CFG_C MSRs, and reprogramming is skipped when a new value matches the cached one. After CPU hotplug, those MSRs may return to reset defaults, but the cached values may still reflect the pre-offline state. This can incorrectly skip MSR writes when events are enabled again, leaving the hardware with reset MSR contents. Clear both caches and corresponding *_CFG_B/*_CFG_C MSRs on CPU teardown, so *_CFG_B and *_CFG_C are always reprogrammed after the CPU comes back online. Fixes: ec980e4facef ("perf/x86/intel: Support auto counter reload") Fixes: 52448a0a7390 ("perf/x86/intel: Setup PEBS data configuration and enable legacy groups") Signed-off-by: Dapeng Mi --- arch/x86/events/intel/core.c | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index d634cc2ddcf9..ee7ace7be3c6 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -6622,9 +6622,50 @@ static void fini_adaptive_pebs_on_cpu(int cpu) wrmsrq_on_cpu(cpu, MSR_PEBS_DATA_CFG, 0); } +static void clear_pmu_ext_msrs_on_cpu(int cpu, u64 mask, + u32 gp_base, u32 fixed_base) +{ + u32 idx, msr; + + for_each_set_bit(idx, (unsigned long *)&mask, X86_PMC_IDX_MAX) { + if (idx < INTEL_PMC_IDX_FIXED) { + msr = gp_base + x86_pmu.addr_offset(idx, false); + } else { + msr = fixed_base + + x86_pmu.addr_offset(idx - INTEL_PMC_IDX_FIXED, false); + } + wrmsrq_on_cpu(cpu, msr, 0); + } +} + +static void fini_pmu_ext_msrs_on_cpu(int cpu) +{ + struct cpu_hw_events *cpuc; + u64 cfg_b_mask, cfg_c_mask; + + if (x86_pmu.version < 6) + return; + + cpuc = &per_cpu(cpu_hw_events, cpu); + cfg_b_mask = hybrid(cpuc->pmu, acr_cntr_mask64); + cfg_c_mask = cfg_b_mask | hybrid(cpuc->pmu, arch_pebs_cap).counters; + + /* + * Clear cached acr_cfg_b[] and cfg_c_val[] so *_CFG_B and + * *_CFG_C MSRs can always be reprogrammed after CPU online. + */ + memset(cpuc->acr_cfg_b, 0, sizeof(cpuc->acr_cfg_b)); + memset(cpuc->cfg_c_val, 0, sizeof(cpuc->cfg_c_val)); + clear_pmu_ext_msrs_on_cpu(cpu, cfg_b_mask, MSR_IA32_PMC_V6_GP0_CFG_B, + MSR_IA32_PMC_V6_FX0_CFG_B); + clear_pmu_ext_msrs_on_cpu(cpu, cfg_c_mask, MSR_IA32_PMC_V6_GP0_CFG_C, + MSR_IA32_PMC_V6_FX0_CFG_C); +} + static void intel_pmu_cpu_dying(int cpu) { fini_fixed_cntrs_on_cpu(cpu); + fini_pmu_ext_msrs_on_cpu(cpu); fini_adaptive_pebs_on_cpu(cpu); fini_debug_store_on_cpu(cpu); fini_arch_pebs_on_cpu(cpu); -- 2.34.1