xref: /linux-6.15/include/linux/btf.h (revision ea145d53)
1eb3f595dSMartin KaFai Lau /* SPDX-License-Identifier: GPL-2.0 */
2eb3f595dSMartin KaFai Lau /* Copyright (c) 2018 Facebook */
3eb3f595dSMartin KaFai Lau 
4eb3f595dSMartin KaFai Lau #ifndef _LINUX_BTF_H
5eb3f595dSMartin KaFai Lau #define _LINUX_BTF_H 1
6eb3f595dSMartin KaFai Lau 
7eb3f595dSMartin KaFai Lau #include <linux/types.h>
814f267d9SKumar Kartikeya Dwivedi #include <linux/bpfptr.h>
98ffa5cc1SKumar Kartikeya Dwivedi #include <linux/bsearch.h>
108ffa5cc1SKumar Kartikeya Dwivedi #include <linux/btf_ids.h>
1138207291SMartin KaFai Lau #include <uapi/linux/btf.h>
12c4d0bfb4SAlan Maguire #include <uapi/linux/bpf.h>
13eb3f595dSMartin KaFai Lau 
1485d33df3SMartin KaFai Lau #define BTF_TYPE_EMIT(type) ((void)(type *)0)
1597a19cafSYonghong Song #define BTF_TYPE_EMIT_ENUM(enum_val) ((void)enum_val)
1685d33df3SMartin KaFai Lau 
17a4703e31SKumar Kartikeya Dwivedi /* These need to be macros, as the expressions are used in assembler input */
18a4703e31SKumar Kartikeya Dwivedi #define KF_ACQUIRE	(1 << 0) /* kfunc is an acquire function */
19a4703e31SKumar Kartikeya Dwivedi #define KF_RELEASE	(1 << 1) /* kfunc is a release function */
20a4703e31SKumar Kartikeya Dwivedi #define KF_RET_NULL	(1 << 2) /* kfunc returns a pointer that may be NULL */
213f00c523SDavid Vernet /* Trusted arguments are those which are guaranteed to be valid when passed to
223f00c523SDavid Vernet  * the kfunc. It is used to enforce that pointers obtained from either acquire
233f00c523SDavid Vernet  * kfuncs, or from the main kernel on a tracepoint or struct_ops callback
243f00c523SDavid Vernet  * invocation, remain unmodified when being passed to helpers taking trusted
253f00c523SDavid Vernet  * args.
2656e948ffSKumar Kartikeya Dwivedi  *
273f00c523SDavid Vernet  * Consider, for example, the following new task tracepoint:
2856e948ffSKumar Kartikeya Dwivedi  *
293f00c523SDavid Vernet  *	SEC("tp_btf/task_newtask")
303f00c523SDavid Vernet  *	int BPF_PROG(new_task_tp, struct task_struct *task, u64 clone_flags)
313f00c523SDavid Vernet  *	{
323f00c523SDavid Vernet  *		...
333f00c523SDavid Vernet  *	}
3456e948ffSKumar Kartikeya Dwivedi  *
353f00c523SDavid Vernet  * And the following kfunc:
3656e948ffSKumar Kartikeya Dwivedi  *
373f00c523SDavid Vernet  *	BTF_ID_FLAGS(func, bpf_task_acquire, KF_ACQUIRE | KF_TRUSTED_ARGS)
3856e948ffSKumar Kartikeya Dwivedi  *
393f00c523SDavid Vernet  * All invocations to the kfunc must pass the unmodified, unwalked task:
4056e948ffSKumar Kartikeya Dwivedi  *
413f00c523SDavid Vernet  *	bpf_task_acquire(task);		    // Allowed
423f00c523SDavid Vernet  *	bpf_task_acquire(task->last_wakee); // Rejected, walked task
433f00c523SDavid Vernet  *
443f00c523SDavid Vernet  * Programs may also pass referenced tasks directly to the kfunc:
453f00c523SDavid Vernet  *
463f00c523SDavid Vernet  *	struct task_struct *acquired;
473f00c523SDavid Vernet  *
483f00c523SDavid Vernet  *	acquired = bpf_task_acquire(task);	// Allowed, same as above
493f00c523SDavid Vernet  *	bpf_task_acquire(acquired);		// Allowed
503f00c523SDavid Vernet  *	bpf_task_acquire(task);			// Allowed
513f00c523SDavid Vernet  *	bpf_task_acquire(acquired->last_wakee); // Rejected, walked task
523f00c523SDavid Vernet  *
533f00c523SDavid Vernet  * Programs may _not_, however, pass a task from an arbitrary fentry/fexit, or
543f00c523SDavid Vernet  * kprobe/kretprobe to the kfunc, as BPF cannot guarantee that all of these
553f00c523SDavid Vernet  * pointers are guaranteed to be safe. For example, the following BPF program
563f00c523SDavid Vernet  * would be rejected:
573f00c523SDavid Vernet  *
583f00c523SDavid Vernet  * SEC("kretprobe/free_task")
593f00c523SDavid Vernet  * int BPF_PROG(free_task_probe, struct task_struct *tsk)
603f00c523SDavid Vernet  * {
613f00c523SDavid Vernet  *	struct task_struct *acquired;
623f00c523SDavid Vernet  *
633f00c523SDavid Vernet  *	acquired = bpf_task_acquire(acquired); // Rejected, not a trusted pointer
643f00c523SDavid Vernet  *	bpf_task_release(acquired);
653f00c523SDavid Vernet  *
663f00c523SDavid Vernet  *	return 0;
673f00c523SDavid Vernet  * }
6856e948ffSKumar Kartikeya Dwivedi  */
6956e948ffSKumar Kartikeya Dwivedi #define KF_TRUSTED_ARGS (1 << 4) /* kfunc only takes trusted pointer arguments */
70fa96b242SBenjamin Tissoires #define KF_SLEEPABLE    (1 << 5) /* kfunc may sleep */
714dd48c6fSArtem Savkov #define KF_DESTRUCTIVE  (1 << 6) /* kfunc performs destructive actions */
7220c09d92SAlexei Starovoitov #define KF_RCU          (1 << 7) /* kfunc takes either rcu or trusted pointer arguments */
73215bf496SAndrii Nakryiko /* only one of KF_ITER_{NEW,NEXT,DESTROY} could be specified per kfunc */
74215bf496SAndrii Nakryiko #define KF_ITER_NEW     (1 << 8) /* kfunc implements BPF iter constructor */
75215bf496SAndrii Nakryiko #define KF_ITER_NEXT    (1 << 9) /* kfunc implements BPF iter next method */
76215bf496SAndrii Nakryiko #define KF_ITER_DESTROY (1 << 10) /* kfunc implements BPF iter destructor */
77dfab99dfSChuyi Zhou #define KF_RCU_PROTECTED (1 << 11) /* kfunc should be protected by rcu cs when they are invoked */
78da7d71bcSEduard Zingerman #define KF_FASTCALL     (1 << 12) /* kfunc supports bpf_fastcall protocol */
79*ea145d53SIhor Solodrai #define KF_ARENA_RET    (1 << 13) /* kfunc returns an arena pointer */
80*ea145d53SIhor Solodrai #define KF_ARENA_ARG1   (1 << 14) /* kfunc takes an arena pointer as its first argument */
81*ea145d53SIhor Solodrai #define KF_ARENA_ARG2   (1 << 15) /* kfunc takes an arena pointer as its second argument */
82dee872e1SKumar Kartikeya Dwivedi 
83b8d31762SRoberto Sassu /*
8457e7c169SDavid Vernet  * Tag marking a kernel function as a kfunc. This is meant to minimize the
8557e7c169SDavid Vernet  * amount of copy-paste that kfunc authors have to include for correctness so
8657e7c169SDavid Vernet  * as to avoid issues such as the compiler inlining or eliding either a static
8757e7c169SDavid Vernet  * kfunc, or a global kfunc in an LTO build.
8857e7c169SDavid Vernet  */
897bdcedd5STony Ambardar #define __bpf_kfunc __used __retain noinline
9057e7c169SDavid Vernet 
91391145baSDave Marchevsky #define __bpf_kfunc_start_defs()					       \
92391145baSDave Marchevsky 	__diag_push();							       \
93391145baSDave Marchevsky 	__diag_ignore_all("-Wmissing-declarations",			       \
94391145baSDave Marchevsky 			  "Global kfuncs as their definitions will be in BTF");\
95391145baSDave Marchevsky 	__diag_ignore_all("-Wmissing-prototypes",			       \
96391145baSDave Marchevsky 			  "Global kfuncs as their definitions will be in BTF")
97391145baSDave Marchevsky 
98391145baSDave Marchevsky #define __bpf_kfunc_end_defs() __diag_pop()
9915fb6f2bSDave Marchevsky #define __bpf_hook_start() __bpf_kfunc_start_defs()
10015fb6f2bSDave Marchevsky #define __bpf_hook_end() __bpf_kfunc_end_defs()
101391145baSDave Marchevsky 
10257e7c169SDavid Vernet /*
103b8d31762SRoberto Sassu  * Return the name of the passed struct, if exists, or halt the build if for
104b8d31762SRoberto Sassu  * example the structure gets renamed. In this way, developers have to revisit
105b8d31762SRoberto Sassu  * the code using that structure name, and update it accordingly.
106b8d31762SRoberto Sassu  */
107b8d31762SRoberto Sassu #define stringify_struct(x)			\
108b8d31762SRoberto Sassu 	({ BUILD_BUG_ON(sizeof(struct x) < 0);	\
109b8d31762SRoberto Sassu 	   __stringify(x); })
110b8d31762SRoberto Sassu 
111eb3f595dSMartin KaFai Lau struct btf;
112ffa0c1cfSYonghong Song struct btf_member;
113eb3f595dSMartin KaFai Lau struct btf_type;
114f56a653cSMartin KaFai Lau union bpf_attr;
11531d0bc81SAlan Maguire struct btf_show;
116dee872e1SKumar Kartikeya Dwivedi struct btf_id_set;
117e924e80eSAditi Ghag struct bpf_prog;
118e924e80eSAditi Ghag 
119e924e80eSAditi Ghag typedef int (*btf_kfunc_filter_t)(const struct bpf_prog *prog, u32 kfunc_id);
120dee872e1SKumar Kartikeya Dwivedi 
121dee872e1SKumar Kartikeya Dwivedi struct btf_kfunc_id_set {
122dee872e1SKumar Kartikeya Dwivedi 	struct module *owner;
123a4703e31SKumar Kartikeya Dwivedi 	struct btf_id_set8 *set;
124e924e80eSAditi Ghag 	btf_kfunc_filter_t filter;
125dee872e1SKumar Kartikeya Dwivedi };
126eb3f595dSMartin KaFai Lau 
1275ce937d6SKumar Kartikeya Dwivedi struct btf_id_dtor_kfunc {
1285ce937d6SKumar Kartikeya Dwivedi 	u32 btf_id;
1295ce937d6SKumar Kartikeya Dwivedi 	u32 kfunc_btf_id;
1305ce937d6SKumar Kartikeya Dwivedi };
1315ce937d6SKumar Kartikeya Dwivedi 
1328ffa5cc1SKumar Kartikeya Dwivedi struct btf_struct_meta {
1338ffa5cc1SKumar Kartikeya Dwivedi 	u32 btf_id;
1348ffa5cc1SKumar Kartikeya Dwivedi 	struct btf_record *record;
1358ffa5cc1SKumar Kartikeya Dwivedi };
1368ffa5cc1SKumar Kartikeya Dwivedi 
1378ffa5cc1SKumar Kartikeya Dwivedi struct btf_struct_metas {
1388ffa5cc1SKumar Kartikeya Dwivedi 	u32 cnt;
1398ffa5cc1SKumar Kartikeya Dwivedi 	struct btf_struct_meta types[];
1408ffa5cc1SKumar Kartikeya Dwivedi };
1418ffa5cc1SKumar Kartikeya Dwivedi 
14260197cfbSMartin KaFai Lau extern const struct file_operations btf_fops;
14360197cfbSMartin KaFai Lau 
1443b1f89e7SKui-Feng Lee const char *btf_get_name(const struct btf *btf);
14522dc4a0fSAndrii Nakryiko void btf_get(struct btf *btf);
146f56a653cSMartin KaFai Lau void btf_put(struct btf *btf);
1478646db23SAlan Maguire const struct btf_header *btf_header(const struct btf *btf);
14847a71c1fSAndrii Nakryiko int btf_new_fd(const union bpf_attr *attr, bpfptr_t uattr, u32 uattr_sz);
149f56a653cSMartin KaFai Lau struct btf *btf_get_by_fd(int fd);
15060197cfbSMartin KaFai Lau int btf_get_info_by_fd(const struct btf *btf,
15160197cfbSMartin KaFai Lau 		       const union bpf_attr *attr,
15260197cfbSMartin KaFai Lau 		       union bpf_attr __user *uattr);
153eb3f595dSMartin KaFai Lau /* Figure out the size of a type_id.  If type_id is a modifier
154eb3f595dSMartin KaFai Lau  * (e.g. const), it will be resolved to find out the type with size.
155eb3f595dSMartin KaFai Lau  *
156eb3f595dSMartin KaFai Lau  * For example:
157eb3f595dSMartin KaFai Lau  * In describing "const void *",  type_id is "const" and "const"
158eb3f595dSMartin KaFai Lau  * refers to "void *".  The return type will be "void *".
159eb3f595dSMartin KaFai Lau  *
160eb3f595dSMartin KaFai Lau  * If type_id is a simple "int", then return type will be "int".
161eb3f595dSMartin KaFai Lau  *
162eb3f595dSMartin KaFai Lau  * @btf: struct btf object
163eb3f595dSMartin KaFai Lau  * @type_id: Find out the size of type_id. The type_id of the return
164eb3f595dSMartin KaFai Lau  *           type is set to *type_id.
165eb3f595dSMartin KaFai Lau  * @ret_size: It can be NULL.  If not NULL, the size of the return
166eb3f595dSMartin KaFai Lau  *            type is set to *ret_size.
167eb3f595dSMartin KaFai Lau  * Return: The btf_type (resolved to another type with size info if needed).
168eb3f595dSMartin KaFai Lau  *         NULL is returned if type_id itself does not have size info
169eb3f595dSMartin KaFai Lau  *         (e.g. void) or it cannot be resolved to another type that
170eb3f595dSMartin KaFai Lau  *         has size info.
171eb3f595dSMartin KaFai Lau  *         *type_id and *ret_size will not be changed in the
172eb3f595dSMartin KaFai Lau  *         NULL return case.
173eb3f595dSMartin KaFai Lau  */
174eb3f595dSMartin KaFai Lau const struct btf_type *btf_type_id_size(const struct btf *btf,
175eb3f595dSMartin KaFai Lau 					u32 *type_id,
176eb3f595dSMartin KaFai Lau 					u32 *ret_size);
17731d0bc81SAlan Maguire 
17831d0bc81SAlan Maguire /*
17931d0bc81SAlan Maguire  * Options to control show behaviour.
18031d0bc81SAlan Maguire  *	- BTF_SHOW_COMPACT: no formatting around type information
18131d0bc81SAlan Maguire  *	- BTF_SHOW_NONAME: no struct/union member names/types
18231d0bc81SAlan Maguire  *	- BTF_SHOW_PTR_RAW: show raw (unobfuscated) pointer values;
18331d0bc81SAlan Maguire  *	  equivalent to %px.
18431d0bc81SAlan Maguire  *	- BTF_SHOW_ZERO: show zero-valued struct/union members; they
18531d0bc81SAlan Maguire  *	  are not displayed by default
18631d0bc81SAlan Maguire  *	- BTF_SHOW_UNSAFE: skip use of bpf_probe_read() to safely read
18731d0bc81SAlan Maguire  *	  data before displaying it.
18831d0bc81SAlan Maguire  */
189c4d0bfb4SAlan Maguire #define BTF_SHOW_COMPACT	BTF_F_COMPACT
190c4d0bfb4SAlan Maguire #define BTF_SHOW_NONAME		BTF_F_NONAME
191c4d0bfb4SAlan Maguire #define BTF_SHOW_PTR_RAW	BTF_F_PTR_RAW
192c4d0bfb4SAlan Maguire #define BTF_SHOW_ZERO		BTF_F_ZERO
19331d0bc81SAlan Maguire #define BTF_SHOW_UNSAFE		(1ULL << 4)
19431d0bc81SAlan Maguire 
195b00b8daeSMartin KaFai Lau void btf_type_seq_show(const struct btf *btf, u32 type_id, void *obj,
196b00b8daeSMartin KaFai Lau 		       struct seq_file *m);
197eb411377SAlan Maguire int btf_type_seq_show_flags(const struct btf *btf, u32 type_id, void *obj,
198eb411377SAlan Maguire 			    struct seq_file *m, u64 flags);
19931d0bc81SAlan Maguire 
20031d0bc81SAlan Maguire /*
20131d0bc81SAlan Maguire  * Copy len bytes of string representation of obj of BTF type_id into buf.
20231d0bc81SAlan Maguire  *
20331d0bc81SAlan Maguire  * @btf: struct btf object
20431d0bc81SAlan Maguire  * @type_id: type id of type obj points to
20531d0bc81SAlan Maguire  * @obj: pointer to typed data
20631d0bc81SAlan Maguire  * @buf: buffer to write to
20731d0bc81SAlan Maguire  * @len: maximum length to write to buf
20831d0bc81SAlan Maguire  * @flags: show options (see above)
20931d0bc81SAlan Maguire  *
21031d0bc81SAlan Maguire  * Return: length that would have been/was copied as per snprintf, or
21131d0bc81SAlan Maguire  *	   negative error.
21231d0bc81SAlan Maguire  */
21331d0bc81SAlan Maguire int btf_type_snprintf_show(const struct btf *btf, u32 type_id, void *obj,
21431d0bc81SAlan Maguire 			   char *buf, int len, u64 flags);
21531d0bc81SAlan Maguire 
21678958fcaSMartin KaFai Lau int btf_get_fd_by_id(u32 id);
21722dc4a0fSAndrii Nakryiko u32 btf_obj_id(const struct btf *btf);
218290248a5SAndrii Nakryiko bool btf_is_kernel(const struct btf *btf);
219541c3badSAndrii Nakryiko bool btf_is_module(const struct btf *btf);
2208646db23SAlan Maguire bool btf_is_vmlinux(const struct btf *btf);
221541c3badSAndrii Nakryiko struct module *btf_try_get_module(const struct btf *btf);
222541c3badSAndrii Nakryiko u32 btf_nr_types(const struct btf *btf);
2238646db23SAlan Maguire struct btf *btf_base_btf(const struct btf *btf);
224ffa0c1cfSYonghong Song bool btf_member_is_reg_int(const struct btf *btf, const struct btf_type *s,
225ffa0c1cfSYonghong Song 			   const struct btf_member *m,
226ffa0c1cfSYonghong Song 			   u32 expected_offset, u32 expected_size);
227db559117SKumar Kartikeya Dwivedi struct btf_record *btf_parse_fields(const struct btf *btf, const struct btf_type *t,
228db559117SKumar Kartikeya Dwivedi 				    u32 field_mask, u32 value_size);
229865ce09aSKumar Kartikeya Dwivedi int btf_check_and_fixup_fields(const struct btf *btf, struct btf_record *rec);
2302824ecb7SDaniel Borkmann bool btf_type_is_void(const struct btf_type *t);
23127ae7997SMartin KaFai Lau s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind);
232b1d1e904SMasami Hiramatsu (Google) s32 bpf_find_btf_id(const char *name, u32 kind, struct btf **btf_p);
23327ae7997SMartin KaFai Lau const struct btf_type *btf_type_skip_modifiers(const struct btf *btf,
23427ae7997SMartin KaFai Lau 					       u32 id, u32 *res_id);
23527ae7997SMartin KaFai Lau const struct btf_type *btf_type_resolve_ptr(const struct btf *btf,
23627ae7997SMartin KaFai Lau 					    u32 id, u32 *res_id);
23727ae7997SMartin KaFai Lau const struct btf_type *btf_type_resolve_func_ptr(const struct btf *btf,
23827ae7997SMartin KaFai Lau 						 u32 id, u32 *res_id);
23985d33df3SMartin KaFai Lau const struct btf_type *
24085d33df3SMartin KaFai Lau btf_resolve_size(const struct btf *btf, const struct btf_type *type,
2416298399bSJiri Olsa 		 u32 *type_size);
242e6ac2450SMartin KaFai Lau const char *btf_type_str(const struct btf_type *t);
24327ae7997SMartin KaFai Lau 
24427ae7997SMartin KaFai Lau #define for_each_member(i, struct_type, member)			\
24527ae7997SMartin KaFai Lau 	for (i = 0, member = btf_type_member(struct_type);	\
24627ae7997SMartin KaFai Lau 	     i < btf_type_vlen(struct_type);			\
24727ae7997SMartin KaFai Lau 	     i++, member++)
248f6161a8fSYonghong Song 
249eaa6bcb7SHao Luo #define for_each_vsi(i, datasec_type, member)			\
250eaa6bcb7SHao Luo 	for (i = 0, member = btf_type_var_secinfo(datasec_type);	\
251eaa6bcb7SHao Luo 	     i < btf_type_vlen(datasec_type);			\
252eaa6bcb7SHao Luo 	     i++, member++)
253eaa6bcb7SHao Luo 
btf_type_is_ptr(const struct btf_type * t)25438207291SMartin KaFai Lau static inline bool btf_type_is_ptr(const struct btf_type *t)
25538207291SMartin KaFai Lau {
25638207291SMartin KaFai Lau 	return BTF_INFO_KIND(t->info) == BTF_KIND_PTR;
25738207291SMartin KaFai Lau }
25838207291SMartin KaFai Lau 
btf_type_is_int(const struct btf_type * t)25938207291SMartin KaFai Lau static inline bool btf_type_is_int(const struct btf_type *t)
26038207291SMartin KaFai Lau {
26138207291SMartin KaFai Lau 	return BTF_INFO_KIND(t->info) == BTF_KIND_INT;
26238207291SMartin KaFai Lau }
26338207291SMartin KaFai Lau 
btf_type_is_small_int(const struct btf_type * t)264a9b59159SJohn Fastabend static inline bool btf_type_is_small_int(const struct btf_type *t)
265a9b59159SJohn Fastabend {
266a9b59159SJohn Fastabend 	return btf_type_is_int(t) && t->size <= sizeof(u64);
267a9b59159SJohn Fastabend }
268a9b59159SJohn Fastabend 
btf_int_encoding(const struct btf_type * t)26949f67f39SIlya Leoshkevich static inline u8 btf_int_encoding(const struct btf_type *t)
27049f67f39SIlya Leoshkevich {
27149f67f39SIlya Leoshkevich 	return BTF_INT_ENCODING(*(u32 *)(t + 1));
27249f67f39SIlya Leoshkevich }
27349f67f39SIlya Leoshkevich 
btf_type_is_signed_int(const struct btf_type * t)27449f67f39SIlya Leoshkevich static inline bool btf_type_is_signed_int(const struct btf_type *t)
27549f67f39SIlya Leoshkevich {
27649f67f39SIlya Leoshkevich 	return btf_type_is_int(t) && (btf_int_encoding(t) & BTF_INT_SIGNED);
27749f67f39SIlya Leoshkevich }
27849f67f39SIlya Leoshkevich 
btf_type_is_enum(const struct btf_type * t)27938207291SMartin KaFai Lau static inline bool btf_type_is_enum(const struct btf_type *t)
28038207291SMartin KaFai Lau {
28138207291SMartin KaFai Lau 	return BTF_INFO_KIND(t->info) == BTF_KIND_ENUM;
28238207291SMartin KaFai Lau }
28338207291SMartin KaFai Lau 
btf_is_any_enum(const struct btf_type * t)2846089fb32SYonghong Song static inline bool btf_is_any_enum(const struct btf_type *t)
2856089fb32SYonghong Song {
2866089fb32SYonghong Song 	return BTF_INFO_KIND(t->info) == BTF_KIND_ENUM ||
2876089fb32SYonghong Song 	       BTF_INFO_KIND(t->info) == BTF_KIND_ENUM64;
2886089fb32SYonghong Song }
2896089fb32SYonghong Song 
btf_kind_core_compat(const struct btf_type * t1,const struct btf_type * t2)2906089fb32SYonghong Song static inline bool btf_kind_core_compat(const struct btf_type *t1,
2916089fb32SYonghong Song 					const struct btf_type *t2)
2926089fb32SYonghong Song {
2936089fb32SYonghong Song 	return BTF_INFO_KIND(t1->info) == BTF_INFO_KIND(t2->info) ||
2946089fb32SYonghong Song 	       (btf_is_any_enum(t1) && btf_is_any_enum(t2));
2956089fb32SYonghong Song }
2966089fb32SYonghong Song 
str_is_empty(const char * s)29729db4beaSAlexei Starovoitov static inline bool str_is_empty(const char *s)
29829db4beaSAlexei Starovoitov {
29929db4beaSAlexei Starovoitov 	return !s || !s[0];
30029db4beaSAlexei Starovoitov }
30129db4beaSAlexei Starovoitov 
btf_kind(const struct btf_type * t)30229db4beaSAlexei Starovoitov static inline u16 btf_kind(const struct btf_type *t)
30329db4beaSAlexei Starovoitov {
30429db4beaSAlexei Starovoitov 	return BTF_INFO_KIND(t->info);
30529db4beaSAlexei Starovoitov }
30629db4beaSAlexei Starovoitov 
btf_is_enum(const struct btf_type * t)30729db4beaSAlexei Starovoitov static inline bool btf_is_enum(const struct btf_type *t)
30829db4beaSAlexei Starovoitov {
30929db4beaSAlexei Starovoitov 	return btf_kind(t) == BTF_KIND_ENUM;
31029db4beaSAlexei Starovoitov }
31129db4beaSAlexei Starovoitov 
btf_is_enum64(const struct btf_type * t)3126089fb32SYonghong Song static inline bool btf_is_enum64(const struct btf_type *t)
3136089fb32SYonghong Song {
3146089fb32SYonghong Song 	return btf_kind(t) == BTF_KIND_ENUM64;
3156089fb32SYonghong Song }
3166089fb32SYonghong Song 
btf_enum64_value(const struct btf_enum64 * e)3176089fb32SYonghong Song static inline u64 btf_enum64_value(const struct btf_enum64 *e)
3186089fb32SYonghong Song {
3196089fb32SYonghong Song 	return ((u64)e->val_hi32 << 32) | e->val_lo32;
3206089fb32SYonghong Song }
3216089fb32SYonghong Song 
btf_is_composite(const struct btf_type * t)32229db4beaSAlexei Starovoitov static inline bool btf_is_composite(const struct btf_type *t)
32329db4beaSAlexei Starovoitov {
32429db4beaSAlexei Starovoitov 	u16 kind = btf_kind(t);
32529db4beaSAlexei Starovoitov 
32629db4beaSAlexei Starovoitov 	return kind == BTF_KIND_STRUCT || kind == BTF_KIND_UNION;
32729db4beaSAlexei Starovoitov }
32829db4beaSAlexei Starovoitov 
btf_is_array(const struct btf_type * t)32929db4beaSAlexei Starovoitov static inline bool btf_is_array(const struct btf_type *t)
33029db4beaSAlexei Starovoitov {
33129db4beaSAlexei Starovoitov 	return btf_kind(t) == BTF_KIND_ARRAY;
33229db4beaSAlexei Starovoitov }
33329db4beaSAlexei Starovoitov 
btf_is_int(const struct btf_type * t)33429db4beaSAlexei Starovoitov static inline bool btf_is_int(const struct btf_type *t)
33529db4beaSAlexei Starovoitov {
33629db4beaSAlexei Starovoitov 	return btf_kind(t) == BTF_KIND_INT;
33729db4beaSAlexei Starovoitov }
33829db4beaSAlexei Starovoitov 
btf_is_ptr(const struct btf_type * t)33929db4beaSAlexei Starovoitov static inline bool btf_is_ptr(const struct btf_type *t)
34029db4beaSAlexei Starovoitov {
34129db4beaSAlexei Starovoitov 	return btf_kind(t) == BTF_KIND_PTR;
34229db4beaSAlexei Starovoitov }
34329db4beaSAlexei Starovoitov 
btf_int_offset(const struct btf_type * t)34429db4beaSAlexei Starovoitov static inline u8 btf_int_offset(const struct btf_type *t)
34529db4beaSAlexei Starovoitov {
34629db4beaSAlexei Starovoitov 	return BTF_INT_OFFSET(*(u32 *)(t + 1));
34729db4beaSAlexei Starovoitov }
34829db4beaSAlexei Starovoitov 
btf_int_bits(const struct btf_type * t)3498646db23SAlan Maguire static inline __u8 btf_int_bits(const struct btf_type *t)
3508646db23SAlan Maguire {
3518646db23SAlan Maguire 	return BTF_INT_BITS(*(__u32 *)(t + 1));
3528646db23SAlan Maguire }
3538646db23SAlan Maguire 
btf_type_is_scalar(const struct btf_type * t)35434747c41SMartin KaFai Lau static inline bool btf_type_is_scalar(const struct btf_type *t)
35534747c41SMartin KaFai Lau {
35634747c41SMartin KaFai Lau 	return btf_type_is_int(t) || btf_type_is_enum(t);
35734747c41SMartin KaFai Lau }
35834747c41SMartin KaFai Lau 
btf_type_is_fwd(const struct btf_type * t)35996ea081eSMartin KaFai Lau static inline bool btf_type_is_fwd(const struct btf_type *t)
36096ea081eSMartin KaFai Lau {
36196ea081eSMartin KaFai Lau 	return BTF_INFO_KIND(t->info) == BTF_KIND_FWD;
36296ea081eSMartin KaFai Lau }
36396ea081eSMartin KaFai Lau 
btf_type_is_typedef(const struct btf_type * t)36438207291SMartin KaFai Lau static inline bool btf_type_is_typedef(const struct btf_type *t)
36538207291SMartin KaFai Lau {
36638207291SMartin KaFai Lau 	return BTF_INFO_KIND(t->info) == BTF_KIND_TYPEDEF;
36738207291SMartin KaFai Lau }
36838207291SMartin KaFai Lau 
btf_type_is_volatile(const struct btf_type * t)36923da464dSKumar Kartikeya Dwivedi static inline bool btf_type_is_volatile(const struct btf_type *t)
37023da464dSKumar Kartikeya Dwivedi {
37123da464dSKumar Kartikeya Dwivedi 	return BTF_INFO_KIND(t->info) == BTF_KIND_VOLATILE;
37223da464dSKumar Kartikeya Dwivedi }
37323da464dSKumar Kartikeya Dwivedi 
btf_type_is_func(const struct btf_type * t)37438207291SMartin KaFai Lau static inline bool btf_type_is_func(const struct btf_type *t)
37538207291SMartin KaFai Lau {
37638207291SMartin KaFai Lau 	return BTF_INFO_KIND(t->info) == BTF_KIND_FUNC;
37738207291SMartin KaFai Lau }
37838207291SMartin KaFai Lau 
btf_type_is_func_proto(const struct btf_type * t)37938207291SMartin KaFai Lau static inline bool btf_type_is_func_proto(const struct btf_type *t)
38038207291SMartin KaFai Lau {
38138207291SMartin KaFai Lau 	return BTF_INFO_KIND(t->info) == BTF_KIND_FUNC_PROTO;
38238207291SMartin KaFai Lau }
38338207291SMartin KaFai Lau 
btf_type_is_var(const struct btf_type * t)3844976b718SHao Luo static inline bool btf_type_is_var(const struct btf_type *t)
3854976b718SHao Luo {
3864976b718SHao Luo 	return BTF_INFO_KIND(t->info) == BTF_KIND_VAR;
3874976b718SHao Luo }
3884976b718SHao Luo 
btf_type_is_type_tag(const struct btf_type * t)389c6f1bfe8SYonghong Song static inline bool btf_type_is_type_tag(const struct btf_type *t)
390c6f1bfe8SYonghong Song {
391c6f1bfe8SYonghong Song 	return BTF_INFO_KIND(t->info) == BTF_KIND_TYPE_TAG;
392c6f1bfe8SYonghong Song }
393c6f1bfe8SYonghong Song 
3944976b718SHao Luo /* union is only a special case of struct:
3954976b718SHao Luo  * all its offsetof(member) == 0
3964976b718SHao Luo  */
btf_type_is_struct(const struct btf_type * t)3974976b718SHao Luo static inline bool btf_type_is_struct(const struct btf_type *t)
3984976b718SHao Luo {
3994976b718SHao Luo 	u8 kind = BTF_INFO_KIND(t->info);
4004976b718SHao Luo 
4014976b718SHao Luo 	return kind == BTF_KIND_STRUCT || kind == BTF_KIND_UNION;
4024976b718SHao Luo }
4034976b718SHao Luo 
__btf_type_is_struct(const struct btf_type * t)40400b85860SKumar Kartikeya Dwivedi static inline bool __btf_type_is_struct(const struct btf_type *t)
40500b85860SKumar Kartikeya Dwivedi {
40600b85860SKumar Kartikeya Dwivedi 	return BTF_INFO_KIND(t->info) == BTF_KIND_STRUCT;
40700b85860SKumar Kartikeya Dwivedi }
40800b85860SKumar Kartikeya Dwivedi 
btf_type_is_array(const struct btf_type * t)40900b85860SKumar Kartikeya Dwivedi static inline bool btf_type_is_array(const struct btf_type *t)
41000b85860SKumar Kartikeya Dwivedi {
41100b85860SKumar Kartikeya Dwivedi 	return BTF_INFO_KIND(t->info) == BTF_KIND_ARRAY;
41200b85860SKumar Kartikeya Dwivedi }
41300b85860SKumar Kartikeya Dwivedi 
btf_type_vlen(const struct btf_type * t)41427ae7997SMartin KaFai Lau static inline u16 btf_type_vlen(const struct btf_type *t)
41527ae7997SMartin KaFai Lau {
41627ae7997SMartin KaFai Lau 	return BTF_INFO_VLEN(t->info);
41727ae7997SMartin KaFai Lau }
41827ae7997SMartin KaFai Lau 
btf_vlen(const struct btf_type * t)41929db4beaSAlexei Starovoitov static inline u16 btf_vlen(const struct btf_type *t)
42029db4beaSAlexei Starovoitov {
42129db4beaSAlexei Starovoitov 	return btf_type_vlen(t);
42229db4beaSAlexei Starovoitov }
42329db4beaSAlexei Starovoitov 
btf_func_linkage(const struct btf_type * t)424be8704ffSAlexei Starovoitov static inline u16 btf_func_linkage(const struct btf_type *t)
425be8704ffSAlexei Starovoitov {
426be8704ffSAlexei Starovoitov 	return BTF_INFO_VLEN(t->info);
427be8704ffSAlexei Starovoitov }
428be8704ffSAlexei Starovoitov 
btf_type_kflag(const struct btf_type * t)42927ae7997SMartin KaFai Lau static inline bool btf_type_kflag(const struct btf_type *t)
43027ae7997SMartin KaFai Lau {
43127ae7997SMartin KaFai Lau 	return BTF_INFO_KFLAG(t->info);
43227ae7997SMartin KaFai Lau }
43327ae7997SMartin KaFai Lau 
__btf_member_bit_offset(const struct btf_type * struct_type,const struct btf_member * member)4348293eb99SAlexei Starovoitov static inline u32 __btf_member_bit_offset(const struct btf_type *struct_type,
43585d33df3SMartin KaFai Lau 					  const struct btf_member *member)
43685d33df3SMartin KaFai Lau {
43785d33df3SMartin KaFai Lau 	return btf_type_kflag(struct_type) ? BTF_MEMBER_BIT_OFFSET(member->offset)
43885d33df3SMartin KaFai Lau 					   : member->offset;
43985d33df3SMartin KaFai Lau }
44085d33df3SMartin KaFai Lau 
__btf_member_bitfield_size(const struct btf_type * struct_type,const struct btf_member * member)4418293eb99SAlexei Starovoitov static inline u32 __btf_member_bitfield_size(const struct btf_type *struct_type,
44227ae7997SMartin KaFai Lau 					     const struct btf_member *member)
44327ae7997SMartin KaFai Lau {
44427ae7997SMartin KaFai Lau 	return btf_type_kflag(struct_type) ? BTF_MEMBER_BITFIELD_SIZE(member->offset)
44527ae7997SMartin KaFai Lau 					   : 0;
44627ae7997SMartin KaFai Lau }
44727ae7997SMartin KaFai Lau 
btf_members(const struct btf_type * t)44829db4beaSAlexei Starovoitov static inline struct btf_member *btf_members(const struct btf_type *t)
44929db4beaSAlexei Starovoitov {
45029db4beaSAlexei Starovoitov 	return (struct btf_member *)(t + 1);
45129db4beaSAlexei Starovoitov }
45229db4beaSAlexei Starovoitov 
btf_member_bit_offset(const struct btf_type * t,u32 member_idx)45329db4beaSAlexei Starovoitov static inline u32 btf_member_bit_offset(const struct btf_type *t, u32 member_idx)
45429db4beaSAlexei Starovoitov {
45529db4beaSAlexei Starovoitov 	const struct btf_member *m = btf_members(t) + member_idx;
45629db4beaSAlexei Starovoitov 
45729db4beaSAlexei Starovoitov 	return __btf_member_bit_offset(t, m);
45829db4beaSAlexei Starovoitov }
45929db4beaSAlexei Starovoitov 
btf_member_bitfield_size(const struct btf_type * t,u32 member_idx)46029db4beaSAlexei Starovoitov static inline u32 btf_member_bitfield_size(const struct btf_type *t, u32 member_idx)
46129db4beaSAlexei Starovoitov {
46229db4beaSAlexei Starovoitov 	const struct btf_member *m = btf_members(t) + member_idx;
46329db4beaSAlexei Starovoitov 
46429db4beaSAlexei Starovoitov 	return __btf_member_bitfield_size(t, m);
46529db4beaSAlexei Starovoitov }
46629db4beaSAlexei Starovoitov 
btf_type_member(const struct btf_type * t)46727ae7997SMartin KaFai Lau static inline const struct btf_member *btf_type_member(const struct btf_type *t)
46827ae7997SMartin KaFai Lau {
46927ae7997SMartin KaFai Lau 	return (const struct btf_member *)(t + 1);
47027ae7997SMartin KaFai Lau }
47127ae7997SMartin KaFai Lau 
btf_array(const struct btf_type * t)47229db4beaSAlexei Starovoitov static inline struct btf_array *btf_array(const struct btf_type *t)
47329db4beaSAlexei Starovoitov {
47429db4beaSAlexei Starovoitov 	return (struct btf_array *)(t + 1);
47529db4beaSAlexei Starovoitov }
47629db4beaSAlexei Starovoitov 
btf_enum(const struct btf_type * t)47729db4beaSAlexei Starovoitov static inline struct btf_enum *btf_enum(const struct btf_type *t)
47829db4beaSAlexei Starovoitov {
47929db4beaSAlexei Starovoitov 	return (struct btf_enum *)(t + 1);
48029db4beaSAlexei Starovoitov }
48129db4beaSAlexei Starovoitov 
btf_enum64(const struct btf_type * t)4826089fb32SYonghong Song static inline struct btf_enum64 *btf_enum64(const struct btf_type *t)
4836089fb32SYonghong Song {
4846089fb32SYonghong Song 	return (struct btf_enum64 *)(t + 1);
4856089fb32SYonghong Song }
4866089fb32SYonghong Song 
btf_type_var_secinfo(const struct btf_type * t)487eaa6bcb7SHao Luo static inline const struct btf_var_secinfo *btf_type_var_secinfo(
488eaa6bcb7SHao Luo 		const struct btf_type *t)
489eaa6bcb7SHao Luo {
490eaa6bcb7SHao Luo 	return (const struct btf_var_secinfo *)(t + 1);
491eaa6bcb7SHao Luo }
492eaa6bcb7SHao Luo 
btf_params(const struct btf_type * t)493e70e13e7SMatteo Croce static inline struct btf_param *btf_params(const struct btf_type *t)
494e70e13e7SMatteo Croce {
495e70e13e7SMatteo Croce 	return (struct btf_param *)(t + 1);
496e70e13e7SMatteo Croce }
497e70e13e7SMatteo Croce 
btf_decl_tag(const struct btf_type * t)4988646db23SAlan Maguire static inline struct btf_decl_tag *btf_decl_tag(const struct btf_type *t)
4998646db23SAlan Maguire {
5008646db23SAlan Maguire 	return (struct btf_decl_tag *)(t + 1);
5018646db23SAlan Maguire }
5028646db23SAlan Maguire 
btf_id_cmp_func(const void * a,const void * b)5038ffa5cc1SKumar Kartikeya Dwivedi static inline int btf_id_cmp_func(const void *a, const void *b)
5048ffa5cc1SKumar Kartikeya Dwivedi {
5058ffa5cc1SKumar Kartikeya Dwivedi 	const int *pa = a, *pb = b;
5068ffa5cc1SKumar Kartikeya Dwivedi 
5078ffa5cc1SKumar Kartikeya Dwivedi 	return *pa - *pb;
5088ffa5cc1SKumar Kartikeya Dwivedi }
5098ffa5cc1SKumar Kartikeya Dwivedi 
btf_id_set_contains(const struct btf_id_set * set,u32 id)5108ffa5cc1SKumar Kartikeya Dwivedi static inline bool btf_id_set_contains(const struct btf_id_set *set, u32 id)
5118ffa5cc1SKumar Kartikeya Dwivedi {
5128ffa5cc1SKumar Kartikeya Dwivedi 	return bsearch(&id, set->ids, set->cnt, sizeof(u32), btf_id_cmp_func) != NULL;
5138ffa5cc1SKumar Kartikeya Dwivedi }
5148ffa5cc1SKumar Kartikeya Dwivedi 
btf_id_set8_contains(const struct btf_id_set8 * set,u32 id)5158ffa5cc1SKumar Kartikeya Dwivedi static inline void *btf_id_set8_contains(const struct btf_id_set8 *set, u32 id)
5168ffa5cc1SKumar Kartikeya Dwivedi {
5178ffa5cc1SKumar Kartikeya Dwivedi 	return bsearch(&id, set->pairs, set->cnt, sizeof(set->pairs[0]), btf_id_cmp_func);
5188ffa5cc1SKumar Kartikeya Dwivedi }
5198ffa5cc1SKumar Kartikeya Dwivedi 
5206115a0aeSKui-Feng Lee bool btf_param_match_suffix(const struct btf *btf,
5216115a0aeSKui-Feng Lee 			    const struct btf_param *arg,
5226115a0aeSKui-Feng Lee 			    const char *suffix);
52316116035SKui-Feng Lee int btf_ctx_arg_offset(const struct btf *btf, const struct btf_type *func_proto,
52416116035SKui-Feng Lee 		       u32 arg_no);
5256115a0aeSKui-Feng Lee 
52600b85860SKumar Kartikeya Dwivedi struct bpf_verifier_log;
52722dc4a0fSAndrii Nakryiko 
528f6be98d1SKui-Feng Lee #if defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL)
529f6be98d1SKui-Feng Lee struct bpf_struct_ops;
530f6be98d1SKui-Feng Lee int __register_bpf_struct_ops(struct bpf_struct_ops *st_ops);
531f6be98d1SKui-Feng Lee const struct bpf_struct_ops_desc *bpf_struct_ops_find_value(struct btf *btf, u32 value_id);
532f6be98d1SKui-Feng Lee const struct bpf_struct_ops_desc *bpf_struct_ops_find(struct btf *btf, u32 type_id);
533f6be98d1SKui-Feng Lee #else
bpf_struct_ops_find(struct btf * btf,u32 type_id)534f6be98d1SKui-Feng Lee static inline const struct bpf_struct_ops_desc *bpf_struct_ops_find(struct btf *btf, u32 type_id)
535f6be98d1SKui-Feng Lee {
536f6be98d1SKui-Feng Lee 	return NULL;
537f6be98d1SKui-Feng Lee }
538f6be98d1SKui-Feng Lee #endif
539f6be98d1SKui-Feng Lee 
5408646db23SAlan Maguire enum btf_field_iter_kind {
5418646db23SAlan Maguire 	BTF_FIELD_ITER_IDS,
5428646db23SAlan Maguire 	BTF_FIELD_ITER_STRS,
5438646db23SAlan Maguire };
5448646db23SAlan Maguire 
5458646db23SAlan Maguire struct btf_field_desc {
5468646db23SAlan Maguire 	/* once-per-type offsets */
5478646db23SAlan Maguire 	int t_off_cnt, t_offs[2];
5488646db23SAlan Maguire 	/* member struct size, or zero, if no members */
5498646db23SAlan Maguire 	int m_sz;
5508646db23SAlan Maguire 	/* repeated per-member offsets */
5518646db23SAlan Maguire 	int m_off_cnt, m_offs[1];
5528646db23SAlan Maguire };
5538646db23SAlan Maguire 
5548646db23SAlan Maguire struct btf_field_iter {
5558646db23SAlan Maguire 	struct btf_field_desc desc;
5568646db23SAlan Maguire 	void *p;
5578646db23SAlan Maguire 	int m_idx;
5588646db23SAlan Maguire 	int off_idx;
5598646db23SAlan Maguire 	int vlen;
5608646db23SAlan Maguire };
5618646db23SAlan Maguire 
56200b85860SKumar Kartikeya Dwivedi #ifdef CONFIG_BPF_SYSCALL
563838e9690SYonghong Song const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id);
5648646db23SAlan Maguire void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);
5658646db23SAlan Maguire int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids);
5668646db23SAlan Maguire int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,
5678646db23SAlan Maguire 			enum btf_field_iter_kind iter_kind);
5688646db23SAlan Maguire __u32 *btf_field_iter_next(struct btf_field_iter *it);
5698646db23SAlan Maguire 
570838e9690SYonghong Song const char *btf_name_by_offset(const struct btf *btf, u32 offset);
5718646db23SAlan Maguire const char *btf_str_by_offset(const struct btf *btf, u32 offset);
5728580ac94SAlexei Starovoitov struct btf *btf_parse_vmlinux(void);
5735b92a28aSAlexei Starovoitov struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog);
574e924e80eSAditi Ghag u32 *btf_kfunc_id_set_contains(const struct btf *btf, u32 kfunc_btf_id,
575e924e80eSAditi Ghag 			       const struct bpf_prog *prog);
576e924e80eSAditi Ghag u32 *btf_kfunc_is_modify_return(const struct btf *btf, u32 kfunc_btf_id,
577e924e80eSAditi Ghag 				const struct bpf_prog *prog);
578dee872e1SKumar Kartikeya Dwivedi int register_btf_kfunc_id_set(enum bpf_prog_type prog_type,
579dee872e1SKumar Kartikeya Dwivedi 			      const struct btf_kfunc_id_set *s);
5805b481acaSBenjamin Tissoires int register_btf_fmodret_id_set(const struct btf_kfunc_id_set *kset);
5815ce937d6SKumar Kartikeya Dwivedi s32 btf_find_dtor_kfunc(struct btf *btf, u32 btf_id);
5825ce937d6SKumar Kartikeya Dwivedi int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_cnt,
5835ce937d6SKumar Kartikeya Dwivedi 				struct module *owner);
5848ffa5cc1SKumar Kartikeya Dwivedi struct btf_struct_meta *btf_find_struct_meta(const struct btf *btf, u32 btf_id);
585ec209ad8SDaniel Xu bool btf_is_projection_of(const char *pname, const char *tname);
586fb5b86cfSAndrii Nakryiko bool btf_is_prog_ctx_type(struct bpf_verifier_log *log, const struct btf *btf,
58700b85860SKumar Kartikeya Dwivedi 			   const struct btf_type *t, enum bpf_prog_type prog_type,
58800b85860SKumar Kartikeya Dwivedi 			   int arg);
589fd264ca0SYonghong Song int get_kern_ctx_btf_id(struct bpf_verifier_log *log, enum bpf_prog_type prog_type);
59000b85860SKumar Kartikeya Dwivedi bool btf_types_are_same(const struct btf *btf1, u32 id1,
59100b85860SKumar Kartikeya Dwivedi 			const struct btf *btf2, u32 id2);
592496ddd19SAndrii Nakryiko int btf_check_iter_arg(struct btf *btf, const struct btf_type *func, int arg_idx);
5939a783139SAlistair Francis 
btf_type_is_struct_ptr(struct btf * btf,const struct btf_type * t)5949a783139SAlistair Francis static inline bool btf_type_is_struct_ptr(struct btf *btf, const struct btf_type *t)
5959a783139SAlistair Francis {
5969a783139SAlistair Francis 	if (!btf_type_is_ptr(t))
5979a783139SAlistair Francis 		return false;
5989a783139SAlistair Francis 
5999a783139SAlistair Francis 	t = btf_type_skip_modifiers(btf, t->type, NULL);
6009a783139SAlistair Francis 
6019a783139SAlistair Francis 	return btf_type_is_struct(t);
6029a783139SAlistair Francis }
603f6161a8fSYonghong Song #else
btf_type_by_id(const struct btf * btf,u32 type_id)604f6161a8fSYonghong Song static inline const struct btf_type *btf_type_by_id(const struct btf *btf,
605f6161a8fSYonghong Song 						    u32 type_id)
606f6161a8fSYonghong Song {
607f6161a8fSYonghong Song 	return NULL;
608f6161a8fSYonghong Song }
6098646db23SAlan Maguire 
btf_set_base_btf(struct btf * btf,const struct btf * base_btf)6108646db23SAlan Maguire static inline void btf_set_base_btf(struct btf *btf, const struct btf *base_btf)
6118646db23SAlan Maguire {
6128646db23SAlan Maguire }
6138646db23SAlan Maguire 
btf_relocate(void * log,struct btf * btf,const struct btf * base_btf,__u32 ** map_ids)6148646db23SAlan Maguire static inline int btf_relocate(void *log, struct btf *btf, const struct btf *base_btf,
6158646db23SAlan Maguire 			       __u32 **map_ids)
6168646db23SAlan Maguire {
6178646db23SAlan Maguire 	return -EOPNOTSUPP;
6188646db23SAlan Maguire }
6198646db23SAlan Maguire 
btf_field_iter_init(struct btf_field_iter * it,struct btf_type * t,enum btf_field_iter_kind iter_kind)6208646db23SAlan Maguire static inline int btf_field_iter_init(struct btf_field_iter *it, struct btf_type *t,
6218646db23SAlan Maguire 				      enum btf_field_iter_kind iter_kind)
6228646db23SAlan Maguire {
6238646db23SAlan Maguire 	return -EOPNOTSUPP;
6248646db23SAlan Maguire }
6258646db23SAlan Maguire 
btf_field_iter_next(struct btf_field_iter * it)6268646db23SAlan Maguire static inline __u32 *btf_field_iter_next(struct btf_field_iter *it)
6278646db23SAlan Maguire {
6288646db23SAlan Maguire 	return NULL;
6298646db23SAlan Maguire }
6308646db23SAlan Maguire 
btf_name_by_offset(const struct btf * btf,u32 offset)631f6161a8fSYonghong Song static inline const char *btf_name_by_offset(const struct btf *btf,
632f6161a8fSYonghong Song 					     u32 offset)
633f6161a8fSYonghong Song {
634f6161a8fSYonghong Song 	return NULL;
635f6161a8fSYonghong Song }
btf_kfunc_id_set_contains(const struct btf * btf,u32 kfunc_btf_id,struct bpf_prog * prog)636a4703e31SKumar Kartikeya Dwivedi static inline u32 *btf_kfunc_id_set_contains(const struct btf *btf,
637e924e80eSAditi Ghag 					     u32 kfunc_btf_id,
638e924e80eSAditi Ghag 					     struct bpf_prog *prog)
639e924e80eSAditi Ghag 
640dee872e1SKumar Kartikeya Dwivedi {
641a4703e31SKumar Kartikeya Dwivedi 	return NULL;
642dee872e1SKumar Kartikeya Dwivedi }
register_btf_kfunc_id_set(enum bpf_prog_type prog_type,const struct btf_kfunc_id_set * s)643dee872e1SKumar Kartikeya Dwivedi static inline int register_btf_kfunc_id_set(enum bpf_prog_type prog_type,
644dee872e1SKumar Kartikeya Dwivedi 					    const struct btf_kfunc_id_set *s)
645dee872e1SKumar Kartikeya Dwivedi {
646dee872e1SKumar Kartikeya Dwivedi 	return 0;
647dee872e1SKumar Kartikeya Dwivedi }
btf_find_dtor_kfunc(struct btf * btf,u32 btf_id)6485ce937d6SKumar Kartikeya Dwivedi static inline s32 btf_find_dtor_kfunc(struct btf *btf, u32 btf_id)
6495ce937d6SKumar Kartikeya Dwivedi {
6505ce937d6SKumar Kartikeya Dwivedi 	return -ENOENT;
6515ce937d6SKumar Kartikeya Dwivedi }
register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc * dtors,u32 add_cnt,struct module * owner)6525ce937d6SKumar Kartikeya Dwivedi static inline int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors,
6535ce937d6SKumar Kartikeya Dwivedi 					      u32 add_cnt, struct module *owner)
6545ce937d6SKumar Kartikeya Dwivedi {
6555ce937d6SKumar Kartikeya Dwivedi 	return 0;
6565ce937d6SKumar Kartikeya Dwivedi }
btf_find_struct_meta(const struct btf * btf,u32 btf_id)6578ffa5cc1SKumar Kartikeya Dwivedi static inline struct btf_struct_meta *btf_find_struct_meta(const struct btf *btf, u32 btf_id)
6588ffa5cc1SKumar Kartikeya Dwivedi {
6598ffa5cc1SKumar Kartikeya Dwivedi 	return NULL;
6608ffa5cc1SKumar Kartikeya Dwivedi }
661fb5b86cfSAndrii Nakryiko static inline bool
btf_is_prog_ctx_type(struct bpf_verifier_log * log,const struct btf * btf,const struct btf_type * t,enum bpf_prog_type prog_type,int arg)662fb5b86cfSAndrii Nakryiko btf_is_prog_ctx_type(struct bpf_verifier_log *log, const struct btf *btf,
66300b85860SKumar Kartikeya Dwivedi 		     const struct btf_type *t, enum bpf_prog_type prog_type,
66400b85860SKumar Kartikeya Dwivedi 		     int arg)
66500b85860SKumar Kartikeya Dwivedi {
666fb5b86cfSAndrii Nakryiko 	return false;
66700b85860SKumar Kartikeya Dwivedi }
get_kern_ctx_btf_id(struct bpf_verifier_log * log,enum bpf_prog_type prog_type)668fd264ca0SYonghong Song static inline int get_kern_ctx_btf_id(struct bpf_verifier_log *log,
669fd264ca0SYonghong Song 				      enum bpf_prog_type prog_type) {
670fd264ca0SYonghong Song 	return -EINVAL;
671fd264ca0SYonghong Song }
btf_types_are_same(const struct btf * btf1,u32 id1,const struct btf * btf2,u32 id2)67200b85860SKumar Kartikeya Dwivedi static inline bool btf_types_are_same(const struct btf *btf1, u32 id1,
67300b85860SKumar Kartikeya Dwivedi 				      const struct btf *btf2, u32 id2)
67400b85860SKumar Kartikeya Dwivedi {
67500b85860SKumar Kartikeya Dwivedi 	return false;
67600b85860SKumar Kartikeya Dwivedi }
btf_check_iter_arg(struct btf * btf,const struct btf_type * func,int arg_idx)677496ddd19SAndrii Nakryiko static inline int btf_check_iter_arg(struct btf *btf, const struct btf_type *func, int arg_idx)
678496ddd19SAndrii Nakryiko {
679496ddd19SAndrii Nakryiko 	return -EOPNOTSUPP;
680496ddd19SAndrii Nakryiko }
681f6161a8fSYonghong Song #endif
682eb3f595dSMartin KaFai Lau #endif
683