linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v11 0/3] Enhance IOMMU default DMA mode build options
@ 2021-06-08 13:18 John Garry
  2021-06-08 13:18 ` [PATCH v11 1/3] iommu: " John Garry
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: John Garry @ 2021-06-08 13:18 UTC (permalink / raw)
  To: joro, will, dwmw2, baolu.lu, robin.murphy
  Cc: linux-kernel, iommu, linuxarm, thunder.leizhen, chenxiang66,
	rdunlap, John Garry

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/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       | 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(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v11 1/3] iommu: Enhance IOMMU default DMA mode build options
  2021-06-08 13:18 [PATCH v11 0/3] Enhance IOMMU default DMA mode build options John Garry
@ 2021-06-08 13:18 ` John Garry
  2021-06-09 15:03   ` Robin Murphy
  2021-06-08 13:18 ` [PATCH v11 2/3] iommu/vt-d: Add support for " John Garry
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: John Garry @ 2021-06-08 13:18 UTC (permalink / raw)
  To: joro, will, dwmw2, baolu.lu, robin.murphy
  Cc: linux-kernel, iommu, linuxarm, thunder.leizhen, chenxiang66,
	rdunlap, John Garry

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 a 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 | 35 +++++++++++++++++++++++++++++++++++
 drivers/iommu/iommu.c |  3 ++-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 1f111b399bca..369a3af9e5bf 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -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
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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v11 2/3] iommu/vt-d: Add support for IOMMU default DMA mode build options
  2021-06-08 13:18 [PATCH v11 0/3] Enhance IOMMU default DMA mode build options John Garry
  2021-06-08 13:18 ` [PATCH v11 1/3] iommu: " John Garry
@ 2021-06-08 13:18 ` John Garry
  2021-06-08 13:18 ` [PATCH v11 3/3] iommu/amd: " John Garry
  2021-06-09  8:15 ` [PATCH v11 0/3] Enhance " Joerg Roedel
  3 siblings, 0 replies; 8+ messages in thread
From: John Garry @ 2021-06-08 13:18 UTC (permalink / raw)
  To: joro, will, dwmw2, baolu.lu, robin.murphy
  Cc: linux-kernel, iommu, linuxarm, thunder.leizhen, chenxiang66,
	rdunlap, John Garry

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 369a3af9e5bf..b68ec7ed23c0 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -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
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index be35284a2016..fe33347f4a1e 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v11 3/3] iommu/amd: Add support for IOMMU default DMA mode build options
  2021-06-08 13:18 [PATCH v11 0/3] Enhance IOMMU default DMA mode build options John Garry
  2021-06-08 13:18 ` [PATCH v11 1/3] iommu: " John Garry
  2021-06-08 13:18 ` [PATCH v11 2/3] iommu/vt-d: Add support for " John Garry
@ 2021-06-08 13:18 ` John Garry
  2021-06-09  8:15 ` [PATCH v11 0/3] Enhance " Joerg Roedel
  3 siblings, 0 replies; 8+ messages in thread
From: John Garry @ 2021-06-08 13:18 UTC (permalink / raw)
  To: joro, will, dwmw2, baolu.lu, robin.murphy
  Cc: linux-kernel, iommu, linuxarm, thunder.leizhen, chenxiang66,
	rdunlap, John Garry

From: Zhen Lei <thunder.leizhen@huawei.com>

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.

[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 b68ec7ed23c0..6d99150050b9 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -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
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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v11 0/3] Enhance IOMMU default DMA mode build options
  2021-06-08 13:18 [PATCH v11 0/3] Enhance IOMMU default DMA mode build options John Garry
                   ` (2 preceding siblings ...)
  2021-06-08 13:18 ` [PATCH v11 3/3] iommu/amd: " John Garry
@ 2021-06-09  8:15 ` Joerg Roedel
  2021-06-10 16:25   ` John Garry
  3 siblings, 1 reply; 8+ messages in thread
From: Joerg Roedel @ 2021-06-09  8:15 UTC (permalink / raw)
  To: John Garry
  Cc: will, dwmw2, baolu.lu, robin.murphy, linux-kernel, iommu,
	linuxarm, thunder.leizhen, chenxiang66, rdunlap

Hi John,

On Tue, Jun 08, 2021 at 09:18:25PM +0800, John Garry wrote:
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v11 1/3] iommu: Enhance IOMMU default DMA mode build options
  2021-06-08 13:18 ` [PATCH v11 1/3] iommu: " John Garry
@ 2021-06-09 15:03   ` Robin Murphy
  2021-06-09 15:24     ` John Garry
  0 siblings, 1 reply; 8+ messages in thread
From: Robin Murphy @ 2021-06-09 15:03 UTC (permalink / raw)
  To: John Garry, joro, will, dwmw2, baolu.lu
  Cc: rdunlap, linux-kernel, linuxarm, iommu

On 2021-06-08 14:18, 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 a 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 | 35 +++++++++++++++++++++++++++++++++++
>   drivers/iommu/iommu.c |  3 ++-
>   2 files changed, 37 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> index 1f111b399bca..369a3af9e5bf 100644
> --- a/drivers/iommu/Kconfig
> +++ b/drivers/iommu/Kconfig
> @@ -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.

> +
> +	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.

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.

> +
> +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 {
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v11 1/3] iommu: Enhance IOMMU default DMA mode build options
  2021-06-09 15:03   ` Robin Murphy
@ 2021-06-09 15:24     ` John Garry
  0 siblings, 0 replies; 8+ messages in thread
From: John Garry @ 2021-06-09 15:24 UTC (permalink / raw)
  To: Robin Murphy, joro, will, dwmw2, baolu.lu
  Cc: rdunlap, linux-kernel, linuxarm, iommu

On 09/06/2021 16:03, Robin Murphy wrote:
> On 2021-06-08 14:18, 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 a 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 | 35 +++++++++++++++++++++++++++++++++++
>>   drivers/iommu/iommu.c |  3 ++-
>>   2 files changed, 37 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
>> index 1f111b399bca..369a3af9e5bf 100644
>> --- a/drivers/iommu/Kconfig
>> +++ b/drivers/iommu/Kconfig
>> @@ -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.

I suppose so.

Configs ARM64, AMD_IOMMU, and INTEL_IOMMU all select this.

> 
>> +
>> +    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.
> 
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v11 0/3] Enhance IOMMU default DMA mode build options
  2021-06-09  8:15 ` [PATCH v11 0/3] Enhance " Joerg Roedel
@ 2021-06-10 16:25   ` John Garry
  0 siblings, 0 replies; 8+ messages in thread
From: John Garry @ 2021-06-10 16:25 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: will, dwmw2, baolu.lu, robin.murphy, linux-kernel, iommu,
	linuxarm, thunder.leizhen, chenxiang66, rdunlap

On 09/06/2021 09:15, Joerg Roedel wrote:
> On Tue, Jun 08, 2021 at 09:18:25PM +0800, John Garry wrote:
>> 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.

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-06-10 16:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-08 13:18 [PATCH v11 0/3] Enhance IOMMU default DMA mode build options John Garry
2021-06-08 13:18 ` [PATCH v11 1/3] iommu: " John Garry
2021-06-09 15:03   ` Robin Murphy
2021-06-09 15:24     ` John Garry
2021-06-08 13:18 ` [PATCH v11 2/3] iommu/vt-d: Add support for " John Garry
2021-06-08 13:18 ` [PATCH v11 3/3] iommu/amd: " John Garry
2021-06-09  8:15 ` [PATCH v11 0/3] Enhance " Joerg Roedel
2021-06-10 16:25   ` John Garry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).