[BUG] perf: older perf.data files may not be readable

From: Stephane Eranian
Date: Thu Jun 09 2011 - 10:18:44 EST


Arnaldo,

I was looking at util/session.c:

int perf_file_header__read(struct perf_file_header *header,
struct perf_header *ph, int fd)
{
lseek(fd, 0, SEEK_SET);

if (readn(fd, header, sizeof(*header)) <= 0 ||
memcmp(&header->magic, __perf_magic, sizeof(header->magic)))
return -1;

if (header->attr_size != sizeof(struct perf_file_attr)) {
u64 attr_size = bswap_64(header->attr_size);

if (attr_size != sizeof(struct perf_file_attr))
return -1;

mem_bswap_64(header, offsetof(struct perf_file_header,
adds_features));
ph->needs_swap = true;
}
...
}

struct perf_file_attr {
struct perf_event_attr attr;
struct perf_file_section ids;
};

The way you detect endianess leads me to believe that perf will not be
able to cope with growth of perf_event_attr struct AND maintain backward
compatibility with perf.data files saved with smaller perf_event_attr struct.

It should be possible to read perf.data files written with a smaller
perf_event_attr struct. You simply ignore leave the extended fields at zero.

Conversely, you can ignore the fields if the perf.data struct is larger
than that of the tool. But this is the more unlikely scenario, so it's
not that important.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/