Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit cb0125e

Browse files
ahunter6gregkh
authored andcommitted
perf/x86/intel/pt: Fix sampling synchronization
commit d92792a upstream. pt_event_snapshot_aux() uses pt->handle_nmi to determine if tracing needs to be stopped, however tracing can still be going because pt->handle_nmi is set to zero before tracing is stopped in pt_event_stop, whereas pt_event_snapshot_aux() requires that tracing must be stopped in order to copy a sample of trace from the buffer. Instead call pt_config_stop() always, which anyway checks config for RTIT_CTL_TRACEEN and does nothing if it is already clear. Note pt_event_snapshot_aux() can continue to use pt->handle_nmi to determine if the trace needs to be restarted afterwards. Fixes: 25e8920 ("perf/x86/intel/pt: Add sampling support") Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20240715160712.127117-2-adrian.hunter@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 19fd2f2 commit cb0125e

File tree

1 file changed

+7
-8
lines changed
  • arch/x86/events/intel

1 file changed

+7
-8
lines changed

arch/x86/events/intel/pt.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,7 @@ static void pt_event_stop(struct perf_event *event, int mode)
16021602
* see comment in intel_pt_interrupt().
16031603
*/
16041604
WRITE_ONCE(pt->handle_nmi, 0);
1605+
barrier();
16051606

16061607
pt_config_stop(event);
16071608

@@ -1653,11 +1654,10 @@ static long pt_event_snapshot_aux(struct perf_event *event,
16531654
return 0;
16541655

16551656
/*
1656-
* Here, handle_nmi tells us if the tracing is on
1657+
* There is no PT interrupt in this mode, so stop the trace and it will
1658+
* remain stopped while the buffer is copied.
16571659
*/
1658-
if (READ_ONCE(pt->handle_nmi))
1659-
pt_config_stop(event);
1660-
1660+
pt_config_stop(event);
16611661
pt_read_offset(buf);
16621662
pt_update_head(pt);
16631663

@@ -1669,11 +1669,10 @@ static long pt_event_snapshot_aux(struct perf_event *event,
16691669
ret = perf_output_copy_aux(&pt->handle, handle, from, to);
16701670

16711671
/*
1672-
* If the tracing was on when we turned up, restart it.
1673-
* Compiler barrier not needed as we couldn't have been
1674-
* preempted by anything that touches pt->handle_nmi.
1672+
* Here, handle_nmi tells us if the tracing was on.
1673+
* If the tracing was on, restart it.
16751674
*/
1676-
if (pt->handle_nmi)
1675+
if (READ_ONCE(pt->handle_nmi))
16771676
pt_config_start(event);
16781677

16791678
return ret;

0 commit comments

Comments
 (0)