Skip to contentSkip to conversation

OMAP IOMMU Fixes for DT-clients

PATCH Applied Suman Anna 4 participants 6 messages Sep 4, 2014 – Sep 5, 2014 3 messages not in the archive IOMMU

lore
Share & tools
lore

Suman Anna

author
#0 lore raw

v2 cover OMAP IOMMU Fixes for DT-clients

Hi,

This is an updated series addressing Laurent's review comments on Patch1. Patch2 is unchanged from the previous series.

Patches are based on 3.17-rc3.

v1:
http://marc.info/?l=linux-omap&m=140978874026176&w=2

Suman Anna (2):
iommu/omap: Check for valid archdata in attach_dev iommu/omap: Fix iommu archdata name for DT-based devices

 drivers/iommu/omap-iommu.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
Signature · 1 line
2.0.4

A message that is not in the archive (sent off-list or not yet received): 1409869650-26115-1-git-send-email-s-anna-l0cyMroinI0@public.gmane.org

#2 lore raw

PATCH v2 1/2 iommu/omap: Check for valid archdata in attach_dev

Any device requiring to be attached to an iommu_domain must have valid archdata containing the necessary iommu information, which is SoC-specific. Add a check in the omap_iommu_attach_dev to make sure that the device has valid archdata before accessing different SoC-specific fields of the archdata. This prevents a NULL pointer dereference on any misconfigured devices.

---
 drivers/iommu/omap-iommu.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/iommu/omap-iommu.c +5 -0
index 02ef0ac..ea6e59d 100644
@@ -1090,6 +1090,11 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
 	struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
 	int ret = 0;
 
+	if (!arch_data || !arch_data->name) {
+		dev_err(dev, "device doesn't have an associated iommu\n");
+		return -EINVAL;
+	}
+
 	spin_lock(&omap_domain->lock);
 
 	/* only a single device is supported per domain for now */
Signature · 1 line
2.0.4

A message that is not in the archive (sent off-list or not yet received): 1409869650-26115-2-git-send-email-s-anna-l0cyMroinI0@public.gmane.org

#4 lore raw

Re: [PATCHv2 1/2] iommu/omap: Check for valid archdata in attach_dev

Hi Suman,

Thank you for the patch.

Quoted 8 lines · On Thursday 04 September 2014 17:27:29 Suman Anna wrote:

Any device requiring to be attached to an iommu_domain must have valid archdata containing the necessary iommu information, which is SoC-specific. Add a check in the omap_iommu_attach_dev to make sure that the device has valid archdata before accessing different SoC-specific fields of the archdata. This prevents a NULL pointer dereference on any misconfigured devices.

Quoted 21 lines
---
 drivers/iommu/omap-iommu.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/iommu/omap-iommu.c +0 -0
index 02ef0ac..ea6e59d 100644
@@ -1090,6 +1090,11 @@ omap_iommu_attach_dev(struct iommu_domain *domain,

struct device *dev) struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;

drivers/iommu/omap-iommu.c +5 -0
 	int ret = 0;
 
+	if (!arch_data || !arch_data->name) {
+		dev_err(dev, "device doesn't have an associated iommu\n");
+		return -EINVAL;
+	}
+
 	spin_lock(&omap_domain->lock);
 
 	/* only a single device is supported per domain for now */
Signature · 3 lines
Regards,

Laurent Pinchart
Applied
#5 lore raw
In reply to a message not in the archive
Quoted 6 lines · Suman Anna

Suman Anna (2):
iommu/omap: Check for valid archdata in attach_dev iommu/omap: Fix iommu archdata name for DT-based devices

 drivers/iommu/omap-iommu.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Applied, thanks.

author
#6 lore raw

PATCH v2 2/2 iommu/omap: Fix iommu archdata name for DT-based devices

In reply to Suman Anna

