Skip to contentSkip to conversation

net/af_xdp: make the PMD compatible with libbpf >= v0.7.0

PATCH Superseded Ciara Loftus 2 participants 3 messages Feb 17, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/af_xdp: make the PMD compatible with libbpf >= v0.7.0

libbpf v0.7.0 deprecates the bpf_prog_load function. Use meson to detect if libbpf >= v0.7.0 is linked and if so, use the recommended replacement functions bpf_object__open_file and bpf_oject__load.

---
 drivers/net/af_xdp/compat.h         | 39 +++++++++++++++++++++++++++++
 drivers/net/af_xdp/meson.build      |  5 ++++
 drivers/net/af_xdp/rte_eth_af_xdp.c |  9 +++----
 3 files changed, 48 insertions(+), 5 deletions(-)
drivers/net/af_xdp/compat.h +39 -0
index bf40c6572e..28ea64aeaa 100644
@@ -7,6 +7,7 @@
 #else
 #include <bpf/xsk.h>
 #endif
+#include <bpf/bpf.h>
 #include <linux/version.h>
 #include <poll.h>
 
@@ -58,3 +59,41 @@ tx_syscall_needed(struct xsk_ring_prod *q __rte_unused)
 	return 1;
 }
 #endif
+
+#ifdef RTE_NET_AF_XDP_LIBBPF_OBJ_OPEN
+static int load_program(const char *prog_path, struct bpf_object **obj)
+{
+	struct bpf_program *prog;
+	int err;
+
+	*obj = bpf_object__open_file(prog_path, NULL);
+	err = libbpf_get_error(*obj);
+	if (err)
+		return -1;
+
+	err = bpf_object__load(*obj);
+	if (err)
+		goto out;
+
+	prog = bpf_object__next_program(*obj, NULL);
+	if (!prog)
+		goto out;
+
+	return bpf_program__fd(prog);
+
+out:
+	bpf_object__close(*obj);
+	return -1;
+}
+#else
+static int load_program(const char *prog_path, struct bpf_object **obj)
+{
+	int ret, prog_fd;
+
+	ret = bpf_prog_load(prog_path, BPF_PROG_TYPE_XDP, obj, &prog_fd);
+	if (ret)
+		return -1;
+
+	return prog_fd;
+}
+#endif
drivers/net/af_xdp/meson.build +5 -0
index 93e895eab9..9fe4063b99 100644
@@ -22,6 +22,11 @@ if cc.has_header('linux/if_xdp.h')
             cflags += ['-DRTE_NET_AF_XDP_SHARED_UMEM']
             ext_deps += xdp_dep
             ext_deps += bpf_dep
+            bpf_ver_dep = dependency('libbpf', version : '>=0.6.0',
+                                 required: false, method: 'pkg-config')
+            if bpf_ver_dep.found()
+                cflags += ['-DRTE_NET_AF_XDP_LIBBPF_OBJ_OPEN']
+            endif
         else
             build = false
             reason = 'missing dependency, libbpf'
drivers/net/af_xdp/rte_eth_af_xdp.c +4 -5
index 6ac710c6bd..bb2a609e7f 100644
@@ -15,7 +15,6 @@
 #include <linux/ethtool.h>
 #include <linux/sockios.h>
 #include "af_xdp_deps.h"
-#include <bpf/bpf.h>
 
 #include <rte_ethdev.h>
 #include <ethdev_driver.h>
@@ -1176,13 +1175,13 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
 static int
 load_custom_xdp_prog(const char *prog_path, int if_index, struct bpf_map **map)
 {
-	int ret, prog_fd = -1;
+	int ret, prog_fd;
 	struct bpf_object *obj;
 
-	ret = bpf_prog_load(prog_path, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
-	if (ret) {
+	prog_fd = load_program(prog_path, &obj);
+	if (prog_fd < 0) {
 		AF_XDP_LOG(ERR, "Failed to load program %s\n", prog_path);
-		return ret;
+		return -1;
 	}
 
 	/*
Signature · 1 line
2.17.1
#1 lore raw
Quoted 11 lines · Ciara Loftus

libbpf v0.7.0 deprecates the bpf_prog_load function. Use meson to detect if libbpf >= v0.7.0 is linked and if so, use the recommended replacement functions bpf_object__open_file and bpf_oject__load.

---
 drivers/net/af_xdp/compat.h         | 39 +++++++++++++++++++++++++++++
 drivers/net/af_xdp/meson.build      |  5 ++++
 drivers/net/af_xdp/rte_eth_af_xdp.c |  9 +++----
 3 files changed, 48 insertions(+), 5 deletions(-)

<snip>

drivers/net/af_xdp/meson.build if cc.has_header('linux/if_xdp.h') · line 25

Quoted 9 lines
drivers/net/af_xdp/meson.build +1 -0
index 93e895eab9..9fe4063b99 100644
@@ -22,6 +22,11 @@ if cc.has_header('linux/if_xdp.h')
             cflags += ['-DRTE_NET_AF_XDP_SHARED_UMEM']
             ext_deps += xdp_dep
             ext_deps += bpf_dep
+            bpf_ver_dep = dependency('libbpf', version : '>=0.6.0',

typo? Commit log refers to v0.7.

#2 lore raw
Quoted 19 lines

Subject: Re: [PATCH] net/af_xdp: make the PMD compatible with libbpf >= v0.7.0

Quoted 7 lines · Ciara Loftus

libbpf v0.7.0 deprecates the bpf_prog_load function. Use meson to detect if libbpf >= v0.7.0 is linked and if so, use the recommended replacement functions bpf_object__open_file and bpf_oject__load.

---
 drivers/net/af_xdp/compat.h         | 39

+++++++++++++++++++++++++++++

Quoted 4 lines
 drivers/net/af_xdp/meson.build      |  5 ++++
 drivers/net/af_xdp/rte_eth_af_xdp.c |  9 +++----
 3 files changed, 48 insertions(+), 5 deletions(-)

<snip>

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/af_xdp/meson.build

Quoted 10 lines

drivers/net/af_xdp/meson.build if cc.has_header('linux/if_xdp.h') · line 25

Quoted 8 lines

index 93e895eab9..9fe4063b99 100644

drivers/net/af_xdp/meson.build +1 -0
@@ -22,6 +22,11 @@ if cc.has_header('linux/if_xdp.h')
             cflags += ['-DRTE_NET_AF_XDP_SHARED_UMEM']
             ext_deps += xdp_dep
             ext_deps += bpf_dep
+            bpf_ver_dep = dependency('libbpf', version : '>=0.6.0',

typo? Commit log refers to v0.7.

Indeed. Thanks for the catch! v2 on the way.

Ciara