• Yonghong Song's avatar
    selftests/bpf: Fix kprobe_multi_bench_attach test failure with LTO kernel · 9edaafad
    Yonghong Song authored
    In my locally build clang LTO kernel (enabling CONFIG_LTO and
    CONFIG_LTO_CLANG_THIN), kprobe_multi_bench_attach/kernel subtest
    failed like:
      test_kprobe_multi_bench_attach:PASS:get_syms 0 nsec
      test_kprobe_multi_bench_attach:PASS:kprobe_multi_empty__open_and_load 0 nsec
      libbpf: prog 'test_kprobe_empty': failed to attach: No such process
      test_kprobe_multi_bench_attach:FAIL:bpf_program__attach_kprobe_multi_opts unexpected error: -3
      #117/1   kprobe_multi_bench_attach/kernel:FAIL
    
    There are multiple symbols in /sys/kernel/debug/tracing/available_filter_functions
    are renamed in /proc/kallsyms due to cross file inlining. One example is for
      static function __access_remote_vm in mm/memory.c.
    In a non-LTO kernel, we have the following call stack:
      ptrace_access_vm (global, kernel/ptrace.c)
        access_remote_vm (global, mm/memory.c)
          __access_remote_vm (static, mm/memory.c)
    
    With LTO kernel, it is possible that access_remote_vm() is inlined by
    ptrace_access_vm(). So we end up with the following call stack:
      ptrace_access_vm (global, kernel/ptrace.c)
        __access_remote_vm (static, mm/memory.c)
    The compiler renames __access_remote_vm to __access_remote_vm.llvm.<hash>
    to prevent potential name collision.
    
    The kernel bpf_kprobe_multi_link_attach() and ftrace_lookup_symbols() try
    to find addresses based on /proc/kallsyms, hence the current test failed
    with LTO kenrel.
    
    This patch consulted /proc/kallsyms to find the corresponding entries
    for the ksym and this solved the issue.
    Signed-off-by: default avatarYonghong Song <yonghong.song@linux.dev>
    Link: https://lore.kernel.org/r/20240326041518.1199758-1-yonghong.song@linux.devSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    9edaafad
kprobe_multi_test.c 15.5 KB