Re: [PATCH] PCI/sysfs: Fix race in pci sysfs creation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 19, 2024 at 10:41:56PM -0800, Saurabh Singh Sengar wrote:
> On Wed, Jan 03, 2024 at 09:38:03PM -0800, Saurabh Singh Sengar wrote:
> > On Tue, Dec 12, 2023 at 12:28:05AM -0800, Saurabh Singh Sengar wrote:
> > > On Tue, Dec 12, 2023 at 08:19:11AM +0100, Alexander Stein wrote:
> > > > Hi Saurabh,
> > > > 
> > > > thanks for the patch.
> > > > 
> > > > Am Samstag, 9. Dezember 2023, 04:46:16 CET schrieb Saurabh Sengar:
> > > > > Currently there is a race in calling pci_create_resource_files function
> > > > > from two different therads, first therad is triggered by pci_sysfs_init
> > > > > from the late initcall where as the second thread is initiated by
> > > > > pci_bus_add_devices from the respective PCI drivers probe.
> > > > > 
> > > > > The synchronization between these threads relies on the sysfs_initialized
> > > > > flag. However, in pci_sysfs_init, sysfs_initialized is set right before
> > > > > calling pci_create_resource_files which is wrong as it can create race
> > > > > condition with pci_bus_add_devices threads. Fix this by setting
> > > > > sysfs_initialized flag at the end of pci_sysfs_init and direecly call the
> > > > 
> > > > Small typo here: direecly -> directly
> > > > 
> > > > > pci_create_resource_files function from it.
> > > > > 
> > > > > There can be an additional case where driver probe is so delayed that
> > > > > pci_bus_add_devices is called after the sysfs is created by pci_sysfs_init.
> > > > > In such cases, attempting to access already existing sysfs resources is
> > > > > unnecessary. Fix this by adding a check for sysfs attributes and return
> > > > > if they are already allocated.
> > > > > 
> > > > > In both cases, the consequence will be the removal of sysfs resources that
> > > > > were appropriately allocated by pci_sysfs_init following the warning below.
> > > > 
> > > > I'm not sure if this is the way to go. Unfortunately I can't trigger this 
> > > > error on my imx6 platform at the moment (apparently timing is off).
> > > > But reading [1] again, the most expressive way is that pci_bus_add_devices() 
> > > > needs to wait until pci_sysfs_init() has passed.
> > > 
> > > (I correct my self a bit in my earlier reply)
> > > The problem with waiting is that sysfs entries will be created by pci_sysfs_init
> > > already and when pci_bus_add_devices try to create it will observe that the
> > > entries are already existing and in such case PCI code will remove the sysfs
> > > entries created by pci_sysfs_init. Resulting system will be having no sysfs
> > > entries.
> > 
> > 
> > Hi Alexander,
> > Have you got time to check this ? Please let me know if you think there is any
> > concern left with this patch.
> 
> Hi PCI Maintainers,
> 
> If there is no objection, can we take this patch in ?
> 

ping

> 
> Regards,
> Saurabh
> 
> 
> 
> 




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux