public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Stein <alexander.stein@ew.tq-group.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: Korneliusz Osmenda <korneliuszo@gmail.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] Guard pci_create_sysfs_dev_files with atomic value
Date: Thu, 16 Mar 2023 10:18:22 +0100	[thread overview]
Message-ID: <4335627.mvXUDI8C0e@steina-w> (raw)
In-Reply-To: <20230316091540.494366-1-alexander.stein@ew.tq-group.com>

Hi,

for some reason my additional info was missing. See below.

Am Donnerstag, 16. März 2023, 10:15:40 CET schrieb Alexander Stein:
> From: Korneliusz Osmenda <korneliuszo@gmail.com>
> 
> On Gateworks Ventana there is a number of PCI devices and:
>   - imx6_pcie_probe takes longer than start of late init
>   - pci_sysfs_init sets up flag sysfs_initialized
>   - pci_sysfs_init initializes already found devices
>   - imx6_pcie_probe tries to reinitialize device
> 
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=215515
> 
> Signed-off-by: Korneliusz Osmenda <korneliuszo@gmail.com>
> Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> ---

Changes in v2:
* Rebased to next-20230323
* checkpath.pl fixes

I'm hitting the same issue on TQMa6x+MBa6x. There is a race in
pci_sysfs_init late initcall and pci_bus_add_device due to regular PCIe
bus probing. Having some debug output 'sysfs_initialized' is set to 1
while pci_bus_add_devices is still adding PCIe devices.
Having this patch applied my PCIe device using several bridges is detected
fine.

My PCIe bus looks like thi (using this patch):
root@tqma6-common:~# lspci
00:00.0 PCI bridge: Synopsys, Inc. DWC_usb3 / PCIe bridge (rev 01)
01:00.0 PCI bridge: Pericom Semiconductor Device a303 (rev 03)
02:01.0 PCI bridge: Pericom Semiconductor Device a303 (rev 03)
02:02.0 PCI bridge: Pericom Semiconductor Device a303 (rev 03)
03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411
PCI Express Gigabit Ethernet Controller (rev 0c)
04:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411
PCI Express Gigabit Ethernet Controller (rev 0c)

root@tqma6-common:~# lspci -t
-[0000:00]---00.0-[01-ff]----00.0-[02-04]--+-01.0-[03]----00.0
                                           \-02.0-[04]----00.0

Best regards,
Alexander

>  drivers/pci/pci-sysfs.c | 6 ++++++
>  include/linux/pci.h     | 2 ++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index dd0d9d9bc509..998e44716b6f 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -1497,6 +1497,9 @@ int __must_check pci_create_sysfs_dev_files(struct
> pci_dev *pdev) if (!sysfs_initialized)
>  		return -EACCES;
> 
> +	if (atomic_cmpxchg(&pdev->sysfs_init_cnt, 0, 1) == 1)
> +		return 0;		/* already added */
> +
>  	return pci_create_resource_files(pdev);
>  }
> 
> @@ -1511,6 +1514,9 @@ void pci_remove_sysfs_dev_files(struct pci_dev *pdev)
>  	if (!sysfs_initialized)
>  		return;
> 
> +	if (atomic_cmpxchg(&pdev->sysfs_init_cnt, 1, 0) == 0)
> +		return;		/* already removed */
> +
>  	pci_remove_resource_files(pdev);
>  }
> 
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index b50e5c79f7e3..024313a7a90a 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -467,6 +467,8 @@ struct pci_dev {
>  	pci_dev_flags_t dev_flags;
>  	atomic_t	enable_cnt;	/* pci_enable_device has been called 
*/
> 
> +	atomic_t	sysfs_init_cnt;	/* pci_create_sysfs_dev_files has been 
called */
> +
>  	u32		saved_config_space[16]; /* Config space saved at 
suspend time */
>  	struct hlist_head saved_cap_space;
>  	int		rom_attr_enabled;	/* Display of ROM attribute 
enabled? */


-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/



  reply	other threads:[~2023-03-16  9:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16  9:15 [PATCH v2 1/1] Guard pci_create_sysfs_dev_files with atomic value Alexander Stein
2023-03-16  9:18 ` Alexander Stein [this message]
2023-03-16  9:23 ` Oliver Neukum
2023-03-16  9:33   ` Alexander Stein
2023-03-16 11:17     ` Oliver Neukum
2023-03-16 11:58       ` Alexander Stein
2023-03-16 12:23         ` Oliver Neukum
2023-03-16 13:16           ` Alexander Stein
2023-03-16 14:01             ` Oliver Neukum
2023-03-16 15:00               ` Alexander Stein
2023-03-21  9:09               ` Oliver Neukum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4335627.mvXUDI8C0e@steina-w \
    --to=alexander.stein@ew.tq-group.com \
    --cc=bhelgaas@google.com \
    --cc=korneliuszo@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox