Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] lib/bpf: Fix btf_load error lead to enable debug log
@ 2021-07-29  4:55 Feng zhou
  2021-07-30 18:40 ` Andrii Nakryiko
  0 siblings, 1 reply; 5+ messages in thread
From: Feng zhou @ 2021-07-29  4:55 UTC (permalink / raw)
  To: netdev
  Cc: stephen, kuznet, duanxiongchun, wangdongdong.6,
	chenzhuowen.simon, zhoufeng.zf

From: Feng Zhou <zhoufeng.zf@bytedance.com>

Use tc with no verbose, when bpf_btf_attach fail,
the conditions:
"if (fd < 0 && (errno == ENOSPC || !ctx->log_size))"
will make ctx->log_size != 0. And then, bpf_prog_attach,
ctx->log_size != 0. so enable debug log.
The verifier log sometimes is so chatty on larger programs.
bpf_prog_attach is failed.
"Log buffer too small to dump verifier log 16777215 bytes (9 tries)!"

BTF load failure does not affect prog load. prog still work.
So when BTF/PROG load fail, enlarge log_size and re-fail with
having verbose.

Signed-off-by: Feng Zhou <zhoufeng.zf@bytedance.com>
---
 lib/bpf_legacy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
index 8a03b9c2..d824388c 100644
--- a/lib/bpf_legacy.c
+++ b/lib/bpf_legacy.c
@@ -1531,7 +1531,7 @@ retry:
 		 * into our buffer. Still, try to give a debuggable error
 		 * log for the user, so enlarge it and re-fail.
 		 */
-		if (fd < 0 && (errno == ENOSPC || !ctx->log_size)) {
+		if (fd < 0 && errno == ENOSPC) {
 			if (tries++ < 10 && !bpf_log_realloc(ctx))
 				goto retry;
 
@@ -2069,7 +2069,7 @@ retry:
 	fd = bpf_btf_load(ctx->btf_data->d_buf, ctx->btf_data->d_size,
 			  ctx->log, ctx->log_size);
 	if (fd < 0 || ctx->verbose) {
-		if (fd < 0 && (errno == ENOSPC || !ctx->log_size)) {
+		if (fd < 0 && errno == ENOSPC) {
 			if (tries++ < 10 && !bpf_log_realloc(ctx))
 				goto retry;
 
-- 
2.11.0


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

* Re: [PATCH] lib/bpf: Fix btf_load error lead to enable debug log
  2021-07-29  4:55 [PATCH] lib/bpf: Fix btf_load error lead to enable debug log Feng zhou
@ 2021-07-30 18:40 ` Andrii Nakryiko
  2021-08-01  5:59   ` [External] " zhoufeng
  0 siblings, 1 reply; 5+ messages in thread
From: Andrii Nakryiko @ 2021-07-30 18:40 UTC (permalink / raw)
  To: Feng zhou
  Cc: Networking, Stephen Hemminger, kuznet, duanxiongchun,
	Dongdong Wang, chenzhuowen.simon

On Wed, Jul 28, 2021 at 9:55 PM Feng zhou <zhoufeng.zf@bytedance.com> wrote:
>
> From: Feng Zhou <zhoufeng.zf@bytedance.com>
>
> Use tc with no verbose, when bpf_btf_attach fail,
> the conditions:
> "if (fd < 0 && (errno == ENOSPC || !ctx->log_size))"
> will make ctx->log_size != 0. And then, bpf_prog_attach,
> ctx->log_size != 0. so enable debug log.
> The verifier log sometimes is so chatty on larger programs.
> bpf_prog_attach is failed.
> "Log buffer too small to dump verifier log 16777215 bytes (9 tries)!"
>
> BTF load failure does not affect prog load. prog still work.
> So when BTF/PROG load fail, enlarge log_size and re-fail with
> having verbose.
>
> Signed-off-by: Feng Zhou <zhoufeng.zf@bytedance.com>
> ---

This seems to be targeted against iproute2? It would be good to
specify that as [PATCH iproute2] or something.


>  lib/bpf_legacy.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
> index 8a03b9c2..d824388c 100644
> --- a/lib/bpf_legacy.c
> +++ b/lib/bpf_legacy.c
> @@ -1531,7 +1531,7 @@ retry:
>                  * into our buffer. Still, try to give a debuggable error
>                  * log for the user, so enlarge it and re-fail.
>                  */
> -               if (fd < 0 && (errno == ENOSPC || !ctx->log_size)) {
> +               if (fd < 0 && errno == ENOSPC) {
>                         if (tries++ < 10 && !bpf_log_realloc(ctx))
>                                 goto retry;
>
> @@ -2069,7 +2069,7 @@ retry:
>         fd = bpf_btf_load(ctx->btf_data->d_buf, ctx->btf_data->d_size,
>                           ctx->log, ctx->log_size);
>         if (fd < 0 || ctx->verbose) {
> -               if (fd < 0 && (errno == ENOSPC || !ctx->log_size)) {
> +               if (fd < 0 && errno == ENOSPC) {
>                         if (tries++ < 10 && !bpf_log_realloc(ctx))
>                                 goto retry;
>
> --
> 2.11.0
>

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

* Re: [External] Re: [PATCH] lib/bpf: Fix btf_load error lead to enable debug log
  2021-07-30 18:40 ` Andrii Nakryiko
