Skip to contentSkip to conversation

Enhance IOMMU default DMA mode build options

PATCH Superseded John Garry 3 participants 8 messages Jun 3, 2021 – Jun 4, 2021

Subsystems (3)

v10 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

John Garry

author
#0 lore raw

v10 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 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       | 35 +++++++++++++++++++++++++++++++++++
 drivers/iommu/amd/init.c    |  3 ++-
 drivers/iommu/intel/iommu.c |  2 +-
 drivers/iommu/iommu.c       |  3 ++-
 4 files changed, 40 insertions(+), 3 deletions(-)
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH v10 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 an choice, as they are mutually-exclusive.

[jpg: Make choice between strict and lazy only (and not passthrough)]
---
 drivers/iommu/Kconfig | 34 ++++++++++++++++++++++++++++++++++
 drivers/iommu/iommu.c |  3 ++-
 2 files changed, 36 insertions(+), 1 deletion(-)
drivers/iommu/Kconfig +34 -0
index 1f111b399bca..12ef90256df8 100644
@@ -90,6 +90,40 @@ config IOMMU_DEFAULT_PASSTHROUGH
 
 	  If unsure, say N here.
 
+choice
+	prompt "IOMMU default DMA mode"
+	depends on IOMMU_API
+
+	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 the two above, but it maybe slower in some
+	  high performace scenarios.
+
+endchoice
+
 config OF_IOMMU
 	def_bool y
 	depends on OF && IOMMU_API
drivers/iommu/iommu.c +2 -1
index 966426a96520..177b0dafc535 100644
@@ -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
#2 lore raw

Re: [PATCH v10 1/3] iommu: Enhance IOMMU default DMA mode build options

Quoted 42 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 an choice, as they are mutually-exclusive.

[jpg: Make choice between strict and lazy only (and not passthrough)]
---
 drivers/iommu/Kconfig | 34 ++++++++++++++++++++++++++++++++++
 drivers/iommu/iommu.c |  3 ++-
 2 files changed, 36 insertions(+), 1 deletion(-)
drivers/iommu/Kconfig +20 -0
index 1f111b399bca..12ef90256df8 100644
@@ -90,6 +90,40 @@ config IOMMU_DEFAULT_PASSTHROUGH
 
 	  If unsure, say N here.
 
+choice
+	prompt "IOMMU default DMA mode"
+	depends on IOMMU_API
+
+	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

drivers/iommu/Kconfig config IOMMU_DEFAULT_PASSTHROUGH · line 122

Quoted 10 lines
drivers/iommu/Kconfig +10 -0
+	  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 the two above, but it maybe slower in some

There don't seem to be two above?

drivers/iommu/Kconfig config IOMMU_DEFAULT_PASSTHROUGH · line 123

Quoted 1 line
drivers/iommu/Kconfig +1 -0
+	  high performace scenarios.

performance

drivers/iommu/Kconfig config IOMMU_DEFAULT_PASSTHROUGH · line 125

Quoted 2 lines
drivers/iommu/Kconfig +2 -0
+
+endchoice

thanks.

Signature · 1 line
~Randy
author
#3 lore raw

Re: [PATCH v10 1/3] iommu: Enhance IOMMU default DMA mode build options

Quoted 10 lines · Randy Dunlap

drivers/iommu/Kconfig config IOMMU_DEFAULT_PASSTHROUGH · line 122

Quoted 8 lines
drivers/iommu/Kconfig +8 -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 the two above, but it maybe slower in some

There don't seem to be two above?

Right, it's a remnant from a previous version - will fix, pending other reviews

Quoted 3 lines

drivers/iommu/Kconfig config IOMMU_DEFAULT_PASSTHROUGH · line 123

Quoted 1 line
drivers/iommu/Kconfig +1 -0
+	  high performace scenarios.

performance

ok

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+endchoice

Thanks!

#4 lore raw

Re: [PATCH v10 1/3] iommu: Enhance IOMMU default DMA mode build options

In reply to John Garry
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 an choice, as they are mutually-exclusive.

[jpg: Make choice between strict and lazy only (and not passthrough)]
---
 drivers/iommu/Kconfig | 34 ++++++++++++++++++++++++++++++++++
 drivers/iommu/iommu.c |  3 ++-
 2 files changed, 36 insertions(+), 1 deletion(-)
drivers/iommu/Kconfig +0 -0
index 1f111b399bca..12ef90256df8 100644

drivers/iommu/Kconfig config IOMMU_DEFAULT_PASSTHROUGH · line 95

Quoted 6 lines
drivers/iommu/Kconfig +3 -0
@@ -90,6 +90,40 @@ config IOMMU_DEFAULT_PASSTHROUGH
 
 	  If unsure, say N here.
 
+choice
+	prompt "IOMMU default DMA mode"
+	depends on IOMMU_API

config INTEL_IOMMU

        depends on PCI_MSI && ACPI && (X86 || IA64)

config AMD_IOMMU

        depends on X86_64 && PCI && ACPI && HAVE_CMPXCHG_DOUBLE

config ARM_SMMU_V3
depends on ARM64

"depends on ARM_SMMU_V3 || INTEL_IOMMU || AMD_IOMMU" may need to be added, because it doesn't work on other platforms.

or "depends on X86 || IA64 || X86_64 || ARM64"

Quoted 39 lines
drivers/iommu/Kconfig +31 -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.
+
+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 the two above, but it maybe slower in some
+	  high performace scenarios.
+
+endchoice
+
 config OF_IOMMU
 	def_bool y
 	depends on OF && IOMMU_API
drivers/iommu/iommu.c +0 -0
index 966426a96520..177b0dafc535 100644

drivers/iommu/iommu.c static struct kset *iommu_group_kset; · line 33

Quoted 6 lines
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);

Currently, a maximum of 100 columns are allowed in a row.

Quoted 4 lines
drivers/iommu/iommu.c +0 -0
 static u32 iommu_cmd_line __read_mostly;
 
 struct iommu_group {
author
#5 lore raw

Re: [PATCH v10 1/3] iommu: Enhance IOMMU default DMA mode build options

Quoted 12 lines

drivers/iommu/Kconfig config IOMMU_DEFAULT_PASSTHROUGH · line 95

Quoted 7 lines

If unsure, say N here.

drivers/iommu/Kconfig +3 -0
+choice
+	prompt "IOMMU default DMA mode"
+	depends on IOMMU_API

config INTEL_IOMMU

         depends on PCI_MSI && ACPI && (X86 || IA64)

config AMD_IOMMU

Quoted 8 lines
         depends on X86_64 && PCI && ACPI && HAVE_CMPXCHG_DOUBLE

config ARM_SMMU_V3
depends on ARM64

"depends on ARM_SMMU_V3 || INTEL_IOMMU || AMD_IOMMU" may need to be added, because it doesn't work on other platforms.

or "depends on X86 || IA64 || X86_64 || ARM64"

I suppose so. But I don't think that any other archs use the value from iommu_dma_strict anyway.

Quoted 42 lines
Quoted 42 lines
drivers/iommu/Kconfig +31 -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.
+
+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 the two above, but it maybe slower in some
+	  high performace scenarios.
+
+endchoice
+
  config OF_IOMMU
  	def_bool y
  	depends on OF && IOMMU_API
drivers/iommu/iommu.c +0 -0
index 966426a96520..177b0dafc535 100644
@@ -29,7 +29,8 @@ static struct kset *iommu_group_kset;
  static DEFINE_IDA(iommu_group_ida);
 
Quoted 6 lines

drivers/iommu/iommu.c static struct kset *iommu_group_kset; · line 33

Quoted 4 lines
drivers/iommu/iommu.c +2 -1
  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);

Currently, a maximum of 100 columns are allowed in a row.

Sure, but some people still prefer limiting to 80, and codingstyle doc mentions a preference for 80.

But if you really think I should change, then that's ok.

Thanks,
John

author
#6 lore raw

PATCH v10 2/3 iommu/vt-d: Add support for IOMMU default DMA mode build options

In reply to John Garry

From: 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
index 12ef90256df8..03c88cee806f 100644
@@ -94,6 +94,7 @@ choice
 	prompt "IOMMU default DMA mode"
 	depends on IOMMU_API
 
+	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
index 708f430af1c4..0d4d2c18ee77 100644
@@ -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 · 1 line
2.26.2
author
#7 lore raw

PATCH v10 3/3 iommu/amd: Add support for IOMMU default DMA mode build options

In reply to John Garry

From: Zhen Lei <[email protected]>

The default DMA mode is 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.

[jpg: Rebase for relocated file]
---
 drivers/iommu/Kconfig    | 2 +-
 drivers/iommu/amd/init.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/iommu/Kconfig +1 -1
index 03c88cee806f..50c1477a6c2e 100644
@@ -94,7 +94,7 @@ choice
 	prompt "IOMMU default DMA mode"
 	depends on IOMMU_API
 
-	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
index d006724f4dc2..af662fc37cbe 100644
@@ -160,7 +160,8 @@ u16 amd_iommu_last_bdf;			/* largest PCI device id we have
 					   to 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 · 1 line
2.26.2