* [PATCH iproute2-next 0/3] bpf: Work around libbpf deprecations
@ 2022-02-28 1:58 David Ahern
2022-02-28 1:58 ` [PATCH iproute2-next 1/3] bpf_glue: Remove use of bpf_load_program from libbpf David Ahern
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: David Ahern @ 2022-02-28 1:58 UTC (permalink / raw)
To: netdev; +Cc: stephen, David Ahern
libbpf is deprecating APIs, so iproute2 needs to adapt. This will be
an on-going effort, especially to handle legacy maps. This is a
starter set for the low handing fruit.
David Ahern (3):
bpf_glue: Remove use of bpf_load_program from libbpf
bpf: Export bpf syscall wrapper
bpf: Remove use of bpf_create_map_xattr
include/bpf_util.h | 2 ++
lib/bpf_glue.c | 15 ++++++++-------
lib/bpf_legacy.c | 19 +++++++------------
lib/bpf_libbpf.c | 24 ++++++++++++------------
4 files changed, 29 insertions(+), 31 deletions(-)
--
2.24.3 (Apple Git-128)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH iproute2-next 1/3] bpf_glue: Remove use of bpf_load_program from libbpf
2022-02-28 1:58 [PATCH iproute2-next 0/3] bpf: Work around libbpf deprecations David Ahern
@ 2022-02-28 1:58 ` David Ahern
2022-02-28 1:58 ` [PATCH iproute2-next 2/3] bpf: Export bpf syscall wrapper David Ahern
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2022-02-28 1:58 UTC (permalink / raw)
To: netdev; +Cc: stephen, David Ahern
bpf_load_program is deprecated starting in v0.7. The preferred
bpf_prog_load requires bpf_prog_load_opts from v0.6. This creates an
ugly scenario for iproute2 to work across libbpf versions from v0.1
and up.
Since bpf_program_load is only used to load the builtin vrf program,
just remove the libbpf call and use the legacy code.
Signed-off-by: David Ahern <dsahern@kernel.org>
---
lib/bpf_glue.c | 12 ------------
lib/bpf_legacy.c | 7 +++++++
2 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/lib/bpf_glue.c b/lib/bpf_glue.c
index 70d001840f7b..cc3015487c68 100644
--- a/lib/bpf_glue.c
+++ b/lib/bpf_glue.c
@@ -11,18 +11,6 @@
#include <bpf/bpf.h>
#endif
-int bpf_program_load(enum bpf_prog_type type, const struct bpf_insn *insns,
- size_t size_insns, const char *license, char *log,
- size_t size_log)
-{
-#ifdef HAVE_LIBBPF
- return bpf_load_program(type, insns, size_insns / sizeof(struct bpf_insn),
- license, 0, log, size_log);
-#else
- return bpf_prog_load_dev(type, insns, size_insns, license, 0, log, size_log);
-#endif
-}
-
int bpf_program_attach(int prog_fd, int target_fd, enum bpf_attach_type type)
{
#ifdef HAVE_LIBBPF
diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
index 6e3891c9f1f1..3779ae90cc1c 100644
--- a/lib/bpf_legacy.c
+++ b/lib/bpf_legacy.c
@@ -1126,6 +1126,13 @@ int bpf_prog_load_dev(enum bpf_prog_type type, const struct bpf_insn *insns,
return bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
}
+int bpf_program_load(enum bpf_prog_type type, const struct bpf_insn *insns,
+ size_t size_insns, const char *license, char *log,
+ size_t size_log)
+{
+ return bpf_prog_load_dev(type, insns, size_insns, license, 0, log, size_log);
+}
+
#ifdef HAVE_ELF
struct bpf_elf_prog {
enum bpf_prog_type type;
--
2.24.3 (Apple Git-128)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH iproute2-next 2/3] bpf: Export bpf syscall wrapper
2022-02-28 1:58 [PATCH iproute2-next 0/3] bpf: Work around libbpf deprecations David Ahern
2022-02-28 1:58 ` [PATCH iproute2-next 1/3] bpf_glue: Remove use of bpf_load_program from libbpf David Ahern
@ 2022-02-28 1:58 ` David Ahern
2022-02-28 1:58 ` [PATCH iproute2-next 3/3] bpf: Remove use of bpf_create_map_xattr David Ahern
2022-03-07 16:10 ` [PATCH iproute2-next 0/3] bpf: Work around libbpf deprecations patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2022-02-28 1:58 UTC (permalink / raw)
To: netdev; +Cc: stephen, David Ahern
Move bpf syscall wrapper to bpf_glue to make it available to libbpf
based functions.
Signed-off-by: David Ahern <dsahern@kernel.org>
---
include/bpf_util.h | 2 ++
lib/bpf_glue.c | 13 +++++++++++++
lib/bpf_legacy.c | 12 ------------
3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/include/bpf_util.h b/include/bpf_util.h
index 53acc4106de8..abb9627556ef 100644
--- a/include/bpf_util.h
+++ b/include/bpf_util.h
@@ -287,6 +287,8 @@ int bpf_program_attach(int prog_fd, int target_fd, enum bpf_attach_type type);
int bpf_dump_prog_info(FILE *f, uint32_t id);
+int bpf(int cmd, union bpf_attr *attr, unsigned int size);
+
#ifdef HAVE_ELF
int bpf_send_map_fds(const char *path, const char *obj);
int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux,
diff --git a/lib/bpf_glue.c b/lib/bpf_glue.c
index cc3015487c68..c1cf351b7359 100644
--- a/lib/bpf_glue.c
+++ b/lib/bpf_glue.c
@@ -4,13 +4,26 @@
* Authors: Hangbin Liu <haliu@redhat.com>
*
*/
+#include <sys/syscall.h>
#include <limits.h>
+#include <unistd.h>
#include "bpf_util.h"
#ifdef HAVE_LIBBPF
#include <bpf/bpf.h>
#endif
+int bpf(int cmd, union bpf_attr *attr, unsigned int size)
+{
+#ifdef __NR_bpf
+ return syscall(__NR_bpf, cmd, attr, size);
+#else
+ fprintf(stderr, "No bpf syscall, kernel headers too old?\n");
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
int bpf_program_attach(int prog_fd, int target_fd, enum bpf_attach_type type)
{
#ifdef HAVE_LIBBPF
diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
index 3779ae90cc1c..9bf7c1c493b4 100644
--- a/lib/bpf_legacy.c
+++ b/lib/bpf_legacy.c
@@ -33,7 +33,6 @@
#include <sys/un.h>
#include <sys/vfs.h>
#include <sys/mount.h>
-#include <sys/syscall.h>
#include <sys/sendfile.h>
#include <sys/resource.h>
@@ -134,17 +133,6 @@ static inline __u64 bpf_ptr_to_u64(const void *ptr)
return (__u64)(unsigned long)ptr;
}
-static int bpf(int cmd, union bpf_attr *attr, unsigned int size)
-{
-#ifdef __NR_bpf
- return syscall(__NR_bpf, cmd, attr, size);
-#else
- fprintf(stderr, "No bpf syscall, kernel headers too old?\n");
- errno = ENOSYS;
- return -1;
-#endif
-}
-
static int bpf_map_update(int fd, const void *key, const void *value,
uint64_t flags)
{
--
2.24.3 (Apple Git-128)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH iproute2-next 3/3] bpf: Remove use of bpf_create_map_xattr
2022-02-28 1:58 [PATCH iproute2-next 0/3] bpf: Work around libbpf deprecations David Ahern
2022-02-28 1:58 ` [PATCH iproute2-next 1/3] bpf_glue: Remove use of bpf_load_program from libbpf David Ahern
2022-02-28 1:58 ` [PATCH iproute2-next 2/3] bpf: Export bpf syscall wrapper David Ahern
@ 2022-02-28 1:58 ` David Ahern
2022-03-07 16:10 ` [PATCH iproute2-next 0/3] bpf: Work around libbpf deprecations patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2022-02-28 1:58 UTC (permalink / raw)
To: netdev; +Cc: stephen, David Ahern
bpf_create_map_xattr is deprecated in v0.7 in favor of bpf_map_create.
bpf_map_create and its bpf_map_create_opts are not available across the
range of v0.1 and up versions of libbpf, so change create_map to use
the bpf syscall directly.
Signed-off-by: David Ahern <dsahern@kernel.org>
---
lib/bpf_libbpf.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/lib/bpf_libbpf.c b/lib/bpf_libbpf.c
index 921716aec8c6..f4f98caa1e58 100644
--- a/lib/bpf_libbpf.c
+++ b/lib/bpf_libbpf.c
@@ -54,18 +54,18 @@ static const char *get_bpf_program__section_name(const struct bpf_program *prog)
static int create_map(const char *name, struct bpf_elf_map *map,
__u32 ifindex, int inner_fd)
{
- struct bpf_create_map_attr map_attr = {};
-
- map_attr.name = name;
- map_attr.map_type = map->type;
- map_attr.map_flags = map->flags;
- map_attr.key_size = map->size_key;
- map_attr.value_size = map->size_value;
- map_attr.max_entries = map->max_elem;
- map_attr.map_ifindex = ifindex;
- map_attr.inner_map_fd = inner_fd;
-
- return bpf_create_map_xattr(&map_attr);
+ union bpf_attr attr = {};
+
+ attr.map_type = map->type;
+ strlcpy(attr.map_name, name, sizeof(attr.map_name));
+ attr.map_flags = map->flags;
+ attr.key_size = map->size_key;
+ attr.value_size = map->size_value;
+ attr.max_entries = map->max_elem;
+ attr.map_ifindex = ifindex;
+ attr.inner_map_fd = inner_fd;
+
+ return bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
}
static int create_map_in_map(struct bpf_object *obj, struct bpf_map *map,
--
2.24.3 (Apple Git-128)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH iproute2-next 0/3] bpf: Work around libbpf deprecations
2022-02-28 1:58 [PATCH iproute2-next 0/3] bpf: Work around libbpf deprecations David Ahern
` (2 preceding siblings ...)
2022-02-28 1:58 ` [PATCH iproute2-next 3/3] bpf: Remove use of bpf_create_map_xattr David Ahern
@ 2022-03-07 16:10 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-07 16:10 UTC (permalink / raw)
To: David Ahern; +Cc: netdev, stephen
Hello:
This series was applied to iproute2/iproute2-next.git (main)
by David Ahern <dsahern@kernel.org>:
On Sun, 27 Feb 2022 18:58:37 -0700 you wrote:
> libbpf is deprecating APIs, so iproute2 needs to adapt. This will be
> an on-going effort, especially to handle legacy maps. This is a
> starter set for the low handing fruit.
>
> David Ahern (3):
> bpf_glue: Remove use of bpf_load_program from libbpf
> bpf: Export bpf syscall wrapper
> bpf: Remove use of bpf_create_map_xattr
>
> [...]
Here is the summary with links:
- [iproute2-next,1/3] bpf_glue: Remove use of bpf_load_program from libbpf
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=873bb9751f84
- [iproute2-next,2/3] bpf: Export bpf syscall wrapper
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=ac4e0913beb1
- [iproute2-next,3/3] bpf: Remove use of bpf_create_map_xattr
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=d9977eafa719
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-03-07 16:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-28 1:58 [PATCH iproute2-next 0/3] bpf: Work around libbpf deprecations David Ahern
2022-02-28 1:58 ` [PATCH iproute2-next 1/3] bpf_glue: Remove use of bpf_load_program from libbpf David Ahern
2022-02-28 1:58 ` [PATCH iproute2-next 2/3] bpf: Export bpf syscall wrapper David Ahern
2022-02-28 1:58 ` [PATCH iproute2-next 3/3] bpf: Remove use of bpf_create_map_xattr David Ahern
2022-03-07 16:10 ` [PATCH iproute2-next 0/3] bpf: Work around libbpf deprecations patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).