All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] libbpf: handle BTF parsing and loading properly
@ 2019-03-08 23:58 Andrii Nakryiko
  2019-03-09  6:10 ` Martin Lau
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrii Nakryiko @ 2019-03-08 23:58 UTC (permalink / raw)
  To: andrii.nakryiko, kernel-team, ast, netdev, bpf, daniel, kafai, tehnerd
  Cc: Andrii Nakryiko

This patch splits and cleans up error handling logic for loading BTF data.
Previously, if BTF data was parsed successfully, but failed to load into
kernel, we'd report nonsensical error code, instead of error returned from
btf__load(). Now btf__new() and btf__load() are handled separately with proper
cleanup and warning reporting.

Fixes: d29d87f7e612 ("btf: separate btf creation and loading")
Reported-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/lib/bpf/libbpf.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index d5b830d60601..5e977d2688da 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -835,12 +835,19 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)
 			obj->efile.maps_shndx = idx;
 		else if (strcmp(name, BTF_ELF_SEC) == 0) {
 			obj->btf = btf__new(data->d_buf, data->d_size);
-			if (IS_ERR(obj->btf) || btf__load(obj->btf)) {
+			if (IS_ERR(obj->btf)) {
 				pr_warning("Error loading ELF section %s: %ld. Ignored and continue.\n",
 					   BTF_ELF_SEC, PTR_ERR(obj->btf));
-				if (!IS_ERR(obj->btf))
-					btf__free(obj->btf);
 				obj->btf = NULL;
+				continue;
+			}
+			err = btf__load(obj->btf);
+			if (err) {
+				pr_warning("Error loading %s into kernel: %d. Ignored and continue.\n",
+					   BTF_ELF_SEC, err);
+				btf__free(obj->btf);
+				obj->btf = NULL;
+				err = 0;
 			}
 		} else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) {
 			btf_ext_data = data;
-- 
2.17.1


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

* Re: [PATCH bpf] libbpf: handle BTF parsing and loading properly
  2019-03-08 23:58 [PATCH bpf] libbpf: handle BTF parsing and loading properly Andrii Nakryiko
@ 2019-03-09  6:10 ` Martin Lau
  2019-03-09  7:30 ` Yonghong Song
  2019-03-11  9:44 ` Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: Martin Lau @ 2019-03-09  6:10 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: andrii.nakryiko, Kernel Team, Alexei Starovoitov, netdev, bpf,
	daniel, tehnerd

On Fri, Mar 08, 2019 at 03:58:20PM -0800, Andrii Nakryiko wrote:
> This patch splits and cleans up error handling logic for loading BTF data.
> Previously, if BTF data was parsed successfully, but failed to load into
> kernel, we'd report nonsensical error code, instead of error returned from
> btf__load(). Now btf__new() and btf__load() are handled separately with proper
> cleanup and warning reporting.
Acked-by: Martin KaFai Lau <kafai@fb.com>

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

* Re: [PATCH bpf] libbpf: handle BTF parsing and loading properly
  2019-03-08 23:58 [PATCH bpf] libbpf: handle BTF parsing and loading properly Andrii Nakryiko
  2019-03-09  6:10 ` Martin Lau
@ 2019-03-09  7:30 ` Yonghong Song
  2019-03-11  9:44 ` Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: Yonghong Song @ 2019-03-09  7:30 UTC (permalink / raw)
  To: Andrii Nakryiko, andrii.nakryiko, Kernel Team,
	Alexei Starovoitov, netdev, bpf, daniel, Martin Lau, tehnerd



On 3/8/19 3:58 PM, Andrii Nakryiko wrote:
> This patch splits and cleans up error handling logic for loading BTF data.
> Previously, if BTF data was parsed successfully, but failed to load into
> kernel, we'd report nonsensical error code, instead of error returned from
> btf__load(). Now btf__new() and btf__load() are handled separately with proper
> cleanup and warning reporting.
> 
> Fixes: d29d87f7e612 ("btf: separate btf creation and loading")
> Reported-by: Martin KaFai Lau <kafai@fb.com>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Acked-by: Yonghong Song <yhs@fb.com>

> ---
>   tools/lib/bpf/libbpf.c | 13 ++++++++++---
>   1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index d5b830d60601..5e977d2688da 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -835,12 +835,19 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)
>   			obj->efile.maps_shndx = idx;
>   		else if (strcmp(name, BTF_ELF_SEC) == 0) {
>   			obj->btf = btf__new(data->d_buf, data->d_size);
> -			if (IS_ERR(obj->btf) || btf__load(obj->btf)) {
> +			if (IS_ERR(obj->btf)) {
>   				pr_warning("Error loading ELF section %s: %ld. Ignored and continue.\n",
>   					   BTF_ELF_SEC, PTR_ERR(obj->btf));
> -				if (!IS_ERR(obj->btf))
> -					btf__free(obj->btf);
>   				obj->btf = NULL;
> +				continue;
> +			}
> +			err = btf__load(obj->btf);
> +			if (err) {
> +				pr_warning("Error loading %s into kernel: %d. Ignored and continue.\n",
> +					   BTF_ELF_SEC, err);
> +				btf__free(obj->btf);
> +				obj->btf = NULL;
> +				err = 0;
>   			}
>   		} else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) {
>   			btf_ext_data = data;
> 

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

* Re: [PATCH bpf] libbpf: handle BTF parsing and loading properly
  2019-03-08 23:58 [PATCH bpf] libbpf: handle BTF parsing and loading properly Andrii Nakryiko
  2019-03-09  6:10 ` Martin Lau
  2019-03-09  7:30 ` Yonghong Song
@ 2019-03-11  9:44 ` Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2019-03-11  9:44 UTC (permalink / raw)
  To: Andrii Nakryiko, andrii.nakryiko, kernel-team, ast, netdev, bpf,
	kafai, tehnerd

On 03/09/2019 12:58 AM, Andrii Nakryiko wrote:
> This patch splits and cleans up error handling logic for loading BTF data.
> Previously, if BTF data was parsed successfully, but failed to load into
> kernel, we'd report nonsensical error code, instead of error returned from
> btf__load(). Now btf__new() and btf__load() are handled separately with proper
> cleanup and warning reporting.
> 
> Fixes: d29d87f7e612 ("btf: separate btf creation and loading")
> Reported-by: Martin KaFai Lau <kafai@fb.com>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Applied, thanks!

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

end of thread, other threads:[~2019-03-11  9:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-08 23:58 [PATCH bpf] libbpf: handle BTF parsing and loading properly Andrii Nakryiko
2019-03-09  6:10 ` Martin Lau
2019-03-09  7:30 ` Yonghong Song
2019-03-11  9:44 ` Daniel Borkmann

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.