Message ID | 20230719202951.534582-3-acme@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2712742vqt; Wed, 19 Jul 2023 14:16:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlFE9kwP4sJtIc9+JfLExrXW7DFDby/rH0Ta0ov3VFaKHxiOotYDyHt773/0WgIQqhYJFivN X-Received: by 2002:a05:6a00:3996:b0:666:ecf4:ed6d with SMTP id fi22-20020a056a00399600b00666ecf4ed6dmr3892091pfb.18.1689801402701; Wed, 19 Jul 2023 14:16:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689801402; cv=none; d=google.com; s=arc-20160816; b=uQqC5WPDMt5CzAE8+BeMKSMnZoDBlxwZMHmH00oqRfAwa7QV8ceNEeBqQ1xXsVBu5N Ldq5L954CnkLhk2wfwY7WnPy5EUu0TyDXjqfZOtYSzUtAgE2fXxZP7LARNUQzUuSHPAh mqwKTsn66UHuWHchyC2ZWuwQHl2sMTZ653GQsfu/Sm1zZz+snNXHrgNfevo6x+Z2/App fkmOhLKgNxZfYUMdYpX+ZjUimNu0IVR8WfcAQF/Pq2EypqIPKzusQrO7i0j1/DkCv/g4 voKgjBOXyDDGbkAp5tyqCOAcQG+YbCrtWg9zBY800/iFEtVuwgI0xL9/i4y4xNN35L3t lTrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hjzRtno2QRvSHOFOPFqObOUXVNYMdykbtcCuqjw9c+w=; fh=GZ4eSIeu5yUrjQDUyFDhKHpL6itJkKQ8QAaBkaJW/mM=; b=QhAIU2vmxLJsHGO5gwRyo2+62oIG9KqAYGtVxareFx5fn512YMvVPicbOlWIIFXlKX 4cvTnFjy7Ya2WDHaGHF+jL5t85Jew3k0CUORLHfRQj/dRVeJYP97z1g6FRFwrNdXJuls 9dgWmQcr/WHwKQV2g8/MICLvOD/4ewahXZcPfDKvvfwrBzx3OB/UpPHjWlwZflJK1QmC EMb+/O//t2ewNaXKs5HJzl8LDA3jD6YXFGY/q16iDnJ5nj/iA/2rb5S0Hi1hRh1JuCzE FXVVWOF3Bum2uQoIz2vhVR1bQucrcLLkg78HQjGqGQ/SMM2QdLrpFXWq2sjgyHzkG3Mr JKHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eLuzMdK3; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f19-20020a635553000000b0055fe860330bsi4068492pgm.205.2023.07.19.14.16.29; Wed, 19 Jul 2023 14:16:42 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eLuzMdK3; 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 S231310AbjGSUcP (ORCPT <rfc822;daweilics@gmail.com> + 99 others); Wed, 19 Jul 2023 16:32:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231303AbjGSUcK (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 19 Jul 2023 16:32:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3DB2268D; Wed, 19 Jul 2023 13:31:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1BC3B61828; Wed, 19 Jul 2023 20:30:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 044B0C433C7; Wed, 19 Jul 2023 20:30:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689798605; bh=BRr5z+/T35P0lcuwuDmZU0RVzfr8a7oe2vprcDbwtgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eLuzMdK34w6j5GXTkBaVLYSnwgF5Bu10EGq7KZeJhZlqE3HnYBLVm4IEb4roVyTwh zaRJeQThJ4AwDxoFLo0FHsKfpHb/hroAwkE9/sVSKF+KehTyNo1IXC9GgO16PNNwSo HBP8mGWr+glXWHk2ty88qBhpLeRNDRCESsWRzJ5g08Mh0YRpsPldwoJMrGo9TmUciG +utjq8ZVV6cRUKH6fodglvjSjZPdTtx5cMD7pQPNig3MKUkA0/xdJ4AK+8/zSQ0IS4 mq0EjGOhSMVIPY1VS4KDrmfwBkQ4g2fjvDt7VpeYtNF26daSz6+Q/2j2sJr+nbs9JD zo/T8JyH7hO/A== From: Arnaldo Carvalho de Melo <acme@kernel.org> To: Namhyung Kim <namhyung@kernel.org> Cc: Ingo Molnar <mingo@kernel.org>, Thomas Gleixner <tglx@linutronix.de>, Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com>, Clark Williams <williams@redhat.com>, Kate Carcia <kcarcia@redhat.com>, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo <acme@redhat.com> Subject: [PATCH 2/6] perf thread: Allow tools to register a thread->priv destructor Date: Wed, 19 Jul 2023 17:29:47 -0300 Message-ID: <20230719202951.534582-3-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719202951.534582-1-acme@kernel.org> References: <20230719202951.534582-1-acme@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771885195691530859 X-GMAIL-MSGID: 1771885195691530859 |
Series |
Fix some 'perf trace' leaks found with -fsanitize=address.
|
|
Commit Message
Arnaldo Carvalho de Melo
July 19, 2023, 8:29 p.m. UTC
From: Arnaldo Carvalho de Melo <acme@redhat.com> So that when thread__delete() runs it can be called and free stuff tools stashed into thread->priv, like 'perf trace' does and will use this new facility to plug some leaks. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- tools/perf/util/thread.c | 11 +++++++++++ tools/perf/util/thread.h | 2 ++ 2 files changed, 13 insertions(+)
Comments
On Wed, Jul 19, 2023 at 1:30 PM Arnaldo Carvalho de Melo <acme@kernel.org> wrote: > > From: Arnaldo Carvalho de Melo <acme@redhat.com> > > So that when thread__delete() runs it can be called and free stuff tools > stashed into thread->priv, like 'perf trace' does and will use this > new facility to plug some leaks. > > Cc: Adrian Hunter <adrian.hunter@intel.com> > Cc: Ian Rogers <irogers@google.com> > Cc: Jiri Olsa <jolsa@kernel.org> > Cc: Namhyung Kim <namhyung@kernel.org> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> > --- > tools/perf/util/thread.c | 11 +++++++++++ > tools/perf/util/thread.h | 2 ++ > 2 files changed, 13 insertions(+) > > diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c > index 0b166404c5c365cf..35dd4e716e411da9 100644 > --- a/tools/perf/util/thread.c > +++ b/tools/perf/util/thread.c > @@ -80,6 +80,13 @@ struct thread *thread__new(pid_t pid, pid_t tid) > return NULL; > } > > +static void (*thread__priv_destructor)(void *priv); > + > +void thread__set_priv_destructor(void (*destructor)(void *priv)) > +{ Perhaps: assert(thread__priv_destructor == NULL); To make it clear that there should never be >1 currently. > + thread__priv_destructor = destructor; > +} > + > void thread__delete(struct thread *thread) > { > struct namespaces *namespaces, *tmp_namespaces; > @@ -112,6 +119,10 @@ void thread__delete(struct thread *thread) > exit_rwsem(thread__namespaces_lock(thread)); > exit_rwsem(thread__comm_lock(thread)); > thread__free_stitch_list(thread); > + > + if (thread__priv_destructor) > + thread__priv_destructor(thread__priv(thread)); > + > RC_CHK_FREE(thread); > } > > diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h > index 9068a21ce0fa1b0f..e79225a0ea46b789 100644 > --- a/tools/perf/util/thread.h > +++ b/tools/perf/util/thread.h > @@ -71,6 +71,8 @@ struct thread *thread__new(pid_t pid, pid_t tid); > int thread__init_maps(struct thread *thread, struct machine *machine); > void thread__delete(struct thread *thread); > > +void thread__set_priv_destructor(void (*destructor)(void *priv)); > + > struct thread *thread__get(struct thread *thread); > void thread__put(struct thread *thread); > > -- > 2.41.0 >
Em Wed, Jul 19, 2023 at 03:31:41PM -0700, Ian Rogers escreveu: > On Wed, Jul 19, 2023 at 1:30 PM Arnaldo Carvalho de Melo > <acme@kernel.org> wrote: > > > > From: Arnaldo Carvalho de Melo <acme@redhat.com> > > > > So that when thread__delete() runs it can be called and free stuff tools > > stashed into thread->priv, like 'perf trace' does and will use this > > new facility to plug some leaks. > > > > Cc: Adrian Hunter <adrian.hunter@intel.com> > > Cc: Ian Rogers <irogers@google.com> > > Cc: Jiri Olsa <jolsa@kernel.org> > > Cc: Namhyung Kim <namhyung@kernel.org> > > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> > > --- > > tools/perf/util/thread.c | 11 +++++++++++ > > tools/perf/util/thread.h | 2 ++ > > 2 files changed, 13 insertions(+) > > > > diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c > > index 0b166404c5c365cf..35dd4e716e411da9 100644 > > --- a/tools/perf/util/thread.c > > +++ b/tools/perf/util/thread.c > > @@ -80,6 +80,13 @@ struct thread *thread__new(pid_t pid, pid_t tid) > > return NULL; > > } > > > > +static void (*thread__priv_destructor)(void *priv); > > + > > +void thread__set_priv_destructor(void (*destructor)(void *priv)) > > +{ > > Perhaps: > assert(thread__priv_destructor == NULL); I'll add that. > To make it clear that there should never be >1 currently. > > > + thread__priv_destructor = destructor; > > +} > > + > > void thread__delete(struct thread *thread) > > { > > struct namespaces *namespaces, *tmp_namespaces; > > @@ -112,6 +119,10 @@ void thread__delete(struct thread *thread) > > exit_rwsem(thread__namespaces_lock(thread)); > > exit_rwsem(thread__comm_lock(thread)); > > thread__free_stitch_list(thread); > > + > > + if (thread__priv_destructor) > > + thread__priv_destructor(thread__priv(thread)); > > + > > RC_CHK_FREE(thread); > > } > > > > diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h > > index 9068a21ce0fa1b0f..e79225a0ea46b789 100644 > > --- a/tools/perf/util/thread.h > > +++ b/tools/perf/util/thread.h > > @@ -71,6 +71,8 @@ struct thread *thread__new(pid_t pid, pid_t tid); > > int thread__init_maps(struct thread *thread, struct machine *machine); > > void thread__delete(struct thread *thread); > > > > +void thread__set_priv_destructor(void (*destructor)(void *priv)); > > + > > struct thread *thread__get(struct thread *thread); > > void thread__put(struct thread *thread); > > > > -- > > 2.41.0 > >
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 0b166404c5c365cf..35dd4e716e411da9 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -80,6 +80,13 @@ struct thread *thread__new(pid_t pid, pid_t tid) return NULL; } +static void (*thread__priv_destructor)(void *priv); + +void thread__set_priv_destructor(void (*destructor)(void *priv)) +{ + thread__priv_destructor = destructor; +} + void thread__delete(struct thread *thread) { struct namespaces *namespaces, *tmp_namespaces; @@ -112,6 +119,10 @@ void thread__delete(struct thread *thread) exit_rwsem(thread__namespaces_lock(thread)); exit_rwsem(thread__comm_lock(thread)); thread__free_stitch_list(thread); + + if (thread__priv_destructor) + thread__priv_destructor(thread__priv(thread)); + RC_CHK_FREE(thread); } diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 9068a21ce0fa1b0f..e79225a0ea46b789 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -71,6 +71,8 @@ struct thread *thread__new(pid_t pid, pid_t tid); int thread__init_maps(struct thread *thread, struct machine *machine); void thread__delete(struct thread *thread); +void thread__set_priv_destructor(void (*destructor)(void *priv)); + struct thread *thread__get(struct thread *thread); void thread__put(struct thread *thread);