Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4393764ybp; Mon, 7 Oct 2019 07:52:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5C0gx0rCKlYj3VoH9YNqGi71JD8NwWYLVaswv28vaot3E8NekEFqzZyQk76tovLg/DoGt X-Received: by 2002:a17:907:388:: with SMTP id ss8mr24278182ejb.26.1570459924082; Mon, 07 Oct 2019 07:52:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570459924; cv=none; d=google.com; s=arc-20160816; b=Z5I2FFw2sJHcqj1YKmQHV7i4S7auzFSN5nTofIu0kOq6o8egnJqAbwzz0EF6XPK0IM 9w2Q8nBwSCM43QlpniP1oP0ZbuyVraP5EMzU267lHJIrWm/lxjelBnIb493TzgRcWBR/ rNm9waWfJRD2ehOEuIMG15CqqVZ1dC0oHcIqBuEYIu222XB3mA8pa+7ExzLWcYup5LDz Y7p02Y2qBTXmlC2zRquB2YHWFMJZ8dC4dQ8O3NZmZ3Eu9m/p18SMgDXj1Pql20JyPgRT YH7N5Go7ziSFHnZQFiKCl724TFf3/9hk3SGW8JtooEECLsgi1LWC3m6xx9/MKPvy1H/H snKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=TLKbaS9sJl6YMfMppLvIrmm0qFJVCRB3OvZ4rX1ahMs=; b=0J3u2zmUxEWnrTK2FT9lK06YlPLD3GNDUXkFeBK+9exqCwOMPQGiXkMI3x47oCFGsm UDYLhoubg6FKtcRCI620tpOIp2crlrIJEGF2bB6FKmQb1DfTwR7OYDoH9tv921ALLkIO vDuR6W5mAahV9ZQu/rKHzLAyDsLRmH/REJLKp4ldf1K8K+3gr+BX319SnAoo2gEzR2C+ zp93BK5mvA7jLFzyJbSgd28sXAbqXM4LOjHSkdKtqzoVKVAC6MBIJyqmIw+9zKceMvRl g9kg/A/kcv9MDkkCVop935EwQuY+Vunv7lDqT3hqW5W7VIUsUmPykNpBJqLKVkqXFfpA I82Q== 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 rn2si7026959ejb.14.2019.10.07.07.51.40; Mon, 07 Oct 2019 07:52:04 -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 S1728264AbfJGOt0 (ORCPT + 99 others); Mon, 7 Oct 2019 10:49:26 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:44232 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727970AbfJGOtZ (ORCPT ); Mon, 7 Oct 2019 10:49:25 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iHUK6-0005yC-6B; Mon, 07 Oct 2019 16:49:18 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 719281C0DC9; Mon, 7 Oct 2019 16:49:15 +0200 (CEST) Date: Mon, 07 Oct 2019 14:49:15 -0000 From: "tip-bot2 for Andi Kleen" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/urgent] perf script brstackinsn: Fix recovery from LBR/binary mismatch Cc: Andi Kleen , Jiri Olsa , Arnaldo Carvalho de Melo , Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: <20190927233546.11533-1-andi@firstfloor.org> References: <20190927233546.11533-1-andi@firstfloor.org> MIME-Version: 1.0 Message-ID: <157045975542.9978.14015561869362479880.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/urgent branch of tip: Commit-ID: e98df280bc2a499fd41d7f9e2d6733884de69902 Gitweb: https://git.kernel.org/tip/e98df280bc2a499fd41d7f9e2d6733884de69902 Author: Andi Kleen AuthorDate: Fri, 27 Sep 2019 16:35:44 -07:00 Committer: Arnaldo Carvalho de Melo CommitterDate: Mon, 30 Sep 2019 17:29:52 -03:00 perf script brstackinsn: Fix recovery from LBR/binary mismatch When the LBR data and the instructions in a binary do not match the loop printing instructions could get confused and print a long stream of bogus instructions. The problem was that if the instruction decoder cannot decode an instruction it ilen wasn't initialized, so the loop going through the basic block would continue with the previous value. Harden the code to avoid such problems: - Make sure ilen is always freshly initialized and is 0 for bad instructions. - Do not overrun the code buffer while printing instructions - Print a warning message if the final jump is not on an instruction boundary. Signed-off-by: Andi Kleen Cc: Jiri Olsa Link: http://lore.kernel.org/lkml/20190927233546.11533-1-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 286fc70..67be8d3 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1063,7 +1063,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, continue; insn = 0; - for (off = 0;; off += ilen) { + for (off = 0; off < (unsigned)len; off += ilen) { uint64_t ip = start + off; printed += ip__fprintf_sym(ip, thread, x.cpumode, x.cpu, &lastsym, attr, fp); @@ -1074,6 +1074,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, printed += print_srccode(thread, x.cpumode, ip); break; } else { + ilen = 0; printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", ip, dump_insn(&x, ip, buffer + off, len - off, &ilen)); if (ilen == 0) @@ -1083,6 +1084,8 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, insn++; } } + if (off != (unsigned)len) + printed += fprintf(fp, "\tmismatch of LBR data and executable\n"); } /* @@ -1123,6 +1126,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, goto out; } for (off = 0; off <= end - start; off += ilen) { + ilen = 0; printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", start + off, dump_insn(&x, start + off, buffer + off, len - off, &ilen)); if (ilen == 0)