History

bpf: Support for new btf kind BTF_KIND_TAG

LLVM14 added support for a new C attribute ([1]) __attribute__((btf_tag("arbitrary_str"))) This attribute will be emitted to dwarf ([2]) and pahole will convert it to BTF. Or for bpf target, this attribute will be emitted to BTF directly ([3], [4]). The attribute is intended to provide additional information for - struct/union type or struct/union member - static/global variables - static/global function or function parameter. For linux kernel, the btf_tag can be applied in various places to specify user pointer, function pre- or post- condition, function allow/deny in certain context, etc. Such information will be encoded in vmlinux BTF and can be used by verifier. The btf_tag can also be applied to bpf programs to help global verifiable functions, e.g., specifying preconditions, etc. This patch added basic parsing and checking support in kernel for new BTF_KIND_TAG kind. [1] https://reviews.llvm.org/D106614 [2] https://reviews.llvm.org/D106621 [3] https://reviews.llvm.org/D106622 [4] https://reviews.llvm.org/D109560

Yonghong Song committed 5 years ago

Commit b5ea8341 parent 41ced4c3 files · +154 −2Browse files

Showing the changes to include/uapi (1 of 3 files). Show all

Unified · Split

include/uapi/linux/btf.h+13−1
@@ -43,7 +43,7 @@ struct btf_type { · 42 unmodified lines
4343 * "size" tells the size of the type it is describing.
4444 *
4545 * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
46− * FUNC, FUNC_PROTO and VAR.
46+ * FUNC, FUNC_PROTO, VAR and TAG.
4747 * "type" is a type_id referring to another type.
4848 */
4949 union {
@@ -74,6 +74,7 @@ enum { · 24 unmodified lines
7474 BTF_KIND_VAR = 14, /* Variable */
7575 BTF_KIND_DATASEC = 15, /* Section */
7676 BTF_KIND_FLOAT = 16, /* Floating point */
77+ BTF_KIND_TAG = 17, /* Tag */
7778
7879 NR_BTF_KINDS,
7980 BTF_KIND_MAX = NR_BTF_KINDS - 1,
@@ -173,4 +174,15 @@ struct btf_var_secinfo { · 93 unmodified lines
173174 __u32 size;
174175 };
175176
177+/* BTF_KIND_TAG is followed by a single "struct btf_tag" to describe
178+ * additional information related to the tag applied location.
179+ * If component_idx == -1, the tag is applied to a struct, union,
180+ * variable or function. Otherwise, it is applied to a struct/union
181+ * member or a func argument, and component_idx indicates which member
182+ * or argument (0 ... vlen-1).
183+ */
184+struct btf_tag {
185+ __s32 component_idx;
186+};
187+
176188 #endif /* _UAPI__LINUX_BTF_H__ */