cs_etm__cpu_mode() decides whether an address is in the kernel by comparing it with the kernel start address. On arm64, modules are loaded below that, so module code is looked up in the thread's user maps which results in a decode failure.
The exception level of the trace is known for ETMv4 and ETE, so use that instead and only fall back to the address when it's unknown. This enables the ability to decode trace from kernel modules.
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-decoder/cs-etm-decoder.c | 6 ++++-- tools/perf/util/cs-etm.c | 12 +++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index b9397151748b..f133e11ccc7b 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -462,7 +462,8 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq, packet->last_instr_type = elem->last_i_type; packet->last_instr_subtype = elem->last_i_subtype; packet->last_instr_cond = elem->last_instr_cond; - packet->el = elem->context.exception_level; + if (elem->context.el_valid) + packet->el = elem->context.exception_level;
if (elem->last_i_type == OCSD_INSTR_BR || elem->last_i_type == OCSD_INSTR_BR_INDIRECT) packet->last_instr_taken_branch = elem->last_instr_exec; @@ -607,7 +608,8 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
packet = &packet_queue->packet_buffer[packet_queue->tail]; packet->tid = tid; - packet->el = elem->context.exception_level; + if (elem->context.el_valid) + packet->el = elem->context.exception_level;
/* * A timestamp is generated after a PE_CONTEXT element so make sure diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 51431a4d5db7..3fce3c357943 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1134,8 +1134,18 @@ static u8 cs_etm__cpu_mode(struct cs_etm_queue *etmq, u64 address, ocsd_ex_level el) { struct machine *machine = cs_etm__get_machine(etmq, el); + bool kernel;
- if (address >= machine__kernel_start(machine)) { + /* + * Prefer the exception level when it's known, because arm64 modules are + * below the kernel start address. + */ + if (el == ocsd_EL_unknown) + kernel = address >= machine__kernel_start(machine); + else + kernel = el != ocsd_EL0; + + if (kernel) { if (machine__is_host(machine)) return PERF_RECORD_MISC_KERNEL; else