Merge tag 'pci-v5.14-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaa...
[sfrench/cifs-2.6.git] / drivers / pci / probe.c
index 72fccb86330f767e5a42912da5b4a00d8ef7db99..cd6fcd84885358c2550ce301f790ffe2e29ce6ec 100644 (file)
@@ -943,7 +943,8 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge)
        device_enable_async_suspend(bus->bridge);
        pci_set_bus_of_node(bus);
        pci_set_bus_msi_domain(bus);
-       if (bridge->msi_domain && !dev_get_msi_domain(&bus->dev))
+       if (bridge->msi_domain && !dev_get_msi_domain(&bus->dev) &&
+           !pci_host_of_has_msi_map(parent))
                bus->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
 
        if (!parent)
@@ -1617,6 +1618,26 @@ static void set_pcie_untrusted(struct pci_dev *dev)
                dev->untrusted = true;
 }
 
+static void pci_set_removable(struct pci_dev *dev)
+{
+       struct pci_dev *parent = pci_upstream_bridge(dev);
+
+       /*
+        * We (only) consider everything downstream from an external_facing
+        * device to be removable by the user. We're mainly concerned with
+        * consumer platforms with user accessible thunderbolt ports that are
+        * vulnerable to DMA attacks, and we expect those ports to be marked by
+        * the firmware as external_facing. Devices in traditional hotplug
+        * slots can technically be removed, but the expectation is that unless
+        * the port is marked with external_facing, such devices are less
+        * accessible to user / may not be removed by end user, and thus not
+        * exposed as "removable" to userspace.
+        */
+       if (parent &&
+           (parent->external_facing || dev_is_removable(&parent->dev)))
+               dev_set_removable(&dev->dev, DEVICE_REMOVABLE);
+}
+
 /**
  * pci_ext_cfg_is_aliased - Is ext config space just an alias of std config?
  * @dev: PCI device
@@ -1864,6 +1885,8 @@ int pci_setup_device(struct pci_dev *dev)
        /* Early fixups, before probing the BARs */
        pci_fixup_device(pci_fixup_early, dev);
 
+       pci_set_removable(dev);
+
        pci_info(dev, "[%04x:%04x] type %02x class %#08x\n",
                 dev->vendor, dev->device, dev->hdr_type, dev->class);