DPDK patches and discussions
 help / color / mirror / Atom feed
* Re: [dpdk-dev] [PATCH] drivers/net: fix segfault in secondary process
  2018-07-19 16:45 [dpdk-dev] [PATCH] drivers/net: fix segfault in secondary process Ferruh Yigit
@ 2018-07-19 16:32 ` Stephen Hemminger
  2018-07-20 10:13   ` Ferruh Yigit
  2018-07-19 22:19 ` Zhang, Qi Z
  2018-07-20 12:44 ` [dpdk-dev] [PATCH v2] " Ferruh Yigit
  2 siblings, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2018-07-19 16:32 UTC (permalink / raw)
  To: Ferruh Yigit
  Cc: John W. Linville, Declan Doherty, Chas Williams, Gaetan Rivet,
	Tetsuya Mukawa, Santosh Shukla, Jerin Jacob, Keith Wiles,
	Maxime Coquelin, Tiwei Bie, Zhihong Wang, dev, stable,
	Vipin Varghese

On Thu, 19 Jul 2018 17:45:56 +0100
Ferruh Yigit <ferruh.yigit@intel.com> wrote:

> Calling rte_eth_dev_info_get() on secondary process cause a crash
> because eth_dev->device is not set properly.
> 
> Fixes: ee27edbe0c10 ("drivers/net: share vdev data to secondary process")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

Good catch.

Maybe eth_dev should do this for the device drivers?
Better to make device drivers as simple and safe as possible.

There seem to be a lot of bugs related to secondary process model.
Do we have a test suite for that.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH] drivers/net: fix segfault in secondary process
@ 2018-07-19 16:45 Ferruh Yigit
  2018-07-19 16:32 ` Stephen Hemminger
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Ferruh Yigit @ 2018-07-19 16:45 UTC (permalink / raw)
  To: John W. Linville, Declan Doherty, Chas Williams, Gaetan Rivet,
	Tetsuya Mukawa, Santosh Shukla, Jerin Jacob, Keith Wiles,
	Maxime Coquelin, Tiwei Bie, Zhihong Wang
  Cc: dev, Ferruh Yigit, stable, Vipin Varghese

Calling rte_eth_dev_info_get() on secondary process cause a crash
because eth_dev->device is not set properly.

Fixes: ee27edbe0c10 ("drivers/net: share vdev data to secondary process")
Cc: stable@dpdk.org

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
Cc: Vipin Varghese <vipin.varghese@intel.com>
---
 drivers/net/af_packet/rte_eth_af_packet.c | 1 +
 drivers/net/bonding/rte_eth_bond_pmd.c    | 1 +
 drivers/net/failsafe/failsafe.c           | 1 +
 drivers/net/kni/rte_eth_kni.c             | 1 +
 drivers/net/null/rte_eth_null.c           | 1 +
 drivers/net/octeontx/octeontx_ethdev.c    | 1 +
 drivers/net/pcap/rte_eth_pcap.c           | 1 +
 drivers/net/tap/rte_eth_tap.c             | 2 ++
 drivers/net/vhost/rte_eth_vhost.c         | 1 +
 9 files changed, 10 insertions(+)

diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index ce1e31aa4..eb3cce3a6 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -936,6 +936,7 @@ rte_pmd_af_packet_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
index fc4d4fd97..ca491a820 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -3184,6 +3184,7 @@ bond_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &default_dev_ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c
index 7f89486d4..657919f93 100644
--- a/drivers/net/failsafe/failsafe.c
+++ b/drivers/net/failsafe/failsafe.c
@@ -328,6 +328,7 @@ rte_pmd_failsafe_probe(struct rte_vdev_device *vdev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &failsafe_ops;
+		eth_dev->device = &vdev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c
index b038fbf1a..085bb8452 100644
--- a/drivers/net/kni/rte_eth_kni.c
+++ b/drivers/net/kni/rte_eth_kni.c
@@ -420,6 +420,7 @@ eth_kni_probe(struct rte_vdev_device *vdev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &eth_kni_ops;
+		eth_dev->device = &vdev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index d85d25f7e..244f86545 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -624,6 +624,7 @@ rte_pmd_null_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/octeontx/octeontx_ethdev.c b/drivers/net/octeontx/octeontx_ethdev.c
index 21e5e4fca..f264bc64e 100644
--- a/drivers/net/octeontx/octeontx_ethdev.c
+++ b/drivers/net/octeontx/octeontx_ethdev.c
@@ -1183,6 +1183,7 @@ octeontx_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &octeontx_dev_ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index 6779f97c1..e8810a171 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -1017,6 +1017,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 22ba872ed..0331eb9f8 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -1931,6 +1931,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 			return -1;
 		}
 		eth_dev->dev_ops = &ops;
+		eth_dev->device = &dev->device;
 		return 0;
 	}
 
@@ -2000,6 +2001,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 47b33456c..e58f32211 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -1354,6 +1354,7 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
-- 
2.17.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH] drivers/net: fix segfault in secondary process
  2018-07-19 16:45 [dpdk-dev] [PATCH] drivers/net: fix segfault in secondary process Ferruh Yigit
  2018-07-19 16:32 ` Stephen Hemminger
@ 2018-07-19 22:19 ` Zhang, Qi Z
  2018-07-20 12:44 ` [dpdk-dev] [PATCH v2] " Ferruh Yigit
  2 siblings, 0 replies; 9+ messages in thread
From: Zhang, Qi Z @ 2018-07-19 22:19 UTC (permalink / raw)
  To: Yigit, Ferruh, John W. Linville, Doherty, Declan, Chas Williams,
	Gaetan Rivet, Tetsuya Mukawa, Santosh Shukla, Jerin Jacob, Wiles,
	Keith, Maxime Coquelin, Bie, Tiwei, Wang, Zhihong
  Cc: dev, Yigit, Ferruh, stable, Varghese, Vipin



> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Ferruh Yigit
> Sent: Friday, July 20, 2018 12:46 AM
> To: John W. Linville <linville@tuxdriver.com>; Doherty, Declan
> <declan.doherty@intel.com>; Chas Williams <chas3@att.com>; Gaetan Rivet
> <gaetan.rivet@6wind.com>; Tetsuya Mukawa <mtetsuyah@gmail.com>;
> Santosh Shukla <santosh.shukla@caviumnetworks.com>; Jerin Jacob
> <jerin.jacob@caviumnetworks.com>; Wiles, Keith <keith.wiles@intel.com>;
> Maxime Coquelin <maxime.coquelin@redhat.com>; Bie, Tiwei
> <tiwei.bie@intel.com>; Wang, Zhihong <zhihong.wang@intel.com>
> Cc: dev@dpdk.org; Yigit, Ferruh <ferruh.yigit@intel.com>; stable@dpdk.org;
> Varghese, Vipin <vipin.varghese@intel.com>
> Subject: [dpdk-dev] [PATCH] drivers/net: fix segfault in secondary process
> 
> Calling rte_eth_dev_info_get() on secondary process cause a crash because
> eth_dev->device is not set properly.
> 
> Fixes: ee27edbe0c10 ("drivers/net: share vdev data to secondary process")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

Yes, this is the same issue I met when detaching the device from a secondary process.
The backend device should be assigned on secondary.

Reviewed-by: Qi Zhang <qi.z.zhang@intel.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH] drivers/net: fix segfault in secondary process
  2018-07-19 16:32 ` Stephen Hemminger
@ 2018-07-20 10:13   ` Ferruh Yigit
  0 siblings, 0 replies; 9+ messages in thread
From: Ferruh Yigit @ 2018-07-20 10:13 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: John W. Linville, Declan Doherty, Chas Williams, Gaetan Rivet,
	Tetsuya Mukawa, Santosh Shukla, Jerin Jacob, Keith Wiles,
	Maxime Coquelin, Tiwei Bie, Zhihong Wang, dev, stable,
	Vipin Varghese

On 7/19/2018 5:32 PM, Stephen Hemminger wrote:
> On Thu, 19 Jul 2018 17:45:56 +0100
> Ferruh Yigit <ferruh.yigit@intel.com> wrote:
> 
>> Calling rte_eth_dev_info_get() on secondary process cause a crash
>> because eth_dev->device is not set properly.
>>
>> Fixes: ee27edbe0c10 ("drivers/net: share vdev data to secondary process")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> 
> Good catch.
> 
> Maybe eth_dev should do this for the device drivers?
> Better to make device drivers as simple and safe as possible.

