提交 e67bce2b 编写于 作者: A Andrii Nakryiko 提交者: Zheng Zengkai

libbpf: Support BTF_KIND_FLOAT during type compatibility checks in CO-RE

mainline inclusion
from mainline-5.13-rc1
commit 6709a914
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=6709a914c8498f42b1498b3d31f4b078d092fd35

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

Add BTF_KIND_FLOAT support when doing CO-RE field type compatibility check.
Without this, relocations against float/double fields will fail.

Also adjust one error message to emit instruction index instead of less
convenient instruction byte offset.

Fixes: 22541a9e ("libbpf: Add BTF_KIND_FLOAT support")
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Acked-by: NLorenz Bauer <lmb@cloudflare.com>
Link: https://lore.kernel.org/bpf/20210426192949.416837-3-andrii@kernel.org
(cherry picked from commit 6709a914)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 de0b6c01
...@@ -5169,6 +5169,7 @@ bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 l ...@@ -5169,6 +5169,7 @@ bpf_core_find_cands(struct bpf_object *obj, const struct btf *local_btf, __u32 l
* least one of enums should be anonymous; * least one of enums should be anonymous;
* - for ENUMs, check sizes, names are ignored; * - for ENUMs, check sizes, names are ignored;
* - for INT, size and signedness are ignored; * - for INT, size and signedness are ignored;
* - any two FLOATs are always compatible;
* - for ARRAY, dimensionality is ignored, element types are checked for * - for ARRAY, dimensionality is ignored, element types are checked for
* compatibility recursively; * compatibility recursively;
* - everything else shouldn't be ever a target of relocation. * - everything else shouldn't be ever a target of relocation.
...@@ -5195,6 +5196,7 @@ static int bpf_core_fields_are_compat(const struct btf *local_btf, ...@@ -5195,6 +5196,7 @@ static int bpf_core_fields_are_compat(const struct btf *local_btf,
switch (btf_kind(local_type)) { switch (btf_kind(local_type)) {
case BTF_KIND_PTR: case BTF_KIND_PTR:
case BTF_KIND_FLOAT:
return 1; return 1;
case BTF_KIND_FWD: case BTF_KIND_FWD:
case BTF_KIND_ENUM: { case BTF_KIND_ENUM: {
...@@ -6299,8 +6301,8 @@ static int bpf_core_apply_relo(struct bpf_program *prog, ...@@ -6299,8 +6301,8 @@ static int bpf_core_apply_relo(struct bpf_program *prog,
/* bpf_core_patch_insn() should know how to handle missing targ_spec */ /* bpf_core_patch_insn() should know how to handle missing targ_spec */
err = bpf_core_patch_insn(prog, relo, relo_idx, &targ_res); err = bpf_core_patch_insn(prog, relo, relo_idx, &targ_res);
if (err) { if (err) {
pr_warn("prog '%s': relo #%d: failed to patch insn at offset %d: %d\n", pr_warn("prog '%s': relo #%d: failed to patch insn #%zu: %d\n",
prog->name, relo_idx, relo->insn_off, err); prog->name, relo_idx, relo->insn_off / BPF_INSN_SZ, err);
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册