Skip to contentSkip to conversation

ethdev: fix dev close in secondary process

PATCH Superseded Min Hu (Connor) 4 participants 10 messages May 27, 2022 – Jun 1, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ethdev: fix dev close in secondary process

From: Min Hu <[email protected]>

Shared memory like port private resources should only be reserved by primary process. Secondary process should not start dev, and the state of 'dev_started' is only meaningful to primary process. While secondary process need to close dev to release process private resources.

This patch limited the scope of 'dev_started'.

Fixes febc855b358e ("ethdev: forbid closing started device")
---
 lib/ethdev/rte_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/ethdev/rte_ethdev.c +2 -1
index 09abee6345..f34c6580a4 100644
@@ -1574,7 +1574,8 @@ rte_eth_dev_close(uint16_t port_id)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_started) {
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
+			dev->data->dev_started) {
 		RTE_ETHDEV_LOG(ERR, "Cannot close started device (port %u)\n",
 			       port_id);
 		return -EINVAL;
Signature · 1 line
2.33.0
#1 lore raw
Quoted 9 lines · Min Hu (Connor)

From: Min Hu <[email protected]>

Shared memory like port private resources should only be reserved by primary process. Secondary process should not start dev, and the state of 'dev_started' is only meaningful to primary process. While secondary process need to close dev to release process private resources.

This patch limited the scope of 'dev_started'.

I agree with the patch since secondary process should not be obliged to wait for device stop before closing ethdev. In any case closing ethdev in secondary process should do nothing harmful to the primary process.

However, the patch description pretends to limit dev_started scope for secondary processes in general. It is wrong since secondary processes need the information and that's why it is stored in shared memory.

Quoted 23 lines
Fixes febc855b358e ("ethdev: forbid closing started device")
---
  lib/ethdev/rte_ethdev.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
lib/ethdev/rte_ethdev.c +2 -1
index 09abee6345..f34c6580a4 100644
@@ -1574,7 +1574,8 @@ rte_eth_dev_close(uint16_t port_id)
  	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
  	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_started) {
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
+			dev->data->dev_started) {
  		RTE_ETHDEV_LOG(ERR, "Cannot close started device (port %u)\n",
  			       port_id);
  		return -EINVAL;
#2 lore raw
Quoted 16 lines · On Tue, 31 May 2022 20:08:55 +0300 Andrew Rybchenko…
Quoted 9 lines · Min Hu (Connor)

From: Min Hu <[email protected]>

Shared memory like port private resources should only be reserved by primary process. Secondary process should not start dev, and the state of 'dev_started' is only meaningful to primary process. While secondary process need to close dev to release process private resources.

This patch limited the scope of 'dev_started'.

I agree with the patch since secondary process should not be obliged to wait for device stop before closing ethdev. In any case closing ethdev in secondary process should do nothing harmful to the primary process.

Quoted 11 lines

However, the patch description pretends to limit dev_started scope for secondary processes in general. It is wrong since secondary processes need the information and that's why it is stored in shared memory.

Quoted 6 lines
Fixes febc855b358e ("ethdev: forbid closing started device")

---

Also secondary processes are used differently by different application models.

Some applications only use secondary process for information. But some have a primary process that only inits DPDK and do everything in a secondary process.

#3 lore raw

Hi,Andrew, Stephen ,
I fixed the comment, thanks for your comment.

Quoted 38 lines · Stephen Hemminger
Quoted 16 lines · On Tue, 31 May 2022 20:08:55 +0300 Andrew Rybchenko…
Quoted 9 lines · Min Hu (Connor)

From: Min Hu <[email protected]>

Shared memory like port private resources should only be reserved by primary process. Secondary process should not start dev, and the state of 'dev_started' is only meaningful to primary process. While secondary process need to close dev to release process private resources.

This patch limited the scope of 'dev_started'.

I agree with the patch since secondary process should not be obliged to wait for device stop before closing ethdev. In any case closing ethdev in secondary process should do nothing harmful to the primary process.

Quoted 11 lines

However, the patch description pretends to limit dev_started scope for secondary processes in general. It is wrong since secondary processes need the information and that's why it is stored in shared memory.

Quoted 6 lines
Fixes febc855b358e ("ethdev: forbid closing started device")

---

Also secondary processes are used differently by different application models.

Some applications only use secondary process for information. But some have a primary process that only inits DPDK and do everything in a secondary process.
.

#4 lore raw

PATCH v2 1/1 ethdev: fix dev close in secondary process

In reply to Min Hu (Connor)

From: Min Hu <[email protected]>

Secondary process need to close dev to release process private resources. But secondary process should not be obliged to wait for device stop before closing ethdev.

This patch fixed it.

Fixes febc855b358e ("ethdev: forbid closing started device")

---
v2:
* fixed comment.

---
 lib/ethdev/rte_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/ethdev/rte_ethdev.c +2 -1
index 09abee6345..f34c6580a4 100644
@@ -1574,7 +1574,8 @@ rte_eth_dev_close(uint16_t port_id)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_started) {
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
+			dev->data->dev_started) {
 		RTE_ETHDEV_LOG(ERR, "Cannot close started device (port %u)\n",
 			       port_id);
 		return -EINVAL;
Signature · 1 line
2.33.0
#5 lore raw
Quoted 25 lines · Min Hu (Connor)

From: Min Hu <[email protected]>

Secondary process need to close dev to release process private resources. But secondary process should not be obliged to wait for device stop before closing ethdev.

This patch fixed it.

Fixes febc855b358e ("ethdev: forbid closing started device")

---
v2:
* fixed comment.

---
 lib/ethdev/rte_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/ethdev/rte_ethdev.c +0 -0
index 09abee6345..f34c6580a4 100644

lib/ethdev/rte_ethdev.c rte_eth_dev_close(uint16_t port_id) · line 1577

Quoted 4 lines
lib/ethdev/rte_ethdev.c +0 -1
@@ -1574,7 +1574,8 @@ rte_eth_dev_close(uint16_t port_id)
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
 
-       if (dev->data->dev_started) {

It will be good to add the comment as a part of the code as well. That way someone in future won't have to look at the commit log to understand the behavior.

Quoted 8 lines
lib/ethdev/rte_ethdev.c +2 -1
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
+                       dev->data->dev_started) {
                RTE_ETHDEV_LOG(ERR, "Cannot close started device (port %u)\n",
                               port_id);
                return -EINVAL;
--

2.33.0

#6 lore raw

Hi, Ajit
v3 has been sent, thanks

Quoted 42 lines · Ajit Khaparde
Quoted 25 lines · Min Hu (Connor)

From: Min Hu <[email protected]>

Secondary process need to close dev to release process private resources. But secondary process should not be obliged to wait for device stop before closing ethdev.

This patch fixed it.

Fixes febc855b358e ("ethdev: forbid closing started device")

---
v2:
* fixed comment.

---
  lib/ethdev/rte_ethdev.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
lib/ethdev/rte_ethdev.c +0 -0
index 09abee6345..f34c6580a4 100644

lib/ethdev/rte_ethdev.c rte_eth_dev_close(uint16_t port_id) · line 1577

Quoted 4 lines
lib/ethdev/rte_ethdev.c +0 -1
@@ -1574,7 +1574,8 @@ rte_eth_dev_close(uint16_t port_id)
         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
         dev = &rte_eth_devices[port_id];
 
-       if (dev->data->dev_started) {

It will be good to add the comment as a part of the code as well. That way someone in future won't have to look at the commit log to understand the behavior.

Quoted 8 lines
lib/ethdev/rte_ethdev.c +2 -1
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
+                       dev->data->dev_started) {
                 RTE_ETHDEV_LOG(ERR, "Cannot close started device (port %u)\n",
                                port_id);
                 return -EINVAL;
--

2.33.0

#7 lore raw
Quoted 3 lines · Min Hu (Connor)

Hi, Ajit
v3 has been sent, thanks

Thanks

#8 lore raw

PATCH v3 1/1 ethdev: fix dev close in secondary process

In reply to Min Hu (Connor)

From: Min Hu <[email protected]>

Secondary process need to close dev to release process private resources. But secondary process should not be obliged to wait for device stop before closing ethdev.

This patch fixed it.

Fixes febc855b358e ("ethdev: forbid closing started device")

---
v3:
* add comment in the code.

v2:
* fixed comment.

---
 lib/ethdev/rte_ethdev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
lib/ethdev/rte_ethdev.c +7 -1
index 09abee6345..902ff96889 100644
@@ -1574,7 +1574,13 @@ rte_eth_dev_close(uint16_t port_id)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_started) {
+	/*
+	 * Secondary process need to close dev to release process private
+	 * resources. But secondary process should not be obliged to wait
+	 * for device stop before closing ethdev.
+	 */
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
+			dev->data->dev_started) {
 		RTE_ETHDEV_LOG(ERR, "Cannot close started device (port %u)\n",
 			       port_id);
 		return -EINVAL;
Signature · 1 line
2.33.0
#9 lore raw
Quoted 6 lines · Min Hu (Connor)

From: Min Hu <[email protected]>

Secondary process need to close dev to release process private resources. But secondary process should not be obliged to wait for device stop before closing ethdev.

Quoted 6 lines

This patch fixed it.

Fixes febc855b358e ("ethdev: forbid closing started device")

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