1. 21 Aug, 2023 37 commits
  2. 18 Aug, 2023 3 commits
    • Yonghong Song's avatar
      selftests/bpf: Fix a selftest compilation error · 0a55264c
      Yonghong Song authored
      When building the kernel and selftest with clang compiler (llvm17 or llvm18),
      I hit the following compilation failure:
        In file included from progs/test_lwt_redirect.c:3:
        In file included from /usr/include/linux/ip.h:21:
        In file included from /usr/include/asm/byteorder.h:5:
        In file included from /usr/include/linux/byteorder/little_endian.h:13:
        /usr/include/linux/swab.h:136:8: error: unknown type name '__always_inline'
          136 | static __always_inline unsigned long __swab(const unsigned long y)
              |        ^
        /usr/include/linux/swab.h:171:8: error: unknown type name '__always_inline'
          171 | static __always_inline __u16 __swab16p(const __u16 *p)
        ...
      
      bpf_helpers.h file provided a definition for __always_inline.
      Putting 'ip.h' after 'bpf_helpers.h' fixed the issue.
      
      Fixes: 43a7c3ef ("selftests/bpf: Add lwt_xmit tests for BPF_REDIRECT")
      Signed-off-by: default avatarYonghong Song <yonghong.song@linux.dev>
      Link: https://lore.kernel.org/r/20230818174312.1883381-1-yonghong.song@linux.devSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
      0a55264c
    • Dave Marchevsky's avatar
      selftests/bpf: Add CO-RE relocs kfunc flavors tests · 63ae8eb2
      Dave Marchevsky authored
      This patch adds selftests that exercise kfunc flavor relocation
      functionality added in the previous patch. The actual kfunc defined
      in kernel/bpf/helpers.c is:
      
        struct task_struct *bpf_task_acquire(struct task_struct *p)
      
      The following relocation behaviors are checked:
      
        struct task_struct *bpf_task_acquire___one(struct task_struct *name)
          * Should succeed despite differing param name
      
        struct task_struct *bpf_task_acquire___two(struct task_struct *p, void *ctx)
          * Should fail because there is no two-param bpf_task_acquire
      
        struct task_struct *bpf_task_acquire___three(void *ctx)
          * Should fail because, despite vmlinux's bpf_task_acquire having one param,
            the types don't match
      Signed-off-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarDavid Vernet <void@manifault.com>
      Link: https://lore.kernel.org/bpf/20230817225353.2570845-2-davemarchevsky@fb.com
      63ae8eb2
    • Dave Marchevsky's avatar
      libbpf: Support triple-underscore flavors for kfunc relocation · 5964a223
      Dave Marchevsky authored
      The function signature of kfuncs can change at any time due to their
      intentional lack of stability guarantees. As kfuncs become more widely
      used, BPF program writers will need facilities to support calling
      different versions of a kfunc from a single BPF object. Consider this
      simplified example based on a real scenario we ran into at Meta:
      
        /* initial kfunc signature */
        int some_kfunc(void *ptr)
      
        /* Oops, we need to add some flag to modify behavior. No problem,
          change the kfunc. flags = 0 retains original behavior */
        int some_kfunc(void *ptr, long flags)
      
      If the initial version of the kfunc is deployed on some portion of the
      fleet and the new version on the rest, a fleetwide service that uses
      some_kfunc will currently need to load different BPF programs depending
      on which some_kfunc is available.
      
      Luckily CO-RE provides a facility to solve a very similar problem,
      struct definition changes, by allowing program writers to declare
      my_struct___old and my_struct___new, with ___suffix being considered a
      'flavor' of the non-suffixed name and being ignored by
      bpf_core_type_exists and similar calls.
      
      This patch extends the 'flavor' facility to the kfunc extern
      relocation process. BPF program writers can now declare
      
        extern int some_kfunc___old(void *ptr)
        extern int some_kfunc___new(void *ptr, int flags)
      
      then test which version of the kfunc exists with bpf_ksym_exists.
      Relocation and verifier's dead code elimination will work in concert as
      expected, allowing this pattern:
      
        if (bpf_ksym_exists(some_kfunc___old))
          some_kfunc___old(ptr);
        else
          some_kfunc___new(ptr, 0);
      Signed-off-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarDavid Vernet <void@manifault.com>
      Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
      Link: https://lore.kernel.org/bpf/20230817225353.2570845-1-davemarchevsky@fb.com
      5964a223