btf_ids.h 7.6 KB

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