patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Kevin Traynor <ktraynor@redhat.com>
To: ciara.loftus@intel.com, stable@dpdk.org
Cc: bluca@debian.org, christian.ehrhardt@canonical.com, xuemingl@nvidia.com
Subject: [PATCH 21.11 2/2] net/af_xdp: make compatible with libbpf >= 0.7.0
Date: Fri,  6 May 2022 12:03:37 +0100
Message-ID: <20220506110337.267796-3-ktraynor@redhat.com> (raw)
In-Reply-To: <20220506110337.267796-1-ktraynor@redhat.com>

From: Ciara Loftus <ciara.loftus@intel.com>

[ upstream commit 8d3d9c72513ac116996a05700f18c10b332e7699 ]

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_object__load.

Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
---
 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(-)

diff --git a/drivers/net/af_xdp/compat.h b/drivers/net/af_xdp/compat.h
index bf40c6572e..28ea64aeaa 100644
--- a/drivers/net/af_xdp/compat.h
+++ b/drivers/net/af_xdp/compat.h
@@ -8,4 +8,5 @@
 #include <bpf/xsk.h>
 #endif
+#include <bpf/bpf.h>
 #include <linux/version.h>
 #include <poll.h>
@@ -59,2 +60,40 @@ tx_syscall_needed(struct xsk_ring_prod *q __rte_unused)
 }
 #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
diff --git a/drivers/net/af_xdp/meson.build b/drivers/net/af_xdp/meson.build
index 93e895eab9..1e0de23705 100644
--- a/drivers/net/af_xdp/meson.build
+++ b/drivers/net/af_xdp/meson.build
@@ -23,4 +23,9 @@ if cc.has_header('linux/if_xdp.h')
             ext_deps += xdp_dep
             ext_deps += bpf_dep
+            bpf_ver_dep = dependency('libbpf', version : '>=0.7.0',
+                                 required: false, method: 'pkg-config')
+            if bpf_ver_dep.found()
+                cflags += ['-DRTE_NET_AF_XDP_LIBBPF_OBJ_OPEN']
+            endif
         else
             build = false
diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
index 0366211243..9db76d4562 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -16,5 +16,4 @@
 #include <linux/sockios.h>
 #include "af_xdp_deps.h"
-#include <bpf/bpf.h>
 
 #include <rte_ethdev.h>
@@ -1150,11 +1149,11 @@ 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;
 	}
 
-- 
2.34.1


  parent reply	other threads:[~2022-05-06 11:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06 11:03 [PATCH 21.11 0/2] Fix UNH CI af_xdp build errors Kevin Traynor
2022-05-06 11:03 ` [PATCH 21.11 1/2] net/af_xdp: use libxdp if available Kevin Traynor
2022-05-06 11:03 ` Kevin Traynor [this message]
2022-05-06 12:13 ` [PATCH 21.11 0/2] Fix UNH CI af_xdp build errors Loftus, Ciara
2022-05-10  8:37   ` Kevin Traynor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220506110337.267796-3-ktraynor@redhat.com \
    --to=ktraynor@redhat.com \
    --cc=bluca@debian.org \
    --cc=christian.ehrhardt@canonical.com \
    --cc=ciara.loftus@intel.com \
    --cc=stable@dpdk.org \
    --cc=xuemingl@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

patches for DPDK stable branches

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.dpdk.org/stable/0 stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ http://inbox.dpdk.org/stable \
		stable@dpdk.org
	public-inbox-index stable

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.stable


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git