Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4323291yba; Mon, 29 Apr 2019 18:10:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIferTCh2TV+Af2UGbm9YLF2WMVl7PQS/q6yLq+gHORQcXWTfTU2ZgbZUviyAKtjtB0kzI X-Received: by 2002:a65:608a:: with SMTP id t10mr6346556pgu.125.1556586610593; Mon, 29 Apr 2019 18:10:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556586610; cv=none; d=google.com; s=arc-20160816; b=t0oNt2WzdWlAewf0ZjbKEAj6VysDCs24qUyvdG737aovRTmD3xE9hNArS0eTv6TVJ3 +9YlBrSqhkRl1O7MXxl0GsC+Ko5HMGo2RoHSYVQbEl6NHekw289rSDSyTYk3dQgzc8yg roA3MUO8cVRP58wBYUxG/laYIO8ax7tmhzwNXmqZSmWqNK9ERSN63lBLb1esatNfaB3X GnsWmZ4bIaKZksf2Q0o76WA2TT5dGSaIvb/KvRqfnm6MpD67y43Mn4ZVAjscaRASXlAG o0hd/t+/eBus/SG/Z4t54oYHuHFV4aPyfk054zKU3cVwiX0ny2Cvmh+UBJA5ArplsSJP jUOw== 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=Ii5I8j9JBuiHdsFz4/aqjjOUNbjy8Zm8aunVEplypu0=; b=wt3JkLS9EGvuaZUAEaqlKsc7/Fclx2zMRD8NRzW1lga2zBG9X1wUxDsOz35a1BTo2X HAn7w0uMMYflm036c8Gv6EfNbkD+Kj8+i0cTFVMOmFrsbULBZbr+80zddlhr6CGLdGSw 0rz+zqj2bnRY/T5Miw9bzbiOlSOl9K4kSb59sLohJB1P+/7MIrqTaYVb6TRHfhJUh2K2 jUp2zJBBJAnVdusoV0+wrYA8pG/gyYiKkFLXpOsKEN4pSGgJy4DqAaC7fstEUMoD3SG3 pUleC8CckJ+QrO6rAot1veIy54AXAxdGcQR4Uq2+B/xyaELw9Xstyla72dR7a0ZpwzEW suLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lRuJvOfX; 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 s189si19560739pgb.346.2019.04.29.18.09.54; Mon, 29 Apr 2019 18:10:10 -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=lRuJvOfX; 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 S1729761AbfD3BHq (ORCPT + 99 others); Mon, 29 Apr 2019 21:07:46 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:34871 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729238AbfD3BHp (ORCPT ); Mon, 29 Apr 2019 21:07:45 -0400 Received: by mail-yw1-f67.google.com with SMTP id n188so2114864ywe.2 for ; Mon, 29 Apr 2019 18:07:45 -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=Ii5I8j9JBuiHdsFz4/aqjjOUNbjy8Zm8aunVEplypu0=; b=lRuJvOfXBmlqyKzC+YU6LdcihtX/VukOFtrX/XxNSvN8jB66ULMjIHrrU48WK4b6yp Zc9EtVBB3WdryrYCq8OQ5iyEy7WaVma8eQ8G+vu7s6VkGbep5ZOajC34s9mpM6yizVS9 l95U/kl8uEDvieUoPU0h2UlibECMknJpC9dyxWJyp9VPNTp6ejvFKfY5us82Z7eh0A2M QPR+sFmFWT/gKdXTzIIU4veQAmGFZlaOr6WFlvMnQjtEXICnlL2R9l24HN2KO5huJlEy IICKtHuf5O+oUKgx7soqJTErkI32pWtu2xq+gNZ8B0pbuX9O/ZiqwUPdmt0zFTwDLwF4 FGNQ== 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=Ii5I8j9JBuiHdsFz4/aqjjOUNbjy8Zm8aunVEplypu0=; b=ryj5V0MhD6ofxr0v1U3PCgrqoOj8XNe4wLy60LaNVEV/Xgfp/+LmLDZre78FvGmAJF ZXknhR27KAal1LcPYnQ8j62Wx8HkEFAKuywfnGXvdE1ALUciuRjXPCWdb+6OJohI+wk0 6c/6FEp5ouO31LVUjLzjN52lXQ/ETUKsnYH7DwqzsIXD5VzfmLlf1lB9/vteDnDNH8K5 k8tAhSWYwr3u9at2Y6915on9nZkfWdkUWJ+3DAx/usxvXvj/kjq7r7Jr4CQQtsj/K7CB cGz75BTrIJcmi4qJzyKZ+xmF/nOtqWN5KnzeQC9YxB43aNKUQqb/6ufK83/9pewjBrZA yUhw== X-Gm-Message-State: APjAAAUOdi4+jE4t0eo5zq83zksGXk9yEaa6gwfNDID88JmgdTEFa7c4 r/z2lU/1th0b8s55kRoqnbSXIyU0 X-Received: by 2002:a0d:c9c7:: with SMTP id l190mr54943974ywd.181.1556586464548; Mon, 29 Apr 2019 18:07:44 -0700 (PDT) Received: from quaco.ghostprotocols.net (adsl-173-228-226-134.prtc.net. [173.228.226.134]) by smtp.gmail.com with ESMTPSA id 205sm3988886ywm.98.2019.04.29.18.07.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Apr 2019 18:07:43 -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 36DC44111F; Mon, 29 Apr 2019 21:07:42 -0400 (EDT) Date: Mon, 29 Apr 2019 21:07:42 -0400 To: Leo Yan Cc: Mathieu Poirier , Robert Walker , Suzuki K Poulose , Mike Leach , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 1/2] perf cs-etm: Always allocate memory for cs_etm_queue::prev_packet Message-ID: <20190430010742.GD7857@kernel.org> References: <20190428083228.20246-1-leo.yan@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190428083228.20246-1-leo.yan@linaro.org> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Sun, Apr 28, 2019 at 04:32:27PM +0800, Leo Yan escreveu: > Robert Walker reported a segmentation fault is observed when process > CoreSight trace data; this issue can be easily reproduced by the > command 'perf report --itrace=i1000i' for decoding tracing data. > > If neither the 'b' flag (synthesize branches events) nor 'l' flag > (synthesize last branch entries) are specified to option '--itrace', > cs_etm_queue::prev_packet will not been initialised. After merging > the code to support exception packets and sample flags, there > introduced a number of uses of cs_etm_queue::prev_packet without > checking whether it is valid, for these cases any accessing to > uninitialised prev_packet will cause crash. > > As cs_etm_queue::prev_packet is used more widely now and it's already > hard to follow which functions have been called in a context where the > validity of cs_etm_queue::prev_packet has been checked, this patch > always allocates memory for cs_etm_queue::prev_packet. > > Reported-by: Robert Walker > Suggested-by: Robert Walker > Fixes: 7100b12cf474 ("perf cs-etm: Generate branch sample for exception packet") Thanks, applied both to perf/urgent, testing them now in the containers. - Arnaldo > Fixes: 24fff5eb2b93 ("perf cs-etm: Avoid stale branch samples when flush packet") > Signed-off-by: Leo Yan > --- > tools/perf/util/cs-etm.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c > index 110804936fc3..054b480aab04 100644 > --- a/tools/perf/util/cs-etm.c > +++ b/tools/perf/util/cs-etm.c > @@ -422,11 +422,9 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm) > if (!etmq->packet) > goto out_free; > > - if (etm->synth_opts.last_branch || etm->sample_branches) { > - etmq->prev_packet = zalloc(szp); > - if (!etmq->prev_packet) > - goto out_free; > - } > + etmq->prev_packet = zalloc(szp); > + if (!etmq->prev_packet) > + goto out_free; > > if (etm->synth_opts.last_branch) { > size_t sz = sizeof(struct branch_stack); > -- > 2.17.1 -- - Arnaldo