Enhance IOMMU default DMA mode build options
Subsystems (3)
v11 cover Enhance IOMMU default DMA mode build options
This is a reboot of Zhen Lei's series from a couple of years ago, which never made it across the line.
I still think that it has some value, so taking up the mantle.
Motivation:
Allow lazy mode be default mode for DMA domains for all ARCHs, and not only those who hardcode it (to be lazy). For ARM64, currently we must use a kernel command line parameter to use lazy mode, which is less than ideal.
Differences to v10:
- Rebase to v5.13-rc4
- Correct comment and typo in Kconfig (Randy)
- Make Kconfig choice depend on relevant architectures
Differences to v9:
https://lore.kernel.org/linux-iommu/[email protected]/#t
- Rebase to v5.13-rc2
- Remove CONFIG_IOMMU_DEFAULT_PASSTHROUGH from choice:
Since we can dynamically change default domain of group, lazy or strict and passthrough are not mutually exclusive
- Drop ia64 patch, which I don't think was ever required
- Drop "x86/dma: use IS_ENABLED() to simplify the code", which is no longer required
- Drop s390/pci patch, as this arch does not use CONFIG_IOMMU_API or even already honour CONFIG_IOMMU_DEFAULT_PASSTHROUGH
https://lore.kernel.org/linux-iommu/[email protected]/
- Drop powernv/iommu patch, as I no longer think that it is relevant
https://lore.kernel.org/linux-iommu/[email protected]/
- Some tidying
Zhen Lei (3):
iommu: Enhance IOMMU default DMA mode build options iommu/vt-d: Add support for IOMMU default DMA mode build options iommu/amd: Add support for IOMMU default DMA mode build options
drivers/iommu/Kconfig | 36 ++++++++++++++++++++++++++++++++++++ drivers/iommu/amd/init.c | 3 ++- drivers/iommu/intel/iommu.c | 2 +- drivers/iommu/iommu.c | 3 ++- 4 files changed, 41 insertions(+), 3 deletions(-)
Signature · 1 line
2.26.2
PATCH v11 1/3 iommu: Enhance IOMMU default DMA mode build options
From: Zhen Lei <[email protected]>
First, add build options IOMMU_DEFAULT_{LAZY|STRICT}, so that we have the opportunity to set {lazy|strict} mode as default at build time. Then put the two config options in a choice, as they are mutually exclusive.
--- drivers/iommu/Kconfig | 35 +++++++++++++++++++++++++++++++++++ drivers/iommu/iommu.c | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-)
drivers/iommu/Kconfig +35 -0
@@ -90,6 +90,41 @@ config IOMMU_DEFAULT_PASSTHROUGH If unsure, say N here. +choice + prompt "IOMMU default DMA mode" + depends on IOMMU_API + depends on X86 || IA64 || X86_64 || ARM || ARM64 + + default IOMMU_DEFAULT_STRICT + help + This option allows an IOMMU DMA mode to be chosen at build time, to + override the default DMA mode of each ARCH, removing the need to + pass in kernel parameters through command line. It is still possible + to provide ARCH-specific or common boot options to override this + option. + + If unsure, keep the default. + +config IOMMU_DEFAULT_LAZY + bool "lazy" + help + Support lazy mode, where for every IOMMU DMA unmap operation, the + flush operation of IOTLB and the free operation of IOVA are deferred. + They are only guaranteed to be done before the related IOVA will be + reused. + +config IOMMU_DEFAULT_STRICT + bool "strict" + help + For every IOMMU DMA unmap operation, the flush operation of IOTLB and + the free operation of IOVA are guaranteed to be done in the unmap + function. + + This mode is safer than lazy mode, but it may be slower in some high + performance scenarios. + +endchoice + config OF_IOMMU def_bool y depends on OF && IOMMU_API
drivers/iommu/iommu.c +2 -1
@@ -29,7 +29,8 @@ static struct kset *iommu_group_kset;static DEFINE_IDA (iommu_group_ida);static unsigned int iommu_def_domain_type__read_mostly ; -static bool iommu_dma_strict__read_mostly = true; +static bool iommu_dma_strict__read_mostly = +IS_ENABLED (CONFIG_IOMMU_DEFAULT_STRICT );static u32 iommu_cmd_line__read_mostly ;struct iommu_group {
Signature · 1 line
2.26.2
Robin Murphy
reviewerRe: [PATCH v11 1/3] iommu: Enhance IOMMU default DMA mode build options
Quoted 19 lines · John Garry
From: Zhen Lei <[email protected]>
First, add build options IOMMU_DEFAULT_{LAZY|STRICT}, so that we have the opportunity to set {lazy|strict} mode as default at build time. Then put the two config options in a choice, as they are mutually exclusive.
[jpg: Make choice between strict and lazy only (and not passthrough)]Signed-off-by Zhen Lei <[email protected]>Signed-off-by John Garry <[email protected]>--- drivers/iommu/Kconfig | 35 +++++++++++++++++++++++++++++++++++ drivers/iommu/iommu.c | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-)drivers/iommu/Kconfig +0
-0
drivers/iommu/Kconfig config IOMMU_DEFAULT_PASSTHROUGH · line 96
Quoted 7 lines
drivers/iommu/Kconfig +4
-0@@ -90,6 +90,41 @@ config IOMMU_DEFAULT_PASSTHROUGH If unsure, say N here. +choice + prompt "IOMMU default DMA mode" + depends on IOMMU_API + depends on X86 || IA64 || X86_64 || ARM || ARM64
Simply "depends on IOMMU_DMA" should suffice, since that's now the only place where flush queues matter.
Quoted 18 lines
drivers/iommu/Kconfig +18
-0+ + default IOMMU_DEFAULT_STRICT + help + This option allows an IOMMU DMA mode to be chosen at build time, to + override the default DMA mode of each ARCH, removing the need to + pass in kernel parameters through command line. It is still possible + to provide ARCH-specific or common boot options to override this + option. + + If unsure, keep the default. + +config IOMMU_DEFAULT_LAZY + bool "lazy" + help + Support lazy mode, where for every IOMMU DMA unmap operation, the + flush operation of IOTLB and the free operation of IOVA are deferred. + They are only guaranteed to be done before the related IOVA will be + reused.
drivers/iommu/Kconfig config IOMMU_DEFAULT_PASSTHROUGH · line 124
Quoted 10 lines
drivers/iommu/Kconfig +10
-0+ +config IOMMU_DEFAULT_STRICT + bool "strict" + help + For every IOMMU DMA unmap operation, the flush operation of IOTLB and + the free operation of IOVA are guaranteed to be done in the unmap + function. + + This mode is safer than lazy mode, but it may be slower in some high + performance scenarios.
FWIW, as an end user who doesn't care much about the implementation details I'd probably appreciate the actual implications being clearer, i.e. what does "safer" mean in practice and what is it relative to?
Robin.
Quoted 21 lines
drivers/iommu/Kconfig +3
-0+ +endchoice + config OF_IOMMU def_bool y depends on OF && IOMMU_APIdrivers/iommu/iommu.c +2
-1@@ -29,7 +29,8 @@ static struct kset *iommu_group_kset;static DEFINE_IDA (iommu_group_ida);static unsigned int iommu_def_domain_type__read_mostly ; -static bool iommu_dma_strict__read_mostly = true; +static bool iommu_dma_strict__read_mostly = +IS_ENABLED (CONFIG_IOMMU_DEFAULT_STRICT );static u32 iommu_cmd_line__read_mostly ;struct iommu_group {
Re: [PATCH v11 1/3] iommu: Enhance IOMMU default DMA mode build options
Quoted 15 lines · Robin Murphy
Quoted 14 lines · John Garry
From: Zhen Lei <[email protected]>
First, add build options IOMMU_DEFAULT_{LAZY|STRICT}, so that we have the opportunity to set {lazy|strict} mode as default at build time. Then put the two config options in a choice, as they are mutually exclusive.
[jpg: Make choice between strict and lazy only (and not passthrough)]Signed-off-by Zhen Lei <[email protected]>Signed-off-by John Garry <[email protected]>---
drivers/iommu/Kconfig| 35 +++++++++++++++++++++++++++++++++++drivers/iommu/iommu.c| 3 ++-2 files changed, 37 insertions(+), 1 deletion(-)
Quoted 12 lines
Quoted 10 lines
drivers/iommu/Kconfig +0
-0@@ -90,6 +90,41 @@ config IOMMU_DEFAULT_PASSTHROUGHIf unsure, say N here.
+choice
+ prompt "IOMMU default DMA mode"
+ depends onIOMMU_API
+ depends on X86 || IA64 ||X86_64|| ARM || ARM64Simply "depends on
IOMMU_DMA" should suffice, since that's now the only place where flush queues matter.
I suppose so.
Configs ARM64, AMD_IOMMU, and INTEL_IOMMU all select this.
Quoted 29 lines
Quoted 29 lines
+
+ defaultIOMMU_DEFAULT_STRICT
+ help
+ This option allows an IOMMU DMA mode to be chosen at build time, to
+ override the default DMA mode of each ARCH, removing the need to + pass in kernel parameters through command line. It is still possible
+ to provide ARCH-specific or common boot options to override this + option.drivers/iommu/Kconfig +8
-0+ + If unsure, keep the default. + +config IOMMU_DEFAULT_LAZY + bool "lazy" + help + Support lazy mode, where for every IOMMU DMA unmap operation, the + flush operation of IOTLB and the free operation of IOVA aredeferred.
+ They are only guaranteed to be done before the related IOVA will be
+ reused.drivers/iommu/Kconfig +5
-0+ +config IOMMU_DEFAULT_STRICT + bool "strict" + help + For every IOMMU DMA unmap operation, the flush operation ofIOTLB and
Quoted 9 lines
Quoted 6 lines
+ the free operation of IOVA are guaranteed to be done in the unmap + function.
+
+ This mode is safer than lazy mode, but it may be slower in some high
+ performance scenarios.FWIW, as an end user who doesn't care much about the implementation details I'd probably appreciate the actual implications being clearer, i.e. what does "safer" mean in practice and what is it relative to?
Fine, I can mention that lazy mode means that we have reduced device isolation and a dangerous window can be created between device driver DMA unmap and zapping the mapping in the IOMMU; however still much safer than passthrough/no IOMMU, which means no isolation at all.
Thanks,
John
PATCH v11 2/3 iommu/vt-d: Add support for IOMMU default DMA mode build options
In reply to John GarryFrom: Zhen Lei <[email protected]>
Make IOMMU_DEFAULT_LAZY default for when INTEL_IOMMU config is set, and make intel_iommu_strict initially hold value of IS_ENABLED(CONFIG_IOMMU_DEFAULT_STRICT).
--- drivers/iommu/Kconfig | 1 + drivers/iommu/intel/iommu.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/Kconfig +1 -0
@@ -95,6 +95,7 @@ choice depends on IOMMU_API depends on X86 || IA64 || X86_64 || ARM || ARM64 + default IOMMU_DEFAULT_LAZY if INTEL_IOMMU default IOMMU_DEFAULT_STRICT help This option allows an IOMMU DMA mode to be chosen at build time, to
drivers/iommu/intel/iommu.c +1 -1
@@ -360,7 +360,7 @@ int intel_iommu_enabled = 0;EXPORT_SYMBOL_GPL (intel_iommu_enabled);static int dmar_map_gfx =1 ; -static int intel_iommu_strict; +static int intel_iommu_strict =IS_ENABLED (CONFIG_IOMMU_DEFAULT_STRICT );static int intel_iommu_superpage =1 ;static int iommu_identity_mapping;static int iommu_skip_te_disable;
Signature · 6 lines
2.26.2 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH v11 3/3 iommu/amd: Add support for IOMMU default DMA mode build options
In reply to John GarryFrom: Zhen Lei <[email protected]>
The default DMA mode lazy, but allow this to be set to strict mode at build time. It may still be overridden by the relevant boot option.
Also make IOMMU_DEFAULT_LAZY default for when AMD_IOMMU config is set.
--- drivers/iommu/Kconfig | 2 +- drivers/iommu/amd/init.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/iommu/Kconfig +1 -1
@@ -95,7 +95,7 @@ choice depends on IOMMU_API depends on X86 || IA64 || X86_64 || ARM || ARM64 - default IOMMU_DEFAULT_LAZY if INTEL_IOMMU + default IOMMU_DEFAULT_LAZY if (AMD_IOMMU || INTEL_IOMMU) default IOMMU_DEFAULT_STRICT help This option allows an IOMMU DMA mode to be chosen at build time, to
drivers/iommu/amd/init.c +2 -1
@@ -160,7 +160,8 @@ u16 amd_iommu_last_bdf; /* largest PCI device id we haveto handle */ LIST_HEAD (amd_iommu_unity_map);/* a list of required unity mappings we find in ACPI */ -bool amd_iommu_unmap_flush;/* if true, flush on every unmap */ +/* if true, flush on every unmap */ +bool amd_iommu_unmap_flush =IS_ENABLED (CONFIG_IOMMU_DEFAULT_STRICT );LIST_HEAD (amd_iommu_list);/* list of all AMD IOMMUs in the system */
Signature · 6 lines
2.26.2 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerHi John,
Quoted 4 lines · John Garry
Zhen Lei (3):
iommu: Enhance IOMMU default DMA mode build options iommu/vt-d: Add support for IOMMU default DMA mode build options iommu/amd: Add support for IOMMU default DMA mode build options
So I like the idea, but can we go a step further and get (mostly) rid of the driver-specific setup code for lazy/non-lazy mode? This can happen in the dma-iommu code and the drivers only need to keep the support for their legacy command line options.
Regards,
Joerg
Quoted 9 lines · Joerg Roedel
Quoted 4 lines · John Garry
Zhen Lei (3):
iommu: Enhance IOMMU default DMA mode build options iommu/vt-d: Add support for IOMMU default DMA mode build options iommu/amd: Add support for IOMMU default DMA mode build optionsSo I like the idea, but can we go a step further and get (mostly) rid of the driver-specific setup code for lazy/non-lazy mode? This can happen in the dma-iommu code and the drivers only need to keep the support for their legacy command line options.
The AMD driver just maintains a flag and a print for the strict mode setting.
The Intel driver still maintains some lazy vs strict config, depending on the platform:
- DMAR caching mode set means that we enforce strict mode globally
- workaround for ironlake gpu means that we enforce strict mode globally
So there isn't much driver-specific setup remaining, and I can't see the intel stuff being moved into dma-iommu.c or asbtracted (for that).
We could prob replace the driver-specific logs with new logs in iommu.c, and do away with maintaining the proprietary driver strict mode flags. That's if we're ok with replacing the driver-specific logs, though.
Thanks,
John