LKML Archive on lore.kernel.org
 help / Atom feed
* [PATCH 1/2] iommu: Add config option to set passthrough as default
@ 2018-07-11 20:59 Olof Johansson
  2018-07-11 20:59 ` [PATCH 2/2] iommu: add sysfs attribyte for domain type Olof Johansson
  2018-07-12  2:04 ` [PATCH 1/2] iommu: Add config option to set passthrough as default Yang, Shunyong
  0 siblings, 2 replies; 3+ messages in thread
From: Olof Johansson @ 2018-07-11 20:59 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, linux-kernel, Olof Johansson

This allows the default behavior to be controlled by a kernel config
option instead of changing the commandline for the kernel to include
"iommu.passthrough=on" on machines where this is desired.

Signed-off-by: Olof Johansson <olof@lixom.net>
---
 drivers/iommu/Kconfig | 10 ++++++++++
 drivers/iommu/iommu.c |  4 ++++
 2 files changed, 14 insertions(+)

diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 689ffe538370..a9bb1a5b5e43 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -60,6 +60,16 @@ config IOMMU_IO_PGTABLE_ARMV7S_SELFTEST
 
 endmenu
 
+config IOMMU_DEFAULT_PASSTHROUGH
+	bool "IOMMU passthrough by default"
+	depends on IOMMU_API
+        help
+	  Enable passthrough by default (removing the need to pass in
+	  iommu.passthrough=on through command line). If this is enabled,
+	  you can still disable with iommu.passthrough=off
+
+	  If unsure, say N here.
+
 config IOMMU_IOVA
 	tristate
 
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 63b37563db7e..ab8fc54467e0 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -36,7 +36,11 @@
 
 static struct kset *iommu_group_kset;
 static DEFINE_IDA(iommu_group_ida);
+#ifdef CONFIG_IOMMU_DEFAULT_PASSTHROUGH
+static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_IDENTITY;
+#else
 static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_DMA;
+#endif
 
 struct iommu_callback_data {
 	const struct iommu_ops *ops;
-- 
2.11.0


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

* [PATCH 2/2] iommu: add sysfs attribyte for domain type
  2018-07-11 20:59 [PATCH 1/2] iommu: Add config option to set passthrough as default Olof Johansson
@ 2018-07-11 20:59 ` Olof Johansson
  2018-07-12  2:04 ` [PATCH 1/2] iommu: Add config option to set passthrough as default Yang, Shunyong
  1 sibling, 0 replies; 3+ messages in thread
From: Olof Johansson @ 2018-07-11 20:59 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, linux-kernel, Olof Johansson

While we could print it at setup time, this is an easier way to match
each device to their default IOMMU allocation type.

Signed-off-by: Olof Johansson <olof@lixom.net>
---
 drivers/iommu/iommu.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index ab8fc54467e0..53164107620c 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -298,11 +298,39 @@ static ssize_t iommu_group_show_resv_regions(struct iommu_group *group,
 	return (str - buf);
 }
 
+static ssize_t iommu_group_show_type(struct iommu_group *group,
+				     char *buf)
+{
+	char *type = "unknown\n";
+
+	if (group->default_domain) {
+		switch (group->default_domain->type) {
+		case IOMMU_DOMAIN_BLOCKED:
+			type = "blocked\n";
+			break;
+		case IOMMU_DOMAIN_IDENTITY:
+			type = "identity\n";
+			break;
+		case IOMMU_DOMAIN_UNMANAGED:
+			type = "unmanaged\n";
+			break;
+		case IOMMU_DOMAIN_DMA:
+			type = "DMA";
+			break;
+		}
+	}
+	strcpy(buf, type);
+
+	return strlen(type);
+}
+
 static IOMMU_GROUP_ATTR(name, S_IRUGO, iommu_group_show_name, NULL);
 
 static IOMMU_GROUP_ATTR(reserved_regions, 0444,
 			iommu_group_show_resv_regions, NULL);
 
+static IOMMU_GROUP_ATTR(type, 0444, iommu_group_show_type, NULL);
+
 static void iommu_group_release(struct kobject *kobj)
 {
 	struct iommu_group *group = to_iommu_group(kobj);
@@ -384,6 +412,10 @@ struct iommu_group *iommu_group_alloc(void)
 	if (ret)
 		return ERR_PTR(ret);
 
+	ret = iommu_group_create_file(group, &iommu_group_attr_type);
+	if (ret)
+		return ERR_PTR(ret);
+
 	pr_debug("Allocated group %d\n", group->id);
 
 	return group;
-- 
2.11.0


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

* Re: [PATCH 1/2] iommu: Add config option to set passthrough as default
  2018-07-11 20:59 [PATCH 1/2] iommu: Add config option to set passthrough as default Olof Johansson
  2018-07-11 20:59 ` [PATCH 2/2] iommu: add sysfs attribyte for domain type Olof Johansson
@ 2018-07-12  2:04 ` Yang, Shunyong
  1 sibling, 0 replies; 3+ messages in thread
From: Yang, Shunyong @ 2018-07-12  2:04 UTC (permalink / raw)
  To: joro, olof; +Cc: linux-kernel, iommu

Hi, Olof,

Tired of changing command line. I like this patch.

Thanks.
Shunyong. 

On Wed, 2018-07-11 at 13:59 -0700, Olof Johansson wrote:
> This allows the default behavior to be controlled by a kernel config
> option instead of changing the commandline for the kernel to include
> "iommu.passthrough=on" on machines where this is desired.
> 
> Signed-off-by: Olof Johansson <olof@lixom.net>
> ---
>  drivers/iommu/Kconfig | 10 ++++++++++
>  drivers/iommu/iommu.c |  4 ++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> index 689ffe538370..a9bb1a5b5e43 100644
> --- a/drivers/iommu/Kconfig
> +++ b/drivers/iommu/Kconfig
> @@ -60,6 +60,16 @@ config IOMMU_IO_PGTABLE_ARMV7S_SELFTEST
>  
>  endmenu
>  
> +config IOMMU_DEFAULT_PASSTHROUGH
> +	bool "IOMMU passthrough by default"
> +	depends on IOMMU_API
> +        help
> +	  Enable passthrough by default (removing the need to pass
> in
> +	  iommu.passthrough=on through command line). If this is
> enabled,
> +	  you can still disable with iommu.passthrough=off
> +
> +	  If unsure, say N here.
> +
>  config IOMMU_IOVA
>  	tristate
>  
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 63b37563db7e..ab8fc54467e0 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -36,7 +36,11 @@
>  
>  static struct kset *iommu_group_kset;
>  static DEFINE_IDA(iommu_group_ida);
> +#ifdef CONFIG_IOMMU_DEFAULT_PASSTHROUGH
> +static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_IDENTITY;
> +#else
>  static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_DMA;
> +#endif
>  
>  struct iommu_callback_data {
>  	const struct iommu_ops *ops;

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-11 20:59 [PATCH 1/2] iommu: Add config option to set passthrough as default Olof Johansson
2018-07-11 20:59 ` [PATCH 2/2] iommu: add sysfs attribyte for domain type Olof Johansson
2018-07-12  2:04 ` [PATCH 1/2] iommu: Add config option to set passthrough as default Yang, Shunyong

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox