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 5FF97A0503 for ; Fri, 6 May 2022 13:03:56 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5954B4014F; Fri, 6 May 2022 13:03:56 +0200 (CEST) Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.133.74]) by mails.dpdk.org (Postfix) with ESMTP id E37014014F for ; Fri, 6 May 2022 13:03:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651835034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4uyVFC5a3VfBFfs3FHp6RZHTZYgWT2a2HEzpn0lN0Fk=; b=gT8jSappjkc6QYyig2Ra1Tuv8+W4NWEySugNXgAV3xJkvGzJ+gGxSA1u1FbDPECebciZdt DfDrCU87QKCrpzoIyIFdxBasGKBnpgezem8BHnRGW87y28arhaICbdfJeTSJL1IsqQ0Ing x2gXV75eiiwFNou/qOem3BReubwgFys= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-44-1cMSV0mQObSWKxJNQ_M4SQ-1; Fri, 06 May 2022 07:03:51 -0400 X-MC-Unique: 1cMSV0mQObSWKxJNQ_M4SQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 37A012999B4D; Fri, 6 May 2022 11:03:51 +0000 (UTC) Received: from rh.redhat.com (unknown [10.39.195.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD37C1121315; Fri, 6 May 2022 11:03:48 +0000 (UTC) From: Kevin Traynor To: ciara.loftus@intel.com, stable@dpdk.org Cc: bluca@debian.org, christian.ehrhardt@canonical.com, xuemingl@nvidia.com Subject: [PATCH 21.11 2/2] net/af_xdp: make compatible with libbpf >= 0.7.0 Date: Fri, 6 May 2022 12:03:37 +0100 Message-Id: <20220506110337.267796-3-ktraynor@redhat.com> In-Reply-To: <20220506110337.267796-1-ktraynor@redhat.com> References: <20220506110337.267796-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ktraynor@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org From: Ciara Loftus [ upstream commit 8d3d9c72513ac116996a05700f18c10b332e7699 ] 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_object__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 @@ -8,4 +8,5 @@ #include #endif +#include #include #include @@ -59,2 +60,40 @@ tx_syscall_needed(struct xsk_ring_prod *q __rte_unused) } #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..1e0de23705 100644 --- a/drivers/net/af_xdp/meson.build +++ b/drivers/net/af_xdp/meson.build @@ -23,4 +23,9 @@ if cc.has_header('linux/if_xdp.h') ext_deps += xdp_dep ext_deps += bpf_dep + 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'] + 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 0366211243..9db76d4562 100644 --- a/drivers/net/af_xdp/rte_eth_af_xdp.c +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c @@ -16,5 +16,4 @@ #include #include "af_xdp_deps.h" -#include #include @@ -1150,11 +1149,11 @@ 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; } -- 2.34.1