Skip to contentSkip to conversation

support RTE_ETH_DEV_CLOSE_REMOVE flag for AF_XDP

PATCH Superseded Xiaolong Ye 3 participants 17 messages Apr 26, 2019 – Apr 30, 2019 Network drivers

lore
Share & tools
lore
#0 lore raw

cover support RTE_ETH_DEV_CLOSE_REMOVE flag for AF_XDP

Hi,

This series is to support the RTE_ETH_DEV_CLOSE_REMOVE in AF_XDP pmd.

Xiaolong Ye (2):
net/af_xdp: remove resources when port is closed net/af_xdp: set MAC addrs field to NULL

 drivers/net/af_xdp/rte_eth_af_xdp.c | 47 +++++++++++++++--------------
 1 file changed, 25 insertions(+), 22 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 net/af_xdp: remove resources when port is closed

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 41 +++++++++++++----------------
 1 file changed, 19 insertions(+), 22 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +19 -22
index acf9ad605..a12551cbf 100644
@@ -426,6 +426,19 @@ remove_xdp_program(struct pmd_internals *internals)
 			XDP_FLAGS_UPDATE_IF_NOEXIST);
 }
 
+static void
+xdp_umem_destroy(struct xsk_umem_info *umem)
+{
+	rte_memzone_free(umem->mz);
+	umem->mz = NULL;
+
+	rte_ring_free(umem->buf_ring);
+	umem->buf_ring = NULL;
+
+	rte_free(umem);
+	umem = NULL;
+}
+
 static void
 eth_dev_close(struct rte_eth_dev *dev)
 {
@@ -444,6 +457,9 @@ eth_dev_close(struct rte_eth_dev *dev)
 	}
 
 	(void)xsk_umem__delete(internals->umem->umem);
+
+	xdp_umem_destroy(internals->umem);
+
 	remove_xdp_program(internals);
 }
 
@@ -459,19 +475,6 @@ eth_link_update(struct rte_eth_dev *dev __rte_unused,
 	return 0;
 }
 
-static void
-xdp_umem_destroy(struct xsk_umem_info *umem)
-{
-	rte_memzone_free(umem->mz);
-	umem->mz = NULL;
-
-	rte_ring_free(umem->buf_ring);
-	umem->buf_ring = NULL;
-
-	rte_free(umem);
-	umem = NULL;
-}
-
 static struct
 xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals)
 {
@@ -856,6 +859,8 @@ init_internals(struct rte_vdev_device *dev,
 	eth_dev->dev_ops = &ops;
 	eth_dev->rx_pkt_burst = eth_af_xdp_rx;
 	eth_dev->tx_pkt_burst = eth_af_xdp_tx;
+	/* Let rte_eth_dev_close() release the port resources. */
+	eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
 
 	return eth_dev;
 
@@ -923,7 +928,6 @@ static int
 rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
-	struct pmd_internals *internals;
 
 	AF_XDP_LOG(INFO, "Removing AF_XDP ethdev on numa socket %u\n",
 		rte_socket_id());
@@ -936,14 +940,7 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return -1;
 
-	internals = eth_dev->data->dev_private;
-
-	rte_ring_free(internals->umem->buf_ring);
-	rte_memzone_free(internals->umem->mz);
-	rte_free(internals->umem);
-
-	rte_eth_dev_release_port(eth_dev);
-
+	eth_dev_close(eth_dev);
 
 	return 0;
 }
Signature · 1 line
2.17.1
#2 lore raw

Re: [dpdk-dev] [PATCH v1 1/2] net/af_xdp: remove resources when port is closed

Quoted 10 lines · Xiaolong Ye

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c rte_pmd_af_xdp_remove(struct rte_vdev_device *dev) · line 945

Quoted 11 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -7
@@ -936,14 +940,7 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return -1;
 
-	internals = eth_dev->data->dev_private;
-
-	rte_ring_free(internals->umem->buf_ring);
-	rte_memzone_free(internals->umem->mz);
-	rte_free(internals->umem);
-
-	rte_eth_dev_release_port(eth_dev);

I thinks we should keep 'rte_eth_dev_release_port()' in '.remove()' path, the 'RTE_ETH_DEV_CLOSE_REMOVE' flag will take care of this in 'rte_eth_dev_close()' but still needed in '.remove()' path.

Quoted 6 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -1
-
+	eth_dev_close(eth_dev);
 
 	return 0;
 }
#3 lore raw

Re: [dpdk-dev] [PATCH v1 1/2] net/af_xdp: remove resources when port is closed

