Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1383612 > unrolled thread
| Started by | Wang Nan <wangnan0@huawei.com> |
|---|---|
| First post | 2016-04-20 20:10 +0200 |
| Last post | 2016-04-20 21:40 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[RFC PATCH 05/13] bpf tools: Save engine type in bpf_program Wang Nan <wangnan0@huawei.com> - 2016-04-20 20:10 +0200
Re: [RFC PATCH 05/13] bpf tools: Save engine type in bpf_program Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-20 21:30 +0200
Re: [RFC PATCH 05/13] bpf tools: Save engine type in bpf_program pi3orama <pi3orama@163.com> - 2016-04-20 21:40 +0200
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-04-20 20:10 +0200 |
| Subject | [RFC PATCH 05/13] bpf tools: Save engine type in bpf_program |
| Message-ID | <rq4JC-3Ai-41@gated-at.bofh.it> |
Add an 'engine' field in bpf_program to indicate whether a program is a
ubpf program or kernel bpf program. For compatibility, the default
engine is kernel bpf, unless explicitly set to ubpf using
bpf_program__set_ubpf().
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
---
tools/lib/bpf/libbpf.c | 40 ++++++++++++++++++++++++++++++++++++++++
tools/lib/bpf/libbpf.h | 4 ++++
2 files changed, 44 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index dd5a107..3755846 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -80,6 +80,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(NOUBPF)] = "UBPF support is not compiled",
};
int libbpf_strerror(int err, char *buf, size_t size)
@@ -147,6 +148,11 @@ union prog_instance {
* linux/filter.h.
*/
struct bpf_program {
+ enum {
+ ENGINE_UNKNOWN,
+ ENGINE_KBPF,
+ ENGINE_UBPF,
+ } engine;
/* Index in elf obj file, for relocation use. */
int idx;
char *section_name;
@@ -291,6 +297,7 @@ bpf_program__init(void *data, size_t size, char *name, int idx,
memcpy(prog->insns, data,
prog->insns_cnt * sizeof(struct bpf_insn));
prog->idx = idx;
+ prog->engine = ENGINE_UNKNOWN;
prog->instances.array = NULL;
prog->instances.nr = -1;
@@ -941,6 +948,11 @@ bpf_program__load(struct bpf_program *prog,
{
int err = 0, fd, i;
+ if (prog->engine == ENGINE_UNKNOWN)
+ prog->engine = ENGINE_KBPF;
+ if (prog->engine != ENGINE_KBPF)
+ return -EINVAL;
+
if (prog->instances.nr < 0 || !prog->instances.array) {
if (prog->preprocessor) {
pr_warning("Internal error: can't load program '%s'\n",
@@ -1318,6 +1330,34 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n)
return fd;
}
+#ifdef HAVE_UBPF_SUPPORT
+int bpf_program__set_ubpf(struct bpf_program *prog)
+{
+ if (prog->engine != ENGINE_UNKNOWN) {
+ pr_warning("Can't set program %s to ubpf\n",
+ prog->section_name);
+ return -EINVAL;
+ }
+ prog->engine = ENGINE_UBPF;
+ return 0;
+}
+
+bool bpf_program__is_ubpf(struct bpf_program *prog)
+{
+ return prog->engine == ENGINE_UBPF;
+}
+#else
+int bpf_program__set_ubpf(struct bpf_program *prog __maybe_unused)
+{
+ return -LIBBPF_ERRNO__NOUBPF;
+}
+
+bool bpf_program__is_ubpf(struct bpf_program *prog __maybe_unused)
+{
+ return false;
+}
+#endif
+
int bpf_map__get_fd(struct bpf_map *map)
{
if (!map)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index a51594c..f6965ce 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -26,6 +26,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__NOUBPF, /* UBPF support is not compiled */
__LIBBPF_ERRNO__END,
};
@@ -86,6 +87,9 @@ int bpf_program__get_private(struct bpf_program *prog,
const char *bpf_program__title(struct bpf_program *prog, bool needs_copy);
+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 bpf_insn;
--
1.8.3.4
[toc] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-04-20 21:30 +0200 |
| Message-ID | <rq5Z0-4rG-25@gated-at.bofh.it> |
| In reply to | #1383612 |
Em Wed, Apr 20, 2016 at 06:01:45PM +0000, Wang Nan escreveu:
> Add an 'engine' field in bpf_program to indicate whether a program is a
> ubpf program or kernel bpf program. For compatibility, the default
> engine is kernel bpf, unless explicitly set to ubpf using
> bpf_program__set_ubpf().
>
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Li Zefan <lizefan@huawei.com>
> ---
> tools/lib/bpf/libbpf.c | 40 ++++++++++++++++++++++++++++++++++++++++
> tools/lib/bpf/libbpf.h | 4 ++++
> 2 files changed, 44 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index dd5a107..3755846 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -80,6 +80,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(NOUBPF)] = "UBPF support is not compiled",
> };
>
> int libbpf_strerror(int err, char *buf, size_t size)
> @@ -147,6 +148,11 @@ union prog_instance {
> * linux/filter.h.
> */
> struct bpf_program {
> + enum {
> + ENGINE_UNKNOWN,
> + ENGINE_KBPF,
> + ENGINE_UBPF,
> + } engine;
> /* Index in elf obj file, for relocation use. */
> int idx;
> char *section_name;
> @@ -291,6 +297,7 @@ bpf_program__init(void *data, size_t size, char *name, int idx,
> memcpy(prog->insns, data,
> prog->insns_cnt * sizeof(struct bpf_insn));
> prog->idx = idx;
> + prog->engine = ENGINE_UNKNOWN;
> prog->instances.array = NULL;
> prog->instances.nr = -1;
>
> @@ -941,6 +948,11 @@ bpf_program__load(struct bpf_program *prog,
> {
> int err = 0, fd, i;
>
> + if (prog->engine == ENGINE_UNKNOWN)
> + prog->engine = ENGINE_KBPF;
> + if (prog->engine != ENGINE_KBPF)
else if (prog->engine != ENGINE_KBPF)
Nitpicking a bit :-)
> + return -EINVAL;
> +
> if (prog->instances.nr < 0 || !prog->instances.array) {
> if (prog->preprocessor) {
> pr_warning("Internal error: can't load program '%s'\n",
> @@ -1318,6 +1330,34 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n)
> return fd;
> }
>
> +#ifdef HAVE_UBPF_SUPPORT
> +int bpf_program__set_ubpf(struct bpf_program *prog)
> +{
> + if (prog->engine != ENGINE_UNKNOWN) {
> + pr_warning("Can't set program %s to ubpf\n",
> + prog->section_name);
> + return -EINVAL;
> + }
> + prog->engine = ENGINE_UBPF;
> + return 0;
> +}
> +
> +bool bpf_program__is_ubpf(struct bpf_program *prog)
> +{
> + return prog->engine == ENGINE_UBPF;
> +}
> +#else
> +int bpf_program__set_ubpf(struct bpf_program *prog __maybe_unused)
> +{
> + return -LIBBPF_ERRNO__NOUBPF;
> +}
> +
> +bool bpf_program__is_ubpf(struct bpf_program *prog __maybe_unused)
> +{
> + return false;
> +}
> +#endif
> +
> int bpf_map__get_fd(struct bpf_map *map)
> {
> if (!map)
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index a51594c..f6965ce 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -26,6 +26,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__NOUBPF, /* UBPF support is not compiled */
> __LIBBPF_ERRNO__END,
> };
>
> @@ -86,6 +87,9 @@ int bpf_program__get_private(struct bpf_program *prog,
>
> const char *bpf_program__title(struct bpf_program *prog, bool needs_copy);
>
> +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 bpf_insn;
> --
> 1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | pi3orama <pi3orama@163.com> |
|---|---|
| Date | 2016-04-20 21:40 +0200 |
| Message-ID | <rq68I-4zt-65@gated-at.bofh.it> |
| In reply to | #1383663 |
发自我的 iPhone
> 在 2016年4月21日,上午3:23,Arnaldo Carvalho de Melo <acme@kernel.org> 写道:
>
> Em Wed, Apr 20, 2016 at 06:01:45PM +0000, Wang Nan escreveu:
>>
[SNIP]
>>
>> + if (prog->engine == ENGINE_UNKNOWN)
>> + prog->engine = ENGINE_KBPF;
>> + if (prog->engine != ENGINE_KBPF)
>
> else if (prog->engine != ENGINE_KBPF)
>
> Nitpicking a bit :-)
>
We set it to ENGINE_KBPF in previous "if",
so can't use "else".
Do this because I want the engine is KBPF
if not explicitly set to UNPF.
Thank you.
>> + return -EINVAL;
>> +
>> if (prog->instances.nr < 0 || !prog->instances.array) {
>> if (prog->preprocessor) {
>> pr_warning("Internal error: can't load program '%s'\n",
>> @@ -1318,6 +1330,34 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n)
>> return fd;
>> }
>>
>> +#ifdef HAVE_UBPF_SUPPORT
>> +int bpf_program__set_ubpf(struct bpf_program *prog)
>> +{
>> + if (prog->engine != ENGINE_UNKNOWN) {
>> + pr_warning("Can't set program %s to ubpf\n",
>> + prog->section_name);
>> + return -EINVAL;
>> + }
>> + prog->engine = ENGINE_UBPF;
>> + return 0;
>> +}
>> +
>> +bool bpf_program__is_ubpf(struct bpf_program *prog)
>> +{
>> + return prog->engine == ENGINE_UBPF;
>> +}
>> +#else
>> +int bpf_program__set_ubpf(struct bpf_program *prog __maybe_unused)
>> +{
>> + return -LIBBPF_ERRNO__NOUBPF;
>> +}
>> +
>> +bool bpf_program__is_ubpf(struct bpf_program *prog __maybe_unused)
>> +{
>> + return false;
>> +}
>> +#endif
>> +
>> int bpf_map__get_fd(struct bpf_map *map)
>> {
>> if (!map)
>> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
>> index a51594c..f6965ce 100644
>> --- a/tools/lib/bpf/libbpf.h
>> +++ b/tools/lib/bpf/libbpf.h
>> @@ -26,6 +26,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__NOUBPF, /* UBPF support is not compiled */
>> __LIBBPF_ERRNO__END,
>> };
>>
>> @@ -86,6 +87,9 @@ int bpf_program__get_private(struct bpf_program *prog,
>>
>> const char *bpf_program__title(struct bpf_program *prog, bool needs_copy);
>>
>> +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 bpf_insn;
>> --
>> 1.8.3.4
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web