1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 #ifndef _LINUX_BTF_IDS_H 4 #define _LINUX_BTF_IDS_H 5 6 struct btf_id_set { 7 u32 cnt; 8 u32 ids[]; 9 }; 10 11 #ifdef CONFIG_DEBUG_INFO_BTF 12 13 #include <linux/compiler.h> /* for __PASTE */ 14 #include <linux/compiler_attributes.h> /* for __maybe_unused */ 15 16 /* 17 * Following macros help to define lists of BTF IDs placed 18 * in .BTF_ids section. They are initially filled with zeros 19 * (during compilation) and resolved later during the 20 * linking phase by resolve_btfids tool. 21 * 22 * Any change in list layout must be reflected in resolve_btfids 23 * tool logic. 24 */ 25 26 #define BTF_IDS_SECTION ".BTF_ids" 27 28 #define ____BTF_ID(symbol) \ 29 asm( \ 30 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 31 ".local " #symbol " ; \n" \ 32 ".type " #symbol ", STT_OBJECT; \n" \ 33 ".size " #symbol ", 4; \n" \ 34 #symbol ": \n" \ 35 ".zero 4 \n" \ 36 ".popsection; \n"); 37 38 #define __BTF_ID(symbol) \ 39 ____BTF_ID(symbol) 40 41 #define __ID(prefix) \ 42 __PASTE(prefix, __COUNTER__) 43 44 /* 45 * The BTF_ID defines unique symbol for each ID pointing 46 * to 4 zero bytes. 47 */ 48 #define BTF_ID(prefix, name) \ 49 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__)) 50 51 /* 52 * The BTF_ID_LIST macro defines pure (unsorted) list 53 * of BTF IDs, with following layout: 54 * 55 * BTF_ID_LIST(list1) 56 * BTF_ID(type1, name1) 57 * BTF_ID(type2, name2) 58 * 59 * list1: 60 * __BTF_ID__type1__name1__1: 61 * .zero 4 62 * __BTF_ID__type2__name2__2: 63 * .zero 4 64 * 65 */ 66 #define __BTF_ID_LIST(name, scope) \ 67 asm( \ 68 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 69 "." #scope " " #name "; \n" \ 70 #name ":; \n" \ 71 ".popsection; \n"); 72 73 #define BTF_ID_LIST(name) \ 74 __BTF_ID_LIST(name, local) \ 75 extern u32 name[]; 76 77 #define BTF_ID_LIST_GLOBAL(name, n) \ 78 __BTF_ID_LIST(name, globl) 79 80 /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with 81 * a single entry. 82 */ 83 #define BTF_ID_LIST_SINGLE(name, prefix, typename) \ 84 BTF_ID_LIST(name) \ 85 BTF_ID(prefix, typename) 86 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \ 87 BTF_ID_LIST_GLOBAL(name, 1) \ 88 BTF_ID(prefix, typename) 89 90 /* 91 * The BTF_ID_UNUSED macro defines 4 zero bytes. 92 * It's used when we want to define 'unused' entry 93 * in BTF_ID_LIST, like: 94 * 95 * BTF_ID_LIST(bpf_skb_output_btf_ids) 96 * BTF_ID(struct, sk_buff) 97 * BTF_ID_UNUSED 98 * BTF_ID(struct, task_struct) 99 */ 100 101 #define BTF_ID_UNUSED \ 102 asm( \ 103 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 104 ".zero 4 \n" \ 105 ".popsection; \n"); 106 107 /* 108 * The BTF_SET_START/END macros pair defines sorted list of 109 * BTF IDs plus its members count, with following layout: 110 * 111 * BTF_SET_START(list) 112 * BTF_ID(type1, name1) 113 * BTF_ID(type2, name2) 114 * BTF_SET_END(list) 115 * 116 * __BTF_ID__set__list: 117 * .zero 4 118 * list: 119 * __BTF_ID__type1__name1__3: 120 * .zero 4 121 * __BTF_ID__type2__name2__4: 122 * .zero 4 123 * 124 */ 125 #define __BTF_SET_START(name, scope) \ 126 asm( \ 127 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 128 "." #scope " __BTF_ID__set__" #name "; \n" \ 129 "__BTF_ID__set__" #name ":; \n" \ 130 ".zero 4 \n" \ 131 ".popsection; \n"); 132 133 #define BTF_SET_START(name) \ 134 __BTF_ID_LIST(name, local) \ 135 __BTF_SET_START(name, local) 136 137 #define BTF_SET_START_GLOBAL(name) \ 138 __BTF_ID_LIST(name, globl) \ 139 __BTF_SET_START(name, globl) 140 141 #define BTF_SET_END(name) \ 142 asm( \ 143 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 144 ".size __BTF_ID__set__" #name ", .-" #name " \n" \ 145 ".popsection; \n"); \ 146 extern struct btf_id_set name; 147 148 #else 149 150 #define BTF_ID_LIST(name) static u32 __maybe_unused name[5]; 151 #define BTF_ID(prefix, name) 152 #define BTF_ID_UNUSED 153 #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n]; 154 #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1]; 155 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1]; 156 #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 }; 157 #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 }; 158 #define BTF_SET_END(name) 159 160 #endif /* CONFIG_DEBUG_INFO_BTF */ 161 162 #ifdef CONFIG_NET 163 /* Define a list of socket types which can be the argument for 164 * skc_to_*_sock() helpers. All these sockets should have 165 * sock_common as the first argument in its memory layout. 166 */ 167 #define BTF_SOCK_TYPE_xxx \ 168 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \ 169 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \ 170 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \ 171 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \ 172 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \ 173 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \ 174 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \ 175 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \ 176 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \ 177 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \ 178 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \ 179 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \ 180 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \ 181 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) 182 183 enum { 184 #define BTF_SOCK_TYPE(name, str) name, 185 BTF_SOCK_TYPE_xxx 186 #undef BTF_SOCK_TYPE 187 MAX_BTF_SOCK_TYPE, 188 }; 189 190 extern u32 btf_sock_ids[]; 191 #endif 192 193 #define BTF_TRACING_TYPE_xxx \ 194 BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \ 195 BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \ 196 BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct) 197 198 enum { 199 #define BTF_TRACING_TYPE(name, type) name, 200 BTF_TRACING_TYPE_xxx 201 #undef BTF_TRACING_TYPE 202 MAX_BTF_TRACING_TYPE, 203 }; 204 205 extern u32 btf_tracing_ids[]; 206 207 #endif 208