diff mbox series

[1/2] PCI: rockchip: Work around missing device_type property in DT

Message ID 20200815125112.462652-2-maz@kernel.org (mailing list archive)
State New, archived
Headers show
Series PCI: rockchip: Fix PCIe probing in 5.9 | expand

Commit Message

Marc Zyngier Aug. 15, 2020, 12:51 p.m. UTC
Recent changes to the DT PCI bus parsing made it mandatory for
device tree nodes describing a PCI controller to have the
'device_type = "pci"' property for the node to be matched.

Although this follows the letter of the specification, it
breaks existing device-trees that have been working fine
for years.  Rockchip rk3399-based systems are a prime example
of such collateral damage, and have stopped discovering their
PCI bus.

In order to paper over the blunder, let's add a workaround
to the pcie-rockchip driver, adding the missing property when
none is found at boot time. A warning will hopefully nudge the
user into updating their DT to a fixed version if they can, but
the insentive is obviously pretty small.

Fixes: 2f96593ecc37 ("of_address: Add bus type match for pci ranges parser")
Suggested-by: Roh Herring <robh+dt@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 drivers/pci/controller/pcie-rockchip-host.c | 29 +++++++++++++++++++++
 1 file changed, 29 insertions(+)

Comments

Bjorn Helgaas Aug. 15, 2020, 11:22 p.m. UTC | #1
On Sat, Aug 15, 2020 at 01:51:11PM +0100, Marc Zyngier wrote:
> Recent changes to the DT PCI bus parsing made it mandatory for
> device tree nodes describing a PCI controller to have the
> 'device_type = "pci"' property for the node to be matched.
> 
> Although this follows the letter of the specification, it
> breaks existing device-trees that have been working fine
> for years.  Rockchip rk3399-based systems are a prime example
> of such collateral damage, and have stopped discovering their
> PCI bus.
> 
> In order to paper over the blunder, let's add a workaround
> to the pcie-rockchip driver, adding the missing property when
> none is found at boot time. A warning will hopefully nudge the
> user into updating their DT to a fixed version if they can, but
> the insentive is obviously pretty small.

s/insentive/incentive/ (Lorenzo or I can fix this up)

> Fixes: 2f96593ecc37 ("of_address: Add bus type match for pci ranges parser")
> Suggested-by: Roh Herring <robh+dt@kernel.org>

s/Roh/Rob/ (similarly)

> Signed-off-by: Marc Zyngier <maz@kernel.org>

This looks like a candidate for v5.9, since 2f96593ecc37 was merged
during the v5.9 merge window, right?

I wonder how many other DTs are similarly broken?  Maybe Rob's DT
checker has already looked?

> ---
>  drivers/pci/controller/pcie-rockchip-host.c | 29 +++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
> index 0bb2fb3e8a0b..d7dd04430a99 100644
> --- a/drivers/pci/controller/pcie-rockchip-host.c
> +++ b/drivers/pci/controller/pcie-rockchip-host.c
> @@ -949,6 +949,35 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
>  	if (!dev->of_node)
>  		return -ENODEV;
>  
> +	/*
> +	 * Most rk3399 DTs are missing the 'device_type = "pci"' property,
> +	 * potentially leading to PCIe probing failure. Be kind to the
> +	 * users and fix it up for them. Upgrading is recommended.
> +	 */
> +	if (!of_find_property(dev->of_node, "device_type", NULL)) {
> +		const char dtype[] = "pci";
> +		struct property *prop;
> +
> +		dev_warn(dev, "Working around missing device_type property\n");
> +
> +		prop = kzalloc(sizeof(*prop), GFP_KERNEL);
> +		if (!prop)
> +			return -ENOMEM;
> +
> +		prop->name	= kstrdup("device_type", GFP_KERNEL);
> +		prop->value	= kstrdup(dtype, GFP_KERNEL);
> +		prop->length	= ARRAY_SIZE(dtype);
> +		if (!prop->name || !prop->value) {
> +			kfree(prop->name);
> +			kfree(prop->value);
> +			kfree(prop);
> +			return -ENOMEM;
> +		}
> +
> +		if (of_add_property(dev->of_node, prop))
> +			dev_warn(dev, "Failed to add property, probing may fail");
> +	}
> +
>  	bridge = devm_pci_alloc_host_bridge(dev, sizeof(*rockchip));
>  	if (!bridge)
>  		return -ENOMEM;
> -- 
> 2.27.0
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Marc Zyngier Aug. 16, 2020, 10:39 a.m. UTC | #2
On Sun, 16 Aug 2020 00:22:28 +0100,
Bjorn Helgaas <helgaas@kernel.org> wrote:
> 
> On Sat, Aug 15, 2020 at 01:51:11PM +0100, Marc Zyngier wrote:
> > Recent changes to the DT PCI bus parsing made it mandatory for
> > device tree nodes describing a PCI controller to have the
> > 'device_type = "pci"' property for the node to be matched.
> > 
> > Although this follows the letter of the specification, it
> > breaks existing device-trees that have been working fine
> > for years.  Rockchip rk3399-based systems are a prime example
> > of such collateral damage, and have stopped discovering their
> > PCI bus.
> > 
> > In order to paper over the blunder, let's add a workaround
> > to the pcie-rockchip driver, adding the missing property when
> > none is found at boot time. A warning will hopefully nudge the
> > user into updating their DT to a fixed version if they can, but
> > the insentive is obviously pretty small.
> 
> s/insentive/incentive/ (Lorenzo or I can fix this up)
> 
> > Fixes: 2f96593ecc37 ("of_address: Add bus type match for pci ranges parser")
> > Suggested-by: Roh Herring <robh+dt@kernel.org>
> 
> s/Roh/Rob/ (similarly)

Clearly not my day when it comes to proofreading commit messages.
Thanks for pointing this out, and in advance for fixing it up.

> 
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> 
> This looks like a candidate for v5.9, since 2f96593ecc37 was merged
> during the v5.9 merge window, right?

Absolutely.

> I wonder how many other DTs are similarly broken?  Maybe Rob's DT
> checker has already looked?

I've just managed to run the checker, which comes up with all kinds of
goodies. Apart from the above, it also spots the following:

- arch/arm64/boot/dts/mediatek/mt7622.dtsi: Has a device_type property
  in its main PCIe node, but not in the child nodes. It isn't obvious
  to me whether that's a violation or not (the spec doesn't say
  whether the property should be set on a per-port basis). Rob?

- arch/arm64/boot/dts/qcom/msm8996.dtsi: Only one out of the three
  PCIe nodes has the device_type property, probably broken similarly
  to rk3399.

I could move the workaround to drivers/pci/of.c, and have it called
from the individual drivers. I don't have the HW to test those though.

Thoughts?

	M.
Rob Herring (Arm) Aug. 17, 2020, 4:12 p.m. UTC | #3
On Sun, Aug 16, 2020 at 4:40 AM Marc Zyngier <maz@kernel.org> wrote:
>
> On Sun, 16 Aug 2020 00:22:28 +0100,
> Bjorn Helgaas <helgaas@kernel.org> wrote:
> >
> > On Sat, Aug 15, 2020 at 01:51:11PM +0100, Marc Zyngier wrote:
> > > Recent changes to the DT PCI bus parsing made it mandatory for
> > > device tree nodes describing a PCI controller to have the
> > > 'device_type = "pci"' property for the node to be matched.
> > >
> > > Although this follows the letter of the specification, it
> > > breaks existing device-trees that have been working fine
> > > for years.  Rockchip rk3399-based systems are a prime example
> > > of such collateral damage, and have stopped discovering their
> > > PCI bus.
> > >
> > > In order to paper over the blunder, let's add a workaround
> > > to the pcie-rockchip driver, adding the missing property when
> > > none is found at boot time. A warning will hopefully nudge the
> > > user into updating their DT to a fixed version if they can, but
> > > the insentive is obviously pretty small.
> >
> > s/insentive/incentive/ (Lorenzo or I can fix this up)
> >
> > > Fixes: 2f96593ecc37 ("of_address: Add bus type match for pci ranges parser")
> > > Suggested-by: Roh Herring <robh+dt@kernel.org>
> >
> > s/Roh/Rob/ (similarly)
>
> Clearly not my day when it comes to proofreading commit messages.
> Thanks for pointing this out, and in advance for fixing it up.
>
> >
> > > Signed-off-by: Marc Zyngier <maz@kernel.org>
> >
> > This looks like a candidate for v5.9, since 2f96593ecc37 was merged
> > during the v5.9 merge window, right?
>
> Absolutely.
>
> > I wonder how many other DTs are similarly broken?  Maybe Rob's DT
> > checker has already looked?
>
> I've just managed to run the checker, which comes up with all kinds of
> goodies. Apart from the above, it also spots the following:
>
> - arch/arm64/boot/dts/mediatek/mt7622.dtsi: Has a device_type property
>   in its main PCIe node, but not in the child nodes. It isn't obvious
>   to me whether that's a violation or not (the spec doesn't say
>   whether the property should be set on a per-port basis). Rob?

The rule is bridge nodes should have 'device_type = "pci"'. But what's
needed to fix these cases is setting device_type where we are parsing
ranges or dma-ranges which we're not doing on the child ndes.
Otherwise, I don't think it matters in this case unless you have child
(grandchild here) nodes for PCI devices. If you did have child nodes,
the address translation was already broken before this change.

> - arch/arm64/boot/dts/qcom/msm8996.dtsi: Only one out of the three
>   PCIe nodes has the device_type property, probably broken similarly
>   to rk3399.

The only upstream board is DB820c, so probably not as wide an impact...

There are also 92 (lots of duplicates due to multiple boards) more
cases in arch/arm/. A log is here[1].

> I could move the workaround to drivers/pci/of.c, and have it called
> from the individual drivers. I don't have the HW to test those though.
>
> Thoughts?

