diff mbox series

[bpf-next,2/2] bpf: Add support to detect and dedup instances of same structs

Message ID 20211023120452.212885-3-jolsa@kernel.org (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series bpf: Fix BTF data for modules | expand

Checks

Context Check Description
netdev/cover_letter success Series has a cover letter
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 1 maintainers not CCed: kpsingh@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch warning WARNING: From:/Signed-off-by: email address mismatch: 'From: Jiri Olsa <jolsa@redhat.com>' != 'Signed-off-by: Jiri Olsa <jolsa@kernel.org>' WARNING: line length of 85 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success No static functions without inline keyword in header files
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next success VM_Test

Commit Message

Jiri Olsa Oct. 23, 2021, 12:04 p.m. UTC
The s390x compiler generates multiple definitions of the same struct
and dedup algorithm does not seem to handle this at the moment.

I found code in dedup that seems to handle such situation for arrays,
and added btf_dedup_is_equiv call for structs.

With this change I can no longer see vmlinux's structs in kernel
module BTF data, but I have no idea if that breaks anything else.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/lib/bpf/btf.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Andrii Nakryiko Oct. 26, 2021, 4:59 a.m. UTC | #1
On Sat, Oct 23, 2021 at 5:05 AM Jiri Olsa <jolsa@redhat.com> wrote:
>
> The s390x compiler generates multiple definitions of the same struct
> and dedup algorithm does not seem to handle this at the moment.
>
> I found code in dedup that seems to handle such situation for arrays,
> and added btf_dedup_is_equiv call for structs.
>
> With this change I can no longer see vmlinux's structs in kernel
> module BTF data, but I have no idea if that breaks anything else.
>

I'm pretty sure this is not the right way to handle this. Let's figure
out what is causing a difference in types (i.e., why they are not
equivalent), before attempting to patch up BTF dedup algorithm.

> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/lib/bpf/btf.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 3a01c4b7f36a..ec164d0cee30 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -3920,8 +3920,16 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
>                  * types within a single CU. So work around that by explicitly
>                  * allowing identical array types here.
>                  */
> -               return hypot_type_id == cand_id ||
> -                      btf_dedup_identical_arrays(d, hypot_type_id, cand_id);
> +               struct btf_type *t;
> +
> +               if (hypot_type_id == cand_id)
> +                       return 1;
> +               t = btf_type_by_id(d->btf, hypot_type_id);
> +               if (btf_is_array(t))
> +                       return btf_dedup_identical_arrays(d, hypot_type_id, cand_id);
> +               if (btf_is_struct(t))
> +                       return btf_dedup_is_equiv(d, hypot_type_id, cand_id);
> +               return 0;
>         }
>
>         if (btf_dedup_hypot_map_add(d, canon_id, cand_id))
> --
> 2.31.1
>
diff mbox series

Patch

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 3a01c4b7f36a..ec164d0cee30 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -3920,8 +3920,16 @@  static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
 		 * types within a single CU. So work around that by explicitly
 		 * allowing identical array types here.
 		 */
-		return hypot_type_id == cand_id ||
-		       btf_dedup_identical_arrays(d, hypot_type_id, cand_id);
+		struct btf_type *t;
+
+		if (hypot_type_id == cand_id)
+			return 1;
+		t = btf_type_by_id(d->btf, hypot_type_id);
+		if (btf_is_array(t))
+			return btf_dedup_identical_arrays(d, hypot_type_id, cand_id);
+		if (btf_is_struct(t))
+			return btf_dedup_is_equiv(d, hypot_type_id, cand_id);
+		return 0;
 	}
 
 	if (btf_dedup_hypot_map_add(d, canon_id, cand_id))