public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] OMAP IOMMU Fixes for DT-clients
@ 2014-09-03 23:58 Suman Anna
       [not found] ` <1409788712-10741-1-git-send-email-s-anna-l0cyMroinI0@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Suman Anna @ 2014-09-03 23:58 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Laurent Pinchart, Florian Vaussard, iommu, linux-omap, Suman Anna

Hi,

Following are couple of minor fixes to the OMAP IOMMU driver for DT-based
client devices. The first patch adds an additional check to detect invalid
usage of IOMMU API for devices with no IOMMUs, and the second patch fixes
the failure to attach to an OMAP IOMMU for properly configured DT devices.
The kernel does not yet have any OMAP IOMMU users represented in DT, so
this failure is not currently seen, but will be seen when users like OMAP3
ISP or OMAP4 remoteprocs are converted to DT.

regards
Suman

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 | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

-- 
2.0.4


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

* [PATCH 1/2] iommu/omap: Check for valid archdata in attach_dev
       [not found] ` <1409788712-10741-1-git-send-email-s-anna-l0cyMroinI0@public.gmane.org>
@ 2014-09-03 23:58   ` Suman Anna
       [not found]     ` <1593534.HBLyulJI44@avalon>
  2014-09-03 23:58   ` [PATCH 2/2] iommu/omap: Fix iommu archdata name for DT-based devices Suman Anna
  1 sibling, 1 reply; 6+ messages in thread
From: Suman Anna @ 2014-09-03 23:58 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, Laurent Pinchart,
	Florian Vaussard

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 non-NULL archdata before accessing
different SoC-specific fields of the archdata. This prevents a
NULL pointer dereference on any misconfigured devices.

Signed-off-by: Suman Anna <s-anna-l0cyMroinI0@public.gmane.org>
---
 drivers/iommu/omap-iommu.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 02ef0ac..f245d51 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1092,6 +1092,12 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
 
 	spin_lock(&omap_domain->lock);
 
+	if (!arch_data) {
+		dev_err(dev, "device doesn't have an associated iommu\n");
+		ret = -EINVAL;
+		goto out;
+	}
+
 	/* only a single device is supported per domain for now */
 	if (omap_domain->iommu_dev) {
 		dev_err(dev, "iommu domain is already attached\n");
-- 
2.0.4

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

* [PATCH 2/2] iommu/omap: Fix iommu archdata name for DT-based devices
       [not found] ` <1409788712-10741-1-git-send-email-s-anna-l0cyMroinI0@public.gmane.org>
  2014-09-03 23:58   ` [PATCH 1/2] iommu/omap: Check for valid archdata in attach_dev Suman Anna
@ 2014-09-03 23:58   ` Suman Anna
       [not found]     ` <2755871.jyTSgisx8z@avalon>
  1 sibling, 1 reply; 6+ messages in thread
From: Suman Anna @ 2014-09-03 23:58 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, Laurent Pinchart,
	Florian Vaussard

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.

Signed-off-by: Suman Anna <s-anna-l0cyMroinI0@public.gmane.org>
---
 drivers/iommu/omap-iommu.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index f245d51..f47ac03 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -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>
 
@@ -1244,6 +1245,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.
@@ -1258,13 +1260,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);
-- 
2.0.4

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

* Re: [PATCH 1/2] iommu/omap: Check for valid archdata in attach_dev
       [not found]     ` <1593534.HBLyulJI44@avalon>
@ 2014-09-04 19:37       ` Suman Anna
  0 siblings, 0 replies; 6+ messages in thread
From: Suman Anna @ 2014-09-04 19:37 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-omap-u79uwXL29TY76Z2rM5mHXA,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Florian Vaussard

Hi Laurent,

> On Wednesday 03 September 2014 18:58:31 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 non-NULL archdata before accessing
>> different SoC-specific fields of the archdata. This prevents a
>> NULL pointer dereference on any misconfigured devices.
>>
>> Signed-off-by: Suman Anna <s-anna-l0cyMroinI0@public.gmane.org>
>> ---
>>  drivers/iommu/omap-iommu.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
>> index 02ef0ac..f245d51 100644
>> --- a/drivers/iommu/omap-iommu.c
>> +++ b/drivers/iommu/omap-iommu.c
>> @@ -1092,6 +1092,12 @@ omap_iommu_attach_dev(struct iommu_domain *domain,
>> struct device *dev)
>>
>>  	spin_lock(&omap_domain->lock);
>>
>> +	if (!arch_data) {
>> +		dev_err(dev, "device doesn't have an associated iommu\n");
>> +		ret = -EINVAL;
>> +		goto out;
>> +	}
> 
> You can move this check outside of the spinlock-protected section. With that 
> change,

Thanks, will fix this in the next revision, will also add the check for
the name field.

regards
Suman

> 
> Acked-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
> 
>> +
>>  	/* only a single device is supported per domain for now */
>>  	if (omap_domain->iommu_dev) {
>>  		dev_err(dev, "iommu domain is already attached\n");
> 

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

* Re: [PATCH 2/2] iommu/omap: Fix iommu archdata name for DT-based devices
       [not found]     ` <2755871.jyTSgisx8z@avalon>
