[PATCH 4.9 023/125] perf intel-pt: Ensure never to set last_ip when packet count is zero

From: Greg Kroah-Hartman
Date: Tue Jul 25 2017 - 16:42:00 EST


4.9-stable review patch. If anyone has any objections, please let me know.

------------------

From: Adrian Hunter <adrian.hunter@xxxxxxxxx>

commit f952eaceb089b691eba7c4e13686e742a8f26bf5 upstream.

Intel PT uses IP compression based on the last IP. For decoding purposes,
'last IP' is not updated when a branch target has been suppressed, which is
indicated by IPBytes == 0. IPBytes is stored in the packet 'count', so
ensure never to set 'last_ip' when packet 'count' is zero.

Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Link: http://lkml.kernel.org/r/1495786658-18063-7-git-send-email-adrian.hunter@xxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1468,7 +1468,8 @@ static int intel_pt_walk_psbend(struct i

case INTEL_PT_FUP:
decoder->pge = true;
- intel_pt_set_last_ip(decoder);
+ if (decoder->packet.count)
+ intel_pt_set_last_ip(decoder);
break;

case INTEL_PT_MODE_TSX:
@@ -1754,8 +1755,9 @@ next:

static inline bool intel_pt_have_ip(struct intel_pt_decoder *decoder)
{
- return decoder->have_last_ip || decoder->packet.count == 0 ||
- decoder->packet.count == 3 || decoder->packet.count == 6;
+ return decoder->packet.count &&
+ (decoder->have_last_ip || decoder->packet.count == 3 ||
+ decoder->packet.count == 6);
}

/* Walk PSB+ packets to get in sync. */