Skip to content
  1. Dec 19, 2021
    • Hao Luo's avatar
      bpf: Replace PTR_TO_XXX_OR_NULL with PTR_TO_XXX | PTR_MAYBE_NULL · c25b2ae1
      Hao Luo authored
      
      
      We have introduced a new type to make bpf_reg composable, by
      allocating bits in the type to represent flags.
      
      One of the flags is PTR_MAYBE_NULL which indicates a pointer
      may be NULL. This patch switches the qualified reg_types to
      use this flag. The reg_types changed in this patch include:
      
      1. PTR_TO_MAP_VALUE_OR_NULL
      2. PTR_TO_SOCKET_OR_NULL
      3. PTR_TO_SOCK_COMMON_OR_NULL
      4. PTR_TO_TCP_SOCK_OR_NULL
      5. PTR_TO_BTF_ID_OR_NULL
      6. PTR_TO_MEM_OR_NULL
      7. PTR_TO_RDONLY_BUF_OR_NULL
      8. PTR_TO_RDWR_BUF_OR_NULL
      
      Signed-off-by: default avatarHao Luo <haoluo@google.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/r/20211217003152.48334-5-haoluo@google.com
      c25b2ae1
    • Hao Luo's avatar
      bpf: Replace RET_XXX_OR_NULL with RET_XXX | PTR_MAYBE_NULL · 3c480732
      Hao Luo authored
      
      
      We have introduced a new type to make bpf_ret composable, by
      reserving high bits to represent flags.
      
      One of the flag is PTR_MAYBE_NULL, which indicates a pointer
      may be NULL. When applying this flag to ret_types, it means
      the returned value could be a NULL pointer. This patch
      switches the qualified arg_types to use this flag.
      The ret_types changed in this patch include:
      
      1. RET_PTR_TO_MAP_VALUE_OR_NULL
      2. RET_PTR_TO_SOCKET_OR_NULL
      3. RET_PTR_TO_TCP_SOCK_OR_NULL
      4. RET_PTR_TO_SOCK_COMMON_OR_NULL
      5. RET_PTR_TO_ALLOC_MEM_OR_NULL
      6. RET_PTR_TO_MEM_OR_BTF_ID_OR_NULL
      7. RET_PTR_TO_BTF_ID_OR_NULL
      
      This patch doesn't eliminate the use of these names, instead
      it makes them aliases to 'RET_PTR_TO_XXX | PTR_MAYBE_NULL'.
      
      Signed-off-by: default avatarHao Luo <haoluo@google.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20211217003152.48334-4-haoluo@google.com
      3c480732
    • Hao Luo's avatar
      bpf: Replace ARG_XXX_OR_NULL with ARG_XXX | PTR_MAYBE_NULL · 48946bd6
      Hao Luo authored
      
      
      We have introduced a new type to make bpf_arg composable, by
      reserving high bits of bpf_arg to represent flags of a type.
      
      One of the flags is PTR_MAYBE_NULL which indicates a pointer
      may be NULL. When applying this flag to an arg_type, it means
      the arg can take NULL pointer. This patch switches the
      qualified arg_types to use this flag. The arg_types changed
      in this patch include:
      
      1. ARG_PTR_TO_MAP_VALUE_OR_NULL
      2. ARG_PTR_TO_MEM_OR_NULL
      3. ARG_PTR_TO_CTX_OR_NULL
      4. ARG_PTR_TO_SOCKET_OR_NULL
      5. ARG_PTR_TO_ALLOC_MEM_OR_NULL
      6. ARG_PTR_TO_STACK_OR_NULL
      
      This patch does not eliminate the use of these arg_types, instead
      it makes them an alias to the 'ARG_XXX | PTR_MAYBE_NULL'.
      
      Signed-off-by: default avatarHao Luo <haoluo@google.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20211217003152.48334-3-haoluo@google.com
      48946bd6
    • Hao Luo's avatar
      bpf: Introduce composable reg, ret and arg types. · d639b9d1
      Hao Luo authored
      
      
      There are some common properties shared between bpf reg, ret and arg
      values. For instance, a value may be a NULL pointer, or a pointer to
      a read-only memory. Previously, to express these properties, enumeration
      was used. For example, in order to test whether a reg value can be NULL,
      reg_type_may_be_null() simply enumerates all types that are possibly
      NULL. The problem of this approach is that it's not scalable and causes
      a lot of duplication. These properties can be combined, for example, a
      type could be either MAYBE_NULL or RDONLY, or both.
      
      This patch series rewrites the layout of reg_type, arg_type and
      ret_type, so that common properties can be extracted and represented as
      composable flag. For example, one can write
      
       ARG_PTR_TO_MEM | PTR_MAYBE_NULL
      
      which is equivalent to the previous
      
       ARG_PTR_TO_MEM_OR_NULL
      
      The type ARG_PTR_TO_MEM are called "base type" in this patch. Base
      types can be extended with flags. A flag occupies the higher bits while
      base types sits in the lower bits.
      
      This patch in particular sets up a set of macro for this purpose. The
      following patches will rewrite arg_types, ret_types and reg_types
      respectively.
      
      Signed-off-by: default avatarHao Luo <haoluo@google.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20211217003152.48334-2-haoluo@google.com
      d639b9d1
  2. Dec 18, 2021
  3. Dec 17, 2021
  4. Dec 15, 2021
  5. Dec 14, 2021