IOMMU Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active)
@ 2019-08-19 13:22 Joerg Roedel
  2019-08-19 13:22 ` [PATCH 01/11] iommu: Remember when default domain type was set on kernel command line Joerg Roedel
                   ` (11 more replies)
  0 siblings, 12 replies; 15+ messages in thread
From: Joerg Roedel @ 2019-08-19 13:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, Thomas.Lendacky, hpa,
	tglx

From: Joerg Roedel <jroedel@suse.de>

Hi,

This patch-set started out small to overwrite the default passthrough
setting (through CONFIG_IOMMU_DEFAULT_PASSTHROUGH=y) when SME is active.

But on the way to that Tom reminded me that the current ways to
configure passthrough/no-passthrough modes for IOMMU on x86 is a mess.
So I added a few more patches to clean that up a bit, getting rid of the
iommu_pass_through variable on the way.This information is now kept only
in iommu code, with helpers to change that setting from architecture
code.

And of course this patch-set still disables 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

Changes since v2:

	- Added 'bool cmd_line' parameter to iommu_set_default_*()
	  functions, so that we correctly recognize iommu=pt/nopt
	  command line parameters

Changes since v1:

	- Cleaned up the kernel command line parameters to
	  configure passthrough/translated mode, getting rid
	  of the global iommu_pass_through variable

Joerg Roedel (11):
  iommu: Remember when default domain type was set on kernel command line
  iommu: Add helpers to set/get default domain type
  iommu: Use Functions to set default domain type in iommu_set_def_domain_type()
  iommu/amd: Request passthrough mode from IOMMU core
  iommu/vt-d: Request passthrough mode from IOMMU core
  x86/dma: Get rid of iommu_pass_through
  ia64: Get rid of iommu_pass_through
  iommu: Print default domain type on boot
  iommu: Set default domain type at runtime
  iommu: Disable passthrough mode when SME is active
  Documentation: Update Documentation for iommu.passthrough

 Documentation/admin-guide/kernel-parameters.txt |  2 +-
 arch/ia64/include/asm/iommu.h                   |  2 -
 arch/ia64/kernel/pci-dma.c                      |  2 -
 arch/x86/include/asm/iommu.h                    |  1 -
 arch/x86/kernel/pci-dma.c                       | 20 +-----
 drivers/iommu/amd_iommu.c                       |  6 +-
 drivers/iommu/intel-iommu.c                     |  2 +-
 drivers/iommu/iommu.c                           | 93 +++++++++++++++++++++++--
 include/linux/iommu.h                           | 16 +++++
 9 files changed, 110 insertions(+), 34 deletions(-)

-- 
2.16.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 01/11] iommu: Remember when default domain type was set on kernel command line
  2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
@ 2019-08-19 13:22 ` Joerg Roedel
  2019-08-19 13:22 ` [PATCH 02/11] iommu: Add helpers to set/get default domain type Joerg Roedel
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Joerg Roedel @ 2019-08-19 13:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, Thomas.Lendacky, hpa,
	tglx

From: Joerg Roedel <jroedel@suse.de>

Introduce an extensible concept to remember when certain
configuration settings for the IOMMU code have been set on
the kernel command line.

This will be used later to prevent overwriting these
settings with other defaults.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/iommu.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 0c674d80c37f..3361ca5ef769 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -32,6 +32,7 @@ static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_IDENTITY;
 static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_DMA;
 #endif
 static bool iommu_dma_strict __read_mostly = true;
+static u32 iommu_cmd_line __read_mostly;
 
 struct iommu_group {
 	struct kobject kobj;
@@ -68,6 +69,18 @@ static const char * const iommu_group_resv_type_string[] = {
 	[IOMMU_RESV_SW_MSI]			= "msi",
 };
 
+#define IOMMU_CMD_LINE_DMA_API		BIT(0)
+
+static void iommu_set_cmd_line_dma_api(void)
+{
+	iommu_cmd_line |= IOMMU_CMD_LINE_DMA_API;
+}
+
+static bool __maybe_unused iommu_cmd_line_dma_api(void)
+{
+	return !!(iommu_cmd_line & IOMMU_CMD_LINE_DMA_API);
+}
+
 #define IOMMU_GROUP_ATTR(_name, _mode, _show, _store)		\
 struct iommu_group_attribute iommu_group_attr_##_name =		\
 	__ATTR(_name, _mode, _show, _store)
@@ -165,6 +178,8 @@ static int __init iommu_set_def_domain_type(char *str)
 	if (ret)
 		return ret;
 
+	iommu_set_cmd_line_dma_api();
+
 	iommu_def_domain_type = pt ? IOMMU_DOMAIN_IDENTITY : IOMMU_DOMAIN_DMA;
 	return 0;
 }
