]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bpf: increase verifier verbosity when in verbose mode
authorShung-Hsi Yu <shung-hsi.yu@suse.com>
Fri, 27 Oct 2023 08:57:06 +0000 (16:57 +0800)
committerDavid Ahern <dsahern@kernel.org>
Fri, 27 Oct 2023 16:56:55 +0000 (16:56 +0000)
The BPF verifier allows setting a higher verbosity level, which is
helpful when it comes to debugging verifier issue, specially when used
on BPF program that loads successfully (but should not have passed the
verifier in the first place). Increase the BPF verifier log level when
in verbose mode to help with such cases.

Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
include/bpf_util.h
ip/ipvrf.c
lib/bpf_legacy.c
lib/bpf_libbpf.c

index 1c924f501f5f6ea638de2794b0e7397c244b88a7..8951a5e84558b050b3a142d47af15b64e99cda78 100644 (file)
@@ -273,10 +273,10 @@ void bpf_print_ops(struct rtattr *bpf_ops, __u16 len);
 
 int bpf_prog_load_dev(enum bpf_prog_type type, const struct bpf_insn *insns,
                      size_t size_insns, const char *license, __u32 ifindex,
-                     char *log, size_t size_log);
+                     char *log, size_t size_log, bool verbose);
 int bpf_program_load(enum bpf_prog_type type, const struct bpf_insn *insns,
                     size_t size_insns, const char *license, char *log,
-                    size_t size_log);
+                    size_t size_log, bool verbose);
 
 int bpf_prog_attach_fd(int prog_fd, int target_fd, enum bpf_attach_type type);
 int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type);
index 12beaec34d409f83e7e66ea25f8d0d8c792e19f3..e7c702abb9c268aa384d5619d8715bb34092ae90 100644 (file)
@@ -253,7 +253,8 @@ static int prog_load(int idx)
        };
 
        return bpf_program_load(BPF_PROG_TYPE_CGROUP_SOCK, prog, sizeof(prog),
-                               "GPL", bpf_log_buf, sizeof(bpf_log_buf));
+                               "GPL", bpf_log_buf, sizeof(bpf_log_buf),
+                               false);
 }
 
 static int vrf_configure_cgroup(const char *path, int ifindex)
index 3542b12fb8625486815e6d8c095dba67190ba922..844974e973d2ce272f638ce8a8ac4f66fe733dcf 100644 (file)
@@ -1098,7 +1098,7 @@ int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type)
 
 int bpf_prog_load_dev(enum bpf_prog_type type, const struct bpf_insn *insns,
                      size_t size_insns, const char *license, __u32 ifindex,
-                     char *log, size_t size_log)
+                     char *log, size_t size_log, bool verbose)
 {
        union bpf_attr attr = {};
 
@@ -1112,6 +1112,8 @@ int bpf_prog_load_dev(enum bpf_prog_type type, const struct bpf_insn *insns,
                attr.log_buf = bpf_ptr_to_u64(log);
                attr.log_size = size_log;
                attr.log_level = 1;
+               if (verbose)
+                       attr.log_level |= 2;
        }
 
        return bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
@@ -1119,9 +1121,9 @@ int bpf_prog_load_dev(enum bpf_prog_type type, const struct bpf_insn *insns,
 
 int bpf_program_load(enum bpf_prog_type type, const struct bpf_insn *insns,
                     size_t size_insns, const char *license, char *log,
-                    size_t size_log)
+                    size_t size_log, bool verbose)
 {
-       return bpf_prog_load_dev(type, insns, size_insns, license, 0, log, size_log);
+       return bpf_prog_load_dev(type, insns, size_insns, license, 0, log, size_log, verbose);
 }
 
 #ifdef HAVE_ELF
@@ -1543,7 +1545,7 @@ retry:
        errno = 0;
        fd = bpf_prog_load_dev(prog->type, prog->insns, prog->size,
                               prog->license, ctx->ifindex,
-                              ctx->log, ctx->log_size);
+                              ctx->log, ctx->log_size, 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
index 4a8a2032075c976c23f409beeba99eb5e2fd684a..08692d30a48f779b31dfcccf7077a62f8bc723b0 100644 (file)
@@ -289,6 +289,8 @@ static int load_bpf_object(struct bpf_cfg_in *cfg)
 
 #if (LIBBPF_MAJOR_VERSION > 0) || (LIBBPF_MINOR_VERSION >= 7)
        open_opts.kernel_log_level = 1;
+       if (cfg->verbose)
+               open_opts.kernel_log_level |= 2;
 #endif
 
        obj = bpf_object__open_file(cfg->object, &open_opts);