Lines Matching refs:prog
2015 static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog) in find_prog_type() argument
2026 if (!bpf_prog_is_offloaded(prog->aux)) in find_prog_type()
2027 prog->aux->ops = ops; in find_prog_type()
2029 prog->aux->ops = &bpf_offload_prog_ops; in find_prog_type()
2030 prog->type = type; in find_prog_type()
2045 static void bpf_audit_prog(const struct bpf_prog *prog, unsigned int op) in bpf_audit_prog() argument
2060 prog->aux->id, bpf_audit_str[op]); in bpf_audit_prog()
2064 static int bpf_prog_alloc_id(struct bpf_prog *prog) in bpf_prog_alloc_id() argument
2070 id = idr_alloc_cyclic(&prog_idr, prog, 1, INT_MAX, GFP_ATOMIC); in bpf_prog_alloc_id()
2072 prog->aux->id = id; in bpf_prog_alloc_id()
2083 void bpf_prog_free_id(struct bpf_prog *prog) in bpf_prog_free_id() argument
2092 if (!prog->aux->id) in bpf_prog_free_id()
2096 idr_remove(&prog_idr, prog->aux->id); in bpf_prog_free_id()
2097 prog->aux->id = 0; in bpf_prog_free_id()
2109 bpf_prog_free(aux->prog); in __bpf_prog_put_rcu()
2112 static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred) in __bpf_prog_put_noref() argument
2114 bpf_prog_kallsyms_del_all(prog); in __bpf_prog_put_noref()
2115 btf_put(prog->aux->btf); in __bpf_prog_put_noref()
2116 module_put(prog->aux->mod); in __bpf_prog_put_noref()
2117 kvfree(prog->aux->jited_linfo); in __bpf_prog_put_noref()
2118 kvfree(prog->aux->linfo); in __bpf_prog_put_noref()
2119 kfree(prog->aux->kfunc_tab); in __bpf_prog_put_noref()
2120 if (prog->aux->attach_btf) in __bpf_prog_put_noref()
2121 btf_put(prog->aux->attach_btf); in __bpf_prog_put_noref()
2124 if (prog->aux->sleepable) in __bpf_prog_put_noref()
2125 call_rcu_tasks_trace(&prog->aux->rcu, __bpf_prog_put_rcu); in __bpf_prog_put_noref()
2127 call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu); in __bpf_prog_put_noref()
2129 __bpf_prog_put_rcu(&prog->aux->rcu); in __bpf_prog_put_noref()
2136 struct bpf_prog *prog; in bpf_prog_put_deferred() local
2139 prog = aux->prog; in bpf_prog_put_deferred()
2140 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_UNLOAD, 0); in bpf_prog_put_deferred()
2141 bpf_audit_prog(prog, BPF_AUDIT_UNLOAD); in bpf_prog_put_deferred()
2142 bpf_prog_free_id(prog); in bpf_prog_put_deferred()
2143 __bpf_prog_put_noref(prog, true); in bpf_prog_put_deferred()
2146 static void __bpf_prog_put(struct bpf_prog *prog) in __bpf_prog_put() argument
2148 struct bpf_prog_aux *aux = prog->aux; in __bpf_prog_put()
2160 void bpf_prog_put(struct bpf_prog *prog) in bpf_prog_put() argument
2162 __bpf_prog_put(prog); in bpf_prog_put()
2168 struct bpf_prog *prog = filp->private_data; in bpf_prog_release() local
2170 bpf_prog_put(prog); in bpf_prog_release()
2180 void notrace bpf_prog_inc_misses_counter(struct bpf_prog *prog) in bpf_prog_inc_misses_counter() argument
2185 stats = this_cpu_ptr(prog->stats); in bpf_prog_inc_misses_counter()
2191 static void bpf_prog_get_stats(const struct bpf_prog *prog, in bpf_prog_get_stats() argument
2202 st = per_cpu_ptr(prog->stats, cpu); in bpf_prog_get_stats()
2221 const struct bpf_prog *prog = filp->private_data; in bpf_prog_show_fdinfo() local
2222 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; in bpf_prog_show_fdinfo()
2225 bpf_prog_get_stats(prog, &stats); in bpf_prog_show_fdinfo()
2226 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); in bpf_prog_show_fdinfo()
2237 prog->type, in bpf_prog_show_fdinfo()
2238 prog->jited, in bpf_prog_show_fdinfo()
2240 prog->pages * 1ULL << PAGE_SHIFT, in bpf_prog_show_fdinfo()
2241 prog->aux->id, in bpf_prog_show_fdinfo()
2245 prog->aux->verified_insns); in bpf_prog_show_fdinfo()
2258 int bpf_prog_new_fd(struct bpf_prog *prog) in bpf_prog_new_fd() argument
2262 ret = security_bpf_prog(prog); in bpf_prog_new_fd()
2266 return anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog, in bpf_prog_new_fd()
2282 void bpf_prog_add(struct bpf_prog *prog, int i) in bpf_prog_add() argument
2284 atomic64_add(i, &prog->aux->refcnt); in bpf_prog_add()
2288 void bpf_prog_sub(struct bpf_prog *prog, int i) in bpf_prog_sub() argument
2295 WARN_ON(atomic64_sub_return(i, &prog->aux->refcnt) == 0); in bpf_prog_sub()
2299 void bpf_prog_inc(struct bpf_prog *prog) in bpf_prog_inc() argument
2301 atomic64_inc(&prog->aux->refcnt); in bpf_prog_inc()
2306 struct bpf_prog *bpf_prog_inc_not_zero(struct bpf_prog *prog) in bpf_prog_inc_not_zero() argument
2310 refold = atomic64_fetch_add_unless(&prog->aux->refcnt, 1, 0); in bpf_prog_inc_not_zero()
2315 return prog; in bpf_prog_inc_not_zero()
2319 bool bpf_prog_get_ok(struct bpf_prog *prog, in bpf_prog_get_ok() argument
2326 if (prog->type != *attach_type) in bpf_prog_get_ok()
2328 if (bpf_prog_is_offloaded(prog->aux) && !attach_drv) in bpf_prog_get_ok()
2338 struct bpf_prog *prog; in __bpf_prog_get() local
2340 prog = ____bpf_prog_get(f); in __bpf_prog_get()
2341 if (IS_ERR(prog)) in __bpf_prog_get()
2342 return prog; in __bpf_prog_get()
2343 if (!bpf_prog_get_ok(prog, attach_type, attach_drv)) { in __bpf_prog_get()
2344 prog = ERR_PTR(-EINVAL); in __bpf_prog_get()
2348 bpf_prog_inc(prog); in __bpf_prog_get()
2351 return prog; in __bpf_prog_get()
2554 struct bpf_prog *prog, *dst_prog = NULL; in bpf_prog_load() local
2639 prog = bpf_prog_alloc(bpf_prog_size(attr->insn_cnt), GFP_USER); in bpf_prog_load()
2640 if (!prog) { in bpf_prog_load()
2648 prog->expected_attach_type = attr->expected_attach_type; in bpf_prog_load()
2649 prog->aux->attach_btf = attach_btf; in bpf_prog_load()
2650 prog->aux->attach_btf_id = attr->attach_btf_id; in bpf_prog_load()
2651 prog->aux->dst_prog = dst_prog; in bpf_prog_load()
2652 prog->aux->dev_bound = !!attr->prog_ifindex; in bpf_prog_load()
2653 prog->aux->sleepable = attr->prog_flags & BPF_F_SLEEPABLE; in bpf_prog_load()
2654 prog->aux->xdp_has_frags = attr->prog_flags & BPF_F_XDP_HAS_FRAGS; in bpf_prog_load()
2656 err = security_bpf_prog_alloc(prog->aux); in bpf_prog_load()
2660 prog->aux->user = get_current_user(); in bpf_prog_load()
2661 prog->len = attr->insn_cnt; in bpf_prog_load()
2664 if (copy_from_bpfptr(prog->insns, in bpf_prog_load()
2666 bpf_prog_insn_size(prog)) != 0) in bpf_prog_load()
2676 prog->gpl_compatible = license_is_gpl_compatible(license) ? 1 : 0; in bpf_prog_load()
2678 prog->orig_prog = NULL; in bpf_prog_load()
2679 prog->jited = 0; in bpf_prog_load()
2681 atomic64_set(&prog->aux->refcnt, 1); in bpf_prog_load()
2683 if (bpf_prog_is_dev_bound(prog->aux)) { in bpf_prog_load()
2684 err = bpf_prog_dev_bound_init(prog, attr); in bpf_prog_load()
2691 err = bpf_prog_dev_bound_inherit(prog, dst_prog); in bpf_prog_load()
2697 err = find_prog_type(type, prog); in bpf_prog_load()
2701 prog->aux->load_time = ktime_get_boottime_ns(); in bpf_prog_load()
2702 err = bpf_obj_name_cpy(prog->aux->name, attr->prog_name, in bpf_prog_load()
2708 err = bpf_check(&prog, attr, uattr, uattr_size); in bpf_prog_load()
2712 prog = bpf_prog_select_runtime(prog, &err); in bpf_prog_load()
2716 err = bpf_prog_alloc_id(prog); in bpf_prog_load()
2734 bpf_prog_kallsyms_add(prog); in bpf_prog_load()
2735 perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_LOAD, 0); in bpf_prog_load()
2736 bpf_audit_prog(prog, BPF_AUDIT_LOAD); in bpf_prog_load()
2738 err = bpf_prog_new_fd(prog); in bpf_prog_load()
2740 bpf_prog_put(prog); in bpf_prog_load()
2748 __bpf_prog_put_noref(prog, prog->aux->func_cnt); in bpf_prog_load()
2751 free_uid(prog->aux->user); in bpf_prog_load()
2752 security_bpf_prog_free(prog->aux); in bpf_prog_load()
2754 if (prog->aux->attach_btf) in bpf_prog_load()
2755 btf_put(prog->aux->attach_btf); in bpf_prog_load()
2756 bpf_prog_free(prog); in bpf_prog_load()
2796 const struct bpf_link_ops *ops, struct bpf_prog *prog) in bpf_link_init() argument
2802 link->prog = prog; in bpf_link_init()
2826 primer->link->prog = NULL; in bpf_link_cleanup()
2841 if (link->prog) { in bpf_link_free()
2844 bpf_prog_put(link->prog); in bpf_link_free()
2900 const struct bpf_prog *prog = link->prog; in bpf_link_show_fdinfo() local
2901 char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; in bpf_link_show_fdinfo()
2908 if (prog) { in bpf_link_show_fdinfo()
2909 bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); in bpf_link_show_fdinfo()
2914 prog->aux->id); in bpf_link_show_fdinfo()
3085 static int bpf_tracing_prog_attach(struct bpf_prog *prog, in bpf_tracing_prog_attach() argument
3097 switch (prog->type) { in bpf_tracing_prog_attach()
3099 if (prog->expected_attach_type != BPF_TRACE_FENTRY && in bpf_tracing_prog_attach()
3100 prog->expected_attach_type != BPF_TRACE_FEXIT && in bpf_tracing_prog_attach()
3101 prog->expected_attach_type != BPF_MODIFY_RETURN) { in bpf_tracing_prog_attach()
3107 if (prog->expected_attach_type != 0) { in bpf_tracing_prog_attach()
3113 if (prog->expected_attach_type != BPF_LSM_MAC) { in bpf_tracing_prog_attach()
3130 if (prog->type != BPF_PROG_TYPE_EXT) { in bpf_tracing_prog_attach()
3151 &bpf_tracing_link_lops, prog); in bpf_tracing_prog_attach()
3152 link->attach_type = prog->expected_attach_type; in bpf_tracing_prog_attach()
3155 mutex_lock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3175 if (!prog->aux->dst_trampoline && !tgt_prog) { in bpf_tracing_prog_attach()
3182 if (prog->type != BPF_PROG_TYPE_TRACING && in bpf_tracing_prog_attach()
3183 prog->type != BPF_PROG_TYPE_LSM) { in bpf_tracing_prog_attach()
3187 btf_id = prog->aux->attach_btf_id; in bpf_tracing_prog_attach()
3188 key = bpf_trampoline_compute_key(NULL, prog->aux->attach_btf, btf_id); in bpf_tracing_prog_attach()
3191 if (!prog->aux->dst_trampoline || in bpf_tracing_prog_attach()
3192 (key && key != prog->aux->dst_trampoline->key)) { in bpf_tracing_prog_attach()
3199 err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id, in bpf_tracing_prog_attach()
3205 module_put(prog->aux->mod); in bpf_tracing_prog_attach()
3206 prog->aux->mod = tgt_info.tgt_mod; in bpf_tracing_prog_attach()
3222 tr = prog->aux->dst_trampoline; in bpf_tracing_prog_attach()
3223 tgt_prog = prog->aux->dst_prog; in bpf_tracing_prog_attach()
3244 if (prog->aux->dst_prog && in bpf_tracing_prog_attach()
3245 (tgt_prog_fd || tr != prog->aux->dst_trampoline)) in bpf_tracing_prog_attach()
3247 bpf_prog_put(prog->aux->dst_prog); in bpf_tracing_prog_attach()
3248 if (prog->aux->dst_trampoline && tr != prog->aux->dst_trampoline) in bpf_tracing_prog_attach()
3250 bpf_trampoline_put(prog->aux->dst_trampoline); in bpf_tracing_prog_attach()
3252 prog->aux->dst_prog = NULL; in bpf_tracing_prog_attach()
3253 prog->aux->dst_trampoline = NULL; in bpf_tracing_prog_attach()
3254 mutex_unlock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3258 if (tr && tr != prog->aux->dst_trampoline) in bpf_tracing_prog_attach()
3260 mutex_unlock(&prog->aux->dst_mutex); in bpf_tracing_prog_attach()
3278 bpf_probe_unregister(raw_tp->btp, raw_tp->link.prog); in bpf_raw_tp_link_release()
3502 switch (event->prog->type) { in bpf_perf_link_fill_link_info()
3520 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_perf_link_attach() argument
3540 bpf_link_init(&link->link, BPF_LINK_TYPE_PERF_EVENT, &bpf_perf_link_lops, prog); in bpf_perf_link_attach()
3550 err = perf_event_set_bpf_prog(event, prog, attr->link_create.perf_event.bpf_cookie); in bpf_perf_link_attach()
3556 bpf_prog_inc(prog); in bpf_perf_link_attach()
3565 static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_perf_link_attach() argument
3571 static int bpf_raw_tp_link_attach(struct bpf_prog *prog, in bpf_raw_tp_link_attach() argument
3581 switch (prog->type) { in bpf_raw_tp_link_attach()
3590 if (prog->type == BPF_PROG_TYPE_TRACING && in bpf_raw_tp_link_attach()
3591 prog->expected_attach_type == BPF_TRACE_RAW_TP) { in bpf_raw_tp_link_attach()
3592 tp_name = prog->aux->attach_func_name; in bpf_raw_tp_link_attach()
3595 return bpf_tracing_prog_attach(prog, 0, 0, 0); in bpf_raw_tp_link_attach()
3617 &bpf_raw_tp_link_lops, prog); in bpf_raw_tp_link_attach()
3626 err = bpf_probe_register(link->btp, prog); in bpf_raw_tp_link_attach()
3643 struct bpf_prog *prog; in bpf_raw_tracepoint_open() local
3649 prog = bpf_prog_get(attr->raw_tracepoint.prog_fd); in bpf_raw_tracepoint_open()
3650 if (IS_ERR(prog)) in bpf_raw_tracepoint_open()
3651 return PTR_ERR(prog); in bpf_raw_tracepoint_open()
3653 fd = bpf_raw_tp_link_attach(prog, u64_to_user_ptr(attr->raw_tracepoint.name)); in bpf_raw_tracepoint_open()
3655 bpf_prog_put(prog); in bpf_raw_tracepoint_open()
3725 static int bpf_prog_attach_check_attach_type(const struct bpf_prog *prog, in bpf_prog_attach_check_attach_type() argument
3730 switch (prog->type) { in bpf_prog_attach_check_attach_type()
3735 return attach_type == prog->expected_attach_type ? 0 : -EINVAL; in bpf_prog_attach_check_attach_type()
3742 return prog->enforce_expected_attach_type && in bpf_prog_attach_check_attach_type()
3743 prog->expected_attach_type != attach_type ? in bpf_prog_attach_check_attach_type()
3757 if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI && in bpf_prog_attach_check_attach_type()
3760 if (prog->expected_attach_type == BPF_TRACE_UPROBE_MULTI && in bpf_prog_attach_check_attach_type()
3775 if (ptype == BPF_PROG_TYPE_UNSPEC || ptype != prog->type) in bpf_prog_attach_check_attach_type()
3798 struct bpf_prog *prog; in bpf_prog_attach() local
3818 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); in bpf_prog_attach()
3819 if (IS_ERR(prog)) in bpf_prog_attach()
3820 return PTR_ERR(prog); in bpf_prog_attach()
3822 if (bpf_prog_attach_check_attach_type(prog, attr->attach_type)) { in bpf_prog_attach()
3823 bpf_prog_put(prog); in bpf_prog_attach()
3830 ret = sock_map_get_from_fd(attr, prog); in bpf_prog_attach()
3833 ret = lirc_prog_attach(attr, prog); in bpf_prog_attach()
3836 ret = netns_bpf_prog_attach(attr, prog); in bpf_prog_attach()
3847 prog->expected_attach_type != BPF_LSM_CGROUP) in bpf_prog_attach()
3850 ret = cgroup_bpf_prog_attach(attr, ptype, prog); in bpf_prog_attach()
3853 ret = tcx_prog_attach(attr, prog); in bpf_prog_attach()
3860 bpf_prog_put(prog); in bpf_prog_attach()
3868 struct bpf_prog *prog = NULL; in bpf_prog_detach() local
3882 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); in bpf_prog_detach()
3883 if (IS_ERR(prog)) in bpf_prog_detach()
3884 return PTR_ERR(prog); in bpf_prog_detach()
3914 ret = tcx_prog_detach(attr, prog); in bpf_prog_detach()
3920 if (prog) in bpf_prog_detach()
3921 bpf_prog_put(prog); in bpf_prog_detach()
3986 struct bpf_prog *prog; in bpf_prog_test_run() local
4000 prog = bpf_prog_get(attr->test.prog_fd); in bpf_prog_test_run()
4001 if (IS_ERR(prog)) in bpf_prog_test_run()
4002 return PTR_ERR(prog); in bpf_prog_test_run()
4004 if (prog->aux->ops->test_run) in bpf_prog_test_run()
4005 ret = prog->aux->ops->test_run(prog, attr, uattr); in bpf_prog_test_run()
4007 bpf_prog_put(prog); in bpf_prog_test_run()
4060 struct bpf_prog *prog; in bpf_prog_get_curr_or_next() local
4064 prog = idr_get_next(&prog_idr, id); in bpf_prog_get_curr_or_next()
4065 if (prog) { in bpf_prog_get_curr_or_next()
4066 prog = bpf_prog_inc_not_zero(prog); in bpf_prog_get_curr_or_next()
4067 if (IS_ERR(prog)) { in bpf_prog_get_curr_or_next()
4074 return prog; in bpf_prog_get_curr_or_next()
4081 struct bpf_prog *prog; in bpf_prog_by_id() local
4087 prog = idr_find(&prog_idr, id); in bpf_prog_by_id()
4088 if (prog) in bpf_prog_by_id()
4089 prog = bpf_prog_inc_not_zero(prog); in bpf_prog_by_id()
4091 prog = ERR_PTR(-ENOENT); in bpf_prog_by_id()
4093 return prog; in bpf_prog_by_id()
4098 struct bpf_prog *prog; in bpf_prog_get_fd_by_id() local
4108 prog = bpf_prog_by_id(id); in bpf_prog_get_fd_by_id()
4109 if (IS_ERR(prog)) in bpf_prog_get_fd_by_id()
4110 return PTR_ERR(prog); in bpf_prog_get_fd_by_id()
4112 fd = bpf_prog_new_fd(prog); in bpf_prog_get_fd_by_id()
4114 bpf_prog_put(prog); in bpf_prog_get_fd_by_id()
4157 static const struct bpf_map *bpf_map_from_imm(const struct bpf_prog *prog, in bpf_map_from_imm() argument
4164 mutex_lock(&prog->aux->used_maps_mutex); in bpf_map_from_imm()
4165 for (i = 0, *off = 0; i < prog->aux->used_map_cnt; i++) { in bpf_map_from_imm()
4166 map = prog->aux->used_maps[i]; in bpf_map_from_imm()
4181 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_map_from_imm()
4185 static struct bpf_insn *bpf_insn_prepare_dump(const struct bpf_prog *prog, in bpf_insn_prepare_dump() argument
4195 insns = kmemdup(prog->insnsi, bpf_prog_insn_size(prog), in bpf_insn_prepare_dump()
4200 for (i = 0; i < prog->len; i++) { in bpf_insn_prepare_dump()
4225 map = bpf_map_from_imm(prog, imm, &off, &type); in bpf_insn_prepare_dump()
4269 struct bpf_prog *prog, in bpf_prog_get_info_by_fd() argument
4274 struct btf *attach_btf = bpf_prog_get_target_btf(prog); in bpf_prog_get_info_by_fd()
4291 info.type = prog->type; in bpf_prog_get_info_by_fd()
4292 info.id = prog->aux->id; in bpf_prog_get_info_by_fd()
4293 info.load_time = prog->aux->load_time; in bpf_prog_get_info_by_fd()
4295 prog->aux->user->uid); in bpf_prog_get_info_by_fd()
4296 info.gpl_compatible = prog->gpl_compatible; in bpf_prog_get_info_by_fd()
4298 memcpy(info.tag, prog->tag, sizeof(prog->tag)); in bpf_prog_get_info_by_fd()
4299 memcpy(info.name, prog->aux->name, sizeof(prog->aux->name)); in bpf_prog_get_info_by_fd()
4301 mutex_lock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
4303 info.nr_map_ids = prog->aux->used_map_cnt; in bpf_prog_get_info_by_fd()
4310 if (put_user(prog->aux->used_maps[i]->id, in bpf_prog_get_info_by_fd()
4312 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
4316 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_get_info_by_fd()
4322 bpf_prog_get_stats(prog, &stats); in bpf_prog_get_info_by_fd()
4327 info.verified_insns = prog->aux->verified_insns; in bpf_prog_get_info_by_fd()
4341 info.xlated_prog_len = bpf_prog_insn_size(prog); in bpf_prog_get_info_by_fd()
4346 if (prog->blinded && !bpf_dump_raw_ok(file->f_cred)) { in bpf_prog_get_info_by_fd()
4350 insns_sanitized = bpf_insn_prepare_dump(prog, file->f_cred); in bpf_prog_get_info_by_fd()
4361 if (bpf_prog_is_offloaded(prog->aux)) { in bpf_prog_get_info_by_fd()
4362 err = bpf_prog_offload_info_fill(&info, prog); in bpf_prog_get_info_by_fd()
4373 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4377 for (i = 0; i < prog->aux->func_cnt; i++) in bpf_prog_get_info_by_fd()
4378 info.jited_prog_len += prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4380 info.jited_prog_len = prog->jited_len; in bpf_prog_get_info_by_fd()
4391 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4396 for (i = 0; i < prog->aux->func_cnt; i++) { in bpf_prog_get_info_by_fd()
4397 len = prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4399 img = (u8 *) prog->aux->func[i]->bpf_func; in bpf_prog_get_info_by_fd()
4408 if (copy_to_user(uinsns, prog->bpf_func, ulen)) in bpf_prog_get_info_by_fd()
4417 info.nr_jited_ksyms = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4429 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4432 prog->aux->func[i]->bpf_func; in bpf_prog_get_info_by_fd()
4438 ksym_addr = (unsigned long) prog->bpf_func; in bpf_prog_get_info_by_fd()
4448 info.nr_jited_func_lens = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4457 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4460 prog->aux->func[i]->jited_len; in bpf_prog_get_info_by_fd()
4465 func_len = prog->jited_len; in bpf_prog_get_info_by_fd()
4474 if (prog->aux->btf) in bpf_prog_get_info_by_fd()
4475 info.btf_id = btf_obj_id(prog->aux->btf); in bpf_prog_get_info_by_fd()
4476 info.attach_btf_id = prog->aux->attach_btf_id; in bpf_prog_get_info_by_fd()
4481 info.nr_func_info = prog->aux->func_info_cnt; in bpf_prog_get_info_by_fd()
4487 if (copy_to_user(user_finfo, prog->aux->func_info, in bpf_prog_get_info_by_fd()
4493 info.nr_line_info = prog->aux->nr_linfo; in bpf_prog_get_info_by_fd()
4499 if (copy_to_user(user_linfo, prog->aux->linfo, in bpf_prog_get_info_by_fd()
4505 if (prog->aux->jited_linfo) in bpf_prog_get_info_by_fd()
4506 info.nr_jited_line_info = prog->aux->nr_linfo; in bpf_prog_get_info_by_fd()
4518 line_addr = (unsigned long)prog->aux->jited_linfo[i]; in bpf_prog_get_info_by_fd()
4528 info.nr_prog_tags = prog->aux->func_cnt ? : 1; in bpf_prog_get_info_by_fd()
4535 if (prog->aux->func_cnt) { in bpf_prog_get_info_by_fd()
4538 prog->aux->func[i]->tag, in bpf_prog_get_info_by_fd()
4544 prog->tag, BPF_TAG_SIZE)) in bpf_prog_get_info_by_fd()
4639 if (link->prog) in bpf_link_get_info_by_fd()
4640 info.prog_id = link->prog->aux->id; in bpf_link_get_info_by_fd()
4805 raw_tp->link.prog->aux->id, in bpf_task_fd_query()
4896 struct bpf_prog *prog; in link_create() local
4905 prog = bpf_prog_get(attr->link_create.prog_fd); in link_create()
4906 if (IS_ERR(prog)) in link_create()
4907 return PTR_ERR(prog); in link_create()
4909 ret = bpf_prog_attach_check_attach_type(prog, in link_create()
4914 switch (prog->type) { in link_create()
4922 ret = cgroup_bpf_link_attach(attr, prog); in link_create()
4925 ret = bpf_tracing_prog_attach(prog, in link_create()
4932 if (attr->link_create.attach_type != prog->expected_attach_type) { in link_create()
4936 if (prog->expected_attach_type == BPF_TRACE_RAW_TP) in link_create()
4937 ret = bpf_raw_tp_link_attach(prog, NULL); in link_create()
4938 else if (prog->expected_attach_type == BPF_TRACE_ITER) in link_create()
4939 ret = bpf_iter_link_attach(attr, uattr, prog); in link_create()
4940 else if (prog->expected_attach_type == BPF_LSM_CGROUP) in link_create()
4941 ret = cgroup_bpf_link_attach(attr, prog); in link_create()
4943 ret = bpf_tracing_prog_attach(prog, in link_create()
4950 ret = netns_bpf_link_create(attr, prog); in link_create()
4954 ret = bpf_xdp_link_attach(attr, prog); in link_create()
4957 ret = tcx_link_attach(attr, prog); in link_create()
4960 ret = bpf_nf_link_attach(attr, prog); in link_create()
4965 ret = bpf_perf_link_attach(attr, prog); in link_create()
4969 ret = bpf_perf_link_attach(attr, prog); in link_create()
4971 ret = bpf_kprobe_multi_link_attach(attr, prog); in link_create()
4973 ret = bpf_uprobe_multi_link_attach(attr, prog); in link_create()
4981 bpf_prog_put(prog); in link_create()
5247 struct bpf_prog *prog; in bpf_prog_bind_map() local
5258 prog = bpf_prog_get(attr->prog_bind_map.prog_fd); in bpf_prog_bind_map()
5259 if (IS_ERR(prog)) in bpf_prog_bind_map()
5260 return PTR_ERR(prog); in bpf_prog_bind_map()
5268 mutex_lock(&prog->aux->used_maps_mutex); in bpf_prog_bind_map()
5270 used_maps_old = prog->aux->used_maps; in bpf_prog_bind_map()
5272 for (i = 0; i < prog->aux->used_map_cnt; i++) in bpf_prog_bind_map()
5278 used_maps_new = kmalloc_array(prog->aux->used_map_cnt + 1, in bpf_prog_bind_map()
5287 sizeof(used_maps_old[0]) * prog->aux->used_map_cnt); in bpf_prog_bind_map()
5288 used_maps_new[prog->aux->used_map_cnt] = map; in bpf_prog_bind_map()
5290 prog->aux->used_map_cnt++; in bpf_prog_bind_map()
5291 prog->aux->used_maps = used_maps_new; in bpf_prog_bind_map()
5296 mutex_unlock(&prog->aux->used_maps_mutex); in bpf_prog_bind_map()
5301 bpf_prog_put(prog); in bpf_prog_bind_map()
5453 const struct bpf_prog *prog, in syscall_prog_is_valid_access() argument
5492 struct bpf_prog * __maybe_unused prog; in kern_sys_bpf() local
5503 prog = bpf_prog_get_type(attr->test.prog_fd, BPF_PROG_TYPE_SYSCALL); in kern_sys_bpf()
5504 if (IS_ERR(prog)) in kern_sys_bpf()
5505 return PTR_ERR(prog); in kern_sys_bpf()
5507 if (attr->test.ctx_size_in < prog->aux->max_ctx_offset || in kern_sys_bpf()
5509 bpf_prog_put(prog); in kern_sys_bpf()
5514 if (!__bpf_prog_enter_sleepable_recur(prog, &run_ctx)) { in kern_sys_bpf()
5516 __bpf_prog_exit_sleepable_recur(prog, 0, &run_ctx); in kern_sys_bpf()
5517 bpf_prog_put(prog); in kern_sys_bpf()
5520 attr->test.retval = bpf_prog_run(prog, (void *) (long) attr->test.ctx_in); in kern_sys_bpf()
5521 __bpf_prog_exit_sleepable_recur(prog, 0 /* bpf_prog_run does runtime stats */, in kern_sys_bpf()
5523 bpf_prog_put(prog); in kern_sys_bpf()
5542 tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) in tracing_prog_func_proto() argument
5590 syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) in syscall_prog_func_proto() argument
5602 return tracing_prog_func_proto(func_id, prog); in syscall_prog_func_proto()