Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools lib bpf: Report error when kernel doesn't support program type

Now libbpf support tracepoint program type. Report meaningful error when kernel
version is less than 4.7.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1468406646-21642-3-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Wang Nan and committed by
Arnaldo Carvalho de Melo
705fa219 5f44e4c8

+21 -7
+20 -7
tools/lib/bpf/libbpf.c
··· 90 90 [ERRCODE_OFFSET(VERIFY)] = "Kernel verifier blocks program loading", 91 91 [ERRCODE_OFFSET(PROG2BIG)] = "Program too big", 92 92 [ERRCODE_OFFSET(KVER)] = "Incorrect kernel version", 93 + [ERRCODE_OFFSET(PROGTYPE)] = "Kernel doesn't support this program type", 93 94 }; 94 95 95 96 int libbpf_strerror(int err, char *buf, size_t size) ··· 927 926 pr_warning("-- BEGIN DUMP LOG ---\n"); 928 927 pr_warning("\n%s\n", log_buf); 929 928 pr_warning("-- END LOG --\n"); 929 + } else if (insns_cnt >= BPF_MAXINSNS) { 930 + pr_warning("Program too large (%d insns), at most %d insns\n", 931 + insns_cnt, BPF_MAXINSNS); 932 + ret = -LIBBPF_ERRNO__PROG2BIG; 930 933 } else { 931 - if (insns_cnt >= BPF_MAXINSNS) { 932 - pr_warning("Program too large (%d insns), at most %d insns\n", 933 - insns_cnt, BPF_MAXINSNS); 934 - ret = -LIBBPF_ERRNO__PROG2BIG; 935 - } else if (log_buf) { 936 - pr_warning("log buffer is empty\n"); 937 - ret = -LIBBPF_ERRNO__KVER; 934 + /* Wrong program type? */ 935 + if (type != BPF_PROG_TYPE_KPROBE) { 936 + int fd; 937 + 938 + fd = bpf_load_program(BPF_PROG_TYPE_KPROBE, insns, 939 + insns_cnt, license, kern_version, 940 + NULL, 0); 941 + if (fd >= 0) { 942 + close(fd); 943 + ret = -LIBBPF_ERRNO__PROGTYPE; 944 + goto out; 945 + } 938 946 } 947 + 948 + if (log_buf) 949 + ret = -LIBBPF_ERRNO__KVER; 939 950 } 940 951 941 952 out:
+1
tools/lib/bpf/libbpf.h
··· 39 39 LIBBPF_ERRNO__VERIFY, /* Kernel verifier blocks program loading */ 40 40 LIBBPF_ERRNO__PROG2BIG, /* Program too big */ 41 41 LIBBPF_ERRNO__KVER, /* Incorrect kernel version */ 42 + LIBBPF_ERRNO__PROGTYPE, /* Kernel doesn't support this program type */ 42 43 __LIBBPF_ERRNO__END, 43 44 }; 44 45