-- 
2.16.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 02/11] iommu: Add helpers to set/get default domain type
  2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
  2019-08-19 13:22 ` [PATCH 01/11] iommu: Remember when default domain type was set on kernel command line Joerg Roedel
@ 2019-08-19 13:22 ` Joerg Roedel
  2019-08-19 13:22 ` [PATCH 03/11] iommu: Use Functions to set default domain type in iommu_set_def_domain_type() Joerg Roedel
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Joerg Roedel @ 2019-08-19 13:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, Thomas.Lendacky, hpa,
	tglx

From: Joerg Roedel <jroedel@suse.de>

Add a couple of functions to allow changing the default
domain type from architecture code and a function for iommu
drivers to request whether the default domain is
passthrough.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/iommu.c | 22 ++++++++++++++++++++++
 include/linux/iommu.h | 16 ++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 3361ca5ef769..84acd47936ac 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2211,6 +2211,28 @@ int iommu_request_dma_domain_for_dev(struct device *dev)
 	return request_default_domain_for_dev(dev, IOMMU_DOMAIN_DMA);
 }
 
+void iommu_set_default_passthrough(bool cmd_line)
+{
+	if (cmd_line)
+		iommu_set_cmd_line_dma_api();
+
+	iommu_def_domain_type = IOMMU_DOMAIN_IDENTITY;
+}
+
+void iommu_set_default_translated(bool cmd_line)
+{
+	if (cmd_line)
+		iommu_set_cmd_line_dma_api();
+
+	iommu_def_domain_type = IOMMU_DOMAIN_DMA;
+}
+
+bool iommu_default_passthrough(void)
+{
+	return iommu_def_domain_type == IOMMU_DOMAIN_IDENTITY;
+}
+EXPORT_SYMBOL_GPL(iommu_default_passthrough);
+
 const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode)
 {
 	const struct iommu_ops *ops = NULL;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index fdc355ccc570..4955498204a9 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -413,6 +413,9 @@ extern void iommu_get_resv_regions(struct device *dev, struct list_head *list);
 extern void iommu_put_resv_regions(struct device *dev, struct list_head *list);
 extern int iommu_request_dm_for_dev(struct device *dev);
 extern int iommu_request_dma_domain_for_dev(struct device *dev);
+extern void iommu_set_default_passthrough(bool cmd_line);
+extern void iommu_set_default_translated(bool cmd_line);
+extern bool iommu_default_passthrough(void);
 extern struct iommu_resv_region *
 iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot,
 			enum iommu_resv_type type);
@@ -694,6 +697,19 @@ static inline int iommu_request_dma_domain_for_dev(struct device *dev)
 	return -ENODEV;
 }
 
+static inline void iommu_set_default_passthrough(bool cmd_line)
+{
+}
+
+static inline void iommu_set_default_translated(bool cmd_line)
+{
+}
+
+static inline bool iommu_default_passthrough(void)
+{
+	return true;
+}
+
 static inline int iommu_attach_group(struct iommu_domain *domain,
 				     struct iommu_group *group)
 {
-- 
2.16.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 03/11] iommu: Use Functions to set default domain type in iommu_set_def_domain_type()
  2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
  2019-08-19 13:22 ` [PATCH 01/11] iommu: Remember when default domain type was set on kernel command line Joerg Roedel
  2019-08-19 13:22 ` [PATCH 02/11] iommu: Add helpers to set/get default domain type Joerg Roedel
@ 2019-08-19 13:22 ` Joerg Roedel
  2019-08-19 13:22 ` [PATCH 04/11] iommu/amd: Request passthrough mode from IOMMU core Joerg Roedel
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Joerg Roedel @ 2019-08-19 13:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, Thomas.Lendacky, hpa,
	tglx

From: Joerg Roedel <jroedel@suse.de>

There are functions now to set the default domain type which
take care of updating other necessary state. Don't open-code
it in iommu_set_def_domain_type() and use those functions
instead.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/iommu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 84acd47936ac..3ee50bb22ca2 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -178,9 +178,11 @@ static int __init iommu_set_def_domain_type(char *str)
 	if (ret)
 		return ret;
 
-	iommu_set_cmd_line_dma_api();
+	if (pt)
+		iommu_set_default_passthrough(true);
+	else
+		iommu_set_default_translated(true);
 
-	iommu_def_domain_type = pt ? IOMMU_DOMAIN_IDENTITY : IOMMU_DOMAIN_DMA;
 	return 0;
 }
 early_param("iommu.passthrough", iommu_set_def_domain_type);
-- 
2.16.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 04/11] iommu/amd: Request passthrough mode from IOMMU core
  2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
                   ` (2 preceding siblings ...)
  2019-08-19 13:22 ` [PATCH 03/11] iommu: Use Functions to set default domain type in iommu_set_def_domain_type() Joerg Roedel
@ 2019-08-19 13:22 ` Joerg Roedel
  2019-08-19 13:22 ` [PATCH 05/11] iommu/vt-d: " Joerg Roedel
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Joerg Roedel @ 2019-08-19 13:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, Thomas.Lendacky, hpa,
	tglx

From: Joerg Roedel <jroedel@suse.de>

Get rid of the iommu_pass_through variable and request
passthrough mode via the new iommu core function.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/amd_iommu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index b607a92791d3..7434b34d7a94 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -436,7 +436,7 @@ static int iommu_init_device(struct device *dev)
 	 * invalid address), we ignore the capability for the device so
 	 * it'll be forced to go into translation mode.
 	 */
-	if ((iommu_pass_through || !amd_iommu_force_isolation) &&
+	if ((iommu_default_passthrough() || !amd_iommu_force_isolation) &&
 	    dev_is_pci(dev) && pci_iommuv2_capable(to_pci_dev(dev))) {
 		struct amd_iommu *iommu;
 
@@ -2226,7 +2226,7 @@ static int amd_iommu_add_device(struct device *dev)
 
 	BUG_ON(!dev_data);
 
-	if (iommu_pass_through || dev_data->iommu_v2)
+	if (dev_data->iommu_v2)
 		iommu_request_dm_for_dev(dev);
 
 	/* Domains are initialized for this device - have a look what we ended up with */
@@ -2805,7 +2805,7 @@ int __init amd_iommu_init_api(void)
 
 int __init amd_iommu_init_dma_ops(void)
 {
-	swiotlb        = (iommu_pass_through || sme_me_mask) ? 1 : 0;
+	swiotlb        = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0;
 	iommu_detected = 1;
 
 	if (amd_iommu_unmap_flush)
-- 
2.16.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 05/11] iommu/vt-d: Request passthrough mode from IOMMU core
  2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
                   ` (3 preceding siblings ...)
  2019-08-19 13:22 ` [PATCH 04/11] iommu/amd: Request passthrough mode from IOMMU core Joerg Roedel
@ 2019-08-19 13:22 ` " Joerg Roedel
  2019-08-19 13:22 ` [PATCH 06/11] x86/dma: Get rid of iommu_pass_through Joerg Roedel
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Joerg Roedel @ 2019-08-19 13:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, Thomas.Lendacky, hpa,
	tglx

From: Joerg Roedel <jroedel@suse.de>

Get rid of the iommu_pass_through variable and request
passthrough mode via the new iommu core function.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/intel-iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 12d094d08c0a..a66c2a1bbbe3 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -3267,7 +3267,7 @@ static int __init init_dmars(void)
 		iommu->flush.flush_iotlb(iommu, 0, 0, 0, DMA_TLB_GLOBAL_FLUSH);
 	}
 
-	if (iommu_pass_through)
+	if (iommu_default_passthrough())
 		iommu_identity_mapping |= IDENTMAP_ALL;
 
 #ifdef CONFIG_INTEL_IOMMU_BROKEN_GFX_WA
-- 
2.16.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 06/11] x86/dma: Get rid of iommu_pass_through
  2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
                   ` (4 preceding siblings ...)
  2019-08-19 13:22 ` [PATCH 05/11] iommu/vt-d: " Joerg Roedel
@ 2019-08-19 13:22 ` Joerg Roedel
  2019-08-20 11:17   ` Borislav Petkov
  2019-08-19 13:22 ` [PATCH 07/11] ia64: " Joerg Roedel
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 15+ messages in thread
From: Joerg Roedel @ 2019-08-19 13:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, Thomas.Lendacky, hpa,
	tglx

