[igt-dev] [PATCH i-g-t] lib/igt_device: Add support for accessing unbound VF PCI devices

Chris Wilson chris.p.wilson at intel.com
Fri Feb 18 20:53:09 UTC 2022


Quoting Janusz Krzysztofik (2022-02-18 17:08:41)
> Hi Chris,
> 
> On Friday, 18 February 2022 17:03:01 CET Chris Wilson wrote:
> > Quoting Janusz Krzysztofik (2022-02-18 15:19:35)
> > > @@ -206,15 +229,19 @@ static struct pci_device *__igt_device_get_pci_device(int fd)
> > >                 igt_warn("Couldn't find PCI device %04x:%02x:%02x:%02x\n",
> > >                          pci_addr.domain, pci_addr.bus,
> > >                          pci_addr.device, pci_addr.function);
> > > -               return NULL;
> > > +               goto cleanup;
> > >         }
> > >  
> > >         if (pci_device_probe(pci_dev)) {
> > >                 igt_warn("Couldn't probe PCI device\n");
> > > -               return NULL;
> > > +               goto cleanup;
> > >         }
> > >  
> > >         return pci_dev;
> > > +
> > > +cleanup:
> > > +       pci_system_cleanup();
> > 
> > This is a global cleanup of libpciaccess iirc, such that if anyone else
> > was using the library they would be affected.
> 
> Right, but shouldn't we also drop pci_system_init() from here and request 
> users to manage initialization and cleanup of that data themselves?  On each 
> call pci_system_init() abandons existing data and overwrites a pointer to it 
> with that of newly allocated memory, then tests calling 
> igt_device_get_pci_device() multiple times are going to suffer from 
> significant memory leaking.

Right, I thought it only inited once -- I just remember the issue with
calling pci_system_cleanup() while others were still using it.

Stick the call to init in an __attribute__((constructor)) or pthread_once.
-Chris


More information about the igt-dev mailing list