Skip to content

Commit

Permalink
vfio/type1: Add extension to test DMA cache coherence of IOMMU
Browse files Browse the repository at this point in the history
Now that the type1 IOMMU backend can support IOMMU_CACHE, we need to
be able to test whether coherency is currently enforced.  Add an
extension for this.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
  • Loading branch information
Alex Williamson committed Feb 26, 2014
1 parent 1ef3e2b commit aa42931
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions drivers/vfio/vfio_iommu_type1.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,23 @@ static void vfio_iommu_type1_release(void *iommu_data)
kfree(iommu);
}

static int vfio_domains_have_iommu_cache(struct vfio_iommu *iommu)
{
struct vfio_domain *domain;
int ret = 1;

mutex_lock(&iommu->lock);
list_for_each_entry(domain, &iommu->domain_list, next) {
if (!(domain->prot & IOMMU_CACHE)) {
ret = 0;
break;
}
}
mutex_unlock(&iommu->lock);

return ret;
}

static long vfio_iommu_type1_ioctl(void *iommu_data,
unsigned int cmd, unsigned long arg)
{
Expand All @@ -878,6 +895,10 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
case VFIO_TYPE1_IOMMU:
case VFIO_TYPE1v2_IOMMU:
return 1;
case VFIO_DMA_CC_IOMMU:
if (!iommu)
return 0;
return vfio_domains_have_iommu_cache(iommu);
default:
return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions include/uapi/linux/vfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#define VFIO_TYPE1_IOMMU 1
#define VFIO_SPAPR_TCE_IOMMU 2
#define VFIO_TYPE1v2_IOMMU 3
/*
* IOMMU enforces DMA cache coherence (ex. PCIe NoSnoop stripping). This
* capability is subject to change as groups are added or removed.
*/
#define VFIO_DMA_CC_IOMMU 4

/*
* The IOCTL interface is designed for extensibility by embedding the
Expand Down

0 comments on commit aa42931

Please sign in to comment.