Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2690769pxj; Mon, 31 May 2021 08:20:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFAfpntjQQwaWtMC1zwPnvklMlU02fV+yZPCMfYdZRVr7lJQhl5DnZQMssN106606A8tbZ X-Received: by 2002:a50:fc84:: with SMTP id f4mr6664178edq.252.1622474437237; Mon, 31 May 2021 08:20:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622474437; cv=none; d=google.com; s=arc-20160816; b=Oiyj4GN0fLWQL0m8rv75/5ZWB6aTrkKry43vVuo/CqqXTWhji7toq5DwGCCLVQSzFd r21pwzfGu5peGKK+qXodYyT+jzGESJUmc5Qhc4BrkP1Exj1Bdwvp8SxqTDFwE13Z5wAP DBJyzwCI3eL/0GakKOmt8d5POPkZBIZSwvnwSqjZxtqcqc7HMY6oITwtM4wsvUgkXIZ9 5l5EuyeHZxZwnRCyTRtIz/EbdQr8s7DVjh2LNgax/Ib03UxI6udbbhZwLpihX6YvcVyx ybXRVEloMnpey29d8v263RSQ2I/P0xbcZRosig6PoA9raxIofjE1Co/c76ePTT89nJBG 8S3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CNTzOd+yVQZjsLLm4nwiADnCHij/XQTy/UYtaN+0gI8=; b=hlv7ibuL8fK46cQ0A+MByhrw412L5KeUze3pOoj33yvYEg88DbKu3UXsNjsZ/i4QaE l8Mnc7lIMhCSiK5wHBg3ON5UMDZyT31dD1tUoY0u936fGIDIfBR0bM/ZxBu1p6vjTguz yBTkGgNHbXmtjE7eW3V08rJVNQaVWvZoFNhmaW5a2+CP9zZsTL60nCwHf8HyeaFj/yV+ /TEbqnzWs4Yrmm1SU/z/So8RPexd3xNaZH646jc86NEnCVNvn42P5fdkt54bc5hwigTT aJQM0i4IU3oKJC8rL4xSCGcnNLXawgiEfNNyuSlAKIHTYCg6FMH5zzWI/l3Xa1kis1Dg tWMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XFYDBcFO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j22si14525527eds.591.2021.05.31.08.20.14; Mon, 31 May 2021 08:20:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XFYDBcFO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232968AbhEaPS1 (ORCPT + 99 others); Mon, 31 May 2021 11:18:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:40830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232901AbhEaOMl (ORCPT ); Mon, 31 May 2021 10:12:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 03C386198C; Mon, 31 May 2021 13:41:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468505; bh=b0Q5+kE6Pc40tmlcoKT6wXVJsrD0ncmvgMdZFD/y0pg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XFYDBcFOc2gjIN43FT/+DmCw7085TYI3Mfb1kLl3Mb1eDSMVOuq5JAG1jM+JMw/wS Jxz5EXZ4F5+78OTkGxxnfSbtQlEyJ+EDhWPrRj/SkgnzxQFY1LLcPxtqTgpsh1dNjV UkUnRzEh4452aEaYcsHtCWqKFf2mZJZHqTe0ODU8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Andi Kleen , Jiri Olsa , Arnaldo Carvalho de Melo Subject: [PATCH 5.4 007/177] perf intel-pt: Fix sample instruction bytes Date: Mon, 31 May 2021 15:12:44 +0200 Message-Id: <20210531130648.155173343@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Adrian Hunter commit c954eb72b31a9dc56c99b450253ec5b121add320 upstream. The decoder reports the current instruction if it was decoded. In some cases the current instruction is not decoded, in which case the instruction bytes length must be set to zero. Ensure that is always done. Note perf script can anyway get the instruction bytes for any samples where they are not present. Also note, that there is a redundant "ptq->insn_len = 0" statement which is not removed until a subsequent patch in order to make this patch apply cleanly to stable branches. Example: A machne that supports TSX is required. It will have flag "rtm". Kernel parameter tsx=on may be required. # for w in `cat /proc/cpuinfo | grep -m1 flags `;do echo $w | grep rtm ; done rtm Test program: #include #include int main() { int x = 0; if (_xbegin() == _XBEGIN_STARTED) { x = 1; _xabort(1); } else { printf("x = %d\n", x); } return 0; } Compile with -mrtm i.e. gcc -Wall -Wextra -mrtm xabort.c -o xabort Record: perf record -e intel_pt/cyc/u --filter 'filter main @ ./xabort' ./xabort Before: # perf script --itrace=xe -F+flags,+insn,-period --xed --ns xabort 1478 [007] 92161.431348581: transactions: x 400b81 main+0x14 (/root/xabort) mov $0xffffffff, %eax xabort 1478 [007] 92161.431348624: transactions: tx abrt 400b93 main+0x26 (/root/xabort) mov $0xffffffff, %eax After: # perf script --itrace=xe -F+flags,+insn,-period --xed --ns xabort 1478 [007] 92161.431348581: transactions: x 400b81 main+0x14 (/root/xabort) xbegin 0x6 xabort 1478 [007] 92161.431348624: transactions: tx abrt 400b93 main+0x26 (/root/xabort) xabort $0x1 Fixes: faaa87680b25d ("perf intel-pt/bts: Report instruction bytes and length in sample") Signed-off-by: Adrian Hunter Cc: Andi Kleen Cc: Jiri Olsa Cc: stable@vger.kernel.org Link: http://lore.kernel.org/lkml/20210519074515.9262-3-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/intel-pt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -602,8 +602,10 @@ static int intel_pt_walk_next_insn(struc *ip += intel_pt_insn->length; - if (to_ip && *ip == to_ip) + if (to_ip && *ip == to_ip) { + intel_pt_insn->length = 0; goto out_no_cache; + } if (*ip >= al.map->end) break; @@ -991,6 +993,7 @@ static void intel_pt_set_pid_tid_cpu(str static void intel_pt_sample_flags(struct intel_pt_queue *ptq) { + ptq->insn_len = 0; if (ptq->state->flags & INTEL_PT_ABORT_TX) { ptq->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT; } else if (ptq->state->flags & INTEL_PT_ASYNC) {