1. 23 Nov, 2022 5 commits
  2. 22 Nov, 2022 7 commits
  3. 21 Nov, 2022 12 commits
  4. 20 Nov, 2022 11 commits
    • Alexei Starovoitov's avatar
      Merge branch 'bpf: Implement two type cast kfuncs' · 99429b22
      Alexei Starovoitov authored
      Yonghong Song says:
      
      ====================
      
      Currenty, a non-tracing bpf program typically has a single 'context' argument
      with predefined uapi struct type. Following these uapi struct, user is able
      to access other fields defined in uapi header. Inside the kernel, the
      user-seen 'context' argument is replaced with 'kernel context' (or 'kctx'
      in short) which can access more information than what uapi header provides.
      To access other info not in uapi header, people typically do two things:
        (1). extend uapi to access more fields rooted from 'context'.
        (2). use bpf_probe_read_kernl() helper to read particular field based on
          kctx.
      Using (1) needs uapi change and using (2) makes code more complex since
      direct memory access is not allowed.
      
      There are already a few instances trying to access more information from
      kctx:
        . trying to access some fields from perf_event kctx ([1]).
        . trying to access some fields from xdp kctx ([2]).
      
      This patch set tried to allow direct memory access for kctx fields
      by introducing bpf_cast_to_kern_ctx() kfunc.
      
      Martin mentioned a use case like type casting below:
        #define skb_shinfo(SKB) ((struct skb_shared_info *)(skb_end_pointer(SKB)))
      basically a 'unsigned char *" casted to 'struct skb_shared_info *'. This patch
      set tries to support such a use case as well with bpf_rdonly_cast().
      
      For the patch series, Patch 1 added support for a kfunc available to all
      prog types. Patch 2 added bpf_cast_to_kern_ctx() kfunc. Patch 3 added
      bpf_rdonly_cast() kfunc. Patch 4 added a few positive and negative tests.
      
        [1] https://lore.kernel.org/bpf/ad15b398-9069-4a0e-48cb-4bb651ec3088@meta.com/
        [2] https://lore.kernel.org/bpf/20221109215242.1279993-1-john.fastabend@gmail.com/
      
      Changelog:
        v3 -> v4:
          - remove unnecessary bpf_ctx_convert.t error checking
          - add and use meta.ret_btf_id instead of meta.arg_constant.value for
            bpf_cast_to_kern_ctx().
          - add PTR_TRUSTED to the return PTR_TO_BTF_ID type for bpf_cast_to_kern_ctx().
        v2 -> v3:
          - rebase on top of bpf-next (for merging conflicts)
          - add the selftest to s390x deny list
        rfcv1 -> v2:
          - break original one kfunc into two.
          - add missing error checks and error logs.
          - adapt to the new conventions in
            https://lore.kernel.org/all/20221118015614.2013203-1-memxor@gmail.com/
            for example, with __ign and __k suffix.
          - added support in fixup_kfunc_call() to replace kfunc calls with a single mov.
      ====================
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      99429b22
    • Yonghong Song's avatar
      bpf: Add type cast unit tests · 58d84bee
      Yonghong Song authored
      Three tests are added. One is from John Fastabend ({1]) which tests
      tracing style access for xdp program from the kernel ctx.
      Another is a tc test to test both kernel ctx tracing style access
      and explicit non-ctx type cast. The third one is for negative tests
      including two tests, a tp_bpf test where the bpf_rdonly_cast()
      returns a untrusted ptr which cannot be used as helper argument,
      and a tracepoint test where the kernel ctx is a u64.
      
      Also added the test to DENYLIST.s390x since s390 does not currently
      support calling kernel functions in JIT mode.
      
        [1] https://lore.kernel.org/bpf/20221109215242.1279993-1-john.fastabend@gmail.com/Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20221120195442.3114844-1-yhs@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      58d84bee
    • Yonghong Song's avatar
      bpf: Add a kfunc for generic type cast · a35b9af4
      Yonghong Song authored
      Implement bpf_rdonly_cast() which tries to cast the object
      to a specified type. This tries to support use case like below:
        #define skb_shinfo(SKB) ((struct skb_shared_info *)(skb_end_pointer(SKB)))
      where skb_end_pointer(SKB) is a 'unsigned char *' and needs to
      be casted to 'struct skb_shared_info *'.
      
      The signature of bpf_rdonly_cast() looks like
         void *bpf_rdonly_cast(void *obj, __u32 btf_id)
      The function returns the same 'obj' but with PTR_TO_BTF_ID with
      btf_id. The verifier will ensure btf_id being a struct type.
      
      Since the supported type cast may not reflect what the 'obj'
      represents, the returned btf_id is marked as PTR_UNTRUSTED, so
      the return value and subsequent pointer chasing cannot be
      used as helper/kfunc arguments.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20221120195437.3114585-1-yhs@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      a35b9af4
    • Yonghong Song's avatar
      bpf: Add a kfunc to type cast from bpf uapi ctx to kernel ctx · fd264ca0
      Yonghong Song authored
      Implement bpf_cast_to_kern_ctx() kfunc which does a type cast
      of a uapi ctx object to the corresponding kernel ctx. Previously
      if users want to access some data available in kctx but not
      in uapi ctx, bpf_probe_read_kernel() helper is needed.
      The introduction of bpf_cast_to_kern_ctx() allows direct
      memory access which makes code simpler and easier to understand.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20221120195432.3113982-1-yhs@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      fd264ca0
    • Yonghong Song's avatar
      bpf: Add support for kfunc set with common btf_ids · cfe14564
      Yonghong Song authored
      Later on, we will introduce kfuncs bpf_cast_to_kern_ctx() and
      bpf_rdonly_cast() which apply to all program types. Currently kfunc set
      only supports individual prog types. This patch added support for kfunc
      applying to all program types.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/r/20221120195426.3113828-1-yhs@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      cfe14564
    • Kumar Kartikeya Dwivedi's avatar
      bpf: Disallow bpf_obj_new_impl call when bpf_mem_alloc_init fails · e181d3f1
      Kumar Kartikeya Dwivedi authored
      In the unlikely event that bpf_global_ma is not correctly initialized,
      instead of checking the boolean everytime bpf_obj_new_impl is called,
      simply check it while loading the program and return an error if
      bpf_global_ma_set is false.
      Suggested-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
      Link: https://lore.kernel.org/r/20221120212610.2361700-1-memxor@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      e181d3f1
    • Alexei Starovoitov's avatar
      Merge branch 'Support storing struct task_struct objects as kptrs' · efc1970d
      Alexei Starovoitov authored
      David Vernet says:
      
      ====================
      
      Now that BPF supports adding new kernel functions with kfuncs, and
      storing kernel objects in maps with kptrs, we can add a set of kfuncs
      which allow struct task_struct objects to be stored in maps as
      referenced kptrs.
      
      The possible use cases for doing this are plentiful.  During tracing,
      for example, it would be useful to be able to collect some tasks that
      performed a certain operation, and then periodically summarize who they
      are, which cgroup they're in, how much CPU time they've utilized, etc.
      Doing this now would require storing the tasks' pids along with some
      relevant data to be exported to user space, and later associating the
      pids to tasks in other event handlers where the data is recorded.
      Another useful by-product of this is that it allows a program to pin a
      task in a BPF program, and by proxy therefore also e.g. pin its task
      local storage.
      
      In order to support this, we'll need to expand KF_TRUSTED_ARGS to
      support receiving trusted, non-refcounted pointers. It currently only
      supports either PTR_TO_CTX pointers, or refcounted pointers. What this
      means in terms of the implementation is that check_kfunc_args() would
      have to also check for the PTR_TRUSTED or MEM_ALLOC type modifiers when
      determining if a trusted KF_ARG_PTR_TO_ALLOC_BTF_ID or
      KF_ARG_PTR_TO_BTF_ID pointer requires a refcount.
      
      Note that PTR_UNTRUSTED is insufficient for this purpose, as it does not
      cover all of the possible types of potentially unsafe pointers. For
      example, a pointer obtained from walking a struct is not PTR_UNTRUSTED.
      To account for this and enable us to expand KF_TRUSTED_ARGS to include
      allow-listed arguments such as those passed by the kernel to tracepoints
      and struct_ops callbacks, this patch set also introduces a new
      PTR_TRUSTED type flag modifier which records if a pointer was obtained
      passed from the kernel in a trusted context.
      
      Currently, both PTR_TRUSTED and MEM_ALLOC are used to imply that a
      pointer is trusted. Longer term, PTR_TRUSTED should be the sole source
      of truth for whether a pointer is trusted. This requires us to set
      PTR_TRUSTED when appropriate (e.g. when setting MEM_ALLOC), and unset it
      when appropriate (e.g. when setting PTR_UNTRUSTED). We don't do that in
      this patch, as we need to do more clean up before this can be done in a
      clear and well-defined manner.
      
      In closing, this patch set:
      
      1. Adds the new PTR_TRUSTED register type modifier flag, and updates the
         verifier and existing selftests accordingly. Also expands
         KF_TRUSTED_ARGS to also include trusted pointers that were not obtained
         from walking structs.
      2. Adds a new set of kfuncs that allows struct task_struct* objects to be
         used as kptrs.
      3. Adds a new selftest suite to validate these new task kfuncs.
      ---
      Changelog:
      v8 -> v9:
      - Moved check for release register back to where we check for
        !PTR_TO_BTF_ID || socket. Change the verifier log message to
        reflect really what's being tested (the presence of unsafe
        modifiers) (Alexei)
      - Fix verifier_test error tests to reflect above changes
      - Remove unneeded parens around bitwise operator checks (Alexei)
      - Move updates to reg_type_str() which allow multiple type modifiers
        to be present in the prefix string, to a separate patch (Alexei)
      - Increase TYPE_STR_BUF_LEN size to 128 to reflect larger prefix size
        in reg_type_str().
      
      v7 -> v8:
      - Rebased onto Kumar's latest patch set which, adds a new MEM_ALLOC reg
        type modifier for bpf_obj_new() calls.
      - Added comments to bpf_task_kptr_get() describing some of the subtle
        races we're protecting against (Alexei and John)
      - Slightly rework process_kf_arg_ptr_to_btf_id(), and add a new
        reg_has_unsafe_modifiers() function which validates that a register
        containing a kfunc release arg doesn't have unsafe modifiers. Note
        that this is slightly different than the check for KF_TRUSTED_ARGS.
        An alternative here would be to treat KF_RELEASE as implicitly
        requiring KF_TRUSTED_ARGS.
      - Export inline bpf_type_has_unsafe_modifiers() function from
        bpf_verifier.h so that it can be used from bpf_tcp_ca.c. Eventually this
        function should likely be changed to bpf_type_is_trusted(), once
        PTR_TRUSTED is the real source of truth.
      
      v6 -> v7:
      - Removed the PTR_WALKED type modifier, and instead define a new
        PTR_TRUSTED type modifier which is set on registers containing
        pointers passed from trusted contexts (i.e. as tracepoint or
        struct_ops callback args) (Alexei)
      - Remove the new KF_OWNED_ARGS kfunc flag. This can be accomplished
        by defining a new type that wraps an existing type, such as with
        struct nf_conn___init (Alexei)
      - Add a test_task_current_acquire_release testcase which verifies we can
        acquire a task struct returned from bpf_get_current_task_btf().
      - Make bpf_task_acquire() no longer return NULL, as it can no longer be
        called with a NULL task.
      - Removed unnecessary is_test_kfunc_task() checks from failure
        testcases.
      
      v5 -> v6:
      - Add a new KF_OWNED_ARGS kfunc flag which may be used by kfuncs to
        express that they require trusted, refcounted args (Kumar)
      - Rename PTR_NESTED -> PTR_WALKED in the verifier (Kumar)
      - Convert reg_type_str() prefixes to use snprintf() instead of strncpy()
        (Kumar)
      - Add PTR_TO_BTF_ID | PTR_WALKED to missing struct btf_reg_type
        instances -- specifically btf_id_sock_common_types, and
        percpu_btf_ptr_types.
      - Add a missing PTR_TO_BTF_ID | PTR_WALKED switch case entry in
        check_func_arg_reg_off(), which is required when validating helper
        calls (Kumar)
      - Update reg_type_mismatch_ok() to check base types for the registers
        (i.e. to accommodate type modifiers). Additionally, add a lengthy
        comment that explains why this is being done (Kumar)
      - Update convert_ctx_accesses() to also issue probe reads for
        PTR_TO_BTF_ID | PTR_WALKED (Kumar)
      - Update selftests to expect new prefix reg type strings.
      - Rename task_kfunc_acquire_trusted_nested testcase to
        task_kfunc_acquire_trusted_walked, and fix a comment (Kumar)
      - Remove KF_TRUSTED_ARGS from bpf_task_release(), which already includes
        KF_RELEASE (Kumar)
      - Add bpf-next in patch subject lines (Kumar)
      
      v4 -> v5:
      - Fix an improperly formatted patch title.
      
      v3 -> v4:
      - Remove an unnecessary check from my repository that I forgot to remove
        after debugging something.
      
      v2 -> v3:
      - Make bpf_task_acquire() check for NULL, and include KF_RET_NULL
        (Martin)
      - Include new PTR_NESTED register modifier type flag which specifies
        whether a pointer was obtained from walking a struct. Use this to
        expand the meaning of KF_TRUSTED_ARGS to include trusted pointers that
        were passed from the kernel (Kumar)
      - Add more selftests to the task_kfunc selftest suite which verify that
        you cannot pass a walked pointer to bpf_task_acquire().
      - Update bpf_task_acquire() to also specify KF_TRUSTED_ARGS.
      
      v1 -> v2:
      - Rename tracing_btf_ids to generic_kfunc_btf_ids, and add the new
        kfuncs to that list instead of making a separate btf id list (Alexei).
      - Don't run the new selftest suite on s390x, which doesn't appear to
        support invoking kfuncs.
      - Add a missing __diag_ignore block for -Wmissing-prototypes
        (lkp@intel.com).
      - Fix formatting on some of the SPDX-License-Identifier tags.
      - Clarified the function header comment a bit on bpf_task_kptr_get().
      ====================
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      efc1970d
    • David Vernet's avatar
      bpf/selftests: Add selftests for new task kfuncs · fe147956
      David Vernet authored
      A previous change added a series of kfuncs for storing struct
      task_struct objects as referenced kptrs. This patch adds a new
      task_kfunc test suite for validating their expected behavior.
      Signed-off-by: default avatarDavid Vernet <void@manifault.com>
      Link: https://lore.kernel.org/r/20221120051004.3605026-5-void@manifault.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      fe147956
    • David Vernet's avatar
      bpf: Add kfuncs for storing struct task_struct * as a kptr · 90660309
      David Vernet authored
      Now that BPF supports adding new kernel functions with kfuncs, and
      storing kernel objects in maps with kptrs, we can add a set of kfuncs
      which allow struct task_struct objects to be stored in maps as
      referenced kptrs. The possible use cases for doing this are plentiful.
      During tracing, for example, it would be useful to be able to collect
      some tasks that performed a certain operation, and then periodically
      summarize who they are, which cgroup they're in, how much CPU time
      they've utilized, etc.
      
      In order to enable this, this patch adds three new kfuncs:
      
      struct task_struct *bpf_task_acquire(struct task_struct *p);
      struct task_struct *bpf_task_kptr_get(struct task_struct **pp);
      void bpf_task_release(struct task_struct *p);
      
      A follow-on patch will add selftests validating these kfuncs.
      Signed-off-by: default avatarDavid Vernet <void@manifault.com>
      Link: https://lore.kernel.org/r/20221120051004.3605026-4-void@manifault.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      90660309
    • David Vernet's avatar
      bpf: Allow trusted pointers to be passed to KF_TRUSTED_ARGS kfuncs · 3f00c523
      David Vernet authored
      Kfuncs currently support specifying the KF_TRUSTED_ARGS flag to signal
      to the verifier that it should enforce that a BPF program passes it a
      "safe", trusted pointer. Currently, "safe" means that the pointer is
      either PTR_TO_CTX, or is refcounted. There may be cases, however, where
      the kernel passes a BPF program a safe / trusted pointer to an object
      that the BPF program wishes to use as a kptr, but because the object
      does not yet have a ref_obj_id from the perspective of the verifier, the
      program would be unable to pass it to a KF_ACQUIRE | KF_TRUSTED_ARGS
      kfunc.
      
      The solution is to expand the set of pointers that are considered
      trusted according to KF_TRUSTED_ARGS, so that programs can invoke kfuncs
      with these pointers without getting rejected by the verifier.
      
      There is already a PTR_UNTRUSTED flag that is set in some scenarios,
      such as when a BPF program reads a kptr directly from a map
      without performing a bpf_kptr_xchg() call. These pointers of course can
      and should be rejected by the verifier. Unfortunately, however,
      PTR_UNTRUSTED does not cover all the cases for safety that need to
      be addressed to adequately protect kfuncs. Specifically, pointers
      obtained by a BPF program "walking" a struct are _not_ considered
      PTR_UNTRUSTED according to BPF. For example, say that we were to add a
      kfunc called bpf_task_acquire(), with KF_ACQUIRE | KF_TRUSTED_ARGS, to
      acquire a struct task_struct *. If we only used PTR_UNTRUSTED to signal
      that a task was unsafe to pass to a kfunc, the verifier would mistakenly
      allow the following unsafe BPF program to be loaded:
      
      SEC("tp_btf/task_newtask")
      int BPF_PROG(unsafe_acquire_task,
                   struct task_struct *task,
                   u64 clone_flags)
      {
              struct task_struct *acquired, *nested;
      
              nested = task->last_wakee;
      
              /* Would not be rejected by the verifier. */
              acquired = bpf_task_acquire(nested);
              if (!acquired)
                      return 0;
      
              bpf_task_release(acquired);
              return 0;
      }
      
      To address this, this patch defines a new type flag called PTR_TRUSTED
      which tracks whether a PTR_TO_BTF_ID pointer is safe to pass to a
      KF_TRUSTED_ARGS kfunc or a BPF helper function. PTR_TRUSTED pointers are
      passed directly from the kernel as a tracepoint or struct_ops callback
      argument. Any nested pointer that is obtained from walking a PTR_TRUSTED
      pointer is no longer PTR_TRUSTED. From the example above, the struct
      task_struct *task argument is PTR_TRUSTED, but the 'nested' pointer
      obtained from 'task->last_wakee' is not PTR_TRUSTED.
      
      A subsequent patch will add kfuncs for storing a task kfunc as a kptr,
      and then another patch will add selftests to validate.
      Signed-off-by: default avatarDavid Vernet <void@manifault.com>
      Link: https://lore.kernel.org/r/20221120051004.3605026-3-void@manifault.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      3f00c523
    • David Vernet's avatar
      bpf: Allow multiple modifiers in reg_type_str() prefix · ef66c547
      David Vernet authored
      reg_type_str() in the verifier currently only allows a single register
      type modifier to be present in the 'prefix' string which is eventually
      stored in the env type_str_buf. This currently works fine because there
      are no overlapping type modifiers, but once PTR_TRUSTED is added, that
      will no longer be the case. This patch updates reg_type_str() to support
      having multiple modifiers in the prefix string, and updates the size of
      type_str_buf to be 128 bytes.
      Signed-off-by: default avatarDavid Vernet <void@manifault.com>
      Link: https://lore.kernel.org/r/20221120051004.3605026-2-void@manifault.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      ef66c547
  5. 18 Nov, 2022 5 commits
    • Tiezhu Yang's avatar
      bpf, samples: Use "grep -E" instead of "egrep" · ee748cd9
      Tiezhu Yang authored
      The latest version of grep (3.8+) claims the egrep is now obsolete so the
      build now contains warnings that look like:
      
        egrep: warning: egrep is obsolescent; using grep -E
      
      Fix this up by moving the related file to use "grep -E" instead.
      Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
      Link: https://lore.kernel.org/bpf/1668765001-12477-1-git-send-email-yangtiezhu@loongson.cn
      ee748cd9
    • Maryam Tahhan's avatar
      bpf, docs: DEVMAPs and XDP_REDIRECT · d1e91173
      Maryam Tahhan authored
      Add documentation for BPF_MAP_TYPE_DEVMAP and BPF_MAP_TYPE_DEVMAP_HASH
      including kernel version introduced, usage and examples.
      
      Add documentation that describes XDP_REDIRECT.
      Signed-off-by: default avatarMaryam Tahhan <mtahhan@redhat.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Reviewed-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
      Acked-by: default avatarYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/bpf/20221115144921.165483-1-mtahhan@redhat.com
      d1e91173
    • Andrii Nakryiko's avatar
      libbpf: Ignore hashmap__find() result explicitly in btf_dump · f80e16b6
      Andrii Nakryiko authored
      Coverity is reporting that btf_dump_name_dups() doesn't check return
      result of hashmap__find() call. This is intentional, so make it explicit
      with (void) cast.
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20221117192824.4093553-1-andrii@kernel.org
      f80e16b6
    • Kumar Kartikeya Dwivedi's avatar
      selftests/bpf: Skip spin lock failure test on s390x · 97c11d6e
      Kumar Kartikeya Dwivedi authored
      Instead of adding the whole test to DENYLIST.s390x, which also has
      success test cases that should be run, just skip over failure test
      cases in case the JIT does not support kfuncs.
      Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
      Link: https://lore.kernel.org/r/20221118185938.2139616-3-memxor@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      97c11d6e
    • Alexei Starovoitov's avatar
      Merge branch 'Allocated objects, BPF linked lists' · db6bf999
      Alexei Starovoitov authored
      Kumar Kartikeya Dwivedi says:
      
      ====================
      
      This series introduces user defined BPF objects of a type in program
      BTF. This allows BPF programs to allocate their own objects, build their
      own object hierarchies, and use the basic building blocks provided by
      BPF runtime to build their own data structures flexibly.
      
      Then, we introduce the support for single ownership BPF linked lists,
      which can be put inside BPF maps, or allocated objects, and hold such
      allocated objects as elements. It works as an instrusive collection,
      which is done to allow making allocated objects part of multiple data
      structures at the same time in the future.
      
      The eventual goal of this and future patches is to allow one to do some
      limited form of kernel style programming in BPF C, and allow programmers
      to build their own complex data structures flexibly out of basic
      building blocks.
      
      The key difference will be that such programs are verified to be safe,
      preserve runtime integrity of the system, and are proven to be bug free
      as far as the invariants of BPF specific APIs are concerned.
      
      One immediate use case that will be using the entire infrastructure this
      series is introducing will be managing percpu NMI safe linked lists
      inside BPF programs.
      
      The other use case this will serve in the near future will be linking
      kernel structures like XDP frame and sk_buff directly into user data
      structures (rbtree, pifomap, etc.) for packet queueing. This will follow
      single ownership concept included in this series.
      
      The user has complete control of the internal locking, and hence also
      the batching of operations for each critical section.
      
      The features are:
      - Allocated objects.
      - bpf_obj_new, bpf_obj_drop to allocate and free them.
      - Single ownership BPF linked lists.
        - Support for them in BPF maps.
        - Support for them in allocated objects.
      - Global spin locks.
      - Spin locks inside allocated objects.
      
      Some other notable things:
      - Completely static verification of locking.
      - Kfunc argument handling has been completely reworked.
      - Argument rewriting support for kfuncs.
      - A new bpf_experimental.h header as a dumping ground for these APIs.
      
      Any functionality exposed in this series is NOT part of UAPI. It is only
      available through use of kfuncs, and structs that can be added to map
      value may also change their size or name in the future. Hence, every
      feature in this series must be considered experimental.
      
      Follow-ups:
      -----------
       * Support for kptrs (local and kernel) in local storage and percpu maps + kptr tests
       * Fixes for helper access checks rebasing on top of this series
      
      Next steps:
      -----------
       * NMI safe percpu single ownership linked lists (using local_t protection).
       * Lockless linked lists.
       * Allow RCU protected BPF allocated objects. This then allows RCU
         protected list lookups, since spinlock protection for readers does
         not scale.
       * Introduce bpf_refcount for local kptrs, shared ownership.
       * Introduce shared ownership linked lists.
       * Documentation.
      
      Changelog:
      ----------
       v9 -> v10
       v9: https://lore.kernel.org/bpf/20221117225510.1676785-1-memxor@gmail.com
      
        * Deduplicate code to find btf_record of reg (Alexei)
        * Add linked_list test to DENYLIST.aarch64 (Alexei)
        * Disable some linked list tests for now so that they compile with
          clang nightly (Alexei)
      
       v8 -> v9
       v8: https://lore.kernel.org/bpf/20221117162430.1213770-1-memxor@gmail.com
      
        * Fix up commit log of patch 2, Simplify patch 3
        * Explain the implicit requirement of bpf_list_head requiring map BTF
          to match in btf_record_equal in a separate patch.
      
       v7 -> v8
       v7: https://lore.kernel.org/bpf/20221114191547.1694267-1-memxor@gmail.com
      
        * Fix early return in map_check_btf (Dan Carpenter)
        * Fix two memory leak bugs in local storage maps, outer maps
        * Address comments from Alexei and Dave
         * More local kptr -> allocated object renaming
         * Use krealloc with NULL instead kmalloc + krealloc
         * Drop WARN_ON_ONCE for field_offs parsing
         * Combine kfunc add + remove patches into one
         * Drop STRONG suffix from KF_ARG_PTR_TO_KPTR
         * Rename is_kfunc_arg_ret_buf_size to is_kfunc_arg_scalar_with_name
         * Remove redundant check for reg->type and arg type in it
         * Drop void * ret type check
         * Remove code duplication in checks for NULL pointer with offset != 0
         * Fix two bpf_list_node typos
         * Improve log message for bpf_list_head operations
         * Improve comments for active_lock struct
         * Improve comments for Implementation details of process_spin_lock
        * Add Dave's acks
      
       v6 -> v7
       v6: https://lore.kernel.org/bpf/20221111193224.876706-1-memxor@gmail.com
      
        * Fix uninitialized variable warning (Dan Carpenter, Kernel Test Robot)
        * One more local_kptr renaming
      
       v5 -> v6
       v5: https://lore.kernel.org/bpf/20221107230950.7117-1-memxor@gmail.com
      
        * Replace (i && !off) check with next_off, include test (Andrii)
        * Drop local kptrs naming (Andrii, Alexei)
        * Drop reg->precise == EXACT patch (Andrii)
        * Add comment about ptr member of struct active_lock (Andrii)
        * Use btf__new_empty + btf__add_xxx APIs (Andrii)
        * Address other misc nits from Andrii
      
       v4 -> v5
       v4: https://lore.kernel.org/bpf/20221103191013.1236066-1-memxor@gmail.com
      
        * Add a lot more selftests (failure, success, runtime, BTF)
        * Make sure series is bisect friendly
        * Move list draining out of spin lock
          * This exposed an issue where bpf_mem_free can now be called in
            map_free path without migrate_disable, also fixed that.
        * Rename MEM_ALLOC -> MEM_RINGBUF, MEM_TYPE_LOCAL -> MEM_ALLOC (Alexei)
        * Group lock identity into a struct active_lock { ptr, id } (Dave)
        * Split set_release_on_unlock logic into separate patch (Alexei)
      
       v3 -> v4
       v3: https://lore.kernel.org/bpf/20221102202658.963008-1-memxor@gmail.com
      
        * Fix compiler error for !CONFIG_BPF_SYSCALL (Kernel Test Robot)
        * Fix error due to BUILD_BUG_ON on 32-bit platforms (Kernel Test Robot)
      
       v2 -> v3
       v2: https://lore.kernel.org/bpf/20221013062303.896469-1-memxor@gmail.com
      
        * Add ack from Dave for patch 5
        * Rename btf_type_fields -> btf_record, btf_type_fields_off ->
          btf_field_offs, rename functions similarly (Alexei)
        * Remove 'kind' component from contains declaration tag (Alexei)
        * Move bpf_list_head, bpf_list_node definitions to UAPI bpf.h (Alexei)
        * Add note in commit log about modifying btf_struct_access API (Dave)
        * Downgrade WARN_ON_ONCE to verbose(env, "...") and return -EFAULT (Dave)
        * Add type_is_local_kptr wrapper to avoid noisy checks (Dave)
        * Remove unused flags parameter from bpf_kptr_new (Alexei)
        * Rename bpf_kptr_new -> bpf_obj_new, bpf_kptr_drop -> bpf_obj_drop (Alexei)
        * Reword comment in ref_obj_id_set_release_on_unlock (Dave)
        * Fix return type of ref_obj_id_set_release_on_unlock (Dave)
        * Introduce is_bpf_list_api_kfunc to dedup checks (Dave)
        * Disallow BPF_WRITE to untrusted local kptrs
        * Add details about soundness of check_reg_allocation_locked logic
        * List untrusted local kptrs for PROBE_MEM handling
      
       v1 -> v2
       v1: https://lore.kernel.org/bpf/20221011012240.3149-1-memxor@gmail.com
      
        * Rebase on bpf-next to resolve merge conflict in DENYLIST.s390x
        * Fix a couple of mental lapses in bpf_list_head_free
      
       RFC v1 -> v1
       RFC v1: https://lore.kernel.org/bpf/20220904204145.3089-1-memxor@gmail.com
      
        * Mostly a complete rewrite of BTF parsing, refactor existing code (Kartikeya)
        * Rebase kfunc rewrite for bpf-next, add support for more changes
        * Cache type metadata in BTF to avoid recomputation inside verifier (Kartikeya)
        * Remove __kernel tag, make things similar to map values, reserve bpf_ prefix
        * bpf_kptr_new, bpf_kptr_drop
        * Rename precision state enum values (Alexei)
        * Drop explicit constructor/destructor support (Alexei)
        * Rewrite code for constructing/destructing objects and offload to runtime
        * Minimize duplication in bpf_map_value_off_desc handling (Alexei)
        * Expose global memory allocator (Alexei)
        * Address other nits from Alexei
        * Split out local kptrs in maps, more kptrs in maps support into a follow up
      
      Links:
      ------
       * Dave's BPF RB-Tree RFC series
         v1 (Discussion thread)
           https://lore.kernel.org/bpf/20220722183438.3319790-1-davemarchevsky@fb.com
         v2 (With support for static locks)
           https://lore.kernel.org/bpf/20220830172759.4069786-1-davemarchevsky@fb.com
       * BPF Linked Lists Discussion
         https://lore.kernel.org/bpf/CAP01T74U30+yeBHEgmgzTJ-XYxZ0zj71kqCDJtTH9YQNfTK+Xw@mail.gmail.com
       * BPF Memory Allocator from Alexei
         https://lore.kernel.org/bpf/20220902211058.60789-1-alexei.starovoitov@gmail.com
       * BPF Memory Allocator UAPI Discussion
         https://lore.kernel.org/bpf/d3f76b27f4e55ec9e400ae8dcaecbb702a4932e8.camel@fb.com
      ====================
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      db6bf999