btf_ids.h 5.8 KB

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