All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only
@ 2015-09-03 12:16 ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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 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                       | 31 +++++++++++++++++++++++++++++++
 drivers/pci/host/pci-host-generic.c       |  9 +--------
 include/linux/of_pci.h                    |  3 +++
 5 files changed, 37 insertions(+), 21 deletions(-)

-- 
2.1.4


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

* [PATCH v3 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only
@ 2015-09-03 12:16 ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-pci-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

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 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                       | 31 +++++++++++++++++++++++++++++++
 drivers/pci/host/pci-host-generic.c       |  9 +--------
 include/linux/of_pci.h                    |  3 +++
 5 files changed, 37 insertions(+), 21 deletions(-)

-- 
2.1.4

--
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] 25+ messages in thread

* [PATCH v3 0/4] PCI: arm64/powerpc: Fix parsing of linux, pci-probe-only
@ 2015-09-03 12:16 ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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 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                       | 31 +++++++++++++++++++++++++++++++
 drivers/pci/host/pci-host-generic.c       |  9 +--------
 include/linux/of_pci.h                    |  3 +++
 5 files changed, 37 insertions(+), 21 deletions(-)

-- 
2.1.4

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

* [PATCH v3 0/4] PCI: arm64/powerpc: Fix parsing of linux, pci-probe-only
@ 2015-09-03 12:16 ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 UTC (permalink / raw)
  To: linux-arm-kernel

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 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                       | 31 +++++++++++++++++++++++++++++++
 drivers/pci/host/pci-host-generic.c       |  9 +--------
 include/linux/of_pci.h                    |  3 +++
 5 files changed, 37 insertions(+), 21 deletions(-)

-- 
2.1.4

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

* [PATCH v3 1/4] of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only"
  2015-09-03 12:16 ` [PATCH v3 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
  (?)
@ 2015-09-03 12:16   ` Marc Zyngier
  -1 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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

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    | 31 +++++++++++++++++++++++++++++++
 include/linux/of_pci.h |  3 +++
 2 files changed, 34 insertions(+)

diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
index 5751dc5..7876343 100644
--- a/drivers/of/of_pci.c
+++ b/drivers/of/of_pci.c
@@ -118,6 +118,37 @@ 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(struct device_node *node)
+{
+	u32 val;
+	int ret;
+
+	if (!node)
+		return;
+
+	ret = of_property_read_u32(node, "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..4c0a617 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(struct device_node *node);
 #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(struct device_node *node) { }
 #endif
 
 #if defined(CONFIG_OF_ADDRESS)
-- 
2.1.4


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

* [PATCH v3 1/4] of/pci: Add of_pci_check_probe_only to parse "linux, pci-probe-only"
@ 2015-09-03 12:16   ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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

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    | 31 +++++++++++++++++++++++++++++++
 include/linux/of_pci.h |  3 +++
 2 files changed, 34 insertions(+)

diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
index 5751dc5..7876343 100644
--- a/drivers/of/of_pci.c
+++ b/drivers/of/of_pci.c
@@ -118,6 +118,37 @@ 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(struct device_node *node)
+{
+	u32 val;
+	int ret;
+
+	if (!node)
+		return;
+
+	ret = of_property_read_u32(node, "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..4c0a617 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(struct device_node *node);
 #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(struct device_node *node) { }
 #endif
 
 #if defined(CONFIG_OF_ADDRESS)
-- 
2.1.4

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

* [PATCH v3 1/4] of/pci: Add of_pci_check_probe_only to parse "linux, pci-probe-only"
@ 2015-09-03 12:16   ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 UTC (permalink / raw)
  To: 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    | 31 +++++++++++++++++++++++++++++++
 include/linux/of_pci.h |  3 +++
 2 files changed, 34 insertions(+)

diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
index 5751dc5..7876343 100644
--- a/drivers/of/of_pci.c
+++ b/drivers/of/of_pci.c
@@ -118,6 +118,37 @@ 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(struct device_node *node)
+{
+	u32 val;
+	int ret;
+
+	if (!node)
+		return;
+
+	ret = of_property_read_u32(node, "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..4c0a617 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(struct device_node *node);
 #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(struct device_node *node) { }
 #endif
 
 #if defined(CONFIG_OF_ADDRESS)
-- 
2.1.4

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

* [PATCH v3 2/4] PCI: pci-host-generic: Fix lookup of linux,pci-probe-only property
  2015-09-03 12:16 ` [PATCH v3 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
  (?)
  (?)
@ 2015-09-03 12:16   ` Marc Zyngier
  -1 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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..545ff4e 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_chosen);
 
 	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] 25+ messages in thread

* [PATCH v3 2/4] PCI: pci-host-generic: Fix lookup of linux, pci-probe-only property
@ 2015-09-03 12:16   ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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

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..545ff4e 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_chosen);
 
 	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] 25+ messages in thread

* [PATCH v3 2/4] PCI: pci-host-generic: Fix lookup of linux, pci-probe-only property
@ 2015-09-03 12:16   ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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..545ff4e 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_chosen);
 
 	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] 25+ messages in thread

