All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf@google.com>
To: netdev@vger.kernel.org, ast@kernel.org
Cc: daniel@iogearbox.net, Stanislav Fomichev <sdf@google.com>
Subject: [PATCH bpf-next v2 1/2] bpf: libbpf: retry program creation without the name
Date: Tue, 20 Nov 2018 15:15:09 -0800	[thread overview]
Message-ID: <20181120231510.46332-1-sdf@google.com> (raw)
In-Reply-To: <20181120230445.os6ikxaqhq777xao@ast-mbp.dhcp.thefacebook.com>

[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
bpf_load_program_xattr without a program name to cover older kernels.

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

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index cb6565d79603..2ea14dfa28fc 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1401,6 +1401,18 @@ load_program(struct bpf_program *prog, struct bpf_insn *insns, int insns_cnt,
 
 	ret = bpf_load_program_xattr(&load_attr, log_buf, BPF_LOG_BUF_SIZE);
 
+	if (ret < 0 && errno == E2BIG && load_attr.name) {
+		/* Retry the same operation, but without the name.
+		 * Pre v4.14 kernels don't support prog names.
+		 */
+		cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
+		pr_warning("Error in bpf_load_program_xattr(%s):%s(%d). Retrying without name.\n",
+			   prog->name, cp, errno);
+		load_attr.name = NULL;
+		ret = bpf_load_program_xattr(&load_attr, log_buf,
+					     BPF_LOG_BUF_SIZE);
+	}
+
 	if (ret >= 0) {
 		*pfd = ret;
 		ret = 0;
-- 
2.19.1.1215.g8438c0b245-goog

  reply	other threads:[~2018-11-21  9:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-20  0:46 [PATCH bpf-next] bpf: libbpf: retry program creation without the name Stanislav Fomichev
2018-11-20  1:24 ` 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       ` Stanislav Fomichev [this message]
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=20181120231510.46332-1-sdf@google.com \
    --to=sdf@google.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.org \
    /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.