Oliver Neukum 25aa1f
From ecaa4902439298f6b0e29f47424a86b310a9ff4f Mon Sep 17 00:00:00 2001
Oliver Neukum 25aa1f
From: D Scott Phillips <scott@os.amperecomputing.com>
Oliver Neukum 25aa1f
Date: Thu, 30 Mar 2023 17:30:54 +0300
Oliver Neukum 25aa1f
Subject: [PATCH] xhci: also avoid the XHCI_ZERO_64B_REGS quirk with a
Oliver Neukum 25aa1f
 passthrough iommu
Oliver Neukum 25aa1f
Git-commit: ecaa4902439298f6b0e29f47424a86b310a9ff4f
Oliver Neukum 25aa1f
References: git-fixes
Oliver Neukum 25aa1f
Patch-mainline: v6.3-rc6
Oliver Neukum 25aa1f
Oliver Neukum 25aa1f
Previously the quirk was skipped when no iommu was present. The same
Oliver Neukum 25aa1f
rationale for skipping the quirk also applies in the iommu.passthrough=1
Oliver Neukum 25aa1f
case.
Oliver Neukum 25aa1f
Oliver Neukum 25aa1f
Skip applying the XHCI_ZERO_64B_REGS quirk if the device's iommu domain is
Oliver Neukum 25aa1f
passthrough.
Oliver Neukum 25aa1f
Oliver Neukum 25aa1f
Fixes: 12de0a35c996 ("xhci: Add quirk to zero 64bit registers on Renesas PCIe controllers")
Oliver Neukum 25aa1f
Cc: stable <stable@kernel.org>
Oliver Neukum 25aa1f
Signed-off-by: D Scott Phillips <scott@os.amperecomputing.com>
Oliver Neukum 25aa1f
Acked-by: Marc Zyngier <maz@kernel.org>
Oliver Neukum 25aa1f
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Oliver Neukum 25aa1f
Link: https://lore.kernel.org/r/20230330143056.1390020-2-mathias.nyman@linux.intel.com
Oliver Neukum 25aa1f
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Oliver Neukum 25aa1f
Signed-off-by: Oliver Neukum <oneukum@suse.com>
Oliver Neukum 25aa1f
---
Oliver Neukum 25aa1f
 drivers/usb/host/xhci.c |    6 +++++-
Oliver Neukum 25aa1f
 1 file changed, 5 insertions(+), 1 deletion(-)
Oliver Neukum 25aa1f
Oliver Neukum 25aa1f
--- a/drivers/usb/host/xhci.c
Oliver Neukum 25aa1f
+++ b/drivers/usb/host/xhci.c
Oliver Neukum 25aa1f
@@ -21,6 +21,7 @@
Oliver Neukum 25aa1f
  */
Oliver Neukum 25aa1f
 
Oliver Neukum 25aa1f
 #include <linux/pci.h>
Oliver Neukum 25aa1f
+#include <linux/iommu.h>
Oliver Neukum 25aa1f
 #include <linux/iopoll.h>
Oliver Neukum 25aa1f
 #include <linux/irq.h>
Oliver Neukum 25aa1f
 #include <linux/log2.h>
Oliver Neukum 25aa1f
@@ -237,6 +238,7 @@ int xhci_reset(struct xhci_hcd *xhci)
Oliver Neukum 25aa1f
 static void xhci_zero_64b_regs(struct xhci_hcd *xhci)
Oliver Neukum 25aa1f
 {
Oliver Neukum 25aa1f
 	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
Oliver Neukum 25aa1f
+	struct iommu_domain *domain;
Oliver Neukum 25aa1f
 	int err, i;
Oliver Neukum 25aa1f
 	u64 val;
Oliver Neukum 25aa1f
 
Oliver Neukum 25aa1f
@@ -254,7 +256,9 @@ static void xhci_zero_64b_regs(struct xh
Oliver Neukum 25aa1f
 	 * an iommu. Doing anything when there is no iommu is definitely
Oliver Neukum 25aa1f
 	 * unsafe...
Oliver Neukum 25aa1f
 	 */
Oliver Neukum 25aa1f
-	if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !dev->iommu_group)
Oliver Neukum 25aa1f
+	domain = iommu_get_domain_for_dev(dev);
Oliver Neukum 25aa1f
+	if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !dev->iommu_group ||
Oliver Neukum 25aa1f
+			domain->type == IOMMU_DOMAIN_IDENTITY)
Oliver Neukum 25aa1f
 		return;
Oliver Neukum 25aa1f
 
Oliver Neukum 25aa1f
 	xhci_info(xhci, "Zeroing 64bit base registers, expecting fault\n");