linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: James Clark <james.clark@linaro.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Stephen Brennan <stephen.s.brennan@oracle.com>,
	Haibo Xu <haibo1.xu@intel.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] perf symbol: Fix ENOENT case for filename__read_build_id
Date: Tue, 9 Dec 2025 09:47:17 +0000	[thread overview]
Message-ID: <45aa45d0-3fd6-4073-87b5-80af287ca9ac@linaro.org> (raw)
In-Reply-To: <20251207022345.909535-1-irogers@google.com>



On 07/12/2025 2:23 am, Ian Rogers wrote:
> Some callers of filename__read_build_id assume the error value must be
> -1, fix by making them handle all < 0 values.
> 
> If is_regular_file fails in filename__read_build_id then it could be
> the file is missing (ENOENT) and it would be wrong to return
> -EWOULDBLOCK in that case. Fix the logic so -EWOULDBLOCK is only
> reported if other errors with stat haven't occurred.
> 
> Fixes: 834ebb5678d7 ("perf tools: Don't read build-ids from non-regular files")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> Note, a shorter version of this patch appeared in a series
> cleaning/refactoring the build id reading code:
> https://lore.kernel.org/lkml/20251201205509.195451-11-irogers@google.com/
> It is sent without the refactor for the sake of fixing the bug in an
> earlier release.

Reviewed-by: James Clark <james.clark@linaro.org>

> ---
>   tools/perf/builtin-buildid-cache.c | 6 ++++--
>   tools/perf/util/libbfd.c           | 4 +++-
>   tools/perf/util/symbol-elf.c       | 4 +++-
>   tools/perf/util/symbol-minimal.c   | 4 +++-
>   4 files changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
> index c98104481c8a..539e779e3268 100644
> --- a/tools/perf/builtin-buildid-cache.c
> +++ b/tools/perf/builtin-buildid-cache.c
> @@ -276,12 +276,14 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
>   {
>   	char filename[PATH_MAX];
>   	struct build_id bid = { .size = 0, };
> +	int err;
>   
>   	if (!dso__build_id_filename(dso, filename, sizeof(filename), false))
>   		return true;
>   
> -	if (filename__read_build_id(filename, &bid) == -1) {
> -		if (errno == ENOENT)
> +	err = filename__read_build_id(filename, &bid);
> +	if (err < 0) {
> +		if (err == -ENOENT)
>   			return false;
>   
>   		pr_warning("Problems with %s file, consider removing it from the cache\n",
> diff --git a/tools/perf/util/libbfd.c b/tools/perf/util/libbfd.c
> index 0099b415decc..edf0829e9635 100644
> --- a/tools/perf/util/libbfd.c
> +++ b/tools/perf/util/libbfd.c
> @@ -391,8 +391,10 @@ int libbfd__read_build_id(const char *filename, struct build_id *bid)
>   
>   	if (!filename)
>   		return -EFAULT;
> +
> +	errno = 0;
>   	if (!is_regular_file(filename))
> -		return -EWOULDBLOCK;
> +		return errno == 0 ? -EWOULDBLOCK : -errno;
>   
>   	fd = open(filename, O_RDONLY);
>   	if (fd < 0)
> diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
> index 957143fbf8a0..d1dcafa4b3b8 100644
> --- a/tools/perf/util/symbol-elf.c
> +++ b/tools/perf/util/symbol-elf.c
> @@ -902,8 +902,10 @@ int filename__read_build_id(const char *filename, struct build_id *bid)
>   
>   	if (!filename)
>   		return -EFAULT;
> +
> +	errno = 0;
>   	if (!is_regular_file(filename))
> -		return -EWOULDBLOCK;
> +		return errno == 0 ? -EWOULDBLOCK : -errno;
>   
>   	err = kmod_path__parse(&m, filename);
>   	if (err)
> diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-minimal.c
> index c6b17c14a2e9..8221dc9868f7 100644
> --- a/tools/perf/util/symbol-minimal.c
> +++ b/tools/perf/util/symbol-minimal.c
> @@ -104,8 +104,10 @@ int filename__read_build_id(const char *filename, struct build_id *bid)
>   
>   	if (!filename)
>   		return -EFAULT;
> +
> +	errno = 0;
>   	if (!is_regular_file(filename))
> -		return -EWOULDBLOCK;
> +		return errno == 0 ? -EWOULDBLOCK : -errno;
>   
>   	fd = open(filename, O_RDONLY);
>   	if (fd < 0)


      reply	other threads:[~2025-12-09  9:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-07  2:23 [PATCH v1] perf symbol: Fix ENOENT case for filename__read_build_id Ian Rogers
2025-12-09  9:47 ` James Clark [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=45aa45d0-3fd6-4073-87b5-80af287ca9ac@linaro.org \
    --to=james.clark@linaro.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=haibo1.xu@intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=stephen.s.brennan@oracle.com \
    /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;
as well as URLs for NNTP newsgroup(s).