mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Raul Silvera <rsilvera@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>,
	Dave Marchevsky <davemarchevsky@fb.com>,
	Colin Ian King <colin.king@intel.com>,
	Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf: Adjust perf-inject output data offset for backward compatibility
Date: Mon, 20 Jun 2022 21:54:24 +0300	[thread overview]
Message-ID: <a651ca26-6aae-fe7f-66b1-18fdbad40f41@intel.com> (raw)
In-Reply-To: <20220620164953.1503934-1-rsilvera@google.com>

On 20/06/22 19:49, Raul Silvera wrote:
> When perf inject creates a new file, it reuses the data offset from the
> input file. If there has been a change on the size of the header, as
> happened in v5.12 -> v5.13, the new offsets will be wrong, resulting in
> a corrupted output file.
> 
> This change adds the function perf_session__data_offset to compute the
> data offset based on the current header size, and uses that instead of
> the offset from the original input file.
> 
> Signed-off-by: Raul Silvera <rsilvera@google.com>
> ---
>  tools/perf/builtin-inject.c |  2 +-
>  tools/perf/util/header.c    | 16 +++++++++++++++-
>  tools/perf/util/header.h    |  2 ++
>  3 files changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
> index a75bf11585b5..1dfdcef36607 100644
> --- a/tools/perf/builtin-inject.c
> +++ b/tools/perf/builtin-inject.c
> @@ -916,7 +916,7 @@ static int __cmd_inject(struct perf_inject *inject)
>  		inject->tool.tracing_data = perf_event__repipe_tracing_data;
>  	}
>  
> -	output_data_offset = session->header.data_offset;
> +	output_data_offset = perf_session__data_offset(session->evlist);
>  
>  	if (inject->build_id_all) {
>  		inject->tool.mmap	  = perf_event__repipe_buildid_mmap;
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index 53332da100e8..93706ae827f1 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -3660,7 +3660,7 @@ static int perf_session__do_write_header(struct perf_session *session,
>  			.size   = evlist->core.nr_entries * sizeof(f_attr),
>  		},
>  		.data = {
> -			.offset = header->data_offset,
> +			.offset = attr_offset + evlist->core.nr_entries * sizeof(f_attr),

This looks too late since, although the header comes before the data,
it also gets written afterwards (at_exit == true).  It would be
better if we could rely on header->data_offset at this point.

>  			.size	= header->data_size,
>  		},
>  		/* event_types is ignored, store zeros */
> @@ -3686,6 +3686,20 @@ int perf_session__write_header(struct perf_session *session,
>  	return perf_session__do_write_header(session, evlist, fd, at_exit, NULL);
>  }
>  
> +size_t perf_session__data_offset(const struct evlist *evlist)
> +{
> +	struct evsel *evsel;
> +	size_t data_offset;
> +
> +	data_offset = sizeof(struct perf_file_header);
> +	evlist__for_each_entry(evlist, evsel) {
> +		data_offset += evsel->core.ids * sizeof(u64);
> +	}
> +	data_offset += evlist->core.nr_entries * sizeof(struct perf_file_attr);
> +
> +	return data_offset;
> +}
> +
>  int perf_session__inject_header(struct perf_session *session,
>  				struct evlist *evlist,
>  				int fd,
> diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
> index 08563c1f1bff..56916dabce7b 100644
> --- a/tools/perf/util/header.h
> +++ b/tools/perf/util/header.h
> @@ -136,6 +136,8 @@ int perf_session__inject_header(struct perf_session *session,
>  				int fd,
>  				struct feat_copier *fc);
>  
> +size_t perf_session__data_offset(const struct evlist *evlist);
> +
>  void perf_header__set_feat(struct perf_header *header, int feat);
>  void perf_header__clear_feat(struct perf_header *header, int feat);
>  bool perf_header__has_feat(const struct perf_header *header, int feat);


  reply	other threads:[~2022-06-20 18:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20 16:49 Raul Silvera
2022-06-20 18:54 ` Adrian Hunter [this message]
2022-06-21  1:35   ` Raul Silvera

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=a651ca26-6aae-fe7f-66b1-18fdbad40f41@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=colin.king@intel.com \
    --cc=davemarchevsky@fb.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rsilvera@google.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®