Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Tengda Wu <wutengda@huaweicloud.com>
Cc: james.clark@linaro.org, xueshuai@linux.alibaba.com,
	Li Huafei <lihuafei1@huawei.com>,
	Peter Zijlstra <peterz@infradead.org>,
	leo.yan@linux.dev, Ian Rogers <irogers@google.com>,
	Kim Phillips <kim.phillips@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Ingo Molnar <mingo@redhat.com>, Bill Wendling <morbo@google.com>,
	Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Zecheng Li <zli94@ncsu.edu>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH v3 01/21] perf capstone: Fix kernel map reference count leak
Date: Wed, 8 Jul 2026 22:57:08 -0700	[thread overview]
Message-ID: <ak84NFSWQXz3r46x@z2> (raw)
In-Reply-To: <20260701035355.752944-2-wutengda@huaweicloud.com>

On Wed, Jul 01, 2026 at 03:53:35AM +0000, Tengda Wu wrote:
> In print_capstone_detail(), maps__find() is used to locate the kernel
> map. This function increments the reference count of the found map
> object. However, the current implementation fails to call map__put()
> after the map is no longer needed, leading to a reference count leak.
> 
> Fix this by adding a map__put(map) call to properly release the
> reference after use.
> 
> Fixes: 92dfc59463d5 ("perf annotate: Add symbol name when using capstone")
> Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>

I'll pick this up separately.

Thanks,
Namhyung

> ---
>  tools/perf/util/capstone.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c
> index 5ad537fea436..9bba78ee0c5a 100644
> --- a/tools/perf/util/capstone.c
> +++ b/tools/perf/util/capstone.c
> @@ -302,6 +302,7 @@ static void print_capstone_detail(struct cs_insn *insn, char *buf, size_t len,
>  	for (i = 0; i < insn->detail->x86.op_count; i++) {
>  		struct cs_x86_op *op = &insn->detail->x86.operands[i];
>  		u64 orig_addr;
> +		struct map *found_map = NULL;
>  
>  		if (op->type != X86_OP_MEM)
>  			continue;
> @@ -317,19 +318,22 @@ static void print_capstone_detail(struct cs_insn *insn, char *buf, size_t len,
>  		if (dso__kernel(map__dso(map))) {
>  			/*
>  			 * The kernel maps can be split into sections, let's
> -			 * find the map first and the search the symbol.
> +			 * find the map first and then search the symbol.
>  			 */
> -			map = maps__find(map__kmaps(map), addr);
> -			if (map == NULL)
> +			found_map = maps__find(map__kmaps(map), addr);
> +			if (found_map == NULL)
>  				continue;
> +			map = found_map;
>  		}
>  
>  		/* convert it to map-relative address for search */
>  		addr = map__map_ip(map, addr);
>  
>  		sym = map__find_symbol(map, addr);
> -		if (sym == NULL)
> +		if (sym == NULL) {
> +			map__put(found_map);
>  			continue;
> +		}
>  
>  		if (addr == sym->start) {
>  			scnprintf(buf, len, "\t# %"PRIx64" <%s>",
> @@ -338,6 +342,7 @@ static void print_capstone_detail(struct cs_insn *insn, char *buf, size_t len,
>  			scnprintf(buf, len, "\t# %"PRIx64" <%s+%#"PRIx64">",
>  				  orig_addr, sym->name, addr - sym->start);
>  		}
> +		map__put(found_map);
>  		break;
>  	}
>  }
> -- 
> 2.34.1
> 

  reply	other threads:[~2026-07-09  5:57 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01  3:53 [PATCH v3 00/21] perf arm64: Support data type profiling Tengda Wu
2026-07-01  3:53 ` [PATCH v3 01/21] perf capstone: Fix kernel map reference count leak Tengda Wu
2026-07-09  5:57   ` Namhyung Kim [this message]
2026-07-10 21:49     ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 02/21] perf capstone: Fix arm64 jump/adrp disassembly mismatch with objdump Tengda Wu
2026-07-01  3:53 ` [PATCH v3 03/21] perf llvm: Fix arm64 adrp instruction " Tengda Wu
2026-07-09  6:18   ` Namhyung Kim
2026-07-09  7:49     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 04/21] perf annotate-arm64: Generalize arm64_mov__parse to support more instructions Tengda Wu
2026-07-01  3:53 ` [PATCH v3 05/21] perf annotate-arm64: Handle load and store instructions Tengda Wu
2026-07-01  3:53 ` [PATCH v3 06/21] perf dwarf-regs: Adapt get_dwarf_regnum() for arm64 Tengda Wu
2026-07-01  3:53 ` [PATCH v3 07/21] perf annotate: Adapt arch__dwarf_regnum() " Tengda Wu
2026-07-01  3:53 ` [PATCH v3 08/21] perf annotate: Introduce extract_op_location callback for arch-specific parsing Tengda Wu
2026-07-01  3:53 ` [PATCH v3 09/21] perf annotate-arm64: Implement extract_op_location() callback Tengda Wu
2026-07-01  3:53 ` [PATCH v3 10/21] perf annotate: Deduplicate overlapping ARM SPE events for data type profiling Tengda Wu
2026-07-01  3:53 ` [PATCH v3 11/21] perf auxtrace: Set default period to 1 for PERF_ITRACE_PERIOD_INSTRUCTIONS type Tengda Wu
2026-07-01  3:53 ` [PATCH v3 12/21] perf annotate-data: Extract invalidate_reg_state() as a common helper Tengda Wu
2026-07-01  3:53 ` [PATCH v3 13/21] perf annotate-arm64: Enable instruction tracking support Tengda Wu
2026-07-01  3:53 ` [PATCH v3 14/21] perf annotate-arm64: Support load instruction tracking Tengda Wu
2026-07-01  3:53 ` [PATCH v3 15/21] perf annotate-arm64: Support store " Tengda Wu
2026-07-01  3:53 ` [PATCH v3 16/21] perf annotate-arm64: Support stack variable tracking Tengda Wu
2026-07-01  3:53 ` [PATCH v3 17/21] perf annotate-arm64: Support 'mov' instruction tracking Tengda Wu
2026-07-01  3:53 ` [PATCH v3 18/21] perf annotate-arm64: Support 'add' " Tengda Wu
2026-07-01  3:53 ` [PATCH v3 19/21] perf annotate-arm64: Support 'adrp' instruction to track global variables Tengda Wu
2026-07-09  7:31   ` Namhyung Kim
2026-07-09  7:42     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 20/21] perf annotate-arm64: Support per-cpu variable access tracking Tengda Wu
2026-07-09  7:29   ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 21/21] perf annotate-arm64: Support 'mrs' instruction to track 'current' pointer Tengda Wu
2026-07-09  5:54 ` [PATCH v3 00/21] perf arm64: Support data type profiling Namhyung Kim
2026-07-09  8:01   ` Tengda Wu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ak84NFSWQXz3r46x@z2 \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=kim.phillips@arm.com \
    --cc=leo.yan@linux.dev \
    --cc=lihuafei1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=morbo@google.com \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=peterz@infradead.org \
    --cc=wutengda@huaweicloud.com \
    --cc=xueshuai@linux.alibaba.com \
    --cc=zli94@ncsu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox