[dpdk-dev] [PATCH 1/3] bus/pci: update device devargs on each rescan

Stojaczyk, Dariusz dariusz.stojaczyk at intel.com
Mon Nov 5 15:52:00 CET 2018


Hi Gaetan,

> -----Original Message-----
> From: Gaëtan Rivet [mailto:gaetan.rivet at 6wind.com]
> Subject: Re: [dpdk-dev] [PATCH 1/3] bus/pci: update device devargs on each
> rescan
> 
> Hi Darek,
> 
> On Mon, Nov 05, 2018 at 08:04:45AM +0100, Darek Stojaczyk wrote:
> > Bus rescan is done e.g. during the device hotplug,
> > where devargs are re-allocated. By not updating the
> > rte_device->devargs pointer we potentially make it
> > a dangling one, as previous devargs could have been
> > (or will be soon) freed.
> >
> > Fixes: 55e411b301c3 ("bus/pci: fix resource mapping override")
> > Cc: qi.z.zhang at intel.com
> >
> > Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk at intel.com>
> > ---
> >  drivers/bus/pci/linux/pci.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c
> > index f87533c5c..f3172960e 100644
> > --- a/drivers/bus/pci/linux/pci.c
> > +++ b/drivers/bus/pci/linux/pci.c
> > @@ -349,10 +349,10 @@ pci_scan_one(const char *dirname, const struct
> rte_pci_addr *addr)
> >  			if (ret < 0) {
> >  				rte_pci_insert_device(dev2, dev);
> >  			} else { /* already registered */
> > +				pci_name_set(dev2);
> 
> This is rather unfortunate to call pci_name_set()
> to trigger the mapping devargs <-> devices.
> 
> pci_devargs_lookup could be made non-static instead,
> if that's sufficient. 

This is unfortunately trigerred by the generic eal device hotplug path which looks as follows:

da = calloc(sizeof rte_devargs);
[...]
rte_devargs_insert(da); # frees the previous devargs that rte_device still references
da->bus->scan(); # this should update the dangling devargs/name pointer in rte_device

Instead of making pci_devargs_lookup public, we would have to introduce a new bus callback for updating devargs of only a single device and that would be a really, realy ugly overkill. Thomas already mentioned in the subsequent patch within this series that we might want to re-think the devargs design in the next release.

> Given that the PCI id matches because the device
> is a duplicate (already registered), then the name itself probably does
> not need to be updated.

The issue here was that old devargs/name could have been freed.
The new name is the same as the old one, it's just in a different buffer.

I know calling pci_name_set() on each device during scan is not perfect, but IMO it's enforced by the current rte_devargs design. Besides, this used to be the original behavior before 55e411b301c3 ("bus/pci: fix resource mapping override").

Thanks,
D.

> 
> >  <snip>
> 
> --
> Gaëtan Rivet
> 6WIND


More information about the dev mailing list