devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only
@ 2015-09-04 16:50 Marc Zyngier
  2015-09-04 16:50 ` [PATCH v4 1/4] of/pci: Add of_pci_check_probe_only to parse "linux, pci-probe-only" Marc Zyngier
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Marc Zyngier @ 2015-09-04 16:50 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Will Deacon, Bjorn Helgaas, Suravee Suthikulpanit,
	Lorenzo Pieralisi, Grant Likely, Rob Herring
  Cc: Alexander Graf, linux-kernel, linux-arm-kernel, linuxppc-dev,
	linux-pci, devicetree

The pci-host-generic driver parses the linux,pci-probe-only property,
and assumes that it will have a boolean parameter.

Turns out that the Seattle DTS file has a naked "linux,pci-probe-only"
property, which leads to the driver dereferencing some unsuspecting
memory location. Nothing really bad happens (we end up reading some
other bit of DT, fortunately), but that not a reason to keep it this
way. Turns out that the Pseries code (where this code was lifted from)
may suffer from the same issue.

The first patch introduces a common (and fixed) version of that check
that can be used by drivers and architectures that require it. The two
following patches change the pci-host-generic driver and the powerpc
code to use it.

Finally, the bad property is removed from the Seatle DTS, because it
is simply not necessary (it actually prevents me from using SR-IOV,
which otherwise runs fine without the probe-only thing).

This has been tested on the offending Seattle board.

* From v3:
  - Restrict the property lookup to /chosen (Rob)
  - Acked-by on patch #4 from Suravee
  - I swear this is the last time I rework these patches! ;-)

* From v2:
  - Use of_property_read_u32 to safely read the property (Rob)
  - Add a log message to indicate when we enable probe-only
    (probably quite useful for debugging)

* From v1:
  - Consolidate the parsing in of_pci.c (Bjorn)

Marc Zyngier (4):
  of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only"
  PCI: pci-host-generic: Fix lookup of linux,pci-probe-only property
  powerpc: PCI: Fix lookup of linux,pci-probe-only property
  arm64: dts: Drop linux,pci-probe-only from the Seattle DTS

 arch/arm64/boot/dts/amd/amd-overdrive.dts |  1 -
 arch/powerpc/platforms/pseries/setup.c    | 14 ++------------
 drivers/of/of_pci.c                       | 28 ++++++++++++++++++++++++++++
 drivers/pci/host/pci-host-generic.c       |  9 +--------
 include/linux/of_pci.h                    |  3 +++
 5 files changed, 34 insertions(+), 21 deletions(-)

-- 
2.1.4

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

* [PATCH v4 1/4] of/pci: Add of_pci_check_probe_only to parse "linux, pci-probe-only"
  2015-09-04 16:50 [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
@ 2015-09-04 16:50 ` Marc Zyngier
       [not found]   ` <1441385411-7624-2-git-send-email-marc.zyngier-5wv7dgnIgG8@public.gmane.org>
  2015-09-04 16:50 ` [PATCH v4 2/4] PCI: pci-host-generic: Fix lookup of linux,pci-probe-only property Marc Zyngier
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Marc Zyngier @ 2015-09-04 16:50 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Will Deacon, Bjorn Helgaas, Suravee Suthikulpanit,
	Lorenzo Pieralisi, Grant Likely, Rob Herring
  Cc: devicetree, linux-pci, Alexander Graf, linux-kernel, linuxppc-dev,
	linux-arm-kernel

Both pci-host-generic and Pseries parse the "linux,pci-probe-only"
property to engage the PCI_PROBE_ONLY mode, and both have a subtle
bug that can be triggered if the property has no parameter.

Provide a generic, safe implementation that can be used by both.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 drivers/of/of_pci.c    | 28 ++++++++++++++++++++++++++++
 include/linux/of_pci.h |  3 +++
 2 files changed, 31 insertions(+)

diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
index 5751dc5..5dd4966 100644
--- a/drivers/of/of_pci.c
+++ b/drivers/of/of_pci.c
@@ -118,6 +118,34 @@ int of_get_pci_domain_nr(struct device_node *node)
 EXPORT_SYMBOL_GPL(of_get_pci_domain_nr);
 
 /**
+ * of_pci_check_probe_only - Setup probe only mode if linux,pci-probe-only
+ *                           is present and valid
+ *
+ * @node: device tree node that may contain the property (usually "chosen")
+ *
+ */
+void of_pci_check_probe_only(void)
+{
+	u32 val;
+	int ret;
+
+	ret = of_property_read_u32(of_chosen, "linux,pci-probe-only", &val);
+	if (ret) {
+		if (ret == -ENODATA || ret == -EOVERFLOW)
+			pr_warn("linux,pci-probe-only without valid value, ignoring\n");
+		return;
+	}
+
+	if (val)
+		pci_add_flags(PCI_PROBE_ONLY);
+	else
+		pci_clear_flags(PCI_PROBE_ONLY);
+
+	pr_info("PCI: PROBE_ONLY %sabled\n", val ? "en" : "dis");
+}
+EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
+
+/**
  * of_pci_dma_configure - Setup DMA configuration
  * @dev: ptr to pci_dev struct of the PCI device
  *
diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h
index 29fd3fe..38c0533 100644
--- a/include/linux/of_pci.h
+++ b/include/linux/of_pci.h
@@ -17,6 +17,7 @@ int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin);
 int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
 int of_get_pci_domain_nr(struct device_node *node);
 void of_pci_dma_configure(struct pci_dev *pci_dev);
+void of_pci_check_probe_only(void);
 #else
 static inline int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq)
 {
@@ -53,6 +54,8 @@ of_get_pci_domain_nr(struct device_node *node)
 }
 
 static inline void of_pci_dma_configure(struct pci_dev *pci_dev) { }
+
+static inline void of_pci_check_probe_only(void) { }
 #endif
 
 #if defined(CONFIG_OF_ADDRESS)
-- 
2.1.4

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

* [PATCH v4 2/4] PCI: pci-host-generic: Fix lookup of linux,pci-probe-only property
  2015-09-04 16:50 [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
  2015-09-04 16:50 ` [PATCH v4 1/4] of/pci: Add of_pci_check_probe_only to parse "linux, pci-probe-only" Marc Zyngier
@ 2015-09-04 16:50 ` Marc Zyngier
       [not found]   ` <1441385411-7624-3-git-send-email-marc.zyngier-5wv7dgnIgG8@public.gmane.org>
  2015-09-04 16:50 ` [PATCH v4 3/4] powerpc: PCI: " Marc Zyngier
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Marc Zyngier @ 2015-09-04 16:50 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Will Deacon, Bjorn Helgaas, Suravee Suthikulpanit,
	Lorenzo Pieralisi, Grant Likely, Rob Herring
  Cc: Alexander Graf, linux-kernel, linux-arm-kernel, linuxppc-dev,
	linux-pci, devicetree

When pci-host-generic looks for the probe-only property, it seems
to trust the DT to be correctly written, and assumes that there
is a parameter to the property.

Unfortunately, this is not always the case, and some firmware expose
this property naked. The driver ends up making a decision based on
whatever the property pointer points to, which is likely to be junk.

Switch to the common of_pci.c implementation that doesn't suffer
from this problem.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 drivers/pci/host/pci-host-generic.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/pci/host/pci-host-generic.c b/drivers/pci/host/pci-host-generic.c
index 265dd25..224303d 100644
--- a/drivers/pci/host/pci-host-generic.c
+++ b/drivers/pci/host/pci-host-generic.c
@@ -210,7 +210,6 @@ static int gen_pci_probe(struct platform_device *pdev)
 	int err;
 	const char *type;
 	const struct of_device_id *of_id;
-	const int *prop;
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
 	struct gen_pci *pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
@@ -225,13 +224,7 @@ static int gen_pci_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	prop = of_get_property(of_chosen, "linux,pci-probe-only", NULL);
-	if (prop) {
-		if (*prop)
-			pci_add_flags(PCI_PROBE_ONLY);
-		else
-			pci_clear_flags(PCI_PROBE_ONLY);
-	}
+	of_pci_check_probe_only();
 
 	of_id = of_match_node(gen_pci_of_match, np);
 	pci->cfg.ops = of_id->data;
-- 
2.1.4

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

* [PATCH v4 3/4] powerpc: PCI: Fix lookup of linux,pci-probe-only property
  2015-09-04 16:50 [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
  2015-09-04 16:50 ` [PATCH v4 1/4] of/pci: Add of_pci_check_probe_only to parse "linux, pci-probe-only" Marc Zyngier
  2015-09-04 16:50 ` [PATCH v4 2/4] PCI: pci-host-generic: Fix lookup of linux,pci-probe-only property Marc Zyngier
@ 2015-09-04 16:50 ` Marc Zyngier
  2015-09-07  8:59   ` Michael Ellerman
  2015-09-04 16:50 ` [PATCH v4 4/4] arm64: dts: Drop linux,pci-probe-only from the Seattle DTS Marc Zyngier
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Marc Zyngier @ 2015-09-04 16:50 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Will Deacon, Bjorn Helgaas, Suravee Suthikulpanit,
	Lorenzo Pieralisi, Grant Likely, Rob Herring
  Cc: Alexander Graf, linux-kernel, linux-arm-kernel, linuxppc-dev,
	linux-pci, devicetree

When find_and_init_phbs() looks for the probe-only property, it seems
to trust the firmware to be correctly written, and assumes that there
is a parameter to the property.

It is conceivable that the firmware could not be that perfect, and it
could expose this property naked (at least one arm64 platform seems to
exhibit this exact behaviour). The setup code the ends up making
a decision based on whatever the property pointer points to, which
is likely to be junk.

Instead, switch to the common of_pci.c implementation that doesn't
suffer from this problem and ignore the property if the firmware
couldn't make up its mind.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 arch/powerpc/platforms/pseries/setup.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 39a74fa..6016709 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -40,6 +40,7 @@
 #include <linux/seq_file.h>
 #include <linux/root_dev.h>
 #include <linux/of.h>
+#include <linux/of_pci.h>
 #include <linux/kexec.h>
 
 #include <asm/mmu.h>
@@ -495,18 +496,7 @@ static void __init find_and_init_phbs(void)
 	 * PCI_PROBE_ONLY and PCI_REASSIGN_ALL_BUS can be set via properties
 	 * in chosen.
 	 */
-	if (of_chosen) {
-		const int *prop;
-
-		prop = of_get_property(of_chosen,
-				"linux,pci-probe-only", NULL);
-		if (prop) {
-			if (*prop)
-				pci_add_flags(PCI_PROBE_ONLY);
-			else
-				pci_clear_flags(PCI_PROBE_ONLY);
-		}
-	}
+	of_pci_check_probe_only();
 }
 
 static void __init pSeries_setup_arch(void)
-- 
2.1.4

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

* [PATCH v4 4/4] arm64: dts: Drop linux,pci-probe-only from the Seattle DTS
  2015-09-04 16:50 [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
                   ` (2 preceding siblings ...)
  2015-09-04 16:50 ` [PATCH v4 3/4] powerpc: PCI: " Marc Zyngier
@ 2015-09-04 16:50 ` Marc Zyngier
  2015-09-04 18:52 ` [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Rob Herring
  2015-09-17 15:30 ` Bjorn Helgaas
  5 siblings, 0 replies; 12+ messages in thread
From: Marc Zyngier @ 2015-09-04 16:50 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Will Deacon, Bjorn Helgaas, Suravee Suthikulpanit,
	Lorenzo Pieralisi, Grant Likely, Rob Herring
  Cc: Alexander Graf, linux-kernel, linux-arm-kernel, linuxppc-dev,
	linux-pci, devicetree

The linux,pci-probe-only property mandates an argument to indicate
whether or not to engage the "probe-only" mode, but the Seattle
DTS just provides a naked property, which is illegal.

Also, it turns out that the board is perfectly happy without
probe-only, so let's drop this altogether.

Acked-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 arch/arm64/boot/dts/amd/amd-overdrive.dts | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/arm64/boot/dts/amd/amd-overdrive.dts b/arch/arm64/boot/dts/amd/amd-overdrive.dts
index 564a3f7..128fa94 100644
--- a/arch/arm64/boot/dts/amd/amd-overdrive.dts
+++ b/arch/arm64/boot/dts/amd/amd-overdrive.dts
@@ -14,7 +14,6 @@
 
 	chosen {
 		stdout-path = &serial0;
-		linux,pci-probe-only;
 	};
 };
 
-- 
2.1.4

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

* Re: [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only
  2015-09-04 16:50 [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
                   ` (3 preceding siblings ...)
  2015-09-04 16:50 ` [PATCH v4 4/4] arm64: dts: Drop linux,pci-probe-only from the Seattle DTS Marc Zyngier
@ 2015-09-04 18:52 ` Rob Herring
  2015-09-17 15:30 ` Bjorn Helgaas
  5 siblings, 0 replies; 12+ messages in thread
From: Rob Herring @ 2015-09-04 18:52 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Will Deacon, Bjorn Helgaas, Suravee Suthikulpanit,
	Lorenzo Pieralisi, Grant Likely, Rob Herring, Alexander Graf,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linuxppc-dev,
	linux-pci@vger.kernel.org, devicetree@vger.kernel.org

On Fri, Sep 4, 2015 at 11:50 AM, Marc Zyngier <marc.zyngier@arm.com> wrote:
> The pci-host-generic driver parses the linux,pci-probe-only property,
> and assumes that it will have a boolean parameter.
>
> Turns out that the Seattle DTS file has a naked "linux,pci-probe-only"
> property, which leads to the driver dereferencing some unsuspecting
> memory location. Nothing really bad happens (we end up reading some
> other bit of DT, fortunately), but that not a reason to keep it this
> way. Turns out that the Pseries code (where this code was lifted from)
> may suffer from the same issue.
>
> The first patch introduces a common (and fixed) version of that check
> that can be used by drivers and architectures that require it. The two
> following patches change the pci-host-generic driver and the powerpc
> code to use it.
>
> Finally, the bad property is removed from the Seatle DTS, because it
> is simply not necessary (it actually prevents me from using SR-IOV,
> which otherwise runs fine without the probe-only thing).
>
> This has been tested on the offending Seattle board.
>
> * From v3:
>   - Restrict the property lookup to /chosen (Rob)
>   - Acked-by on patch #4 from Suravee
>   - I swear this is the last time I rework these patches! ;-)
>
> * From v2:
>   - Use of_property_read_u32 to safely read the property (Rob)
>   - Add a log message to indicate when we enable probe-only
>     (probably quite useful for debugging)
>
> * From v1:
>   - Consolidate the parsing in of_pci.c (Bjorn)
>
> Marc Zyngier (4):
>   of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only"
>   PCI: pci-host-generic: Fix lookup of linux,pci-probe-only property
>   powerpc: PCI: Fix lookup of linux,pci-probe-only property
>   arm64: dts: Drop linux,pci-probe-only from the Seattle DTS
>
>  arch/arm64/boot/dts/amd/amd-overdrive.dts |  1 -
>  arch/powerpc/platforms/pseries/setup.c    | 14 ++------------
>  drivers/of/of_pci.c                       | 28 ++++++++++++++++++++++++++++
>  drivers/pci/host/pci-host-generic.c       |  9 +--------
>  include/linux/of_pci.h                    |  3 +++
>  5 files changed, 34 insertions(+), 21 deletions(-)

For the series:

Reviewed-by: Rob Herring <robh@kernel.org>

Rob

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

* Re: [PATCH v4 1/4] of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only"
       [not found]   ` <1441385411-7624-2-git-send-email-marc.zyngier-5wv7dgnIgG8@public.gmane.org>
@ 2015-09-04 19:19     ` Rob Herring
  0 siblings, 0 replies; 12+ messages in thread
From: Rob Herring @ 2015-09-04 19:19 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Will Deacon, Bjorn Helgaas, Suravee Suthikulpanit,
	Lorenzo Pieralisi, Grant Likely, Rob Herring, Alexander Graf,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linuxppc-dev, linux-pci-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

On Fri, Sep 4, 2015 at 11:50 AM, Marc Zyngier <marc.zyngier-5wv7dgnIgG8@public.gmane.org> wrote:
> Both pci-host-generic and Pseries parse the "linux,pci-probe-only"
> property to engage the PCI_PROBE_ONLY mode, and both have a subtle
> bug that can be triggered if the property has no parameter.
>
> Provide a generic, safe implementation that can be used by both.
>
> Signed-off-by: Marc Zyngier <marc.zyngier-5wv7dgnIgG8@public.gmane.org>
> ---
>  drivers/of/of_pci.c    | 28 ++++++++++++++++++++++++++++
>  include/linux/of_pci.h |  3 +++
>  2 files changed, 31 insertions(+)
>
> diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
> index 5751dc5..5dd4966 100644
> --- a/drivers/of/of_pci.c
> +++ b/drivers/of/of_pci.c
> @@ -118,6 +118,34 @@ int of_get_pci_domain_nr(struct device_node *node)
>  EXPORT_SYMBOL_GPL(of_get_pci_domain_nr);
>
>  /**
> + * of_pci_check_probe_only - Setup probe only mode if linux,pci-probe-only
> + *                           is present and valid
> + *
> + * @node: device tree node that may contain the property (usually "chosen")

This line should be removed. Perhaps Bjorn will fix it up.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v4 3/4] powerpc: PCI: Fix lookup of linux,pci-probe-only property
  2015-09-04 16:50 ` [PATCH v4 3/4] powerpc: PCI: " Marc Zyngier
@ 2015-09-07  8:59   ` Michael Ellerman
  0 siblings, 0 replies; 12+ messages in thread
From: Michael Ellerman @ 2015-09-07  8:59 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Will Deacon,
	Bjorn Helgaas, Suravee Suthikulpanit, Lorenzo Pieralisi,
	Grant Likely, Rob Herring, Alexander Graf, linux-kernel,
	linux-arm-kernel, linuxppc-dev, linux-pci, devicetree,
	Anton Blanchard

On Fri, 2015-09-04 at 17:50 +0100, Marc Zyngier wrote:
> When find_and_init_phbs() looks for the probe-only property, it seems
> to trust the firmware to be correctly written, and assumes that there
> is a parameter to the property.
> 
> It is conceivable that the firmware could not be that perfect, and it
> could expose this property naked (at least one arm64 platform seems to
> exhibit this exact behaviour). The setup code the ends up making
> a decision based on whatever the property pointer points to, which
> is likely to be junk.
> 
> Instead, switch to the common of_pci.c implementation that doesn't
> suffer from this problem and ignore the property if the firmware
> couldn't make up its mind.
> 
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
>  arch/powerpc/platforms/pseries/setup.c | 14 ++------------

Thanks.

I can't find any powerpc machine that is currently using this, or much info on
what ever did use it, so I think it's pretty low impact, and the change looks
sane.

Acked-by: Michael Ellerman <mpe@ellerman.id.au>

cheers

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

* Re: [PATCH v4 2/4] PCI: pci-host-generic: Fix lookup of linux,pci-probe-only property
       [not found]   ` <1441385411-7624-3-git-send-email-marc.zyngier-5wv7dgnIgG8@public.gmane.org>
@ 2015-09-07  9:15     ` Will Deacon
  0 siblings, 0 replies; 12+ messages in thread
From: Will Deacon @ 2015-09-07  9:15 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Bjorn Helgaas, suravee.suthikulpanit-5C7GfCeVMHo@public.gmane.org,
	Lorenzo Pieralisi,
	grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org, Rob Herring,
	agraf-l3A5Bk7waGM@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	linux-pci-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

On Fri, Sep 04, 2015 at 05:50:09PM +0100, Marc Zyngier wrote:
> When pci-host-generic looks for the probe-only property, it seems
> to trust the DT to be correctly written, and assumes that there
> is a parameter to the property.
> 
> Unfortunately, this is not always the case, and some firmware expose
> this property naked. The driver ends up making a decision based on
> whatever the property pointer points to, which is likely to be junk.
> 
> Switch to the common of_pci.c implementation that doesn't suffer
> from this problem.
> 
> Signed-off-by: Marc Zyngier <marc.zyngier-5wv7dgnIgG8@public.gmane.org>
> ---
>  drivers/pci/host/pci-host-generic.c | 9 +--------
>  1 file changed, 1 insertion(+), 8 deletions(-)
> 
> diff --git a/drivers/pci/host/pci-host-generic.c b/drivers/pci/host/pci-host-generic.c
> index 265dd25..224303d 100644
> --- a/drivers/pci/host/pci-host-generic.c
> +++ b/drivers/pci/host/pci-host-generic.c
> @@ -210,7 +210,6 @@ static int gen_pci_probe(struct platform_device *pdev)
>  	int err;
>  	const char *type;
>  	const struct of_device_id *of_id;
> -	const int *prop;
>  	struct device *dev = &pdev->dev;
>  	struct device_node *np = dev->of_node;
>  	struct gen_pci *pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
> @@ -225,13 +224,7 @@ static int gen_pci_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> -	prop = of_get_property(of_chosen, "linux,pci-probe-only", NULL);
> -	if (prop) {
> -		if (*prop)
> -			pci_add_flags(PCI_PROBE_ONLY);
> -		else
> -			pci_clear_flags(PCI_PROBE_ONLY);
> -	}
> +	of_pci_check_probe_only();

Looks good to me:

  Acked-by: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>

Thanks, Marc.

Will
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only
  2015-09-04 16:50 [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
                   ` (4 preceding siblings ...)
  2015-09-04 18:52 ` [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Rob Herring
@ 2015-09-17 15:30 ` Bjorn Helgaas
  2015-09-17 17:17   ` Marc Zyngier
  5 siblings, 1 reply; 12+ messages in thread
From: Bjorn Helgaas @ 2015-09-17 15:30 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Will Deacon, Suravee Suthikulpanit, Lorenzo Pieralisi,
	Grant Likely, Rob Herring, Alexander Graf, linux-kernel,
	linux-arm-kernel, linuxppc-dev, linux-pci, devicetree

On Fri, Sep 04, 2015 at 05:50:07PM +0100, Marc Zyngier wrote:
> The pci-host-generic driver parses the linux,pci-probe-only property,
> and assumes that it will have a boolean parameter.
> 
> Turns out that the Seattle DTS file has a naked "linux,pci-probe-only"
> property, which leads to the driver dereferencing some unsuspecting
> memory location. Nothing really bad happens (we end up reading some
> other bit of DT, fortunately), but that not a reason to keep it this
> way. Turns out that the Pseries code (where this code was lifted from)
> may suffer from the same issue.
> 
> The first patch introduces a common (and fixed) version of that check
> that can be used by drivers and architectures that require it. The two
> following patches change the pci-host-generic driver and the powerpc
> code to use it.
> 
> Finally, the bad property is removed from the Seatle DTS, because it
> is simply not necessary (it actually prevents me from using SR-IOV,
> which otherwise runs fine without the probe-only thing).
> 
> This has been tested on the offending Seattle board.
> 
> * From v3:
>   - Restrict the property lookup to /chosen (Rob)
>   - Acked-by on patch #4 from Suravee
>   - I swear this is the last time I rework these patches! ;-)
> 
> * From v2:
>   - Use of_property_read_u32 to safely read the property (Rob)
>   - Add a log message to indicate when we enable probe-only
>     (probably quite useful for debugging)
> 
> * From v1:
>   - Consolidate the parsing in of_pci.c (Bjorn)
> 
> Marc Zyngier (4):
>   of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only"
>   PCI: pci-host-generic: Fix lookup of linux,pci-probe-only property
>   powerpc: PCI: Fix lookup of linux,pci-probe-only property
>   arm64: dts: Drop linux,pci-probe-only from the Seattle DTS
> 
>  arch/arm64/boot/dts/amd/amd-overdrive.dts |  1 -
>  arch/powerpc/platforms/pseries/setup.c    | 14 ++------------
>  drivers/of/of_pci.c                       | 28 ++++++++++++++++++++++++++++
>  drivers/pci/host/pci-host-generic.c       |  9 +--------
>  include/linux/of_pci.h                    |  3 +++
>  5 files changed, 34 insertions(+), 21 deletions(-)

Applied with the comment tweak and acks to pci/host-generic for v4.4,
thanks!

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

* Re: [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only
  2015-09-17 15:30 ` Bjorn Helgaas
@ 2015-09-17 17:17   ` Marc Zyngier
       [not found]     ` <55FAF5B1.1030401-5wv7dgnIgG8@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Marc Zyngier @ 2015-09-17 17:17 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Will Deacon, Suravee Suthikulpanit, Lorenzo Pieralisi,
	Grant Likely, Rob Herring, Alexander Graf, linux-kernel,
	linux-arm-kernel, linuxppc-dev, linux-pci, devicetree

On 17/09/15 16:30, Bjorn Helgaas wrote:
> On Fri, Sep 04, 2015 at 05:50:07PM +0100, Marc Zyngier wrote:
>> The pci-host-generic driver parses the linux,pci-probe-only property,
>> and assumes that it will have a boolean parameter.
>>
>> Turns out that the Seattle DTS file has a naked "linux,pci-probe-only"
>> property, which leads to the driver dereferencing some unsuspecting
>> memory location. Nothing really bad happens (we end up reading some
>> other bit of DT, fortunately), but that not a reason to keep it this
>> way. Turns out that the Pseries code (where this code was lifted from)
>> may suffer from the same issue.
>>
>> The first patch introduces a common (and fixed) version of that check
>> that can be used by drivers and architectures that require it. The two
>> following patches change the pci-host-generic driver and the powerpc
>> code to use it.
>>
>> Finally, the bad property is removed from the Seatle DTS, because it
>> is simply not necessary (it actually prevents me from using SR-IOV,
>> which otherwise runs fine without the probe-only thing).
>>
>> This has been tested on the offending Seattle board.
>>
>> * From v3:
>>   - Restrict the property lookup to /chosen (Rob)
>>   - Acked-by on patch #4 from Suravee
>>   - I swear this is the last time I rework these patches! ;-)
>>
>> * From v2:
>>   - Use of_property_read_u32 to safely read the property (Rob)
>>   - Add a log message to indicate when we enable probe-only
>>     (probably quite useful for debugging)
>>
>> * From v1:
>>   - Consolidate the parsing in of_pci.c (Bjorn)
>>
>> Marc Zyngier (4):
>>   of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only"
>>   PCI: pci-host-generic: Fix lookup of linux,pci-probe-only property
>>   powerpc: PCI: Fix lookup of linux,pci-probe-only property
>>   arm64: dts: Drop linux,pci-probe-only from the Seattle DTS
>>
>>  arch/arm64/boot/dts/amd/amd-overdrive.dts |  1 -
>>  arch/powerpc/platforms/pseries/setup.c    | 14 ++------------
>>  drivers/of/of_pci.c                       | 28 ++++++++++++++++++++++++++++
>>  drivers/pci/host/pci-host-generic.c       |  9 +--------
>>  include/linux/of_pci.h                    |  3 +++
>>  5 files changed, 34 insertions(+), 21 deletions(-)
> 
> Applied with the comment tweak and acks to pci/host-generic for v4.4,
> thanks!

Turns out that the 01.org infrastructure has picked up on a compilation
bug with randconfig. The following patch seems to fix it and should be
applied on the first patch:

diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
index 485d625..2da5abc 100644
--- a/drivers/of/of_pci.c
+++ b/drivers/of/of_pci.c
@@ -6,6 +6,8 @@
 #include <linux/of_pci.h>
 #include <linux/slab.h>
 
+#include <asm-generic/pci-bridge.h>
+
 static inline int __of_pci_pci_compare(struct device_node *node,
 				       unsigned int data)
 {

Sorry for the annoyance.

	M.
-- 
Jazz is not dead. It just smells funny...

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

* Re: [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only
       [not found]     ` <55FAF5B1.1030401-5wv7dgnIgG8@public.gmane.org>
@ 2015-09-17 17:21       ` Bjorn Helgaas
  0 siblings, 0 replies; 12+ messages in thread
From: Bjorn Helgaas @ 2015-09-17 17:21 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Will Deacon, Suravee Suthikulpanit, Lorenzo Pieralisi,
	Grant Likely, Rob Herring, Alexander Graf,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-arm,
	linuxppc-dev, linux-pci-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

On Thu, Sep 17, 2015 at 12:17 PM, Marc Zyngier <marc.zyngier-5wv7dgnIgG8@public.gmane.org> wrote:
> On 17/09/15 16:30, Bjorn Helgaas wrote:
>> On Fri, Sep 04, 2015 at 05:50:07PM +0100, Marc Zyngier wrote:
>>> The pci-host-generic driver parses the linux,pci-probe-only property,
>>> and assumes that it will have a boolean parameter.
>>>
>>> Turns out that the Seattle DTS file has a naked "linux,pci-probe-only"
>>> property, which leads to the driver dereferencing some unsuspecting
>>> memory location. Nothing really bad happens (we end up reading some
>>> other bit of DT, fortunately), but that not a reason to keep it this
>>> way. Turns out that the Pseries code (where this code was lifted from)
>>> may suffer from the same issue.
>>>
>>> The first patch introduces a common (and fixed) version of that check
>>> that can be used by drivers and architectures that require it. The two
>>> following patches change the pci-host-generic driver and the powerpc
>>> code to use it.
>>>
>>> Finally, the bad property is removed from the Seatle DTS, because it
>>> is simply not necessary (it actually prevents me from using SR-IOV,
>>> which otherwise runs fine without the probe-only thing).
>>>
>>> This has been tested on the offending Seattle board.
>>>
>>> * From v3:
>>>   - Restrict the property lookup to /chosen (Rob)
>>>   - Acked-by on patch #4 from Suravee
>>>   - I swear this is the last time I rework these patches! ;-)
>>>
>>> * From v2:
>>>   - Use of_property_read_u32 to safely read the property (Rob)
>>>   - Add a log message to indicate when we enable probe-only
>>>     (probably quite useful for debugging)
>>>
>>> * From v1:
>>>   - Consolidate the parsing in of_pci.c (Bjorn)
>>>
>>> Marc Zyngier (4):
>>>   of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only"
>>>   PCI: pci-host-generic: Fix lookup of linux,pci-probe-only property
>>>   powerpc: PCI: Fix lookup of linux,pci-probe-only property
>>>   arm64: dts: Drop linux,pci-probe-only from the Seattle DTS
>>>
>>>  arch/arm64/boot/dts/amd/amd-overdrive.dts |  1 -
>>>  arch/powerpc/platforms/pseries/setup.c    | 14 ++------------
>>>  drivers/of/of_pci.c                       | 28 ++++++++++++++++++++++++++++
>>>  drivers/pci/host/pci-host-generic.c       |  9 +--------
>>>  include/linux/of_pci.h                    |  3 +++
>>>  5 files changed, 34 insertions(+), 21 deletions(-)
>>
>> Applied with the comment tweak and acks to pci/host-generic for v4.4,
>> thanks!
>
> Turns out that the 01.org infrastructure has picked up on a compilation
> bug with randconfig. The following patch seems to fix it and should be
> applied on the first patch:
>
> diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
> index 485d625..2da5abc 100644
> --- a/drivers/of/of_pci.c
> +++ b/drivers/of/of_pci.c
> @@ -6,6 +6,8 @@
>  #include <linux/of_pci.h>
>  #include <linux/slab.h>
>
> +#include <asm-generic/pci-bridge.h>
> +
>  static inline int __of_pci_pci_compare(struct device_node *node,
>                                        unsigned int data)
>  {
>
> Sorry for the annoyance.

Folded in and re-pushed, thanks!
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2015-09-17 17:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-04 16:50 [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
2015-09-04 16:50 ` [PATCH v4 1/4] of/pci: Add of_pci_check_probe_only to parse "linux, pci-probe-only" Marc Zyngier
     [not found]   ` <1441385411-7624-2-git-send-email-marc.zyngier-5wv7dgnIgG8@public.gmane.org>
2015-09-04 19:19     ` [PATCH v4 1/4] of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only" Rob Herring
2015-09-04 16:50 ` [PATCH v4 2/4] PCI: pci-host-generic: Fix lookup of linux,pci-probe-only property Marc Zyngier
     [not found]   ` <1441385411-7624-3-git-send-email-marc.zyngier-5wv7dgnIgG8@public.gmane.org>
2015-09-07  9:15     ` Will Deacon
2015-09-04 16:50 ` [PATCH v4 3/4] powerpc: PCI: " Marc Zyngier
2015-09-07  8:59   ` Michael Ellerman
2015-09-04 16:50 ` [PATCH v4 4/4] arm64: dts: Drop linux,pci-probe-only from the Seattle DTS Marc Zyngier
2015-09-04 18:52 ` [PATCH v4 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Rob Herring
2015-09-17 15:30 ` Bjorn Helgaas
2015-09-17 17:17   ` Marc Zyngier
     [not found]     ` <55FAF5B1.1030401-5wv7dgnIgG8@public.gmane.org>
2015-09-17 17:21       ` Bjorn Helgaas

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