Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: btf: Sync bpf.h and btf.h to tools/

This patch sync up the bpf.h and btf.h to tools/

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Alexei Starovoitov <ast@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

authored by

Martin KaFai Lau and committed by
Daniel Borkmann
3bd86a84 a26ca7c9

+142
+12
tools/include/uapi/linux/bpf.h
··· 95 95 BPF_OBJ_GET_INFO_BY_FD, 96 96 BPF_PROG_QUERY, 97 97 BPF_RAW_TRACEPOINT_OPEN, 98 + BPF_BTF_LOAD, 98 99 }; 99 100 100 101 enum bpf_map_type { ··· 280 279 */ 281 280 char map_name[BPF_OBJ_NAME_LEN]; 282 281 __u32 map_ifindex; /* ifindex of netdev to create on */ 282 + __u32 btf_fd; /* fd pointing to a BTF type data */ 283 + __u32 btf_key_id; /* BTF type_id of the key */ 284 + __u32 btf_value_id; /* BTF type_id of the value */ 283 285 }; 284 286 285 287 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ ··· 367 363 __u64 name; 368 364 __u32 prog_fd; 369 365 } raw_tracepoint; 366 + 367 + struct { /* anonymous struct for BPF_BTF_LOAD */ 368 + __aligned_u64 btf; 369 + __aligned_u64 btf_log_buf; 370 + __u32 btf_size; 371 + __u32 btf_log_size; 372 + __u32 btf_log_level; 373 + }; 370 374 } __attribute__((aligned(8))); 371 375 372 376 /* BPF helper function descriptions:
+130
tools/include/uapi/linux/btf.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 + /* Copyright (c) 2018 Facebook */ 3 + #ifndef _UAPI__LINUX_BTF_H__ 4 + #define _UAPI__LINUX_BTF_H__ 5 + 6 + #include <linux/types.h> 7 + 8 + #define BTF_MAGIC 0xeB9F 9 + #define BTF_MAGIC_SWAP 0x9FeB 10 + #define BTF_VERSION 1 11 + #define BTF_FLAGS_COMPR 0x01 12 + 13 + struct btf_header { 14 + __u16 magic; 15 + __u8 version; 16 + __u8 flags; 17 + 18 + __u32 parent_label; 19 + __u32 parent_name; 20 + 21 + /* All offsets are in bytes relative to the end of this header */ 22 + __u32 label_off; /* offset of label section */ 23 + __u32 object_off; /* offset of data object section*/ 24 + __u32 func_off; /* offset of function section */ 25 + __u32 type_off; /* offset of type section */ 26 + __u32 str_off; /* offset of string section */ 27 + __u32 str_len; /* length of string section */ 28 + }; 29 + 30 + /* Max # of type identifier */ 31 + #define BTF_MAX_TYPE 0x7fffffff 32 + /* Max offset into the string section */ 33 + #define BTF_MAX_NAME_OFFSET 0x7fffffff 34 + /* Max # of struct/union/enum members or func args */ 35 + #define BTF_MAX_VLEN 0xffff 36 + 37 + /* The type id is referring to a parent BTF */ 38 + #define BTF_TYPE_PARENT(id) (((id) >> 31) & 0x1) 39 + #define BTF_TYPE_ID(id) ((id) & BTF_MAX_TYPE) 40 + 41 + /* String is in the ELF string section */ 42 + #define BTF_STR_TBL_ELF_ID(ref) (((ref) >> 31) & 0x1) 43 + #define BTF_STR_OFFSET(ref) ((ref) & BTF_MAX_NAME_OFFSET) 44 + 45 + struct btf_type { 46 + __u32 name; 47 + /* "info" bits arrangement 48 + * bits 0-15: vlen (e.g. # of struct's members) 49 + * bits 16-23: unused 50 + * bits 24-28: kind (e.g. int, ptr, array...etc) 51 + * bits 29-30: unused 52 + * bits 31: root 53 + */ 54 + __u32 info; 55 + /* "size" is used by INT, ENUM, STRUCT and UNION. 56 + * "size" tells the size of the type it is describing. 57 + * 58 + * "type" is used by PTR, TYPEDEF, VOLATILE, CONST and RESTRICT. 59 + * "type" is a type_id referring to another type. 60 + */ 61 + union { 62 + __u32 size; 63 + __u32 type; 64 + }; 65 + }; 66 + 67 + #define BTF_INFO_KIND(info) (((info) >> 24) & 0x1f) 68 + #define BTF_INFO_ISROOT(info) (!!(((info) >> 24) & 0x80)) 69 + #define BTF_INFO_VLEN(info) ((info) & 0xffff) 70 + 71 + #define BTF_KIND_UNKN 0 /* Unknown */ 72 + #define BTF_KIND_INT 1 /* Integer */ 73 + #define BTF_KIND_PTR 2 /* Pointer */ 74 + #define BTF_KIND_ARRAY 3 /* Array */ 75 + #define BTF_KIND_STRUCT 4 /* Struct */ 76 + #define BTF_KIND_UNION 5 /* Union */ 77 + #define BTF_KIND_ENUM 6 /* Enumeration */ 78 + #define BTF_KIND_FWD 7 /* Forward */ 79 + #define BTF_KIND_TYPEDEF 8 /* Typedef */ 80 + #define BTF_KIND_VOLATILE 9 /* Volatile */ 81 + #define BTF_KIND_CONST 10 /* Const */ 82 + #define BTF_KIND_RESTRICT 11 /* Restrict */ 83 + #define BTF_KIND_MAX 11 84 + #define NR_BTF_KINDS 12 85 + 86 + /* For some specific BTF_KIND, "struct btf_type" is immediately 87 + * followed by extra data. 88 + */ 89 + 90 + /* BTF_KIND_INT is followed by a u32 and the following 91 + * is the 32 bits arrangement: 92 + */ 93 + #define BTF_INT_ENCODING(VAL) (((VAL) & 0xff000000) >> 24) 94 + #define BTF_INT_OFFSET(VAL) (((VAL & 0x00ff0000)) >> 16) 95 + #define BTF_INT_BITS(VAL) ((VAL) & 0x0000ffff) 96 + 97 + /* Attributes stored in the BTF_INT_ENCODING */ 98 + #define BTF_INT_SIGNED 0x1 99 + #define BTF_INT_CHAR 0x2 100 + #define BTF_INT_BOOL 0x4 101 + #define BTF_INT_VARARGS 0x8 102 + 103 + /* BTF_KIND_ENUM is followed by multiple "struct btf_enum". 104 + * The exact number of btf_enum is stored in the vlen (of the 105 + * info in "struct btf_type"). 106 + */ 107 + struct btf_enum { 108 + __u32 name; 109 + __s32 val; 110 + }; 111 + 112 + /* BTF_KIND_ARRAY is followed by one "struct btf_array" */ 113 + struct btf_array { 114 + __u32 type; 115 + __u32 index_type; 116 + __u32 nelems; 117 + }; 118 + 119 + /* BTF_KIND_STRUCT and BTF_KIND_UNION are followed 120 + * by multiple "struct btf_member". The exact number 121 + * of btf_member is stored in the vlen (of the info in 122 + * "struct btf_type"). 123 + */ 124 + struct btf_member { 125 + __u32 name; 126 + __u32 type; 127 + __u32 offset; /* offset in bits */ 128 + }; 129 + 130 + #endif /* _UAPI__LINUX_BTF_H__ */