All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] driver core: add new dl device status DL_DEV_PROBE_FAILED
@ 2018-03-29 10:00 ` Wang Dongsheng
  0 siblings, 0 replies; 10+ messages in thread
From: Wang Dongsheng @ 2018-03-29 10:00 UTC (permalink / raw)
  To: rjw, lorenzo.pieralisi
  Cc: gregkh, hanjun.guo, sudeep.holla, yu.zheng, linux-acpi,
	linux-kernel, Wang Dongsheng

Recently we found the master of SMMU retries to probe endlessly.

[    3.658956] pci 0000:00:00.0: Retrying from deferred list
[    3.658969] pci 0000:00:00.0: Added to deferred list
[    3.658987] pci 0004:00:00.0: Retrying from deferred list
[    3.658994] pci 0004:00:00.0: Added to deferred list
[    3.659003] pci 0005:00:00.0: Retrying from deferred list
[    3.659010] pci 0005:00:00.0: Added to deferred list
[    3.659019] pci 0004:01:00.0: Retrying from deferred list
[    3.659029] pci 0004:01:00.0: Added to deferred list

The retrying should only happen when the IOMMU instance hasn't been
probed yet.
However, dma_configure() simply return -EPROBE_DEFER when failed to get
an IOMMU instance even if the IOMMU instance is failed to probe.

This patchset tries to fix the issue by distinguishing probe failures and
haven't-been-probed-yet state.

Wang Dongsheng (2):
  driver core: add new dl device status DL_DEV_PROBE_FAILED
  ACPI/IORT: use swiotlb_dma_ops when smmu probe failed

 Documentation/driver-api/device_link.rst |  2 +-
 drivers/acpi/arm64/iort.c                | 39 +++++++++++++++++++++++++++-----
 drivers/base/base.h                      |  2 +-
 drivers/base/core.c                      | 22 ++++++++++++++++--
 drivers/base/dd.c                        |  2 +-
 include/linux/device.h                   |  1 +
 6 files changed, 57 insertions(+), 11 deletions(-)

-- 
2.7.4

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

* [RFC PATCH 0/2] driver core: add new dl device status DL_DEV_PROBE_FAILED
@ 2018-03-29 10:00 ` Wang Dongsheng
  0 siblings, 0 replies; 10+ messages in thread
From: Wang Dongsheng @ 2018-03-29 10:00 UTC (permalink / raw)
  To: rjw, lorenzo.pieralisi
  Cc: gregkh, hanjun.guo, sudeep.holla, yu.zheng, linux-acpi,
	linux-kernel, Wang Dongsheng

Recently we found the master of SMMU retries to probe endlessly.

[    3.658956] pci 0000:00:00.0: Retrying from deferred list
[    3.658969] pci 0000:00:00.0: Added to deferred list
[    3.658987] pci 0004:00:00.0: Retrying from deferred list
[    3.658994] pci 0004:00:00.0: Added to deferred list
[    3.659003] pci 0005:00:00.0: Retrying from deferred list
[    3.659010] pci 0005:00:00.0: Added to deferred list
[    3.659019] pci 0004:01:00.0: Retrying from deferred list
[    3.659029] pci 0004:01:00.0: Added to deferred list

The retrying should only happen when the IOMMU instance hasn't been
probed yet.
However, dma_configure() simply return -EPROBE_DEFER when failed to get
an IOMMU instance even if the IOMMU instance is failed to probe.

This patchset tries to fix the issue by distinguishing probe failures and
haven't-been-probed-yet state.

Wang Dongsheng (2):
  driver core: add new dl device status DL_DEV_PROBE_FAILED
  ACPI/IORT: use swiotlb_dma_ops when smmu probe failed

 Documentation/driver-api/device_link.rst |  2 +-
 drivers/acpi/arm64/iort.c                | 39 +++++++++++++++++++++++++++-----
 drivers/base/base.h                      |  2 +-
 drivers/base/core.c                      | 22 ++++++++++++++++--
 drivers/base/dd.c                        |  2 +-
 include/linux/device.h                   |  1 +
 6 files changed, 57 insertions(+), 11 deletions(-)

-- 
2.7.4

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

* [RFC PATCH 1/2] driver core: add new dl device status DL_DEV_PROBE_FAILED
  2018-03-29 10:00 ` Wang Dongsheng
@ 2018-03-29 10:00   ` Wang Dongsheng
  -1 siblings, 0 replies; 10+ messages in thread
From: Wang Dongsheng @ 2018-03-29 10:00 UTC (permalink / raw)
  To: rjw, lorenzo.pieralisi
  Cc: gregkh, hanjun.guo, sudeep.holla, yu.zheng, linux-acpi,
	linux-kernel, Wang Dongsheng

Currently the initialization state of device is DL_DEV_NO_DRIVER.
The problem is, after probe failure the state will also be set to
DL_DEV_NO_DRIVER as well. And the device is not linked, it has no
supplier or consumer. Thus adding a new state to distinguish
probe failure and not-probed-yet.

