Skip to contentSkip to conversation

dev: don't remove devargs that are still referenced

PATCH Superseded Darek Stojaczyk 4 participants 9 messages Nov 21, 2018 – Nov 25, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dev: don't remove devargs that are still referenced

Even if a device failed to plug, it's still a device object that references the devargs. Those devargs will be freed automatically together with the device, but can't be freed any earlier.

Fixes 7e8b26650146 ("eal: fix hotplug add / remove")
---
 lib/librte_eal/common/eal_common_dev.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
lib/librte_eal/common/eal_common_dev.c +4 -5
index 1fdc9ab17..b6fc5e437 100644
@@ -169,11 +169,10 @@ 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 */
-		RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
-			dev->name);
-		goto err_devarg;
+		if (!rte_dev_is_probed(dev)) /* if hasn't succeeded earlier */
+			RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
+				dev->name);
+		return ret;
 	}
 
 	*new_dev = dev;
Signature · 1 line
2.17.1
#1 lore raw

21/11/2018 19:37, Darek Stojaczyk:

Quoted 4 lines

Even if a device failed to plug, it's still a device object that references the devargs. Those devargs will be freed automatically together with the device, but can't be freed any earlier.

Thanks for the patch.
Please, be more specific about the bug.
You could add 2 more paragraphs:
- One before, to explain the tested scenario and the result.
- One after, to explain how it is fixed (changing the goto by a return).

[...]

Quoted 12 lines
lib/librte_eal/common/eal_common_dev.c +4 -5
 	ret = dev->bus->plug(dev);
 	if (ret) {
-		if (rte_dev_is_probed(dev)) /* if already succeeded earlier */
-			return ret; /* no rollback */
-		RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
-			dev->name);
-		goto err_devarg;
+		if (!rte_dev_is_probed(dev)) /* if hasn't succeeded earlier */
+			RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
+				dev->name);
+		return ret;
 	}
#2 lore raw

PATCH v2 1/1 dev: don't remove devargs that are still referenced

In reply to Darek Stojaczyk

Even if a device failed to plug, it's still a device object that references the devargs. Those devargs will be freed automatically together with the device, but freeing them any earlier - like it's done in the hotplug error handling path right now - will give us a dangling pointer and a segfault scenario.

Consider the following case:
* secondary process receives the hotplug request IPC message
* devargs are either created or updated
* the bus is scanned
* a new device object is created with the latest devargs
* the device can't be plugged for whatever reason, bus->plug returns error
* the devargs are freed, even though they're still referenced by the device object on the bus

For PCI devices, the generic device name comes from a buffer within the devargs. Freeing those will make EAL segfault whenever the device name is checked.

This patch just prevents the hotplug error handling path from removing the devargs when there's a device that references them. This is done by simply exiting early from the hotplug function. As mentioned in the beginning, those devargs will be freed later, together with the device itself.

Fixes 7e8b26650146 ("eal: fix hotplug add / remove")
---
 lib/librte_eal/common/eal_common_dev.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
lib/librte_eal/common/eal_common_dev.c +4 -5
index 1fdc9ab17..b6fc5e437 100644
@@ -169,11 +169,10 @@ 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 */
-		RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
-			dev->name);
-		goto err_devarg;
+		if (!rte_dev_is_probed(dev)) /* if hasn't succeeded earlier */
+			RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
+				dev->name);
+		return ret;
 	}
 
 	*new_dev = dev;
Signature · 1 line
2.17.1
#3 lore raw
Quoted 21 lines · Darek Stojaczyk

Even if a device failed to plug, it's still a device object that references the devargs. Those devargs will be freed automatically together with the device, but freeing them any earlier - like it's done in the hotplug error handling path right now - will give us a dangling pointer and a segfault scenario.

Consider the following case:
* secondary process receives the hotplug request IPC message
* devargs are either created or updated
* the bus is scanned
* a new device object is created with the latest devargs
* the device can't be plugged for whatever reason, bus->plug returns error
* the devargs are freed, even though they're still referenced by the device object on the bus

For PCI devices, the generic device name comes from a buffer within the devargs. Freeing those will make EAL segfault whenever the device name is checked.

Quoted 7 lines

This patch just prevents the hotplug error handling path from removing the devargs when there's a device that references them. This is done by simply exiting early from the hotplug function. As mentioned in the beginning, those devargs will be freed later, together with the device itself.

This seems ok in conjunction with Thomas' patch on overwriting devargs on insertion.

The only place a device will be freed is the unplug bus ops, it already does remove the device devargs.

Quoted 15 lines
Fixes 7e8b26650146 ("eal: fix hotplug add / remove")
---
 lib/librte_eal/common/eal_common_dev.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
