[v2] dev: fix attach rollback of a device that was already attached

Message ID 20181123212640.111642-1-dariusz.stojaczyk@intel.com (mailing list archive)
State Accepted, archived
Headers
Series [v2] dev: fix attach rollback of a device that was already attached |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Stojaczyk, Dariusz Nov. 23, 2018, 9:26 p.m. UTC
  When primary process receives an IPC attach request
of a device that's already locally-attached, it
doesn't setup its variables properly and is prone to
segfaulting on a subsequent rollback.

`ret = local_dev_probe(req->devargs, &dev)`

The above function will set `dev` pointer to the
proper device *unless* it returns with error. One of
those errors is -EEXIST, which the hotplug function
explicitly ignores. For -EEXIST, it proceeds with
attaching the device and expects the dev pointer to
be valid.

This patch makes `local_dev_probe` set the dev pointer
even if it returns -EEXIST.

Fixes: ac9e4a17370f ("eal: support attach/detach shared device from secondary")
Cc: qi.z.zhang@intel.com

Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
---
Changes since v1:
 * attempt to detach the device in primary process (Qi)

 lib/librte_eal/common/eal_common_dev.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
  

Comments

Thomas Monjalon Nov. 25, 2018, 12:25 p.m. UTC | #1
23/11/2018 22:26, Darek Stojaczyk:
> When primary process receives an IPC attach request
> of a device that's already locally-attached, it
> doesn't setup its variables properly and is prone to
> segfaulting on a subsequent rollback.
> 
> `ret = local_dev_probe(req->devargs, &dev)`
> 
> The above function will set `dev` pointer to the
> proper device *unless* it returns with error. One of
> those errors is -EEXIST, which the hotplug function
> explicitly ignores. For -EEXIST, it proceeds with
> attaching the device and expects the dev pointer to
> be valid.
> 
> This patch makes `local_dev_probe` set the dev pointer
> even if it returns -EEXIST.
> 
> Fixes: ac9e4a17370f ("eal: support attach/detach shared device from secondary")
> Cc: qi.z.zhang@intel.com
> 
> Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 1fdc9ab17..a08dc085f 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -168,16 +168,14 @@  local_dev_probe(const char *devargs, struct rte_device **new_dev)
 	}
 
 	ret = dev->bus->plug(dev);
-	if (ret) {
-		if (rte_dev_is_probed(dev)) /* if already succeeded earlier */
-			return ret; /* no rollback */
+	if (ret && !rte_dev_is_probed(dev)) { /* if hasn't ever succeeded */
 		RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
 			dev->name);
 		goto err_devarg;
 	}
 
 	*new_dev = dev;
-	return 0;
+	return ret;
 
 err_devarg:
 	if (rte_devargs_remove(da) != 0) {