Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp6786274ybn; Mon, 30 Sep 2019 03:51:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqySfkxzpOkOd8F3Y6J+01hqHgk1BNEyltKL2T+VmlXn4XfWLkLK+Tok9vibACktZOqVytW3 X-Received: by 2002:a17:906:8406:: with SMTP id n6mr16564928ejx.290.1569840674836; Mon, 30 Sep 2019 03:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569840674; cv=none; d=google.com; s=arc-20160816; b=DgsLfmWSlzrjPllWF0dA/UDVNAhp6md9GXqmWgZrOOVy7yjFvKtWGezp2o4ruNCtqX /P/4I+5Z+gd/G+kOSJsDPMt5MVa7/6SS31OFZx+E4lkpzTCjH/habxR9Z7THnijSZDFn UEiR2HN1x6bPTs+Rj+8HD764jJPZD6haTJO6OPik6gjf5hXSFiGnfyuyTsYc8xzG7tpv BdofFlmmg52v+nla/bBcaXnzoDI83PLcSh//8rHmkqwyujH0my7liCFvB8yINUoCb3g+ GPYSc51Bnxbw3u38PGJrzrTlmvkFqM3G8rQqpZNIt1Ulic3hwcr6LWuYPN0c4YIm0bOD 74fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=eb/OD0+6kl6InPN48kdKyyt3Gl5DHdDbUpre2gx/ub8=; b=yg42u02IxDFJ6g4JmNcx1IgB8BOzx1yv39BKYlb/iOf7MpXdmnr7mO/l5P7lMRE81O xmltq/mU1MDe7lBFKgtxtHGUPFhv2o2AgSEpdybTSNyypaKpHbtJ3J1CIXbK8cZKtZaR bwgC/2MGP80K7Zi2kruCaxBaekVBfhREiKUrci7jD3kG08990AeOEUhxqjJ52LR9PVT2 HzxB3wZxsfShDe+GbMcZ+blyrIozevSH+0mcOTFg14YWAB8egCoH6rwN8WFixDx7iEkD 1PGuSuU2VthrrRUpXTJmf3UqDP6XMqzMBTIDO/xtgM3IMpmHNS84zvRgYTPm0Wwaom57 U7YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lb51xANn; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ok21si6899723ejb.95.2019.09.30.03.50.50; Mon, 30 Sep 2019 03:51:14 -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=@gmail.com header.s=20161025 header.b=lb51xANn; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730643AbfI3Ku0 (ORCPT + 99 others); Mon, 30 Sep 2019 06:50:26 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:46303 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729870AbfI3Ku0 (ORCPT ); Mon, 30 Sep 2019 06:50:26 -0400 Received: by mail-qk1-f194.google.com with SMTP id 201so7269912qkd.13 for ; Mon, 30 Sep 2019 03:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=eb/OD0+6kl6InPN48kdKyyt3Gl5DHdDbUpre2gx/ub8=; b=lb51xANnjO9r1cPtu4SXv42EwBy6ggxalzx1tjYFaEn8flT7hAbcDn0wOzcs99FfDk 6MqDlQs7Xtgtv97FDunjvbOq/y5bGijVG7mmN9RTlEOygmqlN0ow1hONEzvwrEmiwA3o J9o3i/3/BzQPKkiv+Rdt+GxcBWX2GXuCw++uc1xI4wDdnYDvRUk13uJOFWdMDWIPB7WD 5L/LUyuLcI/6I/HlT2vxsp2HQKebNH2To+Ib35CgIRa/eqpW7sUSba7X0V0piW3c/A9R jfZ1ohqEt5wCaTSiG/m3oa3upfrErOp53eAACRxA7JsUQQoPXDHpa0AIfV+NclyHQcEO QDyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=eb/OD0+6kl6InPN48kdKyyt3Gl5DHdDbUpre2gx/ub8=; b=h0WfuRgY33BwXkXTgj9Cks2MVUX0wM+jHxtfPokgUJoI7SOM8yGNAtFK6QkQvkpMKy /6f5DgrQgKUP5GqCHyL7QTU2J5NGQcY5Zrg+rxgYpJxkzMLCQL7ytUyO5F4WODqQAfsM Jmn381QB3EAgIEtZjwiGUwHvVcagBGZ303CMzkW39cQUyT3QesMdqWuz/X8EAWQeFPcB SaTNcdgPLi/cy5hD2+uZbKSUhRlLf/JQZ7TEWXyHUb+WW/99L9Pic0FO/heFpGw5GwIB xYYyt7C3nsMu9HkldJd4Y7oCAMW+UZxW2q9k3P55Dc6Q9D9X4NlCm9UQSMqhpJabsVGe Bf5Q== X-Gm-Message-State: APjAAAVO6rH5Kcob0ry9R8KSSnFrBse6GdPieh2MeGaO5QXtvxPApcUy mEi0h3RN+JzFwTSeWVKMkCEP8LnC X-Received: by 2002:a37:4802:: with SMTP id v2mr18089079qka.496.1569840625589; Mon, 30 Sep 2019 03:50:25 -0700 (PDT) Received: from quaco.ghostprotocols.net ([179.97.35.50]) by smtp.gmail.com with ESMTPSA id x59sm6754687qte.20.2019.09.30.03.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 03:50:24 -0700 (PDT) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 14A7440396; Mon, 30 Sep 2019 07:50:23 -0300 (-03) Date: Mon, 30 Sep 2019 07:50:23 -0300 To: Andi Kleen Cc: jolsa@kernel.org, linux-kernel@vger.kernel.org, Andi Kleen Subject: Re: [PATCH 1/3] perf script brstackinsn: Fix recovery from LBR/binary mismatch Message-ID: <20190930105023.GD9622@kernel.org> References: <20190927233546.11533-1-andi@firstfloor.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190927233546.11533-1-andi@firstfloor.org> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Sep 27, 2019 at 04:35:44PM -0700, Andi Kleen escreveu: > From: Andi Kleen > > 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. Thanks, applied. - Arnaldo > Signed-off-by: Andi Kleen > --- > 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 e079b34201f2..32b17d51c982 100644 > --- a/tools/perf/builtin-script.c > +++ b/tools/perf/builtin-script.c > @@ -1061,7 +1061,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); > @@ -1072,6 +1072,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) > @@ -1081,6 +1082,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"); > } > > /* > @@ -1121,6 +1124,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) > -- > 2.21.0 -- - Arnaldo