Commit 7f46f9c1 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'iommu-fixes-v3.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu

Pull IOMMU fixes from Joerg Roedel:
 "These patches fix a couple of issues.  First of all a few problems
  with ACS on x86 introduced in the last merge window, where ACS did not
  work on AMD and a NULL pointer dereference when there ran against
  SR-IOV devices.

  The patches fallen out of coccinelle checks fix a possible invalid
  memory reference and a possible memory leak.  The other patches mostly
  fix build errors and warnings and a wrong return value."

* tag 'iommu-fixes-v3.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu:
  iommu/amd: Fix ACS path checking
  iommu/intel: Fix ACS path checking
  iommu/amd: Fix pci_request_acs() call-place
  iommu/exynos: Fix build error
  iommu/tegra: smmu: Fix error initial value at domain_init
  iommu/tegra: smmu: Cleanup with lesser nest
  iommu: Add missing forward declaration in include file
  iommu: Include linux/types.h
  iommu/intel: add missing free_domain_mem
  iommu/tegra: remove invalid reference to list iterator variable
parents 6666cabf 31fe9435
...@@ -296,8 +296,13 @@ static int iommu_init_device(struct device *dev) ...@@ -296,8 +296,13 @@ static int iommu_init_device(struct device *dev)
} else } else
dma_pdev = pci_dev_get(pdev); dma_pdev = pci_dev_get(pdev);
/* Account for quirked devices */
swap_pci_ref(&dma_pdev, pci_get_dma_source(dma_pdev)); swap_pci_ref(&dma_pdev, pci_get_dma_source(dma_pdev));
/*
* If it's a multifunction device that does not support our
* required ACS flags, add to the same group as function 0.
*/
if (dma_pdev->multifunction && if (dma_pdev->multifunction &&
!pci_acs_enabled(dma_pdev, REQ_ACS_FLAGS)) !pci_acs_enabled(dma_pdev, REQ_ACS_FLAGS))
swap_pci_ref(&dma_pdev, swap_pci_ref(&dma_pdev,
...@@ -305,14 +310,28 @@ static int iommu_init_device(struct device *dev) ...@@ -305,14 +310,28 @@ static int iommu_init_device(struct device *dev)
PCI_DEVFN(PCI_SLOT(dma_pdev->devfn), PCI_DEVFN(PCI_SLOT(dma_pdev->devfn),
0))); 0)));
/*
* Devices on the root bus go through the iommu. If that's not us,
* find the next upstream device and test ACS up to the root bus.
* Finding the next device may require skipping virtual buses.
*/
while (!pci_is_root_bus(dma_pdev->bus)) { while (!pci_is_root_bus(dma_pdev->bus)) {
if (pci_acs_path_enabled(dma_pdev->bus->self, struct pci_bus *bus = dma_pdev->bus;
NULL, REQ_ACS_FLAGS))
while (!bus->self) {
if (!pci_is_root_bus(bus))
bus = bus->parent;
else
goto root_bus;
}
if (pci_acs_path_enabled(bus->self, NULL, REQ_ACS_FLAGS))
break; break;
swap_pci_ref(&dma_pdev, pci_dev_get(dma_pdev->bus->self)); swap_pci_ref(&dma_pdev, pci_dev_get(bus->self));
} }
root_bus:
group = iommu_group_get(&dma_pdev->dev); group = iommu_group_get(&dma_pdev->dev);
pci_dev_put(dma_pdev); pci_dev_put(dma_pdev);
if (!group) { if (!group) {
......
...@@ -1131,9 +1131,6 @@ static int __init amd_iommu_init_pci(void) ...@@ -1131,9 +1131,6 @@ static int __init amd_iommu_init_pci(void)
break; break;
} }
/* Make sure ACS will be enabled */
pci_request_acs();
ret = amd_iommu_init_devices(); ret = amd_iommu_init_devices();
print_iommu_info(); print_iommu_info();
...@@ -1652,6 +1649,9 @@ static bool detect_ivrs(void) ...@@ -1652,6 +1649,9 @@ static bool detect_ivrs(void)
early_acpi_os_unmap_memory((char __iomem *)ivrs_base, ivrs_size); early_acpi_os_unmap_memory((char __iomem *)ivrs_base, ivrs_size);
/* Make sure ACS will be enabled during PCI probe */
pci_request_acs();
return true; return true;
} }
......
...@@ -732,9 +732,9 @@ static int exynos_iommu_domain_init(struct iommu_domain *domain) ...@@ -732,9 +732,9 @@ static int exynos_iommu_domain_init(struct iommu_domain *domain)
spin_lock_init(&priv->pgtablelock); spin_lock_init(&priv->pgtablelock);
INIT_LIST_HEAD(&priv->clients); INIT_LIST_HEAD(&priv->clients);
dom->geometry.aperture_start = 0; domain->geometry.aperture_start = 0;
dom->geometry.aperture_end = ~0UL; domain->geometry.aperture_end = ~0UL;
dom->geometry.force_aperture = true; domain->geometry.force_aperture = true;
domain->priv = priv; domain->priv = priv;
return 0; return 0;
......
...@@ -2008,6 +2008,7 @@ static struct dmar_domain *get_domain_for_dev(struct pci_dev *pdev, int gaw) ...@@ -2008,6 +2008,7 @@ static struct dmar_domain *get_domain_for_dev(struct pci_dev *pdev, int gaw)
if (!drhd) { if (!drhd) {
printk(KERN_ERR "IOMMU: can't find DMAR for device %s\n", printk(KERN_ERR "IOMMU: can't find DMAR for device %s\n",
pci_name(pdev)); pci_name(pdev));
free_domain_mem(domain);
return NULL; return NULL;
} }
iommu = drhd->iommu; iommu = drhd->iommu;
...@@ -4124,8 +4125,13 @@ static int intel_iommu_add_device(struct device *dev) ...@@ -4124,8 +4125,13 @@ static int intel_iommu_add_device(struct device *dev)
} else } else
dma_pdev = pci_dev_get(pdev); dma_pdev = pci_dev_get(pdev);
/* Account for quirked devices */
swap_pci_ref(&dma_pdev, pci_get_dma_source(dma_pdev)); swap_pci_ref(&dma_pdev, pci_get_dma_source(dma_pdev));
/*
* If it's a multifunction device that does not support our
* required ACS flags, add to the same group as function 0.
*/
if (dma_pdev->multifunction && if (dma_pdev->multifunction &&
!pci_acs_enabled(dma_pdev, REQ_ACS_FLAGS)) !pci_acs_enabled(dma_pdev, REQ_ACS_FLAGS))
swap_pci_ref(&dma_pdev, swap_pci_ref(&dma_pdev,
...@@ -4133,14 +4139,28 @@ static int intel_iommu_add_device(struct device *dev) ...@@ -4133,14 +4139,28 @@ static int intel_iommu_add_device(struct device *dev)
PCI_DEVFN(PCI_SLOT(dma_pdev->devfn), PCI_DEVFN(PCI_SLOT(dma_pdev->devfn),
0))); 0)));
/*
* Devices on the root bus go through the iommu. If that's not us,
* find the next upstream device and test ACS up to the root bus.
* Finding the next device may require skipping virtual buses.
*/
while (!pci_is_root_bus(dma_pdev->bus)) { while (!pci_is_root_bus(dma_pdev->bus)) {
if (pci_acs_path_enabled(dma_pdev->bus->self, struct pci_bus *bus = dma_pdev->bus;
NULL, REQ_ACS_FLAGS))
while (!bus->self) {
if (!pci_is_root_bus(bus))
bus = bus->parent;
else
goto root_bus;
}
if (pci_acs_path_enabled(bus->self, NULL, REQ_ACS_FLAGS))
break; break;
swap_pci_ref(&dma_pdev, pci_dev_get(dma_pdev->bus->self)); swap_pci_ref(&dma_pdev, pci_dev_get(bus->self));
} }
root_bus:
group = iommu_group_get(&dma_pdev->dev); group = iommu_group_get(&dma_pdev->dev);
pci_dev_put(dma_pdev); pci_dev_put(dma_pdev);
if (!group) { if (!group) {
......
...@@ -799,14 +799,14 @@ static void smmu_iommu_detach_dev(struct iommu_domain *domain, ...@@ -799,14 +799,14 @@ static void smmu_iommu_detach_dev(struct iommu_domain *domain,
goto out; goto out;
} }
} }
dev_err(smmu->dev, "Couldn't find %s\n", dev_name(c->dev)); dev_err(smmu->dev, "Couldn't find %s\n", dev_name(dev));
out: out:
spin_unlock(&as->client_lock); spin_unlock(&as->client_lock);
} }
static int smmu_iommu_domain_init(struct iommu_domain *domain) static int smmu_iommu_domain_init(struct iommu_domain *domain)
{ {
int i, err = -ENODEV; int i, err = -EAGAIN;
unsigned long flags; unsigned long flags;
struct smmu_as *as; struct smmu_as *as;
struct smmu_device *smmu = smmu_handle; struct smmu_device *smmu = smmu_handle;
...@@ -814,11 +814,14 @@ static int smmu_iommu_domain_init(struct iommu_domain *domain) ...@@ -814,11 +814,14 @@ static int smmu_iommu_domain_init(struct iommu_domain *domain)
/* Look for a free AS with lock held */ /* Look for a free AS with lock held */
for (i = 0; i < smmu->num_as; i++) { for (i = 0; i < smmu->num_as; i++) {
as = &smmu->as[i]; as = &smmu->as[i];
if (!as->pdir_page) {
if (as->pdir_page)
continue;
err = alloc_pdir(as); err = alloc_pdir(as);
if (!err) if (!err)
goto found; goto found;
}
if (err != -EAGAIN) if (err != -EAGAIN)
break; break;
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#define __LINUX_IOMMU_H #define __LINUX_IOMMU_H
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/types.h>
#define IOMMU_READ (1) #define IOMMU_READ (1)
#define IOMMU_WRITE (2) #define IOMMU_WRITE (2)
...@@ -30,6 +31,7 @@ struct iommu_group; ...@@ -30,6 +31,7 @@ struct iommu_group;
struct bus_type; struct bus_type;
struct device; struct device;
struct iommu_domain; struct iommu_domain;
struct notifier_block;
/* iommu fault flags */ /* iommu fault flags */
#define IOMMU_FAULT_READ 0x0 #define IOMMU_FAULT_READ 0x0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment