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