From nobody Sat Feb 7 17:48:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59B23EB64DA for ; Mon, 26 Jun 2023 16:11:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231723AbjFZQLS (ORCPT ); Mon, 26 Jun 2023 12:11:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231191AbjFZQLN (ORCPT ); Mon, 26 Jun 2023 12:11:13 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9A235E58; Mon, 26 Jun 2023 09:11:11 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6774A13D5; Mon, 26 Jun 2023 09:11:55 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DF9653F663; Mon, 26 Jun 2023 09:11:08 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] perf cs-etm: Handle per-thread mode on EL1 host kernel case Date: Mon, 26 Jun 2023 17:10:57 +0100 Message-Id: <20230626161059.324046-2-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230626161059.324046-1-james.clark@arm.com> References: <20230626161059.324046-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In per-thread mode there are no context packets so no way to determine which type of context packets exist. But because it's only possible to trace host processes in per-thread mode without context packets then assume host in this case. This fixes the per-thread test case failures when running on nVHE: 98: Check Arm CoreSight trace data recording and synthesized samples: --- start --- ... Recording trace with '-e cs_etm/timestamp=3D0/ --per-thread' Looking at perf.data file for dumping branch samples: CoreSight basic testing with '-e cs_etm/timestamp=3D0/ --per-thread': FAIL Recording trace with '-e cs_etm/timestamp=3D1/ --per-thread' Looking at perf.data file for dumping branch samples: CoreSight basic testing with '-e cs_etm/timestamp=3D1/ --per-thread': FAIL ... Fixes: 8d3031d39fe8 ("perf cs-etm: Track exception level") Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 1419b40dfbe8..85821cc5650e 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -900,10 +900,17 @@ static struct machine *cs_etm__get_machine(struct cs_= etm_queue *etmq, =20 /* * For any virtualisation based on nVHE (e.g. pKVM), or host kernels - * running at EL1 assume everything is the host. + * running at EL1, or no context IDs (per-thread mode) assume everything + * is the host. */ - if (pid_fmt =3D=3D CS_ETM_PIDFMT_CTXTID) + switch (pid_fmt) { + case CS_ETM_PIDFMT_CTXTID: + case CS_ETM_PIDFMT_NONE: return &etmq->etm->session->machines.host; + case CS_ETM_PIDFMT_CTXTID2: + default: + break; + } =20 /* * Not perfect, but otherwise assume anything in EL1 is the default --=20 2.34.1 From nobody Sat Feb 7 17:48:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D59B2EB64DC for ; Mon, 26 Jun 2023 16:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231770AbjFZQLV (ORCPT ); Mon, 26 Jun 2023 12:11:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231737AbjFZQLQ (ORCPT ); Mon, 26 Jun 2023 12:11:16 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A87A5E53; Mon, 26 Jun 2023 09:11:14 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68E00143D; Mon, 26 Jun 2023 09:11:58 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D39D63F663; Mon, 26 Jun 2023 09:11:11 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/2] perf report: Don't add to histogram when there is no thread found Date: Mon, 26 Jun 2023 17:10:58 +0100 Message-Id: <20230626161059.324046-3-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230626161059.324046-1-james.clark@arm.com> References: <20230626161059.324046-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" thread__find_map() chooses to exit without assigning a thread to the addr_location in some scenarios, for example when there are samples from a guest and perf_guest =3D=3D false. This results in a segfault when adding to the histogram because it uses unguarded accesses to the thread member of the addr_location. Fix it by exiting early if no thread is set. This fixes the referenced commit when using perf report with Coresight but probably isn't exclusive to that case. Fixes: 8d3031d39fe8 ("perf cs-etm: Track exception level") Signed-off-by: James Clark Acked-by: Ian Rogers --- tools/perf/builtin-report.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index dcedfe00f04d..1a2caa4ce5c3 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -293,6 +293,9 @@ static int process_sample_event(struct perf_tool *tool, goto out_put; } =20 + if (!al.thread) + goto out_put; + if (rep->stitch_lbr) thread__set_lbr_stitch_enable(al.thread, true); =20 --=20 2.34.1