patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH v2] bus/pci: fix unexpected resource mapping override
@ 2018-10-27  3:20 Qi Zhang
  2018-10-28 23:26 ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
  0 siblings, 1 reply; 4+ messages in thread
From: Qi Zhang @ 2018-10-27  3:20 UTC (permalink / raw)
  To: dev
  Cc: anatoly.burakov, ferruh.yigit, geoffrey.lv, ajit.khaparde,
	Qi Zhang, stable

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")
Cc: stable@dpdk.org

Reported-by: Lv Geoffrey <geoffrey.lv@gmail.com>
Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---

v2:
- use rte_dev_is_probed.
- reword comment.

 drivers/bus/pci/linux/pci.c | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c
index 145cb1091..f3175fb2b 100644
--- a/drivers/bus/pci/linux/pci.c
+++ b/drivers/bus/pci/linux/pci.c
@@ -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;
-- 
2.13.6

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH v2] bus/pci: fix unexpected resource mapping override
  2018-10-27  3:20 [dpdk-stable] [PATCH v2] bus/pci: fix unexpected resource mapping override Qi Zhang
@ 2018-10-28 23:26 ` Thomas Monjalon
  2018-10-30 15:19   ` Zhang, Qi Z
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Monjalon @ 2018-10-28 23:26 UTC (permalink / raw)
  To: Qi Zhang
  Cc: dev, anatoly.burakov, ferruh.yigit, geoffrey.lv, ajit.khaparde,
	stable, gaetan.rivet, arybchenko

27/10/2018 05:20, Qi Zhang:
> 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")
> Cc: stable@dpdk.org
> 
> Reported-by: Lv Geoffrey <geoffrey.lv@gmail.com>
> Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH v2] bus/pci: fix unexpected resource mapping override
  2018-10-28 23:26 ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
@ 2018-10-30 15:19   ` Zhang, Qi Z
  2018-10-31 18:24     ` Thomas Monjalon
  0 siblings, 1 reply; 4+ messages in thread
From: Zhang, Qi Z @ 2018-10-30 15:19 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dev, Burakov, Anatoly, Yigit, Ferruh, geoffrey.lv, ajit.khaparde,
	stable, gaetan.rivet, arybchenko



> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Sunday, October 28, 2018 6:27 PM
> To: Zhang, Qi Z <qi.z.zhang@intel.com>
> Cc: dev@dpdk.org; Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit,
> Ferruh <ferruh.yigit@intel.com>; geoffrey.lv@gmail.com;
> ajit.khaparde@broadcom.com; stable@dpdk.org; gaetan.rivet@6wind.com;
> arybchenko@solarflare.com
> Subject: Re: [dpdk-dev] [PATCH v2] bus/pci: fix unexpected resource mapping
> override
> 
> 27/10/2018 05:20, Qi Zhang:
> > 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")
> > Cc: stable@dpdk.org
> >
> > Reported-by: Lv Geoffrey <geoffrey.lv@gmail.com>
> > Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
> 
> I still think something must be fixed in PCI scan.

We are fixing something in PCI scan, right?
> 
> Anyway, there is an error:
> passing argument 1 of ‘rte_dev_is_probed’ from incompatible pointer type

So sorry, I should compile it first
.

> 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH v2] bus/pci: fix unexpected resource mapping override
  2018-10-30 15:19   ` Zhang, Qi Z
@ 2018-10-31 18:24     ` Thomas Monjalon
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Monjalon @ 2018-10-31 18:24 UTC (permalink / raw)
  To: Zhang, Qi Z
  Cc: dev, Burakov, Anatoly, Yigit, Ferruh, geoffrey.lv, ajit.khaparde,
	stable, gaetan.rivet, arybchenko

30/10/2018 16:19, Zhang, Qi Z:
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > 27/10/2018 05:20, Qi Zhang:
> > > 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")
> > > Cc: stable@dpdk.org
> > >
> > > Reported-by: Lv Geoffrey <geoffrey.lv@gmail.com>
> > > Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
> > 
> > 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 :)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-10-31 18:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-27  3:20 [dpdk-stable] [PATCH v2] bus/pci: fix unexpected resource mapping override Qi Zhang
2018-10-28 23:26 ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
2018-10-30 15:19   ` Zhang, Qi Z
2018-10-31 18:24     ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).