提交 7c0bfa74 编写于 作者: K Kumar Kartikeya Dwivedi 提交者: Zheng Zengkai

libbpf: Avoid reload of imm for weak, unresolved, repeating ksym

mainline inclusion
from mainline-5.17-rc1
commit d995816b
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d995816b77eb826e0f6d7adf4471ec191b362be0

-------------------------------------------------

Alexei pointed out that we can use BPF_REG_0 which already contains imm
from move_blob2blob computation. Note that we now compare the second
insn's imm, but this should not matter, since both will be zeroed out
for the error case for the insn populated earlier.
Suggested-by: NAlexei Starovoitov <ast@kernel.org>
Signed-off-by: NKumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Acked-by: NSong Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20211122235733.634914-4-memxor@gmail.com
(cherry picked from commit d995816b)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 d6609a67
...@@ -820,9 +820,8 @@ static void emit_relo_ksym_btf(struct bpf_gen *gen, struct ksym_relo_desc *relo, ...@@ -820,9 +820,8 @@ static void emit_relo_ksym_btf(struct bpf_gen *gen, struct ksym_relo_desc *relo,
kdesc->insn + offsetof(struct bpf_insn, imm)); kdesc->insn + offsetof(struct bpf_insn, imm));
move_blob2blob(gen, insn + sizeof(struct bpf_insn) + offsetof(struct bpf_insn, imm), 4, move_blob2blob(gen, insn + sizeof(struct bpf_insn) + offsetof(struct bpf_insn, imm), 4,
kdesc->insn + sizeof(struct bpf_insn) + offsetof(struct bpf_insn, imm)); kdesc->insn + sizeof(struct bpf_insn) + offsetof(struct bpf_insn, imm));
emit(gen, BPF_LDX_MEM(BPF_W, BPF_REG_9, BPF_REG_8, offsetof(struct bpf_insn, imm))); /* jump over src_reg adjustment if imm is not 0, reuse BPF_REG_0 from move_blob2blob */
/* jump over src_reg adjustment if imm is not 0 */ emit(gen, BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 3));
emit(gen, BPF_JMP_IMM(BPF_JNE, BPF_REG_9, 0, 3));
goto clear_src_reg; goto clear_src_reg;
} }
/* remember insn offset, so we can copy BTF ID and FD later */ /* remember insn offset, so we can copy BTF ID and FD later */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册