Hello,

On Fri, Jun 26, 2026 at 05:21:38PM -0400, Joe Lawrence wrote:
> This patchset fixes two minor perf bugs when livepatches containing
> special so-called livepatch symbols are loaded.  In both cases, perf
> should ignore these symbols as they resolve as relocations to kernel
> addresses and not module space.
> 
> - Patch 1 fixes `perf test 1`
> - Patch 2 fixes `perf record --kcore` bloat
> 
> 
> Testing notes
> =============
> 
> ("perf symbols: skip livepatch symbols when loading kallsyms"):
> 
>   Without patch:
>   ./tools/perf/perf test 1
>     1: vmlinux symtab matches kallsyms                     : FAILED!
> 
>   With patch:
>   ./tools/perf/perf test 1
>     1: vmlinux symtab matches kallsyms                     : Ok
> 
> ("perf symbols: skip livepatch symbols in kcore_copy")
> 
>   1. Baseline = pre-patch perf, no livepatch
>   ------------------------------------------
>   
>   $ ./tools/perf/perf record --kcore -a -o /tmp/baseline.data -- sleep 1
>   [ perf record: Woken up 1 times to write data ]
>   [ perf record: Captured and wrote 0.221 MB /tmp/baseline.data (1717 
> samples) ]
>   
>   $ tree --noreport -h /tmp/baseline.data
>   /tmp/baseline.data
>   |-- [ 235K]  data
>   `-- [   50]  kcore_dir
>       |-- [  11M]  kallsyms
>       |-- [  25M]  kcore
>       `-- [ 1.7K]  modules
>   
>   
>   2. Bloated kcore = pre-patch perf, with livepatch
>   -------------------------------------------------
>   
>   $ insmod kpatch-5_14_0-570_94_1-1-3.ko
>   $ ./tools/perf/perf record --kcore -a -o /tmp/klp-bloated.data -- sleep 1
>   [ perf record: Woken up 1 times to write data ]
>   [ perf record: Captured and wrote 0.274 MB /tmp/klp-bloated.data (2757 
> samples) ]
>   
>   $ tree --noreport  -h /tmp/klp-bloated.data
>   /tmp/klp-bloated.data
>   |-- [ 288K]  data
>   `-- [   50]  kcore_dir
>       |-- [  11M]  kallsyms
>       |-- [  68M]  kcore
>       `-- [ 1.8K]  modules
>   
>   
>   3. Post-fix = patched perf, with livepatch
>   ------------------------------------------
>   
>   [ kpatch-5_14_0-570_94_1-1-3.ko still loaded from test (2) ]
>   
>   $ ./tools/perf/perf record --kcore -a -o /tmp/postfix.data -- sleep 1
>   [ perf record: Woken up 1 times to write data ]
>   [ perf record: Captured and wrote 0.274 MB /tmp/postfix.data (2763 samples) 
> ]
>   
>   $ tree --noreport -h /tmp/postfix.data
>   /tmp/postfix.data
>   |-- [ 289K]  data
>   `-- [   50]  kcore_dir
>       |-- [  11M]  kallsyms
>       |-- [  25M]  kcore
>       `-- [ 1.8K]  modules
> 
> Changes
> =======
> 
> v2:
> - Move klp symbol check into tools/perf/util/symbol.h alongside similar
>   is_ignored_kernel_symbol() check [Petr]
> - Use KLP_SYM_PREFIX instead of inlining it [Petr]
> - Add similar check to kcore_copy__process_kallsyms() [Sashiko]
> 
> - Note: Sashiko flagged a pre-existing off-by-one in kallsyms__parse()
>   where the symbol-name loop could write past symbol_name[] on overlong
>   entries. That issue is unrelated to livepatch symbols and was already
>   fixed by Rui Qi's 68018df3f55e ("perf: Fix off-by-one stack buffer
>   overflow in kallsyms__parse()").

Petr, are you ok with this change?

Thanks,
Namhyung

> 
> v1: 
> https://lore.kernel.org/linux-perf-users/[email protected]/T/#t
> 
> Joe Lawrence (2):
>   perf symbols: skip livepatch symbols when loading kallsyms
>   perf symbols: skip livepatch symbols in kcore_copy kallsyms processing
> 
>  tools/perf/util/symbol-elf.c |  4 ++++
>  tools/perf/util/symbol.c     |  4 ++--
>  tools/perf/util/symbol.h     | 12 ++++++++++++
>  3 files changed, 18 insertions(+), 2 deletions(-)
> 
> -- 
> 2.54.0
> 

Reply via email to