29/04/2019 19:00, Ferruh Yigit:

Quoted 18 lines · Xiaolong Ye
Quoted 10 lines

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

<...>

Quoted 4 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -0
@@ -936,14 +940,7 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return -1;
 
Quoted 11 lines

drivers/net/af_xdp/rte_eth_af_xdp.c rte_pmd_af_xdp_remove(struct rte_vdev_device *dev) · line 945

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -7
-	internals = eth_dev->data->dev_private;
-
-	rte_ring_free(internals->umem->buf_ring);
-	rte_memzone_free(internals->umem->mz);
-	rte_free(internals->umem);
-
-	rte_eth_dev_release_port(eth_dev);

I thinks we should keep 'rte_eth_dev_release_port()' in '.remove()' path, the 'RTE_ETH_DEV_CLOSE_REMOVE' flag will take care of this in 'rte_eth_dev_close()' but still needed in '.remove()' path.

I don't understand your comment.
Calling the close function looks the right thing to do in "remove".

Quoted 2 lines
Quoted 2 lines
(quoted diff) +1 -1
-
+	eth_dev_close(eth_dev);
#4 lore raw

Re: [dpdk-dev] [PATCH v1 1/2] net/af_xdp: remove resources when port is closed

Quoted 31 lines · Thomas Monjalon

29/04/2019 19:00, Ferruh Yigit:

Quoted 18 lines · Xiaolong Ye
Quoted 10 lines

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

<...>

Quoted 4 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -0
@@ -936,14 +940,7 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return -1;
 
Quoted 11 lines

drivers/net/af_xdp/rte_eth_af_xdp.c rte_pmd_af_xdp_remove(struct rte_vdev_device *dev) · line 945

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -7
-	internals = eth_dev->data->dev_private;
-
-	rte_ring_free(internals->umem->buf_ring);
-	rte_memzone_free(internals->umem->mz);
-	rte_free(internals->umem);
-
-	rte_eth_dev_release_port(eth_dev);

I thinks we should keep 'rte_eth_dev_release_port()' in '.remove()' path, the 'RTE_ETH_DEV_CLOSE_REMOVE' flag will take care of this in 'rte_eth_dev_close()' but still needed in '.remove()' path.

Quoted 2 lines

I don't understand your comment.
Calling the close function looks the right thing to do in "remove".

No concern on calling the 'close'.
My comment was to keep 'rte_eth_dev_release_port()' which this patch removes.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +1 -1
-
+	eth_dev_close(eth_dev);
#5 lore raw

Re: [dpdk-dev] [PATCH v1 1/2] net/af_xdp: remove resources when port is closed

30/04/2019 00:28, Ferruh Yigit:

Quoted 32 lines · Thomas Monjalon
Quoted 31 lines

29/04/2019 19:00, Ferruh Yigit:

Quoted 29 lines · Xiaolong Ye
Quoted 10 lines

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c rte_pmd_af_xdp_remove(struct rte_vdev_device *dev) · line 945

Quoted 11 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -7
@@ -936,14 +940,7 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return -1;
 
-	internals = eth_dev->data->dev_private;
-
-	rte_ring_free(internals->umem->buf_ring);
-	rte_memzone_free(internals->umem->mz);
-	rte_free(internals->umem);
-
-	rte_eth_dev_release_port(eth_dev);

I thinks we should keep 'rte_eth_dev_release_port()' in '.remove()' path, the 'RTE_ETH_DEV_CLOSE_REMOVE' flag will take care of this in 'rte_eth_dev_close()' but still needed in '.remove()' path.

Quoted 5 lines
Quoted 2 lines

I don't understand your comment.
Calling the close function looks the right thing to do in "remove".

No concern on calling the 'close'.
My comment was to keep 'rte_eth_dev_release_port()' which this patch removes.

rte_eth_dev_release_port() is called in eth_dev_close(), isn't it?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(quoted diff) +1 -1
-
+	eth_dev_close(eth_dev);
#6 lore raw

Re: [dpdk-dev] [PATCH v1 1/2] net/af_xdp: remove resources when port is closed

Quoted 33 lines · Thomas Monjalon

30/04/2019 00:28, Ferruh Yigit:

Quoted 32 lines · Thomas Monjalon
Quoted 31 lines

29/04/2019 19:00, Ferruh Yigit:

Quoted 29 lines · Xiaolong Ye
Quoted 10 lines

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c rte_pmd_af_xdp_remove(struct rte_vdev_device *dev) · line 945

Quoted 11 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -7
@@ -936,14 +940,7 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return -1;
 
-	internals = eth_dev->data->dev_private;
-
-	rte_ring_free(internals->umem->buf_ring);
-	rte_memzone_free(internals->umem->mz);
-	rte_free(internals->umem);
-
-	rte_eth_dev_release_port(eth_dev);

I thinks we should keep 'rte_eth_dev_release_port()' in '.remove()' path, the 'RTE_ETH_DEV_CLOSE_REMOVE' flag will take care of this in 'rte_eth_dev_close()' but still needed in '.remove()' path.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I don't understand your comment.
Calling the close function looks the right thing to do in "remove".

No concern on calling the 'close'.
My comment was to keep 'rte_eth_dev_release_port()' which this patch removes.

rte_eth_dev_release_port() is called in eth_dev_close(), isn't it?

No, 'eth_dev_close()' is local 'dev_close()' ops, the one to clear driver private resources.
I assume it is confused with 'rte_eth_dev_close()' ...

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +1 -1
-
+	eth_dev_close(eth_dev);
#7 lore raw

Re: [dpdk-dev] [PATCH v1 1/2] net/af_xdp: remove resources when port is closed

30/04/2019 09:33, Ferruh Yigit:

Quoted 40 lines · Thomas Monjalon
Quoted 39 lines

30/04/2019 00:28, Ferruh Yigit:

Quoted 37 lines · Thomas Monjalon
Quoted 31 lines

29/04/2019 19:00, Ferruh Yigit:

Quoted 18 lines · Xiaolong Ye
Quoted 10 lines

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

<...>

Quoted 4 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -0
@@ -936,14 +940,7 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return -1;
 
Quoted 11 lines

drivers/net/af_xdp/rte_eth_af_xdp.c rte_pmd_af_xdp_remove(struct rte_vdev_device *dev) · line 945

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -7
-	internals = eth_dev->data->dev_private;
-
-	rte_ring_free(internals->umem->buf_ring);
-	rte_memzone_free(internals->umem->mz);
-	rte_free(internals->umem);
-
-	rte_eth_dev_release_port(eth_dev);

I thinks we should keep 'rte_eth_dev_release_port()' in '.remove()' path, the 'RTE_ETH_DEV_CLOSE_REMOVE' flag will take care of this in 'rte_eth_dev_close()' but still needed in '.remove()' path.

Quoted 2 lines

I don't understand your comment.
Calling the close function looks the right thing to do in "remove".

No concern on calling the 'close'.
My comment was to keep 'rte_eth_dev_release_port()' which this patch removes.

Quoted 8 lines
Quoted 1 line

rte_eth_dev_release_port() is called in eth_dev_close(), isn't it?

No, 'eth_dev_close()' is local 'dev_close()' ops, the one to clear driver private resources.
I assume it is confused with 'rte_eth_dev_close()' ...

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review rte_pmd_af_xdp_remove(struct rte_vdev_device *dev) · line 943

Quoted 2 lines
(quoted diff) +1 -1
-
+	eth_dev_close(eth_dev);

Ah yes, I overlooked it.
Why not calling rte_eth_dev_close()?

#8 lore raw

Re: [dpdk-dev] [PATCH v1 1/2] net/af_xdp: remove resources when port is closed

Quoted 47 lines · Thomas Monjalon

30/04/2019 09:33, Ferruh Yigit:

Quoted 46 lines · Thomas Monjalon
Quoted 33 lines

30/04/2019 00:28, Ferruh Yigit:

Quoted 32 lines · Thomas Monjalon
Quoted 31 lines

29/04/2019 19:00, Ferruh Yigit:

Quoted 29 lines · Xiaolong Ye
Quoted 10 lines

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

<...>

Review rte_pmd_af_xdp_remove(struct rte_vdev_device *dev) · line 945

Quoted 11 lines
(quoted diff) +0 -7
@@ -936,14 +940,7 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return -1;
 
-	internals = eth_dev->data->dev_private;
-
-	rte_ring_free(internals->umem->buf_ring);
-	rte_memzone_free(internals->umem->mz);
-	rte_free(internals->umem);
-
-	rte_eth_dev_release_port(eth_dev);

I thinks we should keep 'rte_eth_dev_release_port()' in '.remove()' path, the 'RTE_ETH_DEV_CLOSE_REMOVE' flag will take care of this in 'rte_eth_dev_close()' but still needed in '.remove()' path.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I don't understand your comment.
Calling the close function looks the right thing to do in "remove".

No concern on calling the 'close'.
My comment was to keep 'rte_eth_dev_release_port()' which this patch removes.

rte_eth_dev_release_port() is called in eth_dev_close(), isn't it?

No, 'eth_dev_close()' is local 'dev_close()' ops, the one to clear driver private resources.
I assume it is confused with 'rte_eth_dev_close()' ...

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review rte_pmd_af_xdp_remove(struct rte_vdev_device *dev) · line 943

Quoted 2 lines
(quoted diff) +1 -1
-
+	eth_dev_close(eth_dev);

Ah yes, I overlooked it.
Why not calling rte_eth_dev_close()?

It may work, but I am for keeping 'dev_close()' and 'rte_eth_dev_release_port()' as two steps in '.remove()', I think there is no need to include 'rte_eth_dev_close()' API here and its possible/future side affects etc...

#9 lore raw

Re: [dpdk-dev] [PATCH v1 1/2] net/af_xdp: remove resources when port is closed

In reply to Ferruh Yigit

Hi, Ferruh

Quoted 18 lines · Ferruh Yigit
Quoted 10 lines · Xiaolong Ye

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

<...>

Quoted 4 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -0
@@ -936,14 +940,7 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return -1;
 
Quoted 12 lines

drivers/net/af_xdp/rte_eth_af_xdp.c rte_pmd_af_xdp_remove(struct rte_vdev_device *dev) · line 945

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -7
-	internals = eth_dev->data->dev_private;
-
-	rte_ring_free(internals->umem->buf_ring);
-	rte_memzone_free(internals->umem->mz);
-	rte_free(internals->umem);
-
-	rte_eth_dev_release_port(eth_dev);

I thinks we should keep 'rte_eth_dev_release_port()' in '.remove()' path, the 'RTE_ETH_DEV_CLOSE_REMOVE' flag will take care of this in 'rte_eth_dev_close()' but still needed in '.remove()' path.

remove() would call eth_dev_close which includes the rte_eth_dev_release_port().

Thanks,
Xiaolong

Quoted 7 lines
Quoted 6 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -1
-
+	eth_dev_close(eth_dev);
 
 	return 0;
 }
#10 lore raw

Re: [dpdk-dev] [PATCH v1 1/2] net/af_xdp: remove resources when port is closed

Quoted 34 lines · Ye Xiaolong

Hi, Ferruh

Quoted 18 lines · Ferruh Yigit
Quoted 10 lines · Xiaolong Ye

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

<...>

Quoted 4 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -0
@@ -936,14 +940,7 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return -1;
 
Quoted 12 lines

drivers/net/af_xdp/rte_eth_af_xdp.c rte_pmd_af_xdp_remove(struct rte_vdev_device *dev) · line 945

Quoted 7 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -7
-	internals = eth_dev->data->dev_private;
-
-	rte_ring_free(internals->umem->buf_ring);
-	rte_memzone_free(internals->umem->mz);
-	rte_free(internals->umem);
-
-	rte_eth_dev_release_port(eth_dev);

I thinks we should keep 'rte_eth_dev_release_port()' in '.remove()' path, the 'RTE_ETH_DEV_CLOSE_REMOVE' flag will take care of this in 'rte_eth_dev_close()' but still needed in '.remove()' path.

Quoted 1 line

remove() would call eth_dev_close which includes the rte_eth_dev_release_port().

'eth_dev_close()' doesn't call the 'rte_eth_dev_release_port()', and it shouldn't really, am I missing something?

Quoted 11 lines

Thanks,
Xiaolong

Quoted 7 lines
Quoted 6 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -1
-
+	eth_dev_close(eth_dev);
 
 	return 0;
 }
#11 lore raw

Re: [dpdk-dev] [PATCH v1 1/2] net/af_xdp: remove resources when port is closed

Quoted 35 lines · Ferruh Yigit
Quoted 34 lines · Ye Xiaolong

Hi, Ferruh

Quoted 30 lines · Ferruh Yigit
Quoted 10 lines · Xiaolong Ye

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

<...>

drivers/net/af_xdp/rte_eth_af_xdp.c rte_pmd_af_xdp_remove(struct rte_vdev_device *dev) · line 945

Quoted 11 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -7
@@ -936,14 +940,7 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return -1;
 
-	internals = eth_dev->data->dev_private;
-
-	rte_ring_free(internals->umem->buf_ring);
-	rte_memzone_free(internals->umem->mz);
-	rte_free(internals->umem);
-
-	rte_eth_dev_release_port(eth_dev);

