DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ciara Loftus <ciara.loftus@intel.com>
To: dev@dpdk.org
Cc: andrew.rybchenko@oktetlabs.ru, ferruh.yigit@xilinx.com,
	thomas@monjalon.net, Ciara Loftus <ciara.loftus@intel.com>
Subject: [PATCH v2] net/af_xdp: make compatible with libbpf v0.8.0
Date: Tue, 28 Jun 2022 12:18:21 +0000	[thread overview]
Message-ID: <20220628121821.1326012-1-ciara.loftus@intel.com> (raw)
In-Reply-To: <20220624102354.1516606-1-ciara.loftus@intel.com>

libbpf v0.8.0 deprecates the bpf_get_link_xdp_id and bpf_set_link_xdp_fd
functions. Use meson to detect if libbpf >= v0.7.0 is linked and if so, use
the recommended replacement functions bpf_xdp_query_id, bpf_xdp_attach
and bpf_xdp_detach which are available to use since libbpf v0.7.0.

Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
---
v2:
* Updated release notes
* Removed version limiting to libbpf v0.8.0
---
 doc/guides/nics/af_xdp.rst             |  3 ++-
 doc/guides/rel_notes/release_22_07.rst |  4 +++
 drivers/net/af_xdp/compat.h            | 36 +++++++++++++++++++++++++-
 drivers/net/af_xdp/meson.build         |  2 +-
 drivers/net/af_xdp/rte_eth_af_xdp.c    | 19 +++-----------
 5 files changed, 45 insertions(+), 19 deletions(-)

diff --git a/doc/guides/nics/af_xdp.rst b/doc/guides/nics/af_xdp.rst
index d42e0f1f79..ca23940e22 100644
--- a/doc/guides/nics/af_xdp.rst
+++ b/doc/guides/nics/af_xdp.rst
@@ -45,7 +45,8 @@ Prerequisites
 This is a Linux-specific PMD, thus the following prerequisites apply:
 
 *  A Linux Kernel (version > v4.18) with XDP sockets configuration enabled;
-*  Both libxdp >=v1.2.2 and libbpf libraries installed, or, libbpf <=v0.6.0
+*  Both libxdp >=v1.2.2 and libbpf <=v0.8.0 libraries installed, or, libbpf
+   <=v0.6.0.
 *  If using libxdp, it requires an environment variable called
    LIBXDP_OBJECT_PATH to be set to the location of where libxdp placed its bpf
    object files. This is usually in /usr/local/lib/bpf or /usr/local/lib64/bpf.
diff --git a/doc/guides/rel_notes/release_22_07.rst b/doc/guides/rel_notes/release_22_07.rst
index 6365800313..562d12abb2 100644
--- a/doc/guides/rel_notes/release_22_07.rst
+++ b/doc/guides/rel_notes/release_22_07.rst
@@ -125,6 +125,10 @@ New Features
   * Added new devargs option ``max_conf_threads``
     defining the number of management threads for parallel configurations.
 
+* **Updated AF_XDP PMD.**
+
+  * Made compatible with libbpf v0.8.0 (when used with libxdp).
+
 * **Updated Amazon ena driver.**
 
   The new driver version (v2.7.0) includes:
diff --git a/drivers/net/af_xdp/compat.h b/drivers/net/af_xdp/compat.h
index 28ea64aeaa..8f4ac8b5ea 100644
--- a/drivers/net/af_xdp/compat.h
+++ b/drivers/net/af_xdp/compat.h
@@ -60,7 +60,7 @@ tx_syscall_needed(struct xsk_ring_prod *q __rte_unused)
 }
 #endif
 
-#ifdef RTE_NET_AF_XDP_LIBBPF_OBJ_OPEN
+#ifdef RTE_NET_AF_XDP_LIBBPF_V070
 static int load_program(const char *prog_path, struct bpf_object **obj)
 {
 	struct bpf_program *prog;
@@ -85,6 +85,23 @@ static int load_program(const char *prog_path, struct bpf_object **obj)
 	bpf_object__close(*obj);
 	return -1;
 }
+
+static int
+remove_xdp_program(int ifindex)
+{
+	uint32_t curr_prog_id = 0;
+
+	if (bpf_xdp_query_id(ifindex, XDP_FLAGS_UPDATE_IF_NOEXIST,
+				&curr_prog_id))
+		return -1;
+
+	return bpf_xdp_detach(ifindex, XDP_FLAGS_UPDATE_IF_NOEXIST, NULL);
+}
+
+static int link_xdp_prog_with_dev(int ifindex, int fd, __u32 flags)
+{
+	return bpf_xdp_attach(ifindex, fd, flags, NULL);
+}
 #else
 static int load_program(const char *prog_path, struct bpf_object **obj)
 {
@@ -96,4 +113,21 @@ static int load_program(const char *prog_path, struct bpf_object **obj)
 
 	return prog_fd;
 }
+
+static int
+remove_xdp_program(int ifindex)
+{
+	uint32_t curr_prog_id = 0;
+
+	if (bpf_get_link_xdp_id(ifindex, &curr_prog_id,
+				XDP_FLAGS_UPDATE_IF_NOEXIST))
+		return -1;
+
+	return bpf_set_link_xdp_fd(ifindex, -1, XDP_FLAGS_UPDATE_IF_NOEXIST);
+}
+
+static int link_xdp_prog_with_dev(int ifindex, int fd, __u32 flags)
+{
+	return bpf_set_link_xdp_fd(ifindex, fd, flags);
+}
 #endif
