1 From 5a99d99e3310a565b0cf63f785b347be9ee0da45 Mon Sep 17 00:00:00 2001
2 From: Adrian Hunter <adrian.hunter@intel.com>
3 Date: Wed, 6 Feb 2019 12:39:44 +0200
4 Subject: perf intel-pt: Fix overlap calculation for padding
6 From: Adrian Hunter <adrian.hunter@intel.com>
8 commit 5a99d99e3310a565b0cf63f785b347be9ee0da45 upstream.
10 Auxtrace records might have up to 7 bytes of padding appended. Adjust
11 the overlap accordingly.
13 Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
14 Cc: Jiri Olsa <jolsa@redhat.com>
15 Cc: stable@vger.kernel.org
16 Link: http://lkml.kernel.org/r/20190206103947.15750-3-adrian.hunter@intel.com
17 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
18 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 36 ++++++++++++++++++--
22 1 file changed, 34 insertions(+), 2 deletions(-)
24 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
25 +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
30 +#include "../auxtrace.h"
32 #include "intel-pt-insn-decoder.h"
33 #include "intel-pt-pkt-decoder.h"
34 @@ -2558,6 +2559,34 @@ static int intel_pt_tsc_cmp(uint64_t tsc
38 +#define MAX_PADDING (PERF_AUXTRACE_RECORD_ALIGNMENT - 1)
41 + * adj_for_padding - adjust overlap to account for padding.
42 + * @buf_b: second buffer
43 + * @buf_a: first buffer
44 + * @len_a: size of first buffer
46 + * @buf_a might have up to 7 bytes of padding appended. Adjust the overlap
49 + * Return: A pointer into @buf_b from where non-overlapped data starts
51 +static unsigned char *adj_for_padding(unsigned char *buf_b,
52 + unsigned char *buf_a, size_t len_a)
54 + unsigned char *p = buf_b - MAX_PADDING;
55 + unsigned char *q = buf_a + len_a - MAX_PADDING;
58 + for (i = MAX_PADDING; i; i--, p++, q++) {
67 * intel_pt_find_overlap_tsc - determine start of non-overlapped trace data
69 @@ -2608,8 +2637,11 @@ static unsigned char *intel_pt_find_over
71 /* Same TSC, so buffers are consecutive */
72 if (!cmp && rem_b >= rem_a) {
73 + unsigned char *start;
76 - return buf_b + len_b - (rem_b - rem_a);
77 + start = buf_b + len_b - (rem_b - rem_a);
78 + return adj_for_padding(start, buf_a, len_a);
81 return buf_b; /* tsc_a < tsc_b => no overlap */
82 @@ -2672,7 +2704,7 @@ unsigned char *intel_pt_find_overlap(uns
83 found = memmem(buf_a, len_a, buf_b, len_a);
86 - return buf_b + len_a;
87 + return adj_for_padding(buf_b + len_a, buf_a, len_a);
90 /* Try again at next PSB in buffer 'a' */