1. Aug 22, 2023
  2. Aug 19, 2023
    • 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.dev
      
      
      Signed-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
  3. Aug 18, 2023
  4. Aug 17, 2023
    • Jakub Kicinski's avatar
      Merge tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next · f54a2a13
      Jakub Kicinski authored
      Daniel Borkmann says:
      
      ====================
      pull-request: bpf-next 2023-08-16
      
      We've added 17 non-merge commits during the last 6 day(s) which contain
      a total of 20 files changed, 1179 insertions(+), 37 deletions(-).
      
      The main changes are:
      
      1) Add a BPF hook in sys_socket() to change the protocol ID
         from IPPROTO_TCP to IPPROTO_MPTCP to cover migration for legacy
         applications, from Geliang Tang.
      
      2) Follow-up/fallout fix from the SO_REUSEPORT + bpf_sk_assign work
         to fix a splat on non-fullsock sks in inet[6]_steal_sock,
         from Lorenz Bauer.
      
      3) Improvements to struct_ops links to avoid forcing presence of
         update/validate callbacks. Also add bpf_struct_ops fields documentation,
         from David Vernet.
      
      4) Ensure libbpf sets close-on-exec flag on gzopen, from Marco Vedovati.
      
      5) Several new tcx selftest additions and bpftool link show support for
         tcx and xdp links, from Daniel Borkmann.
      
      6) Fix a smatch warning on uninitialized symbol in
         bpf_perf_link_fill_kprobe, from Yafang Shao.
      
      7) BPF selftest fixes e.g. misplaced break in kfunc_call test,
         from Yipeng Zou.
      
      8) Small cleanup to remove unused declaration bpf_link_new_file,
         from Yue Haibing.
      
      9) Small typo fix to bpftool's perf help message, from Daniel T. Lee.
      
      * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next:
        selftests/bpf: Add mptcpify test
        selftests/bpf: Fix error checks of mptcp open_and_load
        selftests/bpf: Add two mptcp netns helpers
        bpf: Add update_socket_protocol hook
        bpftool: Implement link show support for xdp
        bpftool: Implement link show support for tcx
        selftests/bpf: Add selftest for fill_link_info
        bpf: Fix uninitialized symbol in bpf_perf_link_fill_kprobe()
        net: Fix slab-out-of-bounds in inet[6]_steal_sock
        bpf: Document struct bpf_struct_ops fields
        bpf: Support default .validate() and .update() behavior for struct_ops links
        selftests/bpf: Add various more tcx test cases
        selftests/bpf: Clean up fmod_ret in bench_rename test script
        selftests/bpf: Fix repeat option when kfunc_call verification fails
        libbpf: Set close-on-exec flag on gzopen
        bpftool: fix perf help message
        bpf: Remove unused declaration bpf_link_new_file()
      ====================
      
      Link: https://lore.kernel.org/r/20230816212840.1539-1-daniel@iogearbox.net
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      f54a2a13
    • Jakub Kicinski's avatar
      Revert "net: ethernet: ti: am65-cpsw: add mqprio qdisc offload in channel mode" · 42b118c9
      Jakub Kicinski authored
      This reverts commit 90bc21aa.
      
      Patch was merged too hastily, Vladimir requested changes in:
      https://lore.kernel.org/all/20230816121305.5dio5tk3chge2ndh@skbuf/
      
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      42b118c9
    • Martin KaFai Lau's avatar
      Merge branch 'bpf: Force to MPTCP' · de405373
      Martin KaFai Lau authored
      Geliang Tang says:
      
      ====================
      As is described in the "How to use MPTCP?" section in MPTCP wiki [1]:
      
      "Your app should create sockets with IPPROTO_MPTCP as the proto:
      ( socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP); ). Legacy apps can be
      forced to create and use MPTCP sockets instead of TCP ones via the
      mptcpize command bundled with the mptcpd daemon."
      
      But the mptcpize (LD_PRELOAD technique) command has some limitations
      [2]:
      
       - it doesn't work if the application is not using libc (e.g. GoLang
      apps)
       - in some envs, it might not be easy to set env vars / change the way
      apps are launched, e.g. on Android
       - mptcpize needs to be launched with all apps that want MPTCP: we could
      have more control from BPF to enable MPTCP only for some apps or all the
      ones of a netns or a cgroup, etc.
       - it is not in BPF, we cannot talk about it at netdev conf.
      
      So this patchset attempts to use BPF to implement functions similer to
      mptcpize.
      
      The main idea is to add a hook in sys_socket() to change the protocol id
      from IPPROTO_TCP (or 0) to IPPROTO_MPTCP.
      
      [1]
      https://github.com/multipath-tcp/mptcp_net-next/wiki
      [2]
      https://github.com/multipath-tcp/mptcp_net-next/issues/79
      
      v14:
       - Use getsockopt(MPTCP_INFO) to verify mptcp protocol intead of using
      nstat command.
      
      v13:
       - drop "Use random netns name for mptcp" patch.
      
      v12:
       - update diag_* log of update_socket_protocol.
       - add 'ip netns show' after 'ip netns del' to check if there is
      a test did not clean up its netns.
       - return libbpf_get_error() instead of -EIO for the error from
      open_and_load().
       - Use getsockopt(SOL_PROTOCOL) to verify mptcp protocol intead of
      using 'ss -tOni'.
      
      v11:
       - add comments about outputs of 'ss' and 'nstat'.
       - use "err = verify_mptcpify()" instead of using =+.
      
      v10:
       - drop "#ifdef CONFIG_BPF_JIT".
       - include vmlinux.h and bpf_tracing_net.h to avoid defining some
      macros.
       - drop unneeded checks for mptcp.
      
      v9:
       - update comment for 'update_socket_protocol'.
      
      v8:
       - drop the additional checks on the 'protocol' value after the
      'update_socket_protocol()' call.
      
      v7:
       - add __weak and __diag_* for update_socket_protocol.
      
      v6:
       - add update_socket_protocol.
      
      v5:
       - add bpf_mptcpify helper.
      
      v4:
       - use lsm_cgroup/socket_create
      
      v3:
       - patch 8: char cmd[128]; -> char cmd[256];
      
      v2:
       - Fix build selftests errors reported by CI
      
      Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/79
      
      
      ====================
      
      Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
      de405373
    • Geliang Tang's avatar
      selftests/bpf: Add mptcpify test · ddba1224
      Geliang Tang authored
      
      
      Implement a new test program mptcpify: if the family is AF_INET or
      AF_INET6, the type is SOCK_STREAM, and the protocol ID is 0 or
      IPPROTO_TCP, set it to IPPROTO_MPTCP. It will be hooked in
      update_socket_protocol().
      
      Extend the MPTCP test base, add a selftest test_mptcpify() for the
      mptcpify case. Open and load the mptcpify test prog to mptcpify the
      TCP sockets dynamically, then use start_server() and connect_to_fd()
      to create a TCP socket, but actually what's created is an MPTCP
      socket, which can be verified through 'getsockopt(SOL_PROTOCOL)'
      and 'getsockopt(MPTCP_INFO)'.
      
      Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
      Reviewed-by: default avatarMatthieu Baerts <matthieu.baerts@tessares.net>
      Signed-off-by: default avatarGeliang Tang <geliang.tang@suse.com>
      Link: https://lore.kernel.org/r/364e72f307e7bb38382ec7442c182d76298a9c41.1692147782.git.geliang.tang@suse.com
      
      
      Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
      ddba1224
    • Geliang Tang's avatar
      selftests/bpf: Fix error checks of mptcp open_and_load · 20774655
      Geliang Tang authored
      
      
      Return libbpf_get_error(), instead of -EIO, for the error from
      mptcp_sock__open_and_load().
      
      Load success means prog_fd and map_fd are always valid. So drop these
      unneeded ASSERT_GE checks for them in mptcp run_test().
      
      Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
      Signed-off-by: default avatarGeliang Tang <geliang.tang@suse.com>
      Link: https://lore.kernel.org/r/db5fcb93293df9ab173edcbaf8252465b80da6f2.1692147782.git.geliang.tang@suse.com
      
      
      Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
      20774655