Re: [PATCH v2] PCI: Remove redudant call to pci_proc_attach_device()

From: Bjorn Helgaas

Date: Mon Mar 09 2026 - 18:50:24 EST


On Sat, Feb 28, 2026 at 12:51:29PM +0530, Manivannan Sadhasivam wrote:
> pci_proc_init() should just initialize the top level procfs directory for
> PCI devices and let pci_bus_add_device() add the device specific procfs
> attributes later.
>
> But it is also calling pci_proc_attach_device() for each PCI device. This
> causes a race condition with pci_bus_add_device(), which may run in
> parallel, calling the same API, leading to the below warning spat:
>
> proc_dir_entry '000c:00/00.0' already registered
> WARNING: CPU: 2 PID: 179 at fs/proc/generic.c:375 proc_register+0xf6/0x180
> proc_register+0xf6/0x180
> proc_create_data+0x3e/0x60
> pci_proc_attach_device+0x74/0x130
> pci_bus_add_device+0x42/0x100
> pci_bus_add_devices+0xc6/0x110
>
> Hence, remove the call to pci_proc_attach_device() from pci_proc_init().

Seems plausible, but given that this code has been this way basically
forever, I'd sure like to figure out what's different about Shuan and
Lorenzo's system that makes this issue show up now.

> Reported-by: Lorenzo Pieralisi <lpieralisi@xxxxxxxxxx>
> Reported-by: Shuan He <heshuan@xxxxxxxxxxxxx>
> Closes: https://lore.kernel.org/linux-pci/20250702155112.40124-1-heshuan@xxxxxxxxxxxxx
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@xxxxxxxxxxxxxxxx>
> ---
>
> Changes in v2:
>
> * Dropped the sysfs change as it is supposed to be replaced by static resources
> change.

v1: https://lore.kernel.org/linux-pci/20250723111124.13694-1-manivannan.sadhasivam@xxxxxxxxxxxxxxxx/

> NOTE: I don't know if there is any reason to call pci_proc_attach_device()
> before pci_bus_add_device(), but it definitely causes a race.
>
> drivers/pci/proc.c | 3 ---
> 1 file changed, 3 deletions(-)
>
> diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
> index ce36e35681e8..de894ae70e9a 100644
> --- a/drivers/pci/proc.c
> +++ b/drivers/pci/proc.c
> @@ -463,13 +463,10 @@ int pci_proc_detach_bus(struct pci_bus *bus)
>
> static int __init pci_proc_init(void)
> {
> - struct pci_dev *dev = NULL;
> proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
> proc_create_seq("devices", 0, proc_bus_pci_dir,
> &proc_bus_pci_devices_op);
> proc_initialized = 1;
> - for_each_pci_dev(dev)
> - pci_proc_attach_device(dev);
>
> return 0;
> }
> --
> 2.51.0
>