Signed-off-by: Wang Dongsheng <dongsheng.wang@hxt-semitech.com>
---
 Documentation/driver-api/device_link.rst |  2 +-
 drivers/base/base.h                      |  2 +-
 drivers/base/core.c                      | 22 ++++++++++++++++++++--
 drivers/base/dd.c                        |  2 +-
 include/linux/device.h                   |  1 +
 5 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/Documentation/driver-api/device_link.rst b/Documentation/driver-api/device_link.rst
index 70e328e..9054403 100644
--- a/Documentation/driver-api/device_link.rst
+++ b/Documentation/driver-api/device_link.rst
@@ -247,7 +247,7 @@ State machine
   :c:func:`device_links_unbind_consumers()`.)
 
 * If the probe fails, links to suppliers revert back to ``DL_STATE_AVAILABLE``.
-  (Call to :c:func:`device_links_no_driver()` from :c:func:`really_probe()`.)
+  (Call to :c:func:`device_links_probe_failed()` from :c:func:`really_probe()`.)
 
 * If the probe succeeds, links to suppliers progress to ``DL_STATE_ACTIVE``.
   (Call to :c:func:`device_links_driver_bound()` from :c:func:`driver_bound()`.)
diff --git a/drivers/base/base.h b/drivers/base/base.h
index d800de6..f9931d9 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -158,6 +158,6 @@ extern void device_links_read_unlock(int idx);
 extern int device_links_check_suppliers(struct device *dev);
 extern void device_links_driver_bound(struct device *dev);
 extern void device_links_driver_cleanup(struct device *dev);
-extern void device_links_no_driver(struct device *dev);
+extern void device_links_probe_failed(struct device *dev);
 extern bool device_links_busy(struct device *dev);
 extern void device_links_unbind_consumers(struct device *dev);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 5847364..31d4f68 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -452,10 +452,28 @@ static void __device_links_no_driver(struct device *dev)
 	dev->links.status = DL_DEV_NO_DRIVER;
 }
 
-void device_links_no_driver(struct device *dev)
+static void __device_links_probe_failed(struct device *dev)
+{
+	struct device_link *link, *ln;
+
+	list_for_each_entry_safe_reverse(link, ln, &dev->links.suppliers,
+					 c_node) {
+		if (link->flags & DL_FLAG_STATELESS)
+			continue;
+
+		if (link->flags & DL_FLAG_AUTOREMOVE)
+			__device_link_del(link);
+		else if (link->status != DL_STATE_SUPPLIER_UNBIND)
+			WRITE_ONCE(link->status, DL_STATE_AVAILABLE);
+	}
+
+	dev->links.status = DL_DEV_PROBE_FAILED;
+}
+
+void device_links_probe_failed(struct device *dev)
 {
 	device_links_write_lock();
-	__device_links_no_driver(dev);
+	__device_links_probe_failed(dev);
 	device_links_write_unlock();
 }
 
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index de6fd09..90d57e0 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -492,7 +492,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 		blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
 					     BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
 pinctrl_bind_failed:
-	device_links_no_driver(dev);
+	device_links_probe_failed(dev);
 	devres_release_all(dev);
 	driver_sysfs_remove(dev);
 	dev->driver = NULL;
