[PATCH v3 18/28] of: property: Allow fw_devlink device-tree on x86 when PCI device-tree node creation is enabled

Herve Codina posted 28 patches 3 months, 4 weeks ago
[PATCH v3 18/28] of: property: Allow fw_devlink device-tree on x86 when PCI device-tree node creation is enabled
Posted by Herve Codina 3 months, 4 weeks ago
PCI drivers can use a device-tree overlay to describe the hardware
available on the PCI board. This is the case, for instance, of the
LAN966x PCI device driver.

Adding some more nodes in the device-tree overlay adds some more
consumer/supplier relationship between devices instantiated from this
overlay.

Those fw_node consumer/supplier relationships are handled by fw_devlink
and are created based on the device-tree parsing done by the
of_fwnode_add_links() function.

Those consumer/supplier links are needed in order to ensure a correct PM
runtime management and a correct removal order between devices.

For instance, without those links a supplier can be removed before its
consumers is removed leading to all kind of issue if this consumer still
want the use the already removed supplier.

The support for the usage of an overlay from a PCI driver has been added
on x86 systems in commit 1f340724419ed ("PCI: of: Create device tree PCI
host bridge node").

In the past, support for fw_devlink on x86 had been tried but this
support has been removed in commit 4a48b66b3f52 ("of: property: Disable
fw_devlink DT support for X86"). Indeed, this support was breaking some
x86 systems such as OLPC system and the regression was reported in [0].

Instead of disabling this support for all x86 system, a first approach
would be to use a finer grain and disable this support only for the
possible problematic subset of x86 systems (at least OLPC and CE4100).

This first approach could still leads to issues. Indeed, the list of
possible problematic system and the way to identify them using Kconfig
symbols is not well defined and so some system can be missed leading to
kernel regressions on those missing systems.

Use an other way and enable the support on x86 system only when this
support is needed by some specific feature. The usage of a device-tree
overlay by a PCI driver and thus the creation of PCI device-tree nodes
is a feature that needs it.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Link: https://lore.kernel.org/lkml/3c1f2473-92ad-bfc4-258e-a5a08ad73dd0@web.de/ [0]
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/of/property.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index c1feb631e383..8b5cfee696e2 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -1605,7 +1605,7 @@ static int of_fwnode_add_links(struct fwnode_handle *fwnode)
 	const struct property *p;
 	struct device_node *con_np = to_of_node(fwnode);
 
-	if (IS_ENABLED(CONFIG_X86))
+	if (IS_ENABLED(CONFIG_X86) && !IS_ENABLED(CONFIG_PCI_DYNAMIC_OF_NODES))
 		return 0;
 
 	if (!con_np)
-- 
2.49.0
Re: [PATCH v3 18/28] of: property: Allow fw_devlink device-tree on x86 when PCI device-tree node creation is enabled
Posted by Rob Herring 3 months, 2 weeks ago
On Fri, Jun 13, 2025 at 03:47:58PM +0200, Herve Codina wrote:
> PCI drivers can use a device-tree overlay to describe the hardware
> available on the PCI board. This is the case, for instance, of the
> LAN966x PCI device driver.
> 
> Adding some more nodes in the device-tree overlay adds some more
> consumer/supplier relationship between devices instantiated from this
> overlay.
> 
> Those fw_node consumer/supplier relationships are handled by fw_devlink
> and are created based on the device-tree parsing done by the
> of_fwnode_add_links() function.
> 
> Those consumer/supplier links are needed in order to ensure a correct PM
> runtime management and a correct removal order between devices.
> 
> For instance, without those links a supplier can be removed before its
> consumers is removed leading to all kind of issue if this consumer still
> want the use the already removed supplier.
> 
> The support for the usage of an overlay from a PCI driver has been added
> on x86 systems in commit 1f340724419ed ("PCI: of: Create device tree PCI
> host bridge node").
> 
> In the past, support for fw_devlink on x86 had been tried but this
> support has been removed in commit 4a48b66b3f52 ("of: property: Disable
> fw_devlink DT support for X86"). Indeed, this support was breaking some
> x86 systems such as OLPC system and the regression was reported in [0].
> 
> Instead of disabling this support for all x86 system, a first approach
> would be to use a finer grain and disable this support only for the
> possible problematic subset of x86 systems (at least OLPC and CE4100).
> 
> This first approach could still leads to issues. Indeed, the list of
> possible problematic system and the way to identify them using Kconfig
> symbols is not well defined and so some system can be missed leading to
> kernel regressions on those missing systems.
> 
> Use an other way and enable the support on x86 system only when this
> support is needed by some specific feature. The usage of a device-tree
> overlay by a PCI driver and thus the creation of PCI device-tree nodes
> is a feature that needs it.
> 
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> Link: https://lore.kernel.org/lkml/3c1f2473-92ad-bfc4-258e-a5a08ad73dd0@web.de/ [0]
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/of/property.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/of/property.c b/drivers/of/property.c
> index c1feb631e383..8b5cfee696e2 100644
> --- a/drivers/of/property.c
> +++ b/drivers/of/property.c
> @@ -1605,7 +1605,7 @@ static int of_fwnode_add_links(struct fwnode_handle *fwnode)
>  	const struct property *p;
>  	struct device_node *con_np = to_of_node(fwnode);
>  
> -	if (IS_ENABLED(CONFIG_X86))
> +	if (IS_ENABLED(CONFIG_X86) && !IS_ENABLED(CONFIG_PCI_DYNAMIC_OF_NODES))

I really want CONFIG_PCI_DYNAMIC_OF_NODES to go away at some point, not 
add more users. 

I think this should instead check for specific platforms not with 
kconfig symbols but DT properties. For ce4100, you can just check the 
root compatible string. For OLPC, there isn't a root compatible (in the 
DT I have). You could check for /architecture == OLPC instead. There's 
some virtualization guests using DT now too. I would think their DT's 
are simple enough to avoid any fw_devlink issues. 

Alternatively, we could perhaps make x86 fw_devlink default off and then 
enable it only when you create nodes. Maybe it has to be restricted a 
sub tree of the DT to avoid any later interactions if devices are 
unbound and rebound. Not a fully fleshed out idea...

Rob
Re: [PATCH v3 18/28] of: property: Allow fw_devlink device-tree on x86 when PCI device-tree node creation is enabled
Posted by Andy Shevchenko 3 months, 2 weeks ago
On Fri, Jun 27, 2025 at 11:22:45AM -0500, Rob Herring wrote:
> On Fri, Jun 13, 2025 at 03:47:58PM +0200, Herve Codina wrote:

...

> > -	if (IS_ENABLED(CONFIG_X86))
> > +	if (IS_ENABLED(CONFIG_X86) && !IS_ENABLED(CONFIG_PCI_DYNAMIC_OF_NODES))
> 
> I really want CONFIG_PCI_DYNAMIC_OF_NODES to go away at some point, not 
> add more users. 
> 
> I think this should instead check for specific platforms not with 
> kconfig symbols but DT properties. For ce4100, you can just check the 
> root compatible string. For OLPC, there isn't a root compatible (in the 
> DT I have). You could check for /architecture == OLPC instead. There's 
> some virtualization guests using DT now too. I would think their DT's 
> are simple enough to avoid any fw_devlink issues. 

I don't think this is good approach. The above check is more reliable in my
opinion.

> Alternatively, we could perhaps make x86 fw_devlink default off

For my (little) knowledge I believe this is not feasible anymore.
Some x86 code (drivers) relies on fw_devlink nowadays. But take
this with grain of salt, I may be way mistaken.

> and then enable it only when you create nodes. Maybe it has to be restricted
> a sub tree of the DT to avoid any later interactions if devices are unbound
> and rebound. Not a fully fleshed out idea...

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 18/28] of: property: Allow fw_devlink device-tree on x86 when PCI device-tree node creation is enabled
Posted by Rob Herring 3 months, 2 weeks ago
On Fri, Jun 27, 2025 at 11:33 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Fri, Jun 27, 2025 at 11:22:45AM -0500, Rob Herring wrote:
> > On Fri, Jun 13, 2025 at 03:47:58PM +0200, Herve Codina wrote:
>
> ...
>
> > > -   if (IS_ENABLED(CONFIG_X86))
> > > +   if (IS_ENABLED(CONFIG_X86) && !IS_ENABLED(CONFIG_PCI_DYNAMIC_OF_NODES))
> >
> > I really want CONFIG_PCI_DYNAMIC_OF_NODES to go away at some point, not
> > add more users.
> >
> > I think this should instead check for specific platforms not with
> > kconfig symbols but DT properties. For ce4100, you can just check the
> > root compatible string. For OLPC, there isn't a root compatible (in the
> > DT I have). You could check for /architecture == OLPC instead. There's
> > some virtualization guests using DT now too. I would think their DT's
> > are simple enough to avoid any fw_devlink issues.
>
> I don't think this is good approach. The above check is more reliable in my
> opinion.

I'm fine with any solution that doesn't add a
CONFIG_PCI_DYNAMIC_OF_NODES which we can't remove. Adding it was a
kick the can down the road to merge the support worry the mixed
usecase (on ACPI systems) later. It's now later.

> > Alternatively, we could perhaps make x86 fw_devlink default off
>
> For my (little) knowledge I believe this is not feasible anymore.
> Some x86 code (drivers) relies on fw_devlink nowadays. But take
> this with grain of salt, I may be way mistaken.

Doesn't the CONFIG_X86 check disable it?

Rob
Re: [PATCH v3 18/28] of: property: Allow fw_devlink device-tree on x86 when PCI device-tree node creation is enabled
Posted by Herve Codina 3 months, 1 week ago
Hi Rob, Andy,

On Fri, 27 Jun 2025 12:49:36 -0500
Rob Herring <robh@kernel.org> wrote:

> On Fri, Jun 27, 2025 at 11:33 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > On Fri, Jun 27, 2025 at 11:22:45AM -0500, Rob Herring wrote:  
> > > On Fri, Jun 13, 2025 at 03:47:58PM +0200, Herve Codina wrote:  
> >
> > ...
> >  
> > > > -   if (IS_ENABLED(CONFIG_X86))
> > > > +   if (IS_ENABLED(CONFIG_X86) && !IS_ENABLED(CONFIG_PCI_DYNAMIC_OF_NODES))  
> > >
> > > I really want CONFIG_PCI_DYNAMIC_OF_NODES to go away at some point, not
> > > add more users.
> > >
> > > I think this should instead check for specific platforms not with
> > > kconfig symbols but DT properties. For ce4100, you can just check the
> > > root compatible string. For OLPC, there isn't a root compatible (in the
> > > DT I have). You could check for /architecture == OLPC instead. There's
> > > some virtualization guests using DT now too. I would think their DT's
> > > are simple enough to avoid any fw_devlink issues.  
> >
> > I don't think this is good approach. The above check is more reliable in my
> > opinion.  
> 
> I'm fine with any solution that doesn't add a
> CONFIG_PCI_DYNAMIC_OF_NODES which we can't remove. Adding it was a
> kick the can down the road to merge the support worry the mixed
> usecase (on ACPI systems) later. It's now later.
> 
> > > Alternatively, we could perhaps make x86 fw_devlink default off  
> >
> > For my (little) knowledge I believe this is not feasible anymore.
> > Some x86 code (drivers) relies on fw_devlink nowadays. But take
> > this with grain of salt, I may be way mistaken.  
> 
> Doesn't the CONFIG_X86 check disable it?
> 
> Rob

Filtering out by Kconfig seems a no-go:
  - Check for CONFIG_OLPC of CONFIG_X86_INTEL_CE as proposed in v1
    (https://lore.kernel.org/lkml/20250407145546.270683-12-herve.codina@bootlin.com/)
    was a no-go from Andy

  - Check for CONFIG_PCI_DYNAMIC_OF_NODES as proposed here is a no-go from
    Rob

I will follow Rob's suggestion based on DT properties. With a DT property
list, it would be easier to add more x86 fw_delink broken system in the list
of the system to exclude.

Best regards,
Hervé