A device is tied to an iommu through its archdata field. The archdata is allocated on the fly for DT-based devices automatically through the .add_device iommu ops. The current logic incorrectly assigned the name of the IOMMU user device, instead of the name of the IOMMU device as required by the attach logic. Fix this issue so that DT-based devices can attach successfully to an IOMMU domain.

---
 drivers/iommu/omap-iommu.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/iommu/omap-iommu.c +9 -1
index ea6e59d..8cf8bf1 100644
@@ -26,6 +26,7 @@
 #include <linux/of.h>
 #include <linux/of_iommu.h>
 #include <linux/of_irq.h>
+#include <linux/of_platform.h>
 
 #include <asm/cacheflush.h>
 
@@ -1243,6 +1244,7 @@ static int omap_iommu_add_device(struct device *dev)
 {
 	struct omap_iommu_arch_data *arch_data;
 	struct device_node *np;
+	struct platform_device *pdev;
 
 	/*
 	 * Allocate the archdata iommu structure for DT-based devices.
@@ -1257,13 +1259,19 @@ static int omap_iommu_add_device(struct device *dev)
 	if (!np)
 		return 0;
 
+	pdev = of_find_device_by_node(np);
+	if (WARN_ON(!pdev)) {
+		of_node_put(np);
+		return -EINVAL;
+	}
+
 	arch_data = kzalloc(sizeof(*arch_data), GFP_KERNEL);
 	if (!arch_data) {
 		of_node_put(np);
 		return -ENOMEM;
 	}
 
-	arch_data->name = kstrdup(dev_name(dev), GFP_KERNEL);
+	arch_data->name = kstrdup(dev_name(&pdev->dev), GFP_KERNEL);
 	dev->archdata.iommu = arch_data;
 
 	of_node_put(np);
Signature · 1 line
2.0.4

A message that is not in the archive (sent off-list or not yet received): 1409869650-26115-3-git-send-email-s-anna-l0cyMroinI0@public.gmane.org

#8 lore raw

Re: [PATCHv2 2/2] iommu/omap: Fix iommu archdata name for DT-based devices

Hi Suman,

Thank you for the patch.

Quoted 8 lines · On Thursday 04 September 2014 17:27:30 Suman Anna wrote:

A device is tied to an iommu through its archdata field. The archdata is allocated on the fly for DT-based devices automatically through the .add_device iommu ops. The current logic incorrectly assigned the name of the IOMMU user device, instead of the name of the IOMMU device as required by the attach logic. Fix this issue so that DT-based devices can attach successfully to an IOMMU domain.

Quoted 45 lines
---
 drivers/iommu/omap-iommu.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/iommu/omap-iommu.c +9 -1
index ea6e59d..8cf8bf1 100644
@@ -26,6 +26,7 @@
 #include <linux/of.h>
 #include <linux/of_iommu.h>
 #include <linux/of_irq.h>
+#include <linux/of_platform.h>
 
 #include <asm/cacheflush.h>
 
@@ -1243,6 +1244,7 @@ static int omap_iommu_add_device(struct device *dev)
 {
 	struct omap_iommu_arch_data *arch_data;
 	struct device_node *np;
+	struct platform_device *pdev;
 
 	/*
 	 * Allocate the archdata iommu structure for DT-based devices.
@@ -1257,13 +1259,19 @@ static int omap_iommu_add_device(struct device *dev)
 if (!np)
 		return 0;
 
+	pdev = of_find_device_by_node(np);
+	if (WARN_ON(!pdev)) {
+		of_node_put(np);
+		return -EINVAL;
+	}
+
 	arch_data = kzalloc(sizeof(*arch_data), GFP_KERNEL);
 	if (!arch_data) {
 		of_node_put(np);
 		return -ENOMEM;
 	}
 
-	arch_data->name = kstrdup(dev_name(dev), GFP_KERNEL);
+	arch_data->name = kstrdup(dev_name(&pdev->dev), GFP_KERNEL);
 	dev->archdata.iommu = arch_data;
 
 	of_node_put(np);
Signature · 3 lines
Regards,

Laurent Pinchart