From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E48DFA0032; Fri, 24 Jun 2022 12:24:09 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9DF434069D; Fri, 24 Jun 2022 12:24:09 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id C029B400EF for ; Fri, 24 Jun 2022 12:24:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656066248; x=1687602248; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=TkGFRDKgTFBzniv4L55kcJNbMsL7a7Vfm1xT/0tzdQg=; b=nWt91GtsuPEXX79wmlK/7LIu8iFSi+hT/zgp7tniKxAy9NOnU6I5rUVw jOARALH6L16iX/PSP7aeDqioCk1C+1nlZ3sALxwBpb1gmK1rGJQh18ccZ Ck+Y8nKZzT5ekpcEk/1JNLUlOaQunrNqOqo4Au3sYUOCsLutcjZD7LMwG fhgUA5z7zEjo7Ffp11mD0SVzi41QHIR1DucwJKhQetREkQGlG0q3FJv38 0cH/hLWay29mxJZ13taUBhYXy738Dp4bL8B9e/2qyFQsICjwGyKATVGjB svSzOunynCvhRATrFMzQQKbcnUkYLr63YeKVgMD8ZE6/emvlwBgEfEoAm A==; X-IronPort-AV: E=McAfee;i="6400,9594,10387"; a="281015601" X-IronPort-AV: E=Sophos;i="5.92,218,1650956400"; d="scan'208";a="281015601" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2022 03:24:07 -0700 X-IronPort-AV: E=Sophos;i="5.92,218,1650956400"; d="scan'208";a="593166224" Received: from silpixa00401086.ir.intel.com ([10.55.128.124]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2022 03:24:05 -0700 From: Ciara Loftus To: dev@dpdk.org Cc: thomas@monjalon.net, ferruh.yigit@xilinx.com, Ciara Loftus Subject: [PATCH] net/af_xdp: make compatible with libbpf v0.8.0 Date: Fri, 24 Jun 2022 10:23:54 +0000 Message-Id: <20220624102354.1516606-1-ciara.loftus@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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. Also prevent linking with libbpf versions > v0.8.0. Signed-off-by: Ciara Loftus --- doc/guides/nics/af_xdp.rst | 3 ++- drivers/net/af_xdp/compat.h | 36 ++++++++++++++++++++++++++++- drivers/net/af_xdp/meson.build | 7 ++---- drivers/net/af_xdp/rte_eth_af_xdp.c | 19 +++------------ 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/doc/guides/nics/af_xdp.rst b/doc/guides/nics/af_xdp.rst index 56681c8365..9edb48df67 100644 --- a/doc/guides/nics/af_xdp.rst +++ b/doc/guides/nics/af_xdp.rst @@ -43,7 +43,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/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..349f8e7c12 100644 --- a/drivers/net/af_xdp/meson.build +++ b/drivers/net/af_xdp/meson.build @@ -10,10 +10,7 @@ endif sources = files('rte_eth_af_xdp.c') xdp_dep = dependency('libxdp', version : '>=1.2.2', required: false, method: 'pkg-config') -bpf_dep = dependency('libbpf', required: false, method: 'pkg-config') -if not bpf_dep.found() - bpf_dep = cc.find_library('bpf', required: false) -endif +bpf_dep = dependency('libbpf', version : '<=0.8.0', required: false, method: 'pkg-config') if cc.has_header('linux/if_xdp.h') if xdp_dep.found() and cc.has_header('xdp/xsk.h') @@ -25,7 +22,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 1e37da6e84..943d5c9838 100644 --- a/drivers/net/af_xdp/rte_eth_af_xdp.c +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c @@ -863,20 +863,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) { @@ -929,7 +915,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; @@ -1195,7 +1182,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