diff options
-rw-r--r-- | arch/x86/include/asm/amd_iommu_types.h | 2 | ||||
-rw-r--r-- | arch/x86/kernel/amd_iommu.c | 34 |
2 files changed, 16 insertions, 20 deletions
diff --git a/arch/x86/include/asm/amd_iommu_types.h b/arch/x86/include/asm/amd_iommu_types.h index fffbe3c9e6c2..5b9c5075e81a 100644 --- a/arch/x86/include/asm/amd_iommu_types.h +++ b/arch/x86/include/asm/amd_iommu_types.h | |||
@@ -311,7 +311,7 @@ struct protection_domain { | |||
311 | struct iommu_dev_data { | 311 | struct iommu_dev_data { |
312 | struct list_head list; /* For domain->dev_list */ | 312 | struct list_head list; /* For domain->dev_list */ |
313 | struct list_head dev_data_list; /* For global dev_data_list */ | 313 | struct list_head dev_data_list; /* For global dev_data_list */ |
314 | struct device *alias; /* The Alias Device */ | 314 | struct iommu_dev_data *alias_data;/* The alias dev_data */ |
315 | struct protection_domain *domain; /* Domain the device is bound to */ | 315 | struct protection_domain *domain; /* Domain the device is bound to */ |
316 | atomic_t bind; /* Domain attach reverent count */ | 316 | atomic_t bind; /* Domain attach reverent count */ |
317 | u16 devid; /* PCI Device ID */ | 317 | u16 devid; /* PCI Device ID */ |
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c index f64799878d45..0ed1c940d76b 100644 --- a/arch/x86/kernel/amd_iommu.c +++ b/arch/x86/kernel/amd_iommu.c | |||
@@ -203,7 +203,6 @@ static bool check_device(struct device *dev) | |||
203 | static int iommu_init_device(struct device *dev) | 203 | static int iommu_init_device(struct device *dev) |
204 | { | 204 | { |
205 | struct iommu_dev_data *dev_data; | 205 | struct iommu_dev_data *dev_data; |
206 | struct pci_dev *pdev; | ||
207 | u16 alias; | 206 | u16 alias; |
208 | 207 | ||
209 | if (dev->archdata.iommu) | 208 | if (dev->archdata.iommu) |
@@ -215,13 +214,16 @@ static int iommu_init_device(struct device *dev) | |||
215 | 214 | ||
216 | alias = amd_iommu_alias_table[dev_data->devid]; | 215 | alias = amd_iommu_alias_table[dev_data->devid]; |
217 | if (alias != dev_data->devid) { | 216 | if (alias != dev_data->devid) { |
218 | pdev = pci_get_bus_and_slot(PCI_BUS(alias), alias & 0xff); | 217 | struct iommu_dev_data *alias_data; |
219 | if (pdev) | 218 | |
220 | dev_data->alias = &pdev->dev; | 219 | alias_data = find_dev_data(alias); |
221 | else { | 220 | if (alias_data == NULL) { |
221 | pr_err("AMD-Vi: Warning: Unhandled device %s\n", | ||
222 | dev_name(dev)); | ||
222 | free_dev_data(dev_data); | 223 | free_dev_data(dev_data); |
223 | return -ENOTSUPP; | 224 | return -ENOTSUPP; |
224 | } | 225 | } |
226 | dev_data->alias_data = alias_data; | ||
225 | } | 227 | } |
226 | 228 | ||
227 | dev->archdata.iommu = dev_data; | 229 | dev->archdata.iommu = dev_data; |
@@ -1642,14 +1644,8 @@ static int __attach_device(struct iommu_dev_data *dev_data, | |||
1642 | /* lock domain */ | 1644 | /* lock domain */ |
1643 | spin_lock(&domain->lock); | 1645 | spin_lock(&domain->lock); |
1644 | 1646 | ||
1645 | if (dev_data->alias != NULL) { | 1647 | if (dev_data->alias_data != NULL) { |
1646 | struct iommu_dev_data *alias_data; | 1648 | struct iommu_dev_data *alias_data = dev_data->alias_data; |
1647 | |||
1648 | alias_data = get_dev_data(dev_data->alias); | ||
1649 | |||
1650 | ret = -EINVAL; | ||
1651 | if (!alias_data) | ||
1652 | goto out_unlock; | ||
1653 | 1649 | ||
1654 | /* Some sanity checks */ | 1650 | /* Some sanity checks */ |
1655 | ret = -EBUSY; | 1651 | ret = -EBUSY; |
@@ -1721,7 +1717,6 @@ static int attach_device(struct device *dev, | |||
1721 | */ | 1717 | */ |
1722 | static void __detach_device(struct iommu_dev_data *dev_data) | 1718 | static void __detach_device(struct iommu_dev_data *dev_data) |
1723 | { | 1719 | { |
1724 | struct iommu_dev_data *alias_data; | ||
1725 | struct protection_domain *domain; | 1720 | struct protection_domain *domain; |
1726 | unsigned long flags; | 1721 | unsigned long flags; |
1727 | 1722 | ||
@@ -1731,8 +1726,9 @@ static void __detach_device(struct iommu_dev_data *dev_data) | |||
1731 | 1726 | ||
1732 | spin_lock_irqsave(&domain->lock, flags); | 1727 | spin_lock_irqsave(&domain->lock, flags); |
1733 | 1728 | ||
1734 | if (dev_data->alias) { | 1729 | if (dev_data->alias_data != NULL) { |
1735 | alias_data = get_dev_data(dev_data->alias); | 1730 | struct iommu_dev_data *alias_data = dev_data->alias_data; |
1731 | |||
1736 | if (atomic_dec_and_test(&alias_data->bind)) | 1732 | if (atomic_dec_and_test(&alias_data->bind)) |
1737 | do_detach(alias_data); | 1733 | do_detach(alias_data); |
1738 | } | 1734 | } |
@@ -1779,7 +1775,7 @@ static void detach_device(struct device *dev) | |||
1779 | */ | 1775 | */ |
1780 | static struct protection_domain *domain_for_device(struct device *dev) | 1776 | static struct protection_domain *domain_for_device(struct device *dev) |
1781 | { | 1777 | { |
1782 | struct iommu_dev_data *dev_data, *alias_data; | 1778 | struct iommu_dev_data *dev_data; |
1783 | struct protection_domain *dom = NULL; | 1779 | struct protection_domain *dom = NULL; |
1784 | unsigned long flags; | 1780 | unsigned long flags; |
1785 | 1781 | ||
@@ -1788,8 +1784,8 @@ static struct protection_domain *domain_for_device(struct device *dev) | |||
1788 | if (dev_data->domain) | 1784 | if (dev_data->domain) |
1789 | return dev_data->domain; | 1785 | return dev_data->domain; |
1790 | 1786 | ||
1791 | if (dev_data->alias != NULL) { | 1787 | if (dev_data->alias_data != NULL) { |
1792 | alias_data = get_dev_data(dev_data->alias); | 1788 | struct iommu_dev_data *alias_data = dev_data->alias_data; |
1793 | 1789 | ||
1794 | read_lock_irqsave(&amd_iommu_devtable_lock, flags); | 1790 | read_lock_irqsave(&amd_iommu_devtable_lock, flags); |
1795 | if (alias_data->domain != NULL) { | 1791 | if (alias_data->domain != NULL) { |