Martin KaFai Lau 78958fca7e bpf: btf: Introduce BTF ID
This patch gives an ID to each loaded BTF.  The ID is allocated by
the idr like the existing prog-id and map-id.

The bpf_put(map->btf) is moved to __bpf_map_put() so that the
userspace can stop seeing the BTF ID ASAP when the last BTF
refcnt is gone.

It also makes BTF accessible from userspace through the
1. new BPF_BTF_GET_FD_BY_ID command.  It is limited to CAP_SYS_ADMIN
   which is inline with the BPF_BTF_LOAD cmd and the existing
   BPF_[MAP|PROG]_GET_FD_BY_ID cmd.
2. new btf_id (and btf_key_id + btf_value_id) in "struct bpf_map_info"

Once the BTF ID handler is accessible from userspace, freeing a BTF
object has to go through a rcu period.  The BPF_BTF_GET_FD_BY_ID cmd
can then be done under a rcu_read_lock() instead of taking
spin_lock.
[Note: A similar rcu usage can be done to the existing
       bpf_prog_get_fd_by_id() in a follow up patch]

When processing the BPF_BTF_GET_FD_BY_ID cmd,
refcount_inc_not_zero() is needed because the BTF object
could be already in the rcu dead row .  btf_get() is
removed since its usage is currently limited to btf.c
alone.  refcount_inc() is used directly instead.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Alexei Starovoitov <ast@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-05-09 17:25:13 +02:00
..
2018-02-14 09:43:22 -08:00
2018-02-01 09:51:57 -08:00
2018-01-01 22:54:42 -08:00
2018-04-13 16:20:36 -07:00
2018-02-20 11:34:54 +00:00
2018-03-08 13:56:24 +05:30
2018-04-07 12:08:19 -07:00
2018-04-12 12:55:50 -07:00
2018-04-05 10:42:07 -07:00
2018-04-20 17:18:35 -07:00
2018-04-11 10:28:37 -07:00
2018-04-25 21:13:40 -07:00
2018-03-16 10:56:13 +01:00
2018-03-31 02:16:26 +02:00
2018-05-09 17:25:13 +02:00
2018-02-04 11:16:35 -08:00
2018-03-16 15:45:51 -07:00
2018-01-03 14:03:48 +01:00
2018-03-16 10:55:47 +01:00
2018-03-26 15:09:38 +02:00
2018-04-05 10:23:24 -07:00
2018-04-05 14:21:13 -07:00
2018-03-12 10:05:01 +01:00
2018-01-01 12:40:27 -07:00
2018-03-26 15:56:44 +02:00
\n
2018-04-25 21:23:38 -07:00
2018-01-29 09:08:34 -08:00
2018-02-26 09:48:42 -07:00
2018-04-09 11:42:31 -07:00
2018-04-05 14:27:02 -07:00
2018-02-22 21:13:03 +01:00
2018-03-26 08:53:43 -06:00
2018-01-17 11:30:16 +00:00
2018-01-29 09:08:34 -08:00
2018-04-11 10:28:35 -07:00
2018-04-11 10:28:38 -07:00
2018-02-24 01:43:47 +01:00
2018-03-13 13:29:10 -07:00
2018-04-12 09:41:19 -07:00
2018-01-03 11:00:22 -05:00
2018-04-07 12:08:19 -07:00
2018-04-11 10:28:32 -07:00
2018-04-11 10:28:39 -07:00
2018-03-26 13:14:43 -04:00
2018-03-26 13:14:43 -04:00
2018-03-26 13:14:43 -04:00
2018-01-28 22:17:24 -05:00
2018-01-08 08:22:45 -06:00
2018-02-01 10:57:45 -08:00
2018-01-17 15:25:50 +01:00
2018-01-08 08:22:45 -06:00
2017-12-14 16:00:49 -08:00
2018-04-11 10:28:39 -07:00
2018-01-31 17:18:37 -08:00
2018-04-06 18:31:06 -07:00
2018-04-06 18:31:06 -07:00
2018-01-19 16:50:53 -08:00
2018-04-28 16:48:04 -04:00
2017-12-16 02:05:48 +01:00
2018-02-20 16:12:26 -08:00
2017-12-11 14:37:11 -07:00
2018-03-17 14:20:55 +01:00
2018-03-01 08:33:05 -07:00
2018-04-05 14:27:02 -07:00
2018-01-29 12:02:54 -05:00
2018-04-05 21:36:24 -07:00
2018-04-05 21:36:27 -07:00
2018-05-03 15:55:23 -07:00
2018-01-18 11:56:49 +01:00
2018-01-15 12:07:46 -08:00
2018-02-06 09:59:40 -08:00
2018-02-06 18:32:47 -08:00
2018-01-09 16:27:43 +01:00
2018-04-10 11:27:30 -07:00
2018-02-20 16:10:25 -08:00
2018-04-26 15:08:04 -04:00
2018-02-06 18:32:44 -08:00
2017-12-20 09:53:54 -07:00