• Andrii Nakryiko's avatar
    libbpf: warn on unexpected __arg_ctx type when rewriting BTF · 76ec90a9
    Andrii Nakryiko authored
    On kernel that don't support arg:ctx tag, before adjusting global
    subprog BTF information to match kernel's expected canonical type names,
    make sure that types used by user are meaningful, and if not, warn and
    don't do BTF adjustments.
    
    This is similar to checks that kernel performs, but narrower in scope,
    as only a small subset of BPF program types can be accommodated by
    libbpf using canonical type names.
    
    Libbpf unconditionally allows `struct pt_regs *` for perf_event program
    types, unlike kernel, which supports that conditionally on architecture.
    This is done to keep things simple and not cause unnecessary false
    positives. This seems like a minor and harmless deviation, which in
    real-world programs will be caught by kernels with arg:ctx tag support
    anyways. So KISS principle.
    
    This logic is hard to test (especially on latest kernels), so manual
    testing was performed instead. Libbpf emitted the following warning for
    perf_event program with wrong context argument type:
    
      libbpf: prog 'arg_tag_ctx_perf': subprog 'subprog_ctx_tag' arg#0 is expected to be of `struct bpf_perf_event_data *` type
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/r/20240118033143.3384355-6-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    76ec90a9
libbpf.c 369 KB