Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3052404imm; Sun, 1 Jul 2018 11:07:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK6mC7rgqJIeb+5tkLlYGs72/4e+BCxmxBjlI+h5VhdH2wdT1sHSXlnOAqX8+4S1ufIcWiR X-Received: by 2002:a17:902:1703:: with SMTP id i3-v6mr22367101pli.263.1530468462160; Sun, 01 Jul 2018 11:07:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530468462; cv=none; d=google.com; s=arc-20160816; b=ge8eDlO+HDjvOiSzmrra7dVOCtlg64nxbFLpZK6nAoDp1YfhKxRzhhHLDyATaEfH9H 8Iro/Ap2ZKHZhfklxzC0c50DMTiq0xlAzEf1qZukrOCH8tsvW64sJlUY3myrmOf2+YA2 4QWzyMI2PEoOKxS8wzINyc48DhAHUWNTTN9XjdSBloL0/YKbAxbRUFkts+NnBzAIEBBJ /TdFkXCXp5Qv/lrX/tJWFZLLd4SB5sNWwgyOZcMD2Uu4fIP78YhcNWVsBOnwMf9UTC6V s/akNt0RjZYXhBD/9S6MERmrsUDhO1Jg9FLC05G5AoUTFCxjn/mTNbuQdBYqfwrGfwtR qx8A== 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=u8WrhO61XVfTJPR0a91hwQisHWqw0ge1f+FHgOeT3tM=; b=chezSMhgpoZylQn3PfEbtsKQCOR3jh5yQ9Yo3s+AZIQ1+vP4OpoS31uqTut60xyubL DUJbNwYSiLjImiSUfTDRrLjw4tqZPO0tT7j43i+qeXdyEZlVKTZEOk/okF7RW4BROp6K 5Ae7nXUEJf47BV1NcKNLaoiMtr8imO/4hg/IY3Uhw4LhPB4oFdGIhf0vHMFBVlYijal7 cbvHxNiDHs3Ne/E8GlFK10aFQbJEo0BMlZT9XzC1q9KIx6/zXpcFblKgunCGRTv8XMYj zsq4aMumZ3Nmrc4v7MO/t733ndJRZ89H+CTfuqQgrZJEYPmH5on5XwO1Wxk6QzciaCHr E+7w== 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 x1-v6si12663147pga.205.2018.07.01.11.07.27; Sun, 01 Jul 2018 11:07:42 -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 S965795AbeGAQ3C (ORCPT + 99 others); Sun, 1 Jul 2018 12:29:02 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34412 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933823AbeGAQ25 (ORCPT ); Sun, 1 Jul 2018 12:28:57 -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 64F8EAD8; Sun, 1 Jul 2018 16:28:56 +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.9 079/101] perf intel-pt: Fix "Unexpected indirect branch" error Date: Sun, 1 Jul 2018 18:22:05 +0200 Message-Id: <20180701160800.332053955@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160757.138608453@linuxfoundation.org> References: <20180701160757.138608453@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.9-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 @@ -112,6 +112,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; @@ -215,6 +216,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; @@ -1012,6 +1015,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; @@ -1024,7 +1036,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; @@ -1034,7 +1047,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; @@ -92,6 +100,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 @@ -752,6 +752,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)); @@ -832,6 +833,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;