iommu: of: Fix check for returning EPROBE_DEFER
Subsystems (8)
PATCH v5 1/5 iommu: of: Fix check for returning EPROBE_DEFER
Now with IOMMU probe deferral, we return -EPROBE_DEFER for masters 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.
--- drivers/iommu/of_iommu.c | 1 + 1 file changed, 1 insertion(+)
drivers/iommu/of_iommu.c +1 -0
@@ -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
PATCH v5 2/5 iommu: of: Ignore all errors except EPROBE_DEFER
While deferring the probe of IOMMU masters, xlate and add_device callbacks called from of_iommu_configure can pass back error values like -ENODEV, which means the IOMMU cannot be connected with that master for real reasons. Before the IOMMU probe deferral, all such errors were ignored. Now all those errors are propagated back, killing the master's probe for such errors. Instead ignore all the errors except EPROBE_DEFER, which is the only one of concern and let the master work without IOMMU, thus restoring the old behavior. Also make explicit that of_dma_configure handles only -EPROBE_DEFER from of_iommu_configure.
---
[v5] Added the check in of_dma_configure
drivers/iommu/of_iommu.c | 6 ++++++ drivers/of/device.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/iommu/of_iommu.c +6 -0
@@ -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_dbg (dev,"Adding to IOMMU failed: %ld\n" ,PTR_ERR (ops)); + ops =NULL ; + } +return ops; }
drivers/of/device.c +2 -2
@@ -144,8 +144,8 @@ int of_dma_configure(struct device *dev, struct device_node *np) coherent ? " " : " not "); iommu =of_iommu_configure (dev, np); -if (IS_ERR (iommu)) -return PTR_ERR (iommu); +if (IS_ERR (iommu) &&PTR_ERR (iommu) == -EPROBE_DEFER ) +return -EPROBE_DEFER ;dev_dbg (dev,"device is%sbehind an iommu\n" , iommu ?" " :" not " );
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v5 3/5 ACPI/IORT: Ignore all errors except EPROBE_DEFER
In reply to Sricharan RWhile deferring the probe of IOMMU masters, xlate and add_device callbacks called from iort_iommu_configure can pass back error values like -ENODEV, which means the IOMMU cannot be connected with that master for real reasons. Before the IOMMU probe deferral, all such errors were ignored. Now all those errors are propagated back, killing the master's probe for such errors. Instead ignore all the errors except EPROBE_DEFER, which is the only one of concern and let the master work without IOMMU, thus restoring the old behavior. Also make explicit that acpi_dma_configure handles only -EPROBE_DEFER from iort_iommu_configure.
---
[v5] Added the check in acpi_dma_configure
drivers/acpi/arm64/iort.c | 6 ++++++ drivers/acpi/scan.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/acpi/arm64/iort.c +6 -0
@@ -782,6 +782,12 @@ const struct iommu_ops *iort_iommu_configure(struct device *dev)if (err) ops =ERR_PTR (err); +/* Ignore all other errors apart from EPROBE_DEFER */ +if (IS_ERR (ops) && (PTR_ERR (ops) != -EPROBE_DEFER )) { +dev_dbg (dev,"Adding to IOMMU failed: %ld\n" ,PTR_ERR (ops)); + ops =NULL ; + } +return ops; }
drivers/acpi/scan.c +2 -2
@@ -1371,8 +1371,8 @@ int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr)iort_set_dma_mask (dev); iommu =iort_iommu_configure (dev); -if (IS_ERR (iommu)) -return PTR_ERR (iommu); +if (IS_ERR (iommu) &&PTR_ERR (iommu) == -EPROBE_DEFER ) +return -EPROBE_DEFER ; size =max (dev->coherent_dma_mask, dev->coherent_dma_mask +1 );/*
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v5 4/5 ARM: dma-mapping: Don't tear third-party mappings
In reply to Sricharan RFrom: 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.
--- 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
@@ -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
@@ -2430,9 +2430,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
PATCH v5 5/5 ACPI/IORT: Move the check to get iommu_ops from translated fwspec
In reply to Sricharan RFrom: Lorenzo Pieralisi <[email protected]>
With IOMMU probe deferral, iort_iommu_configure can be called multiple times for the same device. Hence we have a check to see if the device's fwspec is already translated and return the iommu_ops from that directly. But the check is wrongly placed in iort_iommu_xlate, which breaks devices with multiple sids. Move the check to iort_iommu_configure.
---
[v5] new patch
drivers/acpi/arm64/iort.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/acpi/arm64/iort.c +8 -8
@@ -666,14 +666,6 @@ static const struct iommu_ops *iort_iommu_xlate(struct device *dev,int ret = -ENODEV ;struct fwnode_handle *iort_fwnode; -/* -* If we already translated the fwspec there -* is nothing left to do, return the iommu_ops. -*/ - ops =iort_fwspec_iommu_ops (dev->iommu_fwspec); -if (ops) -return ops; -if (node) { iort_fwnode =iort_get_fwnode (node);if (!iort_fwnode)
@@ -735,6 +727,14 @@ const struct iommu_ops *iort_iommu_configure(struct device *dev)u32 streamid =0 ;int err; +/* +* If we already translated the fwspec there +* is nothing left to do, return the iommu_ops. +*/ + ops =iort_fwspec_iommu_ops (dev->iommu_fwspec); +if (ops) +return ops; +if (dev_is_pci (dev)) {struct pci_bus *bus =to_pci_dev (dev)->bus;u32 rid;
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 9 lines · Sricharan R
Now with IOMMU probe deferral, we return -EPROBE_DEFER for masters 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 theof_iommunode 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.
Quoted 7 lines
Fixes 7b07cbefb68d ("iommu: of: Handle IOMMU lookup failure with deferred probing or error")Signed-off-by Sricharan R <[email protected]>Reported-by Geert Uytterhoeven <[email protected]>Tested-by Will Deacon <[email protected]>Tested-by Magnus Damn <[email protected]>Acked-by Will Deacon <[email protected]>
Applied all to iommu/fixes, thanks.