Commit 727998de authored by Adrian Hunter's avatar Adrian Hunter Committed by Greg Kroah-Hartman

perf intel-pt: Fix "Unexpected indirect branch" error

commit 9fb52336 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: default avatarAdrian 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent eadc0ef1
...@@ -111,6 +111,7 @@ struct intel_pt_decoder { ...@@ -111,6 +111,7 @@ struct intel_pt_decoder {
bool have_cyc; bool have_cyc;
bool fixup_last_mtc; bool fixup_last_mtc;
bool have_last_ip; bool have_last_ip;
enum intel_pt_param_flags flags;
uint64_t pos; uint64_t pos;
uint64_t last_ip; uint64_t last_ip;
uint64_t ip; uint64_t ip;
...@@ -213,6 +214,8 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params) ...@@ -213,6 +214,8 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params)
decoder->data = params->data; decoder->data = params->data;
decoder->return_compression = params->return_compression; decoder->return_compression = params->return_compression;
decoder->flags = params->flags;
decoder->period = params->period; decoder->period = params->period;
decoder->period_type = params->period_type; decoder->period_type = params->period_type;
...@@ -1010,6 +1013,15 @@ static int intel_pt_walk_insn(struct intel_pt_decoder *decoder, ...@@ -1010,6 +1013,15 @@ static int intel_pt_walk_insn(struct intel_pt_decoder *decoder,
return err; return err;
} }
static inline bool intel_pt_fup_with_nlip(struct intel_pt_decoder *decoder,
struct intel_pt_insn *intel_pt_insn,
uint64_t ip, int err)
{
return decoder->flags & INTEL_PT_FUP_WITH_NLIP && !err &&
intel_pt_insn->branch == INTEL_PT_BR_INDIRECT &&
ip == decoder->ip + intel_pt_insn->length;
}
static int intel_pt_walk_fup(struct intel_pt_decoder *decoder) static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
{ {
struct intel_pt_insn intel_pt_insn; struct intel_pt_insn intel_pt_insn;
...@@ -1022,7 +1034,8 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder) ...@@ -1022,7 +1034,8 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
err = intel_pt_walk_insn(decoder, &intel_pt_insn, ip); err = intel_pt_walk_insn(decoder, &intel_pt_insn, ip);
if (err == INTEL_PT_RETURN) if (err == INTEL_PT_RETURN)
return 0; return 0;
if (err == -EAGAIN) { if (err == -EAGAIN ||
intel_pt_fup_with_nlip(decoder, &intel_pt_insn, ip, err)) {
if (decoder->set_fup_tx_flags) { if (decoder->set_fup_tx_flags) {
decoder->set_fup_tx_flags = false; decoder->set_fup_tx_flags = false;
decoder->tx_flags = decoder->fup_tx_flags; decoder->tx_flags = decoder->fup_tx_flags;
...@@ -1032,7 +1045,7 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder) ...@@ -1032,7 +1045,7 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
decoder->state.flags = decoder->fup_tx_flags; decoder->state.flags = decoder->fup_tx_flags;
return 0; return 0;
} }
return err; return -EAGAIN;
} }
decoder->set_fup_tx_flags = false; decoder->set_fup_tx_flags = false;
if (err) if (err)
......
...@@ -53,6 +53,14 @@ enum { ...@@ -53,6 +53,14 @@ enum {
INTEL_PT_ERR_MAX, INTEL_PT_ERR_MAX,
}; };
enum intel_pt_param_flags {
/*
* FUP packet can contain next linear instruction pointer instead of
* current linear instruction pointer.
*/
INTEL_PT_FUP_WITH_NLIP = 1 << 0,
};
struct intel_pt_state { struct intel_pt_state {
enum intel_pt_sample_type type; enum intel_pt_sample_type type;
int err; int err;
...@@ -91,6 +99,7 @@ struct intel_pt_params { ...@@ -91,6 +99,7 @@ struct intel_pt_params {
unsigned int mtc_period; unsigned int mtc_period;
uint32_t tsc_ctc_ratio_n; uint32_t tsc_ctc_ratio_n;
uint32_t tsc_ctc_ratio_d; uint32_t tsc_ctc_ratio_d;
enum intel_pt_param_flags flags;
}; };
struct intel_pt_decoder; struct intel_pt_decoder;
......
...@@ -676,6 +676,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, ...@@ -676,6 +676,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
unsigned int queue_nr) unsigned int queue_nr)
{ {
struct intel_pt_params params = { .get_trace = 0, }; struct intel_pt_params params = { .get_trace = 0, };
struct perf_env *env = pt->machine->env;
struct intel_pt_queue *ptq; struct intel_pt_queue *ptq;
ptq = zalloc(sizeof(struct intel_pt_queue)); ptq = zalloc(sizeof(struct intel_pt_queue));
...@@ -753,6 +754,9 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, ...@@ -753,6 +754,9 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
} }
} }
if (env->cpuid && !strncmp(env->cpuid, "GenuineIntel,6,92,", 18))
params.flags |= INTEL_PT_FUP_WITH_NLIP;
ptq->decoder = intel_pt_decoder_new(&params); ptq->decoder = intel_pt_decoder_new(&params);
if (!ptq->decoder) if (!ptq->decoder)
goto out_free; goto out_free;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment