Skip to contentSkip to conversation

common/mlx5: fix external memory pool registration

PATCH New Dmitry Kozlyuk 3 participants 3 messages Nov 2, 2021 – Nov 9, 2021 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/mlx5: fix external memory pool registration

Registration of packet mempools with RTE_PKTMBUF_POOL_PINNED_EXT_MEM was performed incorrectly: after population of such mempool chunks only contain memory for rte_mbuf structures, while pointers to actual external memory are not yet filled. MR LKeys could not be obtained for external memory addresses of such mempools. Rx datapath assumes all used mempools are registered and does not fallback to dynamic MR creation in such case, so no packets could be received.

Skip registration of extmem pools on population because it is useless. If used for Rx, they are registered at port start.
During registration, recognize such pools, inspect their mbufs and recover the pages they reside in.

While MRs for these pages may already be created by rte_dev_dma_map(), they are not reused to avoid synchronization on Rx datapath in case these MRs are changed in the database.

Fixes 690b2a88c2f7 ("common/mlx5: add mempool registration facilities")
---
 drivers/common/mlx5/mlx5_common.c    |   4 +
 drivers/common/mlx5/mlx5_common_mr.c | 113 +++++++++++++++++++++++++--
 drivers/net/mlx5/mlx5_trigger.c      |   8 +-
 3 files changed, 117 insertions(+), 8 deletions(-)
