Lines Matching refs:prog
2230 static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog) in find_prog_type() argument
2241 if (!bpf_prog_is_offloaded(prog->aux)) in find_prog_type()
2242 prog->aux->ops = ops; in find_prog_type()
2244 prog->aux->ops = &bpf_offload_prog_ops; in find_prog_type()
2245 prog->type = type; in find_prog_type()
2260 static void bpf_audit_prog(const struct bpf_prog *prog, unsigned int op) in bpf_audit_prog() argument
2275 prog->aux->id, bpf_audit_str[op]); in bpf_audit_prog()
2279 static int bpf_prog_alloc_id(struct bpf_prog *prog) in bpf_prog_alloc_id() argument
2285 id = idr_alloc_cyclic(&prog_idr, prog, 1, INT_MAX, GFP_ATOMIC); in bpf_prog_alloc_id()
2287 prog->aux->id = id; in bpf_prog_alloc_id()
2298 void bpf_prog_free_id(struct bpf_prog *prog) in bpf_prog_free_id() argument
2307 if (!prog->aux->id) in bpf_prog_free_id()
2311 idr_remove(&prog_idr, prog->aux->id); in bpf_prog_free_id()
2312 prog->aux->id = 0; in bpf_prog_free_id()
2323 security_bpf_prog_free(aux->prog); in __bpf_prog_put_rcu()
2324 bpf_prog_free(aux->prog); in __bpf_prog_put_rcu()
2327 static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred) in __bpf_prog_put_noref() argument
2329 bpf_prog_kallsyms_del_all(prog); in __bpf_prog_put_noref()
2330 btf_put(prog->aux->btf); in __bpf_prog_put_noref()
2331 module_put(prog->aux->mod); in __bpf_prog_put_noref()
2332 kvfree(prog->aux->jited_linfo); in __bpf_prog_put_noref()
2333 kvfree(prog->aux->linfo); in __bpf_prog_put_noref()
2334 kfree(prog->aux->kfunc_tab); in __bpf_prog_put_noref()
2335 kfree(prog->aux->ctx_arg_info); in __bpf_prog_put_noref()
2336 if (prog->aux->attach_btf) in __bpf_prog_put_noref()
2337 btf_put(prog->aux->attach_btf); in __bpf_prog_put_noref()
2340 if (prog->sleepable) in __bpf_prog_put_noref()
2341 call_rcu_tasks_trace(&prog->aux->rcu, __bpf_prog_put_rcu); in __bpf_prog_put_noref()
2343 call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu); in __bpf_prog_put_noref()
2345 __bpf_prog_put_rcu(&prog->aux->rcu); in __bpf_prog_put_noref()
2352 struct bpf_prog *prog; in bpf_prog_put_deferred() local
2355 prog = aux->prog; in bpf_prog_put_deferred()
2356 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_UNLOAD, 0); in bpf_prog_put_deferred()
2357 bpf_audit_prog(prog, BPF_AUDIT_UNLOAD); in bpf_prog_put_deferred()
2358 bpf_prog_free_id(prog); in bpf_prog_put_deferred()
2359 __bpf_prog_put_noref(prog, true); in bpf_prog_put_deferred()
2362 static void __bpf_prog_put(struct bpf_prog *prog) in __bpf_prog_put() argument
2364 struct bpf_prog_aux *aux = prog->aux; in __bpf_prog_put()
2376 void bpf_prog_put(struct bpf_prog *prog) in bpf_prog_put() argument
2378 __bpf_prog_put(prog); in bpf_prog_put()
2384 struct bpf_prog *prog = filp->private_data; in bpf_prog_release() local
2386 bpf_prog_put(prog); in bpf_prog_release()
2396 void notrace bpf_prog_inc_misses_counter(struct bpf_prog *prog) in bpf_prog_inc_misses_counter() argument
2401 stats = this_cpu_ptr(prog->stats); in bpf_prog_inc_misses_counter()
2407 static void bpf_prog_get_stats(const struct bpf_prog *prog, in bpf_prog_get_stats() argument
2418 st = per_cpu_ptr(prog->stats, cpu); in bpf_prog_get_stats()
2437 const struct bpf_prog *prog = filp->private_data; in bpf_prog_show_fdinfo() local
2438 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; in bpf_prog_show_fdinfo()
2441 bpf_prog_get_stats(prog, &stats); in bpf_prog_show_fdinfo()
2442 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); in bpf_prog_show_fdinfo()
2453 prog->type, in bpf_prog_show_fdinfo()
2454 prog->jited, in bpf_prog_show_fdinfo()
2456 prog->pages * 1ULL << PAGE_SHIFT, in bpf_prog_show_fdinfo()
2457 prog->aux->id, in bpf_prog_show_fdinfo()
2461 prog->aux->verified_insns); in bpf_prog_show_fdinfo()
2474 int bpf_prog_new_fd(struct bpf_prog *prog) in bpf_prog_new_fd() argument
2478 ret = security_bpf_prog(prog); in bpf_prog_new_fd()
2482 return anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog, in bpf_prog_new_fd()
2486 void bpf_prog_add(struct bpf_prog *prog, int i) in bpf_prog_add() argument
2488 atomic64_add(i, &prog->aux->refcnt); in bpf_prog_add()
2492 void bpf_prog_sub(struct bpf_prog *prog, int i) in bpf_prog_sub() argument
2499 WARN_ON(atomic64_sub_return(i, &prog->aux->refcnt) == 0); in bpf_prog_sub()
2503 void bpf_prog_inc(struct bpf_prog *prog) in bpf_prog_inc() argument
2505 atomic64_inc(&prog->aux->refcnt); in bpf_prog_inc()
2510 struct bpf_prog *bpf_prog_inc_not_zero(struct bpf_prog *prog) in bpf_prog_inc_not_zero() argument
2514 refold = atomic64_fetch_add_unless(&prog->aux->refcnt, 1, 0); in bpf_prog_inc_not_zero()
2519 return prog; in bpf_prog_inc_not_zero()
2523 bool bpf_prog_get_ok(struct bpf_prog *prog, in bpf_prog_get_ok() argument
2530 if (prog->type != *attach_type) in bpf_prog_get_ok()
2532 if (bpf_prog_is_offloaded(prog->aux) && !attach_drv) in bpf_prog_get_ok()
2542 struct bpf_prog *prog; in __bpf_prog_get() local
2549 prog = fd_file(f)->private_data; in __bpf_prog_get()
2550 if (!bpf_prog_get_ok(prog, attach_type, attach_drv)) in __bpf_prog_get()
2553 bpf_prog_inc(prog); in __bpf_prog_get()
2554 return prog; in __bpf_prog_get()
2762 struct bpf_prog *prog, *dst_prog = NULL; in bpf_prog_load() local
2881 prog = bpf_prog_alloc(bpf_prog_size(attr->insn_cnt), GFP_USER); in bpf_prog_load()
2882 if (!prog) { in bpf_prog_load()
2891 prog->expected_attach_type = attr->expected_attach_type; in bpf_prog_load()
2892 prog->sleepable = !!(attr->prog_flags & BPF_F_SLEEPABLE); in bpf_prog_load()
2893 prog->aux->attach_btf = attach_btf; in bpf_prog_load()
2894 prog->aux->attach_btf_id = attr->attach_btf_id; in bpf_prog_load()
2895 prog->aux->dst_prog = dst_prog; in bpf_prog_load()
2896 prog->aux->dev_bound = !!attr->prog_ifindex; in bpf_prog_load()
2897 prog->aux->xdp_has_frags = attr->prog_flags & BPF_F_XDP_HAS_FRAGS; in bpf_prog_load()
2900 prog->aux->token = token; in bpf_prog_load()
2903 prog->aux->user = get_current_user(); in bpf_prog_load()
2904 prog->len = attr->insn_cnt; in bpf_prog_load()
2907 if (copy_from_bpfptr(prog->insns, in bpf_prog_load()
2909 bpf_prog_insn_size(prog)) != 0) in bpf_prog_load()
2919 prog->gpl_compatible = license_is_gpl_compatible(license) ? 1 : 0; in bpf_prog_load()
2921 prog->orig_prog = NULL; in bpf_prog_load()
2922 prog->jited = 0; in bpf_prog_load()
2924 atomic64_set(&prog->aux->refcnt, 1); in bpf_prog_load()
2926 if (bpf_prog_is_dev_bound(prog->aux)) { in bpf_prog_load()
2927 err = bpf_prog_dev_bound_init(prog, attr); in bpf_prog_load()
2934 err = bpf_prog_dev_bound_inherit(prog, dst_prog); in bpf_prog_load()
2952 prog->aux->attach_tracing_prog = true; in bpf_prog_load()
2956 err = find_prog_type(type, prog); in bpf_prog_load()
2960 prog->aux->load_time = ktime_get_boottime_ns(); in bpf_prog_load()
2961 err = bpf_obj_name_cpy(prog->aux->name, attr->prog_name, in bpf_prog_load()
2966 err = security_bpf_prog_load(prog, attr, token, uattr.is_kernel); in bpf_prog_load()
2971 err = bpf_check(&prog, attr, uattr, uattr_size); in bpf_prog_load()
2975 prog = bpf_prog_select_runtime(prog, &err); in bpf_prog_load()
2979 err = bpf_prog_alloc_id(prog); in bpf_prog_load()
2997 bpf_prog_kallsyms_add(prog); in bpf_prog_load()
2998 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_LOAD, 0); in bpf_prog_load()
2999 bpf_audit_prog(prog, BPF_AUDIT_LOAD); in bpf_prog_load()
3001 err = bpf_prog_new_fd(prog); in bpf_prog_load()
3003 bpf_prog_put(prog); in bpf_prog_load()
3011 __bpf_prog_put_noref(prog, prog->aux->real_func_cnt); in bpf_prog_load()
3015 security_bpf_prog_free(prog); in bpf_prog_load()
3017 free_uid(prog->aux->user); in bpf_prog_load()
3018 if (prog->aux->attach_btf) in bpf_prog_load()
3019 btf_put(prog->aux->attach_btf); in bpf_prog_load()
3020 bpf_prog_free(prog); in bpf_prog_load()
3070 const struct bpf_link_ops *ops, struct bpf_prog *prog, in bpf_link_init_sleepable() argument
3079 link->prog = prog; in bpf_link_init_sleepable()
3083 const struct bpf_link_ops *ops, struct bpf_prog *prog) in bpf_link_init() argument
3085 bpf_link_init_sleepable(link, type, ops, prog, false); in bpf_link_init()
3109 primer->link->prog = NULL; in bpf_link_cleanup()
3123 if (link->prog) in bpf_link_dealloc()
3124 bpf_prog_put(link->prog); in bpf_link_dealloc()
3155 if (link->prog) in bpf_link_free()
3166 if (link->sleepable || (link->prog && link->prog->sleepable)) in bpf_link_free()
3225 const struct bpf_prog *prog = link->prog; in bpf_link_show_fdinfo() local
3227 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; in bpf_link_show_fdinfo()
3237 if (prog) { in bpf_link_show_fdinfo()
3238 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); in bpf_link_show_fdinfo()
3243 prog->aux->id); in bpf_link_show_fdinfo()
3432 static int bpf_tracing_prog_attach(struct bpf_prog *prog, in bpf_tracing_prog_attach() argument
3444 switch (prog->type) { in bpf_tracing_prog_attach()
3446 if (prog->expected_attach_type != BPF_TRACE_FENTRY && in bpf_tracing_prog_attach()
3447 prog->expected_attach_type != BPF_TRACE_FEXIT && in bpf_tracing_prog_attach()
3448 prog->expected_attach_type != BPF_MODIFY_RETURN) { in bpf_tracing_prog_attach()
3454 if (prog->expected_attach_type != 0) { in bpf_tracing_prog_attach()
3460 if (prog->expected_attach_type != BPF_LSM_MAC) { in bpf_tracing_prog_attach()
3482 if (prog->type != BPF_PROG_TYPE_EXT) { in bpf_tracing_prog_attach()
3503 &bpf_tracing_link_lops, prog); in bpf_tracing_prog_attach()
3504 link->attach_type = prog->expected_attach_type; in bpf_tracing_prog_attach()
3507 mutex_lock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3531 if (!prog->aux->dst_trampoline && !tgt_prog) { in bpf_tracing_prog_attach()
3538 if (prog->type != BPF_PROG_TYPE_TRACING && in bpf_tracing_prog_attach()
3539 prog->type != BPF_PROG_TYPE_LSM) { in bpf_tracing_prog_attach()
3544 if (!prog->aux->attach_btf) { in bpf_tracing_prog_attach()
3548 btf_id = prog->aux->attach_btf_id; in bpf_tracing_prog_attach()
3549 key = bpf_trampoline_compute_key(NULL, prog->aux->attach_btf, btf_id); in bpf_tracing_prog_attach()
3552 if (!prog->aux->dst_trampoline || in bpf_tracing_prog_attach()
3553 (key && key != prog->aux->dst_trampoline->key)) { in bpf_tracing_prog_attach()
3560 err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id, in bpf_tracing_prog_attach()
3566 module_put(prog->aux->mod); in bpf_tracing_prog_attach()
3567 prog->aux->mod = tgt_info.tgt_mod; in bpf_tracing_prog_attach()
3583 tr = prog->aux->dst_trampoline; in bpf_tracing_prog_attach()
3584 tgt_prog = prog->aux->dst_prog; in bpf_tracing_prog_attach()
3605 if (prog->aux->dst_prog && in bpf_tracing_prog_attach()
3606 (tgt_prog_fd || tr != prog->aux->dst_trampoline)) in bpf_tracing_prog_attach()
3608 bpf_prog_put(prog->aux->dst_prog); in bpf_tracing_prog_attach()
3609 if (prog->aux->dst_trampoline && tr != prog->aux->dst_trampoline) in bpf_tracing_prog_attach()
3611 bpf_trampoline_put(prog->aux->dst_trampoline); in bpf_tracing_prog_attach()
3613 prog->aux->dst_prog = NULL; in bpf_tracing_prog_attach()
3614 prog->aux->dst_trampoline = NULL; in bpf_tracing_prog_attach()
3615 mutex_unlock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3619 if (tr && tr != prog->aux->dst_trampoline) in bpf_tracing_prog_attach()
3621 mutex_unlock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3879 switch (event->prog->type) { in bpf_perf_link_fill_link_info()
3897 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_perf_link_attach() argument
3917 bpf_link_init(&link->link, BPF_LINK_TYPE_PERF_EVENT, &bpf_perf_link_lops, prog); in bpf_perf_link_attach()
3927 err = perf_event_set_bpf_prog(event, prog, attr->link_create.perf_event.bpf_cookie); in bpf_perf_link_attach()
3933 bpf_prog_inc(prog); in bpf_perf_link_attach()
3942 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_perf_link_attach() argument
3948 static int bpf_raw_tp_link_attach(struct bpf_prog *prog, in bpf_raw_tp_link_attach() argument
3958 switch (prog->type) { in bpf_raw_tp_link_attach()
3967 if (prog->type == BPF_PROG_TYPE_TRACING && in bpf_raw_tp_link_attach()
3968 prog->expected_attach_type == BPF_TRACE_RAW_TP) { in bpf_raw_tp_link_attach()
3969 tp_name = prog->aux->attach_func_name; in bpf_raw_tp_link_attach()
3972 return bpf_tracing_prog_attach(prog, 0, 0, 0); in bpf_raw_tp_link_attach()
3994 &bpf_raw_tp_link_lops, prog, in bpf_raw_tp_link_attach()
4022 struct bpf_prog *prog; in bpf_raw_tracepoint_open() local
4030 prog = bpf_prog_get(attr->raw_tracepoint.prog_fd); in bpf_raw_tracepoint_open()
4031 if (IS_ERR(prog)) in bpf_raw_tracepoint_open()
4032 return PTR_ERR(prog); in bpf_raw_tracepoint_open()
4036 fd = bpf_raw_tp_link_attach(prog, tp_name, cookie); in bpf_raw_tracepoint_open()
4038 bpf_prog_put(prog); in bpf_raw_tracepoint_open()
4115 static int bpf_prog_attach_check_attach_type(const struct bpf_prog *prog, in bpf_prog_attach_check_attach_type() argument
4120 switch (prog->type) { in bpf_prog_attach_check_attach_type()
4125 return attach_type == prog->expected_attach_type ? 0 : -EINVAL; in bpf_prog_attach_check_attach_type()
4127 if (!bpf_token_capable(prog->aux->token, CAP_NET_ADMIN)) in bpf_prog_attach_check_attach_type()
4134 if (prog->type != ptype) in bpf_prog_attach_check_attach_type()
4137 return prog->enforce_expected_attach_type && in bpf_prog_attach_check_attach_type()
4138 prog->expected_attach_type != attach_type ? in bpf_prog_attach_check_attach_type()
4152 if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI && in bpf_prog_attach_check_attach_type()
4155 if (prog->expected_attach_type == BPF_TRACE_KPROBE_SESSION && in bpf_prog_attach_check_attach_type()
4158 if (prog->expected_attach_type == BPF_TRACE_UPROBE_MULTI && in bpf_prog_attach_check_attach_type()
4161 if (prog->expected_attach_type == BPF_TRACE_UPROBE_SESSION && in bpf_prog_attach_check_attach_type()
4180 if (ptype == BPF_PROG_TYPE_UNSPEC || ptype != prog->type) in bpf_prog_attach_check_attach_type()
4204 struct bpf_prog *prog; in bpf_prog_attach() local
4224 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); in bpf_prog_attach()
4225 if (IS_ERR(prog)) in bpf_prog_attach()
4226 return PTR_ERR(prog); in bpf_prog_attach()
4228 if (bpf_prog_attach_check_attach_type(prog, attr->attach_type)) { in bpf_prog_attach()
4229 bpf_prog_put(prog); in bpf_prog_attach()
4236 ret = sock_map_get_from_fd(attr, prog); in bpf_prog_attach()
4239 ret = lirc_prog_attach(attr, prog); in bpf_prog_attach()
4242 ret = netns_bpf_prog_attach(attr, prog); in bpf_prog_attach()
4253 prog->expected_attach_type != BPF_LSM_CGROUP) in bpf_prog_attach()
4256 ret = cgroup_bpf_prog_attach(attr, ptype, prog); in bpf_prog_attach()
4261 ret = tcx_prog_attach(attr, prog); in bpf_prog_attach()
4263 ret = netkit_prog_attach(attr, prog); in bpf_prog_attach()
4270 bpf_prog_put(prog); in bpf_prog_attach()
4278 struct bpf_prog *prog = NULL; in bpf_prog_detach() local
4292 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); in bpf_prog_detach()
4293 if (IS_ERR(prog)) in bpf_prog_detach()
4294 return PTR_ERR(prog); in bpf_prog_detach()
4326 ret = tcx_prog_detach(attr, prog); in bpf_prog_detach()
4328 ret = netkit_prog_detach(attr, prog); in bpf_prog_detach()
4334 if (prog) in bpf_prog_detach()
4335 bpf_prog_put(prog); in bpf_prog_detach()
4408 struct bpf_prog *prog; in bpf_prog_test_run() local
4422 prog = bpf_prog_get(attr->test.prog_fd); in bpf_prog_test_run()
4423 if (IS_ERR(prog)) in bpf_prog_test_run()
4424 return PTR_ERR(prog); in bpf_prog_test_run()
4426 if (prog->aux->ops->test_run) in bpf_prog_test_run()
4427 ret = prog->aux->ops->test_run(prog, attr, uattr); in bpf_prog_test_run()
4429 bpf_prog_put(prog); in bpf_prog_test_run()
4482 struct bpf_prog *prog; in bpf_prog_get_curr_or_next() local
4486 prog = idr_get_next(&prog_idr, id); in bpf_prog_get_curr_or_next()
4487 if (prog) { in bpf_prog_get_curr_or_next()
4488 prog = bpf_prog_inc_not_zero(prog); in bpf_prog_get_curr_or_next()
4489 if (IS_ERR(prog)) { in bpf_prog_get_curr_or_next()
4496 return prog; in bpf_prog_get_curr_or_next()
4503 struct bpf_prog *prog; in bpf_prog_by_id() local
4509 prog = idr_find(&prog_idr, id); in bpf_prog_by_id()
4510 if (prog) in bpf_prog_by_id()
4511 prog = bpf_prog_inc_not_zero(prog); in bpf_prog_by_id()
4513 prog = ERR_PTR(-ENOENT); in bpf_prog_by_id()
4515 return prog; in bpf_prog_by_id()
4520 struct bpf_prog *prog; in bpf_prog_get_fd_by_id() local
4530 prog = bpf_prog_by_id(id); in bpf_prog_get_fd_by_id()
4531 if (IS_ERR(prog)) in bpf_prog_get_fd_by_id()
4532 return PTR_ERR(prog); in bpf_prog_get_fd_by_id()
4534 fd = bpf_prog_new_fd(prog); in bpf_prog_get_fd_by_id()
4536 bpf_prog_put(prog); in bpf_prog_get_fd_by_id()
4579 static const struct bpf_map *bpf_map_from_imm(const struct bpf_prog *prog, in bpf_map_from_imm() argument
4586 mutex_lock(&prog->aux->used_maps_mutex); in bpf_map_from_imm()
4587 for (i = 0, *off = 0; i < prog->aux->used_map_cnt; i++) { in bpf_map_from_imm()
4588 map = prog->aux->used_maps[i]; in bpf_map_from_imm()
4603 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_map_from_imm()
4607 static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog, in bpf_insn_prepare_dump() argument
4617 insns = kmemdup(prog->insnsi, bpf_prog_insn_size(prog), in bpf_insn_prepare_dump()
4622 for (i = 0; i < prog->len; i++) { in bpf_insn_prepare_dump()
4653 map = bpf_map_from_imm(prog, imm, &off, &type); in bpf_insn_prepare_dump()
4697 struct bpf_prog *prog, in bpf_prog_get_info_by_fd() argument
4702 struct btf *attach_btf = bpf_prog_get_target_btf(prog); in bpf_prog_get_info_by_fd()
4719 info.type = prog->type; in bpf_prog_get_info_by_fd()
4720 info.id = prog->aux->id; in bpf_prog_get_info_by_fd()
4721 info.load_time = prog->aux->load_time; in bpf_prog_get_info_by_fd()
4723 prog->aux->user->uid); in bpf_prog_get_info_by_fd()
4724 info.gpl_compatible = prog->gpl_compatible; in bpf_prog_get_info_by_fd()
4726 memcpy(info.tag, prog->tag, sizeof(prog->tag)); in bpf_prog_get_info_by_fd()
4727 memcpy(info.name, prog->aux->name, sizeof(prog->aux->name)); in bpf_prog_get_info_by_fd()
4729 mutex_lock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
4731 info.nr_map_ids = prog->aux->used_map_cnt; in bpf_prog_get_info_by_fd()
4738 if (put_user(prog->aux->used_maps[i]->id, in bpf_prog_get_info_by_fd()
4740 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
4744 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
4750 bpf_prog_get_stats(prog, &stats); in bpf_prog_get_info_by_fd()
4755 info.verified_insns = prog->aux->verified_insns; in bpf_prog_get_info_by_fd()
4756 if (prog->aux->btf) in bpf_prog_get_info_by_fd()
4757 info.btf_id = btf_obj_id(prog->aux->btf); in bpf_prog_get_info_by_fd()
4771 info.xlated_prog_len = bpf_prog_insn_size(prog); in bpf_prog_get_info_by_fd()
4776 if (prog->blinded && !bpf_dump_raw_ok(file->f_cred)) { in bpf_prog_get_info_by_fd()
4780 insns_sanitized = bpf_insn_prepare_dump(prog, file->f_cred); in bpf_prog_get_info_by_fd()
4791 if (bpf_prog_is_offloaded(prog->aux)) { in bpf_prog_get_info_by_fd()
4792 err = bpf_prog_offload_info_fill(&info, prog); in bpf_prog_get_info_by_fd()
4803 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4807 for (i = 0; i < prog->aux->func_cnt; i++) in bpf_prog_get_info_by_fd()
4808 info.jited_prog_len += prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4810 info.jited_prog_len = prog->jited_len; in bpf_prog_get_info_by_fd()
4821 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4826 for (i = 0; i < prog->aux->func_cnt; i++) { in bpf_prog_get_info_by_fd()
4827 len = prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4829 img = (u8 *) prog->aux->func[i]->bpf_func; in bpf_prog_get_info_by_fd()
4838 if (copy_to_user(uinsns, prog->bpf_func, ulen)) in bpf_prog_get_info_by_fd()
4847 info.nr_jited_ksyms = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4859 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4862 prog->aux->func[i]->bpf_func; in bpf_prog_get_info_by_fd()
4868 ksym_addr = (unsigned long) prog->bpf_func; in bpf_prog_get_info_by_fd()
4878 info.nr_jited_func_lens = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4887 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4890 prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4895 func_len = prog->jited_len; in bpf_prog_get_info_by_fd()
4904 info.attach_btf_id = prog->aux->attach_btf_id; in bpf_prog_get_info_by_fd()
4909 info.nr_func_info = prog->aux->func_info_cnt; in bpf_prog_get_info_by_fd()
4915 if (copy_to_user(user_finfo, prog->aux->func_info, in bpf_prog_get_info_by_fd()
4921 info.nr_line_info = prog->aux->nr_linfo; in bpf_prog_get_info_by_fd()
4927 if (copy_to_user(user_linfo, prog->aux->linfo, in bpf_prog_get_info_by_fd()
4933 if (prog->aux->jited_linfo) in bpf_prog_get_info_by_fd()
4934 info.nr_jited_line_info = prog->aux->nr_linfo; in bpf_prog_get_info_by_fd()
4946 line_addr = (unsigned long)prog->aux->jited_linfo[i]; in bpf_prog_get_info_by_fd()
4956 info.nr_prog_tags = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4963 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4966 prog->aux->func[i]->tag, in bpf_prog_get_info_by_fd()
4972 prog->tag, BPF_TAG_SIZE)) in bpf_prog_get_info_by_fd()
5069 if (link->prog) in bpf_link_get_info_by_fd()
5070 info.prog_id = link->prog->aux->id; in bpf_link_get_info_by_fd()
5265 raw_tp->link.prog->aux->id, in bpf_task_fd_query()
5356 struct bpf_prog *prog; in link_create() local
5365 prog = bpf_prog_get(attr->link_create.prog_fd); in link_create()
5366 if (IS_ERR(prog)) in link_create()
5367 return PTR_ERR(prog); in link_create()
5369 ret = bpf_prog_attach_check_attach_type(prog, in link_create()
5374 switch (prog->type) { in link_create()
5382 ret = cgroup_bpf_link_attach(attr, prog); in link_create()
5385 ret = bpf_tracing_prog_attach(prog, in link_create()
5392 if (attr->link_create.attach_type != prog->expected_attach_type) { in link_create()
5396 if (prog->expected_attach_type == BPF_TRACE_RAW_TP) in link_create()
5397 ret = bpf_raw_tp_link_attach(prog, NULL, attr->link_create.tracing.cookie); in link_create()
5398 else if (prog->expected_attach_type == BPF_TRACE_ITER) in link_create()
5399 ret = bpf_iter_link_attach(attr, uattr, prog); in link_create()
5400 else if (prog->expected_attach_type == BPF_LSM_CGROUP) in link_create()
5401 ret = cgroup_bpf_link_attach(attr, prog); in link_create()
5403 ret = bpf_tracing_prog_attach(prog, in link_create()
5410 ret = netns_bpf_link_create(attr, prog); in link_create()
5414 ret = sock_map_link_create(attr, prog); in link_create()
5418 ret = bpf_xdp_link_attach(attr, prog); in link_create()
5423 ret = tcx_link_attach(attr, prog); in link_create()
5425 ret = netkit_link_attach(attr, prog); in link_create()
5428 ret = bpf_nf_link_attach(attr, prog); in link_create()
5433 ret = bpf_perf_link_attach(attr, prog); in link_create()
5437 ret = bpf_perf_link_attach(attr, prog); in link_create()
5440 ret = bpf_kprobe_multi_link_attach(attr, prog); in link_create()
5443 ret = bpf_uprobe_multi_link_attach(attr, prog); in link_create()
5451 bpf_prog_put(prog); in link_create()
5718 struct bpf_prog *prog; in bpf_prog_bind_map() local
5729 prog = bpf_prog_get(attr->prog_bind_map.prog_fd); in bpf_prog_bind_map()
5730 if (IS_ERR(prog)) in bpf_prog_bind_map()
5731 return PTR_ERR(prog); in bpf_prog_bind_map()
5739 mutex_lock(&prog->aux->used_maps_mutex); in bpf_prog_bind_map()
5741 used_maps_old = prog->aux->used_maps; in bpf_prog_bind_map()
5743 for (i = 0; i < prog->aux->used_map_cnt; i++) in bpf_prog_bind_map()
5749 used_maps_new = kmalloc_array(prog->aux->used_map_cnt + 1, in bpf_prog_bind_map()
5760 if (prog->sleepable) in bpf_prog_bind_map()
5763 sizeof(used_maps_old[0]) * prog->aux->used_map_cnt); in bpf_prog_bind_map()
5764 used_maps_new[prog->aux->used_map_cnt] = map; in bpf_prog_bind_map()
5766 prog->aux->used_map_cnt++; in bpf_prog_bind_map()
5767 prog->aux->used_maps = used_maps_new; in bpf_prog_bind_map()
5772 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_bind_map()
5777 bpf_prog_put(prog); in bpf_prog_bind_map()
5946 const struct bpf_prog *prog, in syscall_prog_is_valid_access() argument
5985 struct bpf_prog * __maybe_unused prog; in kern_sys_bpf() local
5996 prog = bpf_prog_get_type(attr->test.prog_fd, BPF_PROG_TYPE_SYSCALL); in kern_sys_bpf()
5997 if (IS_ERR(prog)) in kern_sys_bpf()
5998 return PTR_ERR(prog); in kern_sys_bpf()
6000 if (attr->test.ctx_size_in < prog->aux->max_ctx_offset || in kern_sys_bpf()
6002 bpf_prog_put(prog); in kern_sys_bpf()
6007 if (!__bpf_prog_enter_sleepable_recur(prog, &run_ctx)) { in kern_sys_bpf()
6009 __bpf_prog_exit_sleepable_recur(prog, 0, &run_ctx); in kern_sys_bpf()
6010 bpf_prog_put(prog); in kern_sys_bpf()
6013 attr->test.retval = bpf_prog_run(prog, (void *) (long) attr->test.ctx_in); in kern_sys_bpf()
6014 __bpf_prog_exit_sleepable_recur(prog, 0 /* bpf_prog_run does runtime stats */, in kern_sys_bpf()
6016 bpf_prog_put(prog); in kern_sys_bpf()
6035 tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) in tracing_prog_func_proto() argument
6037 return bpf_base_func_proto(func_id, prog); in tracing_prog_func_proto()
6085 syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) in syscall_prog_func_proto() argument
6089 return !bpf_token_capable(prog->aux->token, CAP_PERFMON) in syscall_prog_func_proto()
6098 return tracing_prog_func_proto(func_id, prog); in syscall_prog_func_proto()