From patchwork Wed Apr 20 18:01:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 66242 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2596185qge; Wed, 20 Apr 2016 11:04:41 -0700 (PDT) X-Received: by 10.66.25.133 with SMTP id c5mr13225471pag.104.1461175481703; Wed, 20 Apr 2016 11:04:41 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 190si19009360pfv.7.2016.04.20.11.04.41; Wed, 20 Apr 2016 11:04:41 -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 S1752570AbcDTSEh (ORCPT + 29 others); Wed, 20 Apr 2016 14:04:37 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:26314 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752291AbcDTSCf (ORCPT ); Wed, 20 Apr 2016 14:02:35 -0400 Received: from 172.24.1.137 (EHLO szxeml430-hub.china.huawei.com) ([172.24.1.137]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CAG94108; Thu, 21 Apr 2016 02:02:12 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.235.1; Thu, 21 Apr 2016 02:02:05 +0800 From: Wang Nan To: , , CC: , , Wang Nan , Arnaldo Carvalho de Melo , "Alexei Starovoitov" , Jiri Olsa , Li Zefan Subject: [RFC PATCH 08/13] bpf tools: Add API for fetching ubpf_vm Date: Wed, 20 Apr 2016 18:01:48 +0000 Message-ID: <1461175313-38310-9-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1461175313-38310-1-git-send-email-wangnan0@huawei.com> References: <1461175313-38310-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090204.5717C424.0153, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: af39bbc98dafba7a30e0c840971d238e Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce bpf_program__vm and bpf_program__nth_vm for fetching ubpf program instance. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Jiri Olsa Cc: Li Zefan --- tools/lib/bpf/libbpf.c | 38 ++++++++++++++++++++++++++++++++++++++ tools/lib/bpf/libbpf.h | 2 ++ 2 files changed, 40 insertions(+) -- 1.8.3.4 diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index e4a1e77..4045a7e 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1375,6 +1375,11 @@ int bpf_program__fd(struct bpf_program *prog) return bpf_program__nth_fd(prog, 0); } +struct ubpf_vm *bpf_program__vm(struct bpf_program *prog) +{ + return bpf_program__nth_vm(prog, 0); +} + int bpf_program__set_prep(struct bpf_program *prog, int nr_instances, bpf_program_prep_t prep) { @@ -1429,6 +1434,32 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n) } #ifdef HAVE_UBPF_SUPPORT +struct ubpf_vm *bpf_program__nth_vm(struct bpf_program *prog, int n) +{ + struct ubpf_vm *vm; + + if (prog->engine != ENGINE_UBPF) { + pr_warning("Can't get ubpf_vm from program %s: engine not UBPF or not loaded\n", + prog->section_name); + return ERR_PTR(-EINVAL); + } + + if (n >= prog->instances.nr || n < 0) { + pr_warning("Can't get the %dth vm from program %s: only %d instances\n", + n, prog->section_name, prog->instances.nr); + return ERR_PTR(-EINVAL); + } + + vm = prog->instances.array[n].vm; + if (!vm) { + pr_warning("%dth instance of program '%s' is invalid\n", + n, prog->section_name); + return ERR_PTR(-ENOENT); + } + + return vm; +} + int bpf_program__set_ubpf(struct bpf_program *prog) { if (prog->engine != ENGINE_UNKNOWN) { @@ -1454,6 +1485,13 @@ bool bpf_program__is_ubpf(struct bpf_program *prog __maybe_unused) { return false; } + +struct ubpf_vm * +bpf_program__nth_vm(struct bpf_program *prog __maybe_unused, + int n __maybe_unused) +{ + return ERR_PTR(-LIBBPF_ERRNO__NOUBPF); +} #endif int bpf_map__get_fd(struct bpf_map *map) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 8e69c6f..41c35fd 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -92,6 +92,7 @@ int bpf_program__set_ubpf(struct bpf_program *prog); bool bpf_program__is_ubpf(struct bpf_program *prog); int bpf_program__fd(struct bpf_program *prog); +struct ubpf_vm *bpf_program__vm(struct bpf_program *prog); struct bpf_insn; @@ -162,6 +163,7 @@ int bpf_program__set_prep(struct bpf_program *prog, int nr_instance, bpf_program_prep_t prep); int bpf_program__nth_fd(struct bpf_program *prog, int n); +struct ubpf_vm *bpf_program__nth_vm(struct bpf_program *prog, int n); /* * We don't need __attribute__((packed)) now since it is