1. 08 9月, 2022 8 次提交
  2. 07 9月, 2022 11 次提交
    • A
      Merge branch 'bpf: Support struct argument for trampoline base progs' · 028a9642
      Alexei Starovoitov 提交于
      Yonghong Song says:
      
      ====================
      Currently struct arguments are not supported for trampoline based progs.
      One of major reason is that struct argument may pass by value which may
      use more than one registers. This breaks trampoline progs where
      each argument is assumed to take one register. bcc community reported the
      issue ([1]) where struct argument is not supported for fentry program.
        typedef struct {
              uid_t val;
        } kuid_t;
        typedef struct {
              gid_t val;
        } kgid_t;
        int security_path_chown(struct path *path, kuid_t uid, kgid_t gid);
      Inside Meta, we also have a use case to attach to tcp_setsockopt()
        typedef struct {
              union {
                      void            *kernel;
                      void __user     *user;
              };
              bool            is_kernel : 1;
        } sockptr_t;
        int tcp_setsockopt(struct sock *sk, int level, int optname,
                           sockptr_t optval, unsigned int optlen);
      
      This patch added struct value support for bpf tracing programs which
      uses trampoline. Only <= 16 byte struct size is supported for now
      which covers use cases in the above. For x86/arm64/bpf, <= 16
      struct value will be passed in registers instead of by reference.
      Only x86_64 is supported in this patch. arm64 support can be
      added later.
      
       [1] https://github.com/iovisor/bcc/issues/3657
      
      Changelog:
        v3 -> v4:
         - fix a test failure where no casting for
           bpf_get_func_arg() value as the value type is 'int'.
         - add tracing_struct test in DENYLIST.s390x
         - simplify macro BPF_REG_CNT for BPF_PROG2.
        v2 -> v3:
         - previously struct arguments (<= 16 bytes) are passed
           by reference for bpf programs. Suggested by Alexei,
           it is passed by value now.
         - in order to support passing <= 16 struct value, a
           new macro BPF_PROG2 is invented.
        rfc v1 -> v2:
         - changed bpf_func_model struct info fields to
           arg_flags[] to make it easy to iterate arguments
           in arch specific {save|restore}_regs() functions.
         - added fexit tests to test return values with
           struct arguments.
      ====================
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      028a9642
    • Y
      selftests/bpf: Add tracing_struct test in DENYLIST.s390x · ae63c10f
      Yonghong Song 提交于
      Add tracing_struct test in DENYLIST.s390x since s390x does not
      support trampoline now.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20220831152723.2081551-1-yhs@fb.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      ae63c10f
    • Y
      selftests/bpf: Use BPF_PROG2 for some fentry programs without struct arguments · a7c2ca3a
      Yonghong Song 提交于
      Use BPF_PROG2 instead of BPF_PROG for programs in progs/timer.c
      to test BPF_PROG2 for cases without struct arguments.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20220831152718.2081091-1-yhs@fb.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      a7c2ca3a
    • Y
      selftests/bpf: Add struct argument tests with fentry/fexit programs. · 1642a394
      Yonghong Song 提交于
      Add various struct argument tests with fentry/fexit programs.
      Also add one test with a kernel func which does not have any
      argument to test BPF_PROG2 macro in such situation.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20220831152713.2080039-1-yhs@fb.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      1642a394
    • Y
      libbpf: Add new BPF_PROG2 macro · 34586d29
      Yonghong Song 提交于
      To support struct arguments in trampoline based programs,
      existing BPF_PROG doesn't work any more since
      the type size is needed to find whether a parameter
      takes one or two registers. So this patch added a new
      BPF_PROG2 macro to support such trampoline programs.
      
      The idea is suggested by Andrii. For example, if the
      to-be-traced function has signature like
        typedef struct {
             void *x;
             int t;
        } sockptr;
        int blah(sockptr x, char y);
      
      In the new BPF_PROG2 macro, the argument can be
      represented as
        __bpf_prog_call(
           ({ union {
                struct { __u64 x, y; } ___z;
                sockptr x;
              } ___tmp = { .___z = { ctx[0], ctx[1] }};
              ___tmp.x;
           }),
           ({ union {
                struct { __u8 x; } ___z;
                char y;
              } ___tmp = { .___z = { ctx[2] }};
              ___tmp.y;
           }));
      In the above, the values stored on the stack are properly
      assigned to the actual argument type value by using 'union'
      magic. Note that the macro also works even if no arguments
      are with struct types.
      
      Note that new BPF_PROG2 works for both llvm16 and pre-llvm16
      compilers where llvm16 supports bpf target passing value
      with struct up to 16 byte size and pre-llvm16 will pass
      by reference by storing values on the stack. With static functions
      with struct argument as always inline, the compiler is able
      to optimize and remove additional stack saving of struct values.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20220831152707.2079473-1-yhs@fb.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      34586d29
    • Y
      bpf: arm64: No support of struct argument in trampoline programs · eb707dde
      Yonghong Song 提交于
      ARM64 does not support struct argument for trampoline based
      bpf programs yet.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20220831152702.2079066-1-yhs@fb.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      eb707dde
    • Y
      bpf: Update descriptions for helpers bpf_get_func_arg[_cnt]() · 27ed9353
      Yonghong Song 提交于
      Now instead of the number of arguments, the number of registers
      holding argument values are stored in trampoline. Update
      the description of bpf_get_func_arg[_cnt]() helpers. Previous
      programs without struct arguments should continue to work
      as usual.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20220831152657.2078805-1-yhs@fb.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      27ed9353
    • Y
      bpf: x86: Support in-register struct arguments in trampoline programs · a9c5ad31
      Yonghong Song 提交于
      In C, struct value can be passed as a function argument.
      For small structs, struct value may be passed in
      one or more registers. For trampoline based bpf programs,
      this would cause complication since one-to-one mapping between
      function argument and arch argument register is not valid
      any more.
      
      The latest llvm16 added bpf support to pass by values
      for struct up to 16 bytes ([1]). This is also true for
      x86_64 architecture where two registers will hold
      the struct value if the struct size is >8 and <= 16.
      This may not be true if one of struct member is 'double'
      type but in current linux source code we don't have
      such instance yet, so we assume all >8 && <= 16 struct
      holds two general purpose argument registers.
      
      Also change on-stack nr_args value to the number
      of registers holding the arguments. This will
      permit bpf_get_func_arg() helper to get all
      argument values.
      
       [1] https://reviews.llvm.org/D132144Signed-off-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20220831152652.2078600-1-yhs@fb.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      a9c5ad31
    • Y
      bpf: Allow struct argument in trampoline based programs · 720e6a43
      Yonghong Song 提交于
      Allow struct argument in trampoline based programs where
      the struct size should be <= 16 bytes. In such cases, the argument
      will be put into up to 2 registers for bpf, x86_64 and arm64
      architectures.
      
      To support arch-specific trampoline manipulation,
      add arg_flags for additional struct information about arguments
      in btf_func_model. Such information will be used in arch specific
      function arch_prepare_bpf_trampoline() to prepare argument access
      properly in trampoline.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20220831152646.2078089-1-yhs@fb.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      720e6a43
    • A
      bpf: Replace __ksize with ksize. · 1e660f7e
      Alexei Starovoitov 提交于
      __ksize() was made private. Use ksize() instead.
      Reported-by: NStephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      1e660f7e
    • P
      Merge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next · 2786bcff
      Paolo Abeni 提交于
      Daniel Borkmann says:
      
      ====================
      pull-request: bpf-next 2022-09-05
      
      The following pull-request contains BPF updates for your *net-next* tree.
      
      We've added 106 non-merge commits during the last 18 day(s) which contain
      a total of 159 files changed, 5225 insertions(+), 1358 deletions(-).
      
      There are two small merge conflicts, resolve them as follows:
      
      1) tools/testing/selftests/bpf/DENYLIST.s390x
      
        Commit 27e23836 ("selftests/bpf: Add lru_bug to s390x deny list") in
        bpf tree was needed to get BPF CI green on s390x, but it conflicted with
        newly added tests on bpf-next. Resolve by adding both hunks, result:
      
        [...]
        lru_bug                                  # prog 'printk': failed to auto-attach: -524
        setget_sockopt                           # attach unexpected error: -524                                               (trampoline)
        cb_refs                                  # expected error message unexpected error: -524                               (trampoline)
        cgroup_hierarchical_stats                # JIT does not support calling kernel function                                (kfunc)
        htab_update                              # failed to attach: ERROR: strerror_r(-524)=22                                (trampoline)
        [...]
      
      2) net/core/filter.c
      
        Commit 1227c177 ("net: Fix data-races around sysctl_[rw]mem_(max|default).")
        from net tree conflicts with commit 29003875 ("bpf: Change bpf_setsockopt(SOL_SOCKET)
        to reuse sk_setsockopt()") from bpf-next tree. Take the code as it is from
        bpf-next tree, result:
      
        [...]
      	if (getopt) {
      		if (optname == SO_BINDTODEVICE)
      			return -EINVAL;
      		return sk_getsockopt(sk, SOL_SOCKET, optname,
      				     KERNEL_SOCKPTR(optval),
      				     KERNEL_SOCKPTR(optlen));
      	}
      
      	return sk_setsockopt(sk, SOL_SOCKET, optname,
      			     KERNEL_SOCKPTR(optval), *optlen);
        [...]
      
      The main changes are:
      
      1) Add any-context BPF specific memory allocator which is useful in particular for BPF
         tracing with bonus of performance equal to full prealloc, from Alexei Starovoitov.
      
      2) Big batch to remove duplicated code from bpf_{get,set}sockopt() helpers as an effort
         to reuse the existing core socket code as much as possible, from Martin KaFai Lau.
      
      3) Extend BPF flow dissector for BPF programs to just augment the in-kernel dissector
         with custom logic. In other words, allow for partial replacement, from Shmulik Ladkani.
      
      4) Add a new cgroup iterator to BPF with different traversal options, from Hao Luo.
      
      5) Support for BPF to collect hierarchical cgroup statistics efficiently through BPF
         integration with the rstat framework, from Yosry Ahmed.
      
      6) Support bpf_{g,s}et_retval() under more BPF cgroup hooks, from Stanislav Fomichev.
      
      7) BPF hash table and local storages fixes under fully preemptible kernel, from Hou Tao.
      
      8) Add various improvements to BPF selftests and libbpf for compilation with gcc BPF
         backend, from James Hilliard.
      
      9) Fix verifier helper permissions and reference state management for synchronous
         callbacks, from Kumar Kartikeya Dwivedi.
      
      10) Add support for BPF selftest's xskxceiver to also be used against real devices that
          support MAC loopback, from Maciej Fijalkowski.
      
      11) Various fixes to the bpf-helpers(7) man page generation script, from Quentin Monnet.
      
      12) Document BPF verifier's tnum_in(tnum_range(), ...) gotchas, from Shung-Hsi Yu.
      
      13) Various minor misc improvements all over the place.
      
      * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (106 commits)
        bpf: Optimize rcu_barrier usage between hash map and bpf_mem_alloc.
        bpf: Remove usage of kmem_cache from bpf_mem_cache.
        bpf: Remove prealloc-only restriction for sleepable bpf programs.
        bpf: Prepare bpf_mem_alloc to be used by sleepable bpf programs.
        bpf: Remove tracing program restriction on map types
        bpf: Convert percpu hash map to per-cpu bpf_mem_alloc.
        bpf: Add percpu allocation support to bpf_mem_alloc.
        bpf: Batch call_rcu callbacks instead of SLAB_TYPESAFE_BY_RCU.
        bpf: Adjust low/high watermarks in bpf_mem_cache
        bpf: Optimize call_rcu in non-preallocated hash map.
        bpf: Optimize element count in non-preallocated hash map.
        bpf: Relax the requirement to use preallocated hash maps in tracing progs.
        samples/bpf: Reduce syscall overhead in map_perf_test.
        selftests/bpf: Improve test coverage of test_maps
        bpf: Convert hash map to bpf_mem_alloc.
        bpf: Introduce any context BPF specific memory allocator.
        selftest/bpf: Add test for bpf_getsockopt()
        bpf: Change bpf_getsockopt(SOL_IPV6) to reuse do_ipv6_getsockopt()
        bpf: Change bpf_getsockopt(SOL_IP) to reuse do_ip_getsockopt()
        bpf: Change bpf_getsockopt(SOL_TCP) to reuse do_tcp_getsockopt()
        ...
      ====================
      
      Link: https://lore.kernel.org/r/20220905161136.9150-1-daniel@iogearbox.netSigned-off-by: NPaolo Abeni <pabeni@redhat.com>
      2786bcff
  3. 06 9月, 2022 3 次提交
  4. 05 9月, 2022 18 次提交