[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20181120231510.46332-1-sdf@google.com>
Date: Tue, 20 Nov 2018 15:15:09 -0800
From: Stanislav Fomichev <sdf@...gle.com>
To: netdev@...r.kernel.org, ast@...nel.org
Cc: daniel@...earbox.net, Stanislav Fomichev <sdf@...gle.com>
Subject: [PATCH bpf-next v2 1/2] bpf: libbpf: retry program creation without
the name
[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@...gle.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
Powered by blists - more mailing lists