linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Denis Nikitin <denik@chromium.org>
Cc: linux-perf-users@vger.kernel.org, peterz@infradead.org,
	mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, namhyung@kernel.org,
	al.grant@arm.com, al.grant@foss.arm.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf inject: correct event attribute sizes
Date: Wed, 23 Dec 2020 23:11:05 +0100	[thread overview]
Message-ID: <20201223221105.GA236568@krava> (raw)
In-Reply-To: <20201216065816.1840893-1-denik@chromium.org>

On Tue, Dec 15, 2020 at 10:58:16PM -0800, Denis Nikitin wrote:
> When perf inject reads a perf.data file from an older version of perf,
> it writes event attributes into the output with the original size field,
> but lays them out as if they had the size currently used. Readers see
> a corrupt file. Update the size field to match the layout.
> 
> Signed-off-by: Al Grant <al.grant@foss.arm.com>
> Signed-off-by: Denis Nikitin <denik@chromium.org>
> ---
>  tools/perf/util/header.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index be850e9f8852..0d95981df8dd 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -3331,6 +3331,14 @@ int perf_session__write_header(struct perf_session *session,
>  	attr_offset = lseek(ff.fd, 0, SEEK_CUR);
>  
>  	evlist__for_each_entry(evlist, evsel) {
> +		if (evsel->core.attr.size < sizeof(evsel->core.attr)) {
> +			/*
> +			 * We are likely in "perf inject" and have read
> +			 * from an older file. Update attr size so that
> +			 * reader gets the right offset to the ids.
> +			 */
> +			evsel->core.attr.size = sizeof(evsel->core.attr);
> +		}

seems ok, just wondering if it would be better
to fix it in perf_event__process_attr instead

where we know where the data is coming from,
here we could cover for some unexpected case
of having different attr.size?

anyway both would be probably equal, I'm ok
with either way

Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka


>  		f_attr = (struct perf_file_attr){
>  			.attr = evsel->core.attr,
>  			.ids  = {
> -- 
> 2.29.2.684.gfbc64c5ab5-goog
> 


  reply	other threads:[~2020-12-23 22:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24 19:58 [PATCH] perf inject: correct event attribute sizes Al Grant
2020-12-16  6:58 ` Denis Nikitin
2020-12-23 22:11   ` Jiri Olsa [this message]
2021-01-15 19:48     ` Arnaldo Carvalho de Melo
  -- strict thread matches above, loose matches on Subject: below --
2020-08-26  9:42 Al Grant
2020-08-26 11:27 ` Mark Rutland
2020-08-26 13:23   ` Al Grant
2020-09-01 17:26 ` 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=20201223221105.GA236568@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=al.grant@arm.com \
    --cc=al.grant@foss.arm.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=denik@chromium.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 \
    /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;
as well as URLs for NNTP newsgroup(s).