1e5a0516eSJiri Olsa /* SPDX-License-Identifier: GPL-2.0 */ 2e5a0516eSJiri Olsa 3e5a0516eSJiri Olsa #ifndef _LINUX_BTF_IDS_H 4e5a0516eSJiri Olsa #define _LINUX_BTF_IDS_H 5e5a0516eSJiri Olsa 6eae2e83eSJiri Olsa struct btf_id_set { 7eae2e83eSJiri Olsa u32 cnt; 8eae2e83eSJiri Olsa u32 ids[]; 9eae2e83eSJiri Olsa }; 10eae2e83eSJiri Olsa 11d8dfe5bfSYonghong Song #ifdef CONFIG_DEBUG_INFO_BTF 12d8dfe5bfSYonghong Song 13e5a0516eSJiri Olsa #include <linux/compiler.h> /* for __PASTE */ 14e5a0516eSJiri Olsa 15e5a0516eSJiri Olsa /* 16e5a0516eSJiri Olsa * Following macros help to define lists of BTF IDs placed 17e5a0516eSJiri Olsa * in .BTF_ids section. They are initially filled with zeros 18e5a0516eSJiri Olsa * (during compilation) and resolved later during the 19e5a0516eSJiri Olsa * linking phase by resolve_btfids tool. 20e5a0516eSJiri Olsa * 21e5a0516eSJiri Olsa * Any change in list layout must be reflected in resolve_btfids 22e5a0516eSJiri Olsa * tool logic. 23e5a0516eSJiri Olsa */ 24e5a0516eSJiri Olsa 25e5a0516eSJiri Olsa #define BTF_IDS_SECTION ".BTF_ids" 26e5a0516eSJiri Olsa 27e5a0516eSJiri Olsa #define ____BTF_ID(symbol) \ 28e5a0516eSJiri Olsa asm( \ 29e5a0516eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 30e5a0516eSJiri Olsa ".local " #symbol " ; \n" \ 31d8dfe5bfSYonghong Song ".type " #symbol ", STT_OBJECT; \n" \ 32e5a0516eSJiri Olsa ".size " #symbol ", 4; \n" \ 33e5a0516eSJiri Olsa #symbol ": \n" \ 34e5a0516eSJiri Olsa ".zero 4 \n" \ 35e5a0516eSJiri Olsa ".popsection; \n"); 36e5a0516eSJiri Olsa 37e5a0516eSJiri Olsa #define __BTF_ID(symbol) \ 38e5a0516eSJiri Olsa ____BTF_ID(symbol) 39e5a0516eSJiri Olsa 40e5a0516eSJiri Olsa #define __ID(prefix) \ 41*c0bb9fb0SNick Desaulniers __PASTE(__PASTE(prefix, __COUNTER__), __LINE__) 42e5a0516eSJiri Olsa 43e5a0516eSJiri Olsa /* 44e5a0516eSJiri Olsa * The BTF_ID defines unique symbol for each ID pointing 45e5a0516eSJiri Olsa * to 4 zero bytes. 46e5a0516eSJiri Olsa */ 47e5a0516eSJiri Olsa #define BTF_ID(prefix, name) \ 48e5a0516eSJiri Olsa __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__)) 49e5a0516eSJiri Olsa 50e5a0516eSJiri Olsa /* 51e5a0516eSJiri Olsa * The BTF_ID_LIST macro defines pure (unsorted) list 52e5a0516eSJiri Olsa * of BTF IDs, with following layout: 53e5a0516eSJiri Olsa * 54e5a0516eSJiri Olsa * BTF_ID_LIST(list1) 55e5a0516eSJiri Olsa * BTF_ID(type1, name1) 56e5a0516eSJiri Olsa * BTF_ID(type2, name2) 57e5a0516eSJiri Olsa * 58e5a0516eSJiri Olsa * list1: 59e5a0516eSJiri Olsa * __BTF_ID__type1__name1__1: 60e5a0516eSJiri Olsa * .zero 4 61e5a0516eSJiri Olsa * __BTF_ID__type2__name2__2: 62e5a0516eSJiri Olsa * .zero 4 63e5a0516eSJiri Olsa * 64e5a0516eSJiri Olsa */ 650f12e584SYonghong Song #define __BTF_ID_LIST(name, scope) \ 66e5a0516eSJiri Olsa asm( \ 67e5a0516eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 680f12e584SYonghong Song "." #scope " " #name "; \n" \ 69e5a0516eSJiri Olsa #name ":; \n" \ 70eae2e83eSJiri Olsa ".popsection; \n"); 71e5a0516eSJiri Olsa 72e5a0516eSJiri Olsa #define BTF_ID_LIST(name) \ 730f12e584SYonghong Song __BTF_ID_LIST(name, local) \ 74e5a0516eSJiri Olsa extern u32 name[]; 75e5a0516eSJiri Olsa 763b34bcb9SStanislav Fomichev #define BTF_ID_LIST_GLOBAL(name, n) \ 770f12e584SYonghong Song __BTF_ID_LIST(name, globl) 780f12e584SYonghong Song 7927774b70SLorenz Bauer /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with 8027774b70SLorenz Bauer * a single entry. 8127774b70SLorenz Bauer */ 8227774b70SLorenz Bauer #define BTF_ID_LIST_SINGLE(name, prefix, typename) \ 8327774b70SLorenz Bauer BTF_ID_LIST(name) \ 8427774b70SLorenz Bauer BTF_ID(prefix, typename) 853b34bcb9SStanislav Fomichev #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \ 863b34bcb9SStanislav Fomichev BTF_ID_LIST_GLOBAL(name, 1) \ 873b34bcb9SStanislav Fomichev BTF_ID(prefix, typename) 8827774b70SLorenz Bauer 89e5a0516eSJiri Olsa /* 90e5a0516eSJiri Olsa * The BTF_ID_UNUSED macro defines 4 zero bytes. 91e5a0516eSJiri Olsa * It's used when we want to define 'unused' entry 92e5a0516eSJiri Olsa * in BTF_ID_LIST, like: 93e5a0516eSJiri Olsa * 94e5a0516eSJiri Olsa * BTF_ID_LIST(bpf_skb_output_btf_ids) 95e5a0516eSJiri Olsa * BTF_ID(struct, sk_buff) 96e5a0516eSJiri Olsa * BTF_ID_UNUSED 97e5a0516eSJiri Olsa * BTF_ID(struct, task_struct) 98e5a0516eSJiri Olsa */ 99e5a0516eSJiri Olsa 100e5a0516eSJiri Olsa #define BTF_ID_UNUSED \ 101e5a0516eSJiri Olsa asm( \ 102e5a0516eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 103e5a0516eSJiri Olsa ".zero 4 \n" \ 104e5a0516eSJiri Olsa ".popsection; \n"); 105e5a0516eSJiri Olsa 106eae2e83eSJiri Olsa /* 107eae2e83eSJiri Olsa * The BTF_SET_START/END macros pair defines sorted list of 108eae2e83eSJiri Olsa * BTF IDs plus its members count, with following layout: 109eae2e83eSJiri Olsa * 110eae2e83eSJiri Olsa * BTF_SET_START(list) 111eae2e83eSJiri Olsa * BTF_ID(type1, name1) 112eae2e83eSJiri Olsa * BTF_ID(type2, name2) 113eae2e83eSJiri Olsa * BTF_SET_END(list) 114eae2e83eSJiri Olsa * 115eae2e83eSJiri Olsa * __BTF_ID__set__list: 116eae2e83eSJiri Olsa * .zero 4 117eae2e83eSJiri Olsa * list: 118eae2e83eSJiri Olsa * __BTF_ID__type1__name1__3: 119eae2e83eSJiri Olsa * .zero 4 120eae2e83eSJiri Olsa * __BTF_ID__type2__name2__4: 121eae2e83eSJiri Olsa * .zero 4 122eae2e83eSJiri Olsa * 123eae2e83eSJiri Olsa */ 124eae2e83eSJiri Olsa #define __BTF_SET_START(name, scope) \ 125eae2e83eSJiri Olsa asm( \ 126eae2e83eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 127eae2e83eSJiri Olsa "." #scope " __BTF_ID__set__" #name "; \n" \ 128eae2e83eSJiri Olsa "__BTF_ID__set__" #name ":; \n" \ 129eae2e83eSJiri Olsa ".zero 4 \n" \ 130eae2e83eSJiri Olsa ".popsection; \n"); 131eae2e83eSJiri Olsa 132eae2e83eSJiri Olsa #define BTF_SET_START(name) \ 133eae2e83eSJiri Olsa __BTF_ID_LIST(name, local) \ 134eae2e83eSJiri Olsa __BTF_SET_START(name, local) 135eae2e83eSJiri Olsa 136eae2e83eSJiri Olsa #define BTF_SET_START_GLOBAL(name) \ 137eae2e83eSJiri Olsa __BTF_ID_LIST(name, globl) \ 138eae2e83eSJiri Olsa __BTF_SET_START(name, globl) 139eae2e83eSJiri Olsa 140eae2e83eSJiri Olsa #define BTF_SET_END(name) \ 141eae2e83eSJiri Olsa asm( \ 142eae2e83eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 143eae2e83eSJiri Olsa ".size __BTF_ID__set__" #name ", .-" #name " \n" \ 144eae2e83eSJiri Olsa ".popsection; \n"); \ 145eae2e83eSJiri Olsa extern struct btf_id_set name; 146eae2e83eSJiri Olsa 147d8dfe5bfSYonghong Song #else 148d8dfe5bfSYonghong Song 1493b34bcb9SStanislav Fomichev #define BTF_ID_LIST(name) static u32 __maybe_unused name[5]; 150d8dfe5bfSYonghong Song #define BTF_ID(prefix, name) 151d8dfe5bfSYonghong Song #define BTF_ID_UNUSED 1523b34bcb9SStanislav Fomichev #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n]; 1533b34bcb9SStanislav Fomichev #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1]; 1543b34bcb9SStanislav Fomichev #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1]; 1553b34bcb9SStanislav Fomichev #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 }; 1563b34bcb9SStanislav Fomichev #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 }; 157eae2e83eSJiri Olsa #define BTF_SET_END(name) 158d8dfe5bfSYonghong Song 159d8dfe5bfSYonghong Song #endif /* CONFIG_DEBUG_INFO_BTF */ 160e5a0516eSJiri Olsa 161fce557bcSYonghong Song #ifdef CONFIG_NET 162fce557bcSYonghong Song /* Define a list of socket types which can be the argument for 163fce557bcSYonghong Song * skc_to_*_sock() helpers. All these sockets should have 164fce557bcSYonghong Song * sock_common as the first argument in its memory layout. 165fce557bcSYonghong Song */ 166fce557bcSYonghong Song #define BTF_SOCK_TYPE_xxx \ 167fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \ 168fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \ 169fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \ 170fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \ 171fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \ 172fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \ 173fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \ 174fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \ 175fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \ 176fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \ 177fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \ 178fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \ 1793b34bcb9SStanislav Fomichev BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \ 1803b34bcb9SStanislav Fomichev BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \ 1813b34bcb9SStanislav Fomichev BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) \ 1823b34bcb9SStanislav Fomichev BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket) 183fce557bcSYonghong Song 184fce557bcSYonghong Song enum { 185fce557bcSYonghong Song #define BTF_SOCK_TYPE(name, str) name, 186fce557bcSYonghong Song BTF_SOCK_TYPE_xxx 187fce557bcSYonghong Song #undef BTF_SOCK_TYPE 188fce557bcSYonghong Song MAX_BTF_SOCK_TYPE, 189fce557bcSYonghong Song }; 190fce557bcSYonghong Song 191fce557bcSYonghong Song extern u32 btf_sock_ids[]; 192fce557bcSYonghong Song #endif 193fce557bcSYonghong Song 1943b34bcb9SStanislav Fomichev #define BTF_TRACING_TYPE_xxx \ 1953b34bcb9SStanislav Fomichev BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \ 1963b34bcb9SStanislav Fomichev BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \ 1973b34bcb9SStanislav Fomichev BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct) 1983b34bcb9SStanislav Fomichev 1993b34bcb9SStanislav Fomichev enum { 2003b34bcb9SStanislav Fomichev #define BTF_TRACING_TYPE(name, type) name, 2013b34bcb9SStanislav Fomichev BTF_TRACING_TYPE_xxx 2023b34bcb9SStanislav Fomichev #undef BTF_TRACING_TYPE 2033b34bcb9SStanislav Fomichev MAX_BTF_TRACING_TYPE, 2043b34bcb9SStanislav Fomichev }; 2053b34bcb9SStanislav Fomichev 2063b34bcb9SStanislav Fomichev extern u32 btf_tracing_ids[]; 2073b34bcb9SStanislav Fomichev 208e5a0516eSJiri Olsa #endif 209