aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2019-02-01 19:14:15 -0500
committerAlexei Starovoitov <ast@kernel.org>2019-02-04 12:40:58 -0500
commit9d100a19ffa519b17a0e998918337da5386e47fb (patch)
tree33ba27812e8abc05913c8f57b654e30f1e1e1cd6 /tools/lib/bpf
parent8461ef8b7ef286212ca954d8b82dac3ceecb219d (diff)
tools/bpf: print out btf log at LIBBPF_WARN level
Currently, the btf log is allocated and printed out in case of error at LIBBPF_DEBUG level. Such logs from kernel are very important for debugging. For example, bpf syscall BPF_PROG_LOAD command can get verifier logs back to user space. In function load_program() of libbpf.c, the log buffer is allocated unconditionally and printed out at pr_warning() level. Let us do the similar thing here for btf. Allocate buffer unconditionally and print out error logs at pr_warning() level. This can reduce one global function and optimize for common situations where pr_warning() is activated either by default or by user supplied debug output function. Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r--tools/lib/bpf/btf.c19
-rw-r--r--tools/lib/bpf/libbpf.c10
-rw-r--r--tools/lib/bpf/libbpf_util.h2
3 files changed, 9 insertions, 22 deletions
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 93e792b82242..51a0db05bf80 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -377,16 +377,15 @@ struct btf *btf__new(__u8 *data, __u32 size)
377 377
378 btf->fd = -1; 378 btf->fd = -1;
379 379
380 if (libbpf_print_level_available(LIBBPF_DEBUG)) { 380 log_buf = malloc(BPF_LOG_BUF_SIZE);
381 log_buf = malloc(BPF_LOG_BUF_SIZE); 381 if (!log_buf) {
382 if (!log_buf) { 382 err = -ENOMEM;
383 err = -ENOMEM; 383 goto done;
384 goto done;
385 }
386 *log_buf = 0;
387 log_buf_size = BPF_LOG_BUF_SIZE;
388 } 384 }
389 385
386 *log_buf = 0;
387 log_buf_size = BPF_LOG_BUF_SIZE;
388
390 btf->data = malloc(size); 389 btf->data = malloc(size);
391 if (!btf->data) { 390 if (!btf->data) {
392 err = -ENOMEM; 391 err = -ENOMEM;
@@ -401,9 +400,9 @@ struct btf *btf__new(__u8 *data, __u32 size)
401 400
402 if (btf->fd == -1) { 401 if (btf->fd == -1) {
403 err = -errno; 402 err = -errno;
404 pr_debug("Error loading BTF: %s(%d)\n", strerror(errno), errno); 403 pr_warning("Error loading BTF: %s(%d)\n", strerror(errno), errno);
405 if (log_buf && *log_buf) 404 if (log_buf && *log_buf)
406 pr_debug("%s\n", log_buf); 405 pr_warning("%s\n", log_buf);
407 goto done; 406 goto done;
408 } 407 }
409 408
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index eeba77b695ad..0354af03b038 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -98,16 +98,6 @@ void libbpf_print(enum libbpf_print_level level, const char *format, ...)
98 va_end(args); 98 va_end(args);
99} 99}
100 100
101bool libbpf_print_level_available(enum libbpf_print_level level)
102{
103 if (level == LIBBPF_WARN)
104 return !!__pr_warning;
105 else if (level == LIBBPF_INFO)
106 return !!__pr_info;
107 else
108 return !!__pr_debug;
109}
110
111#define STRERR_BUFSIZE 128 101#define STRERR_BUFSIZE 128
112 102
113#define CHECK_ERR(action, err, out) do { \ 103#define CHECK_ERR(action, err, out) do { \
diff --git a/tools/lib/bpf/libbpf_util.h b/tools/lib/bpf/libbpf_util.h
index 0fdc3b1d0e33..81ecda0cb9c9 100644
--- a/tools/lib/bpf/libbpf_util.h
+++ b/tools/lib/bpf/libbpf_util.h
@@ -14,8 +14,6 @@ extern void libbpf_print(enum libbpf_print_level level,
14 const char *format, ...) 14 const char *format, ...)
15 __attribute__((format(printf, 2, 3))); 15 __attribute__((format(printf, 2, 3)));
16 16
17extern bool libbpf_print_level_available(enum libbpf_print_level level);
18
19#define __pr(level, fmt, ...) \ 17#define __pr(level, fmt, ...) \
20do { \ 18do { \
21 libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__); \ 19 libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__); \