Skip to contentSkip to conversation

iommu: of: Fix check for returning EPROBE_DEFER

PATCH Superseded Sricharan R 2 participants 5 messages May 17, 2017 – May 18, 2017

Subsystems (6)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 iommu: of: Fix check for returning EPROBE_DEFER

Now with iommu probe deferral, we return -EPROBE_DEFER for master's that are connected to an iommu which is not probed yet, but going to get probed, so that we can attach the correct dma_ops. So while trying to defer the probe of the master, check if the of_iommu node that it is connected to is marked in DT as 'status=disabled', then the iommu is never is going to get probed. So simply return NULL and let the master work without an iommu.

Fixes 7b07cbefb68d ("iommu: of: Handle IOMMU lookup failure with deferred probing or error")
---
 drivers/iommu/of_iommu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/of_iommu.c +1 -0
index 9f44ee8..e6e9bec 100644
@@ -118,6 +118,7 @@ static bool of_iommu_driver_present(struct device_node *np)
 
 	ops = iommu_ops_from_fwnode(fwnode);
 	if ((ops && !ops->of_xlate) ||
+	    !of_device_is_available(iommu_spec->np) ||
 	    (!ops && !of_iommu_driver_present(iommu_spec->np)))
 		return NULL;
 
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw

PATCH 2/3 iommu: of: Ignore all errors except EPROBE_DEFER

While deferring the probe of iommu masters, xlate and add_device callback can pass back error values like -ENODEV, which means iommu cannot be connected with that master for real reasons. So rather than killing the master's probe for such errors, just ignore the errors and let the master work without an iommu.

Fixes 7b07cbefb68d ("iommu: of: Handle IOMMU lookup failure with deferred probing or error")
---
 drivers/iommu/of_iommu.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/iommu/of_iommu.c +6 -0
index e6e9bec..2ec2f0b 100644
@@ -237,6 +237,12 @@ const struct iommu_ops *of_iommu_configure(struct device *dev,
 			ops = ERR_PTR(err);
 	}
 
+	/* Ignore all other errors apart from EPROBE_DEFER */
+	if (IS_ERR(ops) && (PTR_ERR(ops) != -EPROBE_DEFER)) {
+		dev_info(dev, "Adding to iommu failed: %ld\n", PTR_ERR(ops));
+		ops = NULL;
+	}
+
 	return ops;
 }
 
Signature · 6 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

PATCH 3/3 ARM: dma-mapping: Don't tear third-party mappings

In reply to Sricharan R

From: Laurent Pinchart <laurent.pinchart+renesas-ryLnwIuWjnjg/[email protected]>

arch_setup_dma_ops() is used in device probe code paths to create an IOMMU mapping and attach it to the device. The function assumes that the device is attached to a device-specific IOMMU instance (or at least a device-specific TLB in a shared IOMMU instance) and thus creates a separate mapping for every device.

On several systems (Renesas R-Car Gen2 being one of them), that assumption is not true, and IOMMU mappings must be shared between multiple devices. In those cases the IOMMU driver knows better than the generic ARM dma-mapping layer and attaches mapping to devices manually with arm_iommu_attach_device(), which sets the DMA ops for the device.

The arch_setup_dma_ops() function takes this into account and bails out immediately if the device already has DMA ops assigned. However, the corresponding arch_teardown_dma_ops() function, called from driver unbind code paths (including probe deferral), will tear the mapping down regardless of who created it. When the device is reprobed arch_setup_dma_ops() will be called again but won't perform any operation as the DMA ops will still be set.

We need to reset the DMA ops in arch_teardown_dma_ops() to fix this. However, we can't do so unconditionally, as then a new mapping would be created by arch_setup_dma_ops() when the device is reprobed, regardless of whether the device needs to share a mapping or not. We must thus keep track of whether arch_setup_dma_ops() created the mapping, and only in that case tear it down in arch_teardown_dma_ops().

