btf_ids.h 6.0 KB

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