OpenCSD caches instruction memory one page size at a time. Perf reads this requested size from the file on disk without limiting it to the end of the map, so the page can contain ELF metadata from the file that wasn't mapped. If a subsequent read for a different .so file falls into this range, then it won't be decoded properly.
Fix it by clamping the read size to the end of the map. Now when OpenCSD requests an address outside of that range, Perf will load the next .so file rather than OpenCSD using the mis-cached data.
Fixes: c9a01a11dfe6 ("perf tools: Add support for decoding CoreSight trace data") Signed-off-by: James Clark james.clark@linaro.org --- tools/perf/util/cs-etm.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 3fce3c357943..fb4582dc378e 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1213,6 +1213,12 @@ static u32 __cs_etm__mem_access(struct cs_etm_queue *etmq,
offset = map__map_ip(al.map, address);
+ /* + * Clamp to the map size to avoid putting unmapped ELF file data from + * the .so into OpenCSD's cache as map data. + */ + size = min_t(u64, size, map__end(al.map) - address); + map__load(al.map);
len = dso__data_read_offset(dso, maps__machine(thread__maps(thread)),