From: Andrey Ignatov <rdna@fb.com>
To: Jakub Kicinski <jakub.kicinski@netronome.com>
Cc: <alexei.starovoitov@gmail.com>, <daniel@iogearbox.net>,
<oss-drivers@netronome.com>, <netdev@vger.kernel.org>
Subject: Re: [PATCH bpf-next v2 08/12] tools: libbpf: add extended attributes version of bpf_object__open()
Date: Mon, 9 Jul 2018 22:39:45 -0700 [thread overview]
Message-ID: <20180710053944.GC77322@rdna-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <20180709175944.32265-9-jakub.kicinski@netronome.com>
Jakub Kicinski <jakub.kicinski@netronome.com> [Mon, 2018-07-09 11:01 -0700]:
> Similarly to bpf_prog_load() users of bpf_object__open() may need
> to specify the expected program type. Program type is needed at
> open to avoid the kernel version check for program types which don't
> require it.
>
> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
> ---
> tools/lib/bpf/libbpf.c | 21 +++++++++++++++++----
> tools/lib/bpf/libbpf.h | 6 ++++++
> 2 files changed, 23 insertions(+), 4 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index edc3b0b3737d..5b0e84fbcf71 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -1520,7 +1520,8 @@ __bpf_object__open(const char *path, void *obj_buf, size_t obj_buf_sz,
> return ERR_PTR(err);
> }
>
> -struct bpf_object *bpf_object__open(const char *path)
> +struct bpf_object *bpf_object__open_xattr(const char *path,
> + struct bpf_object_open_attr *attr)
> {
> /* param validation */
> if (!path)
> @@ -1528,7 +1529,17 @@ struct bpf_object *bpf_object__open(const char *path)
>
> pr_debug("loading %s\n", path);
>
> - return __bpf_object__open(path, NULL, 0, true);
> + return __bpf_object__open(path, NULL, 0,
> + bpf_prog_type__needs_kver(attr->prog_type));
> +}
> +
> +struct bpf_object *bpf_object__open(const char *path)
> +{
> + struct bpf_object_open_attr attr = {
> + .prog_type = BPF_PROG_TYPE_UNSPEC,
> + };
> +
> + return bpf_object__open_xattr(path, &attr);
> }
>
> struct bpf_object *bpf_object__open_buffer(void *obj_buf,
> @@ -2238,6 +2249,9 @@ int bpf_prog_load(const char *file, enum bpf_prog_type type,
> int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
> struct bpf_object **pobj, int *prog_fd)
> {
> + struct bpf_object_open_attr open_attr = {
> + .prog_type = attr->prog_type,
> + };
> struct bpf_program *prog, *first_prog = NULL;
> enum bpf_attach_type expected_attach_type;
> enum bpf_prog_type prog_type;
> @@ -2250,8 +2264,7 @@ int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
> if (!attr->file)
> return -EINVAL;
>
> - obj = __bpf_object__open(attr->file, NULL, 0,
> - bpf_prog_type__needs_kver(attr->prog_type));
> + obj = bpf_object__open_xattr(attr->file, &open_attr);
> if (IS_ERR_OR_NULL(obj))
> return -ENOENT;
>
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index 3122d74f2643..60593ac44700 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -66,7 +66,13 @@ void libbpf_set_print(libbpf_print_fn_t warn,
> /* Hide internal to user */
> struct bpf_object;
>
> +struct bpf_object_open_attr {
> + enum bpf_prog_type prog_type;
> +};
> +
> struct bpf_object *bpf_object__open(const char *path);
> +struct bpf_object *bpf_object__open_xattr(const char *path,
> + struct bpf_object_open_attr *attr);
Should the new bpf_object__open_xattr() API have _only_ attr argument?
Path, in turn, can become a member of attr.
That way it can be reused e.g. to load object from buffer (like
bpf_object__open_buffer() below), where path is not needed.
Otherwise, if bpf_object__open_buffer() has to be extended in the
future, another _xattr function will be needed (or caller would need to
pass NULL to path, what would make API less convenient).
> struct bpf_object *bpf_object__open_buffer(void *obj_buf,
> size_t obj_buf_sz,
> const char *name);
> --
> 2.17.1
>
--
Andrey Ignatov
next prev parent reply other threads:[~2018-07-10 5:40 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-09 17:59 [PATCH bpf-next v2 00/12] tools: bpf: extend bpftool prog load Jakub Kicinski
2018-07-09 17:59 ` [PATCH bpf-next v2 01/12] selftests/bpf: remove duplicated word from test offloads Jakub Kicinski
2018-07-09 17:59 ` [PATCH bpf-next v2 02/12] selftests/bpf: add Error: prefix in check_extack helper Jakub Kicinski
2018-07-09 17:59 ` [PATCH bpf-next v2 03/12] tools: bpftool: refactor argument parsing for prog load Jakub Kicinski
2018-07-09 17:59 ` [PATCH bpf-next v2 04/12] tools: bpftool: add support for loading programs for offload Jakub Kicinski
2018-07-09 17:59 ` [PATCH bpf-next v2 05/12] tools: libbpf: expose the prog type guessing from section name logic Jakub Kicinski
2018-07-10 5:10 ` Andrey Ignatov
2018-07-09 17:59 ` [PATCH bpf-next v2 06/12] tools: bpftool: allow users to specify program type for prog load Jakub Kicinski
2018-07-09 17:59 ` [PATCH bpf-next v2 07/12] tools: libbpf: recognize offload neutral maps Jakub Kicinski
2018-07-09 17:59 ` [PATCH bpf-next v2 08/12] tools: libbpf: add extended attributes version of bpf_object__open() Jakub Kicinski
2018-07-10 5:39 ` Andrey Ignatov [this message]
2018-07-09 17:59 ` [PATCH bpf-next v2 09/12] tools: bpftool: reimplement bpf_prog_load() for prog load Jakub Kicinski
2018-07-09 19:40 ` Alexei Starovoitov
2018-07-09 17:59 ` [PATCH bpf-next v2 10/12] tools: bpf: make use of reallocarray Jakub Kicinski
2018-07-09 17:59 ` [PATCH bpf-next v2 11/12] tools: libbpf: allow map reuse Jakub Kicinski
2018-07-09 20:22 ` Andrey Ignatov
2018-07-10 2:49 ` Jakub Kicinski
2018-07-10 4:23 ` Andrey Ignatov
2018-07-10 18:09 ` Jakub Kicinski
2018-07-10 18:16 ` Daniel Borkmann
2018-07-10 20:58 ` Jakub Kicinski
2018-07-09 17:59 ` [PATCH bpf-next v2 12/12] tools: bpftool: allow reuse of maps with bpftool prog load Jakub Kicinski
2018-07-09 19:48 ` Alexei Starovoitov
2018-07-10 1:38 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180710053944.GC77322@rdna-mbp.dhcp.thefacebook.com \
--to=rdna@fb.com \
--cc=alexei.starovoitov@gmail.com \
--cc=daniel@iogearbox.net \
--cc=jakub.kicinski@netronome.com \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox