Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b29d3c6 authored by Joerg Roedel's avatar Joerg Roedel
Browse files

iommu/amd: Fix cleanup_domain for mass device removal



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.

Cc: stable@vger.kernel.org
Tested-by: default avatarMarti Raudsepp <marti@juffo.org>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent e7f9fa54
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -3149,14 +3149,16 @@ int __init amd_iommu_init_dma_ops(void)


static void cleanup_domain(struct protection_domain *domain)
static void cleanup_domain(struct protection_domain *domain)
{
{
	struct iommu_dev_data *dev_data, *next;
	struct iommu_dev_data *entry;
	unsigned long flags;
	unsigned long flags;


	write_lock_irqsave(&amd_iommu_devtable_lock, flags);
	write_lock_irqsave(&amd_iommu_devtable_lock, flags);


	list_for_each_entry_safe(dev_data, next, &domain->dev_list, list) {
	while (!list_empty(&domain->dev_list)) {
		__detach_device(dev_data);
		entry = list_first_entry(&domain->dev_list,
		atomic_set(&dev_data->bind, 0);
					 struct iommu_dev_data, list);
		__detach_device(entry);
		atomic_set(&entry->bind, 0);
	}
	}


	write_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
	write_unlock_irqrestore(&amd_iommu_devtable_lock, flags);