linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Guard pci_create_sysfs_dev_files with atomic value
@ 2022-08-29 19:14 Korneliusz Osmenda
  2022-10-06 10:08 ` Alexander Stein
  0 siblings, 1 reply; 2+ messages in thread
From: Korneliusz Osmenda @ 2022-08-29 19:14 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, linux-kernel

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

Bug: https://bugzilla.kernel.org/show_bug.cgi?id=215515

Signed-off-by: Korneliusz Osmenda <korneliuszo@gmail.com>
---
  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 fc804e08e3cb..a6648239e235 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1378,6 +1378,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);
  }

@@ -1392,6 +1395,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 060af91bafcd..5477de2ef057 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -465,6 +465,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? */
-- 
2.36.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Guard pci_create_sysfs_dev_files with atomic value
  2022-08-29 19:14 [PATCH] Guard pci_create_sysfs_dev_files with atomic value Korneliusz Osmenda
@ 2022-10-06 10:08 ` Alexander Stein
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Stein @ 2022-10-06 10:08 UTC (permalink / raw)
  To: Bjorn Helgaas, Korneliusz Osmenda; +Cc: linux-pci, linux-kernel

Hi,

Am Montag, 29. August 2022, 21:14:43 CEST schrieb Korneliusz Osmenda:
> 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
> 
> Bug: https://bugzilla.kernel.org/show_bug.cgi?id=215515
> 
> Signed-off-by: Korneliusz Osmenda <korneliuszo@gmail.com>
> ---
>   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 fc804e08e3cb..a6648239e235 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -1378,6 +1378,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);
>   }
> 
> @@ -1392,6 +1395,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 060af91bafcd..5477de2ef057 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -465,6 +465,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? */

Is there any feedback here? I'm hitting the same issue on TQMa6x+MBa6x.
Having this patch applied my PCIe device using several bridges is detected 
fine.

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-06 10:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-29 19:14 [PATCH] Guard pci_create_sysfs_dev_files with atomic value Korneliusz Osmenda
2022-10-06 10:08 ` Alexander Stein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).