Lines Matching defs:insn
591 /* BTF fd index to be patched in for insn->off, this is
769 static bool insn_is_subprog_call(const struct bpf_insn *insn)
771 return BPF_CLASS(insn->code) == BPF_JMP &&
772 BPF_OP(insn->code) == BPF_CALL &&
773 BPF_SRC(insn->code) == BPF_K &&
774 insn->src_reg == BPF_PSEUDO_CALL &&
775 insn->dst_reg == 0 &&
776 insn->off == 0;
779 static bool is_call_insn(const struct bpf_insn *insn)
781 return insn->code == (BPF_JMP | BPF_CALL);
784 static bool insn_is_pseudo_func(struct bpf_insn *insn)
786 return is_ldimm64_insn(insn) && insn->src_reg == BPF_PSEUDO_FUNC;
895 pr_debug("sec '%s': found program '%s' at insn offset %zu (%zu bytes), code size %zu insns (%zu bytes)\n",
4437 struct bpf_insn *insn = &prog->insns[insn_idx];
4445 if (!is_call_insn(insn) && !is_ldimm64_insn(insn)) {
4447 prog->name, sym_name, insn_idx, insn->code);
4466 pr_debug("prog '%s': found extern #%d '%s' (sym %d) for insn #%u\n",
4468 if (insn->code == (BPF_JMP | BPF_CALL))
4478 if (is_call_insn(insn)) {
4479 if (insn->src_reg != BPF_PSEUDO_CALL) {
4513 /* global_func: sym->st_value = offset in the section, insn->imm = 0.
4514 * local_func: sym->st_value = 0, insn->imm = offset in the section.
4516 if ((sym->st_value % BPF_INSN_SZ) || (insn->imm % BPF_INSN_SZ)) {
4518 prog->name, sym_name, (size_t)sym->st_value, insn->imm);
4547 pr_debug("prog '%s': found map %zd (%s, sec %d, off %zu) for insn #%u\n",
4574 pr_debug("prog '%s': found data map %zd (%s, sec %d, off %zu) for insn %u\n",
4712 pr_debug("sec '%s': relo #%d: insn #%u against '%s'\n",
4717 pr_debug("sec '%s': relo #%d: couldn't find program in section '%s' for insn #%u, probably overridden weak function, skipping...\n",
6195 struct bpf_insn *insn;
6247 pr_debug("sec '%s': skipping CO-RE relocation #%d for insn #%d belonging to eliminated weak subprogram\n",
6264 insn = &prog->insns[insn_idx];
6283 err = bpf_core_patch_insn(prog->name, insn, insn_idx, rec, i, &targ_res);
6285 pr_warn("prog '%s': relo #%d: failed to patch insn #%u: %d\n",
6311 int insn_idx, struct bpf_insn *insn,
6316 pr_debug("prog '%s': relo #%d: poisoning insn #%d that loads map #%d '%s'\n",
6321 insn->code = BPF_JMP | BPF_CALL;
6322 insn->dst_reg = 0;
6323 insn->src_reg = 0;
6324 insn->off = 0;
6330 insn->imm = POISON_LDIMM64_MAP_BASE + map_idx;
6332 insn++;
6341 int insn_idx, struct bpf_insn *insn,
6344 pr_debug("prog '%s': relo #%d: poisoning insn #%d that calls kfunc '%s'\n",
6348 insn->code = BPF_JMP | BPF_CALL;
6349 insn->dst_reg = 0;
6350 insn->src_reg = 0;
6351 insn->off = 0;
6357 insn->imm = POISON_CALL_KFUNC_BASE + ext_idx;
6372 struct bpf_insn *insn = &prog->insns[relo->insn_idx];
6380 insn[0].src_reg = BPF_PSEUDO_MAP_IDX;
6381 insn[0].imm = relo->map_idx;
6383 insn[0].src_reg = BPF_PSEUDO_MAP_FD;
6384 insn[0].imm = map->fd;
6386 poison_map_ldimm64(prog, i, relo->insn_idx, insn,
6392 insn[1].imm = insn[0].imm + relo->sym_off;
6394 insn[0].src_reg = BPF_PSEUDO_MAP_IDX_VALUE;
6395 insn[0].imm = relo->map_idx;
6397 insn[0].src_reg = BPF_PSEUDO_MAP_VALUE;
6398 insn[0].imm = map->fd;
6400 poison_map_ldimm64(prog, i, relo->insn_idx, insn,
6408 insn[0].src_reg = BPF_PSEUDO_MAP_IDX_VALUE;
6409 insn[0].imm = obj->kconfig_map_idx;
6411 insn[0].src_reg = BPF_PSEUDO_MAP_VALUE;
6412 insn[0].imm = obj->maps[obj->kconfig_map_idx].fd;
6414 insn[1].imm = ext->kcfg.data_off;
6417 insn[0].src_reg = BPF_PSEUDO_BTF_ID;
6418 insn[0].imm = ext->ksym.kernel_btf_id;
6419 insn[1].imm = ext->ksym.kernel_btf_obj_fd;
6421 insn[0].imm = (__u32)ext->ksym.addr;
6422 insn[1].imm = ext->ksym.addr >> 32;
6428 insn[0].src_reg = BPF_PSEUDO_KFUNC_CALL;
6430 insn[0].imm = ext->ksym.kernel_btf_id;
6431 insn[0].off = ext->ksym.btf_fd_idx;
6433 poison_kfunc_call(prog, i, relo->insn_idx, insn,
6438 if (insn[0].src_reg != BPF_PSEUDO_FUNC) {
6439 pr_warn("prog '%s': relo #%d: bad insn\n",
6687 struct bpf_insn *insn;
6695 insn = &main_prog->insns[prog->sub_insn_off + insn_idx];
6696 if (!insn_is_subprog_call(insn) && !insn_is_pseudo_func(insn))
6706 pr_warn("prog '%s': unexpected relo for insn #%zu, type %d\n",
6715 * relocation is against STT_SECTION and insn->imm
6718 * for subprog addr relocation, the relo->sym_off + insn->imm is
6722 sub_insn_idx = relo->sym_off / BPF_INSN_SZ + insn->imm + 1;
6724 sub_insn_idx = (relo->sym_off + insn->imm) / BPF_INSN_SZ;
6725 } else if (insn_is_pseudo_func(insn)) {
6730 pr_warn("prog '%s': missing subprog addr relo for insn #%zu\n",
6740 sub_insn_idx = prog->sec_insn_off + insn_idx + insn->imm + 1;
6773 insn = &main_prog->insns[prog->sub_insn_off + insn_idx];
6780 insn->imm = subprog->sub_insn_off - (prog->sub_insn_off + insn_idx) - 1;
6782 pr_debug("prog '%s': insn #%zu relocated, imm %d points to subprog '%s' (now at %zu offset)\n",
6783 prog->name, insn_idx, insn->imm, subprog->name, subprog->sub_insn_off);
6965 struct bpf_insn *insn = &prog->insns[relo->insn_idx];
6967 /* mark the insn, so it's recognized by insn_is_pseudo_func() */
6969 insn[0].src_reg = BPF_PSEUDO_FUNC;
7215 static bool insn_is_helper_call(struct bpf_insn *insn, enum bpf_func_id *func_id)
7217 if (BPF_CLASS(insn->code) == BPF_JMP &&
7218 BPF_OP(insn->code) == BPF_CALL &&
7219 BPF_SRC(insn->code) == BPF_K &&
7220 insn->src_reg == 0 &&
7221 insn->dst_reg == 0) {
7222 *func_id = insn->imm;
7230 struct bpf_insn *insn = prog->insns;
7237 for (i = 0; i < prog->insns_cnt; i++, insn++) {
7238 if (!insn_is_helper_call(insn, &func_id))
7249 insn->imm = BPF_FUNC_probe_read;
7254 insn->imm = BPF_FUNC_probe_read_str;
8161 /* insn->off is s16 */
8184 * populates FD into ld_imm64 insn when it's used to point to kfunc.