I think we should go with my other suggestion of looking at the node
name. Looks like just checking 'pcie' is enough. We can skip 'pci' as
I don't see any cases.

Rob

[1] https://gitlab.com/robherring/linux-dt-bindings/-/jobs/688752562
Marc Zyngier Aug. 18, 2020, 7:35 a.m. UTC | #4
On 2020-08-17 17:12, Rob Herring wrote:
> On Sun, Aug 16, 2020 at 4:40 AM Marc Zyngier <maz@kernel.org> wrote:
>> 
>> On Sun, 16 Aug 2020 00:22:28 +0100,
>> Bjorn Helgaas <helgaas@kernel.org> wrote:
>> >
>> > On Sat, Aug 15, 2020 at 01:51:11PM +0100, Marc Zyngier wrote:
>> > > Recent changes to the DT PCI bus parsing made it mandatory for
>> > > device tree nodes describing a PCI controller to have the
>> > > 'device_type = "pci"' property for the node to be matched.
>> > >
>> > > Although this follows the letter of the specification, it
>> > > breaks existing device-trees that have been working fine
>> > > for years.  Rockchip rk3399-based systems are a prime example
>> > > of such collateral damage, and have stopped discovering their
>> > > PCI bus.
>> > >
>> > > In order to paper over the blunder, let's add a workaround
>> > > to the pcie-rockchip driver, adding the missing property when
>> > > none is found at boot time. A warning will hopefully nudge the
>> > > user into updating their DT to a fixed version if they can, but
>> > > the insentive is obviously pretty small.
>> >
>> > s/insentive/incentive/ (Lorenzo or I can fix this up)
>> >
>> > > Fixes: 2f96593ecc37 ("of_address: Add bus type match for pci ranges parser")
>> > > Suggested-by: Roh Herring <robh+dt@kernel.org>
>> >
>> > s/Roh/Rob/ (similarly)
>> 
>> Clearly not my day when it comes to proofreading commit messages.
>> Thanks for pointing this out, and in advance for fixing it up.
>> 
>> >
>> > > Signed-off-by: Marc Zyngier <maz@kernel.org>
>> >
>> > This looks like a candidate for v5.9, since 2f96593ecc37 was merged
>> > during the v5.9 merge window, right?
>> 
>> Absolutely.
>> 
>> > I wonder how many other DTs are similarly broken?  Maybe Rob's DT
>> > checker has already looked?
>> 
>> I've just managed to run the checker, which comes up with all kinds of
>> goodies. Apart from the above, it also spots the following:
>> 
>> - arch/arm64/boot/dts/mediatek/mt7622.dtsi: Has a device_type property
>>   in its main PCIe node, but not in the child nodes. It isn't obvious
>>   to me whether that's a violation or not (the spec doesn't say
>>   whether the property should be set on a per-port basis). Rob?
> 
> The rule is bridge nodes should have 'device_type = "pci"'. But what's
> needed to fix these cases is setting device_type where we are parsing
> ranges or dma-ranges which we're not doing on the child ndes.
> Otherwise, I don't think it matters in this case unless you have child
> (grandchild here) nodes for PCI devices. If you did have child nodes,
> the address translation was already broken before this change.

Fair enough.

>> - arch/arm64/boot/dts/qcom/msm8996.dtsi: Only one out of the three
>>   PCIe nodes has the device_type property, probably broken similarly
>>   to rk3399.
> 
> The only upstream board is DB820c, so probably not as wide an impact...
> 
> There are also 92 (lots of duplicates due to multiple boards) more
> cases in arch/arm/. A log is here[1].

Mostly Broadcom stuff, apparently. I'll see if I can have a stab
at it (although someone will have to test it).

> 
>> I could move the workaround to drivers/pci/of.c, and have it called
>> from the individual drivers. I don't have the HW to test those though.
>> 
>> Thoughts?
> 
> I think we should go with my other suggestion of looking at the node
> name. Looks like just checking 'pcie' is enough. We can skip 'pci' as
> I don't see any cases.

I really dislike it.

Once we put this node name matching in, there is no incentive for
people to write their DT correctly at all. It also sound pretty
fragile (what if the PCIe node is named something else?).

My preference goes towards having point fixes in the affected drivers,
clearly showing that this is addressing a firmware bug.

         M.
Rob Herring (Arm) Aug. 18, 2020, 2:23 p.m. UTC | #5
On Tue, Aug 18, 2020 at 1:35 AM Marc Zyngier <maz@kernel.org> wrote:
>
> On 2020-08-17 17:12, Rob Herring wrote:
> > On Sun, Aug 16, 2020 at 4:40 AM Marc Zyngier <maz@kernel.org> wrote:
> >>
> >> On Sun, 16 Aug 2020 00:22:28 +0100,
> >> Bjorn Helgaas <helgaas@kernel.org> wrote:
> >> >
> >> > On Sat, Aug 15, 2020 at 01:51:11PM +0100, Marc Zyngier wrote:
> >> > > Recent changes to the DT PCI bus parsing made it mandatory for
> >> > > device tree nodes describing a PCI controller to have the
> >> > > 'device_type = "pci"' property for the node to be matched.
> >> > >
> >> > > Although this follows the letter of the specification, it
> >> > > breaks existing device-trees that have been working fine
> >> > > for years.  Rockchip rk3399-based systems are a prime example
> >> > > of such collateral damage, and have stopped discovering their
> >> > > PCI bus.
> >> > >
> >> > > In order to paper over the blunder, let's add a workaround
> >> > > to the pcie-rockchip driver, adding the missing property when
> >> > > none is found at boot time. A warning will hopefully nudge the
> >> > > user into updating their DT to a fixed version if they can, but
> >> > > the insentive is obviously pretty small.
> >> >
> >> > s/insentive/incentive/ (Lorenzo or I can fix this up)
> >> >
> >> > > Fixes: 2f96593ecc37 ("of_address: Add bus type match for pci ranges parser")
> >> > > Suggested-by: Roh Herring <robh+dt@kernel.org>
> >> >
> >> > s/Roh/Rob/ (similarly)
> >>
> >> Clearly not my day when it comes to proofreading commit messages.
> >> Thanks for pointing this out, and in advance for fixing it up.
> >>
> >> >
> >> > > Signed-off-by: Marc Zyngier <maz@kernel.org>
> >> >
> >> > This looks like a candidate for v5.9, since 2f96593ecc37 was merged
> >> > during the v5.9 merge window, right?
> >>
> >> Absolutely.
> >>
> >> > I wonder how many other DTs are similarly broken?  Maybe Rob's DT
> >> > checker has already looked?
> >>
> >> I've just managed to run the checker, which comes up with all kinds of
> >> goodies. Apart from the above, it also spots the following:
> >>
> >> - arch/arm64/boot/dts/mediatek/mt7622.dtsi: Has a device_type property
> >>   in its main PCIe node, but not in the child nodes. It isn't obvious
> >>   to me whether that's a violation or not (the spec doesn't say
> >>   whether the property should be set on a per-port basis). Rob?
> >
> > The rule is bridge nodes should have 'device_type = "pci"'. But what's
> > needed to fix these cases is setting device_type where we are parsing
> > ranges or dma-ranges which we're not doing on the child ndes.
> > Otherwise, I don't think it matters in this case unless you have child
> > (grandchild here) nodes for PCI devices. If you did have child nodes,
> > the address translation was already broken before this change.
>
> Fair enough.
>
> >> - arch/arm64/boot/dts/qcom/msm8996.dtsi: Only one out of the three
> >>   PCIe nodes has the device_type property, probably broken similarly
> >>   to rk3399.
> >
> > The only upstream board is DB820c, so probably not as wide an impact...
> >
> > There are also 92 (lots of duplicates due to multiple boards) more
> > cases in arch/arm/. A log is here[1].
>
> Mostly Broadcom stuff, apparently. I'll see if I can have a stab
> at it (although someone will have to test it).
>
> >
> >> I could move the workaround to drivers/pci/of.c, and have it called
> >> from the individual drivers. I don't have the HW to test those though.
> >>
> >> Thoughts?
> >
> > I think we should go with my other suggestion of looking at the node
> > name. Looks like just checking 'pcie' is enough. We can skip 'pci' as
> > I don't see any cases.
>
> I really dislike it.
>
> Once we put this node name matching in, there is no incentive for
> people to write their DT correctly at all. It also sound pretty
> fragile (what if the PCIe node is named something else?).

That would require 2 wrongs. Both missing device_type and wrong node
name. You could still warn if we matched on node name.

This is just one possible error out of thousands. It's not the
kernel's job to validate DTs (if it is, we're doing a horrible job).
We have a solution for this with schema. The question is how to get to
the point the schema checks are part of the main build flow. The
primary issue is just getting to some platforms being warning free,
and then they could opt in. There's effort around some platforms
(Rockchip is not one), but I think we have a ways to go. The other
aspect is what's the coverage with the schema. There's 2900 remaining
bindings to convert to schema. We're doing about 100-200 a cycle, so
that's what the next ~5 years looks like for me. :(

> My preference goes towards having point fixes in the affected drivers,
> clearly showing that this is addressing a firmware bug.

I didn't filter down how many drivers all the failures equates to in
terms of drivers. I guess all of Broadcom is just one. If you want to
fixup all the drivers, then I'm fine with that.

Rob
Marc Zyngier Aug. 18, 2020, 5:34 p.m. UTC | #6
On 2020-08-18 15:23, Rob Herring wrote:
> On Tue, Aug 18, 2020 at 1:35 AM Marc Zyngier <maz@kernel.org> wrote:
>> 
>> On 2020-08-17 17:12, Rob Herring wrote:
>> > On Sun, Aug 16, 2020 at 4:40 AM Marc Zyngier <maz@kernel.org> wrote:
>> >>
>> >> On Sun, 16 Aug 2020 00:22:28 +0100,
>> >> Bjorn Helgaas <helgaas@kernel.org> wrote:
>> >> >
>> >> > On Sat, Aug 15, 2020 at 01:51:11PM +0100, Marc Zyngier wrote:
>> >> > > Recent changes to the DT PCI bus parsing made it mandatory for
>> >> > > device tree nodes describing a PCI controller to have the
>> >> > > 'device_type = "pci"' property for the node to be matched.
>> >> > >
>> >> > > Although this follows the letter of the specification, it
>> >> > > breaks existing device-trees that have been working fine
>> >> > > for years.  Rockchip rk3399-based systems are a prime example
>> >> > > of such collateral damage, and have stopped discovering their
>> >> > > PCI bus.
>> >> > >
>> >> > > In order to paper over the blunder, let's add a workaround
>> >> > > to the pcie-rockchip driver, adding the missing property when
>> >> > > none is found at boot time. A warning will hopefully nudge the
>> >> > > user into updating their DT to a fixed version if they can, but
>> >> > > the insentive is obviously pretty small.
>> >> >
>> >> > s/insentive/incentive/ (Lorenzo or I can fix this up)
>> >> >
>> >> > > Fixes: 2f96593ecc37 ("of_address: Add bus type match for pci ranges parser")
>> >> > > Suggested-by: Roh Herring <robh+dt@kernel.org>
>> >> >
>> >> > s/Roh/Rob/ (similarly)
>> >>
>> >> Clearly not my day when it comes to proofreading commit messages.
>> >> Thanks for pointing this out, and in advance for fixing it up.
>> >>
>> >> >
>> >> > > Signed-off-by: Marc Zyngier <maz@kernel.org>
>> >> >
>> >> > This looks like a candidate for v5.9, since 2f96593ecc37 was merged
>> >> > during the v5.9 merge window, right?
>> >>
>> >> Absolutely.
>> >>
>> >> > I wonder how many other DTs are similarly broken?  Maybe Rob's DT
>> >> > checker has already looked?
>> >>
>> >> I've just managed to run the checker, which comes up with all kinds of
>> >> goodies. Apart from the above, it also spots the following:
>> >>
>> >> - arch/arm64/boot/dts/mediatek/mt7622.dtsi: Has a device_type property
>> >>   in its main PCIe node, but not in the child nodes. It isn't obvious
>> >>   to me whether that's a violation or not (the spec doesn't say
>> >>   whether the property should be set on a per-port basis). Rob?
>> >
>> > The rule is bridge nodes should have 'device_type = "pci"'. But what's
>> > needed to fix these cases is setting device_type where we are parsing
>> > ranges or dma-ranges which we're not doing on the child ndes.
>> > Otherwise, I don't think it matters in this case unless you have child
>> > (grandchild here) nodes for PCI devices. If you did have child nodes,
>> > the address translation was already broken before this change.
>> 
>> Fair enough.
>> 
>> >> - arch/arm64/boot/dts/qcom/msm8996.dtsi: Only one out of the three
>> >>   PCIe nodes has the device_type property, probably broken similarly
>> >>   to rk3399.
>> >
>> > The only upstream board is DB820c, so probably not as wide an impact...
>> >
>> > There are also 92 (lots of duplicates due to multiple boards) more
>> > cases in arch/arm/. A log is here[1].
>> 
>> Mostly Broadcom stuff, apparently. I'll see if I can have a stab
>> at it (although someone will have to test it).
>> 
>> >
>> >> I could move the workaround to drivers/pci/of.c, and have it called
>> >> from the individual drivers. I don't have the HW to test those though.
>> >>
>> >> Thoughts?
>> >
>> > I think we should go with my other suggestion of looking at the node
>> > name. Looks like just checking 'pcie' is enough. We can skip 'pci' as
>> > I don't see any cases.
>> 
>> I really dislike it.
>> 
>> Once we put this node name matching in, there is no incentive for
>> people to write their DT correctly at all. It also sound pretty
>> fragile (what if the PCIe node is named something else?).
> 
> That would require 2 wrongs. Both missing device_type and wrong node
> name. You could still warn if we matched on node name.

OK. So how about something like this?

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 590493e04b01..a7a6ee599b14 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -134,9 +134,13 @@ static int of_bus_pci_match(struct device_node *np)
   	 * "pciex" is PCI Express
  	 * "vci" is for the /chaos bridge on 1st-gen PCI powermacs
  	 * "ht" is hypertransport
+	 *
+	 * If none of the device_type match, and that the node name is
+	 * "pcie", accept the device as PCI (with a warning).
  	 */
  	return of_node_is_type(np, "pci") || of_node_is_type(np, "pciex") ||
-		of_node_is_type(np, "vci") || of_node_is_type(np, "ht");
+		of_node_is_type(np, "vci") || of_node_is_type(np, "ht") ||
+		WARN_ON_ONCE(of_node_name_eq(np, "pcie"));
  }

  static void of_bus_pci_count_cells(struct device_node *np,

It should address all the drivers in one go, and yet tell users
that something is amiss.

         M.
Saravana Kannan Aug. 18, 2020, 5:48 p.m. UTC | #7
On Tue, Aug 18, 2020 at 10:34 AM Marc Zyngier <maz@kernel.org> wrote:
>
> On 2020-08-18 15:23, Rob Herring wrote:
> > On Tue, Aug 18, 2020 at 1:35 AM Marc Zyngier <maz@kernel.org> wrote:
> >>
> >> On 2020-08-17 17:12, Rob Herring wrote:
> >> > On Sun, Aug 16, 2020 at 4:40 AM Marc Zyngier <maz@kernel.org> wrote:
> >> >>
> >> >> On Sun, 16 Aug 2020 00:22:28 +0100,
> >> >> Bjorn Helgaas <helgaas@kernel.org> wrote:
> >> >> >
> >> >> > On Sat, Aug 15, 2020 at 01:51:11PM +0100, Marc Zyngier wrote:
> >> >> > > Recent changes to the DT PCI bus parsing made it mandatory for
> >> >> > > device tree nodes describing a PCI controller to have the
> >> >> > > 'device_type = "pci"' property for the node to be matched.
> >> >> > >
> >> >> > > Although this follows the letter of the specification, it
> >> >> > > breaks existing device-trees that have been working fine
> >> >> > > for years.  Rockchip rk3399-based systems are a prime example
> >> >> > > of such collateral damage, and have stopped discovering their
> >> >> > > PCI bus.
> >> >> > >
> >> >> > > In order to paper over the blunder, let's add a workaround
> >> >> > > to the pcie-rockchip driver, adding the missing property when
> >> >> > > none is found at boot time. A warning will hopefully nudge the
> >> >> > > user into updating their DT to a fixed version if they can, but
> >> >> > > the insentive is obviously pretty small.
> >> >> >
> >> >> > s/insentive/incentive/ (Lorenzo or I can fix this up)
> >> >> >
> >> >> > > Fixes: 2f96593ecc37 ("of_address: Add bus type match for pci ranges parser")
> >> >> > > Suggested-by: Roh Herring <robh+dt@kernel.org>
> >> >> >
> >> >> > s/Roh/Rob/ (similarly)
> >> >>
> >> >> Clearly not my day when it comes to proofreading commit messages.
> >> >> Thanks for pointing this out, and in advance for fixing it up.
> >> >>
> >> >> >
> >> >> > > Signed-off-by: Marc Zyngier <maz@kernel.org>
> >> >> >
> >> >> > This looks like a candidate for v5.9, since 2f96593ecc37 was merged
> >> >> > during the v5.9 merge window, right?
> >> >>
> >> >> Absolutely.
> >> >>
> >> >> > I wonder how many other DTs are similarly broken?  Maybe Rob's DT
> >> >> > checker has already looked?
> >> >>
> >> >> I've just managed to run the checker, which comes up with all kinds of
> >> >> goodies. Apart from the above, it also spots the following:
> >> >>
> >> >> - arch/arm64/boot/dts/mediatek/mt7622.dtsi: Has a device_type property
> >> >>   in its main PCIe node, but not in the child nodes. It isn't obvious
> >> >>   to me whether that's a violation or not (the spec doesn't say
> >> >>   whether the property should be set on a per-port basis). Rob?
> >> >
> >> > The rule is bridge nodes should have 'device_type = "pci"'. But what's
> >> > needed to fix these cases is setting device_type where we are parsing
> >> > ranges or dma-ranges which we're not doing on the child ndes.
> >> > Otherwise, I don't think it matters in this case unless you have child
> >> > (grandchild here) nodes for PCI devices. If you did have child nodes,
> >> > the address translation was already broken before this change.
> >>
> >> Fair enough.
> >>
> >> >> - arch/arm64/boot/dts/qcom/msm8996.dtsi: Only one out of the three
> >> >>   PCIe nodes has the device_type property, probably broken similarly
> >> >>   to rk3399.
> >> >
> >> > The only upstream board is DB820c, so probably not as wide an impact...
> >> >
> >> > There are also 92 (lots of duplicates due to multiple boards) more
> >> > cases in arch/arm/. A log is here[1].
> >>
> >> Mostly Broadcom stuff, apparently. I'll see if I can have a stab
> >> at it (although someone will have to test it).
> >>
> >> >
> >> >> I could move the workaround to drivers/pci/of.c, and have it called
> >> >> from the individual drivers. I don't have the HW to test those though.
> >> >>
> >> >> Thoughts?
> >> >
> >> > I think we should go with my other suggestion of looking at the node
> >> > name. Looks like just checking 'pcie' is enough. We can skip 'pci' as
> >> > I don't see any cases.
> >>
> >> I really dislike it.
> >>
> >> Once we put this node name matching in, there is no incentive for
> >> people to write their DT correctly at all. It also sound pretty
> >> fragile (what if the PCIe node is named something else?).
> >
> > That would require 2 wrongs. Both missing device_type and wrong node
> > name. You could still warn if we matched on node name.
>
> OK. So how about something like this?
>
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index 590493e04b01..a7a6ee599b14 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -134,9 +134,13 @@ static int of_bus_pci_match(struct device_node *np)
>          * "pciex" is PCI Express
>          * "vci" is for the /chaos bridge on 1st-gen PCI powermacs
>          * "ht" is hypertransport
> +        *
> +        * If none of the device_type match, and that the node name is
> +        * "pcie", accept the device as PCI (with a warning).
>          */
>         return of_node_is_type(np, "pci") || of_node_is_type(np, "pciex") ||
> -               of_node_is_type(np, "vci") || of_node_is_type(np, "ht");
> +               of_node_is_type(np, "vci") || of_node_is_type(np, "ht") ||
> +               WARN_ON_ONCE(of_node_name_eq(np, "pcie"));

I don't think we need the _ONCE. Otherwise, it'd warn only for the
first device that has this problem.

How about?
WARN(of_node_name_eq(np, "pcie"), "Missing device type in %pOF", np)

That'll even tell them which node is bad.

-Saravana
Marc Zyngier Aug. 18, 2020, 7:02 p.m. UTC | #8
On 2020-08-18 18:48, Saravana Kannan wrote:
> On Tue, Aug 18, 2020 at 10:34 AM Marc Zyngier <maz@kernel.org> wrote:

[...]

>> OK. So how about something like this?
>> 
>> diff --git a/drivers/of/address.c b/drivers/of/address.c
>> index 590493e04b01..a7a6ee599b14 100644
>> --- a/drivers/of/address.c
>> +++ b/drivers/of/address.c
>> @@ -134,9 +134,13 @@ static int of_bus_pci_match(struct device_node 
>> *np)
>>          * "pciex" is PCI Express
>>          * "vci" is for the /chaos bridge on 1st-gen PCI powermacs
>>          * "ht" is hypertransport
>> +        *
>> +        * If none of the device_type match, and that the node name is
>> +        * "pcie", accept the device as PCI (with a warning).
>>          */
>>         return of_node_is_type(np, "pci") || of_node_is_type(np, 
>> "pciex") ||
>> -               of_node_is_type(np, "vci") || of_node_is_type(np, 
>> "ht");
>> +               of_node_is_type(np, "vci") || of_node_is_type(np, 
>> "ht") ||
>> +               WARN_ON_ONCE(of_node_name_eq(np, "pcie"));
> 
> I don't think we need the _ONCE. Otherwise, it'd warn only for the
> first device that has this problem.

Because probing devices doesn't necessarily occur once. Case in point,
it takes *10 to 15* attempts for a rk3399 system such as mine to finally
probe its PCIe device, thanks to the wonderful -EPROBE_DEFER.

Do I want to see the same stack trace 10 (or more) times? No.

> How about?
> WARN(of_node_name_eq(np, "pcie"), "Missing device type in %pOF", np)
> 
> That'll even tell them which node is bad.

I explained my objections above. Spitting out the device node is
useful, but there is no need to be exhaustive (if you're in a
position to fix the DT, you can track all the broken instances
for your device easily).

I'm actually minded to tone it down even more, because the stack
trace is meaningless to most users. See below for a revised patch.

         M.

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 590493e04b01..b37bd9cc2810 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -128,15 +128,29 @@ static unsigned int of_bus_pci_get_flags(const 
__be32 *addr)
   * PCI bus specific translator
   */

