Lines Matching refs:btf
201 struct btf { struct
217 struct btf *base_btf; argument
257 struct btf *btf; member
354 const struct btf *btf; member
393 void (*show)(const struct btf *btf, const struct btf_type *t,
463 u32 btf_nr_types(const struct btf *btf) in btf_nr_types() argument
467 while (btf) { in btf_nr_types()
468 total += btf->nr_types; in btf_nr_types()
469 btf = btf->base_btf; in btf_nr_types()
475 s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind) in btf_find_by_name_kind() argument
481 total = btf_nr_types(btf); in btf_find_by_name_kind()
483 t = btf_type_by_id(btf, i); in btf_find_by_name_kind()
487 tname = btf_name_by_offset(btf, t->name_off); in btf_find_by_name_kind()
495 const struct btf_type *btf_type_skip_modifiers(const struct btf *btf, in btf_type_skip_modifiers() argument
498 const struct btf_type *t = btf_type_by_id(btf, id); in btf_type_skip_modifiers()
502 t = btf_type_by_id(btf, t->type); in btf_type_skip_modifiers()
511 const struct btf_type *btf_type_resolve_ptr(const struct btf *btf, in btf_type_resolve_ptr() argument
516 t = btf_type_skip_modifiers(btf, id, NULL); in btf_type_resolve_ptr()
520 return btf_type_skip_modifiers(btf, t->type, res_id); in btf_type_resolve_ptr()
523 const struct btf_type *btf_type_resolve_func_ptr(const struct btf *btf, in btf_type_resolve_func_ptr() argument
528 ptype = btf_type_resolve_ptr(btf, id, res_id); in btf_type_resolve_func_ptr()
625 static bool btf_name_offset_valid(const struct btf *btf, u32 offset) in btf_name_offset_valid() argument
630 while (offset < btf->start_str_off) in btf_name_offset_valid()
631 btf = btf->base_btf; in btf_name_offset_valid()
633 offset -= btf->start_str_off; in btf_name_offset_valid()
634 return offset < btf->hdr.str_len; in btf_name_offset_valid()
647 static const char *btf_str_by_offset(const struct btf *btf, u32 offset) in btf_str_by_offset() argument
649 while (offset < btf->start_str_off) in btf_str_by_offset()
650 btf = btf->base_btf; in btf_str_by_offset()
652 offset -= btf->start_str_off; in btf_str_by_offset()
653 if (offset < btf->hdr.str_len) in btf_str_by_offset()
654 return &btf->strings[offset]; in btf_str_by_offset()
659 static bool __btf_name_valid(const struct btf *btf, u32 offset) in __btf_name_valid() argument
662 const char *src = btf_str_by_offset(btf, offset); in __btf_name_valid()
680 static bool btf_name_valid_identifier(const struct btf *btf, u32 offset) in btf_name_valid_identifier() argument
682 return __btf_name_valid(btf, offset); in btf_name_valid_identifier()
685 static bool btf_name_valid_section(const struct btf *btf, u32 offset) in btf_name_valid_section() argument
687 return __btf_name_valid(btf, offset); in btf_name_valid_section()
690 static const char *__btf_name_by_offset(const struct btf *btf, u32 offset) in __btf_name_by_offset() argument
697 name = btf_str_by_offset(btf, offset); in __btf_name_by_offset()
701 const char *btf_name_by_offset(const struct btf *btf, u32 offset) in btf_name_by_offset() argument
703 return btf_str_by_offset(btf, offset); in btf_name_by_offset()
706 const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id) in btf_type_by_id() argument
708 while (type_id < btf->start_id) in btf_type_by_id()
709 btf = btf->base_btf; in btf_type_by_id()
711 type_id -= btf->start_id; in btf_type_by_id()
712 if (type_id >= btf->nr_types) in btf_type_by_id()
714 return btf->types[type_id]; in btf_type_by_id()
744 bool btf_member_is_reg_int(const struct btf *btf, const struct btf_type *s, in btf_member_is_reg_int() argument
753 t = btf_type_id_size(btf, &id, NULL); in btf_member_is_reg_int()
782 static const struct btf_type *btf_type_skip_qualifiers(const struct btf *btf, in btf_type_skip_qualifiers() argument
785 const struct btf_type *t = btf_type_by_id(btf, id); in btf_type_skip_qualifiers()
789 t = btf_type_by_id(btf, t->type); in btf_type_skip_qualifiers()
835 member = btf_name_by_offset(show->btf, m->name_off); in btf_show_name()
847 t = btf_type_by_id(show->btf, id); in btf_show_name()
878 name = btf_name_by_offset(show->btf, in btf_show_name()
905 t = btf_type_skip_qualifiers(show->btf, id); in btf_show_name()
912 name = btf_name_by_offset(show->btf, t->name_off); in btf_show_name()
1100 rt = btf_resolve_size(show->btf, t, &size); in btf_show_obj_safe()
1293 struct btf *btf = env->btf; in __btf_verifier_log_type() local
1308 if (env->btf->base_btf && IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) in __btf_verifier_log_type()
1315 __btf_name_by_offset(btf, t->name_off), in __btf_verifier_log_type()
1343 struct btf *btf = env->btf; in btf_verifier_log_member() local
1354 if (env->btf->base_btf && IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH)) in btf_verifier_log_member()
1370 __btf_name_by_offset(btf, member->name_off), in btf_verifier_log_member()
1376 __btf_name_by_offset(btf, member->name_off), in btf_verifier_log_member()
1421 const struct btf *btf = env->btf; in btf_verifier_log_hdr() local
1429 hdr = &btf->hdr; in btf_verifier_log_hdr()
1443 struct btf *btf = env->btf; in btf_add_type() local
1445 if (btf->types_size == btf->nr_types) { in btf_add_type()
1451 if (btf->start_id + btf->types_size == BTF_MAX_TYPE) { in btf_add_type()
1456 expand_by = max_t(u32, btf->types_size >> 2, 16); in btf_add_type()
1458 btf->types_size + expand_by); in btf_add_type()
1465 if (btf->nr_types == 0) { in btf_add_type()
1466 if (!btf->base_btf) { in btf_add_type()
1469 btf->nr_types++; in btf_add_type()
1472 memcpy(new_types, btf->types, in btf_add_type()
1473 sizeof(*btf->types) * btf->nr_types); in btf_add_type()
1476 kvfree(btf->types); in btf_add_type()
1477 btf->types = new_types; in btf_add_type()
1478 btf->types_size = new_size; in btf_add_type()
1481 btf->types[btf->nr_types++] = t; in btf_add_type()
1486 static int btf_alloc_id(struct btf *btf) in btf_alloc_id() argument
1492 id = idr_alloc_cyclic(&btf_idr, btf, 1, INT_MAX, GFP_ATOMIC); in btf_alloc_id()
1494 btf->id = id; in btf_alloc_id()
1504 static void btf_free_id(struct btf *btf) in btf_free_id() argument
1518 idr_remove(&btf_idr, btf->id); in btf_free_id()
1522 static void btf_free(struct btf *btf) in btf_free() argument
1524 kvfree(btf->types); in btf_free()
1525 kvfree(btf->resolved_sizes); in btf_free()
1526 kvfree(btf->resolved_ids); in btf_free()
1527 kvfree(btf->data); in btf_free()
1528 kfree(btf); in btf_free()
1533 struct btf *btf = container_of(rcu, struct btf, rcu); in btf_free_rcu() local
1535 btf_free(btf); in btf_free_rcu()
1538 void btf_get(struct btf *btf) in btf_get() argument
1540 refcount_inc(&btf->refcnt); in btf_get()
1543 void btf_put(struct btf *btf) in btf_put() argument
1545 if (btf && refcount_dec_and_test(&btf->refcnt)) { in btf_put()
1546 btf_free_id(btf); in btf_put()
1547 call_rcu(&btf->rcu, btf_free_rcu); in btf_put()
1553 struct btf *btf = env->btf; in env_resolve_init() local
1554 u32 nr_types = btf->nr_types; in env_resolve_init()
1574 btf->resolved_sizes = resolved_sizes; in env_resolve_init()
1575 btf->resolved_ids = resolved_ids; in env_resolve_init()
1622 if (type_id < env->btf->start_id) in env_type_is_resolved()
1625 return env->visit_states[type_id - env->btf->start_id] == RESOLVED; in env_type_is_resolved()
1631 const struct btf *btf = env->btf; in env_stack_push() local
1637 if (type_id < btf->start_id in env_stack_push()
1638 || env->visit_states[type_id - btf->start_id] != NOT_VISITED) in env_stack_push()
1641 env->visit_states[type_id - btf->start_id] = VISITED; in env_stack_push()
1669 struct btf *btf = env->btf; in env_stack_pop_resolved() local
1671 type_id -= btf->start_id; /* adjust to local type id */ in env_stack_pop_resolved()
1672 btf->resolved_sizes[type_id] = resolved_size; in env_stack_pop_resolved()
1673 btf->resolved_ids[type_id] = resolved_type_id; in env_stack_pop_resolved()
1703 __btf_resolve_size(const struct btf *btf, const struct btf_type *type, in __btf_resolve_size() argument
1732 type = btf_type_by_id(btf, type->type); in __btf_resolve_size()
1742 type = btf_type_by_id(btf, array->type); in __btf_resolve_size()
1771 btf_resolve_size(const struct btf *btf, const struct btf_type *type, in btf_resolve_size() argument
1774 return __btf_resolve_size(btf, type, type_size, NULL, NULL, NULL, NULL); in btf_resolve_size()
1777 static u32 btf_resolved_type_id(const struct btf *btf, u32 type_id) in btf_resolved_type_id() argument
1779 while (type_id < btf->start_id) in btf_resolved_type_id()
1780 btf = btf->base_btf; in btf_resolved_type_id()
1782 return btf->resolved_ids[type_id - btf->start_id]; in btf_resolved_type_id()
1786 static const struct btf_type *btf_type_id_resolve(const struct btf *btf, in btf_type_id_resolve() argument
1789 *type_id = btf_resolved_type_id(btf, *type_id); in btf_type_id_resolve()
1790 return btf_type_by_id(btf, *type_id); in btf_type_id_resolve()
1793 static u32 btf_resolved_type_size(const struct btf *btf, u32 type_id) in btf_resolved_type_size() argument
1795 while (type_id < btf->start_id) in btf_resolved_type_size()
1796 btf = btf->base_btf; in btf_resolved_type_size()
1798 return btf->resolved_sizes[type_id - btf->start_id]; in btf_resolved_type_size()
1801 const struct btf_type *btf_type_id_size(const struct btf *btf, in btf_type_id_size() argument
1808 size_type = btf_type_by_id(btf, size_type_id); in btf_type_id_size()
1815 size = btf_resolved_type_size(btf, size_type_id); in btf_type_id_size()
1823 size_type_id = btf_resolved_type_id(btf, size_type_id); in btf_type_id_size()
1824 size_type = btf_type_by_id(btf, size_type_id); in btf_type_id_size()
1830 size = btf_resolved_type_size(btf, size_type_id); in btf_type_id_size()
1893 static void btf_df_show(const struct btf *btf, const struct btf_type *t, in btf_df_show() argument
2161 static void btf_int_bits_show(const struct btf *btf, in btf_int_bits_show() argument
2180 static void btf_int_show(const struct btf *btf, const struct btf_type *t, in btf_int_show() argument
2196 btf_int_bits_show(btf, t, safe_data, bits_offset, show); in btf_int_show()
2243 btf_int_bits_show(btf, t, safe_data, bits_offset, show); in btf_int_show()
2267 struct btf *btf = env->btf; in btf_modifier_check_member() local
2269 resolved_type = btf_type_id_size(btf, &resolved_type_id, NULL); in btf_modifier_check_member()
2292 struct btf *btf = env->btf; in btf_modifier_check_kflag_member() local
2294 resolved_type = btf_type_id_size(btf, &resolved_type_id, NULL); in btf_modifier_check_kflag_member()
2359 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_ref_type_check_meta()
2381 struct btf *btf = env->btf; in btf_modifier_resolve() local
2383 next_type = btf_type_by_id(btf, next_type_id); in btf_modifier_resolve()
2399 if (!btf_type_id_size(btf, &next_type_id, NULL)) { in btf_modifier_resolve()
2401 next_type = btf_type_id_resolve(btf, &next_type_id); in btf_modifier_resolve()
2423 struct btf *btf = env->btf; in btf_var_resolve() local
2425 next_type = btf_type_by_id(btf, next_type_id); in btf_var_resolve()
2440 resolved_type = btf_type_id_resolve(btf, &resolved_type_id); in btf_var_resolve()
2453 if (!btf_type_id_size(btf, &next_type_id, NULL)) { in btf_var_resolve()
2469 struct btf *btf = env->btf; in btf_ptr_resolve() local
2471 next_type = btf_type_by_id(btf, next_type_id); in btf_ptr_resolve()
2494 resolved_type = btf_type_id_resolve(btf, &resolved_type_id); in btf_ptr_resolve()
2503 if (!btf_type_id_size(btf, &next_type_id, NULL)) { in btf_ptr_resolve()
2505 next_type = btf_type_id_resolve(btf, &next_type_id); in btf_ptr_resolve()
2520 static void btf_modifier_show(const struct btf *btf, in btf_modifier_show() argument
2525 if (btf->resolved_ids) in btf_modifier_show()
2526 t = btf_type_id_resolve(btf, &type_id); in btf_modifier_show()
2528 t = btf_type_skip_modifiers(btf, type_id, NULL); in btf_modifier_show()
2530 btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show); in btf_modifier_show()
2533 static void btf_var_show(const struct btf *btf, const struct btf_type *t, in btf_var_show() argument
2537 t = btf_type_id_resolve(btf, &type_id); in btf_var_show()
2539 btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show); in btf_var_show()
2542 static void btf_ptr_show(const struct btf *btf, const struct btf_type *t, in btf_ptr_show() argument
2600 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_fwd_check_meta()
2633 struct btf *btf = env->btf; in btf_array_check_member() local
2642 btf_type_id_size(btf, &array_type_id, &array_size); in btf_array_check_member()
2713 struct btf *btf = env->btf; in btf_array_resolve() local
2718 index_type = btf_type_by_id(btf, index_type_id); in btf_array_resolve()
2729 index_type = btf_type_id_size(btf, &index_type_id, NULL); in btf_array_resolve()
2738 elem_type = btf_type_by_id(btf, elem_type_id); in btf_array_resolve()
2750 elem_type = btf_type_id_size(btf, &elem_type_id, &elem_size); in btf_array_resolve()
2781 static void __btf_array_show(const struct btf *btf, const struct btf_type *t, in __btf_array_show() argument
2792 elem_type = btf_type_skip_modifiers(btf, elem_type_id, NULL); in __btf_array_show()
2821 elem_ops->show(btf, elem_type, elem_type_id, data, in __btf_array_show()
2834 static void btf_array_show(const struct btf *btf, const struct btf_type *t, in btf_array_show() argument
2850 __btf_array_show(btf, t, type_id, data, bits_offset, show); in btf_array_show()
2864 __btf_array_show(btf, t, type_id, data, bits_offset, show); in btf_array_show()
2908 struct btf *btf = env->btf; in btf_struct_check_meta() local
2923 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_struct_check_meta()
2932 if (!btf_name_offset_valid(btf, member->name_off)) { in btf_struct_check_meta()
2941 !btf_name_valid_identifier(btf, member->name_off)) { in btf_struct_check_meta()
3004 last_member_type = btf_type_by_id(env->btf, in btf_struct_resolve()
3020 const struct btf_type *member_type = btf_type_by_id(env->btf, in btf_struct_resolve()
3059 static int btf_find_struct_field(const struct btf *btf, const struct btf_type *t, in btf_find_struct_field() argument
3066 const struct btf_type *member_type = btf_type_by_id(btf, in btf_find_struct_field()
3072 if (strcmp(__btf_name_by_offset(btf, member_type->name_off), name)) in btf_find_struct_field()
3088 static int btf_find_datasec_var(const struct btf *btf, const struct btf_type *t, in btf_find_datasec_var() argument
3095 const struct btf_type *var = btf_type_by_id(btf, vsi->type); in btf_find_datasec_var()
3096 const struct btf_type *var_type = btf_type_by_id(btf, var->type); in btf_find_datasec_var()
3104 if (strcmp(__btf_name_by_offset(btf, var_type->name_off), name)) in btf_find_datasec_var()
3116 static int btf_find_field(const struct btf *btf, const struct btf_type *t, in btf_find_field() argument
3121 return btf_find_struct_field(btf, t, name, sz, align); in btf_find_field()
3123 return btf_find_datasec_var(btf, t, name, sz, align); in btf_find_field()
3131 int btf_find_spin_lock(const struct btf *btf, const struct btf_type *t) in btf_find_spin_lock() argument
3133 return btf_find_field(btf, t, "bpf_spin_lock", in btf_find_spin_lock()
3138 int btf_find_timer(const struct btf *btf, const struct btf_type *t) in btf_find_timer() argument
3140 return btf_find_field(btf, t, "bpf_timer", in btf_find_timer()
3145 static void __btf_struct_show(const struct btf *btf, const struct btf_type *t, in __btf_struct_show() argument
3158 const struct btf_type *member_type = btf_type_by_id(btf, in __btf_struct_show()
3182 ops->show(btf, member_type, member->type, in __btf_struct_show()
3192 static void btf_struct_show(const struct btf *btf, const struct btf_type *t, in btf_struct_show() argument
3208 __btf_struct_show(btf, t, type_id, data, bits_offset, show); in btf_struct_show()
3223 __btf_struct_show(btf, t, type_id, data, bits_offset, show); in btf_struct_show()
3300 struct btf *btf = env->btf; in btf_enum_check_meta() local
3326 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_enum_check_meta()
3334 if (!btf_name_offset_valid(btf, enums[i].name_off)) { in btf_enum_check_meta()
3342 !btf_name_valid_identifier(btf, enums[i].name_off)) { in btf_enum_check_meta()
3350 __btf_name_by_offset(btf, enums[i].name_off), in btf_enum_check_meta()
3363 static void btf_enum_show(const struct btf *btf, const struct btf_type *t, in btf_enum_show() argument
3383 __btf_name_by_offset(btf, in btf_enum_show()
3450 __btf_name_by_offset(env->btf, in btf_func_proto_log()
3454 __btf_name_by_offset(env->btf, in btf_func_proto_log()
3462 __btf_name_by_offset(env->btf, in btf_func_proto_log()
3495 !btf_name_valid_identifier(env->btf, t->name_off)) { in btf_func_check_meta()
3549 !__btf_name_valid(env->btf, t->name_off)) { in btf_var_check_meta()
3615 !btf_name_valid_section(env->btf, t->name_off)) { in btf_datasec_check_meta()
3665 struct btf *btf = env->btf; in btf_datasec_resolve() local
3671 const struct btf_type *var_type = btf_type_by_id(env->btf, in btf_datasec_resolve()
3686 if (!btf_type_id_size(btf, &type_id, &type_size)) { in btf_datasec_resolve()
3707 static void btf_datasec_show(const struct btf *btf, in btf_datasec_show() argument
3720 __btf_name_by_offset(btf, t->name_off)); in btf_datasec_show()
3722 var = btf_type_by_id(btf, vsi->type); in btf_datasec_show()
3725 btf_type_ops(var)->show(btf, var, vsi->type, in btf_datasec_show()
3820 const struct btf *btf; in btf_func_proto_check() local
3824 btf = env->btf; in btf_func_proto_check()
3832 ret_type = btf_type_by_id(btf, ret_type_id); in btf_func_proto_check()
3846 if (!btf_type_id_size(btf, &ret_type_id, NULL)) { in btf_func_proto_check()
3871 arg_type = btf_type_by_id(btf, arg_type_id); in btf_func_proto_check()
3884 (!btf_name_offset_valid(btf, args[i].name_off) || in btf_func_proto_check()
3885 !btf_name_valid_identifier(btf, args[i].name_off))) { in btf_func_proto_check()
3899 if (!btf_type_id_size(btf, &arg_type_id, NULL)) { in btf_func_proto_check()
3914 const struct btf *btf; in btf_func_check() local
3917 btf = env->btf; in btf_func_check()
3918 proto_type = btf_type_by_id(btf, t->type); in btf_func_check()
3983 if (!btf_name_offset_valid(env->btf, t->name_off)) { in btf_check_meta()
4000 struct btf *btf = env->btf; in btf_check_all_metas() local
4004 hdr = &btf->hdr; in btf_check_all_metas()
4005 cur = btf->nohdr_data + hdr->type_off; in btf_check_all_metas()
4008 env->log_type_id = btf->base_btf ? btf->start_id : 1; in btf_check_all_metas()
4029 struct btf *btf = env->btf; in btf_resolve_valid() local
4035 return !btf_resolved_type_id(btf, type_id) && in btf_resolve_valid()
4036 !btf_resolved_type_size(btf, type_id); in btf_resolve_valid()
4040 t = btf_type_id_resolve(btf, &type_id); in btf_resolve_valid()
4053 elem_type = btf_type_id_size(btf, &elem_type_id, &elem_size); in btf_resolve_valid()
4056 btf_resolved_type_size(btf, type_id)); in btf_resolve_valid()
4097 struct btf *btf = env->btf; in btf_check_all_types() local
4107 for (i = btf->base_btf ? 0 : 1; i < btf->nr_types; i++) { in btf_check_all_types()
4108 type_id = btf->start_id + i; in btf_check_all_types()
4109 t = btf_type_by_id(btf, type_id); in btf_check_all_types()
4137 const struct btf_header *hdr = &env->btf->hdr; in btf_parse_type_sec()
4146 if (!env->btf->base_btf && !hdr->type_len) { in btf_parse_type_sec()
4161 struct btf *btf = env->btf; in btf_parse_str_sec() local
4164 hdr = &btf->hdr; in btf_parse_str_sec()
4165 start = btf->nohdr_data + hdr->str_off; in btf_parse_str_sec()
4168 if (end != btf->data + btf->data_size) { in btf_parse_str_sec()
4173 btf->strings = start; in btf_parse_str_sec()
4175 if (btf->base_btf && !hdr->str_len) in btf_parse_str_sec()
4181 if (!btf->base_btf && start[0]) { in btf_parse_str_sec()
4208 const struct btf *btf; in btf_check_sec_info() local
4210 btf = env->btf; in btf_check_sec_info()
4211 hdr = &btf->hdr; in btf_check_sec_info()
4259 struct btf *btf; in btf_parse_hdr() local
4262 btf = env->btf; in btf_parse_hdr()
4263 btf_data_size = btf->data_size; in btf_parse_hdr()
4271 hdr = btf->data; in btf_parse_hdr()
4279 if (hdr_len > sizeof(btf->hdr)) { in btf_parse_hdr()
4280 u8 *expected_zero = btf->data + sizeof(btf->hdr); in btf_parse_hdr()
4281 u8 *end = btf->data + hdr_len; in btf_parse_hdr()
4291 hdr_copy = min_t(u32, hdr_len, sizeof(btf->hdr)); in btf_parse_hdr()
4292 memcpy(&btf->hdr, btf->data, hdr_copy); in btf_parse_hdr()
4294 hdr = &btf->hdr; in btf_parse_hdr()
4313 if (!btf->base_btf && btf_data_size == hdr->hdr_len) { in btf_parse_hdr()
4325 static struct btf *btf_parse(bpfptr_t btf_data, u32 btf_data_size, in btf_parse()
4330 struct btf *btf = NULL; in btf_parse() local
4357 btf = kzalloc(sizeof(*btf), GFP_KERNEL | __GFP_NOWARN); in btf_parse()
4358 if (!btf) { in btf_parse()
4362 env->btf = btf; in btf_parse()
4370 btf->data = data; in btf_parse()
4371 btf->data_size = btf_data_size; in btf_parse()
4382 btf->nohdr_data = btf->data + btf->hdr.hdr_len; in btf_parse()
4398 refcount_set(&btf->refcnt, 1); in btf_parse()
4399 return btf; in btf_parse()
4403 if (btf) in btf_parse()
4404 btf_free(btf); in btf_parse()
4410 extern struct btf *btf_vmlinux;
4443 btf_get_prog_ctx_type(struct bpf_verifier_log *log, const struct btf *btf, in btf_get_prog_ctx_type() argument
4457 t = btf_type_by_id(btf, t->type); in btf_get_prog_ctx_type()
4459 t = btf_type_by_id(btf, t->type); in btf_get_prog_ctx_type()
4468 tname = btf_name_by_offset(btf, t->name_off); in btf_get_prog_ctx_type()
4520 static int btf_vmlinux_map_ids_init(const struct btf *btf, in btf_vmlinux_map_ids_init() argument
4534 btf_id = btf_find_by_name_kind(btf, ops->map_btf_name, in btf_vmlinux_map_ids_init()
4545 struct btf *btf, in btf_translate_to_vmlinux() argument
4552 prog_ctx_type = btf_get_prog_ctx_type(log, btf, t, prog_type, arg); in btf_translate_to_vmlinux()
4562 struct btf *btf_parse_vmlinux(void) in BTF_ID()
4566 struct btf *btf = NULL; in BTF_ID() local
4576 btf = kzalloc(sizeof(*btf), GFP_KERNEL | __GFP_NOWARN); in BTF_ID()
4577 if (!btf) { in BTF_ID()
4581 env->btf = btf; in BTF_ID()
4583 btf->data = __start_BTF; in BTF_ID()
4584 btf->data_size = __stop_BTF - __start_BTF; in BTF_ID()
4585 btf->kernel_btf = true; in BTF_ID()
4586 snprintf(btf->name, sizeof(btf->name), "vmlinux"); in BTF_ID()
4592 btf->nohdr_data = btf->data + btf->hdr.hdr_len; in BTF_ID()
4603 bpf_ctx_convert.t = btf_type_by_id(btf, bpf_ctx_convert_btf_id[0]); in BTF_ID()
4606 err = btf_vmlinux_map_ids_init(btf, log); in BTF_ID()
4610 bpf_struct_ops_init(btf, log); in BTF_ID()
4612 refcount_set(&btf->refcnt, 1); in BTF_ID()
4614 err = btf_alloc_id(btf); in BTF_ID()
4619 return btf; in BTF_ID()
4623 if (btf) { in BTF_ID()
4624 kvfree(btf->types); in BTF_ID()
4625 kfree(btf); in BTF_ID()
4632 static struct btf *btf_parse_module(const char *module_name, const void *data, unsigned int data_si… in btf_parse_module()
4636 struct btf *btf = NULL, *base_btf; in btf_parse_module() local
4652 btf = kzalloc(sizeof(*btf), GFP_KERNEL | __GFP_NOWARN); in btf_parse_module()
4653 if (!btf) { in btf_parse_module()
4657 env->btf = btf; in btf_parse_module()
4659 btf->base_btf = base_btf; in btf_parse_module()
4660 btf->start_id = base_btf->nr_types; in btf_parse_module()
4661 btf->start_str_off = base_btf->hdr.str_len; in btf_parse_module()
4662 btf->kernel_btf = true; in btf_parse_module()
4663 snprintf(btf->name, sizeof(btf->name), "%s", module_name); in btf_parse_module()
4665 btf->data = kvmalloc(data_size, GFP_KERNEL | __GFP_NOWARN); in btf_parse_module()
4666 if (!btf->data) { in btf_parse_module()
4670 memcpy(btf->data, data, data_size); in btf_parse_module()
4671 btf->data_size = data_size; in btf_parse_module()
4677 btf->nohdr_data = btf->data + btf->hdr.hdr_len; in btf_parse_module()
4688 refcount_set(&btf->refcnt, 1); in btf_parse_module()
4689 return btf; in btf_parse_module()
4693 if (btf) { in btf_parse_module()
4694 kvfree(btf->data); in btf_parse_module()
4695 kvfree(btf->types); in btf_parse_module()
4696 kfree(btf); in btf_parse_module()
4703 struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog) in bpf_prog_get_target_btf()
4708 return tgt_prog->aux->btf; in bpf_prog_get_target_btf()
4713 static bool is_string_ptr(struct btf *btf, const struct btf_type *t) in is_string_ptr() argument
4716 t = btf_type_by_id(btf, t->type); in is_string_ptr()
4720 t = btf_type_by_id(btf, t->type); in is_string_ptr()
4732 struct btf *btf = bpf_prog_get_target_btf(prog); in btf_ctx_access() local
4781 t = btf_type_by_id(btf, t->type); in btf_ctx_access()
4790 t = btf_type_skip_modifiers(btf, t->type, NULL); in btf_ctx_access()
4807 t = btf_type_by_id(btf, args[arg].type); in btf_ctx_access()
4812 t = btf_type_by_id(btf, t->type); in btf_ctx_access()
4820 __btf_name_by_offset(btf, t->name_off), in btf_ctx_access()
4846 if (is_string_ptr(btf, t)) in btf_ctx_access()
4860 info->btf = btf_vmlinux; in btf_ctx_access()
4875 ret = btf_translate_to_vmlinux(log, btf, t, tgt_type, arg); in btf_ctx_access()
4877 info->btf = btf_vmlinux; in btf_ctx_access()
4885 info->btf = btf; in btf_ctx_access()
4887 t = btf_type_by_id(btf, t->type); in btf_ctx_access()
4891 t = btf_type_by_id(btf, t->type); in btf_ctx_access()
4901 __btf_name_by_offset(btf, t->name_off)); in btf_ctx_access()
4912 static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf, in btf_struct_walk() argument
4923 tname = __btf_name_by_offset(btf, t->name_off); in btf_struct_walk()
4940 mtype = btf_type_skip_modifiers(btf, member->type, in btf_struct_walk()
4956 t = btf_type_skip_modifiers(btf, array_elem->type, in btf_struct_walk()
5014 mtype = btf_type_by_id(btf, member->type); in btf_struct_walk()
5015 mname = __btf_name_by_offset(btf, member->name_off); in btf_struct_walk()
5017 mtype = __btf_resolve_size(btf, mtype, &msize, in btf_struct_walk()
5112 stype = btf_type_skip_modifiers(btf, mtype->type, &id); in btf_struct_walk()
5138 int btf_struct_access(struct bpf_verifier_log *log, const struct btf *btf, in btf_struct_access() argument
5147 err = btf_struct_walk(log, btf, t, off, size, &id); in btf_struct_access()
5163 t = btf_type_by_id(btf, id); in btf_struct_access()
5184 static bool btf_types_are_same(const struct btf *btf1, u32 id1, in btf_types_are_same()
5185 const struct btf *btf2, u32 id2) in btf_types_are_same()
5195 const struct btf *btf, u32 id, int off, in btf_struct_ids_match() argument
5196 const struct btf *need_btf, u32 need_type_id) in btf_struct_ids_match()
5202 if (off == 0 && btf_types_are_same(btf, id, need_btf, need_type_id)) in btf_struct_ids_match()
5206 type = btf_type_by_id(btf, id); in btf_struct_ids_match()
5209 err = btf_struct_walk(log, btf, type, off, 1, &id); in btf_struct_ids_match()
5218 if (!btf_types_are_same(btf, id, need_btf, need_type_id)) { in btf_struct_ids_match()
5226 static int __get_type_size(struct btf *btf, u32 btf_id, in __get_type_size() argument
5234 t = btf_type_by_id(btf, btf_id); in __get_type_size()
5236 t = btf_type_by_id(btf, t->type); in __get_type_size()
5238 *bad_type = btf_type_by_id(btf, 0); in __get_type_size()
5251 struct btf *btf, in btf_distill_func_proto() argument
5279 ret = __get_type_size(btf, func->type, &t); in btf_distill_func_proto()
5295 ret = __get_type_size(btf, args[i].type, &t); in btf_distill_func_proto()
5323 struct btf *btf1, const struct btf_type *t1, in btf_check_func_type_match()
5324 struct btf *btf2, const struct btf_type *t2) in btf_check_func_type_match()
5434 struct btf *btf2, const struct btf_type *t2) in btf_check_type_match()
5436 struct btf *btf1 = prog->aux->btf; in btf_check_type_match()
5465 const struct btf *btf, u32 func_id, in btf_check_func_arg_match() argument
5477 t = btf_type_by_id(btf, func_id); in btf_check_func_arg_match()
5486 func_name = btf_name_by_offset(btf, t->name_off); in btf_check_func_arg_match()
5488 t = btf_type_by_id(btf, t->type); in btf_check_func_arg_match()
5508 t = btf_type_skip_modifiers(btf, args[i].type, NULL); in btf_check_func_arg_match()
5522 ref_t = btf_type_skip_modifiers(btf, t->type, &ref_id); in btf_check_func_arg_match()
5523 ref_tname = btf_name_by_offset(btf, ref_t->name_off); in btf_check_func_arg_match()
5524 if (btf_is_kernel(btf)) { in btf_check_func_arg_match()
5526 const struct btf *reg_btf; in btf_check_func_arg_match()
5538 reg_btf = reg->btf; in btf_check_func_arg_match()
5555 reg->off, btf, ref_id)) { in btf_check_func_arg_match()
5563 } else if (btf_get_prog_ctx_type(log, btf, t, prog_type, i)) { in btf_check_func_arg_match()
5579 resolve_ret = btf_resolve_size(btf, ref_t, &type_size); in btf_check_func_arg_match()
5609 struct btf *btf = prog->aux->btf; in btf_check_subprog_arg_match() local
5625 err = btf_check_func_arg_match(env, btf, btf_id, regs, is_global); in btf_check_subprog_arg_match()
5637 const struct btf *btf, u32 func_id, in btf_check_kfunc_arg_match() argument
5640 return btf_check_func_arg_match(env, btf, func_id, regs, false); in btf_check_kfunc_arg_match()
5656 struct btf *btf = prog->aux->btf; in btf_prepare_func_args() local
5674 t = btf_type_by_id(btf, btf_id); in btf_prepare_func_args()
5683 tname = btf_name_by_offset(btf, t->name_off); in btf_prepare_func_args()
5696 t = btf_type_by_id(btf, t->type); in btf_prepare_func_args()
5709 t = btf_type_by_id(btf, t->type); in btf_prepare_func_args()
5711 t = btf_type_by_id(btf, t->type); in btf_prepare_func_args()
5724 t = btf_type_by_id(btf, args[i].type); in btf_prepare_func_args()
5726 t = btf_type_by_id(btf, t->type); in btf_prepare_func_args()
5732 if (btf_get_prog_ctx_type(log, btf, t, prog_type, i)) { in btf_prepare_func_args()
5737 t = btf_type_skip_modifiers(btf, t->type, NULL); in btf_prepare_func_args()
5739 ref_t = btf_resolve_size(btf, t, ®->mem_size); in btf_prepare_func_args()
5743 i, btf_type_str(t), btf_name_by_offset(btf, t->name_off), in btf_prepare_func_args()
5760 static void btf_type_show(const struct btf *btf, u32 type_id, void *obj, in btf_type_show() argument
5763 const struct btf_type *t = btf_type_by_id(btf, type_id); in btf_type_show()
5765 show->btf = btf; in btf_type_show()
5769 btf_type_ops(t)->show(btf, t, type_id, obj, 0, show); in btf_type_show()
5778 int btf_type_seq_show_flags(const struct btf *btf, u32 type_id, in btf_type_seq_show_flags() argument
5787 btf_type_show(btf, type_id, obj, &sseq); in btf_type_seq_show_flags()
5792 void btf_type_seq_show(const struct btf *btf, u32 type_id, void *obj, in btf_type_seq_show() argument
5795 (void) btf_type_seq_show_flags(btf, type_id, obj, m, in btf_type_seq_show()
5828 int btf_type_snprintf_show(const struct btf *btf, u32 type_id, void *obj, in btf_type_snprintf_show() argument
5839 btf_type_show(btf, type_id, obj, (struct btf_show *)&ssnprintf); in btf_type_snprintf_show()
5852 const struct btf *btf = filp->private_data; in bpf_btf_show_fdinfo() local
5854 seq_printf(m, "btf_id:\t%u\n", btf->id); in bpf_btf_show_fdinfo()
5871 static int __btf_new_fd(struct btf *btf) in __btf_new_fd() argument
5873 return anon_inode_getfd("btf", &btf_fops, btf, O_RDONLY | O_CLOEXEC); in __btf_new_fd()
5878 struct btf *btf; in btf_new_fd() local
5881 btf = btf_parse(make_bpfptr(attr->btf, uattr.is_kernel), in btf_new_fd()
5885 if (IS_ERR(btf)) in btf_new_fd()
5886 return PTR_ERR(btf); in btf_new_fd()
5888 ret = btf_alloc_id(btf); in btf_new_fd()
5890 btf_free(btf); in btf_new_fd()
5900 ret = __btf_new_fd(btf); in btf_new_fd()
5902 btf_put(btf); in btf_new_fd()
5907 struct btf *btf_get_by_fd(int fd) in btf_get_by_fd()
5909 struct btf *btf; in btf_get_by_fd() local
5922 btf = f.file->private_data; in btf_get_by_fd()
5923 refcount_inc(&btf->refcnt); in btf_get_by_fd()
5926 return btf; in btf_get_by_fd()
5929 int btf_get_info_by_fd(const struct btf *btf, in btf_get_info_by_fd() argument
5949 info.id = btf->id; in btf_get_info_by_fd()
5950 ubtf = u64_to_user_ptr(info.btf); in btf_get_info_by_fd()
5951 btf_copy = min_t(u32, btf->data_size, info.btf_size); in btf_get_info_by_fd()
5952 if (copy_to_user(ubtf, btf->data, btf_copy)) in btf_get_info_by_fd()
5954 info.btf_size = btf->data_size; in btf_get_info_by_fd()
5956 info.kernel_btf = btf->kernel_btf; in btf_get_info_by_fd()
5963 name_len = strlen(btf->name); in btf_get_info_by_fd()
5968 if (copy_to_user(uname, btf->name, name_len + 1)) in btf_get_info_by_fd()
5973 if (copy_to_user(uname, btf->name, uname_len - 1)) in btf_get_info_by_fd()
5991 struct btf *btf; in btf_get_fd_by_id() local
5995 btf = idr_find(&btf_idr, id); in btf_get_fd_by_id()
5996 if (!btf || !refcount_inc_not_zero(&btf->refcnt)) in btf_get_fd_by_id()
5997 btf = ERR_PTR(-ENOENT); in btf_get_fd_by_id()
6000 if (IS_ERR(btf)) in btf_get_fd_by_id()
6001 return PTR_ERR(btf); in btf_get_fd_by_id()
6003 fd = __btf_new_fd(btf); in btf_get_fd_by_id()
6005 btf_put(btf); in btf_get_fd_by_id()
6010 u32 btf_obj_id(const struct btf *btf) in btf_obj_id() argument
6012 return btf->id; in btf_obj_id()
6015 bool btf_is_kernel(const struct btf *btf) in btf_is_kernel() argument
6017 return btf->kernel_btf; in btf_is_kernel()
6020 bool btf_is_module(const struct btf *btf) in btf_is_module() argument
6022 return btf->kernel_btf && strcmp(btf->name, "vmlinux") != 0; in btf_is_module()
6045 struct btf *btf; member
6058 const struct btf *btf = bin_attr->private; in btf_module_read() local
6060 memcpy(buf, btf->data + off, len); in btf_module_read()
6069 struct btf *btf; in btf_module_notify() local
6084 btf = btf_parse_module(mod->name, mod->btf_data, mod->btf_data_size); in btf_module_notify()
6085 if (IS_ERR(btf)) { in btf_module_notify()
6089 mod->name, PTR_ERR(btf)); in btf_module_notify()
6090 err = PTR_ERR(btf); in btf_module_notify()
6096 err = btf_alloc_id(btf); in btf_module_notify()
6098 btf_free(btf); in btf_module_notify()
6105 btf_mod->btf = btf; in btf_module_notify()
6117 attr->attr.name = btf->name; in btf_module_notify()
6119 attr->size = btf->data_size; in btf_module_notify()
6120 attr->private = btf; in btf_module_notify()
6156 btf_put(btf_mod->btf); in btf_module_notify()
6181 struct module *btf_try_get_module(const struct btf *btf) in btf_try_get_module() argument
6189 if (btf_mod->btf != btf) in btf_try_get_module()
6210 struct btf *btf; in BPF_CALL_4() local
6219 btf = bpf_get_btf_vmlinux(); in BPF_CALL_4()
6220 if (IS_ERR(btf)) in BPF_CALL_4()
6221 return PTR_ERR(btf); in BPF_CALL_4()
6223 ret = btf_find_by_name_kind(btf, name, kind); in BPF_CALL_4()
6228 struct btf *mod_btf; in BPF_CALL_4()