Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 
0003 #ifndef _LINUX_BTF_IDS_H
0004 #define _LINUX_BTF_IDS_H
0005 
0006 struct btf_id_set {
0007     u32 cnt;
0008     u32 ids[];
0009 };
0010 
0011 #ifdef CONFIG_DEBUG_INFO_BTF
0012 
0013 #include <linux/compiler.h> /* for __PASTE */
0014 
0015 /*
0016  * Following macros help to define lists of BTF IDs placed
0017  * in .BTF_ids section. They are initially filled with zeros
0018  * (during compilation) and resolved later during the
0019  * linking phase by resolve_btfids tool.
0020  *
0021  * Any change in list layout must be reflected in resolve_btfids
0022  * tool logic.
0023  */
0024 
0025 #define BTF_IDS_SECTION ".BTF_ids"
0026 
0027 #define ____BTF_ID(symbol)              \
0028 asm(                            \
0029 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"  \
0030 ".local " #symbol " ;                          \n"  \
0031 ".type  " #symbol ", STT_OBJECT;               \n"  \
0032 ".size  " #symbol ", 4;                        \n"  \
0033 #symbol ":                                     \n"  \
0034 ".zero 4                                       \n"  \
0035 ".popsection;                                  \n");
0036 
0037 #define __BTF_ID(symbol) \
0038     ____BTF_ID(symbol)
0039 
0040 #define __ID(prefix) \
0041     __PASTE(prefix, __COUNTER__)
0042 
0043 /*
0044  * The BTF_ID defines unique symbol for each ID pointing
0045  * to 4 zero bytes.
0046  */
0047 #define BTF_ID(prefix, name) \
0048     __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__))
0049 
0050 /*
0051  * The BTF_ID_LIST macro defines pure (unsorted) list
0052  * of BTF IDs, with following layout:
0053  *
0054  * BTF_ID_LIST(list1)
0055  * BTF_ID(type1, name1)
0056  * BTF_ID(type2, name2)
0057  *
0058  * list1:
0059  * __BTF_ID__type1__name1__1:
0060  * .zero 4
0061  * __BTF_ID__type2__name2__2:
0062  * .zero 4
0063  *
0064  */
0065 #define __BTF_ID_LIST(name, scope)          \
0066 asm(                            \
0067 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"  \
0068 "." #scope " " #name ";                        \n"  \
0069 #name ":;                                      \n"  \
0070 ".popsection;                                  \n");
0071 
0072 #define BTF_ID_LIST(name)               \
0073 __BTF_ID_LIST(name, local)              \
0074 extern u32 name[];
0075 
0076 #define BTF_ID_LIST_GLOBAL(name, n)         \
0077 __BTF_ID_LIST(name, globl)
0078 
0079 /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
0080  * a single entry.
0081  */
0082 #define BTF_ID_LIST_SINGLE(name, prefix, typename)  \
0083     BTF_ID_LIST(name) \
0084     BTF_ID(prefix, typename)
0085 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
0086     BTF_ID_LIST_GLOBAL(name, 1)           \
0087     BTF_ID(prefix, typename)
0088 
0089 /*
0090  * The BTF_ID_UNUSED macro defines 4 zero bytes.
0091  * It's used when we want to define 'unused' entry
0092  * in BTF_ID_LIST, like:
0093  *
0094  *   BTF_ID_LIST(bpf_skb_output_btf_ids)
0095  *   BTF_ID(struct, sk_buff)
0096  *   BTF_ID_UNUSED
0097  *   BTF_ID(struct, task_struct)
0098  */
0099 
0100 #define BTF_ID_UNUSED                   \
0101 asm(                            \
0102 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"  \
0103 ".zero 4                                       \n"  \
0104 ".popsection;                                  \n");
0105 
0106 /*
0107  * The BTF_SET_START/END macros pair defines sorted list of
0108  * BTF IDs plus its members count, with following layout:
0109  *
0110  * BTF_SET_START(list)
0111  * BTF_ID(type1, name1)
0112  * BTF_ID(type2, name2)
0113  * BTF_SET_END(list)
0114  *
0115  * __BTF_ID__set__list:
0116  * .zero 4
0117  * list:
0118  * __BTF_ID__type1__name1__3:
0119  * .zero 4
0120  * __BTF_ID__type2__name2__4:
0121  * .zero 4
0122  *
0123  */
0124 #define __BTF_SET_START(name, scope)            \
0125 asm(                            \
0126 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"  \
0127 "." #scope " __BTF_ID__set__" #name ";         \n"  \
0128 "__BTF_ID__set__" #name ":;                    \n"  \
0129 ".zero 4                                       \n"  \
0130 ".popsection;                                  \n");
0131 
0132 #define BTF_SET_START(name)             \
0133 __BTF_ID_LIST(name, local)              \
0134 __BTF_SET_START(name, local)
0135 
0136 #define BTF_SET_START_GLOBAL(name)          \
0137 __BTF_ID_LIST(name, globl)              \
0138 __BTF_SET_START(name, globl)
0139 
0140 #define BTF_SET_END(name)               \
0141 asm(                            \
0142 ".pushsection " BTF_IDS_SECTION ",\"a\";      \n"   \
0143 ".size __BTF_ID__set__" #name ", .-" #name "  \n"   \
0144 ".popsection;                                 \n"); \
0145 extern struct btf_id_set name;
0146 
0147 #else
0148 
0149 #define BTF_ID_LIST(name) static u32 __maybe_unused name[5];
0150 #define BTF_ID(prefix, name)
0151 #define BTF_ID_UNUSED
0152 #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n];
0153 #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1];
0154 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1];
0155 #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 };
0156 #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 };
0157 #define BTF_SET_END(name)
0158 
0159 #endif /* CONFIG_DEBUG_INFO_BTF */
0160 
0161 #ifdef CONFIG_NET
0162 /* Define a list of socket types which can be the argument for
0163  * skc_to_*_sock() helpers. All these sockets should have
0164  * sock_common as the first argument in its memory layout.
0165  */
0166 #define BTF_SOCK_TYPE_xxx \
0167     BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)            \
0168     BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)    \
0169     BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)    \
0170     BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)    \
0171     BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)          \
0172     BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)             \
0173     BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)       \
0174     BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)          \
0175     BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)      \
0176     BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)      \
0177     BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)            \
0178     BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)          \
0179     BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)            \
0180     BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock)            \
0181     BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock)          \
0182     BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket)
0183 
0184 enum {
0185 #define BTF_SOCK_TYPE(name, str) name,
0186 BTF_SOCK_TYPE_xxx
0187 #undef BTF_SOCK_TYPE
0188 MAX_BTF_SOCK_TYPE,
0189 };
0190 
0191 extern u32 btf_sock_ids[];
0192 #endif
0193 
0194 #define BTF_TRACING_TYPE_xxx    \
0195     BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct)    \
0196     BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file)       \
0197     BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct)
0198 
0199 enum {
0200 #define BTF_TRACING_TYPE(name, type) name,
0201 BTF_TRACING_TYPE_xxx
0202 #undef BTF_TRACING_TYPE
0203 MAX_BTF_TRACING_TYPE,
0204 };
0205 
0206 extern u32 btf_tracing_ids[];
0207 
0208 #endif