Skip to content

Commit

Permalink
kvm/vfio: Support for DMA coherent IOMMUs
Browse files Browse the repository at this point in the history
VFIO now has support for using the IOMMU_CACHE flag and a mechanism
for an external user to test the current operating mode of the IOMMU.
Add support for this to the kvm-vfio pseudo device so that we only
register noncoherent DMA when necessary.

Signed-off-by: Alex Williamson <[email protected]>
Cc: Gleb Natapov <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Acked-by: Paolo Bonzini <[email protected]>
  • Loading branch information
awilliam committed Feb 26, 2014
1 parent 88d7ab8 commit 9d830d4
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions virt/kvm/vfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ static void kvm_vfio_group_put_external_user(struct vfio_group *vfio_group)
symbol_put(vfio_group_put_external_user);
}

static bool kvm_vfio_group_is_coherent(struct vfio_group *vfio_group)
{
long (*fn)(struct vfio_group *, unsigned long);
long ret;

fn = symbol_get(vfio_external_check_extension);
if (!fn)
return false;

ret = fn(vfio_group, VFIO_DMA_CC_IOMMU);

symbol_put(vfio_external_check_extension);

return ret > 0;
}

/*
* Groups can use the same or different IOMMU domains. If the same then
* adding a new group may change the coherency of groups we've previously
Expand All @@ -75,13 +91,10 @@ static void kvm_vfio_update_coherency(struct kvm_device *dev)
mutex_lock(&kv->lock);

list_for_each_entry(kvg, &kv->group_list, node) {
/*
* TODO: We need an interface to check the coherency of
* the IOMMU domain this group is using. For now, assume
* it's always noncoherent.
*/
noncoherent = true;
break;
if (!kvm_vfio_group_is_coherent(kvg->vfio_group)) {
noncoherent = true;
break;
}
}

if (noncoherent != kv->noncoherent) {
Expand Down

0 comments on commit 9d830d4

Please sign in to comment.