Commit adee5587 authored by Kunkun Jiang's avatar Kunkun Jiang Committed by Jia Qingtong
Browse files

vfio/iommu_type1: Add HWDBM status maintenance

virt inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8UZSP


CVE: NA

------------------------------

We are going to optimize dirty log tracking based on iommu dirty
log tracking, but the dirty log from iommu is useful only when
all iommu backed domains support it.

This maintains a counter in vfio_iommu, which is used for dirty
bitmap population in next patch.

This also maintains a boolean flag in vfio_domain, which is used
in the policy of switch dirty log in next patch.

Signed-off-by: default avatarKeqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: default avatarKunkun Jiang <jiangkunkun@huawei.com>
Signed-off-by: default avatarjiaqingtong <jiaqingtong@huawei.com>
parent 86f3d00a
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ struct vfio_iommu {
	unsigned int		vaddr_invalid_count;
	uint64_t		pgsize_bitmap;
	uint64_t		num_non_pinned_groups;
	uint64_t		num_non_hwdbm_domains;
	bool			v2;
	bool			nesting;
	bool			dirty_page_tracking;
@@ -83,6 +84,7 @@ struct vfio_domain {
	struct list_head	group_list;
	bool			fgsp : 1;	/* Fine-grained super pages */
	bool			enforce_cache_coherency : 1;
	bool			iommu_hwdbm;	/* Hardware dirty management */
};

struct vfio_dma {
@@ -2149,6 +2151,26 @@ static int vfio_iommu_domain_alloc(struct device *dev, void *data)
	return 1; /* Don't iterate */
}

/*
 * Called after a new group is added to the iommu_domain, or an old group is
 * removed from the iommu_domain. Update the HWDBM status of vfio_domain and
 * vfio_iommu.
 */
static void vfio_iommu_update_hwdbm(struct vfio_iommu *iommu,
				    struct vfio_domain *domain,
				    bool attach)
{
	bool old_hwdbm = domain->iommu_hwdbm;
	bool new_hwdbm = iommu_support_dirty_log(domain->domain);

	if (old_hwdbm && !new_hwdbm && attach)
		iommu->num_non_hwdbm_domains++;
	else if (!old_hwdbm && new_hwdbm && !attach)
		iommu->num_non_hwdbm_domains--;

	domain->iommu_hwdbm = new_hwdbm;
}

static int vfio_iommu_type1_attach_group(void *iommu_data,
		struct iommu_group *iommu_group, enum vfio_group_type type)
{
@@ -2291,6 +2313,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
			if (!iommu_attach_group(d->domain,
						group->iommu_group)) {
				list_add(&group->next, &d->group_list);
				vfio_iommu_update_hwdbm(iommu, d, true);
				iommu_domain_free(domain->domain);
				kfree(domain);
				goto done;
@@ -2318,6 +2341,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,

	list_add(&domain->next, &iommu->domain_list);
	vfio_update_pgsize_bitmap(iommu);
	vfio_iommu_update_hwdbm(iommu, domain, true);
done:
	/* Delete the old one and insert new iova list */
	vfio_iommu_iova_insert_copy(iommu, &iova_copy);
@@ -2496,6 +2520,7 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,
			continue;

		iommu_detach_group(domain->domain, group->iommu_group);
		vfio_iommu_update_hwdbm(iommu, domain, false);
		update_dirty_scope = !group->pinned_page_dirty_scope;
		list_del(&group->next);
		kfree(group);