Lines Matching refs:btf
224 struct btf { struct
242 struct btf *base_btf; argument
282 struct btf *btf; member
382 const struct btf *btf; member
421 void (*show)(const struct btf *btf, const struct btf_type *t,
506 u32 btf_nr_types(const struct btf *btf) in btf_nr_types() argument
510 while (btf) { in btf_nr_types()
511 total += btf->nr_types; in btf_nr_types()
512 btf = btf->base_btf; in btf_nr_types()
518 s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind) in btf_find_by_name_kind() argument
524 total = btf_nr_types(btf); in btf_find_by_name_kind()
526 t = btf_type_by_id(btf, i); in btf_find_by_name_kind()
530 tname = btf_name_by_offset(btf, t->name_off); in btf_find_by_name_kind()
538 static s32 bpf_find_btf_id(const char *name, u32 kind, struct btf **btf_p) in bpf_find_btf_id()
540 struct btf *btf; in bpf_find_btf_id() local
544 btf = bpf_get_btf_vmlinux(); in bpf_find_btf_id()
545 if (IS_ERR(btf)) in bpf_find_btf_id()
546 return PTR_ERR(btf); in bpf_find_btf_id()
547 if (!btf) in bpf_find_btf_id()
550 ret = btf_find_by_name_kind(btf, name, kind); in bpf_find_btf_id()
555 btf_get(btf); in bpf_find_btf_id()
556 *btf_p = btf; in bpf_find_btf_id()
562 idr_for_each_entry(&btf_idr, btf, id) { in bpf_find_btf_id()
563 if (!btf_is_module(btf)) in bpf_find_btf_id()
568 btf_get(btf); in bpf_find_btf_id()
570 ret = btf_find_by_name_kind(btf, name, kind); in bpf_find_btf_id()
572 *btf_p = btf; in bpf_find_btf_id()
576 btf_put(btf); in bpf_find_btf_id()
582 const struct btf_type *btf_type_skip_modifiers(const struct btf *btf, in btf_type_skip_modifiers() argument
585 const struct btf_type *t = btf_type_by_id(btf, id); in btf_type_skip_modifiers()
589 t = btf_type_by_id(btf, t->type); in btf_type_skip_modifiers()
598 const struct btf_type *btf_type_resolve_ptr(const struct btf *btf, in btf_type_resolve_ptr() argument
603 t = btf_type_skip_modifiers(btf, id, NULL); in btf_type_resolve_ptr()
607 return btf_type_skip_modifiers(btf, t->type, res_id); in btf_type_resolve_ptr()
610 const struct btf_type *btf_type_resolve_func_ptr(const struct btf *btf, in btf_type_resolve_func_ptr() argument
615 ptype = btf_type_resolve_ptr(btf, id, res_id); in btf_type_resolve_func_ptr()
726 static bool btf_name_offset_valid(const struct btf *btf, u32 offset) in btf_name_offset_valid() argument
731 while (offset < btf->start_str_off) in btf_name_offset_valid()
732 btf = btf->base_btf; in btf_name_offset_valid()
734 offset -= btf->start_str_off; in btf_name_offset_valid()
735 return offset < btf->hdr.str_len; in btf_name_offset_valid()
749 static const char *btf_str_by_offset(const struct btf *btf, u32 offset) in btf_str_by_offset() argument
751 while (offset < btf->start_str_off) in btf_str_by_offset()
752 btf = btf->base_btf; in btf_str_by_offset()
754 offset -= btf->start_str_off; in btf_str_by_offset()
755 if (offset < btf->hdr.str_len) in btf_str_by_offset()
756 return &btf->strings[offset]; in btf_str_by_offset()
761 static bool __btf_name_valid(const struct btf *btf, u32 offset, bool dot_ok) in __btf_name_valid() argument
764 const char *src = btf_str_by_offset(btf, offset); in __btf_name_valid()
785 static bool btf_name_valid_identifier(const struct btf *btf, u32 offset) in btf_name_valid_identifier() argument
787 return __btf_name_valid(btf, offset, false); in btf_name_valid_identifier()
790 static bool btf_name_valid_section(const struct btf *btf, u32 offset) in btf_name_valid_section() argument
792 return __btf_name_valid(btf, offset, true); in btf_name_valid_section()
795 static const char *__btf_name_by_offset(const struct btf *btf, u32 offset) in __btf_name_by_offset() argument
802 name = btf_str_by_offset(btf, offset); in __btf_name_by_offset()
806 const char *btf_name_by_offset(const struct btf *btf, u32 offset) in btf_name_by_offset() argument
808 return btf_str_by_offset(btf, offset); in btf_name_by_offset()
811 const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id) in btf_type_by_id() argument
813 while (type_id < btf->start_id) in btf_type_by_id()
814 btf = btf->base_btf; in btf_type_by_id()
816 type_id -= btf->start_id; in btf_type_by_id()
817 if (type_id >= btf->nr_types) in btf_type_by_id()
819 return btf->types[type_id]; in btf_type_by_id()
850 bool btf_member_is_reg_int(const struct btf *btf, const struct btf_type *s, in btf_member_is_reg_int() argument
859 t = btf_type_id_size(btf, &id, NULL); in btf_member_is_reg_int()
888 static const struct btf_type *btf_type_skip_qualifiers(const struct btf *btf, in btf_type_skip_qualifiers() argument
891 const struct btf_type *t = btf_type_by_id(btf, id); in btf_type_skip_qualifiers()
895 t = btf_type_by_id(btf, t->type); in btf_type_skip_qualifiers()
941 member = btf_name_by_offset(show->btf, m->name_off); in btf_show_name()
953 t = btf_type_by_id(show->btf, id); in btf_show_name()
984 name = btf_name_by_offset(show->btf, in btf_show_name()
1011 t = btf_type_skip_qualifiers(show->btf, id); in btf_show_name()
1018 name = btf_name_by_offset(show->btf, t->name_off); in btf_show_name()
1208 rt = btf_resolve_size(show->btf, t, &size); in btf_show_obj_safe()
1400 struct btf *btf = env->btf; in __btf_verifier_log_type() local
1416 __btf_name_by_offset(btf, t->name_off), in __btf_verifier_log_type()
1444 struct btf *btf = env->btf; in btf_verifier_log_member() local
1464 __btf_name_by_offset(btf, member->name_off), in btf_verifier_log_member()
1470 __btf_name_by_offset(btf, member->name_off), in btf_verifier_log_member()
1515 const struct btf *btf = env->btf; in btf_verifier_log_hdr() local
1523 hdr = &btf->hdr; in btf_verifier_log_hdr()
1537 struct btf *btf = env->btf; in btf_add_type() local
1539 if (btf->types_size == btf->nr_types) { in btf_add_type()
1545 if (btf->start_id + btf->types_size == BTF_MAX_TYPE) { in btf_add_type()
1550 expand_by = max_t(u32, btf->types_size >> 2, 16); in btf_add_type()
1552 btf->types_size + expand_by); in btf_add_type()
1559 if (btf->nr_types == 0) { in btf_add_type()
1560 if (!btf->base_btf) { in btf_add_type()
1563 btf->nr_types++; in btf_add_type()
1566 memcpy(new_types, btf->types, in btf_add_type()
1567 sizeof(*btf->types) * btf->nr_types); in btf_add_type()
1570 kvfree(btf->types); in btf_add_type()
1571 btf->types = new_types; in btf_add_type()
1572 btf->types_size = new_size; in btf_add_type()
1575 btf->types[btf->nr_types++] = t; in btf_add_type()
1580 static int btf_alloc_id(struct btf *btf) in btf_alloc_id() argument
1586 id = idr_alloc_cyclic(&btf_idr, btf, 1, INT_MAX, GFP_ATOMIC); in btf_alloc_id()
1588 btf->id = id; in btf_alloc_id()
1598 static void btf_free_id(struct btf *btf) in btf_free_id() argument
1612 idr_remove(&btf_idr, btf->id); in btf_free_id()
1616 static void btf_free_kfunc_set_tab(struct btf *btf) in btf_free_kfunc_set_tab() argument
1618 struct btf_kfunc_set_tab *tab = btf->kfunc_set_tab; in btf_free_kfunc_set_tab()
1626 if (btf_is_module(btf)) in btf_free_kfunc_set_tab()
1632 btf->kfunc_set_tab = NULL; in btf_free_kfunc_set_tab()
1635 static void btf_free_dtor_kfunc_tab(struct btf *btf) in btf_free_dtor_kfunc_tab() argument
1637 struct btf_id_dtor_kfunc_tab *tab = btf->dtor_kfunc_tab; in btf_free_dtor_kfunc_tab()
1642 btf->dtor_kfunc_tab = NULL; in btf_free_dtor_kfunc_tab()
1645 static void btf_free(struct btf *btf) in btf_free() argument
1647 btf_free_dtor_kfunc_tab(btf); in btf_free()
1648 btf_free_kfunc_set_tab(btf); in btf_free()
1649 kvfree(btf->types); in btf_free()
1650 kvfree(btf->resolved_sizes); in btf_free()
1651 kvfree(btf->resolved_ids); in btf_free()
1652 kvfree(btf->data); in btf_free()
1653 kfree(btf); in btf_free()
1658 struct btf *btf = container_of(rcu, struct btf, rcu); in btf_free_rcu() local
1660 btf_free(btf); in btf_free_rcu()
1663 void btf_get(struct btf *btf) in btf_get() argument
1665 refcount_inc(&btf->refcnt); in btf_get()
1668 void btf_put(struct btf *btf) in btf_put() argument
1670 if (btf && refcount_dec_and_test(&btf->refcnt)) { in btf_put()
1671 btf_free_id(btf); in btf_put()
1672 call_rcu(&btf->rcu, btf_free_rcu); in btf_put()
1678 struct btf *btf = env->btf; in env_resolve_init() local
1679 u32 nr_types = btf->nr_types; in env_resolve_init()
1699 btf->resolved_sizes = resolved_sizes; in env_resolve_init()
1700 btf->resolved_ids = resolved_ids; in env_resolve_init()
1747 if (type_id < env->btf->start_id) in env_type_is_resolved()
1750 return env->visit_states[type_id - env->btf->start_id] == RESOLVED; in env_type_is_resolved()
1756 const struct btf *btf = env->btf; in env_stack_push() local
1762 if (type_id < btf->start_id in env_stack_push()
1763 || env->visit_states[type_id - btf->start_id] != NOT_VISITED) in env_stack_push()
1766 env->visit_states[type_id - btf->start_id] = VISITED; in env_stack_push()
1794 struct btf *btf = env->btf; in env_stack_pop_resolved() local
1796 type_id -= btf->start_id; /* adjust to local type id */ in env_stack_pop_resolved()
1797 btf->resolved_sizes[type_id] = resolved_size; in env_stack_pop_resolved()
1798 btf->resolved_ids[type_id] = resolved_type_id; in env_stack_pop_resolved()
1828 __btf_resolve_size(const struct btf *btf, const struct btf_type *type, in __btf_resolve_size() argument
1859 type = btf_type_by_id(btf, type->type); in __btf_resolve_size()
1869 type = btf_type_by_id(btf, array->type); in __btf_resolve_size()
1898 btf_resolve_size(const struct btf *btf, const struct btf_type *type, in btf_resolve_size() argument
1901 return __btf_resolve_size(btf, type, type_size, NULL, NULL, NULL, NULL); in btf_resolve_size()
1904 static u32 btf_resolved_type_id(const struct btf *btf, u32 type_id) in btf_resolved_type_id() argument
1906 while (type_id < btf->start_id) in btf_resolved_type_id()
1907 btf = btf->base_btf; in btf_resolved_type_id()
1909 return btf->resolved_ids[type_id - btf->start_id]; in btf_resolved_type_id()
1913 static const struct btf_type *btf_type_id_resolve(const struct btf *btf, in btf_type_id_resolve() argument
1916 *type_id = btf_resolved_type_id(btf, *type_id); in btf_type_id_resolve()
1917 return btf_type_by_id(btf, *type_id); in btf_type_id_resolve()
1920 static u32 btf_resolved_type_size(const struct btf *btf, u32 type_id) in btf_resolved_type_size() argument
1922 while (type_id < btf->start_id) in btf_resolved_type_size()
1923 btf = btf->base_btf; in btf_resolved_type_size()
1925 return btf->resolved_sizes[type_id - btf->start_id]; in btf_resolved_type_size()
1928 const struct btf_type *btf_type_id_size(const struct btf *btf, in btf_type_id_size() argument
1935 size_type = btf_type_by_id(btf, size_type_id); in btf_type_id_size()
1942 size = btf_resolved_type_size(btf, size_type_id); in btf_type_id_size()
1950 size_type_id = btf_resolved_type_id(btf, size_type_id); in btf_type_id_size()
1951 size_type = btf_type_by_id(btf, size_type_id); in btf_type_id_size()
1957 size = btf_resolved_type_size(btf, size_type_id); in btf_type_id_size()
2020 static void btf_df_show(const struct btf *btf, const struct btf_type *t, in btf_df_show() argument
2288 static void btf_int_bits_show(const struct btf *btf, in btf_int_bits_show() argument
2307 static void btf_int_show(const struct btf *btf, const struct btf_type *t, in btf_int_show() argument
2323 btf_int_bits_show(btf, t, safe_data, bits_offset, show); in btf_int_show()
2370 btf_int_bits_show(btf, t, safe_data, bits_offset, show); in btf_int_show()
2394 struct btf *btf = env->btf; in btf_modifier_check_member() local
2396 resolved_type = btf_type_id_size(btf, &resolved_type_id, NULL); in btf_modifier_check_member()
2419 struct btf *btf = env->btf; in btf_modifier_check_kflag_member() local
2421 resolved_type = btf_type_id_size(btf, &resolved_type_id, NULL); in btf_modifier_check_kflag_member()
2488 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_ref_type_check_meta()
2493 value = btf_name_by_offset(env->btf, t->name_off); in btf_ref_type_check_meta()
2516 struct btf *btf = env->btf; in btf_modifier_resolve() local
2518 next_type = btf_type_by_id(btf, next_type_id); in btf_modifier_resolve()
2534 if (!btf_type_id_size(btf, &next_type_id, NULL)) { in btf_modifier_resolve()
2536 next_type = btf_type_id_resolve(btf, &next_type_id); in btf_modifier_resolve()
2558 struct btf *btf = env->btf; in btf_var_resolve() local
2560 next_type = btf_type_by_id(btf, next_type_id); in btf_var_resolve()
2575 resolved_type = btf_type_id_resolve(btf, &resolved_type_id); in btf_var_resolve()
2588 if (!btf_type_id_size(btf, &next_type_id, NULL)) { in btf_var_resolve()
2604 struct btf *btf = env->btf; in btf_ptr_resolve() local
2606 next_type = btf_type_by_id(btf, next_type_id); in btf_ptr_resolve()
2629 resolved_type = btf_type_id_resolve(btf, &resolved_type_id); in btf_ptr_resolve()
2638 if (!btf_type_id_size(btf, &next_type_id, NULL)) { in btf_ptr_resolve()
2640 next_type = btf_type_id_resolve(btf, &next_type_id); in btf_ptr_resolve()
2655 static void btf_modifier_show(const struct btf *btf, in btf_modifier_show() argument
2660 if (btf->resolved_ids) in btf_modifier_show()
2661 t = btf_type_id_resolve(btf, &type_id); in btf_modifier_show()
2663 t = btf_type_skip_modifiers(btf, type_id, NULL); in btf_modifier_show()
2665 btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show); in btf_modifier_show()
2668 static void btf_var_show(const struct btf *btf, const struct btf_type *t, in btf_var_show() argument
2672 t = btf_type_id_resolve(btf, &type_id); in btf_var_show()
2674 btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show); in btf_var_show()
2677 static void btf_ptr_show(const struct btf *btf, const struct btf_type *t, in btf_ptr_show() argument
2735 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_fwd_check_meta()
2768 struct btf *btf = env->btf; in btf_array_check_member() local
2777 btf_type_id_size(btf, &array_type_id, &array_size); in btf_array_check_member()
2848 struct btf *btf = env->btf; in btf_array_resolve() local
2853 index_type = btf_type_by_id(btf, index_type_id); in btf_array_resolve()
2864 index_type = btf_type_id_size(btf, &index_type_id, NULL); in btf_array_resolve()
2873 elem_type = btf_type_by_id(btf, elem_type_id); in btf_array_resolve()
2885 elem_type = btf_type_id_size(btf, &elem_type_id, &elem_size); in btf_array_resolve()
2916 static void __btf_array_show(const struct btf *btf, const struct btf_type *t, in __btf_array_show() argument
2927 elem_type = btf_type_skip_modifiers(btf, elem_type_id, NULL); in __btf_array_show()
2956 elem_ops->show(btf, elem_type, elem_type_id, data, in __btf_array_show()
2969 static void btf_array_show(const struct btf *btf, const struct btf_type *t, in btf_array_show() argument
2985 __btf_array_show(btf, t, type_id, data, bits_offset, show); in btf_array_show()
2999 __btf_array_show(btf, t, type_id, data, bits_offset, show); in btf_array_show()
3043 struct btf *btf = env->btf; in btf_struct_check_meta() local
3058 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_struct_check_meta()
3067 if (!btf_name_offset_valid(btf, member->name_off)) { in btf_struct_check_meta()
3076 !btf_name_valid_identifier(btf, member->name_off)) { in btf_struct_check_meta()
3139 last_member_type = btf_type_by_id(env->btf, in btf_struct_resolve()
3155 const struct btf_type *member_type = btf_type_by_id(env->btf, in btf_struct_resolve()
3211 static int btf_find_struct(const struct btf *btf, const struct btf_type *t, in btf_find_struct() argument
3222 static int btf_find_kptr(const struct btf *btf, const struct btf_type *t, in btf_find_kptr() argument
3231 t = btf_type_by_id(btf, t->type); in btf_find_kptr()
3236 if (btf_type_is_type_tag(btf_type_by_id(btf, t->type))) in btf_find_kptr()
3238 if (!strcmp("kptr", __btf_name_by_offset(btf, t->name_off))) in btf_find_kptr()
3240 else if (!strcmp("kptr_ref", __btf_name_by_offset(btf, t->name_off))) in btf_find_kptr()
3246 t = btf_type_skip_modifiers(btf, t->type, &res_id); in btf_find_kptr()
3257 static int btf_find_struct_field(const struct btf *btf, const struct btf_type *t, in btf_find_struct_field() argument
3268 const struct btf_type *member_type = btf_type_by_id(btf, in btf_find_struct_field()
3271 if (name && strcmp(__btf_name_by_offset(btf, member_type->name_off), name)) in btf_find_struct_field()
3285 ret = btf_find_struct(btf, member_type, off, sz, in btf_find_struct_field()
3291 ret = btf_find_kptr(btf, member_type, off, sz, in btf_find_struct_field()
3309 static int btf_find_datasec_var(const struct btf *btf, const struct btf_type *t, in btf_find_datasec_var() argument
3320 const struct btf_type *var = btf_type_by_id(btf, vsi->type); in btf_find_datasec_var()
3321 const struct btf_type *var_type = btf_type_by_id(btf, var->type); in btf_find_datasec_var()
3325 if (name && strcmp(__btf_name_by_offset(btf, var_type->name_off), name)) in btf_find_datasec_var()
3335 ret = btf_find_struct(btf, var_type, off, sz, in btf_find_datasec_var()
3341 ret = btf_find_kptr(btf, var_type, off, sz, in btf_find_datasec_var()
3359 static int btf_find_field(const struct btf *btf, const struct btf_type *t, in btf_find_field() argument
3387 return btf_find_struct_field(btf, t, name, sz, align, field_type, info, info_cnt); in btf_find_field()
3389 return btf_find_datasec_var(btf, t, name, sz, align, field_type, info, info_cnt); in btf_find_field()
3397 int btf_find_spin_lock(const struct btf *btf, const struct btf_type *t) in btf_find_spin_lock() argument
3402 ret = btf_find_field(btf, t, BTF_FIELD_SPIN_LOCK, &info, 1); in btf_find_spin_lock()
3410 int btf_find_timer(const struct btf *btf, const struct btf_type *t) in btf_find_timer() argument
3415 ret = btf_find_field(btf, t, BTF_FIELD_TIMER, &info, 1); in btf_find_timer()
3423 struct bpf_map_value_off *btf_parse_kptrs(const struct btf *btf, in btf_parse_kptrs() argument
3428 struct btf *kernel_btf = NULL; in btf_parse_kptrs()
3432 ret = btf_find_field(btf, t, BTF_FIELD_KPTR, info_arr, ARRAY_SIZE(info_arr)); in btf_parse_kptrs()
3450 t = btf_type_by_id(btf, info_arr[i].type_id); in btf_parse_kptrs()
3451 id = bpf_find_btf_id(__btf_name_by_offset(btf, t->name_off), BTF_INFO_KIND(t->info), in btf_parse_kptrs()
3506 tab->off[i].kptr.btf = kernel_btf; in btf_parse_kptrs()
3517 btf_put(tab->off[i].kptr.btf); in btf_parse_kptrs()
3525 static void __btf_struct_show(const struct btf *btf, const struct btf_type *t, in __btf_struct_show() argument
3538 const struct btf_type *member_type = btf_type_by_id(btf, in __btf_struct_show()
3562 ops->show(btf, member_type, member->type, in __btf_struct_show()
3572 static void btf_struct_show(const struct btf *btf, const struct btf_type *t, in btf_struct_show() argument
3588 __btf_struct_show(btf, t, type_id, data, bits_offset, show); in btf_struct_show()
3603 __btf_struct_show(btf, t, type_id, data, bits_offset, show); in btf_struct_show()
3680 struct btf *btf = env->btf; in btf_enum_check_meta() local
3702 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_enum_check_meta()
3710 if (!btf_name_offset_valid(btf, enums[i].name_off)) { in btf_enum_check_meta()
3718 !btf_name_valid_identifier(btf, enums[i].name_off)) { in btf_enum_check_meta()
3727 __btf_name_by_offset(btf, enums[i].name_off), in btf_enum_check_meta()
3740 static void btf_enum_show(const struct btf *btf, const struct btf_type *t, in btf_enum_show() argument
3760 __btf_name_by_offset(btf, in btf_enum_show()
3788 struct btf *btf = env->btf; in btf_enum64_check_meta() local
3810 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_enum64_check_meta()
3818 if (!btf_name_offset_valid(btf, enums[i].name_off)) { in btf_enum64_check_meta()
3826 !btf_name_valid_identifier(btf, enums[i].name_off)) { in btf_enum64_check_meta()
3836 __btf_name_by_offset(btf, enums[i].name_off), in btf_enum64_check_meta()
3843 static void btf_enum64_show(const struct btf *btf, const struct btf_type *t, in btf_enum64_show() argument
3863 __btf_name_by_offset(btf, in btf_enum64_show()
3933 __btf_name_by_offset(env->btf, in btf_func_proto_log()
3937 __btf_name_by_offset(env->btf, in btf_func_proto_log()
3945 __btf_name_by_offset(env->btf, in btf_func_proto_log()
3978 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_func_check_meta()
4047 !__btf_name_valid(env->btf, t->name_off, true)) { in btf_var_check_meta()
4113 !btf_name_valid_section(env->btf, t->name_off)) { in btf_datasec_check_meta()
4163 struct btf *btf = env->btf; in btf_datasec_resolve() local
4168 const struct btf_type *var_type = btf_type_by_id(env->btf, in btf_datasec_resolve()
4183 if (!btf_type_id_size(btf, &type_id, &type_size)) { in btf_datasec_resolve()
4204 static void btf_datasec_show(const struct btf *btf, in btf_datasec_show() argument
4217 __btf_name_by_offset(btf, t->name_off)); in btf_datasec_show()
4219 var = btf_type_by_id(btf, vsi->type); in btf_datasec_show()
4222 btf_type_ops(var)->show(btf, var, vsi->type, in btf_datasec_show()
4328 value = btf_name_by_offset(env->btf, t->name_off); in btf_decl_tag_check_meta()
4361 struct btf *btf = env->btf; in btf_decl_tag_resolve() local
4365 next_type = btf_type_by_id(btf, next_type_id); in btf_decl_tag_resolve()
4386 next_type = btf_type_by_id(btf, next_type->type); in btf_decl_tag_resolve()
4421 const struct btf *btf; in btf_func_proto_check() local
4425 btf = env->btf; in btf_func_proto_check()
4433 ret_type = btf_type_by_id(btf, ret_type_id); in btf_func_proto_check()
4452 if (!btf_type_id_size(btf, &ret_type_id, NULL)) { in btf_func_proto_check()
4477 arg_type = btf_type_by_id(btf, arg_type_id); in btf_func_proto_check()
4485 (!btf_name_offset_valid(btf, args[i].name_off) || in btf_func_proto_check()
4486 !btf_name_valid_identifier(btf, args[i].name_off))) { in btf_func_proto_check()
4500 if (!btf_type_id_size(btf, &arg_type_id, NULL)) { in btf_func_proto_check()
4515 const struct btf *btf; in btf_func_check() local
4518 btf = env->btf; in btf_func_check()
4519 proto_type = btf_type_by_id(btf, t->type); in btf_func_check()
4587 if (!btf_name_offset_valid(env->btf, t->name_off)) { in btf_check_meta()
4604 struct btf *btf = env->btf; in btf_check_all_metas() local
4608 hdr = &btf->hdr; in btf_check_all_metas()
4609 cur = btf->nohdr_data + hdr->type_off; in btf_check_all_metas()
4612 env->log_type_id = btf->base_btf ? btf->start_id : 1; in btf_check_all_metas()
4633 struct btf *btf = env->btf; in btf_resolve_valid() local
4639 return !btf_resolved_type_id(btf, type_id) && in btf_resolve_valid()
4640 !btf_resolved_type_size(btf, type_id); in btf_resolve_valid()
4643 return btf_resolved_type_id(btf, type_id) && in btf_resolve_valid()
4644 !btf_resolved_type_size(btf, type_id); in btf_resolve_valid()
4648 t = btf_type_id_resolve(btf, &type_id); in btf_resolve_valid()
4661 elem_type = btf_type_id_size(btf, &elem_type_id, &elem_size); in btf_resolve_valid()
4664 btf_resolved_type_size(btf, type_id)); in btf_resolve_valid()
4705 struct btf *btf = env->btf; in btf_check_all_types() local
4715 for (i = btf->base_btf ? 0 : 1; i < btf->nr_types; i++) { in btf_check_all_types()
4716 type_id = btf->start_id + i; in btf_check_all_types()
4717 t = btf_type_by_id(btf, type_id); in btf_check_all_types()
4739 const struct btf_header *hdr = &env->btf->hdr; in btf_parse_type_sec()
4748 if (!env->btf->base_btf && !hdr->type_len) { in btf_parse_type_sec()
4763 struct btf *btf = env->btf; in btf_parse_str_sec() local
4766 hdr = &btf->hdr; in btf_parse_str_sec()
4767 start = btf->nohdr_data + hdr->str_off; in btf_parse_str_sec()
4770 if (end != btf->data + btf->data_size) { in btf_parse_str_sec()
4775 btf->strings = start; in btf_parse_str_sec()
4777 if (btf->base_btf && !hdr->str_len) in btf_parse_str_sec()
4783 if (!btf->base_btf && start[0]) { in btf_parse_str_sec()
4810 const struct btf *btf; in btf_check_sec_info() local
4812 btf = env->btf; in btf_check_sec_info()
4813 hdr = &btf->hdr; in btf_check_sec_info()
4861 struct btf *btf; in btf_parse_hdr() local
4863 btf = env->btf; in btf_parse_hdr()
4864 btf_data_size = btf->data_size; in btf_parse_hdr()
4871 hdr = btf->data; in btf_parse_hdr()
4879 if (hdr_len > sizeof(btf->hdr)) { in btf_parse_hdr()
4880 u8 *expected_zero = btf->data + sizeof(btf->hdr); in btf_parse_hdr()
4881 u8 *end = btf->data + hdr_len; in btf_parse_hdr()
4891 hdr_copy = min_t(u32, hdr_len, sizeof(btf->hdr)); in btf_parse_hdr()
4892 memcpy(&btf->hdr, btf->data, hdr_copy); in btf_parse_hdr()
4894 hdr = &btf->hdr; in btf_parse_hdr()
4913 if (!btf->base_btf && btf_data_size == hdr->hdr_len) { in btf_parse_hdr()
4922 struct btf *btf, int start_id) in btf_check_type_tags() argument
4927 n = btf_nr_types(btf); in btf_check_type_tags()
4933 t = btf_type_by_id(btf, i); in btf_check_type_tags()
4959 t = btf_type_by_id(btf, cur_id); in btf_check_type_tags()
4968 static struct btf *btf_parse(bpfptr_t btf_data, u32 btf_data_size, in btf_parse()
4973 struct btf *btf = NULL; in btf_parse() local
5000 btf = kzalloc(sizeof(*btf), GFP_KERNEL | __GFP_NOWARN); in btf_parse()
5001 if (!btf) { in btf_parse()
5005 env->btf = btf; in btf_parse()
5013 btf->data = data; in btf_parse()
5014 btf->data_size = btf_data_size; in btf_parse()
5025 btf->nohdr_data = btf->data + btf->hdr.hdr_len; in btf_parse()
5035 err = btf_check_type_tags(env, btf, 1); in btf_parse()
5045 refcount_set(&btf->refcnt, 1); in btf_parse()
5046 return btf; in btf_parse()
5050 if (btf) in btf_parse()
5051 btf_free(btf); in btf_parse()
5057 extern struct btf *btf_vmlinux;
5090 btf_get_prog_ctx_type(struct bpf_verifier_log *log, const struct btf *btf, in btf_get_prog_ctx_type() argument
5104 t = btf_type_by_id(btf, t->type); in btf_get_prog_ctx_type()
5106 t = btf_type_by_id(btf, t->type); in btf_get_prog_ctx_type()
5115 tname = btf_name_by_offset(btf, t->name_off); in btf_get_prog_ctx_type()
5148 struct btf *btf, in btf_translate_to_vmlinux() argument
5155 prog_ctx_type = btf_get_prog_ctx_type(log, btf, t, prog_type, arg); in btf_translate_to_vmlinux()
5165 struct btf *btf_parse_vmlinux(void) in BTF_ID()
5169 struct btf *btf = NULL; in BTF_ID() local
5179 btf = kzalloc(sizeof(*btf), GFP_KERNEL | __GFP_NOWARN); in BTF_ID()
5180 if (!btf) { in BTF_ID()
5184 env->btf = btf; in BTF_ID()
5186 btf->data = __start_BTF; in BTF_ID()
5187 btf->data_size = __stop_BTF - __start_BTF; in BTF_ID()
5188 btf->kernel_btf = true; in BTF_ID()
5189 snprintf(btf->name, sizeof(btf->name), "vmlinux"); in BTF_ID()
5195 btf->nohdr_data = btf->data + btf->hdr.hdr_len; in BTF_ID()
5205 err = btf_check_type_tags(env, btf, 1); in BTF_ID()
5210 bpf_ctx_convert.t = btf_type_by_id(btf, bpf_ctx_convert_btf_id[0]); in BTF_ID()
5212 bpf_struct_ops_init(btf, log); in BTF_ID()
5214 refcount_set(&btf->refcnt, 1); in BTF_ID()
5216 err = btf_alloc_id(btf); in BTF_ID()
5221 return btf; in BTF_ID()
5225 if (btf) { in BTF_ID()
5226 kvfree(btf->types); in BTF_ID()
5227 kfree(btf); in BTF_ID()
5234 static struct btf *btf_parse_module(const char *module_name, const void *data, unsigned int data_si… in btf_parse_module()
5238 struct btf *btf = NULL, *base_btf; in btf_parse_module() local
5254 btf = kzalloc(sizeof(*btf), GFP_KERNEL | __GFP_NOWARN); in btf_parse_module()
5255 if (!btf) { in btf_parse_module()
5259 env->btf = btf; in btf_parse_module()
5261 btf->base_btf = base_btf; in btf_parse_module()
5262 btf->start_id = base_btf->nr_types; in btf_parse_module()
5263 btf->start_str_off = base_btf->hdr.str_len; in btf_parse_module()
5264 btf->kernel_btf = true; in btf_parse_module()
5265 snprintf(btf->name, sizeof(btf->name), "%s", module_name); in btf_parse_module()
5267 btf->data = kvmalloc(data_size, GFP_KERNEL | __GFP_NOWARN); in btf_parse_module()
5268 if (!btf->data) { in btf_parse_module()
5272 memcpy(btf->data, data, data_size); in btf_parse_module()
5273 btf->data_size = data_size; in btf_parse_module()
5279 btf->nohdr_data = btf->data + btf->hdr.hdr_len; in btf_parse_module()
5289 err = btf_check_type_tags(env, btf, btf_nr_types(base_btf)); in btf_parse_module()
5294 refcount_set(&btf->refcnt, 1); in btf_parse_module()
5295 return btf; in btf_parse_module()
5299 if (btf) { in btf_parse_module()
5300 kvfree(btf->data); in btf_parse_module()
5301 kvfree(btf->types); in btf_parse_module()
5302 kfree(btf); in btf_parse_module()
5309 struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog) in bpf_prog_get_target_btf()
5314 return tgt_prog->aux->btf; in bpf_prog_get_target_btf()
5319 static bool is_int_ptr(struct btf *btf, const struct btf_type *t) in is_int_ptr() argument
5322 t = btf_type_by_id(btf, t->type); in is_int_ptr()
5326 t = btf_type_by_id(btf, t->type); in is_int_ptr()
5331 static u32 get_ctx_arg_idx(struct btf *btf, const struct btf_type *func_proto, in get_ctx_arg_idx() argument
5345 t = btf_type_skip_modifiers(btf, args[i].type, NULL); in get_ctx_arg_idx()
5351 t = btf_type_skip_modifiers(btf, func_proto->type, NULL); in get_ctx_arg_idx()
5365 struct btf *btf = bpf_prog_get_target_btf(prog); in btf_ctx_access() local
5378 arg = get_ctx_arg_idx(btf, t, off); in btf_ctx_access()
5416 t = btf_type_by_id(btf, t->type); in btf_ctx_access()
5425 t = btf_type_skip_modifiers(btf, t->type, NULL); in btf_ctx_access()
5442 t = btf_type_by_id(btf, args[arg].type); in btf_ctx_access()
5447 t = btf_type_by_id(btf, t->type); in btf_ctx_access()
5455 __btf_name_by_offset(btf, t->name_off), in btf_ctx_access()
5481 if (is_int_ptr(btf, t)) in btf_ctx_access()
5495 info->btf = btf_vmlinux; in btf_ctx_access()
5510 ret = btf_translate_to_vmlinux(log, btf, t, tgt_type, arg); in btf_ctx_access()
5512 info->btf = btf_vmlinux; in btf_ctx_access()
5520 info->btf = btf; in btf_ctx_access()
5522 t = btf_type_by_id(btf, t->type); in btf_ctx_access()
5525 tag_value = __btf_name_by_offset(btf, t->name_off); in btf_ctx_access()
5535 t = btf_type_by_id(btf, t->type); in btf_ctx_access()
5545 __btf_name_by_offset(btf, t->name_off)); in btf_ctx_access()
5556 static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf, in btf_struct_walk() argument
5567 tname = __btf_name_by_offset(btf, t->name_off); in btf_struct_walk()
5584 mtype = btf_type_skip_modifiers(btf, member->type, in btf_struct_walk()
5600 t = btf_type_skip_modifiers(btf, array_elem->type, in btf_struct_walk()
5658 mtype = btf_type_by_id(btf, member->type); in btf_struct_walk()
5659 mname = __btf_name_by_offset(btf, member->name_off); in btf_struct_walk()
5661 mtype = __btf_resolve_size(btf, mtype, &msize, in btf_struct_walk()
5759 t = btf_type_by_id(btf, mtype->type); in btf_struct_walk()
5761 tag_value = __btf_name_by_offset(btf, t->name_off); in btf_struct_walk()
5770 stype = btf_type_skip_modifiers(btf, mtype->type, &id); in btf_struct_walk()
5797 int btf_struct_access(struct bpf_verifier_log *log, const struct btf *btf, in btf_struct_access() argument
5807 err = btf_struct_walk(log, btf, t, off, size, &id, &tmp_flag); in btf_struct_access()
5824 t = btf_type_by_id(btf, id); in btf_struct_access()
5845 static bool btf_types_are_same(const struct btf *btf1, u32 id1, in btf_types_are_same()
5846 const struct btf *btf2, u32 id2) in btf_types_are_same()
5856 const struct btf *btf, u32 id, int off, in btf_struct_ids_match() argument
5857 const struct btf *need_btf, u32 need_type_id, in btf_struct_ids_match()
5865 if (off == 0 && btf_types_are_same(btf, id, need_btf, need_type_id)) in btf_struct_ids_match()
5874 type = btf_type_by_id(btf, id); in btf_struct_ids_match()
5877 err = btf_struct_walk(log, btf, type, off, 1, &id, &flag); in btf_struct_ids_match()
5886 if (!btf_types_are_same(btf, id, need_btf, need_type_id)) { in btf_struct_ids_match()
5894 static int __get_type_size(struct btf *btf, u32 btf_id, in __get_type_size() argument
5899 *ret_type = btf_type_by_id(btf, 0); in __get_type_size()
5903 t = btf_type_by_id(btf, btf_id); in __get_type_size()
5905 t = btf_type_by_id(btf, t->type); in __get_type_size()
5918 struct btf *btf, in btf_distill_func_proto() argument
5948 ret = __get_type_size(btf, func->type, &t); in btf_distill_func_proto()
5964 ret = __get_type_size(btf, args[i].type, &t); in btf_distill_func_proto()
5995 struct btf *btf1, const struct btf_type *t1, in btf_check_func_type_match()
5996 struct btf *btf2, const struct btf_type *t2) in btf_check_func_type_match()
6106 struct btf *btf2, const struct btf_type *t2) in btf_check_type_match()
6108 struct btf *btf1 = prog->aux->btf; in btf_check_type_match()
6138 const struct btf *btf, in __btf_type_is_scalar_struct() argument
6151 member_type = btf_type_skip_modifiers(btf, member->type, NULL); in __btf_type_is_scalar_struct()
6157 if (!__btf_type_is_scalar_struct(log, btf, member_type, rec + 1)) in __btf_type_is_scalar_struct()
6165 member_type = btf_type_skip_modifiers(btf, array->type, NULL); in __btf_type_is_scalar_struct()
6176 static bool is_kfunc_arg_mem_size(const struct btf *btf, in is_kfunc_arg_mem_size() argument
6184 t = btf_type_skip_modifiers(btf, arg->type, NULL); in is_kfunc_arg_mem_size()
6189 param_name = btf_name_by_offset(btf, arg->name_off); in is_kfunc_arg_mem_size()
6202 static bool btf_is_kfunc_arg_mem_size(const struct btf *btf, in btf_is_kfunc_arg_mem_size() argument
6211 t = btf_type_skip_modifiers(btf, arg->type, NULL); in btf_is_kfunc_arg_mem_size()
6215 param_name = btf_name_by_offset(btf, arg->name_off); in btf_is_kfunc_arg_mem_size()
6228 const struct btf *btf, u32 func_id, in btf_check_func_arg_match() argument
6239 bool is_kfunc = btf_is_kernel(btf); in btf_check_func_arg_match()
6245 t = btf_type_by_id(btf, func_id); in btf_check_func_arg_match()
6254 func_name = btf_name_by_offset(btf, t->name_off); in btf_check_func_arg_match()
6256 t = btf_type_by_id(btf, t->type); in btf_check_func_arg_match()
6286 t = btf_type_skip_modifiers(btf, args[i].type, NULL); in btf_check_func_arg_match()
6294 if (btf_is_kfunc_arg_mem_size(btf, &args[i], reg, in btf_check_func_arg_match()
6298 } else if (btf_is_kfunc_arg_mem_size(btf, &args[i], reg, in btf_check_func_arg_match()
6347 ref_t = btf_type_skip_modifiers(btf, t->type, &ref_id); in btf_check_func_arg_match()
6348 ref_tname = btf_name_by_offset(btf, ref_t->name_off); in btf_check_func_arg_match()
6398 ref_t = btf_type_skip_modifiers(btf, ref_t->type, &ref_id); in btf_check_func_arg_match()
6399 ref_tname = btf_name_by_offset(btf, ref_t->name_off); in btf_check_func_arg_match()
6406 if (!btf_struct_ids_match(log, btf, ref_id, 0, off_desc->kptr.btf, in btf_check_func_arg_match()
6413 } else if (btf_get_prog_ctx_type(log, btf, t, prog_type, i)) { in btf_check_func_arg_match()
6426 const struct btf *reg_btf; in btf_check_func_arg_match()
6438 reg_btf = reg->btf; in btf_check_func_arg_match()
6450 reg->off, btf, ref_id, in btf_check_func_arg_match()
6464 bool arg_mem_size = i + 1 < nargs && is_kfunc_arg_mem_size(btf, &args[i + 1], ®s[regno + 1]); in btf_check_func_arg_match()
6477 !__btf_type_is_scalar_struct(log, btf, ref_t, 0) && in btf_check_func_arg_match()
6526 resolve_ret = btf_resolve_size(btf, ref_t, &type_size); in btf_check_func_arg_match()
6581 struct btf *btf = prog->aux->btf; in btf_check_subprog_arg_match() local
6597 err = btf_check_func_arg_match(env, btf, btf_id, regs, is_global, NULL, false); in btf_check_subprog_arg_match()
6624 struct btf *btf = prog->aux->btf; in btf_check_subprog_call() local
6640 err = btf_check_func_arg_match(env, btf, btf_id, regs, is_global, NULL, true); in btf_check_subprog_call()
6652 const struct btf *btf, u32 func_id, in btf_check_kfunc_arg_match() argument
6656 return btf_check_func_arg_match(env, btf, func_id, regs, true, meta, true); in btf_check_kfunc_arg_match()
6672 struct btf *btf = prog->aux->btf; in btf_prepare_func_args() local
6690 t = btf_type_by_id(btf, btf_id); in btf_prepare_func_args()
6699 tname = btf_name_by_offset(btf, t->name_off); in btf_prepare_func_args()
6712 t = btf_type_by_id(btf, t->type); in btf_prepare_func_args()
6725 t = btf_type_by_id(btf, t->type); in btf_prepare_func_args()
6727 t = btf_type_by_id(btf, t->type); in btf_prepare_func_args()
6740 t = btf_type_by_id(btf, args[i].type); in btf_prepare_func_args()
6742 t = btf_type_by_id(btf, t->type); in btf_prepare_func_args()
6748 if (btf_get_prog_ctx_type(log, btf, t, prog_type, i)) { in btf_prepare_func_args()
6753 t = btf_type_skip_modifiers(btf, t->type, NULL); in btf_prepare_func_args()
6755 ref_t = btf_resolve_size(btf, t, ®->mem_size); in btf_prepare_func_args()
6759 i, btf_type_str(t), btf_name_by_offset(btf, t->name_off), in btf_prepare_func_args()
6776 static void btf_type_show(const struct btf *btf, u32 type_id, void *obj, in btf_type_show() argument
6779 const struct btf_type *t = btf_type_by_id(btf, type_id); in btf_type_show()
6781 show->btf = btf; in btf_type_show()
6785 btf_type_ops(t)->show(btf, t, type_id, obj, 0, show); in btf_type_show()
6794 int btf_type_seq_show_flags(const struct btf *btf, u32 type_id, in btf_type_seq_show_flags() argument
6803 btf_type_show(btf, type_id, obj, &sseq); in btf_type_seq_show_flags()
6808 void btf_type_seq_show(const struct btf *btf, u32 type_id, void *obj, in btf_type_seq_show() argument
6811 (void) btf_type_seq_show_flags(btf, type_id, obj, m, in btf_type_seq_show()
6844 int btf_type_snprintf_show(const struct btf *btf, u32 type_id, void *obj, in btf_type_snprintf_show() argument
6855 btf_type_show(btf, type_id, obj, (struct btf_show *)&ssnprintf); in btf_type_snprintf_show()
6868 const struct btf *btf = filp->private_data; in bpf_btf_show_fdinfo() local
6870 seq_printf(m, "btf_id:\t%u\n", btf->id); in bpf_btf_show_fdinfo()
6887 static int __btf_new_fd(struct btf *btf) in __btf_new_fd() argument
6889 return anon_inode_getfd("btf", &btf_fops, btf, O_RDONLY | O_CLOEXEC); in __btf_new_fd()
6894 struct btf *btf; in btf_new_fd() local
6897 btf = btf_parse(make_bpfptr(attr->btf, uattr.is_kernel), in btf_new_fd()
6901 if (IS_ERR(btf)) in btf_new_fd()
6902 return PTR_ERR(btf); in btf_new_fd()
6904 ret = btf_alloc_id(btf); in btf_new_fd()
6906 btf_free(btf); in btf_new_fd()
6916 ret = __btf_new_fd(btf); in btf_new_fd()
6918 btf_put(btf); in btf_new_fd()
6923 struct btf *btf_get_by_fd(int fd) in btf_get_by_fd()
6925 struct btf *btf; in btf_get_by_fd() local
6938 btf = f.file->private_data; in btf_get_by_fd()
6939 refcount_inc(&btf->refcnt); in btf_get_by_fd()
6942 return btf; in btf_get_by_fd()
6945 int btf_get_info_by_fd(const struct btf *btf, in btf_get_info_by_fd() argument
6965 info.id = btf->id; in btf_get_info_by_fd()
6966 ubtf = u64_to_user_ptr(info.btf); in btf_get_info_by_fd()
6967 btf_copy = min_t(u32, btf->data_size, info.btf_size); in btf_get_info_by_fd()
6968 if (copy_to_user(ubtf, btf->data, btf_copy)) in btf_get_info_by_fd()
6970 info.btf_size = btf->data_size; in btf_get_info_by_fd()
6972 info.kernel_btf = btf->kernel_btf; in btf_get_info_by_fd()
6979 name_len = strlen(btf->name); in btf_get_info_by_fd()
6984 if (copy_to_user(uname, btf->name, name_len + 1)) in btf_get_info_by_fd()
6989 if (copy_to_user(uname, btf->name, uname_len - 1)) in btf_get_info_by_fd()
7007 struct btf *btf; in btf_get_fd_by_id() local
7011 btf = idr_find(&btf_idr, id); in btf_get_fd_by_id()
7012 if (!btf || !refcount_inc_not_zero(&btf->refcnt)) in btf_get_fd_by_id()
7013 btf = ERR_PTR(-ENOENT); in btf_get_fd_by_id()
7016 if (IS_ERR(btf)) in btf_get_fd_by_id()
7017 return PTR_ERR(btf); in btf_get_fd_by_id()
7019 fd = __btf_new_fd(btf); in btf_get_fd_by_id()
7021 btf_put(btf); in btf_get_fd_by_id()
7026 u32 btf_obj_id(const struct btf *btf) in btf_obj_id() argument
7028 return btf->id; in btf_obj_id()
7031 bool btf_is_kernel(const struct btf *btf) in btf_is_kernel() argument
7033 return btf->kernel_btf; in btf_is_kernel()
7036 bool btf_is_module(const struct btf *btf) in btf_is_module() argument
7038 return btf->kernel_btf && strcmp(btf->name, "vmlinux") != 0; in btf_is_module()
7066 struct btf *btf; member
7079 const struct btf *btf = bin_attr->private; in btf_module_read() local
7081 memcpy(buf, btf->data + off, len); in btf_module_read()
7085 static void purge_cand_cache(struct btf *btf);
7092 struct btf *btf; in btf_module_notify() local
7107 btf = btf_parse_module(mod->name, mod->btf_data, mod->btf_data_size); in btf_module_notify()
7108 if (IS_ERR(btf)) { in btf_module_notify()
7110 mod->name, PTR_ERR(btf)); in btf_module_notify()
7113 err = PTR_ERR(btf); in btf_module_notify()
7116 err = btf_alloc_id(btf); in btf_module_notify()
7118 btf_free(btf); in btf_module_notify()
7126 btf_mod->btf = btf; in btf_module_notify()
7138 attr->attr.name = btf->name; in btf_module_notify()
7140 attr->size = btf->data_size; in btf_module_notify()
7141 attr->private = btf; in btf_module_notify()
7177 purge_cand_cache(btf_mod->btf); in btf_module_notify()
7178 btf_put(btf_mod->btf); in btf_module_notify()
7203 struct module *btf_try_get_module(const struct btf *btf) in btf_try_get_module() argument
7211 if (btf_mod->btf != btf) in btf_try_get_module()
7233 static struct btf *btf_get_module_btf(const struct module *module) in btf_get_module_btf()
7238 struct btf *btf = NULL; in btf_get_module_btf() local
7241 btf = bpf_get_btf_vmlinux(); in btf_get_module_btf()
7242 if (!IS_ERR_OR_NULL(btf)) in btf_get_module_btf()
7243 btf_get(btf); in btf_get_module_btf()
7244 return btf; in btf_get_module_btf()
7253 btf_get(btf_mod->btf); in btf_get_module_btf()
7254 btf = btf_mod->btf; in btf_get_module_btf()
7260 return btf; in btf_get_module_btf()
7265 struct btf *btf = NULL; in BPF_CALL_4() local
7275 ret = bpf_find_btf_id(name, kind, &btf); in BPF_CALL_4()
7276 if (ret > 0 && btf_is_module(btf)) { in BPF_CALL_4()
7277 btf_obj_fd = __btf_new_fd(btf); in BPF_CALL_4()
7279 btf_put(btf); in BPF_CALL_4()
7285 btf_put(btf); in BPF_CALL_4()
7306 static int btf_populate_kfunc_set(struct btf *btf, enum btf_kfunc_hook hook, in BTF_ID_LIST_GLOBAL()
7309 bool vmlinux_set = !btf_is_module(btf); in BTF_ID_LIST_GLOBAL()
7323 tab = btf->kfunc_set_tab; in BTF_ID_LIST_GLOBAL()
7328 btf->kfunc_set_tab = tab; in BTF_ID_LIST_GLOBAL()
7390 btf_free_kfunc_set_tab(btf); in BTF_ID_LIST_GLOBAL()
7394 static u32 *__btf_kfunc_id_set_contains(const struct btf *btf, in __btf_kfunc_id_set_contains() argument
7403 if (!btf->kfunc_set_tab) in __btf_kfunc_id_set_contains()
7405 set = btf->kfunc_set_tab->sets[hook]; in __btf_kfunc_id_set_contains()
7441 u32 *btf_kfunc_id_set_contains(const struct btf *btf, in btf_kfunc_id_set_contains() argument
7448 return __btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id); in btf_kfunc_id_set_contains()
7456 struct btf *btf; in register_btf_kfunc_id_set() local
7459 btf = btf_get_module_btf(kset->owner); in register_btf_kfunc_id_set()
7460 if (!btf) { in register_btf_kfunc_id_set()
7471 if (IS_ERR(btf)) in register_btf_kfunc_id_set()
7472 return PTR_ERR(btf); in register_btf_kfunc_id_set()
7475 ret = btf_populate_kfunc_set(btf, hook, kset->set); in register_btf_kfunc_id_set()
7476 btf_put(btf); in register_btf_kfunc_id_set()
7481 s32 btf_find_dtor_kfunc(struct btf *btf, u32 btf_id) in btf_find_dtor_kfunc() argument
7483 struct btf_id_dtor_kfunc_tab *tab = btf->dtor_kfunc_tab; in btf_find_dtor_kfunc()
7498 static int btf_check_dtor_kfuncs(struct btf *btf, const struct btf_id_dtor_kfunc *dtors, u32 cnt) in btf_check_dtor_kfuncs() argument
7508 dtor_func = btf_type_by_id(btf, dtor_btf_id); in btf_check_dtor_kfuncs()
7512 dtor_func_proto = btf_type_by_id(btf, dtor_func->type); in btf_check_dtor_kfuncs()
7517 t = btf_type_by_id(btf, dtor_func_proto->type); in btf_check_dtor_kfuncs()
7525 t = btf_type_by_id(btf, args[0].type); in btf_check_dtor_kfuncs()
7540 struct btf *btf; in register_btf_id_dtor_kfuncs() local
7544 btf = btf_get_module_btf(owner); in register_btf_id_dtor_kfuncs()
7545 if (!btf) { in register_btf_id_dtor_kfuncs()
7556 if (IS_ERR(btf)) in register_btf_id_dtor_kfuncs()
7557 return PTR_ERR(btf); in register_btf_id_dtor_kfuncs()
7566 ret = btf_check_dtor_kfuncs(btf, dtors, add_cnt); in register_btf_id_dtor_kfuncs()
7570 tab = btf->dtor_kfunc_tab; in register_btf_id_dtor_kfuncs()
7572 if (WARN_ON_ONCE(tab && btf_is_module(btf))) { in register_btf_id_dtor_kfuncs()
7588 tab = krealloc(btf->dtor_kfunc_tab, in register_btf_id_dtor_kfuncs()
7596 if (!btf->dtor_kfunc_tab) in register_btf_id_dtor_kfuncs()
7598 btf->dtor_kfunc_tab = tab; in register_btf_id_dtor_kfuncs()
7607 btf_free_dtor_kfunc_tab(btf); in register_btf_id_dtor_kfuncs()
7608 btf_put(btf); in register_btf_id_dtor_kfuncs()
7634 int bpf_core_types_are_compat(const struct btf *local_btf, __u32 local_id, in bpf_core_types_are_compat()
7635 const struct btf *targ_btf, __u32 targ_id) in bpf_core_types_are_compat()
7643 int bpf_core_types_match(const struct btf *local_btf, u32 local_id, in bpf_core_types_match()
7644 const struct btf *targ_btf, u32 targ_id) in bpf_core_types_match()
7676 const struct btf *btf; member
7786 static void __purge_cand_cache(struct btf *btf, struct bpf_cand_cache **cache, in __purge_cand_cache() argument
7796 if (!btf) { in __purge_cand_cache()
7809 if (cc->cands[j].btf == btf) { in __purge_cand_cache()
7818 static void purge_cand_cache(struct btf *btf) in purge_cand_cache() argument
7821 __purge_cand_cache(btf, module_cand_cache, MODULE_CAND_CACHE_SIZE); in purge_cand_cache()
7827 bpf_core_add_cands(struct bpf_cand_cache *cands, const struct btf *targ_btf, in bpf_core_add_cands()
7868 cands->cands[cands->cnt].btf = targ_btf; in bpf_core_add_cands()
7879 const struct btf *local_btf = ctx->btf; in bpf_core_find_cands()
7881 const struct btf *main_btf; in bpf_core_find_cands()
7883 struct btf *mod_btf; in bpf_core_find_cands()
8004 cands.cands[i].btf = cc->cands[i].btf; in bpf_core_apply()
8015 err = bpf_core_calc_relo_insn((void *)ctx->log, relo, relo_idx, ctx->btf, &cands, specs, in bpf_core_apply()