Disable IOMMU Passthrough when SME is active
Joerg Roedel
maintainercover Disable IOMMU Passthrough when SME is active
Hi,
here is a small patch-set to disable IOMMU Passthrough mode when SME is active even when CONFIG_IOMMU_DEFAULT_PASSTHROUGH=y is set.
The reason for that change is that SME with passthrough mode turned out to be fragile with devices requiring SWIOTLB, mainly because SWIOTLB has a maximum allocation size of 256kb and a limit overall size of the bounce buffer.
Therefore having IOMMU in translation mode by default is better when SME is active on a system.
Please review.
Thanks,
Joerg
Joerg Roedel (3):
iommu: Print default domain type on boot
iommu: Set default domain type at runtime
iommu: Disable passthrough mode when SME is active
drivers/iommu/iommu.c | 48 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-)
Signature · 1 line
2.17.1
Joerg Roedel
maintainerPATCH 1/3 iommu: Print default domain type on boot
From: Joerg Roedel <[email protected]>
Introduce a subsys_initcall for IOMMU code and use it to print the default domain type at boot.
--- drivers/iommu/iommu.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
drivers/iommu/iommu.c +29 -1
@@ -80,12 +80,40 @@ struct iommu_group_attribute iommu_group_attr_##_name = \static LIST_HEAD (iommu_device_list);static DEFINE_SPINLOCK (iommu_device_lock); +/* +* Use a function instead of an array here because the domain-type is a +* bit-field, so an array would waste memory. +*/ +static const char *iommu_domain_type_str (unsigned int t) +{ +switch (t) { +case IOMMU_DOMAIN_BLOCKED : +return "Blocked" ; +case IOMMU_DOMAIN_IDENTITY : +return "Passthrough" ; +case IOMMU_DOMAIN_UNMANAGED : +return "Unmanaged" ; +case IOMMU_DOMAIN_DMA : +return "Translated" ; +default : +return "Unknown" ; + } +} + +static int __init iommu_subsys_init (void ) +{ +pr_info ("Default domain type: %s\n" , +iommu_domain_type_str (iommu_def_domain_type)); + +return 0 ; +} +subsys_initcall (iommu_subsys_init); +int iommu_device_register (struct iommu_device *iommu) {spin_lock (&iommu_device_lock);list_add_tail (&iommu->list, &iommu_device_list);spin_unlock (&iommu_device_lock); -return 0 ; }
Signature · 1 line
2.17.1
Joerg Roedel
maintainerPATCH 2/3 iommu: Set default domain type at runtime
In reply to Joerg RoedelFrom: Joerg Roedel <[email protected]>
Set the default domain-type at runtime, not at compile-time. This keeps default domain type setting in one place when we have to change it at runtime.
--- drivers/iommu/iommu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/iommu/iommu.c +7 -5
@@ -26,11 +26,8 @@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 + +static unsigned int iommu_def_domain_type__read_mostly ;static bool iommu_dma_strict__read_mostly = true;struct iommu_group {
@@ -102,6 +99,11 @@ static const char *iommu_domain_type_str(unsigned int t)static int __init iommu_subsys_init (void ) { +if (IS_ENABLED (CONFIG_IOMMU_DEFAULT_PASSTHROUGH )) + iommu_def_domain_type =IOMMU_DOMAIN_IDENTITY ; +else + iommu_def_domain_type =IOMMU_DOMAIN_DMA ; +pr_info ("Default domain type: %s\n" ,iommu_domain_type_str (iommu_def_domain_type));
Signature · 1 line
2.17.1
Joerg Roedel
maintainerPATCH 3/3 iommu: Disable passthrough mode when SME is active
In reply to Joerg RoedelFrom: Joerg Roedel <[email protected]>
Using Passthrough mode when SME is active causes certain devices to use the SWIOTLB bounce buffer. The bounce buffer code has an upper limit of 256kb for the size of DMA allocations, which is too small for certain devices and causes them to fail.
With this patch we enable IOMMU by default when SME is active in the system, making the default configuration work for more systems than it does now.
Users that don't want IOMMUs to be enabled still can disable them with kernel parameters.
--- drivers/iommu/iommu.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/iommu/iommu.c +6 -0
@@ -104,6 +104,12 @@ static int __init iommu_subsys_init(void)else iommu_def_domain_type =IOMMU_DOMAIN_DMA ; +if ((iommu_def_domain_type ==IOMMU_DOMAIN_IDENTITY ) && +sme_active ()) { +pr_info ("SME detected - Disabling default IOMMU passthrough\n" ); + iommu_def_domain_type =IOMMU_DOMAIN_DMA ; + } +pr_info ("Default domain type: %s\n" ,iommu_domain_type_str (iommu_def_domain_type));
Signature · 1 line
2.17.1
Re: [PATCH 3/3] iommu: Disable passthrough mode when SME is active
Quoted 25 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
Using Passthrough mode when SME is active causes certain devices to use the SWIOTLB bounce buffer. The bounce buffer code has an upper limit of 256kb for the size of DMA allocations, which is too small for certain devices and causes them to fail.
With this patch we enable IOMMU by default when SME is active in the system, making the default configuration work for more systems than it does now.
Users that don't want IOMMUs to be enabled still can disable them with kernel parameters.
Signed-off-by Joerg Roedel <[email protected]>--- drivers/iommu/iommu.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/iommu/iommu.c +0
-0
drivers/iommu/iommu.c static int __init iommu_subsys_init(void) · line 110
Quoted 7 lines
drivers/iommu/iommu.c +4
-0@@ -104,6 +104,12 @@ static int __init iommu_subsys_init(void)else iommu_def_domain_type =IOMMU_DOMAIN_DMA ; +if ((iommu_def_domain_type ==IOMMU_DOMAIN_IDENTITY ) && +sme_active ()) { +pr_info ("SME detected - Disabling default IOMMU passthrough\n" ); + iommu_def_domain_type =IOMMU_DOMAIN_DMA ;
Should this also clear the iommu_pass_through variable (the one set by the iommu kernel parameter in arch/x86/kernel/pci-dma.c)?
I guess this is more applicable to the original patchset that created the CONFIG_IOMMU_DEFAULT_PASSTHROUGH option, but should the default passthrough support be modified so that you don't have to specify multiple kernel parameters to change it?
Right now, if CONFIG_IOMMU_DEFAULT_PASSTHROUGH is set to yes, you can't just specify iommu=nopt to enable the IOMMU. You have to also specify iommu.passthrough=0. Do we want to fix that so that just specifying iommu=nopt or iommu.passthrough=0 does what is needed?
Thanks,
Tom
drivers/iommu/iommu.c static int __init iommu_subsys_init(void) · line 115
Quoted 6 lines
drivers/iommu/iommu.c +2
-0+ } +pr_info ("Default domain type: %s\n" ,iommu_domain_type_str (iommu_def_domain_type));
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerRe: [PATCH 3/3] iommu: Disable passthrough mode when SME is active
Hey Tom,
Quoted 8 lines · Thomas
drivers/iommu/iommu.c static int __init iommu_subsys_init(void) · line 110
Quoted 4 lines · Joerg Roedel
drivers/iommu/iommu.c +4
-0+if ((iommu_def_domain_type ==IOMMU_DOMAIN_IDENTITY ) && +sme_active ()) { +pr_info ("SME detected - Disabling default IOMMU passthrough\n" ); + iommu_def_domain_type =IOMMU_DOMAIN_DMA ;Should this also clear the
iommu_pass_throughvariable (the one set by the iommu kernel parameter inarch/x86/kernel/pci-dma.c)?
This code is used on different architectures, so I can't cleanly access architecture specific variables here.
Quoted 9 lines
I guess this is more applicable to the original patchset that created the
CONFIG_IOMMU_DEFAULT_PASSTHROUGHoption, but should the default passthrough support be modified so that you don't have to specify multiple kernel parameters to change it?Right now, if
CONFIG_IOMMU_DEFAULT_PASSTHROUGHis set to yes, you can't just specify iommu=nopt to enable the IOMMU. You have to also specify iommu.passthrough=0. Do we want to fix that so that just specifying iommu=nopt or iommu.passthrough=0 does what is needed?
Yeah, that is currently a mess and I think cleaning that up is at least partly in the scope of this patch-set. I'll look into that next week.
Regards,
Joerg