Re: [PATCH] perf/x86/amd: Avoid double-decrementing n_pair on failed transactions

From: Hang Zhengyang

Date: Wed Nov 11 2026 - 02:03:04 EST


On Mon, 9 Nov 2026 19:19:09 +0800, Zhao Gongyi wrote:
> On a failed PERF_PMU_TXN_ADD commit, x86_schedule_events() releases
> constraints for newly added pair events. The AMD put callback decrements
> n_pair, and x86_pmu_cancel_txn() then subtracts n_txn_pair for the same
> events.

Reproduced in a KVM guest on a Zen 3 host (Ryzen 7 PRO 5850U), kernel
7.3-rc6, with a trace_printk() in x86_schedule_events() and
x86_pmu_cancel_txn(). With four pinned cycles events on CPU 0, each
failed attempt to add a pinned '{fp_ret_sse_avx_ops.all,cycles}' group
leaves n_pair one lower: -1, -2, -3, so gpmax goes 5, 6, 7 on 6
counters. With this patch n_pair is back to 0 after each attempt and
gpmax stays 5.

Tested-by: Hang Zhengyang <hang.zhengyang1010@xxxxxxxxx>

To reproduce:

perf stat -C 0 -e '{cycles,cycles,cycles,cycles}:D' -- sleep 4 &
# three times:
perf stat -C 0 -e '{fp_ret_sse_avx_ops.all,cycles}:D' -- taskset -c 0 <workload>

(Analysis and testing done with an AI assistant; I reproduced the
n_pair drift.)