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 <[email protected]>
Signed-off-by: Al Grant <[email protected]>
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 = {
On Wed, Aug 26, 2020 at 10:42:04AM +0100, Al Grant 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.
>
> From: Denis Nikitin <[email protected]>
> Signed-off-by: Al Grant <[email protected]>
Did Denis write this patch?
If so, we need an S-o-B line from them.
Mark.
> 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 = {
On 26/08/2020 12:27, Mark Rutland wrote:
> On Wed, Aug 26, 2020 at 10:42:04AM +0100, Al Grant 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.
>>
>> From: Denis Nikitin <[email protected]>
>> Signed-off-by: Al Grant <[email protected]>
>
> Did Denis write this patch?
Joint work - I fixed the sizes in the event attributes section,
but Denis noticed that the copies in HEADER_EVENT_DESC also need
fixing, so the final text is his.
> If so, we need an S-o-B line from them.
I have his approval to upstream this, so:
Signed-off-by: Denis Nikitin <[email protected]>
Al
>
> Mark.
>
>> 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 = {
Em Wed, Aug 26, 2020 at 10:42:04AM +0100, Al Grant escreveu:
> 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 <[email protected]>
> Signed-off-by: Al Grant <[email protected]>
Ok, so the author is Denis, has he provided his Signed-off-by?
- Arnaldo
> 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 = {
--
- Arnaldo