Keep track of that information in the dev_archdata structure. As the structure is embedded in all instances of struct device let's not grow it, but turn the existing dma_coherent bool field into a bitfield that can be used for other purposes.

Fixes 09515ef5ddad ("of/acpi: Configure dma operations at probe time for platform/amba/pci bus devices")
---
 arch/arm/include/asm/device.h | 3 ++-
 arch/arm/mm/dma-mapping.c     | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)
arch/arm/include/asm/device.h +2 -1
index 36ec9c8..3234fe9 100644
@@ -19,7 +19,8 @@ struct dev_archdata {
 #ifdef CONFIG_XEN
 	const struct dma_map_ops *dev_dma_ops;
 #endif
-	bool dma_coherent;
+	unsigned int dma_coherent:1;
+	unsigned int dma_ops_setup:1;
 };
 
 struct omap_device;
arch/arm/mm/dma-mapping.c +4 -0
index cb57f59..b5099d0 100644
@@ -2431,9 +2431,13 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
 		dev->dma_ops = xen_dma_ops;
 	}
 #endif
+	dev->archdata.dma_ops_setup = true;
 }
 
 void arch_teardown_dma_ops(struct device *dev)
 {
+	if (!dev->archdata.dma_ops_setup)
+		return;
+
 	arm_teardown_iommu_dma_ops(dev);
 }
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#3 lore raw
In reply to Sricharan R
Quoted 2 lines · Sricharan R

Now with iommu probe deferral, we return -EPROBE_DEFER for master's that are connected to an iommu which is not

s/master's/masters/

s/iommu/IOMMU/ in your English text (changelogs and comments). That seems to be the convention, based on "git log drivers/iommu/of_iommu.c"

Quoted 37 lines

probed yet, but going to get probed, so that we can attach the correct dma_ops. So while trying to defer the probe of the master, check if the of_iommu node that it is connected to is marked in DT as 'status=disabled', then the iommu is never is going to get probed. So simply return NULL and let the master work without an iommu.

Fixes 7b07cbefb68d ("iommu: of: Handle IOMMU lookup failure with deferred probing or error")
---
 drivers/iommu/of_iommu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/of_iommu.c +1 -0
index 9f44ee8..e6e9bec 100644
@@ -118,6 +118,7 @@ static bool of_iommu_driver_present(struct device_node *np)
 
 	ops = iommu_ops_from_fwnode(fwnode);
 	if ((ops && !ops->of_xlate) ||
+	    !of_device_is_available(iommu_spec->np) ||
 	    (!ops && !of_iommu_driver_present(iommu_spec->np)))
 		return NULL;
 
Signature · 7 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#4 lore raw

Hi Bjorn,

Quoted 9 lines · Bjorn Helgaas
Quoted 2 lines · Sricharan R

Now with iommu probe deferral, we return -EPROBE_DEFER for master's that are connected to an iommu which is not

s/master's/masters/

s/iommu/IOMMU/ in your English text (changelogs and comments). That seems to be the convention, based on "git log drivers/iommu/of_iommu.c"

ok, will correct those.

Regards,
Sricharan

Quoted 37 lines
Quoted 37 lines

probed yet, but going to get probed, so that we can attach the correct dma_ops. So while trying to defer the probe of the master, check if the of_iommu node that it is connected to is marked in DT as 'status=disabled', then the iommu is never is going to get probed. So simply return NULL and let the master work without an iommu.

Fixes 7b07cbefb68d ("iommu: of: Handle IOMMU lookup failure with deferred probing or error")
---
 drivers/iommu/of_iommu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/of_iommu.c +1 -0
index 9f44ee8..e6e9bec 100644
@@ -118,6 +118,7 @@ static bool of_iommu_driver_present(struct device_node *np)
 
 	ops = iommu_ops_from_fwnode(fwnode);
 	if ((ops && !ops->of_xlate) ||
+	    !of_device_is_available(iommu_spec->np) ||
 	    (!ops && !of_iommu_driver_present(iommu_spec->np)))
 		return NULL;
 
Signature · 7 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 1 line
"QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation