summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorJoerg Roedel <jroedel@suse.de>2014-08-05 17:50:15 +0200
committerZefan Li <lizefan@huawei.com>2014-09-25 11:49:11 +0800
commit77e5657567adc61ab425a070c5a9ec13b20913e8 (patch)
tree07956e00130747421b9f235927c4d81b4bed6c1c /drivers
parentdb83744afb3a43a21722d3bb17c8e1e8da5a9cf7 (diff)
iommu/amd: Fix cleanup_domain for mass device removal
commit 9b29d3c6510407d91786c1cf9183ff4debb3473a upstream. When multiple devices are detached in __detach_device, they are also removed from the domains dev_list. This makes it unsafe to use list_for_each_entry_safe, as the next pointer might also not be in the list anymore after __detach_device returns. So just repeatedly remove the first element of the list until it is empty. Tested-by: Marti Raudsepp <marti@juffo.org> Signed-off-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Zefan Li <lizefan@huawei.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/iommu/amd_iommu.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index c0536eda58e9..a55353c37b3d 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -3028,14 +3028,16 @@ free_domains:
static void cleanup_domain(struct protection_domain *domain)
{
- struct iommu_dev_data *dev_data, *next;
+ struct iommu_dev_data *entry;
unsigned long flags;
write_lock_irqsave(&amd_iommu_devtable_lock, flags);
- list_for_each_entry_safe(dev_data, next, &domain->dev_list, list) {
- __detach_device(dev_data);
- atomic_set(&dev_data->bind, 0);
+ while (!list_empty(&domain->dev_list)) {
+ entry = list_first_entry(&domain->dev_list,
+ struct iommu_dev_data, list);
+ __detach_device(entry);
+ atomic_set(&entry->bind, 0);
}
write_unlock_irqrestore(&amd_iommu_devtable_lock, flags);