From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=80.241.56.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796477559; b=iQgeUFkiKdZ1P55cZ6ttEOBL821LL8hXO9C1hHYZVl9cb9yWghAEaf2qyLfEJQ5GPFcy UflSP9SuQIxzeqwaCqS3HFE6ysp4lJ9wXDHDYybVHjx8liA7EJPGHrt5KN4NadieTq+Qx QqS8wsuLSFwRRi1XT9Kbf/cLNNxfXg2IwRpAaGgvPoXfz+Pg+xkIrNUSprdebToBPNC5n wal2KFVTiIn5ZxRxJjym7dNPRRfED9q6UZc9r0AtLjYw88+DuhjI3txTUZ+jy2ZTVUEdg C3tk/t64ixfBPnj4MKzDf8lZdG4AMz33st7HxNxORDwkVQ9MAqzXMtMxiLYUP+7048Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796477559; 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-META:X-MBO-RS-ID; bh=4MHCT7IVTHnb6eTBwmoWR0YyKUTZfZbrmfToNCFctqg=; b=t4l/DTJFj9+MAgeZGP8Bl4OWiYuMyLKFsUAj692CGXWEiQ01kLPk1kCl3t2JMhHgAFWR JCzlzC1P2VcoqgZhywwGKtZCZr3IalNvUVBTuPPqFX69zmidr0pGbiZxl+s1lXzgVRnA0 aeJCwWk3cpnmHkJ8njZ3MVykA0c2fMfhyOUYpggx2OppnWQfBWnhXZvm+JKPq0iBgncvF 0Y5TQkHmsZ73wA3KgDRZGqBD1tzC5IDroV6LQHdsnJatUTOSx/Epxi8aCmwkWAzBkNTvr OjZZ71ll8tfj2hF54F3YbGmw5U/OGh449qVH+aCQNVmOyimiO7mIIErXBYLFmB/WhZQ== 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=fQWdJ+BN; arc=none smtp.remote-ip=80.241.56.171 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (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 B2FC2606A33E; Sat, 5 Dec 2026 13:32:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B2FC2606A33E 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=fQWdJ+BN Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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-201.mailbox.org (Postfix) with ESMTPS id 4jhTnH4D6SzMllX; Sat, 05 Dec 2026 14:32:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1796477555; 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=4MHCT7IVTHnb6eTBwmoWR0YyKUTZfZbrmfToNCFctqg=; b=fQWdJ+BNu7ECmxQdbYRRNiXf14mS6msnUP/9nUQfyybmRzO/VKEp544IvggD43hR4Pk/Q+ vL6G+X64yrEdva+UHlug93r5D7TLijOUFoN1G2ySHZ6YZ0Gh/VQLNFFR+FW4ffAsxlNbJZ DTZiLhiIH2ztUgoVMSPJDEG2siJ7dhtJCW/txnYIzgK86UBYELTVlX2OPpFFAB26kmahFZ CyjzBfwMi/nVmstqmzGFWOzB6KhfcHB87hOFACZxlFZSoJmAK07xrlZdymfTLaALy7MHvh p4KQVyA8YwGStU7viIFOu0UrMJCnVCz4+trLLxx6yQhuoS4l2TXxB64sIMRUWQ== 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, shicenci@gmail.com, Ravi Bangoria , Dapeng Mi Subject: [PATCH v5 4/8] perf/x86: Handle overflows of counters stopped by a throttle Date: Sat, 5 Dec 2026 15:32:17 +0200 Message-ID: <20261205133221.3294-5-john3@mailbox.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261205133221.3294-1-john3@mailbox.org> References: <20261205133221.3294-1-john3@mailbox.org> 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 X-MBO-RS-META: fezkfncu4q3g9h17pb1yrn3n6588x1oq X-MBO-RS-ID: 6711facf387b3205a62 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 Reviewed-by: Dapeng Mi Cc: stable@vger.kernel.org --- Tested with the reproducer of patch 3 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