* [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
` (2 more replies)
0 siblings, 3 replies; 6+ 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 related [flat|nested] 6+ 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 [not found] ` <20180711205936.18614-1-olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org> 2 siblings, 0 replies; 6+ 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 related [flat|nested] 6+ 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 [not found] ` <20180711205936.18614-1-olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org> 2 siblings, 0 replies; 6+ messages in thread From: Yang, Shunyong @ 2018-07-12 2:04 UTC (permalink / raw) To: joro@8bytes.org, olof@lixom.net Cc: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org 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] 6+ messages in thread
[parent not found: <20180711205936.18614-1-olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org>]
* Re: [PATCH 1/2] iommu: Add config option to set passthrough as default [not found] ` <20180711205936.18614-1-olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org> @ 2018-07-20 12:16 ` Joerg Roedel [not found] ` <20180720121619.pqrgth4zxdj7zjym-zLv9SwRftAIdnm+yROfE0A@public.gmane.org> 2018-07-20 18:02 ` [PATCH] " Olof Johansson 1 sibling, 1 reply; 6+ messages in thread From: Joerg Roedel @ 2018-07-20 12:16 UTC (permalink / raw) To: Olof Johansson Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, linux-kernel-u79uwXL29TY76Z2rM5mHXA Hi Olof, On Wed, Jul 11, 2018 at 01:59:35PM -0700, Olof Johansson wrote: > +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. > + The patch is a good start, but the description above indicates that it affects all IOMMU driver, which it does not. Please make the Intel and AMD IOMMU drivers also take this option into account. Joerg ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <20180720121619.pqrgth4zxdj7zjym-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>]
* Re: [PATCH 1/2] iommu: Add config option to set passthrough as default [not found] ` <20180720121619.pqrgth4zxdj7zjym-zLv9SwRftAIdnm+yROfE0A@public.gmane.org> @ 2018-07-20 17:37 ` Olof Johansson 0 siblings, 0 replies; 6+ messages in thread From: Olof Johansson @ 2018-07-20 17:37 UTC (permalink / raw) To: Joerg Roedel Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Linux Kernel Mailing List On Fri, Jul 20, 2018 at 5:16 AM, Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org> wrote: > Hi Olof, > > On Wed, Jul 11, 2018 at 01:59:35PM -0700, Olof Johansson wrote: >> +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. >> + > > The patch is a good start, but the description above indicates that it > affects all IOMMU driver, which it does not. Please make the Intel and > AMD IOMMU drivers also take this option into account. It looks like it should make the AMD driver should honor it, since it uses the generic infrastructure for domain types? But it also shares iommu_pass_through variable usage with Intel, so if I change it over there it'll be covered for sure. One unfortunate thing here is the divergence in command line options between arm64 and x86. I'll add a 'iommu=nopt' on x86 so it can be turned off at runtime if enabled in config, but it'd be nice to also have it adhere to the .passthrough options. That's a larger topic than just this specific patch though. Posting new patch shortly. -Olof ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] iommu: Add config option to set passthrough as default [not found] ` <20180711205936.18614-1-olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org> 2018-07-20 12:16 ` Joerg Roedel @ 2018-07-20 18:02 ` Olof Johansson 1 sibling, 0 replies; 6+ messages in thread From: Olof Johansson @ 2018-07-20 18:02 UTC (permalink / raw) To: Joerg Roedel Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, linux-kernel-u79uwXL29TY76Z2rM5mHXA 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" or "iommu=pt" on machines where this is desired. Likewise, for machines where this config option is enabled, it can be disabled at boot time with "iommu.passthrough=off" or "iommu=nopt". Also corrected iommu=pt documentation for IA-64, since it has no code that parses iommu= at all. Signed-off-by: Olof Johansson <olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org> --- Chances since v1: - Added analogous behavior for Intel/AMD - Added iommu=nopt for x86 and updated docs Documentation/admin-guide/kernel-parameters.txt | 3 ++- arch/x86/kernel/pci-dma.c | 8 ++++++++ drivers/iommu/Kconfig | 11 +++++++++++ drivers/iommu/iommu.c | 4 ++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index c9dbdf1009f1..4c822aa50f13 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1744,7 +1744,8 @@ merge nomerge soft - pt [x86, IA-64] + pt [x86] + nopt [x86] nobypass [PPC/POWERNV] Disable IOMMU bypass, using IOMMU for PCI devices. diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index ab5d9dd668d2..0acb135de7fb 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c @@ -40,8 +40,14 @@ int iommu_detected __read_mostly = 0; * devices and allow every device to access to whole physical memory. This is * useful if a user wants to use an IOMMU only for KVM device assignment to * guests and not for driver dma translation. + * It is also possible to disable by default in kernel config, and enable with + * iommu=nopt at boot time. */ +#ifdef CONFIG_IOMMU_DEFAULT_PASSTHROUGH +int iommu_pass_through __read_mostly = 1; +#else int iommu_pass_through __read_mostly; +#endif extern struct iommu_table_entry __iommu_table[], __iommu_table_end[]; @@ -135,6 +141,8 @@ static __init int iommu_setup(char *p) #endif if (!strncmp(p, "pt", 2)) iommu_pass_through = 1; + if (!strncmp(p, "nopt", 4)) + iommu_pass_through = 0; gart_parse_options(p); diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 568ae81b0e99..1813319c8342 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -70,6 +70,17 @@ config IOMMU_DEBUGFS debug/iommu directory, and then populate a subdirectory with entries as required. +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 or iommu=pt through command line. If this + is enabled, you can still disable with iommu.passthrough=off + or iommu=nopt depending on the architecture. + + If unsure, say N here. + config IOMMU_IOVA tristate diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index d227b864a109..6f8f59684def 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 related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-07-20 18:02 UTC | newest]
Thread overview: 6+ 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
[not found] ` <20180711205936.18614-1-olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org>
2018-07-20 12:16 ` Joerg Roedel
[not found] ` <20180720121619.pqrgth4zxdj7zjym-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-07-20 17:37 ` Olof Johansson
2018-07-20 18:02 ` [PATCH] " Olof Johansson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox