From patchwork Thu Feb 17 12:14:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Loftus, Ciara" X-Patchwork-Id: 107733 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 62F5BA00BE; Thu, 17 Feb 2022 13:15:06 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E8A134115C; Thu, 17 Feb 2022 13:15:05 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 020044115A for ; Thu, 17 Feb 2022 13:15:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645100105; x=1676636105; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=imIIQX2yHikh3isM+f+BT+LKQTwrjkcmJq7rFuozN38=; b=G8QVDt/W4Wer1xtD3soAWUI98dRnIDfH60hoB6BrqvPG0Pztecn5FT50 8Xc0LwS18WbaAbEBzmEe+SVmZY+GRMiqI4H/tfwUf1ksy/3KMW77uFyi8 RaK0hykVyyL25xrJq0ezSQs6CWd5WDutXIdEz6Jrxqpz1d4bI4dKJlnpe NsVvLoTPOqZWLuRqdi4RxwruQtJq2/oEOyYsrDsN9w/VxnmofP8YYaNKv uOMDhVmGyHDUarcFLb0v6f1fN3/v84xS3UkjWCpyT/UcBi4E7v0Xg9eMs d82Y3MfYOw7KcbjB80W39/99jvBm94NtQUBPG7aR1mSoiuZF66uLpnLdp A==; X-IronPort-AV: E=McAfee;i="6200,9189,10260"; a="238263507" X-IronPort-AV: E=Sophos;i="5.88,375,1635231600"; d="scan'208";a="238263507" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 04:15:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,375,1635231600"; d="scan'208";a="502119904" Received: from silpixa00399839.ir.intel.com (HELO localhost.localdomain) ([10.237.222.159]) by orsmga006.jf.intel.com with ESMTP; 17 Feb 2022 04:15:03 -0800 From: Ciara Loftus To: dev@dpdk.org Cc: Ciara Loftus Subject: [PATCH] net/af_xdp: make the PMD compatible with libbpf >= v0.7.0 Date: Thu, 17 Feb 2022 12:14:30 +0000 Message-Id: <20220217121430.17610-1-ciara.loftus@intel.com> X-Mailer: git-send-email 2.17.1 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 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_oject__load. Signed-off-by: Ciara Loftus --- 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 @@ -7,6 +7,7 @@ #else #include #endif +#include #include #include @@ -58,3 +59,41 @@ tx_syscall_needed(struct xsk_ring_prod *q __rte_unused) return 1; } #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..9fe4063b99 100644 --- a/drivers/net/af_xdp/meson.build +++ b/drivers/net/af_xdp/meson.build @@ -22,6 +22,11 @@ if cc.has_header('linux/if_xdp.h') cflags += ['-DRTE_NET_AF_XDP_SHARED_UMEM'] ext_deps += xdp_dep ext_deps += bpf_dep + bpf_ver_dep = dependency('libbpf', version : '>=0.6.0', + required: false, method: 'pkg-config') + if bpf_ver_dep.found() + cflags += ['-DRTE_NET_AF_XDP_LIBBPF_OBJ_OPEN'] + endif else build = false reason = 'missing dependency, libbpf' diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c index 6ac710c6bd..bb2a609e7f 100644 --- a/drivers/net/af_xdp/rte_eth_af_xdp.c +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c @@ -15,7 +15,6 @@ #include #include #include "af_xdp_deps.h" -#include #include #include @@ -1176,13 +1175,13 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals, 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; } /*