Agreed, let me try to create a helper function for this.

> 
> There seem to be a lot of bugs related to secondary process model.
> Do we have a test suite for that.
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v2] drivers/net: fix segfault in secondary process
  2018-07-20 12:44 ` [dpdk-dev] [PATCH v2] " Ferruh Yigit
@ 2018-07-20 12:23   ` Thomas Monjalon
  2018-07-20 13:36     ` Ferruh Yigit
  2018-07-20 14:54   ` [dpdk-dev] [PATCH v3] " Ferruh Yigit
  1 sibling, 1 reply; 9+ messages in thread
From: Thomas Monjalon @ 2018-07-20 12:23 UTC (permalink / raw)
  To: Ferruh Yigit
  Cc: John W. Linville, Declan Doherty, Chas Williams, Hemant Agrawal,
	Shreyansh Jain, Gaetan Rivet, Tetsuya Mukawa, Santosh Shukla,
	Jerin Jacob, Keith Wiles, Maxime Coquelin, Tiwei Bie,
	Zhihong Wang, Andrew Rybchenko, dev, stable

20/07/2018 14:44, Ferruh Yigit:
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
>  	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
>  	    strlen(params) == 0) {
> -		eth_dev = rte_eth_dev_attach_secondary(name);
> +		eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops);
>  		if (!eth_dev) {
>  			TAP_LOG(ERR, "Failed to probe %s", name);
>  			return -1;
>  		}
> -		/* TODO: request info from primary to set up Rx and Tx */
> -		eth_dev->dev_ops = &ops;
> -		rte_eth_dev_probing_finish(eth_dev);
>  		return 0;
>  	}
>  
> --- a/lib/librte_ethdev/rte_ethdev_vdev.h
> +++ b/lib/librte_ethdev/rte_ethdev_vdev.h
> +static inline struct rte_eth_dev *
> +rte_eth_vdev_secondary_probe(struct rte_vdev_device *vdev,
> +		const char *name, const struct eth_dev_ops *ops)
> +{
> +	struct rte_eth_dev *eth_dev;
> +
> +	eth_dev = rte_eth_dev_attach_secondary(name);
> +	if (!eth_dev)
> +		return NULL;
> +
> +	/* TODO: request info from primary to set up Rx and Tx */
> +	eth_dev->dev_ops = ops;
> +	eth_dev->device = &vdev->device;
> +	rte_eth_dev_probing_finish(eth_dev);
> +	return eth_dev;
> +}

As you can see in the following patch,

	net/tap: add queues when attaching from secondary process
	https://patches.dpdk.org/patch/43229/

The synchronization with primary process can be specific to the PMD.
It will use some private data and can need IPC call to translate some
file descriptors.
Moreover, we will need to think about a more complex sync in order
to update queues when a process re-configure queues number,
and also attach in primary a device created in secondary.
We need also to handle hotplug as Qi already proposed.

My suggestion: just fix the PMDs without creating an helper.
We could design a helper later when we will have thought to the global
issue we want to solve.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH v2] drivers/net: fix segfault in secondary process
  2018-07-19 16:45 [dpdk-dev] [PATCH] drivers/net: fix segfault in secondary process Ferruh Yigit
  2018-07-19 16:32 ` Stephen Hemminger
  2018-07-19 22:19 ` Zhang, Qi Z