From: Joerg Roedel <jroedel@suse.de>

This variable has no users anymore. Remove it and tell the
IOMMU code via its new functions about requested DMA modes.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 arch/x86/include/asm/iommu.h |  1 -
 arch/x86/kernel/pci-dma.c    | 20 +++-----------------
 2 files changed, 3 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
index baedab8ac538..b91623d521d9 100644
--- a/arch/x86/include/asm/iommu.h
+++ b/arch/x86/include/asm/iommu.h
@@ -4,7 +4,6 @@
 
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
-extern int iommu_pass_through;
 
 /* 10 seconds */
 #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index f62b498b18fb..fa4352dce491 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/dma-direct.h>
 #include <linux/dma-debug.h>
+#include <linux/iommu.h>
 #include <linux/dmar.h>
 #include <linux/export.h>
 #include <linux/memblock.h>
@@ -34,21 +35,6 @@ int no_iommu __read_mostly;
 /* Set this to 1 if there is a HW IOMMU in the system */
 int iommu_detected __read_mostly = 0;
 
-/*
- * This variable becomes 1 if iommu=pt is passed on the kernel command line.
- * If this variable is 1, IOMMU implementations do no DMA translation for
- * devices and allow every device to access to whole physical memory. This is
- * useful if a user wants to use an IOMMU only for KVM device assignment to
- * guests and not for driver dma translation.
- * It is also possible to disable by default in kernel config, and enable with
- * iommu=nopt at boot time.
- */
-#ifdef CONFIG_IOMMU_DEFAULT_PASSTHROUGH
-int iommu_pass_through __read_mostly = 1;
-#else
-int iommu_pass_through __read_mostly;
-#endif
-
 extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
 
 void __init pci_iommu_alloc(void)
@@ -120,9 +106,9 @@ static __init int iommu_setup(char *p)
 			swiotlb = 1;
 #endif
 		if (!strncmp(p, "pt", 2))
-			iommu_pass_through = 1;
+			iommu_set_default_passthrough(true);
 		if (!strncmp(p, "nopt", 4))
-			iommu_pass_through = 0;
+			iommu_set_default_translated(true);
 
 		gart_parse_options(p);
 
-- 
2.16.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 07/11] ia64: Get rid of iommu_pass_through
  2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
                   ` (5 preceding siblings ...)
  2019-08-19 13:22 ` [PATCH 06/11] x86/dma: Get rid of iommu_pass_through Joerg Roedel
@ 2019-08-19 13:22 ` " Joerg Roedel
  2019-08-19 13:22 ` [PATCH 08/11] iommu: Print default domain type on boot Joerg Roedel
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Joerg Roedel @ 2019-08-19 13:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, Thomas.Lendacky, hpa,
	tglx

From: Joerg Roedel <jroedel@suse.de>

This variable has no users anymore so it can be removed.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 arch/ia64/include/asm/iommu.h | 2 --
 arch/ia64/kernel/pci-dma.c    | 2 --
 2 files changed, 4 deletions(-)

diff --git a/arch/ia64/include/asm/iommu.h b/arch/ia64/include/asm/iommu.h
index 7429a72f3f92..92aceef63710 100644
--- a/arch/ia64/include/asm/iommu.h
+++ b/arch/ia64/include/asm/iommu.h
@@ -8,10 +8,8 @@
 extern void no_iommu_init(void);
 #ifdef	CONFIG_INTEL_IOMMU
 extern int force_iommu, no_iommu;
-extern int iommu_pass_through;
 extern int iommu_detected;
 #else
-#define iommu_pass_through	(0)
 #define no_iommu		(1)
 #define iommu_detected		(0)
 #endif
diff --git a/arch/ia64/kernel/pci-dma.c b/arch/ia64/kernel/pci-dma.c
index fe988c49f01c..f5d49cd3fbb0 100644
--- a/arch/ia64/kernel/pci-dma.c
+++ b/arch/ia64/kernel/pci-dma.c
@@ -22,8 +22,6 @@ int force_iommu __read_mostly = 1;
 int force_iommu __read_mostly;
 #endif
 
-int iommu_pass_through;
-
 static int __init pci_iommu_init(void)
 {
 	if (iommu_detected)
-- 
2.16.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 08/11] iommu: Print default domain type on boot
  2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
                   ` (6 preceding siblings ...)
  2019-08-19 13:22 ` [PATCH 07/11] ia64: " Joerg Roedel
@ 2019-08-19 13:22 ` Joerg Roedel
  2019-08-19 13:22 ` [PATCH 09/11] iommu: Set default domain type at runtime Joerg Roedel
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Joerg Roedel @ 2019-08-19 13:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, Thomas.Lendacky, hpa,
	tglx

From: Joerg Roedel <jroedel@suse.de>

Introduce a subsys_initcall for IOMMU code and use it to
print the default domain type at boot.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/iommu.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 3ee50bb22ca2..0ddd0bd1ff75 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -93,12 +93,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;
 }
 
-- 
2.16.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 09/11] iommu: Set default domain type at runtime
  2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
                   ` (7 preceding siblings ...)
  2019-08-19 13:22 ` [PATCH 08/11] iommu: Print default domain type on boot Joerg Roedel
@ 2019-08-19 13:22 ` Joerg Roedel
  2019-08-19 13:22 ` [PATCH 10/11] iommu: Disable passthrough mode when SME is active Joerg Roedel
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Joerg Roedel @ 2019-08-19 13:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, Thomas.Lendacky, hpa,
	tglx

From: Joerg Roedel <jroedel@suse.de>

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.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/iommu.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 0ddd0bd1ff75..01759d4ac70b 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -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;
 static u32 iommu_cmd_line __read_mostly;
 
@@ -76,7 +73,7 @@ static void iommu_set_cmd_line_dma_api(void)
 	iommu_cmd_line |= IOMMU_CMD_LINE_DMA_API;
 }
 
-static bool __maybe_unused iommu_cmd_line_dma_api(void)
+static bool iommu_cmd_line_dma_api(void)
 {
 	return !!(iommu_cmd_line & IOMMU_CMD_LINE_DMA_API);
 }
@@ -115,8 +112,18 @@ static const char *iommu_domain_type_str(unsigned int t)
 
 static int __init iommu_subsys_init(void)
 {
-	pr_info("Default domain type: %s\n",
-		iommu_domain_type_str(iommu_def_domain_type));
+	bool cmd_line = iommu_cmd_line_dma_api();
+
+	if (!cmd_line) {
+		if (IS_ENABLED(CONFIG_IOMMU_DEFAULT_PASSTHROUGH))
+			iommu_set_default_passthrough(false);
+		else
+			iommu_set_default_translated(false);
+	}
+
+	pr_info("Default domain type: %s %s\n",
+		iommu_domain_type_str(iommu_def_domain_type),
+		cmd_line ? "(set via kernel command line)" : "");
 
 	return 0;
 }
-- 
2.16.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 10/11] iommu: Disable passthrough mode when SME is active
  2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
                   ` (8 preceding siblings ...)
  2019-08-19 13:22 ` [PATCH 09/11] iommu: Set default domain type at runtime Joerg Roedel
@ 2019-08-19 13:22 ` Joerg Roedel
  2019-08-20 21:18   ` Lendacky, Thomas
  2019-08-19 13:22 ` [PATCH 11/11] Documentation: Update Documentation for iommu.passthrough Joerg Roedel
  2019-08-23  8:12 ` [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
  11 siblings, 1 reply; 15+ messages in thread
From: Joerg Roedel @ 2019-08-19 13:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, Thomas.Lendacky, hpa,
	tglx

From: Joerg Roedel <jroedel@suse.de>

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 <jroedel@suse.de>
---
 drivers/iommu/iommu.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 01759d4ac70b..ec18c9630e93 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -119,6 +119,11 @@ static int __init iommu_subsys_init(void)
 			iommu_set_default_passthrough(false);
 		else
 			iommu_set_default_translated(false);
+
+		if (iommu_default_passthrough() && sme_active()) {
+			pr_info("SME detected - Disabling default IOMMU Passthrough\n");
+			iommu_set_default_translated(false);
+		}
 	}
 
 	pr_info("Default domain type: %s %s\n",
-- 
2.16.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 11/11] Documentation: Update Documentation for iommu.passthrough
  2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
                   ` (9 preceding siblings ...)
  2019-08-19 13:22 ` [PATCH 10/11] iommu: Disable passthrough mode when SME is active Joerg Roedel
@ 2019-08-19 13:22 ` Joerg Roedel
  2019-08-23  8:12 ` [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
  11 siblings, 0 replies; 15+ messages in thread
From: Joerg Roedel @ 2019-08-19 13:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, Thomas.Lendacky, hpa,
	tglx

From: Joerg Roedel <jroedel@suse.de>

This kernel parameter now takes also effect on X86.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 Documentation/admin-guide/kernel-parameters.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 47d981a86e2f..2d5dfa46e88a 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1811,7 +1811,7 @@
 			  synchronously.
 
 	iommu.passthrough=
-			[ARM64] Configure DMA to bypass the IOMMU by default.
+			[ARM64, X86] Configure DMA to bypass the IOMMU by default.
 			Format: { "0" | "1" }
 			0 - Use IOMMU translation for DMA.
 			1 - Bypass the IOMMU for DMA.
-- 
2.16.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH 06/11] x86/dma: Get rid of iommu_pass_through
  2019-08-19 13:22 ` [PATCH 06/11] x86/dma: Get rid of iommu_pass_through Joerg Roedel
@ 2019-08-20 11:17   ` Borislav Petkov
  0 siblings, 0 replies; 15+ messages in thread
From: Borislav Petkov @ 2019-08-20 11:17 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, Thomas.Lendacky, hpa,
	tglx

