Skip to contentSkip to conversation

perf inject: correct event attribute sizes

PATCH New Al Grant 4 participants 4 messages Nov 24, 2020 – Jan 15, 2021 perf events

lore
Share & tools
lore

Al Grant

author
#0 lore raw

PATCH 1/1 perf inject: correct event attribute sizes

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.

---
 tools/perf/util/header.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/perf/util/header.c +8 -0
index be850e9f8852..0d95981df8dd 100644
@@ -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  = {
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 perf inject: correct event attribute sizes

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.

---
 tools/perf/util/header.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/perf/util/header.c +8 -0
index be850e9f8852..0d95981df8dd 100644
@@ -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  = {
Signature · 1 line
2.29.2.684.gfbc64c5ab5-goog
Acked-by on v1 1/1
#2 lore raw
Quoted 17 lines · Denis Nikitin

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.

---
 tools/perf/util/header.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/perf/util/header.c +0 -0
index be850e9f8852..0d95981df8dd 100644
@@ -3331,6 +3331,14 @@ int perf_session__write_header(struct perf_session *session,
 	attr_offset = lseek(ff.fd, 0, SEEK_CUR);

tools/perf/util/header.c int perf_session__write_header(struct perf_session *session, · line 3341

Quoted 10 lines
tools/perf/util/header.c +8 -0
 
 	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

thanks,
jirka

Quoted 6 lines
tools/perf/util/header.c +0 -0
 		f_attr = (struct perf_file_attr){
 			.attr = evsel->core.attr,
 			.ids  = {
Signature · 1 line
2.29.2.684.gfbc64c5ab5-goog
maintainer Applied
#3 lore raw

Em Wed, Dec 23, 2020 at 11:11:05PM +0100, Jiri Olsa escreveu:

Quoted 32 lines · Denis Nikitin
Quoted 17 lines

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.

---
 tools/perf/util/header.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/perf/util/header.c +0 -0
index be850e9f8852..0d95981df8dd 100644
@@ -3331,6 +3331,14 @@ int perf_session__write_header(struct perf_session *session,
 	attr_offset = lseek(ff.fd, 0, SEEK_CUR);

tools/perf/util/header.c int perf_session__write_header(struct perf_session *session, · line 3341

Quoted 10 lines
tools/perf/util/header.c +8 -0
 
 	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

Quoted 8 lines

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

Thanks, applied.

- Arnaldo