mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: irogers@google.com, acme@kernel.org, adrian.hunter@intel.com,
	 namhyung@kernel.org
Cc: dapeng1.mi@linux.intel.com, james.clark@linaro.org,
	leo.yan@linux.dev,  linux-kernel@vger.kernel.org,
	linux-perf-users@vger.kernel.org,  mingo@redhat.com,
	peterz@infradead.org, ravi.bangoria@amd.com,
	 thomas.falcon@intel.com
Subject: [PATCH v5 0/2] perf inject intel-PT LBR/brstack synthesis fixes
Date: Mon, 18 May 2026 10:12:29 -0700	[thread overview]
Message-ID: <20260518171231.2834947-1-irogers@google.com> (raw)
In-Reply-To: <20260518153754.2795820-1-irogers@google.com>

An intel-pt trace can be turned into LBR events either in perf script
or perf inject with the --itrace=L option. With perf inject the
generated perf.data file failed to be parsed as the sample events were
out of sync with their perf_event_attr. A range of fixes were
required.

This patch was separated from a large perf script refactor that
highlighted the breakage:
https://lore.kernel.org/lkml/20260425224951.174663-1-irogers@google.com/

v5:
 - Restored the missing PEBS branch stack synthesis fixes in intel-pt.c
   which were accidentally dropped in a previous rebase/conflict
   resolution.
 - Addressed the pipe mode size mismatch and ID array out-of-bounds read:
   * Safely copy the incoming attribute payload using min_t and
     memset zero, preventing trailing ID corruption.
   * Explicitly set the synthesized event's attr.size to match the tool's
     physical sizeof(struct perf_event_attr), guaranteeing perfect offset
     alignment and removing any risk of hallucinated/garbage IDs or
     underflow out-of-bounds reads.
 - Refactored both commit descriptions to strictly focus on code changes,
   deferring meta-commentary and implementation details exclusively to
   the cover letter.

v4:
 - Avoid temporary regressions in Commit 1:
   * Used local masked sample_type in convert_sample_callchain instead of
     unmasked evsel attribute, preventing heap overflows.
   * Promoted hardware tracer signature changes and dynamic retrieval of
     branch_sample_type to Commit 1, removing hardcoded 0 bugs.
   * Checked sample->evsel first before performing evlist__id2evsel lookup
     to optimize evsel retrieval when already populated.
 - Address critical security and correctness feedback in Commit 2:
   * Added check in perf_event__repipe_attr to prevent n_ids underflow.
   * Fixed early return error path in perf_event__repipe_sample to
     prevent state corruption and dangling pointers on dummy_bs.
   * Ensured perf_inject__cut_auxtrace_sample cuts the 8-byte size field
     even when aux_sample.size is 0 to prevent parser misalignment.
   * Expanded older attributes to PERF_ATTR_SIZE_VER2 in file mode
     within __cmd_inject to prevent silent truncation of
     branch_sample_type.
   * Added bounds checks against PERF_SAMPLE_MAX_SIZE to all hardware
     tracing synthetic helpers to prevent heap buffer overflows.
   * Fixed checkpatch.pl warnings/errors for line-wrapping.

v3:
 - Add missing Fixes: tags on both commits.
 - Refactor perf_event__repipe_attr to avoid in-place modifications on
   read-only mmap buffers, preventing SIGSEGV in file mode and premature
   evsel updates in pipe mode.
 - Use perf_event__synthesize_attr to correctly construct and repipe
   attributes in pipe mode.
 - Replace manual arithmetic in convert_sample_callchain with
   perf_event__sample_event_size to prevent uninitialized memory leaks.
 - Retrieve evsel branch_sample_type dynamically in util/arm-spe.c and
   util/cs-etm.c instead of hardcoding 0, resolving missing hw_idx field
   on synthesized branch stacks.

v2: Response to sashiko fixes for patch 2, Namhyung's acked-by for patch 1.

v1: https://lore.kernel.org/lkml/20260428070328.1880314-1-irogers@google.com/

