1. 30 Mar, 2023 4 commits
    • Alexei Starovoitov's avatar
      Merge branch 'veristat: add better support of freplace programs' · 8a9abe02
      Alexei Starovoitov authored
      Andrii Nakryiko says:
      
      ====================
      
      Teach veristat how to deal with freplace BPF programs. As they can't be
      directly loaded by veristat without custom user-space part that sets correct
      target program FD, veristat always fails freplace programs. This patch set
      teaches veristat to guess target program type that will be inherited by
      freplace program itself, and subtitute it for BPF_PROG_TYPE_EXT (freplace) one
      for the purposes of BPF verification.
      
      Patch #1 fixes bug in libbpf preventing overriding freplace with specific
      program type.
      
      Patch #2 adds convenient -d flag to request veristat to emit libbpf debug
      logs. It help debugging why a specific BPF program fails to load, if the
      problem is not due to BPF verification itself.
      
      v3->v4:
        - fix optional kern_name check when guessing prog type (Alexei);
      v2->v3:
        - fix bpf_obj_id selftest that uses legacy bpf_prog_test_load() helper,
          which always sets program type programmatically; teach the helper to do it
          only if actually necessary (Stanislav);
      v1->v2:
        - fix compilation error reported by old GCC (my GCC v11 doesn't produce even
          a warning) and Clang (see CI failure at [0]):
      
      GCC version:
      
        veristat.c: In function ‘fixup_obj’:
        veristat.c:908:1: error: label at end of compound statement
          908 | skip_freplace_fixup:
              | ^~~~~~~~~~~~~~~~~~~
      
      Clang version:
      
        veristat.c:909:1: error: label at end of compound statement is a C2x extension [-Werror,-Wc2x-extensions]
        }
        ^
        1 error generated.
      
        [0] https://github.com/kernel-patches/bpf/actions/runs/4515972059/jobs/7953845335
      ====================
      Acked-by: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      8a9abe02
    • Andrii Nakryiko's avatar
      veristat: guess and substitue underlying program type for freplace (EXT) progs · fa7cc906
      Andrii Nakryiko authored
      SEC("freplace") (i.e., BPF_PROG_TYPE_EXT) programs are not loadable as
      is through veristat, as kernel expects actual program's FD during
      BPF_PROG_LOAD time, which veristat has no way of knowing.
      
      Unfortunately, freplace programs are a pretty important class of
      programs, especially when dealing with XDP chaining solutions, which
      rely on EXT programs.
      
      So let's do our best and teach veristat to try to guess the original
      program type, based on program's context argument type. And if guessing
      process succeeds, we manually override freplace/EXT with guessed program
      type using bpf_program__set_type() setter to increase chances of proper
      BPF verification.
      
      We rely on BTF and maintain a simple lookup table. This process is
      obviously not 100% bulletproof, as valid program might not use context
      and thus wouldn't have to specify correct type. Also, __sk_buff is very
      ambiguous and is the context type across many different program types.
      We pick BPF_PROG_TYPE_CGROUP_SKB for now, which seems to work fine in
      practice so far. Similarly, some program types require specifying attach
      type, and so we pick one out of possible few variants.
      
      Best effort at its best. But this makes veristat even more widely
      applicable.
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Tested-by: default avatarEduard Zingerman <eddyz87@gmail.com>
      Link: https://lore.kernel.org/r/20230327185202.1929145-4-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      fa7cc906
    • Andrii Nakryiko's avatar
      veristat: add -d debug mode option to see debug libbpf log · b3c63d7a
      Andrii Nakryiko authored
      Add -d option to allow requesting libbpf debug logs from veristat.
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20230327185202.1929145-3-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      b3c63d7a
    • Andrii Nakryiko's avatar
      libbpf: disassociate section handler on explicit bpf_program__set_type() call · d6e6286a
      Andrii Nakryiko authored
      If user explicitly overrides programs's type with
      bpf_program__set_type() API call, we need to disassociate whatever
      SEC_DEF handler libbpf determined initially based on program's SEC()
      definition, as it's not goind to be valid anymore and could lead to
      crashes and/or confusing failures.
      
      Also, fix up bpf_prog_test_load() helper in selftests/bpf, which is
      force-setting program type (even if that's completely unnecessary; this
      is quite a legacy piece of code), and thus should expect auto-attach to
      not work, yet one of the tests explicitly relies on auto-attach for
      testing.
      
      Instead, force-set program type only if it differs from the desired one.
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20230327185202.1929145-2-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      d6e6286a
  2. 29 Mar, 2023 4 commits
  3. 28 Mar, 2023 4 commits
  4. 27 Mar, 2023 2 commits
  5. 26 Mar, 2023 26 commits