Skip to content

Commit 5d70499

Browse files
eaugerwildea01
authored andcommitted
vfio/type1: Allow transparent MSI IOVA allocation
When attaching a group to the container, check the group's reserved regions and test whether the IOMMU translates MSI transactions. If yes, we initialize an IOVA allocator through the iommu_get_msi_cookie API. This will allow the MSI IOVAs to be transparently allocated on MSI controller's compose(). Signed-off-by: Eric Auger <eric.auger@redhat.com> Acked-by: Alex Williamson <alex.williamson@redhat.com> Reviewed-by: Tomasz Nowicki <tomasz.nowicki@caviumnetworks.com> Tested-by: Tomasz Nowicki <tomasz.nowicki@caviumnetworks.com> Tested-by: Bharat Bhushan <bharat.bhushan@nxp.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 5976852 commit 5d70499

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

drivers/vfio/vfio_iommu_type1.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <linux/pid_namespace.h>
4040
#include <linux/mdev.h>
4141
#include <linux/notifier.h>
42+
#include <linux/dma-iommu.h>
4243

4344
#define DRIVER_VERSION "0.2"
4445
#define DRIVER_AUTHOR "Alex Williamson <alex.williamson@redhat.com>"
@@ -1181,6 +1182,28 @@ static struct vfio_group *find_iommu_group(struct vfio_domain *domain,
11811182
return NULL;
11821183
}
11831184

1185+
static bool vfio_iommu_has_resv_msi(struct iommu_group *group,
1186+
phys_addr_t *base)
1187+
{
1188+
struct list_head group_resv_regions;
1189+
struct iommu_resv_region *region, *next;
1190+
bool ret = false;
1191+
1192+
INIT_LIST_HEAD(&group_resv_regions);
1193+
iommu_get_group_resv_regions(group, &group_resv_regions);
1194+
list_for_each_entry(region, &group_resv_regions, list) {
1195+
if (region->type & IOMMU_RESV_MSI) {
1196+
*base = region->start;
1197+
ret = true;
1198+
goto out;
1199+
}
1200+
}
1201+
out:
1202+
list_for_each_entry_safe(region, next, &group_resv_regions, list)
1203+
kfree(region);
1204+
return ret;
1205+
}
1206+
11841207
static int vfio_iommu_type1_attach_group(void *iommu_data,
11851208
struct iommu_group *iommu_group)
11861209
{
@@ -1189,6 +1212,8 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
11891212
struct vfio_domain *domain, *d;
11901213
struct bus_type *bus = NULL, *mdev_bus;
11911214
int ret;
1215+
bool resv_msi;
1216+
phys_addr_t resv_msi_base;
11921217

11931218
mutex_lock(&iommu->lock);
11941219

@@ -1258,6 +1283,8 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
12581283
if (ret)
12591284
goto out_domain;
12601285

1286+
resv_msi = vfio_iommu_has_resv_msi(iommu_group, &resv_msi_base);
1287+
12611288
INIT_LIST_HEAD(&domain->group_list);
12621289
list_add(&group->next, &domain->group_list);
12631290

@@ -1304,6 +1331,9 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
13041331
if (ret)
13051332
goto out_detach;
13061333

1334+
if (resv_msi && iommu_get_msi_cookie(domain->domain, resv_msi_base))
1335+
goto out_detach;
1336+
13071337
list_add(&domain->next, &iommu->domain_list);
13081338

13091339
mutex_unlock(&iommu->lock);

0 commit comments

Comments
 (0)