I thinks we should keep 'rte_eth_dev_release_port()' in '.remove()' path, the 'RTE_ETH_DEV_CLOSE_REMOVE' flag will take care of this in 'rte_eth_dev_close()' but still needed in '.remove()' path.

Quoted 4 lines
Quoted 1 line

remove() would call eth_dev_close which includes the rte_eth_dev_release_port().

'eth_dev_close()' doesn't call the 'rte_eth_dev_release_port()', and it shouldn't really, am I missing something?

Sorry, it's the rte_eth_dev_close that calls rte_eth_dev_release_port, here in .remove we do need to call rte_eth_dev_release_port explicitly.

will send a new version.

Thanks,
Xiaolong

Quoted 13 lines
Quoted 12 lines

Thanks,
Xiaolong

Quoted 7 lines
Quoted 6 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +1 -1
-
+	eth_dev_close(eth_dev);
 
 	return 0;
 }
#12 lore raw

PATCH 2/2 net/af_xdp: set MAC addrs field to NULL

In reply to Xiaolong Ye

As af_xdp pmd doesn't allocate MAC addresses dynamically, it needs to be set as NULL, so it won't be released by rte_eth_dev_release_port(), otherwise, there would be "EAL: Error: Invalid memory" error.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/af_xdp/rte_eth_af_xdp.c +6 -0
index a12551cbf..f659c0496 100644
@@ -458,6 +458,12 @@ eth_dev_close(struct rte_eth_dev *dev)
 
 	(void)xsk_umem__delete(internals->umem->umem);
 
+	/*
+	 * MAC is not allocated dynamically, setting it to NULL would prevent
+	 * from releasing it in rte_eth_dev_release_port.
+	 */
+	dev->data->mac_addrs = NULL;
+
 	xdp_umem_destroy(internals->umem);
 
 	remove_xdp_program(internals);
Signature · 1 line
2.17.1
#13 lore raw

Re: [dpdk-dev] [PATCH v1 2/2] net/af_xdp: set MAC addrs field to NULL

Quoted 17 lines · Xiaolong Ye

As af_xdp pmd doesn't allocate MAC addresses dynamically, it needs to be set as NULL, so it won't be released by rte_eth_dev_release_port(), otherwise, there would be "EAL: Error: Invalid memory" error.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -0
index a12551cbf..f659c0496 100644
@@ -458,6 +458,12 @@ eth_dev_close(struct rte_eth_dev *dev)
 
 	(void)xsk_umem__delete(internals->umem->umem);

drivers/net/af_xdp/rte_eth_af_xdp.c eth_dev_close(struct rte_eth_dev *dev) · line 469

Quoted 10 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +6 -0
 
+	/*
+	 * MAC is not allocated dynamically, setting it to NULL would prevent
+	 * from releasing it in rte_eth_dev_release_port.
+	 */
+	dev->data->mac_addrs = NULL;
+
 	xdp_umem_destroy(internals->umem);
 
 	remove_xdp_program(internals);

Keeping this patch in separate patch will cause the above error after first patch, what do you think merging this with prev patch?

#14 lore raw

Re: [dpdk-dev] [PATCH v1 2/2] net/af_xdp: set MAC addrs field to NULL

Quoted 26 lines · Ferruh Yigit
Quoted 25 lines · Xiaolong Ye

As af_xdp pmd doesn't allocate MAC addresses dynamically, it needs to be set as NULL, so it won't be released by rte_eth_dev_release_port(), otherwise, there would be "EAL: Error: Invalid memory" error.

---
 drivers/net/af_xdp/rte_eth_af_xdp.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/af_xdp/rte_eth_af_xdp.c +6 -0
index a12551cbf..f659c0496 100644
@@ -458,6 +458,12 @@ eth_dev_close(struct rte_eth_dev *dev)
 
 	(void)xsk_umem__delete(internals->umem->umem);
 
+	/*
+	 * MAC is not allocated dynamically, setting it to NULL would prevent
+	 * from releasing it in rte_eth_dev_release_port.
+	 */
+	dev->data->mac_addrs = NULL;
+
 	xdp_umem_destroy(internals->umem);
 
Quoted 5 lines

drivers/net/af_xdp/rte_eth_af_xdp.c eth_dev_close(struct rte_eth_dev *dev) · line 469

Quoted 2 lines
drivers/net/af_xdp/rte_eth_af_xdp.c +0 -0
 	remove_xdp_program(internals);

