Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1220638imm; Tue, 5 Jun 2018 10:54:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLK9Aaij6/RAq2p3UEndfdmbOc4Ifwm9VphyuWJZ0BC4oqNfM20W0TA71gmpIA75ZE7pEJY X-Received: by 2002:a63:7459:: with SMTP id e25-v6mr5822831pgn.186.1528221252713; Tue, 05 Jun 2018 10:54:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528221252; cv=none; d=google.com; s=arc-20160816; b=sSfcEBuQ8mrOmudwFppkV0uXX2wE7xAiFcq4x8YJUlcdZIG7ubB3cNt4khY5f4PPWZ hhK0ES1UIXLY2oBEkDW/CezuyEots/rZs4q0wZB7d3RmfXWhmw+xn+6OOIk89f54Hmvs SrjghYHhXgDS/AAXKWTMd753pB2sDZeptNpM8YlbnXJuTJUt4o1p6FdboJ4ufsr7ien4 b2z9KQZXeXkU4jbNyLttu0kjAgFpTKnc8vKUmXCZeG6kWfHhkB27KQ6mDscTQUsDXMvH VYYEGQdaMjJoS7vImOG275guWXrZZwYlQgzKUtog7uOXeFsQ5jlYY3gdjMQbymEgQ6DX 1UDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=ljAd0soZojsd7hXGROZHnA5L/D88HMI9m2GXszlGMTk=; b=DJorpGPdwh6rXmMBs+qU02wWMsEnDh2LxjNnOxmcsshR8WUTgyS8Yy/N3l1QwN9Nu7 RNdIRM+lWjkTDEZqvJcEv71OiRUJhUKlwqW+2+E+44KvHHnLSgxolYkrt9MQN0r8h2dq FqABG6dmPe/EUcsi19NzI5buWFrx87RpWSTDSNv+S29wq4NkDsO61faVzlhgy7g5Mi6+ L4w9gxKnBXnNRzRx0rUn+DLGhOuFBvcEWc7D04uJB0ogj2c+okGejGXLzb1SZc2/xyCu 8AKcSp4mdnS1VG1ZF880/1J1AAY2EpoEyVNGAG8H6eQc6uZZgAsFp61JsqtzQ40NMOol I78A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WbcW9UHY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21-v6si48203457plp.199.2018.06.05.10.53.58; Tue, 05 Jun 2018 10:54:12 -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; dkim=pass header.i=@kernel.org header.s=default header.b=WbcW9UHY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753191AbeFERxP (ORCPT + 99 others); Tue, 5 Jun 2018 13:53:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:46832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753093AbeFERwz (ORCPT ); Tue, 5 Jun 2018 13:52:55 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 88EA62075B; Tue, 5 Jun 2018 17:52:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528221174; bh=xh8/ygdWWIsbOCW7ixGe6qkR6f/oWmHEgR4gdPoACH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WbcW9UHY5wjpR0ysw40LFn4NdE2j3vEk59yyriNZBXDuC/ekUcZLBsgafxGNf3aj/ flpGSMQbYMBGZ9UhrR8xQqaOrFmMDvF6GF8JUKrMEVgLSzE91jwdMH4U69STeFbNxv kjckVTEcfT2g7V+sCt3jkwONWNfZOcSpjrwi/ipY= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Adrian Hunter , stable@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH 46/46] perf intel-pt: Fix "Unexpected indirect branch" error Date: Tue, 5 Jun 2018 14:50:30 -0300 Message-Id: <20180605175030.32549-47-acme@kernel.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180605175030.32549-1-acme@kernel.org> References: <20180605175030.32549-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Adrian Hunter 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 --- 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(-) diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c index 881d7c5e5e2a..d404bed7003a 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c @@ -113,6 +113,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; @@ -226,6 +227,8 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params) decoder->return_compression = params->return_compression; decoder->branch_enable = params->branch_enable; + decoder->flags = params->flags; + decoder->period = params->period; decoder->period_type = params->period_type; @@ -1097,6 +1100,15 @@ static bool intel_pt_fup_event(struct intel_pt_decoder *decoder) return ret; } +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; @@ -1109,10 +1121,11 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder) 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 (intel_pt_fup_event(decoder)) return 0; - return err; + return -EAGAIN; } decoder->set_fup_tx_flags = false; if (err) diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h index fc1752d50019..51c18d67f4ca 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h @@ -60,6 +60,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; @@ -106,6 +114,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; diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index 3db7f0ee52a8..aec68908d604 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -749,6 +749,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, 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)); @@ -830,6 +831,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(¶ms); if (!ptq->decoder) goto out_free; -- 2.14.3