Skip to content

Commit 99b50be

Browse files
Rajat Jainbjorn-helgaas
authored andcommitted
PCI: Treat "external-facing" devices themselves as internal
"External-facing" devices are internal devices that expose PCIe hierarchies such as Thunderbolt outside the platform [1]. Previously these internal devices were marked as "untrusted" the same as devices downstream from them. Use the ACPI or DT information to identify external-facing devices, but only mark the devices *downstream* from them as "untrusted" [2]. The external-facing device itself is no longer marked as untrusted. [1] https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports#identifying-externally-exposed-pcie-root-ports [2] https://lore.kernel.org/linux-pci/20200610230906.GA1528594@bjorn-Precision-5520/ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rajat Jain <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 52fbf5b commit 99b50be

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4730,20 +4730,20 @@ const struct attribute_group *intel_iommu_groups[] = {
47304730
NULL,
47314731
};
47324732

4733-
static inline bool has_untrusted_dev(void)
4733+
static inline bool has_external_pci(void)
47344734
{
47354735
struct pci_dev *pdev = NULL;
47364736

47374737
for_each_pci_dev(pdev)
4738-
if (pdev->untrusted)
4738+
if (pdev->external_facing)
47394739
return true;
47404740

47414741
return false;
47424742
}
47434743

47444744
static int __init platform_optin_force_iommu(void)
47454745
{
4746-
if (!dmar_platform_optin() || no_platform_optin || !has_untrusted_dev())
4746+
if (!dmar_platform_optin() || no_platform_optin || !has_external_pci())
47474747
return 0;
47484748

47494749
if (no_iommu || dmar_disabled)

drivers/pci/of.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void pci_set_bus_of_node(struct pci_bus *bus)
4242
} else {
4343
node = of_node_get(bus->self->dev.of_node);
4444
if (node && of_property_read_bool(node, "external-facing"))
45-
bus->self->untrusted = true;
45+
bus->self->external_facing = true;
4646
}
4747

4848
bus->dev.of_node = node;

drivers/pci/pci-acpi.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ static void pci_acpi_optimize_delay(struct pci_dev *pdev,
12131213
ACPI_FREE(obj);
12141214
}
12151215

1216-
static void pci_acpi_set_untrusted(struct pci_dev *dev)
1216+
static void pci_acpi_set_external_facing(struct pci_dev *dev)
12171217
{
12181218
u8 val;
12191219

@@ -1224,11 +1224,10 @@ static void pci_acpi_set_untrusted(struct pci_dev *dev)
12241224

12251225
/*
12261226
* These root ports expose PCIe (including DMA) outside of the
1227-
* system so make sure we treat them and everything behind as
1228-
* untrusted.
1227+
* system. Everything downstream from them is external.
12291228
*/
12301229
if (val)
1231-
dev->untrusted = 1;
1230+
dev->external_facing = 1;
12321231
}
12331232

12341233
static void pci_acpi_setup(struct device *dev)
@@ -1240,7 +1239,7 @@ static void pci_acpi_setup(struct device *dev)
12401239
return;
12411240

12421241
pci_acpi_optimize_delay(pci_dev, adev->handle);
1243-
pci_acpi_set_untrusted(pci_dev);
1242+
pci_acpi_set_external_facing(pci_dev);
12441243
pci_acpi_add_edr_notifier(pci_dev);
12451244

12461245
pci_acpi_add_pm_notifier(adev, pci_dev);

drivers/pci/probe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ static void set_pcie_untrusted(struct pci_dev *dev)
15521552
* untrusted as well.
15531553
*/
15541554
parent = pci_upstream_bridge(dev);
1555-
if (parent && parent->untrusted)
1555+
if (parent && (parent->untrusted || parent->external_facing))
15561556
dev->untrusted = true;
15571557
}
15581558

include/linux/pci.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ struct pci_dev {
432432
* mappings to make sure they cannot access arbitrary memory.
433433
*/
434434
unsigned int untrusted:1;
435+
/*
436+
* Info from the platform, e.g., ACPI or device tree, may mark a
437+
* device as "external-facing". An external-facing device is
438+
* itself internal but devices downstream from it are external.
439+
*/
440+
unsigned int external_facing:1;
435441
unsigned int broken_intx_masking:1; /* INTx masking can't be used */
436442
unsigned int io_window_1k:1; /* Intel bridge 1K I/O windows */
437443
unsigned int irq_managed:1;

0 commit comments

Comments
 (0)