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

Commit 74a8147a authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "iommu/iommu-debug: Maintain list of domains during alloc"

parents 2b1907cd e6e311e0
Loading
Loading
Loading
Loading
+65 −18
Original line number Diff line number Diff line
/*
 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
 * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -275,8 +275,7 @@ err_rmdir:
	return -EIO;
}

void iommu_debug_attach_device(struct iommu_domain *domain,
			       struct device *dev)
void iommu_debug_domain_add(struct iommu_domain *domain)
{
	struct iommu_debug_attachment *attach;

@@ -287,6 +286,47 @@ void iommu_debug_attach_device(struct iommu_domain *domain,
		goto out_unlock;

	attach->domain = domain;
	attach->dev = NULL;
	list_add(&attach->list, &iommu_debug_attachments);

out_unlock:
	mutex_unlock(&iommu_debug_attachments_lock);
}

void iommu_debug_domain_remove(struct iommu_domain *domain)
{
	struct iommu_debug_attachment *it;

	mutex_lock(&iommu_debug_attachments_lock);
	list_for_each_entry(it, &iommu_debug_attachments, list)
		if (it->domain == domain && it->dev == NULL)
			break;

	if (&it->list == &iommu_debug_attachments) {
		WARN(1, "Couldn't find debug attachment for domain=0x%p",
				domain);
	} else {
		list_del(&it->list);
		kfree(it);
	}
	mutex_unlock(&iommu_debug_attachments_lock);
}

void iommu_debug_attach_device(struct iommu_domain *domain,
			       struct device *dev)
{
	struct iommu_debug_attachment *attach;

	mutex_lock(&iommu_debug_attachments_lock);

	list_for_each_entry(attach, &iommu_debug_attachments, list)
		if (attach->domain == domain && attach->dev == NULL)
			break;

	if (&attach->list == &iommu_debug_attachments) {
		WARN(1, "Couldn't find debug attachment for domain=0x%p dev=%s",
		     domain, dev_name(dev));
	} else {
		attach->dev = dev;

		/*
@@ -296,11 +336,11 @@ void iommu_debug_attach_device(struct iommu_domain *domain,
		 * directory (by calling debugfs_create_dir with a NULL
		 * parent). These will be flushed out later once we init.
		 */

		if (debugfs_attachments_dir)
			iommu_debug_attach_add_debugfs(attach);
	}

	list_add(&attach->list, &iommu_debug_attachments);
out_unlock:
	mutex_unlock(&iommu_debug_attachments_lock);
}

@@ -318,9 +358,15 @@ void iommu_debug_detach_device(struct iommu_domain *domain,
		WARN(1, "Couldn't find debug attachment for domain=0x%p dev=%s",
		     domain, dev_name(dev));
	} else {
		list_del(&it->list);
		/*
		 * Just remove debugfs entry and mark dev as NULL on
		 * iommu_detach call. We would remove the actual
		 * attachment entry from the list only on domain_free call.
		 * This is to ensure we keep track of unattached domains too.
		 */

		debugfs_remove_recursive(it->dentry);
		kfree(it);
		it->dev = NULL;
	}
	mutex_unlock(&iommu_debug_attachments_lock);
}
@@ -341,6 +387,7 @@ static int iommu_debug_init_tracking(void)

	/* set up debugfs entries for attachments made during early boot */
	list_for_each_entry(attach, &iommu_debug_attachments, list)
		if (attach->dev)
			iommu_debug_attach_add_debugfs(attach);

out_unlock:
+10 −0
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@

void iommu_debug_attach_device(struct iommu_domain *domain, struct device *dev);
void iommu_debug_detach_device(struct iommu_domain *domain, struct device *dev);
void iommu_debug_domain_add(struct iommu_domain *domain);
void iommu_debug_domain_remove(struct iommu_domain *domain);

#else  /* !CONFIG_IOMMU_DEBUG_TRACKING */

@@ -18,6 +20,14 @@ static inline void iommu_debug_detach_device(struct iommu_domain *domain,
{
}

static inline void iommu_debug_domain_add(struct iommu_domain *domain)
{
}

static inline void iommu_debug_domain_remove(struct iommu_domain *domain)
{
}

#endif  /* CONFIG_IOMMU_DEBUG_TRACKING */

#endif /* IOMMU_DEBUG_H */
+4 −0
Original line number Diff line number Diff line
@@ -977,6 +977,8 @@ struct iommu_domain *iommu_domain_alloc(struct bus_type *bus)
	if (ret)
		goto out_free;

	iommu_debug_domain_add(domain);

	return domain;

out_free:
@@ -991,6 +993,8 @@ void iommu_domain_free(struct iommu_domain *domain)
	if (likely(domain->ops->domain_destroy != NULL))
		domain->ops->domain_destroy(domain);

	iommu_debug_domain_remove(domain);

	kfree(domain);
}
EXPORT_SYMBOL_GPL(iommu_domain_free);