Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2177449rwd; Fri, 9 Jun 2023 07:41:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Qv1H7JmH9ZbtkVLYXcxhjPhL4tcXRmTiJV4bcMj4thcw/kvF4K9mEwutNef3jJ0mY0Etd X-Received: by 2002:a17:902:8d8d:b0:1af:b97c:2353 with SMTP id v13-20020a1709028d8d00b001afb97c2353mr1108248plo.15.1686321692911; Fri, 09 Jun 2023 07:41:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686321692; cv=none; d=google.com; s=arc-20160816; b=cfOPnpxq8ot3Wshxf6qRDeCwEX1peMkRVUyHulg811vwFIBBFUxuz5mXPsymAxH5hB MklHz4cv8TCwo6j2PCarhEqHM4RX4Ig58Ubx5rPtw4E75hgKli1Y4Bt5GxjyFfHNIFzL C/QJ+E45CFFD8o4Mlm+HYqZwqmDU+hhXnM/jVqevVA5omibVkikUpAiXwLiNDXNBQlvv 4cjaPmM1kAM+6Gpp4JHnVawFRSj1DG4Q2mox6zMuJ9yfs78G5160Wm+9lETFLyWfHq9d 3EzCoNnkM5Ki+EXTnqo39nxSwWRZVmP2jj8tCk27i3TGltzzQiq7pefutC0XCPJNQqYk Bc4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=83rnEPvPujOX8bCW0XTxK24uVzVcAFGADX+s0t+48ro=; b=I6kXTShwQcB/5KybApkLK+QeuxmQ/FhgwBgNZzK1XELi2DoN9dZuf4F3ft1qWk4Had P6OUtF1YnlDwPM4zphPtgQTkud5I+wglWhiwx7kJ/+0IxOgbDj6U6idxfEdp52AoxEy1 Kieaf+PlU/HXFEQRLcjZ3viTk6HePpE44i5Y/JZJaDhK0+AxZ/K1x7ogYWA+k69x0B23 QqZka0UsVjNsUpuXNEEUDSPKlvxezEQ6Pb/hZm6x5nYMb/Xy9diWc8PLjv0aF+PJHXHT P8ItIKGhSF5qTl0iF/UCFLyyW7ErGQjLjqJzORj021NQk5n4Jcw+YJefDHNbnQ3KSMt9 xT4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="bcxaqp/D"; 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 kx7-20020a170902f94700b001ac6a9353ffsi2766523plb.116.2023.06.09.07.41.17; Fri, 09 Jun 2023 07:41:32 -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="bcxaqp/D"; 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 S238708AbjFIORt (ORCPT + 99 others); Fri, 9 Jun 2023 10:17:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231134AbjFIORr (ORCPT ); Fri, 9 Jun 2023 10:17:47 -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 3D1A830E5; Fri, 9 Jun 2023 07:17:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C1FB361D32; Fri, 9 Jun 2023 14:17:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E724DC4339B; Fri, 9 Jun 2023 14:17:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686320265; bh=dwVgdncCcYDj2hwb+9JaEVfH+lUQWzk/oa0ZMJ0g83Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bcxaqp/DQ+I9UtNrpBdehBwpsXR4syK8aVC2JrCLRX81P4gijnPmZ1xgtIwJ5Nl5C 4ckG5W2i6Gdiw+FPuuBnNeJrIEWG/StZQrvjhMIdu0ZUXKB/RdLZwx2xDbxu9X3txl Nzl0gndPSqh1cEZ7I6wI2Z5idDzqtFYq3nO3TFu3IopUhSb0xARu4NPaCG/aGazYwf RuhTnnw6X/vf8q932pwaofOkFdgaJ1PByHW5gty8dHZIU3rWpqbPCsY1B+RhK6tQ6z +SL8uwzcmWflu+wIJcdJIC6H9YY8NLcuCpYuPg1SERvWHuWSfZtG87gcLpFuHYfKwk hEIsLwe4loUfg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 20E2140692; Fri, 9 Jun 2023 11:17:42 -0300 (-03) Date: Fri, 9 Jun 2023 11:17:42 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Suzuki K Poulose , "Naveen N. Rao" , Kan Liang , German Gomez , Ali Saidi , Jing Zhang , Athira Rajeev , Miguel Ojeda , ye xingchen , Liam Howlett , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , K Prateek Nayak , Changbin Du , Ravi Bangoria , Sean Christopherson , Andi Kleen , "Steinar H. Gunderson" , Yuan Can , Brian Robbins , liuwenyu , Ivan Babrou , Fangrui Song , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, coresight@lists.linaro.org Subject: Re: [PATCH v2 04/26] perf maps: Make delete static, always use put Message-ID: References: <20230608232823.4027869-1-irogers@google.com> <20230608232823.4027869-5-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230608232823.4027869-5-irogers@google.com> X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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: X-Mailing-List: linux-kernel@vger.kernel.org Em Thu, Jun 08, 2023 at 04:28:01PM -0700, Ian Rogers escreveu: > Address/leak sanitizer with reference count checking can identify the > location of leaks, so use put rather than delete to avoid free-ing > memory when the reference count is >1. Add maps__zput to ensure the > variable is cleared. Applied. - Arnaldo > Signed-off-by: Ian Rogers > --- > tools/perf/tests/maps.c | 2 +- > tools/perf/util/machine.c | 2 +- > tools/perf/util/maps.c | 2 +- > tools/perf/util/maps.h | 9 ++++++++- > 4 files changed, 11 insertions(+), 4 deletions(-) > > diff --git a/tools/perf/tests/maps.c b/tools/perf/tests/maps.c > index 8c0eb5cf8bb5..5bb1123a91a7 100644 > --- a/tools/perf/tests/maps.c > +++ b/tools/perf/tests/maps.c > @@ -140,7 +140,7 @@ static int test__maps__merge_in(struct test_suite *t __maybe_unused, int subtest > ret = check_maps(merged3, ARRAY_SIZE(merged3), maps); > TEST_ASSERT_VAL("merge check failed", !ret); > > - maps__delete(maps); > + maps__zput(maps); > return TEST_OK; > } > > diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c > index 5d34d60a0045..8972c852d3bd 100644 > --- a/tools/perf/util/machine.c > +++ b/tools/perf/util/machine.c > @@ -248,7 +248,7 @@ void machine__exit(struct machine *machine) > return; > > machine__destroy_kernel_maps(machine); > - maps__delete(machine->kmaps); > + maps__zput(machine->kmaps); > dsos__exit(&machine->dsos); > machine__exit_vdso(machine); > zfree(&machine->root_dir); > diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c > index 5ae6379a1b42..5206a6433117 100644 > --- a/tools/perf/util/maps.c > +++ b/tools/perf/util/maps.c > @@ -171,7 +171,7 @@ struct maps *maps__new(struct machine *machine) > return result; > } > > -void maps__delete(struct maps *maps) > +static void maps__delete(struct maps *maps) > { > maps__exit(maps); > unwind__finish_access(maps); > diff --git a/tools/perf/util/maps.h b/tools/perf/util/maps.h > index d2963456cfbe..83144e0645ed 100644 > --- a/tools/perf/util/maps.h > +++ b/tools/perf/util/maps.h > @@ -57,13 +57,20 @@ struct kmap { > }; > > struct maps *maps__new(struct machine *machine); > -void maps__delete(struct maps *maps); > bool maps__empty(struct maps *maps); > int maps__clone(struct thread *thread, struct maps *parent); > > struct maps *maps__get(struct maps *maps); > void maps__put(struct maps *maps); > > +static inline void __maps__zput(struct maps **map) > +{ > + maps__put(*map); > + *map = NULL; > +} > + > +#define maps__zput(map) __maps__zput(&map) > + > static inline struct rb_root *maps__entries(struct maps *maps) > { > return &RC_CHK_ACCESS(maps)->entries; > -- > 2.41.0.162.gfafddb0af9-goog > -- - Arnaldo