From patchwork Thu Jun 8 23:28:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13273010 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3EF67C7EE45 for ; Thu, 8 Jun 2023 23:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fmfhR43R5Tf+43GNzBQeKLZjkI9/RML45YLU/Yk1eOg=; b=grLb2ohz0MjAhu 7W/ampPwJklooQKhx4rUhGhmLyRf4fBUb9OB3NiQSOLkSHFfuh1x61vccT1YyA7APwyMnLYqndcnv BF/LcmamM+wgOwQe3moa/GJFd5Sx0VQjctqrkfIu1d0aXtEByLjpH2S7holx//x2IWf6sUuuhd95w G5FQ8mNd8VPg5cuRK0xVJC5FsfK44tV2sFWURSxYry1gxSfNBTU4Qq/TReytK5HFa9PEB2gi2EovF 90McY+6nASBnbgkPHxzpwYgYnKNOik8c3RFMoJ5dPv99qAw8enosC+emSrxLGIn17p/DRnHyMJ7vP cikpkT/OSDtjfN8E8XpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7P4L-00AuyI-2S; Thu, 08 Jun 2023 23:29:29 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q7P4E-00Auu1-2u for linux-arm-kernel@lists.infradead.org; Thu, 08 Jun 2023 23:29:24 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bb3cb542875so1661775276.1 for ; Thu, 08 Jun 2023 16:29:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686266961; x=1688858961; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=d8nZzpxNSCbRXHMzfJBAp7eVEh2n3zxwlDLBqqql/Uw=; b=Qc8L5FoARN90TEPW/tyBzgIkWZWMgC4vWKig+/L6A+nCr71SA5XPdM4GS9PuePF8XD vDVxVO4oJh1fDlu65LjQD5xdYcsCS7gzFhfD9C41ue5zDcLBzC2PR5pa1JLVsFMSFmwR /Gjccb+eR+2tOYSY/bXlfmbYOqiBN4vn8OyOVFLo6eGRNsJcG3cObVOUT3yOPgaWmt/e 0t3prXyPPW2p8WgFaTmsrsK+nwyFr0+bA5n3BJoyGFQxtmlXO9gnb2wQgqdg91RtnM5Y u9HM9/WhfiAzifHPJ9RsufS+aukJguBxiGtTEZZAzCE+10ItDUd4dhL1y8uJwJIsO8Rx QbrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686266961; x=1688858961; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=d8nZzpxNSCbRXHMzfJBAp7eVEh2n3zxwlDLBqqql/Uw=; b=darlIrEER/PATVo+I5aHJYtBL9ppxUKDhtWhJ8MZljHpzEk9sdZG7PDo+7vfYJuodn /pKOG6PxB4A01MOoVgUEQ/dhbLexOb3XyqdgXzATF8xcnEQquPTgRdXxfRpciOx3JkIl NYzRvy+txPtbngIKinw7fQ9DrGgdCbNB3bqm/J6+X34j8/L2+effY+znvaruzQPuhkZ9 cet7i0z5FwMQaFVGEHEt9kfu/Wb7p+q/2RMpmVlPsZXrx56Czhn47HHD7OW4R3aZzhP8 scuqa3imQsZX2yG8V/CZYauErblx6N4iO5BGutAbtSGg8PepCf76HDQh6TEM1jaBiqXr wicg== X-Gm-Message-State: AC+VfDzItXbRlSbD+djyhXJ5TioNd4+VYFV7C9J371VXaQapr19MaG6J 5hLjs2Nz39yoGGQEqDuTOYpWoU9FHcPe X-Google-Smtp-Source: ACHHUZ6mO0KY7WuSqm4kMAhhX7wri86AghEsVjmLTPQvjGHUK8KzarbyNv9ibdY6QZfzQ4veQySzF++IRrLF X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:c3e5:ebc6:61e5:c73f]) (user=irogers job=sendgmr) by 2002:a25:2004:0:b0:bbb:8c13:ce26 with SMTP id g4-20020a252004000000b00bbb8c13ce26mr599080ybg.11.1686266961427; Thu, 08 Jun 2023 16:29:21 -0700 (PDT) Date: Thu, 8 Jun 2023 16:28:01 -0700 In-Reply-To: <20230608232823.4027869-1-irogers@google.com> Message-Id: <20230608232823.4027869-5-irogers@google.com> Mime-Version: 1.0 References: <20230608232823.4027869-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Subject: [PATCH v2 04/26] perf maps: Make delete static, always use put From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230608_162922_938183_15B20DDC X-CRM114-Status: GOOD ( 14.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. 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;