Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1576049 > unrolled thread

[PATCH v3 2/5] bpf: Simplify bpf_load_program() error handling in the library

Started byMickaël Salaün <mic@digikod.net>
First post2017-02-07 22:00 +0100
Last post2017-02-08 21:20 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v3 2/5] bpf: Simplify bpf_load_program() error handling in the library Mickaël Salaün <mic@digikod.net> - 2017-02-07 22:00 +0100
    Re: [PATCH v3 2/5] bpf: Simplify bpf_load_program() error handling in  the library "Wangnan (F)" <wangnan0@huawei.com> - 2017-02-08 03:40 +0100
      Re: [PATCH v3 2/5] bpf: Simplify bpf_load_program() error handling in  the library Mickaël Salaün <mic@digikod.net> - 2017-02-08 21:20 +0100

#1576049 — [PATCH v3 2/5] bpf: Simplify bpf_load_program() error handling in the library

FromMickaël Salaün <mic@digikod.net>
Date2017-02-07 22:00 +0100
Subject[PATCH v3 2/5] bpf: Simplify bpf_load_program() error handling in the library
Message-ID<t8l1M-7If-3@gated-at.bofh.it>
Do not call a second time bpf(2) when a program load failed.

Signed-off-by: Mickaël Salaün <mic@digikod.net>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Wang Nan <wangnan0@huawei.com>
---
 tools/lib/bpf/bpf.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 3ddb58a36d3c..fda3f494f1cd 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -73,7 +73,6 @@ int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns,
 		     size_t insns_cnt, char *license,
 		     __u32 kern_version, char *log_buf, size_t log_buf_sz)
 {
-	int fd;
 	union bpf_attr attr;
 
 	bzero(&attr, sizeof(attr));
@@ -81,20 +80,15 @@ int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns,
 	attr.insn_cnt = (__u32)insns_cnt;
 	attr.insns = ptr_to_u64(insns);
 	attr.license = ptr_to_u64(license);
-	attr.log_buf = ptr_to_u64(NULL);
-	attr.log_size = 0;
-	attr.log_level = 0;
+	attr.log_buf = ptr_to_u64(log_buf);
+	attr.log_size = log_buf_sz;
 	attr.kern_version = kern_version;
 
-	fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
-	if (fd >= 0 || !log_buf || !log_buf_sz)
-		return fd;
+	if (log_buf && log_buf_sz > 0) {
+		attr.log_level = 1;
+		log_buf[0] = 0;
+	}
 
-	/* Try again with log */
-	attr.log_buf = ptr_to_u64(log_buf);
-	attr.log_size = log_buf_sz;
-	attr.log_level = 1;
-	log_buf[0] = 0;
 	return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
 }
 
-- 
2.11.0

[toc] | [next] | [standalone]


#1576240 — Re: [PATCH v3 2/5] bpf: Simplify bpf_load_program() error handling in the library

From"Wangnan (F)" <wangnan0@huawei.com>
Date2017-02-08 03:40 +0100
SubjectRe: [PATCH v3 2/5] bpf: Simplify bpf_load_program() error handling in the library
Message-ID<t8qkN-2EP-1@gated-at.bofh.it>
In reply to#1576049

On 2017/2/8 4:56, Mickaël Salaün wrote:
> Do not call a second time bpf(2) when a program load failed.

BPF_PROG_LOAD should success most of the time. Setting log_level to
0 by default and require log buffer when failure can make it faster
in normal case.

Thank you.

