Pablo Greco 7b2c62
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
Pablo Greco 7b2c62
From: Laura Abbott <labbott@redhat.com>
Pablo Greco 7b2c62
Date: Mon, 20 May 2019 22:21:02 -0400
Pablo Greco 7b2c62
Subject: [PATCH] iommu/arm-smmu: workaround DMA mode issues
Pablo Greco 7b2c62
Pablo Greco 7b2c62
Message-id: <20190520222102.19488-1-labbott@redhat.com>
Pablo Greco 7b2c62
Patchwork-id: 259215
Pablo Greco 7b2c62
O-Subject: [ARK INTERNAL PATCH] iommu/arm-smmu: workaround DMA mode issues
Pablo Greco 7b2c62
Bugzilla:
Pablo Greco 7b2c62
RH-Acked-by: Mark Langsdorf <mlangsdo@redhat.com>
Pablo Greco 7b2c62
RH-Acked-by: Mark Salter <msalter@redhat.com>
Pablo Greco 7b2c62
Pablo Greco 7b2c62
From: Mark Salter <msalter@redhat.com>
Pablo Greco 7b2c62
Pablo Greco 7b2c62
Rebased for v5.2-rc1
Pablo Greco 7b2c62
Pablo Greco 7b2c62
	Bugzilla: 1652259
Pablo Greco 7b2c62
	Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=19244562
Pablo Greco 7b2c62
	Upstream status: RHEL only.
Pablo Greco 7b2c62
Pablo Greco 7b2c62
	rhel8 commit 65feb1ed0ec9a088a63a90d46c0f7563ac96ad0f
Pablo Greco 7b2c62
	Author: Mark Salter <msalter@redhat.com>
Pablo Greco 7b2c62
	Date:   Wed Nov 21 17:15:59 2018 +0100
Pablo Greco 7b2c62
Pablo Greco 7b2c62
	    [iommu] iommu/arm-smmu: workaround DMA mode issues
Pablo Greco 7b2c62
Pablo Greco 7b2c62
	    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1624077
Pablo Greco 7b2c62
	    Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=18112820
Pablo Greco 7b2c62
	    Testing: Verified iommu.passthrough=1 no longer needed on gigabyte platforms.
Pablo Greco 7b2c62
	    Upstream Status: RHEL-only
Pablo Greco 7b2c62
Pablo Greco 7b2c62
	    In RHEL_ALT 7.5 we carried a RHEL-only patch which forced the arm smmuv2
Pablo Greco 7b2c62
	    into bypass mode due to performance issues on CN88xx. This was intended
Pablo Greco 7b2c62
	    to be a temporary hack until the issues were resolved. Another vendor
Pablo Greco 7b2c62
	    had issues with the iommu in bypass mode so we reverted the RHEL-only
Pablo Greco 7b2c62
	    patch so that iommu is in DMA mode by default (upstream default).
Pablo Greco 7b2c62
Pablo Greco 7b2c62
	    It turns on that there are remaining SMMU DMA mode issues on Gigabyte
Pablo Greco 7b2c62
	    platformws with CN88xx cpus. The problem manifests itself by pcie
Pablo Greco 7b2c62
	    card drivers failing to initialize the cards when SMMU is in DMA mode.
Pablo Greco 7b2c62
	    The root cause has not been determined yet, but looks likely to be
Pablo Greco 7b2c62
	    a hw or firmware issue. This patch forces bypass mode for Gigabyte
Pablo Greco 7b2c62
	    platforms. CN88xx isn't officially supported in RHEL but we have a
Pablo Greco 7b2c62
	    lot of them being used internally for testing, so I think we want
Pablo Greco 7b2c62
	    this to support that use case in RHEL8.
Pablo Greco 7b2c62
Pablo Greco 7b2c62
	    Signed-off-by: Mark Salter <msalter@redhat.com>
Pablo Greco 7b2c62
	    Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
Pablo Greco 7b2c62
Pablo Greco 7b2c62
	Acked-by: Mark Salter <msalter@redhat.com>
Pablo Greco 7b2c62
	Acked-by: Donald Dutile <ddutile@redhat.com>
Pablo Greco 7b2c62
Pablo Greco 7b2c62
Upstream Status: RHEL only
Pablo Greco 7b2c62
Signed-off-by: Laura Abbott <labbott@redhat.com>
Pablo Greco 7b2c62
---
Pablo Greco 7b2c62
 drivers/iommu/iommu.c | 22 ++++++++++++++++++++++
Pablo Greco 7b2c62
 1 file changed, 22 insertions(+)
Pablo Greco 7b2c62
Pablo Greco 7b2c62
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
Pablo Greco 7b2c62
index 609bd25bf154..c701912b13ab 100644
Pablo Greco 7b2c62
--- a/drivers/iommu/iommu.c
Pablo Greco 7b2c62
+++ b/drivers/iommu/iommu.c
Pablo Greco 7b2c62
@@ -7,6 +7,7 @@
Pablo Greco 7b2c62
 #define pr_fmt(fmt)    "iommu: " fmt
Pablo Greco 7b2c62
Pablo Greco 7b2c62
 #include <linux/device.h>
Pablo Greco 7b2c62
+#include <linux/dmi.h>
Pablo Greco 7b2c62
 #include <linux/kernel.h>
Pablo Greco 7b2c62
 #include <linux/bug.h>
Pablo Greco 7b2c62
 #include <linux/types.h>
Pablo Greco 7b2c62
@@ -2849,3 +2850,24 @@ int iommu_sva_get_pasid(struct iommu_sva *handle)
Pablo Greco 7b2c62
 	return ops->sva_get_pasid(handle);
Pablo Greco 7b2c62
 }
Pablo Greco 7b2c62
 EXPORT_SYMBOL_GPL(iommu_sva_get_pasid);
Pablo Greco 7b2c62
+
Pablo Greco 7b2c62
+#ifdef CONFIG_ARM64
Pablo Greco 7b2c62
+static int __init iommu_quirks(void)
Pablo Greco 7b2c62
+{
Pablo Greco 7b2c62
+	const char *vendor, *name;
Pablo Greco 7b2c62
+
Pablo Greco 7b2c62
+	vendor = dmi_get_system_info(DMI_SYS_VENDOR);
Pablo Greco 7b2c62
+	name = dmi_get_system_info(DMI_PRODUCT_NAME);
Pablo Greco 7b2c62
+
Pablo Greco 7b2c62
+	if (vendor &&
Pablo Greco 7b2c62
+	    (strncmp(vendor, "GIGABYTE", 8) == 0 && name &&
Pablo Greco 7b2c62
+	     (strncmp(name, "R120", 4) == 0 ||
Pablo Greco 7b2c62
+	      strncmp(name, "R270", 4) == 0))) {
Pablo Greco 7b2c62
+		pr_warn("Gigabyte %s detected, force iommu passthrough mode", name);
Pablo Greco 7b2c62
+		iommu_def_domain_type = IOMMU_DOMAIN_IDENTITY;
Pablo Greco 7b2c62
+	}
Pablo Greco 7b2c62
+
Pablo Greco 7b2c62
+	return 0;
Pablo Greco 7b2c62
+}
Pablo Greco 7b2c62
+arch_initcall(iommu_quirks);
Pablo Greco 7b2c62
+#endif
Pablo Greco 7b2c62
-- 
Pablo Greco 7b2c62
2.28.0
Pablo Greco 7b2c62