diff --git a/include/linux/device.h b/include/linux/device.h
index b093405..bf9630a 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -794,6 +794,7 @@ struct device_link {
 enum dl_dev_state {
 	DL_DEV_NO_DRIVER = 0,
 	DL_DEV_PROBING,
+	DL_DEV_PROBE_FAILED,
 	DL_DEV_DRIVER_BOUND,
 	DL_DEV_UNBINDING,
 };
-- 
2.7.4

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

* [RFC PATCH 1/2] driver core: add new dl device status DL_DEV_PROBE_FAILED
@ 2018-03-29 10:00   ` Wang Dongsheng
  0 siblings, 0 replies; 10+ messages in thread
From: Wang Dongsheng @ 2018-03-29 10:00 UTC (permalink / raw)
  To: rjw, lorenzo.pieralisi
  Cc: gregkh, hanjun.guo, sudeep.holla, yu.zheng, linux-acpi,
	linux-kernel, Wang Dongsheng

Currently the initialization state of device is DL_DEV_NO_DRIVER.
The problem is, after probe failure the state will also be set to
DL_DEV_NO_DRIVER as well. And the device is not linked, it has no
supplier or consumer. Thus adding a new state to distinguish
probe failure and not-probed-yet.

Signed-off-by: Wang Dongsheng <dongsheng.wang@hxt-semitech.com>
---
 Documentation/driver-api/device_link.rst |  2 +-
 drivers/base/base.h                      |  2 +-
 drivers/base/core.c                      | 22 ++++++++++++++++++++--
 drivers/base/dd.c                        |  2 +-
 include/linux/device.h                   |  1 +
 5 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/Documentation/driver-api/device_link.rst b/Documentation/driver-api/device_link.rst
index 70e328e..9054403 100644
--- a/Documentation/driver-api/device_link.rst
+++ b/Documentation/driver-api/device_link.rst
@@ -247,7 +247,7 @@ State machine
   :c:func:`device_links_unbind_consumers()`.)
 
 * If the probe fails, links to suppliers revert back to ``DL_STATE_AVAILABLE``.
-  (Call to :c:func:`device_links_no_driver()` from :c:func:`really_probe()`.)
+  (Call to :c:func:`device_links_probe_failed()` from :c:func:`really_probe()`.)
 
 * If the probe succeeds, links to suppliers progress to ``DL_STATE_ACTIVE``.
   (Call to :c:func:`device_links_driver_bound()` from :c:func:`driver_bound()`.)
diff --git a/drivers/base/base.h b/drivers/base/base.h
index d800de6..f9931d9 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -158,6 +158,6 @@ extern void device_links_read_unlock(int idx);
 extern int device_links_check_suppliers(struct device *dev);
 extern void device_links_driver_bound(struct device *dev);
 extern void device_links_driver_cleanup(struct device *dev);
-extern void device_links_no_driver(struct device *dev);
+extern void device_links_probe_failed(struct device *dev);
 extern bool device_links_busy(struct device *dev);
 extern void device_links_unbind_consumers(struct device *dev);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 5847364..31d4f68 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -452,10 +452,28 @@ static void __device_links_no_driver(struct device *dev)
 	dev->links.status = DL_DEV_NO_DRIVER;
 }
 
-void device_links_no_driver(struct device *dev)
+static void __device_links_probe_failed(struct device *dev)
+{
+	struct device_link *link, *ln;
+
+	list_for_each_entry_safe_reverse(link, ln, &dev->links.suppliers,
+					 c_node) {
+		if (link->flags & DL_FLAG_STATELESS)
+			continue;
+
+		if (link->flags & DL_FLAG_AUTOREMOVE)
+			__device_link_del(link);
+		else if (link->status != DL_STATE_SUPPLIER_UNBIND)
+			WRITE_ONCE(link->status, DL_STATE_AVAILABLE);
+	}
+
+	dev->links.status = DL_DEV_PROBE_FAILED;
+}
+
+void device_links_probe_failed(struct device *dev)
 {
 	device_links_write_lock();
-	__device_links_no_driver(dev);
+	__device_links_probe_failed(dev);
 	device_links_write_unlock();
 }
 
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index de6fd09..90d57e0 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -492,7 +492,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 		blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
 					     BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
 pinctrl_bind_failed:
-	device_links_no_driver(dev);
+	device_links_probe_failed(dev);
 	devres_release_all(dev);
 	driver_sysfs_remove(dev);
 	dev->driver = NULL;
diff --git a/include/linux/device.h b/include/linux/device.h
index b093405..bf9630a 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -794,6 +794,7 @@ struct device_link {
 enum dl_dev_state {
 	DL_DEV_NO_DRIVER = 0,
 	DL_DEV_PROBING,
+	DL_DEV_PROBE_FAILED,
 	DL_DEV_DRIVER_BOUND,
 	DL_DEV_UNBINDING,
 };
-- 
2.7.4

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

* [RFC PATCH 2/2] ACPI/IORT: use swiotlb_dma_ops when smmu probe failed
  2018-03-29 10:00 ` Wang Dongsheng
@ 2018-03-29 10:01   ` Wang Dongsheng
  -1 siblings, 0 replies; 10+ messages in thread
From: Wang Dongsheng @ 2018-03-29 10:01 UTC (permalink / raw)
  To: rjw, lorenzo.pieralisi
  Cc: gregkh, hanjun.guo, sudeep.holla, yu.zheng, linux-acpi,
	linux-kernel, Wang Dongsheng

If SMMU probe failed, master should use swiotlb as dma ops.
SMMU may probe failed with specified environment, so there
are not any iommu resources in iommu_device_list.

The master will always get EPROBE_DEFER from really_probe
(dma_configure) but in fact SMMU has probe failed. The issue
causes all of masters failed to be driven.

Signed-off-by: Wang Dongsheng <dongsheng.wang@hxt-semitech.com>
---
 drivers/acpi/arm64/iort.c | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index e2f7bdd..a6f4c27 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -774,17 +774,45 @@ static int arm_smmu_iort_xlate(struct device *dev, u32 streamid,
 	return ret;
 }
 
-static inline bool iort_iommu_driver_enabled(u8 type)
+static int iort_check_dev_dl_status(struct device *dev, void *data)
 {
+	struct fwnode_handle *fwnode = data;
+
+	if (dev->fwnode != fwnode)
+		return 0;
+
+	if (dev->links.status == DL_DEV_PROBE_FAILED)
+		return -ENODEV;
+
+	return -EPROBE_DEFER;
+}
+
+static int iort_iommu_driver_enabled(u8 type, struct fwnode_handle *fwnode)
+{
+	bool buildin;
+	int ret;
+
 	switch (type) {
 	case ACPI_IORT_NODE_SMMU_V3:
-		return IS_BUILTIN(CONFIG_ARM_SMMU_V3);
+		buildin = IS_BUILTIN(CONFIG_ARM_SMMU_V3);
+		break;
 	case ACPI_IORT_NODE_SMMU:
-		return IS_BUILTIN(CONFIG_ARM_SMMU);
+		buildin = IS_BUILTIN(CONFIG_ARM_SMMU);
+		break;
 	default:
 		pr_warn("IORT node type %u does not describe an SMMU\n", type);
-		return false;
+		buildin = false;
 	}
+
+	if (!buildin)
+		return -ENODEV;
+
+	ret = bus_for_each_dev(&platform_bus_type, NULL, fwnode,
+			       iort_check_dev_dl_status);
+	if (!ret)
+		return -EPROBE_DEFER;
+
+	return ret;
 }
 
 #ifdef CONFIG_IOMMU_API
@@ -919,8 +947,7 @@ static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node,
 	 */
 	ops = iommu_ops_from_fwnode(iort_fwnode);
 	if (!ops)
-		return iort_iommu_driver_enabled(node->type) ?
-		       -EPROBE_DEFER : -ENODEV;
+		return iort_iommu_driver_enabled(node->type, iort_fwnode);
 
 	return arm_smmu_iort_xlate(dev, streamid, iort_fwnode, ops);
 }
-- 
2.7.4

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

* [RFC PATCH 2/2] ACPI/IORT: use swiotlb_dma_ops when smmu probe failed
@ 2018-03-29 10:01   ` Wang Dongsheng
  0 siblings, 0 replies; 10+ messages in thread
From: Wang Dongsheng @ 2018-03-29 10:01 UTC (permalink / raw)
  To: rjw, lorenzo.pieralisi
  Cc: gregkh, hanjun.guo, sudeep.holla, yu.zheng, linux-acpi,
	linux-kernel, Wang Dongsheng

If SMMU probe failed, master should use swiotlb as dma ops.
SMMU may probe failed with specified environment, so there
are not any iommu resources in iommu_device_list.

The master will always get EPROBE_DEFER from really_probe
(dma_configure) but in fact SMMU has probe failed. The issue
causes all of masters failed to be driven.

Signed-off-by: Wang Dongsheng <dongsheng.wang@hxt-semitech.com>
---
 drivers/acpi/arm64/iort.c | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index e2f7bdd..a6f4c27 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -774,17 +774,45 @@ static int arm_smmu_iort_xlate(struct device *dev, u32 streamid,
 	return ret;
 }
 
-static inline bool iort_iommu_driver_enabled(u8 type)
+static int iort_check_dev_dl_status(struct device *dev, void *data)
 {
+	struct fwnode_handle *fwnode = data;
+
+	if (dev->fwnode != fwnode)
+		return 0;
+
+	if (dev->links.status == DL_DEV_PROBE_FAILED)
+		return -ENODEV;
+
+	return -EPROBE_DEFER;
+}
+
+static int iort_iommu_driver_enabled(u8 type, struct fwnode_handle *fwnode)
+{
+	bool buildin;
+	int ret;
+
 	switch (type) {
 	case ACPI_IORT_NODE_SMMU_V3:
-		return IS_BUILTIN(CONFIG_ARM_SMMU_V3);
+		buildin = IS_BUILTIN(CONFIG_ARM_SMMU_V3);
+		break;
 	case ACPI_IORT_NODE_SMMU:
-		return IS_BUILTIN(CONFIG_ARM_SMMU);
+		buildin = IS_BUILTIN(CONFIG_ARM_SMMU);
+		break;
 	default:
 		pr_warn("IORT node type %u does not describe an SMMU\n", type);
-		return false;
+		buildin = false;
 	}
+
+	if (!buildin)
+		return -ENODEV;
+
+	ret = bus_for_each_dev(&platform_bus_type, NULL, fwnode,
+			       iort_check_dev_dl_status);
+	if (!ret)
+		return -EPROBE_DEFER;
+
+	return ret;
 }
 
 #ifdef CONFIG_IOMMU_API
@@ -919,8 +947,7 @@ static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node,
 	 */
 	ops = iommu_ops_from_fwnode(iort_fwnode);
 	if (!ops)
-		return iort_iommu_driver_enabled(node->type) ?
-		       -EPROBE_DEFER : -ENODEV;
+		return iort_iommu_driver_enabled(node->type, iort_fwnode);
 
 	return arm_smmu_iort_xlate(dev, streamid, iort_fwnode, ops);
 }
-- 
2.7.4

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

* Re: [RFC PATCH 1/2] driver core: add new dl device status DL_DEV_PROBE_FAILED
  2018-03-29 10:00   ` Wang Dongsheng
  (?)
@ 2018-03-29 10:51   ` Rafael J. Wysocki
  2018-03-29 11:24     ` Wang, Dongsheng
  -1 siblings, 1 reply; 10+ messages in thread
From: Rafael J. Wysocki @ 2018-03-29 10:51 UTC (permalink / raw)
  To: Wang Dongsheng
  Cc: Rafael J. Wysocki, Lorenzo Pieralisi, Greg Kroah-Hartman,
	Hanjun Guo, Sudeep Holla, yu.zheng, ACPI Devel Maling List,
	Linux Kernel Mailing List

On Thu, Mar 29, 2018 at 12:00 PM, Wang Dongsheng
<dongsheng.wang@hxt-semitech.com> wrote:
> Currently the initialization state of device is DL_DEV_NO_DRIVER.
> The problem is, after probe failure the state will also be set to
> DL_DEV_NO_DRIVER as well. And the device is not linked, it has no
> supplier or consumer. Thus adding a new state to distinguish
> probe failure and not-probed-yet.
>
> Signed-off-by: Wang Dongsheng <dongsheng.wang@hxt-semitech.com>

I guess what you want is a cleanup after a failing probe, but after
that the state really is "no driver" again, isn't it?

> ---
>  Documentation/driver-api/device_link.rst |  2 +-
>  drivers/base/base.h                      |  2 +-
>  drivers/base/core.c                      | 22 ++++++++++++++++++++--
>  drivers/base/dd.c                        |  2 +-
>  include/linux/device.h                   |  1 +
>  5 files changed, 24 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/driver-api/device_link.rst b/Documentation/driver-api/device_link.rst
> index 70e328e..9054403 100644
> --- a/Documentation/driver-api/device_link.rst
> +++ b/Documentation/driver-api/device_link.rst
> @@ -247,7 +247,7 @@ State machine
>    :c:func:`device_links_unbind_consumers()`.)
>
>  * If the probe fails, links to suppliers revert back to ``DL_STATE_AVAILABLE``.
> -  (Call to :c:func:`device_links_no_driver()` from :c:func:`really_probe()`.)
> +  (Call to :c:func:`device_links_probe_failed()` from :c:func:`really_probe()`.)
>
>  * If the probe succeeds, links to suppliers progress to ``DL_STATE_ACTIVE``.
>    (Call to :c:func:`device_links_driver_bound()` from :c:func:`driver_bound()`.)
> diff --git a/drivers/base/base.h b/drivers/base/base.h
> index d800de6..f9931d9 100644
> --- a/drivers/base/base.h
> +++ b/drivers/base/base.h
> @@ -158,6 +158,6 @@ extern void device_links_read_unlock(int idx);
>  extern int device_links_check_suppliers(struct device *dev);
>  extern void device_links_driver_bound(struct device *dev);
>  extern void device_links_driver_cleanup(struct device *dev);
> -extern void device_links_no_driver(struct device *dev);
> +extern void device_links_probe_failed(struct device *dev);
>  extern bool device_links_busy(struct device *dev);
>  extern void device_links_unbind_consumers(struct device *dev);
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 5847364..31d4f68 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -452,10 +452,28 @@ static void __device_links_no_driver(struct device *dev)
>         dev->links.status = DL_DEV_NO_DRIVER;
>  }
>
> -void device_links_no_driver(struct device *dev)
> +static void __device_links_probe_failed(struct device *dev)
> +{
> +       struct device_link *link, *ln;
> +
> +       list_for_each_entry_safe_reverse(link, ln, &dev->links.suppliers,
> +                                        c_node) {
> +               if (link->flags & DL_FLAG_STATELESS)
> +                       continue;
> +
> +               if (link->flags & DL_FLAG_AUTOREMOVE)
> +                       __device_link_del(link);
> +               else if (link->status != DL_STATE_SUPPLIER_UNBIND)
> +                       WRITE_ONCE(link->status, DL_STATE_AVAILABLE);
> +       }
> +
> +       dev->links.status = DL_DEV_PROBE_FAILED;
> +}
> +
> +void device_links_probe_failed(struct device *dev)
>  {
>         device_links_write_lock();
> -       __device_links_no_driver(dev);
> +       __device_links_probe_failed(dev);
>         device_links_write_unlock();
>  }
>
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index de6fd09..90d57e0 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -492,7 +492,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
>                 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
>                                              BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
>  pinctrl_bind_failed:
> -       device_links_no_driver(dev);
> +       device_links_probe_failed(dev);
>         devres_release_all(dev);
>         driver_sysfs_remove(dev);
>         dev->driver = NULL;
> diff --git a/include/linux/device.h b/include/linux/device.h
> index b093405..bf9630a 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -794,6 +794,7 @@ struct device_link {
>  enum dl_dev_state {
>         DL_DEV_NO_DRIVER = 0,
>         DL_DEV_PROBING,
> +       DL_DEV_PROBE_FAILED,
>         DL_DEV_DRIVER_BOUND,
>         DL_DEV_UNBINDING,
>  };
> --
> 2.7.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [RFC PATCH 1/2] driver core: add new dl device status DL_DEV_PROBE_FAILED
  2018-03-29 10:51   ` Rafael J. Wysocki
@ 2018-03-29 11:24     ` Wang, Dongsheng
  0 siblings, 0 replies; 10+ messages in thread
From: Wang, Dongsheng @ 2018-03-29 11:24 UTC (permalink / raw)
  To: rafael
  Cc: linux-kernel, lorenzo.pieralisi, Zheng, Joey, rjw, sudeep.holla,
	gregkh, linux-acpi, hanjun.guo

On Thu, 2018-03-29 at 12:51 +0200, Rafael J. Wysocki wrote:
> On Thu, Mar 29, 2018 at 12:00 PM, Wang Dongsheng
> <dongsheng.wang@hxt-semitech.com> wrote:
> > Currently the initialization state of device is DL_DEV_NO_DRIVER.
> > The problem is, after probe failure the state will also be set to
> > DL_DEV_NO_DRIVER as well. And the device is not linked, it has no
> > supplier or consumer. Thus adding a new state to distinguish
> > probe failure and not-probed-yet.
> > 
> > Signed-off-by: Wang Dongsheng <dongsheng.wang@hxt-semitech.com>
> 
> I guess what you want is a cleanup after a failing probe, but after
> that the state really is "no driver" again, isn't it?
Yes, agree "no driver", device is never get a driver again.

But A depend on B successful probe. if B failed, A will never know:
1. B can't work.
2. B hasn't got a probe yet.

Like IOMMU. After SMMU successful probed, the driver add a resource
into "iommu_device_list". Master lookup the corresponding SMMU fwnode
from "iommu_device_list", after matched master will do probe. but if
the list is NULL master will get -EPROBE_DEFER, means SMMU device may
not probe yet, in fact SMMU may probe failed.

I try to use DL_DEV state to fix this issue, but NO_DRIVER does not
distinguish between the two cases.

Cheers,
-Dongsheng

> 
> > ---
> >  Documentation/driver-api/device_link.rst |  2 +-
> >  drivers/base/base.h                      |  2 +-
> >  drivers/base/core.c                      | 22
> > ++++++++++++++++++++--
> >  drivers/base/dd.c                        |  2 +-
> >  include/linux/device.h                   |  1 +
> >  5 files changed, 24 insertions(+), 5 deletions(-)
> > 
> > diff --git a/Documentation/driver-api/device_link.rst
> > b/Documentation/driver-api/device_link.rst
> > index 70e328e..9054403 100644
> > --- a/Documentation/driver-api/device_link.rst
> > +++ b/Documentation/driver-api/device_link.rst
> > @@ -247,7 +247,7 @@ State machine
> >    :c:func:`device_links_unbind_consumers()`.)
> > 
> >  * If the probe fails, links to suppliers revert back to
> > ``DL_STATE_AVAILABLE``.
> > -  (Call to :c:func:`device_links_no_driver()` from
> > :c:func:`really_probe()`.)
> > +  (Call to :c:func:`device_links_probe_failed()` from
> > :c:func:`really_probe()`.)
> > 
> >  * If the probe succeeds, links to suppliers progress to
> > ``DL_STATE_ACTIVE``.
> >    (Call to :c:func:`device_links_driver_bound()` from
> > :c:func:`driver_bound()`.)
> > diff --git a/drivers/base/base.h b/drivers/base/base.h
> > index d800de6..f9931d9 100644
> > --- a/drivers/base/base.h
> > +++ b/drivers/base/base.h
> > @@ -158,6 +158,6 @@ extern void device_links_read_unlock(int idx);
> >  extern int device_links_check_suppliers(struct device *dev);
> >  extern void device_links_driver_bound(struct device *dev);
> >  extern void device_links_driver_cleanup(struct device *dev);
> > -extern void device_links_no_driver(struct device *dev);
> > +extern void device_links_probe_failed(struct device *dev);
> >  extern bool device_links_busy(struct device *dev);
> >  extern void device_links_unbind_consumers(struct device *dev);
> > diff --git a/drivers/base/core.c b/drivers/base/core.c
> > index 5847364..31d4f68 100644
> > --- a/drivers/base/core.c
> > +++ b/drivers/base/core.c
> > @@ -452,10 +452,28 @@ static void __device_links_no_driver(struct
> > device *dev)
> >         dev->links.status = DL_DEV_NO_DRIVER;
> >  }
> > 
> > -void device_links_no_driver(struct device *dev)
> > +static void __device_links_probe_failed(struct device *dev)
> > +{
> > +       struct device_link *link, *ln;
> > +
> > +       list_for_each_entry_safe_reverse(link, ln, &dev-
> > >links.suppliers,
> > +                                        c_node) {
> > +               if (link->flags & DL_FLAG_STATELESS)
> > +                       continue;
> > +
> > +               if (link->flags & DL_FLAG_AUTOREMOVE)
> > +                       __device_link_del(link);
> > +               else if (link->status != DL_STATE_SUPPLIER_UNBIND)
> > +                       WRITE_ONCE(link->status,
> > DL_STATE_AVAILABLE);
> > +       }
> > +
> > +       dev->links.status = DL_DEV_PROBE_FAILED;
> > +}
> > +
> > +void device_links_probe_failed(struct device *dev)
> >  {
> >         device_links_write_lock();
> > -       __device_links_no_driver(dev);
> > +       __device_links_probe_failed(dev);
> >         device_links_write_unlock();
> >  }
> > 
> > diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> > index de6fd09..90d57e0 100644
> > --- a/drivers/base/dd.c
> > +++ b/drivers/base/dd.c
> > @@ -492,7 +492,7 @@ static int really_probe(struct device *dev,
> > struct device_driver *drv)
> >                 blocking_notifier_call_chain(&dev->bus->p-
> > >bus_notifier,
> >                                              BUS_NOTIFY_DRIVER_NOT_
> > BOUND, dev);
> >  pinctrl_bind_failed:
> > -       device_links_no_driver(dev);
> > +       device_links_probe_failed(dev);
> >         devres_release_all(dev);
> >         driver_sysfs_remove(dev);
> >         dev->driver = NULL;
> > diff --git a/include/linux/device.h b/include/linux/device.h
> > index b093405..bf9630a 100644
> > --- a/include/linux/device.h
> > +++ b/include/linux/device.h
> > @@ -794,6 +794,7 @@ struct device_link {
> >  enum dl_dev_state {
> >         DL_DEV_NO_DRIVER = 0,
> >         DL_DEV_PROBING,
> > +       DL_DEV_PROBE_FAILED,
> >         DL_DEV_DRIVER_BOUND,
> >         DL_DEV_UNBINDING,
> >  };
> > --
> > 2.7.4
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-
> > acpi" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" 
> in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [RFC PATCH 2/2] ACPI/IORT: use swiotlb_dma_ops when smmu probe failed
  2018-03-29 10:01   ` Wang Dongsheng
  (?)
