Lines Matching refs:prog
1922 static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog) in find_prog_type() argument
1933 if (!bpf_prog_is_dev_bound(prog->aux)) in find_prog_type()
1934 prog->aux->ops = ops; in find_prog_type()
1936 prog->aux->ops = &bpf_offload_prog_ops; in find_prog_type()
1937 prog->type = type; in find_prog_type()
1952 static void bpf_audit_prog(const struct bpf_prog *prog, unsigned int op) in bpf_audit_prog() argument
1967 prog->aux->id, bpf_audit_str[op]); in bpf_audit_prog()
1971 static int bpf_prog_alloc_id(struct bpf_prog *prog) in bpf_prog_alloc_id() argument
1977 id = idr_alloc_cyclic(&prog_idr, prog, 1, INT_MAX, GFP_ATOMIC); in bpf_prog_alloc_id()
1979 prog->aux->id = id; in bpf_prog_alloc_id()
1990 void bpf_prog_free_id(struct bpf_prog *prog, bool do_idr_lock) in bpf_prog_free_id() argument
1999 if (!prog->aux->id) in bpf_prog_free_id()
2007 idr_remove(&prog_idr, prog->aux->id); in bpf_prog_free_id()
2008 prog->aux->id = 0; in bpf_prog_free_id()
2024 bpf_prog_free(aux->prog); in __bpf_prog_put_rcu()
2027 static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred) in __bpf_prog_put_noref() argument
2029 bpf_prog_kallsyms_del_all(prog); in __bpf_prog_put_noref()
2030 btf_put(prog->aux->btf); in __bpf_prog_put_noref()
2031 kvfree(prog->aux->jited_linfo); in __bpf_prog_put_noref()
2032 kvfree(prog->aux->linfo); in __bpf_prog_put_noref()
2033 kfree(prog->aux->kfunc_tab); in __bpf_prog_put_noref()
2034 if (prog->aux->attach_btf) in __bpf_prog_put_noref()
2035 btf_put(prog->aux->attach_btf); in __bpf_prog_put_noref()
2038 if (prog->aux->sleepable) in __bpf_prog_put_noref()
2039 call_rcu_tasks_trace(&prog->aux->rcu, __bpf_prog_put_rcu); in __bpf_prog_put_noref()
2041 call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu); in __bpf_prog_put_noref()
2043 __bpf_prog_put_rcu(&prog->aux->rcu); in __bpf_prog_put_noref()
2050 struct bpf_prog *prog; in bpf_prog_put_deferred() local
2053 prog = aux->prog; in bpf_prog_put_deferred()
2054 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_UNLOAD, 0); in bpf_prog_put_deferred()
2055 bpf_audit_prog(prog, BPF_AUDIT_UNLOAD); in bpf_prog_put_deferred()
2056 __bpf_prog_put_noref(prog, true); in bpf_prog_put_deferred()
2059 static void __bpf_prog_put(struct bpf_prog *prog, bool do_idr_lock) in __bpf_prog_put() argument
2061 struct bpf_prog_aux *aux = prog->aux; in __bpf_prog_put()
2065 bpf_prog_free_id(prog, do_idr_lock); in __bpf_prog_put()
2076 void bpf_prog_put(struct bpf_prog *prog) in bpf_prog_put() argument
2078 __bpf_prog_put(prog, true); in bpf_prog_put()
2084 struct bpf_prog *prog = filp->private_data; in bpf_prog_release() local
2086 bpf_prog_put(prog); in bpf_prog_release()
2096 void notrace bpf_prog_inc_misses_counter(struct bpf_prog *prog) in bpf_prog_inc_misses_counter() argument
2101 stats = this_cpu_ptr(prog->stats); in bpf_prog_inc_misses_counter()
2107 static void bpf_prog_get_stats(const struct bpf_prog *prog, in bpf_prog_get_stats() argument
2118 st = per_cpu_ptr(prog->stats, cpu); in bpf_prog_get_stats()
2137 const struct bpf_prog *prog = filp->private_data; in bpf_prog_show_fdinfo() local
2138 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; in bpf_prog_show_fdinfo()
2141 bpf_prog_get_stats(prog, &stats); in bpf_prog_show_fdinfo()
2142 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); in bpf_prog_show_fdinfo()
2153 prog->type, in bpf_prog_show_fdinfo()
2154 prog->jited, in bpf_prog_show_fdinfo()
2156 prog->pages * 1ULL << PAGE_SHIFT, in bpf_prog_show_fdinfo()
2157 prog->aux->id, in bpf_prog_show_fdinfo()
2161 prog->aux->verified_insns); in bpf_prog_show_fdinfo()
2174 int bpf_prog_new_fd(struct bpf_prog *prog) in bpf_prog_new_fd() argument
2178 ret = security_bpf_prog(prog); in bpf_prog_new_fd()
2182 return anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog, in bpf_prog_new_fd()
2198 void bpf_prog_add(struct bpf_prog *prog, int i) in bpf_prog_add() argument
2200 atomic64_add(i, &prog->aux->refcnt); in bpf_prog_add()
2204 void bpf_prog_sub(struct bpf_prog *prog, int i) in bpf_prog_sub() argument
2211 WARN_ON(atomic64_sub_return(i, &prog->aux->refcnt) == 0); in bpf_prog_sub()
2215 void bpf_prog_inc(struct bpf_prog *prog) in bpf_prog_inc() argument
2217 atomic64_inc(&prog->aux->refcnt); in bpf_prog_inc()
2222 struct bpf_prog *bpf_prog_inc_not_zero(struct bpf_prog *prog) in bpf_prog_inc_not_zero() argument
2226 refold = atomic64_fetch_add_unless(&prog->aux->refcnt, 1, 0); in bpf_prog_inc_not_zero()
2231 return prog; in bpf_prog_inc_not_zero()
2235 bool bpf_prog_get_ok(struct bpf_prog *prog, in bpf_prog_get_ok() argument
2242 if (prog->type != *attach_type) in bpf_prog_get_ok()
2244 if (bpf_prog_is_dev_bound(prog->aux) && !attach_drv) in bpf_prog_get_ok()
2254 struct bpf_prog *prog; in __bpf_prog_get() local
2256 prog = ____bpf_prog_get(f); in __bpf_prog_get()
2257 if (IS_ERR(prog)) in __bpf_prog_get()
2258 return prog; in __bpf_prog_get()
2259 if (!bpf_prog_get_ok(prog, attach_type, attach_drv)) { in __bpf_prog_get()
2260 prog = ERR_PTR(-EINVAL); in __bpf_prog_get()
2264 bpf_prog_inc(prog); in __bpf_prog_get()
2267 return prog; in __bpf_prog_get()
2466 struct bpf_prog *prog, *dst_prog = NULL; in bpf_prog_load() local
2551 prog = bpf_prog_alloc(bpf_prog_size(attr->insn_cnt), GFP_USER); in bpf_prog_load()
2552 if (!prog) { in bpf_prog_load()
2560 prog->expected_attach_type = attr->expected_attach_type; in bpf_prog_load()
2561 prog->aux->attach_btf = attach_btf; in bpf_prog_load()
2562 prog->aux->attach_btf_id = attr->attach_btf_id; in bpf_prog_load()
2563 prog->aux->dst_prog = dst_prog; in bpf_prog_load()
2564 prog->aux->offload_requested = !!attr->prog_ifindex; in bpf_prog_load()
2565 prog->aux->sleepable = attr->prog_flags & BPF_F_SLEEPABLE; in bpf_prog_load()
2566 prog->aux->xdp_has_frags = attr->prog_flags & BPF_F_XDP_HAS_FRAGS; in bpf_prog_load()
2568 err = security_bpf_prog_alloc(prog->aux); in bpf_prog_load()
2572 prog->aux->user = get_current_user(); in bpf_prog_load()
2573 prog->len = attr->insn_cnt; in bpf_prog_load()
2576 if (copy_from_bpfptr(prog->insns, in bpf_prog_load()
2578 bpf_prog_insn_size(prog)) != 0) in bpf_prog_load()
2581 prog->orig_prog = NULL; in bpf_prog_load()
2582 prog->jited = 0; in bpf_prog_load()
2584 atomic64_set(&prog->aux->refcnt, 1); in bpf_prog_load()
2585 prog->gpl_compatible = is_gpl ? 1 : 0; in bpf_prog_load()
2587 if (bpf_prog_is_dev_bound(prog->aux)) { in bpf_prog_load()
2588 err = bpf_prog_offload_init(prog, attr); in bpf_prog_load()
2594 err = find_prog_type(type, prog); in bpf_prog_load()
2598 prog->aux->load_time = ktime_get_boottime_ns(); in bpf_prog_load()
2599 err = bpf_obj_name_cpy(prog->aux->name, attr->prog_name, in bpf_prog_load()
2605 err = bpf_check(&prog, attr, uattr); in bpf_prog_load()
2609 prog = bpf_prog_select_runtime(prog, &err); in bpf_prog_load()
2613 err = bpf_prog_alloc_id(prog); in bpf_prog_load()
2631 bpf_prog_kallsyms_add(prog); in bpf_prog_load()
2632 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_LOAD, 0); in bpf_prog_load()
2633 bpf_audit_prog(prog, BPF_AUDIT_LOAD); in bpf_prog_load()
2635 err = bpf_prog_new_fd(prog); in bpf_prog_load()
2637 bpf_prog_put(prog); in bpf_prog_load()
2645 __bpf_prog_put_noref(prog, prog->aux->func_cnt); in bpf_prog_load()
2648 free_uid(prog->aux->user); in bpf_prog_load()
2649 security_bpf_prog_free(prog->aux); in bpf_prog_load()
2651 if (prog->aux->attach_btf) in bpf_prog_load()
2652 btf_put(prog->aux->attach_btf); in bpf_prog_load()
2653 bpf_prog_free(prog); in bpf_prog_load()
2678 const struct bpf_link_ops *ops, struct bpf_prog *prog) in bpf_link_init() argument
2684 link->prog = prog; in bpf_link_init()
2706 primer->link->prog = NULL; in bpf_link_cleanup()
2721 if (link->prog) { in bpf_link_free()
2724 bpf_prog_put(link->prog); in bpf_link_free()
2777 const struct bpf_prog *prog = link->prog; in bpf_link_show_fdinfo() local
2778 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; in bpf_link_show_fdinfo()
2780 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); in bpf_link_show_fdinfo()
2789 prog->aux->id); in bpf_link_show_fdinfo()
2952 static int bpf_tracing_prog_attach(struct bpf_prog *prog, in bpf_tracing_prog_attach() argument
2964 switch (prog->type) { in bpf_tracing_prog_attach()
2966 if (prog->expected_attach_type != BPF_TRACE_FENTRY && in bpf_tracing_prog_attach()
2967 prog->expected_attach_type != BPF_TRACE_FEXIT && in bpf_tracing_prog_attach()
2968 prog->expected_attach_type != BPF_MODIFY_RETURN) { in bpf_tracing_prog_attach()
2974 if (prog->expected_attach_type != 0) { in bpf_tracing_prog_attach()
2980 if (prog->expected_attach_type != BPF_LSM_MAC) { in bpf_tracing_prog_attach()
2997 if (prog->type != BPF_PROG_TYPE_EXT) { in bpf_tracing_prog_attach()
3018 &bpf_tracing_link_lops, prog); in bpf_tracing_prog_attach()
3019 link->attach_type = prog->expected_attach_type; in bpf_tracing_prog_attach()
3022 mutex_lock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3042 if (!prog->aux->dst_trampoline && !tgt_prog) { in bpf_tracing_prog_attach()
3049 if (prog->type != BPF_PROG_TYPE_TRACING && in bpf_tracing_prog_attach()
3050 prog->type != BPF_PROG_TYPE_LSM) { in bpf_tracing_prog_attach()
3054 btf_id = prog->aux->attach_btf_id; in bpf_tracing_prog_attach()
3055 key = bpf_trampoline_compute_key(NULL, prog->aux->attach_btf, btf_id); in bpf_tracing_prog_attach()
3058 if (!prog->aux->dst_trampoline || in bpf_tracing_prog_attach()
3059 (key && key != prog->aux->dst_trampoline->key)) { in bpf_tracing_prog_attach()
3066 err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id, in bpf_tracing_prog_attach()
3084 tr = prog->aux->dst_trampoline; in bpf_tracing_prog_attach()
3085 tgt_prog = prog->aux->dst_prog; in bpf_tracing_prog_attach()
3106 if (prog->aux->dst_prog && in bpf_tracing_prog_attach()
3107 (tgt_prog_fd || tr != prog->aux->dst_trampoline)) in bpf_tracing_prog_attach()
3109 bpf_prog_put(prog->aux->dst_prog); in bpf_tracing_prog_attach()
3110 if (prog->aux->dst_trampoline && tr != prog->aux->dst_trampoline) in bpf_tracing_prog_attach()
3112 bpf_trampoline_put(prog->aux->dst_trampoline); in bpf_tracing_prog_attach()
3114 prog->aux->dst_prog = NULL; in bpf_tracing_prog_attach()
3115 prog->aux->dst_trampoline = NULL; in bpf_tracing_prog_attach()
3116 mutex_unlock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3120 if (tr && tr != prog->aux->dst_trampoline) in bpf_tracing_prog_attach()
3122 mutex_unlock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3140 bpf_probe_unregister(raw_tp->btp, raw_tp->link.prog); in bpf_raw_tp_link_release()
3231 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_perf_link_attach() argument
3251 bpf_link_init(&link->link, BPF_LINK_TYPE_PERF_EVENT, &bpf_perf_link_lops, prog); in bpf_perf_link_attach()
3261 err = perf_event_set_bpf_prog(event, prog, attr->link_create.perf_event.bpf_cookie); in bpf_perf_link_attach()
3267 bpf_prog_inc(prog); in bpf_perf_link_attach()
3276 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_perf_link_attach() argument
3282 static int bpf_raw_tp_link_attach(struct bpf_prog *prog, in bpf_raw_tp_link_attach() argument
3292 switch (prog->type) { in bpf_raw_tp_link_attach()
3301 if (prog->type == BPF_PROG_TYPE_TRACING && in bpf_raw_tp_link_attach()
3302 prog->expected_attach_type == BPF_TRACE_RAW_TP) { in bpf_raw_tp_link_attach()
3303 tp_name = prog->aux->attach_func_name; in bpf_raw_tp_link_attach()
3306 return bpf_tracing_prog_attach(prog, 0, 0, 0); in bpf_raw_tp_link_attach()
3328 &bpf_raw_tp_link_lops, prog); in bpf_raw_tp_link_attach()
3337 err = bpf_probe_register(link->btp, prog); in bpf_raw_tp_link_attach()
3354 struct bpf_prog *prog; in bpf_raw_tracepoint_open() local
3360 prog = bpf_prog_get(attr->raw_tracepoint.prog_fd); in bpf_raw_tracepoint_open()
3361 if (IS_ERR(prog)) in bpf_raw_tracepoint_open()
3362 return PTR_ERR(prog); in bpf_raw_tracepoint_open()
3364 fd = bpf_raw_tp_link_attach(prog, u64_to_user_ptr(attr->raw_tracepoint.name)); in bpf_raw_tracepoint_open()
3366 bpf_prog_put(prog); in bpf_raw_tracepoint_open()
3370 static int bpf_prog_attach_check_attach_type(const struct bpf_prog *prog, in bpf_prog_attach_check_attach_type() argument
3373 switch (prog->type) { in bpf_prog_attach_check_attach_type()
3378 return attach_type == prog->expected_attach_type ? 0 : -EINVAL; in bpf_prog_attach_check_attach_type()
3385 return prog->enforce_expected_attach_type && in bpf_prog_attach_check_attach_type()
3386 prog->expected_attach_type != attach_type ? in bpf_prog_attach_check_attach_type()
3464 struct bpf_prog *prog; in bpf_prog_attach() local
3477 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); in bpf_prog_attach()
3478 if (IS_ERR(prog)) in bpf_prog_attach()
3479 return PTR_ERR(prog); in bpf_prog_attach()
3481 if (bpf_prog_attach_check_attach_type(prog, attr->attach_type)) { in bpf_prog_attach()
3482 bpf_prog_put(prog); in bpf_prog_attach()
3489 ret = sock_map_get_from_fd(attr, prog); in bpf_prog_attach()
3492 ret = lirc_prog_attach(attr, prog); in bpf_prog_attach()
3495 ret = netns_bpf_prog_attach(attr, prog); in bpf_prog_attach()
3506 prog->expected_attach_type != BPF_LSM_CGROUP) in bpf_prog_attach()
3509 ret = cgroup_bpf_prog_attach(attr, ptype, prog); in bpf_prog_attach()
3516 bpf_prog_put(prog); in bpf_prog_attach()
3611 struct bpf_prog *prog; in bpf_prog_test_run() local
3625 prog = bpf_prog_get(attr->test.prog_fd); in bpf_prog_test_run()
3626 if (IS_ERR(prog)) in bpf_prog_test_run()
3627 return PTR_ERR(prog); in bpf_prog_test_run()
3629 if (prog->aux->ops->test_run) in bpf_prog_test_run()
3630 ret = prog->aux->ops->test_run(prog, attr, uattr); in bpf_prog_test_run()
3632 bpf_prog_put(prog); in bpf_prog_test_run()
3685 struct bpf_prog *prog; in bpf_prog_get_curr_or_next() local
3689 prog = idr_get_next(&prog_idr, id); in bpf_prog_get_curr_or_next()
3690 if (prog) { in bpf_prog_get_curr_or_next()
3691 prog = bpf_prog_inc_not_zero(prog); in bpf_prog_get_curr_or_next()
3692 if (IS_ERR(prog)) { in bpf_prog_get_curr_or_next()
3699 return prog; in bpf_prog_get_curr_or_next()
3706 struct bpf_prog *prog; in bpf_prog_by_id() local
3712 prog = idr_find(&prog_idr, id); in bpf_prog_by_id()
3713 if (prog) in bpf_prog_by_id()
3714 prog = bpf_prog_inc_not_zero(prog); in bpf_prog_by_id()
3716 prog = ERR_PTR(-ENOENT); in bpf_prog_by_id()
3718 return prog; in bpf_prog_by_id()
3723 struct bpf_prog *prog; in bpf_prog_get_fd_by_id() local
3733 prog = bpf_prog_by_id(id); in bpf_prog_get_fd_by_id()
3734 if (IS_ERR(prog)) in bpf_prog_get_fd_by_id()
3735 return PTR_ERR(prog); in bpf_prog_get_fd_by_id()
3737 fd = bpf_prog_new_fd(prog); in bpf_prog_get_fd_by_id()
3739 bpf_prog_put(prog); in bpf_prog_get_fd_by_id()
3782 static const struct bpf_map *bpf_map_from_imm(const struct bpf_prog *prog, in bpf_map_from_imm() argument
3789 mutex_lock(&prog->aux->used_maps_mutex); in bpf_map_from_imm()
3790 for (i = 0, *off = 0; i < prog->aux->used_map_cnt; i++) { in bpf_map_from_imm()
3791 map = prog->aux->used_maps[i]; in bpf_map_from_imm()
3806 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_map_from_imm()
3810 static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog, in bpf_insn_prepare_dump() argument
3820 insns = kmemdup(prog->insnsi, bpf_prog_insn_size(prog), in bpf_insn_prepare_dump()
3825 for (i = 0; i < prog->len; i++) { in bpf_insn_prepare_dump()
3850 map = bpf_map_from_imm(prog, imm, &off, &type); in bpf_insn_prepare_dump()
3894 struct bpf_prog *prog, in bpf_prog_get_info_by_fd() argument
3899 struct btf *attach_btf = bpf_prog_get_target_btf(prog); in bpf_prog_get_info_by_fd()
3916 info.type = prog->type; in bpf_prog_get_info_by_fd()
3917 info.id = prog->aux->id; in bpf_prog_get_info_by_fd()
3918 info.load_time = prog->aux->load_time; in bpf_prog_get_info_by_fd()
3920 prog->aux->user->uid); in bpf_prog_get_info_by_fd()
3921 info.gpl_compatible = prog->gpl_compatible; in bpf_prog_get_info_by_fd()
3923 memcpy(info.tag, prog->tag, sizeof(prog->tag)); in bpf_prog_get_info_by_fd()
3924 memcpy(info.name, prog->aux->name, sizeof(prog->aux->name)); in bpf_prog_get_info_by_fd()
3926 mutex_lock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
3928 info.nr_map_ids = prog->aux->used_map_cnt; in bpf_prog_get_info_by_fd()
3935 if (put_user(prog->aux->used_maps[i]->id, in bpf_prog_get_info_by_fd()
3937 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
3941 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
3947 bpf_prog_get_stats(prog, &stats); in bpf_prog_get_info_by_fd()
3952 info.verified_insns = prog->aux->verified_insns; in bpf_prog_get_info_by_fd()
3966 info.xlated_prog_len = bpf_prog_insn_size(prog); in bpf_prog_get_info_by_fd()
3971 if (prog->blinded && !bpf_dump_raw_ok(file->f_cred)) { in bpf_prog_get_info_by_fd()
3975 insns_sanitized = bpf_insn_prepare_dump(prog, file->f_cred); in bpf_prog_get_info_by_fd()
3986 if (bpf_prog_is_dev_bound(prog->aux)) { in bpf_prog_get_info_by_fd()
3987 err = bpf_prog_offload_info_fill(&info, prog); in bpf_prog_get_info_by_fd()
3998 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4002 for (i = 0; i < prog->aux->func_cnt; i++) in bpf_prog_get_info_by_fd()
4003 info.jited_prog_len += prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4005 info.jited_prog_len = prog->jited_len; in bpf_prog_get_info_by_fd()
4016 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4021 for (i = 0; i < prog->aux->func_cnt; i++) { in bpf_prog_get_info_by_fd()
4022 len = prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4024 img = (u8 *) prog->aux->func[i]->bpf_func; in bpf_prog_get_info_by_fd()
4033 if (copy_to_user(uinsns, prog->bpf_func, ulen)) in bpf_prog_get_info_by_fd()
4042 info.nr_jited_ksyms = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4054 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4057 prog->aux->func[i]->bpf_func; in bpf_prog_get_info_by_fd()
4063 ksym_addr = (unsigned long) prog->bpf_func; in bpf_prog_get_info_by_fd()
4073 info.nr_jited_func_lens = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4082 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4085 prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4090 func_len = prog->jited_len; in bpf_prog_get_info_by_fd()
4099 if (prog->aux->btf) in bpf_prog_get_info_by_fd()
4100 info.btf_id = btf_obj_id(prog->aux->btf); in bpf_prog_get_info_by_fd()
4101 info.attach_btf_id = prog->aux->attach_btf_id; in bpf_prog_get_info_by_fd()
4106 info.nr_func_info = prog->aux->func_info_cnt; in bpf_prog_get_info_by_fd()
4112 if (copy_to_user(user_finfo, prog->aux->func_info, in bpf_prog_get_info_by_fd()
4118 info.nr_line_info = prog->aux->nr_linfo; in bpf_prog_get_info_by_fd()
4124 if (copy_to_user(user_linfo, prog->aux->linfo, in bpf_prog_get_info_by_fd()
4130 if (prog->aux->jited_linfo) in bpf_prog_get_info_by_fd()
4131 info.nr_jited_line_info = prog->aux->nr_linfo; in bpf_prog_get_info_by_fd()
4143 line_addr = (unsigned long)prog->aux->jited_linfo[i]; in bpf_prog_get_info_by_fd()
4153 info.nr_prog_tags = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4160 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4163 prog->aux->func[i]->tag, in bpf_prog_get_info_by_fd()
4169 prog->tag, BPF_TAG_SIZE)) in bpf_prog_get_info_by_fd()
4264 info.prog_id = link->prog->aux->id; in bpf_link_get_info_by_fd()
4429 raw_tp->link.prog->aux->id, in bpf_task_fd_query()
4521 struct bpf_prog *prog; in link_create() local
4527 prog = bpf_prog_get(attr->link_create.prog_fd); in link_create()
4528 if (IS_ERR(prog)) in link_create()
4529 return PTR_ERR(prog); in link_create()
4531 ret = bpf_prog_attach_check_attach_type(prog, in link_create()
4536 switch (prog->type) { in link_create()
4555 if (ptype == BPF_PROG_TYPE_UNSPEC || ptype != prog->type) { in link_create()
4562 switch (prog->type) { in link_create()
4570 ret = cgroup_bpf_link_attach(attr, prog); in link_create()
4573 ret = bpf_tracing_prog_attach(prog, in link_create()
4580 if (attr->link_create.attach_type != prog->expected_attach_type) { in link_create()
4584 if (prog->expected_attach_type == BPF_TRACE_RAW_TP) in link_create()
4585 ret = bpf_raw_tp_link_attach(prog, NULL); in link_create()
4586 else if (prog->expected_attach_type == BPF_TRACE_ITER) in link_create()
4587 ret = bpf_iter_link_attach(attr, uattr, prog); in link_create()
4588 else if (prog->expected_attach_type == BPF_LSM_CGROUP) in link_create()
4589 ret = cgroup_bpf_link_attach(attr, prog); in link_create()
4591 ret = bpf_tracing_prog_attach(prog, in link_create()
4598 ret = netns_bpf_link_create(attr, prog); in link_create()
4602 ret = bpf_xdp_link_attach(attr, prog); in link_create()
4607 ret = bpf_perf_link_attach(attr, prog); in link_create()
4611 ret = bpf_perf_link_attach(attr, prog); in link_create()
4613 ret = bpf_kprobe_multi_link_attach(attr, prog); in link_create()
4621 bpf_prog_put(prog); in link_create()
4853 struct bpf_prog *prog; in bpf_prog_bind_map() local
4864 prog = bpf_prog_get(attr->prog_bind_map.prog_fd); in bpf_prog_bind_map()
4865 if (IS_ERR(prog)) in bpf_prog_bind_map()
4866 return PTR_ERR(prog); in bpf_prog_bind_map()
4874 mutex_lock(&prog->aux->used_maps_mutex); in bpf_prog_bind_map()
4876 used_maps_old = prog->aux->used_maps; in bpf_prog_bind_map()
4878 for (i = 0; i < prog->aux->used_map_cnt; i++) in bpf_prog_bind_map()
4884 used_maps_new = kmalloc_array(prog->aux->used_map_cnt + 1, in bpf_prog_bind_map()
4893 sizeof(used_maps_old[0]) * prog->aux->used_map_cnt); in bpf_prog_bind_map()
4894 used_maps_new[prog->aux->used_map_cnt] = map; in bpf_prog_bind_map()
4896 prog->aux->used_map_cnt++; in bpf_prog_bind_map()
4897 prog->aux->used_maps = used_maps_new; in bpf_prog_bind_map()
4902 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_bind_map()
4907 bpf_prog_put(prog); in bpf_prog_bind_map()
5074 const struct bpf_prog *prog, in syscall_prog_is_valid_access() argument
5113 struct bpf_prog * __maybe_unused prog; in kern_sys_bpf() local
5124 prog = bpf_prog_get_type(attr->test.prog_fd, BPF_PROG_TYPE_SYSCALL); in kern_sys_bpf()
5125 if (IS_ERR(prog)) in kern_sys_bpf()
5126 return PTR_ERR(prog); in kern_sys_bpf()
5128 if (attr->test.ctx_size_in < prog->aux->max_ctx_offset || in kern_sys_bpf()
5130 bpf_prog_put(prog); in kern_sys_bpf()
5136 if (!__bpf_prog_enter_sleepable(prog, &run_ctx)) { in kern_sys_bpf()
5138 bpf_prog_put(prog); in kern_sys_bpf()
5141 attr->test.retval = bpf_prog_run(prog, (void *) (long) attr->test.ctx_in); in kern_sys_bpf()
5142 __bpf_prog_exit_sleepable(prog, 0 /* bpf_prog_run does runtime stats */, &run_ctx); in kern_sys_bpf()
5143 bpf_prog_put(prog); in kern_sys_bpf()
5162 tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) in tracing_prog_func_proto() argument
5210 syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) in syscall_prog_func_proto() argument
5222 return tracing_prog_func_proto(func_id, prog); in syscall_prog_func_proto()