Keeping this patch in separate patch will cause the above error after first patch, what do you think merging this with prev patch?

Make sence, will squash it into first patch.

Thanks,
Xiaolong

#15 lore raw

PATCH v3 1/1 net/af_xdp: remove resources when port is closed

In reply to Xiaolong Ye

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

Also as af_xdp pmd doesn't allocate MAC addresses dynamically, it needs to be set as NULL, so it won't be released by rte_eth_dev_release_port(), otherwise, there would be "EAL: Error: Invalid memory" error.

---

V3: keep rte_eth_dev_release_port in .remove ops

V2: merge previous 2 patches into 1 patch since the first one would
introduce one error (second patch is the fix), it makes more sense to squash the second into the first one.

 drivers/net/af_xdp/rte_eth_af_xdp.c | 45 ++++++++++++++++-------------
 1 file changed, 25 insertions(+), 20 deletions(-)
drivers/net/af_xdp/rte_eth_af_xdp.c +25 -20
index acf9ad605..35c72272c 100644
@@ -426,6 +426,19 @@ remove_xdp_program(struct pmd_internals *internals)
 			XDP_FLAGS_UPDATE_IF_NOEXIST);
 }
 
+static void
+xdp_umem_destroy(struct xsk_umem_info *umem)
+{
+	rte_memzone_free(umem->mz);
+	umem->mz = NULL;
+
+	rte_ring_free(umem->buf_ring);
+	umem->buf_ring = NULL;
+
+	rte_free(umem);
+	umem = NULL;
+}
+
 static void
 eth_dev_close(struct rte_eth_dev *dev)
 {
@@ -444,6 +457,15 @@ eth_dev_close(struct rte_eth_dev *dev)
 	}
 
 	(void)xsk_umem__delete(internals->umem->umem);
+
+	/*
+	 * MAC is not allocated dynamically, setting it to NULL would prevent
+	 * from releasing it in rte_eth_dev_release_port.
+	 */
+	dev->data->mac_addrs = NULL;
+
+	xdp_umem_destroy(internals->umem);
+
 	remove_xdp_program(internals);
 }
 
@@ -459,19 +481,6 @@ eth_link_update(struct rte_eth_dev *dev __rte_unused,
 	return 0;
 }
 
-static void
-xdp_umem_destroy(struct xsk_umem_info *umem)
-{
-	rte_memzone_free(umem->mz);
-	umem->mz = NULL;
-
-	rte_ring_free(umem->buf_ring);
-	umem->buf_ring = NULL;
-
-	rte_free(umem);
-	umem = NULL;
-}
-
 static struct
 xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals)
 {
@@ -856,6 +865,8 @@ init_internals(struct rte_vdev_device *dev,
 	eth_dev->dev_ops = &ops;
 	eth_dev->rx_pkt_burst = eth_af_xdp_rx;
 	eth_dev->tx_pkt_burst = eth_af_xdp_tx;
+	/* Let rte_eth_dev_close() release the port resources. */
+	eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
 
 	return eth_dev;
 
@@ -923,7 +934,6 @@ static int
 rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
-	struct pmd_internals *internals;
 
 	AF_XDP_LOG(INFO, "Removing AF_XDP ethdev on numa socket %u\n",
 		rte_socket_id());
@@ -936,12 +946,7 @@ rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return -1;
 
-	internals = eth_dev->data->dev_private;
-
-	rte_ring_free(internals->umem->buf_ring);
-	rte_memzone_free(internals->umem->mz);
-	rte_free(internals->umem);
-
+	eth_dev_close(eth_dev);
 	rte_eth_dev_release_port(eth_dev);
 
 
Signature · 1 line
2.17.1
Reviewed-by on v3 1/1 Applied
#16 lore raw

Re: [dpdk-dev] [PATCH v3] net/af_xdp: remove resources when port is closed

Quoted 6 lines · Xiaolong Ye

Since 18.11, it is suggested that driver should release all its private resources at the dev_close routine. So all resources previously released in remove routine are now released at the dev_close routine, and the dev_close routine will be called in driver remove routine in order to support removing a device without closing its ports.

Quoted 8 lines

Above behavior changes are supported by setting RTE_ETH_DEV_CLOSE_REMOVE flag during probe stage.

Also as af_xdp pmd doesn't allocate MAC addresses dynamically, it needs to be set as NULL, so it won't be released by rte_eth_dev_release_port(), otherwise, there would be "EAL: Error: Invalid memory" error.

Applied to dpdk-next-net/master, thanks.