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 struct btf_id_set8 {
0012     u32 cnt;
0013     u32 flags;
0014     struct {
0015         u32 id;
0016         u32 flags;
0017     } pairs[];
0018 };
0019 
0020 #ifdef CONFIG_DEBUG_INFO_BTF
0021 
0022 #include <linux/compiler.h> /* for __PASTE */
0023 #include <linux/compiler_attributes.h> /* for __maybe_unused */
0024 
0025 /*
0026  * Following macros help to define lists of BTF IDs placed
0027  * in .BTF_ids section. They are initially filled with zeros
0028  * (during compilation) and resolved later during the
0029  * linking phase by resolve_btfids tool.
0030  *
0031  * Any change in list layout must be reflected in resolve_btfids
0032  * tool logic.
0033  */
0034 
0035 #define BTF_IDS_SECTION ".BTF_ids"
0036 
0037 #define ____BTF_ID(symbol, word)            \
0038 asm(                            \
0039 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"  \
0040 ".local " #symbol " ;                          \n"  \
0041 ".type  " #symbol ", STT_OBJECT;               \n"  \
0042 ".size  " #symbol ", 4;                        \n"  \
0043 #symbol ":                                     \n"  \
0044 ".zero 4                                       \n"  \
0045 word                            \
0046 ".popsection;                                  \n");
0047 
0048 #define __BTF_ID(symbol, word) \
0049     ____BTF_ID(symbol, word)
0050 
0051 #define __ID(prefix) \
0052     __PASTE(prefix, __COUNTER__)
0053 
0054 /*
0055  * The BTF_ID defines unique symbol for each ID pointing
0056  * to 4 zero bytes.
0057  */
0058 #define BTF_ID(prefix, name) \
0059     __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), "")
0060 
0061 #define ____BTF_ID_FLAGS(prefix, name, flags) \
0062     __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), ".long " #flags "\n")
0063 #define __BTF_ID_FLAGS(prefix, name, flags, ...) \
0064     ____BTF_ID_FLAGS(prefix, name, flags)
0065 #define BTF_ID_FLAGS(prefix, name, ...) \
0066     __BTF_ID_FLAGS(prefix, name, ##__VA_ARGS__, 0)
0067 
0068 /*
0069  * The BTF_ID_LIST macro defines pure (unsorted) list
0070  * of BTF IDs, with following layout:
0071  *
0072  * BTF_ID_LIST(list1)
0073  * BTF_ID(type1, name1)
0074  * BTF_ID(type2, name2)
0075  *
0076  * list1:
0077  * __BTF_ID__type1__name1__1:
0078  * .zero 4
0079  * __BTF_ID__type2__name2__2:
0080  * .zero 4
0081  *
0082  */
0083 #define __BTF_ID_LIST(name, scope)          \
0084 asm(                            \
0085 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"  \
0086 "." #scope " " #name ";                        \n"  \
0087 #name ":;                                      \n"  \
0088 ".popsection;                                  \n");
0089 
0090 #define BTF_ID_LIST(name)               \
0091 __BTF_ID_LIST(name, local)              \
0092 extern u32 name[];
0093 
0094 #define BTF_ID_LIST_GLOBAL(name, n)         \
0095 __BTF_ID_LIST(name, globl)
0096 
0097 /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
0098  * a single entry.
0099  */
0100 #define BTF_ID_LIST_SINGLE(name, prefix, typename)  \
0101     BTF_ID_LIST(name) \
0102     BTF_ID(prefix, typename)
0103 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
0104     BTF_ID_LIST_GLOBAL(name, 1)           \
0105     BTF_ID(prefix, typename)
0106 
0107 /*
0108  * The BTF_ID_UNUSED macro defines 4 zero bytes.
0109  * It's used when we want to define 'unused' entry
0110  * in BTF_ID_LIST, like:
0111  *
0112  *   BTF_ID_LIST(bpf_skb_output_btf_ids)
0113  *   BTF_ID(struct, sk_buff)
0114  *   BTF_ID_UNUSED
0115  *   BTF_ID(struct, task_struct)
0116  */
0117 
0118 #define BTF_ID_UNUSED                   \
0119 asm(                            \
0120 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"  \
0121 ".zero 4                                       \n"  \
0122 ".popsection;                                  \n");
0123 
0124 /*
0125  * The BTF_SET_START/END macros pair defines sorted list of
0126  * BTF IDs plus its members count, with following layout:
0127  *
0128  * BTF_SET_START(list)
0129  * BTF_ID(type1, name1)
0130  * BTF_ID(type2, name2)
0131  * BTF_SET_END(list)
0132  *
0133  * __BTF_ID__set__list:
0134  * .zero 4
0135  * list:
0136  * __BTF_ID__type1__name1__3:
0137  * .zero 4
0138  * __BTF_ID__type2__name2__4:
0139  * .zero 4
0140  *
0141  */
0142 #define __BTF_SET_START(name, scope)            \
0143 asm(                            \
0144 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"  \
0145 "." #scope " __BTF_ID__set__" #name ";         \n"  \
0146 "__BTF_ID__set__" #name ":;                    \n"  \
0147 ".zero 4                                       \n"  \
0148 ".popsection;                                  \n");
0149 
0150 #define BTF_SET_START(name)             \
0151 __BTF_ID_LIST(name, local)              \
0152 __BTF_SET_START(name, local)
0153 
0154 #define BTF_SET_START_GLOBAL(name)          \
0155 __BTF_ID_LIST(name, globl)              \
0156 __BTF_SET_START(name, globl)
0157 
0158 #define BTF_SET_END(name)               \
0159 asm(                            \
0160 ".pushsection " BTF_IDS_SECTION ",\"a\";      \n"   \
0161 ".size __BTF_ID__set__" #name ", .-" #name "  \n"   \
0162 ".popsection;                                 \n"); \
0163 extern struct btf_id_set name;
0164 
0165 /*
0166  * The BTF_SET8_START/END macros pair defines sorted list of
0167  * BTF IDs and their flags plus its members count, with the
0168  * following layout:
0169  *
0170  * BTF_SET8_START(list)
0171  * BTF_ID_FLAGS(type1, name1, flags)
0172  * BTF_ID_FLAGS(type2, name2, flags)
0173  * BTF_SET8_END(list)
0174  *
0175  * __BTF_ID__set8__list:
0176  * .zero 8
0177  * list:
0178  * __BTF_ID__type1__name1__3:
0179  * .zero 4
0180  * .word (1 << 0) | (1 << 2)
0181  * __BTF_ID__type2__name2__5:
0182  * .zero 4
0183  * .word (1 << 3) | (1 << 1) | (1 << 2)
0184  *
0185  */
0186 #define __BTF_SET8_START(name, scope)           \
0187 asm(                            \
0188 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"  \
0189 "." #scope " __BTF_ID__set8__" #name ";        \n"  \
0190 "__BTF_ID__set8__" #name ":;                   \n"  \
0191 ".zero 8                                       \n"  \
0192 ".popsection;                                  \n");
0193 
0194 #define BTF_SET8_START(name)                \
0195 __BTF_ID_LIST(name, local)              \
0196 __BTF_SET8_START(name, local)
0197 
0198 #define BTF_SET8_END(name)              \
0199 asm(                            \
0200 ".pushsection " BTF_IDS_SECTION ",\"a\";      \n"   \
0201 ".size __BTF_ID__set8__" #name ", .-" #name "  \n"  \
0202 ".popsection;                                 \n"); \
0203 extern struct btf_id_set8 name;
0204 
0205 #else
0206 
0207 #define BTF_ID_LIST(name) static u32 __maybe_unused name[5];
0208 #define BTF_ID(prefix, name)
0209 #define BTF_ID_FLAGS(prefix, name, ...)
0210 #define BTF_ID_UNUSED
0211 #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n];
0212 #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1];
0213 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1];
0214 #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 };
0215 #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 };
0216 #define BTF_SET_END(name)
0217 #define BTF_SET8_START(name) static struct btf_id_set8 __maybe_unused name = { 0 };
0218 #define BTF_SET8_END(name)
0219 
0220 #endif /* CONFIG_DEBUG_INFO_BTF */
0221 
0222 #ifdef CONFIG_NET
0223 /* Define a list of socket types which can be the argument for
0224  * skc_to_*_sock() helpers. All these sockets should have
0225  * sock_common as the first argument in its memory layout.
0226  */
0227 #define BTF_SOCK_TYPE_xxx \
0228     BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)            \
0229     BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)    \
0230     BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)    \
0231     BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)    \
0232     BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)          \
0233     BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)             \
0234     BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)       \
0235     BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)          \
0236     BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)      \
0237     BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)      \
0238     BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)            \
0239     BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)          \
0240     BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)            \
0241     BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock)            \
0242     BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock)          \
0243     BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket)
0244 
0245 enum {
0246 #define BTF_SOCK_TYPE(name, str) name,
0247 BTF_SOCK_TYPE_xxx
0248 #undef BTF_SOCK_TYPE
0249 MAX_BTF_SOCK_TYPE,
0250 };
0251 
0252 extern u32 btf_sock_ids[];
0253 #endif
0254 
0255 #define BTF_TRACING_TYPE_xxx    \
0256     BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct)    \
0257     BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file)       \
0258     BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct)
0259 
0260 enum {
0261 #define BTF_TRACING_TYPE(name, type) name,
0262 BTF_TRACING_TYPE_xxx
0263 #undef BTF_TRACING_TYPE
0264 MAX_BTF_TRACING_TYPE,
0265 };
0266 
0267 extern u32 btf_tracing_ids[];
0268 
0269 #endif