@ 2018-07-20 12:44 ` Ferruh Yigit
  2018-07-20 12:23   ` Thomas Monjalon
  2018-07-20 14:54   ` [dpdk-dev] [PATCH v3] " Ferruh Yigit
  2 siblings, 2 replies; 9+ messages in thread
From: Ferruh Yigit @ 2018-07-20 12:44 UTC (permalink / raw)
  To: John W. Linville, Declan Doherty, Chas Williams, Hemant Agrawal,
	Shreyansh Jain, Gaetan Rivet, Tetsuya Mukawa, Santosh Shukla,
	Jerin Jacob, Keith Wiles, Maxime Coquelin, Tiwei Bie,
	Zhihong Wang, Thomas Monjalon, Andrew Rybchenko
  Cc: dev, Ferruh Yigit, stable

Calling rte_eth_dev_info_get() on secondary process cause a crash
because eth_dev->device is not set properly.

Adding a helper function rte_eth_vdev_secondary_probe() that initializes
eth_dev fields properly.

Fixes: ee27edbe0c10 ("drivers/net: share vdev data to secondary process")
Cc: stable@dpdk.org

Reported-by: Vipin Varghese <vipin.varghese@intel.com>
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
v2:
* Added rte_eth_vdev_secondary_probe
* Updated dpaa
* More update on octeontx
---
 drivers/net/af_packet/rte_eth_af_packet.c |  5 +----
 drivers/net/bonding/rte_eth_bond_pmd.c    |  6 ++----
 drivers/net/dpaa/dpaa_ethdev.c            |  2 ++
 drivers/net/failsafe/failsafe.c           |  6 ++----
 drivers/net/kni/rte_eth_kni.c             |  6 ++----
 drivers/net/null/rte_eth_null.c           |  7 ++-----
 drivers/net/octeontx/octeontx_ethdev.c    |  9 +++++----
 drivers/net/pcap/rte_eth_pcap.c           |  6 ++----
 drivers/net/tap/rte_eth_tap.c             |  8 ++------
 drivers/net/vhost/rte_eth_vhost.c         |  5 +----
 lib/librte_ethdev/rte_ethdev_vdev.h       | 17 +++++++++++++++++
 11 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index ce1e31aa4..548aee09e 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -929,14 +929,11 @@ rte_pmd_af_packet_probe(struct rte_vdev_device *dev)
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(rte_vdev_device_args(dev)) == 0) {
-		eth_dev = rte_eth_dev_attach_secondary(name);
+		eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops);
 		if (!eth_dev) {
 			PMD_LOG(ERR, "Failed to probe %s", name);
 			return -1;
 		}
-		/* TODO: request info from primary to set up Rx and Tx */
-		eth_dev->dev_ops = &ops;
-		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
 
diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
index fc4d4fd97..d155c7ac2 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -3177,14 +3177,12 @@ bond_probe(struct rte_vdev_device *dev)
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(rte_vdev_device_args(dev)) == 0) {
-		eth_dev = rte_eth_dev_attach_secondary(name);
+		eth_dev = rte_eth_vdev_secondary_probe(dev, name,
+			&default_dev_ops);
 		if (!eth_dev) {
 			RTE_BOND_LOG(ERR, "Failed to probe %s", name);
 			return -1;
 		}
-		/* TODO: request info from primary to set up Rx and Tx */
-		eth_dev->dev_ops = &default_dev_ops;
-		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
 
diff --git a/drivers/net/dpaa/dpaa_ethdev.c b/drivers/net/dpaa/dpaa_ethdev.c
index 5c0aafb3c..7a950ac04 100644
--- a/drivers/net/dpaa/dpaa_ethdev.c
+++ b/drivers/net/dpaa/dpaa_ethdev.c
@@ -1389,6 +1389,8 @@ rte_dpaa_probe(struct rte_dpaa_driver *dpaa_drv,
 		eth_dev = rte_eth_dev_attach_secondary(dpaa_dev->name);
 		if (!eth_dev)
 			return -ENOMEM;
+		eth_dev->device = &dpaa_dev->device;
+		eth_dev->dev_ops = &dpaa_devops;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c
index 7f89486d4..0278deb33 100644
--- a/drivers/net/failsafe/failsafe.c
+++ b/drivers/net/failsafe/failsafe.c
@@ -321,14 +321,12 @@ rte_pmd_failsafe_probe(struct rte_vdev_device *vdev)
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(rte_vdev_device_args(vdev)) == 0) {
-		eth_dev = rte_eth_dev_attach_secondary(name);
+		eth_dev = rte_eth_vdev_secondary_probe(vdev, name,
+			&failsafe_ops);
 		if (!eth_dev) {
 			ERROR("Failed to probe %s", name);
 			return -1;
 		}
-		/* TODO: request info from primary to set up Rx and Tx */
-		eth_dev->dev_ops = &failsafe_ops;
-		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
 
diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c
index b038fbf1a..3e653d729 100644
--- a/drivers/net/kni/rte_eth_kni.c
+++ b/drivers/net/kni/rte_eth_kni.c
@@ -413,14 +413,12 @@ eth_kni_probe(struct rte_vdev_device *vdev)
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(params) == 0) {
-		eth_dev = rte_eth_dev_attach_secondary(name);
+		eth_dev = rte_eth_vdev_secondary_probe(vdev, name,
+			&eth_kni_ops);
 		if (!eth_dev) {
 			PMD_LOG(ERR, "Failed to probe %s", name);
 			return -1;
 		}
-		/* TODO: request info from primary to set up Rx and Tx */
-		eth_dev->dev_ops = &eth_kni_ops;
-		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
 
diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index d85d25f7e..46ee494f6 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -616,15 +616,12 @@ rte_pmd_null_probe(struct rte_vdev_device *dev)
 	PMD_LOG(INFO, "Initializing pmd_null for %s", name);
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
-	    strlen(params) == 0) {
-		eth_dev = rte_eth_dev_attach_secondary(name);
+			strlen(params) == 0) {
+		eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops);
 		if (!eth_dev) {
 			PMD_LOG(ERR, "Failed to probe %s", name);
 			return -1;
 		}
-		/* TODO: request info from primary to set up Rx and Tx */
-		eth_dev->dev_ops = &ops;
-		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
 
diff --git a/drivers/net/octeontx/octeontx_ethdev.c b/drivers/net/octeontx/octeontx_ethdev.c
index 21e5e4fca..ad96b152d 100644
--- a/drivers/net/octeontx/octeontx_ethdev.c
+++ b/drivers/net/octeontx/octeontx_ethdev.c
@@ -19,6 +19,7 @@
 #include <rte_mbuf_pool_ops.h>
 #include <rte_prefetch.h>
 #include <rte_bus_vdev.h>
+#include <rte_ethdev_vdev.h>
 
 #include "octeontx_ethdev.h"
 #include "octeontx_rxtx.h"
@@ -1015,6 +1016,8 @@ octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
 		if (eth_dev == NULL)
 			return -ENODEV;
 
+		eth_dev->dev_ops = &octeontx_dev_ops;
+		eth_dev->device = &dev->device;
 		eth_dev->tx_pkt_burst = octeontx_xmit_pkts;
 		eth_dev->rx_pkt_burst = octeontx_recv_pkts;
 		rte_eth_dev_probing_finish(eth_dev);
@@ -1176,14 +1179,12 @@ octeontx_probe(struct rte_vdev_device *dev)
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(rte_vdev_device_args(dev)) == 0) {
-		eth_dev = rte_eth_dev_attach_secondary(dev_name);
+		eth_dev = rte_eth_vdev_secondary_probe(dev, dev_name,
+			&octeontx_dev_ops);
 		if (!eth_dev) {
 			RTE_LOG(ERR, PMD, "Failed to probe %s\n", dev_name);
 			return -1;
 		}
-		/* TODO: request info from primary to set up Rx and Tx */
-		eth_dev->dev_ops = &octeontx_dev_ops;
-		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
 
diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index 6779f97c1..d714c4be7 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -1010,14 +1010,12 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(rte_vdev_device_args(dev)) == 0) {
-		eth_dev = rte_eth_dev_attach_secondary(name);
+		eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops);
 		if (!eth_dev) {
 			PMD_LOG(ERR, "Failed to probe %s", name);
 			return -1;
 		}
-		/* TODO: request info from primary to set up Rx and Tx */
-		eth_dev->dev_ops = &ops;
-		rte_eth_dev_probing_finish(eth_dev);
+		return 0;
 		return 0;
 	}
 
diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 22ba872ed..e17d8955d 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -1925,12 +1925,11 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(params) == 0) {
-		eth_dev = rte_eth_dev_attach_secondary(name);
+		eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops);
 		if (!eth_dev) {
 			TAP_LOG(ERR, "Failed to probe %s", name);
 			return -1;
 		}
-		eth_dev->dev_ops = &ops;
 		return 0;
 	}
 
@@ -1993,14 +1992,11 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(params) == 0) {
-		eth_dev = rte_eth_dev_attach_secondary(name);
+		eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops);
 		if (!eth_dev) {
 			TAP_LOG(ERR, "Failed to probe %s", name);
 			return -1;
 		}
-		/* TODO: request info from primary to set up Rx and Tx */
-		eth_dev->dev_ops = &ops;
-		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
 
diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 47b33456c..c4d8decd0 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -1347,14 +1347,11 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev)
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
 	    strlen(rte_vdev_device_args(dev)) == 0) {
-		eth_dev = rte_eth_dev_attach_secondary(name);
+		eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops);
 		if (!eth_dev) {
 			VHOST_LOG(ERR, "Failed to probe %s\n", name);
 			return -1;
 		}
-		/* TODO: request info from primary to set up Rx and Tx */
-		eth_dev->dev_ops = &ops;
-		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
 
diff --git a/lib/librte_ethdev/rte_ethdev_vdev.h b/lib/librte_ethdev/rte_ethdev_vdev.h
index 259feda3f..6092f6e71 100644
--- a/lib/librte_ethdev/rte_ethdev_vdev.h
+++ b/lib/librte_ethdev/rte_ethdev_vdev.h
@@ -81,4 +81,21 @@ rte_eth_vdev_allocate(struct rte_vdev_device *dev, size_t private_data_size)
 	return eth_dev;
 }
 
+static inline struct rte_eth_dev *
+rte_eth_vdev_secondary_probe(struct rte_vdev_device *vdev,
+		const char *name, const struct eth_dev_ops *ops)
+{
+	struct rte_eth_dev *eth_dev;
+
+	eth_dev = rte_eth_dev_attach_secondary(name);
+	if (!eth_dev)
+		return NULL;
+
+	/* TODO: request info from primary to set up Rx and Tx */
+	eth_dev->dev_ops = ops;
+	eth_dev->device = &vdev->device;
+	rte_eth_dev_probing_finish(eth_dev);
+	return eth_dev;
+}
+
 #endif /* _RTE_ETHDEV_VDEV_H_ */
-- 
2.17.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v2] drivers/net: fix segfault in secondary process
  2018-07-20 12:23   ` Thomas Monjalon
