All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thunderbolt: Stop using iommu_present()
@ 2022-03-16 11:25 ` Robin Murphy
  0 siblings, 0 replies; 36+ messages in thread
From: Robin Murphy @ 2022-03-16 11:25 UTC (permalink / raw)
  To: andreas.noever, michael.jamet, mika.westerberg, YehezkelShB
  Cc: linux-usb, linux-kernel, iommu, mario.limonciello, hch

Even if an IOMMU might be present for some PCI segment in the system,
that doesn't necessarily mean it provides translation for the device
we care about. Furthermore, the presence or not of one firmware flag
doesn't imply anything about the IOMMU driver's behaviour, which may
still depend on other firmware properties and kernel options too. What
actually matters is whether an IOMMU is enforcing protection for our
device - regardless of whether that stemmed from firmware policy, kernel
config, or user control - at the point we need to decide whether to
authorise it. We can ascertain that generically by simply looking at
whether we're currently attached to a translation domain or not.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---

I don't have the means to test this, but I'm at least 80% confident
in my unpicking of the structures to retrieve the correct device...

 drivers/thunderbolt/domain.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/thunderbolt/domain.c b/drivers/thunderbolt/domain.c
index 7018d959f775..5f5fc5f6a09b 100644
--- a/drivers/thunderbolt/domain.c
+++ b/drivers/thunderbolt/domain.c
@@ -257,13 +257,14 @@ static ssize_t iommu_dma_protection_show(struct device *dev,
 					 struct device_attribute *attr,
 					 char *buf)
 {
+	struct tb *tb = container_of(dev, struct tb, dev);
+	struct iommu_domain *iod = iommu_get_domain_for_dev(&tb->nhi->pdev->dev);
 	/*
 	 * Kernel DMA protection is a feature where Thunderbolt security is
 	 * handled natively using IOMMU. It is enabled when IOMMU is
-	 * enabled and ACPI DMAR table has DMAR_PLATFORM_OPT_IN set.
+	 * enabled and actively enforcing translation.
 	 */
-	return sprintf(buf, "%d\n",
-		       iommu_present(&pci_bus_type) && dmar_platform_optin());
+	return sprintf(buf, "%d\n", iod && iod->type != IOMMU_DOMAIN_IDENTITY);
 }
 static DEVICE_ATTR_RO(iommu_dma_protection);
 
-- 
2.28.0.dirty


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

end of thread, other threads:[~2022-03-17 14:23 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-16 11:25 [PATCH] thunderbolt: Stop using iommu_present() Robin Murphy
2022-03-16 11:25 ` Robin Murphy
2022-03-16 12:45 ` Mika Westerberg
2022-03-16 12:45   ` Mika Westerberg
2022-03-16 14:49   ` Robin Murphy
2022-03-16 14:49     ` Robin Murphy
2022-03-16 17:18     ` Mika Westerberg
2022-03-16 17:18       ` Mika Westerberg
2022-03-16 17:24       ` Limonciello, Mario
2022-03-16 17:24         ` Limonciello, Mario via iommu
2022-03-16 17:37         ` Mika Westerberg
2022-03-16 17:37           ` Mika Westerberg
2022-03-16 17:49           ` Robin Murphy
2022-03-16 17:49             ` Robin Murphy
2022-03-16 17:53             ` Limonciello, Mario
2022-03-16 17:53               ` Limonciello, Mario via iommu
2022-03-16 18:08               ` Limonciello, Mario
2022-03-16 18:08                 ` Limonciello, Mario via iommu
2022-03-16 18:22               ` Robin Murphy
2022-03-16 18:22                 ` Robin Murphy
2022-03-16 18:34                 ` Limonciello, Mario
2022-03-16 18:34                   ` Limonciello, Mario via iommu
2022-03-16 19:17                   ` Robin Murphy
2022-03-16 19:17                     ` Robin Murphy
2022-03-16 19:25                     ` Limonciello, Mario
2022-03-16 19:25                       ` Limonciello, Mario via iommu
2022-03-17  8:08                     ` Mika Westerberg
2022-03-17  8:08                       ` Mika Westerberg
2022-03-17 13:42                       ` Robin Murphy
2022-03-17 13:42                         ` Robin Murphy
2022-03-17 14:21                         ` Mika Westerberg
2022-03-17 14:21                           ` Mika Westerberg
2022-03-17  6:30                   ` Mika Westerberg
2022-03-17  6:30                     ` Mika Westerberg
2022-03-16 14:49   ` Limonciello, Mario
2022-03-16 14:49     ` Limonciello, Mario via iommu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.