* [PATCH] perf intel-pt: Save the reference window used to detect snapshot wraps
@ 2026-11-16 9:26 lirongqing
2026-11-16 9:48 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: lirongqing @ 2026-11-16 9:26 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, James Clark, Li RongQing,
linux-perf-users, linux-kernel
From: Li RongQing <lirongqing@baidu.com>
The snapshot reference offset is initialized to the end of the AUX
buffer and does not change. The comparison checks that fixed window,
but the reference update copies bytes immediately before the current
head instead.
Two snapshots before the trace reaches the buffer end can consequently
compare trace bytes against an untouched tail and falsely report a wrap.
The reader then treats the buffer as full and emits stale or unwritten
bytes in addition to the new trace.
Copy the window ending at ref_offset plus its size, matching the window
used by the comparison.
Fixes: 90e457f7be08 ("perf tools: Add Intel PT support")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
tools/perf/arch/x86/util/intel-pt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index a533114..5e38b9c 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -1091,7 +1091,7 @@ static bool intel_pt_wrapped(struct intel_pt_recording *ptr, int idx,
data, head);
intel_pt_copy_ref(ref->ref_buf, ptr->snapshot_ref_buf_size, mm->len,
- data, head);
+ data, ref->ref_offset + ptr->snapshot_ref_buf_size);
return wrapped;
}
--
2.9.4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] perf intel-pt: Save the reference window used to detect snapshot wraps
2026-11-16 9:26 [PATCH] perf intel-pt: Save the reference window used to detect snapshot wraps lirongqing
@ 2026-11-16 9:48 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-16 9:48 UTC (permalink / raw)
To: lirongqing, linux-perf-users
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf intel-pt: fixed tail window in intel_pt_wrapped()
falsely detects wraps
--
commit db3c47adedfe1494edbb28fa120460d2030e1f73
Author: Li RongQing <lirongqing@baidu.com>
perf intel-pt: Save the reference window used to detect snapshot wraps
This commit changes intel_pt_wrapped() to copy the snapshot reference buffer
from ref->ref_offset + ptr->snapshot_ref_buf_size instead of head.
> diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
> index 4c183ccf4e5b6..f034e3d55051a 100644
> --- a/tools/perf/arch/x86/util/intel-pt.c
> +++ b/tools/perf/arch/x86/util/intel-pt.c
> @@ -1092,7 +1092,7 @@ static bool intel_pt_wrapped(struct intel_pt_recording *ptr, int idx,
> data, head);
>
> intel_pt_copy_ref(ref->ref_buf, ptr->snapshot_ref_buf_size, mm->len,
> - data, head);
> + data, ref->ref_offset + ptr->snapshot_ref_buf_size);
>
> return wrapped;
> }
[Severity: Medium]
Does keeping ref->ref_offset fixed at the end of the AUX buffer cause
intel_pt_wrapped() to falsely report wraps?
intel_pt_alloc_snapshot_ref() initializes ref->ref_offset to
mm->len - ptr->snapshot_ref_buf_size (the window immediately preceding the
initial head at 0). With ref->ref_offset never updated, ref_end in
intel_pt_compare_ref() is always mm->len:
tools/perf/arch/x86/util/intel-pt.c:intel_pt_compare_ref() {
size_t ref_end = ref_offset + ref_size;
if (ref_end > buf_size) {
if (head > ref_offset || head < ref_end - buf_size)
return true;
} else if (head > ref_offset && head < ref_end) {
return true;
}
return intel_pt_compare_buffers(ref_buf, ref_size, data, ref_offset,
buf_size);
}
Whenever a snapshot is taken with head in (ref_offset, mm->len),
intel_pt_compare_ref() unconditionally returns true before comparing
ref_buf, even before the first wrap or when head has not moved at all. In
addition, any later snapshot whose trace merely crosses the end of the AUX
buffer from *old <= ref_offset to *head < *old overwrites that fixed tail
window and triggers wrapped = true without having wrapped a full mm->len
around *old.
When wrapped is true, intel_pt_find_snapshot() sets *old = *head and
*head += mm->len instead of advancing from the previous *old, so
__auxtrace_mmap__read() emits unwritten zero bytes before the first wrap or
re-emits stale trace bytes that were already recorded in earlier snapshots.
Instead of copying the fixed window at the end of the buffer,
intel_pt_wrapped() should keep copying the window preceding head and update
ref->ref_offset to match (head - ptr->snapshot_ref_buf_size, wrapped modulo
mm->len). Note that with a sliding ref->ref_offset that can wrap across
mm->len, intel_pt_compare_buffers() also needs part_size = buf2_size - offs2
rather than end2 - buf2_size to avoid reading past buf2 + buf2_size, and the
head < ref_size branch of intel_pt_copy_ref() needs to place the tail segment
data + buf_size - (ref_size - head) at the start of ref_buf followed by
data[0..head) so the two halves match the order expected by
intel_pt_compare_buffers().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116092650.1714-1-lirongqing@baidu.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 9:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 9:26 [PATCH] perf intel-pt: Save the reference window used to detect snapshot wraps lirongqing
2026-11-16 9:48 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox