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 C3DACA0524 for ; Fri, 5 Feb 2021 12:20:59 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BECFE1606C3; Fri, 5 Feb 2021 12:20:59 +0100 (CET) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by mails.dpdk.org (Postfix) with ESMTP id E04731606BA for ; Fri, 5 Feb 2021 12:20:57 +0100 (CET) Received: by mail-wm1-f52.google.com with SMTP id u14so5604686wmq.4 for ; Fri, 05 Feb 2021 03:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ruB3lHNIF++u+3x6EJ4TiFbQaGVpemISmIUT08hpZNk=; b=oIWkfYIrftD+38eZuoxRziZEHHZMI5QXSLWSdTVlR8ZsmeDFx+/QpYdiXsUaeHfVst sRP4khM7gbtkeRjqBNVku3yuyHSpnJErKDkyMdfcNeos4lob7+AXvGVq8Coaz7KHAIb6 TERxLlTDq6TWSTpaaAnQO7Jkp8jFjJcDnNcD5k94sCKMZlUEAIA03liDqcs1VVLhASVl fag7dKWH+45d6hwaYVMF5NNlK7htRNNicqib2iwzD9Bvzww0PyOfYL34vMpjnRY5CxXj tSaHnwfW/Oakh4hZCD6i5YlNtgpPismG5L9ML9FyrQCkOLk1/I6TvaVOhp1L0dEjnIDj UPQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ruB3lHNIF++u+3x6EJ4TiFbQaGVpemISmIUT08hpZNk=; b=sIlG+bx3TiQkLjohfOphga1JnP0HUlmYPCPOS+oC8BPH/9EDzn/rSrH2Ulj8ysfZ0A OKToQIZyeh+ia8LeHn11cywKkquEj487ka9i7CAogpFc7ny3ySOzlDFv8ha3JA7KCo7S 44lSMh26TjzqjGpcjhjpVC9gzTHAd5b79VHc33MPh0tjpWXZ2qAlep6g+BgdIA1/E6mZ xlAZnOfD6SjtzBS21XlsDnSdmVbgSB0Xo0zUUuSAJcsCi8Ih63xM7DEN5JH7lX5I3lGi 7z0pZ2H07T4gWo0GJ7XiC62ucAQgsNzAeqf2GGBolFu/GkAFm9Ozp5Gp8QIUFby5SgzB afXg== X-Gm-Message-State: AOAM531UHa1GAwPzd+352/ucgYSRIGtfXBYyNiv/JKQlUrhImzxLN5td x/B3SZYLR4B5ZG47Oc+gMBgFsRQLfvdMN+lf X-Google-Smtp-Source: ABdhPJyzVFFaVXaAWd94dsFTPsewJz8BbYQ2nHPvtWpFoHEOQSl3T/3NM+Xn+KE0sJZfBl1oGY0peQ== X-Received: by 2002:a1c:1fca:: with SMTP id f193mr3236149wmf.102.1612524057668; Fri, 05 Feb 2021 03:20:57 -0800 (PST) Received: from localhost ([88.98.246.218]) by smtp.gmail.com with ESMTPSA id t17sm8575207wmi.46.2021.02.05.03.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 03:20:56 -0800 (PST) From: luca.boccassi@gmail.com To: Viacheslav Ovsiienko Cc: Matan Azrad , dpdk stable Date: Fri, 5 Feb 2021 11:15:16 +0000 Message-Id: <20210205111920.1272063-30-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210205111920.1272063-1-luca.boccassi@gmail.com> References: <20210205111920.1272063-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'net/mlx5: fix Verbs memory allocation callback' has been queued to stable release 20.11.1 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 Sender: "stable" Hi, FYI, your patch has been queued to stable release 20.11.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 02/07/21. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/bluca/dpdk-stable This queued commit can be viewed at: https://github.com/bluca/dpdk-stable/commit/ccbc4125d8dcbf2ff347907e20f3fbd280d10fd7 Thanks. Luca Boccassi --- >From ccbc4125d8dcbf2ff347907e20f3fbd280d10fd7 Mon Sep 17 00:00:00 2001 From: Viacheslav Ovsiienko Date: Tue, 24 Nov 2020 10:26:43 +0000 Subject: [PATCH] net/mlx5: fix Verbs memory allocation callback [ upstream commit 81c3b97735c26b575f8167f2b892edd3a7af451b ] The rdma-core library uses callbacks to allocate and free memory from DPDK. The memory allocation callback used the complicated and incorrect way to get the NUMA socket ID from the context. The context was wrong that might result in wrong socket ID and allocating memory from wrong node. The callbacks are assigned once as Infinibande device context is created allowing early access to shared DPDK memory for all Verbs internal objects need that. Fixes: 36dabcea78f0 ("net/mlx5: use anonymous Direct Verbs allocator argument") Fixes: 2eb4d0107acc ("net/mlx5: refactor PCI probing on Linux") Fixes: 17e19bc4dde7 ("net/mlx5: add IB shared context alloc/free functions") Signed-off-by: Viacheslav Ovsiienko Acked-by: Matan Azrad --- drivers/net/mlx5/linux/mlx5_os.c | 27 +++++++++++++-------------- drivers/net/mlx5/linux/mlx5_verbs.c | 8 -------- drivers/net/mlx5/mlx5.h | 19 ------------------- 3 files changed, 13 insertions(+), 41 deletions(-) diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index 4c863db1a7..9062191dd1 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -168,9 +168,8 @@ mlx5_os_get_dev_attr(void *ctx, struct mlx5_dev_attr *device_attr) static void * mlx5_alloc_verbs_buf(size_t size, void *data) { - struct mlx5_priv *priv = data; + struct mlx5_dev_ctx_shared *sh = data; void *ret; - unsigned int socket = SOCKET_ID_ANY; size_t alignment = rte_mem_page_size(); if (alignment == (size_t)-1) { DRV_LOG(ERR, "Failed to get mem page size"); @@ -178,18 +177,8 @@ mlx5_alloc_verbs_buf(size_t size, void *data) return NULL; } - if (priv->verbs_alloc_ctx.type == MLX5_VERBS_ALLOC_TYPE_TX_QUEUE) { - const struct mlx5_txq_ctrl *ctrl = priv->verbs_alloc_ctx.obj; - - socket = ctrl->socket; - } else if (priv->verbs_alloc_ctx.type == - MLX5_VERBS_ALLOC_TYPE_RX_QUEUE) { - const struct mlx5_rxq_ctrl *ctrl = priv->verbs_alloc_ctx.obj; - - socket = ctrl->socket; - } MLX5_ASSERT(data != NULL); - ret = mlx5_malloc(0, size, alignment, socket); + ret = mlx5_malloc(0, size, alignment, sh->numa_node); if (!ret && size) rte_errno = ENOMEM; return ret; @@ -1459,7 +1448,7 @@ err_secondary: (void *)((uintptr_t)&(struct mlx5dv_ctx_allocators){ .alloc = &mlx5_alloc_verbs_buf, .free = &mlx5_free_verbs_buf, - .data = priv, + .data = sh, })); /* Bring Ethernet device up. */ DRV_LOG(DEBUG, "port %u forcing Ethernet interface up", @@ -2324,6 +2313,16 @@ mlx5_os_open_device(const struct mlx5_dev_spawn_data *spawn, DRV_LOG(DEBUG, "DevX is NOT supported"); err = 0; } + if (!err && sh->ctx) { + /* Hint libmlx5 to use PMD allocator for data plane resources */ + mlx5_glue->dv_set_context_attr(sh->ctx, + MLX5DV_CTX_ATTR_BUF_ALLOCATORS, + (void *)((uintptr_t)&(struct mlx5dv_ctx_allocators){ + .alloc = &mlx5_alloc_verbs_buf, + .free = &mlx5_free_verbs_buf, + .data = sh, + })); + } return err; } diff --git a/drivers/net/mlx5/linux/mlx5_verbs.c b/drivers/net/mlx5/linux/mlx5_verbs.c index 540ce32990..9161fa3b7d 100644 --- a/drivers/net/mlx5/linux/mlx5_verbs.c +++ b/drivers/net/mlx5/linux/mlx5_verbs.c @@ -366,8 +366,6 @@ mlx5_rxq_ibv_obj_new(struct rte_eth_dev *dev, uint16_t idx) MLX5_ASSERT(rxq_data); MLX5_ASSERT(tmpl); - priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_RX_QUEUE; - priv->verbs_alloc_ctx.obj = rxq_ctrl; tmpl->rxq_ctrl = rxq_ctrl; if (rxq_ctrl->irq) { tmpl->ibv_channel = @@ -438,7 +436,6 @@ mlx5_rxq_ibv_obj_new(struct rte_eth_dev *dev, uint16_t idx) rxq_data->cq_arm_sn = 0; mlx5_rxq_initialize(rxq_data); rxq_data->cq_ci = 0; - priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_NONE; dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED; rxq_ctrl->wqn = ((struct ibv_wq *)(tmpl->wq))->wq_num; return 0; @@ -451,7 +448,6 @@ error: if (tmpl->ibv_channel) claim_zero(mlx5_glue->destroy_comp_channel(tmpl->ibv_channel)); rte_errno = ret; /* Restore rte_errno. */ - priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_NONE; return -rte_errno; } @@ -932,8 +928,6 @@ mlx5_txq_ibv_obj_new(struct rte_eth_dev *dev, uint16_t idx) MLX5_ASSERT(txq_data); MLX5_ASSERT(txq_obj); txq_obj->txq_ctrl = txq_ctrl; - priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_TX_QUEUE; - priv->verbs_alloc_ctx.obj = txq_ctrl; if (mlx5_getenv_int("MLX5_ENABLE_CQE_COMPRESSION")) { DRV_LOG(ERR, "Port %u MLX5_ENABLE_CQE_COMPRESSION " "must never be set.", dev->data->port_id); @@ -1039,7 +1033,6 @@ mlx5_txq_ibv_obj_new(struct rte_eth_dev *dev, uint16_t idx) } txq_uar_init(txq_ctrl); dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED; - priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_NONE; return 0; error: ret = rte_errno; /* Save rte_errno before cleanup. */ @@ -1047,7 +1040,6 @@ error: claim_zero(mlx5_glue->destroy_cq(txq_obj->cq)); if (txq_obj->qp) claim_zero(mlx5_glue->destroy_qp(txq_obj->qp)); - priv->verbs_alloc_ctx.type = MLX5_VERBS_ALLOC_TYPE_NONE; rte_errno = ret; /* Restore rte_errno. */ return -rte_errno; } diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 041240e6fe..121d726405 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -258,30 +258,12 @@ struct mlx5_dev_config { }; -/** - * Type of object being allocated. - */ -enum mlx5_verbs_alloc_type { - MLX5_VERBS_ALLOC_TYPE_NONE, - MLX5_VERBS_ALLOC_TYPE_TX_QUEUE, - MLX5_VERBS_ALLOC_TYPE_RX_QUEUE, -}; - /* Structure for VF VLAN workaround. */ struct mlx5_vf_vlan { uint32_t tag:12; uint32_t created:1; }; -/** - * Verbs allocator needs a context to know in the callback which kind of - * resources it is allocating. - */ -struct mlx5_verbs_alloc_ctx { - enum mlx5_verbs_alloc_type type; /* Kind of object being allocated. */ - const void *obj; /* Pointer to the DPDK object. */ -}; - /* Flow drop context necessary due to Verbs API. */ struct mlx5_drop { struct mlx5_hrxq *hrxq; /* Hash Rx queue queue. */ @@ -989,7 +971,6 @@ struct mlx5_priv { struct mlx5_xstats_ctrl xstats_ctrl; /* Extended stats control. */ struct mlx5_stats_ctrl stats_ctrl; /* Stats control. */ struct mlx5_dev_config config; /* Device configuration. */ - struct mlx5_verbs_alloc_ctx verbs_alloc_ctx; /* Context for Verbs allocator. */ int nl_socket_rdma; /* Netlink socket (NETLINK_RDMA). */ int nl_socket_route; /* Netlink socket (NETLINK_ROUTE). */ -- 2.29.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2021-02-05 11:18:30.641544091 +0000 +++ 0030-net-mlx5-fix-Verbs-memory-allocation-callback.patch 2021-02-05 11:18:28.646688066 +0000 @@ -1 +1 @@ -From 81c3b97735c26b575f8167f2b892edd3a7af451b Mon Sep 17 00:00:00 2001 +From ccbc4125d8dcbf2ff347907e20f3fbd280d10fd7 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 81c3b97735c26b575f8167f2b892edd3a7af451b ] + @@ -19 +20,0 @@ -Cc: stable@dpdk.org