Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2] perf record: Fix destructor invocation and event counting in fdarray__filter
Date: Thu, 16 Jul 2026 08:00:43 +0000	[thread overview]
Message-ID: <20260716080043.BBC751F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716073753.567782-1-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] perf record and perf trace hang indefinitely when profiling a target process that exits.
--

--- Patch [1]: [PATCH v2] perf record: Fix destructor invocation and event counting in fdarray__filter ---
commit 586c1ed32764876e9ecee40639dd9f2a7fcfdcd5
Author: Ian Rogers <irogers@google.com>

perf record: Fix destructor invocation and event counting in fdarray__filter

This commit modifies the fdarray filtering logic to separate lifecycle and
masking logic. It removes the early bypass for nonfilterable file descriptors
so their destructors can run, and uses a non_perf_event flag to prevent
clearing their masks.

> diff --git a/tools/lib/api/fd/array.c b/tools/lib/api/fd/array.c
> index 16a047f1906ee..92d9a3fb652c0 100644
> --- a/tools/lib/api/fd/array.c
> +++ b/tools/lib/api/fd/array.c
> @@ -115,9 +115,6 @@ int fdarray__filter(struct fdarray *fda, short revents,
>  		return 0;
>  
>  	for (fd = 0; fd < fda->nr; ++fd) {
> -		if (fda->priv[fd].flags & fdarray_flag__nonfilterable)
> -			continue;
> -
>  		if (!fda->entries[fd].events)
>  			continue;
>  
> @@ -125,6 +122,9 @@ int fdarray__filter(struct fdarray *fda, short revents,
>  			if (entry_destructor)
>  				entry_destructor(fda, fd, arg);
>  
> +			if (fda->priv[fd].flags & fdarray_flag__non_perf_event)
> +				continue;
> +
>  			/*
>  			 * Set fd to -1 so poll() ignores this entry; otherwise

[Severity: High]
With the removal of the early continue for nonfilterable file descriptors,
does this regression cause the active event count to never reach zero? 

When profiling a target process that exits, auxiliary file descriptors like
control pipes usually do not match the revents mask (such as POLLHUP). They
now bypass the revents check block and unconditionally reach the counter
increment at the bottom of the loop:

fdarray__filter()
        ...
		if (fda->entries[fd].revents & revents) {
			...
			continue;
		}

		++nr;
	}

	return nr;
}

In the main event loop, __cmd_record() relies on this function returning 0
to transition to the draining state and terminate gracefully:

    if (fdarray__filter(&thread->pollfd, POLLERR | POLLHUP,
                        record__thread_munmap_filtered, NULL) == 0)
        draining = true;

Since nonfilterable and non-perf-event file descriptors unconditionally
increment nr when they don't have matching revents, could this cause
perf record and perf trace to hang indefinitely waiting in poll()
after the traced process exits?

[ ... ]

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

      reply	other threads:[~2026-07-16  8:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10  5:39 [PATCH v1 1/2] perf record: Fix teardown hang on system-wide multi-threaded sessions Ian Rogers
2026-07-10  5:39 ` [PATCH v1 2/2] perf cap: If capability is missing still perform root test Ian Rogers
2026-07-10  5:47   ` sashiko-bot
2026-07-10 22:24     ` Namhyung Kim
2026-07-16  7:40       ` [PATCH v2] perf cap: Remove used_root parameter and simplify capability checks Ian Rogers
2026-07-10  5:56 ` [PATCH v1 1/2] perf record: Fix teardown hang on system-wide multi-threaded sessions sashiko-bot
2026-07-10 22:02 ` Namhyung Kim
2026-07-12  6:56 ` (subset) " Namhyung Kim
2026-07-16  7:37   ` [PATCH v2] perf record: Fix destructor invocation and event counting in fdarray__filter Ian Rogers
2026-07-16  8:00     ` sashiko-bot [this message]

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=20260716080043.BBC751F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=irogers@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