lib/librte_eal/common/eal_common_dev.c +0 -0
index 1fdc9ab17..b6fc5e437 100644
@@ -169,11 +169,10 @@ local_dev_probe(const char *devargs, struct rte_device **new_dev)
 

lib/librte_eal/common/eal_common_dev.c local_dev_probe(const char *devargs, struct rte_device **new_dev) · line 174

Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +3 -5
 	ret = dev->bus->plug(dev);
 	if (ret) {
-		if (rte_dev_is_probed(dev)) /* if already succeeded earlier */
-			return ret; /* no rollback */
-		RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
-			dev->name);
-		goto err_devarg;
+		if (!rte_dev_is_probed(dev)) /* if hasn't succeeded earlier */
+			RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
+				dev->name);

Maybe a comment here to describe that the devargs is still the responsibility of the rte_device and should not be removed.

Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +1 -0
+		return ret;
 	}
 
 	*new_dev = dev;
Signature · 1 line
2.17.1
Signature · 2 lines
Gaëtan Rivet
6WIND
#4 lore raw
Quoted 72 lines

-----Original Message-----
From: Gaëtan Rivet [mailto:[email protected]]
Sent: Thursday, November 22, 2018 10:54 AM
To: Stojaczyk, Dariusz <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v2] dev: don't remove devargs that are still referenced

Quoted 21 lines · Darek Stojaczyk

Even if a device failed to plug, it's still a device object that references the devargs. Those devargs will be freed automatically together with the device, but freeing them any earlier - like it's done in the hotplug error handling path right now - will give us a dangling pointer and a segfault scenario.

Consider the following case:
* secondary process receives the hotplug request IPC message
* devargs are either created or updated
* the bus is scanned
* a new device object is created with the latest devargs
* the device can't be plugged for whatever reason, bus->plug returns error
* the devargs are freed, even though they're still referenced by the device object on the bus

For PCI devices, the generic device name comes from a buffer within the devargs. Freeing those will make EAL segfault whenever the device name is checked.

Quoted 7 lines

This patch just prevents the hotplug error handling path from removing the devargs when there's a device that references them. This is done by simply exiting early from the hotplug function. As mentioned in the beginning, those devargs will be freed later, together with the device itself.

This seems ok in conjunction with Thomas' patch on overwriting devargs on insertion.

The only place a device will be freed is the unplug bus ops, it already does remove the device devargs.

Review

Quoted 10 lines
Fixes 7e8b26650146 ("eal: fix hotplug add / remove")
---
 lib/librte_eal/common/eal_common_dev.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/lib/librte_eal/common/eal_common_dev.c

lib/librte_eal/common/eal_common_dev.c local_dev_probe(const char *devargs, struct

Quoted 4 lines

index 1fdc9ab17..b6fc5e437 100644

lib/librte_eal/common/eal_common_dev.c +0 -0
@@ -169,11 +169,10 @@ local_dev_probe(const char *devargs, struct

rte_device **new_dev)

lib/librte_eal/common/eal_common_dev.c local_dev_probe(const char *devargs, struct rte_device **new_dev)

Quoted 4 lines
lib/librte_eal/common/eal_common_dev.c +0 -1
 	ret = dev->bus->plug(dev);
 	if (ret) {
-		if (rte_dev_is_probed(dev)) /* if already succeeded earlier

*/

lib/librte_eal/common/eal_common_dev.c local_dev_probe(const char *devargs, struct rte_device **new_dev)

Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c +2 -4
-			return ret; /* no rollback */
-		RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
-			dev->name);
-		goto err_devarg;
+		if (!rte_dev_is_probed(dev)) /* if hasn't succeeded earlier */
+			RTE_LOG(ERR, EAL, "Driver cannot attach the device

(%s)\n",

Quoted 4 lines

lib/librte_eal/common/eal_common_dev.c local_dev_probe(const char *devargs, struct rte_device **new_dev) · line 174

Quoted 1 line
lib/librte_eal/common/eal_common_dev.c +1 -0
+				dev->name);

Maybe a comment here to describe that the devargs is still the responsibility of the rte_device and should not be removed.

Ack, I'll do that.

Quoted 12 lines
Quoted 8 lines
lib/librte_eal/common/eal_common_dev.c +1 -1
+		return ret;
 	}
 
 	*new_dev = dev;
--

2.17.1

--
Gaëtan Rivet
6WIND

#5 lore raw

PATCH v3 1/1 dev: don't remove devargs that are still referenced

In reply to Darek Stojaczyk

Even if a device failed to plug, it's still a device object that references the devargs. Those devargs will be freed automatically together with the device, but freeing them any earlier - like it's done in the hotplug error handling path right now - will give us a dangling pointer and a segfault scenario.

