dev: don't try to rollback a device attach that failed

Message ID 20181121190507.61845-1-dariusz.stojaczyk@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series dev: don't try to rollback a device attach that failed |

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. 21, 2018, 7:05 p.m. UTC
  If a device fails to attach before it's plugged,
the subsequent rollback will still try to detach it,
causing a segfault. Unplugging a device that wasn't
plugged isn't really supported, so this patch adds
an extra error check to prevent that from happening.

While here, fix this also for normal (non-rollback)
detach, which could also theoretically segfault on
non-plugged device.

Fixes: 244d5130719c ("eal: enable hotplug on multi-process")
Cc: qi.z.zhang@intel.com

Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
---
 lib/librte_eal/common/hotplug_mp.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
  

Comments

Thomas Monjalon Nov. 25, 2018, 12:10 p.m. UTC | #1
21/11/2018 20:05, Darek Stojaczyk:
> If a device fails to attach before it's plugged,
> the subsequent rollback will still try to detach it,
> causing a segfault. Unplugging a device that wasn't
> plugged isn't really supported, so this patch adds
> an extra error check to prevent that from happening.
> 
> While here, fix this also for normal (non-rollback)
> detach, which could also theoretically segfault on
> non-plugged device.
> 
> Fixes: 244d5130719c ("eal: enable hotplug on multi-process")
> 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/hotplug_mp.c b/lib/librte_eal/common/hotplug_mp.c
index 7c9fcc46c..d9e6790da 100644
--- a/lib/librte_eal/common/hotplug_mp.c
+++ b/lib/librte_eal/common/hotplug_mp.c
@@ -264,6 +264,19 @@  static void __handle_primary_request(void *param)
 			goto quit;
 		}
 
+		if (!rte_dev_is_probed(dev)) {
+			if (req->t == EAL_DEV_REQ_TYPE_ATTACH_ROLLBACK) {
+				/**
+				 * Don't fail the rollback just because there's
+				 * nothing to do.
+				 */
+				ret = 0;
+			} else
+				ret = -ENODEV;
+
+			goto quit;
+		}
+
 		ret = local_dev_remove(dev);
 quit:
 		free(da->args);