Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

amd_iommu: Make use of DMA quirks and ACS checks in IOMMU groups

Work around broken devices and adhere to ACS support when determining
IOMMU grouping.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>

authored by

Alex Williamson and committed by
Joerg Roedel
664b6003 abdfdde2

+25
+25
drivers/iommu/amd_iommu.c
··· 254 254 return true; 255 255 } 256 256 257 + static void swap_pci_ref(struct pci_dev **from, struct pci_dev *to) 258 + { 259 + pci_dev_put(*from); 260 + *from = to; 261 + } 262 + 263 + #define REQ_ACS_FLAGS (PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF) 264 + 257 265 static int iommu_init_device(struct device *dev) 258 266 { 259 267 struct pci_dev *dma_pdev, *pdev = to_pci_dev(dev); ··· 293 285 dma_pdev = pci_get_bus_and_slot(alias >> 8, alias & 0xff); 294 286 } else 295 287 dma_pdev = pci_dev_get(pdev); 288 + 289 + swap_pci_ref(&dma_pdev, pci_get_dma_source(dma_pdev)); 290 + 291 + if (dma_pdev->multifunction && 292 + !pci_acs_enabled(dma_pdev, REQ_ACS_FLAGS)) 293 + swap_pci_ref(&dma_pdev, 294 + pci_get_slot(dma_pdev->bus, 295 + PCI_DEVFN(PCI_SLOT(dma_pdev->devfn), 296 + 0))); 297 + 298 + while (!pci_is_root_bus(dma_pdev->bus)) { 299 + if (pci_acs_path_enabled(dma_pdev->bus->self, 300 + NULL, REQ_ACS_FLAGS)) 301 + break; 302 + 303 + swap_pci_ref(&dma_pdev, pci_dev_get(dma_pdev->bus->self)); 304 + } 296 305 297 306 group = iommu_group_get(&dma_pdev->dev); 298 307 pci_dev_put(dma_pdev);