All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] libbpf: fix deduplication of typedef with base definitions
@ 2026-04-16  7:38 Antoine Tenart
  2026-04-16  8:31 ` Alan Maguire
  0 siblings, 1 reply; 4+ messages in thread
From: Antoine Tenart @ 2026-04-16  7:38 UTC (permalink / raw)
  To: andrii, eddyz87; +Cc: Antoine Tenart, bpf, Paul Houssel

When deduplicating definitions for a module, typedef defined in the base
are not removed. This is because the hash used for base types differs
from the one used in the deduplication logic in btf_dedup_struct_type.

This was introduced by the referenced commit when moving the typedef
deduplication logic handling from btf_dedup_ref_type to
btf_dedup_struct_type, as this also changed the hash logic
(btf_hash_common to btf_hash_typedef).

This also impacts other types referencing those typedef (e.g. const). In
my test, the BTF section size of the openvswitch module went from 31KB
to 45KB.

Cc: Paul Houssel <paulhoussel2@gmail.com>
Fixes: 3781413465df ("libbpf: Fix BTF dedup to support recursive typedef definitions").
Signed-off-by: Antoine Tenart <atenart@kernel.org>
---
 tools/lib/bpf/btf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index ceb57b46a878..771aeaa0262b 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -4578,12 +4578,14 @@ static int btf_dedup_prep(struct btf_dedup *d)
 		case BTF_KIND_RESTRICT:
 		case BTF_KIND_PTR:
 		case BTF_KIND_FWD:
-		case BTF_KIND_TYPEDEF:
 		case BTF_KIND_FUNC:
 		case BTF_KIND_FLOAT:
 		case BTF_KIND_TYPE_TAG:
 			h = btf_hash_common(t);
 			break;
+		case BTF_KIND_TYPEDEF:
+			h = btf_hash_typedef(t);
+			break;
 		case BTF_KIND_INT:
 		case BTF_KIND_DECL_TAG:
 			h = btf_hash_int_decl_tag(t);
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] libbpf: fix deduplication of typedef with base definitions
  2026-04-16  7:38 [PATCH bpf] libbpf: fix deduplication of typedef with base definitions Antoine Tenart
@ 2026-04-16  8:31 ` Alan Maguire
  2026-04-16 10:20   ` Antoine Tenart
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Maguire @ 2026-04-16  8:31 UTC (permalink / raw)
  To: Antoine Tenart, andrii, eddyz87; +Cc: bpf, Paul Houssel

On 16/04/2026 08:38, Antoine Tenart wrote:
> When deduplicating definitions for a module, typedef defined in the base
> are not removed. This is because the hash used for base types differs
> from the one used in the deduplication logic in btf_dedup_struct_type.
> 
> This was introduced by the referenced commit when moving the typedef
> deduplication logic handling from btf_dedup_ref_type to
> btf_dedup_struct_type, as this also changed the hash logic
> (btf_hash_common to btf_hash_typedef).
> 
> This also impacts other types referencing those typedef (e.g. const). In
> my test, the BTF section size of the openvswitch module went from 31KB
> to 45KB.
> 
> Cc: Paul Houssel <paulhoussel2@gmail.com>
> Fixes: 3781413465df ("libbpf: Fix BTF dedup to support recursive typedef definitions").
> Signed-off-by: Antoine Tenart <atenart@kernel.org>

Nice catch! It would be great to have test coverage for this in
prog_tests/btf_dedup_split.c ; adding a duplicated typedef to base and split
BTF in test_split_simple() and ensuring it's removed from split BTF
would do the trick I think.
> ---
>  tools/lib/bpf/btf.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index ceb57b46a878..771aeaa0262b 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -4578,12 +4578,14 @@ static int btf_dedup_prep(struct btf_dedup *d)
>  		case BTF_KIND_RESTRICT:
>  		case BTF_KIND_PTR:
>  		case BTF_KIND_FWD:
> -		case BTF_KIND_TYPEDEF:
>  		case BTF_KIND_FUNC:
>  		case BTF_KIND_FLOAT:
>  		case BTF_KIND_TYPE_TAG:
>  			h = btf_hash_common(t);
>  			break;
> +		case BTF_KIND_TYPEDEF:
> +			h = btf_hash_typedef(t);
> +			break;
>  		case BTF_KIND_INT:
>  		case BTF_KIND_DECL_TAG:
>  			h = btf_hash_int_decl_tag(t);


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] libbpf: fix deduplication of typedef with base definitions
  2026-04-16  8:31 ` Alan Maguire