On Mon, Aug 19, 2019 at 03:22:51PM +0200, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel@suse.de>
> 
> This variable has no users anymore. Remove it and tell the
> IOMMU code via its new functions about requested DMA modes.
> 
> Signed-off-by: Joerg Roedel <jroedel@suse.de>
> ---
>  arch/x86/include/asm/iommu.h |  1 -
>  arch/x86/kernel/pci-dma.c    | 20 +++-----------------
>  2 files changed, 3 insertions(+), 18 deletions(-)
> 
> diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
> index baedab8ac538..b91623d521d9 100644
> --- a/arch/x86/include/asm/iommu.h
> +++ b/arch/x86/include/asm/iommu.h
> @@ -4,7 +4,6 @@
>  
>  extern int force_iommu, no_iommu;
>  extern int iommu_detected;
> -extern int iommu_pass_through;
>  
>  /* 10 seconds */
>  #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000)
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index f62b498b18fb..fa4352dce491 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -1,6 +1,7 @@
>  // SPDX-License-Identifier: GPL-2.0
>  #include <linux/dma-direct.h>
>  #include <linux/dma-debug.h>
> +#include <linux/iommu.h>
>  #include <linux/dmar.h>
>  #include <linux/export.h>
>  #include <linux/memblock.h>
> @@ -34,21 +35,6 @@ int no_iommu __read_mostly;
>  /* Set this to 1 if there is a HW IOMMU in the system */
>  int iommu_detected __read_mostly = 0;
>  
> -/*
> - * This variable becomes 1 if iommu=pt is passed on the kernel command line.
> - * If this variable is 1, IOMMU implementations do no DMA translation for
> - * devices and allow every device to access to whole physical memory. This is
> - * useful if a user wants to use an IOMMU only for KVM device assignment to
> - * guests and not for driver dma translation.
> - * It is also possible to disable by default in kernel config, and enable with
> - * iommu=nopt at boot time.
> - */
> -#ifdef CONFIG_IOMMU_DEFAULT_PASSTHROUGH
> -int iommu_pass_through __read_mostly = 1;
> -#else
> -int iommu_pass_through __read_mostly;
> -#endif
> -
>  extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
>  
>  void __init pci_iommu_alloc(void)
> @@ -120,9 +106,9 @@ static __init int iommu_setup(char *p)
>  			swiotlb = 1;
>  #endif
>  		if (!strncmp(p, "pt", 2))
> -			iommu_pass_through = 1;
> +			iommu_set_default_passthrough(true);
>  		if (!strncmp(p, "nopt", 4))
> -			iommu_pass_through = 0;
> +			iommu_set_default_translated(true);
>  
>  		gart_parse_options(p);
>  
> -- 

Reviewed-by: Borislav Petkov <bp@suse.de>

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH 10/11] iommu: Disable passthrough mode when SME is active
  2019-08-19 13:22 ` [PATCH 10/11] iommu: Disable passthrough mode when SME is active Joerg Roedel
@ 2019-08-20 21:18   ` Lendacky, Thomas
  0 siblings, 0 replies; 15+ messages in thread
From: Lendacky, Thomas @ 2019-08-20 21:18 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: fenghua.yu, tony.luck, linux-ia64, corbet, Joerg Roedel, x86,
	linux-doc, linux-kernel, iommu, mingo, bp, hpa, tglx

On 8/19/19 8:22 AM, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel@suse.de>
> 
> 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 <jroedel@suse.de>

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Tested-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
>  drivers/iommu/iommu.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 01759d4ac70b..ec18c9630e93 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -119,6 +119,11 @@ static int __init iommu_subsys_init(void)
>  			iommu_set_default_passthrough(false);
>  		else
>  			iommu_set_default_translated(false);
> +
> +		if (iommu_default_passthrough() && sme_active()) {
> +			pr_info("SME detected - Disabling default IOMMU Passthrough\n");
> +			iommu_set_default_translated(false);
> +		}
>  	}
>  
>  	pr_info("Default domain type: %s %s\n",
> 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active)
  2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
                   ` (10 preceding siblings ...)
  2019-08-19 13:22 ` [PATCH 11/11] Documentation: Update Documentation for iommu.passthrough Joerg Roedel
@ 2019-08-23  8:12 ` Joerg Roedel
  11 siblings, 0 replies; 15+ messages in thread
From: Joerg Roedel @ 2019-08-23  8:12 UTC (permalink / raw)
  To: corbet, tony.luck, fenghua.yu, tglx, mingo, bp, hpa, x86,
	linux-doc, linux-ia64, iommu, linux-kernel, Thomas.Lendacky,
	Suravee.Suthikulpanit, Joerg Roedel

On Mon, Aug 19, 2019 at 03:22:45PM +0200, Joerg Roedel wrote:
> Joerg Roedel (11):
>   iommu: Remember when default domain type was set on kernel command line
>   iommu: Add helpers to set/get default domain type
>   iommu: Use Functions to set default domain type in iommu_set_def_domain_type()
>   iommu/amd: Request passthrough mode from IOMMU core
>   iommu/vt-d: Request passthrough mode from IOMMU core
>   x86/dma: Get rid of iommu_pass_through
>   ia64: Get rid of iommu_pass_through
>   iommu: Print default domain type on boot
>   iommu: Set default domain type at runtime
>   iommu: Disable passthrough mode when SME is active
>   Documentation: Update Documentation for iommu.passthrough
> 
>  Documentation/admin-guide/kernel-parameters.txt |  2 +-
>  arch/ia64/include/asm/iommu.h                   |  2 -
>  arch/ia64/kernel/pci-dma.c                      |  2 -
>  arch/x86/include/asm/iommu.h                    |  1 -
>  arch/x86/kernel/pci-dma.c                       | 20 +-----
>  drivers/iommu/amd_iommu.c                       |  6 +-
>  drivers/iommu/intel-iommu.c                     |  2 +-
>  drivers/iommu/iommu.c                           | 93 +++++++++++++++++++++++--
>  include/linux/iommu.h                           | 16 +++++
>  9 files changed, 110 insertions(+), 34 deletions(-)

Applied.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

end of thread, back to index

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-19 13:22 [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel
2019-08-19 13:22 ` [PATCH 01/11] iommu: Remember when default domain type was set on kernel command line Joerg Roedel
2019-08-19 13:22 ` [PATCH 02/11] iommu: Add helpers to set/get default domain type Joerg Roedel
2019-08-19 13:22 ` [PATCH 03/11] iommu: Use Functions to set default domain type in iommu_set_def_domain_type() Joerg Roedel
2019-08-19 13:22 ` [PATCH 04/11] iommu/amd: Request passthrough mode from IOMMU core Joerg Roedel
2019-08-19 13:22 ` [PATCH 05/11] iommu/vt-d: " Joerg Roedel
2019-08-19 13:22 ` [PATCH 06/11] x86/dma: Get rid of iommu_pass_through Joerg Roedel
2019-08-20 11:17   ` Borislav Petkov
2019-08-19 13:22 ` [PATCH 07/11] ia64: " Joerg Roedel
2019-08-19 13:22 ` [PATCH 08/11] iommu: Print default domain type on boot Joerg Roedel
2019-08-19 13:22 ` [PATCH 09/11] iommu: Set default domain type at runtime Joerg Roedel
2019-08-19 13:22 ` [PATCH 10/11] iommu: Disable passthrough mode when SME is active Joerg Roedel
2019-08-20 21:18   ` Lendacky, Thomas
2019-08-19 13:22 ` [PATCH 11/11] Documentation: Update Documentation for iommu.passthrough Joerg Roedel
2019-08-23  8:12 ` [PATCH 00/11 v3] Cleanup IOMMU passthrough setting (and disable IOMMU Passthrough when SME is active) Joerg Roedel

IOMMU Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iommu/0 linux-iommu/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iommu linux-iommu/ https://lore.kernel.org/linux-iommu \
		iommu@lists.linux-foundation.org iommu@archiver.kernel.org
	public-inbox-index linux-iommu


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.linux-foundation.lists.iommu


AGPL code for this site: git clone https://public-inbox.org/ public-inbox