* [PATCH bpf] libbpf: skip base btf sanity checks
@ 2024-06-24 9:09 Antoine Tenart
2024-06-24 13:30 ` Alan Maguire
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Antoine Tenart @ 2024-06-24 9:09 UTC (permalink / raw)
To: andrii, eddyz87; +Cc: Antoine Tenart, bpf
When upgrading to libbpf 1.3 we noticed a big performance hit while
loading programs using CORE on non base-BTF symbols. This was tracked
down to the new BTF sanity check logic. The issue is the base BTF
definitions are checked first for the base BTF and then again for every
module BTF.
Loading 5 dummy programs (using libbpf-rs) that are using CORE on a
non-base BTF symbol on my system:
- Before this fix: 3s.
- With this fix: 0.1s.
Fix this by only checking the types starting at the BTF start id. This
should ensure the base BTF is still checked as expected but only once
(btf->start_id == 1 when creating the base BTF), and then only
additional types are checked for each module BTF.
Fixes: 3903802bb99a ("libbpf: Add basic BTF sanity validation")
Signed-off-by: Antoine Tenart <atenart@kernel.org>
---
tools/lib/bpf/btf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 2d0840ef599a..142060bbce0a 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -598,7 +598,7 @@ static int btf_sanity_check(const struct btf *btf)
__u32 i, n = btf__type_cnt(btf);
int err;
- for (i = 1; i < n; i++) {
+ for (i = btf->start_id; i < n; i++) {
t = btf_type_by_id(btf, i);
err = btf_validate_type(btf, t, i);
if (err)
--
2.45.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH bpf] libbpf: skip base btf sanity checks
2024-06-24 9:09 [PATCH bpf] libbpf: skip base btf sanity checks Antoine Tenart
@ 2024-06-24 13:30 ` Alan Maguire
2024-06-24 16:18 ` Andrii Nakryiko
2024-06-24 20:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Alan Maguire @ 2024-06-24 13:30 UTC (permalink / raw)
To: Antoine Tenart, andrii, eddyz87; +Cc: bpf
On 24/06/2024 10:09, Antoine Tenart wrote:
> When upgrading to libbpf 1.3 we noticed a big performance hit while
> loading programs using CORE on non base-BTF symbols. This was tracked
> down to the new BTF sanity check logic. The issue is the base BTF
> definitions are checked first for the base BTF and then again for every
> module BTF.
>
> Loading 5 dummy programs (using libbpf-rs) that are using CORE on a
> non-base BTF symbol on my system:
> - Before this fix: 3s.
> - With this fix: 0.1s.
>
> Fix this by only checking the types starting at the BTF start id. This
> should ensure the base BTF is still checked as expected but only once
> (btf->start_id == 1 when creating the base BTF), and then only
> additional types are checked for each module BTF.
>
> Fixes: 3903802bb99a ("libbpf: Add basic BTF sanity validation")
> Signed-off-by: Antoine Tenart <atenart@kernel.org>
This looks good to me.
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
> ---
> tools/lib/bpf/btf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 2d0840ef599a..142060bbce0a 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -598,7 +598,7 @@ static int btf_sanity_check(const struct btf *btf)
> __u32 i, n = btf__type_cnt(btf);
> int err;
>
> - for (i = 1; i < n; i++) {
> + for (i = btf->start_id; i < n; i++) {
> t = btf_type_by_id(btf, i);
> err = btf_validate_type(btf, t, i);
> if (err)
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH bpf] libbpf: skip base btf sanity checks
2024-06-24 9:09 [PATCH bpf] libbpf: skip base btf sanity checks Antoine Tenart
2024-06-24 13:30 ` Alan Maguire
@ 2024-06-24 16:18 ` Andrii Nakryiko
2024-06-24 20:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Andrii Nakryiko @ 2024-06-24 16:18 UTC (permalink / raw)
To: Antoine Tenart; +Cc: andrii, eddyz87, bpf
On Mon, Jun 24, 2024 at 2:09 AM Antoine Tenart <atenart@kernel.org> wrote:
>
> When upgrading to libbpf 1.3 we noticed a big performance hit while
> loading programs using CORE on non base-BTF symbols. This was tracked
> down to the new BTF sanity check logic. The issue is the base BTF
> definitions are checked first for the base BTF and then again for every
> module BTF.
>
> Loading 5 dummy programs (using libbpf-rs) that are using CORE on a
> non-base BTF symbol on my system:
> - Before this fix: 3s.
> - With this fix: 0.1s.
>
> Fix this by only checking the types starting at the BTF start id. This
> should ensure the base BTF is still checked as expected but only once
> (btf->start_id == 1 when creating the base BTF), and then only
> additional types are checked for each module BTF.
>
> Fixes: 3903802bb99a ("libbpf: Add basic BTF sanity validation")
> Signed-off-by: Antoine Tenart <atenart@kernel.org>
> ---
> tools/lib/bpf/btf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
Makes total sense, thanks, applied!
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 2d0840ef599a..142060bbce0a 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -598,7 +598,7 @@ static int btf_sanity_check(const struct btf *btf)
> __u32 i, n = btf__type_cnt(btf);
> int err;
>
> - for (i = 1; i < n; i++) {
> + for (i = btf->start_id; i < n; i++) {
> t = btf_type_by_id(btf, i);
> err = btf_validate_type(btf, t, i);
> if (err)
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH bpf] libbpf: skip base btf sanity checks
2024-06-24 9:09 [PATCH bpf] libbpf: skip base btf sanity checks Antoine Tenart
2024-06-24 13:30 ` Alan Maguire
2024-06-24 16:18 ` Andrii Nakryiko
@ 2024-06-24 20:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-06-24 20:10 UTC (permalink / raw)
To: Antoine Tenart; +Cc: andrii, eddyz87, bpf
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Mon, 24 Jun 2024 11:09:07 +0200 you wrote:
> When upgrading to libbpf 1.3 we noticed a big performance hit while
> loading programs using CORE on non base-BTF symbols. This was tracked
> down to the new BTF sanity check logic. The issue is the base BTF
> definitions are checked first for the base BTF and then again for every
> module BTF.
>
> Loading 5 dummy programs (using libbpf-rs) that are using CORE on a
> non-base BTF symbol on my system:
> - Before this fix: 3s.
> - With this fix: 0.1s.
>
> [...]
Here is the summary with links:
- [bpf] libbpf: skip base btf sanity checks
https://git.kernel.org/bpf/bpf-next/c/c73a9683cb21
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-06-24 20:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-24 9:09 [PATCH bpf] libbpf: skip base btf sanity checks Antoine Tenart
2024-06-24 13:30 ` Alan Maguire
2024-06-24 16:18 ` Andrii Nakryiko
2024-06-24 20:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox