iommu: Add config option to set passthrough as default
Subsystems (3)
PATCH 1/2 iommu: Add config option to set passthrough as default
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.
--- drivers/iommu/Kconfig | 10 ++++++++++ drivers/iommu/iommu.c | 4 ++++ 2 files changed, 14 insertions(+)
drivers/iommu/Kconfig +10 -0
@@ -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
drivers/iommu/iommu.c +4 -0
@@ -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;
Signature · 1 line
2.11.0
PATCH 2/2 iommu: add sysfs attribyte for domain type
While we could print it at setup time, this is an easier way to match each device to their default IOMMU allocation type.
--- drivers/iommu/iommu.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/iommu/iommu.c +32 -0
@@ -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;
Signature · 1 line
2.11.0
Hi, Olof,
Tired of changing command line. I like this patch.
Thanks.
Shunyong.
Quoted 49 lines · 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 <[email protected]>---
drivers/iommu/Kconfig | 10 ++++++++++
drivers/iommu/iommu.c | 4 ++++2 files changed, 14 insertions(+)drivers/iommu/Kconfig +0
-0@@ -60,6 +60,16 @@ config IOMMU_IO_PGTABLE_ARMV7S_SELFTEST
endmenudrivers/iommu/Kconfig +5
-0+config IOMMU_DEFAULT_PASSTHROUGH + bool "IOMMU passthrough by default" + depends on IOMMU_API + help + Enable passthrough by default (removing the need to passin
drivers/iommu/Kconfig +1
-0+ iommu.passthrough=on through command line). If this isenabled,
drivers/iommu/Kconfig +4
-0+ you can still disable with iommu.passthrough=off + + If unsure, say N here. +config
IOMMU_IOVA
tristatedrivers/iommu/iommu.c +0
-0@@ -36,7 +36,11 @@
static struct kset*iommu_group_kset;
staticDEFINE_IDA(iommu_group_ida);drivers/iommu/iommu.c +3
-0+#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
structiommu_callback_data{
const structiommu_ops*ops;
Joerg Roedel
maintainerHi Olof,
drivers/iommu/Kconfig config IOMMU_IO_PGTABLE_ARMV7S_SELFTEST · line 72
Quoted 10 lines · Olof Johansson
drivers/iommu/Kconfig +10
-0+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
Quoted 17 lines · Joerg Roedel
Hi Olof,
drivers/iommu/Kconfig config IOMMU_IO_PGTABLE_ARMV7S_SELFTEST · line 72
Quoted 10 lines · Olof Johansson
drivers/iommu/Kconfig +10
-0+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
PATCH 1/1 iommu: Add config option to set passthrough as default
In reply to Olof JohanssonThis 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.
---
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(-)
Documentation/admin-guide/kernel-parameters.txt +2 -1
@@ -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.
arch/x86/kernel/pci-dma.c +8 -0
@@ -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);
drivers/iommu/Kconfig +11 -0
@@ -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
drivers/iommu/iommu.c +4 -0
@@ -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;
Signature · 1 line
2.11.0