diff mbox series

[5/5] iommu: Allow default domain type to be set on the kernel command line

Message ID 1484849955-1871-6-git-send-email-will.deacon@arm.com
State New
Headers show
Series Implement SMMU passthrough using the default domain | expand

Commit Message

Will Deacon Jan. 19, 2017, 6:19 p.m. UTC
The IOMMU core currently initialises the default domain for each group
to IOMMU_DOMAIN_DMA, under the assumption that devices will use
IOMMU-backed DMA ops by default. However, in some cases it is desirable
for the DMA ops to bypass the IOMMU for performance reasons, reserving
use of translation for subsystems such as VFIO that require it for
enforcing device isolation.

Rather than modify each IOMMU driver to provide different semantics for
DMA domains, instead we introduce a command line parameter that can be
used to change the type of the default domain. Passthrough can then be
specified using "iommu.default_domain=identity" on the kernel command
line.

Signed-off-by: Will Deacon <will.deacon@arm.com>

---
 drivers/iommu/iommu.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

-- 
2.1.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Comments

Joerg Roedel Jan. 26, 2017, 5:15 p.m. UTC | #1
On Thu, Jan 19, 2017 at 06:19:15PM +0000, Will Deacon wrote:
> Rather than modify each IOMMU driver to provide different semantics for

> DMA domains, instead we introduce a command line parameter that can be

> used to change the type of the default domain. Passthrough can then be

> specified using "iommu.default_domain=identity" on the kernel command

> line.


I like the general idea of this, but the above is a terrible name for a
kernel commandline-parameter. The x86 iommus support iommu=pt which is
pretty much the same as this patch does.

How about something like "iommu.passthrough=0/1"? And please add the
parameter to the kernel documentation too.


	Joerg


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Robin Murphy Jan. 26, 2017, 5:26 p.m. UTC | #2
On 26/01/17 17:15, Joerg Roedel wrote:
> On Thu, Jan 19, 2017 at 06:19:15PM +0000, Will Deacon wrote:

>> Rather than modify each IOMMU driver to provide different semantics for

>> DMA domains, instead we introduce a command line parameter that can be

>> used to change the type of the default domain. Passthrough can then be

>> specified using "iommu.default_domain=identity" on the kernel command

>> line.

> 

> I like the general idea of this, but the above is a terrible name for a

> kernel commandline-parameter. The x86 iommus support iommu=pt which is

> pretty much the same as this patch does.


Indeed, I was keen on making "iommu=pt" also do this default domain
switch itself so we wouldn't need a new option - it didn't *appear* that
that would break the AMD driver (as the only other default domain user
supporting identity domains) but I may have overlooked something.

Robin.

> How about something like "iommu.passthrough=0/1"? And please add the

> parameter to the kernel documentation too.

> 

> 

> 	Joerg

> 



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon Jan. 26, 2017, 5:48 p.m. UTC | #3
On Thu, Jan 26, 2017 at 06:15:55PM +0100, Joerg Roedel wrote:
> On Thu, Jan 19, 2017 at 06:19:15PM +0000, Will Deacon wrote:

> > Rather than modify each IOMMU driver to provide different semantics for

> > DMA domains, instead we introduce a command line parameter that can be

> > used to change the type of the default domain. Passthrough can then be

> > specified using "iommu.default_domain=identity" on the kernel command

> > line.

> 

> I like the general idea of this, but the above is a terrible name for a

> kernel commandline-parameter. The x86 iommus support iommu=pt which is

> pretty much the same as this patch does.


Happy to bikeshed the name ;)

> How about something like "iommu.passthrough=0/1"? And please add the

> parameter to the kernel documentation too.


Sure, if you think that the identity domain is the only thing we'll ever
want to set (so far, it's the only thing people have asked me for).

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
diff mbox series

Patch

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index dbe7f653bb7c..69f7f1a75543 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -36,6 +36,7 @@ 
 
 static struct kset *iommu_group_kset;
 static DEFINE_IDA(iommu_group_ida);
+static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_DMA;
 
 struct iommu_callback_data {
 	const struct iommu_ops *ops;
@@ -86,6 +87,20 @@  static int __iommu_attach_group(struct iommu_domain *domain,
 static void __iommu_detach_group(struct iommu_domain *domain,
 				 struct iommu_group *group);
 
+static int __init iommu_set_def_domain_type(char *str)
+{
+	if (!str)
+		return -EINVAL;
+
+	if (!strcmp(str, "identity"))
+		iommu_def_domain_type = IOMMU_DOMAIN_IDENTITY;
+	else if (!strcmp(str, "dma"))
+		iommu_def_domain_type = IOMMU_DOMAIN_DMA;
+
+	return 0;
+}
+early_param("iommu.default_domain", iommu_set_def_domain_type);
+
 static ssize_t iommu_group_attr_show(struct kobject *kobj,
 				     struct attribute *__attr, char *buf)
 {
@@ -847,8 +862,8 @@  struct iommu_group *iommu_group_get_for_dev(struct device *dev)
 	 * IOMMU driver.
 	 */
 	if (!group->default_domain) {
-		group->default_domain = __iommu_domain_alloc(dev->bus,
-							     IOMMU_DOMAIN_DMA);
+		group->default_domain =
+			__iommu_domain_alloc(dev->bus, iommu_def_domain_type);
 		if (!group->domain)
 			group->domain = group->default_domain;
 	}