Re: [PATCH] libtracecmd: Support changing /proc/kallsyms

Ilya Leoshkevich <[email protected]> Wed, 14 May 2025 09:51:16 +0200
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
On Thu, 2025-04-17 at 01:13 +0200, Ilya Leoshkevich wrote:
> Running BPF selftests under trace-cmd intermittently fails with:
> 
>     error in size of file '/proc/kallsyms'
> 
> This is because these selftests load and unload BPF programs.
> bpf_prog_put() uses workqueues and RCU, so these programs disappear
> from /proc/kallsyms after a delay.
> 
> trace-cmd reads /proc/kallsyms twice: the first time to compute its
> size, and the second time to copy it into the trace file. If the
> resulting sizes don't match, which is what happens in this case,
> recording fails.
> 
> Fix by first copying /proc/kallsyms into a temporary file, and then
> into the trace file. An alternative would be to read it into a
> malloc()-ed buffer, but this would increase trace-cmd memory usage,
> since /proc/kallsyms can be a few dozen megabytes large. In case
> /tmp is tmpfs, both solutions are almost equivalent.
> 
> Signed-off-by: Ilya Leoshkevich <[email protected]>
> ---
>  lib/trace-cmd/trace-output.c | 66 ++++++++++++++++++++++++++++------
> --
>  1 file changed, 52 insertions(+), 14 deletions(-)

Gentle ping.