From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=80.241.56.152 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796297976; b=oZcm3zURwg6elYRDnTtPcl7vWg92d+l7/qo1pJYz7m/Q1ITqHDu8lvz/evyJUi6pIKOs QYU9Y2WjSZwIgBC95meIKUcGy23agvemmpBEZxwUjK9FkBMTeOGMRj+OXUVhOX0SBnJ4W OEzpZyRoyCHQDRROoqLzmduwT2EOaneVdvwNsK+405HDofQO2I+SMEXwQPOzr4HVTMIhA I+rdFHCpSCdgJeipPwVxE4UmFmwxHDVWqT5w4gEG0bRb3S0s/ds8nBFMsAAksjHamAX2Q viJ/ZYHZaeC3xAs9V99zKwLzY60igGj2TqIJq0/fl+mYGchdOav9TWZZV2Jj2KV70gQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796297976; 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=9nK6euYPd6kG/1Tl7SCsmsSgPPuyOWe236j87dTrUFA=; b=tflIZJ26S6jKAjSSr6Zhi3NvcAoI+rRIha6yqUPWLbDzK6CAwhunvtLPLmMXMm31jARz 7Nk32qRhw313Wh8aQwbzEilssyR9/1cmv3+OtzD3DGQ4qm5xtzDWLzJYPl+CIsJthCPbR u/GXXcxf6JgC7kJql1vKI9Qd8LLFaQhXIz2lSvxLb7kKojPksWjR35TLfU4xZx0eclTXz 0HpNhUOCOpuN6E6zApdDscfWbBBeqQDg+fjUo3AwGREQaCCNwSChaGmm7lsAuFug+4uHf KIB5KCwp905tt1JDBJuLQ5nFLLdPRBv3vAqWFG2lRBmLgqaocWJWmtaku07r0ZXN2Kw== 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=EdCXQOOE; arc=none smtp.remote-ip=80.241.56.152 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) (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 73380606A339; Thu, 3 Dec 2026 11:39:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 73380606A339 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=EdCXQOOE Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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-102.mailbox.org (Postfix) with ESMTPS id 4jgCMm6FwLzKpBT; Thu, 03 Dec 2026 12:39:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1796297972; 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=9nK6euYPd6kG/1Tl7SCsmsSgPPuyOWe236j87dTrUFA=; b=EdCXQOOEL5p0ofAUWTU2waoqO9o6GFEmjpBv3ig9X2lpTaZ472aZciguu8CeqQAIMnRD6G YQNbZLIXPAd3o3JWAag+gPKONBA490yaUjIo8uuzoQQuiApPHybx0dvD0vlX4rHlqXT4PP 5A6+msVfo7EZLY28cqfjQ4v/pf5pClIqLmPms+40vcWxhSdwhyx/5hiPjP+SVQQ0jwW4mi WTtMP51uwfwr4KUuK2JfLCNZhbXV1ZC/RyA9YF72SmPVaOHG4B3sOWHtCD8aq4FTUkALyz 3dJqSp2QXND/kttH3hsi4Ga9jP3JVs+VxP53WyRMUjhZiv5m8+j/GmdkgLXzDw== 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 v4 3/4] perf/x86: Handle overflows of counters stopped by a throttle Date: Thu, 3 Dec 2026 13:39:21 +0200 Message-ID: <20261203113922.77972-4-john3@mailbox.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203113922.77972-1-john3@mailbox.org> References: <20261203113922.77972-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: 3zrqn5up3noaafzzgfp35oqektadi6hm X-MBO-RS-ID: 327e3a51417c0a0c531 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 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