History

Merge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next

Andrii Nakryiko says: ==================== bpf-next 2021-12-10 v2 We've added 115 non-merge commits during the last 26 day(s) which contain a total of 182 files changed, 5747 insertions(+), 2564 deletions(-). The main changes are: 1) Various samples fixes, from Alexander Lobakin. 2) BPF CO-RE support in kernel and light skeleton, from Alexei Starovoitov. 3) A batch of new unified APIs for libbpf, logging improvements, version querying, etc. Also a batch of old deprecations for old APIs and various bug fixes, in preparation for libbpf 1.0, from Andrii Nakryiko. 4) BPF documentation reorganization and improvements, from Christoph Hellwig and Dave Tucker. 5) Support for declarative initialization of BPF_MAP_TYPE_PROG_ARRAY in libbpf, from Hengqi Chen. 6) Verifier log fixes, from Hou Tao. 7) Runtime-bounded loops support with bpf_loop() helper, from Joanne Koong. 8) Extend branch record capturing to all platforms that support it, from Kajol Jain. 9) Light skeleton codegen improvements, from Kumar Kartikeya Dwivedi. 10) bpftool doc-generating script improvements, from Quentin Monnet. 11) Two libbpf v0.6 bug fixes, from Shuyi Cheng and Vincent Minet. 12) Deprecation warning fix for perf/bpf_counter, from Song Liu. 13) MAX_TAIL_CALL_CNT unification and MIPS build fix for libbpf, from Tiezhu Yang. 14) BTF_KING_TYPE_TAG follow-up fixes, from Yonghong Song. 15) Selftests fixes and improvements, from Ilya Leoshkevich, Jean-Philippe Brucker, Jiri Olsa, Maxim Mikityanskiy, Tirthendu Sarkar, Yucong Sun, and others. * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (115 commits) libbpf: Add "bool skipped" to struct bpf_map libbpf: Fix typo in btf__dedup@LIBBPF_0.0.2 definition bpftool: Switch bpf_object__load_xattr() to bpf_object__load() selftests/bpf: Remove the only use of deprecated bpf_object__load_xattr() selftests/bpf: Add test for libbpf's custom log_buf behavior selftests/bpf: Replace all uses of bpf_load_btf() with bpf_btf_load() libbpf: Deprecate bpf_object__load_xattr() libbpf: Add per-program log buffer setter and getter libbpf: Preserve kernel error code and remove kprobe prog type guessing libbpf: Improve logging around BPF program loading libbpf: Allow passing user log setting through bpf_object_open_opts libbpf: Allow passing preallocated log_buf when loading BTF into kernel libbpf: Add OPTS-based bpf_btf_load() API libbpf: Fix bpf_prog_load() log_buf logic for log_level 0 samples/bpf: Remove unneeded variable bpf: Remove redundant assignment to pointer t selftests/bpf: Fix a compilation warning perf/bpf_counter: Use bpf_map_create instead of bpf_create_map samples: bpf: Fix 'unknown warning group' build warning on Clang samples: bpf: Fix xdp_sample_user.o linking with Clang ... ====================

Jakub Kicinski committed 4 years ago

Commit be315822 parents db10415 229fae3181 files · +5747 −2562Browse files

Showing the changes to include/uapi/linux (1 of 181 files). Show all

Unified · Split

