[dpdk-dev] ethdev: check process type before reset dev data

Message ID 1484209998-21852-1-git-send-email-zhanghaibo5@huawei.com (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel compilation success Compilation OK

Commit Message

Anson Zhang Jan. 12, 2017, 8:33 a.m. UTC
  Overwrite dev date by no primary process would cause
segment fault issue to primary proccess during receive pkt

Signed-off-by: Haibo Zhang <zhanghaibo5@huawei.com>
---
 lib/librte_ether/rte_ethdev.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
  

Comments

Thomas Monjalon Jan. 12, 2017, 1:45 p.m. UTC | #1
2017-01-12 16:33, Haibo Zhang:
> Overwrite dev date by no primary process would cause
> segment fault issue to primary proccess during receive pkt
> 
> Signed-off-by: Haibo Zhang <zhanghaibo5@huawei.com>

Thank you for the fix.
A similar one was proposed by Yuanhan:
	http://dpdk.org/ml/archives/dev/2017-January/054220.html
  

Patch

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 9dea1f1..e25f056 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -212,12 +212,15 @@  struct rte_eth_dev *
 
 	eth_dev = &rte_eth_devices[port_id];
 	eth_dev->data = &rte_eth_dev_data[port_id];
-	memset(eth_dev->data, 0, sizeof(*eth_dev->data));
-	snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
-	eth_dev->data->port_id = port_id;
-	eth_dev->data->mtu = ETHER_MTU;
-	TAILQ_INIT(&(eth_dev->link_intr_cbs));
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+		memset(eth_dev->data, 0, sizeof(*eth_dev->data));
+		snprintf(eth_dev->data->name,
+			sizeof(eth_dev->data->name), "%s", name);
+		eth_dev->data->port_id = port_id;
+		eth_dev->data->mtu = ETHER_MTU;
+	}
 
+	TAILQ_INIT(&(eth_dev->link_intr_cbs));
 	eth_dev->attached = DEV_ATTACHED;
 	eth_dev_last_created_port = port_id;
 	nb_ports++;