Lines Matching refs:prog
1930 static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog) in find_prog_type() argument
1941 if (!bpf_prog_is_dev_bound(prog->aux)) in find_prog_type()
1942 prog->aux->ops = ops; in find_prog_type()
1944 prog->aux->ops = &bpf_offload_prog_ops; in find_prog_type()
1945 prog->type = type; in find_prog_type()
1960 static void bpf_audit_prog(const struct bpf_prog *prog, unsigned int op) in bpf_audit_prog() argument
1975 prog->aux->id, bpf_audit_str[op]); in bpf_audit_prog()
1979 static int bpf_prog_alloc_id(struct bpf_prog *prog) in bpf_prog_alloc_id() argument
1985 id = idr_alloc_cyclic(&prog_idr, prog, 1, INT_MAX, GFP_ATOMIC); in bpf_prog_alloc_id()
1987 prog->aux->id = id; in bpf_prog_alloc_id()
1998 void bpf_prog_free_id(struct bpf_prog *prog, bool do_idr_lock) in bpf_prog_free_id() argument
2007 if (!prog->aux->id) in bpf_prog_free_id()
2015 idr_remove(&prog_idr, prog->aux->id); in bpf_prog_free_id()
2016 prog->aux->id = 0; in bpf_prog_free_id()
2032 bpf_prog_free(aux->prog); in __bpf_prog_put_rcu()
2035 static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred) in __bpf_prog_put_noref() argument
2037 bpf_prog_kallsyms_del_all(prog); in __bpf_prog_put_noref()
2038 btf_put(prog->aux->btf); in __bpf_prog_put_noref()
2039 kvfree(prog->aux->jited_linfo); in __bpf_prog_put_noref()
2040 kvfree(prog->aux->linfo); in __bpf_prog_put_noref()
2041 kfree(prog->aux->kfunc_tab); in __bpf_prog_put_noref()
2042 if (prog->aux->attach_btf) in __bpf_prog_put_noref()
2043 btf_put(prog->aux->attach_btf); in __bpf_prog_put_noref()
2046 if (prog->aux->sleepable) in __bpf_prog_put_noref()
2047 call_rcu_tasks_trace(&prog->aux->rcu, __bpf_prog_put_rcu); in __bpf_prog_put_noref()
2049 call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu); in __bpf_prog_put_noref()
2051 __bpf_prog_put_rcu(&prog->aux->rcu); in __bpf_prog_put_noref()
2058 struct bpf_prog *prog; in bpf_prog_put_deferred() local
2061 prog = aux->prog; in bpf_prog_put_deferred()
2062 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_UNLOAD, 0); in bpf_prog_put_deferred()
2063 bpf_audit_prog(prog, BPF_AUDIT_UNLOAD); in bpf_prog_put_deferred()
2064 bpf_prog_free_id(prog, true); in bpf_prog_put_deferred()
2065 __bpf_prog_put_noref(prog, true); in bpf_prog_put_deferred()
2068 static void __bpf_prog_put(struct bpf_prog *prog, bool do_idr_lock) in __bpf_prog_put() argument
2070 struct bpf_prog_aux *aux = prog->aux; in __bpf_prog_put()
2082 void bpf_prog_put(struct bpf_prog *prog) in bpf_prog_put() argument
2084 __bpf_prog_put(prog, true); in bpf_prog_put()
2090 struct bpf_prog *prog = filp->private_data; in bpf_prog_release() local
2092 bpf_prog_put(prog); in bpf_prog_release()
2102 void notrace bpf_prog_inc_misses_counter(struct bpf_prog *prog) in bpf_prog_inc_misses_counter() argument
2107 stats = this_cpu_ptr(prog->stats); in bpf_prog_inc_misses_counter()
2113 static void bpf_prog_get_stats(const struct bpf_prog *prog, in bpf_prog_get_stats() argument
2124 st = per_cpu_ptr(prog->stats, cpu); in bpf_prog_get_stats()
2143 const struct bpf_prog *prog = filp->private_data; in bpf_prog_show_fdinfo() local
2144 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; in bpf_prog_show_fdinfo()
2147 bpf_prog_get_stats(prog, &stats); in bpf_prog_show_fdinfo()
2148 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); in bpf_prog_show_fdinfo()
2159 prog->type, in bpf_prog_show_fdinfo()
2160 prog->jited, in bpf_prog_show_fdinfo()
2162 prog->pages * 1ULL << PAGE_SHIFT, in bpf_prog_show_fdinfo()
2163 prog->aux->id, in bpf_prog_show_fdinfo()
2167 prog->aux->verified_insns); in bpf_prog_show_fdinfo()
2180 int bpf_prog_new_fd(struct bpf_prog *prog) in bpf_prog_new_fd() argument
2184 ret = security_bpf_prog(prog); in bpf_prog_new_fd()
2188 return anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog, in bpf_prog_new_fd()
2204 void bpf_prog_add(struct bpf_prog *prog, int i) in bpf_prog_add() argument
2206 atomic64_add(i, &prog->aux->refcnt); in bpf_prog_add()
2210 void bpf_prog_sub(struct bpf_prog *prog, int i) in bpf_prog_sub() argument
2217 WARN_ON(atomic64_sub_return(i, &prog->aux->refcnt) == 0); in bpf_prog_sub()
2221 void bpf_prog_inc(struct bpf_prog *prog) in bpf_prog_inc() argument
2223 atomic64_inc(&prog->aux->refcnt); in bpf_prog_inc()
2228 struct bpf_prog *bpf_prog_inc_not_zero(struct bpf_prog *prog) in bpf_prog_inc_not_zero() argument
2232 refold = atomic64_fetch_add_unless(&prog->aux->refcnt, 1, 0); in bpf_prog_inc_not_zero()
2237 return prog; in bpf_prog_inc_not_zero()
2241 bool bpf_prog_get_ok(struct bpf_prog *prog, in bpf_prog_get_ok() argument
2248 if (prog->type != *attach_type) in bpf_prog_get_ok()
2250 if (bpf_prog_is_dev_bound(prog->aux) && !attach_drv) in bpf_prog_get_ok()
2260 struct bpf_prog *prog; in __bpf_prog_get() local
2262 prog = ____bpf_prog_get(f); in __bpf_prog_get()
2263 if (IS_ERR(prog)) in __bpf_prog_get()
2264 return prog; in __bpf_prog_get()
2265 if (!bpf_prog_get_ok(prog, attach_type, attach_drv)) { in __bpf_prog_get()
2266 prog = ERR_PTR(-EINVAL); in __bpf_prog_get()
2270 bpf_prog_inc(prog); in __bpf_prog_get()
2273 return prog; in __bpf_prog_get()
2472 struct bpf_prog *prog, *dst_prog = NULL; in bpf_prog_load() local
2557 prog = bpf_prog_alloc(bpf_prog_size(attr->insn_cnt), GFP_USER); in bpf_prog_load()
2558 if (!prog) { in bpf_prog_load()
2566 prog->expected_attach_type = attr->expected_attach_type; in bpf_prog_load()
2567 prog->aux->attach_btf = attach_btf; in bpf_prog_load()
2568 prog->aux->attach_btf_id = attr->attach_btf_id; in bpf_prog_load()
2569 prog->aux->dst_prog = dst_prog; in bpf_prog_load()
2570 prog->aux->offload_requested = !!attr->prog_ifindex; in bpf_prog_load()
2571 prog->aux->sleepable = attr->prog_flags & BPF_F_SLEEPABLE; in bpf_prog_load()
2572 prog->aux->xdp_has_frags = attr->prog_flags & BPF_F_XDP_HAS_FRAGS; in bpf_prog_load()
2574 err = security_bpf_prog_alloc(prog->aux); in bpf_prog_load()
2578 prog->aux->user = get_current_user(); in bpf_prog_load()
2579 prog->len = attr->insn_cnt; in bpf_prog_load()
2582 if (copy_from_bpfptr(prog->insns, in bpf_prog_load()
2584 bpf_prog_insn_size(prog)) != 0) in bpf_prog_load()
2587 prog->orig_prog = NULL; in bpf_prog_load()
2588 prog->jited = 0; in bpf_prog_load()
2590 atomic64_set(&prog->aux->refcnt, 1); in bpf_prog_load()
2591 prog->gpl_compatible = is_gpl ? 1 : 0; in bpf_prog_load()
2593 if (bpf_prog_is_dev_bound(prog->aux)) { in bpf_prog_load()
2594 err = bpf_prog_offload_init(prog, attr); in bpf_prog_load()
2600 err = find_prog_type(type, prog); in bpf_prog_load()
2604 prog->aux->load_time = ktime_get_boottime_ns(); in bpf_prog_load()
2605 err = bpf_obj_name_cpy(prog->aux->name, attr->prog_name, in bpf_prog_load()
2611 err = bpf_check(&prog, attr, uattr); in bpf_prog_load()
2615 prog = bpf_prog_select_runtime(prog, &err); in bpf_prog_load()
2619 err = bpf_prog_alloc_id(prog); in bpf_prog_load()
2637 bpf_prog_kallsyms_add(prog); in bpf_prog_load()
2638 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_LOAD, 0); in bpf_prog_load()
2639 bpf_audit_prog(prog, BPF_AUDIT_LOAD); in bpf_prog_load()
2641 err = bpf_prog_new_fd(prog); in bpf_prog_load()
2643 bpf_prog_put(prog); in bpf_prog_load()
2651 __bpf_prog_put_noref(prog, prog->aux->func_cnt); in bpf_prog_load()
2654 free_uid(prog->aux->user); in bpf_prog_load()
2655 security_bpf_prog_free(prog->aux); in bpf_prog_load()
2657 if (prog->aux->attach_btf) in bpf_prog_load()
2658 btf_put(prog->aux->attach_btf); in bpf_prog_load()
2659 bpf_prog_free(prog); in bpf_prog_load()
2684 const struct bpf_link_ops *ops, struct bpf_prog *prog) in bpf_link_init() argument
2690 link->prog = prog; in bpf_link_init()
2712 primer->link->prog = NULL; in bpf_link_cleanup()
2727 if (link->prog) { in bpf_link_free()
2730 bpf_prog_put(link->prog); in bpf_link_free()
2783 const struct bpf_prog *prog = link->prog; in bpf_link_show_fdinfo() local
2784 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; in bpf_link_show_fdinfo()
2786 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); in bpf_link_show_fdinfo()
2795 prog->aux->id); in bpf_link_show_fdinfo()
2958 static int bpf_tracing_prog_attach(struct bpf_prog *prog, in bpf_tracing_prog_attach() argument
2970 switch (prog->type) { in bpf_tracing_prog_attach()
2972 if (prog->expected_attach_type != BPF_TRACE_FENTRY && in bpf_tracing_prog_attach()
2973 prog->expected_attach_type != BPF_TRACE_FEXIT && in bpf_tracing_prog_attach()
2974 prog->expected_attach_type != BPF_MODIFY_RETURN) { in bpf_tracing_prog_attach()
2980 if (prog->expected_attach_type != 0) { in bpf_tracing_prog_attach()
2986 if (prog->expected_attach_type != BPF_LSM_MAC) { in bpf_tracing_prog_attach()
3003 if (prog->type != BPF_PROG_TYPE_EXT) { in bpf_tracing_prog_attach()
3024 &bpf_tracing_link_lops, prog); in bpf_tracing_prog_attach()
3025 link->attach_type = prog->expected_attach_type; in bpf_tracing_prog_attach()
3028 mutex_lock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3052 if (!prog->aux->dst_trampoline && !tgt_prog) { in bpf_tracing_prog_attach()
3059 if (prog->type != BPF_PROG_TYPE_TRACING && in bpf_tracing_prog_attach()
3060 prog->type != BPF_PROG_TYPE_LSM) { in bpf_tracing_prog_attach()
3065 if (!prog->aux->attach_btf) { in bpf_tracing_prog_attach()
3069 btf_id = prog->aux->attach_btf_id; in bpf_tracing_prog_attach()
3070 key = bpf_trampoline_compute_key(NULL, prog->aux->attach_btf, btf_id); in bpf_tracing_prog_attach()
3073 if (!prog->aux->dst_trampoline || in bpf_tracing_prog_attach()
3074 (key && key != prog->aux->dst_trampoline->key)) { in bpf_tracing_prog_attach()
3081 err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id, in bpf_tracing_prog_attach()
3099 tr = prog->aux->dst_trampoline; in bpf_tracing_prog_attach()
3100 tgt_prog = prog->aux->dst_prog; in bpf_tracing_prog_attach()
3121 if (prog->aux->dst_prog && in bpf_tracing_prog_attach()
3122 (tgt_prog_fd || tr != prog->aux->dst_trampoline)) in bpf_tracing_prog_attach()
3124 bpf_prog_put(prog->aux->dst_prog); in bpf_tracing_prog_attach()
3125 if (prog->aux->dst_trampoline && tr != prog->aux->dst_trampoline) in bpf_tracing_prog_attach()
3127 bpf_trampoline_put(prog->aux->dst_trampoline); in bpf_tracing_prog_attach()
3129 prog->aux->dst_prog = NULL; in bpf_tracing_prog_attach()
3130 prog->aux->dst_trampoline = NULL; in bpf_tracing_prog_attach()
3131 mutex_unlock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3135 if (tr && tr != prog->aux->dst_trampoline) in bpf_tracing_prog_attach()
3137 mutex_unlock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3155 bpf_probe_unregister(raw_tp->btp, raw_tp->link.prog); in bpf_raw_tp_link_release()
3246 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_perf_link_attach() argument
3266 bpf_link_init(&link->link, BPF_LINK_TYPE_PERF_EVENT, &bpf_perf_link_lops, prog); in bpf_perf_link_attach()
3276 err = perf_event_set_bpf_prog(event, prog, attr->link_create.perf_event.bpf_cookie); in bpf_perf_link_attach()
3282 bpf_prog_inc(prog); in bpf_perf_link_attach()
3291 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_perf_link_attach() argument
3297 static int bpf_raw_tp_link_attach(struct bpf_prog *prog, in bpf_raw_tp_link_attach() argument
3307 switch (prog->type) { in bpf_raw_tp_link_attach()
3316 if (prog->type == BPF_PROG_TYPE_TRACING && in bpf_raw_tp_link_attach()
3317 prog->expected_attach_type == BPF_TRACE_RAW_TP) { in bpf_raw_tp_link_attach()
3318 tp_name = prog->aux->attach_func_name; in bpf_raw_tp_link_attach()
3321 return bpf_tracing_prog_attach(prog, 0, 0, 0); in bpf_raw_tp_link_attach()
3343 &bpf_raw_tp_link_lops, prog); in bpf_raw_tp_link_attach()
3352 err = bpf_probe_register(link->btp, prog); in bpf_raw_tp_link_attach()
3369 struct bpf_prog *prog; in bpf_raw_tracepoint_open() local
3375 prog = bpf_prog_get(attr->raw_tracepoint.prog_fd); in bpf_raw_tracepoint_open()
3376 if (IS_ERR(prog)) in bpf_raw_tracepoint_open()
3377 return PTR_ERR(prog); in bpf_raw_tracepoint_open()
3379 fd = bpf_raw_tp_link_attach(prog, u64_to_user_ptr(attr->raw_tracepoint.name)); in bpf_raw_tracepoint_open()
3381 bpf_prog_put(prog); in bpf_raw_tracepoint_open()
3385 static int bpf_prog_attach_check_attach_type(const struct bpf_prog *prog, in bpf_prog_attach_check_attach_type() argument
3388 switch (prog->type) { in bpf_prog_attach_check_attach_type()
3393 return attach_type == prog->expected_attach_type ? 0 : -EINVAL; in bpf_prog_attach_check_attach_type()
3400 return prog->enforce_expected_attach_type && in bpf_prog_attach_check_attach_type()
3401 prog->expected_attach_type != attach_type ? in bpf_prog_attach_check_attach_type()
3404 if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI && in bpf_prog_attach_check_attach_type()
3484 struct bpf_prog *prog; in bpf_prog_attach() local
3497 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); in bpf_prog_attach()
3498 if (IS_ERR(prog)) in bpf_prog_attach()
3499 return PTR_ERR(prog); in bpf_prog_attach()
3501 if (bpf_prog_attach_check_attach_type(prog, attr->attach_type)) { in bpf_prog_attach()
3502 bpf_prog_put(prog); in bpf_prog_attach()
3509 ret = sock_map_get_from_fd(attr, prog); in bpf_prog_attach()
3512 ret = lirc_prog_attach(attr, prog); in bpf_prog_attach()
3515 ret = netns_bpf_prog_attach(attr, prog); in bpf_prog_attach()
3526 prog->expected_attach_type != BPF_LSM_CGROUP) in bpf_prog_attach()
3529 ret = cgroup_bpf_prog_attach(attr, ptype, prog); in bpf_prog_attach()
3536 bpf_prog_put(prog); in bpf_prog_attach()
3631 struct bpf_prog *prog; in bpf_prog_test_run() local
3645 prog = bpf_prog_get(attr->test.prog_fd); in bpf_prog_test_run()
3646 if (IS_ERR(prog)) in bpf_prog_test_run()
3647 return PTR_ERR(prog); in bpf_prog_test_run()
3649 if (prog->aux->ops->test_run) in bpf_prog_test_run()
3650 ret = prog->aux->ops->test_run(prog, attr, uattr); in bpf_prog_test_run()
3652 bpf_prog_put(prog); in bpf_prog_test_run()
3705 struct bpf_prog *prog; in bpf_prog_get_curr_or_next() local
3709 prog = idr_get_next(&prog_idr, id); in bpf_prog_get_curr_or_next()
3710 if (prog) { in bpf_prog_get_curr_or_next()
3711 prog = bpf_prog_inc_not_zero(prog); in bpf_prog_get_curr_or_next()
3712 if (IS_ERR(prog)) { in bpf_prog_get_curr_or_next()
3719 return prog; in bpf_prog_get_curr_or_next()
3726 struct bpf_prog *prog; in bpf_prog_by_id() local
3732 prog = idr_find(&prog_idr, id); in bpf_prog_by_id()
3733 if (prog) in bpf_prog_by_id()
3734 prog = bpf_prog_inc_not_zero(prog); in bpf_prog_by_id()
3736 prog = ERR_PTR(-ENOENT); in bpf_prog_by_id()
3738 return prog; in bpf_prog_by_id()
3743 struct bpf_prog *prog; in bpf_prog_get_fd_by_id() local
3753 prog = bpf_prog_by_id(id); in bpf_prog_get_fd_by_id()
3754 if (IS_ERR(prog)) in bpf_prog_get_fd_by_id()
3755 return PTR_ERR(prog); in bpf_prog_get_fd_by_id()
3757 fd = bpf_prog_new_fd(prog); in bpf_prog_get_fd_by_id()
3759 bpf_prog_put(prog); in bpf_prog_get_fd_by_id()
3802 static const struct bpf_map *bpf_map_from_imm(const struct bpf_prog *prog, in bpf_map_from_imm() argument
3809 mutex_lock(&prog->aux->used_maps_mutex); in bpf_map_from_imm()
3810 for (i = 0, *off = 0; i < prog->aux->used_map_cnt; i++) { in bpf_map_from_imm()
3811 map = prog->aux->used_maps[i]; in bpf_map_from_imm()
3826 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_map_from_imm()
3830 static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog, in bpf_insn_prepare_dump() argument
3840 insns = kmemdup(prog->insnsi, bpf_prog_insn_size(prog), in bpf_insn_prepare_dump()
3845 for (i = 0; i < prog->len; i++) { in bpf_insn_prepare_dump()
3870 map = bpf_map_from_imm(prog, imm, &off, &type); in bpf_insn_prepare_dump()
3914 struct bpf_prog *prog, in bpf_prog_get_info_by_fd() argument
3919 struct btf *attach_btf = bpf_prog_get_target_btf(prog); in bpf_prog_get_info_by_fd()
3936 info.type = prog->type; in bpf_prog_get_info_by_fd()
3937 info.id = prog->aux->id; in bpf_prog_get_info_by_fd()
3938 info.load_time = prog->aux->load_time; in bpf_prog_get_info_by_fd()
3940 prog->aux->user->uid); in bpf_prog_get_info_by_fd()
3941 info.gpl_compatible = prog->gpl_compatible; in bpf_prog_get_info_by_fd()
3943 memcpy(info.tag, prog->tag, sizeof(prog->tag)); in bpf_prog_get_info_by_fd()
3944 memcpy(info.name, prog->aux->name, sizeof(prog->aux->name)); in bpf_prog_get_info_by_fd()
3946 mutex_lock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
3948 info.nr_map_ids = prog->aux->used_map_cnt; in bpf_prog_get_info_by_fd()
3955 if (put_user(prog->aux->used_maps[i]->id, in bpf_prog_get_info_by_fd()
3957 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
3961 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
3967 bpf_prog_get_stats(prog, &stats); in bpf_prog_get_info_by_fd()
3972 info.verified_insns = prog->aux->verified_insns; in bpf_prog_get_info_by_fd()
3986 info.xlated_prog_len = bpf_prog_insn_size(prog); in bpf_prog_get_info_by_fd()
3991 if (prog->blinded && !bpf_dump_raw_ok(file->f_cred)) { in bpf_prog_get_info_by_fd()
3995 insns_sanitized = bpf_insn_prepare_dump(prog, file->f_cred); in bpf_prog_get_info_by_fd()
4006 if (bpf_prog_is_dev_bound(prog->aux)) { in bpf_prog_get_info_by_fd()
4007 err = bpf_prog_offload_info_fill(&info, prog); in bpf_prog_get_info_by_fd()
4018 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4022 for (i = 0; i < prog->aux->func_cnt; i++) in bpf_prog_get_info_by_fd()
4023 info.jited_prog_len += prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4025 info.jited_prog_len = prog->jited_len; in bpf_prog_get_info_by_fd()
4036 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4041 for (i = 0; i < prog->aux->func_cnt; i++) { in bpf_prog_get_info_by_fd()
4042 len = prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4044 img = (u8 *) prog->aux->func[i]->bpf_func; in bpf_prog_get_info_by_fd()
4053 if (copy_to_user(uinsns, prog->bpf_func, ulen)) in bpf_prog_get_info_by_fd()
4062 info.nr_jited_ksyms = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4074 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4077 prog->aux->func[i]->bpf_func; in bpf_prog_get_info_by_fd()
4083 ksym_addr = (unsigned long) prog->bpf_func; in bpf_prog_get_info_by_fd()
4093 info.nr_jited_func_lens = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4102 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4105 prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4110 func_len = prog->jited_len; in bpf_prog_get_info_by_fd()
4119 if (prog->aux->btf) in bpf_prog_get_info_by_fd()
4120 info.btf_id = btf_obj_id(prog->aux->btf); in bpf_prog_get_info_by_fd()
4121 info.attach_btf_id = prog->aux->attach_btf_id; in bpf_prog_get_info_by_fd()
4126 info.nr_func_info = prog->aux->func_info_cnt; in bpf_prog_get_info_by_fd()
4132 if (copy_to_user(user_finfo, prog->aux->func_info, in bpf_prog_get_info_by_fd()
4138 info.nr_line_info = prog->aux->nr_linfo; in bpf_prog_get_info_by_fd()
4144 if (copy_to_user(user_linfo, prog->aux->linfo, in bpf_prog_get_info_by_fd()
4150 if (prog->aux->jited_linfo) in bpf_prog_get_info_by_fd()
4151 info.nr_jited_line_info = prog->aux->nr_linfo; in bpf_prog_get_info_by_fd()
4163 line_addr = (unsigned long)prog->aux->jited_linfo[i]; in bpf_prog_get_info_by_fd()
4173 info.nr_prog_tags = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4180 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4183 prog->aux->func[i]->tag, in bpf_prog_get_info_by_fd()
4189 prog->tag, BPF_TAG_SIZE)) in bpf_prog_get_info_by_fd()
4284 info.prog_id = link->prog->aux->id; in bpf_link_get_info_by_fd()
4449 raw_tp->link.prog->aux->id, in bpf_task_fd_query()
4541 struct bpf_prog *prog; in link_create() local
4547 prog = bpf_prog_get(attr->link_create.prog_fd); in link_create()
4548 if (IS_ERR(prog)) in link_create()
4549 return PTR_ERR(prog); in link_create()
4551 ret = bpf_prog_attach_check_attach_type(prog, in link_create()
4556 switch (prog->type) { in link_create()
4575 if (ptype == BPF_PROG_TYPE_UNSPEC || ptype != prog->type) { in link_create()
4582 switch (prog->type) { in link_create()
4590 ret = cgroup_bpf_link_attach(attr, prog); in link_create()
4593 ret = bpf_tracing_prog_attach(prog, in link_create()
4600 if (attr->link_create.attach_type != prog->expected_attach_type) { in link_create()
4604 if (prog->expected_attach_type == BPF_TRACE_RAW_TP) in link_create()
4605 ret = bpf_raw_tp_link_attach(prog, NULL); in link_create()
4606 else if (prog->expected_attach_type == BPF_TRACE_ITER) in link_create()
4607 ret = bpf_iter_link_attach(attr, uattr, prog); in link_create()
4608 else if (prog->expected_attach_type == BPF_LSM_CGROUP) in link_create()
4609 ret = cgroup_bpf_link_attach(attr, prog); in link_create()
4611 ret = bpf_tracing_prog_attach(prog, in link_create()
4618 ret = netns_bpf_link_create(attr, prog); in link_create()
4622 ret = bpf_xdp_link_attach(attr, prog); in link_create()
4627 ret = bpf_perf_link_attach(attr, prog); in link_create()
4631 ret = bpf_perf_link_attach(attr, prog); in link_create()
4633 ret = bpf_kprobe_multi_link_attach(attr, prog); in link_create()
4641 bpf_prog_put(prog); in link_create()
4873 struct bpf_prog *prog; in bpf_prog_bind_map() local
4884 prog = bpf_prog_get(attr->prog_bind_map.prog_fd); in bpf_prog_bind_map()
4885 if (IS_ERR(prog)) in bpf_prog_bind_map()
4886 return PTR_ERR(prog); in bpf_prog_bind_map()
4894 mutex_lock(&prog->aux->used_maps_mutex); in bpf_prog_bind_map()
4896 used_maps_old = prog->aux->used_maps; in bpf_prog_bind_map()
4898 for (i = 0; i < prog->aux->used_map_cnt; i++) in bpf_prog_bind_map()
4904 used_maps_new = kmalloc_array(prog->aux->used_map_cnt + 1, in bpf_prog_bind_map()
4913 sizeof(used_maps_old[0]) * prog->aux->used_map_cnt); in bpf_prog_bind_map()
4914 used_maps_new[prog->aux->used_map_cnt] = map; in bpf_prog_bind_map()
4916 prog->aux->used_map_cnt++; in bpf_prog_bind_map()
4917 prog->aux->used_maps = used_maps_new; in bpf_prog_bind_map()
4922 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_bind_map()
4927 bpf_prog_put(prog); in bpf_prog_bind_map()
5096 const struct bpf_prog *prog, in syscall_prog_is_valid_access() argument
5135 struct bpf_prog * __maybe_unused prog; in kern_sys_bpf() local
5146 prog = bpf_prog_get_type(attr->test.prog_fd, BPF_PROG_TYPE_SYSCALL); in kern_sys_bpf()
5147 if (IS_ERR(prog)) in kern_sys_bpf()
5148 return PTR_ERR(prog); in kern_sys_bpf()
5150 if (attr->test.ctx_size_in < prog->aux->max_ctx_offset || in kern_sys_bpf()
5152 bpf_prog_put(prog); in kern_sys_bpf()
5157 if (!__bpf_prog_enter_sleepable_recur(prog, &run_ctx)) { in kern_sys_bpf()
5159 __bpf_prog_exit_sleepable_recur(prog, 0, &run_ctx); in kern_sys_bpf()
5160 bpf_prog_put(prog); in kern_sys_bpf()
5163 attr->test.retval = bpf_prog_run(prog, (void *) (long) attr->test.ctx_in); in kern_sys_bpf()
5164 __bpf_prog_exit_sleepable_recur(prog, 0 /* bpf_prog_run does runtime stats */, in kern_sys_bpf()
5166 bpf_prog_put(prog); in kern_sys_bpf()
5185 tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) in tracing_prog_func_proto() argument
5233 syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) in syscall_prog_func_proto() argument
5245 return tracing_prog_func_proto(func_id, prog); in syscall_prog_func_proto()