Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5009994rdb; Fri, 15 Sep 2023 22:11:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpSpG/gUonxtZPuX6sUGYCgxYXmSTg7L1gyLA3IF/ogpibdEYWbsCrrYwFBwSJb7F22nUu X-Received: by 2002:a9d:6b0a:0:b0:6b8:82ed:ea2e with SMTP id g10-20020a9d6b0a000000b006b882edea2emr3731034otp.4.1694841112501; Fri, 15 Sep 2023 22:11:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694841112; cv=none; d=google.com; s=arc-20160816; b=vto9HskcvjGO7K8SgS3ZW+5uhnqZgtjE4Qf9lrfWfHllIEsDbCgfID54c5bPbswtCM x/YgBl39SFqvcgQPhh8VQL/CqFLxmvE/eeDe+etYOKSfQzJwR/9TiiV/w2ZiUqFg4xvf tf3px4/Z7TJpT7dcqudxp3qOxFiDt7jZAWnYBAJZZE94yBKmjYeo1FBomIKCeEzbiOZY HF307XmkxpiKRfy95Y+YsV16sMit6746UQDuDKYCzzjf8qasf8cbbC3IZMR2AP7ANHqp O/rhOFxQCaKlzqZ0KrZRuGbQv6L6CFSUdqIoBHYvdgxUCVNDdLCB/BJhUxfYtHCkM2d/ GxfQ== 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=syTDTrshUF5SFirABmARqauR5mR8y8+dKSQEBJXASCc=; fh=Kw1Ip5tjwv6LQ1gejxKktM20o8hSXss4XgjdCpxfNJA=; b=YZcUAaXmu0F1mKE7fIBpF9E0bcsUnryg4gUC9THQNMSHLrFiLal5RESupdGdngjpaP WnJT1jF1xqBN7otP16ybhM3xkQ9XNGuHg5kiopvCuPBVcYZ4xEmQFufClJPHBNieI7Re 55NUJ3urPUK9nTkb99CON1OxtvBwKZ3gokLYN7YwxoZSS2Oe1S0oxa2eU6C3jMu5vBrH 3UmCtaaqkZDfdiABDNumP1Wux4g/eBsHHTRn4I//xxUBfsGXc6xyN0iSnPpUKNih5hPm joKbPVN2YMAP83TWMXxpo2sfT5aLBYnvZdTOl1mb3BrO6otdNQrgFpDvvWKNczRkC5TC 5ODw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DipMFQ5i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id q5-20020a170902c74500b001c42b2b02bbsi2427562plq.265.2023.09.15.22.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 22:11:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DipMFQ5i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 82C4083CDF45; Fri, 15 Sep 2023 21:12:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232052AbjIPEL0 (ORCPT + 99 others); Sat, 16 Sep 2023 00:11:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232825AbjIPELK (ORCPT ); Sat, 16 Sep 2023 00:11:10 -0400 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D95941BD2 for ; Fri, 15 Sep 2023 21:11:04 -0700 (PDT) Received: by mail-qt1-x82e.google.com with SMTP id d75a77b69052e-414ba610766so163501cf.0 for ; Fri, 15 Sep 2023 21:11:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694837463; x=1695442263; 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=syTDTrshUF5SFirABmARqauR5mR8y8+dKSQEBJXASCc=; b=DipMFQ5iyOXfIKKtybDHdegJofxAKHO8xRVszxHetZD9PEZc8xFPaiUzI8kdF/8GAq gXK834NDZp1aaGoii/xfPtdKlwyuMzMSNoSWwyp5MpDWDH9/YLNuZI6qHxTIgKFcGQK/ h7qlXyMoHDDfgfUVUqEDB83TCjmz01EMnSKaVQ7CYtddR6cq02ucmMhvW2682BjpukqM w2nzHoyQnEZGzOjfpTVQQ8n7npGkyDW1hsIhGpOQERXBC4TA9sw/Jjl77OldPT0zVItc SwApCFJnqiChHW4vhQ8/S2Tj0GlmI6eHMcACIiQj7q0rIO+BQM5HKPWgsJhvi1UoyDGf xe8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694837463; x=1695442263; 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=syTDTrshUF5SFirABmARqauR5mR8y8+dKSQEBJXASCc=; b=KGJK7m085hl3yi6qvUbwj7/KMQ2rH7Z9sNJO7rG/aOjeE4rwgtBHJQ0yPh9SuTLm8Y SG1TbLSNplhJoXuMWMWaKKnOlVKDAGAlwmKYhRmZrxOyTwROohReFhjsZtkKvMOWPCaZ bI3YT3z6E7Y5aT/mgqUjjIU5yK7PHQyK1/Wo5RRNJpBdOza7vOqZb/pVILK0qK6SY+Rj gneHjOvhdjoyipb2XtPdppbhXaI5i/b9LWEUifC4a8LT3xK+31o4DjkvSU5lDwLufPKh SisEIQz0q+bcs3CasknMFhYUEYFV59Np3saFPdRm/MBa3opS0820czul7tObuOf0qByc tOBQ== X-Gm-Message-State: AOJu0YxVu81BFZrwkYNKZbebDgk8tnwOtCa3NEwv1BFOm1knTyfgjO6u Eu32YdvNYfPNpQ00XxQyk1/zw8W/W/aeqY3Avv8Uaw== X-Received: by 2002:a05:622a:1104:b0:403:e1d1:8b63 with SMTP id e4-20020a05622a110400b00403e1d18b63mr152321qty.24.1694837463307; Fri, 15 Sep 2023 21:11:03 -0700 (PDT) MIME-Version: 1.0 References: <20230913125157.2790375-1-tmricht@linux.ibm.com> In-Reply-To: From: Ian Rogers Date: Fri, 15 Sep 2023 21:10:50 -0700 Message-ID: Subject: Re: [PATCH] perf jevent: fix core dump on software events on s390 To: Namhyung Kim Cc: Thomas Richter , 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 X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Fri, 15 Sep 2023 21:12:10 -0700 (PDT) On Fri, Sep 15, 2023 at 4:40=E2=80=AFPM Namhyung Kim w= rote: > > Hello, > > On Thu, Sep 14, 2023 at 6:14=E2=80=AFAM Ian Rogers w= rote: > > > > 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 , dirf= d=3D3, > > > 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 > > I'll add this too, ok? > > Fixes: 7c52f10c0d4d8 ("perf pmu: Cache JSON events table") Looks good, thanks! Ian > Thanks, > Namhyung