From: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
To: <alex.williamson@redhat.com>, <eric.auger@redhat.com>,
<pmorel@linux.vnet.ibm.com>
Cc: <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linuxarm@huawei.com>, <john.garry@huawei.com>,
<xuwei5@hisilicon.com>,
Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Subject: [PATCH v4 3/6] vfio/type1: Update iova list on detach
Date: Wed, 21 Feb 2018 12:22:06 +0000 [thread overview]
Message-ID: <20180221122209.9292-4-shameerali.kolothum.thodi@huawei.com> (raw)
In-Reply-To: <20180221122209.9292-1-shameerali.kolothum.thodi@huawei.com>
Get a copy of iova list on _group_detach and try to update the list.
On success replace the current one with the copy. Leave the list as
it is if update fails.
Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
---
drivers/vfio/vfio_iommu_type1.c | 91 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 66c57ee..a80884e 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -1655,12 +1655,88 @@ static void vfio_sanity_check_pfn_list(struct vfio_iommu *iommu)
WARN_ON(iommu->notifier.head);
}
+/*
+ * Called when a domain is removed in detach. It is possible that
+ * the removed domain decided the iova aperture window. Modify the
+ * iova aperture with the smallest window among existing domains.
+ */
+static void vfio_iommu_aper_expand(struct vfio_iommu *iommu,
+ struct list_head *iova_copy)
+{
+ struct vfio_domain *domain;
+ struct iommu_domain_geometry geo;
+ struct vfio_iova *node;
+ dma_addr_t start = 0;
+ dma_addr_t end = (dma_addr_t)~0;
+
+ list_for_each_entry(domain, &iommu->domain_list, next) {
+ iommu_domain_get_attr(domain->domain, DOMAIN_ATTR_GEOMETRY,
+ &geo);
+ if (geo.aperture_start > start)
+ start = geo.aperture_start;
+ if (geo.aperture_end < end)
+ end = geo.aperture_end;
+ }
+
+ /* Modify aperture limits. The new aper is either same or bigger */
+ node = list_first_entry(iova_copy, struct vfio_iova, list);
+ node->start = start;
+ node = list_last_entry(iova_copy, struct vfio_iova, list);
+ node->end = end;
+}
+
+/*
+ * Called when a group is detached. The reserved regions for that
+ * group can be part of valid iova now. But since reserved regions
+ * may be duplicated among groups, populate the iova valid regions
+ * list again.
+ */
+static int vfio_iommu_resv_refresh(struct vfio_iommu *iommu,
+ struct list_head *iova_copy)
+{
+ struct vfio_domain *d;
+ struct vfio_group *g;
+ struct vfio_iova *node;
+ dma_addr_t start, end;
+ LIST_HEAD(resv_regions);
+ int ret;
+
+ list_for_each_entry(d, &iommu->domain_list, next) {
+ list_for_each_entry(g, &d->group_list, next)
+ iommu_get_group_resv_regions(g->iommu_group,
+ &resv_regions);
+ }
+
+ if (list_empty(&resv_regions))
+ return 0;
+
+ node = list_first_entry(iova_copy, struct vfio_iova, list);
+ start = node->start;
+ node = list_last_entry(iova_copy, struct vfio_iova, list);
+ end = node->end;
+
+ /* purge the iova list and create new one */
+ vfio_iommu_iova_free(iova_copy);
+
+ ret = vfio_iommu_aper_resize(iova_copy, start, end);
+ if (ret)
+ goto done;
+
+ /* Exclude current reserved regions from iova ranges */
+ ret = vfio_iommu_resv_exclude(iova_copy, &resv_regions);
+done:
+ vfio_iommu_resv_free(&resv_regions);
+ return ret;
+}
+
static void vfio_iommu_type1_detach_group(void *iommu_data,
struct iommu_group *iommu_group)
{
struct vfio_iommu *iommu = iommu_data;
struct vfio_domain *domain;
struct vfio_group *group;
+ bool iova_copy_fail;
+ LIST_HEAD(iova_copy);
mutex_lock(&iommu->lock);
@@ -1683,6 +1759,12 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,
}
}
+ /*
+ * Get a copy of iova list. If success, use copy to update the
+ * list and to replace the current one.
+ */
+ iova_copy_fail = !!vfio_iommu_iova_get_copy(iommu, &iova_copy);
+
list_for_each_entry(domain, &iommu->domain_list, next) {
group = find_iommu_group(domain, iommu_group);
if (!group)
@@ -1708,10 +1790,19 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,
iommu_domain_free(domain->domain);
list_del(&domain->next);
kfree(domain);
+ if (!iova_copy_fail && !list_empty(&iommu->domain_list))
+ vfio_iommu_aper_expand(iommu, &iova_copy);
}
break;
}
+ if (!iova_copy_fail && !list_empty(&iommu->domain_list)) {
+ if (!vfio_iommu_resv_refresh(iommu, &iova_copy))
+ vfio_iommu_iova_insert_copy(iommu, &iova_copy);
+ else
+ vfio_iommu_iova_free(&iova_copy);
+ }
+
detach_group_done:
mutex_unlock(&iommu->lock);
}
--
2.7.4
next prev parent reply other threads:[~2018-02-21 12:24 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-21 12:22 [PATCH v4 0/6] vfio/type1: Add support for valid iova list management Shameer Kolothum
2018-02-21 12:22 ` [PATCH v4 1/6] vfio/type1: Introduce iova list and add iommu aperture validity check Shameer Kolothum
2018-02-21 12:22 ` [PATCH v4 2/6] vfio/type1: Check reserve region conflict and update iova list Shameer Kolothum
2018-02-21 12:22 ` Shameer Kolothum [this message]
2018-02-21 12:22 ` [PATCH v4 4/6] vfio/type1: check dma map request is within a valid iova range Shameer Kolothum
2018-02-26 22:05 ` Auger Eric
2018-02-26 23:13 ` Alex Williamson
2018-02-27 8:26 ` Auger Eric
2018-02-27 9:57 ` Shameerali Kolothum Thodi
2018-02-27 17:13 ` Alex Williamson
2018-02-28 9:02 ` Auger Eric
2018-02-28 9:25 ` Shameerali Kolothum Thodi
2018-02-28 11:53 ` Auger Eric
2018-02-28 13:39 ` Shameerali Kolothum Thodi
2018-02-28 15:32 ` Auger Eric
2018-02-28 15:24 ` Alex Williamson
2018-03-02 13:19 ` Shameerali Kolothum Thodi
2018-03-02 16:04 ` Alex Williamson
2018-03-02 17:16 ` Robin Murphy
2018-03-05 11:44 ` Shameerali Kolothum Thodi
2018-03-14 18:12 ` Robin Murphy
2018-03-08 9:35 ` Shameerali Kolothum Thodi
2018-02-27 16:57 ` Alex Williamson
2018-02-27 12:40 ` Robin Murphy
2018-02-21 12:22 ` [PATCH v4 5/6] vfio/type1: Add IOVA range capability support Shameer Kolothum
2018-02-22 22:54 ` Alex Williamson
2018-02-23 10:56 ` Shameerali Kolothum Thodi
2018-02-21 12:22 ` [PATCH v4 6/6] vfio/type1: remove duplicate retrieval of reserved regions Shameer Kolothum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180221122209.9292-4-shameerali.kolothum.thodi@huawei.com \
--to=shameerali.kolothum.thodi@huawei.com \
--cc=alex.williamson@redhat.com \
--cc=eric.auger@redhat.com \
--cc=john.garry@huawei.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=pmorel@linux.vnet.ibm.com \
--cc=xuwei5@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).