> Signed-off-by: Mickaël Salaün <mic@digikod.net>
> Cc: Alexei Starovoitov <ast@fb.com>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Wang Nan <wangnan0@huawei.com>
> ---
>   tools/lib/bpf/bpf.c | 18 ++++++------------
>   1 file changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index 3ddb58a36d3c..fda3f494f1cd 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -73,7 +73,6 @@ int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns,
>   		     size_t insns_cnt, char *license,
>   		     __u32 kern_version, char *log_buf, size_t log_buf_sz)
>   {
> -	int fd;
>   	union bpf_attr attr;
>   
>   	bzero(&attr, sizeof(attr));
> @@ -81,20 +80,15 @@ int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns,
>   	attr.insn_cnt = (__u32)insns_cnt;
>   	attr.insns = ptr_to_u64(insns);
>   	attr.license = ptr_to_u64(license);
> -	attr.log_buf = ptr_to_u64(NULL);
> -	attr.log_size = 0;
> -	attr.log_level = 0;
> +	attr.log_buf = ptr_to_u64(log_buf);
> +	attr.log_size = log_buf_sz;
>   	attr.kern_version = kern_version;
>   
> -	fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
> -	if (fd >= 0 || !log_buf || !log_buf_sz)
> -		return fd;
> +	if (log_buf && log_buf_sz > 0) {
> +		attr.log_level = 1;
> +		log_buf[0] = 0;
> +	}
>   
> -	/* Try again with log */
> -	attr.log_buf = ptr_to_u64(log_buf);
> -	attr.log_size = log_buf_sz;
> -	attr.log_level = 1;
> -	log_buf[0] = 0;
>   	return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
>   }
>   

[toc] | [prev] | [next] | [standalone]


#1577017 — Re: [PATCH v3 2/5] bpf: Simplify bpf_load_program() error handling in the library

FromMickaël Salaün <mic@digikod.net>
Date2017-02-08 21:20 +0100
SubjectRe: [PATCH v3 2/5] bpf: Simplify bpf_load_program() error handling in the library
Message-ID<t8GSB-4S1-9@gated-at.bofh.it>
In reply to#1576240

[Multipart message — attachments visible in raw view] — view raw

On 08/02/2017 03:35, Wangnan (F) wrote:
> 
> 
> On 2017/2/8 4:56, Mickaël Salaün wrote:
>> Do not call a second time bpf(2) when a program load failed.
> 
> BPF_PROG_LOAD should success most of the time. Setting log_level to
> 0 by default and require log buffer when failure can make it faster
> in normal case.

OK, I'm not sure if this is relevant for a test but I'm going to remove
this patch.

Thanks

> 
> Thank you.
> 
>> Signed-off-by: Mickaël Salaün <mic@digikod.net>
>> Cc: Alexei Starovoitov <ast@fb.com>
>> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
>> Cc: Daniel Borkmann <daniel@iogearbox.net>
>> Cc: Wang Nan <wangnan0@huawei.com>
>> ---
>>   tools/lib/bpf/bpf.c | 18 ++++++------------
>>   1 file changed, 6 insertions(+), 12 deletions(-)
>>
>> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
>> index 3ddb58a36d3c..fda3f494f1cd 100644
>> --- a/tools/lib/bpf/bpf.c
>> +++ b/tools/lib/bpf/bpf.c
>> @@ -73,7 +73,6 @@ int bpf_load_program(enum bpf_prog_type type, struct
>> bpf_insn *insns,
>>                size_t insns_cnt, char *license,
>>                __u32 kern_version, char *log_buf, size_t log_buf_sz)
>>   {
>> -    int fd;
>>       union bpf_attr attr;
>>         bzero(&attr, sizeof(attr));
>> @@ -81,20 +80,15 @@ int bpf_load_program(enum bpf_prog_type type,
>> struct bpf_insn *insns,
>>       attr.insn_cnt = (__u32)insns_cnt;
>>       attr.insns = ptr_to_u64(insns);
>>       attr.license = ptr_to_u64(license);
>> -    attr.log_buf = ptr_to_u64(NULL);
>> -    attr.log_size = 0;
>> -    attr.log_level = 0;
>> +    attr.log_buf = ptr_to_u64(log_buf);
>> +    attr.log_size = log_buf_sz;
>>       attr.kern_version = kern_version;
>>   -    fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
>> -    if (fd >= 0 || !log_buf || !log_buf_sz)
>> -        return fd;
>> +    if (log_buf && log_buf_sz > 0) {
>> +        attr.log_level = 1;
>> +        log_buf[0] = 0;
>> +    }
>>   -    /* Try again with log */
>> -    attr.log_buf = ptr_to_u64(log_buf);
>> -    attr.log_size = log_buf_sz;
>> -    attr.log_level = 1;
>> -    log_buf[0] = 0;
>>       return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
>>   }
>>   
> 
> 
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web