From patchwork Thu Jul 14 02:20:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 71980 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1297900qga; Wed, 13 Jul 2016 19:23:32 -0700 (PDT) X-Received: by 10.98.98.193 with SMTP id w184mr8723875pfb.162.1468463012419; Wed, 13 Jul 2016 19:23:32 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l88si3521691pfj.272.2016.07.13.19.23.32; Wed, 13 Jul 2016 19:23:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751211AbcGNCXa (ORCPT + 30 others); Wed, 13 Jul 2016 22:23:30 -0400 Received: from merlin.infradead.org ([205.233.59.134]:45502 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751164AbcGNCVT (ORCPT ); Wed, 13 Jul 2016 22:21:19 -0400 Received: from [179.235.155.208] (helo=jouet.infradead.org) by merlin.infradead.org with esmtpsa (Exim 4.85_2 #1 (Red Hat Linux)) id 1bNWGr-0006aL-4d; Thu, 14 Jul 2016 02:21:01 +0000 Received: by jouet.infradead.org (Postfix, from userid 1000) id 6F5AC143C39; Wed, 13 Jul 2016 23:20:57 -0300 (BRT) From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Wang Nan , Alexei Starovoitov , Jiri Olsa , Zefan Li , pi3orama@163.com, Arnaldo Carvalho de Melo Subject: [PATCH 05/19] tools lib bpf: Report error when kernel doesn't support program type Date: Wed, 13 Jul 2016 23:20:41 -0300 Message-Id: <1468462855-30196-6-git-send-email-acme@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468462855-30196-1-git-send-email-acme@kernel.org> References: <1468462855-30196-1-git-send-email-acme@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by merlin.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wang Nan Now libbpf support tracepoint program type. Report meaningful error when kernel version is less than 4.7. Signed-off-by: Wang Nan Cc: Alexei Starovoitov Cc: Jiri Olsa Cc: Zefan Li 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 --- tools/lib/bpf/libbpf.c | 27 ++++++++++++++++++++------- tools/lib/bpf/libbpf.h | 1 + 2 files changed, 21 insertions(+), 7 deletions(-) -- 2.7.4 diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 4751936831d7..32e6b6bc6f7d 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -90,6 +90,7 @@ static const char *libbpf_strerror_table[NR_ERRNO] = { [ERRCODE_OFFSET(VERIFY)] = "Kernel verifier blocks program loading", [ERRCODE_OFFSET(PROG2BIG)] = "Program too big", [ERRCODE_OFFSET(KVER)] = "Incorrect kernel version", + [ERRCODE_OFFSET(PROGTYPE)] = "Kernel doesn't support this program type", }; 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, pr_warning("-- BEGIN DUMP LOG ---\n"); pr_warning("\n%s\n", log_buf); pr_warning("-- END LOG --\n"); + } else if (insns_cnt >= BPF_MAXINSNS) { + pr_warning("Program too large (%d insns), at most %d insns\n", + insns_cnt, BPF_MAXINSNS); + ret = -LIBBPF_ERRNO__PROG2BIG; } else { - if (insns_cnt >= BPF_MAXINSNS) { - pr_warning("Program too large (%d insns), at most %d insns\n", - insns_cnt, BPF_MAXINSNS); - ret = -LIBBPF_ERRNO__PROG2BIG; - } else if (log_buf) { - pr_warning("log buffer is empty\n"); - ret = -LIBBPF_ERRNO__KVER; + /* Wrong program type? */ + if (type != BPF_PROG_TYPE_KPROBE) { + int fd; + + fd = bpf_load_program(BPF_PROG_TYPE_KPROBE, insns, + insns_cnt, license, kern_version, + NULL, 0); + if (fd >= 0) { + close(fd); + ret = -LIBBPF_ERRNO__PROGTYPE; + goto out; + } } + + if (log_buf) + ret = -LIBBPF_ERRNO__KVER; } out: diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index eb2a4c45f6b6..dd7a513efb10 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -39,6 +39,7 @@ enum libbpf_errno { LIBBPF_ERRNO__VERIFY, /* Kernel verifier blocks program loading */ LIBBPF_ERRNO__PROG2BIG, /* Program too big */ LIBBPF_ERRNO__KVER, /* Incorrect kernel version */ + LIBBPF_ERRNO__PROGTYPE, /* Kernel doesn't support this program type */ __LIBBPF_ERRNO__END, };