DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
To: Ciara Loftus <ciara.loftus@intel.com>, Qi Zhang <qi.z.zhang@intel.com>
Cc: dev@dpdk.org, Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH v4 6/6] net/af_xdp: make compatible with libbpf v0.8.0
Date: Thu,  6 Oct 2022 09:26:54 +0300	[thread overview]
Message-ID: <20221006062654.1420349-7-andrew.rybchenko@oktetlabs.ru> (raw)
In-Reply-To: <20221006062654.1420349-1-andrew.rybchenko@oktetlabs.ru>

From: Ciara Loftus <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
bpf_xdp_attach() is available and if so, use the recommended
replacement functions bpf_xdp_query_id(), bpf_xdp_attach()
and bpf_xdp_detach().

Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 doc/guides/rel_notes/release_22_11.rst |  4 +++
 drivers/net/af_xdp/meson.build         |  5 ++++
 drivers/net/af_xdp/rte_eth_af_xdp.c    | 38 +++++++++++++++++++++++++-
 3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/doc/guides/rel_notes/release_22_11.rst b/doc/guides/rel_notes/release_22_11.rst
index f1cc129933..490186b992 100644
--- a/doc/guides/rel_notes/release_22_11.rst
+++ b/doc/guides/rel_notes/release_22_11.rst
@@ -78,6 +78,10 @@ New Features
   Added new rte_flow action which allows application to re-route packets
   directly to the kernel without software involvement.
 
+* **Updated AF_XDP PMD.**
+
+  * Made compatible with libbpf v0.8.0 (when used with libxdp).
+
 * **Updated Intel iavf driver.**
 
   * Added flow subscription support.
diff --git a/drivers/net/af_xdp/meson.build b/drivers/net/af_xdp/meson.build
index 9d5ffab96b..858047989e 100644
--- a/drivers/net/af_xdp/meson.build
+++ b/drivers/net/af_xdp/meson.build
@@ -64,4 +64,9 @@ if build
                      dependencies : bpf_dep)
       cflags += ['-DRTE_NET_AF_XDP_LIBBPF_OBJ_OPEN']
   endif
+  if cc.has_function('bpf_xdp_attach',
+                     prefix : '#include <bpf/libbpf.h>',
+                     dependencies : bpf_dep)
+      cflags += ['-DRTE_NET_AF_XDP_LIBBPF_XDP_ATTACH']
+  endif
 endif
diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
index f7c2321a18..b6ec9bf490 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -866,6 +866,40 @@ eth_stats_reset(struct rte_eth_dev *dev)
 	return 0;
 }
 
+#ifdef RTE_NET_AF_XDP_LIBBPF_XDP_ATTACH
+
+static int link_xdp_prog_with_dev(int ifindex, int fd, __u32 flags)
+{
+	return bpf_xdp_attach(ifindex, fd, flags, NULL);
+}
+
+static int
+remove_xdp_program(struct pmd_internals *internals)
+{
+	uint32_t curr_prog_id = 0;
+	int ret;
+
+	ret = bpf_xdp_query_id(internals->if_index, XDP_FLAGS_UPDATE_IF_NOEXIST,
+			       &curr_prog_id);
+	if (ret != 0) {
+		AF_XDP_LOG(ERR, "bpf_xdp_query_id failed\n");
+		return ret;
+	}
+
+	ret = bpf_xdp_detach(internals->if_index, XDP_FLAGS_UPDATE_IF_NOEXIST,
+			     NULL);
+	if (ret != 0)
+		AF_XDP_LOG(ERR, "bpf_xdp_detach failed\n");
+	return ret;
+}
+
+#else
+
+static int link_xdp_prog_with_dev(int ifindex, int fd, __u32 flags)
+{
+	return bpf_set_link_xdp_fd(ifindex, fd, flags);
+}
+
 static int
 remove_xdp_program(struct pmd_internals *internals)
 {
@@ -886,6 +920,8 @@ remove_xdp_program(struct pmd_internals *internals)
 	return ret;
 }
 
+#endif
+
 static void
 xdp_umem_destroy(struct xsk_umem_info *umem)
 {
@@ -1205,7 +1241,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.30.2


  parent reply	other threads:[~2022-10-06  6:27 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 ` [PATCH v2] " Ciara Loftus
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   ` Andrew Rybchenko [this message]
2022-10-07 17:19     ` [PATCH v4 6/6] net/af_xdp: make compatible with libbpf v0.8.0 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=20221006062654.1420349-7-andrew.rybchenko@oktetlabs.ru \
    --to=andrew.rybchenko@oktetlabs.ru \
    --cc=bruce.richardson@intel.com \
    --cc=ciara.loftus@intel.com \
    --cc=dev@dpdk.org \
    --cc=qi.z.zhang@intel.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
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).