pci: Rename pci_dev->untrusted to pci_dev->external
Subsystems (4)
PATCH 1/1 pci: Rename pci_dev->untrusted to pci_dev->external
The current flag name "untrusted" is not correct as it is populated using the firmware property "external-facing" for the parent ports. In other words, the firmware only says which ports are external facing, so the field really identifies the devices as external (vs internal).
Only field renaming. No functional change intended.
--- drivers/iommu/dma-iommu.c | 2 +- drivers/iommu/intel/iommu.c | 2 +- drivers/iommu/iommu.c | 2 +- drivers/pci/ats.c | 2 +- drivers/pci/pci.c | 2 +- drivers/pci/probe.c | 12 ++++++------ drivers/pci/quirks.c | 2 +- include/linux/pci.h | 9 +-------- 8 files changed, 13 insertions(+), 20 deletions(-)
drivers/iommu/dma-iommu.c +1 -1
@@ -313,7 +313,7 @@ static void iommu_dma_flush_iotlb_all(struct iova_domain *iovad)static bool dev_is_untrusted (struct device *dev) { -return dev_is_pci (dev) &&to_pci_dev (dev)->untrusted; +return dev_is_pci (dev) &&to_pci_dev (dev)->external; }/**
drivers/iommu/intel/iommu.c +1 -1
@@ -5511,7 +5511,7 @@ intel_iommu_domain_get_attr(struct iommu_domain *domain,*/ static bool risky_device (struct pci_dev *pdev) { -if (pdev->untrusted) { +if (pdev->external) {pci_info (pdev,"Skipping IOMMU quirk for dev [%04X:%04X] on untrusted PCI link\n" , pdev->vendor, pdev->device);
drivers/iommu/iommu.c +1 -1
@@ -1482,7 +1482,7 @@ static int iommu_get_def_domain_type(struct device *dev) {const struct iommu_ops *ops = dev->bus->iommu_ops; -if (dev_is_pci (dev) &&to_pci_dev (dev)->untrusted) +if (dev_is_pci (dev) &&to_pci_dev (dev)->external)return IOMMU_DOMAIN_DMA ;if (ops->def_domain_type)
drivers/pci/ats.c +1 -1
@@ -42,7 +42,7 @@ bool pci_ats_supported(struct pci_dev *dev)if (!dev->ats_cap)return false; -return (dev->untrusted ==0 ); +return (dev->external ==0 ); }EXPORT_SYMBOL_GPL (pci_ats_supported);
drivers/pci/pci.c +1 -1
@@ -886,7 +886,7 @@ static void pci_std_enable_acs(struct pci_dev *dev) ctrl |= (cap &PCI_ACS_UF );/* Enable Translation Blocking for external devices */ -if (dev->external_facing || dev->untrusted) +if (dev->external_facing || dev->external) ctrl |= (cap &PCI_ACS_TB );pci_write_config_word (dev, pos +PCI_ACS_CTRL , ctrl);
drivers/pci/probe.c +6 -6
@@ -1562,17 +1562,17 @@ static void set_pcie_thunderbolt(struct pci_dev *dev) } } -static void set_pcie_untrusted (struct pci_dev *dev) +static void set_pcie_external (struct pci_dev *dev) {struct pci_dev *parent;/* -* If the upstream bridge is untrusted we treat this device -* untrusted as well. +* If the upstream bridge is external we mark this device +* external as well. */ parent =pci_upstream_bridge (dev); -if (parent && (parent->untrusted || parent->external_facing)) - dev->untrusted = true; +if (parent && (parent->external || parent->external_facing)) + dev->external = true; }/**
@@ -1814,7 +1814,7 @@ int pci_setup_device(struct pci_dev *dev)/* Need to have dev->cfg_size ready */ set_pcie_thunderbolt (dev); -set_pcie_untrusted (dev); +set_pcie_external (dev);/* "Unknown power state" */ dev->current_state =PCI_UNKNOWN ;
drivers/pci/quirks.c +1 -1
@@ -4942,7 +4942,7 @@ static int pci_quirk_enable_intel_spt_pch_acs(struct pci_dev *dev) ctrl |= (cap &PCI_ACS_CR ); ctrl |= (cap &PCI_ACS_UF ); -if (dev->external_facing || dev->untrusted) +if (dev->external_facing || dev->external) ctrl |= (cap &PCI_ACS_TB );pci_write_config_dword (dev, pos +INTEL_SPT_ACS_CTRL , ctrl);
include/linux/pci.h +1 -8
@@ -431,14 +431,7 @@ struct pci_dev { unsigned int is_hotplug_bridge:1; unsigned int shpc_managed:1; /* SHPC owned by shpchp */ unsigned int is_thunderbolt:1; /* Thunderbolt controller */ -/* -* Devices marked being untrusted are the ones that can potentially -* execute DMA attacks and similar. They are typically connected -* through external ports such as Thunderbolt but not limited to -* that. When an IOMMU is enabled they should be getting full -* mappings to make sure they cannot access arbitrary memory. -*/ - unsigned int untrusted:1; + unsigned int external:1; /* Device sits on an external PCI bus *//* * Info from the platform, e.g., ACPI or device tree, may mark a * device as "external-facing". An external-facing device is
Signature · 1 line
2.31.1.368.gbe11c130af-goog
Quoted 6 lines · Rajat Jain
The current flag name "untrusted" is not correct as it is populated using the firmware property "external-facing" for the parent ports. In other words, the firmware only says which ports are external facing, so the field really identifies the devices as external (vs internal).
Only field renaming. No functional change intended.
I don't think this is a good idea. First the field should have been added to the generic struct device as requested multiple times before. Right now this requires horrible hacks in the IOMMU code to get at the pci_dev, and also doesn't scale to various other potential users.
Second the untrusted is objectively a better name. Because untrusted is how we treat the device, which is what mattes. External is just how we come to that conclusion.
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Rajat Jain
The current flag name "untrusted" is not correct as it is populated using the firmware property "external-facing" for the parent ports. In other words, the firmware only says which ports are external facing, so the field really identifies the devices as external (vs internal).
Only field renaming. No functional change intended.
I don't think this is a good idea. First the field should have been added to the generic struct device as requested multiple times before.
Fair point. There isn't anything PCI-specific about this idea. The ACPI "ExternalFacingPort" and DT "external-facing" are currently only defined for PCI devices, but could be applied elsewhere.
Quoted 2 lines
Right now this requires horrible hacks in the IOMMU code to get at the
pci_dev, and also doesn't scale to various other potential users.
Agreed, this is definitely suboptimal. Do you have other users in mind? Maybe they could help inform the plan.
Quoted 3 lines
Second the untrusted is objectively a better name. Because untrusted is how we treat the device, which is what mattes. External is just how we come to that conclusion.
The decision to treat "external" as being "untrusted" is a little bit of policy that the PCI core really doesn't care about, so I think it does make some sense to let the places that *do* care decide what to trust based on "external" and possibly other factors, e.g., whether the device is a BMC or processes untrusted data, etc.
But I guess it makes sense to wait until we have a better motivation before renaming it, since we don't gain any functionality here.
Bjorn