All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf@google.com>
To: netdev@vger.kernel.org, daniel@iogearbox.net
Cc: ast@kernel.org, vladum@google.com, Stanislav Fomichev <sdf@google.com>
Subject: [PATCH bpf-next] bpf: libbpf: retry program creation without the name
Date: Mon, 19 Nov 2018 16:46:25 -0800	[thread overview]
Message-ID: <20181120004625.243494-1-sdf@google.com> (raw)

[Recent commit 23499442c319 ("bpf: libbpf: retry map creation without
the name") fixed this issue for maps, let's do the same for programs.]

Since commit 88cda1c9da02 ("bpf: libbpf: Provide basic API support
to specify BPF obj name"), libbpf unconditionally sets bpf_attr->name
for programs. Pre v4.14 kernels don't know about programs names and
return an error about unexpected non-zero data. Retry sys_bpf without
a program name to cover older kernels.

Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 tools/lib/bpf/bpf.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 961e1b9fc592..cbe9d757c646 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -212,6 +212,16 @@ int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr,
 	if (fd >= 0 || !log_buf || !log_buf_sz)
 		return fd;
 
+	if (fd < 0 && errno == E2BIG && load_attr->name) {
+		/* Retry the same syscall, but without the name.
+		 * Pre v4.14 kernels don't support prog names.
+		 */
+		memset(attr.prog_name, 0, sizeof(attr.prog_name));
+		fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
+		if (fd >= 0 || !log_buf || !log_buf_sz)
+			return fd;
+	}
+
 	/* Try again with log */
 	attr.log_buf = ptr_to_u64(log_buf);
 	attr.log_size = log_buf_sz;
-- 
2.19.1.1215.g8438c0b245-goog

             reply	other threads:[~2018-11-20 11:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-20  0:46 Stanislav Fomichev [this message]
2018-11-20  1:24 ` [PATCH bpf-next] bpf: libbpf: retry program creation without the name Y Song
2018-11-20 19:51 ` Alexei Starovoitov
2018-11-20 21:19   ` Stanislav Fomichev
2018-11-20 23:04     ` Alexei Starovoitov
2018-11-20 23:15       ` [PATCH bpf-next v2 1/2] " Stanislav Fomichev
2018-11-20 23:15         ` [PATCH bpf-next v2 2/2] bpf: libbpf: move map name retry into libbpf.c Stanislav Fomichev
2018-11-20 23:18       ` [PATCH bpf-next] bpf: libbpf: retry program creation without the name Daniel Borkmann
2018-11-20 23:20         ` Alexei Starovoitov
2018-11-20 23:26           ` Stanislav Fomichev
2018-11-21  2:49             ` Quentin Monnet
2018-11-21 17:28               ` Stanislav Fomichev
2018-11-23 10:51                 ` Quentin Monnet
2018-11-26 19:08                   ` Vlad Dumitrescu
2018-11-26 19:45                     ` Quentin Monnet

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=20181120004625.243494-1-sdf@google.com \
    --to=sdf@google.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.org \
    --cc=vladum@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.