Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4744296rwl; Mon, 10 Apr 2023 16:26:07 -0700 (PDT) X-Google-Smtp-Source: AKy350Z0rz+ksrKkxIpjSiqTUb+1mLJsLl8B4hxP8ec89VHrfjPccPoIM1NtyNI3+ATGz4bUOyA/ X-Received: by 2002:a17:907:a08e:b0:946:f79b:e785 with SMTP id hu14-20020a170907a08e00b00946f79be785mr8585995ejc.2.1681169167271; Mon, 10 Apr 2023 16:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681169167; cv=none; d=google.com; s=arc-20160816; b=Qj2STalNpJvBjLLBAW9pNv821rpeoguFyhhx+OLSWH6bETND8OzWk79Rvt6r0d98NB pVE1ojYaO+1bNnc8ie+NGpVWcRwyBBwfLE4X2KeM5drzxTX1F/ETqNS2s9058aY9V8vz mTqZYuJ6ShXVTb/VrjWO0rtC6tWpqclnW2SgD+Dg1h9WKN/sPVP9LuWGtQkMx1DHq20W lw5lNu94Rh+qeaoicuGR4g1NfE3bzg7RJABk42GHrU68FdRURz0NpB+ez5pkKpgz0Lpy p3riUA9VtRPO2su6uCQlI31H2nnCV1Sph05u7h6lJ4r+gcpUmLnK7CihBvQsbSod/GU7 zEmQ== 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; bh=FchgOo6bqK8kpDoR49xGt/bDbkDDWEhEDn7q9EzD1JY=; b=iEnDPpGRHOdvYOe5LhuSgG+MQUk+uf0mUPa3hL8uWT6Yijh6+j/q9X6oLjUAPvRWmI 29AE4xfu65DyPQ+ARw9RJWLscvaveAnE/8uj08lIdbP0ixiUutteHdYXunHJ8vB0/0S5 sCb8HwG+6qkIhONXbAAZLCGWB8TAg9ZqoXSFkH8Kv+3HNkNWjg4hl5n0KLMhmdT7d1UD Wdjmca3yA0Tthw9puRgYtn2QVcRWDsUks/pC5F710ZWfWTo8357EbyaO9/0ruxNQw4Hv pgz1R6nQ6fTyWRXkTKrF8nMrXJkS3kBhapyOn2ta1C4AMSWo6sUmvhZgUJH0O/gMsaV9 0XOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hk7-20020a170906c9c700b0093345001d1dsi9393328ejb.498.2023.04.10.16.25.43; Mon, 10 Apr 2023 16:26:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229705AbjDJXVd convert rfc822-to-8bit (ORCPT + 99 others); Mon, 10 Apr 2023 19:21:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbjDJXVc (ORCPT ); Mon, 10 Apr 2023 19:21:32 -0400 Received: from mail-ua1-f49.google.com (mail-ua1-f49.google.com [209.85.222.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6D912118; Mon, 10 Apr 2023 16:21:09 -0700 (PDT) Received: by mail-ua1-f49.google.com with SMTP id ba16so4410966uab.4; Mon, 10 Apr 2023 16:21:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681168869; x=1683760869; 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=P4Lc7kTtUKpJq2HePJoO52rNn2Ss3QVKDL6cqFdOw4s=; b=MxBSz9HWyK5hgCi29CGRVBEoPh7dV+/rI4YzgRrAfh7IvMTfh24wF3BDxWQt1/I+PQ mEM4FUxIP1XofKXqMNYwdvNVDDx6Mx7Khitqtk+bsZ3CT8LE+Jv7It9dhFmMMiWHjxWg rsqaiYyHSILt/Gtbs0GxEjbYkxkDFqYsOZWQlu9T3UHJvElqu5I2tw0huiMgt6GU9bFi yhqKJ16yQFr2aYlk4bIIZKafjFOIoJrOaeI7Fj6nxJgFT92c9CfbXSHADBIWFjlTd1yg fUjZ40aOLE1TdfVgYaeXGeTyHzYeGzcQFBznaCQ0FHBzS7gpRfIZuUWII6oLyVc+3BtM K54Q== X-Gm-Message-State: AAQBX9fS6ELsN+T5YMoVOuwzox9DFFb//5Kp7hm9HFtCee8cKPFJlkqY Jb9JslmeQi2jlMYk2Mrr0jH/lBBogCwMh2RYE3rBLSll X-Received: by 2002:a05:6122:1691:b0:43b:ead4:669e with SMTP id 17-20020a056122169100b0043bead4669emr3979285vkl.16.1681168868654; Mon, 10 Apr 2023 16:21:08 -0700 (PDT) MIME-Version: 1.0 References: <20230410205659.3131608-1-irogers@google.com> In-Reply-To: <20230410205659.3131608-1-irogers@google.com> From: Namhyung Kim Date: Mon, 10 Apr 2023 16:20:57 -0700 Message-ID: Subject: Re: [PATCH v1] perf evsel: Avoid segv if delete is called on NULL To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , Florian Fischer , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ian, On Mon, Apr 10, 2023 at 1:57 PM Ian Rogers wrote: > > Seen in "perf stat --bpf-counters --for-each-cgroup test" running in a > container: > > libbpf: Failed to bump RLIMIT_MEMLOCK (err = -1), you might need to do it explicitly! > libbpf: Error in bpf_object__probe_loading():Operation not permitted(1). Couldn't load trivial BPF program. Make sure your kernel supports BPF (CONFIG_BPF_SYSCALL=y) and/or that RLIMIT_MEMLOCK is set to big enough value. > libbpf: failed to load object 'bperf_cgroup_bpf' > libbpf: failed to load BPF skeleton 'bperf_cgroup_bpf': -1 > Failed to load cgroup skeleton > > #0 0x55f28a650981 in list_empty tools/include/linux/list.h:189 > #1 0x55f28a6593b4 in evsel__exit util/evsel.c:1518 > #2 0x55f28a6596af in evsel__delete util/evsel.c:1544 > #3 0x55f28a89d166 in bperf_cgrp__destroy util/bpf_counter_cgroup.c:283 > #4 0x55f28a899e9a in bpf_counter__destroy util/bpf_counter.c:816 > #5 0x55f28a659455 in evsel__exit util/evsel.c:1520 > #6 0x55f28a6596af in evsel__delete util/evsel.c:1544 > #7 0x55f28a640d4d in evlist__purge util/evlist.c:148 > #8 0x55f28a640ea6 in evlist__delete util/evlist.c:169 > #9 0x55f28a4efbf2 in cmd_stat tools/perf/builtin-stat.c:2598 > #10 0x55f28a6050c2 in run_builtin tools/perf/perf.c:330 > #11 0x55f28a605633 in handle_internal_command tools/perf/perf.c:384 > #12 0x55f28a6059fb in run_argv tools/perf/perf.c:428 > #13 0x55f28a6061d3 in main tools/perf/perf.c:562 > > Signed-off-by: Ian Rogers Acked-by: Namhyung Kim In addition to this, I think bperf code should clear the evsel->bpf_skel at the end of the bpf_counter__destroy() to avoid confusion with the bpf_filter as they share the fields in a union. Thanks, Namhyung > --- > tools/perf/util/evsel.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index dc3faf005c3b..fe3ce765a4f3 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -1541,6 +1541,9 @@ void evsel__exit(struct evsel *evsel) > > void evsel__delete(struct evsel *evsel) > { > + if (!evsel) > + return; > + > evsel__exit(evsel); > free(evsel); > } > -- > 2.40.0.577.gac1e443424-goog >