From patchwork Thu Oct 6 06:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Rybchenko X-Patchwork-Id: 117436 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A2143A00C2; Thu, 6 Oct 2022 08:27:39 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D989842B85; Thu, 6 Oct 2022 08:27:12 +0200 (CEST) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id 8E5B840697 for ; Thu, 6 Oct 2022 08:27:06 +0200 (CEST) Received: by shelob.oktetlabs.ru (Postfix, from userid 115) id 6244E74; Thu, 6 Oct 2022 09:27:06 +0300 (MSK) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mail1.oktetlabs.ru X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=ALL_TRUSTED, DKIM_ADSP_DISCARD, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from aros.oktetlabs.ru (aros.oktetlabs.ru [192.168.38.17]) by shelob.oktetlabs.ru (Postfix) with ESMTP id 0A5E97F; Thu, 6 Oct 2022 09:27:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru 0A5E97F Authentication-Results: shelob.oktetlabs.ru/0A5E97F; dkim=none; dkim-atps=neutral From: Andrew Rybchenko To: Ciara Loftus , Qi Zhang Cc: dev@dpdk.org, Bruce Richardson Subject: [PATCH v4 6/6] net/af_xdp: make compatible with libbpf v0.8.0 Date: Thu, 6 Oct 2022 09:26:54 +0300 Message-Id: <20221006062654.1420349-7-andrew.rybchenko@oktetlabs.ru> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221006062654.1420349-1-andrew.rybchenko@oktetlabs.ru> References: <20220624102354.1516606-1-ciara.loftus@intel.com> <20221006062654.1420349-1-andrew.rybchenko@oktetlabs.ru> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Ciara Loftus 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 Signed-off-by: Andrew Rybchenko --- 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 ', + 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",