Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp6054927rdb; Mon, 18 Sep 2023 02:42:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+/5d9EQv6NXGWKwVywiNJhCl+wXV1EhvviLjLZWlDC4Q1jw7JaXc9+8GNMjsntOmUK3C7 X-Received: by 2002:a05:6a20:5489:b0:14d:9938:735f with SMTP id i9-20020a056a20548900b0014d9938735fmr8666185pzk.17.1695030139684; Mon, 18 Sep 2023 02:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695030139; cv=none; d=google.com; s=arc-20160816; b=EfJNbfp7E036bnI2dy0OylA5mutEJsyaQjgGYzJ8Gtw7hE+XrApCj9150jFAh2LX6k H9mMpBhypncstgL5rs2QXTYB94w1Gh3qjFiyF+DbvAC10YEMeH7/9zWttYglxnlql4Av 1+jLuhhTEYG98gLl/bzNZsqWElGaejUfBr2vwL+lWs7+hCLHr+qRHj0d8DCIb9ABx7YK eL79b6aoWCL5Up6P/QOYT54MSW1MgeatQbKhrFHFQ7bwLuHRbXwq6Qc2O1u2r0jIYpaG 3nkQeVwLcy43A2rvNZYmpkkoQNOq5+3AL3PJ/1awFTpvqm0oOHaXiVMamLgc7y4H6Hcm tBcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=UL1+8gmPxouyw6k8cAgdpAHbmNWJPGN1+BZ4gjPiZpA=; fh=A4WCmOsXCjbIfXHQJu95t13CgZ9HWMIoS2DHzDewYfA=; b=0FG7YroPPmIUq5XPNwF9wRNK45BoRDxUkpicoyn4ZgNBt4CqNsCK8TERxAL6ihEoZO JsOtsqYzgKjAQ+9W1aY6fivyrPnrGRZmm5NZ6q8rIEibP9Ai8qsXsZkCIXBsZ7dOI8St 8n3a3yIdaFq7NCMHMDQ5GSHFZbcYULBhZBOqH7A/0sd0VqXaSQZklGvAwWOcSx653TgV 7CR4M4lItW/AVfuPHQtmiWGt8qjW6xS6o/41jEPADG9VIwOTTf/z+rnAn+DhGrhk2VGW t/Zq1IbzIUsqYqP27ELaQ//JZWeZl0DY07JUOsiUZnIi36Ek/a23KPB0OCFwRNiTn732 g/PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=sYLMg5JH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id f1-20020a170902684100b001b9c34985e1si7929397pln.497.2023.09.18.02.42.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 02:42:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=sYLMg5JH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 06F108038B09; Mon, 18 Sep 2023 01:30:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240704AbjIRI3a (ORCPT + 99 others); Mon, 18 Sep 2023 04:29:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240687AbjIRI3G (ORCPT ); Mon, 18 Sep 2023 04:29:06 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F32AA99; Mon, 18 Sep 2023 01:28:59 -0700 (PDT) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38I86P6P025592; Mon, 18 Sep 2023 08:28:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=UL1+8gmPxouyw6k8cAgdpAHbmNWJPGN1+BZ4gjPiZpA=; b=sYLMg5JHs5EFXgqekGUxybwRBYFQPi8Fh0sR/wAcGKzqmSjmAP9rKyyrIoZlSd/8asX5 U0nHCwi8Z9oSoOPQVLoOWyuIG1gpqMa6QF8j83SuDHvxgWJeqcOZcenyd6VAMXwMI7rk 8pD3zSA+lSAHzB3Di0ZT2ZYAPTd/rwFJtUuGH1E901ju6D+WZ7NPe/dPeYlleB581X3p bPQdqWjpuGbgG+mA/z1qrKcCgMWf3PuPhWPPBOwj92C8VMBQ6DTQbTUTQcXjAZRpQ8Ku 8eHl3vQVBYWg7YrEAslSeecLAPfKT0R81RWdS0jD3ePDEcseDgPT9E1tJ/6KL6srtCHy ig== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3t6h6dj4s5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Sep 2023 08:28:51 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 38I86ct1027355; Mon, 18 Sep 2023 08:28:50 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3t6h6dj4rm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Sep 2023 08:28:50 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 38I6vJIM016841; Mon, 18 Sep 2023 08:28:49 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3t5sd1ggjw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Sep 2023 08:28:49 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 38I8SkWK28508768 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Sep 2023 08:28:46 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 753D020049; Mon, 18 Sep 2023 08:28:46 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F348520040; Mon, 18 Sep 2023 08:28:45 +0000 (GMT) Received: from [9.171.25.42] (unknown [9.171.25.42]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 18 Sep 2023 08:28:45 +0000 (GMT) Message-ID: <521bbe73-ba4d-7f2f-fce5-3799ef78e603@linux.ibm.com> Date: Mon, 18 Sep 2023 10:28:45 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH] perf jevent: fix core dump on software events on s390 To: Namhyung Kim , Ian Rogers 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 References: <20230913125157.2790375-1-tmricht@linux.ibm.com> Content-Language: en-US From: Thomas Richter Organization: IBM In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: B5dGEdPcC1PCOts2svazHlwe83enfxYZ X-Proofpoint-GUID: 7g4Q99XSlOHi5VLNVqxxtzlTAt6wSrsV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-18_01,2023-09-15_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 phishscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309180070 X-Spam-Status: No, score=-2.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 18 Sep 2023 01:30:08 -0700 (PDT) On 9/16/23 01:40, Namhyung Kim wrote: > Hello, > > On Thu, Sep 14, 2023 at 6:14 AM Ian Rogers wrote: >> >> On Wed, Sep 13, 2023 at 5:52 AM 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=1) >>> +--> pmu_read_sysfs(core_only=false) >>> +--> perf_pmu__find2(dirfd=3, name=0x152a113 "software") >>> +--> perf_pmu__lookup(pmus=0x14f0568 , dirfd=3, >>> lookup_name=0x152a113 "software") >>> +--> perf_pmu__find_events_table (pmu=0x1532130) >>> >>> 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[] = { >>> const struct pmu_table_entry pmu_events__cf_z13[] = { >>> const struct pmu_table_entry pmu_metrics__cf_z13[] = { >>> const struct pmu_table_entry pmu_events__cf_z14[] = { >>> const struct pmu_table_entry pmu_metrics__cf_z14[] = { >>> const struct pmu_table_entry pmu_events__cf_z15[] = { >>> const struct pmu_table_entry pmu_metrics__cf_z15[] = { >>> const struct pmu_table_entry pmu_events__cf_z16[] = { >>> const struct pmu_table_entry pmu_metrics__cf_z16[] = { >>> const struct pmu_table_entry pmu_events__cf_z196[] = { >>> const struct pmu_table_entry pmu_events__cf_zec12[] = { >>> const struct pmu_table_entry pmu_metrics__cf_zec12[] = { >>> const struct pmu_table_entry pmu_events__test_soc_cpu[] = { >>> const struct pmu_table_entry pmu_metrics__test_soc_cpu[] = { >>> const struct pmu_table_entry pmu_events__test_soc_sys[] = { >>> # >>> >>> 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 = 0; >>> for (;;) { >>> const struct pmu_events_map *map = &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 = &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 = 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") > > Thanks, > Namhyung Yep fine with me. -- Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany -- Vorsitzender des Aufsichtsrats: Gregor Pillen Geschäftsführung: David Faller Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294