Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: lirongqing <lirongqing@baidu.com>, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf intel-pt: Save the reference window used to detect snapshot wraps
Date: Mon, 16 Nov 2026 09:48:58 +0000	[thread overview]
Message-ID: <sashiko-outbox-216640@kernel.org> (raw)
In-Reply-To: <20261116092650.1714-1-lirongqing@baidu.com>

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

      reply	other threads:[~2026-11-16  9:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-216640@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox