of: property: fw_devlink misc fixes
v2 cover of: property: fw_devlink misc fixes
As I'm interested in using this feature to fine-tune Raspberry Pi 4's device probe dependencies, I tried to get the board to boot with fw_devlink=on. As of today's linux-next the board won't boot with that option. I tried to address the underlying issues.
---
Changes since v1:
- Address Saravana's comments
- Drop patch #3 & #4
Nicolas Saenz Julienne (2):
of: property: Fix create device links for all child-supplier
dependencies
of: property: Do not link to disabled devices
drivers/of/property.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
Signature · 1 line
2.26.0
PATCH v2 1/2 of: property: Fix create device links for all child-supplier dependencies
Upon adding a new device from a DT node, we scan its properties and its children's properties in order to create a consumer/supplier relationship between the device and the property provider.
That said, it's possible for some of the node's children to be disabled, which will create links that'll never be fulfilled.
To get around this, use the for_each_available_child_of_node() function instead of for_each_available_node() when iterating over the node's children.
---
Changes since v1:
- Slightly reword description
drivers/of/property.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/property.c +1 -1
@@ -1298,7 +1298,7 @@ static int of_link_to_suppliers(struct device *dev,if (of_link_property (dev, con_np, p->name)) ret = -ENODEV ; -for_each_child_of_node (con_np, child) +for_each_available_child_of_node (con_np, child)if (of_link_to_suppliers (dev, child) && !ret) ret = -EAGAIN ;
Signature · 1 line
2.26.0
Re: [PATCH v2 1/2] of: property: Fix create device links for all child-supplier dependencies
Quoted 28 lines · Nicolas Saenz Julienne
Upon adding a new device from a DT node, we scan its properties and its children's properties in order to create a consumer/supplier relationship between the device and the property provider.
That said, it's possible for some of the node's children to be disabled, which will create links that'll never be fulfilled.
To get around this, use the
for_each_available_child_of_node()function instead offor_each_available_node()when iterating over the node's children.Fixes d4387cd11741 ("of: property: Create device links for all child-supplier depencencies")Signed-off-by Nicolas Saenz Julienne <[email protected]>---
Changes since v1:
- Slightly reword descriptiondrivers/of/property.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/of/property.c +0
-0
drivers/of/property.c static int of_link_to_suppliers(struct device *dev, · line 1304
Quoted 8 lines
drivers/of/property.c +1
-1@@ -1298,7 +1298,7 @@ static int of_link_to_suppliers(struct device *dev,if (of_link_property (dev, con_np, p->name)) ret = -ENODEV ; -for_each_child_of_node (con_np, child) +for_each_available_child_of_node (con_np, child)if (of_link_to_suppliers (dev, child) && !ret) ret = -EAGAIN ;
PATCH v2 2/2 of: property: Do not link to disabled devices
In reply to Nicolas Saenz JulienneWhen creating a consumer/supplier relationship between two devices, make sure the supplier node is actually active. Otherwise this will create a link relationship that will never be fulfilled. This, in the worst case scenario, will hang the system during boot.
Note that, in practice, the fact that a device-tree represented consumer/supplier relationship isn't fulfilled will not prevent devices from successfully probing.
---
Changes since v1:
- Move availability check into the compatible search routine and bail if device node disabled
drivers/of/property.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/of/property.c +18 -1
@@ -1045,8 +1045,25 @@ static int of_link_to_phandle(struct device *dev, struct device_node *sup_np,* Find the device node that contains the supplier phandle. It may be * @sup_np or it may be an ancestor of @sup_np. */ -while (sup_np && !of_find_property (sup_np,"compatible" ,NULL )) +while (sup_np) { + +/* +* Don't allow linking a device node as consumer of a disabled +* node. +*/ +if (!of_device_is_available (sup_np)) { +dev_dbg (dev,"Not linking to %pOFP - Not available\n" , + sup_np); +of_node_put (sup_np); +return -ENODEV ; + } + +if (of_find_property (sup_np,"compatible" ,NULL )) +break ; + sup_np =of_get_next_parent (sup_np); + } +if (!sup_np) {dev_dbg (dev,"Not linking to %pOFP - No device\n" , tmp_np);return -ENODEV ;
Signature · 1 line
2.26.0
Re: [PATCH v2 2/2] of: property: Do not link to disabled devices
Quoted 27 lines · Nicolas Saenz Julienne
When creating a consumer/supplier relationship between two devices, make sure the supplier node is actually active. Otherwise this will create a link relationship that will never be fulfilled. This, in the worst case scenario, will hang the system during boot.
Note that, in practice, the fact that a device-tree represented consumer/supplier relationship isn't fulfilled will not prevent devices from successfully probing.
Fixes a3e1d1a7f5fc ("of: property: Add functional dependency link from DT bindings")Signed-off-by Nicolas Saenz Julienne <[email protected]>---
Changes since v1:
- Move availability check into the compatible search routine and bail if device node disableddrivers/of/property.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)drivers/of/property.c +0
-0
drivers/of/property.c static int of_link_to_phandle(struct device *dev, struct device_node *sup_np, · line 1053
Quoted 10 lines
drivers/of/property.c +6
-1@@ -1045,8 +1045,25 @@ static int of_link_to_phandle(struct device *dev, struct device_node *sup_np,* Find the device node that contains the supplier phandle. It may be * @sup_np or it may be an ancestor of @sup_np. */ -while (sup_np && !of_find_property (sup_np,"compatible" ,NULL )) +while (sup_np) { + +/* +* Don't allow linking a device node as consumer of a disabled +* node. +*/
Minor nit: I'd just say "Don't allow linking to a disabled supplier".
drivers/of/property.c static int of_link_to_phandle(struct device *dev, struct device_node *sup_np, · line 1059
Quoted 6 lines
drivers/of/property.c +6
-0+if (!of_device_is_available (sup_np)) { +dev_dbg (dev,"Not linking to %pOFP - Not available\n" , + sup_np); +of_node_put (sup_np); +return -ENODEV ; + }
This if block looks very similar to the one right after the loop. Maybe there's a nice way to combine it?
If you replace this if block with this, it'll end up with the same result.
if (!of_device_is_available(sup_np)) {
of_node_put(sup_np);
sup_np = NULL;
}of_get_next_parent() handles a NULL input properly. So that won't be a problem. And "No device" is a valid statement for both cases I think.
drivers/of/property.c static int of_link_to_phandle(struct device *dev, struct device_node *sup_np, · line 1069
Quoted 10 lines
drivers/of/property.c +6
-0+ +if (of_find_property (sup_np,"compatible" ,NULL )) +break ; + sup_np =of_get_next_parent (sup_np); + } +if (!sup_np) {dev_dbg (dev,"Not linking to %pOFP - No device\n" , tmp_np);return -ENODEV ;
However, not against this patch as is if Rob/Frank like it as is.
-Saravana
Re: [PATCH v2 2/2] of: property: Do not link to disabled devices
Quoted 65 lines · Saravana Kannan
Quoted 38 lines · Nicolas Saenz Julienne
When creating a consumer/supplier relationship between two devices, make sure the supplier node is actually active. Otherwise this will create a link relationship that will never be fulfilled. This, in the worst case scenario, will hang the system during boot.
Note that, in practice, the fact that a device-tree represented consumer/supplier relationship isn't fulfilled will not prevent devices from successfully probing.
Fixes a3e1d1a7f5fc ("of: property: Add functional dependency link from DTbindings")
Signed-off-by Nicolas Saenz Julienne <[email protected]>---
Changes since v1:
- Move availability check into the compatible search routine and bail if device node disableddrivers/of/property.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)drivers/of/property.c +0
-0@@ -1045,8 +1045,25 @@ static int of_link_to_phandle(struct device *dev,struct device_node *sup_np, * Find the device node that contains the supplier phandle. It maybe
* @sup_np or it may be an ancestor of @sup_np. */drivers/of/property.c +4
-1-while (sup_np && !of_find_property (sup_np,"compatible" ,NULL )) +while (sup_np) { + +/* +* Don't allow linking a device node as consumer of a disabled
drivers/of/property.c static int of_link_to_phandle(struct device *dev, struct device_node *sup_np, · line 1053
Quoted 2 lines
drivers/of/property.c +2
-0+* node. +*/ Minor nit: I'd just say "Don't allow linking to a disabled supplier".
drivers/of/property.c static int of_link_to_phandle(struct device *dev, struct device_node *sup_np, · line 1059
Quoted 7 lines
drivers/of/property.c +2
-0+if (!of_device_is_available (sup_np)) { + dev_dbg(dev, "Not linking to %pOFP - Notavailable\n",
drivers/of/property.c +4
-0+ sup_np); +of_node_put (sup_np); +return -ENODEV ; + }This if block looks very similar to the one right after the loop. Maybe there's a nice way to combine it?
If you replace this if block with this, it'll end up with the same result.
if (!of_device_is_available(sup_np)) { of_node_put(sup_np); sup_np = NULL; }
of_get_next_parent()handles a NULL input properly. So that won't be a problem. And "No device" is a valid statement for both cases I think.
Quoted 12 lines
drivers/of/property.c static int of_link_to_phandle(struct device *dev, struct device_node *sup_np, · line 1069
Quoted 10 lines
drivers/of/property.c +6
-0+ +if (of_find_property (sup_np,"compatible" ,NULL )) +break ; + sup_np =of_get_next_parent (sup_np); + } +if (!sup_np) {dev_dbg (dev,"Not linking to %pOFP - No device\n" , tmp_np);return -ENODEV ;However, not against this patch as is if Rob/Frank like it as is.
Agree with your suggestions, I'll send an v3.
Regards,
Nicolas
Hi Saravana,
Quoted 5 lines · Nicolas Saenz Julienne
As I'm interested in using this feature to fine-tune Raspberry Pi 4's device probe dependencies, I tried to get the board to boot with fw_devlink=on. As of today's linux-next the board won't boot with that option. I tried to address the underlying issues.
On a semi-related topic, have you looked at vendor specific properties? most of them create a consumer/supplier relationship, it'd be nice to be able to take those ones into account as well.
Regards,
Nicolas
Quoted 10 lines · Nicolas Saenz Julienne
Hi Saravana,
Quoted 5 lines · Nicolas Saenz Julienne
As I'm interested in using this feature to fine-tune Raspberry Pi 4's device probe dependencies, I tried to get the board to boot with fw_devlink=on. As of today's linux-next the board won't boot with that option. I tried to address the underlying issues.
Quoted 3 lines
On a semi-related topic, have you looked at vendor specific properties? most of them create a consumer/supplier relationship, it'd be nice to be able to take those ones into account as well.
I'm on the wall about that. If we take every vendor specific property, this file will explode. Not sure I want to do that.
Also, we haven't even finished all the generic bindings. I'm just adding bindings as I get familiar with each of them and I test them on hardware I have lying around before sending it out. So, there's where my focus is right now wrt fw_devlink and DT.
I wonder how many of the vendor specific properties do very similar things and got in over time. Maybe they can be made generic? What one did you have in mind?
-Saravana
Hi Saravana,
Quoted 20 lines · Saravana Kannan
Quoted 9 lines · Nicolas Saenz Julienne
Hi Saravana,
Quoted 5 lines · Nicolas Saenz Julienne
As I'm interested in using this feature to fine-tune Raspberry Pi 4's device probe dependencies, I tried to get the board to boot with fw_devlink=on. As of today's linux-next the board won't boot with that option. I tried to address the underlying issues.
Quoted 5 lines
On a semi-related topic, have you looked at vendor specific properties? most of
them create a consumer/supplier relationship, it'd be nice to be able to take
those ones into account as well.I'm on the wall about that. If we take every vendor specific property, this file will explode. Not sure I want to do that.
Quoted 8 lines
Also, we haven't even finished all the generic bindings. I'm just adding bindings as I get familiar with each of them and I test them on hardware I have lying around before sending it out. So, there's where my focus is right now wrt
fw_devlinkand DT.I wonder how many of the vendor specific properties do very similar things and got in over time. Maybe they can be made generic? What one did you have in mind?
Well, long story short, we need to create a relationship between RPi4's PCI bus (which hangs from an interconnect in DT) and RPi4's co-processor, which has a highly unconventional firmware driver (raspberrypi.c in drivers/firmware). The PCI bus just needs the co-processor interface to be up before probing, that's all (I'll spare you the details of why). Ideally we want to avoid adding platform specific code into an otherwise generic bus driver as it'll be used by a number of unrelated SoCs, and it's generally frowned upon.
There is no generic property to handle this case, and it's very unlikely there will ever be one, since these firmware drivers have very little in common. I guess this could make an argument for a generic _last resort only_ 'supplied-by' property, but I bet this solution won't be very popular.
Another idea that comes to mind for vendor specific properties would be exporting a macro in the lines of "DEFINE_SIMPLE_PROP()" for supplier drivers to define custom properties. The parse_prop() callbacks could then be added into a special section for of/property.c to pickup and parse. The good thing is that the list length would be limited by the kernel configuration and the maintenance burden moved to the driver authors, at least to some extent.
Anyway, if something comes to mind to solve RPi4's situation feel free to propose anything :).
Regards,
Nicolas
Quoted 29 lines · Nicolas Saenz Julienne
Hi Saravana,
Quoted 25 lines · Saravana Kannan
Quoted 9 lines · Nicolas Saenz Julienne
Hi Saravana,
Quoted 5 lines · Nicolas Saenz Julienne
As I'm interested in using this feature to fine-tune Raspberry Pi 4's device probe dependencies, I tried to get the board to boot with fw_devlink=on. As of today's linux-next the board won't boot with that option. I tried to address the underlying issues.
Quoted 5 lines
On a semi-related topic, have you looked at vendor specific properties? most of
them create a consumer/supplier relationship, it'd be nice to be able to take
those ones into account as well.I'm on the wall about that. If we take every vendor specific property, this file will explode. Not sure I want to do that.
Also, we haven't even finished all the generic bindings. I'm just adding bindings as I get familiar with each of them and I test them on hardware I have lying around before sending it out. So, there's where my focus is right now wrt
fw_devlinkand DT.
Quoted 8 lines
Quoted 3 lines
I wonder how many of the vendor specific properties do very similar things and got in over time. Maybe they can be made generic? What one did you have in mind?
Well, long story short, we need to create a relationship between RPi4's PCI bus (which hangs from an interconnect in DT) and RPi4's co-processor, which has a highly unconventional firmware driver (
raspberrypi.cindrivers/firmware). The PCI bus just needs the co-processor interface to be up before probing,
I'm guessing it still works fine today by doing a deferred probe and you are just trying to avoid having to do a deferred probe? I haven't kept track of RPi4's upstream support status.
Quoted 4 lines
that's
all (I'll spare you the details of why). Ideally we want to avoid adding platform specific code into an otherwise generic bus driver as it'll be used by a number of unrelated SoCs, and it's generally frowned upon.
Which PCI driver is that specifically (I'm sure I can dig around to find RPi4's DT and figure it out, but it's easier to just ask :) ) ? Also, can you point me to the DT and the nodes that we are talking about here (the PCI and the firmware nodes)?
Quoted 4 lines
There is no generic property to handle this case, and it's very unlikely there will ever be one, since these firmware drivers have very little in common. I guess this could make an argument for a generic
_lastresortonly_'supplied-by' property, but I bet this solution won't be very popular.
Ha, this was my initial idea for the whole fw_devlink feature. I called it depends-on. Rob/Frank convinced me to instead just parse the existing bindings -- which was definitely the right call. Otherwise DT would have been a mess. Adding support for "depends-on" for one off use cases might still be a touchy topic. I myself am on the wall. It's useful for some rare cases, but it's also very easy to abuse.
Quoted 6 lines
Another idea that comes to mind for vendor specific properties would be exporting a macro in the lines of "
DEFINE_SIMPLE_PROP()" for supplier drivers to define custom properties. Theparse_prop()callbacks could then be added into a special section forof/property.cto pickup and parse. The good thing is that the list length would be limited by the kernel configuration and the maintenance burden moved to the driver authors, at least to some extent.
I did think about this option too sometime back, but not too keen on that -- at least at this point. Mostly because there are other issues I want to resolve first and want to get their design right before getting to hand off property parsing to other drivers/files.
Quoted 2 lines
Anyway, if something comes to mind to solve RPi4's situation feel free to propose anything :).
I'll let you know if I do. I'm not sure I fully understand the issue though. I don't think you are trying to avoid deferred probes because you aren't trying to improve boot time. I'm guessing the PCI bus driver in question has no way to know when to defer the probe, in this case you are trying to fix?
-Saravana
On Mon, 2020-04-20 at 15:37 -0700, Saravana Kannan wrote:
[...]
Quoted 9 lines
On Mon, Apr 20, 2020 at 4:29 AM Nicolas Saenz Julienne
Quoted 7 lines
Well, long story short, we need to create a relationship between RPi4's PCI bus
(which hangs from an interconnect in DT) and RPi4's co-processor, which has a
highly unconventional firmware driver (raspberrypi.cindrivers/firmware). The
PCI bus just needs the co-processor interface to be up before probing,
Quoted 3 lines
I'm guessing it still works fine today by doing a deferred probe and you are just trying to avoid having to do a deferred probe? I haven't kept track of RPi4's upstream support status.
Yes that's the idea, and here's the patch I'm trying to avoid:
https://lkml.org/lkml/2020/3/24/1508
Quoted 10 lines
Quoted 5 lines
that's
all (I'll spare you the details of why). Ideally we want to avoid adding platform specific code into an otherwise generic bus driver as it'll be used by
a number of unrelated SoCs, and it's generally frowned upon.Which PCI driver is that specifically (I'm sure I can dig around to find RPi4's DT and figure it out, but it's easier to just ask :) ) ? Also, can you point me to the DT and the nodes that we are talking about here (the PCI and the firmware nodes)?
So the PCI driver is pcie-brcmstb.c, its DT node is available in bcm2711.dtsi (search for pcie0), the firmware interface is defined in bcm2835-rpi.dtsi (search for firmware).
Quoted 6 lines
Quoted 5 lines
There is no generic property to handle this case, and it's very unlikely there
will ever be one, since these firmware drivers have very little in common. I guess this could make an argument for a generic_lastresortonly_'supplied-by' property, but I bet this solution won't be very popular.
Quoted 6 lines
Ha, this was my initial idea for the whole
fw_devlinkfeature. I called it depends-on. Rob/Frank convinced me to instead just parse the existing bindings -- which was definitely the right call. Otherwise DT would have been a mess. Adding support for "depends-on" for one off use cases might still be a touchy topic. I myself am on the wall. It's useful for some rare cases, but it's also very easy to abuse.
Yes, I agree.
Regards,
Nicolas