The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf build-id: Fix caching files with a wrong build ID
Date: Tue, 21 Jun 2022 12:56:09 -0300	[thread overview]
Message-ID: <YrHqGS0XB800GF09@kernel.org> (raw)
In-Reply-To: <20220621125144.5623-1-adrian.hunter@intel.com>

Em Tue, Jun 21, 2022 at 03:51:44PM +0300, Adrian Hunter escreveu:
> Build ID events associate a file name with a build ID.  However, when
> using perf inject, there is no guarantee that the file on the current
> machine at the current time has that build ID. Fix by comparing the
> build IDs and skip adding to the cache if they are different.
> 
> Example:
> 
>  $ echo "int main() {return 0;}" > prog.c
>  $ gcc -o prog prog.c
>  $ perf record --buildid-all ./prog
>  [ perf record: Woken up 1 times to write data ]
>  [ perf record: Captured and wrote 0.019 MB perf.data ]
>  $ file-buildid() { file $1 | awk -F= '{print $2}' | awk -F, '{print $1}' ; }
>  $ file-buildid prog
>  444ad9be165d8058a48ce2ffb4e9f55854a3293e
>  $ file-buildid ~/.debug/$(pwd)/prog/444ad9be165d8058a48ce2ffb4e9f55854a3293e/elf
>  444ad9be165d8058a48ce2ffb4e9f55854a3293e
>  $ echo "int main() {return 1;}" > prog.c
>  $ gcc -o prog prog.c
>  $ file-buildid prog
>  885524d5aaa24008a3e2b06caa3ea95d013c0fc5
> 
>  Before:
> 
>  $ perf buildid-cache --purge $(pwd)/prog
>  $ perf inject -i perf.data -o junk
>  $ file-buildid ~/.debug/$(pwd)/prog/444ad9be165d8058a48ce2ffb4e9f55854a3293e/elf
>  885524d5aaa24008a3e2b06caa3ea95d013c0fc5
>  $
> 
>  After:
> 
>  $ perf buildid-cache --purge $(pwd)/prog
>  $ perf inject -i perf.data -o junk
>  $ file-buildid ~/.debug/$(pwd)/prog/444ad9be165d8058a48ce2ffb4e9f55854a3293e/elf
> 
>  $
> 
> Fixes: 454c407ec17a0c ("perf: add perf-inject builtin")


Thanks, applied.

- Arnaldo


> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  tools/perf/util/build-id.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
> index 82f3d46bea70..328668f38c69 100644
> --- a/tools/perf/util/build-id.c
> +++ b/tools/perf/util/build-id.c
> @@ -872,6 +872,30 @@ int build_id_cache__remove_s(const char *sbuild_id)
>  	return err;
>  }
>  
> +static int filename__read_build_id_ns(const char *filename,
> +				      struct build_id *bid,
> +				      struct nsinfo *nsi)
> +{
> +	struct nscookie nsc;
> +	int ret;
> +
> +	nsinfo__mountns_enter(nsi, &nsc);
> +	ret = filename__read_build_id(filename, bid);
> +	nsinfo__mountns_exit(&nsc);
> +
> +	return ret;
> +}
> +
> +static bool dso__build_id_mismatch(struct dso *dso, const char *name)
> +{
> +	struct build_id bid;
> +
> +	if (filename__read_build_id_ns(name, &bid, dso->nsinfo) < 0)
> +		return false;
> +
> +	return !dso__build_id_equal(dso, &bid);
> +}
> +
>  static int dso__cache_build_id(struct dso *dso, struct machine *machine,
>  			       void *priv __maybe_unused)
>  {
> @@ -886,6 +910,10 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine,
>  		is_kallsyms = true;
>  		name = machine->mmap_name;
>  	}
> +
> +	if (!is_kallsyms && dso__build_id_mismatch(dso, name))
> +		return 0;
> +
>  	return build_id_cache__add_b(&dso->bid, name, dso->nsinfo,
>  				     is_kallsyms, is_vdso);
>  }
> -- 
> 2.25.1

-- 

- Arnaldo

      reply	other threads:[~2022-06-21 15:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21 12:51 [PATCH] perf build-id: Fix caching files with a wrong build ID Adrian Hunter
2022-06-21 15:56 ` Arnaldo Carvalho de Melo [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=YrHqGS0XB800GF09@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /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