Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf intel-pt: Enable decoder to handle TIP.PGD with missing IP

When address filters are used, the decoder must detect the end of a
filter region (or a branch into a tracestop region) by matching Packet
Generation Disabled (TIP.PGD) packets against the object code using the
IP given in the packet. However, due to errata SKL014 "Intel PT TIP.PGD
May Not Have Target IP Payload", that IP may not be present.

Enable the decoder to handle that by adding a new callback function
'pgd_ip()' which indicates whether the IP is not traced, in which case
that is the point where the trace was disabled.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Link: http://lkml.kernel.org/r/1474641528-18776-16-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
9f1d122b 2b9e32c4

+31
+30
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
··· 80 80 int (*walk_insn)(struct intel_pt_insn *intel_pt_insn, 81 81 uint64_t *insn_cnt_ptr, uint64_t *ip, uint64_t to_ip, 82 82 uint64_t max_insn_cnt, void *data); 83 + bool (*pgd_ip)(uint64_t ip, void *data); 83 84 void *data; 84 85 struct intel_pt_state state; 85 86 const unsigned char *buf; ··· 187 186 188 187 decoder->get_trace = params->get_trace; 189 188 decoder->walk_insn = params->walk_insn; 189 + decoder->pgd_ip = params->pgd_ip; 190 190 decoder->data = params->data; 191 191 decoder->return_compression = params->return_compression; 192 192 ··· 1010 1008 int err; 1011 1009 1012 1010 err = intel_pt_walk_insn(decoder, &intel_pt_insn, 0); 1011 + if (err == INTEL_PT_RETURN && 1012 + decoder->pgd_ip && 1013 + decoder->pkt_state == INTEL_PT_STATE_TIP_PGD && 1014 + (decoder->state.type & INTEL_PT_BRANCH) && 1015 + decoder->pgd_ip(decoder->state.to_ip, decoder->data)) { 1016 + /* Unconditional branch leaving filter region */ 1017 + decoder->no_progress = 0; 1018 + decoder->pge = false; 1019 + decoder->continuous_period = false; 1020 + decoder->pkt_state = INTEL_PT_STATE_IN_SYNC; 1021 + decoder->state.to_ip = 0; 1022 + return 0; 1023 + } 1013 1024 if (err == INTEL_PT_RETURN) 1014 1025 return 0; 1015 1026 if (err) ··· 1051 1036 } 1052 1037 1053 1038 if (intel_pt_insn.branch == INTEL_PT_BR_CONDITIONAL) { 1039 + uint64_t to_ip = decoder->ip + intel_pt_insn.length + 1040 + intel_pt_insn.rel; 1041 + 1042 + if (decoder->pgd_ip && 1043 + decoder->pkt_state == INTEL_PT_STATE_TIP_PGD && 1044 + decoder->pgd_ip(to_ip, decoder->data)) { 1045 + /* Conditional branch leaving filter region */ 1046 + decoder->pge = false; 1047 + decoder->continuous_period = false; 1048 + decoder->pkt_state = INTEL_PT_STATE_IN_SYNC; 1049 + decoder->ip = to_ip; 1050 + decoder->state.from_ip = decoder->ip; 1051 + decoder->state.to_ip = 0; 1052 + return 0; 1053 + } 1054 1054 intel_pt_log_at("ERROR: Conditional branch when expecting indirect branch", 1055 1055 decoder->ip); 1056 1056 decoder->pkt_state = INTEL_PT_STATE_ERR_RESYNC;
+1
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
··· 83 83 int (*walk_insn)(struct intel_pt_insn *intel_pt_insn, 84 84 uint64_t *insn_cnt_ptr, uint64_t *ip, uint64_t to_ip, 85 85 uint64_t max_insn_cnt, void *data); 86 + bool (*pgd_ip)(uint64_t ip, void *data); 86 87 void *data; 87 88 bool return_compression; 88 89 uint64_t period;