@ 2021-08-01  5:59   ` zhoufeng
  0 siblings, 0 replies; 5+ messages in thread
From: zhoufeng @ 2021-08-01  5:59 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Networking, Stephen Hemminger, kuznet, duanxiongchun,
	Dongdong Wang, chenzhuowen.simon, cong.wang



在 2021/7/31 上午2:40, Andrii Nakryiko 写道:
> On Wed, Jul 28, 2021 at 9:55 PM Feng zhou <zhoufeng.zf@bytedance.com> wrote:
>>
>> From: Feng Zhou <zhoufeng.zf@bytedance.com>
>>
>> Use tc with no verbose, when bpf_btf_attach fail,
>> the conditions:
>> "if (fd < 0 && (errno == ENOSPC || !ctx->log_size))"
>> will make ctx->log_size != 0. And then, bpf_prog_attach,
>> ctx->log_size != 0. so enable debug log.
>> The verifier log sometimes is so chatty on larger programs.
>> bpf_prog_attach is failed.
>> "Log buffer too small to dump verifier log 16777215 bytes (9 tries)!"
>>
>> BTF load failure does not affect prog load. prog still work.
>> So when BTF/PROG load fail, enlarge log_size and re-fail with
>> having verbose.
>>
>> Signed-off-by: Feng Zhou <zhoufeng.zf@bytedance.com>
>> ---
> 
> This seems to be targeted against iproute2? It would be good to
> specify that as [PATCH iproute2] or something.
> 
> 

Yeah, it's a good idea. I will resend it.


>>   lib/bpf_legacy.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
>> index 8a03b9c2..d824388c 100644
>> --- a/lib/bpf_legacy.c
>> +++ b/lib/bpf_legacy.c
>> @@ -1531,7 +1531,7 @@ retry:
>>                   * into our buffer. Still, try to give a debuggable error
>>                   * log for the user, so enlarge it and re-fail.
>>                   */
>> -               if (fd < 0 && (errno == ENOSPC || !ctx->log_size)) {
>> +               if (fd < 0 && errno == ENOSPC) {
>>                          if (tries++ < 10 && !bpf_log_realloc(ctx))
>>                                  goto retry;
>>
>> @@ -2069,7 +2069,7 @@ retry:
>>          fd = bpf_btf_load(ctx->btf_data->d_buf, ctx->btf_data->d_size,
>>                            ctx->log, ctx->log_size);
>>          if (fd < 0 || ctx->verbose) {
>> -               if (fd < 0 && (errno == ENOSPC || !ctx->log_size)) {
>> +               if (fd < 0 && errno == ENOSPC) {
>>                          if (tries++ < 10 && !bpf_log_realloc(ctx))
>>                                  goto retry;
>>
>> --
>> 2.11.0
>>

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

* Re: [PATCH] lib/bpf: Fix btf_load error lead to enable debug log
  2021-07-28  9:33 Feng zhou
@ 2021-07-29  4:02 ` zhoufeng
  0 siblings, 0 replies; 5+ messages in thread
From: zhoufeng @ 2021-07-29  4:02 UTC (permalink / raw)
  To: netdev; +Cc: stephen, kuznet, duanxiongchun, wangdongdong.6, chenzhuowen.simon



