Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3065030imm; Sun, 1 Jul 2018 11:25:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL/FkchdQtm9/WshcwG6e9krnOsIIZ3GiFBK6uxQyZ4FwviyWUdRaCbYrfbE5v3SDciJukm X-Received: by 2002:a17:902:7891:: with SMTP id q17-v6mr23312253pll.186.1530469527580; Sun, 01 Jul 2018 11:25:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530469527; cv=none; d=google.com; s=arc-20160816; b=kRl6+Ck02aezzm1B98a4V4Xwqi/k9aAXbRrmL5BnmlkVDgulmCu3jFyb9AvkIeWZ7r s+IyjCAHscSiz1oTzHoC0usOSyiQlPmjquoRsq2720GiRqg5c9m8overI+eQNEvdGURc bZOgAeaogKqMRLCcWAxKyBxj/JbesK9CrAUL4bASHw8D8vsKgcccFk61ST4Nuogm1Jc3 vTe7Qk8YDFg3MVnV7tQzUfbrV+F58E/zBhfLnsUdEY6xT+HPmI54lKyaiePmGpAmsj3m xYK6UchfR++sqpK1k3Wipuc0ceg/RP6pkudWLHYrrj0el0JlFkrFDFKasjn0kBXi5eBl uFHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=2m5pB1Y4gkkoYpLNX9DnNU9GKRA4s7PxzD1koeVPeF4=; b=NGIyIqHWFsOSqW6gI3Uqb1Epn9QB1pnAs4QzsdPTb7fDP+Z19c5xqTCYx54tF+NoP2 bZSnWSYkC7M08RyBT2QSp/K/80W9BHqowTPw8ih5dmaVBfNeDTZph83xG2Rnw+XTCEaN VcHQhyzhRrOlqYywldFSmg8imFnAx0IuhyjPkMyvpp/Uqglz8HACe5VHbkAxpJaVq7Fg y7Z5AJ8LzXbYKdShqHfRpPk0ke4elzHsh/q7o3O/qWrshj2CnrDwYgtXHZ4HpUtqB5LK DwJnklHMJMdtqUXZq0om/KFf3YOVbSxxzXQqmUZzBD7zwD8Aa0BTDBoZOPfFR7LrnYBW HmwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t22-v6si13887927plo.263.2018.07.01.11.25.13; Sun, 01 Jul 2018 11:25:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753410AbeGAQSw (ORCPT + 99 others); Sun, 1 Jul 2018 12:18:52 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33090 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753217AbeGAQSs (ORCPT ); Sun, 1 Jul 2018 12:18:48 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C0B2549B; Sun, 1 Jul 2018 16:18:47 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Arnaldo Carvalho de Melo Subject: [PATCH 4.4 085/105] perf intel-pt: Fix "Unexpected indirect branch" error Date: Sun, 1 Jul 2018 18:02:35 +0200 Message-Id: <20180701153155.529983389@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701153149.382300170@linuxfoundation.org> References: <20180701153149.382300170@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Adrian Hunter commit 9fb523363f6e3984457fee95bb7019395384ffa7 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 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 Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 17 +++++++++++++++-- tools/perf/util/intel-pt-decoder/intel-pt-decoder.h | 9 +++++++++ tools/perf/util/intel-pt.c | 4 ++++ 3 files changed, 28 insertions(+), 2 deletions(-) --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c @@ -111,6 +111,7 @@ struct intel_pt_decoder { bool have_cyc; bool fixup_last_mtc; bool have_last_ip; + enum intel_pt_param_flags flags; uint64_t pos; uint64_t last_ip; uint64_t ip; @@ -213,6 +214,8 @@ struct intel_pt_decoder *intel_pt_decode decoder->data = params->data; decoder->return_compression = params->return_compression; + decoder->flags = params->flags; + decoder->period = params->period; decoder->period_type = params->period_type; @@ -1010,6 +1013,15 @@ out_no_progress: 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) { struct intel_pt_insn intel_pt_insn; @@ -1022,7 +1034,8 @@ static int intel_pt_walk_fup(struct inte err = intel_pt_walk_insn(decoder, &intel_pt_insn, ip); if (err == INTEL_PT_RETURN) 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) { decoder->set_fup_tx_flags = false; decoder->tx_flags = decoder->fup_tx_flags; @@ -1032,7 +1045,7 @@ static int intel_pt_walk_fup(struct inte decoder->state.flags = decoder->fup_tx_flags; return 0; } - return err; + return -EAGAIN; } decoder->set_fup_tx_flags = false; if (err) --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h @@ -53,6 +53,14 @@ enum { 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 { enum intel_pt_sample_type type; int err; @@ -91,6 +99,7 @@ struct intel_pt_params { unsigned int mtc_period; uint32_t tsc_ctc_ratio_n; uint32_t tsc_ctc_ratio_d; + enum intel_pt_param_flags flags; }; struct intel_pt_decoder; --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -676,6 +676,7 @@ static struct intel_pt_queue *intel_pt_a unsigned int queue_nr) { struct intel_pt_params params = { .get_trace = 0, }; + struct perf_env *env = pt->machine->env; struct intel_pt_queue *ptq; ptq = zalloc(sizeof(struct intel_pt_queue)); @@ -753,6 +754,9 @@ static struct intel_pt_queue *intel_pt_a } } + if (env->cpuid && !strncmp(env->cpuid, "GenuineIntel,6,92,", 18)) + params.flags |= INTEL_PT_FUP_WITH_NLIP; + ptq->decoder = intel_pt_decoder_new(¶ms); if (!ptq->decoder) goto out_free;