From patchwork Thu May 10 04:01:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 135385 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp523639lji; Wed, 9 May 2018 21:02:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr3oL0K9A0FLvqe5m2FoWKvyoFOuEeWehNtFywbH1hduDI9fd8VsZt6Uk7mCF7bqMChd0OJ X-Received: by 2002:a17:902:8d85:: with SMTP id v5-v6mr33059814plo.93.1525924949301; Wed, 09 May 2018 21:02:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525924949; cv=none; d=google.com; s=arc-20160816; b=vzmNvqyE7t9BBx9ox5NGWjoNo4nnn22xzb2K4iIxOBNT3K3pdQqPcDkgapDNpLkT9f 9gYPhGpZWiZhBYCc8mhUt1x/4wXPSIs6oFCgH/TIM+sXdyYORzkDIm7SikJflEA6oBwn AFRkD4Y8bIELUS84cZCPceCcD1iAWpJGQX1rttjeCbRPNkQVbPr9JmImmhyB/OdUkUZ7 C6znS74QuWGY7jgRoLT24AkqNs8itvdGSELtbjgi6JpEp231n3CScWtXpdSL8sbS24BY UVubAgcIkh51f5PYkVD2PdX7yEXMciW9VOQvW7sjosCTOsVwEHAHXk4jeQZQWAI69N9i fhag== 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:arc-authentication-results; bh=Wum+rzdoXN+FHN2IKXvcJz2kTVf930y5axBnIVXgUj4=; b=H8U36QV72kxL+Uopuryc6d7RdHWtGiCfNKE5bJ3v8NaU1J+tMAe2RM6YkSxnboqLzt XNZ2LCBnMyR8XZwjmaXddmvu6WdgdjC4RiOgi+ac+gIrWfBa4KBjXNkE6FMiK1ywaKJ6 wOxWIiQOWOoF9a41zcIAUJEj3h52QnYDqGp8cWtb32onc2OQ/tn38YfjCh1la1l72fU6 TcgdmKdjp7x6WaIHMaOxJdrrgQJp2IBu1Z4oMXwswuX3j6Rf4pnh+fTeyr6/OGyi7VNt fzVsvv2dIVshj7DDCmpkTzY/yaVpFcL/eJGcsXlPKD1OScnNRkY3jZu7b910I+X9sVws 8KHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CiQZuxn0; 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 z86si28612961pfa.120.2018.05.09.21.02.28; Wed, 09 May 2018 21:02:29 -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=CiQZuxn0; 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 S1751219AbeEJECW (ORCPT + 29 others); Thu, 10 May 2018 00:02:22 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:40654 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750711AbeEJECV (ORCPT ); Thu, 10 May 2018 00:02:21 -0400 Received: by mail-pg0-f68.google.com with SMTP id l2-v6so364918pgc.7 for ; Wed, 09 May 2018 21:02:21 -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=CiQZuxn0nN1gDbh9BxeZzDrV2Ksna/f1hsgknWaWv6TQ0DT4fk3pXcAxfaW8C6mV2f o4MmIBxPfQFr98YZSaH2bcV3QxGyhKLcDtEk623y133hTmr+Er3DTcSQlV/d+RD1DklJ WIbxgdlxRxLiaWOmC8G/2pYAfKXK3ibrASLbA= 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=Chwsk51HH9Ternjh7cBI9AjOYWT/I2ZVoJT6P14mjAdljFd28mMdLRDv2cCfY3Xlds Okdlb+7oxECn7FpjOFR9esHNRPSlxp4UI5d2sb3fORDkRd+8+l+v3JnGxTX/OW0KatU/ kxCJ/XyIR7bzP7y+r8NdqDLK3G9ejTiUJox59RXM+k3E0p+INQ+6aHdroiE2i/KfSKUE v2axtoc+7n12qGGhpWu0otNw8dEln5O0SIMddMtqAHjKKncFW+Nefi8K5IY47X0wHGvK 3RVBLz8Kl0+B/j2bnVfD5w/zELvDfUzz9qU6Te2VVRamCUE41kVtb0BtZQ5Rd2i2/f4E faWA== X-Gm-Message-State: ALQs6tD31zlfC36dMGS/GwlYm5bKNSycz+JNpm3XYBixh4s44Q4xWbuX MnY3WeziR3SysBg7/FGJv1MXE/KVtZw= X-Received: by 10.98.236.24 with SMTP id k24mr46264844pfh.204.1525924941023; Wed, 09 May 2018 21:02:21 -0700 (PDT) Received: from localhost.localdomain (li1168-94.members.linode.com. [45.79.69.94]) by smtp.gmail.com with ESMTPSA id p71sm65694877pfl.170.2018.05.09.21.02.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 May 2018 21:02:19 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH RESEND v2 1/2] perf cs-etm: Support unknown_thread in cs_etm_auxtrace Date: Thu, 10 May 2018 12:01:59 +0800 Message-Id: <1525924920-4381-1-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.7.4 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;