From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02ACFC7619A for ; Wed, 12 Apr 2023 17:45:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbjDLRpM (ORCPT ); Wed, 12 Apr 2023 13:45:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbjDLRpL (ORCPT ); Wed, 12 Apr 2023 13:45:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FE0E5BA0; Wed, 12 Apr 2023 10:45:06 -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 D76216364D; Wed, 12 Apr 2023 17:45:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2AD7C433EF; Wed, 12 Apr 2023 17:45:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681321505; bh=C2Okaxi8HAPm3p9Co7NK51xvlY6z88fd67UrEVYXqdk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rtL+TXMwzgXBXsDgu16n+fEQrfpKn/7dh/fCcRCEdcNn13GP+T/B6oXQSj2I1aVGH /QUVqOkB64VdrOB3j7yPF+XCMeuDwN3k6/NTgEil9dU4CO4+a6MwGu/vDAqZUj0AuK Ug65B2D8Wu811tM5xnXn1Jr2gIrlxHKnn0nlDiWQqhOrxciWA7IU3Qy2+VDoWy8yIy kUYzcE3ID5BW68gRWLppdHvtgMgDVifOMHuxwTpAnSmTNcj06UH99cYL02yGIl4ncN ixM93NLQ7bouAiToG3fAvq2EJYpH8BP2yRf6LTF3mYFpIwfnMnCkDw5b6nX9RhtbQu udvr9JpWNIbdQ== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id CC32140080; Wed, 12 Apr 2023 14:45:01 -0300 (-03) Date: Wed, 12 Apr 2023 14:45:01 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Darren Hart , Davidlohr Bueso , James Clark , John Garry , Riccardo Mancini , Yury Norov , Andy Shevchenko , Andrew Morton , Adrian Hunter , Leo Yan , Andi Kleen , Thomas Richter , Kan Liang , Madhavan Srinivasan , Shunsuke Nakamura , Song Liu , Masami Hiramatsu , Steven Rostedt , Miaoqian Lin , Stephen Brennan , Kajol Jain , Alexey Bayduraev , German Gomez , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Dumazet , Dmitry Vyukov , Hao Luo , Stephane Eranian Subject: Re: [PATCH v7 2/5] perf cpumap: Add reference count checking Message-ID: References: <20230407230405.2931830-1-irogers@google.com> <20230407230405.2931830-3-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org Em Tue, Apr 11, 2023 at 03:19:06PM -0300, Arnaldo Carvalho de Melo escreveu: > Em Fri, Apr 07, 2023 at 04:04:02PM -0700, Ian Rogers escreveu: > > This change is intended to catch: > > - use after put: using a cpumap after you have put it will cause a > > segv. > > - unbalanced puts: two puts for a get will result in a double free > > that can be captured and reported by tools like address sanitizer, > > including with the associated stack traces of allocation and frees. > > - missing puts: if a put is missing then the get turns into a memory > > leak that can be reported by leak sanitizer, including the stack > > trace at the point the get occurs. > I think this should be further split into self contained patches as it > does: > > 2. Exports perf_cpu_map__alloc() from libperf for use in tools/perf > > And its usage should be on a separate patch: > > > - struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr); > > + struct perf_cpu_map *cpus = perf_cpu_map__alloc(nr); >From 1f94479edb4decdcec3e902528abb47f0ccd5d16 Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Wed, 12 Apr 2023 12:54:44 -0300 Subject: [PATCH 1/1] libperf: Make perf_cpu_map__alloc() available as an internal function for tools/perf to use We had the open coded equivalent in perf_cpu_map__empty_new(), so reuse what is in libperf. Signed-off-by: Ian Rogers Cc: Adrian Hunter Cc: Alexey Bayduraev Cc: Dmitriy Vyukov Cc: Jiri Olsa Cc: Namhyung Kim Cc: Riccardo Mancini Cc: Stephane Eranian Cc: Stephen Brennan Link: https://lore.kernel.org/lkml/20230407230405.2931830-3-irogers@google.com [ Split from a larger patch ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/perf/cpumap.c | 2 +- tools/lib/perf/include/internal/cpumap.h | 1 + tools/perf/util/cpumap.c | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 6cd0be7c1bb438e5..0833423c243b9b49 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -10,7 +10,7 @@ #include #include -static struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus) +struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus) { struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus); diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/include/internal/cpumap.h index 35dd29642296e660..f5bffb1f86748ca2 100644 --- a/tools/lib/perf/include/internal/cpumap.h +++ b/tools/lib/perf/include/internal/cpumap.h @@ -24,6 +24,7 @@ struct perf_cpu_map { #define MAX_NR_CPUS 2048 #endif +struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus); int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu); bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct perf_cpu_map *b); diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index c8484b75413ef709..072831f0cad46065 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -160,7 +160,7 @@ size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp) struct perf_cpu_map *perf_cpu_map__empty_new(int nr) { - struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr); + struct perf_cpu_map *cpus = perf_cpu_map__alloc(nr); if (cpus != NULL) { int i; -- 2.39.2