在 2021/7/28 下午5:33, Feng zhou 写道:
> From: Feng Zhou <zhoufeng.zf@bytedance.com>
> 
> Use tc with no verbose, when bpf_btf_attach fail,
> the conditions:
> "if (fd < 0 && (errno == ENOSPC || !ctx->log_size))"
> will make ctx->log_size != 0. And then, bpf_prog_attach,
> ctx->log_size != 0. so enable debug log.
> The verifier log sometimes is so chatty on larger programs.
> bpf_prog_attach is failed.
> "Log buffer too small to dump verifier log 16777215 bytes (9 tries)!"
> 
> BTF load failure does not affect prog load. prog still work.
> So when BTF/PROG load fail, enlarge log_size and re-fail with
> having verbose.
> 
> Signed-off-by: Feng Zhou <zhoufeng.zf@bytedance.com>
> ---
>   lib/bpf_legacy.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
> index 8a03b9c2..80c49f08 100644
> --- a/lib/bpf_legacy.c
> +++ b/lib/bpf_legacy.c
> @@ -1525,13 +1525,13 @@ retry:
>   	fd = bpf_prog_load_dev(prog->type, prog->insns, prog->size,
>   			       prog->license, ctx->ifindex,
>   			       ctx->log, ctx->log_size);
> -	if (fd < 0 || ctx->verbose) {
> +	if (fd < 0 && ctx->verbose) {
>   		/* The verifier log is pretty chatty, sometimes so chatty
>   		 * on larger programs, that we could fail to dump everything
>   		 * into our buffer. Still, try to give a debuggable error
>   		 * log for the user, so enlarge it and re-fail.
>   		 */
> -		if (fd < 0 && (errno == ENOSPC || !ctx->log_size)) {
> +		if (errno == ENOSPC) {
>   			if (tries++ < 10 && !bpf_log_realloc(ctx))
>   				goto retry;
>   
> @@ -2068,8 +2068,8 @@ retry:
>   	errno = 0;
>   	fd = bpf_btf_load(ctx->btf_data->d_buf, ctx->btf_data->d_size,
>   			  ctx->log, ctx->log_size);
> -	if (fd < 0 || ctx->verbose) {
> -		if (fd < 0 && (errno == ENOSPC || !ctx->log_size)) {
> +	if (fd < 0 && ctx->verbose) {
> +		if (errno == ENOSPC) {
>   			if (tries++ < 10 && !bpf_log_realloc(ctx))
>   				goto retry;
>   
> 

Sorry, this patch is wrong. please ignore it. I will send a new one.

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

* [PATCH] lib/bpf: Fix btf_load error lead to enable debug log
@ 2021-07-28  9:33 Feng zhou
  2021-07-29  4:02 ` zhoufeng
  0 siblings, 1 reply; 5+ messages in thread
From: Feng zhou @ 2021-07-28  9:33 UTC (permalink / raw)
  To: netdev
  Cc: stephen, kuznet, duanxiongchun, wangdongdong.6,
	chenzhuowen.simon, zhoufeng.zf

From: Feng Zhou <zhoufeng.zf@bytedance.com>

Use tc with no verbose, when bpf_btf_attach fail,
the conditions:
"if (fd < 0 && (errno == ENOSPC || !ctx->log_size))"
will make ctx->log_size != 0. And then, bpf_prog_attach,
ctx->log_size != 0. so enable debug log.
The verifier log sometimes is so chatty on larger programs.
bpf_prog_attach is failed.
"Log buffer too small to dump verifier log 16777215 bytes (9 tries)!"

BTF load failure does not affect prog load. prog still work.
So when BTF/PROG load fail, enlarge log_size and re-fail with
having verbose.

Signed-off-by: Feng Zhou <zhoufeng.zf@bytedance.com>
---
 lib/bpf_legacy.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
index 8a03b9c2..80c49f08 100644
--- a/lib/bpf_legacy.c
+++ b/lib/bpf_legacy.c
@@ -1525,13 +1525,13 @@ retry:
 	fd = bpf_prog_load_dev(prog->type, prog->insns, prog->size,
 			       prog->license, ctx->ifindex,
 			       ctx->log, ctx->log_size);
-	if (fd < 0 || ctx->verbose) {
+	if (fd < 0 && ctx->verbose) {
 		/* The verifier log is pretty chatty, sometimes so chatty
 		 * on larger programs, that we could fail to dump everything
 		 * into our buffer. Still, try to give a debuggable error
 		 * log for the user, so enlarge it and re-fail.
 		 */
-		if (fd < 0 && (errno == ENOSPC || !ctx->log_size)) {
+		if (errno == ENOSPC) {
 			if (tries++ < 10 && !bpf_log_realloc(ctx))
 				goto retry;
 
@@ -2068,8 +2068,8 @@ retry:
 	errno = 0;
 	fd = bpf_btf_load(ctx->btf_data->d_buf, ctx->btf_data->d_size,
 			  ctx->log, ctx->log_size);
-	if (fd < 0 || ctx->verbose) {
-		if (fd < 0 && (errno == ENOSPC || !ctx->log_size)) {
+	if (fd < 0 && ctx->verbose) {
+		if (errno == ENOSPC) {
 			if (tries++ < 10 && !bpf_log_realloc(ctx))
 				goto retry;
 
-- 
2.11.0


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

end of thread, other threads:[~2021-08-01  5:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29  4:55 [PATCH] lib/bpf: Fix btf_load error lead to enable debug log Feng zhou
2021-07-30 18:40 ` Andrii Nakryiko
2021-08-01  5:59   ` [External] " zhoufeng
  -- strict thread matches above, loose matches on Subject: below --
2021-07-28  9:33 Feng zhou
2021-07-29  4:02 ` zhoufeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).