* [PATCH v3 2/4] PCI: pci-host-generic: Fix lookup of linux, pci-probe-only property
@ 2015-09-03 12:16   ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 UTC (permalink / raw)
  To: linux-arm-kernel

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..545ff4e 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_chosen);
 
 	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] 25+ messages in thread

* [PATCH v3 3/4] powerpc: PCI: Fix lookup of linux,pci-probe-only property
  2015-09-03 12:16 ` [PATCH v3 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
  (?)
@ 2015-09-03 12:16   ` Marc Zyngier
  -1 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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..412531f 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(of_chosen);
 }
 
 static void __init pSeries_setup_arch(void)
-- 
2.1.4


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

* [PATCH v3 3/4] powerpc: PCI: Fix lookup of linux, pci-probe-only property
@ 2015-09-03 12:16   ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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..412531f 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(of_chosen);
 }
 
 static void __init pSeries_setup_arch(void)
-- 
2.1.4

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

* [PATCH v3 3/4] powerpc: PCI: Fix lookup of linux, pci-probe-only property
@ 2015-09-03 12:16   ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 UTC (permalink / raw)
  To: linux-arm-kernel

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..412531f 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(of_chosen);
 }
 
 static void __init pSeries_setup_arch(void)
-- 
2.1.4

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

* [PATCH v3 4/4] arm64: dts: Drop linux,pci-probe-only from the Seattle DTS
  2015-09-03 12:16 ` [PATCH v3 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
  (?)
  (?)
@ 2015-09-03 12:16   ` Marc Zyngier
  -1 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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.

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] 25+ messages in thread

* [PATCH v3 4/4] arm64: dts: Drop linux, pci-probe-only from the Seattle DTS
@ 2015-09-03 12:16   ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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

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.

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] 25+ messages in thread

* [PATCH v3 4/4] arm64: dts: Drop linux, pci-probe-only from the Seattle DTS
@ 2015-09-03 12:16   ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 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.

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] 25+ messages in thread

* [PATCH v3 4/4] arm64: dts: Drop linux, pci-probe-only from the Seattle DTS
@ 2015-09-03 12:16   ` Marc Zyngier
  0 siblings, 0 replies; 25+ messages in thread
From: Marc Zyngier @ 2015-09-03 12:16 UTC (permalink / raw)
  To: linux-arm-kernel

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.

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] 25+ messages in thread

* Re: [PATCH v3 1/4] of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only"
  2015-09-03 12:16   ` Marc Zyngier
  (?)
  (?)
@ 2015-09-03 14:01     ` Rob Herring
  -1 siblings, 0 replies; 25+ messages in thread
From: Rob Herring @ 2015-09-03 14:01 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, linux-arm-kernel, linuxppc-dev, linux-pci,
	devicetree

On Thu, Sep 3, 2015 at 7:16 AM, Marc Zyngier <marc.zyngier@arm.com> 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.

Sorry, but a couple of other minor things I noticed.

>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
>  drivers/of/of_pci.c    | 31 +++++++++++++++++++++++++++++++
>  include/linux/of_pci.h |  3 +++
>  2 files changed, 34 insertions(+)
>
> diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
> index 5751dc5..7876343 100644
> --- a/drivers/of/of_pci.c
> +++ b/drivers/of/of_pci.c
> @@ -118,6 +118,37 @@ 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(struct device_node *node)

This property is only valid in /chosen, so there's no point passing
of_chosen in and you can constrain it to only look in /chosen.

> +{
> +       u32 val;
> +       int ret;
> +
> +       if (!node)
> +               return;

I believe of_property_read_u32 will check this.

> +
> +       ret = of_property_read_u32(node, "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..4c0a617 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(struct device_node *node);
>  #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(struct device_node *node) { }
>  #endif
>
>  #if defined(CONFIG_OF_ADDRESS)
> --
> 2.1.4
>

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

* Re: [PATCH v3 1/4] of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only"
@ 2015-09-03 14:01     ` Rob Herring
  0 siblings, 0 replies; 25+ messages in thread
From: Rob Herring @ 2015-09-03 14:01 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, linux-arm-kernel, linuxppc-dev, linux-pci,
	devicetree

On Thu, Sep 3, 2015 at 7:16 AM, Marc Zyngier <marc.zyngier@arm.com> 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.

Sorry, but a couple of other minor things I noticed.

>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
>  drivers/of/of_pci.c    | 31 +++++++++++++++++++++++++++++++
>  include/linux/of_pci.h |  3 +++
>  2 files changed, 34 insertions(+)
>
> diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
> index 5751dc5..7876343 100644
> --- a/drivers/of/of_pci.c
> +++ b/drivers/of/of_pci.c
> @@ -118,6 +118,37 @@ 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(struct device_node *node)

This property is only valid in /chosen, so there's no point passing
of_chosen in and you can constrain it to only look in /chosen.

> +{
> +       u32 val;
> +       int ret;
> +
> +       if (!node)
> +               return;

I believe of_property_read_u32 will check this.

> +
> +       ret = of_property_read_u32(node, "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..4c0a617 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(struct device_node *node);
>  #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(struct device_node *node) { }
>  #endif
>
>  #if defined(CONFIG_OF_ADDRESS)
> --
> 2.1.4
>

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

* Re: [PATCH v3 1/4] of/pci: Add of_pci_check_probe_only to parse "linux, pci-probe-only"
@ 2015-09-03 14:01     ` Rob Herring
  0 siblings, 0 replies; 25+ messages in thread
From: Rob Herring @ 2015-09-03 14:01 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, linux-arm-kernel, linuxppc-dev, linux-pci,
	devicetree

On Thu, Sep 3, 2015 at 7:16 AM, Marc Zyngier <marc.zyngier@arm.com> 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.

Sorry, but a couple of other minor things I noticed.

>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
>  drivers/of/of_pci.c    | 31 +++++++++++++++++++++++++++++++
>  include/linux/of_pci.h |  3 +++
>  2 files changed, 34 insertions(+)
>
> diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
> index 5751dc5..7876343 100644
> --- a/drivers/of/of_pci.c
> +++ b/drivers/of/of_pci.c
> @@ -118,6 +118,37 @@ 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(struct device_node *node)

This property is only valid in /chosen, so there's no point passing
of_chosen in and you can constrain it to only look in /chosen.

> +{
> +       u32 val;
> +       int ret;
> +
> +       if (!node)
> +               return;

I believe of_property_read_u32 will check this.

> +
> +       ret = of_property_read_u32(node, "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..4c0a617 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(struct device_node *node);
>  #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(struct device_node *node) { }
>  #endif
>
>  #if defined(CONFIG_OF_ADDRESS)
> --
> 2.1.4
>

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

* [PATCH v3 1/4] of/pci: Add of_pci_check_probe_only to parse "linux, pci-probe-only"
@ 2015-09-03 14:01     ` Rob Herring
  0 siblings, 0 replies; 25+ messages in thread
From: Rob Herring @ 2015-09-03 14:01 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Sep 3, 2015 at 7:16 AM, Marc Zyngier <marc.zyngier@arm.com> 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.

Sorry, but a couple of other minor things I noticed.

>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
>  drivers/of/of_pci.c    | 31 +++++++++++++++++++++++++++++++
>  include/linux/of_pci.h |  3 +++
>  2 files changed, 34 insertions(+)
>
> diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
> index 5751dc5..7876343 100644
> --- a/drivers/of/of_pci.c
> +++ b/drivers/of/of_pci.c
> @@ -118,6 +118,37 @@ 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(struct device_node *node)

This property is only valid in /chosen, so there's no point passing
of_chosen in and you can constrain it to only look in /chosen.

> +{
> +       u32 val;
> +       int ret;
> +
> +       if (!node)
> +               return;

I believe of_property_read_u32 will check this.

> +
> +       ret = of_property_read_u32(node, "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..4c0a617 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(struct device_node *node);
>  #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(struct device_node *node) { }
>  #endif
>
>  #if defined(CONFIG_OF_ADDRESS)
> --
> 2.1.4
>

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

* Re: [PATCH v3 4/4] arm64: dts: Drop linux,pci-probe-only from the Seattle DTS
  2015-09-03 12:16   ` Marc Zyngier
  (?)
@ 2015-09-03 14:19     ` Suthikulpanit, Suravee
  -1 siblings, 0 replies; 25+ messages in thread
From: Suthikulpanit, Suravee @ 2015-09-03 14:19 UTC (permalink / raw)
  To: Marc Zyngier, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman, Will Deacon, Bjorn Helgaas, Lorenzo Pieralisi,
	Grant Likely, Rob Herring
  Cc: Alexander Graf, linux-kernel, linux-arm-kernel, linuxppc-dev,
	linux-pci, devicetree

Hi Marc

On 9/3/2015 7:16 PM, Marc Zyngier wrote:
> 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.
>
> 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;
>   	};
>   };
>
>

Thanks, I was planning to do this as well. The embedded DT in the UEFI 
FW will soon remove this property.

Acked-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>

Suravee

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

* Re: [PATCH v3 4/4] arm64: dts: Drop linux,pci-probe-only from the Seattle DTS
@ 2015-09-03 14:19     ` Suthikulpanit, Suravee
  0 siblings, 0 replies; 25+ messages in thread
From: Suthikulpanit, Suravee @ 2015-09-03 14:19 UTC (permalink / raw)
  To: Marc Zyngier, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman, Will Deacon, Bjorn Helgaas, Lorenzo Pieralisi,
	Grant Likely, Rob Herring
  Cc: Alexander Graf, linux-kernel, linux-arm-kernel, linuxppc-dev,
	linux-pci, devicetree

Hi Marc

On 9/3/2015 7:16 PM, Marc Zyngier wrote:
> 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.
>
> 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;
>   	};
>   };
>
>

Thanks, I was planning to do this as well. The embedded DT in the UEFI 
FW will soon remove this property.

Acked-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>

Suravee

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

* [PATCH v3 4/4] arm64: dts: Drop linux,pci-probe-only from the Seattle DTS
@ 2015-09-03 14:19     ` Suthikulpanit, Suravee
  0 siblings, 0 replies; 25+ messages in thread
From: Suthikulpanit, Suravee @ 2015-09-03 14:19 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Marc

On 9/3/2015 7:16 PM, Marc Zyngier wrote:
> 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.
>
> 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;
>   	};
>   };
>
>

Thanks, I was planning to do this as well. The embedded DT in the UEFI 
FW will soon remove this property.

Acked-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>

Suravee

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

end of thread, other threads:[~2015-09-03 14:20 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-03 12:16 [PATCH v3 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
2015-09-03 12:16 ` [PATCH v3 0/4] PCI: arm64/powerpc: Fix parsing of linux, pci-probe-only Marc Zyngier
2015-09-03 12:16 ` Marc Zyngier
2015-09-03 12:16 ` [PATCH v3 0/4] PCI: arm64/powerpc: Fix parsing of linux,pci-probe-only Marc Zyngier
2015-09-03 12:16 ` [PATCH v3 1/4] of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only" Marc Zyngier
2015-09-03 12:16   ` [PATCH v3 1/4] of/pci: Add of_pci_check_probe_only to parse "linux, pci-probe-only" Marc Zyngier
2015-09-03 12:16   ` Marc Zyngier
2015-09-03 14:01   ` [PATCH v3 1/4] of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only" Rob Herring
2015-09-03 14:01     ` [PATCH v3 1/4] of/pci: Add of_pci_check_probe_only to parse "linux, pci-probe-only" Rob Herring
2015-09-03 14:01     ` Rob Herring
2015-09-03 14:01     ` [PATCH v3 1/4] of/pci: Add of_pci_check_probe_only to parse "linux,pci-probe-only" Rob Herring
2015-09-03 12:16 ` [PATCH v3 2/4] PCI: pci-host-generic: Fix lookup of linux,pci-probe-only property Marc Zyngier
2015-09-03 12:16   ` [PATCH v3 2/4] PCI: pci-host-generic: Fix lookup of linux, pci-probe-only property Marc Zyngier
2015-09-03 12:16   ` Marc Zyngier
2015-09-03 12:16   ` Marc Zyngier
2015-09-03 12:16 ` [PATCH v3 3/4] powerpc: PCI: Fix lookup of linux,pci-probe-only property Marc Zyngier
2015-09-03 12:16   ` [PATCH v3 3/4] powerpc: PCI: Fix lookup of linux, pci-probe-only property Marc Zyngier
2015-09-03 12:16   ` Marc Zyngier
2015-09-03 12:16 ` [PATCH v3 4/4] arm64: dts: Drop linux,pci-probe-only from the Seattle DTS Marc Zyngier
2015-09-03 12:16   ` [PATCH v3 4/4] arm64: dts: Drop linux, pci-probe-only " Marc Zyngier
2015-09-03 12:16   ` Marc Zyngier
2015-09-03 12:16   ` Marc Zyngier
2015-09-03 14:19   ` [PATCH v3 4/4] arm64: dts: Drop linux,pci-probe-only " Suthikulpanit, Suravee
2015-09-03 14:19     ` Suthikulpanit, Suravee
2015-09-03 14:19     ` Suthikulpanit, Suravee

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.