Skip to contentSkip to conversation

pci: Don't call probe callback if driver already loaded.

PATCH Applied Ben Walker 4 participants 8 messages Oct 25, 2016 – Nov 7, 2016

lore
Share & tools
lore

Ben Walker

author
#0 lore raw

PATCH 1/1 pci: Don't call probe callback if driver already loaded.

If the user asks to probe multiple times, the probe callback should only be called on devices that don't have a driver already loaded.

This is useful if a driver is registered after the execution of a program has started and the list of devices needs to be re-scanned.

---
 lib/librte_eal/common/eal_common_pci.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/librte_eal/common/eal_common_pci.c +4 -0
index 638cd86..971ad20 100644
@@ -289,6 +289,10 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 	if (dev == NULL)
 		return -1;
 
+	/* Check if a driver is already loaded */
+	if (dev->driver != NULL)
+		return 0;
+
 	TAILQ_FOREACH(dr, &pci_driver_list, next) {
 		rc = rte_eal_pci_probe_one_driver(dr, dev);
 		if (rc < 0)
Signature · 1 line
2.7.4
#1 lore raw

Hello Benjamin,

Quoted 7 lines · Ben Walker

If the user asks to probe multiple times, the probe callback should only be called on devices that don't have a driver already loaded.

This is useful if a driver is registered after the execution of a program has started and the list of devices needs to be re-scanned.

Why not use the hotplug api, attaching explicitely one pci device ?

Quoted 10 lines
---
 lib/librte_eal/common/eal_common_pci.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/librte_eal/common/eal_common_pci.c +0 -0
index 638cd86..971ad20 100644

lib/librte_eal/common/eal_common_pci.c pci_probe_all_drivers(struct rte_pci_device *dev) · line 295

Quoted 7 lines
lib/librte_eal/common/eal_common_pci.c +4 -0
@@ -289,6 +289,10 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
        if (dev == NULL)
                return -1;
 
+       /* Check if a driver is already loaded */
+       if (dev->driver != NULL)
+               return 0;
+

This can do the trick, yes.

To be safe, I think we are missing a check in rte_eal_pci_probe_one_driver() so that dev->driver is only set when the probe function from the driver did succeed.

Signature · 1 line
David Marchand
#2 lore raw
Quoted 10 lines · David Marchand
Quoted 7 lines · Ben Walker

If the user asks to probe multiple times, the probe callback should only be called on devices that don't have a driver already loaded.

This is useful if a driver is registered after the execution of a program has started and the list of devices needs to be re-scanned.

Why not use the hotplug api, attaching explicitely one pci device ?

Ah, scratch that.
I've been too quick to reply.
Ok, you are loading a new driver.

Signature · 1 line
David Marchand
#3 lore raw
In reply to Ben Walker
Quoted 18 lines · Ben Walker

If the user asks to probe multiple times, the probe callback should only be called on devices that don't have a driver already loaded.

This is useful if a driver is registered after the execution of a program has started and the list of devices needs to be re-scanned.

---
 lib/librte_eal/common/eal_common_pci.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/librte_eal/common/eal_common_pci.c +0 -0
index 638cd86..971ad20 100644

lib/librte_eal/common/eal_common_pci.c pci_probe_all_drivers(struct rte_pci_device *dev) · line 295

Quoted 7 lines
lib/librte_eal/common/eal_common_pci.c +4 -0
@@ -289,6 +289,10 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 	if (dev == NULL)
 		return -1;
 
+	/* Check if a driver is already loaded */
+	if (dev->driver != NULL)
+		return 0;
+

In case if it is required to change the driver assigned to a device, would it mean application relies on detach(dev)->new-driver-plugged-in->attach(dev) sequence? To me, the above change sounds fine. Though, I am not aware if there is even a use case for changing driver assigned to a device. detach()->attach() should be able to work in those cases, I think.

lib/librte_eal/common/eal_common_pci.c pci_probe_all_drivers(struct rte_pci_device *dev) · line 298

Quoted 4 lines
lib/librte_eal/common/eal_common_pci.c +0 -0
 	TAILQ_FOREACH(dr, &pci_driver_list, next) {
 		rc = rte_eal_pci_probe_one_driver(dr, dev);
 		if (rc < 0)

-
Shreyansh

#4 lore raw
In reply to Ben Walker

2016-10-25 14:50, Ben Walker:

Quoted 9 lines

If the user asks to probe multiple times, the probe callback should only be called on devices that don't have a driver already loaded.

This is useful if a driver is registered after the execution of a program has started and the list of devices needs to be re-scanned.

Applied, thanks

#5 lore raw

Hello Thomas,

Quoted 5 lines · Thomas Monjalon

2016-10-25 14:50, Ben Walker:

Quoted 4 lines

If the user asks to probe multiple times, the probe callback should only be called on devices that don't have a driver already loaded.

Quoted 7 lines
Quoted 5 lines

This is useful if a driver is registered after the execution of a program has started and the list of devices needs to be re-scanned.

Applied, thanks

Can you add a follow up patch I will send shortly ? Thanks.

Signature · 1 line
David Marchand
#6 lore raw

PATCH 1/1 pci: do not mark device as taken when probe fails

dev->driver should be set only if a driver did take the device.

---
 lib/librte_eal/common/eal_common_pci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_pci.c +5 -1
index 971ad20..6163b09 100644
@@ -214,7 +214,11 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
 		dev->driver = dr;
 
 		/* call the driver probe() function */
-		return dr->probe(dr, dev);
+		ret = dr->probe(dr, dev);
+		if (ret)
+			dev->driver = NULL;
+
+		return ret;
 	}
 	/* return positive value if driver doesn't support this device */
 	return 1;
Signature · 1 line
2.7.4
#7 lore raw

Re: [PATCH] pci: do not mark device as taken when probe fails

2016-11-07 10:03, David Marchand:

Quoted 3 lines

dev->driver should be set only if a driver did take the device.

Applied, thanks