All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Alireza Haghdoost <haghdoost@uber.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8 4/7] perf symbols: Check the file before reading lazy symbol names
Date: Sun, 22 Nov 2026 16:43:07 -0800	[thread overview]
Message-ID: <awOMG8xqEUl39vcW@google.com> (raw)
In-Reply-To: <20261121-perf-symbol-memory-send-v8-4-370561cbb5a7@uber.com>

On Sat, Nov 21, 2026 at 08:41:04AM -0800, Alireza Haghdoost wrote:
> This patch makes perf check that a file is still the one it loaded
> before it reads lazy symbol names from it. A lazy name is read later
> from a file that perf opens again by path, at the offset that its
> string table had at load time. If the file was replaced in between,
> for example by a deploy, perf would read names from the wrong file and
> print wrong names without a warning. Eager loading rejects such a
> file, since symsrc__init() checks its build ID.
> 
> perf checks the file each time it opens it again. dso__set_lazy_file()
> records the file at load time. Nothing calls it yet: the next patch
> makes the ELF loader call it when it creates lazy symbols.
> 
> If the DSO has a build ID, symsrc__init() matched the file with it at
> load time, so accept a file with that build ID, such as a copy of the
> same build. The build ID alone is not enough, since the offsets are
> only valid if the string tables did not move: objcopy
> --add-gnu-debuglink keeps the build ID but moves .strtab, and strip
> --strip-debug removes sections. So perf also records the index, offset
> and size of the .symtab and .dynsym string tables, and compares them.

I think it's extremely rare that the symbol file is being modified while
perf is running.

> 
> Reading the build ID each time is slow when most lookups load a name:
> the parity test on a 524 MiB binary, which loads 260k names one at a
> time, takes 9.3 seconds instead of 3.9. So perf also records the
> device, inode, size, mtime and ctime of the file, and reads the build
> ID only if they changed. The ctime changes when another file is copied
> over this one in place, even if its size and mtime are kept, as with
> cp -p. Then perf keeps the identity of the accepted file for later
> reads. With this, the test takes 4.1 seconds. A DSO without a build ID
> must keep the same identity.

Is ctime really needed?  I think dev/inode will catch new file creation
and mtime is for in-place mofifications.

> 
> If the file is not the one perf loaded, perf warns and shows the
> remaining lazy symbols of that DSO as "[unknown]" rather than print
> wrong names, without opening the file again. If the file cannot be
> opened or checked, for example because perf ran out of file descriptors
> or fstat() or a read of its ELF headers failed, perf warns once and
> shows the symbols it was reading the names of as "[unknown]", but tries
> again for later names, since the failure can be temporary. A file whose
> build ID cannot be read counts as not checked, since perf cannot tell a
> failed read from a missing build ID note; perf reads no names from it
> either.
> 
> Like symsrc__init(), the check trusts the build ID: a file edited after
> linking without a new build ID, and with its string tables in place,
> gives the edited names.

Right, but I don't think it's gonna be a problem in practice.

Thanks,
Namhyung

> 
> The unit tests later in this series cover these cases.
> 
> No functional change, since no symbol has a lazy name yet.
> 
> Signed-off-by: Alireza Haghdoost <haghdoost@uber.com>
> ---

  reply	other threads:[~2026-11-23  0:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 16:41 [PATCH v8 0/7] perf script: Lazy symbol loading Alireza Haghdoost via B4 Relay
2026-11-21 16:41 ` Alireza Haghdoost
2026-11-21 16:41 ` [PATCH v8 1/7] perf symbols: Split out name-independent duplicate symbol selection Alireza Haghdoost via B4 Relay
2026-11-21 16:41   ` Alireza Haghdoost
2026-11-21 16:41 ` [PATCH v8 2/7] perf symbols: Point to the symbol name instead of embedding it Alireza Haghdoost via B4 Relay
2026-11-21 16:41   ` Alireza Haghdoost
2026-11-21 16:41 ` [PATCH v8 3/7] perf symbols: Add lazy symbol names Alireza Haghdoost via B4 Relay
2026-11-21 16:41   ` Alireza Haghdoost
2026-11-21 16:41 ` [PATCH v8 4/7] perf symbols: Check the file before reading " Alireza Haghdoost via B4 Relay
2026-11-21 16:41   ` Alireza Haghdoost
2026-11-23  0:43   ` Namhyung Kim [this message]
2026-11-23 22:02     ` Alireza Haghdoost
2026-11-21 16:41 ` [PATCH v8 5/7] perf script: Add --lazy-load-symbols to load symbol names lazily Alireza Haghdoost
2026-11-21 16:41   ` Alireza Haghdoost via B4 Relay
2026-11-23  1:03   ` Namhyung Kim
2026-11-23 22:32     ` Alireza Haghdoost
2026-11-21 16:41 ` [PATCH v8 6/7] perf test: Add lazy symbol loading unit tests Alireza Haghdoost via B4 Relay
2026-11-21 16:41   ` Alireza Haghdoost
2026-11-21 16:41 ` [PATCH v8 7/7] perf test: Add lazy symbol loading shell tests Alireza Haghdoost via B4 Relay
2026-11-21 16:41   ` Alireza Haghdoost
2026-11-21 17:00 ` [PATCH v8 0/7] perf script: Lazy symbol loading sashiko-bot
2026-11-23  2:04 ` Namhyung Kim

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=awOMG8xqEUl39vcW@google.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=haghdoost@uber.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.