Skip to content

Commit 4e7b363

Browse files
ahunter6gregkh
authored andcommitted
perf intel-pt: Fix "Unexpected indirect branch" error
commit 9fb5233 upstream. Some Atom CPUs can produce FUP packets that contain NLIP (next linear instruction pointer) instead of CLIP (current linear instruction pointer). That will result in "Unexpected indirect branch" errors. Fix by comparing IP to NLIP in that case. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/1527762225-26024-5-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 65a1639 commit 4e7b363

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎tools/perf/util/intel-pt-decoder/intel-pt-decoder.c‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct intel_pt_decoder {
113113
bool have_cyc;
114114
bool fixup_last_mtc;
115115
bool have_last_ip;
116+
enum intel_pt_param_flags flags;
116117
uint64_t pos;
117118
uint64_t last_ip;
118119
uint64_t ip;
@@ -226,6 +227,8 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params)
226227
decoder->return_compression = params->return_compression;
227228
decoder->branch_enable = params->branch_enable;
228229

230+
decoder->flags = params->flags;
231+
229232
decoder->period = params->period;
230233
decoder->period_type = params->period_type;
231234

@@ -1097,6 +1100,15 @@ static bool intel_pt_fup_event(struct intel_pt_decoder *decoder)
10971100
return ret;
10981101
}
10991102

1103+
static inline bool intel_pt_fup_with_nlip(struct intel_pt_decoder *decoder,
1104+
struct intel_pt_insn *intel_pt_insn,
1105+
uint64_t ip, int err)
1106+
{
1107+
return decoder->flags & INTEL_PT_FUP_WITH_NLIP && !err &&
1108+
intel_pt_insn->branch == INTEL_PT_BR_INDIRECT &&
1109+
ip == decoder->ip + intel_pt_insn->length;
1110+
}
1111+
11001112
static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
11011113
{
11021114
struct intel_pt_insn intel_pt_insn;
@@ -1109,10 +1121,11 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
11091121
err = intel_pt_walk_insn(decoder, &intel_pt_insn, ip);
11101122
if (err == INTEL_PT_RETURN)
11111123
return 0;
1112-
if (err == -EAGAIN) {
1124+
if (err == -EAGAIN ||
1125+
intel_pt_fup_with_nlip(decoder, &intel_pt_insn, ip, err)) {
11131126
if (intel_pt_fup_event(decoder))
11141127
return 0;
1115-
return err;
1128+
return -EAGAIN;
11161129
}
11171130
decoder->set_fup_tx_flags = false;
11181131
if (err)

‎tools/perf/util/intel-pt-decoder/intel-pt-decoder.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ enum {
6060
INTEL_PT_ERR_MAX,
6161
};
6262

63+
enum intel_pt_param_flags {
64+
/*
65+
* FUP packet can contain next linear instruction pointer instead of
66+
* current linear instruction pointer.
67+
*/
68+
INTEL_PT_FUP_WITH_NLIP = 1 << 0,
69+
};
70+
6371
struct intel_pt_state {
6472
enum intel_pt_sample_type type;
6573
int err;
@@ -106,6 +114,7 @@ struct intel_pt_params {
106114
unsigned int mtc_period;
107115
uint32_t tsc_ctc_ratio_n;
108116
uint32_t tsc_ctc_ratio_d;
117+
enum intel_pt_param_flags flags;
109118
};
110119

111120
struct intel_pt_decoder;

‎tools/perf/util/intel-pt.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
784784
unsigned int queue_nr)
785785
{
786786
struct intel_pt_params params = { .get_trace = 0, };
787+
struct perf_env *env = pt->machine->env;
787788
struct intel_pt_queue *ptq;
788789

789790
ptq = zalloc(sizeof(struct intel_pt_queue));
@@ -865,6 +866,9 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
865866
}
866867
}
867868

869+
if (env->cpuid && !strncmp(env->cpuid, "GenuineIntel,6,92,", 18))
870+
params.flags |= INTEL_PT_FUP_WITH_NLIP;
871+
868872
ptq->decoder = intel_pt_decoder_new(&params);
869873
if (!ptq->decoder)
870874
goto out_free;

0 commit comments

Comments
 (0)