include/uapi/linux/bpf.h+103−2
@@ -1342,8 +1342,10 @@ union bpf_attr { · 1341 unmodified lines
1342 /* or valid module BTF object fd or 0 to attach to vmlinux */1342 /* or valid module BTF object fd or 0 to attach to vmlinux */
1343 __u32 attach_btf_obj_fd;1343 __u32 attach_btf_obj_fd;
1344 };1344 };
1345 __u32 :32; /* pad */1345 __u32 core_relo_cnt; /* number of bpf_core_relo */
1346 __aligned_u64 fd_array; /* array of FDs */1346 __aligned_u64 fd_array; /* array of FDs */
1347 __aligned_u64 core_relos;
1348 __u32 core_relo_rec_size; /* sizeof(struct bpf_core_relo) */
1347 };1349 };
1348 1350
1349 struct { /* anonymous struct used by BPF_OBJ_* commands */1351 struct { /* anonymous struct used by BPF_OBJ_* commands */
@@ -1744,7 +1746,7 @@ union bpf_attr { · 394 unmodified lines
1744 * if the maximum number of tail calls has been reached for this1746 * if the maximum number of tail calls has been reached for this
1745 * chain of programs. This limit is defined in the kernel by the1747 * chain of programs. This limit is defined in the kernel by the
1746 * macro **MAX_TAIL_CALL_CNT** (not accessible to user space),1748 * macro **MAX_TAIL_CALL_CNT** (not accessible to user space),
1747 * which is currently set to 32.1749 * which is currently set to 33.
1748 * Return1750 * Return
1749 * 0 on success, or a negative error in case of failure.1751 * 0 on success, or a negative error in case of failure.
1750 *1752 *
@@ -4957,6 +4959,30 @@ union bpf_attr { · 3206 unmodified lines
4957 * **-ENOENT** if *task->mm* is NULL, or no vma contains *addr*.4959 * **-ENOENT** if *task->mm* is NULL, or no vma contains *addr*.
4958 * **-EBUSY** if failed to try lock mmap_lock.4960 * **-EBUSY** if failed to try lock mmap_lock.
4959 * **-EINVAL** for invalid **flags**.4961 * **-EINVAL** for invalid **flags**.
4962 *
4963 * long bpf_loop(u32 nr_loops, void *callback_fn, void *callback_ctx, u64 flags)
4964 * Description
4965 * For **nr_loops**, call **callback_fn** function
4966 * with **callback_ctx** as the context parameter.
4967 * The **callback_fn** should be a static function and
4968 * the **callback_ctx** should be a pointer to the stack.
4969 * The **flags** is used to control certain aspects of the helper.
4970 * Currently, the **flags** must be 0. Currently, nr_loops is
4971 * limited to 1 << 23 (~8 million) loops.
4972 *
4973 * long (\*callback_fn)(u32 index, void \*ctx);
4974 *
4975 * where **index** is the current index in the loop. The index
4976 * is zero-indexed.
4977 *
4978 * If **callback_fn** returns 0, the helper will continue to the next
4979 * loop. If return value is 1, the helper will skip the rest of
4980 * the loops and return. Other return values are not used now,
4981 * and will be rejected by the verifier.
4982 *
4983 * Return
4984 * The number of loops performed, **-EINVAL** for invalid **flags**,
4985 * **-E2BIG** if **nr_loops** exceeds the maximum number of loops.
4960 */4986 */
4961#define __BPF_FUNC_MAPPER(FN) \4987#define __BPF_FUNC_MAPPER(FN) \
4962 FN(unspec), \4988 FN(unspec), \
@@ -5140,6 +5166,7 @@ union bpf_attr { · 177 unmodified lines
5140 FN(skc_to_unix_sock), \5166 FN(skc_to_unix_sock), \
5141 FN(kallsyms_lookup_name), \5167 FN(kallsyms_lookup_name), \
5142 FN(find_vma), \5168 FN(find_vma), \
5169 FN(loop), \
5143 /* */5170 /* */
5144 5171
5145/* integer value in 'imm' field of BPF_CALL instruction selects which helper5172/* integer value in 'imm' field of BPF_CALL instruction selects which helper
@@ -6349,4 +6376,78 @@ enum { · 1203 unmodified lines
6349 BTF_F_ZERO = (1ULL << 3),6376 BTF_F_ZERO = (1ULL << 3),
6350};6377};
6351 6378
6379/* bpf_core_relo_kind encodes which aspect of captured field/type/enum value
6380 * has to be adjusted by relocations. It is emitted by llvm and passed to
6381 * libbpf and later to the kernel.
6382 */
6383enum bpf_core_relo_kind {
6384 BPF_CORE_FIELD_BYTE_OFFSET = 0, /* field byte offset */
6385 BPF_CORE_FIELD_BYTE_SIZE = 1, /* field size in bytes */
6386 BPF_CORE_FIELD_EXISTS = 2, /* field existence in target kernel */
6387 BPF_CORE_FIELD_SIGNED = 3, /* field signedness (0 - unsigned, 1 - signed) */
6388 BPF_CORE_FIELD_LSHIFT_U64 = 4, /* bitfield-specific left bitshift */
6389 BPF_CORE_FIELD_RSHIFT_U64 = 5, /* bitfield-specific right bitshift */
6390 BPF_CORE_TYPE_ID_LOCAL = 6, /* type ID in local BPF object */
6391 BPF_CORE_TYPE_ID_TARGET = 7, /* type ID in target kernel */
6392 BPF_CORE_TYPE_EXISTS = 8, /* type existence in target kernel */
6393 BPF_CORE_TYPE_SIZE = 9, /* type size in bytes */
6394 BPF_CORE_ENUMVAL_EXISTS = 10, /* enum value existence in target kernel */
6395 BPF_CORE_ENUMVAL_VALUE = 11, /* enum value integer value */
6396};
6397
6398/*
6399 * "struct bpf_core_relo" is used to pass relocation data form LLVM to libbpf
6400 * and from libbpf to the kernel.
6401 *
6402 * CO-RE relocation captures the following data:
6403 * - insn_off - instruction offset (in bytes) within a BPF program that needs
6404 * its insn->imm field to be relocated with actual field info;
6405 * - type_id - BTF type ID of the "root" (containing) entity of a relocatable
6406 * type or field;
6407 * - access_str_off - offset into corresponding .BTF string section. String
6408 * interpretation depends on specific relocation kind:
6409 * - for field-based relocations, string encodes an accessed field using
6410 * a sequence of field and array indices, separated by colon (:). It's
6411 * conceptually very close to LLVM's getelementptr ([0]) instruction's
6412 * arguments for identifying offset to a field.
6413 * - for type-based relocations, strings is expected to be just "0";
6414 * - for enum value-based relocations, string contains an index of enum
6415 * value within its enum type;
6416 * - kind - one of enum bpf_core_relo_kind;
6417 *
6418 * Example:
6419 * struct sample {
6420 * int a;
6421 * struct {
6422 * int b[10];
6423 * };
6424 * };
6425 *
6426 * struct sample *s = ...;
6427 * int *x = &s->a; // encoded as "0:0" (a is field #0)
6428 * int *y = &s->b[5]; // encoded as "0:1:0:5" (anon struct is field #1,
6429 * // b is field #0 inside anon struct, accessing elem #5)
6430 * int *z = &s[10]->b; // encoded as "10:1" (ptr is used as an array)
6431 *
6432 * type_id for all relocs in this example will capture BTF type id of
6433 * `struct sample`.
6434 *
6435 * Such relocation is emitted when using __builtin_preserve_access_index()
6436 * Clang built-in, passing expression that captures field address, e.g.:
6437 *
6438 * bpf_probe_read(&dst, sizeof(dst),
6439 * __builtin_preserve_access_index(&src->a.b.c));
6440 *
6441 * In this case Clang will emit field relocation recording necessary data to
6442 * be able to find offset of embedded `a.b.c` field within `src` struct.
6443 *
6444 * [0] https://llvm.org/docs/LangRef.html#getelementptr-instruction
6445 */
6446struct bpf_core_relo {
6447 __u32 insn_off;
6448 __u32 type_id;
6449 __u32 access_str_off;
6450 enum bpf_core_relo_kind kind;
6451};
6452
6352#endif /* _UAPI__LINUX_BPF_H__ */6453#endif /* _UAPI__LINUX_BPF_H__ */