Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3660764rdb; Wed, 13 Sep 2023 21:02:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGCGnGusbarcyBH354HImci9/PMK4rBOuU8tvf5HaJG1d94bJEf9wlUaBprHVJFrcxh1JWx X-Received: by 2002:a05:6a00:2d8f:b0:68f:dd50:aef8 with SMTP id fb15-20020a056a002d8f00b0068fdd50aef8mr5157833pfb.4.1694664147565; Wed, 13 Sep 2023 21:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694664147; cv=none; d=google.com; s=arc-20160816; b=ROaIjaVG+7slxpzfDIj6BTeKv8H9w9nscGXC1ehS0G/OhItqL997Z7mpnSEmXEvO8U zI0ku48ZWAerw2mgVXsJND6Ge3V3l7Bpvf/f8rQjpFoJJYqdwzWEZefMROqAQslIJ3Yn eHR9vGRyP8sJSyxW0xNWjb5qqUYY3xEkWDb12T7G4boKpKzt4qTOafz62HR9w1JnwS07 2FsfoRyQKhpWyebrlURPxFByQf0UiGSqceLWbGHLIkloRxckndk6cFFV7Mc0DwF6ZuHU JabNb98wGfH0YZYCNNsF7AUKR/5J/BydNQEnYJ1jvyxZcYsidmpjBWL75t3r9Ykt1+B+ bbsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=DpztZBQJl10oqU07wK0IFzN+LLamje8BENXZn/FkHvA=; fh=WTLFJkc8R2SZN6rtxM+UtHhPbUb5jftZwG9G0kRG6dQ=; b=iXcwy6Kz9B65UWwjESj0A+16/YFx7ITvt2P9Q4l4+Msw+QAzbRiQq79skPZteihKUl m/AH0i4C6GLiyWFIYZtzGGJs/7X3tnFGQYZGBfZDf1lpvBH9Wjsb7ewAfA1rkuC/SBQb 9bh0tb4LhwRVwumcjSulnrJDW0zr0uGx1K4RuAEebpAspjMW/vqN7d/0ZAVPcXcDP8uF cVXy+6+hT1dRQeq8ryfNx78iBWve/f2iacAxVBMsUScJgyavFkO3yqWceslDpQV87Wmb poldO5iW3IPklltfMbYqSzBqoB39LiDHBdEDNHNKZ9cM70Y4H4Wc1YpbaJjNCGz9My7a c3Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eFlf0Vfg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id x190-20020a6363c7000000b0056f81e7418fsi617331pgb.551.2023.09.13.21.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 21:02:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eFlf0Vfg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3E4708028872; Wed, 13 Sep 2023 09:31:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229468AbjIMQbt (ORCPT + 99 others); Wed, 13 Sep 2023 12:31:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbjIMQbs (ORCPT ); Wed, 13 Sep 2023 12:31:48 -0400 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BECE919A8 for ; Wed, 13 Sep 2023 09:31:44 -0700 (PDT) Received: by mail-il1-x12a.google.com with SMTP id e9e14a558f8ab-34df0f0a5beso705ab.0 for ; Wed, 13 Sep 2023 09:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694622704; x=1695227504; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DpztZBQJl10oqU07wK0IFzN+LLamje8BENXZn/FkHvA=; b=eFlf0VfguD9/Yi2hXCPcn0IBj01XvuunXpGNEwPrk5EYZyVlO7JdFWaBhJhEE/R0q0 cspg+EPQZUX9ZyNxQCcYe0IUJ/+GKVW7WaALLOLWs0wSYqiNMrL0rfYH5MrFDjt8ygiz A8yWOlNwo666KO9DdA0tn23DrjVFX9nyPVa5l8gMVBnPkSgS4m22cMym8LHA75ywVoE4 w5EjZvARORDKG2v77Grm1g/iP0beNj/a02LgyTvXpEhdWF5voAxFE13omWUY3r1jPRTy wEBI9cZe5nujr/ZjJoqtnSLR6hIPWFSrcOfaJAyQ1fp1D9Q+ZAZJLlQAuLPcGFFPSJ9U Hydw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694622704; x=1695227504; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DpztZBQJl10oqU07wK0IFzN+LLamje8BENXZn/FkHvA=; b=Oqz1l6qxQoI7E46+au9RSFxyV+u4RfFp5lHeBIBfbFF4NfwjyzWBFqc/yIqbcdDm1o r7zFcI6PPtWH/AVDnHOpSfLJp/NDP9eE8Zq9DzgxwpiRb30tRgI2z6VF89c3/HbLy7Xw k+CAMgbxQO3tq5eu4QcjmRRRaROp9/eW1DYbtJbx9h2VZKqifaMT6jfdsVVJX/sankHo zMhYD/HliB6yLXZZfmD/giiRTrAyM5g4Oo3rugyhAyTkKkWy3ysj9aaCKc0osUTbdKtm LTMj8O1q6JCI1FzIi+0edBwfrwhNzKRkkX/1G+aox0eUvx9zBvW+aEOjweZfosBnBzfS KlOA== X-Gm-Message-State: AOJu0Ywt5VjXDHLVnS5SqJ2Rv0BQTK/UspP8Bg2W0AENj+EOqec43lvF qZu99PDICsY8/tkYc2OYcwN/juIFuXPazB3Ra34Rig== X-Received: by 2002:a05:6e02:12cd:b0:349:3dd2:3cf1 with SMTP id i13-20020a056e0212cd00b003493dd23cf1mr207318ilm.23.1694622704010; Wed, 13 Sep 2023 09:31:44 -0700 (PDT) MIME-Version: 1.0 References: <20230913125157.2790375-1-tmricht@linux.ibm.com> In-Reply-To: <20230913125157.2790375-1-tmricht@linux.ibm.com> From: Ian Rogers Date: Wed, 13 Sep 2023 09:31:29 -0700 Message-ID: Subject: Re: [PATCH] perf jevent: fix core dump on software events on s390 To: Thomas Richter Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, acme@kernel.org, sumanthk@linux.ibm.com, dengler@linux.ibm.com, svens@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Sep 2023 09:31:52 -0700 (PDT) On Wed, Sep 13, 2023 at 5:52=E2=80=AFAM Thomas Richter wrote: > > Running commands such as > # ./perf stat -e cs -- true > Segmentation fault (core dumped) > # ./perf stat -e cpu-clock-- true > Segmentation fault (core dumped) > # > > dump core. This should not happen as these events are defined > even when no hardware PMU is available. > Debugging this reveals this call chain: > > perf_pmus__find_by_type(type=3D1) > +--> pmu_read_sysfs(core_only=3Dfalse) > +--> perf_pmu__find2(dirfd=3D3, name=3D0x152a113 "software") > +--> perf_pmu__lookup(pmus=3D0x14f0568 , dirfd=3D= 3, > lookup_name=3D0x152a113 "software") > +--> perf_pmu__find_events_table (pmu=3D0x1532130) > > Now the pmu is "software" and it tries to find a proper table > generated by the pmu-event generation process for s390: > > # cd pmu-events/ > # ./jevents.py s390 all /root/linux/tools/perf/pmu-events/arch |\ > grep -E '^const struct pmu_table_entry' > const struct pmu_table_entry pmu_events__cf_z10[] =3D { > const struct pmu_table_entry pmu_events__cf_z13[] =3D { > const struct pmu_table_entry pmu_metrics__cf_z13[] =3D { > const struct pmu_table_entry pmu_events__cf_z14[] =3D { > const struct pmu_table_entry pmu_metrics__cf_z14[] =3D { > const struct pmu_table_entry pmu_events__cf_z15[] =3D { > const struct pmu_table_entry pmu_metrics__cf_z15[] =3D { > const struct pmu_table_entry pmu_events__cf_z16[] =3D { > const struct pmu_table_entry pmu_metrics__cf_z16[] =3D { > const struct pmu_table_entry pmu_events__cf_z196[] =3D { > const struct pmu_table_entry pmu_events__cf_zec12[] =3D { > const struct pmu_table_entry pmu_metrics__cf_zec12[] =3D { > const struct pmu_table_entry pmu_events__test_soc_cpu[] =3D { > const struct pmu_table_entry pmu_metrics__test_soc_cpu[] =3D { > const struct pmu_table_entry pmu_events__test_soc_sys[] =3D { > # > > However event "software" is not listed, as can be seen in the > generated const struct pmu_events_map pmu_events_map[]. > So in function perf_pmu__find_events_table(), the variable > table is initialized to NULL, but never set to a proper > value. The function scans all generated &pmu_events_map[] > tables, but no table matches, because the tables are > s390 CPU Measurement unit specific: > > i =3D 0; > for (;;) { > const struct pmu_events_map *map =3D &pmu_events_map[i++]; > if (!map->arch) > break; > > --> the maps are there because the build generated them > > if (!strcmp_cpuid_str(map->cpuid, cpuid)) { > table =3D &map->event_table; > break; > } > --> Since no matching CPU string the table var remains 0x0 > } > free(cpuid); > if (!pmu) > return table; > > --> The pmu is "software" so it exists and no return > > --> and here perf dies because table is 0x0 > for (i =3D 0; i < table->num_pmus; i++) { > ... > } > return NULL; > > Fix this and do not access the table variable. Instead return 0x0 > which is the same return code when the for-loop was not successful. > > Output after: > # ./perf stat -e cs -- true > > Performance counter stats for 'true': > > 0 cs > > 0.000853105 seconds time elapsed > > 0.000061000 seconds user > 0.000827000 seconds sys > > # ./perf stat -e cpu-clock -- true > > Performance counter stats for 'true': > > 0.25 msec cpu-clock # 0.341 CPUs utilized > > 0.000728383 seconds time elapsed > > 0.000055000 seconds user > 0.000706000 seconds sys > > # ./perf stat -e cycles -- true > > Performance counter stats for 'true': > > cycles > > 0.000767298 seconds time elapsed > > 0.000055000 seconds user > 0.000739000 seconds sys > > # > > Signed-off-by: Thomas Richter Reviewed-by: Ian Rogers Thanks! Ian > --- > tools/perf/pmu-events/jevents.py | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jev= ents.py > index a7e88332276d..72ba4a9239c6 100755 > --- a/tools/perf/pmu-events/jevents.py > +++ b/tools/perf/pmu-events/jevents.py > @@ -991,7 +991,7 @@ const struct pmu_events_table *perf_pmu__find_events_= table(struct perf_pmu *pmu) > } > } > free(cpuid); > - if (!pmu) > + if (!pmu || !table) > return table; > > for (i =3D 0; i < table->num_pmus; i++) { > -- > 2.41.0 >