Martin KaFai Lau
1df8f55a37
bpf: Enable bpf_skc_to_* sock casting helper to networking prog type
...
There is a constant need to add more fields into the bpf_tcp_sock
for the bpf programs running at tc, sock_ops...etc.
A current workaround could be to use bpf_probe_read_kernel(). However,
other than making another helper call for reading each field and missing
CO-RE, it is also not as intuitive to use as directly reading
"tp->lsndtime" for example. While already having perfmon cap to do
bpf_probe_read_kernel(), it will be much easier if the bpf prog can
directly read from the tcp_sock.
This patch tries to do that by using the existing casting-helpers
bpf_skc_to_*() whose func_proto returns a btf_id. For example, the
func_proto of bpf_skc_to_tcp_sock returns the btf_id of the
kernel "struct tcp_sock".
These helpers are also added to is_ptr_cast_function().
It ensures the returning reg (BPF_REF_0) will also carries the ref_obj_id.
That will keep the ref-tracking works properly.
The bpf_skc_to_* helpers are made available to most of the bpf prog
types in filter.c. The bpf_skc_to_* helpers will be limited by
perfmon cap.
This patch adds a ARG_PTR_TO_BTF_ID_SOCK_COMMON. The helper accepting
this arg can accept a btf-id-ptr (PTR_TO_BTF_ID + &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON])
or a legacy-ctx-convert-skc-ptr (PTR_TO_SOCK_COMMON). The bpf_skc_to_*()
helpers are changed to take ARG_PTR_TO_BTF_ID_SOCK_COMMON such that
they will accept pointer obtained from skb->sk.
Instead of specifying both arg_type and arg_btf_id in the same func_proto
which is how the current ARG_PTR_TO_BTF_ID does, the arg_btf_id of
the new ARG_PTR_TO_BTF_ID_SOCK_COMMON is specified in the
compatible_reg_types[] in verifier.c. The reason is the arg_btf_id is
always the same. Discussion in this thread:
https://lore.kernel.org/bpf/20200922070422.1917351-1-kafai@fb.com/
The ARG_PTR_TO_BTF_ID_ part gives a clear expectation that the helper is
expecting a PTR_TO_BTF_ID which could be NULL. This is the same
behavior as the existing helper taking ARG_PTR_TO_BTF_ID.
The _SOCK_COMMON part means the helper is also expecting the legacy
SOCK_COMMON pointer.
By excluding the _OR_NULL part, the bpf prog cannot call helper
with a literal NULL which doesn't make sense in most cases.
e.g. bpf_skc_to_tcp_sock(NULL) will be rejected. All PTR_TO_*_OR_NULL
reg has to do a NULL check first before passing into the helper or else
the bpf prog will be rejected. This behavior is nothing new and
consistent with the current expectation during bpf-prog-load.
[ ARG_PTR_TO_BTF_ID_SOCK_COMMON will be used to replace
ARG_PTR_TO_SOCK* of other existing helpers later such that
those existing helpers can take the PTR_TO_BTF_ID returned by
the bpf_skc_to_*() helpers.
The only special case is bpf_sk_lookup_assign() which can accept a
literal NULL ptr. It has to be handled specially in another follow
up patch if there is a need (e.g. by renaming ARG_PTR_TO_SOCKET_OR_NULL
to ARG_PTR_TO_BTF_ID_SOCK_COMMON_OR_NULL). ]
[ When converting the older helpers that take ARG_PTR_TO_SOCK* in
the later patch, if the kernel does not support BTF,
ARG_PTR_TO_BTF_ID_SOCK_COMMON will behave like ARG_PTR_TO_SOCK_COMMON
because no reg->type could have PTR_TO_BTF_ID in this case.
It is not a concern for the newer-btf-only helper like the bpf_skc_to_*()
here though because these helpers must require BTF vmlinux to begin
with. ]
Signed-off-by: Martin KaFai Lau <kafai@fb.com >
Signed-off-by: Alexei Starovoitov <ast@kernel.org >
Acked-by: John Fastabend <john.fastabend@gmail.com >
Link: https://lore.kernel.org/bpf/20200925000350.3855720-1-kafai@fb.com
2020-09-25 13:58:01 -07:00
..
2020-06-30 00:32:59 +02:00
2020-09-21 10:13:19 +02:00
2020-08-24 10:33:08 +02:00
2020-07-24 02:19:08 -07:00
2020-08-03 11:05:26 +02:00
2020-07-31 11:49:08 +02:00
2020-08-12 10:57:59 -07:00
2020-09-20 19:01:34 -07:00
2020-08-05 11:43:47 -07:00
2020-09-18 17:49:20 -07:00
2020-08-04 01:22:02 +02:00
2020-07-13 15:07:34 +01:00
2020-07-08 22:31:51 -07:00
2020-08-12 10:57:59 -07:00
2020-08-07 12:58:11 -07:00
2020-08-27 06:55:50 -07:00
2020-08-15 08:09:38 -07:00
2020-09-15 11:59:53 -07:00
2020-08-05 20:13:21 -07:00
2020-08-07 08:54:16 +02:00
2020-06-25 22:25:13 -07:00
2020-09-09 11:21:19 -07:00
2020-06-25 00:50:31 +02:00
2020-06-25 00:50:31 +02:00
2020-08-27 06:55:50 -07:00
2020-08-15 08:18:22 -07:00
2020-07-29 22:33:10 +02:00
2020-09-22 16:45:34 -07:00
2020-07-16 15:35:21 +02:00
2020-07-17 00:16:50 +01:00
2020-07-28 17:11:02 -07:00
2020-06-16 14:19:57 +02:00
2020-08-17 09:39:18 -07:00
2020-08-16 22:00:22 +01:00
2020-07-21 16:05:40 +05:30
2020-07-27 14:55:22 +01:00
2020-08-15 08:26:55 -07:00
2020-08-05 20:13:21 -07:00
2020-07-15 20:34:02 -07:00
2020-07-28 15:51:31 +01:00
2020-08-04 18:11:58 -07:00
2020-07-22 10:22:05 +02:00
2020-08-03 19:30:59 -07:00
2020-08-12 10:57:59 -07:00
2020-07-19 18:16:40 -07:00
2020-06-11 08:03:24 +02:00
2020-06-25 08:23:22 -07:00
2020-06-11 08:03:24 +02:00
2020-07-21 11:12:31 -04:00
2020-07-08 17:20:46 -06:00
2020-07-08 17:20:46 -06:00
2020-07-20 10:27:11 +01:00
2020-07-21 08:24:52 -05:00
2020-06-29 09:09:08 -06:00
2020-08-10 12:16:51 -07:00
2020-07-08 10:48:35 -07:00
2020-07-17 07:15:10 -06:00
2020-07-08 17:05:53 -06:00
2020-07-28 10:22:19 -06:00
2020-08-05 11:12:34 -07:00
2020-08-25 15:00:04 -07:00
2020-08-25 15:00:04 -07:00
2020-08-25 15:00:04 -07:00
2020-09-17 19:56:07 -07:00
2020-08-24 14:35:00 -07:00
2020-07-17 20:18:16 -07:00
2020-09-25 13:58:01 -07:00
2020-07-24 15:41:54 -07:00
2020-09-21 17:16:17 -07:00
2020-06-11 15:14:53 +02:00
2020-09-21 15:00:40 -07:00
2020-08-25 15:37:41 -07:00
2020-08-12 10:57:59 -07:00
2020-06-24 09:16:02 -06:00
2020-09-02 20:59:40 -06:00
2020-06-09 09:39:16 -07:00
2020-07-19 20:14:42 +02:00
2020-06-15 23:08:31 -05:00
2020-07-08 16:20:01 -06:00
2020-07-09 16:28:44 -07:00
2020-07-07 13:34:11 -07:00
2020-08-03 15:07:18 -07:00
2020-08-12 10:57:56 -07:00
2020-08-23 17:36:59 -05:00
2020-08-27 09:53:06 +02:00
2020-08-29 09:29:32 +02:00
2020-08-12 10:57:59 -07:00
2020-08-04 13:49:43 -07:00
2020-08-03 14:25:40 -07:00
2020-06-24 17:08:33 +02:00
2020-06-24 17:08:31 +02:00
2020-06-11 15:14:36 +02:00
2020-07-24 13:56:23 +02:00
2020-07-21 15:48:40 +02:00
2020-06-17 17:28:08 +02:00
2020-08-27 12:51:25 +02:00
2020-09-17 18:12:18 +01:00
2020-09-16 19:36:26 +02:00
2020-08-12 10:58:01 -07:00
2020-06-09 09:39:13 -07:00
2020-07-16 21:49:09 +10:00
2020-06-24 09:16:02 -06:00
2020-09-21 06:53:09 -07:00
2020-07-29 16:14:27 +02:00
2020-06-11 15:15:28 +02:00
2020-07-10 13:54:00 -07:00
2020-08-12 10:57:59 -07:00
2020-07-30 19:26:10 +02:00
2020-07-30 17:22:57 +09:00
2020-08-03 11:57:03 -07:00
2020-09-10 19:19:42 +02:00
2020-07-10 15:39:29 +05:30
2020-08-14 15:22:43 -07:00
2020-08-14 16:27:00 +02:00
2020-07-21 09:42:19 +02:00
2020-08-14 16:27:00 +02:00
2020-06-09 09:39:13 -07:00
2020-07-29 16:14:25 +02:00
2020-08-07 12:41:36 -07:00
2020-07-24 14:33:39 +02:00
2020-09-04 17:21:56 +02:00
2020-08-06 16:13:13 +02:00
2020-06-16 19:25:20 +02:00
2020-09-10 18:19:16 +02:00
2020-08-07 11:33:28 -07:00
2020-07-27 14:29:22 -04:00
2020-07-27 14:29:23 -04:00
2020-06-24 17:16:42 +02:00
2020-09-04 15:50:14 +02:00
2020-07-24 15:03:42 +02:00
2020-09-15 13:26:28 -07:00
2020-08-12 10:57:59 -07:00
2020-07-27 23:24:00 +02:00
2020-08-04 07:37:23 +02:00
2020-06-17 00:07:38 +02:00
2020-07-13 11:03:45 -07:00
2020-09-23 13:11:11 -07:00
2020-07-17 13:12:44 -04:00
2020-08-12 10:57:57 -07:00
2020-07-14 14:45:41 +02:00
2020-09-16 19:12:27 -04:00
2020-07-29 16:14:27 +02:00
2020-08-28 10:57:14 -07:00
2020-06-15 23:08:31 -05:00
2020-07-21 16:02:13 -07:00
2020-07-27 23:25:50 +02:00
2020-07-27 23:24:00 +02:00
2020-07-21 16:02:41 -07:00
2020-09-19 13:13:39 -07:00
2020-08-12 10:57:59 -07:00
2020-07-17 20:18:00 -06:00
2020-07-10 12:00:01 +02:00
2020-07-20 17:00:02 -07:00
2020-06-24 15:45:51 +10:00
2020-09-01 12:06:41 +02:00
2020-08-12 10:57:57 -07:00
2020-07-10 16:24:28 -03:00
2020-07-17 16:06:14 +02:00
2020-08-06 16:13:13 +02:00
2020-08-14 19:56:56 -07:00
2020-08-12 10:58:02 -07:00
2020-08-06 17:54:04 +02:00
2020-06-20 09:16:19 +00:00
2020-09-09 10:22:40 +02:00
2020-08-13 18:41:00 -07:00
2020-07-24 17:12:41 -07:00
2020-06-19 13:41:59 -07:00
2020-09-18 12:27:27 +02:00
2020-09-23 13:24:34 -07:00
2020-08-19 14:02:49 -07:00
2020-07-07 15:48:38 -07:00
2020-07-20 13:28:16 -04:00
2020-06-23 15:11:19 -07:00
2020-09-03 15:17:28 -07:00
2020-08-04 21:02:38 -04:00
2020-07-30 08:22:33 +02:00
2020-07-24 13:56:23 +02:00
2020-07-27 14:17:36 +02:00
2020-07-24 14:33:39 +02:00
2020-06-16 16:43:23 +03:00
2020-06-10 14:04:39 -07:00
2020-07-30 11:16:01 -07:00
2020-08-14 19:56:57 -07:00
2020-08-14 19:56:57 -07:00
2020-07-24 12:42:42 -07:00
2020-07-24 14:29:47 +02:00
2020-07-29 14:42:00 +02:00
2020-08-31 13:08:10 -07:00
2020-06-28 17:01:20 +02:00
2020-07-27 16:20:40 +02:00
2020-07-27 08:55:04 +01:00
2020-07-04 10:02:06 +02:00
2020-08-26 12:41:56 +02:00
2020-07-04 10:02:06 +02:00
2020-08-21 11:03:38 -07:00
2020-08-23 17:36:59 -05:00
2020-06-19 14:17:05 -06:00
2020-07-08 15:59:57 -07:00
2020-08-07 11:33:28 -07:00
2020-06-26 10:01:08 -06:00
2020-08-28 11:21:20 -07:00
2020-07-29 23:47:53 +10:00
2020-07-09 20:12:19 -07:00
2020-07-23 10:33:12 +02:00
2020-09-18 14:27:24 -04:00
2020-09-04 09:25:20 -07:00
2020-06-11 13:25:53 -07:00
2020-08-06 16:13:13 +02:00
2020-08-21 14:04:14 +01:00
2020-07-29 16:14:29 +02:00
2020-07-09 13:29:42 -04:00
2020-07-22 14:41:29 +02:00
2020-08-12 10:57:59 -07:00
2020-07-22 14:42:07 +02:00
2020-09-02 11:31:23 -06:00
2020-07-28 19:29:22 -06:00
2020-07-01 07:27:24 -06:00
2020-07-20 17:59:43 -07:00
2020-08-02 20:39:44 -07:00
2020-07-28 10:45:46 +02:00
2020-08-26 12:41:53 +02:00
2020-09-05 12:14:30 -07:00
2020-08-11 14:30:36 -07:00
2020-08-11 14:30:36 -07:00
2020-06-22 16:28:34 -07:00
2020-08-07 21:27:37 -07:00
2020-08-31 12:52:33 -07:00
2020-07-10 15:08:09 +02:00
2020-08-14 19:56:57 -07:00
2020-06-10 13:42:09 -07:00
2020-08-12 10:57:56 -07:00
2020-09-04 09:59:59 +02:00
2020-07-23 09:35:36 +02:00
2020-09-11 17:41:55 -07:00
2020-08-12 10:58:02 -07:00
2020-08-14 19:56:56 -07:00
2020-08-14 19:56:56 -07:00
2020-09-17 10:26:41 -07:00
2020-08-07 11:33:26 -07:00
2020-06-09 09:39:14 -07:00
2020-08-26 12:41:53 +02:00
2020-08-07 11:33:21 -07:00
2020-08-12 10:57:56 -07:00
2020-07-23 09:12:15 +02:00
2020-08-05 10:31:28 +02:00
2020-07-20 10:39:54 +02:00
2020-06-09 15:40:50 -07:00
2020-07-31 18:08:59 +10:00
2020-07-24 15:41:54 -07:00
2020-07-24 15:41:54 -07:00
2020-08-06 16:13:13 +02:00
2020-08-24 16:16:06 -07:00
2020-09-10 13:30:22 -07:00
2020-09-22 16:45:34 -07:00
2020-08-13 04:16:15 +02:00
2020-07-24 15:41:54 -07:00
2020-07-15 07:45:25 -07:00
2020-08-15 08:26:55 -07:00
2020-07-13 17:52:45 -04:00
2020-07-13 17:52:46 -04:00
2020-07-13 17:52:45 -04:00
2020-07-21 10:50:36 +01:00
2020-07-29 07:45:20 +02:00
2020-07-29 07:45:21 +02:00
2020-07-29 17:12:08 +02:00
2020-07-29 17:12:08 +02:00
2020-07-28 22:49:52 +02:00
2020-07-28 15:51:32 +01:00
2020-07-01 10:49:02 +02:00
2020-07-28 15:51:32 +01:00
2020-07-28 15:51:32 +01:00
2020-06-30 15:57:34 -07:00
2020-09-05 13:09:03 -07:00
2020-08-12 10:57:56 -07:00
2020-06-16 20:45:08 -07:00
2020-07-23 17:34:18 +10:00
2020-07-16 12:32:25 -07:00
2020-08-07 11:33:29 -07:00
2020-08-14 19:56:56 -07:00
2020-08-12 12:09:36 -07:00
2020-07-24 09:50:41 -05:00
2020-08-07 18:48:15 -07:00
2020-08-31 12:52:33 -07:00
2020-08-07 11:33:26 -07:00
2020-07-21 10:50:37 +01:00
2020-09-16 16:26:56 +02:00
2020-08-05 20:13:21 -07:00
2020-08-17 21:50:54 +03:00
2020-08-03 15:01:02 -07:00
2020-08-31 12:52:33 -07:00
2020-06-13 09:56:21 -07:00
2020-07-28 17:07:06 -07:00
2020-07-14 15:14:27 +02:00
2020-08-04 12:44:53 +02:00
2020-08-04 12:39:28 +02:00
2020-07-27 13:52:36 +02:00
2020-08-12 10:57:59 -07:00
2020-08-06 16:50:59 +02:00
2020-07-31 14:33:56 +02:00
2020-09-10 19:27:59 +02:00
2020-08-03 23:24:26 -07:00
2020-09-14 09:45:34 -07:00
2020-07-27 17:46:24 +09:00
2020-07-25 20:16:32 -07:00
2020-07-19 14:16:09 +02:00
2020-06-15 14:10:03 +02:00
2020-06-15 17:38:53 +10:00
2020-08-19 16:09:19 -07:00
2020-07-21 10:50:37 +01:00
2020-06-17 20:42:11 +02:00
2020-07-24 22:09:54 -04:00
2020-07-13 22:43:43 -07:00
2020-08-03 23:24:26 -07:00
2020-07-27 17:46:24 +09:00
2020-07-27 17:46:24 +09:00
2020-06-29 11:58:11 -07:00
2020-08-03 14:39:35 -07:00
2020-09-23 19:32:09 -07:00
2020-06-29 11:59:26 -07:00
2020-06-29 11:59:26 -07:00
2020-06-29 11:59:25 -07:00
2020-07-17 00:03:11 +01:00
2020-07-27 14:31:13 -04:00
2020-08-04 20:16:37 -07:00
2020-07-28 17:09:49 -07:00
2020-06-30 17:18:56 -04:00
2020-06-09 09:39:14 -07:00
2020-07-21 14:07:51 -07:00
2020-07-16 13:35:25 +02:00
2020-07-22 13:39:31 +02:00
2020-07-16 23:19:51 +02:00
2020-07-06 16:07:25 +02:00
2020-07-20 11:50:47 +01:00
2020-08-26 12:41:51 +02:00
2020-07-13 09:40:21 +01:00
2020-06-15 23:08:32 -05:00
2020-08-04 21:00:11 -07:00
2020-06-14 11:39:31 -07:00
2020-08-06 16:13:13 +02:00
2020-07-29 17:14:38 +02:00
2020-09-16 13:22:44 +02:00
2020-06-11 15:19:17 +02:00
2020-08-07 11:33:24 -07:00
2020-08-23 17:36:59 -05:00
2020-09-09 11:04:39 -07:00
2020-08-21 15:16:11 -07:00
2020-08-07 11:33:25 -07:00
2020-08-07 11:33:25 -07:00
2020-08-07 11:33:25 -07:00
2020-06-28 17:01:20 +02:00
2020-06-28 17:01:20 +02:00
2020-06-30 09:34:23 -04:00
2020-08-10 12:06:44 -07:00
2020-06-17 18:33:13 +02:00
2020-06-17 18:33:13 +02:00
2020-09-19 13:13:39 -07:00
2020-06-10 19:14:18 -07:00
2020-07-15 12:45:06 +03:00
2020-07-28 19:28:32 -06:00
2020-08-12 10:57:56 -07:00
2020-08-14 19:56:56 -07:00
2020-08-14 19:56:56 -07:00
2020-07-25 19:34:48 -06:00
2020-06-30 12:18:08 -06:00
2020-07-27 14:11:22 +02:00
2020-09-10 13:15:40 -07:00
2020-07-07 15:55:21 +02:00
2020-06-22 19:58:06 +03:00
2020-06-15 23:08:32 -05:00
2020-07-08 11:14:22 +02:00
2020-08-06 16:13:13 +02:00
2020-06-18 11:37:03 +02:00
2020-06-29 12:01:44 -07:00
2020-07-24 08:16:01 +03:00
2020-07-24 09:26:23 +03:00
2020-08-07 17:05:01 -04:00
2020-08-03 13:34:37 -04:00
2020-07-29 16:14:18 +02:00
2020-08-12 10:57:59 -07:00
2020-06-30 09:34:23 -04:00
2020-07-04 09:35:36 -05:00
2020-07-15 16:48:11 +02:00
2020-07-07 11:58:59 -05:00
2020-07-20 15:04:32 +02:00
2020-07-10 13:45:32 +02:00
2020-08-05 19:00:23 -04:00
2020-08-01 11:28:17 +02:00
2020-08-06 16:13:13 +02:00
2020-08-05 11:08:41 -04:00
2020-08-05 19:56:03 -04:00
2020-08-05 09:30:19 -04:00
2020-09-04 09:31:54 -07:00
2020-06-26 00:27:38 -07:00
2020-08-07 11:33:24 -07:00
2020-07-10 14:55:25 +02:00
2020-06-24 17:08:31 +02:00
2020-09-17 10:26:41 -07:00
2020-08-05 18:43:02 +02:00
2020-08-12 10:57:59 -07:00
2020-08-06 16:13:13 +02:00
2020-08-09 13:58:04 -07:00
2020-08-12 10:57:59 -07:00
2020-08-12 10:57:59 -07:00
2020-08-12 10:57:59 -07:00