Lines Matching refs:prog

2050 static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog)  in find_prog_type()  argument
2061 if (!bpf_prog_is_offloaded(prog->aux)) in find_prog_type()
2062 prog->aux->ops = ops; in find_prog_type()
2064 prog->aux->ops = &bpf_offload_prog_ops; in find_prog_type()
2065 prog->type = type; in find_prog_type()
2080 static void bpf_audit_prog(const struct bpf_prog *prog, unsigned int op) in bpf_audit_prog() argument
2095 prog->aux->id, bpf_audit_str[op]); in bpf_audit_prog()
2099 static int bpf_prog_alloc_id(struct bpf_prog *prog) in bpf_prog_alloc_id() argument
2105 id = idr_alloc_cyclic(&prog_idr, prog, 1, INT_MAX, GFP_ATOMIC); in bpf_prog_alloc_id()
2107 prog->aux->id = id; in bpf_prog_alloc_id()
2118 void bpf_prog_free_id(struct bpf_prog *prog) in bpf_prog_free_id() argument
2127 if (!prog->aux->id) in bpf_prog_free_id()
2131 idr_remove(&prog_idr, prog->aux->id); in bpf_prog_free_id()
2132 prog->aux->id = 0; in bpf_prog_free_id()
2144 bpf_prog_free(aux->prog); in __bpf_prog_put_rcu()
2147 static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred) in __bpf_prog_put_noref() argument
2149 bpf_prog_kallsyms_del_all(prog); in __bpf_prog_put_noref()
2150 btf_put(prog->aux->btf); in __bpf_prog_put_noref()
2151 module_put(prog->aux->mod); in __bpf_prog_put_noref()
2152 kvfree(prog->aux->jited_linfo); in __bpf_prog_put_noref()
2153 kvfree(prog->aux->linfo); in __bpf_prog_put_noref()
2154 kfree(prog->aux->kfunc_tab); in __bpf_prog_put_noref()
2155 if (prog->aux->attach_btf) in __bpf_prog_put_noref()
2156 btf_put(prog->aux->attach_btf); in __bpf_prog_put_noref()
2159 if (prog->aux->sleepable) in __bpf_prog_put_noref()
2160 call_rcu_tasks_trace(&prog->aux->rcu, __bpf_prog_put_rcu); in __bpf_prog_put_noref()
2162 call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu); in __bpf_prog_put_noref()
2164 __bpf_prog_put_rcu(&prog->aux->rcu); in __bpf_prog_put_noref()
2171 struct bpf_prog *prog; in bpf_prog_put_deferred() local
2174 prog = aux->prog; in bpf_prog_put_deferred()
2175 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_UNLOAD, 0); in bpf_prog_put_deferred()
2176 bpf_audit_prog(prog, BPF_AUDIT_UNLOAD); in bpf_prog_put_deferred()
2177 bpf_prog_free_id(prog); in bpf_prog_put_deferred()
2178 __bpf_prog_put_noref(prog, true); in bpf_prog_put_deferred()
2181 static void __bpf_prog_put(struct bpf_prog *prog) in __bpf_prog_put() argument
2183 struct bpf_prog_aux *aux = prog->aux; in __bpf_prog_put()
2195 void bpf_prog_put(struct bpf_prog *prog) in bpf_prog_put() argument
2197 __bpf_prog_put(prog); in bpf_prog_put()
2203 struct bpf_prog *prog = filp->private_data; in bpf_prog_release() local
2205 bpf_prog_put(prog); in bpf_prog_release()
2215 void notrace bpf_prog_inc_misses_counter(struct bpf_prog *prog) in bpf_prog_inc_misses_counter() argument
2220 stats = this_cpu_ptr(prog->stats); in bpf_prog_inc_misses_counter()
2226 static void bpf_prog_get_stats(const struct bpf_prog *prog, in bpf_prog_get_stats() argument
2237 st = per_cpu_ptr(prog->stats, cpu); in bpf_prog_get_stats()
2256 const struct bpf_prog *prog = filp->private_data; in bpf_prog_show_fdinfo() local
2257 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; in bpf_prog_show_fdinfo()
2260 bpf_prog_get_stats(prog, &stats); in bpf_prog_show_fdinfo()
2261 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); in bpf_prog_show_fdinfo()
2272 prog->type, in bpf_prog_show_fdinfo()
2273 prog->jited, in bpf_prog_show_fdinfo()
2275 prog->pages * 1ULL << PAGE_SHIFT, in bpf_prog_show_fdinfo()
2276 prog->aux->id, in bpf_prog_show_fdinfo()
2280 prog->aux->verified_insns); in bpf_prog_show_fdinfo()
2293 int bpf_prog_new_fd(struct bpf_prog *prog) in bpf_prog_new_fd() argument
2297 ret = security_bpf_prog(prog); in bpf_prog_new_fd()
2301 return anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog, in bpf_prog_new_fd()
2317 void bpf_prog_add(struct bpf_prog *prog, int i) in bpf_prog_add() argument
2319 atomic64_add(i, &prog->aux->refcnt); in bpf_prog_add()
2323 void bpf_prog_sub(struct bpf_prog *prog, int i) in bpf_prog_sub() argument
2330 WARN_ON(atomic64_sub_return(i, &prog->aux->refcnt) == 0); in bpf_prog_sub()
2334 void bpf_prog_inc(struct bpf_prog *prog) in bpf_prog_inc() argument
2336 atomic64_inc(&prog->aux->refcnt); in bpf_prog_inc()
2341 struct bpf_prog *bpf_prog_inc_not_zero(struct bpf_prog *prog) in bpf_prog_inc_not_zero() argument
2345 refold = atomic64_fetch_add_unless(&prog->aux->refcnt, 1, 0); in bpf_prog_inc_not_zero()
2350 return prog; in bpf_prog_inc_not_zero()
2354 bool bpf_prog_get_ok(struct bpf_prog *prog, in bpf_prog_get_ok() argument
2361 if (prog->type != *attach_type) in bpf_prog_get_ok()
2363 if (bpf_prog_is_offloaded(prog->aux) && !attach_drv) in bpf_prog_get_ok()
2373 struct bpf_prog *prog; in __bpf_prog_get() local
2375 prog = ____bpf_prog_get(f); in __bpf_prog_get()
2376 if (IS_ERR(prog)) in __bpf_prog_get()
2377 return prog; in __bpf_prog_get()
2378 if (!bpf_prog_get_ok(prog, attach_type, attach_drv)) { in __bpf_prog_get()
2379 prog = ERR_PTR(-EINVAL); in __bpf_prog_get()
2383 bpf_prog_inc(prog); in __bpf_prog_get()
2386 return prog; in __bpf_prog_get()
2589 struct bpf_prog *prog, *dst_prog = NULL; in bpf_prog_load() local
2674 prog = bpf_prog_alloc(bpf_prog_size(attr->insn_cnt), GFP_USER); in bpf_prog_load()
2675 if (!prog) { in bpf_prog_load()
2683 prog->expected_attach_type = attr->expected_attach_type; in bpf_prog_load()
2684 prog->aux->attach_btf = attach_btf; in bpf_prog_load()
2685 prog->aux->attach_btf_id = attr->attach_btf_id; in bpf_prog_load()
2686 prog->aux->dst_prog = dst_prog; in bpf_prog_load()
2687 prog->aux->dev_bound = !!attr->prog_ifindex; in bpf_prog_load()
2688 prog->aux->sleepable = attr->prog_flags & BPF_F_SLEEPABLE; in bpf_prog_load()
2689 prog->aux->xdp_has_frags = attr->prog_flags & BPF_F_XDP_HAS_FRAGS; in bpf_prog_load()
2691 err = security_bpf_prog_alloc(prog->aux); in bpf_prog_load()
2695 prog->aux->user = get_current_user(); in bpf_prog_load()
2696 prog->len = attr->insn_cnt; in bpf_prog_load()
2699 if (copy_from_bpfptr(prog->insns, in bpf_prog_load()
2701 bpf_prog_insn_size(prog)) != 0) in bpf_prog_load()
2711 prog->gpl_compatible = license_is_gpl_compatible(license) ? 1 : 0; in bpf_prog_load()
2713 prog->orig_prog = NULL; in bpf_prog_load()
2714 prog->jited = 0; in bpf_prog_load()
2716 atomic64_set(&prog->aux->refcnt, 1); in bpf_prog_load()
2718 if (bpf_prog_is_dev_bound(prog->aux)) { in bpf_prog_load()
2719 err = bpf_prog_dev_bound_init(prog, attr); in bpf_prog_load()
2726 err = bpf_prog_dev_bound_inherit(prog, dst_prog); in bpf_prog_load()
2732 err = find_prog_type(type, prog); in bpf_prog_load()
2736 prog->aux->load_time = ktime_get_boottime_ns(); in bpf_prog_load()
2737 err = bpf_obj_name_cpy(prog->aux->name, attr->prog_name, in bpf_prog_load()
2743 err = bpf_check(&prog, attr, uattr, uattr_size); in bpf_prog_load()
2747 prog = bpf_prog_select_runtime(prog, &err); in bpf_prog_load()
2751 err = bpf_prog_alloc_id(prog); in bpf_prog_load()
2769 bpf_prog_kallsyms_add(prog); in bpf_prog_load()
2770 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_LOAD, 0); in bpf_prog_load()
2771 bpf_audit_prog(prog, BPF_AUDIT_LOAD); in bpf_prog_load()
2773 err = bpf_prog_new_fd(prog); in bpf_prog_load()
2775 bpf_prog_put(prog); in bpf_prog_load()
2783 __bpf_prog_put_noref(prog, prog->aux->func_cnt); in bpf_prog_load()
2786 free_uid(prog->aux->user); in bpf_prog_load()
2787 security_bpf_prog_free(prog->aux); in bpf_prog_load()
2789 if (prog->aux->attach_btf) in bpf_prog_load()
2790 btf_put(prog->aux->attach_btf); in bpf_prog_load()
2791 bpf_prog_free(prog); in bpf_prog_load()
2831 const struct bpf_link_ops *ops, struct bpf_prog *prog) in bpf_link_init() argument
2838 link->prog = prog; in bpf_link_init()
2862 primer->link->prog = NULL; in bpf_link_cleanup()
2896 if (link->prog) { in bpf_link_free()
2897 sleepable = link->prog->aux->sleepable; in bpf_link_free()
2900 bpf_prog_put(link->prog); in bpf_link_free()
2965 const struct bpf_prog *prog = link->prog; in bpf_link_show_fdinfo() local
2966 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; in bpf_link_show_fdinfo()
2973 if (prog) { in bpf_link_show_fdinfo()
2974 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); in bpf_link_show_fdinfo()
2979 prog->aux->id); in bpf_link_show_fdinfo()
3150 static int bpf_tracing_prog_attach(struct bpf_prog *prog, in bpf_tracing_prog_attach() argument
3162 switch (prog->type) { in bpf_tracing_prog_attach()
3164 if (prog->expected_attach_type != BPF_TRACE_FENTRY && in bpf_tracing_prog_attach()
3165 prog->expected_attach_type != BPF_TRACE_FEXIT && in bpf_tracing_prog_attach()
3166 prog->expected_attach_type != BPF_MODIFY_RETURN) { in bpf_tracing_prog_attach()
3172 if (prog->expected_attach_type != 0) { in bpf_tracing_prog_attach()
3178 if (prog->expected_attach_type != BPF_LSM_MAC) { in bpf_tracing_prog_attach()
3195 if (prog->type != BPF_PROG_TYPE_EXT) { in bpf_tracing_prog_attach()
3216 &bpf_tracing_link_lops, prog); in bpf_tracing_prog_attach()
3217 link->attach_type = prog->expected_attach_type; in bpf_tracing_prog_attach()
3220 mutex_lock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3244 if (!prog->aux->dst_trampoline && !tgt_prog) { in bpf_tracing_prog_attach()
3251 if (prog->type != BPF_PROG_TYPE_TRACING && in bpf_tracing_prog_attach()
3252 prog->type != BPF_PROG_TYPE_LSM) { in bpf_tracing_prog_attach()
3257 if (!prog->aux->attach_btf) { in bpf_tracing_prog_attach()
3261 btf_id = prog->aux->attach_btf_id; in bpf_tracing_prog_attach()
3262 key = bpf_trampoline_compute_key(NULL, prog->aux->attach_btf, btf_id); in bpf_tracing_prog_attach()
3265 if (!prog->aux->dst_trampoline || in bpf_tracing_prog_attach()
3266 (key && key != prog->aux->dst_trampoline->key)) { in bpf_tracing_prog_attach()
3273 err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id, in bpf_tracing_prog_attach()
3279 module_put(prog->aux->mod); in bpf_tracing_prog_attach()
3280 prog->aux->mod = tgt_info.tgt_mod; in bpf_tracing_prog_attach()
3296 tr = prog->aux->dst_trampoline; in bpf_tracing_prog_attach()
3297 tgt_prog = prog->aux->dst_prog; in bpf_tracing_prog_attach()
3318 if (prog->aux->dst_prog && in bpf_tracing_prog_attach()
3319 (tgt_prog_fd || tr != prog->aux->dst_trampoline)) in bpf_tracing_prog_attach()
3321 bpf_prog_put(prog->aux->dst_prog); in bpf_tracing_prog_attach()
3322 if (prog->aux->dst_trampoline && tr != prog->aux->dst_trampoline) in bpf_tracing_prog_attach()
3324 bpf_trampoline_put(prog->aux->dst_trampoline); in bpf_tracing_prog_attach()
3326 prog->aux->dst_prog = NULL; in bpf_tracing_prog_attach()
3327 prog->aux->dst_trampoline = NULL; in bpf_tracing_prog_attach()
3328 mutex_unlock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3332 if (tr && tr != prog->aux->dst_trampoline) in bpf_tracing_prog_attach()
3334 mutex_unlock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3352 bpf_probe_unregister(raw_tp->btp, raw_tp->link.prog); in bpf_raw_tp_link_release()
3576 switch (event->prog->type) { in bpf_perf_link_fill_link_info()
3594 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_perf_link_attach() argument
3614 bpf_link_init(&link->link, BPF_LINK_TYPE_PERF_EVENT, &bpf_perf_link_lops, prog); in bpf_perf_link_attach()
3624 err = perf_event_set_bpf_prog(event, prog, attr->link_create.perf_event.bpf_cookie); in bpf_perf_link_attach()
3630 bpf_prog_inc(prog); in bpf_perf_link_attach()
3639 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_perf_link_attach() argument
3645 static int bpf_raw_tp_link_attach(struct bpf_prog *prog, in bpf_raw_tp_link_attach() argument
3655 switch (prog->type) { in bpf_raw_tp_link_attach()
3664 if (prog->type == BPF_PROG_TYPE_TRACING && in bpf_raw_tp_link_attach()
3665 prog->expected_attach_type == BPF_TRACE_RAW_TP) { in bpf_raw_tp_link_attach()
3666 tp_name = prog->aux->attach_func_name; in bpf_raw_tp_link_attach()
3669 return bpf_tracing_prog_attach(prog, 0, 0, 0); in bpf_raw_tp_link_attach()
3691 &bpf_raw_tp_link_lops, prog); in bpf_raw_tp_link_attach()
3700 err = bpf_probe_register(link->btp, prog); in bpf_raw_tp_link_attach()
3717 struct bpf_prog *prog; in bpf_raw_tracepoint_open() local
3723 prog = bpf_prog_get(attr->raw_tracepoint.prog_fd); in bpf_raw_tracepoint_open()
3724 if (IS_ERR(prog)) in bpf_raw_tracepoint_open()
3725 return PTR_ERR(prog); in bpf_raw_tracepoint_open()
3727 fd = bpf_raw_tp_link_attach(prog, u64_to_user_ptr(attr->raw_tracepoint.name)); in bpf_raw_tracepoint_open()
3729 bpf_prog_put(prog); in bpf_raw_tracepoint_open()
3799 static int bpf_prog_attach_check_attach_type(const struct bpf_prog *prog, in bpf_prog_attach_check_attach_type() argument
3804 switch (prog->type) { in bpf_prog_attach_check_attach_type()
3809 return attach_type == prog->expected_attach_type ? 0 : -EINVAL; in bpf_prog_attach_check_attach_type()
3818 if (prog->type != ptype) in bpf_prog_attach_check_attach_type()
3821 return prog->enforce_expected_attach_type && in bpf_prog_attach_check_attach_type()
3822 prog->expected_attach_type != attach_type ? in bpf_prog_attach_check_attach_type()
3836 if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI && in bpf_prog_attach_check_attach_type()
3839 if (prog->expected_attach_type == BPF_TRACE_UPROBE_MULTI && in bpf_prog_attach_check_attach_type()
3854 if (ptype == BPF_PROG_TYPE_UNSPEC || ptype != prog->type) in bpf_prog_attach_check_attach_type()
3877 struct bpf_prog *prog; in bpf_prog_attach() local
3897 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); in bpf_prog_attach()
3898 if (IS_ERR(prog)) in bpf_prog_attach()
3899 return PTR_ERR(prog); in bpf_prog_attach()
3901 if (bpf_prog_attach_check_attach_type(prog, attr->attach_type)) { in bpf_prog_attach()
3902 bpf_prog_put(prog); in bpf_prog_attach()
3909 ret = sock_map_get_from_fd(attr, prog); in bpf_prog_attach()
3912 ret = lirc_prog_attach(attr, prog); in bpf_prog_attach()
3915 ret = netns_bpf_prog_attach(attr, prog); in bpf_prog_attach()
3926 prog->expected_attach_type != BPF_LSM_CGROUP) in bpf_prog_attach()
3929 ret = cgroup_bpf_prog_attach(attr, ptype, prog); in bpf_prog_attach()
3932 ret = tcx_prog_attach(attr, prog); in bpf_prog_attach()
3939 bpf_prog_put(prog); in bpf_prog_attach()
3947 struct bpf_prog *prog = NULL; in bpf_prog_detach() local
3961 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); in bpf_prog_detach()
3962 if (IS_ERR(prog)) in bpf_prog_detach()
3963 return PTR_ERR(prog); in bpf_prog_detach()
3993 ret = tcx_prog_detach(attr, prog); in bpf_prog_detach()
3999 if (prog) in bpf_prog_detach()
4000 bpf_prog_put(prog); in bpf_prog_detach()
4065 struct bpf_prog *prog; in bpf_prog_test_run() local
4079 prog = bpf_prog_get(attr->test.prog_fd); in bpf_prog_test_run()
4080 if (IS_ERR(prog)) in bpf_prog_test_run()
4081 return PTR_ERR(prog); in bpf_prog_test_run()
4083 if (prog->aux->ops->test_run) in bpf_prog_test_run()
4084 ret = prog->aux->ops->test_run(prog, attr, uattr); in bpf_prog_test_run()
4086 bpf_prog_put(prog); in bpf_prog_test_run()
4139 struct bpf_prog *prog; in bpf_prog_get_curr_or_next() local
4143 prog = idr_get_next(&prog_idr, id); in bpf_prog_get_curr_or_next()
4144 if (prog) { in bpf_prog_get_curr_or_next()
4145 prog = bpf_prog_inc_not_zero(prog); in bpf_prog_get_curr_or_next()
4146 if (IS_ERR(prog)) { in bpf_prog_get_curr_or_next()
4153 return prog; in bpf_prog_get_curr_or_next()
4160 struct bpf_prog *prog; in bpf_prog_by_id() local
4166 prog = idr_find(&prog_idr, id); in bpf_prog_by_id()
4167 if (prog) in bpf_prog_by_id()
4168 prog = bpf_prog_inc_not_zero(prog); in bpf_prog_by_id()
4170 prog = ERR_PTR(-ENOENT); in bpf_prog_by_id()
4172 return prog; in bpf_prog_by_id()
4177 struct bpf_prog *prog; in bpf_prog_get_fd_by_id() local
4187 prog = bpf_prog_by_id(id); in bpf_prog_get_fd_by_id()
4188 if (IS_ERR(prog)) in bpf_prog_get_fd_by_id()
4189 return PTR_ERR(prog); in bpf_prog_get_fd_by_id()
4191 fd = bpf_prog_new_fd(prog); in bpf_prog_get_fd_by_id()
4193 bpf_prog_put(prog); in bpf_prog_get_fd_by_id()
4236 static const struct bpf_map *bpf_map_from_imm(const struct bpf_prog *prog, in bpf_map_from_imm() argument
4243 mutex_lock(&prog->aux->used_maps_mutex); in bpf_map_from_imm()
4244 for (i = 0, *off = 0; i < prog->aux->used_map_cnt; i++) { in bpf_map_from_imm()
4245 map = prog->aux->used_maps[i]; in bpf_map_from_imm()
4260 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_map_from_imm()
4264 static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog, in bpf_insn_prepare_dump() argument
4274 insns = kmemdup(prog->insnsi, bpf_prog_insn_size(prog), in bpf_insn_prepare_dump()
4279 for (i = 0; i < prog->len; i++) { in bpf_insn_prepare_dump()
4304 map = bpf_map_from_imm(prog, imm, &off, &type); in bpf_insn_prepare_dump()
4348 struct bpf_prog *prog, in bpf_prog_get_info_by_fd() argument
4353 struct btf *attach_btf = bpf_prog_get_target_btf(prog); in bpf_prog_get_info_by_fd()
4370 info.type = prog->type; in bpf_prog_get_info_by_fd()
4371 info.id = prog->aux->id; in bpf_prog_get_info_by_fd()
4372 info.load_time = prog->aux->load_time; in bpf_prog_get_info_by_fd()
4374 prog->aux->user->uid); in bpf_prog_get_info_by_fd()
4375 info.gpl_compatible = prog->gpl_compatible; in bpf_prog_get_info_by_fd()
4377 memcpy(info.tag, prog->tag, sizeof(prog->tag)); in bpf_prog_get_info_by_fd()
4378 memcpy(info.name, prog->aux->name, sizeof(prog->aux->name)); in bpf_prog_get_info_by_fd()
4380 mutex_lock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
4382 info.nr_map_ids = prog->aux->used_map_cnt; in bpf_prog_get_info_by_fd()
4389 if (put_user(prog->aux->used_maps[i]->id, in bpf_prog_get_info_by_fd()
4391 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
4395 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
4401 bpf_prog_get_stats(prog, &stats); in bpf_prog_get_info_by_fd()
4406 info.verified_insns = prog->aux->verified_insns; in bpf_prog_get_info_by_fd()
4420 info.xlated_prog_len = bpf_prog_insn_size(prog); in bpf_prog_get_info_by_fd()
4425 if (prog->blinded && !bpf_dump_raw_ok(file->f_cred)) { in bpf_prog_get_info_by_fd()
4429 insns_sanitized = bpf_insn_prepare_dump(prog, file->f_cred); in bpf_prog_get_info_by_fd()
4440 if (bpf_prog_is_offloaded(prog->aux)) { in bpf_prog_get_info_by_fd()
4441 err = bpf_prog_offload_info_fill(&info, prog); in bpf_prog_get_info_by_fd()
4452 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4456 for (i = 0; i < prog->aux->func_cnt; i++) in bpf_prog_get_info_by_fd()
4457 info.jited_prog_len += prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4459 info.jited_prog_len = prog->jited_len; in bpf_prog_get_info_by_fd()
4470 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4475 for (i = 0; i < prog->aux->func_cnt; i++) { in bpf_prog_get_info_by_fd()
4476 len = prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4478 img = (u8 *) prog->aux->func[i]->bpf_func; in bpf_prog_get_info_by_fd()
4487 if (copy_to_user(uinsns, prog->bpf_func, ulen)) in bpf_prog_get_info_by_fd()
4496 info.nr_jited_ksyms = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4508 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4511 prog->aux->func[i]->bpf_func; in bpf_prog_get_info_by_fd()
4517 ksym_addr = (unsigned long) prog->bpf_func; in bpf_prog_get_info_by_fd()
4527 info.nr_jited_func_lens = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4536 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4539 prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4544 func_len = prog->jited_len; in bpf_prog_get_info_by_fd()
4553 if (prog->aux->btf) in bpf_prog_get_info_by_fd()
4554 info.btf_id = btf_obj_id(prog->aux->btf); in bpf_prog_get_info_by_fd()
4555 info.attach_btf_id = prog->aux->attach_btf_id; in bpf_prog_get_info_by_fd()
4560 info.nr_func_info = prog->aux->func_info_cnt; in bpf_prog_get_info_by_fd()
4566 if (copy_to_user(user_finfo, prog->aux->func_info, in bpf_prog_get_info_by_fd()
4572 info.nr_line_info = prog->aux->nr_linfo; in bpf_prog_get_info_by_fd()
4578 if (copy_to_user(user_linfo, prog->aux->linfo, in bpf_prog_get_info_by_fd()
4584 if (prog->aux->jited_linfo) in bpf_prog_get_info_by_fd()
4585 info.nr_jited_line_info = prog->aux->nr_linfo; in bpf_prog_get_info_by_fd()
4597 line_addr = (unsigned long)prog->aux->jited_linfo[i]; in bpf_prog_get_info_by_fd()
4607 info.nr_prog_tags = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4614 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4617 prog->aux->func[i]->tag, in bpf_prog_get_info_by_fd()
4623 prog->tag, BPF_TAG_SIZE)) in bpf_prog_get_info_by_fd()
4718 if (link->prog) in bpf_link_get_info_by_fd()
4719 info.prog_id = link->prog->aux->id; in bpf_link_get_info_by_fd()
4884 raw_tp->link.prog->aux->id, in bpf_task_fd_query()
4975 struct bpf_prog *prog; in link_create() local
4984 prog = bpf_prog_get(attr->link_create.prog_fd); in link_create()
4985 if (IS_ERR(prog)) in link_create()
4986 return PTR_ERR(prog); in link_create()
4988 ret = bpf_prog_attach_check_attach_type(prog, in link_create()
4993 switch (prog->type) { in link_create()
5001 ret = cgroup_bpf_link_attach(attr, prog); in link_create()
5004 ret = bpf_tracing_prog_attach(prog, in link_create()
5011 if (attr->link_create.attach_type != prog->expected_attach_type) { in link_create()
5015 if (prog->expected_attach_type == BPF_TRACE_RAW_TP) in link_create()
5016 ret = bpf_raw_tp_link_attach(prog, NULL); in link_create()
5017 else if (prog->expected_attach_type == BPF_TRACE_ITER) in link_create()
5018 ret = bpf_iter_link_attach(attr, uattr, prog); in link_create()
5019 else if (prog->expected_attach_type == BPF_LSM_CGROUP) in link_create()
5020 ret = cgroup_bpf_link_attach(attr, prog); in link_create()
5022 ret = bpf_tracing_prog_attach(prog, in link_create()
5029 ret = netns_bpf_link_create(attr, prog); in link_create()
5033 ret = bpf_xdp_link_attach(attr, prog); in link_create()
5036 ret = tcx_link_attach(attr, prog); in link_create()
5039 ret = bpf_nf_link_attach(attr, prog); in link_create()
5044 ret = bpf_perf_link_attach(attr, prog); in link_create()
5048 ret = bpf_perf_link_attach(attr, prog); in link_create()
5050 ret = bpf_kprobe_multi_link_attach(attr, prog); in link_create()
5052 ret = bpf_uprobe_multi_link_attach(attr, prog); in link_create()
5060 bpf_prog_put(prog); in link_create()
5326 struct bpf_prog *prog; in bpf_prog_bind_map() local
5337 prog = bpf_prog_get(attr->prog_bind_map.prog_fd); in bpf_prog_bind_map()
5338 if (IS_ERR(prog)) in bpf_prog_bind_map()
5339 return PTR_ERR(prog); in bpf_prog_bind_map()
5347 mutex_lock(&prog->aux->used_maps_mutex); in bpf_prog_bind_map()
5349 used_maps_old = prog->aux->used_maps; in bpf_prog_bind_map()
5351 for (i = 0; i < prog->aux->used_map_cnt; i++) in bpf_prog_bind_map()
5357 used_maps_new = kmalloc_array(prog->aux->used_map_cnt + 1, in bpf_prog_bind_map()
5368 if (prog->aux->sleepable) in bpf_prog_bind_map()
5371 sizeof(used_maps_old[0]) * prog->aux->used_map_cnt); in bpf_prog_bind_map()
5372 used_maps_new[prog->aux->used_map_cnt] = map; in bpf_prog_bind_map()
5374 prog->aux->used_map_cnt++; in bpf_prog_bind_map()
5375 prog->aux->used_maps = used_maps_new; in bpf_prog_bind_map()
5380 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_bind_map()
5385 bpf_prog_put(prog); in bpf_prog_bind_map()
5537 const struct bpf_prog *prog, in syscall_prog_is_valid_access() argument
5576 struct bpf_prog * __maybe_unused prog; in kern_sys_bpf() local
5587 prog = bpf_prog_get_type(attr->test.prog_fd, BPF_PROG_TYPE_SYSCALL); in kern_sys_bpf()
5588 if (IS_ERR(prog)) in kern_sys_bpf()
5589 return PTR_ERR(prog); in kern_sys_bpf()
5591 if (attr->test.ctx_size_in < prog->aux->max_ctx_offset || in kern_sys_bpf()
5593 bpf_prog_put(prog); in kern_sys_bpf()
5598 if (!__bpf_prog_enter_sleepable_recur(prog, &run_ctx)) { in kern_sys_bpf()
5600 __bpf_prog_exit_sleepable_recur(prog, 0, &run_ctx); in kern_sys_bpf()
5601 bpf_prog_put(prog); in kern_sys_bpf()
5604 attr->test.retval = bpf_prog_run(prog, (void *) (long) attr->test.ctx_in); in kern_sys_bpf()
5605 __bpf_prog_exit_sleepable_recur(prog, 0 /* bpf_prog_run does runtime stats */, in kern_sys_bpf()
5607 bpf_prog_put(prog); in kern_sys_bpf()
5626 tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) in tracing_prog_func_proto() argument
5676 syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) in syscall_prog_func_proto() argument
5688 return tracing_prog_func_proto(func_id, prog); in syscall_prog_func_proto()