@ 2026-04-16 10:20   ` Antoine Tenart
  2026-04-16 11:53     ` Alan Maguire
  0 siblings, 1 reply; 4+ messages in thread
From: Antoine Tenart @ 2026-04-16 10:20 UTC (permalink / raw)
  To: Alan Maguire; +Cc: Antoine Tenart, andrii, eddyz87, bpf, Paul Houssel

On Thu, Apr 16, 2026 at 09:31:53AM +0100, Alan Maguire wrote:
> On 16/04/2026 08:38, Antoine Tenart wrote:
> > When deduplicating definitions for a module, typedef defined in the base
> > are not removed. This is because the hash used for base types differs
> > from the one used in the deduplication logic in btf_dedup_struct_type.
> > 
> > This was introduced by the referenced commit when moving the typedef
> > deduplication logic handling from btf_dedup_ref_type to
> > btf_dedup_struct_type, as this also changed the hash logic
> > (btf_hash_common to btf_hash_typedef).
> > 
> > This also impacts other types referencing those typedef (e.g. const). In
> > my test, the BTF section size of the openvswitch module went from 31KB
> > to 45KB.
> > 
> > Cc: Paul Houssel <paulhoussel2@gmail.com>
> > Fixes: 3781413465df ("libbpf: Fix BTF dedup to support recursive typedef definitions").
> > Signed-off-by: Antoine Tenart <atenart@kernel.org>
> 
> Nice catch! It would be great to have test coverage for this in
> prog_tests/btf_dedup_split.c ; adding a duplicated typedef to base and split
> BTF in test_split_simple() and ensuring it's removed from split BTF
> would do the trick I think.

Makes sense, I'll add a test for v2. Would you prefer a dedicated test
or reusing an existing one?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] libbpf: fix deduplication of typedef with base definitions
  2026-04-16 10:20   ` Antoine Tenart
@ 2026-04-16 11:53     ` Alan Maguire
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Maguire @ 2026-04-16 11:53 UTC (permalink / raw)
  To: Antoine Tenart; +Cc: andrii, eddyz87, bpf, Paul Houssel

On 16/04/2026 11:20, Antoine Tenart wrote:
> On Thu, Apr 16, 2026 at 09:31:53AM +0100, Alan Maguire wrote:
>> On 16/04/2026 08:38, Antoine Tenart wrote:
>>> When deduplicating definitions for a module, typedef defined in the base
>>> are not removed. This is because the hash used for base types differs
>>> from the one used in the deduplication logic in btf_dedup_struct_type.
>>>
>>> This was introduced by the referenced commit when moving the typedef
>>> deduplication logic handling from btf_dedup_ref_type to
>>> btf_dedup_struct_type, as this also changed the hash logic
>>> (btf_hash_common to btf_hash_typedef).
>>>
>>> This also impacts other types referencing those typedef (e.g. const). In
>>> my test, the BTF section size of the openvswitch module went from 31KB
>>> to 45KB.
>>>
>>> Cc: Paul Houssel <paulhoussel2@gmail.com>
>>> Fixes: 3781413465df ("libbpf: Fix BTF dedup to support recursive typedef definitions").
>>> Signed-off-by: Antoine Tenart <atenart@kernel.org>
>>
>> Nice catch! It would be great to have test coverage for this in
>> prog_tests/btf_dedup_split.c ; adding a duplicated typedef to base and split
>> BTF in test_split_simple() and ensuring it's removed from split BTF
>> would do the trick I think.
> 
> Makes sense, I'll add a test for v2. Would you prefer a dedicated test
> or reusing an existing one?

Thanks! I'd suggest just adding identical typedefs to the base+split BTF 
in the existing  test_split_simple() in prog_tests/btf_dedup_split.c, ensuring 
the deduped BTF only has one instance of the typedef (but in a separate
patch from this one). That should be enough to verify this is fixed I think.

Feel free to add my

Reviewed-by: Alan Maguire <alan.maguire@oracle.com>

to the libbpf patch.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-16 11:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-16  7:38 [PATCH bpf] libbpf: fix deduplication of typedef with base definitions Antoine Tenart
2026-04-16  8:31 ` Alan Maguire
2026-04-16 10:20   ` Antoine Tenart
2026-04-16 11:53     ` Alan Maguire

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.