* [PATCH bpf-next] bpf: libbpf: retry map creation without the name
@ 2018-11-19 21:35 Stanislav Fomichev
2018-11-19 22:36 ` Daniel Borkmann
0 siblings, 1 reply; 5+ messages in thread
From: Stanislav Fomichev @ 2018-11-19 21:35 UTC (permalink / raw)
To: netdev, ast, daniel; +Cc: vladum, Stanislav Fomichev
Since commit 88cda1c9da02 ("bpf: libbpf: Provide basic API support
to specify BPF obj name"), libbpf unconditionally sets bpf_attr->name
for maps. Pre v4.14 kernels don't know about map names and return an
error about unexpected non-zero data. Retry sys_bpf without a map
name to cover older kernels.
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/lib/bpf/bpf.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 03f9bcc4ef50..673175bc06ee 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -69,6 +69,7 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr)
{
__u32 name_len = create_attr->name ? strlen(create_attr->name) : 0;
union bpf_attr attr;
+ int ret;
memset(&attr, '\0', sizeof(attr));
@@ -86,7 +87,15 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr)
attr.map_ifindex = create_attr->map_ifindex;
attr.inner_map_fd = create_attr->inner_map_fd;
- return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
+ ret = sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
+ if (ret < 0 && create_attr->name) {
+ /* Retry the same syscall, but without the name.
+ * Pre v4.14 kernels don't support map names.
+ */
+ memset(attr.map_name, 0, sizeof(attr.map_name));
+ return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
+ }
+ return ret;
}
int bpf_create_map_node(enum bpf_map_type map_type, const char *name,
--
2.19.1.1215.g8438c0b245-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpf: libbpf: retry map creation without the name
2018-11-19 21:35 [PATCH bpf-next] bpf: libbpf: retry map creation without the name Stanislav Fomichev
@ 2018-11-19 22:36 ` Daniel Borkmann
2018-11-19 22:49 ` [PATCH bpf-next v2] " Stanislav Fomichev
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Borkmann @ 2018-11-19 22:36 UTC (permalink / raw)
To: Stanislav Fomichev, netdev, ast; +Cc: vladum
On 11/19/2018 10:35 PM, Stanislav Fomichev wrote:
> Since commit 88cda1c9da02 ("bpf: libbpf: Provide basic API support
> to specify BPF obj name"), libbpf unconditionally sets bpf_attr->name
> for maps. Pre v4.14 kernels don't know about map names and return an
> error about unexpected non-zero data. Retry sys_bpf without a map
> name to cover older kernels.
Looks good, small nit below:
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---
> tools/lib/bpf/bpf.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index 03f9bcc4ef50..673175bc06ee 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -69,6 +69,7 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr)
> {
> __u32 name_len = create_attr->name ? strlen(create_attr->name) : 0;
> union bpf_attr attr;
> + int ret;
>
> memset(&attr, '\0', sizeof(attr));
>
> @@ -86,7 +87,15 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr)
> attr.map_ifindex = create_attr->map_ifindex;
> attr.inner_map_fd = create_attr->inner_map_fd;
>
> - return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
> + ret = sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
> + if (ret < 0 && create_attr->name) {
Could you also check errno being EINVAL here so that we do not try to
confuse it with an error coming from insufficient memlock which is
EPERM in that case.
> + /* Retry the same syscall, but without the name.
> + * Pre v4.14 kernels don't support map names.
> + */
> + memset(attr.map_name, 0, sizeof(attr.map_name));
> + return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
> + }
> + return ret;
> }
>
> int bpf_create_map_node(enum bpf_map_type map_type, const char *name,
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH bpf-next v2] bpf: libbpf: retry map creation without the name
2018-11-19 22:36 ` Daniel Borkmann
@ 2018-11-19 22:49 ` Stanislav Fomichev
2018-11-19 23:57 ` Daniel Borkmann
0 siblings, 1 reply; 5+ messages in thread
From: Stanislav Fomichev @ 2018-11-19 22:49 UTC (permalink / raw)
To: netdev, ast, daniel; +Cc: vladum, Stanislav Fomichev
Since commit 88cda1c9da02 ("bpf: libbpf: Provide basic API support
to specify BPF obj name"), libbpf unconditionally sets bpf_attr->name
for maps. Pre v4.14 kernels don't know about map names and return an
error about unexpected non-zero data. Retry sys_bpf without a map
name to cover older kernels.
v2 changes:
* check for errno == EINVAL as suggested by Daniel Borkmann
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/lib/bpf/bpf.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 03f9bcc4ef50..961e1b9fc592 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -69,6 +69,7 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr)
{
__u32 name_len = create_attr->name ? strlen(create_attr->name) : 0;
union bpf_attr attr;
+ int ret;
memset(&attr, '\0', sizeof(attr));
@@ -86,7 +87,15 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr)
attr.map_ifindex = create_attr->map_ifindex;
attr.inner_map_fd = create_attr->inner_map_fd;
- return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
+ ret = sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
+ if (ret < 0 && errno == EINVAL && create_attr->name) {
+ /* Retry the same syscall, but without the name.
+ * Pre v4.14 kernels don't support map names.
+ */
+ memset(attr.map_name, 0, sizeof(attr.map_name));
+ return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
+ }
+ return ret;
}
int bpf_create_map_node(enum bpf_map_type map_type, const char *name,
--
2.19.1.1215.g8438c0b245-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v2] bpf: libbpf: retry map creation without the name
2018-11-19 22:49 ` [PATCH bpf-next v2] " Stanislav Fomichev
@ 2018-11-19 23:57 ` Daniel Borkmann
2018-11-20 0:12 ` Stanislav Fomichev
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Borkmann @ 2018-11-19 23:57 UTC (permalink / raw)
To: Stanislav Fomichev, netdev, ast; +Cc: vladum
On 11/19/2018 11:49 PM, Stanislav Fomichev wrote:
> Since commit 88cda1c9da02 ("bpf: libbpf: Provide basic API support
> to specify BPF obj name"), libbpf unconditionally sets bpf_attr->name
> for maps. Pre v4.14 kernels don't know about map names and return an
> error about unexpected non-zero data. Retry sys_bpf without a map
> name to cover older kernels.
>
> v2 changes:
> * check for errno == EINVAL as suggested by Daniel Borkmann
>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
Applied to bpf-next, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v2] bpf: libbpf: retry map creation without the name
2018-11-19 23:57 ` Daniel Borkmann
@ 2018-11-20 0:12 ` Stanislav Fomichev
0 siblings, 0 replies; 5+ messages in thread
From: Stanislav Fomichev @ 2018-11-20 0:12 UTC (permalink / raw)
To: Daniel Borkmann; +Cc: Stanislav Fomichev, netdev, ast, vladum
On 11/20, Daniel Borkmann wrote:
> On 11/19/2018 11:49 PM, Stanislav Fomichev wrote:
> > Since commit 88cda1c9da02 ("bpf: libbpf: Provide basic API support
> > to specify BPF obj name"), libbpf unconditionally sets bpf_attr->name
> > for maps. Pre v4.14 kernels don't know about map names and return an
> > error about unexpected non-zero data. Retry sys_bpf without a map
> > name to cover older kernels.
> >
> > v2 changes:
> > * check for errno == EINVAL as suggested by Daniel Borkmann
> >
> > Signed-off-by: Stanislav Fomichev <sdf@google.com>
>
> Applied to bpf-next, thanks!
Great, thanks! It looks like there might be the same problem with the
program's name. I'll probably follow up with another patch soon.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-11-20 10:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-19 21:35 [PATCH bpf-next] bpf: libbpf: retry map creation without the name Stanislav Fomichev
2018-11-19 22:36 ` Daniel Borkmann
2018-11-19 22:49 ` [PATCH bpf-next v2] " Stanislav Fomichev
2018-11-19 23:57 ` Daniel Borkmann
2018-11-20 0:12 ` Stanislav Fomichev
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.