From patchwork Sun Apr 28 08:32:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 163001 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp585281ill; Sun, 28 Apr 2019 01:32:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8ZBpSsoGe8ChtUyQOwnvzPvWniIZqdfNdRlaP/1XfPPt6VHbtq/p+yZP3wW3trWiKJyOb X-Received: by 2002:a17:902:a5cb:: with SMTP id t11mr26606387plq.268.1556440375674; Sun, 28 Apr 2019 01:32:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556440375; cv=none; d=google.com; s=arc-20160816; b=IN6uHUoG6ZirA0vgGZeyCRO/sxE5eCnkcEBhkbv78gLFaw20Vz0laNT7qgvGr1IRUv poZrL6CA+eXzpKBbNpT1ayP83Zs7XoEUAqUFNNk6qOoflwfJlG49/xX+U0GIdxQ5mQqN 6YHhNyXnxAy23WUjUMDHjmyDSswRR0x35YZ8uX+HsxJBDeWbTZ1SWQi4brrZtbICBHbF +hseAzulnx3X0Lcpt/i1RR/e0kydeb/u3FCx9CPCdyYzI/H1uaCr4lvGqCZybXUxcvr7 nf7dEM9wD3mDRWyQUMXa1+pmCK63JOtWhxVmg93Ub7w2NZWprEk+UVSfZZKlf/uP127w sEUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=BZzKmMo+qjjyommvsHqCKRlBwkTvNOIM1AtqhVGSBu8=; b=V+H6m+sKV5xRF/TIlkKptzkKXwYpSsYTTI6D0ghbbPKOcKot0h12fGQZCkUiTo7Y2A PmY7Glb+c2CXKfaYLX6xKj6coTfit4lfc5MB0X4BBv8CTuUyd5mYU046t8p13dzw/uq9 NHWgSOZjcWmyBs5H2ftAGrr+9WINBlordKwxilnYXNq1HG/FdfzryiH+d7KmhCtXnUvn cYBDvex6+6QzpDShOLHoceYUTx7H/3AEaYAgaZ5kbu/Ag1mTSKRCsH9yeJuC1jUKNlwe VTYs8N1zYYOZo0iUmXzK+ojM7te/5kOeCVZ9CS8ECwgC8vTh8/3Es7e8pQijlSfNs9Lb 7nsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wu5QE43+; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si5403968pgj.491.2019.04.28.01.32.55; Sun, 28 Apr 2019 01:32:55 -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=@linaro.org header.s=google header.b=wu5QE43+; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726622AbfD1Icr (ORCPT + 30 others); Sun, 28 Apr 2019 04:32:47 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45339 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726466AbfD1Icr (ORCPT ); Sun, 28 Apr 2019 04:32:47 -0400 Received: by mail-pg1-f195.google.com with SMTP id i21so229856pgi.12 for ; Sun, 28 Apr 2019 01:32:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=BZzKmMo+qjjyommvsHqCKRlBwkTvNOIM1AtqhVGSBu8=; b=wu5QE43+AeRJsCx5EsAFQ2WNN/6Pa5OHvDpSZUE3LqXCoegpmt5xwl2xMcIjZK1a8f JN1e575Y97uYNyL/D011tx6b8xfVBhZ1AE24pACltyswm1WgB1S6WztEKBL7XqoBiyER Fvhnt93SyMNVKo7wFuP8flLqfsi0O7HvOlyCBz5MxU7YoqWszzaVlNDYo1wWaSl9VECs mkj8mQZnB0Jy89/+wy8e6XXq2eeRmk2nIKe0Uu/xVMO4/q9o8tdGC5x+s9sSKCv7Bh2n ofJSPaSUV4jcfr2NyGPC/Gp8LGRwRljm3XrvOTPW5Y1+OTXNF1ptQkkubjadVG3vhCak Gk5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BZzKmMo+qjjyommvsHqCKRlBwkTvNOIM1AtqhVGSBu8=; b=sKA9ZB158YLg/hYdLP67JJWTKolfdt4/x1wC+91hJeyxAf2+T3OSA4uWFwRjhBGIvA T7YMTsF7XYgSElicdN+EU2WjcwtVqnaoEYJbKEPSQoZnPEBjq2dTtermYQIsi0XVt6B7 xaRBkCfpfF3Jj9sXDdW0ucioHaNtV/KuYjx/sG4HvB0SljjXMWowQxesbgwpB/Zdahdd 0S3AZ0omVRoWDqn6Kk866Hfc1YyC668XAkmYT3tedUN/ZE/5vH4Qez8n9oWhz4GaP7G3 WEpdHqDgU8Wy0c/ipe6nK/kuhiE0sGvaN8Sjb2Fy7RmwHucy5Hs0Qb+B/ZXdWgy+9ezr p+Sw== X-Gm-Message-State: APjAAAXZs/uuhaVBO4vslDmKQQId0SQa8AKegeYNKj7mKyqF3904Lkoa Ft2Pg/eeyjw6y/Fq0+6EdTOWOg== X-Received: by 2002:a62:2fc1:: with SMTP id v184mr24439025pfv.258.1556440365813; Sun, 28 Apr 2019 01:32:45 -0700 (PDT) Received: from localhost.localdomain (li990-117.members.linode.com. [45.33.40.117]) by smtp.gmail.com with ESMTPSA id a12sm31960518pgq.21.2019.04.28.01.32.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Apr 2019 01:32:43 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , 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 Cc: Leo Yan Subject: [PATCH v1 1/2] perf cs-etm: Always allocate memory for cs_etm_queue::prev_packet Date: Sun, 28 Apr 2019 16:32:27 +0800 Message-Id: <20190428083228.20246-1-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") 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(-) -- 2.17.1 Tested-by: Robert Walker 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); From patchwork Sun Apr 28 08:32:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 163002 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp585289ill; Sun, 28 Apr 2019 01:32:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLaiyAUg2jut7G2USyCkvGtKAuwtypKN070JTSfrJu5NIHpMuO5T9fGSWcTDNS/mB/pnO5 X-Received: by 2002:a63:318b:: with SMTP id x133mr4040432pgx.297.1556440376058; Sun, 28 Apr 2019 01:32:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556440376; cv=none; d=google.com; s=arc-20160816; b=mv5ZxMaa+ALL9NhofrYfPqR56qIK5TJNSuNw1AtEAZq1KZp0/IzII4lq8wFRvtfDQ/ egzwYCgmZ4fYZpD0nIRP3m8bgYEBboOdWCuyBPHo3dg+iSSmlaURgsIvemHGB+nqRGhQ xz0ciztH5UqBpissW9eghDtJm+5h3zlIPEJK3xuGXU42Nz/aLf4tu7obnLnATrR2fNtu jTo4EEwmwZpYZxusNK5mjP5+gVx6biBxL/0DtP81b1agQm1KZcKTS6tGHgt65KV3r88T 44FcXfp7v9EwrUfDM3ggwr1b0epvX32jgYj3pmxde7xvDXsG3wmyW8IneE/zZtr4tB2D kbtQ== 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; bh=za5L9TH7RfVFEUEVo+b+Xe+/+fVMc7D24YekrWmKylM=; b=lFuSCK/bXjjg8jVXLVoS1seU3bb5IVVKZbi0zZoJldMLiAJAuaef+u1RAiUeCn0Lh+ whX3e2FcRf6tEELEznUGaPQ37+5HcOjag8PTM1lFyCXTU+DO6f/BIHZNAGQMiCMMEvhZ ciflBW5OYJ7zX0ef2fzagBqGwg9o60nsJyge/mc5Z25x0Y1KFoiQPVtVXtuKKvT6YBB/ hULsTBwDw53zIV1l9Maaavi7Ou8o1hxA5XoEx924U8UyuXYOAZYBylIhHqVGp0W96wcZ KyV9a2eJ+n/Cxi18nERqXgKHUR5kYAF91h63S572rYLyhVLVN8qWSJnJoQBcUCw8d0JP kjjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aJgC+ktE; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si5403968pgj.491.2019.04.28.01.32.55; Sun, 28 Apr 2019 01:32:56 -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=@linaro.org header.s=google header.b=aJgC+ktE; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726659AbfD1Icv (ORCPT + 30 others); Sun, 28 Apr 2019 04:32:51 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:45154 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726466AbfD1Icv (ORCPT ); Sun, 28 Apr 2019 04:32:51 -0400 Received: by mail-pl1-f194.google.com with SMTP id o5so3598680pls.12 for ; Sun, 28 Apr 2019 01:32:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=za5L9TH7RfVFEUEVo+b+Xe+/+fVMc7D24YekrWmKylM=; b=aJgC+ktE44qrl5zRP84bJJagrrWxh9plDl7AkXkHZjy0goL6aE1PC0dJYg8ZIvnA3A +SeyCgowcSpuVPm2b9an/EFpBwk1uP/QHaXT5n52kcAGYzziXy0YkvRcsDyz8H+CfFbr ARKRvaIPlHZRQfSy8uk9CSGNt7SLbRYo7XvYq0VivFYyPJhV25nxCS00wim2Y7zX9gmf gXf2OFzrhB2a4KBUJM4+rvcyd0pR12w9B2PGqTlVn6cCE4sm2milmo2T4qD2MJ0iL8Es gdxhlXGn+yM+Lp1h4XB/anMSlFNO+o/GyoIfF7BfHta7+AQ0OEEtOeTsLF9xVvd3oMUB RByQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=za5L9TH7RfVFEUEVo+b+Xe+/+fVMc7D24YekrWmKylM=; b=NwLWv/vVf0xddT5ek78MyHEr54sMgj/SqbcPCvRDsWjwxUNvvyfJXUudNspOubEXDX 2CsRqqW+Fym5g7LQfQaLeviw3OgwmsYiUqi65CjYtTDSTwxvAGU+U2jYWP5IrbJhTjUQ OR8NaN/90mxP5J9jJTe86rc75ci8CJoqXHJGTmKu45UUVQmTQAfIsAUk8egqp6jCAlmv yaHx7UiH0XFwuToTJ5PWEiy3K6dPnCrnTvkd2Qr2SOc1EvFhaGUJqn0QWlEXk7S27hU3 5Vr6FALY1IbXbC/JoGuP3ZZ3AW0/QDo837N6D1EHzUXj2u01HgQt2zB8WCpqbaP71fLT X/pw== X-Gm-Message-State: APjAAAXw8wxzWu3yfnM3lakmTRJWZgw3VWUK2WetoCqi+3QS6QsiTbjC qd/jzZzrZqMBc1mmcIEiBTYuTQ== X-Received: by 2002:a17:902:1103:: with SMTP id d3mr17956465pla.247.1556440370534; Sun, 28 Apr 2019 01:32:50 -0700 (PDT) Received: from localhost.localdomain (li990-117.members.linode.com. [45.33.40.117]) by smtp.gmail.com with ESMTPSA id a12sm31960518pgq.21.2019.04.28.01.32.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Apr 2019 01:32:49 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , 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 Cc: Leo Yan Subject: [PATCH v1 2/2] perf cs-etm: Don't check cs_etm_queue::prev_packet validity Date: Sun, 28 Apr 2019 16:32:28 +0800 Message-Id: <20190428083228.20246-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190428083228.20246-1-leo.yan@linaro.org> References: <20190428083228.20246-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since cs_etm_queue::prev_packet is allocated for all cases, it will never be NULL pointer; now validity checking prev_packet is pointless, remove all of them. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) -- 2.17.1 Tested-by: Robert Walker diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 054b480aab04..de488b43f440 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -979,7 +979,6 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) * PREV_PACKET is a branch. */ if (etm->synth_opts.last_branch && - etmq->prev_packet && etmq->prev_packet->sample_type == CS_ETM_RANGE && etmq->prev_packet->last_instr_taken_branch) cs_etm__update_last_branch_rb(etmq); @@ -1012,7 +1011,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) etmq->period_instructions = instrs_over; } - if (etm->sample_branches && etmq->prev_packet) { + if (etm->sample_branches) { bool generate_sample = false; /* Generate sample for tracing on packet */ @@ -1069,9 +1068,6 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) struct cs_etm_auxtrace *etm = etmq->etm; struct cs_etm_packet *tmp; - if (!etmq->prev_packet) - return 0; - /* Handle start tracing packet */ if (etmq->prev_packet->sample_type == CS_ETM_EMPTY) goto swap_packet;