lan966x pci device: Add support for SFPs, PCI part
Subsystems (11)
v7 cover lan966x pci device: Add support for SFPs, PCI part
Hi,
Previously, I sent a big picture series adding support for SFP ports available on the LAN966x PCI device [0].
In this series patches touch several parts and sub-system in the kernel. Reviews have be done and it makes sense to split the series and send parts separately.
This current series is the extraction of patches related to issues in the PCI subsystem. It has to be seen as a continuation of the big picture series but related to this specific core part.
Patches 1 to 6 introduce and use fw_devlink_set_device() in already existing code. No functional change but the introduction of the fw_devlink_set_device() wrapper.
Patches 7 and 8 fix fw_devlink issues specific to PCI and the device-tree nodes created during enumeration.
[0] https://lore.kernel.org/all/[email protected]/
Best regards,
Hervé
Changes:
v6 -> v7
Rebase on top v7.1-rc1
- Patch 1
Add Cc stable. Needed for patches 11 and 12
- Patches 2 to 5
No changes
- Patch 6
Add Cc stable. Needed for patch 13
Add 'Acked-by: Bjorn Helgaas'
- Patch 7
Fix a typo in commit log
Add Fixes tag + Cc stable
Add 'Acked-by: Bjorn Helgaas'
- Patch 8
Add Fixes tag + Cc stable
Add 'Acked-by: Bjorn Helgaas'
Older iterations:
Patches 6 to 13 in the big picture series
https://lore.kernel.org/all/[email protected]/
Herve Codina (8):
driver core: fw_devlink: Introduce fw_devlink_set_device()
drivers: core: Use fw_devlink_set_device()
pinctrl: cs42l43: Use fw_devlink_set_device()
cxl/test: Use device_set_node()
cxl/test: Use fw_devlink_set_device()
PCI: of: Use fw_devlink_set_device()
PCI: of: Set fwnode device of newly created PCI device nodes
PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge
node
drivers/base/core.c | 4 ++-- drivers/pci/of.c | 10 ++++++++-- drivers/pinctrl/cirrus/pinctrl-cs42l43.c | 2 +- include/linux/fwnode.h | 6 ++++++ tools/testing/cxl/test/cxl.c | 4 ++-- 5 files changed, 19 insertions(+), 7 deletions(-)
Signature · 1 line
2.54.0
PATCH v7 1/8 driver core: fw_devlink: Introduce fw_devlink_set_device()
Setting fwnode->dev is specific to fw_devlink.
In order to avoid having a direct 'fwnode->dev = dev;' in several place in the kernel, introduce fw_devlink_set_device() helper to perform this operation.
Having this helper allows to hide the fwnode devlink related stuff behind the helper.
---
Cc stable because used by other patches with Fixes + Cc stable
--- include/linux/fwnode.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/fwnode.h +6 -0
@@ -252,4 +252,10 @@ void fwnode_links_purge(struct fwnode_handle *fwnode);void fw_devlink_purge_absent_suppliers (struct fwnode_handle *fwnode);bool fw_devlink_is_strict (void ); +static inline void fw_devlink_set_device (struct fwnode_handle *fwnode, +struct device *dev) +{ + fwnode->dev = dev; +} +#endif
Signature · 1 line
2.54.0
PATCH v7 2/8 drivers: core: Use fw_devlink_set_device()
In reply to Herve CodinaThe code set directly fwnode->dev field.
Use the dedicated fw_devlink_set_device() helper to perform this operation.
--- drivers/base/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/core.c +2 -2
@@ -3684,7 +3684,7 @@ int device_add(struct device *dev)* device and the driver sync_state callback is called for this device. */ if (dev->fwnode && !dev->fwnode->dev) { - dev->fwnode->dev = dev; +fw_devlink_set_device (dev->fwnode, dev);fw_devlink_link_device (dev); }
@@ -3859,7 +3859,7 @@ void device_del(struct device *dev)device_unlock (dev);if (dev->fwnode && dev->fwnode->dev == dev) - dev->fwnode->dev =NULL ; +fw_devlink_set_device (dev->fwnode,NULL );/* Notify clients of device removal. This call must come * before dpm_sysfs_remove().
Signature · 1 line
2.54.0
PATCH v7 3/8 pinctrl: cs42l43: Use fw_devlink_set_device()
In reply to Herve CodinaThe code set directly fwnode->dev field.
Use the dedicated fw_devlink_set_device() helper to perform this operation.
--- drivers/pinctrl/cirrus/pinctrl-cs42l43.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/cirrus/pinctrl-cs42l43.c +1 -1
@@ -578,7 +578,7 @@ static int cs42l43_pin_probe(struct platform_device *pdev)return ret;if (!child->dev) - child->dev = priv->dev; +fw_devlink_set_device (child, priv->dev); fwnode = child; } }
Signature · 1 line
2.54.0
PATCH v7 4/8 cxl/test: Use device_set_node()
In reply to Herve CodinaThe code set directly dev->fwnode.
Use the dedicated helper to perform this operation.
--- tools/testing/cxl/test/cxl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/cxl/test/cxl.c +1 -1
@@ -1515,7 +1515,7 @@ static void mock_companion(struct acpi_device *adev, struct device *dev) {device_initialize (&adev->dev);fwnode_init (&adev->fwnode,NULL ); - dev->fwnode = &adev->fwnode; +device_set_node (dev, &adev->fwnode); adev->fwnode.dev = dev; }
Signature · 1 line
2.54.0
Re: [PATCH v7 4/8] cxl/test: Use device_set_node()
Quoted 3 lines · Herve Codina
The code set directly
dev->fwnode.Use the dedicated helper to perform this operation.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v7 5/8 cxl/test: Use fw_devlink_set_device()
In reply to Herve CodinaThe code set directly fwnode.dev field.
Use the dedicated fw_devlink_set_device() helper to perform this operation.
--- tools/testing/cxl/test/cxl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/cxl/test/cxl.c +1 -1
@@ -1516,7 +1516,7 @@ static void mock_companion(struct acpi_device *adev, struct device *dev)device_initialize (&adev->dev);fwnode_init (&adev->fwnode,NULL );device_set_node (dev, &adev->fwnode); - adev->fwnode.dev = dev; +fw_devlink_set_device (&adev->fwnode, dev); }#ifndef SZ_64G
Signature · 1 line
2.54.0
Re: [PATCH v7 5/8] cxl/test: Use fw_devlink_set_device()
Quoted 4 lines · Herve Codina
The code set directly fwnode.dev field.
Use the dedicated
fw_devlink_set_device()helper to perform this operation.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v7 6/8 PCI: of: Use fw_devlink_set_device()
In reply to Herve CodinaThe code set directly fwnode.dev field.
Use the dedicated fw_devlink_set_device() helper to perform this operation.
---
Cc stable because used by other patches with Fixes + Cc stable
--- drivers/pci/of.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/of.c +1 -1
@@ -803,7 +803,7 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)* bus. Avoid any new device creation. */ of_node_set_flag (np,OF_POPULATED ); - np->fwnode.dev = &bridge->dev; +fw_devlink_set_device (&np->fwnode, &bridge->dev);fwnode_dev_initialized (&np->fwnode, true); ret =of_changeset_apply (cset);
Signature · 1 line
2.54.0
PATCH v7 7/8 PCI: of: Set fwnode device of newly created PCI device nodes
In reply to Herve CodinaDevice-tree node can be created when CONFIG_PCI_DYNAMIC_OF_NODES. Those nodes are created and filled based on PCI core information but the fwnode device field is not set.
When later an overlay is applied, this confuses fw_devlink. Indeed, without any device attached to the node, fw_devlink considers that this node will never become a device. When this node is pointed as a supplier, devlink looks at its ancestors in order to find a node with a device that could be used as the supplier.
In the PCI use case, this leads to links that wrongly use the PCI root bridge device as the supplier instead of the expected PCI device.
Setting the fwnode device to the device of the PCI device allows devlink to use this device as a supplier and so, correct links are created.
--- drivers/pci/of.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/pci/of.c +7 -0
@@ -709,6 +709,13 @@ void of_pci_make_dev_node(struct pci_dev *pdev)if (ret) goto out_free_node; +/* +* Set the fwnode device in order to have fw_devlink creating links +* pointing to this PCI device instead of walking up to the PCI host +* bridge. +*/ +fw_devlink_set_device (&np->fwnode, &pdev->dev); + ret =of_changeset_apply (cset);if (ret) goto out_free_node;
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v7 7/8] PCI: of: Set fwnode device of newly created PCI device nodes
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The patch fails to achieve its stated goal because `of_changeset_apply()` unconditionally sets the…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The patch fails to achieve its stated goal because of_changeset_apply() unconditionally sets the FWNODE_FLAG_NOT_DEVICE flag, causing fw_devlink to ignore the explicitly set fwnode device.
- [High] Dangling fwnode->dev pointer leads to a Use-After-Free when the PCI device is removed.
--
commit 3981405050778ad9837921511772531243255e6a
Author: Herve Codina <[email protected]>
PCI: of: Set fwnode device of newly created PCI device nodes
This commit sets the fwnode device field of dynamically created PCI device nodes to the corresponding PCI device. This aims to allow fw_devlink to properly use the PCI device as a supplier, instead of falling back to the PCI root bridge.
Quoted 5 lines
drivers/pci/of.c +0
-0
drivers/pci/of.c void of_pci_make_dev_node(struct pci_dev *pdev) · line 717
Quoted 9 lines
drivers/pci/of.c +6
-0@@ -709,6 +709,13 @@ void of_pci_make_dev_node(struct pci_dev *pdev)if (ret) goto out_free_node; +/* +* Set the fwnode device in order to have fw_devlink creating links +* pointing to this PCI device instead of walking up to the PCI host +* bridge. +*/ +fw_devlink_set_device (&np->fwnode, &pdev->dev);
Can this lead to a use-after-free regression when the PCI device is removed?
During PCI device removal, of_pci_remove_node() calls device_remove_of_node(&pdev->dev) which explicitly sets pdev->dev.fwnode to NULL.
Later, when device_del(&pdev->dev) is executed, its built-in fwnode cleanup mechanism is completely bypassed because pdev->dev.fwnode was already cleared:
if (dev->fwnode && dev->fwnode->dev == dev)
fw_devlink_set_device(dev->fwnode, NULL);This leaves np->fwnode.dev as a dangling pointer to &pdev->dev.
If the OF node outlives the PCI device, any subsequent operation that accesses the node through fw_devlink will dereference the freed pdev->dev memory.
drivers/pci/of.c void of_pci_make_dev_node(struct pci_dev *pdev) · line 719
Quoted 2 lines
drivers/pci/of.c +1
-0+ ret =of_changeset_apply (cset);
Does this code actually prevent fw_devlink from walking up to the PCI host bridge?
of_changeset_apply() invokes __of_attach_node(), which unconditionally executes fwnode_set_flag(&np->fwnode, FWNODE_FLAG_NOT_DEVICE).
When fw_devlink attempts to resolve a supplier, it checks for this flag:
if (fwnode_test_flag(sup_handle, FWNODE_FLAG_NOT_DEVICE))
sup_dev = fwnode_get_next_parent_dev(sup_handle);
Because FWNODE_FLAG_NOT_DEVICE is set, fw_devlink bypasses the explicitly mapped np->fwnode.dev and walks up the tree to the parent device anyway.
Quoted 2 lines
drivers/pci/of.c +0
-0if (ret) goto out_free_node;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Re: [PATCH v7 7/8] PCI: of: Set fwnode device of newly created PCI device nodes
Hi All,
Quoted 39 lines · On Tue, 12 May 2026 22:46:21 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The patch fails to achieve its stated goal becauseof_changeset_apply()unconditionally sets theFWNODE_FLAG_NOT_DEVICEflag, causingfw_devlinkto ignore the explicitly set fwnode device.
- [High] Danglingfwnode->devpointer leads to a Use-After-Free when the PCI device is removed.
--commit
3981405050778ad9837921511772531243255e6a
Author: Herve Codina <[email protected]>PCI: of: Set fwnode device of newly created PCI device nodes
This commit sets the fwnode device field of dynamically created PCI device nodes to the corresponding PCI device. This aims to allow
fw_devlinkto properly use the PCI device as a supplier, instead of falling back to the PCI root bridge.Quoted 5 lines
drivers/pci/of.c +0
-0drivers/pci/of.c void of_pci_make_dev_node(struct pci_dev *pdev) · line 717
Quoted 9 lines
drivers/pci/of.c +6
-0@@ -709,6 +709,13 @@ void of_pci_make_dev_node(struct pci_dev *pdev)if (ret) goto out_free_node; +/* +* Set the fwnode device in order to have fw_devlink creating links +* pointing to this PCI device instead of walking up to the PCI host +* bridge. +*/ +fw_devlink_set_device (&np->fwnode, &pdev->dev);Can this lead to a use-after-free regression when the PCI device is removed?
During PCI device removal,
of_pci_remove_node()callsdevice_remove_of_node(&pdev->dev)which explicitly setspdev->dev.fwnodeto NULL.Later, when
device_del(&pdev->dev)is executed, its built-in fwnode cleanup mechanism is completely bypassed becausepdev->dev.fwnodewas already cleared:
Quoted 7 lines
if (dev->fwnode && dev->fwnode->dev == dev) fw_devlink_set_device(dev->fwnode, NULL);This leaves
np->fwnode.devas a dangling pointer to&pdev->dev.If the OF node outlives the PCI device, any subsequent operation that accesses the node through
fw_devlinkwill dereference the freedpdev->devmemory.
It will not. In device_remove_of_node(), the OF node is destroyed when the of_changeset_revert() and of_changeset_destroy() are called.
Quoted 10 lines
drivers/pci/of.c void of_pci_make_dev_node(struct pci_dev *pdev) · line 719
Quoted 3 lines
drivers/pci/of.c +1
-0+ ret =of_changeset_apply (cset);Does this code actually prevent
fw_devlinkfrom walking up to the PCI host bridge?
of_changeset_apply()invokes__of_attach_node(), which unconditionally executesfwnode_set_flag(&np->fwnode, FWNODE_FLAG_NOT_DEVICE).
Quoted 11 lines
When
fw_devlinkattempts to resolve a supplier, it checks for this flag:if (
fwnode_test_flag(sup_handle, FWNODE_FLAG_NOT_DEVICE))
sup_dev=fwnode_get_next_parent_dev(sup_handle);Because
FWNODE_FLAG_NOT_DEVICEis set,fw_devlinkbypasses the explicitly mappednp->fwnode.devand walks up the tree to the parent device anyway.Quoted 2 lines
drivers/pci/of.c +0
-0if (ret) goto out_free_node;
Well, an other series fixes this FWNODE_FLAG_NOT_DEVICE issue [1].
In this one, with or without the fw_devlink_set_device() call the issue is present.
[1] patches 1 and 2 in https://lore.kernel.org/all/[email protected]/
Best regards,
Hervé
PATCH v7 8/8 PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node
In reply to Herve CodinaDuring the instantiation of devices described by a device-tree overlay applied on a PCI device, devlink displays the following kind of debug messages instead of creating the expected links:
'Not linking xxxx - might never become dev'
Without those expected links, the device removal order cannot be correct.
Those debug traces are printed by fw_devlink_create_devlink(). In our use case, they are all printed because the supplier of the link has at least one of its ancestor with its fwnode flag FWNODE_FLAG_INITIALIZED set.
The culprit ancestor is the PCI root bridge.
The fwnode related to the PCI root bridge is created dynamically by the of_pci_make_host_bridge_node() function. During this creation fwnode_dev_initialized() is called which set the FWNODE_FLAG_INITIALIZED flag.
Calling fwnode_dev_initialized() tells devlink that the device related to this node is handled out of the driver core. This is not correct in our case. Indeed the device related to this firmware node is handled using driver core mechanisms and is fully compliant devlink expectations.
Simply remove the fwnode_dev_initialized() call. With that done, the devlink debug messages are no more displayed and links that were missing are correctly created.
--- drivers/pci/of.c | 1 - 1 file changed, 1 deletion(-)
drivers/pci/of.c +0 -1
@@ -811,7 +811,6 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)*/ of_node_set_flag (np,OF_POPULATED );fw_devlink_set_device (&np->fwnode, &bridge->dev); -fwnode_dev_initialized (&np->fwnode, true); ret =of_changeset_apply (cset);if (ret)
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v7 8/8] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Removing `fwnode_dev_initialized()` causes consumers of the PCI host bridge to indefinitely defer…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Removing fwnode_dev_initialized() causes consumers of the PCI host bridge to indefinitely defer probe or suffer a 30-second boot delay. --
commit 77e0afe5e647b8f57bcce68df03d0b7040fbfe25
Author: Herve Codina <[email protected]>
PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node
This commit removes the fwnode_dev_initialized() call during the creation of the PCI host bridge node to allow devlink to correctly create links for devices in device-tree overlays.
drivers/pci/of.c void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge) · line 814
Quoted 9 lines
drivers/pci/of.c +0
-1@@ -811,7 +811,6 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)*/ of_node_set_flag (np,OF_POPULATED );fw_devlink_set_device (&np->fwnode, &bridge->dev); -fwnode_dev_initialized (&np->fwnode, true);
Will removing this cause consumers of the PCI host bridge to indefinitely defer probe or suffer a 30-second boot delay?
The commit message indicates that the device related to this firmware node is handled using driver core mechanisms and is fully compliant with devlink expectations. However, isn't bridge->dev a structural device with no bus (dev->bus == NULL)? If so, it would never undergo driver matching or probing.
If fwnode_dev_initialized() is removed, FWNODE_FLAG_INITIALIZED is cleared. When consumer devices are parsed, fw_devlink creates a managed device link from the consumer to bridge->dev, expecting it to eventually probe. Since the bridge device never probes, its status remains DL_DEV_NO_DRIVER.
When the consumer device attempts to probe, device_links_check_suppliers() might see a dormant supplier and return -EPROBE_DEFER.
Additionally, because device_add(&bridge->dev) executes before of_pci_make_host_bridge_node() attaches the fwnode, device_add() would see a NULL fwnode and skip the fallback fw_devlink_unblock_consumers() call.
Quoted 3 lines
drivers/pci/of.c +0
-0ret =of_changeset_apply (cset);if (ret)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Re: [PATCH v7 8/8] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node
Hi all,
Quoted 13 lines · On Tue, 12 May 2026 23:35:17 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Removingfwnode_dev_initialized()causes consumers of the PCI host bridge to indefinitely defer probe or suffer a 30-second boot delay. --commit
77e0afe5e647b8f57bcce68df03d0b7040fbfe25
Author: Herve Codina <[email protected]>PCI: of: Remove
fwnode_dev_initialized()call for a PCI root bridge nodeThis commit removes the
fwnode_dev_initialized()call during the creation of the PCI host bridge node to allow devlink to correctly create links for devices in device-tree overlays.
Quoted 12 lines
drivers/pci/of.c void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge) · line 814
Quoted 9 lines
drivers/pci/of.c +0
-1@@ -811,7 +811,6 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge)*/ of_node_set_flag (np,OF_POPULATED );fw_devlink_set_device (&np->fwnode, &bridge->dev); -fwnode_dev_initialized (&np->fwnode, true);Will removing this cause consumers of the PCI host bridge to indefinitely defer probe or suffer a 30-second boot delay?
No, nothing of this kind has been observed.
Quoted 12 lines
The commit message indicates that the device related to this firmware node is handled using driver core mechanisms and is fully compliant with devlink expectations. However, isn't
bridge->deva structural device with no bus (dev->bus== NULL)? If so, it would never undergo driver matching or probing.If
fwnode_dev_initialized()is removed,FWNODE_FLAG_INITIALIZEDis cleared. When consumer devices are parsed,fw_devlinkcreates a managed device link from the consumer tobridge->dev, expecting it to eventually probe. Since the bridge device never probes, its status remainsDL_DEV_NO_DRIVER.
Quoted 11 lines
When the consumer device attempts to probe,
device_links_check_suppliers()might see a dormant supplier and return -EPROBE_DEFER.Additionally, because
device_add(&bridge->dev)executes beforeof_pci_make_host_bridge_node()attaches the fwnode,device_add()would see a NULL fwnode and skip the fallbackfw_devlink_unblock_consumers()call.Quoted 3 lines
drivers/pci/of.c +0
-0ret =of_changeset_apply (cset);if (ret)
No devlink should be created with a consumer/supplier relationship between a device and the host bridge.
The traditional parent/child relationship between the host bridge and devices behind the bridge is sufficient and fully handled without devlink.
With the flag set, the trace 'Not linking xxxx - might never become dev' [1] is present for devlink creation where chidren of the host bridge are involved.
Don't confuse devlink setting this flag while all devices are created using driver core mechanism.
Maybe Sashiko is confused also by the way things are done. Usually, fwnodes are created first and devices are instantiated based on those fwnodes. Here, devices already exist and OF nodes (fwnodes) are created and attached to those devices. Indeed, we are on the PCI enumeration and missing OF nodes are dynamically created.
[1] https://elixir.bootlin.com/linux/v7.1-rc4/source/drivers/base/core.c#L2167
Best regards,
Hervé
Hi Bjorn, all,
Quoted 17 lines · On Mon, 11 May 2026 17:59:20 +0200 Herve Codina <[email protected]>…
Hi,
Previously, I sent a big picture series adding support for SFP ports available on the LAN966x PCI device [0].
In this series patches touch several parts and sub-system in the kernel. Reviews have be done and it makes sense to split the series and send parts separately.
This current series is the extraction of patches related to issues in the PCI subsystem. It has to be seen as a continuation of the big picture series but related to this specific core part.
Patches 1 to 6 introduce and use
fw_devlink_set_device()in already existing code. No functional change but the introduction of thefw_devlink_set_device()wrapper.
Quoted 8 lines
Patches 7 and 8 fix
fw_devlinkissues specific to PCI and the device-tree nodes created during enumeration.[0] https://lore.kernel.org/all/[email protected]/
Best regards,
Hervé
I haven't received any feedback on this series other than the "Reviewed-by: Andy Shevchenko" tags.
IHMO, the series is ready to be applied. Do you have any comments ?
Best regards,
Hervé