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/20190613084240.16768-1-thunder.leizhen@huawei.com/#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/20190613084240.16768-4-thunder.leizhen@huawei.com/ - Drop powernv/iommu patch, as I no longer think that it is relevant https://lore.kernel.org/linux-iommu/20190613084240.16768-5-thunder.leizhen@huawei.com/ - 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(-) -- 2.26.2
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/20190613084240.16768-1-thunder.leizhen@huawei.com/#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/20190613084240.16768-4-thunder.leizhen@huawei.com/ - Drop powernv/iommu patch, as I no longer think that it is relevant https://lore.kernel.org/linux-iommu/20190613084240.16768-5-thunder.leizhen@huawei.com/ - 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(-) -- 2.26.2 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
From: Zhen Lei <thunder.leizhen@huawei.com> 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)] Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> Signed-off-by: John Garry <john.garry@huawei.com> --- drivers/iommu/Kconfig | 34 ++++++++++++++++++++++++++++++++++ drivers/iommu/iommu.c | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 1f111b399bca..12ef90256df8 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -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 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 966426a96520..177b0dafc535 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -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 { -- 2.26.2
From: Zhen Lei <thunder.leizhen@huawei.com> 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)] Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> Signed-off-by: John Garry <john.garry@huawei.com> --- drivers/iommu/Kconfig | 34 ++++++++++++++++++++++++++++++++++ drivers/iommu/iommu.c | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 1f111b399bca..12ef90256df8 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -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 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 966426a96520..177b0dafc535 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -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 { -- 2.26.2 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
From: Zhen Lei <thunder.leizhen@huawei.com> 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). Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> Signed-off-by: John Garry <john.garry@huawei.com> --- drivers/iommu/Kconfig | 1 + drivers/iommu/intel/iommu.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 12ef90256df8..03c88cee806f 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -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 diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 708f430af1c4..0d4d2c18ee77 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -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; -- 2.26.2
From: Zhen Lei <thunder.leizhen@huawei.com> 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). Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> Signed-off-by: John Garry <john.garry@huawei.com> --- drivers/iommu/Kconfig | 1 + drivers/iommu/intel/iommu.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 12ef90256df8..03c88cee806f 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -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 diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 708f430af1c4..0d4d2c18ee77 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -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; -- 2.26.2 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
From: Zhen Lei <thunder.leizhen@huawei.com> 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] Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> Signed-off-by: John Garry <john.garry@huawei.com> --- drivers/iommu/Kconfig | 2 +- drivers/iommu/amd/init.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 03c88cee806f..50c1477a6c2e 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -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 diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index d006724f4dc2..af662fc37cbe 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -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 */ -- 2.26.2
From: Zhen Lei <thunder.leizhen@huawei.com> 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] Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> Signed-off-by: John Garry <john.garry@huawei.com> --- drivers/iommu/Kconfig | 2 +- drivers/iommu/amd/init.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 03c88cee806f..50c1477a6c2e 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -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 diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index d006724f4dc2..af662fc37cbe 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -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 */ -- 2.26.2 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
On 6/3/21 6:58 AM, John Garry wrote: > From: Zhen Lei <thunder.leizhen@huawei.com> > > 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)] > Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> > Signed-off-by: John Garry <john.garry@huawei.com> > --- > drivers/iommu/Kconfig | 34 ++++++++++++++++++++++++++++++++++ > drivers/iommu/iommu.c | 3 ++- > 2 files changed, 36 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig > index 1f111b399bca..12ef90256df8 100644 > --- a/drivers/iommu/Kconfig > +++ b/drivers/iommu/Kconfig > @@ -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 There don't seem to be two above? > + high performace scenarios. performance > + > +endchoice thanks. -- ~Randy
On 6/3/21 6:58 AM, John Garry wrote: > From: Zhen Lei <thunder.leizhen@huawei.com> > > 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)] > Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> > Signed-off-by: John Garry <john.garry@huawei.com> > --- > drivers/iommu/Kconfig | 34 ++++++++++++++++++++++++++++++++++ > drivers/iommu/iommu.c | 3 ++- > 2 files changed, 36 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig > index 1f111b399bca..12ef90256df8 100644 > --- a/drivers/iommu/Kconfig > +++ b/drivers/iommu/Kconfig > @@ -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 There don't seem to be two above? > + high performace scenarios. performance > + > +endchoice thanks. -- ~Randy _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
On 03/06/2021 18:00, Randy Dunlap wrote: >> +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 >> + high performace scenarios. > performance > ok >> + >> +endchoice Thanks!
On 03/06/2021 18:00, Randy Dunlap wrote: >> +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 >> + high performace scenarios. > performance > ok >> + >> +endchoice Thanks! _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
On 2021/6/3 21:58, John Garry wrote: > From: Zhen Lei <thunder.leizhen@huawei.com> > > 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)] > Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> > Signed-off-by: John Garry <john.garry@huawei.com> > --- > drivers/iommu/Kconfig | 34 ++++++++++++++++++++++++++++++++++ > drivers/iommu/iommu.c | 3 ++- > 2 files changed, 36 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig > index 1f111b399bca..12ef90256df8 100644 > --- a/drivers/iommu/Kconfig > +++ b/drivers/iommu/Kconfig > @@ -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" > + > + 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 > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index 966426a96520..177b0dafc535 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -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. > static u32 iommu_cmd_line __read_mostly; > > struct iommu_group { >
On 2021/6/3 21:58, John Garry wrote: > From: Zhen Lei <thunder.leizhen@huawei.com> > > 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)] > Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> > Signed-off-by: John Garry <john.garry@huawei.com> > --- > drivers/iommu/Kconfig | 34 ++++++++++++++++++++++++++++++++++ > drivers/iommu/iommu.c | 3 ++- > 2 files changed, 36 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig > index 1f111b399bca..12ef90256df8 100644 > --- a/drivers/iommu/Kconfig > +++ b/drivers/iommu/Kconfig > @@ -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" > + > + 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 > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index 966426a96520..177b0dafc535 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -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. > static u32 iommu_cmd_line __read_mostly; > > struct iommu_group { > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
>> >> 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" I suppose so. But I don't think that any other archs use the value from iommu_dma_strict anyway. > >> + >> + 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 >> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c >> index 966426a96520..177b0dafc535 100644 >> --- a/drivers/iommu/iommu.c >> +++ b/drivers/iommu/iommu.c >> @@ -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. 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
>> >> 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" I suppose so. But I don't think that any other archs use the value from iommu_dma_strict anyway. > >> + >> + 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 >> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c >> index 966426a96520..177b0dafc535 100644 >> --- a/drivers/iommu/iommu.c >> +++ b/drivers/iommu/iommu.c >> @@ -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. 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 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu