diff mbox series

[RFC,bpf-next,5/9] bpf: Remove ARG_PTR_TO_CTX_OR_NULL

Message ID 20211109021624.1140446-6-haoluo@google.com (mailing list archive)
State RFC
Delegated to: BPF
Headers show
Series bpf: Clean up _OR_NULL arg types | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR fail merge-conflict

Commit Message

Hao Luo Nov. 9, 2021, 2:16 a.m. UTC
Remove ARG_PTR_TO_CTX_OR_NULL and use flag to mark that the argument
may be null.

Signed-off-by: Hao Luo <haoluo@google.com>
---
 include/linux/bpf.h   |  1 -
 kernel/bpf/cgroup.c   |  5 ++++-
 kernel/bpf/verifier.c |  2 --
 net/core/filter.c     | 20 ++++++++++++++++----
 4 files changed, 20 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 27f81989f992..27bf974ea6b5 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -324,7 +324,6 @@  struct bpf_arg_type {
 
 		ARG_CONST_SIZE,		/* number of bytes accessed from memory */
 		ARG_PTR_TO_CTX,		/* pointer to context */
-		ARG_PTR_TO_CTX_OR_NULL,	/* pointer to context or NULL */
 		ARG_ANYTHING,		/* any (initialized) argument is ok */
 		ARG_PTR_TO_SPIN_LOCK,	/* pointer to bpf_spin_lock */
 		ARG_PTR_TO_SOCK_COMMON,	/* pointer to sock_common */
diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index ce4de222605f..a0b431be46f8 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -1888,7 +1888,10 @@  static const struct bpf_func_proto bpf_get_netns_cookie_sockopt_proto = {
 	.func		= bpf_get_netns_cookie_sockopt,
 	.gpl_only	= false,
 	.ret_type	= RET_INTEGER,
-	.arg1		= { .type = ARG_PTR_TO_CTX_OR_NULL },
+	.arg1		= {
+		.type = ARG_PTR_TO_CTX,
+		.flag = ARG_FLAG_MAYBE_NULL,
+	},
 };
 #endif
 
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1a4830ad2be2..07b93bfd3518 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -481,7 +481,6 @@  static bool arg_type_may_be_refcounted(struct bpf_arg_type arg)
 static bool arg_type_may_be_null(struct bpf_arg_type arg)
 {
 	return arg.flag & ARG_FLAG_MAYBE_NULL ||
-	       arg.type == ARG_PTR_TO_CTX_OR_NULL ||
 	       arg.type == ARG_PTR_TO_SOCKET_OR_NULL ||
 	       arg.type == ARG_PTR_TO_ALLOC_MEM_OR_NULL ||
 	       arg.type == ARG_PTR_TO_STACK_OR_NULL;
@@ -5090,7 +5089,6 @@  static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = {
 	[ARG_CONST_ALLOC_SIZE_OR_ZERO]	= &scalar_types,
 	[ARG_CONST_MAP_PTR]		= &const_map_ptr_types,
 	[ARG_PTR_TO_CTX]		= &context_types,
-	[ARG_PTR_TO_CTX_OR_NULL]	= &context_types,
 	[ARG_PTR_TO_SOCK_COMMON]	= &sock_types,
 #ifdef CONFIG_NET
 	[ARG_PTR_TO_BTF_ID_SOCK_COMMON]	= &btf_id_sock_common_types,
diff --git a/net/core/filter.c b/net/core/filter.c
index 5e0f726a9bcd..2575460c054f 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4691,7 +4691,10 @@  static const struct bpf_func_proto bpf_get_netns_cookie_sock_proto = {
 	.func		= bpf_get_netns_cookie_sock,
 	.gpl_only	= false,
 	.ret_type	= RET_INTEGER,
-	.arg1		= { .type = ARG_PTR_TO_CTX_OR_NULL },
+	.arg1		= {
+		.type = ARG_PTR_TO_CTX,
+		.flag = ARG_FLAG_MAYBE_NULL,
+	},
 };
 
 BPF_CALL_1(bpf_get_netns_cookie_sock_addr, struct bpf_sock_addr_kern *, ctx)
@@ -4703,7 +4706,10 @@  static const struct bpf_func_proto bpf_get_netns_cookie_sock_addr_proto = {
 	.func		= bpf_get_netns_cookie_sock_addr,
 	.gpl_only	= false,
 	.ret_type	= RET_INTEGER,
-	.arg1		= { .type = ARG_PTR_TO_CTX_OR_NULL },
+	.arg1		= {
+		.type = ARG_PTR_TO_CTX,
+		.flag = ARG_FLAG_MAYBE_NULL,
+	},
 };
 
 BPF_CALL_1(bpf_get_netns_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx)
@@ -4715,7 +4721,10 @@  static const struct bpf_func_proto bpf_get_netns_cookie_sock_ops_proto = {
 	.func		= bpf_get_netns_cookie_sock_ops,
 	.gpl_only	= false,
 	.ret_type	= RET_INTEGER,
-	.arg1		= { .type = ARG_PTR_TO_CTX_OR_NULL },
+	.arg1		= {
+		.type = ARG_PTR_TO_CTX,
+		.flag = ARG_FLAG_MAYBE_NULL,
+	},
 };
 
 BPF_CALL_1(bpf_get_netns_cookie_sk_msg, struct sk_msg *, ctx)
@@ -4727,7 +4736,10 @@  static const struct bpf_func_proto bpf_get_netns_cookie_sk_msg_proto = {
 	.func		= bpf_get_netns_cookie_sk_msg,
 	.gpl_only	= false,
 	.ret_type	= RET_INTEGER,
-	.arg1		= { .type = ARG_PTR_TO_CTX_OR_NULL },
+	.arg1		= {
+		.type = ARG_PTR_TO_CTX,
+		.flag = ARG_FLAG_MAYBE_NULL,
+	},
 };
 
 BPF_CALL_1(bpf_get_socket_uid, struct sk_buff *, skb)