bpf: Convert PTR_TO_MEM_OR_NULL to composable types.
authorHao Luo <haoluo@google.com>
Fri, 17 Dec 2021 00:31:49 +0000 (16:31 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 18 Dec 2021 21:27:41 +0000 (13:27 -0800)
Remove PTR_TO_MEM_OR_NULL and replace it with PTR_TO_MEM combined with
flag PTR_MAYBE_NULL.

Signed-off-by: Hao Luo <haoluo@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211217003152.48334-7-haoluo@google.com
include/linux/bpf.h
kernel/bpf/btf.c
kernel/bpf/verifier.c

index 1260481..567d83b 100644 (file)
@@ -506,7 +506,6 @@ enum bpf_reg_type {
        PTR_TO_SOCK_COMMON_OR_NULL      = PTR_MAYBE_NULL | PTR_TO_SOCK_COMMON,
        PTR_TO_TCP_SOCK_OR_NULL         = PTR_MAYBE_NULL | PTR_TO_TCP_SOCK,
        PTR_TO_BTF_ID_OR_NULL           = PTR_MAYBE_NULL | PTR_TO_BTF_ID,
-       PTR_TO_MEM_OR_NULL              = PTR_MAYBE_NULL | PTR_TO_MEM,
 
        /* This must be the last entry. Its purpose is to ensure the enum is
         * wide enough to hold the higher bits reserved for bpf_type_flag.
index d1447b0..d948b5b 100644 (file)
@@ -5859,7 +5859,7 @@ int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog,
                                return -EINVAL;
                        }
 
-                       reg->type = PTR_TO_MEM_OR_NULL;
+                       reg->type = PTR_TO_MEM | PTR_MAYBE_NULL;
                        reg->id = ++env->id_gen;
 
                        continue;
index e0a8a55..9073337 100644 (file)
@@ -13578,7 +13578,7 @@ static int do_check_common(struct bpf_verifier_env *env, int subprog)
                                mark_reg_known_zero(env, regs, i);
                        else if (regs[i].type == SCALAR_VALUE)
                                mark_reg_unknown(env, regs, i);
-                       else if (regs[i].type == PTR_TO_MEM_OR_NULL) {
+                       else if (base_type(regs[i].type) == PTR_TO_MEM) {
                                const u32 mem_size = regs[i].mem_size;
 
                                mark_reg_known_zero(env, regs, i);