+static bool of_node_is_pcie(struct device_node *np)
+{
+	bool is_pcie = of_node_name_eq(np, "pcie");
+
+	if (is_pcie)
+		pr_warn_once("%pOF: Missing device_type\n", np);
+
+	return is_pcie;
+}
+
  static int of_bus_pci_match(struct device_node *np)
  {
  	/*
   	 * "pciex" is PCI Express
  	 * "vci" is for the /chaos bridge on 1st-gen PCI powermacs
  	 * "ht" is hypertransport
+	 *
+	 * If none of the device_type match, and that the node name is
+	 * "pcie", accept the device as PCI (with a warning).
  	 */
  	return of_node_is_type(np, "pci") || of_node_is_type(np, "pciex") ||
-		of_node_is_type(np, "vci") || of_node_is_type(np, "ht");
+		of_node_is_type(np, "vci") || of_node_is_type(np, "ht") ||
+		of_node_is_pcie(np);
  }

  static void of_bus_pci_count_cells(struct device_node *np,
Rob Herring (Arm) Aug. 18, 2020, 7:06 p.m. UTC | #9
On Tue, Aug 18, 2020 at 1:03 PM Marc Zyngier <maz@kernel.org> wrote:
>
> On 2020-08-18 18:48, Saravana Kannan wrote:
> > On Tue, Aug 18, 2020 at 10:34 AM Marc Zyngier <maz@kernel.org> wrote:
>
> [...]
>
> >> OK. So how about something like this?
> >>
> >> diff --git a/drivers/of/address.c b/drivers/of/address.c
> >> index 590493e04b01..a7a6ee599b14 100644
> >> --- a/drivers/of/address.c
> >> +++ b/drivers/of/address.c
> >> @@ -134,9 +134,13 @@ static int of_bus_pci_match(struct device_node
> >> *np)
> >>          * "pciex" is PCI Express
> >>          * "vci" is for the /chaos bridge on 1st-gen PCI powermacs
> >>          * "ht" is hypertransport
> >> +        *
> >> +        * If none of the device_type match, and that the node name is
> >> +        * "pcie", accept the device as PCI (with a warning).
> >>          */
> >>         return of_node_is_type(np, "pci") || of_node_is_type(np,
> >> "pciex") ||
> >> -               of_node_is_type(np, "vci") || of_node_is_type(np,
> >> "ht");
> >> +               of_node_is_type(np, "vci") || of_node_is_type(np,
> >> "ht") ||
> >> +               WARN_ON_ONCE(of_node_name_eq(np, "pcie"));
> >
> > I don't think we need the _ONCE. Otherwise, it'd warn only for the
> > first device that has this problem.
>
> Because probing devices doesn't necessarily occur once. Case in point,
> it takes *10 to 15* attempts for a rk3399 system such as mine to finally
> probe its PCIe device, thanks to the wonderful -EPROBE_DEFER.
>
> Do I want to see the same stack trace 10 (or more) times? No.
>
> > How about?
> > WARN(of_node_name_eq(np, "pcie"), "Missing device type in %pOF", np)
> >
> > That'll even tell them which node is bad.
>
> I explained my objections above. Spitting out the device node is
> useful, but there is no need to be exhaustive (if you're in a
> position to fix the DT, you can track all the broken instances
> for your device easily).
>
> I'm actually minded to tone it down even more, because the stack
> trace is meaningless to most users. See below for a revised patch.

LGTM.

>          M.
>
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index 590493e04b01..b37bd9cc2810 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -128,15 +128,29 @@ static unsigned int of_bus_pci_get_flags(const
> __be32 *addr)
>    * PCI bus specific translator
>    */
>
> +static bool of_node_is_pcie(struct device_node *np)
> +{
> +       bool is_pcie = of_node_name_eq(np, "pcie");
> +
> +       if (is_pcie)
> +               pr_warn_once("%pOF: Missing device_type\n", np);
> +
> +       return is_pcie;
> +}
> +
>   static int of_bus_pci_match(struct device_node *np)
>   {
>         /*
>          * "pciex" is PCI Express
>          * "vci" is for the /chaos bridge on 1st-gen PCI powermacs
>          * "ht" is hypertransport
> +        *
> +        * If none of the device_type match, and that the node name is
> +        * "pcie", accept the device as PCI (with a warning).
>          */
>         return of_node_is_type(np, "pci") || of_node_is_type(np, "pciex") ||
> -               of_node_is_type(np, "vci") || of_node_is_type(np, "ht");
> +               of_node_is_type(np, "vci") || of_node_is_type(np, "ht") ||
> +               of_node_is_pcie(np);
>   }
>
>   static void of_bus_pci_count_cells(struct device_node *np,
>
> --
> Jazz is not dead. It just smells funny...
diff mbox series

Patch

diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
index 0bb2fb3e8a0b..d7dd04430a99 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -949,6 +949,35 @@  static int rockchip_pcie_probe(struct platform_device *pdev)
 	if (!dev->of_node)
 		return -ENODEV;
 
+	/*
+	 * Most rk3399 DTs are missing the 'device_type = "pci"' property,
+	 * potentially leading to PCIe probing failure. Be kind to the
+	 * users and fix it up for them. Upgrading is recommended.
+	 */
+	if (!of_find_property(dev->of_node, "device_type", NULL)) {
+		const char dtype[] = "pci";
+		struct property *prop;
+
+		dev_warn(dev, "Working around missing device_type property\n");
+
+		prop = kzalloc(sizeof(*prop), GFP_KERNEL);
+		if (!prop)
+			return -ENOMEM;
+
+		prop->name	= kstrdup("device_type", GFP_KERNEL);
+		prop->value	= kstrdup(dtype, GFP_KERNEL);
+		prop->length	= ARRAY_SIZE(dtype);
+		if (!prop->name || !prop->value) {
+			kfree(prop->name);
+			kfree(prop->value);
+			kfree(prop);
+			return -ENOMEM;
+		}
+
+		if (of_add_property(dev->of_node, prop))
+			dev_warn(dev, "Failed to add property, probing may fail");
+	}
+
 	bridge = devm_pci_alloc_host_bridge(dev, sizeof(*rockchip));
 	if (!bridge)
 		return -ENOMEM;