@ 2014-09-04 21:17       ` Suman Anna
  2014-09-05 11:11         ` Laurent Pinchart
  0 siblings, 1 reply; 6+ messages in thread
From: Suman Anna @ 2014-09-04 21:17 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-omap-u79uwXL29TY76Z2rM5mHXA,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	Florian Vaussard

Hi Laurent,
>
> On Wednesday 03 September 2014 18:58:32 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.
>>
>> Signed-off-by: Suman Anna <s-anna-l0cyMroinI0@public.gmane.org>
>> ---
>>  drivers/iommu/omap-iommu.c | 10 +++++++++-
>>  1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
>> index f245d51..f47ac03 100644
>> --- a/drivers/iommu/omap-iommu.c
>> +++ b/drivers/iommu/omap-iommu.c
>> @@ -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>
>>
>> @@ -1244,6 +1245,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.
>> @@ -1258,13 +1260,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;
>> +	}
> 
> I might be wrong, but I don't think there's a guarantee at this point that the 
> IOMMU device is already instantiated :-/

The omap_iommu_init which registers the iommu_ops is a subsys_initcall,
so the platform devices are guaranteed to be created by this point. My
test on OMAP4 in fact has the dsp node created before the IOMMU node,
and this is not an issue. I have added the WARN_ON in case some one has
the IOMMU node disabled, but try to use it.

> Will Deacon has posted patches that rework the IOMMU core for better DT 
> integration, have you seen them ?

Can you point out the thread? Are you talking about
http://marc.info/?l=linux-arm-kernel&m=140968072117851&w=2?

regards
Suman

> 
>> +
>>  	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);
> 

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

* Re: [PATCH 2/2] iommu/omap: Fix iommu archdata name for DT-based devices
  2014-09-04 21:17       ` Suman Anna
@ 2014-09-05 11:11         ` Laurent Pinchart
  0 siblings, 0 replies; 6+ messages in thread
From: Laurent Pinchart @ 2014-09-05 11:11 UTC (permalink / raw)
  To: Suman Anna; +Cc: Joerg Roedel, Florian Vaussard, iommu, linux-omap

Hi Suman,

On Thursday 04 September 2014 16:17:53 Suman Anna wrote:
> Hi Laurent,
> 
> > On Wednesday 03 September 2014 18:58:32 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.
> >> 
> >> Signed-off-by: Suman Anna <s-anna@ti.com>
> >> ---
> >> 
> >>  drivers/iommu/omap-iommu.c | 10 +++++++++-
> >>  1 file changed, 9 insertions(+), 1 deletion(-)
> >> 
> >> diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
> >> index f245d51..f47ac03 100644
> >> --- a/drivers/iommu/omap-iommu.c
> >> +++ b/drivers/iommu/omap-iommu.c
> >> @@ -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>
> >> 
> >> @@ -1244,6 +1245,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.
> >> @@ -1258,13 +1260,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;
> >> +	}
> > 
> > I might be wrong, but I don't think there's a guarantee at this point that
> > the IOMMU device is already instantiated :-/
> 
> The omap_iommu_init which registers the iommu_ops is a subsys_initcall,
> so the platform devices are guaranteed to be created by this point.

OK, no worries then.

> My test on OMAP4 in fact has the dsp node created before the IOMMU node,
> and this is not an issue. I have added the WARN_ON in case some one has
> the IOMMU node disabled, but try to use it.
> 
> > Will Deacon has posted patches that rework the IOMMU core for better DT
> > integration, have you seen them ?
> 
> Can you point out the thread? Are you talking about
> http://marc.info/?l=linux-arm-kernel&m=140968072117851&w=2?

Yes that's the one.

-- 
Regards,

Laurent Pinchart


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

end of thread, other threads:[~2014-09-05 11:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-03 23:58 [PATCH 0/2] OMAP IOMMU Fixes for DT-clients Suman Anna
     [not found] ` <1409788712-10741-1-git-send-email-s-anna-l0cyMroinI0@public.gmane.org>
2014-09-03 23:58   ` [PATCH 1/2] iommu/omap: Check for valid archdata in attach_dev Suman Anna
     [not found]     ` <1593534.HBLyulJI44@avalon>
2014-09-04 19:37       ` Suman Anna
2014-09-03 23:58   ` [PATCH 2/2] iommu/omap: Fix iommu archdata name for DT-based devices Suman Anna
     [not found]     ` <2755871.jyTSgisx8z@avalon>
2014-09-04 21:17       ` Suman Anna
2014-09-05 11:11         ` Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox