Skip to contentSkip to conversation

bus/pci: fix unexpected resource mapping override

PATCH Superseded Qi Zhang 2 participants 4 messages Oct 27, 2018 – Oct 31, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Qi Zhang

author
#0 lore raw

PATCH v2 1/1 bus/pci: fix unexpected resource mapping override

When scanning an already plugged device, the virtual address of mapped PCI resource in rte_pci_device will be overridden with 0, that may cause driver does not work correctly. The fix is not to update any rte_pci_device's field if the being scanned device's driver is already probed.

Bugzilla ID: 85

Fixes c752998b5e2e ("pci: introduce library and driver")

---

v2:
- use rte_dev_is_probed.
- reword comment.

 drivers/bus/pci/linux/pci.c | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)
drivers/bus/pci/linux/pci.c +30 -5
index 145cb1091..f3175fb2b 100644
@@ -349,11 +349,36 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 			if (ret < 0) {
 				rte_pci_insert_device(dev2, dev);
 			} else { /* already registered */
-				dev2->kdrv = dev->kdrv;
-				dev2->max_vfs = dev->max_vfs;
-				pci_name_set(dev2);
-				memmove(dev2->mem_resource, dev->mem_resource,
-					sizeof(dev->mem_resource));
+				if (!rte_dev_is_probed(dev2)) {
+					dev2->kdrv = dev->kdrv;
+					dev2->max_vfs = dev->max_vfs;
+					pci_name_set(dev2);
+					memmove(dev2->mem_resource,
+						dev->mem_resource,
+						sizeof(dev->mem_resource));
+				} else {
+					/**
+					 * If device is plugged and driver is
+					 * probed already, (This happens when we
+					 * call rte_dev_probe which will scan all
+					 * device on the bus) we don't need
+					 * to do anything here unless...
+					 **/
+					if (dev2->kdrv != dev->kdrv ||
+						dev2->max_vfs != dev->max_vfs)
+						/*
+						 * This should not happens.
+						 * But it is still possible if
+						 * we unbind a device from
+						 * vfio or uio before hotplug
+						 * remove and rebind it with
+						 * a different configure.
+						 * So we just print out the
+						 * error as an alarm.
+						 */
+						RTE_LOG(ERR, EAL, "Unexpected device scan at %s!\n",
+							filename);
+				}
 				free(dev);
 			}
 			return 0;
Signature · 1 line
2.13.6
#1 lore raw

27/10/2018 05:20, Qi Zhang:

Quoted 6 lines

When scanning an already plugged device, the virtual address of mapped PCI resource in rte_pci_device will be overridden with 0, that may cause driver does not work correctly. The fix is not to update any rte_pci_device's field if the being scanned device's driver is already probed.

Quoted 6 lines

Bugzilla ID: 85

Fixes c752998b5e2e ("pci: introduce library and driver")

I still think something must be fixed in PCI scan.

Anyway, there is an error:
passing argument 1 of ‘rte_dev_is_probed’ from incompatible pointer type

#2 lore raw
Quoted 20 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Sunday, October 28, 2018 6:27 PM
To: Zhang, Qi Z <[email protected]>
Cc: [email protected]; Burakov, Anatoly <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v2] bus/pci: fix unexpected resource mapping override

27/10/2018 05:20, Qi Zhang:

Quoted 6 lines

When scanning an already plugged device, the virtual address of mapped PCI resource in rte_pci_device will be overridden with 0, that may cause driver does not work correctly.
The fix is not to update any rte_pci_device's field if the being scanned device's driver is already probed.

Quoted 8 lines
Quoted 6 lines

Bugzilla ID: 85

Fixes c752998b5e2e ("pci: introduce library and driver")

I still think something must be fixed in PCI scan.

We are fixing something in PCI scan, right?

Quoted 3 lines

Anyway, there is an error:
passing argument 1 of ‘rte_dev_is_probed’ from incompatible pointer type

So sorry, I should compile it first
.

Quoted 2 lines
#3 lore raw

30/10/2018 16:19, Zhang, Qi Z:

Quoted 12 lines

From: Thomas Monjalon [mailto:[email protected]]

Quoted 11 lines

27/10/2018 05:20, Qi Zhang:

Quoted 10 lines

When scanning an already plugged device, the virtual address of mapped PCI resource in rte_pci_device will be overridden with 0, that may cause driver does not work correctly.
The fix is not to update any rte_pci_device's field if the being scanned device's driver is already probed.

Bugzilla ID: 85

Fixes c752998b5e2e ("pci: introduce library and driver")
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I still think something must be fixed in PCI scan.

We are fixing something in PCI scan, right?

Yes :)
I was thinking about not scanning an already scanned device. If the device has been unplugged, it should be removed, and re-added when plugged, instead of trying to update it.

I understand this is another kind of change and deserves more time to think about the right design. That's why I will accept the v3 of this patch.

Anyway the road to get hotplug handled right is long :)