Skip to content

Commit 92ca7da

Browse files
virtuosoPeter Zijlstra
authored andcommitted
perf/x86/intel: Fix PT PMI handling
Commit: ccbebba ("perf/x86/intel/pt: Bypass PT vs. LBR exclusivity if the core supports it") skips the PT/LBR exclusivity check on CPUs where PT and LBRs coexist, but also inadvertently skips the active_events bump for PT in that case, which is a bug. If there aren't any hardware events at the same time as PT, the PMI handler will ignore PT PMIs, as active_events reads zero in that case, resulting in the "Uhhuh" spurious NMI warning and PT data loss. Fix this by always increasing active_events for PT events. Fixes: ccbebba ("perf/x86/intel/pt: Bypass PT vs. LBR exclusivity if the core supports it") Reported-by: Vitaly Slobodskoy <[email protected]> Signed-off-by: Alexander Shishkin <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Alexey Budankov <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent ff61541 commit 92ca7da

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

arch/x86/events/core.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ int x86_add_exclusive(unsigned int what)
376376
* LBR and BTS are still mutually exclusive.
377377
*/
378378
if (x86_pmu.lbr_pt_coexist && what == x86_lbr_exclusive_pt)
379-
return 0;
379+
goto out;
380380

381381
if (!atomic_inc_not_zero(&x86_pmu.lbr_exclusive[what])) {
382382
mutex_lock(&pmc_reserve_mutex);
@@ -388,6 +388,7 @@ int x86_add_exclusive(unsigned int what)
388388
mutex_unlock(&pmc_reserve_mutex);
389389
}
390390

391+
out:
391392
atomic_inc(&active_events);
392393
return 0;
393394

@@ -398,11 +399,15 @@ int x86_add_exclusive(unsigned int what)
398399

399400
void x86_del_exclusive(unsigned int what)
400401
{
402+
atomic_dec(&active_events);
403+
404+
/*
405+
* See the comment in x86_add_exclusive().
406+
*/
401407
if (x86_pmu.lbr_pt_coexist && what == x86_lbr_exclusive_pt)
402408
return;
403409

404410
atomic_dec(&x86_pmu.lbr_exclusive[what]);
405-
atomic_dec(&active_events);
406411
}
407412

408413
int x86_setup_perfctr(struct perf_event *event)

0 commit comments

Comments
 (0)