From patchwork Wed May 9 04:15:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 10388087 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 15DF660318 for ; Wed, 9 May 2018 04:16:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03AD728BB3 for ; Wed, 9 May 2018 04:16:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC54328C08; Wed, 9 May 2018 04:16:06 +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 9F33E28BB3 for ; Wed, 9 May 2018 04:16:06 +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=yxrPODmxEO+8rGThdSL8O3hfifxvvuV4qqrWGPDbYDQ=; b=sg1 ooVl+D/OTfhOPJswqQNpegY2U+Y0w7Dc2GaaQjG1hcKULPQ8ZJdzpm5fzW2jg51cUw1m/nd1kcYq7 kC/siScAf88PjEhxcTIudVo3wnEKgRcucaLzQ7ObOLIETPx8tb7Igwr50GQQt8ezds8RvdQM6g4Ll PIhy6s/b4xBxSr4zYSX6lZZag7S+mAWreBSti1dTtCjBNTAuNfGc6OB/ecMiOYM8uNZVBJNBkUceh o0rOg2IP0htbRaLwQ8oCVTx1krDf9gUjfUOK3dY3GScm8EZ/9LHdJkHz3Piwn3jK/V/uUZwDHBOb+ ozR7y7ut7AkixM+8D1fmmPKAAZuH25A==; 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 1fGGWG-0003JN-HD; Wed, 09 May 2018 04:16:00 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fGGWC-0003I0-5J for linux-arm-kernel@lists.infradead.org; Wed, 09 May 2018 04:15:57 +0000 Received: by mail-wm0-x242.google.com with SMTP id j4so22077774wme.1 for ; Tue, 08 May 2018 21:15:44 -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=Wum+rzdoXN+FHN2IKXvcJz2kTVf930y5axBnIVXgUj4=; b=Rss+uuNpbwulzodJp4Hr53RXSbcg/WPkoP98xHzFjkCddf5N0SmjdqBrCi/0cOHd0V aqKHJl3SjFVlzrKbf950zIYjypNVF5zQ3fFkHNqR4CUHDcVJ2+EGakt0JDyrU1lB3Lu1 htFDR/clcuKaql/pJy3DvxtHAl/vOxYYew3wI= 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=Wum+rzdoXN+FHN2IKXvcJz2kTVf930y5axBnIVXgUj4=; b=cmiZcLCyqr6xT+d1zG1MgJIx9RLxrnoq+FSCaAkqJLsVY7gXPdMoOuTMAuHI3Dt2H2 3IRFPaSjlslANyeJv3Rx76lHgq5CzN1Ug8uvOHyKPUzglXLpzDNM/lSNDyDrr/iBDS8S irNdY2gQVKWJIjpeEkQjEBIT8Er1ocMmLiMNw98i5cMmi3XhB6yvKL8rwiG9Rf7ZfA09 AtTz9GiY1joDVoRJ6gsBdZuDPoDXbpxRGv1tgh2LEbSXlLn7diu0WGqtUgcqHK2VzA6L K0nAGLIRy2od1jLmyStUme726vQaOqNUTVVEye5OM3JBZtJE9b0tVUCuTQsFixstNvxB v1eg== X-Gm-Message-State: ALKqPwd+FWkTwP8KugfKyd8vMGCtnB6dNkXQQCMLDP5VeyYHZ06U+XL6 PR751wV3wYadA7cmwlaobSgWj7zPfBA= X-Google-Smtp-Source: AB8JxZrOfq8BxSSCSJ4zCT0Nnvc+T1nRvSbcPABnO/LmDvR9TtvQBab8K6tTOlT4a1CpoEpF/lyYRQ== X-Received: by 10.28.109.144 with SMTP id b16mr4479953wmi.138.1525839342627; Tue, 08 May 2018 21:15:42 -0700 (PDT) Received: from localhost.localdomain (li1489-133.members.linode.com. [139.162.172.133]) by smtp.gmail.com with ESMTPSA id m35-v6sm27354849wrm.51.2018.05.08.21.15.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 May 2018 21:15: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 v2 1/2] perf cs-etm: Support unknown_thread in cs_etm_auxtrace Date: Wed, 9 May 2018 12:15:11 +0800 Message-Id: <1525839312-20544-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-20180508_211556_205777_6468BD04 X-CRM114-Status: GOOD ( 14.98 ) 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 | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 6533b1a..69f21de 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); } @@ -1355,6 +1356,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 +1387,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;