Lines Matching refs:prog

2106 static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog)  in find_prog_type()  argument
2117 if (!bpf_prog_is_offloaded(prog->aux)) in find_prog_type()
2118 prog->aux->ops = ops; in find_prog_type()
2120 prog->aux->ops = &bpf_offload_prog_ops; in find_prog_type()
2121 prog->type = type; in find_prog_type()
2136 static void bpf_audit_prog(const struct bpf_prog *prog, unsigned int op) in bpf_audit_prog() argument
2151 prog->aux->id, bpf_audit_str[op]); in bpf_audit_prog()
2155 static int bpf_prog_alloc_id(struct bpf_prog *prog) in bpf_prog_alloc_id() argument
2161 id = idr_alloc_cyclic(&prog_idr, prog, 1, INT_MAX, GFP_ATOMIC); in bpf_prog_alloc_id()
2163 prog->aux->id = id; in bpf_prog_alloc_id()
2174 void bpf_prog_free_id(struct bpf_prog *prog) in bpf_prog_free_id() argument
2183 if (!prog->aux->id) in bpf_prog_free_id()
2187 idr_remove(&prog_idr, prog->aux->id); in bpf_prog_free_id()
2188 prog->aux->id = 0; in bpf_prog_free_id()
2199 security_bpf_prog_free(aux->prog); in __bpf_prog_put_rcu()
2200 bpf_prog_free(aux->prog); in __bpf_prog_put_rcu()
2203 static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred) in __bpf_prog_put_noref() argument
2205 bpf_prog_kallsyms_del_all(prog); in __bpf_prog_put_noref()
2206 btf_put(prog->aux->btf); in __bpf_prog_put_noref()
2207 module_put(prog->aux->mod); in __bpf_prog_put_noref()
2208 kvfree(prog->aux->jited_linfo); in __bpf_prog_put_noref()
2209 kvfree(prog->aux->linfo); in __bpf_prog_put_noref()
2210 kfree(prog->aux->kfunc_tab); in __bpf_prog_put_noref()
2211 if (prog->aux->attach_btf) in __bpf_prog_put_noref()
2212 btf_put(prog->aux->attach_btf); in __bpf_prog_put_noref()
2215 if (prog->sleepable) in __bpf_prog_put_noref()
2216 call_rcu_tasks_trace(&prog->aux->rcu, __bpf_prog_put_rcu); in __bpf_prog_put_noref()
2218 call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu); in __bpf_prog_put_noref()
2220 __bpf_prog_put_rcu(&prog->aux->rcu); in __bpf_prog_put_noref()
2227 struct bpf_prog *prog; in bpf_prog_put_deferred() local
2230 prog = aux->prog; in bpf_prog_put_deferred()
2231 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_UNLOAD, 0); in bpf_prog_put_deferred()
2232 bpf_audit_prog(prog, BPF_AUDIT_UNLOAD); in bpf_prog_put_deferred()
2233 bpf_prog_free_id(prog); in bpf_prog_put_deferred()
2234 __bpf_prog_put_noref(prog, true); in bpf_prog_put_deferred()
2237 static void __bpf_prog_put(struct bpf_prog *prog) in __bpf_prog_put() argument
2239 struct bpf_prog_aux *aux = prog->aux; in __bpf_prog_put()
2251 void bpf_prog_put(struct bpf_prog *prog) in bpf_prog_put() argument
2253 __bpf_prog_put(prog); in bpf_prog_put()
2259 struct bpf_prog *prog = filp->private_data; in bpf_prog_release() local
2261 bpf_prog_put(prog); in bpf_prog_release()
2271 void notrace bpf_prog_inc_misses_counter(struct bpf_prog *prog) in bpf_prog_inc_misses_counter() argument
2276 stats = this_cpu_ptr(prog->stats); in bpf_prog_inc_misses_counter()
2282 static void bpf_prog_get_stats(const struct bpf_prog *prog, in bpf_prog_get_stats() argument
2293 st = per_cpu_ptr(prog->stats, cpu); in bpf_prog_get_stats()
2312 const struct bpf_prog *prog = filp->private_data; in bpf_prog_show_fdinfo() local
2313 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; in bpf_prog_show_fdinfo()
2316 bpf_prog_get_stats(prog, &stats); in bpf_prog_show_fdinfo()
2317 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); in bpf_prog_show_fdinfo()
2328 prog->type, in bpf_prog_show_fdinfo()
2329 prog->jited, in bpf_prog_show_fdinfo()
2331 prog->pages * 1ULL << PAGE_SHIFT, in bpf_prog_show_fdinfo()
2332 prog->aux->id, in bpf_prog_show_fdinfo()
2336 prog->aux->verified_insns); in bpf_prog_show_fdinfo()
2349 int bpf_prog_new_fd(struct bpf_prog *prog) in bpf_prog_new_fd() argument
2353 ret = security_bpf_prog(prog); in bpf_prog_new_fd()
2357 return anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog, in bpf_prog_new_fd()
2361 void bpf_prog_add(struct bpf_prog *prog, int i) in bpf_prog_add() argument
2363 atomic64_add(i, &prog->aux->refcnt); in bpf_prog_add()
2367 void bpf_prog_sub(struct bpf_prog *prog, int i) in bpf_prog_sub() argument
2374 WARN_ON(atomic64_sub_return(i, &prog->aux->refcnt) == 0); in bpf_prog_sub()
2378 void bpf_prog_inc(struct bpf_prog *prog) in bpf_prog_inc() argument
2380 atomic64_inc(&prog->aux->refcnt); in bpf_prog_inc()
2385 struct bpf_prog *bpf_prog_inc_not_zero(struct bpf_prog *prog) in bpf_prog_inc_not_zero() argument
2389 refold = atomic64_fetch_add_unless(&prog->aux->refcnt, 1, 0); in bpf_prog_inc_not_zero()
2394 return prog; in bpf_prog_inc_not_zero()
2398 bool bpf_prog_get_ok(struct bpf_prog *prog, in bpf_prog_get_ok() argument
2405 if (prog->type != *attach_type) in bpf_prog_get_ok()
2407 if (bpf_prog_is_offloaded(prog->aux) && !attach_drv) in bpf_prog_get_ok()
2417 struct bpf_prog *prog; in __bpf_prog_get() local
2424 prog = fd_file(f)->private_data; in __bpf_prog_get()
2425 if (!bpf_prog_get_ok(prog, attach_type, attach_drv)) in __bpf_prog_get()
2428 bpf_prog_inc(prog); in __bpf_prog_get()
2429 return prog; in __bpf_prog_get()
2637 struct bpf_prog *prog, *dst_prog = NULL; in bpf_prog_load() local
2756 prog = bpf_prog_alloc(bpf_prog_size(attr->insn_cnt), GFP_USER); in bpf_prog_load()
2757 if (!prog) { in bpf_prog_load()
2766 prog->expected_attach_type = attr->expected_attach_type; in bpf_prog_load()
2767 prog->sleepable = !!(attr->prog_flags & BPF_F_SLEEPABLE); in bpf_prog_load()
2768 prog->aux->attach_btf = attach_btf; in bpf_prog_load()
2769 prog->aux->attach_btf_id = attr->attach_btf_id; in bpf_prog_load()
2770 prog->aux->dst_prog = dst_prog; in bpf_prog_load()
2771 prog->aux->dev_bound = !!attr->prog_ifindex; in bpf_prog_load()
2772 prog->aux->xdp_has_frags = attr->prog_flags & BPF_F_XDP_HAS_FRAGS; in bpf_prog_load()
2775 prog->aux->token = token; in bpf_prog_load()
2778 prog->aux->user = get_current_user(); in bpf_prog_load()
2779 prog->len = attr->insn_cnt; in bpf_prog_load()
2782 if (copy_from_bpfptr(prog->insns, in bpf_prog_load()
2784 bpf_prog_insn_size(prog)) != 0) in bpf_prog_load()
2794 prog->gpl_compatible = license_is_gpl_compatible(license) ? 1 : 0; in bpf_prog_load()
2796 prog->orig_prog = NULL; in bpf_prog_load()
2797 prog->jited = 0; in bpf_prog_load()
2799 atomic64_set(&prog->aux->refcnt, 1); in bpf_prog_load()
2801 if (bpf_prog_is_dev_bound(prog->aux)) { in bpf_prog_load()
2802 err = bpf_prog_dev_bound_init(prog, attr); in bpf_prog_load()
2809 err = bpf_prog_dev_bound_inherit(prog, dst_prog); in bpf_prog_load()
2827 prog->aux->attach_tracing_prog = true; in bpf_prog_load()
2831 err = find_prog_type(type, prog); in bpf_prog_load()
2835 prog->aux->load_time = ktime_get_boottime_ns(); in bpf_prog_load()
2836 err = bpf_obj_name_cpy(prog->aux->name, attr->prog_name, in bpf_prog_load()
2841 err = security_bpf_prog_load(prog, attr, token); in bpf_prog_load()
2846 err = bpf_check(&prog, attr, uattr, uattr_size); in bpf_prog_load()
2850 prog = bpf_prog_select_runtime(prog, &err); in bpf_prog_load()
2854 err = bpf_prog_alloc_id(prog); in bpf_prog_load()
2872 bpf_prog_kallsyms_add(prog); in bpf_prog_load()
2873 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_LOAD, 0); in bpf_prog_load()
2874 bpf_audit_prog(prog, BPF_AUDIT_LOAD); in bpf_prog_load()
2876 err = bpf_prog_new_fd(prog); in bpf_prog_load()
2878 bpf_prog_put(prog); in bpf_prog_load()
2886 __bpf_prog_put_noref(prog, prog->aux->real_func_cnt); in bpf_prog_load()
2890 security_bpf_prog_free(prog); in bpf_prog_load()
2892 free_uid(prog->aux->user); in bpf_prog_load()
2893 if (prog->aux->attach_btf) in bpf_prog_load()
2894 btf_put(prog->aux->attach_btf); in bpf_prog_load()
2895 bpf_prog_free(prog); in bpf_prog_load()
2937 const struct bpf_link_ops *ops, struct bpf_prog *prog) in bpf_link_init() argument
2944 link->prog = prog; in bpf_link_init()
2968 primer->link->prog = NULL; in bpf_link_cleanup()
3002 if (link->prog) { in bpf_link_free()
3003 sleepable = link->prog->sleepable; in bpf_link_free()
3006 bpf_prog_put(link->prog); in bpf_link_free()
3071 const struct bpf_prog *prog = link->prog; in bpf_link_show_fdinfo() local
3073 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; in bpf_link_show_fdinfo()
3083 if (prog) { in bpf_link_show_fdinfo()
3084 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); in bpf_link_show_fdinfo()
3089 prog->aux->id); in bpf_link_show_fdinfo()
3277 static int bpf_tracing_prog_attach(struct bpf_prog *prog, in bpf_tracing_prog_attach() argument
3289 switch (prog->type) { in bpf_tracing_prog_attach()
3291 if (prog->expected_attach_type != BPF_TRACE_FENTRY && in bpf_tracing_prog_attach()
3292 prog->expected_attach_type != BPF_TRACE_FEXIT && in bpf_tracing_prog_attach()
3293 prog->expected_attach_type != BPF_MODIFY_RETURN) { in bpf_tracing_prog_attach()
3299 if (prog->expected_attach_type != 0) { in bpf_tracing_prog_attach()
3305 if (prog->expected_attach_type != BPF_LSM_MAC) { in bpf_tracing_prog_attach()
3327 if (prog->type != BPF_PROG_TYPE_EXT) { in bpf_tracing_prog_attach()
3348 &bpf_tracing_link_lops, prog); in bpf_tracing_prog_attach()
3349 link->attach_type = prog->expected_attach_type; in bpf_tracing_prog_attach()
3352 mutex_lock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3376 if (!prog->aux->dst_trampoline && !tgt_prog) { in bpf_tracing_prog_attach()
3383 if (prog->type != BPF_PROG_TYPE_TRACING && in bpf_tracing_prog_attach()
3384 prog->type != BPF_PROG_TYPE_LSM) { in bpf_tracing_prog_attach()
3389 if (!prog->aux->attach_btf) { in bpf_tracing_prog_attach()
3393 btf_id = prog->aux->attach_btf_id; in bpf_tracing_prog_attach()
3394 key = bpf_trampoline_compute_key(NULL, prog->aux->attach_btf, btf_id); in bpf_tracing_prog_attach()
3397 if (!prog->aux->dst_trampoline || in bpf_tracing_prog_attach()
3398 (key && key != prog->aux->dst_trampoline->key)) { in bpf_tracing_prog_attach()
3405 err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id, in bpf_tracing_prog_attach()
3411 module_put(prog->aux->mod); in bpf_tracing_prog_attach()
3412 prog->aux->mod = tgt_info.tgt_mod; in bpf_tracing_prog_attach()
3428 tr = prog->aux->dst_trampoline; in bpf_tracing_prog_attach()
3429 tgt_prog = prog->aux->dst_prog; in bpf_tracing_prog_attach()
3450 if (prog->aux->dst_prog && in bpf_tracing_prog_attach()
3451 (tgt_prog_fd || tr != prog->aux->dst_trampoline)) in bpf_tracing_prog_attach()
3453 bpf_prog_put(prog->aux->dst_prog); in bpf_tracing_prog_attach()
3454 if (prog->aux->dst_trampoline && tr != prog->aux->dst_trampoline) in bpf_tracing_prog_attach()
3456 bpf_trampoline_put(prog->aux->dst_trampoline); in bpf_tracing_prog_attach()
3458 prog->aux->dst_prog = NULL; in bpf_tracing_prog_attach()
3459 prog->aux->dst_trampoline = NULL; in bpf_tracing_prog_attach()
3460 mutex_unlock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3464 if (tr && tr != prog->aux->dst_trampoline) in bpf_tracing_prog_attach()
3466 mutex_unlock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3724 switch (event->prog->type) { in bpf_perf_link_fill_link_info()
3742 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_perf_link_attach() argument
3762 bpf_link_init(&link->link, BPF_LINK_TYPE_PERF_EVENT, &bpf_perf_link_lops, prog); in bpf_perf_link_attach()
3772 err = perf_event_set_bpf_prog(event, prog, attr->link_create.perf_event.bpf_cookie); in bpf_perf_link_attach()
3778 bpf_prog_inc(prog); in bpf_perf_link_attach()
3787 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_perf_link_attach() argument
3793 static int bpf_raw_tp_link_attach(struct bpf_prog *prog, in bpf_raw_tp_link_attach() argument
3803 switch (prog->type) { in bpf_raw_tp_link_attach()
3812 if (prog->type == BPF_PROG_TYPE_TRACING && in bpf_raw_tp_link_attach()
3813 prog->expected_attach_type == BPF_TRACE_RAW_TP) { in bpf_raw_tp_link_attach()
3814 tp_name = prog->aux->attach_func_name; in bpf_raw_tp_link_attach()
3817 return bpf_tracing_prog_attach(prog, 0, 0, 0); in bpf_raw_tp_link_attach()
3839 &bpf_raw_tp_link_lops, prog); in bpf_raw_tp_link_attach()
3866 struct bpf_prog *prog; in bpf_raw_tracepoint_open() local
3874 prog = bpf_prog_get(attr->raw_tracepoint.prog_fd); in bpf_raw_tracepoint_open()
3875 if (IS_ERR(prog)) in bpf_raw_tracepoint_open()
3876 return PTR_ERR(prog); in bpf_raw_tracepoint_open()
3880 fd = bpf_raw_tp_link_attach(prog, tp_name, cookie); in bpf_raw_tracepoint_open()
3882 bpf_prog_put(prog); in bpf_raw_tracepoint_open()
3959 static int bpf_prog_attach_check_attach_type(const struct bpf_prog *prog, in bpf_prog_attach_check_attach_type() argument
3964 switch (prog->type) { in bpf_prog_attach_check_attach_type()
3969 return attach_type == prog->expected_attach_type ? 0 : -EINVAL; in bpf_prog_attach_check_attach_type()
3971 if (!bpf_token_capable(prog->aux->token, CAP_NET_ADMIN)) in bpf_prog_attach_check_attach_type()
3978 if (prog->type != ptype) in bpf_prog_attach_check_attach_type()
3981 return prog->enforce_expected_attach_type && in bpf_prog_attach_check_attach_type()
3982 prog->expected_attach_type != attach_type ? in bpf_prog_attach_check_attach_type()
3996 if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI && in bpf_prog_attach_check_attach_type()
3999 if (prog->expected_attach_type == BPF_TRACE_KPROBE_SESSION && in bpf_prog_attach_check_attach_type()
4002 if (prog->expected_attach_type == BPF_TRACE_UPROBE_MULTI && in bpf_prog_attach_check_attach_type()
4020 if (ptype == BPF_PROG_TYPE_UNSPEC || ptype != prog->type) in bpf_prog_attach_check_attach_type()
4043 struct bpf_prog *prog; in bpf_prog_attach() local
4063 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); in bpf_prog_attach()
4064 if (IS_ERR(prog)) in bpf_prog_attach()
4065 return PTR_ERR(prog); in bpf_prog_attach()
4067 if (bpf_prog_attach_check_attach_type(prog, attr->attach_type)) { in bpf_prog_attach()
4068 bpf_prog_put(prog); in bpf_prog_attach()
4075 ret = sock_map_get_from_fd(attr, prog); in bpf_prog_attach()
4078 ret = lirc_prog_attach(attr, prog); in bpf_prog_attach()
4081 ret = netns_bpf_prog_attach(attr, prog); in bpf_prog_attach()
4092 prog->expected_attach_type != BPF_LSM_CGROUP) in bpf_prog_attach()
4095 ret = cgroup_bpf_prog_attach(attr, ptype, prog); in bpf_prog_attach()
4100 ret = tcx_prog_attach(attr, prog); in bpf_prog_attach()
4102 ret = netkit_prog_attach(attr, prog); in bpf_prog_attach()
4109 bpf_prog_put(prog); in bpf_prog_attach()
4117 struct bpf_prog *prog = NULL; in bpf_prog_detach() local
4131 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); in bpf_prog_detach()
4132 if (IS_ERR(prog)) in bpf_prog_detach()
4133 return PTR_ERR(prog); in bpf_prog_detach()
4165 ret = tcx_prog_detach(attr, prog); in bpf_prog_detach()
4167 ret = netkit_prog_detach(attr, prog); in bpf_prog_detach()
4173 if (prog) in bpf_prog_detach()
4174 bpf_prog_put(prog); in bpf_prog_detach()
4247 struct bpf_prog *prog; in bpf_prog_test_run() local
4261 prog = bpf_prog_get(attr->test.prog_fd); in bpf_prog_test_run()
4262 if (IS_ERR(prog)) in bpf_prog_test_run()
4263 return PTR_ERR(prog); in bpf_prog_test_run()
4265 if (prog->aux->ops->test_run) in bpf_prog_test_run()
4266 ret = prog->aux->ops->test_run(prog, attr, uattr); in bpf_prog_test_run()
4268 bpf_prog_put(prog); in bpf_prog_test_run()
4321 struct bpf_prog *prog; in bpf_prog_get_curr_or_next() local
4325 prog = idr_get_next(&prog_idr, id); in bpf_prog_get_curr_or_next()
4326 if (prog) { in bpf_prog_get_curr_or_next()
4327 prog = bpf_prog_inc_not_zero(prog); in bpf_prog_get_curr_or_next()
4328 if (IS_ERR(prog)) { in bpf_prog_get_curr_or_next()
4335 return prog; in bpf_prog_get_curr_or_next()
4342 struct bpf_prog *prog; in bpf_prog_by_id() local
4348 prog = idr_find(&prog_idr, id); in bpf_prog_by_id()
4349 if (prog) in bpf_prog_by_id()
4350 prog = bpf_prog_inc_not_zero(prog); in bpf_prog_by_id()
4352 prog = ERR_PTR(-ENOENT); in bpf_prog_by_id()
4354 return prog; in bpf_prog_by_id()
4359 struct bpf_prog *prog; in bpf_prog_get_fd_by_id() local
4369 prog = bpf_prog_by_id(id); in bpf_prog_get_fd_by_id()
4370 if (IS_ERR(prog)) in bpf_prog_get_fd_by_id()
4371 return PTR_ERR(prog); in bpf_prog_get_fd_by_id()
4373 fd = bpf_prog_new_fd(prog); in bpf_prog_get_fd_by_id()
4375 bpf_prog_put(prog); in bpf_prog_get_fd_by_id()
4418 static const struct bpf_map *bpf_map_from_imm(const struct bpf_prog *prog, in bpf_map_from_imm() argument
4425 mutex_lock(&prog->aux->used_maps_mutex); in bpf_map_from_imm()
4426 for (i = 0, *off = 0; i < prog->aux->used_map_cnt; i++) { in bpf_map_from_imm()
4427 map = prog->aux->used_maps[i]; in bpf_map_from_imm()
4442 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_map_from_imm()
4446 static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog, in bpf_insn_prepare_dump() argument
4456 insns = kmemdup(prog->insnsi, bpf_prog_insn_size(prog), in bpf_insn_prepare_dump()
4461 for (i = 0; i < prog->len; i++) { in bpf_insn_prepare_dump()
4492 map = bpf_map_from_imm(prog, imm, &off, &type); in bpf_insn_prepare_dump()
4536 struct bpf_prog *prog, in bpf_prog_get_info_by_fd() argument
4541 struct btf *attach_btf = bpf_prog_get_target_btf(prog); in bpf_prog_get_info_by_fd()
4558 info.type = prog->type; in bpf_prog_get_info_by_fd()
4559 info.id = prog->aux->id; in bpf_prog_get_info_by_fd()
4560 info.load_time = prog->aux->load_time; in bpf_prog_get_info_by_fd()
4562 prog->aux->user->uid); in bpf_prog_get_info_by_fd()
4563 info.gpl_compatible = prog->gpl_compatible; in bpf_prog_get_info_by_fd()
4565 memcpy(info.tag, prog->tag, sizeof(prog->tag)); in bpf_prog_get_info_by_fd()
4566 memcpy(info.name, prog->aux->name, sizeof(prog->aux->name)); in bpf_prog_get_info_by_fd()
4568 mutex_lock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
4570 info.nr_map_ids = prog->aux->used_map_cnt; in bpf_prog_get_info_by_fd()
4577 if (put_user(prog->aux->used_maps[i]->id, in bpf_prog_get_info_by_fd()
4579 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
4583 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
4589 bpf_prog_get_stats(prog, &stats); in bpf_prog_get_info_by_fd()
4594 info.verified_insns = prog->aux->verified_insns; in bpf_prog_get_info_by_fd()
4608 info.xlated_prog_len = bpf_prog_insn_size(prog); in bpf_prog_get_info_by_fd()
4613 if (prog->blinded && !bpf_dump_raw_ok(file->f_cred)) { in bpf_prog_get_info_by_fd()
4617 insns_sanitized = bpf_insn_prepare_dump(prog, file->f_cred); in bpf_prog_get_info_by_fd()
4628 if (bpf_prog_is_offloaded(prog->aux)) { in bpf_prog_get_info_by_fd()
4629 err = bpf_prog_offload_info_fill(&info, prog); in bpf_prog_get_info_by_fd()
4640 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4644 for (i = 0; i < prog->aux->func_cnt; i++) in bpf_prog_get_info_by_fd()
4645 info.jited_prog_len += prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4647 info.jited_prog_len = prog->jited_len; in bpf_prog_get_info_by_fd()
4658 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4663 for (i = 0; i < prog->aux->func_cnt; i++) { in bpf_prog_get_info_by_fd()
4664 len = prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4666 img = (u8 *) prog->aux->func[i]->bpf_func; in bpf_prog_get_info_by_fd()
4675 if (copy_to_user(uinsns, prog->bpf_func, ulen)) in bpf_prog_get_info_by_fd()
4684 info.nr_jited_ksyms = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4696 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4699 prog->aux->func[i]->bpf_func; in bpf_prog_get_info_by_fd()
4705 ksym_addr = (unsigned long) prog->bpf_func; in bpf_prog_get_info_by_fd()
4715 info.nr_jited_func_lens = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4724 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4727 prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4732 func_len = prog->jited_len; in bpf_prog_get_info_by_fd()
4741 if (prog->aux->btf) in bpf_prog_get_info_by_fd()
4742 info.btf_id = btf_obj_id(prog->aux->btf); in bpf_prog_get_info_by_fd()
4743 info.attach_btf_id = prog->aux->attach_btf_id; in bpf_prog_get_info_by_fd()
4748 info.nr_func_info = prog->aux->func_info_cnt; in bpf_prog_get_info_by_fd()
4754 if (copy_to_user(user_finfo, prog->aux->func_info, in bpf_prog_get_info_by_fd()
4760 info.nr_line_info = prog->aux->nr_linfo; in bpf_prog_get_info_by_fd()
4766 if (copy_to_user(user_linfo, prog->aux->linfo, in bpf_prog_get_info_by_fd()
4772 if (prog->aux->jited_linfo) in bpf_prog_get_info_by_fd()
4773 info.nr_jited_line_info = prog->aux->nr_linfo; in bpf_prog_get_info_by_fd()
4785 line_addr = (unsigned long)prog->aux->jited_linfo[i]; in bpf_prog_get_info_by_fd()
4795 info.nr_prog_tags = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4802 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4805 prog->aux->func[i]->tag, in bpf_prog_get_info_by_fd()
4811 prog->tag, BPF_TAG_SIZE)) in bpf_prog_get_info_by_fd()
4908 if (link->prog) in bpf_link_get_info_by_fd()
4909 info.prog_id = link->prog->aux->id; in bpf_link_get_info_by_fd()
5085 raw_tp->link.prog->aux->id, in bpf_task_fd_query()
5176 struct bpf_prog *prog; in link_create() local
5185 prog = bpf_prog_get(attr->link_create.prog_fd); in link_create()
5186 if (IS_ERR(prog)) in link_create()
5187 return PTR_ERR(prog); in link_create()
5189 ret = bpf_prog_attach_check_attach_type(prog, in link_create()
5194 switch (prog->type) { in link_create()
5202 ret = cgroup_bpf_link_attach(attr, prog); in link_create()
5205 ret = bpf_tracing_prog_attach(prog, in link_create()
5212 if (attr->link_create.attach_type != prog->expected_attach_type) { in link_create()
5216 if (prog->expected_attach_type == BPF_TRACE_RAW_TP) in link_create()
5217 ret = bpf_raw_tp_link_attach(prog, NULL, attr->link_create.tracing.cookie); in link_create()
5218 else if (prog->expected_attach_type == BPF_TRACE_ITER) in link_create()
5219 ret = bpf_iter_link_attach(attr, uattr, prog); in link_create()
5220 else if (prog->expected_attach_type == BPF_LSM_CGROUP) in link_create()
5221 ret = cgroup_bpf_link_attach(attr, prog); in link_create()
5223 ret = bpf_tracing_prog_attach(prog, in link_create()
5230 ret = netns_bpf_link_create(attr, prog); in link_create()
5234 ret = sock_map_link_create(attr, prog); in link_create()
5238 ret = bpf_xdp_link_attach(attr, prog); in link_create()
5243 ret = tcx_link_attach(attr, prog); in link_create()
5245 ret = netkit_link_attach(attr, prog); in link_create()
5248 ret = bpf_nf_link_attach(attr, prog); in link_create()
5253 ret = bpf_perf_link_attach(attr, prog); in link_create()
5257 ret = bpf_perf_link_attach(attr, prog); in link_create()
5260 ret = bpf_kprobe_multi_link_attach(attr, prog); in link_create()
5262 ret = bpf_uprobe_multi_link_attach(attr, prog); in link_create()
5270 bpf_prog_put(prog); in link_create()
5537 struct bpf_prog *prog; in bpf_prog_bind_map() local
5548 prog = bpf_prog_get(attr->prog_bind_map.prog_fd); in bpf_prog_bind_map()
5549 if (IS_ERR(prog)) in bpf_prog_bind_map()
5550 return PTR_ERR(prog); in bpf_prog_bind_map()
5558 mutex_lock(&prog->aux->used_maps_mutex); in bpf_prog_bind_map()
5560 used_maps_old = prog->aux->used_maps; in bpf_prog_bind_map()
5562 for (i = 0; i < prog->aux->used_map_cnt; i++) in bpf_prog_bind_map()
5568 used_maps_new = kmalloc_array(prog->aux->used_map_cnt + 1, in bpf_prog_bind_map()
5579 if (prog->sleepable) in bpf_prog_bind_map()
5582 sizeof(used_maps_old[0]) * prog->aux->used_map_cnt); in bpf_prog_bind_map()
5583 used_maps_new[prog->aux->used_map_cnt] = map; in bpf_prog_bind_map()
5585 prog->aux->used_map_cnt++; in bpf_prog_bind_map()
5586 prog->aux->used_maps = used_maps_new; in bpf_prog_bind_map()
5591 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_bind_map()
5596 bpf_prog_put(prog); in bpf_prog_bind_map()
5765 const struct bpf_prog *prog, in syscall_prog_is_valid_access() argument
5804 struct bpf_prog * __maybe_unused prog; in kern_sys_bpf() local
5815 prog = bpf_prog_get_type(attr->test.prog_fd, BPF_PROG_TYPE_SYSCALL); in kern_sys_bpf()
5816 if (IS_ERR(prog)) in kern_sys_bpf()
5817 return PTR_ERR(prog); in kern_sys_bpf()
5819 if (attr->test.ctx_size_in < prog->aux->max_ctx_offset || in kern_sys_bpf()
5821 bpf_prog_put(prog); in kern_sys_bpf()
5826 if (!__bpf_prog_enter_sleepable_recur(prog, &run_ctx)) { in kern_sys_bpf()
5828 __bpf_prog_exit_sleepable_recur(prog, 0, &run_ctx); in kern_sys_bpf()
5829 bpf_prog_put(prog); in kern_sys_bpf()
5832 attr->test.retval = bpf_prog_run(prog, (void *) (long) attr->test.ctx_in); in kern_sys_bpf()
5833 __bpf_prog_exit_sleepable_recur(prog, 0 /* bpf_prog_run does runtime stats */, in kern_sys_bpf()
5835 bpf_prog_put(prog); in kern_sys_bpf()
5854 tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) in tracing_prog_func_proto() argument
5856 return bpf_base_func_proto(func_id, prog); in tracing_prog_func_proto()
5904 syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) in syscall_prog_func_proto() argument
5908 return !bpf_token_capable(prog->aux->token, CAP_PERFMON) in syscall_prog_func_proto()
5917 return tracing_prog_func_proto(func_id, prog); in syscall_prog_func_proto()