@ 2018-04-04 16:01   ` Lorenzo Pieralisi
  2018-04-04 18:57     ` Robin Murphy
  -1 siblings, 1 reply; 10+ messages in thread
From: Lorenzo Pieralisi @ 2018-04-04 16:01 UTC (permalink / raw)
  To: Wang Dongsheng
  Cc: rjw, gregkh, hanjun.guo, sudeep.holla, yu.zheng, linux-acpi,
	linux-kernel, robin.murphy

[+cc Robin]

On Thu, Mar 29, 2018 at 03:01:00AM -0700, Wang Dongsheng wrote:
> If SMMU probe failed, master should use swiotlb as dma ops.
> SMMU may probe failed with specified environment, so there
> are not any iommu resources in iommu_device_list.
> 
> The master will always get EPROBE_DEFER from really_probe
> (dma_configure) but in fact SMMU has probe failed. The issue
> causes all of masters failed to be driven.

I added Robin to pick his brain. An alternative would consist
in using a bus notifier to prevent deferred probing once the SMMU
driver probing failed but that seems backwards given that a major
reason to move to deferred probing was to remove the bus notifiers
dependency in the first place.

It seems to me this is both an OF/ACPI issue - it is not an IORT
only problem.

Lorenzo

> Signed-off-by: Wang Dongsheng <dongsheng.wang@hxt-semitech.com>
> ---
>  drivers/acpi/arm64/iort.c | 39 +++++++++++++++++++++++++++++++++------
>  1 file changed, 33 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> index e2f7bdd..a6f4c27 100644
> --- a/drivers/acpi/arm64/iort.c
> +++ b/drivers/acpi/arm64/iort.c
> @@ -774,17 +774,45 @@ static int arm_smmu_iort_xlate(struct device *dev, u32 streamid,
>  	return ret;
>  }
>  
> -static inline bool iort_iommu_driver_enabled(u8 type)
> +static int iort_check_dev_dl_status(struct device *dev, void *data)
>  {
> +	struct fwnode_handle *fwnode = data;
> +
> +	if (dev->fwnode != fwnode)
> +		return 0;
> +
> +	if (dev->links.status == DL_DEV_PROBE_FAILED)
> +		return -ENODEV;
> +
> +	return -EPROBE_DEFER;
> +}
> +
> +static int iort_iommu_driver_enabled(u8 type, struct fwnode_handle *fwnode)
> +{
> +	bool buildin;
> +	int ret;
> +
>  	switch (type) {
>  	case ACPI_IORT_NODE_SMMU_V3:
> -		return IS_BUILTIN(CONFIG_ARM_SMMU_V3);
> +		buildin = IS_BUILTIN(CONFIG_ARM_SMMU_V3);
> +		break;
>  	case ACPI_IORT_NODE_SMMU:
> -		return IS_BUILTIN(CONFIG_ARM_SMMU);
> +		buildin = IS_BUILTIN(CONFIG_ARM_SMMU);
> +		break;
>  	default:
>  		pr_warn("IORT node type %u does not describe an SMMU\n", type);
> -		return false;
> +		buildin = false;
>  	}
> +
> +	if (!buildin)
> +		return -ENODEV;
> +
> +	ret = bus_for_each_dev(&platform_bus_type, NULL, fwnode,
> +			       iort_check_dev_dl_status);
> +	if (!ret)
> +		return -EPROBE_DEFER;
> +
> +	return ret;
>  }
>  
>  #ifdef CONFIG_IOMMU_API
> @@ -919,8 +947,7 @@ static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node,
>  	 */
>  	ops = iommu_ops_from_fwnode(iort_fwnode);
>  	if (!ops)
> -		return iort_iommu_driver_enabled(node->type) ?
> -		       -EPROBE_DEFER : -ENODEV;
> +		return iort_iommu_driver_enabled(node->type, iort_fwnode);
>  
>  	return arm_smmu_iort_xlate(dev, streamid, iort_fwnode, ops);
>  }
> -- 
> 2.7.4
> 

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

