1. 03 Feb, 2021 1 commit
  2. 02 Feb, 2021 1 commit
    • Tiezhu Yang's avatar
      samples/bpf: Add include dir for MIPS Loongson64 to fix build errors · 058107ab
      Tiezhu Yang authored
      There exists many build errors when make M=samples/bpf on the Loongson
      platform. This issue is MIPS related, x86 compiles just fine.
      
      Here are some errors:
      
        CLANG-bpf  samples/bpf/sockex2_kern.o
      In file included from samples/bpf/sockex2_kern.c:2:
      In file included from ./include/uapi/linux/in.h:24:
      In file included from ./include/linux/socket.h:8:
      In file included from ./include/linux/uio.h:8:
      In file included from ./include/linux/kernel.h:11:
      In file included from ./include/linux/bitops.h:32:
      In file included from ./arch/mips/include/asm/bitops.h:19:
      In file included from ./arch/mips/include/asm/barrier.h:11:
      ./arch/mips/include/asm/addrspace.h:13:10: fatal error: 'spaces.h' file not found
               ^~~~~~~~~~
      1 error generated.
      
        CLANG-bpf  samples/bpf/sockex2_kern.o
      In file included from samples/bpf/sockex2_kern.c:2:
      In file included from ./include/uapi/linux/in.h:24:
      In file included from ./include/linux/socket.h:8:
      In file included from ./include/linux/uio.h:8:
      In file included from ./include/linux/kernel.h:11:
      In file included from ./include/linux/bitops.h:32:
      In file included from ./arch/mips/include/asm/bitops.h:22:
      In file included from ./arch/mips/include/asm/cpu-features.h:13:
      In file included from ./arch/mips/include/asm/cpu-info.h:15:
      In file included from ./include/linux/cache.h:6:
      ./arch/mips/include/asm/cache.h:12:10: fatal error: 'kmalloc.h' file not found
               ^~~~~~~~~~~
      1 error generated.
      
        CLANG-bpf  samples/bpf/sockex2_kern.o
      In file included from samples/bpf/sockex2_kern.c:2:
      In file included from ./include/uapi/linux/in.h:24:
      In file included from ./include/linux/socket.h:8:
      In file included from ./include/linux/uio.h:8:
      In file included from ./include/linux/kernel.h:11:
      In file included from ./include/linux/bitops.h:32:
      In file included from ./arch/mips/include/asm/bitops.h:22:
      ./arch/mips/include/asm/cpu-features.h:15:10: fatal error: 'cpu-feature-overrides.h' file not found
               ^~~~~~~~~~~~~~~~~~~~~~~~~
      1 error generated.
      
      $ find arch/mips/include/asm -name spaces.h | sort
      arch/mips/include/asm/mach-ar7/spaces.h
      ...
      arch/mips/include/asm/mach-generic/spaces.h
      ...
      arch/mips/include/asm/mach-loongson64/spaces.h
      ...
      arch/mips/include/asm/mach-tx49xx/spaces.h
      
      $ find arch/mips/include/asm -name kmalloc.h | sort
      arch/mips/include/asm/mach-generic/kmalloc.h
      arch/mips/include/asm/mach-ip32/kmalloc.h
      arch/mips/include/asm/mach-tx49xx/kmalloc.h
      
      $ find arch/mips/include/asm -name cpu-feature-overrides.h | sort
      arch/mips/include/asm/mach-ath25/cpu-feature-overrides.h
      ...
      arch/mips/include/asm/mach-generic/cpu-feature-overrides.h
      ...
      arch/mips/include/asm/mach-loongson64/cpu-feature-overrides.h
      ...
      arch/mips/include/asm/mach-tx49xx/cpu-feature-overrides.h
      
      In the arch/mips/Makefile, there exists the following board-dependent
      options:
      
      include arch/mips/Kbuild.platforms
      cflags-y += -I$(srctree)/arch/mips/include/asm/mach-generic
      
      So we can do the similar things in samples/bpf/Makefile, just add
      platform specific and generic include dir for MIPS Loongson64 to
      fix the build errors.
      Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/1611669925-25315-1-git-send-email-yangtiezhu@loongson.cn
      058107ab
  3. 29 Jan, 2021 6 commits
  4. 28 Jan, 2021 2 commits
  5. 27 Jan, 2021 2 commits
  6. 26 Jan, 2021 1 commit
  7. 25 Jan, 2021 17 commits
  8. 22 Jan, 2021 3 commits
  9. 21 Jan, 2021 4 commits
  10. 20 Jan, 2021 3 commits
    • Alexei Starovoitov's avatar
      Merge branch 'bpf: misc performance improvements for cgroup' · 636d549f
      Alexei Starovoitov authored
      Stanislav Fomichev says:
      
      ====================
      
      First patch adds custom getsockopt for TCP_ZEROCOPY_RECEIVE
      to remove kmalloc and lock_sock overhead from the dat path.
      
      Second patch removes kzalloc/kfree from getsockopt for the common cases.
      
      Third patch switches cgroup_bpf_enabled to be per-attach to
      to add only overhead for the cgroup attach types used on the system.
      
      No visible user-side changes.
      
      v9:
      - include linux/tcp.h instead of netinet/tcp.h in sockopt_sk.c
      - note that v9 depends on the commit 4be34f3d ("bpf: Don't leak
        memory in bpf getsockopt when optlen == 0") from bpf tree
      
      v8:
      - add bpi.h to tools/include/uapi in the same patch (Martin KaFai Lau)
      - kmalloc instead of kzalloc when exporting buffer (Martin KaFai Lau)
      - note that v8 depends on the commit 4be34f3d ("bpf: Don't leak
        memory in bpf getsockopt when optlen == 0") from bpf tree
      
      v7:
      - add comment about buffer contents for retval != 0 (Martin KaFai Lau)
      - export tcp.h into tools/include/uapi (Martin KaFai Lau)
      - note that v7 depends on the commit 4be34f3d ("bpf: Don't leak
        memory in bpf getsockopt when optlen == 0") from bpf tree
      
      v6:
      - avoid indirect cost for new bpf_bypass_getsockopt (Eric Dumazet)
      
      v5:
      - reorder patches to reduce the churn (Martin KaFai Lau)
      
      v4:
      - update performance numbers
      - bypass_bpf_getsockopt (Martin KaFai Lau)
      
      v3:
      - remove extra newline, add comment about sizeof tcp_zerocopy_receive
        (Martin KaFai Lau)
      - add another patch to remove lock_sock overhead from
        TCP_ZEROCOPY_RECEIVE; technically, this makes patch #1 obsolete,
        but I'd still prefer to keep it to help with other socket
        options
      
      v2:
      - perf numbers for getsockopt kmalloc reduction (Song Liu)
      - (sk) in BPF_CGROUP_PRE_CONNECT_ENABLED (Song Liu)
      - 128 -> 64 buffer size, BUILD_BUG_ON (Martin KaFai Lau)
      ====================
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      636d549f
    • Stanislav Fomichev's avatar
      bpf: Split cgroup_bpf_enabled per attach type · a9ed15da
      Stanislav Fomichev authored
      When we attach any cgroup hook, the rest (even if unused/unattached) start
      to contribute small overhead. In particular, the one we want to avoid is
      __cgroup_bpf_run_filter_skb which does two redirections to get to
      the cgroup and pushes/pulls skb.
      
      Let's split cgroup_bpf_enabled to be per-attach to make sure
      only used attach types trigger.
      
      I've dropped some existing high-level cgroup_bpf_enabled in some
      places because BPF_PROG_CGROUP_XXX_RUN macros usually have another
      cgroup_bpf_enabled check.
      
      I also had to copy-paste BPF_CGROUP_RUN_SA_PROG_LOCK for
      GETPEERNAME/GETSOCKNAME because type for cgroup_bpf_enabled[type]
      has to be constant and known at compile time.
      Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarSong Liu <songliubraving@fb.com>
      Link: https://lore.kernel.org/bpf/20210115163501.805133-4-sdf@google.com
      a9ed15da
    • Stanislav Fomichev's avatar
      bpf: Try to avoid kzalloc in cgroup/{s,g}etsockopt · 20f2505f
      Stanislav Fomichev authored
      When we attach a bpf program to cgroup/getsockopt any other getsockopt()
      syscall starts incurring kzalloc/kfree cost.
      
      Let add a small buffer on the stack and use it for small (majority)
      {s,g}etsockopt values. The buffer is small enough to fit into
      the cache line and cover the majority of simple options (most
      of them are 4 byte ints).
      
      It seems natural to do the same for setsockopt, but it's a bit more
      involved when the BPF program modifies the data (where we have to
      kmalloc). The assumption is that for the majority of setsockopt
      calls (which are doing pure BPF options or apply policy) this
      will bring some benefit as well.
      
      Without this patch (we remove about 1% __kmalloc):
           3.38%     0.07%  tcp_mmap  [kernel.kallsyms]  [k] __cgroup_bpf_run_filter_getsockopt
                  |
                   --3.30%--__cgroup_bpf_run_filter_getsockopt
                             |
                              --0.81%--__kmalloc
      Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Link: https://lore.kernel.org/bpf/20210115163501.805133-3-sdf@google.com
      20f2505f