@ 2018-07-20 13:36     ` Ferruh Yigit
  0 siblings, 0 replies; 9+ messages in thread
From: Ferruh Yigit @ 2018-07-20 13:36 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: John W. Linville, Declan Doherty, Chas Williams, Hemant Agrawal,
	Shreyansh Jain, Gaetan Rivet, Tetsuya Mukawa, Santosh Shukla,
	Jerin Jacob, Keith Wiles, Maxime Coquelin, Tiwei Bie,
	Zhihong Wang, Andrew Rybchenko, dev, stable

On 7/20/2018 1:23 PM, Thomas Monjalon wrote:
> 20/07/2018 14:44, Ferruh Yigit:
>> --- a/drivers/net/tap/rte_eth_tap.c
>> +++ b/drivers/net/tap/rte_eth_tap.c
>>  	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
>>  	    strlen(params) == 0) {
>> -		eth_dev = rte_eth_dev_attach_secondary(name);
>> +		eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops);
>>  		if (!eth_dev) {
>>  			TAP_LOG(ERR, "Failed to probe %s", name);
>>  			return -1;
>>  		}
>> -		/* TODO: request info from primary to set up Rx and Tx */
>> -		eth_dev->dev_ops = &ops;
>> -		rte_eth_dev_probing_finish(eth_dev);
>>  		return 0;
>>  	}
>>  
>> --- a/lib/librte_ethdev/rte_ethdev_vdev.h
>> +++ b/lib/librte_ethdev/rte_ethdev_vdev.h
>> +static inline struct rte_eth_dev *
>> +rte_eth_vdev_secondary_probe(struct rte_vdev_device *vdev,
>> +		const char *name, const struct eth_dev_ops *ops)
>> +{
>> +	struct rte_eth_dev *eth_dev;
>> +
>> +	eth_dev = rte_eth_dev_attach_secondary(name);
>> +	if (!eth_dev)
>> +		return NULL;
>> +
>> +	/* TODO: request info from primary to set up Rx and Tx */
>> +	eth_dev->dev_ops = ops;
>> +	eth_dev->device = &vdev->device;
>> +	rte_eth_dev_probing_finish(eth_dev);
>> +	return eth_dev;
>> +}
> 
> As you can see in the following patch,
> 
> 	net/tap: add queues when attaching from secondary process
> 	https://patches.dpdk.org/patch/43229/
> 
> The synchronization with primary process can be specific to the PMD.
> It will use some private data and can need IPC call to translate some
> file descriptors.
> Moreover, we will need to think about a more complex sync in order
> to update queues when a process re-configure queues number,
> and also attach in primary a device created in secondary.
> We need also to handle hotplug as Qi already proposed.
> 
> My suggestion: just fix the PMDs without creating an helper.
> We could design a helper later when we will have thought to the global
> issue we want to solve.

This was to help PMDs as Stephen suggested, helper function can be introduced
later, I will send initial version with updated PMDs in v2.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH v3] drivers/net: fix segfault in secondary process
  2018-07-20 12:44 ` [dpdk-dev] [PATCH v2] " Ferruh Yigit
  2018-07-20 12:23   ` Thomas Monjalon
@ 2018-07-20 14:54   ` Ferruh Yigit
  2018-07-26 12:58     ` Thomas Monjalon
  1 sibling, 1 reply; 9+ messages in thread
From: Ferruh Yigit @ 2018-07-20 14:54 UTC (permalink / raw)
  To: John W. Linville, Declan Doherty, Chas Williams, Hemant Agrawal,
	Shreyansh Jain, Gaetan Rivet, Tetsuya Mukawa, Santosh Shukla,
	Jerin Jacob, Keith Wiles, Maxime Coquelin, Tiwei Bie,
	Zhihong Wang
  Cc: dev, Ferruh Yigit, stable, Stephen Hemminger, Thomas Monjalon

Calling rte_eth_dev_info_get() on secondary process cause a crash
because eth_dev->device is not set properly.

Fixes: ee27edbe0c10 ("drivers/net: share vdev data to secondary process")
Cc: stable@dpdk.org

Reported-by: Vipin Varghese <vipin.varghese@intel.com>
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Reviewed-by: Qi Zhang <qi.z.zhang@intel.com>
---
Cc: Stephen Hemminger <stephen@networkplumber.org>
Cc: Thomas Monjalon <thomas@monjalon.net>

v2:
* Added rte_eth_vdev_secondary_probe
* Updated dpaa
* More update on octeontx

v3:
* Removed helper function, fixed PMDs
---
 drivers/net/af_packet/rte_eth_af_packet.c | 1 +
 drivers/net/bonding/rte_eth_bond_pmd.c    | 1 +
 drivers/net/dpaa/dpaa_ethdev.c            | 2 ++
 drivers/net/failsafe/failsafe.c           | 1 +
 drivers/net/kni/rte_eth_kni.c             | 1 +
 drivers/net/null/rte_eth_null.c           | 1 +
 drivers/net/octeontx/octeontx_ethdev.c    | 3 +++
 drivers/net/pcap/rte_eth_pcap.c           | 1 +
 drivers/net/tap/rte_eth_tap.c             | 2 ++
 drivers/net/vhost/rte_eth_vhost.c         | 1 +
 10 files changed, 14 insertions(+)

diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index ce1e31aa4..eb3cce3a6 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -936,6 +936,7 @@ rte_pmd_af_packet_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
index fc4d4fd97..ca491a820 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -3184,6 +3184,7 @@ bond_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &default_dev_ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/dpaa/dpaa_ethdev.c b/drivers/net/dpaa/dpaa_ethdev.c
index 5c0aafb3c..7a950ac04 100644
--- a/drivers/net/dpaa/dpaa_ethdev.c
+++ b/drivers/net/dpaa/dpaa_ethdev.c
@@ -1389,6 +1389,8 @@ rte_dpaa_probe(struct rte_dpaa_driver *dpaa_drv,
 		eth_dev = rte_eth_dev_attach_secondary(dpaa_dev->name);
 		if (!eth_dev)
 			return -ENOMEM;
+		eth_dev->device = &dpaa_dev->device;
+		eth_dev->dev_ops = &dpaa_devops;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c
index 7f89486d4..657919f93 100644
--- a/drivers/net/failsafe/failsafe.c
+++ b/drivers/net/failsafe/failsafe.c
@@ -328,6 +328,7 @@ rte_pmd_failsafe_probe(struct rte_vdev_device *vdev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &failsafe_ops;
+		eth_dev->device = &vdev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c
index b038fbf1a..085bb8452 100644
--- a/drivers/net/kni/rte_eth_kni.c
+++ b/drivers/net/kni/rte_eth_kni.c
@@ -420,6 +420,7 @@ eth_kni_probe(struct rte_vdev_device *vdev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &eth_kni_ops;
+		eth_dev->device = &vdev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index d85d25f7e..244f86545 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -624,6 +624,7 @@ rte_pmd_null_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/octeontx/octeontx_ethdev.c b/drivers/net/octeontx/octeontx_ethdev.c
index 21e5e4fca..974ef57c4 100644
--- a/drivers/net/octeontx/octeontx_ethdev.c
+++ b/drivers/net/octeontx/octeontx_ethdev.c
@@ -1015,6 +1015,8 @@ octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
 		if (eth_dev == NULL)
 			return -ENODEV;
 
+		eth_dev->dev_ops = &octeontx_dev_ops;
+		eth_dev->device = &dev->device;
 		eth_dev->tx_pkt_burst = octeontx_xmit_pkts;
 		eth_dev->rx_pkt_burst = octeontx_recv_pkts;
 		rte_eth_dev_probing_finish(eth_dev);
@@ -1183,6 +1185,7 @@ octeontx_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &octeontx_dev_ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index 6779f97c1..e8810a171 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -1017,6 +1017,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 22ba872ed..0331eb9f8 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -1931,6 +1931,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
 			return -1;
 		}
 		eth_dev->dev_ops = &ops;
+		eth_dev->device = &dev->device;
 		return 0;
 	}
 
@@ -2000,6 +2001,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 47b33456c..e58f32211 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -1354,6 +1354,7 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev)
 		}
 		/* TODO: request info from primary to set up Rx and Tx */
 		eth_dev->dev_ops = &ops;
+		eth_dev->device = &dev->device;
 		rte_eth_dev_probing_finish(eth_dev);
 		return 0;
 	}
-- 
2.17.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v3] drivers/net: fix segfault in secondary process
  2018-07-20 14:54   ` [dpdk-dev] [PATCH v3] " Ferruh Yigit
