From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=80.241.56.161 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796279240; b=G3BEEzwctvOvaMDm/MM1gDBaEeH4YlqPM+paRelwYkgR/OZH+fk362KhsEItF4/C1uFT pKzekrdr3IG9BxypFtxq0pqlHNDJFtL3UTN98/3KRnqR0yCr8zMqc2cl7L9nMCMZraLjW rc5jK5eP15xMpZuUytTxfqGQFBl7KH4us0zOrIGAoIyeLDg+JHC8WOL/cOhNRHCfe38zA PLpGRXaSHuoipn5GRSA28bwgnBbOioJBCgdlUflH+qBCYqNkyDdiH/OPUHJENxSOyupTj wBqlNiXcL8/uM5x/iY6Hvy7/9JVhhLmUqEZvBPY27vb9B4lF4UnF8sGFGw4wokqJuww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796279240; h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-MBO-RS-ID:X-MBO-RS-META; bh=jq5Obh5zC1gu58xuUFLIRx2vjn5akTk8fe+iGczTpa4=; b=dgAamOGvWyFlV8855+9YO/YiZNc57VFx9UV/wJJuhY6+1WW7VsIq5BPBWmP1PUjruO4x A1J4M9DoEvyhbegAbFJ+EGnd619orNXsMgFeugSUOM5FSEcx4s1oNNhhHjjX18+uMHfu6 pzFlAw2/HnQp7aZlw7WJimsextIPuqJwPhBX3Pc56x0ZJn6JkRhbNx50A2ZJerM+fhwoa QUl37VV/MWv2qbs/FdSv54MRxldPzq4fwJTlC6c4PqDQcMZSkrcq/2M1GfYV2eOGRA0mq 8KdX1C3MMZmQEf64FO1ebCe7vDQu55m+23l/8fInYmrWhYU/HLeKWhPI6S6jUdSfuVQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=MCYNs3Ou; arc=none smtp.remote-ip=80.241.56.161 Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CCF4606A336; Thu, 3 Dec 2026 06:27:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6CCF4606A336 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=MCYNs3Ou Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4jg4RL6VPMzKnP7; Thu, 03 Dec 2026 07:27:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1796279230; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jq5Obh5zC1gu58xuUFLIRx2vjn5akTk8fe+iGczTpa4=; b=MCYNs3OukLvhSes/IFdq9cE8Oe9HksT93/hxlApg0s1h+IZtN9s1sA3eS0E+X/UdfLwEQZ yzBDPDtGOwiah+MgKXZ4dTxOWHCitx8o0b+aw9jpTJooyZpT6AcQ6wm/9KrnJn9ZseVqy0 AqIrxZvSZspwEXDz44o8LdUiBL58nuumqUBOw/1h9nN3EPtQvldEMZMws0oBq4euZ5bV16 JaUyisaMsb8Zf2V12qZyT4IQbLUIr5tiXlUwDSy2fSLEriBNJtErUXmQRVs108hwdmHCtk u99pWnoqJYjKlXMRWjKIvcOi+qE7Pbuh7rlffJ86tm/6ThdGbt3x602cLvJ8Kw== From: Oancea Catalin To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim Cc: Kan Liang , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Ravi Bangoria , Dapeng Mi Subject: [PATCH v3 3/4] perf/x86: Handle overflows of counters stopped by a throttle Date: Thu, 3 Dec 2026 08:27:02 +0200 Message-ID: <20261203062703.15346-4-john3@mailbox.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203062703.15346-1-john3@mailbox.org> References: <20261203062703.15346-1-john3@mailbox.org> 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 X-MBO-RS-ID: 442981f2a6fa5192def X-MBO-RS-META: zmxhfktzm5bqkgw6x1wwgf5u9s793pxq x86_pmu_handle_irq() tests cpuc->active_mask while it walks the counters. When perf_event_overflow() throttles a group, the other events of the group are stopped and the loop skips them, also when they have overflowed in the same NMI. The period of such a counter is not set up again. The counter is restarted as it is when the group is unthrottled, so the overflow is noticed by a later NMI of another counter, or not at all when the event is scheduled out first. Take a copy of active_mask before the loop and walk the counters which were active on entry, as in amd_pmu_v2_handle_irq(). An AI coding assistant (Claude Code) was used in the analysis and in writing the patch. Fixes: 9734e25fbf5a ("perf: Fix the throttle logic for a group") Signed-off-by: Oancea Catalin Cc: stable@vger.kernel.org --- Tested with the reproducer of patch 2 on the same AMD machine and in the guest, booted with clearcpuid=perfmon_v2 so that amd_pmu_handle_irq() is used. I have no other hardware which uses this handler. arch/x86/events/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 4e344fb1ae3e..b4f956c5ca1c 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2157,6 +2157,7 @@ void x86_pmu_update_perf_regs(struct perf_event *event, int x86_pmu_handle_irq(struct pt_regs *regs) { + DECLARE_BITMAP(active, X86_PMC_IDX_MAX); struct perf_sample_data data; struct cpu_hw_events *cpuc; struct perf_event *event; @@ -2176,8 +2177,15 @@ int x86_pmu_handle_irq(struct pt_regs *regs) */ apic_write(APIC_LVTPC, APIC_DM_NMI); + /* + * perf_event_overflow() can throttle and thereby stop the whole group. + * Walk the counters which are active now, so that a pending overflow + * of a sibling stopped that way is still handled. + */ + bitmap_copy(active, cpuc->active_mask, X86_PMC_IDX_MAX); + for_each_set_bit(idx, x86_pmu.cntr_mask, X86_PMC_IDX_MAX) { - if (!test_bit(idx, cpuc->active_mask)) + if (!test_bit(idx, active)) continue; event = cpuc->events[idx]; -- 2.56.1