]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf/amd/ibs: Fix perf_ibs_op.cnt_mask for CurCnt
authorRavi Bangoria <ravi.bangoria@amd.com>
Wed, 15 Jan 2025 05:44:33 +0000 (05:44 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Jun 2025 12:38:04 +0000 (14:38 +0200)
[ Upstream commit 46dcf85566170d4528b842bf83ffc350d71771fa ]

IBS Op uses two counters: MaxCnt and CurCnt. MaxCnt is programmed with
the desired sample period. IBS hw generates sample when CurCnt reaches
to MaxCnt. The size of these counter used to be 20 bits but later they
were extended to 27 bits. The 7 bit extension is indicated by CPUID
Fn8000_001B_EAX[6 / OpCntExt].

perf_ibs->cnt_mask variable contains bit masks for MaxCnt and CurCnt.
But IBS driver does not set upper 7 bits of CurCnt in cnt_mask even
when OpCntExt CPUID bit is set. Fix this.

IBS driver uses cnt_mask[CurCnt] bits only while disabling an event.
Fortunately, CurCnt bits are not read from MSR while re-enabling the
event, instead MaxCnt is programmed with desired period and CurCnt is
set to 0. Hence, we did not see any issues so far.

Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/r/20250115054438.1021-5-ravi.bangoria@amd.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/events/amd/ibs.c
arch/x86/include/asm/perf_event.h

index b605e08f9a8ef2295e72528b1abb5ce949faf3e8..2b830560299421391c58d07a8fdb343f72173ac8 100644 (file)
@@ -803,7 +803,8 @@ static __init int perf_event_ibs_init(void)
        if (ibs_caps & IBS_CAPS_OPCNTEXT) {
                perf_ibs_op.max_period  |= IBS_OP_MAX_CNT_EXT_MASK;
                perf_ibs_op.config_mask |= IBS_OP_MAX_CNT_EXT_MASK;
-               perf_ibs_op.cnt_mask    |= IBS_OP_MAX_CNT_EXT_MASK;
+               perf_ibs_op.cnt_mask    |= (IBS_OP_MAX_CNT_EXT_MASK |
+                                           IBS_OP_CUR_CNT_EXT_MASK);
        }
 
        ret = perf_ibs_pmu_init(&perf_ibs_op, "ibs_op");
index 0e4efcde07831d84935d05a55a58424be7fc6109..cbfca9d2c419bd5efcc06b7dec97fdd83998d356 100644 (file)
@@ -417,6 +417,7 @@ struct pebs_xmm {
  */
 #define IBS_OP_CUR_CNT         (0xFFF80ULL<<32)
 #define IBS_OP_CUR_CNT_RAND    (0x0007FULL<<32)
+#define IBS_OP_CUR_CNT_EXT_MASK        (0x7FULL<<52)
 #define IBS_OP_CNT_CTL         (1ULL<<19)
 #define IBS_OP_VAL             (1ULL<<18)
 #define IBS_OP_ENABLE          (1ULL<<17)