[PATCH] lib/bpf: Fix btf_load error lead to enable debug log

Subsystems: library code, the rest

STALE1857d

3 messages, 2 authors, 2021-08-01 · open the first message on its own page

[PATCH] lib/bpf: Fix btf_load error lead to enable debug log

From: Feng zhou <hidden>
Date: 2021-07-29 04:55:29

From: Feng Zhou <redacted>

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 <redacted>
---
 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

Re: [PATCH] lib/bpf: Fix btf_load error lead to enable debug log

From: Andrii Nakryiko <hidden>
Date: 2021-07-30 18:40:43

On Wed, Jul 28, 2021 at 9:55 PM Feng zhou [off-list ref] wrote:
From: Feng Zhou <redacted>

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 <redacted>
---
This seems to be targeted against iproute2? It would be good to
specify that as [PATCH iproute2] or something.

quoted hunk
 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

Re: [External] Re: [PATCH] lib/bpf: Fix btf_load error lead to enable debug log

From: zhoufeng <hidden>
Date: 2021-08-01 05:59:26


在 2021/7/31 上午2:40, Andrii Nakryiko 写道:
On Wed, Jul 28, 2021 at 9:55 PM Feng zhou [off-list ref] wrote:
quoted
From: Feng Zhou <redacted>

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 <redacted>
---
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.

quoted
  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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help