Ian Rogers (2):
  perf event: Fix size of synthesized sample with branch stacks
  perf inject: Fix itrace branch stack synthesis

 tools/perf/bench/inject-buildid.c  |   9 +-
 tools/perf/builtin-inject.c        | 153 +++++++++++++++++++++++++----
 tools/perf/tests/dlfilter-test.c   |   8 +-
 tools/perf/tests/sample-parsing.c  |   5 +-
 tools/perf/util/arm-spe.c          |  28 +++++-
 tools/perf/util/cs-etm.c           |  28 +++++-
 tools/perf/util/intel-bts.c        |   3 +-
 tools/perf/util/intel-pt.c         |  32 ++++--
 tools/perf/util/synthetic-events.c |  25 +++--
 tools/perf/util/synthetic-events.h |   6 +-
 10 files changed, 247 insertions(+), 50 deletions(-)

-- 
2.54.0.631.ge1b05301d1-goog


  parent reply	other threads:[~2026-05-18 17:12 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-28  7:03 [PATCH v1 " Ian Rogers
2026-04-28  7:03 ` [PATCH v1 1/2] perf event: Fix size of synthesized sample with branch stacks Ian Rogers
2026-04-28 23:19   ` Namhyung Kim
2026-04-28  7:03 ` [PATCH v1 2/2] perf inject: Fix itrace branch stack synthesis Ian Rogers
2026-04-29 18:11 ` [PATCH v2 0/2] perf inject intel-PT LBR/brstack synthesis fixes Ian Rogers
2026-04-29 18:11   ` [PATCH v2 1/2] perf event: Fix size of synthesized sample with branch stacks Ian Rogers
2026-04-29 18:11   ` [PATCH v2 2/2] perf inject: Fix itrace branch stack synthesis Ian Rogers
2026-05-18  6:12   ` [PATCH v3 0/2] perf inject intel-PT LBR/brstack synthesis fixes Ian Rogers
2026-05-18  6:12     ` [PATCH v3 1/2] perf event: Fix size of synthesized sample with branch stacks Ian Rogers
2026-05-18  6:12     ` [PATCH v3 2/2] perf inject: Fix itrace branch stack synthesis Ian Rogers
2026-05-18 15:37     ` [PATCH v4 0/2] perf inject intel-PT LBR/brstack synthesis fixes Ian Rogers
2026-05-18 15:37       ` [PATCH v4 1/2] perf event: Fix size of synthesized sample with branch stacks Ian Rogers
2026-05-18 15:37       ` [PATCH v4 2/2] perf inject: Fix itrace branch stack synthesis Ian Rogers
2026-05-18 17:12       ` Ian Rogers [this message]
2026-05-18 17:12         ` [PATCH v5 1/2] perf event: Fix size of synthesized sample with branch stacks Ian Rogers
2026-05-18 17:12         ` [PATCH v5 2/2] perf inject: Fix itrace branch stack synthesis Ian Rogers
2026-05-18 18:49         ` [PATCH v6 0/2] perf inject intel-PT LBR/brstack synthesis fixes Ian Rogers
2026-05-18 18:49           ` [PATCH v6 1/2] perf event: Fix size of synthesized sample with branch stacks Ian Rogers
2026-05-18 18:49           ` [PATCH v6 2/2] perf inject: Fix itrace branch stack synthesis Ian Rogers
2026-05-18 20:38           ` [PATCH v7 0/2] perf inject intel-PT LBR/brstack synthesis fixes Ian Rogers
2026-05-18 20:38             ` [PATCH v7 1/2] perf event: Fix size of synthesized sample with branch stacks Ian Rogers
2026-05-18 20:38             ` [PATCH v7 2/2] perf inject: Fix itrace branch stack synthesis Ian Rogers
2026-05-18 22:43             ` [PATCH v8 0/2] perf inject intel-PT LBR/brstack synthesis fixes Ian Rogers
2026-05-18 22:43               ` [PATCH v8 1/2] perf event: Fix size of synthesized sample with branch stacks Ian Rogers
2026-05-18 22:43               ` [PATCH v8 2/2] perf inject: Fix itrace branch stack synthesis Ian Rogers
2026-05-20 19:13               ` [PATCH v8 0/2] perf inject intel-PT LBR/brstack synthesis fixes Arnaldo Carvalho de Melo

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=20260518171231.2834947-1-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=james.clark@linaro.org \
    --cc=leo.yan@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=thomas.falcon@intel.com \
    /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

all inboxes | Powered by JetHome®