Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chun-Tse Shao" <ctshao@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v6 2/2] perf evsel: Find process with busy PMUs for EBUSY
Date: Mon, 18 May 2026 18:27:44 +0000	[thread overview]
Message-ID: <20260518182744.E56CFC2BCB7@smtp.kernel.org> (raw)
In-Reply-To: <20260518174159.1177549-2-ctshao@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The file descriptor `fdinfo_fd` is permanently leaked on all successful open paths.
--

commit 89c8fa0a46a0a7739ea59073f27c6161911eb75b
Author: Chun-Tse Shao <ctshao@google.com>

perf evsel: Find process with busy PMUs for EBUSY

This commit parses the fdinfo of perf events to extract the PMU type.
It then compares this type with the failed event to accurately report
the specific processes that are causing an EBUSY error.

> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 2ee87fd84d3ea..f6282099320ee 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
[ ... ]
> @@ -3969,29 +3970,61 @@ static int dump_perf_event_processes(char *msg, size_t size)
>  				continue;
>  			/* Take care as readlink doesn't null terminate the string. */
>  			if (!strncmp(buf, "anon_inode:[perf_event]", link_size)) {
> -				int cmdline_fd;
> -				ssize_t cmdline_size;
> -
> -				scnprintf(buf, sizeof(buf), "%s/cmdline", proc_entry->d_name);
> -				cmdline_fd = openat(dirfd(proc_dir), buf, O_RDONLY);
> -				if (cmdline_fd == -1)
> -					continue;
> -				cmdline_size = read(cmdline_fd, buf, sizeof(buf) - 1);
> -				close(cmdline_fd);
> -				if (cmdline_size < 0)
> +				int fdinfo_fd;
> +				ssize_t fdinfo_size;
> +				char *line;
> +				u32 perf_event_type = UINT32_MAX;
> +
> +				/* Let's check the PMU type reserved by this process */
> +				scnprintf(buf, sizeof(buf), "%s/fdinfo/%s",
> +					  proc_entry->d_name, fd_entry->d_name);
> +				fdinfo_fd = openat(dirfd(proc_dir), buf, O_RDONLY);
> +				fdinfo_size = read(fdinfo_fd, buf, sizeof(buf) - 1);
> +				if (fdinfo_size < 0)
>  					continue;

Is fdinfo_fd leaked here and on subsequent execution paths in this loop?

Since this loop scans potentially thousands of file descriptors across all
active processes in /proc, could leaking a file descriptor for every
discovered perf event rapidly exhaust the process's file descriptor limit
and lead to EMFILE?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260518174159.1177549-1-ctshao@google.com?part=2

  reply	other threads:[~2026-05-18 18:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-18 17:41 [PATCH v6 1/2] perf: Reveal PMU type in fdinfo Chun-Tse Shao
2026-05-18 17:41 ` [PATCH v6 2/2] perf evsel: Find process with busy PMUs for EBUSY Chun-Tse Shao
2026-05-18 18:27   ` sashiko-bot [this message]
2026-05-18 18:12 ` [PATCH v6 1/2] perf: Reveal PMU type in fdinfo sashiko-bot

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=20260518182744.E56CFC2BCB7@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ctshao@google.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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