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