Skip to content

Commit 705fa21

Browse files
WangNan0acmel
authored andcommitted
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 <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Zefan Li <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 5f44e4c commit 705fa21

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ static const char *libbpf_strerror_table[NR_ERRNO] = {
9090
[ERRCODE_OFFSET(VERIFY)] = "Kernel verifier blocks program loading",
9191
[ERRCODE_OFFSET(PROG2BIG)] = "Program too big",
9292
[ERRCODE_OFFSET(KVER)] = "Incorrect kernel version",
93+
[ERRCODE_OFFSET(PROGTYPE)] = "Kernel doesn't support this program type",
9394
};
9495

9596
int libbpf_strerror(int err, char *buf, size_t size)
@@ -926,15 +927,27 @@ load_program(enum bpf_prog_type type, struct bpf_insn *insns,
926927
pr_warning("-- BEGIN DUMP LOG ---\n");
927928
pr_warning("\n%s\n", log_buf);
928929
pr_warning("-- END LOG --\n");
930+
} else if (insns_cnt >= BPF_MAXINSNS) {
931+
pr_warning("Program too large (%d insns), at most %d insns\n",
932+
insns_cnt, BPF_MAXINSNS);
933+
ret = -LIBBPF_ERRNO__PROG2BIG;
929934
} else {
930-
if (insns_cnt >= BPF_MAXINSNS) {
931-
pr_warning("Program too large (%d insns), at most %d insns\n",
932-
insns_cnt, BPF_MAXINSNS);
933-
ret = -LIBBPF_ERRNO__PROG2BIG;
934-
} else if (log_buf) {
935-
pr_warning("log buffer is empty\n");
936-
ret = -LIBBPF_ERRNO__KVER;
935+
/* Wrong program type? */
936+
if (type != BPF_PROG_TYPE_KPROBE) {
937+
int fd;
938+
939+
fd = bpf_load_program(BPF_PROG_TYPE_KPROBE, insns,
940+
insns_cnt, license, kern_version,
941+
NULL, 0);
942+
if (fd >= 0) {
943+
close(fd);
944+
ret = -LIBBPF_ERRNO__PROGTYPE;
945+
goto out;
946+
}
937947
}
948+
949+
if (log_buf)
950+
ret = -LIBBPF_ERRNO__KVER;
938951
}
939952

940953
out:

tools/lib/bpf/libbpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum libbpf_errno {
3939
LIBBPF_ERRNO__VERIFY, /* Kernel verifier blocks program loading */
4040
LIBBPF_ERRNO__PROG2BIG, /* Program too big */
4141
LIBBPF_ERRNO__KVER, /* Incorrect kernel version */
42+
LIBBPF_ERRNO__PROGTYPE, /* Kernel doesn't support this program type */
4243
__LIBBPF_ERRNO__END,
4344
};
4445

0 commit comments

Comments
 (0)