linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf inject: correct event attribute sizes
@ 2020-08-26  9:42 Al Grant
  2020-08-26 11:27 ` Mark Rutland
  2020-09-01 17:26 ` Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 8+ messages in thread
From: Al Grant @ 2020-08-26  9:42 UTC (permalink / raw)
  To: linux-perf-users, linux-kernel, acme

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.

From: Denis Nikitin <denik@google.com>
Signed-off-by: Al Grant <al.grant@foss.arm.com>

  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 9cf4efdcbbbd..762eb94bd532 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3326,6 +3326,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);
+               }
                 f_attr = (struct perf_file_attr){
                         .attr = evsel->core.attr,
                         .ids  = {

^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [PATCH] perf inject: correct event attribute sizes
@ 2020-11-24 19:58 Al Grant
  2020-12-16  6:58 ` Denis Nikitin
  0 siblings, 1 reply; 8+ messages in thread
From: Al Grant @ 2020-11-24 19:58 UTC (permalink / raw)
  To: linux-perf-users, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim
  Cc: Al Grant, Al Grant, linux-kernel

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>
---
 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);
+		}
 		f_attr = (struct perf_file_attr){
 			.attr = evsel->core.attr,
 			.ids  = {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-01-15 19:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-26  9:42 [PATCH] perf inject: correct event attribute sizes 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
2020-11-24 19:58 Al Grant
2020-12-16  6:58 ` Denis Nikitin
2020-12-23 22:11   ` Jiri Olsa
2021-01-15 19:48     ` Arnaldo Carvalho de Melo

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).