From patchwork Fri Nov 12 10:30:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Loftus, Ciara" X-Patchwork-Id: 104236 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 A4865A034F; Fri, 12 Nov 2021 11:30:18 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5ACB24113D; Fri, 12 Nov 2021 11:30:13 +0100 (CET) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 3B3BE40692 for ; Fri, 12 Nov 2021 11:30:11 +0100 (CET) X-IronPort-AV: E=McAfee;i="6200,9189,10165"; a="233358664" X-IronPort-AV: E=Sophos;i="5.87,229,1631602800"; d="scan'208";a="233358664" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Nov 2021 02:30:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,229,1631602800"; d="scan'208";a="643472951" Received: from silpixa00401086.ir.intel.com (HELO localhost.localdomain) ([10.55.129.110]) by fmsmga001.fm.intel.com with ESMTP; 12 Nov 2021 02:30:09 -0800 From: Ciara Loftus To: dev@dpdk.org Cc: Ciara Loftus Subject: [PATCH 2/2] net/af_xdp: workaround custom program loading issue Date: Fri, 12 Nov 2021 10:30:02 +0000 Message-Id: <20211112103002.50380-2-ciara.loftus@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211112103002.50380-1-ciara.loftus@intel.com> References: <20211112103002.50380-1-ciara.loftus@intel.com> 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 Since v0.4.0, if the underlying kernel supports it, libbpf uses 'bpf link' to manage the programs on the interfaces of the XDP sockets (xsks). This is not compatible with the PMD's custom XDP program loading feature which uses the netlink-based method for loading custom programs. The conflict arises when libbpf searches for a custom program on the interface using bpf link, but doesn't find one because the netlink method was used. libbpf then proceeds to try to load the default program on the interface, but fails due to the presence of the custom program. To work around this, the PMD now uses the XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD flag which prevents libbpf from attempting to search for or load a program. One repurcussion is that DPDK must now insert the xsk into the xsks_map as this was previously handled by libbpf during the routines for program loading/probing. Ideally, the PMD would use bpf link to load the custom program, however at present there is no convenient and reliable way of detecting whether the underlying kernel supports bpf link. Perhaps this may become available in a future libbpf release, at which point we can switch the PMD over to the new bpf link based method. Signed-off-by: Ciara Loftus --- drivers/net/af_xdp/rte_eth_af_xdp.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c index 1c7689c9b4..96c2c9d939 100644 --- a/drivers/net/af_xdp/rte_eth_af_xdp.c +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c @@ -15,6 +15,7 @@ #include #include #include "af_xdp_deps.h" +#include #include #include @@ -139,6 +140,7 @@ struct pmd_internals { bool shared_umem; char prog_path[PATH_MAX]; bool custom_prog_configured; + struct bpf_map *map; struct rte_ether_addr eth_addr; @@ -1147,11 +1149,10 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals, } static int -load_custom_xdp_prog(const char *prog_path, int if_index) +load_custom_xdp_prog(const char *prog_path, int if_index, struct bpf_map **map) { int ret, prog_fd = -1; struct bpf_object *obj; - struct bpf_map *map; ret = bpf_prog_load(prog_path, BPF_PROG_TYPE_XDP, &obj, &prog_fd); if (ret) { @@ -1161,11 +1162,10 @@ load_custom_xdp_prog(const char *prog_path, int if_index) /* * The loaded program must provision for a map of xsks, such that some - * traffic can be redirected to userspace. When the xsk is created, - * libbpf inserts it into the map. + * traffic can be redirected to userspace. */ - map = bpf_object__find_map_by_name(obj, "xsks_map"); - if (!map) { + *map = bpf_object__find_map_by_name(obj, "xsks_map"); + if (!*map) { AF_XDP_LOG(ERR, "Failed to find xsks_map in %s\n", prog_path); return -1; } @@ -1272,13 +1272,15 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq, if (strnlen(internals->prog_path, PATH_MAX) && !internals->custom_prog_configured) { ret = load_custom_xdp_prog(internals->prog_path, - internals->if_index); + internals->if_index, + &internals->map); if (ret) { AF_XDP_LOG(ERR, "Failed to load custom XDP program %s\n", internals->prog_path); goto err; } internals->custom_prog_configured = 1; + cfg.libbpf_flags = XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD; } if (internals->shared_umem) @@ -1295,6 +1297,19 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq, goto err; } + /* insert the xsk into the xsks_map */ + if (internals->custom_prog_configured) { + int err, fd; + + fd = xsk_socket__fd(rxq->xsk); + err = bpf_map_update_elem(bpf_map__fd(internals->map), + &rxq->xsk_queue_idx, &fd, 0); + if (err) { + AF_XDP_LOG(ERR, "Failed to insert xsk in map.\n"); + goto err; + } + } + #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG) ret = rte_pktmbuf_alloc_bulk(rxq->umem->mb_pool, fq_bufs, reserve_size); if (ret) {