* Re: [RFC PATCH 2/2] ACPI/IORT: use swiotlb_dma_ops when smmu probe failed
  2018-04-04 16:01   ` Lorenzo Pieralisi
@ 2018-04-04 18:57     ` Robin Murphy
  0 siblings, 0 replies; 10+ messages in thread
From: Robin Murphy @ 2018-04-04 18:57 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Wang Dongsheng
  Cc: rjw, gregkh, hanjun.guo, sudeep.holla, yu.zheng, linux-acpi,
	linux-kernel

On 04/04/18 17:01, Lorenzo Pieralisi wrote:
> [+cc Robin]
> 
> On Thu, Mar 29, 2018 at 03:01:00AM -0700, Wang Dongsheng wrote:
>> If SMMU probe failed, master should use swiotlb as dma ops.
>> SMMU may probe failed with specified environment, so there
>> are not any iommu resources in iommu_device_list.
>>
>> The master will always get EPROBE_DEFER from really_probe
>> (dma_configure) but in fact SMMU has probe failed. The issue
>> causes all of masters failed to be driven.

Let's just take a step back - why is SMMU probe failing? That seems to 
be the primary issue here, because it implies that either your hardware, 
firmware or kernel is broken, any of which would make boot failure 
somewhat unsurprising anyway.