Consider the following case:
* secondary process receives the hotplug request IPC message
* devargs are either created or updated
* the bus is scanned
* a new device object is created with the latest devargs
* the device can't be plugged for whatever reason, bus->plug returns error
* the devargs are freed, even though they're still referenced by the device object on the bus

For PCI devices, the generic device name comes from a buffer within the devargs. Freeing those will make EAL segfault whenever the device name is checked.

This patch just prevents the hotplug error handling path from removing the devargs when there's a device that references them. This is done by simply exiting early from the hotplug function. As mentioned in the beginning, those devargs will be freed later, together with the device itself.

Fixes 7e8b26650146 ("eal: fix hotplug add / remove")

---
Changes since v2:
* added an extra comment (Gaetan)

Changes since v1:
* described the failing scenario in commit msg (Thomas)

 lib/librte_eal/common/eal_common_dev.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
lib/librte_eal/common/eal_common_dev.c +8 -5
index 1fdc9ab17..d7950bc9a 100644
@@ -166,14 +166,17 @@ local_dev_probe(const char *devargs, struct rte_device **new_dev)
 		ret = -ENODEV;
 		goto err_devarg;
 	}
+	/* Since there is a matching device, it is now its responsibility
+	 * to manage the devargs we've just inserted. From this point
+	 * those devargs shouldn't be removed manually anymore.
+	 */
 
 	ret = dev->bus->plug(dev);
 	if (ret) {
-		if (rte_dev_is_probed(dev)) /* if already succeeded earlier */
-			return ret; /* no rollback */
-		RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
-			dev->name);
-		goto err_devarg;
+		if (!rte_dev_is_probed(dev)) /* if hasn't succeeded earlier */
+			RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
+				dev->name);
+		return ret;
 	}
 
 	*new_dev = dev;
Signature · 1 line
2.17.1
Acked-by on v3 1/1
#6 lore raw

Hi,

Quoted 21 lines · Darek Stojaczyk

Even if a device failed to plug, it's still a device object that references the devargs. Those devargs will be freed automatically together with the device, but freeing them any earlier - like it's done in the hotplug error handling path right now - will give us a dangling pointer and a segfault scenario.

Consider the following case:
* secondary process receives the hotplug request IPC message
* devargs are either created or updated
* the bus is scanned
* a new device object is created with the latest devargs
* the device can't be plugged for whatever reason, bus->plug returns error
* the devargs are freed, even though they're still referenced by the device object on the bus

For PCI devices, the generic device name comes from a buffer within the devargs. Freeing those will make EAL segfault whenever the device name is checked.

Quoted 8 lines

This patch just prevents the hotplug error handling path from removing the devargs when there's a device that references them. This is done by simply exiting early from the hotplug function. As mentioned in the beginning, those devargs will be freed later, together with the device itself.

Fixes 7e8b26650146 ("eal: fix hotplug add / remove")

Should you also cc stable?
Above commit is in since v17.08.

Quoted 32 lines

---
Changes since v2:
* added an extra comment (Gaetan)

Changes since v1:
* described the failing scenario in commit msg (Thomas)

  lib/librte_eal/common/eal_common_dev.c | 13 ++++++++-----
  1 file changed, 8 insertions(+), 5 deletions(-)
lib/librte_eal/common/eal_common_dev.c +4 -2
index 1fdc9ab17..d7950bc9a 100644
@@ -166,14 +166,17 @@ local_dev_probe(const char *devargs, struct rte_device **new_dev)
  		ret = -ENODEV;
  		goto err_devarg;
  	}
+	/* Since there is a matching device, it is now its responsibility
+	 * to manage the devargs we've just inserted. From this point
+	 * those devargs shouldn't be removed manually anymore.
+	 */
 
  	ret = dev->bus->plug(dev);
  	if (ret) {
-		if (rte_dev_is_probed(dev)) /* if already succeeded earlier */
-			return ret; /* no rollback */

lib/librte_eal/common/eal_common_dev.c local_dev_probe(const char *devargs, struct rte_device **new_dev) · line 182

Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +4 -3
-		RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
-			dev->name);
-		goto err_devarg;
+		if (!rte_dev_is_probed(dev)) /* if hasn't succeeded earlier */
+			RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
+				dev->name);
+		return ret;
  	}
 
  	*new_dev = dev;

Other than that, it looks good to me:

Regards,
Maxime

#7 lore raw
Quoted 41 lines

-----Original Message-----
From: Maxime Coquelin [mailto:[email protected]]
Sent: Friday, November 23, 2018 6:05 PM
To: Stojaczyk, Dariusz <[email protected]>; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v3] dev: don't remove devargs that are still referenced

Hi,

Quoted 28 lines · Darek Stojaczyk

Even if a device failed to plug, it's still a device object that references the devargs. Those devargs will be freed automatically together with the device, but freeing them any earlier - like it's done in the hotplug error handling path right now - will give us a dangling pointer and a segfault scenario.

Consider the following case:
* secondary process receives the hotplug request IPC message
* devargs are either created or updated
* the bus is scanned
* a new device object is created with the latest devargs
* the device can't be plugged for whatever reason, bus->plug returns error
* the devargs are freed, even though they're still referenced by the device object on the bus

For PCI devices, the generic device name comes from a buffer within the devargs. Freeing those will make EAL segfault whenever the device name is checked.

This patch just prevents the hotplug error handling path from removing the devargs when there's a device that references them. This is done by simply exiting early from the hotplug function. As mentioned in the beginning, those devargs will be freed later, together with the device itself.

Quoted 5 lines
Quoted 1 line
Fixes 7e8b26650146 ("eal: fix hotplug add / remove")

Should you also cc stable?
Above commit is in since v17.08.

Hi Maxime,

Stable could use a similar patch, but not exactly this one as it is now. I'll resubmit for stable once the one here gets approved.

Thank you,
D.

Quoted 52 lines
Quoted 8 lines

---
Changes since v2:
* added an extra comment (Gaetan)

Review

Quoted 7 lines

Changes since v1:
* described the failing scenario in commit msg (Thomas)

  lib/librte_eal/common/eal_common_dev.c | 13 ++++++++-----
  1 file changed, 8 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/lib/librte_eal/common/eal_common_dev.c

lib/librte_eal/common/eal_common_dev.c local_dev_probe(const char *devargs, struct

Quoted 4 lines

index 1fdc9ab17..d7950bc9a 100644

lib/librte_eal/common/eal_common_dev.c +0 -0
@@ -166,14 +166,17 @@ local_dev_probe(const char *devargs, struct

rte_device **new_dev)

lib/librte_eal/common/eal_common_dev.c local_dev_probe(const char *devargs, struct rte_device **new_dev)

Quoted 11 lines
lib/librte_eal/common/eal_common_dev.c +4 -1
  		ret = -ENODEV;
  		goto err_devarg;
  	}
+	/* Since there is a matching device, it is now its responsibility
+	 * to manage the devargs we've just inserted. From this point
+	 * those devargs shouldn't be removed manually anymore.
+	 */
 
  	ret = dev->bus->plug(dev);
  	if (ret) {
-		if (rte_dev_is_probed(dev)) /* if already succeeded earlier

*/

lib/librte_eal/common/eal_common_dev.c local_dev_probe(const char *devargs, struct rte_device **new_dev)

Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c +2 -4
-			return ret; /* no rollback */
-		RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
-			dev->name);
-		goto err_devarg;
+		if (!rte_dev_is_probed(dev)) /* if hasn't succeeded earlier */
+			RTE_LOG(ERR, EAL, "Driver cannot attach the device

(%s)\n",

lib/librte_eal/common/eal_common_dev.c local_dev_probe(const char *devargs, struct rte_device **new_dev) · line 182

Quoted 6 lines
lib/librte_eal/common/eal_common_dev.c +2 -0
+				dev->name);
+		return ret;
  	}
 
  	*new_dev = dev;

Other than that, it looks good to me:

Regards,
Maxime

#8 lore raw
In reply to Maxime Coquelin

23/11/2018 18:04, Maxime Coquelin:

Quoted 33 lines

Hi,

Quoted 21 lines · Darek Stojaczyk

Even if a device failed to plug, it's still a device object that references the devargs. Those devargs will be freed automatically together with the device, but freeing them any earlier - like it's done in the hotplug error handling path right now - will give us a dangling pointer and a segfault scenario.

Consider the following case:
* secondary process receives the hotplug request IPC message
* devargs are either created or updated
* the bus is scanned
* a new device object is created with the latest devargs
* the device can't be plugged for whatever reason, bus->plug returns error
* the devargs are freed, even though they're still referenced by the device object on the bus

For PCI devices, the generic device name comes from a buffer within the devargs. Freeing those will make EAL segfault whenever the device name is checked.

Quoted 8 lines

This patch just prevents the hotplug error handling path from removing the devargs when there's a device that references them. This is done by simply exiting early from the hotplug function. As mentioned in the beginning, those devargs will be freed later, together with the device itself.

Fixes 7e8b26650146 ("eal: fix hotplug add / remove")
Quoted 8 lines

Should you also cc stable?
Above commit is in since v17.08.

Quoted 4 lines

Applied (with rebase), thanks