]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.31/perf-intel-pt-fix-overlap-calculation-for-padding.patch
Linux 4.19.31
[thirdparty/kernel/stable-queue.git] / releases / 4.19.31 / perf-intel-pt-fix-overlap-calculation-for-padding.patch
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
5
6 From: Adrian Hunter <adrian.hunter@intel.com>
7
8 commit 5a99d99e3310a565b0cf63f785b347be9ee0da45 upstream.
9
10 Auxtrace records might have up to 7 bytes of padding appended. Adjust
11 the overlap accordingly.
12
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>
19
20 ---
21 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 36 ++++++++++++++++++--
22 1 file changed, 34 insertions(+), 2 deletions(-)
23
24 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
25 +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
26 @@ -26,6 +26,7 @@
27
28 #include "../cache.h"
29 #include "../util.h"
30 +#include "../auxtrace.h"
31
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
35 }
36 }
37
38 +#define MAX_PADDING (PERF_AUXTRACE_RECORD_ALIGNMENT - 1)
39 +
40 +/**
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
45 + *
46 + * @buf_a might have up to 7 bytes of padding appended. Adjust the overlap
47 + * accordingly.
48 + *
49 + * Return: A pointer into @buf_b from where non-overlapped data starts
50 + */
51 +static unsigned char *adj_for_padding(unsigned char *buf_b,
52 + unsigned char *buf_a, size_t len_a)
53 +{
54 + unsigned char *p = buf_b - MAX_PADDING;
55 + unsigned char *q = buf_a + len_a - MAX_PADDING;
56 + int i;
57 +
58 + for (i = MAX_PADDING; i; i--, p++, q++) {
59 + if (*p != *q)
60 + break;
61 + }
62 +
63 + return p;
64 +}
65 +
66 /**
67 * intel_pt_find_overlap_tsc - determine start of non-overlapped trace data
68 * using TSC.
69 @@ -2608,8 +2637,11 @@ static unsigned char *intel_pt_find_over
70
71 /* Same TSC, so buffers are consecutive */
72 if (!cmp && rem_b >= rem_a) {
73 + unsigned char *start;
74 +
75 *consecutive = true;
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);
79 }
80 if (cmp < 0)
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);
84 if (found) {
85 *consecutive = true;
86 - return buf_b + len_a;
87 + return adj_for_padding(buf_b + len_a, buf_a, len_a);
88 }
89
90 /* Try again at next PSB in buffer 'a' */