diff --git a/drivers/net/af_xdp/meson.build b/drivers/net/af_xdp/meson.build
index 1e0de23705..6075a69c00 100644
--- a/drivers/net/af_xdp/meson.build
+++ b/drivers/net/af_xdp/meson.build
@@ -25,7 +25,7 @@ if cc.has_header('linux/if_xdp.h')
             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']
+                cflags += ['-DRTE_NET_AF_XDP_LIBBPF_V070']
             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 fce649c2a1..355130087a 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -866,20 +866,6 @@ eth_stats_reset(struct rte_eth_dev *dev)
 	return 0;
 }
 
-static void
-remove_xdp_program(struct pmd_internals *internals)
-{
-	uint32_t curr_prog_id = 0;
-
-	if (bpf_get_link_xdp_id(internals->if_index, &curr_prog_id,
-				XDP_FLAGS_UPDATE_IF_NOEXIST)) {
-		AF_XDP_LOG(ERR, "bpf_get_link_xdp_id failed\n");
-		return;
-	}
-	bpf_set_link_xdp_fd(internals->if_index, -1,
-			XDP_FLAGS_UPDATE_IF_NOEXIST);
-}
-
 static void
 xdp_umem_destroy(struct xsk_umem_info *umem)
 {
@@ -932,7 +918,8 @@ eth_dev_close(struct rte_eth_dev *dev)
 	 */
 	dev->data->mac_addrs = NULL;
 
-	remove_xdp_program(internals);
+	if (remove_xdp_program(internals->if_index))
+		AF_XDP_LOG(ERR, "Error while removing XDP program.\n");
 
 	if (internals->shared_umem) {
 		struct internal_list *list;
@@ -1198,7 +1185,7 @@ load_custom_xdp_prog(const char *prog_path, int if_index, struct bpf_map **map)
 	}
 
 	/* Link the program with the given network device */
-	ret = bpf_set_link_xdp_fd(if_index, prog_fd,
+	ret = link_xdp_prog_with_dev(if_index, prog_fd,
 					XDP_FLAGS_UPDATE_IF_NOEXIST);
 	if (ret) {
 		AF_XDP_LOG(ERR, "Failed to set prog fd %d on interface\n",
-- 
2.25.1


  parent reply	other threads:[~2022-06-28 12:19 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-24 10:23 [PATCH] " Ciara Loftus
2022-06-24 11:45 ` Andrew Rybchenko
2022-06-27 14:17   ` Loftus, Ciara
2022-06-27 14:50     ` Andrew Rybchenko
2022-06-27 15:24       ` Loftus, Ciara
2022-06-28  9:15         ` Andrew Rybchenko
2022-06-28 10:07           ` Loftus, Ciara
2022-07-21 12:16             ` Loftus, Ciara
2022-06-28 12:18 ` Ciara Loftus [this message]
2022-10-05  9:50 ` [PATCH v3 0/6] " Andrew Rybchenko
2022-10-05  9:50   ` [PATCH v3] mempool: fix get objects from mempool with cache Andrew Rybchenko
2022-10-05  9:56     ` Andrew Rybchenko
2022-10-05  9:50   ` [PATCH v3 1/6] net/af_xdp: move XDP library presence flag to right branch Andrew Rybchenko
2022-10-05  9:50   ` [PATCH v3 2/6] net/af_xdp: make it clear which libxdp version is required Andrew Rybchenko
2022-10-05  9:50   ` [PATCH v3 3/6] net/af_xdp: avoid version-based check for shared UMEM Andrew Rybchenko
2022-10-05  9:50   ` [PATCH v3 4/6] net/af_xdp: avoid version-based check for program load mech Andrew Rybchenko
2022-10-05  9:50   ` [PATCH v3 5/6] net/af_xdp: log errors on XDP program removal failures Andrew Rybchenko
2022-10-05  9:50   ` [PATCH v3 6/6] net/af_xdp: make compatible with libbpf v0.8.0 Andrew Rybchenko
2022-10-06  6:26 ` [PATCH v4 0/6] " Andrew Rybchenko
2022-10-06  6:26   ` [PATCH v4 1/6] net/af_xdp: move XDP library presence flag to right branch Andrew Rybchenko
2022-10-06  6:26   ` [PATCH v4 2/6] net/af_xdp: make it clear which libxdp version is required Andrew Rybchenko
2022-10-06  6:26   ` [PATCH v4 3/6] net/af_xdp: avoid version-based check for shared UMEM Andrew Rybchenko
2022-10-06  6:26   ` [PATCH v4 4/6] net/af_xdp: avoid version-based check for program load mech Andrew Rybchenko
2022-10-06  6:26   ` [PATCH v4 5/6] net/af_xdp: log errors on XDP program removal failures Andrew Rybchenko
2022-10-06  6:26   ` [PATCH v4 6/6] net/af_xdp: make compatible with libbpf v0.8.0 Andrew Rybchenko
2022-10-07 17:19     ` Ferruh Yigit
2022-10-07 17:28       ` Ferruh Yigit
2022-10-07 17:40   ` [PATCH v4 0/6] " Ferruh Yigit
2022-12-20 14:05 ` [PATCH] " Kevin Traynor
2022-12-21  6:09   ` Andrew Rybchenko
2022-12-21  9:28     ` Kevin Traynor
2023-03-15 11:47       ` Kevin Traynor
2023-03-16 13:31         ` Kevin Traynor
2023-03-23 10:23           ` Kevin Traynor
2023-04-04 15:51       ` 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=20220628121821.1326012-1-ciara.loftus@intel.com \
    --to=ciara.loftus@intel.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@xilinx.com \
    --cc=thomas@monjalon.net \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).