drivers/common/mlx5/mlx5_common.c +4 -0
index e6ff045c95..97df19db4e 100644
@@ -395,9 +395,13 @@ mlx5_dev_mempool_event_cb(enum rte_mempool_event event, struct rte_mempool *mp,
 			  void *arg)
 {
 	struct mlx5_common_device *cdev = arg;
+	bool extmem = rte_pktmbuf_priv_flags(mp) &
+		      RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF;
 
 	switch (event) {
 	case RTE_MEMPOOL_EVENT_READY:
+		if (extmem)
+			break;
 		if (mlx5_dev_mempool_register(cdev, mp) < 0)
 			DRV_LOG(ERR,
 				"Failed to register new mempool %s for PD %p: %s",
drivers/common/mlx5/mlx5_common_mr.c +107 -6

126 lines not on this page · raw message

drivers/net/mlx5/mlx5_trigger.c +6 -2
index d916c8addc..546b20bf86 100644
@@ -146,14 +146,18 @@ mlx5_rxq_mempool_register(struct mlx5_rxq_ctrl *rxq_ctrl)
 		return 0;
 	}
 	for (s = 0; s < rxq_ctrl->rxq.rxseg_n; s++) {
+		uint32_t flags;
+
 		mp = rxq_ctrl->rxq.rxseg[s].mp;
+		flags = rte_pktmbuf_priv_flags(mp);
 		ret = mlx5_mr_mempool_register(&priv->sh->cdev->mr_scache,
 					       priv->sh->cdev->pd, mp,
 					       &priv->mp_id);
 		if (ret < 0 && rte_errno != EEXIST)
 			return ret;
-		rte_mempool_mem_iter(mp, mlx5_rxq_mempool_register_cb,
-				     &rxq_ctrl->rxq);
+		if ((flags & RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF) == 0)
+			rte_mempool_mem_iter(mp, mlx5_rxq_mempool_register_cb,
+					&rxq_ctrl->rxq);
 	}
 	return 0;
 }
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/1 common/mlx5: fix external memory pool registration

Registration of packet mempools with RTE_PKTMBUF_POOL_PINNED_EXT_MEM was performed incorrectly: after population of such mempool chunks only contain memory for rte_mbuf structures, while pointers to actual external memory are not yet filled. MR LKeys could not be obtained for external memory addresses of such mempools. Rx datapath assumes all used mempools are registered and does not fallback to dynamic MR creation in such case, so no packets could be received.

Skip registration of extmem pools on population because it is useless. If used for Rx, they are registered at port start.
During registration, recognize such pools, inspect their mbufs and recover the pages they reside in.

While MRs for these pages may already be created by rte_dev_dma_map(), they are not reused to avoid synchronization on Rx datapath in case these MRs are changed in the database.

Fixes 690b2a88c2f7 ("common/mlx5: add mempool registration facilities")

---
v2: rebase on next-net-mlx

 drivers/common/mlx5/mlx5_common.c    |   4 +
 drivers/common/mlx5/mlx5_common_mr.c | 113 +++++++++++++++++++++++++--
 drivers/net/mlx5/mlx5_trigger.c      |   8 +-
 3 files changed, 117 insertions(+), 8 deletions(-)
drivers/common/mlx5/mlx5_common.c +4 -0
index 9c75e5f173..b9ed5ee676 100644
@@ -390,9 +390,13 @@ mlx5_dev_mempool_event_cb(enum rte_mempool_event event, struct rte_mempool *mp,
 			  void *arg)
 {
 	struct mlx5_common_device *cdev = arg;
+	bool extmem = rte_pktmbuf_priv_flags(mp) &
+		      RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF;
 
 	switch (event) {
 	case RTE_MEMPOOL_EVENT_READY:
+		if (extmem)
+			break;
 		if (mlx5_dev_mempool_register(cdev, mp) < 0)
 			DRV_LOG(ERR,
 				"Failed to register new mempool %s for PD %p: %s",
drivers/common/mlx5/mlx5_common_mr.c +107 -6

126 lines not on this page · raw message

drivers/net/mlx5/mlx5_trigger.c +6 -2
index a8dd07bdce..1952d68444 100644
@@ -146,12 +146,16 @@ mlx5_rxq_mempool_register(struct mlx5_rxq_ctrl *rxq_ctrl)
 		return 0;
 	}
 	for (s = 0; s < rxq_ctrl->rxq.rxseg_n; s++) {
+		uint32_t flags;
+
 		mp = rxq_ctrl->rxq.rxseg[s].mp;
+		flags = rte_pktmbuf_priv_flags(mp);
 		ret = mlx5_mr_mempool_register(rxq_ctrl->sh->cdev, mp);
 		if (ret < 0 && rte_errno != EEXIST)
 			return ret;
-		rte_mempool_mem_iter(mp, mlx5_rxq_mempool_register_cb,
-				     &rxq_ctrl->rxq);
+		if ((flags & RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF) == 0)
+			rte_mempool_mem_iter(mp, mlx5_rxq_mempool_register_cb,
+					&rxq_ctrl->rxq);
 	}
 	return 0;
 }
Signature · 1 line
2.25.1
#2 lore raw

Hi,

Quoted 26 lines

-----Original Message-----
From: Dmitry Kozlyuk <[email protected]>
Sent: Tuesday, November 9, 2021 12:33 PM
To: [email protected]
Cc: Raslan Darawsheh <[email protected]>; Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>
Subject: [PATCH v2] common/mlx5: fix external memory pool registration

Registration of packet mempools with RTE_PKTMBUF_POOL_PINNED_EXT_MEM
was performed incorrectly: after population of such mempool chunks only contain memory for rte_mbuf structures, while pointers to actual external memory are not yet filled. MR LKeys could not be obtained for external memory addresses of such mempools. Rx datapath assumes all used mempools are registered and does not fallback to dynamic MR creation in such case, so no packets could be received.

Skip registration of extmem pools on population because it is useless. If used for Rx, they are registered at port start.
During registration, recognize such pools, inspect their mbufs and recover the pages they reside in.

While MRs for these pages may already be created by rte_dev_dma_map(), they are not reused to avoid synchronization on Rx datapath in case these MRs are changed in the database.

Quoted 7 lines
Fixes 690b2a88c2f7 ("common/mlx5: add mempool registration facilities")

---
v2: rebase on next-net-mlx

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh