AMD iommu is not needed by most users, but enabled by default, and
causes performance issue for some device like NICs, so add config
option to set amd iommu off as default as Intel

if AMD iommu is needed, it can be enabled by passing amd_iommu=on

Signed-off-by: Li RongQing <[email protected]>
---
 Documentation/admin-guide/kernel-parameters.txt | 1 +
 arch/x86/configs/x86_64_defconfig               | 1 +
 drivers/iommu/amd/Kconfig                       | 8 ++++++++
 drivers/iommu/amd/init.c                        | 4 +++-
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 9725c54..0c754c8 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -304,6 +304,7 @@
                        fullflush - Deprecated, equivalent to iommu.strict=1
                        off       - do not initialize any AMD IOMMU found in
                                    the system
+                       on        - initialize any AMD IOMMU found in the system
                        force_isolation - Force device isolation for all
                                          devices. The IOMMU driver is not
                                          allowed anymore to lift isolation
diff --git a/arch/x86/configs/x86_64_defconfig 
b/arch/x86/configs/x86_64_defconfig
index e8a7a0a..0693b62 100644
--- a/arch/x86/configs/x86_64_defconfig
+++ b/arch/x86/configs/x86_64_defconfig
@@ -218,6 +218,7 @@ CONFIG_EEEPC_LAPTOP=y
 CONFIG_AMD_IOMMU=y
 CONFIG_INTEL_IOMMU=y
 # CONFIG_INTEL_IOMMU_DEFAULT_ON is not set
+# CONFIG_AMD_IOMMU_DEFAULT_ON is not set
 CONFIG_EXT4_FS=y
 CONFIG_EXT4_FS_POSIX_ACL=y
 CONFIG_EXT4_FS_SECURITY=y
diff --git a/drivers/iommu/amd/Kconfig b/drivers/iommu/amd/Kconfig
index a3cbafb..7962c46 100644
--- a/drivers/iommu/amd/Kconfig
+++ b/drivers/iommu/amd/Kconfig
@@ -32,6 +32,14 @@ config AMD_IOMMU_V2
          hardware. Select this option if you want to use devices that support
          the PCI PRI and PASID interface.
 
+config AMD_IOMMU_DEFAULT_ON
+       bool "Enable AMD IOMMU by default"
+       default n
+       help
+         Selecting this option will enable a AMD IOMMU at boot time if
+         one is found. If this option is not selected, AMD IOMMU support can
+         be enabled by passing amd_iommu=on to the kernel.
+
 config AMD_IOMMU_DEBUGFS
        bool "Enable AMD IOMMU internals in DebugFS"
        depends on AMD_IOMMU && IOMMU_DEBUGFS
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index 1eacd43..dcf24cb 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -155,7 +155,7 @@ int amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_VAPIC;
 static int amd_iommu_xt_mode = IRQ_REMAP_XAPIC_MODE;
 
 static bool amd_iommu_detected;
-static bool amd_iommu_disabled __initdata;
+static bool amd_iommu_disabled __initdata = 
!IS_ENABLED(CONFIG_AMD_IOMMU_DEFAULT_ON);
 static bool amd_iommu_force_enable __initdata;
 static int amd_iommu_target_ivhd_type;
 
@@ -3120,6 +3120,8 @@ static int __init parse_amd_iommu_options(char *str)
                        amd_iommu_force_enable = true;
                if (strncmp(str, "off", 3) == 0)
                        amd_iommu_disabled = true;
+               if (strncmp(str, "on", 2) == 0)
+                       amd_iommu_disabled = false;
                if (strncmp(str, "force_isolation", 15) == 0)
                        amd_iommu_force_isolation = true;
        }
-- 
2.9.4

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to