[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20181120004625.243494-1-sdf@google.com>
Date: Mon, 19 Nov 2018 16:46:25 -0800
From: Stanislav Fomichev <sdf@...gle.com>
To: netdev@...r.kernel.org, daniel@...earbox.net
Cc: ast@...nel.org, vladum@...gle.com,
Stanislav Fomichev <sdf@...gle.com>
Subject: [PATCH bpf-next] 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 sys_bpf without
a program name to cover older kernels.
Signed-off-by: Stanislav Fomichev <sdf@...gle.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
Powered by blists - more mailing lists