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 6*eae2e83eSJiri Olsa struct btf_id_set { 7*eae2e83eSJiri Olsa u32 cnt; 8*eae2e83eSJiri Olsa u32 ids[]; 9*eae2e83eSJiri Olsa }; 10*eae2e83eSJiri 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) \ 41e5a0516eSJiri Olsa __PASTE(prefix, __COUNTER__) 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" \ 70*eae2e83eSJiri 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 760f12e584SYonghong Song #define BTF_ID_LIST_GLOBAL(name) \ 770f12e584SYonghong Song __BTF_ID_LIST(name, globl) 780f12e584SYonghong Song 79e5a0516eSJiri Olsa /* 80e5a0516eSJiri Olsa * The BTF_ID_UNUSED macro defines 4 zero bytes. 81e5a0516eSJiri Olsa * It's used when we want to define 'unused' entry 82e5a0516eSJiri Olsa * in BTF_ID_LIST, like: 83e5a0516eSJiri Olsa * 84e5a0516eSJiri Olsa * BTF_ID_LIST(bpf_skb_output_btf_ids) 85e5a0516eSJiri Olsa * BTF_ID(struct, sk_buff) 86e5a0516eSJiri Olsa * BTF_ID_UNUSED 87e5a0516eSJiri Olsa * BTF_ID(struct, task_struct) 88e5a0516eSJiri Olsa */ 89e5a0516eSJiri Olsa 90e5a0516eSJiri Olsa #define BTF_ID_UNUSED \ 91e5a0516eSJiri Olsa asm( \ 92e5a0516eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 93e5a0516eSJiri Olsa ".zero 4 \n" \ 94e5a0516eSJiri Olsa ".popsection; \n"); 95e5a0516eSJiri Olsa 96*eae2e83eSJiri Olsa /* 97*eae2e83eSJiri Olsa * The BTF_SET_START/END macros pair defines sorted list of 98*eae2e83eSJiri Olsa * BTF IDs plus its members count, with following layout: 99*eae2e83eSJiri Olsa * 100*eae2e83eSJiri Olsa * BTF_SET_START(list) 101*eae2e83eSJiri Olsa * BTF_ID(type1, name1) 102*eae2e83eSJiri Olsa * BTF_ID(type2, name2) 103*eae2e83eSJiri Olsa * BTF_SET_END(list) 104*eae2e83eSJiri Olsa * 105*eae2e83eSJiri Olsa * __BTF_ID__set__list: 106*eae2e83eSJiri Olsa * .zero 4 107*eae2e83eSJiri Olsa * list: 108*eae2e83eSJiri Olsa * __BTF_ID__type1__name1__3: 109*eae2e83eSJiri Olsa * .zero 4 110*eae2e83eSJiri Olsa * __BTF_ID__type2__name2__4: 111*eae2e83eSJiri Olsa * .zero 4 112*eae2e83eSJiri Olsa * 113*eae2e83eSJiri Olsa */ 114*eae2e83eSJiri Olsa #define __BTF_SET_START(name, scope) \ 115*eae2e83eSJiri Olsa asm( \ 116*eae2e83eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 117*eae2e83eSJiri Olsa "." #scope " __BTF_ID__set__" #name "; \n" \ 118*eae2e83eSJiri Olsa "__BTF_ID__set__" #name ":; \n" \ 119*eae2e83eSJiri Olsa ".zero 4 \n" \ 120*eae2e83eSJiri Olsa ".popsection; \n"); 121*eae2e83eSJiri Olsa 122*eae2e83eSJiri Olsa #define BTF_SET_START(name) \ 123*eae2e83eSJiri Olsa __BTF_ID_LIST(name, local) \ 124*eae2e83eSJiri Olsa __BTF_SET_START(name, local) 125*eae2e83eSJiri Olsa 126*eae2e83eSJiri Olsa #define BTF_SET_START_GLOBAL(name) \ 127*eae2e83eSJiri Olsa __BTF_ID_LIST(name, globl) \ 128*eae2e83eSJiri Olsa __BTF_SET_START(name, globl) 129*eae2e83eSJiri Olsa 130*eae2e83eSJiri Olsa #define BTF_SET_END(name) \ 131*eae2e83eSJiri Olsa asm( \ 132*eae2e83eSJiri Olsa ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 133*eae2e83eSJiri Olsa ".size __BTF_ID__set__" #name ", .-" #name " \n" \ 134*eae2e83eSJiri Olsa ".popsection; \n"); \ 135*eae2e83eSJiri Olsa extern struct btf_id_set name; 136*eae2e83eSJiri Olsa 137d8dfe5bfSYonghong Song #else 138d8dfe5bfSYonghong Song 139d8dfe5bfSYonghong Song #define BTF_ID_LIST(name) static u32 name[5]; 140d8dfe5bfSYonghong Song #define BTF_ID(prefix, name) 141d8dfe5bfSYonghong Song #define BTF_ID_UNUSED 1420f12e584SYonghong Song #define BTF_ID_LIST_GLOBAL(name) u32 name[1]; 143*eae2e83eSJiri Olsa #define BTF_SET_START(name) static struct btf_id_set name = { 0 }; 144*eae2e83eSJiri Olsa #define BTF_SET_START_GLOBAL(name) static struct btf_id_set name = { 0 }; 145*eae2e83eSJiri Olsa #define BTF_SET_END(name) 146d8dfe5bfSYonghong Song 147d8dfe5bfSYonghong Song #endif /* CONFIG_DEBUG_INFO_BTF */ 148e5a0516eSJiri Olsa 149fce557bcSYonghong Song #ifdef CONFIG_NET 150fce557bcSYonghong Song /* Define a list of socket types which can be the argument for 151fce557bcSYonghong Song * skc_to_*_sock() helpers. All these sockets should have 152fce557bcSYonghong Song * sock_common as the first argument in its memory layout. 153fce557bcSYonghong Song */ 154fce557bcSYonghong Song #define BTF_SOCK_TYPE_xxx \ 155fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \ 156fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \ 157fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \ 158fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \ 159fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \ 160fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \ 161fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \ 162fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \ 163fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \ 164fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \ 165fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \ 166fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \ 167fce557bcSYonghong Song BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) 168fce557bcSYonghong Song 169fce557bcSYonghong Song enum { 170fce557bcSYonghong Song #define BTF_SOCK_TYPE(name, str) name, 171fce557bcSYonghong Song BTF_SOCK_TYPE_xxx 172fce557bcSYonghong Song #undef BTF_SOCK_TYPE 173fce557bcSYonghong Song MAX_BTF_SOCK_TYPE, 174fce557bcSYonghong Song }; 175fce557bcSYonghong Song 176fce557bcSYonghong Song extern u32 btf_sock_ids[]; 177fce557bcSYonghong Song #endif 178fce557bcSYonghong Song 179e5a0516eSJiri Olsa #endif 180