> I added Robin to pick his brain. An alternative would consist
> in using a bus notifier to prevent deferred probing once the SMMU
> driver probing failed but that seems backwards given that a major
> reason to move to deferred probing was to remove the bus notifiers
> dependency in the first place.
> 
> It seems to me this is both an OF/ACPI issue - it is not an IORT
> only problem.

Yes, this is just an instance of the general probe-deferral problem, 
e.g. once you have multiple dependencies it's possible to end up in a 
stalemate where everything including the IOMMU ends up on the deferred 
probe list with nothing to kick it and make progress again.

Furthermore it seems to me that the whole premise in this patch is 
flawed, since even genuine probe failure may well be transient - just 
because one attempt failed doesn't mean a later attempt can't succeed. 
Thus "the most recent probe attempt failed" cannot be considered a 
fundamentally different state from "no driver is currently bound".

Robin.

> 
> Lorenzo
> 
>> Signed-off-by: Wang Dongsheng <dongsheng.wang@hxt-semitech.com>
>> ---
>>   drivers/acpi/arm64/iort.c | 39 +++++++++++++++++++++++++++++++++------
>>   1 file changed, 33 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
>> index e2f7bdd..a6f4c27 100644
>> --- a/drivers/acpi/arm64/iort.c
>> +++ b/drivers/acpi/arm64/iort.c
>> @@ -774,17 +774,45 @@ static int arm_smmu_iort_xlate(struct device *dev, u32 streamid,
>>   	return ret;
>>   }
>>   
>> -static inline bool iort_iommu_driver_enabled(u8 type)
>> +static int iort_check_dev_dl_status(struct device *dev, void *data)
>>   {
>> +	struct fwnode_handle *fwnode = data;
>> +
>> +	if (dev->fwnode != fwnode)
>> +		return 0;
>> +
>> +	if (dev->links.status == DL_DEV_PROBE_FAILED)
>> +		return -ENODEV;
>> +
>> +	return -EPROBE_DEFER;
>> +}
>> +
>> +static int iort_iommu_driver_enabled(u8 type, struct fwnode_handle *fwnode)
>> +{
>> +	bool buildin;
>> +	int ret;
>> +
>>   	switch (type) {
>>   	case ACPI_IORT_NODE_SMMU_V3:
>> -		return IS_BUILTIN(CONFIG_ARM_SMMU_V3);
>> +		buildin = IS_BUILTIN(CONFIG_ARM_SMMU_V3);
>> +		break;
>>   	case ACPI_IORT_NODE_SMMU:
>> -		return IS_BUILTIN(CONFIG_ARM_SMMU);
>> +		buildin = IS_BUILTIN(CONFIG_ARM_SMMU);
>> +		break;
>>   	default:
>>   		pr_warn("IORT node type %u does not describe an SMMU\n", type);
>> -		return false;
>> +		buildin = false;
>>   	}
>> +
>> +	if (!buildin)
>> +		return -ENODEV;
>> +
>> +	ret = bus_for_each_dev(&platform_bus_type, NULL, fwnode,
>> +			       iort_check_dev_dl_status);
>> +	if (!ret)
>> +		return -EPROBE_DEFER;
>> +
>> +	return ret;
>>   }
>>   
>>   #ifdef CONFIG_IOMMU_API
>> @@ -919,8 +947,7 @@ static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node,
>>   	 */
>>   	ops = iommu_ops_from_fwnode(iort_fwnode);
>>   	if (!ops)
>> -		return iort_iommu_driver_enabled(node->type) ?
>> -		       -EPROBE_DEFER : -ENODEV;
>> +		return iort_iommu_driver_enabled(node->type, iort_fwnode);
>>   
>>   	return arm_smmu_iort_xlate(dev, streamid, iort_fwnode, ops);
>>   }
>> -- 
>> 2.7.4
>>

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

end of thread, other threads:[~2018-04-04 18:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-29 10:00 [RFC PATCH 0/2] driver core: add new dl device status DL_DEV_PROBE_FAILED Wang Dongsheng
2018-03-29 10:00 ` Wang Dongsheng
2018-03-29 10:00 ` [RFC PATCH 1/2] " Wang Dongsheng
2018-03-29 10:00   ` Wang Dongsheng
2018-03-29 10:51   ` Rafael J. Wysocki
2018-03-29 11:24     ` Wang, Dongsheng
2018-03-29 10:01 ` [RFC PATCH 2/2] ACPI/IORT: use swiotlb_dma_ops when smmu probe failed Wang Dongsheng
2018-03-29 10:01   ` Wang Dongsheng
2018-04-04 16:01   ` Lorenzo Pieralisi
2018-04-04 18:57     ` Robin Murphy

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.