From patchwork Thu May 3 15:18:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 10378633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B13D260353 for ; Thu, 3 May 2018 15:19:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A27C328A71 for ; Thu, 3 May 2018 15:19:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95B1E28FB0; Thu, 3 May 2018 15:19:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1265C28A71 for ; Thu, 3 May 2018 15:19:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=Xb1IU4VzXRgeHkVMQu+EddbMt48STl/KDtEi27sqhF8=; b=k97 hH2DlL3DzT6SXbQ3Nfa++AyRKBwcdZ8dlbfvXVyw85+uONEMy183J1KbNmSIC6h47xbIeI8S7w/wX lLrSsxTWvWbSLgzacI0hF4LQrPPBby5fz40/WQ8KG0eND2pbsjcqumD5eE/+0EUMUTD/77iH4xavT KzAD550VQuqVvCLpV9urAyyqqdLep8bcn9Xa5Fwwl3yE1YI5jZjj5kuV6VoirLroKsZQNxHDktcPn YkOwS0peSLM8w3kzzWQ6Lla94SWfm7/2PPTf2Ay13fLpJDsNCgL0Tvw59e8Vz+pDoXHeFyaZDhSFt w1tuaW7pt1u11JYUi9HdexpHsiXDmrg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fEG0X-0001Yz-EZ; Thu, 03 May 2018 15:18:57 +0000 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fEG0T-0001VW-9P for linux-arm-kernel@lists.infradead.org; Thu, 03 May 2018 15:18:54 +0000 Received: by mail-pg0-x241.google.com with SMTP id p9-v6so10456654pgc.9 for ; Thu, 03 May 2018 08:18:42 -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=9el/zCbBYWuz7WTle5ZIkHG1G3bV4ZvnWaPs3uJjg28=; b=AlQrT77LlbCulj3/DNxP/Th1Hef7vzV8/++cAk4y46O0n0Q1YX+EPFJ26jTLl03Ez+ zejqoSL7CpteFsok3hXalFHxJouk3pb2ZIITzHdSkqnjEG2qZkB7Wi4+3W9DkauPonbG 3da3V+6VQ3+sDlTwsE8Z/QDYm06OemlAR7qmk= 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=9el/zCbBYWuz7WTle5ZIkHG1G3bV4ZvnWaPs3uJjg28=; b=VzVSJFbete5NVTawLwNxg4nh8P3irrvC6tUqRPkSzfiANzfLrJfs8eZOnZRbUOjnlA agr0wp58U3QoPNndBFVkIRefSaBvVxrQaTnDwR7hcs1G7L2XIAVhd7TVvFUUC1+Oskyw P9t8QA8iYf5SJPkQJpWh0KC9rVxF4zGsAoOzhZYD/eiEptYCxRM1A0r7xwiyFtWIijUO DqV6Rg+JO9yVIFpMv7sniTBeyPxfS3KtZZhqFoRVU8t7wE44hcRc1C1ajOvz8PVXz7s4 3YWPDIVTvOlE2138tpiIVxrMuRrX68Q7gLcPdsjKI8NLANac/odsZKez7Yx0Mmcz8m8q G2Sw== X-Gm-Message-State: ALQs6tAeoaBjEq84Dv2CTSaWeOt97swn1typH1xJJKLkzz3i7JYqLR2Z N08E+ZXsHMUuRbYeD0QQIN9jQQ== X-Google-Smtp-Source: AB8JxZruLGpwlTHLzkosggcV+Ar8l/IashJMWCcaG/W/3VgMfI0ckr5x3YP/FfYXQkMNCTtFp58zhw== X-Received: by 2002:a63:7114:: with SMTP id m20-v6mr19653789pgc.144.1525360722217; Thu, 03 May 2018 08:18:42 -0700 (PDT) Received: from localhost.localdomain (li1168-94.members.linode.com. [45.79.69.94]) by smtp.gmail.com with ESMTPSA id x5-v6sm18134192pgv.15.2018.05.03.08.18.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 May 2018 08:18:41 -0700 (PDT) From: Leo Yan To: Mathieu Poirier , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org Subject: [PATCH 1/2] perf cs-etm: Support unknown_thread in cs_etm_auxtrace Date: Thu, 3 May 2018 23:18:22 +0800 Message-Id: <1525360703-26159-1-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180503_081853_346628_71B358BD X-CRM114-Status: GOOD ( 14.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP CoreSight doesn't allocate thread structure for unknown_thread in etm auxtrace, so unknown_thread is NULL pointer. If the perf data doesn't contain valid tid and then cs_etm__mem_access() uses unknown_thread instead as thread handler, this results in segmentation fault when thread__find_addr_map() accesses thread handler. This commit creates new thread data which is used by unknown_thread, so CoreSight tracing can roll back to use unknown_thread if perf data doesn't include valid thread info. This commit also releases thread data for initialization failure case and for normal auxtrace free flow. Signed-off-by: Leo Yan Acked-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 6533b1a..417302c 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -239,6 +239,7 @@ static void cs_etm__free(struct perf_session *session) for (i = 0; i < aux->num_cpu; i++) zfree(&aux->metadata[i]); + thread__zput(aux->unknown_thread); zfree(&aux->metadata); zfree(&aux); } @@ -266,6 +267,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address, if (!thread) { if (cpumode != PERF_RECORD_MISC_KERNEL) return -EINVAL; + thread = etmq->etm->unknown_thread; } @@ -1355,6 +1357,23 @@ int cs_etm__process_auxtrace_info(union perf_event *event, etm->auxtrace.free = cs_etm__free; session->auxtrace = &etm->auxtrace; + etm->unknown_thread = thread__new(999999999, 999999999); + if (!etm->unknown_thread) + goto err_free_queues; + + /* + * Initialize list node so that at thread__zput() we can avoid + * segmentation fault at list_del_init(). + */ + INIT_LIST_HEAD(&etm->unknown_thread->node); + + err = thread__set_comm(etm->unknown_thread, "unknown", 0); + if (err) + goto err_delete_thread; + + if (thread__init_map_groups(etm->unknown_thread, etm->machine)) + goto err_delete_thread; + if (dump_trace) { cs_etm__print_auxtrace_info(auxtrace_info->priv, num_cpu); return 0; @@ -1369,16 +1388,18 @@ int cs_etm__process_auxtrace_info(union perf_event *event, err = cs_etm__synth_events(etm, session); if (err) - goto err_free_queues; + goto err_delete_thread; err = auxtrace_queues__process_index(&etm->queues, session); if (err) - goto err_free_queues; + goto err_delete_thread; etm->data_queued = etm->queues.populated; return 0; +err_delete_thread: + thread__zput(etm->unknown_thread); err_free_queues: auxtrace_queues__free(&etm->queues); session->auxtrace = NULL;