@ 2018-07-26 12:58     ` Thomas Monjalon
  0 siblings, 0 replies; 9+ messages in thread
From: Thomas Monjalon @ 2018-07-26 12:58 UTC (permalink / raw)
  To: Ferruh Yigit
  Cc: dev, John W. Linville, Declan Doherty, Chas Williams,
	Hemant Agrawal, Shreyansh Jain, Gaetan Rivet, Tetsuya Mukawa,
	Santosh Shukla, Jerin Jacob, Keith Wiles, Maxime Coquelin,
	Tiwei Bie, Zhihong Wang, stable, Stephen Hemminger

20/07/2018 16:54, Ferruh Yigit:
> Calling rte_eth_dev_info_get() on secondary process cause a crash
> because eth_dev->device is not set properly.
> 
> Fixes: ee27edbe0c10 ("drivers/net: share vdev data to secondary process")
> Cc: stable@dpdk.org
> 
> Reported-by: Vipin Varghese <vipin.varghese@intel.com>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> Reviewed-by: Qi Zhang <qi.z.zhang@intel.com>

Applied, thanks

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-07-26 12:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-19 16:45 [dpdk-dev] [PATCH] drivers/net: fix segfault in secondary process Ferruh Yigit
2018-07-19 16:32 ` Stephen Hemminger
2018-07-20 10:13   ` Ferruh Yigit
2018-07-19 22:19 ` Zhang, Qi Z
2018-07-20 12:44 ` [dpdk-dev] [PATCH v2] " Ferruh Yigit
2018-07-20 12:23   ` Thomas Monjalon
2018-07-20 13:36     ` Ferruh Yigit
2018-07-20 14:54   ` [dpdk-dev] [PATCH v3] " Ferruh Yigit
2018-07-26 12:58     ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).